@cortex-agent/server 2026.10.15 → 2026.10.21
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/README.md +76 -50
- package/defaults/board/board.css +140 -62
- package/defaults/board/scaffold.html +36 -13
- package/defaults/config/environments/creative.json +0 -1
- package/defaults/config/environments/main.json +1 -2
- package/defaults/plugins/cortex-board/skills/board/SKILL.md +30 -22
- package/defaults/plugins/cortex-system/plugin.json +2 -2
- package/defaults/plugins/cortex-system/skills/browser/SKILL.md +56 -0
- package/dist/agent-adapter/claude/adapter.d.ts +2 -5
- package/dist/agent-adapter/claude/adapter.js +6 -5
- package/dist/agent-adapter/claude/assistant-blocks.d.ts +5 -0
- package/dist/agent-adapter/claude/assistant-blocks.js +61 -0
- package/dist/agent-adapter/claude/cache-refresh.d.ts +58 -0
- package/dist/agent-adapter/claude/cache-refresh.js +145 -0
- package/dist/agent-adapter/claude/cache-touch.d.ts +12 -0
- package/dist/agent-adapter/claude/cache-touch.js +75 -0
- package/dist/agent-adapter/claude/event-parser.d.ts +8 -3
- package/dist/agent-adapter/claude/event-parser.js +33 -17
- package/dist/agent-adapter/claude/event-translator.d.ts +2 -0
- package/dist/agent-adapter/claude/event-translator.js +2 -0
- package/dist/agent-adapter/claude/session-options.d.ts +6 -13
- package/dist/agent-adapter/claude/session-options.js +2 -13
- package/dist/agent-adapter/claude/spawn-args.d.ts +4 -21
- package/dist/agent-adapter/claude/spawn-args.js +17 -24
- package/dist/agent-adapter/claude/transcript-clear.d.ts +42 -0
- package/dist/agent-adapter/claude/transcript-clear.js +217 -0
- package/dist/agent-adapter/claude/turn-machine.d.ts +3 -2
- package/dist/agent-adapter/claude/turn-machine.js +21 -68
- package/dist/agent-adapter/claude/window-warmup.d.ts +13 -0
- package/dist/agent-adapter/claude/window-warmup.js +38 -0
- package/dist/agent-adapter/continuation-phase.js +3 -0
- package/dist/agent-adapter/normalize/event-types.d.ts +8 -0
- package/dist/agent-adapter/pi/adapter.d.ts +0 -1
- package/dist/agent-adapter/pi/adapter.js +5 -13
- package/dist/agent-adapter/pi/event-parser.d.ts +1 -1
- package/dist/agent-adapter/pi/event-parser.js +43 -27
- package/dist/agent-adapter/pi/mcp-bridge.d.ts +1 -1
- package/dist/agent-adapter/pi/pi-session.d.ts +2 -0
- package/dist/agent-adapter/pi/pi-session.js +15 -0
- package/dist/agent-adapter/pi/providers-config.d.ts +2 -2
- package/dist/agent-adapter/pi/providers-config.js +1 -1
- package/dist/agent-adapter/pi/quota-sink.d.ts +3 -3
- package/dist/agent-adapter/pi/quota-sink.js +3 -3
- package/dist/agent-adapter/pi/runtime.js +6 -1
- package/dist/agent-adapter/pi/session-options.d.ts +9 -13
- package/dist/agent-adapter/pi/session-options.js +12 -25
- package/dist/agent-adapter/run-events.d.ts +11 -10
- package/dist/agent-adapter/run-events.js +2 -0
- package/dist/agent-adapter/types.d.ts +5 -4
- package/dist/client-bundle/manifest.json +2 -2
- package/dist/core/codex-quota.d.ts +1 -1
- package/dist/core/codex-quota.js +1 -1
- package/dist/core/gateway-generator.d.ts +9 -11
- package/dist/core/gateway-generator.js +31 -58
- package/dist/core/locales/en.d.ts +51 -77
- package/dist/core/locales/slices/commands.d.ts +26 -31
- package/dist/core/locales/slices/commands.js +54 -64
- package/dist/core/locales/slices/init.d.ts +8 -19
- package/dist/core/locales/slices/init.js +17 -53
- package/dist/core/locales/slices/interactions.d.ts +3 -3
- package/dist/core/locales/slices/interactions.js +6 -6
- package/dist/core/locales/slices/notices.d.ts +1 -3
- package/dist/core/locales/slices/notices.js +2 -6
- package/dist/core/locales/slices/scheduling.d.ts +9 -9
- package/dist/core/locales/slices/scheduling.js +18 -18
- package/dist/core/locales/slices/status.d.ts +0 -4
- package/dist/core/locales/slices/status.js +0 -8
- package/dist/core/locales/slices/tui.d.ts +0 -1
- package/dist/core/locales/slices/tui.js +0 -2
- package/dist/core/locales/slices/uimsg.d.ts +4 -7
- package/dist/core/locales/slices/uimsg.js +9 -15
- package/dist/core/models-generator.d.ts +29 -0
- package/dist/core/models-generator.js +82 -0
- package/dist/core/paths.d.ts +1 -1
- package/dist/core/paths.js +1 -1
- package/dist/core/settings-spec.d.ts +25 -0
- package/dist/core/settings-spec.js +34 -0
- package/dist/core/status-format.d.ts +3 -2
- package/dist/core/status-format.js +2 -2
- package/dist/core/types/environment-types.d.ts +0 -2
- package/dist/domain/agents/agent-state.d.ts +11 -56
- package/dist/domain/agents/agent-state.js +48 -115
- package/dist/domain/agents/agent-switch.d.ts +2 -24
- package/dist/domain/agents/agent-switch.js +9 -72
- package/dist/domain/agents/config.d.ts +11 -61
- package/dist/domain/agents/config.js +47 -154
- package/dist/domain/agents/engine-selection.d.ts +21 -0
- package/dist/domain/agents/engine-selection.js +37 -0
- package/dist/domain/agents/environments/registry.js +2 -1
- package/dist/domain/agents/environments/resolve.js +0 -1
- package/dist/domain/agents/environments/schema.d.ts +0 -1
- package/dist/domain/agents/environments/schema.js +0 -1
- package/dist/domain/agents/index.d.ts +2 -1
- package/dist/domain/agents/index.js +3 -7
- package/dist/domain/agents/model-selection.d.ts +18 -70
- package/dist/domain/agents/model-selection.js +100 -150
- package/dist/domain/agents/models.d.ts +12 -0
- package/dist/domain/agents/models.js +94 -0
- package/dist/domain/agents/subagent/registry.d.ts +2 -0
- package/dist/domain/agents/subagent/registry.js +8 -0
- package/dist/domain/agents/subagent/runner.d.ts +5 -5
- package/dist/domain/agents/subagent/runner.js +12 -35
- package/dist/domain/auth/auth-status.d.ts +4 -4
- package/dist/domain/auth/auth-status.js +17 -28
- package/dist/domain/auth/gateway-sync.d.ts +6 -26
- package/dist/domain/auth/gateway-sync.js +31 -75
- package/dist/domain/benchmark/identity.d.ts +3 -5
- package/dist/domain/benchmark/identity.js +0 -1
- package/dist/domain/benchmark/production-attempt-identity.d.ts +6 -5
- package/dist/domain/benchmark/production-attempt-identity.js +32 -35
- package/dist/domain/benchmark/session-evidence.d.ts +2 -1
- package/dist/domain/benchmark/session-evidence.js +8 -1
- package/dist/domain/browser/broker.d.ts +99 -0
- package/dist/domain/browser/broker.js +487 -0
- package/dist/domain/costs/claude-account.js +21 -0
- package/dist/domain/costs/rate-limit-throttle.js +3 -1
- package/dist/domain/costs/reset-account.d.ts +2 -0
- package/dist/domain/costs/usage-service.d.ts +1 -1
- package/dist/domain/costs/usage-service.js +20 -7
- package/dist/domain/mcp/tools/context.d.ts +5 -6
- package/dist/domain/mcp/tools/context.js +17 -3
- package/dist/domain/mcp/tools/subagent.js +1 -1
- package/dist/domain/mcp/tools/ui-file.js +1 -1
- package/dist/domain/pi-providers/custom-provider-model.d.ts +1 -1
- package/dist/domain/pi-providers/custom-provider-model.js +1 -1
- package/dist/domain/remote/device-browser.js +1 -1
- package/dist/domain/remote/device-chrome-commands.js +2 -0
- package/dist/domain/remote/device-port.js +2 -2
- package/dist/domain/runs/attempt.d.ts +3 -3
- package/dist/domain/runs/attempt.js +2 -3
- package/dist/domain/runs/builders.d.ts +4 -4
- package/dist/domain/runs/builders.js +4 -5
- package/dist/domain/runs/compact.d.ts +4 -17
- package/dist/domain/runs/compact.js +14 -56
- package/dist/domain/runs/config-resolver.d.ts +15 -83
- package/dist/domain/runs/config-resolver.js +24 -150
- package/dist/domain/runs/engine-spec.d.ts +8 -8
- package/dist/domain/runs/engine-spec.js +15 -31
- package/dist/domain/runs/events.d.ts +1 -1
- package/dist/domain/runs/fallback.d.ts +6 -38
- package/dist/domain/runs/fallback.js +10 -72
- package/dist/domain/runs/notices.d.ts +1 -11
- package/dist/domain/runs/notices.js +3 -30
- package/dist/domain/runs/request.d.ts +4 -3
- package/dist/domain/runs/retryable-errors.d.ts +0 -13
- package/dist/domain/runs/retryable-errors.js +0 -17
- package/dist/domain/runs/run.d.ts +12 -42
- package/dist/domain/runs/run.js +40 -147
- package/dist/domain/runs/service.d.ts +1 -1
- package/dist/domain/runs/service.js +8 -3
- package/dist/domain/runs/spec-loader.d.ts +1 -1
- package/dist/domain/runs/spend.d.ts +1 -1
- package/dist/domain/runs/spend.js +1 -1
- package/dist/domain/scheduling/jobs/scheduled-task.d.ts +3 -2
- package/dist/domain/scheduling/jobs/scheduled-task.js +25 -19
- package/dist/domain/scheduling/schedule-ops.d.ts +0 -1
- package/dist/domain/scheduling/schedule-ops.js +2 -5
- package/dist/domain/scheduling/schedule-selection.d.ts +3 -0
- package/dist/domain/scheduling/schedule-selection.js +16 -0
- package/dist/domain/scheduling/schedule-spec.d.ts +6 -5
- package/dist/domain/scheduling/schedule-spec.js +6 -6
- package/dist/domain/scheduling/scheduler.d.ts +3 -1
- package/dist/domain/scheduling/scheduler.js +22 -21
- package/dist/domain/sessions/session-hooks.d.ts +5 -4
- package/dist/domain/sessions/session-hooks.js +15 -33
- package/dist/domain/sessions/session-lifecycle.d.ts +19 -51
- package/dist/domain/sessions/session-lifecycle.js +34 -96
- package/dist/domain/system/doctor.d.ts +3 -3
- package/dist/domain/system/doctor.js +22 -26
- package/dist/domain/system/own-bin-path.d.ts +13 -0
- package/dist/domain/system/own-bin-path.js +36 -0
- package/dist/domain/system/terminal-cli/index.d.ts +58 -0
- package/dist/domain/system/terminal-cli/index.js +100 -0
- package/dist/domain/system/terminal-cli/posix-profiles.d.ts +23 -0
- package/dist/domain/system/terminal-cli/posix-profiles.js +74 -0
- package/dist/domain/system/terminal-cli/registrar.d.ts +12 -0
- package/dist/domain/system/terminal-cli/registrar.js +1 -0
- package/dist/domain/system/terminal-cli/shims.d.ts +27 -0
- package/dist/domain/system/terminal-cli/shims.js +108 -0
- package/dist/domain/system/terminal-cli/state.d.ts +7 -0
- package/dist/domain/system/terminal-cli/state.js +36 -0
- package/dist/domain/system/terminal-cli/windows-user-path.d.ts +13 -0
- package/dist/domain/system/terminal-cli/windows-user-path.js +67 -0
- package/dist/domain/tui-session/tui-session-service.js +1 -1
- package/dist/domain/tui-session/types.d.ts +2 -2
- package/dist/domain/ui-service/app-router.d.ts +49 -71
- package/dist/domain/ui-service/app-router.js +9 -13
- package/dist/domain/ui-service/assistant-snapshots.js +2 -0
- package/dist/domain/ui-service/contract.parity.d.ts +19 -0
- package/dist/domain/ui-service/contract.parity.js +1 -0
- package/dist/domain/ui-service/inline-media-types.d.ts +18 -0
- package/dist/domain/ui-service/inline-media-types.js +1 -0
- package/dist/domain/ui-service/input-schemas.d.ts +52 -115
- package/dist/domain/ui-service/input-schemas.js +38 -84
- package/dist/domain/ui-service/mutate/auth.d.ts +1 -1
- package/dist/domain/ui-service/mutate/auth.js +3 -2
- package/dist/domain/ui-service/mutate/config.d.ts +0 -8
- package/dist/domain/ui-service/mutate/config.js +0 -22
- package/dist/domain/ui-service/mutate/models.d.ts +13 -0
- package/dist/domain/ui-service/mutate/models.js +137 -0
- package/dist/domain/ui-service/mutate/resolve-media.d.ts +4 -0
- package/dist/domain/ui-service/mutate/resolve-media.js +17 -0
- package/dist/domain/ui-service/mutate/sessions.d.ts +2 -2
- package/dist/domain/ui-service/mutate/sessions.js +29 -126
- package/dist/domain/ui-service/query/config.js +22 -42
- package/dist/domain/ui-service/query/models.js +2 -2
- package/dist/domain/ui-service/query/schedules.js +1 -1
- package/dist/domain/ui-service/query/sessions.js +7 -13
- package/dist/domain/ui-service/types.d.ts +51 -177
- package/dist/domain/ui-service/ui-service.d.ts +23 -49
- package/dist/domain/ui-service/ui-service.js +8 -6
- package/dist/entry/app.js +42 -19
- package/dist/entry/browser-cli.d.ts +39 -0
- package/dist/entry/browser-cli.js +317 -0
- package/dist/entry/cli-help.d.ts +1 -0
- package/dist/entry/cli-help.js +37 -6
- package/dist/entry/cli.js +16 -14
- package/dist/entry/daemon.js +2 -0
- package/dist/entry/init-auth.js +1 -1
- package/dist/entry/init.d.ts +7 -8
- package/dist/entry/init.js +89 -249
- package/dist/entry/path-cli.d.ts +4 -0
- package/dist/entry/path-cli.js +65 -0
- package/dist/entry/schedule-cli.js +13 -6
- package/dist/entry/shutdown.d.ts +1 -1
- package/dist/entry/shutdown.js +8 -1
- package/dist/entry/start-ui-http.js +8 -0
- package/dist/entry/ui-service-wiring.js +8 -10
- package/dist/events/event-types.d.ts +3 -2
- package/dist/orchestration/agent-runner.d.ts +2 -2
- package/dist/orchestration/agent-runner.js +10 -9
- package/dist/orchestration/benchmark-session-webhook.js +13 -1
- package/dist/orchestration/browser-webhook.d.ts +11 -0
- package/dist/orchestration/browser-webhook.js +28 -0
- package/dist/orchestration/cache-keep-warm.d.ts +77 -0
- package/dist/orchestration/cache-keep-warm.js +213 -0
- package/dist/orchestration/claude-window-warmup.d.ts +40 -0
- package/dist/orchestration/claude-window-warmup.js +126 -0
- package/dist/orchestration/conversation-request.d.ts +6 -10
- package/dist/orchestration/conversation-request.js +5 -23
- package/dist/orchestration/delta-coalescer.d.ts +4 -2
- package/dist/orchestration/delta-coalescer.js +5 -5
- package/dist/orchestration/edit-retry.js +9 -11
- package/dist/orchestration/inline-media-eager.d.ts +13 -0
- package/dist/orchestration/inline-media-eager.js +58 -0
- package/dist/orchestration/inline-media.d.ts +22 -0
- package/dist/orchestration/inline-media.js +151 -0
- package/dist/orchestration/interactions/ask-user-resume.js +3 -7
- package/dist/orchestration/interactions/interaction-handlers.js +6 -6
- package/dist/orchestration/mid-turn-inject.d.ts +2 -1
- package/dist/orchestration/mid-turn-inject.js +1 -1
- package/dist/orchestration/pending-injection-recovery.d.ts +2 -1
- package/dist/orchestration/pending-injection-recovery.js +1 -1
- package/dist/orchestration/routing/commands/index.js +4 -4
- package/dist/orchestration/routing/commands/mode.d.ts +5 -44
- package/dist/orchestration/routing/commands/mode.js +98 -272
- package/dist/orchestration/routing/commands/schedule.js +29 -18
- package/dist/orchestration/routing/commands/session.js +9 -9
- package/dist/orchestration/routing/commands/status.js +1 -1
- package/dist/orchestration/routing/commands/usage-format.js +3 -0
- package/dist/orchestration/routing/webhook.js +4 -0
- package/dist/orchestration/session-compact.d.ts +0 -1
- package/dist/orchestration/session-compact.js +5 -7
- package/dist/orchestration/session-events.d.ts +2 -1
- package/dist/orchestration/session-events.js +1 -0
- package/dist/orchestration/status-helpers.d.ts +0 -4
- package/dist/orchestration/status-helpers.js +0 -18
- package/dist/orchestration/subagent-webhook.js +9 -34
- package/dist/orchestration/team-webhook.d.ts +8 -9
- package/dist/orchestration/team-webhook.js +16 -42
- package/dist/orchestration/transcript-sink.d.ts +6 -0
- package/dist/orchestration/transcript-sink.js +21 -2
- package/dist/orchestration/turn/terminal.js +7 -7
- package/dist/orchestration/turn/turn-prep.d.ts +0 -8
- package/dist/orchestration/turn/turn-prep.js +0 -51
- package/dist/orchestration/turn/turn-tracking.d.ts +2 -2
- package/dist/orchestration/turn/turn-tracking.js +8 -5
- package/dist/orchestration/turn/turn.d.ts +0 -2
- package/dist/orchestration/turn/turn.js +13 -15
- package/dist/platform/adapters/tui/ports.d.ts +1 -1
- package/dist/platform/adapters/tui/tui-transcript.js +2 -0
- package/dist/platform/browser/agent-browser.d.ts +50 -0
- package/dist/platform/browser/agent-browser.js +165 -0
- package/dist/platform/browser/managed-browser.d.ts +1 -11
- package/dist/platform/browser/managed-browser.js +4 -12
- package/dist/platform/ui-http/browser-stream.d.ts +110 -0
- package/dist/platform/ui-http/browser-stream.js +447 -0
- package/dist/platform/ui-http/ui-http-server.d.ts +12 -0
- package/dist/platform/ui-http/ui-http-server.js +23 -6
- package/dist/store/conversation-history-reader.js +8 -0
- package/dist/store/conversation-history-repo.d.ts +8 -1
- package/dist/store/conversation-history-repo.js +5 -0
- package/dist/store/conversation-ledger-repo.d.ts +6 -6
- package/dist/store/conversation-ledger-repo.js +4 -4
- package/dist/store/models-repo.d.ts +18 -0
- package/dist/store/models-repo.js +74 -0
- package/dist/store/pending-injection-repo.d.ts +2 -1
- package/dist/store/pending-injection-repo.js +3 -1
- package/dist/store/retire-profiles-migration.d.ts +28 -0
- package/dist/store/retire-profiles-migration.js +335 -0
- package/dist/store/schedule-repo.d.ts +2 -1
- package/dist/store/session-registry-import.js +3 -2
- package/dist/store/session-registry-journal.d.ts +10 -13
- package/dist/store/session-registry-journal.js +48 -25
- package/dist/store/session-registry-repo.d.ts +4 -4
- package/dist/store/session-registry-repo.js +4 -5
- package/dist/store/version-migrations.d.ts +2 -3
- package/dist/store/version-migrations.js +19 -3
- package/dist/tui/slash-commands.js +2 -2
- package/dist/tui/turn-status.js +1 -1
- package/package.json +6 -4
- package/web/dist/assets/board-math-css-CB4GJ6qO.js +2 -0
- package/web/dist/assets/index-CaSZPg_H.css +1 -0
- package/web/dist/assets/index-CzOR7Edh.js +522 -0
- package/web/dist/assets/{index-CndZZ1IQ.js → index-cIGFv27z.js} +1 -1
- package/web/dist/index.html +3 -2
- package/web/dist/theme.css +6 -0
- package/dist/agent-adapter/browser-mcp-server.d.ts +0 -13
- package/dist/agent-adapter/browser-mcp-server.js +0 -28
- package/dist/agent-adapter/claude/browser-mcp.d.ts +0 -9
- package/dist/agent-adapter/claude/browser-mcp.js +0 -10
- package/dist/core/profile-generator.d.ts +0 -79
- package/dist/core/profile-generator.js +0 -215
- package/dist/domain/agents/profile-manager.d.ts +0 -103
- package/dist/domain/agents/profile-manager.js +0 -286
- package/dist/domain/agents/profile-switch.d.ts +0 -49
- package/dist/domain/agents/profile-switch.js +0 -62
- package/dist/domain/ui-service/mutate/profiles.d.ts +0 -36
- package/dist/domain/ui-service/mutate/profiles.js +0 -151
- package/dist/store/profile-repo.d.ts +0 -20
- package/dist/store/profile-repo.js +0 -97
- package/web/dist/assets/index-B76ueW3q.js +0 -494
- package/web/dist/assets/index-C8O0yxg8.css +0 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AsyncMutex } from '../core/async-mutex.js';
|
|
2
|
+
import type { ModelsFile } from '../domain/agents/engine-selection.js';
|
|
3
|
+
export declare const MODELS_FILE: string;
|
|
4
|
+
export declare const modelsWriteLock: AsyncMutex;
|
|
5
|
+
export declare function getModelsConfigRevision(): number;
|
|
6
|
+
export declare class ModelsRepo {
|
|
7
|
+
private readonly filePath;
|
|
8
|
+
private cache;
|
|
9
|
+
constructor(filePath?: string);
|
|
10
|
+
readSync(): ModelsFile;
|
|
11
|
+
readIfPresent(): ModelsFile | null;
|
|
12
|
+
invalidate(): void;
|
|
13
|
+
/** Parse before replacing the cache: a failed reload keeps the last usable snapshot. */
|
|
14
|
+
reload(): void;
|
|
15
|
+
}
|
|
16
|
+
export declare const modelsRepo: ModelsRepo;
|
|
17
|
+
export declare function setAdminNotifier(fn: (text: string) => void): void;
|
|
18
|
+
export declare function startModelsWatcher(repo?: ModelsRepo, filePath?: string, onReload?: () => void): () => void;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { CONFIG_DIR } from '../core/paths.js';
|
|
4
|
+
import { AsyncMutex } from '../core/async-mutex.js';
|
|
5
|
+
import { createLogger } from '../core/log.js';
|
|
6
|
+
import { createFileWatchMonitor } from '../core/resilient-watch.js';
|
|
7
|
+
import { Icons } from '../core/icons.js';
|
|
8
|
+
const log = createLogger('models-repo');
|
|
9
|
+
let modelsConfigRevision = 0;
|
|
10
|
+
export const MODELS_FILE = path.join(CONFIG_DIR, 'models.json');
|
|
11
|
+
// UI mutations and login sync must hold this across read, write, and invalidation.
|
|
12
|
+
export const modelsWriteLock = new AsyncMutex();
|
|
13
|
+
export function getModelsConfigRevision() { return modelsConfigRevision; }
|
|
14
|
+
export class ModelsRepo {
|
|
15
|
+
filePath;
|
|
16
|
+
cache = null;
|
|
17
|
+
constructor(filePath = MODELS_FILE) {
|
|
18
|
+
this.filePath = filePath;
|
|
19
|
+
}
|
|
20
|
+
readSync() {
|
|
21
|
+
if (!this.cache)
|
|
22
|
+
this.cache = JSON.parse(readFileSync(this.filePath, 'utf8'));
|
|
23
|
+
return this.cache;
|
|
24
|
+
}
|
|
25
|
+
readIfPresent() {
|
|
26
|
+
try {
|
|
27
|
+
return this.readSync();
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error.code === 'ENOENT')
|
|
31
|
+
return null;
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
invalidate() { this.cache = null; modelsConfigRevision += 1; }
|
|
36
|
+
/** Parse before replacing the cache: a failed reload keeps the last usable snapshot. */
|
|
37
|
+
reload() {
|
|
38
|
+
const parsed = JSON.parse(readFileSync(this.filePath, 'utf8'));
|
|
39
|
+
this.cache = parsed;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export const modelsRepo = new ModelsRepo();
|
|
43
|
+
let adminNotifier = null;
|
|
44
|
+
export function setAdminNotifier(fn) { adminNotifier = fn; }
|
|
45
|
+
function reloadModels(repo, onReload) {
|
|
46
|
+
try {
|
|
47
|
+
repo.reload();
|
|
48
|
+
modelsConfigRevision += 1;
|
|
49
|
+
onReload?.();
|
|
50
|
+
log.info('Hot-reload: models.json reloaded');
|
|
51
|
+
adminNotifier?.(`${Icons.refresh} \`models.json\` hot-reloaded`);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
log.error(`Hot-reload models.json failed: ${error.message} — keeping previous config`);
|
|
55
|
+
adminNotifier?.(`${Icons.warning} \`models.json\` hot-reload FAILED — keeping previous config`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export function startModelsWatcher(repo = modelsRepo, filePath = MODELS_FILE, onReload) {
|
|
59
|
+
let timer = null;
|
|
60
|
+
const onChange = () => {
|
|
61
|
+
if (timer)
|
|
62
|
+
clearTimeout(timer);
|
|
63
|
+
timer = setTimeout(() => { timer = null; reloadModels(repo, onReload); }, 300);
|
|
64
|
+
};
|
|
65
|
+
const monitor = createFileWatchMonitor({
|
|
66
|
+
label: 'models.json', filePath, onChange, warn: (message) => log.error(message),
|
|
67
|
+
});
|
|
68
|
+
return () => {
|
|
69
|
+
monitor.close();
|
|
70
|
+
if (timer)
|
|
71
|
+
clearTimeout(timer);
|
|
72
|
+
timer = null;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { EngineSelection } from '../domain/agents/engine-selection.js';
|
|
1
2
|
import type { AttachmentMeta, SystemTurnOrigin } from '../core/types/agent-types.js';
|
|
2
3
|
export type PendingAttachment = AttachmentMeta;
|
|
3
4
|
export interface PendingInjectionRecord {
|
|
@@ -6,7 +7,7 @@ export interface PendingInjectionRecord {
|
|
|
6
7
|
channel: string;
|
|
7
8
|
messageId: string;
|
|
8
9
|
backend: string;
|
|
9
|
-
|
|
10
|
+
selection: EngineSelection | null;
|
|
10
11
|
text: string;
|
|
11
12
|
attachments?: PendingAttachment[];
|
|
12
13
|
agentMessage?: string;
|
|
@@ -2,11 +2,13 @@ import path from 'node:path';
|
|
|
2
2
|
import { JsonRepository } from '../core/json-repository.js';
|
|
3
3
|
import { STORE_DIR } from '../core/paths.js';
|
|
4
4
|
function cloneRecord(record) {
|
|
5
|
-
//
|
|
5
|
+
// Ignore retired keys in memory without rewriting persisted data.
|
|
6
6
|
const current = { ...record };
|
|
7
7
|
delete current.sessionName;
|
|
8
|
+
delete current.profileName;
|
|
8
9
|
return {
|
|
9
10
|
...current,
|
|
11
|
+
selection: record.selection ? { ...record.selection } : null,
|
|
10
12
|
...(record.attachments
|
|
11
13
|
? { attachments: record.attachments.map((attachment) => ({ ...attachment })) }
|
|
12
14
|
: {}),
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface RetireProfilesReport {
|
|
2
|
+
skipped?: 'immutable' | 'no-profiles';
|
|
3
|
+
profiles: number;
|
|
4
|
+
favorites: number;
|
|
5
|
+
channels: number;
|
|
6
|
+
overrides: number;
|
|
7
|
+
sessions: number;
|
|
8
|
+
conversations: number;
|
|
9
|
+
schedules: number;
|
|
10
|
+
environments: number;
|
|
11
|
+
archive?: string;
|
|
12
|
+
missingNames: Array<{
|
|
13
|
+
name: string;
|
|
14
|
+
context: string;
|
|
15
|
+
}>;
|
|
16
|
+
discarded: Array<{
|
|
17
|
+
name: string;
|
|
18
|
+
fields: string[];
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
21
|
+
/** S10 only. Registry migration finishes before removing channel overrides; archive is LAST.
|
|
22
|
+
* Each destination preserves compatible materialized values, so any interrupted prefix can retry.
|
|
23
|
+
* A sealed home is entirely untouched, including its mutable state. */
|
|
24
|
+
export declare function retireProfiles(options: {
|
|
25
|
+
dataDir: string;
|
|
26
|
+
storeDir: string;
|
|
27
|
+
now?: Date;
|
|
28
|
+
}): Promise<RetireProfilesReport>;
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { atomicWrite } from '../core/atomic-write.js';
|
|
4
|
+
import { createLogger } from '../core/log.js';
|
|
5
|
+
import { SessionRegistryRepo } from './session-registry-repo.js';
|
|
6
|
+
const log = createLogger('retire-profiles-migration');
|
|
7
|
+
function emptyReport() {
|
|
8
|
+
return { profiles: 0, favorites: 0, channels: 0, overrides: 0, sessions: 0, conversations: 0,
|
|
9
|
+
schedules: 0, environments: 0, missingNames: [], discarded: [] };
|
|
10
|
+
}
|
|
11
|
+
function object(value) {
|
|
12
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
13
|
+
}
|
|
14
|
+
function text(value) {
|
|
15
|
+
return typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
16
|
+
}
|
|
17
|
+
async function readOptional(file) {
|
|
18
|
+
try {
|
|
19
|
+
return await fs.readFile(file, 'utf8');
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
if (error.code === 'ENOENT')
|
|
23
|
+
return null;
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async function readObject(file) {
|
|
28
|
+
const raw = await readOptional(file);
|
|
29
|
+
if (raw === null)
|
|
30
|
+
return null;
|
|
31
|
+
const parsed = JSON.parse(raw);
|
|
32
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
33
|
+
throw new Error(`Expected a JSON object in ${file}`);
|
|
34
|
+
}
|
|
35
|
+
return parsed;
|
|
36
|
+
}
|
|
37
|
+
async function writeObject(file, value) {
|
|
38
|
+
const next = `${JSON.stringify(value, null, 2)}\n`;
|
|
39
|
+
if (await readOptional(file) !== next)
|
|
40
|
+
await atomicWrite(file, next);
|
|
41
|
+
}
|
|
42
|
+
// Same model identity as modelKey; keep this store migration independent of domain runtime code.
|
|
43
|
+
function key(ref) { return JSON.stringify([ref.backend, ref.provider, ref.model]); }
|
|
44
|
+
function profileSelection(name, raw) {
|
|
45
|
+
const entry = object(raw);
|
|
46
|
+
const backend = entry.backend ?? 'claude';
|
|
47
|
+
if (backend !== 'claude' && backend !== 'pi')
|
|
48
|
+
throw new Error(`Invalid backend for profile ${name}`);
|
|
49
|
+
const model = text(entry.model);
|
|
50
|
+
if (!model)
|
|
51
|
+
throw new Error(`Missing model for profile ${name}`);
|
|
52
|
+
const provider = backend === 'pi' ? text(entry.provider) ?? text(entry.mode) ?? 'anthropic' : null;
|
|
53
|
+
const extra = object(entry.extraOption);
|
|
54
|
+
return { backend, provider, model,
|
|
55
|
+
thinking: text(entry.thinking) ?? text(extra['--thinking']) ?? text(extra['--effort']) ?? null,
|
|
56
|
+
mode: text(entry.mode) ?? (backend === 'pi' ? provider : 'plan') };
|
|
57
|
+
}
|
|
58
|
+
function recordDiscarded(name, entry, report) {
|
|
59
|
+
const fields = ['fallback', 'extraEnv', 'maxOutputTokens'].filter(field => field in object(entry));
|
|
60
|
+
if (!fields.length)
|
|
61
|
+
return;
|
|
62
|
+
report.discarded.push({ name, fields });
|
|
63
|
+
log.info(`Discarding retired fields for profile ${name}: ${fields.join(', ')}`);
|
|
64
|
+
}
|
|
65
|
+
function buildSnapshot(source, report) {
|
|
66
|
+
const selections = new Map();
|
|
67
|
+
const favorites = new Map();
|
|
68
|
+
const memory = {};
|
|
69
|
+
for (const [name, entry] of Object.entries(object(source.profiles))) {
|
|
70
|
+
const selection = profileSelection(name, entry);
|
|
71
|
+
selections.set(name, selection);
|
|
72
|
+
const { backend, provider, model, thinking, mode } = selection;
|
|
73
|
+
favorites.set(key(selection), { backend, provider, model });
|
|
74
|
+
memory[key(selection)] ??= { thinking, mode };
|
|
75
|
+
recordDiscarded(name, entry, report);
|
|
76
|
+
}
|
|
77
|
+
const defaultSelection = selections.get(String(source.defaultProfile));
|
|
78
|
+
if (!defaultSelection)
|
|
79
|
+
throw new Error(`Default profile not found: ${String(source.defaultProfile)}`);
|
|
80
|
+
const { thinking, mode } = defaultSelection;
|
|
81
|
+
memory[key(defaultSelection)] = { thinking, mode };
|
|
82
|
+
report.profiles = selections.size;
|
|
83
|
+
report.favorites = favorites.size;
|
|
84
|
+
return { selections, models: { default: defaultSelection, favorites: [...favorites.values()] }, memory, report };
|
|
85
|
+
}
|
|
86
|
+
function resolveName(snapshot, name, context) {
|
|
87
|
+
if (!text(name) || name === '__active__')
|
|
88
|
+
return { ...snapshot.models.default };
|
|
89
|
+
const selected = snapshot.selections.get(String(name));
|
|
90
|
+
if (selected)
|
|
91
|
+
return { ...selected };
|
|
92
|
+
snapshot.report.missingNames.push({ name: String(name), context });
|
|
93
|
+
log.warn(`Unknown profile ${String(name)} at ${context}; resolving fallback selection`);
|
|
94
|
+
return { ...snapshot.models.default };
|
|
95
|
+
}
|
|
96
|
+
function compatible(value, backend) {
|
|
97
|
+
return Boolean(value) && (backend === undefined || object(value).backend === backend);
|
|
98
|
+
}
|
|
99
|
+
function resolveCompatibleName(snapshot, name, context, backend) {
|
|
100
|
+
const selected = resolveName(snapshot, name, context);
|
|
101
|
+
if (compatible(selected, backend))
|
|
102
|
+
return selected;
|
|
103
|
+
if (compatible(snapshot.models.default, backend))
|
|
104
|
+
return { ...snapshot.models.default };
|
|
105
|
+
const favorite = snapshot.models.favorites.find(ref => ref.backend === backend);
|
|
106
|
+
return favorite ? { ...favorite, ...snapshot.memory[key(favorite)] } : null;
|
|
107
|
+
}
|
|
108
|
+
/** Bindings, not session.channel (the creation origin), identify the resume target. */
|
|
109
|
+
async function channelBackend(repo, channel) {
|
|
110
|
+
const boundId = await repo.getBoundSessionId(channel);
|
|
111
|
+
const bound = boundId ? await repo.getById(boundId) : null;
|
|
112
|
+
if (bound)
|
|
113
|
+
return bound.backend;
|
|
114
|
+
const header = await repo.getConversationHeader(channel);
|
|
115
|
+
const session = header?.sessionId ? await repo.getById(header.sessionId) : null;
|
|
116
|
+
return session?.backend ?? header?.backend;
|
|
117
|
+
}
|
|
118
|
+
function mergeOverride(selection, raw) {
|
|
119
|
+
const override = object(raw);
|
|
120
|
+
const next = { ...selection };
|
|
121
|
+
for (const field of ['model', 'mode']) {
|
|
122
|
+
const value = text(override[field]);
|
|
123
|
+
if (value)
|
|
124
|
+
next[field] = value;
|
|
125
|
+
}
|
|
126
|
+
if (override.thinking === null || text(override.thinking))
|
|
127
|
+
next.thinking = override.thinking;
|
|
128
|
+
const provider = text(override.provider);
|
|
129
|
+
if (next.backend === 'pi' && provider && provider !== next.provider) {
|
|
130
|
+
next.provider = provider;
|
|
131
|
+
next.mode = provider;
|
|
132
|
+
}
|
|
133
|
+
return next;
|
|
134
|
+
}
|
|
135
|
+
async function migrateChannels(state, snapshot, repo) {
|
|
136
|
+
const profiles = object(state.channelProfiles);
|
|
137
|
+
const overrides = object(state.channelOverrides);
|
|
138
|
+
const channels = new Set([...Object.keys(profiles), ...Object.keys(overrides)]);
|
|
139
|
+
const selections = { ...object(state.channelSelections) };
|
|
140
|
+
for (const channel of channels) {
|
|
141
|
+
const backend = await channelBackend(repo, channel);
|
|
142
|
+
if (compatible(selections[channel], backend))
|
|
143
|
+
continue;
|
|
144
|
+
const base = resolveCompatibleName(snapshot, profiles[channel] ?? state.activeProfile, `channel:${channel}`, backend);
|
|
145
|
+
delete selections[channel];
|
|
146
|
+
if (!base)
|
|
147
|
+
continue;
|
|
148
|
+
selections[channel] = mergeOverride(base, overrides[channel]);
|
|
149
|
+
snapshot.report.channels += 1;
|
|
150
|
+
if (Object.keys(object(overrides[channel])).length)
|
|
151
|
+
snapshot.report.overrides += 1;
|
|
152
|
+
}
|
|
153
|
+
return selections;
|
|
154
|
+
}
|
|
155
|
+
function migrateSeed(state, snapshot) {
|
|
156
|
+
const seed = object(state.selectionDefault);
|
|
157
|
+
if (!state.selectionDefault || seed.backend)
|
|
158
|
+
return state.selectionDefault;
|
|
159
|
+
const selection = mergeOverride(resolveName(snapshot, seed.profileName ?? state.activeProfile, 'selectionDefault'), seed);
|
|
160
|
+
return { ...selection, ...(text(seed.agentName) ? { agentName: seed.agentName } : {}) };
|
|
161
|
+
}
|
|
162
|
+
async function migrateState(state, snapshot, repo) {
|
|
163
|
+
const next = { ...state, channelSelections: await migrateChannels(state, snapshot, repo),
|
|
164
|
+
modelMemory: { ...snapshot.memory, ...object(state.modelMemory) } };
|
|
165
|
+
if ('selectionDefault' in state)
|
|
166
|
+
next.selectionDefault = migrateSeed(state, snapshot);
|
|
167
|
+
for (const field of ['activeProfile', 'channelProfiles', 'channelOverrides'])
|
|
168
|
+
delete next[field];
|
|
169
|
+
return next;
|
|
170
|
+
}
|
|
171
|
+
function applyName(names, id, fields) {
|
|
172
|
+
if (!('profileName' in fields))
|
|
173
|
+
return;
|
|
174
|
+
const name = text(fields.profileName);
|
|
175
|
+
if (name)
|
|
176
|
+
names.set(id, name);
|
|
177
|
+
else
|
|
178
|
+
names.delete(id);
|
|
179
|
+
}
|
|
180
|
+
function replaySessionName(names, row) {
|
|
181
|
+
const id = String(row.id);
|
|
182
|
+
if (row.op === 'put') {
|
|
183
|
+
names.delete(id);
|
|
184
|
+
applyName(names, id, object(row.record));
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (row.op === 'patch') {
|
|
188
|
+
applyName(names, id, object(row.fields));
|
|
189
|
+
if (Array.isArray(row.unset) && row.unset.includes('profileName'))
|
|
190
|
+
names.delete(id);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (row.op === 'delete-intent' || row.op === 'delete-commit')
|
|
194
|
+
names.delete(id);
|
|
195
|
+
}
|
|
196
|
+
/** Read committed legacy names, including those carried through earlier import/compaction.
|
|
197
|
+
* An unterminated tail is not committed (the repo truncates it on load). */
|
|
198
|
+
async function readRawNames(file) {
|
|
199
|
+
const names = { sessions: new Map(), conversations: new Map() };
|
|
200
|
+
const raw = await readOptional(file);
|
|
201
|
+
if (!raw)
|
|
202
|
+
return names;
|
|
203
|
+
const committed = raw.slice(0, raw.lastIndexOf('\n') + 1);
|
|
204
|
+
for (const line of committed.split('\n').filter(line => line.trim())) {
|
|
205
|
+
const row = object(JSON.parse(line));
|
|
206
|
+
if (row.op !== 'conversation') {
|
|
207
|
+
replaySessionName(names.sessions, row);
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
const channel = String(row.channel);
|
|
211
|
+
if (row.kind === 'clear')
|
|
212
|
+
names.conversations.delete(channel);
|
|
213
|
+
else
|
|
214
|
+
applyName(names.conversations, channel, object(row.fields));
|
|
215
|
+
}
|
|
216
|
+
return names;
|
|
217
|
+
}
|
|
218
|
+
async function migrateSessions(names, repo, overrides, snapshot) {
|
|
219
|
+
// Sessions without a stored name stay unmaterialized; runtime guards their resume backend.
|
|
220
|
+
for (const [id, name] of names) {
|
|
221
|
+
const session = await repo.getById(id);
|
|
222
|
+
if (!session || compatible(session.selection, session.backend))
|
|
223
|
+
continue;
|
|
224
|
+
const base = resolveCompatibleName(snapshot, name, `session:${id}`, session.backend);
|
|
225
|
+
if (!base && !session.selection)
|
|
226
|
+
continue;
|
|
227
|
+
const selection = base ? mergeOverride(base, overrides[session.channel]) : null;
|
|
228
|
+
await repo.updateSession(id, { selection });
|
|
229
|
+
snapshot.report.sessions += 1;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
async function migrateConversations(names, repo, overrides, snapshot) {
|
|
233
|
+
for (const [channel, name] of names) {
|
|
234
|
+
const header = await repo.getConversationHeader(channel);
|
|
235
|
+
const backend = await channelBackend(repo, channel);
|
|
236
|
+
if (!header || compatible(header.selection, backend))
|
|
237
|
+
continue;
|
|
238
|
+
const base = resolveCompatibleName(snapshot, name, `conversation:${channel}`, backend);
|
|
239
|
+
if (!base && !header.selection)
|
|
240
|
+
continue;
|
|
241
|
+
const selection = base ? mergeOverride(base, overrides[channel]) : null;
|
|
242
|
+
await repo.setConversation(channel, { selection });
|
|
243
|
+
snapshot.report.conversations += 1;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
async function migrateRegistry(file, repo, state, snapshot) {
|
|
247
|
+
const names = await readRawNames(file);
|
|
248
|
+
const overrides = object(state.channelOverrides);
|
|
249
|
+
await migrateSessions(names.sessions, repo, overrides, snapshot);
|
|
250
|
+
await migrateConversations(names.conversations, repo, overrides, snapshot);
|
|
251
|
+
await repo.flush();
|
|
252
|
+
}
|
|
253
|
+
async function migrateSchedules(file, snapshot) {
|
|
254
|
+
const schedules = await readObject(file);
|
|
255
|
+
if (!schedules || !Array.isArray(schedules.tasks))
|
|
256
|
+
return;
|
|
257
|
+
for (const raw of schedules.tasks) {
|
|
258
|
+
const task = object(raw);
|
|
259
|
+
if (!('profile' in task))
|
|
260
|
+
continue;
|
|
261
|
+
task.selection ??= resolveName(snapshot, task.profile, `schedule:${String(task.id)}`);
|
|
262
|
+
delete task.profile;
|
|
263
|
+
snapshot.report.schedules += 1;
|
|
264
|
+
}
|
|
265
|
+
await writeObject(file, schedules);
|
|
266
|
+
}
|
|
267
|
+
async function listEnvironments(dir) {
|
|
268
|
+
try {
|
|
269
|
+
return (await fs.readdir(dir, { withFileTypes: true }))
|
|
270
|
+
.filter(entry => entry.isFile() && entry.name.endsWith('.json')).map(entry => entry.name);
|
|
271
|
+
}
|
|
272
|
+
catch (error) {
|
|
273
|
+
if (error.code === 'ENOENT')
|
|
274
|
+
return [];
|
|
275
|
+
throw error;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
async function migrateEnvironments(dir, report) {
|
|
279
|
+
for (const name of await listEnvironments(dir)) {
|
|
280
|
+
const file = path.join(dir, name);
|
|
281
|
+
const environment = await readObject(file);
|
|
282
|
+
if (!environment || !('profile' in environment))
|
|
283
|
+
continue;
|
|
284
|
+
delete environment.profile;
|
|
285
|
+
await writeObject(file, environment);
|
|
286
|
+
report.environments += 1;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
async function archiveProfiles(source, now) {
|
|
290
|
+
const stamp = now.toISOString().replace(/[-:.]/g, '');
|
|
291
|
+
const dir = path.join(path.dirname(source), 'archive', `profiles-${stamp}`);
|
|
292
|
+
await fs.mkdir(dir, { recursive: true });
|
|
293
|
+
const destination = path.join(dir, 'profiles.json');
|
|
294
|
+
// Refuse to replace an older archive, including a dangling symlink.
|
|
295
|
+
try {
|
|
296
|
+
await fs.lstat(destination);
|
|
297
|
+
throw new Error(`Archive target already exists: ${destination}`);
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
if (error.code !== 'ENOENT')
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
await fs.rename(source, destination);
|
|
304
|
+
return destination;
|
|
305
|
+
}
|
|
306
|
+
/** S10 only. Registry migration finishes before removing channel overrides; archive is LAST.
|
|
307
|
+
* Each destination preserves compatible materialized values, so any interrupted prefix can retry.
|
|
308
|
+
* A sealed home is entirely untouched, including its mutable state. */
|
|
309
|
+
export async function retireProfiles(options) {
|
|
310
|
+
const report = emptyReport();
|
|
311
|
+
if (process.env.CORTEX_CONFIG_IMMUTABLE === '1')
|
|
312
|
+
return { ...report, skipped: 'immutable' };
|
|
313
|
+
const configDir = path.join(options.dataDir, 'config');
|
|
314
|
+
const sourcePath = path.join(configDir, 'profiles.json');
|
|
315
|
+
const source = await readObject(sourcePath);
|
|
316
|
+
if (!source)
|
|
317
|
+
return { ...report, skipped: 'no-profiles' };
|
|
318
|
+
const snapshot = buildSnapshot(source, report);
|
|
319
|
+
const statePath = path.join(options.storeDir, 'agent-state.json');
|
|
320
|
+
const state = await readObject(statePath) ?? {};
|
|
321
|
+
const registryPath = path.join(options.storeDir, 'session-registry.jsonl');
|
|
322
|
+
// Never use the singleton or compact away legacy names needed by a partial retry.
|
|
323
|
+
const repo = new SessionRegistryRepo(registryPath, { shouldCompact: () => false });
|
|
324
|
+
const nextState = await migrateState(state, snapshot, repo);
|
|
325
|
+
const modelsPath = path.join(configDir, 'models.json');
|
|
326
|
+
if (!await readObject(modelsPath))
|
|
327
|
+
await writeObject(modelsPath, snapshot.models);
|
|
328
|
+
await migrateRegistry(registryPath, repo, state, snapshot);
|
|
329
|
+
await migrateSchedules(path.join(options.storeDir, 'schedules.json'), snapshot);
|
|
330
|
+
await migrateEnvironments(path.join(configDir, 'environments'), report);
|
|
331
|
+
await writeObject(statePath, nextState);
|
|
332
|
+
report.archive = await archiveProfiles(sourcePath, options.now ?? new Date());
|
|
333
|
+
log.info(`Retired profiles: ${JSON.stringify(report)}`);
|
|
334
|
+
return report;
|
|
335
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { EngineSelection } from '../domain/agents/engine-selection.js';
|
|
1
2
|
export declare const SCHEDULES_FILE: string;
|
|
2
3
|
export declare const CHANNEL_REGISTRY_FILE: string;
|
|
3
4
|
export interface ScheduleTask {
|
|
@@ -5,7 +6,7 @@ export interface ScheduleTask {
|
|
|
5
6
|
type: 'interval' | 'daily' | 'weekly' | 'once';
|
|
6
7
|
message: string;
|
|
7
8
|
projectId: string;
|
|
8
|
-
|
|
9
|
+
selection?: EngineSelection;
|
|
9
10
|
intervalMs?: number;
|
|
10
11
|
time?: string;
|
|
11
12
|
dayOfWeek?: number;
|
|
@@ -105,7 +105,7 @@ function parseBindings(data) {
|
|
|
105
105
|
return out;
|
|
106
106
|
}
|
|
107
107
|
/** conversation-ledger.json is a flat `{ "<channel>": { sessionId, sessionName, backend, profileName,
|
|
108
|
-
* turns[], updatedAt } }`. Legacy sessionName is ignored;
|
|
108
|
+
* turns[], updatedAt } }`. Legacy sessionName is ignored; profileName is carried until S10. Fields (including
|
|
109
109
|
* `sessionId: null`) and source `updatedAt` are preserved; turns keep their order and indices. */
|
|
110
110
|
function parseConversations(data) {
|
|
111
111
|
if (!isPlainObject(data))
|
|
@@ -117,7 +117,8 @@ function parseConversations(data) {
|
|
|
117
117
|
const header = {
|
|
118
118
|
sessionId: headerString(value.sessionId),
|
|
119
119
|
backend: typeof value.backend === 'string' ? value.backend : '',
|
|
120
|
-
|
|
120
|
+
selection: null,
|
|
121
|
+
...(value.profileName !== undefined ? { profileName: value.profileName } : {}),
|
|
121
122
|
updatedAt: typeof value.updatedAt === 'string' ? value.updatedAt : '',
|
|
122
123
|
};
|
|
123
124
|
const turns = Array.isArray(value.turns) ? value.turns.filter(isPlainObject).map(toTurnRecord) : [];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { EngineSelection } from '../domain/agents/engine-selection.js';
|
|
1
2
|
import fsp from 'node:fs/promises';
|
|
2
3
|
export type SessionOrigin = 'direct' | 'thread' | 'scheduled';
|
|
3
4
|
export type SessionKind = 'local' | 'scheduled';
|
|
@@ -8,13 +9,6 @@ export interface PendingSessionDelete {
|
|
|
8
9
|
session: SessionRecord;
|
|
9
10
|
cleanup: SessionDeleteCleanup;
|
|
10
11
|
}
|
|
11
|
-
/** Per-session browser opt-in (plan/embedded-browser.md §17). Absent/null means the session gets
|
|
12
|
-
* ZERO browser tools — the whole point of making this opt-in is that ~24 Playwright tools are not
|
|
13
|
-
* worth their context cost in a session that never browses. `device` names WHERE the browser runs;
|
|
14
|
-
* only 'server' exists until the cortex-client reverse channel lands. */
|
|
15
|
-
export interface SessionBrowserOption {
|
|
16
|
-
device: string;
|
|
17
|
-
}
|
|
18
12
|
export interface SessionRecord {
|
|
19
13
|
sessionId: string;
|
|
20
14
|
projectId: string;
|
|
@@ -27,9 +21,11 @@ export interface SessionRecord {
|
|
|
27
21
|
label: string | null;
|
|
28
22
|
starred?: boolean;
|
|
29
23
|
labelRenamed?: boolean;
|
|
30
|
-
|
|
24
|
+
selection: EngineSelection | null;
|
|
25
|
+
/** Read-only legacy data carried verbatim through pre-S10 import/compaction. */
|
|
26
|
+
readonly profileName?: unknown;
|
|
31
27
|
/** The agent template this session runs as — its execution environment (prompt, tools, skills,
|
|
32
|
-
* rules)
|
|
28
|
+
* rules). Absent/null means the session follows its
|
|
33
29
|
* channel's selection, and beneath that the global default. */
|
|
34
30
|
agentName?: string | null;
|
|
35
31
|
backendSessionId?: string | null;
|
|
@@ -42,7 +38,6 @@ export interface SessionRecord {
|
|
|
42
38
|
* the next turn; compaction clears it, because compaction drops the delivered copy. */
|
|
43
39
|
boardBlockFor?: string | null;
|
|
44
40
|
contextUsage?: unknown;
|
|
45
|
-
browser?: SessionBrowserOption | null;
|
|
46
41
|
/** Team mode: the lead session that owns this worker. Non-null means this session is a worker. */
|
|
47
42
|
teamLeadId?: string | null;
|
|
48
43
|
/** The worker's short name, unique within its lead's team. */
|
|
@@ -73,16 +68,18 @@ export interface TurnRecord {
|
|
|
73
68
|
export interface ConversationHeader {
|
|
74
69
|
sessionId: string | null;
|
|
75
70
|
backend: string;
|
|
76
|
-
|
|
71
|
+
selection: EngineSelection | null;
|
|
72
|
+
/** Read-only legacy data carried verbatim through pre-S10 import/compaction. */
|
|
73
|
+
readonly profileName?: unknown;
|
|
77
74
|
updatedAt: string;
|
|
78
75
|
}
|
|
79
76
|
/** Header mutation payload for a `conversation set` event. A key present overwrites; a key absent is
|
|
80
77
|
* left untouched (the reducer merges onto the previous header, or onto a null base for a new one). */
|
|
81
|
-
export type ConversationFields = Partial<ConversationHeader
|
|
78
|
+
export type ConversationFields = Partial<Omit<ConversationHeader, 'profileName'>>;
|
|
82
79
|
/** Patch payload: only the record keys a `patch` may carry. `sessionId` is identity and
|
|
83
80
|
* never travels in a patch (the event keys off it). A key set to `null` means "store null"; a key
|
|
84
81
|
* listed in `unset` is deleted (→ `undefined`); a key in neither is untouched. */
|
|
85
|
-
export type SessionPatchFields = Partial<Omit<SessionRecord, 'sessionId'>>;
|
|
82
|
+
export type SessionPatchFields = Partial<Omit<SessionRecord, 'sessionId' | 'profileName'>>;
|
|
86
83
|
export type SessionPatchUnsetKey = keyof SessionPatchFields;
|
|
87
84
|
export type SessionRegistryEvent = {
|
|
88
85
|
v: 1;
|