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,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Refuse to start on a Node.js older than 22.
|
|
3
|
+
*
|
|
4
|
+
* Imported first by every entry point, so it runs before the modules that
|
|
5
|
+
* would otherwise fail on an old runtime with an error that doesn't mention
|
|
6
|
+
* the version at all. It has no imports of its own for the same reason, and
|
|
7
|
+
* sticks to syntax and APIs every Node release still in use understands.
|
|
8
|
+
*
|
|
9
|
+
* Node 20 reached end of life in April 2026; 22 is the oldest line that still
|
|
10
|
+
* gets security fixes, and the one CI runs.
|
|
11
|
+
*/
|
|
12
|
+
export const MIN_NODE_MAJOR = 22;
|
|
13
|
+
/** The message to print for `version` (like "v20.11.1"), or undefined if it is new enough. */
|
|
14
|
+
export function nodeVersionProblem(version, minMajor = MIN_NODE_MAJOR) {
|
|
15
|
+
const major = parseInt(version.replace(/^v/, '').split('.')[0], 10);
|
|
16
|
+
if (Number.isFinite(major) && major >= minMajor)
|
|
17
|
+
return undefined;
|
|
18
|
+
return (`TeleCoder needs Node.js ${minMajor} or newer, and this is Node.js ${version}.\n` +
|
|
19
|
+
`Install Node.js ${minMajor} (https://nodejs.org, or e.g. \`nvm install ${minMajor}\`), ` +
|
|
20
|
+
'then run `npm install` again so native modules are rebuilt for it.');
|
|
21
|
+
}
|
|
22
|
+
const problem = nodeVersionProblem(process.version);
|
|
23
|
+
if (problem) {
|
|
24
|
+
console.error(`❌ ${problem}`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=node-version-check.js.map
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as os from 'os';
|
|
4
|
+
import { spawn } from 'child_process';
|
|
5
|
+
import { config } from '../config.js';
|
|
6
|
+
const CCR_PID_PATH = path.join(os.homedir(), '.claude-code-router', '.claude-code-router.pid');
|
|
7
|
+
const PROBE_TIMEOUT_MS = 1500;
|
|
8
|
+
const START_POLL_INTERVAL_MS = 250;
|
|
9
|
+
const START_TIMEOUT_MS = 8000;
|
|
10
|
+
export async function isCcrRunning(timeoutMs = PROBE_TIMEOUT_MS) {
|
|
11
|
+
try {
|
|
12
|
+
const url = `${config.CCR_BASE_URL.replace(/\/$/, '')}/api/config`;
|
|
13
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(timeoutMs) });
|
|
14
|
+
return res.ok;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function isPidAlive(pid) {
|
|
21
|
+
try {
|
|
22
|
+
process.kill(pid, 0);
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function clearStalePidfile() {
|
|
30
|
+
try {
|
|
31
|
+
if (!fs.existsSync(CCR_PID_PATH))
|
|
32
|
+
return;
|
|
33
|
+
const raw = fs.readFileSync(CCR_PID_PATH, 'utf-8').trim();
|
|
34
|
+
const pid = parseInt(raw, 10);
|
|
35
|
+
if (!Number.isFinite(pid) || !isPidAlive(pid)) {
|
|
36
|
+
fs.unlinkSync(CCR_PID_PATH);
|
|
37
|
+
console.log(`[CCR] Removed stale pidfile (pid ${raw} not running)`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
console.warn('[CCR] Failed to inspect pidfile:', err instanceof Error ? err.message : err);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function waitUntilUp(deadline) {
|
|
45
|
+
while (Date.now() < deadline) {
|
|
46
|
+
if (await isCcrRunning(800))
|
|
47
|
+
return true;
|
|
48
|
+
await new Promise((resolve) => setTimeout(resolve, START_POLL_INTERVAL_MS));
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
async function startCcrProcess() {
|
|
53
|
+
clearStalePidfile();
|
|
54
|
+
return new Promise((resolve) => {
|
|
55
|
+
let resolved = false;
|
|
56
|
+
const finish = (result) => {
|
|
57
|
+
if (!resolved) {
|
|
58
|
+
resolved = true;
|
|
59
|
+
resolve(result);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
try {
|
|
63
|
+
const child = spawn(config.CCR_BINARY, ['start'], {
|
|
64
|
+
detached: true,
|
|
65
|
+
stdio: 'ignore',
|
|
66
|
+
});
|
|
67
|
+
child.on('error', (err) => {
|
|
68
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
69
|
+
finish({ ok: false, message: `failed to spawn \`${config.CCR_BINARY} start\`: ${msg}` });
|
|
70
|
+
});
|
|
71
|
+
child.unref();
|
|
72
|
+
// Give spawn a brief moment to surface ENOENT before declaring success.
|
|
73
|
+
setTimeout(() => finish({ ok: true }), 100);
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
77
|
+
finish({ ok: false, message: `failed to spawn \`${config.CCR_BINARY} start\`: ${msg}` });
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Preflight check used by the CCR provider before each query.
|
|
83
|
+
*
|
|
84
|
+
* Strategy:
|
|
85
|
+
* - Probe the proxy. If up, return `ok` immediately.
|
|
86
|
+
* - If down and autostart is disabled, return `not_running` with a
|
|
87
|
+
* user-facing message telling them how to start CCR.
|
|
88
|
+
* - If down and autostart is enabled, attempt `ccr start`, poll until the
|
|
89
|
+
* proxy responds, and return `started` on success or `start_failed`
|
|
90
|
+
* with the underlying reason otherwise.
|
|
91
|
+
*/
|
|
92
|
+
export async function ensureCcrRunning() {
|
|
93
|
+
if (await isCcrRunning())
|
|
94
|
+
return { status: 'ok' };
|
|
95
|
+
if (!config.CCR_AUTOSTART) {
|
|
96
|
+
return {
|
|
97
|
+
status: 'not_running',
|
|
98
|
+
message: `CCR proxy isn't reachable at ${config.CCR_BASE_URL}. Start it with \`ccr start\`, or set \`CCR_AUTOSTART=true\` to let TeleCoder start it on demand.`,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
console.log('[CCR] Proxy unreachable — attempting autostart');
|
|
102
|
+
const spawnResult = await startCcrProcess();
|
|
103
|
+
if (!spawnResult.ok) {
|
|
104
|
+
return {
|
|
105
|
+
status: 'start_failed',
|
|
106
|
+
message: `CCR autostart failed: ${spawnResult.message}. Start it manually with \`ccr start\`.`,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
const up = await waitUntilUp(Date.now() + START_TIMEOUT_MS);
|
|
110
|
+
if (up) {
|
|
111
|
+
console.log('[CCR] Proxy is up after autostart');
|
|
112
|
+
return { status: 'started' };
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
status: 'start_failed',
|
|
116
|
+
message: `CCR autostart launched but the proxy didn't come up within ${Math.round(START_TIMEOUT_MS / 1000)}s. Check \`ccr status\` and \`~/.claude-code-router/logs/\`.`,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=ccr-health.js.map
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as os from 'os';
|
|
4
|
+
import { config } from '../config.js';
|
|
5
|
+
const CCR_LOG_DIR = path.join(os.homedir(), '.claude-code-router', 'logs');
|
|
6
|
+
// Read this many bytes from the tail of the latest CCR log. Plenty to
|
|
7
|
+
// contain at least one full response chunk (largest observed ~5KB) without
|
|
8
|
+
// having to slurp megabytes when the log grows.
|
|
9
|
+
const TAIL_BYTES = 32 * 1024;
|
|
10
|
+
let cachedLatestLog;
|
|
11
|
+
let cachedLatestLogMtime = 0;
|
|
12
|
+
function findLatestLog() {
|
|
13
|
+
if (!fs.existsSync(CCR_LOG_DIR))
|
|
14
|
+
return undefined;
|
|
15
|
+
let best;
|
|
16
|
+
for (const entry of fs.readdirSync(CCR_LOG_DIR)) {
|
|
17
|
+
if (!entry.endsWith('.log'))
|
|
18
|
+
continue;
|
|
19
|
+
const full = path.join(CCR_LOG_DIR, entry);
|
|
20
|
+
try {
|
|
21
|
+
const stat = fs.statSync(full);
|
|
22
|
+
if (!best || stat.mtimeMs > best.mtime) {
|
|
23
|
+
best = { name: full, mtime: stat.mtimeMs };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
// ignore unreadable entries
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return best?.name;
|
|
31
|
+
}
|
|
32
|
+
function readTail(filePath, bytes) {
|
|
33
|
+
const stat = fs.statSync(filePath);
|
|
34
|
+
const size = stat.size;
|
|
35
|
+
if (size === 0)
|
|
36
|
+
return '';
|
|
37
|
+
const start = Math.max(0, size - bytes);
|
|
38
|
+
const length = size - start;
|
|
39
|
+
const buf = Buffer.alloc(length);
|
|
40
|
+
const fd = fs.openSync(filePath, 'r');
|
|
41
|
+
try {
|
|
42
|
+
fs.readSync(fd, buf, 0, length, start);
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
fs.closeSync(fd);
|
|
46
|
+
}
|
|
47
|
+
return buf.toString('utf-8');
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Best-effort: scan the most recent CCR log for the actual provider+model
|
|
51
|
+
* that served the last response. Returns undefined if no CCR log exists or
|
|
52
|
+
* no usable entry is found.
|
|
53
|
+
*
|
|
54
|
+
* Caveat: in a multi-user/multi-client setup the most recent log entry may
|
|
55
|
+
* not belong to the caller. For TeleCoder's single-user case it's fine.
|
|
56
|
+
*/
|
|
57
|
+
function getLastCcrRouteFromLog() {
|
|
58
|
+
try {
|
|
59
|
+
const latest = findLatestLog();
|
|
60
|
+
if (!latest)
|
|
61
|
+
return undefined;
|
|
62
|
+
// Quick mtime check — if the file hasn't changed since last call we
|
|
63
|
+
// could skip work, but we want freshness here, so always re-read tail.
|
|
64
|
+
const stat = fs.statSync(latest);
|
|
65
|
+
cachedLatestLog = latest;
|
|
66
|
+
cachedLatestLogMtime = stat.mtimeMs;
|
|
67
|
+
const tail = readTail(latest, TAIL_BYTES);
|
|
68
|
+
const lines = tail.split('\n');
|
|
69
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
70
|
+
const line = lines[i];
|
|
71
|
+
if (!line || !line.includes('"provider"'))
|
|
72
|
+
continue;
|
|
73
|
+
try {
|
|
74
|
+
const obj = JSON.parse(line);
|
|
75
|
+
const resp = obj?.response;
|
|
76
|
+
if (resp && typeof resp.provider === 'string' && typeof resp.model === 'string') {
|
|
77
|
+
return { provider: resp.provider, model: resp.model };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
// Tail can start mid-line; skip malformed entries.
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
console.debug('[CCR] log introspection failed:', err instanceof Error ? err.message : err);
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const CONFIG_TTL_MS = 60_000;
|
|
92
|
+
let cachedCcrConfig;
|
|
93
|
+
async function fetchCcrConfig() {
|
|
94
|
+
if (cachedCcrConfig && Date.now() - cachedCcrConfig.fetchedAt < CONFIG_TTL_MS) {
|
|
95
|
+
return cachedCcrConfig.router;
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const url = `${config.CCR_BASE_URL.replace(/\/$/, '')}/api/config`;
|
|
99
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(2000) });
|
|
100
|
+
if (!res.ok) {
|
|
101
|
+
cachedCcrConfig = { router: undefined, fetchedAt: Date.now() };
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
const data = (await res.json());
|
|
105
|
+
cachedCcrConfig = { router: data.Router, fetchedAt: Date.now() };
|
|
106
|
+
return data.Router;
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
cachedCcrConfig = { router: undefined, fetchedAt: Date.now() };
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function parseRoute(spec) {
|
|
114
|
+
if (!spec || !spec.includes(','))
|
|
115
|
+
return undefined;
|
|
116
|
+
const idx = spec.indexOf(',');
|
|
117
|
+
const provider = spec.substring(0, idx).trim();
|
|
118
|
+
const model = spec.substring(idx + 1).trim();
|
|
119
|
+
if (!provider || !model)
|
|
120
|
+
return undefined;
|
|
121
|
+
return { provider, model };
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Resolve which provider+model CCR routed the last response to.
|
|
125
|
+
*
|
|
126
|
+
* Strategy:
|
|
127
|
+
* 1. Read CCR's log tail (authoritative — what *actually* served).
|
|
128
|
+
* 2. Fall back to CCR's `/api/config` `Router.default` (a prediction —
|
|
129
|
+
* what would serve a typical chat turn, accurate for most cases).
|
|
130
|
+
*
|
|
131
|
+
* Returns undefined when neither source is available (CCR down, logs off,
|
|
132
|
+
* unreachable proxy). Callers should treat undefined as "show CCR tag but
|
|
133
|
+
* keep the SDK alias as the model name".
|
|
134
|
+
*/
|
|
135
|
+
export async function getCcrRoute() {
|
|
136
|
+
const fromLog = getLastCcrRouteFromLog();
|
|
137
|
+
if (fromLog)
|
|
138
|
+
return { ...fromLog, source: 'log' };
|
|
139
|
+
const router = await fetchCcrConfig();
|
|
140
|
+
const fromConfig = parseRoute(router?.default);
|
|
141
|
+
if (fromConfig)
|
|
142
|
+
return { ...fromConfig, source: 'config' };
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
/** Convenience: synchronous log-only check (no /api/config fallback). */
|
|
146
|
+
export function getLastCcrRoute() {
|
|
147
|
+
return getLastCcrRouteFromLog();
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=ccr-introspect.js.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { sendToAgent as claudeSendToAgent, sendLoopToAgent as claudeSendLoopToAgent, clearConversation as claudeClearConversation, setModel as claudeSetModel, getModel as claudeGetModel, clearModel as claudeClearModel, getCachedUsage as claudeGetCachedUsage, isDangerousMode as claudeIsDangerousMode, } from '../claude/agent.js';
|
|
2
|
+
import { getCcrShimPath } from '../claude/ccr-shim.js';
|
|
3
|
+
import { ensureCcrRunning } from './ccr-health.js';
|
|
4
|
+
// CCR's router config decides the actual backend model per request — the
|
|
5
|
+
// SDK-level model name is largely advisory. Deliberately just the three tiers
|
|
6
|
+
// CCR configs actually route on, rather than the Claude provider's full alias
|
|
7
|
+
// list: aliases like `opusplan` or `fable[1m]` mean nothing to a router whose
|
|
8
|
+
// rules key off opus/sonnet/haiku.
|
|
9
|
+
const CCR_MODELS = [
|
|
10
|
+
{ id: 'opus', label: 'opus', description: 'Routed via CCR' },
|
|
11
|
+
{ id: 'sonnet', label: 'sonnet', description: 'Routed via CCR' },
|
|
12
|
+
{ id: 'haiku', label: 'haiku', description: 'Routed via CCR' },
|
|
13
|
+
];
|
|
14
|
+
function withShim(options) {
|
|
15
|
+
const shim = getCcrShimPath();
|
|
16
|
+
return { ...(options ?? {}), executableOverride: shim };
|
|
17
|
+
}
|
|
18
|
+
async function preflightOrFailure() {
|
|
19
|
+
const result = await ensureCcrRunning();
|
|
20
|
+
if (result.status === 'ok' || result.status === 'started')
|
|
21
|
+
return undefined;
|
|
22
|
+
return { text: `⚠️ ${result.message}`, toolsUsed: [] };
|
|
23
|
+
}
|
|
24
|
+
export const ccrProvider = {
|
|
25
|
+
name: 'ccr',
|
|
26
|
+
async sendToAgent(sessionKey, message, options) {
|
|
27
|
+
const failure = await preflightOrFailure();
|
|
28
|
+
if (failure)
|
|
29
|
+
return failure;
|
|
30
|
+
return claudeSendToAgent(sessionKey, message, withShim(options));
|
|
31
|
+
},
|
|
32
|
+
async sendLoopToAgent(sessionKey, message, options) {
|
|
33
|
+
const failure = await preflightOrFailure();
|
|
34
|
+
if (failure)
|
|
35
|
+
return failure;
|
|
36
|
+
return claudeSendLoopToAgent(sessionKey, message, withShim(options));
|
|
37
|
+
},
|
|
38
|
+
clearConversation(sessionKey) {
|
|
39
|
+
claudeClearConversation(sessionKey);
|
|
40
|
+
},
|
|
41
|
+
setModel(scope, model) {
|
|
42
|
+
claudeSetModel(scope, model);
|
|
43
|
+
},
|
|
44
|
+
getModel(scope) {
|
|
45
|
+
return claudeGetModel(scope);
|
|
46
|
+
},
|
|
47
|
+
clearModel(scope) {
|
|
48
|
+
claudeClearModel(scope);
|
|
49
|
+
},
|
|
50
|
+
getCachedUsage(sessionKey) {
|
|
51
|
+
return claudeGetCachedUsage(sessionKey);
|
|
52
|
+
},
|
|
53
|
+
isDangerousMode() {
|
|
54
|
+
return claudeIsDangerousMode();
|
|
55
|
+
},
|
|
56
|
+
async getAvailableModels() {
|
|
57
|
+
return CCR_MODELS;
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=ccr-provider.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { userPreferences } from './user-preferences.js';
|
|
2
|
+
import { sdkProvider } from './sdk-provider.js';
|
|
3
|
+
import { PtyProvider } from '../claude/pty-provider.js';
|
|
4
|
+
import { config } from '../config.js';
|
|
5
|
+
// Instantiate both providers. The router will decide which one to use.
|
|
6
|
+
const ptyProvider = new PtyProvider();
|
|
7
|
+
export function getPtyProvider() {
|
|
8
|
+
return ptyProvider;
|
|
9
|
+
}
|
|
10
|
+
function getMethod(scope) {
|
|
11
|
+
// The thread's or chat's /method wins; CLAUDE_METHOD_DEFAULT decides for one
|
|
12
|
+
// that has never picked one. The permission gate runs on both.
|
|
13
|
+
return userPreferences.getMethod(scope) || config.CLAUDE_METHOD_DEFAULT;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Which transport this chat's turns run through. Exported for the handlers
|
|
17
|
+
* that need to match the transport's behaviour without routing a turn — e.g.
|
|
18
|
+
* inspecting the CLI build that would actually serve the chat.
|
|
19
|
+
*/
|
|
20
|
+
export function getActiveMethod(scope) {
|
|
21
|
+
return getMethod(scope);
|
|
22
|
+
}
|
|
23
|
+
function getInternalProvider(scope) {
|
|
24
|
+
const method = getMethod(scope);
|
|
25
|
+
if (method === 'pty') {
|
|
26
|
+
return ptyProvider;
|
|
27
|
+
}
|
|
28
|
+
return sdkProvider;
|
|
29
|
+
}
|
|
30
|
+
// This new claudeProvider is a router that delegates to either the
|
|
31
|
+
// SDK or PTY provider based on user preference.
|
|
32
|
+
export const claudeProvider = {
|
|
33
|
+
name: 'claude',
|
|
34
|
+
sendToAgent(sessionKey, message, options) {
|
|
35
|
+
return getInternalProvider(sessionKey).sendToAgent(sessionKey, message, options);
|
|
36
|
+
},
|
|
37
|
+
sendLoopToAgent(sessionKey, message, options) {
|
|
38
|
+
return getInternalProvider(sessionKey).sendLoopToAgent(sessionKey, message, options);
|
|
39
|
+
},
|
|
40
|
+
clearConversation(sessionKey) {
|
|
41
|
+
getInternalProvider(sessionKey).clearConversation(sessionKey);
|
|
42
|
+
},
|
|
43
|
+
setModel(scope, model) {
|
|
44
|
+
getInternalProvider(scope).setModel(scope, model);
|
|
45
|
+
},
|
|
46
|
+
getModel(scope) {
|
|
47
|
+
return getInternalProvider(scope).getModel(scope);
|
|
48
|
+
},
|
|
49
|
+
clearModel(scope) {
|
|
50
|
+
getInternalProvider(scope).clearModel(scope);
|
|
51
|
+
},
|
|
52
|
+
getCachedUsage(sessionKey) {
|
|
53
|
+
return getInternalProvider(sessionKey).getCachedUsage(sessionKey);
|
|
54
|
+
},
|
|
55
|
+
isDangerousMode() {
|
|
56
|
+
// This is consistent across both methods.
|
|
57
|
+
return sdkProvider.isDangerousMode();
|
|
58
|
+
},
|
|
59
|
+
async getAvailableModels(scope) {
|
|
60
|
+
return getInternalProvider(scope).getAvailableModels(scope);
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=claude-provider.js.map
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applying one chat's model or effort choice to every bot instance at once.
|
|
3
|
+
*
|
|
4
|
+
* Preferences are per-bot (see user-preferences.ts), which is the right default
|
|
5
|
+
* — but "put all my bots on Haiku" is a real thing to want, and writing to the
|
|
6
|
+
* siblings' files behind their backs would not work: every worker holds its
|
|
7
|
+
* preferences in memory and would overwrite the edit on its next save, and the
|
|
8
|
+
* pty reads `--model` at spawn, so a bot with a live session would go on using
|
|
9
|
+
* the old one regardless.
|
|
10
|
+
*
|
|
11
|
+
* So the change is sent, not written. The requesting worker asks the launcher
|
|
12
|
+
* to relay it; each sibling applies it through the same code path as a local
|
|
13
|
+
* /model, tears down the pty sessions for that chat so the next turn respawns
|
|
14
|
+
* with the new flag, and reports back what it did. The requester waits for the
|
|
15
|
+
* round trip so it can tell the user which bots actually took the change.
|
|
16
|
+
*
|
|
17
|
+
* Single-instance mode has no launcher to relay through: every function here
|
|
18
|
+
* degrades to "this bot only" rather than failing.
|
|
19
|
+
*/
|
|
20
|
+
import { isMainThread, parentPort } from 'worker_threads';
|
|
21
|
+
import { BOT_ID } from '../config.js';
|
|
22
|
+
import { isInFlight } from '../claude/in-flight-tracker.js';
|
|
23
|
+
import { listSiblingBots } from '../utils/instances.js';
|
|
24
|
+
import { getPtyProvider } from './claude-provider.js';
|
|
25
|
+
import { setModel, clearModel, setEffort, clearEffort, getActiveProviderName, isValidEffortLevel, } from './provider-router.js';
|
|
26
|
+
import { userPreferences } from './user-preferences.js';
|
|
27
|
+
/** Bots other than this one, from instances.json. Empty in single-bot setups. */
|
|
28
|
+
export function siblingBotNames() {
|
|
29
|
+
if (isMainThread)
|
|
30
|
+
return [];
|
|
31
|
+
return listSiblingBots(BOT_ID).map((b) => b.name);
|
|
32
|
+
}
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// Applying a change locally (the receiving side)
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
/**
|
|
37
|
+
* Apply a relayed change to this instance.
|
|
38
|
+
*
|
|
39
|
+
* Goes through provider-router rather than the preferences file directly, so
|
|
40
|
+
* the in-memory caches that actually serve the next turn are updated too.
|
|
41
|
+
*
|
|
42
|
+
* A pty holding a session that is mid-turn is left alone: killing it would
|
|
43
|
+
* abort a turn nobody in this chat asked to interrupt, and the user isn't
|
|
44
|
+
* watching that bot — they're in the one they typed the command into. Those
|
|
45
|
+
* sessions keep the old value until they next respawn, and the count comes
|
|
46
|
+
* back so the confirmation can say so.
|
|
47
|
+
*/
|
|
48
|
+
export function applyPrefsChange(change) {
|
|
49
|
+
const { chatId } = change;
|
|
50
|
+
const active = getActiveProviderName(chatId);
|
|
51
|
+
if (active !== change.provider) {
|
|
52
|
+
return { name: '', status: 'skipped', reason: `on ${active}, not ${change.provider}` };
|
|
53
|
+
}
|
|
54
|
+
if (change.setting === 'model') {
|
|
55
|
+
if (change.value === null)
|
|
56
|
+
clearModel(chatId);
|
|
57
|
+
else
|
|
58
|
+
setModel(chatId, change.value);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
if (change.value === null) {
|
|
62
|
+
clearEffort(chatId);
|
|
63
|
+
}
|
|
64
|
+
else if (isValidEffortLevel(change.value)) {
|
|
65
|
+
setEffort(chatId, change.value);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
return { name: '', status: 'skipped', reason: `unknown effort level "${change.value}"` };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return { name: '', status: 'applied', busy: restartPtySessionsForChat(chatId) };
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Tear down this chat's idle pty sessions so the next turn respawns with the
|
|
75
|
+
* new flag. Returns how many were left running because they were mid-turn.
|
|
76
|
+
* Only sessions that actually run on the pty transport count; with threads,
|
|
77
|
+
* that is decided per thread, since each can have picked its own.
|
|
78
|
+
*/
|
|
79
|
+
function restartPtySessionsForChat(chatId) {
|
|
80
|
+
const pty = getPtyProvider();
|
|
81
|
+
let busy = 0;
|
|
82
|
+
for (const sessionKey of pty.listSessionKeysForChat(chatId)) {
|
|
83
|
+
if (getActiveProviderName(sessionKey) !== 'claude')
|
|
84
|
+
continue;
|
|
85
|
+
if (userPreferences.getMethod(sessionKey) !== 'pty')
|
|
86
|
+
continue;
|
|
87
|
+
if (isInFlight(sessionKey)) {
|
|
88
|
+
busy++;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
pty.clearConversation(sessionKey);
|
|
92
|
+
}
|
|
93
|
+
return busy;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Listen for changes relayed from sibling bots. Called once at startup; a
|
|
97
|
+
* no-op outside multi-instance mode, where nothing can relay to us.
|
|
98
|
+
*/
|
|
99
|
+
export function initPrefsSync() {
|
|
100
|
+
if (isMainThread || !parentPort)
|
|
101
|
+
return;
|
|
102
|
+
const pp = parentPort;
|
|
103
|
+
pp.on('message', (msg) => {
|
|
104
|
+
if (msg?.type !== 'prefs_apply' || !msg.change || !msg.requestId)
|
|
105
|
+
return;
|
|
106
|
+
let outcome;
|
|
107
|
+
try {
|
|
108
|
+
outcome = applyPrefsChange(msg.change);
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
outcome = {
|
|
112
|
+
name: '',
|
|
113
|
+
status: 'skipped',
|
|
114
|
+
reason: err instanceof Error ? err.message : 'failed to apply',
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const { setting, value } = msg.change;
|
|
118
|
+
console.log(`[PrefsSync] ${outcome.status} relayed ${setting}=${value ?? 'default'} for chat ${msg.change.chatId}${outcome.reason ? ` (${outcome.reason})` : ''}`);
|
|
119
|
+
pp.postMessage({ type: 'prefs_apply_result', requestId: msg.requestId, ...outcome });
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
let requestCounter = 0;
|
|
123
|
+
/**
|
|
124
|
+
* How long to wait for the launcher's aggregate reply. Each sibling's work is
|
|
125
|
+
* a couple of synchronous file writes plus a pty kill, so the only thing this
|
|
126
|
+
* really covers is a worker too busy to service its message queue — and one
|
|
127
|
+
* that unresponsive is better reported as unreachable than waited on.
|
|
128
|
+
*/
|
|
129
|
+
const BROADCAST_TIMEOUT_MS = 5000;
|
|
130
|
+
/**
|
|
131
|
+
* Ask every other instance to apply `change`. Resolves once they have all
|
|
132
|
+
* answered, or on timeout with whatever came back by then.
|
|
133
|
+
*/
|
|
134
|
+
export function broadcastPrefsChange(change) {
|
|
135
|
+
return new Promise((resolve) => {
|
|
136
|
+
if (isMainThread || !parentPort) {
|
|
137
|
+
resolve({ applied: [], skipped: [], unreachable: [], multiInstance: false });
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const pp = parentPort;
|
|
141
|
+
const requestId = `${BOT_ID}-${++requestCounter}`;
|
|
142
|
+
const handler = (msg) => {
|
|
143
|
+
if (msg?.type !== 'prefs_broadcast_result' || msg.requestId !== requestId)
|
|
144
|
+
return;
|
|
145
|
+
pp.off('message', handler);
|
|
146
|
+
clearTimeout(timer);
|
|
147
|
+
resolve({
|
|
148
|
+
applied: msg.applied ?? [],
|
|
149
|
+
skipped: msg.skipped ?? [],
|
|
150
|
+
unreachable: msg.unreachable ?? [],
|
|
151
|
+
multiInstance: true,
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
pp.on('message', handler);
|
|
155
|
+
pp.postMessage({ type: 'prefs_broadcast', requestId, change });
|
|
156
|
+
const timer = setTimeout(() => {
|
|
157
|
+
pp.off('message', handler);
|
|
158
|
+
// A launcher too old to know this message type never answers at all.
|
|
159
|
+
console.warn('[PrefsSync] Launcher did not answer the preference broadcast — is it running current code?');
|
|
160
|
+
resolve({ applied: [], skipped: [], unreachable: [], multiInstance: true, timedOut: true });
|
|
161
|
+
}, BROADCAST_TIMEOUT_MS);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=prefs-sync.js.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { ensureStateDir, getStateDir, readJsonFile, writeJsonFile } from '../utils/json-store.js';
|
|
5
|
+
const favoriteSchema = z.object({
|
|
6
|
+
path: z.string(),
|
|
7
|
+
addedAt: z.string(),
|
|
8
|
+
});
|
|
9
|
+
const favoritesDataSchema = z.object({
|
|
10
|
+
sessions: z.record(z.string(), z.array(favoriteSchema)),
|
|
11
|
+
});
|
|
12
|
+
const FAVORITES_DIR = getStateDir();
|
|
13
|
+
const FAVORITES_FILE = path.join(FAVORITES_DIR, 'project-favorites.json');
|
|
14
|
+
/**
|
|
15
|
+
* One list per chat, shared by every bot: the same person moves their bots across
|
|
16
|
+
* the same projects. Each bot is its own process, so the file is the only copy
|
|
17
|
+
* that counts, and it's read before every use. A bot saving from what it loaded
|
|
18
|
+
* earlier would put back whatever the others had changed since.
|
|
19
|
+
*
|
|
20
|
+
* Saves aren't locked against each other. They only happen on a button tap, so
|
|
21
|
+
* two landing in the same instant isn't worth guarding, and at worst loses a tap.
|
|
22
|
+
*/
|
|
23
|
+
class ProjectFavoritesManager {
|
|
24
|
+
data = {};
|
|
25
|
+
constructor() {
|
|
26
|
+
ensureStateDir(FAVORITES_DIR, 'ProjectFavorites');
|
|
27
|
+
}
|
|
28
|
+
refresh() {
|
|
29
|
+
if (!fs.existsSync(FAVORITES_FILE)) {
|
|
30
|
+
this.data = {};
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
// A file that's there but can't be read isn't an empty one: keep what we last
|
|
34
|
+
// read, or the next save would wipe every chat's favorites.
|
|
35
|
+
const loaded = readJsonFile(FAVORITES_FILE, favoritesDataSchema, 'ProjectFavorites');
|
|
36
|
+
if (loaded)
|
|
37
|
+
this.data = loaded.sessions;
|
|
38
|
+
}
|
|
39
|
+
save() {
|
|
40
|
+
writeJsonFile(FAVORITES_FILE, { sessions: this.data }, 'ProjectFavorites');
|
|
41
|
+
}
|
|
42
|
+
list(sessionKey) {
|
|
43
|
+
this.refresh();
|
|
44
|
+
return this.data[sessionKey] ?? [];
|
|
45
|
+
}
|
|
46
|
+
has(sessionKey, projectPath) {
|
|
47
|
+
const normalized = path.resolve(projectPath);
|
|
48
|
+
return this.list(sessionKey).some((f) => f.path === normalized);
|
|
49
|
+
}
|
|
50
|
+
add(sessionKey, projectPath) {
|
|
51
|
+
this.refresh();
|
|
52
|
+
const normalized = path.resolve(projectPath);
|
|
53
|
+
const existing = this.data[sessionKey] ?? [];
|
|
54
|
+
if (existing.some((f) => f.path === normalized))
|
|
55
|
+
return false;
|
|
56
|
+
existing.push({ path: normalized, addedAt: new Date().toISOString() });
|
|
57
|
+
this.data[sessionKey] = existing;
|
|
58
|
+
this.save();
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
remove(sessionKey, projectPath) {
|
|
62
|
+
this.refresh();
|
|
63
|
+
const normalized = path.resolve(projectPath);
|
|
64
|
+
const existing = this.data[sessionKey] ?? [];
|
|
65
|
+
const filtered = existing.filter((f) => f.path !== normalized);
|
|
66
|
+
if (filtered.length === existing.length)
|
|
67
|
+
return false;
|
|
68
|
+
this.data[sessionKey] = filtered;
|
|
69
|
+
this.save();
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export const projectFavorites = new ProjectFavoritesManager();
|
|
74
|
+
//# sourceMappingURL=project-favorites.js.map
|