Files
Evandro Fonseca Junior d1d04001d0
Release / release (push) Failing after 5s
Validate / validate (push) Failing after 5m21s
chore: fork @llblab/[email protected] as @evandrodevbr/oh-my-pi-telegram
Fork of upstream llblab/[email protected].0 (SHA afe09c5) repackaged as a
drop-in extension for can1357/oh-my-pi (omp >= 16.5.2).

Changes vs upstream:
- Rename package: @llblab/pi-telegram -> @evandrodevbr/oh-my-pi-telegram
- Bump version: 0.22.0 -> 0.22.0-evandro.1
- Update repository/homepage/bugs URLs to evandrodevbr
- Add omp field in package.json (displayName + compatibleWith)
- README: prepend 'Oh My Pi (omp) Compatibility' section with install
  commands, verified-components table, upstream lineage, and rationale
- CHANGELOG: add '0.22.0-evandro.1' entry under Unreleased
- docs/: rename @llblab/pi-telegram imports to @evandrodevbr/oh-my-pi-telegram
- tests/public-api.test.ts: rename package import paths

Gates re-run on the fork:
- npm run typecheck  -> tsc --noEmit (success)
- npm test           -> 1229 pass / 0 fail / 1 platform-only skip
- npm run audit      -> found 0 vulnerabilities
- npm run pack:check -> evandrodevbr-oh-my-pi-telegram-0.22.0-evandro.1.tgz

Verified:
- omp install --link ./pi-telegram -> Linked OK
- omp plugin list -> @evandrodevbr/[email protected].0-evandro.1

Upstream lineage: badlogic/pi-telegram -> llblab/pi-telegram (0.22.0) -> evandrodevbr/oh-my-pi-telegram (this fork)
2026-07-15 14:18:16 -03:00

90 lines
3.1 KiB
TypeScript

/**
* Telegram bridge path resolution for Pi-compatible runtimes
* Zones: telemetry paths, filesystem, runtime identity
* Owns agent-dir detection and extension-local path derivation
*
* This domain is pure/path-only: it resolves directories and file paths
* from environment and runtime identity. It does not read config, manage
* state, or import broader Telegram domains.
*/
import { homedir } from "node:os";
import { join, resolve } from "node:path";
export interface TelegramAgentDirResolutionInput {
env?: Partial<Pick<NodeJS.ProcessEnv, "PI_CODING_AGENT_DIR">>;
execPath?: string;
argv?: readonly string[];
}
/**
* Resolve the agent data directory for the current Pi-compatible runtime.
*
* Precedence:
* 1. `PI_CODING_AGENT_DIR` env variable, when explicitly set.
* 2. Detect Pi-compatible runtime identity from the executable or argv[1]
* (e.g. OMP vs standard Pi agent).
* 3. Fallback: `~/.pi/agent`.
*/
export function resolveAgentDir(
input: TelegramAgentDirResolutionInput = {},
): string {
const env = input.env ?? process.env;
if (env.PI_CODING_AGENT_DIR) return resolve(env.PI_CODING_AGENT_DIR);
const execPath = input.execPath ?? process.execPath;
const argv = input.argv ?? process.argv;
const execBasename = execPath.toLowerCase().split(/[\\/]/u).pop() ?? "";
const argv1Last = (argv[1] ?? "").toLowerCase().split(/[\\/]/u).pop() ?? "";
if (execBasename.startsWith("omp") || argv1Last.startsWith("omp")) {
return join(homedir(), ".omp", "agent");
}
return join(homedir(), ".pi", "agent");
}
/** Telegram bridge configuration file (<agentDir>/telegram.json). */
export function resolveTelegramConfigPath(): string {
return join(resolveAgentDir(), "telegram.json");
}
/** Telegram singleton lock file (<agentDir>/locks.json). */
export function resolveTelegramLocksPath(): string {
return join(resolveAgentDir(), "locks.json");
}
/** Telegram bridge temporary directory (<agentDir>/tmp/telegram). */
export function resolveTelegramTempDir(agentDir = resolveAgentDir()): string {
return join(agentDir, "tmp", "telegram");
}
export function getTelegramProfilePathSuffix(profileName?: string): string {
return profileName ? `.${profileName.replace(/[^a-zA-Z0-9._-]+/g, "_")}` : "";
}
export function resolveTelegramProfileTempFilePath(
baseName: string,
extension: string,
agentDir = resolveAgentDir(),
profileName?: string,
): string {
return join(
resolveTelegramTempDir(agentDir),
`${baseName}${getTelegramProfilePathSuffix(profileName)}.${extension}`,
);
}
export function getTelegramDiagnosticsDisplayPaths(profileName?: string): {
state: string;
logs: string;
} {
const suffix = getTelegramProfilePathSuffix(profileName);
const profileSlug = suffix.slice(1);
return {
state: `~/.pi/agent/tmp/telegram/state${suffix}.json`,
logs: `~/.pi/agent/tmp/telegram/logs${profileSlug ? `.${profileSlug}` : ""}.jsonl`,
};
}
/** Runtime event log (<agentDir>/tmp/telegram/logs.jsonl). */
export function resolveTelegramRuntimeLogPath(): string {
return resolveTelegramProfileTempFilePath("logs", "jsonl");
}