telecoder 0.0.0-stage → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +363 -0
- package/CHANGELOG.md +1186 -0
- package/LICENSE +22 -0
- package/README.md +126 -2
- package/dist/audio/transcribe.js +50 -0
- package/dist/bin/mcp-server.js +378 -0
- package/dist/bin/tool-result.js +22 -0
- package/dist/bot/access/group-access.js +147 -0
- package/dist/bot/bot.js +592 -0
- package/dist/bot/file-access.js +141 -0
- package/dist/bot/handlers/command/access.js +407 -0
- package/dist/bot/handlers/command/admin.js +827 -0
- package/dist/bot/handlers/command/auto-approve.js +138 -0
- package/dist/bot/handlers/command/btw.js +224 -0
- package/dist/bot/handlers/command/cost.js +409 -0
- package/dist/bot/handlers/command/media.js +197 -0
- package/dist/bot/handlers/command/model.js +305 -0
- package/dist/bot/handlers/command/prefs-scope.js +197 -0
- package/dist/bot/handlers/command/project.js +536 -0
- package/dist/bot/handlers/command/resume.js +321 -0
- package/dist/bot/handlers/command/session.js +438 -0
- package/dist/bot/handlers/command/settings.js +1012 -0
- package/dist/bot/handlers/command/shared.js +210 -0
- package/dist/bot/handlers/command/streaming-mode.js +16 -0
- package/dist/bot/handlers/command/tasks.js +513 -0
- package/dist/bot/handlers/command/topic-store.js +113 -0
- package/dist/bot/handlers/command/topic.js +80 -0
- package/dist/bot/handlers/command.handler.js +772 -0
- package/dist/bot/handlers/fork.handler.js +1109 -0
- package/dist/bot/handlers/media-fallback.js +121 -0
- package/dist/bot/handlers/message/replies.js +133 -0
- package/dist/bot/handlers/message/shared.js +117 -0
- package/dist/bot/handlers/message/throttle.js +49 -0
- package/dist/bot/handlers/message/turn-notify.js +169 -0
- package/dist/bot/handlers/message/turn-runner.js +141 -0
- package/dist/bot/handlers/message.handler.js +107 -0
- package/dist/bot/handlers/newbot.handler.js +221 -0
- package/dist/bot/handlers/photo.handler.js +327 -0
- package/dist/bot/handlers/prompts.handler.js +343 -0
- package/dist/bot/handlers/running-note.js +44 -0
- package/dist/bot/handlers/schedule.handler.js +303 -0
- package/dist/bot/handlers/session-guard.js +78 -0
- package/dist/bot/handlers/suggestion.handler.js +84 -0
- package/dist/bot/handlers/tree.handler.js +480 -0
- package/dist/bot/handlers/view.js +41 -0
- package/dist/bot/handlers/voice.handler.js +209 -0
- package/dist/bot/middleware/admin-only.js +49 -0
- package/dist/bot/middleware/auth.middleware.js +122 -0
- package/dist/bot/middleware/group-mention.middleware.js +139 -0
- package/dist/bot/middleware/group-role.middleware.js +75 -0
- package/dist/bot/middleware/message-batcher.js +87 -0
- package/dist/bot/middleware/queued-messages.js +971 -0
- package/dist/bot/middleware/stale-filter.js +31 -0
- package/dist/build-info.json +8 -0
- package/dist/claude/agent-watchdog.js +162 -0
- package/dist/claude/agent.js +1458 -0
- package/dist/claude/ask-user.js +295 -0
- package/dist/claude/auto-approve.js +225 -0
- package/dist/claude/auto-topic-haiku.js +126 -0
- package/dist/claude/available-commands.js +153 -0
- package/dist/claude/carry-over.js +27 -0
- package/dist/claude/ccr-shim.js +46 -0
- package/dist/claude/charter-judge.js +214 -0
- package/dist/claude/claude-auth.js +121 -0
- package/dist/claude/command-parser.js +200 -0
- package/dist/claude/cost-overlay-scraper.js +129 -0
- package/dist/claude/enabled-plugins.js +56 -0
- package/dist/claude/fork-tree.js +393 -0
- package/dist/claude/held-query.js +190 -0
- package/dist/claude/in-flight-tracker.js +61 -0
- package/dist/claude/ipc-server.js +192 -0
- package/dist/claude/mcp-bridge.js +453 -0
- package/dist/claude/mcp-tools.js +354 -0
- package/dist/claude/message-offsets.js +88 -0
- package/dist/claude/modal-relay.js +450 -0
- package/dist/claude/model-catalog.js +85 -0
- package/dist/claude/monitor-relay.js +597 -0
- package/dist/claude/pending-forks.js +93 -0
- package/dist/claude/pending-suggestions.js +50 -0
- package/dist/claude/permission-gate.js +337 -0
- package/dist/claude/permission-mode.js +178 -0
- package/dist/claude/poll-user.js +51 -0
- package/dist/claude/project-commands.js +69 -0
- package/dist/claude/prompt-hold.js +124 -0
- package/dist/claude/prompt-suggestion-scraper.js +89 -0
- package/dist/claude/pty-provider.js +2214 -0
- package/dist/claude/pty-spawn-config.js +296 -0
- package/dist/claude/pty-stream.js +363 -0
- package/dist/claude/request-queue.js +135 -0
- package/dist/claude/scheduled-runner.js +91 -0
- package/dist/claude/scheduler.js +237 -0
- package/dist/claude/scope-guard.js +274 -0
- package/dist/claude/sdk-permission-gate.js +77 -0
- package/dist/claude/secret-request.js +576 -0
- package/dist/claude/session-cost.js +41 -0
- package/dist/claude/session-history.js +286 -0
- package/dist/claude/session-jsonl.js +920 -0
- package/dist/claude/session-manager.js +195 -0
- package/dist/claude/session-scan.js +270 -0
- package/dist/claude/setup-token.js +285 -0
- package/dist/claude/side-call-options.js +45 -0
- package/dist/claude/side-question.js +249 -0
- package/dist/claude/stage-images.js +62 -0
- package/dist/claude/subagent-tools.js +12 -0
- package/dist/claude/synthetic-ctx.js +51 -0
- package/dist/claude/system-prompt.js +162 -0
- package/dist/claude/tasks-overlay-scraper.js +94 -0
- package/dist/claude/tip-scraper.js +78 -0
- package/dist/claude/tui-modal.js +501 -0
- package/dist/claude/tui-state.js +384 -0
- package/dist/claude/turn-end.js +91 -0
- package/dist/claude/turn-prose.js +64 -0
- package/dist/claude/update-banner-relay.js +70 -0
- package/dist/cli/commands/doctor.js +305 -0
- package/dist/cli/commands/help.js +25 -0
- package/dist/cli/commands/init.js +123 -0
- package/dist/cli/commands/service.js +678 -0
- package/dist/cli/commands/start.js +53 -0
- package/dist/cli/commands/version.js +11 -0
- package/dist/cli/dispatch.js +79 -0
- package/dist/cli/init/env-file.js +99 -0
- package/dist/cli/init/flow.js +638 -0
- package/dist/cli/init/prompter.js +116 -0
- package/dist/cli/init/telegram.js +94 -0
- package/dist/cli/service/render.js +212 -0
- package/dist/cli.js +18 -0
- package/dist/config-report.js +107 -0
- package/dist/config.js +500 -0
- package/dist/index.js +367 -0
- package/dist/launcher.js +933 -0
- package/dist/node-version-check.js +27 -0
- package/dist/providers/ccr-health.js +119 -0
- package/dist/providers/ccr-introspect.js +149 -0
- package/dist/providers/ccr-provider.js +60 -0
- package/dist/providers/claude-provider.js +63 -0
- package/dist/providers/prefs-sync.js +164 -0
- package/dist/providers/project-favorites.js +74 -0
- package/dist/providers/provider-router.js +127 -0
- package/dist/providers/provider-switch.js +91 -0
- package/dist/providers/sdk-provider.js +37 -0
- package/dist/providers/types.js +8 -0
- package/dist/providers/user-preferences.js +214 -0
- package/dist/restart-when-idle.js +153 -0
- package/dist/startup/auto-continue.js +67 -0
- package/dist/startup/auto-resume.js +173 -0
- package/dist/startup/notices.js +120 -0
- package/dist/startup/shared.js +44 -0
- package/dist/startup/verify-token.js +31 -0
- package/dist/telegram/access-request.js +153 -0
- package/dist/telegram/action-logger.js +684 -0
- package/dist/telegram/admin-mention.js +107 -0
- package/dist/telegram/background-activity-card.js +502 -0
- package/dist/telegram/botname-settings.js +336 -0
- package/dist/telegram/button-text.js +26 -0
- package/dist/telegram/client-options.js +27 -0
- package/dist/telegram/deduplication.js +33 -0
- package/dist/telegram/entities.js +295 -0
- package/dist/telegram/force-reply-tracker.js +57 -0
- package/dist/telegram/lettered-options.js +87 -0
- package/dist/telegram/markdown.js +362 -0
- package/dist/telegram/message-sender.js +1287 -0
- package/dist/telegram/prompt-label.js +142 -0
- package/dist/telegram/prompt-suggestion.js +54 -0
- package/dist/telegram/send.js +123 -0
- package/dist/telegram/streaming-turn.js +105 -0
- package/dist/telegram/suggestions-settings.js +30 -0
- package/dist/telegram/task-list.js +367 -0
- package/dist/telegram/task-tracker.js +209 -0
- package/dist/telegram/telegraph-settings.js +31 -0
- package/dist/telegram/telegraph.js +453 -0
- package/dist/telegram/terminal-renderer.js +671 -0
- package/dist/telegram/terminal-settings.js +25 -0
- package/dist/telegram/thread-titles.js +190 -0
- package/dist/telegram/threads-setup.js +117 -0
- package/dist/tts/tts-settings.js +62 -0
- package/dist/tts/tts.js +245 -0
- package/dist/tts/voice-reply.js +78 -0
- package/dist/utils/admins.js +143 -0
- package/dist/utils/agent-timer.js +55 -0
- package/dist/utils/atomic-write.js +24 -0
- package/dist/utils/bot-token.js +74 -0
- package/dist/utils/bounded-map.js +55 -0
- package/dist/utils/build-info.js +57 -0
- package/dist/utils/caffeinate.js +50 -0
- package/dist/utils/claude-env.js +54 -0
- package/dist/utils/claude-version.js +48 -0
- package/dist/utils/config-home.js +62 -0
- package/dist/utils/debug-agent.js +117 -0
- package/dist/utils/debug-watchdog.js +121 -0
- package/dist/utils/download.js +111 -0
- package/dist/utils/exit-codes.js +48 -0
- package/dist/utils/file-type.js +149 -0
- package/dist/utils/format.js +81 -0
- package/dist/utils/home-project.js +30 -0
- package/dist/utils/host-stall.js +51 -0
- package/dist/utils/id-list.js +44 -0
- package/dist/utils/idle-restart.js +92 -0
- package/dist/utils/install-mode.js +63 -0
- package/dist/utils/instance-config.js +148 -0
- package/dist/utils/instances.js +95 -0
- package/dist/utils/json-store.js +140 -0
- package/dist/utils/keyed-settings.js +62 -0
- package/dist/utils/legacy-env.js +35 -0
- package/dist/utils/npm-version.js +134 -0
- package/dist/utils/prefs-relay.js +107 -0
- package/dist/utils/proc-children.js +102 -0
- package/dist/utils/project-data-dir.js +33 -0
- package/dist/utils/reasoning-summary.js +12 -0
- package/dist/utils/resolve-bin.js +86 -0
- package/dist/utils/resolve-claude-bin.js +63 -0
- package/dist/utils/respawn-backoff.js +19 -0
- package/dist/utils/sanitize.js +91 -0
- package/dist/utils/session-key.js +37 -0
- package/dist/utils/stale-launcher.js +109 -0
- package/dist/utils/state-dir-migration.js +92 -0
- package/dist/utils/systemd.js +126 -0
- package/dist/utils/user-roster.js +275 -0
- package/dist/utils/verbosity.js +118 -0
- package/dist/utils/version-check.js +166 -0
- package/dist/utils/workspace-guard.js +44 -0
- package/dist/worker-restart.js +141 -0
- package/instances.json.example +41 -0
- package/package.json +76 -4
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A per-session settings store backed by a JSON file in the state directory.
|
|
3
|
+
*
|
|
4
|
+
* The TTS, Terminal UI, Telegraph, prompt-suggestion and bot-name settings are
|
|
5
|
+
* all the same thing: a `sessionKey → settings` map, persisted as
|
|
6
|
+
* `{ settings: { [key]: entry } }`, where any field absent from disk falls back
|
|
7
|
+
* to an env-level default. This factory is that shape, once.
|
|
8
|
+
*
|
|
9
|
+
* Each bot has its own file. Each bot is its own process with its own copy of
|
|
10
|
+
* the entries, so when they shared one, every save put back whatever the others
|
|
11
|
+
* had changed since that copy was loaded. Merging by key wouldn't have helped:
|
|
12
|
+
* a private chat's key is the user's id, the same for every bot they talk to.
|
|
13
|
+
*/
|
|
14
|
+
import * as path from 'path';
|
|
15
|
+
import { z } from 'zod';
|
|
16
|
+
import { BOT_ID } from '../config.js';
|
|
17
|
+
import { ensureStateDir, getStateDir, readSeededJsonFile, writeJsonFile } from './json-store.js';
|
|
18
|
+
export function createKeyedSettings(opts) {
|
|
19
|
+
const dir = opts.dir ?? getStateDir();
|
|
20
|
+
const filePath = path.join(dir, `${path.basename(opts.file, '.json')}-${opts.botId ?? BOT_ID}.json`);
|
|
21
|
+
const sharedPath = path.join(dir, opts.file);
|
|
22
|
+
const fileSchema = z.object({ settings: z.record(z.string(), opts.entrySchema) });
|
|
23
|
+
const entries = new Map();
|
|
24
|
+
ensureStateDir(dir, opts.label);
|
|
25
|
+
// A seed is copied as it was on disk rather than normalized: a field nobody
|
|
26
|
+
// chose has to keep following its env-level default, see get().
|
|
27
|
+
const loaded = readSeededJsonFile(filePath, sharedPath, fileSchema, opts.label);
|
|
28
|
+
if (loaded) {
|
|
29
|
+
for (const [key, stored] of Object.entries(loaded.settings)) {
|
|
30
|
+
entries.set(key, opts.normalize(stored));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function assertKey(key) {
|
|
34
|
+
if (!key || typeof key !== 'string') {
|
|
35
|
+
throw new Error(`[${opts.label}] Invalid settings key: ${key}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function save() {
|
|
39
|
+
ensureStateDir(dir, opts.label);
|
|
40
|
+
writeJsonFile(filePath, { settings: Object.fromEntries(entries) }, opts.label);
|
|
41
|
+
}
|
|
42
|
+
function get(key) {
|
|
43
|
+
assertKey(key);
|
|
44
|
+
const existing = entries.get(key);
|
|
45
|
+
if (existing)
|
|
46
|
+
return existing;
|
|
47
|
+
// Deliberately not stored: a session that has never chosen keeps tracking
|
|
48
|
+
// its env-level default, so changing the default in config still reaches
|
|
49
|
+
// every user who hasn't overridden it. Persisting here would freeze the
|
|
50
|
+
// default at whatever it happened to be the first time something read it.
|
|
51
|
+
return opts.normalize();
|
|
52
|
+
}
|
|
53
|
+
function update(key, patch) {
|
|
54
|
+
assertKey(key);
|
|
55
|
+
const next = { ...get(key), ...patch };
|
|
56
|
+
entries.set(key, next);
|
|
57
|
+
save();
|
|
58
|
+
return next;
|
|
59
|
+
}
|
|
60
|
+
return { get, update };
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=keyed-settings.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TeleCoder was renamed from Claudegram in July 2026, and its environment
|
|
3
|
+
* variables moved from `CLAUDEGRAM_*` to `TELECODER_*`. Anyone upgrading across
|
|
4
|
+
* that rename still has the old names in their `.env` or exported shell env, so
|
|
5
|
+
* every *user-settable* var reads the new name first and falls back to the old
|
|
6
|
+
* one — warning once per var so the deprecation is visible without spamming a
|
|
7
|
+
* line on every read.
|
|
8
|
+
*
|
|
9
|
+
* Internal parent→child vars are deliberately NOT routed through here. The ones
|
|
10
|
+
* `launcher.ts` sets for its workers and `pty-provider.ts` sets for the MCP
|
|
11
|
+
* subprocess are written and read by the same build, so they rename in lockstep
|
|
12
|
+
* and have no older peer to stay compatible with.
|
|
13
|
+
*/
|
|
14
|
+
const warned = new Set();
|
|
15
|
+
/**
|
|
16
|
+
* Read `TELECODER_<suffix>`, falling back to the pre-rename `CLAUDEGRAM_<suffix>`.
|
|
17
|
+
* Pass the suffix only — e.g. `legacyEnv('PERMISSION_PROMPTS')`.
|
|
18
|
+
*/
|
|
19
|
+
export function legacyEnv(suffix) {
|
|
20
|
+
const current = process.env[`TELECODER_${suffix}`];
|
|
21
|
+
if (current !== undefined)
|
|
22
|
+
return current;
|
|
23
|
+
const legacy = process.env[`CLAUDEGRAM_${suffix}`];
|
|
24
|
+
if (legacy !== undefined && !warned.has(suffix)) {
|
|
25
|
+
warned.add(suffix);
|
|
26
|
+
console.warn(`[env] CLAUDEGRAM_${suffix} is deprecated — rename it to TELECODER_${suffix}. ` +
|
|
27
|
+
'The old name still works, but support for it will be dropped.');
|
|
28
|
+
}
|
|
29
|
+
return legacy;
|
|
30
|
+
}
|
|
31
|
+
/** Reset the warn-once state. Test seam — production never needs this. */
|
|
32
|
+
export function resetLegacyEnvWarnings() {
|
|
33
|
+
warned.clear();
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=legacy-env.js.map
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The npm side of /version and /update, for a package install (see
|
|
3
|
+
* utils/install-mode.ts). A checkout asks git instead (utils/version-check.ts).
|
|
4
|
+
*
|
|
5
|
+
* `npm view` goes to the registry, so its answer is cached in the state
|
|
6
|
+
* directory and only asked for on demand — never on the way up.
|
|
7
|
+
*/
|
|
8
|
+
import { execFile } from 'child_process';
|
|
9
|
+
import * as fs from 'fs';
|
|
10
|
+
import * as path from 'path';
|
|
11
|
+
import { getStateDir } from './json-store.js';
|
|
12
|
+
import { atomicWriteFileSync } from './atomic-write.js';
|
|
13
|
+
export const PACKAGE_NAME = 'telecoder';
|
|
14
|
+
const VIEW_TIMEOUT_MS = 10_000;
|
|
15
|
+
const CACHE_TTL_MS = 6 * 60 * 60 * 1000;
|
|
16
|
+
const CACHE_FILE = 'npm-latest.json';
|
|
17
|
+
/** -1, 0 or 1, comparing the numeric x.y.z parts; a prerelease sorts below its release. */
|
|
18
|
+
export function compareVersions(a, b) {
|
|
19
|
+
const parse = (v) => {
|
|
20
|
+
const [core, pre] = v.trim().replace(/^v/, '').split('-', 2);
|
|
21
|
+
return { nums: core.split('.').map((n) => parseInt(n, 10) || 0), pre: pre ?? null };
|
|
22
|
+
};
|
|
23
|
+
const x = parse(a);
|
|
24
|
+
const y = parse(b);
|
|
25
|
+
for (let i = 0; i < Math.max(x.nums.length, y.nums.length); i++) {
|
|
26
|
+
const d = (x.nums[i] ?? 0) - (y.nums[i] ?? 0);
|
|
27
|
+
if (d !== 0)
|
|
28
|
+
return d < 0 ? -1 : 1;
|
|
29
|
+
}
|
|
30
|
+
if (x.pre === y.pre)
|
|
31
|
+
return 0;
|
|
32
|
+
if (x.pre === null)
|
|
33
|
+
return 1;
|
|
34
|
+
if (y.pre === null)
|
|
35
|
+
return -1;
|
|
36
|
+
return x.pre < y.pre ? -1 : 1;
|
|
37
|
+
}
|
|
38
|
+
/** What `npm view telecoder version` answers, or null when it can't be asked. */
|
|
39
|
+
export function fetchLatestVersion(timeout = VIEW_TIMEOUT_MS) {
|
|
40
|
+
return new Promise((resolve) => {
|
|
41
|
+
execFile('npm', ['view', PACKAGE_NAME, 'version'], { timeout }, (error, stdout) => {
|
|
42
|
+
if (error) {
|
|
43
|
+
console.debug(`[Version] npm view failed (${error.code ?? error.signal})`);
|
|
44
|
+
resolve(null);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const version = stdout.trim().split('\n').pop()?.trim() ?? '';
|
|
48
|
+
resolve(/^\d+\.\d+\.\d+/.test(version) ? version : null);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function cachePath() {
|
|
53
|
+
return path.join(getStateDir(), CACHE_FILE);
|
|
54
|
+
}
|
|
55
|
+
function readCache(now) {
|
|
56
|
+
try {
|
|
57
|
+
const entry = JSON.parse(fs.readFileSync(cachePath(), 'utf-8'));
|
|
58
|
+
if (typeof entry.version !== 'string' || typeof entry.checkedAt !== 'number')
|
|
59
|
+
return null;
|
|
60
|
+
return now - entry.checkedAt < CACHE_TTL_MS ? entry.version : null;
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function writeCache(version, now) {
|
|
67
|
+
try {
|
|
68
|
+
fs.mkdirSync(path.dirname(cachePath()), { recursive: true, mode: 0o700 });
|
|
69
|
+
atomicWriteFileSync(cachePath(), JSON.stringify({ version, checkedAt: now }), { mode: 0o600 });
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// A cache that can't be written only costs the next caller a registry call.
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** The latest published version, from the cache when it's fresh. */
|
|
76
|
+
export async function getLatestVersion({ fresh = false, fetch = fetchLatestVersion, now = Date.now() } = {}) {
|
|
77
|
+
if (!fresh) {
|
|
78
|
+
const cached = readCache(now);
|
|
79
|
+
if (cached)
|
|
80
|
+
return cached;
|
|
81
|
+
}
|
|
82
|
+
const latest = await fetch();
|
|
83
|
+
if (latest)
|
|
84
|
+
writeCache(latest, now);
|
|
85
|
+
return latest;
|
|
86
|
+
}
|
|
87
|
+
export function compareInstalled(installed, latest) {
|
|
88
|
+
if (!installed || !latest)
|
|
89
|
+
return { kind: 'unknown', installed };
|
|
90
|
+
const order = compareVersions(installed, latest);
|
|
91
|
+
if (order === 0)
|
|
92
|
+
return { kind: 'current', installed, latest };
|
|
93
|
+
return order < 0 ? { kind: 'behind', installed, latest } : { kind: 'ahead', installed, latest };
|
|
94
|
+
}
|
|
95
|
+
/** The command that updates this install, as a person would type it. */
|
|
96
|
+
export function updateCommand(runner) {
|
|
97
|
+
switch (runner) {
|
|
98
|
+
case 'global':
|
|
99
|
+
return `npm install -g ${PACKAGE_NAME}@latest`;
|
|
100
|
+
case 'npx':
|
|
101
|
+
return `npx ${PACKAGE_NAME}@latest start`;
|
|
102
|
+
case 'local':
|
|
103
|
+
return `npm install ${PACKAGE_NAME}@latest`;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export function describeNpmCheck(check, runner) {
|
|
107
|
+
switch (check.kind) {
|
|
108
|
+
case 'unknown':
|
|
109
|
+
return check.installed
|
|
110
|
+
? `❓ Couldn't ask npm for the latest version, so v${check.installed} may or may not be current.`
|
|
111
|
+
: "❓ Couldn't tell which version this is.";
|
|
112
|
+
case 'current':
|
|
113
|
+
return `✅ v${check.installed} is the latest release.`;
|
|
114
|
+
case 'ahead':
|
|
115
|
+
return `⬆️ v${check.installed} is newer than the latest release (v${check.latest}).`;
|
|
116
|
+
case 'behind':
|
|
117
|
+
return runner === 'global'
|
|
118
|
+
? `⚠️ v${check.latest} is out (this is v${check.installed}). /update installs it.`
|
|
119
|
+
: `⚠️ v${check.latest} is out (this is v${check.installed}). Update with: ${updateCommand(runner)}`;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/** Run `npm install -g telecoder@latest`. Resolves with npm's output, rejects with its error. */
|
|
123
|
+
export function installLatestGlobally() {
|
|
124
|
+
return new Promise((resolve, reject) => {
|
|
125
|
+
execFile('npm', ['install', '-g', `${PACKAGE_NAME}@latest`], { timeout: 300_000, maxBuffer: 4 * 1024 * 1024 }, (error, stdout, stderr) => {
|
|
126
|
+
if (error) {
|
|
127
|
+
reject(new Error((stderr || error.message || 'npm install failed').trim()));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
resolve((stdout || stderr || '').trim());
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=npm-version.js.map
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bookkeeping for a preference change one bot asked to apply to all of them.
|
|
3
|
+
*
|
|
4
|
+
* The launcher is the only path between workers, so it has to hold each
|
|
5
|
+
* broadcast open until every sibling has answered, then hand the requester a
|
|
6
|
+
* summary of what they each did. Getting that wrong is invisible in the good
|
|
7
|
+
* case and misleading in the bad one — a bot reported as "applied" that never
|
|
8
|
+
* got the message, or a requester left waiting on a worker that died mid-relay.
|
|
9
|
+
*
|
|
10
|
+
* Kept out of launcher.ts, alongside the backoff and host-stall policies, for
|
|
11
|
+
* the same reason those are: the launcher spawns worker threads at import time
|
|
12
|
+
* and can't be loaded in a test, and this is the part with the edge cases.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Tracks broadcasts in flight and decides when each is done.
|
|
16
|
+
*
|
|
17
|
+
* A broadcast settles exactly once: on the last reply, on the timeout, or
|
|
18
|
+
* immediately when there was nobody to wait for. Everything after that —
|
|
19
|
+
* a late reply from a slow worker, a duplicate — is dropped, because the
|
|
20
|
+
* requester has already been answered and been told that bot didn't respond.
|
|
21
|
+
*/
|
|
22
|
+
export class PrefsRelay {
|
|
23
|
+
pending = new Map();
|
|
24
|
+
/** Whether this id is still open. */
|
|
25
|
+
has(requestId) {
|
|
26
|
+
return this.pending.has(requestId);
|
|
27
|
+
}
|
|
28
|
+
/** Bots this broadcast is still waiting on. Empty for an unknown id. */
|
|
29
|
+
awaiting(requestId) {
|
|
30
|
+
return [...(this.pending.get(requestId)?.awaiting ?? [])];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Open a broadcast. Settles synchronously — before returning — when there
|
|
34
|
+
* are no siblings to wait on, so a lone bot gets an answer straight away
|
|
35
|
+
* rather than after the timeout.
|
|
36
|
+
*/
|
|
37
|
+
begin(requestId, input) {
|
|
38
|
+
// A reused id would orphan the first requester; settling it first at least
|
|
39
|
+
// answers them rather than leaving them on their own timeout.
|
|
40
|
+
if (this.pending.has(requestId))
|
|
41
|
+
this.settle(requestId);
|
|
42
|
+
const entry = {
|
|
43
|
+
awaiting: new Set(input.awaiting),
|
|
44
|
+
outcomes: [],
|
|
45
|
+
unreachable: [...input.unreachable],
|
|
46
|
+
onSettle: input.onSettle,
|
|
47
|
+
};
|
|
48
|
+
this.pending.set(requestId, entry);
|
|
49
|
+
if (entry.awaiting.size === 0) {
|
|
50
|
+
this.settle(requestId);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
entry.timer = setTimeout(() => {
|
|
54
|
+
input.onTimeout?.(this.awaiting(requestId));
|
|
55
|
+
this.settle(requestId);
|
|
56
|
+
}, input.timeoutMs);
|
|
57
|
+
// The launcher must not be held alive by a broadcast nobody is waiting on.
|
|
58
|
+
entry.timer.unref?.();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Record one bot's answer, settling the broadcast if it was the last one
|
|
62
|
+
* outstanding. Ignores answers for unknown ids and bots not being awaited —
|
|
63
|
+
* a duplicate reply, or one that arrives after the timeout.
|
|
64
|
+
*/
|
|
65
|
+
record(requestId, outcome) {
|
|
66
|
+
const entry = this.pending.get(requestId);
|
|
67
|
+
if (!entry || !entry.awaiting.delete(outcome.name))
|
|
68
|
+
return;
|
|
69
|
+
entry.outcomes.push(outcome);
|
|
70
|
+
if (entry.awaiting.size === 0)
|
|
71
|
+
this.settle(requestId);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Give up on a bot without an answer from it — it exited while the broadcast
|
|
75
|
+
* was open. Settles if it was the last one outstanding.
|
|
76
|
+
*/
|
|
77
|
+
abandon(requestId, name) {
|
|
78
|
+
const entry = this.pending.get(requestId);
|
|
79
|
+
if (!entry || !entry.awaiting.delete(name))
|
|
80
|
+
return;
|
|
81
|
+
entry.unreachable.push(name);
|
|
82
|
+
if (entry.awaiting.size === 0)
|
|
83
|
+
this.settle(requestId);
|
|
84
|
+
}
|
|
85
|
+
/** Same, for every broadcast currently waiting on `name`. */
|
|
86
|
+
abandonEverywhere(name) {
|
|
87
|
+
for (const requestId of [...this.pending.keys()]) {
|
|
88
|
+
this.abandon(requestId, name);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** Answer the requester now, with whatever has come back. */
|
|
92
|
+
settle(requestId) {
|
|
93
|
+
const entry = this.pending.get(requestId);
|
|
94
|
+
if (!entry)
|
|
95
|
+
return;
|
|
96
|
+
if (entry.timer)
|
|
97
|
+
clearTimeout(entry.timer);
|
|
98
|
+
this.pending.delete(requestId);
|
|
99
|
+
entry.onSettle({
|
|
100
|
+
applied: entry.outcomes.filter((o) => o.status === 'applied'),
|
|
101
|
+
skipped: entry.outcomes.filter((o) => o.status === 'skipped'),
|
|
102
|
+
// Anything still awaited when we settle never answered.
|
|
103
|
+
unreachable: [...entry.unreachable, ...entry.awaiting],
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=prefs-relay.js.map
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
const CLK_TCK = 100;
|
|
3
|
+
export function getDirectChildren(pid) {
|
|
4
|
+
let tids;
|
|
5
|
+
try {
|
|
6
|
+
tids = fs.readdirSync(`/proc/${pid}/task`);
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
const out = new Set();
|
|
12
|
+
for (const tid of tids) {
|
|
13
|
+
try {
|
|
14
|
+
const content = fs.readFileSync(`/proc/${pid}/task/${tid}/children`, 'utf8');
|
|
15
|
+
for (const part of content.trim().split(/\s+/)) {
|
|
16
|
+
if (!part)
|
|
17
|
+
continue;
|
|
18
|
+
const child = Number.parseInt(part, 10);
|
|
19
|
+
if (Number.isFinite(child))
|
|
20
|
+
out.add(child);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch { /* tid raced away */ }
|
|
24
|
+
}
|
|
25
|
+
return [...out].sort((a, b) => a - b);
|
|
26
|
+
}
|
|
27
|
+
export function getDescendantPids(rootPid) {
|
|
28
|
+
const out = [];
|
|
29
|
+
const queue = [rootPid];
|
|
30
|
+
const seen = new Set([rootPid]);
|
|
31
|
+
while (queue.length) {
|
|
32
|
+
const cur = queue.shift();
|
|
33
|
+
for (const child of getDirectChildren(cur)) {
|
|
34
|
+
if (seen.has(child))
|
|
35
|
+
continue;
|
|
36
|
+
seen.add(child);
|
|
37
|
+
out.push(child);
|
|
38
|
+
queue.push(child);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
export function describeProcess(pid) {
|
|
44
|
+
let argvRaw;
|
|
45
|
+
let statRaw;
|
|
46
|
+
try {
|
|
47
|
+
argvRaw = fs.readFileSync(`/proc/${pid}/cmdline`);
|
|
48
|
+
statRaw = fs.readFileSync(`/proc/${pid}/stat`, 'utf8');
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
const argv = argvRaw.toString('utf8').split('\0').filter(Boolean);
|
|
54
|
+
if (argv.length === 0)
|
|
55
|
+
return undefined;
|
|
56
|
+
// /proc/<pid>/stat: "<pid> (<comm>) <state> <ppid> ..."
|
|
57
|
+
// comm can contain spaces and parens, so split after the LAST ')'.
|
|
58
|
+
const lastParen = statRaw.lastIndexOf(')');
|
|
59
|
+
const fields = statRaw.substring(lastParen + 2).split(' ');
|
|
60
|
+
const ppid = Number.parseInt(fields[1], 10) || 0;
|
|
61
|
+
// starttime is stat field 22 (1-indexed). After dropping pid, comm, and the
|
|
62
|
+
// post-')' state field, the offset into `fields` is 19.
|
|
63
|
+
const startTimeTicks = Number.parseInt(fields[19], 10);
|
|
64
|
+
let ageSec = 0;
|
|
65
|
+
try {
|
|
66
|
+
const uptimeSec = Number.parseFloat(fs.readFileSync('/proc/uptime', 'utf8').split(' ')[0]);
|
|
67
|
+
if (Number.isFinite(startTimeTicks) && Number.isFinite(uptimeSec)) {
|
|
68
|
+
ageSec = Math.max(0, Math.round(uptimeSec - startTimeTicks / CLK_TCK));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch { /* keep 0 */ }
|
|
72
|
+
return { pid, ppid, cmd: argv.join(' '), argv, ageSec };
|
|
73
|
+
}
|
|
74
|
+
export function isDescendantOf(rootPid, candidatePid) {
|
|
75
|
+
if (rootPid === candidatePid)
|
|
76
|
+
return false;
|
|
77
|
+
let cur = candidatePid;
|
|
78
|
+
for (let i = 0; i < 64; i++) {
|
|
79
|
+
const info = describeProcess(cur);
|
|
80
|
+
if (!info || info.ppid <= 1)
|
|
81
|
+
return false;
|
|
82
|
+
if (info.ppid === rootPid)
|
|
83
|
+
return true;
|
|
84
|
+
cur = info.ppid;
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
export function killTree(rootPid, signal = 'SIGTERM') {
|
|
89
|
+
// Leaves first — otherwise the kernel reparents live grandchildren to init
|
|
90
|
+
// before we get to them.
|
|
91
|
+
const targets = [...getDescendantPids(rootPid), rootPid].reverse();
|
|
92
|
+
let killed = 0;
|
|
93
|
+
for (const pid of targets) {
|
|
94
|
+
try {
|
|
95
|
+
process.kill(pid, signal);
|
|
96
|
+
killed++;
|
|
97
|
+
}
|
|
98
|
+
catch { /* already gone or no perms */ }
|
|
99
|
+
}
|
|
100
|
+
return killed;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=proc-children.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TeleCoder's own folder inside a project: `<project>/.telecoder/`, holding
|
|
3
|
+
* what the bot writes there for Claude to read — files sent in the chat
|
|
4
|
+
* (`uploads/`) and conversation handoffs (`handoffs/`).
|
|
5
|
+
*
|
|
6
|
+
* The folder ignores itself: the first time it is made, it gets a `.gitignore`
|
|
7
|
+
* of `*`. A project's own `.gitignore` can't be relied on to cover it — one
|
|
8
|
+
* that ignores the pre-rename `.claudegram/` doesn't ignore `.telecoder/` — and
|
|
9
|
+
* without this the photos someone sent would be one `git add -A` away from a
|
|
10
|
+
* commit. Nothing in the project has to change for it.
|
|
11
|
+
*/
|
|
12
|
+
import * as fs from 'fs';
|
|
13
|
+
import * as path from 'path';
|
|
14
|
+
/** The folder's name inside a project. */
|
|
15
|
+
export const PROJECT_DATA_DIR = '.telecoder';
|
|
16
|
+
const SELF_IGNORE = '# Written by TeleCoder: nothing in this folder belongs in git.\n*\n';
|
|
17
|
+
/** Create `<projectDir>/.telecoder/<sub>` if needed, and return its path. */
|
|
18
|
+
export function ensureProjectDataDir(projectDir, sub) {
|
|
19
|
+
const root = path.join(projectDir, PROJECT_DATA_DIR);
|
|
20
|
+
const dir = path.join(root, sub);
|
|
21
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
22
|
+
try {
|
|
23
|
+
// 'wx' leaves a .gitignore someone has edited alone.
|
|
24
|
+
fs.writeFileSync(path.join(root, '.gitignore'), SELF_IGNORE, { flag: 'wx', mode: 0o600 });
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
if (err.code !== 'EEXIST') {
|
|
28
|
+
console.warn(`[ProjectData] Couldn't write ${path.join(root, '.gitignore')}: ${err.message}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return dir;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=project-data-dir.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strip the "Reasoning Summary" section from the end of a response
|
|
3
|
+
* so it doesn't appear in Telegram chat (it's already in logs).
|
|
4
|
+
*/
|
|
5
|
+
export function stripReasoningSummary(text) {
|
|
6
|
+
// Match a trailing reasoning summary block:
|
|
7
|
+
// ---\n**Reasoning Summary**\n... (to end)
|
|
8
|
+
// or: **Reasoning Summary**\n... (to end)
|
|
9
|
+
// or: *Reasoning Summary*\n... (to end)
|
|
10
|
+
return text.replace(/\n*(?:---\n+)?(?:\*{1,2})Reasoning Summary(?:\*{1,2})\n[\s\S]*$/, '').trimEnd();
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=reasoning-summary.js.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { execFileSync } from 'child_process';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as os from 'os';
|
|
4
|
+
import * as path from 'path';
|
|
5
|
+
const cache = new Map();
|
|
6
|
+
const isWin = process.platform === 'win32';
|
|
7
|
+
/**
|
|
8
|
+
* Check if a resolved path is a valid executable file.
|
|
9
|
+
* Follows symlinks (required for Homebrew, snap, etc.).
|
|
10
|
+
*/
|
|
11
|
+
function isValidExecutable(filePath) {
|
|
12
|
+
try {
|
|
13
|
+
const resolved = fs.realpathSync(filePath);
|
|
14
|
+
const stats = fs.statSync(resolved);
|
|
15
|
+
if (!stats.isFile())
|
|
16
|
+
return false;
|
|
17
|
+
if (!isWin && !(stats.mode & 0o111))
|
|
18
|
+
return false;
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function getSearchDirs() {
|
|
26
|
+
const home = os.homedir();
|
|
27
|
+
switch (process.platform) {
|
|
28
|
+
case 'win32':
|
|
29
|
+
return [];
|
|
30
|
+
case 'darwin':
|
|
31
|
+
return [
|
|
32
|
+
'/opt/homebrew/bin',
|
|
33
|
+
'/usr/local/bin',
|
|
34
|
+
'/usr/bin',
|
|
35
|
+
path.join(home, '.local', 'bin'),
|
|
36
|
+
];
|
|
37
|
+
default:
|
|
38
|
+
return [
|
|
39
|
+
path.join(home, '.local', 'bin'),
|
|
40
|
+
'/usr/local/bin',
|
|
41
|
+
'/usr/bin',
|
|
42
|
+
'/snap/bin',
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const SEARCH_DIRS = getSearchDirs();
|
|
47
|
+
/**
|
|
48
|
+
* Resolve a binary name to its full path.
|
|
49
|
+
* Checks platform-specific install locations so execFile works under
|
|
50
|
+
* systemd, launchd, and other environments with minimal PATH.
|
|
51
|
+
*/
|
|
52
|
+
export function resolveBin(name) {
|
|
53
|
+
// Reject names with path separators to prevent traversal
|
|
54
|
+
if (name.includes('/') || name.includes('\\') || name.includes('..')) {
|
|
55
|
+
throw new Error(`Invalid binary name: path separators not allowed`);
|
|
56
|
+
}
|
|
57
|
+
const cached = cache.get(name);
|
|
58
|
+
if (cached) {
|
|
59
|
+
if (isValidExecutable(cached)) {
|
|
60
|
+
return cached;
|
|
61
|
+
}
|
|
62
|
+
cache.delete(name);
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const cmd = isWin ? 'where' : 'which';
|
|
66
|
+
const result = execFileSync(cmd, [name], { encoding: 'utf8', timeout: 3000 }).trim();
|
|
67
|
+
const resolved = result.split(/\r?\n/)[0];
|
|
68
|
+
if (resolved && isValidExecutable(resolved)) {
|
|
69
|
+
cache.set(name, resolved);
|
|
70
|
+
return resolved;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// Lookup failed or binary not found in PATH
|
|
75
|
+
}
|
|
76
|
+
for (const dir of SEARCH_DIRS) {
|
|
77
|
+
const fullPath = path.join(dir, name);
|
|
78
|
+
if (isValidExecutable(fullPath)) {
|
|
79
|
+
cache.set(name, fullPath);
|
|
80
|
+
return fullPath;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Fall back to bare name and let execFile resolve via PATH
|
|
84
|
+
return name;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=resolve-bin.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { config } from '../config.js';
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
let cachedBundled;
|
|
5
|
+
/**
|
|
6
|
+
* Resolve the executable path TeleCoder would normally hand to the SDK.
|
|
7
|
+
* Mirrors the precedence in `src/claude/agent.ts`:
|
|
8
|
+
* 1. If CLAUDE_USE_BUNDLED_EXECUTABLE=false, use CLAUDE_EXECUTABLE_PATH.
|
|
9
|
+
* 2. Else, prefer the matching-libc bundled binary.
|
|
10
|
+
* 3. Fall back to CLAUDE_EXECUTABLE_PATH (or `claude` on PATH).
|
|
11
|
+
*/
|
|
12
|
+
export function resolveActiveClaudeExecutable() {
|
|
13
|
+
if (!config.CLAUDE_USE_BUNDLED_EXECUTABLE) {
|
|
14
|
+
return config.CLAUDE_EXECUTABLE_PATH;
|
|
15
|
+
}
|
|
16
|
+
return resolveBundledClaudeBin() ?? config.CLAUDE_EXECUTABLE_PATH;
|
|
17
|
+
}
|
|
18
|
+
function isMuslLibc() {
|
|
19
|
+
// On glibc systems, process.report.header includes glibcVersionRuntime.
|
|
20
|
+
// On musl (Alpine etc.), that field is absent.
|
|
21
|
+
const header = process.report?.getReport?.()?.header;
|
|
22
|
+
return !header?.glibcVersionRuntime;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Resolve the bundled Claude Code binary for the current Linux libc.
|
|
26
|
+
*
|
|
27
|
+
* The SDK's own auto-detection (sdk.mjs `N7`) tries the musl package first
|
|
28
|
+
* and only falls back when require.resolve throws. Both packages are
|
|
29
|
+
* installed as optional deps, so it always picks musl — which fails to
|
|
30
|
+
* spawn on glibc systems with a misleading "binary not found" error.
|
|
31
|
+
*
|
|
32
|
+
* Returns undefined on non-Linux platforms (SDK detection works correctly
|
|
33
|
+
* there) or when the matching package isn't installed.
|
|
34
|
+
*/
|
|
35
|
+
export function resolveBundledClaudeBin() {
|
|
36
|
+
if (process.platform !== 'linux')
|
|
37
|
+
return undefined;
|
|
38
|
+
if (cachedBundled !== undefined)
|
|
39
|
+
return cachedBundled ?? undefined;
|
|
40
|
+
const variant = isMuslLibc() ? `linux-${process.arch}-musl` : `linux-${process.arch}`;
|
|
41
|
+
const pkg = `@anthropic-ai/claude-agent-sdk-${variant}/claude`;
|
|
42
|
+
try {
|
|
43
|
+
cachedBundled = require.resolve(pkg);
|
|
44
|
+
return cachedBundled;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
cachedBundled = null;
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The executable a given transport actually runs, so anything that inspects
|
|
53
|
+
* the CLI (its command list, its version) inspects the same build the user's
|
|
54
|
+
* turns go through. The two can be different installs at different versions:
|
|
55
|
+
* SDK mode prefers the binary bundled in node_modules, PTY mode spawns
|
|
56
|
+
* CLAUDE_BIN — the same precedence `/context` already follows.
|
|
57
|
+
*/
|
|
58
|
+
export function resolveClaudeExecutableForMethod(method) {
|
|
59
|
+
return method === 'pty'
|
|
60
|
+
? process.env.CLAUDE_BIN || config.CLAUDE_EXECUTABLE_PATH
|
|
61
|
+
: resolveActiveClaudeExecutable();
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=resolve-claude-bin.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Backoff policy for respawning a bot instance that exited unexpectedly.
|
|
3
|
+
*
|
|
4
|
+
* Kept separate from the launcher so it can be tested directly — the launcher
|
|
5
|
+
* spawns worker threads and reads config at import time, and this is the part
|
|
6
|
+
* that only ever runs when something has already gone wrong.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Decide whether a crashed instance gets another respawn, and how long to wait.
|
|
10
|
+
*
|
|
11
|
+
* Crashes only accumulate while they cluster. An instance that survived
|
|
12
|
+
* `streakResetMs` before dying is treated as a first crash again, so two
|
|
13
|
+
* unrelated failures days apart never add up to a give-up.
|
|
14
|
+
*/
|
|
15
|
+
export function planRespawn({ aliveMs, previousStreak, delays, streakResetMs, }) {
|
|
16
|
+
const streak = aliveMs >= streakResetMs ? 1 : previousStreak + 1;
|
|
17
|
+
return { streak, delayMs: delays[streak - 1] ?? null };
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=respawn-backoff.js.map
|