@cortex-agent/server 2026.9.14 → 2026.9.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 +3 -2
- package/defaults/config/hooks/08-agents-md-injector-post-tool.json +10 -0
- package/defaults/config/hooks/{10-cortex-md-injector-session-start.json → 10-agents-md-injector-session-start.json} +3 -3
- package/defaults/config/hooks/{CORTEX.md → AGENTS.md} +2 -2
- package/defaults/hooks/{CORTEX.md → AGENTS.md} +1 -1
- package/defaults/hooks/{cortex-md-injector.mjs → agents-md-injector.mjs} +117 -26
- package/defaults/hooks/cortex-hook-api.mjs +2 -2
- package/defaults/hooks/new-session-hook.mjs +2 -2
- package/defaults/hooks/rules-loader.mjs +2 -2
- package/defaults/hooks/status-md-guard.mjs +8 -8
- package/defaults/hooks/task-status-check.mjs +18 -76
- package/defaults/hooks/tasks-yaml-guard.mjs +2 -2
- package/defaults/plugins/cortex-commission/.claude-plugin/plugin.json +2 -2
- package/defaults/plugins/cortex-commission/plugin.json +2 -2
- package/defaults/plugins/cortex-commission/skills/commission/SKILL.md +3 -3
- package/defaults/plugins/cortex-feishu/skills/feishu-doc/SKILL.md +1 -1
- package/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +2 -2
- package/defaults/plugins/cortex-system/skills/project-init/SKILL.md +4 -4
- package/defaults/plugins/cortex-system/skills/task/SKILL.md +1 -1
- package/defaults/rules/{cortex-md.md → agents-md.md} +4 -4
- package/defaults/rules/decision-records.md +1 -1
- package/defaults/rules/meta-conventions.md +4 -4
- package/defaults/rules/mission-md.md +1 -1
- package/dist/agent-adapter/claude/adapter.d.ts +0 -6
- package/dist/agent-adapter/claude/adapter.js +0 -8
- package/dist/agent-adapter/claude/defaults.d.ts +10 -7
- package/dist/agent-adapter/claude/defaults.js +18 -16
- package/dist/agent-adapter/claude/hooks-builder.js +2 -2
- package/dist/agent-adapter/claude/spawn-args.d.ts +0 -3
- package/dist/agent-adapter/claude/spawn-args.js +20 -16
- package/dist/agent-adapter/claude/turn-machine.d.ts +11 -0
- package/dist/agent-adapter/claude/turn-machine.js +46 -5
- package/dist/agent-adapter/normalize/prompt-builder.d.ts +16 -1
- package/dist/agent-adapter/normalize/prompt-builder.js +24 -6
- package/dist/agent-adapter/pi/mcp-bridge-logic.d.ts +11 -2
- package/dist/agent-adapter/pi/mcp-bridge-logic.js +32 -1
- package/dist/agent-adapter/pi/mcp-bridge.js +16 -15
- package/dist/agent-adapter/pi/session-options.d.ts +0 -6
- package/dist/agent-adapter/pi/session-options.js +1 -8
- package/dist/agent-adapter/types.d.ts +1 -1
- package/dist/core/mcp-tool-gate.d.ts +3 -17
- package/dist/core/mcp-tool-gate.js +4 -19
- package/dist/core/media-types.d.ts +10 -0
- package/dist/core/media-types.js +34 -0
- package/dist/core/platform-settings-spec.js +1 -1
- package/dist/core/settings-spec.d.ts +22 -1
- package/dist/core/settings-spec.js +33 -2
- package/dist/core/types/agent-types.d.ts +3 -1
- package/dist/core/utils.d.ts +1 -1
- package/dist/core/utils.js +1 -1
- package/dist/domain/agents/config.d.ts +1 -1
- package/dist/domain/agents/config.js +1 -1
- package/dist/domain/agents/profile-switch.d.ts +1 -1
- package/dist/domain/agents/profile-switch.js +3 -5
- package/dist/domain/agents/subagent/runner.js +0 -1
- package/dist/domain/commissions/commission-draft.d.ts +58 -0
- package/dist/domain/commissions/commission-draft.js +87 -4
- package/dist/domain/commissions/commission-finalize.d.ts +8 -3
- package/dist/domain/commissions/commission-finalize.js +14 -0
- package/dist/domain/executions/registry.d.ts +1 -2
- package/dist/domain/executions/registry.js +0 -3
- package/dist/domain/mcp/bundled-server.js +4 -3
- package/dist/domain/mcp/feishu/file.js +37 -18
- package/dist/domain/mcp/feishu/types.d.ts +3 -0
- package/dist/domain/mcp/feishu-server.js +1 -1
- package/dist/domain/mcp/tools/{cortex-md.d.ts → agents-md.d.ts} +6 -6
- package/dist/domain/mcp/tools/{cortex-md.js → agents-md.js} +6 -6
- package/dist/domain/mcp/tools/commission-tools.d.ts +12 -1
- package/dist/domain/mcp/tools/commission-tools.js +68 -14
- package/dist/domain/mcp/tools/remote-file.d.ts +20 -0
- package/dist/domain/mcp/tools/remote-file.js +44 -0
- package/dist/domain/mcp/tools/slack.d.ts +2 -0
- package/dist/domain/mcp/tools/slack.js +22 -7
- package/dist/domain/mcp/tools/task-ops.js +5 -13
- package/dist/domain/mcp/tools/ui-file.js +23 -10
- package/dist/domain/mcp/tools/waitpoint.d.ts +3 -0
- package/dist/domain/mcp/tools/waitpoint.js +122 -0
- package/dist/domain/memory/agents-md-injector.d.ts +24 -0
- package/dist/domain/memory/{cortex-md-injector.js → agents-md-injector.js} +10 -7
- package/dist/domain/projects/project-store.d.ts +1 -1
- package/dist/domain/projects/project-store.js +3 -3
- package/dist/domain/remote/client-hot-reload.js +3 -1
- package/dist/domain/remote/client-manager.js +105 -126
- package/dist/domain/remote/client-ssh-tunnel.d.ts +16 -5
- package/dist/domain/remote/client-ssh-tunnel.js +12 -5
- package/dist/domain/remote/cortex-client-config.d.ts +1 -1
- package/dist/domain/remote/cortex-client-config.js +1 -1
- package/dist/domain/remote/device-file.d.ts +51 -0
- package/dist/domain/remote/device-file.js +193 -0
- package/dist/domain/remote/device-port.js +3 -0
- package/dist/domain/remote/reverse-stream.d.ts +18 -7
- package/dist/domain/remote/reverse-stream.js +19 -6
- package/dist/domain/runs/builders.js +0 -1
- package/dist/domain/runs/compact.js +0 -1
- package/dist/domain/runs/engine-spec.d.ts +11 -4
- package/dist/domain/runs/engine-spec.js +7 -4
- package/dist/domain/runs/prompt.js +16 -10
- package/dist/domain/runs/request.d.ts +0 -1
- package/dist/domain/sessions/session-hooks.d.ts +5 -12
- package/dist/domain/sessions/session-hooks.js +6 -13
- package/dist/domain/sessions/session-lifecycle.d.ts +4 -4
- package/dist/domain/sessions/session-lifecycle.js +5 -6
- package/dist/domain/sessions/session-retention.d.ts +1 -3
- package/dist/domain/sessions/session-retention.js +9 -26
- package/dist/domain/sessions/session-use.d.ts +32 -0
- package/dist/domain/sessions/session-use.js +63 -0
- package/dist/domain/sessions/session.js +6 -5
- package/dist/domain/system/server-update-check.js +29 -1
- package/dist/domain/system/update-ui-state.d.ts +32 -0
- package/dist/domain/system/update-ui-state.js +63 -0
- package/dist/domain/tasks/claim-recovery.js +2 -2
- package/dist/domain/tasks/dispatch-utils.d.ts +10 -1
- package/dist/domain/tasks/dispatch-utils.js +46 -1
- package/dist/domain/tasks/dispatcher.js +4 -5
- package/dist/domain/tasks/mutator.d.ts +2 -2
- package/dist/domain/tasks/mutator.js +2 -2
- package/dist/domain/tasks/system/task-cli.js +2 -2
- package/dist/domain/tasks/system/task-state.js +1 -1
- package/dist/domain/threads/runner.js +3 -2
- package/dist/domain/ui-service/app-router.d.ts +54 -3
- package/dist/domain/ui-service/app-router.js +12 -14
- package/dist/domain/ui-service/input-schemas.d.ts +49 -5
- package/dist/domain/ui-service/input-schemas.js +35 -9
- package/dist/domain/ui-service/mutate/platform-settings.js +1 -1
- package/dist/domain/ui-service/mutate/sessions.d.ts +17 -1
- package/dist/domain/ui-service/mutate/sessions.js +83 -3
- package/dist/domain/ui-service/mutate/system.d.ts +3 -1
- package/dist/domain/ui-service/mutate/system.js +13 -0
- package/dist/domain/ui-service/mutate/waitpoints.d.ts +2 -0
- package/dist/domain/ui-service/mutate/waitpoints.js +20 -0
- package/dist/domain/ui-service/platform-settings.js +1 -1
- package/dist/domain/ui-service/plugins-shared.js +1 -1
- package/dist/domain/ui-service/query/config.js +1 -1
- package/dist/domain/ui-service/query/executions.js +0 -2
- package/dist/domain/ui-service/query/machine-detail.js +3 -8
- package/dist/domain/ui-service/query/memory.js +1 -1
- package/dist/domain/ui-service/query/sessions.js +7 -0
- package/dist/domain/ui-service/query/system.d.ts +2 -1
- package/dist/domain/ui-service/query/system.js +4 -0
- package/dist/domain/ui-service/query/threads.js +1 -54
- package/dist/domain/ui-service/query/waitpoints.d.ts +30 -0
- package/dist/domain/ui-service/query/waitpoints.js +117 -0
- package/dist/domain/ui-service/query-input-schemas.d.ts +3 -0
- package/dist/domain/ui-service/query-input-schemas.js +3 -0
- package/dist/domain/ui-service/trpc.js +1 -1
- package/dist/domain/ui-service/types.d.ts +175 -50
- package/dist/domain/ui-service/types.js +1 -1
- package/dist/domain/ui-service/ui-service.js +13 -33
- package/dist/domain/waitpoints/notices.d.ts +21 -0
- package/dist/domain/waitpoints/notices.js +115 -0
- package/dist/domain/waitpoints/service.d.ts +91 -0
- package/dist/domain/waitpoints/service.js +243 -0
- package/dist/entry/app.js +39 -29
- package/dist/entry/auth-login-cli.js +1 -1
- package/dist/entry/auth-login-terminal.js +1 -1
- package/dist/entry/init-auth.js +1 -1
- package/dist/entry/init.js +6 -6
- package/dist/entry/signal-cli.d.ts +30 -0
- package/dist/entry/signal-cli.js +207 -0
- package/dist/entry/start-ui-http.d.ts +1 -1
- package/dist/entry/start-ui-http.js +5 -3
- package/dist/events/event-types.d.ts +5 -7
- package/dist/hooks/{cortex-md-injector.mjs → agents-md-injector.mjs} +117 -26
- package/dist/hooks/cortex-hook-api.mjs +2 -2
- package/dist/hooks/new-session-hook.mjs +2 -2
- package/dist/hooks/rules-loader.mjs +2 -2
- package/dist/hooks/status-md-guard.mjs +8 -8
- package/dist/hooks/task-status-check.mjs +18 -76
- package/dist/hooks/tasks-yaml-guard.mjs +2 -2
- package/dist/orchestration/agent-file-send.d.ts +9 -0
- package/dist/orchestration/agent-file-send.js +21 -2
- package/dist/orchestration/agent-runner.d.ts +4 -3
- package/dist/orchestration/agent-runner.js +25 -23
- package/dist/orchestration/attachments-store.d.ts +31 -0
- package/dist/orchestration/attachments-store.js +184 -0
- package/dist/orchestration/conversation-request.d.ts +30 -8
- package/dist/orchestration/conversation-request.js +62 -26
- package/dist/orchestration/edit-retry.js +2 -1
- package/dist/orchestration/interactions/ask-user-resume.js +2 -1
- package/dist/orchestration/interactions/plan-approvals.js +1 -1
- package/dist/orchestration/interactions/ui-update-prompt.d.ts +8 -0
- package/dist/orchestration/interactions/ui-update-prompt.js +47 -0
- package/dist/orchestration/outputs-store.d.ts +11 -0
- package/dist/orchestration/outputs-store.js +32 -6
- package/dist/orchestration/resume-dispatcher.js +2 -2
- package/dist/orchestration/routing/file-handler.d.ts +23 -2
- package/dist/orchestration/routing/file-handler.js +22 -5
- package/dist/orchestration/routing/webhook.js +240 -39
- package/dist/orchestration/session-compact.d.ts +3 -0
- package/dist/orchestration/session-compact.js +3 -2
- package/dist/orchestration/session-events.d.ts +6 -0
- package/dist/orchestration/session-events.js +5 -0
- package/dist/orchestration/session-gateway.d.ts +1 -1
- package/dist/orchestration/session-gateway.js +1 -0
- package/dist/orchestration/thread-executor.d.ts +2 -0
- package/dist/orchestration/thread-executor.js +11 -1
- package/dist/orchestration/thread-input.d.ts +3 -2
- package/dist/orchestration/thread-input.js +8 -9
- package/dist/orchestration/turn/turn-prep.d.ts +15 -1
- package/dist/orchestration/turn/turn-prep.js +21 -9
- package/dist/orchestration/waitpoint-ingress.d.ts +41 -0
- package/dist/orchestration/waitpoint-ingress.js +172 -0
- package/dist/orchestration/waitpoint-notifier.d.ts +21 -0
- package/dist/orchestration/waitpoint-notifier.js +119 -0
- package/dist/orchestration/waitpoint-remote-drain.d.ts +20 -0
- package/dist/orchestration/waitpoint-remote-drain.js +147 -0
- package/dist/orchestration/waitpoint-sweep.d.ts +42 -0
- package/dist/orchestration/waitpoint-sweep.js +87 -0
- package/dist/platform/adapters/feishu-image.d.ts +19 -0
- package/dist/platform/adapters/feishu-image.js +71 -0
- package/dist/platform/adapters/feishu.d.ts +2 -0
- package/dist/platform/adapters/feishu.js +26 -16
- package/dist/platform/ui-http/app-update.d.ts +11 -0
- package/dist/platform/ui-http/app-update.js +3 -0
- package/dist/platform/ui-http/listening-ports.d.ts +1 -1
- package/dist/platform/ui-http/listening-ports.js +1 -1
- package/dist/platform/ui-http/ui-session.js +1 -1
- package/dist/store/conversation-ledger-repo.d.ts +10 -19
- package/dist/store/conversation-ledger-repo.js +143 -152
- package/dist/store/execution-repo.d.ts +1 -19
- package/dist/store/execution-repo.js +1 -18
- package/dist/store/project-notes-repo.js +11 -2
- package/dist/store/prompt-migration-replacements.js +1 -1
- package/dist/store/session-registry-import.d.ts +34 -0
- package/dist/store/session-registry-import.js +182 -0
- package/dist/store/session-registry-journal.d.ts +107 -0
- package/dist/store/session-registry-journal.js +308 -19
- package/dist/store/session-registry-repo.d.ts +113 -28
- package/dist/store/session-registry-repo.js +288 -105
- package/dist/store/version-migrations.d.ts +29 -3
- package/dist/store/version-migrations.js +288 -24
- package/dist/store/waitpoint-repo.d.ts +108 -0
- package/dist/store/waitpoint-repo.js +94 -0
- package/package.json +2 -2
- package/web/dist/assets/index-CwwQNMpP.css +1 -0
- package/web/dist/assets/index-DLSfgq3o.js +444 -0
- package/web/dist/assets/{index-aHbOZSP6.js → index-DZTuqUO4.js} +1 -1
- package/web/dist/index.html +2 -2
- package/defaults/config/hooks/08-cortex-md-injector-post-tool.json +0 -10
- package/dist/domain/executions/log-tailer.d.ts +0 -71
- package/dist/domain/executions/log-tailer.js +0 -194
- package/dist/domain/memory/cortex-md-injector.d.ts +0 -24
- package/dist/domain/memory/cortex-md-scanner.d.ts +0 -10
- package/dist/domain/memory/cortex-md-scanner.js +0 -66
- package/dist/domain/remote/cortex-client.d.ts +0 -1
- package/dist/domain/remote/cortex-client.js +0 -662
- package/dist/domain/tasks/system/cortex-run.d.ts +0 -25
- package/dist/domain/tasks/system/cortex-run.js +0 -360
- package/dist/store/session-repo.d.ts +0 -65
- package/dist/store/session-repo.js +0 -184
- package/web/dist/assets/index-BuXbCsuz.js +0 -444
- package/web/dist/assets/index-CCPxQ94C.css +0 -1
- /package/defaults/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/config/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/context/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/context/ideas/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/context/projects/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/context/scans/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/context/user/{CORTEX.md → AGENTS.md} +0 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// input: fs, readline, STORE_DIR, and append/compact journal callers
|
|
2
2
|
// output: JSONL session registry replay, append, compact, and migration helpers
|
|
3
|
-
//
|
|
4
|
-
//
|
|
3
|
+
// (records + channel bindings + per-CHANNEL conversation header & turn history;
|
|
4
|
+
// events: put/patch/delete-*/bind/unbind/turn/conversation)
|
|
5
|
+
// pos: Low-level journal I/O for session registry state — the single owner of session identity
|
|
6
|
+
// >>> Once I am updated, be sure to update my header comment and the parent folder AGENTS.md <<<
|
|
5
7
|
import fs from 'node:fs';
|
|
6
8
|
import fsp from 'node:fs/promises';
|
|
7
9
|
import path from 'node:path';
|
|
@@ -17,6 +19,9 @@ export function createSessionRegistryState() {
|
|
|
17
19
|
live: new Map(),
|
|
18
20
|
pending: new Map(),
|
|
19
21
|
nameIndex: new Map(),
|
|
22
|
+
bindings: new Map(),
|
|
23
|
+
turns: new Map(),
|
|
24
|
+
conversations: new Map(),
|
|
20
25
|
eventCount: 0,
|
|
21
26
|
fileSize: 0,
|
|
22
27
|
};
|
|
@@ -42,7 +47,8 @@ export function shouldCompactSessionRegistry(state, options) {
|
|
|
42
47
|
};
|
|
43
48
|
if (options.shouldCompact)
|
|
44
49
|
return options.shouldCompact(stats);
|
|
45
|
-
|
|
50
|
+
// Lowered from 2048 (B.T1): patch/turn ticks are cheap, so compact sooner to keep the tail small.
|
|
51
|
+
const threshold = Math.max(512, state.live.size * 4);
|
|
46
52
|
return state.fileSize > MAX_FILE_BYTES || state.eventCount > threshold;
|
|
47
53
|
}
|
|
48
54
|
export async function loadSessionRegistryState(filePath, options = {}) {
|
|
@@ -66,10 +72,25 @@ export async function compactSessionRegistry(filePath, state, options = {}) {
|
|
|
66
72
|
options.onCompact?.();
|
|
67
73
|
}
|
|
68
74
|
function compactedEvents(state) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
75
|
+
const events = [];
|
|
76
|
+
for (const record of state.live.values())
|
|
77
|
+
events.push(putEvent(record));
|
|
78
|
+
for (const entry of state.pending.values())
|
|
79
|
+
events.push(deleteIntentEvent(entry.session, entry.cleanup));
|
|
80
|
+
// Bindings, conversation headers and turns are channel-keyed and re-materialised as-is: bind is a
|
|
81
|
+
// free map (not filtered by liveness), and headers/turns outlive the session record they name.
|
|
82
|
+
// Order: puts → delete-intents → binds → conversation headers → turns.
|
|
83
|
+
for (const [channel, sessionId] of state.bindings) {
|
|
84
|
+
events.push({ v: 1, op: 'bind', channel, sessionId });
|
|
85
|
+
}
|
|
86
|
+
for (const [channel, header] of state.conversations) {
|
|
87
|
+
events.push({ v: 1, op: 'conversation', channel, kind: 'set', fields: header });
|
|
88
|
+
}
|
|
89
|
+
for (const [channel, turns] of state.turns) {
|
|
90
|
+
for (const turn of turns)
|
|
91
|
+
events.push({ v: 1, op: 'turn', channel, kind: 'begin', turn });
|
|
92
|
+
}
|
|
93
|
+
return events;
|
|
73
94
|
}
|
|
74
95
|
function putEvent(record) {
|
|
75
96
|
return { v: 1, op: 'put', id: record.sessionId, record };
|
|
@@ -230,23 +251,85 @@ function normalizeEvent(raw, lineNo) {
|
|
|
230
251
|
const row = raw;
|
|
231
252
|
const version = row?.v;
|
|
232
253
|
const op = row?.op;
|
|
233
|
-
const id = row?.id;
|
|
234
254
|
if (version !== REGISTRY_VERSION)
|
|
235
255
|
throw new Error(`Unknown session registry version at line ${lineNo}`);
|
|
236
|
-
if (
|
|
237
|
-
|
|
238
|
-
if (op === 'put')
|
|
256
|
+
if (op === 'put') {
|
|
257
|
+
const id = requireId(row, lineNo);
|
|
239
258
|
return { v: 1, op, id, record: assertSessionRecord(row.record, id) };
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
};
|
|
259
|
+
}
|
|
260
|
+
if (op === 'delete-intent') {
|
|
261
|
+
const id = requireId(row, lineNo);
|
|
262
|
+
return { v: 1, op, id, record: assertSessionRecord(row.record, id), cleanup: normalizeDeleteCleanup(row.cleanup) };
|
|
263
|
+
}
|
|
246
264
|
if (op === 'delete-commit')
|
|
247
|
-
return { v: 1, op, id };
|
|
265
|
+
return { v: 1, op, id: requireId(row, lineNo) };
|
|
266
|
+
if (op === 'patch')
|
|
267
|
+
return normalizePatchEvent(row, lineNo);
|
|
268
|
+
if (op === 'bind')
|
|
269
|
+
return normalizeBindEvent(row, lineNo);
|
|
270
|
+
if (op === 'unbind')
|
|
271
|
+
return { v: 1, op: 'unbind', channel: requireField(row, 'channel', lineNo) };
|
|
272
|
+
if (op === 'conversation')
|
|
273
|
+
return normalizeConversationEvent(row, lineNo);
|
|
274
|
+
if (op === 'turn')
|
|
275
|
+
return normalizeTurnEvent(row, lineNo);
|
|
248
276
|
throw new Error(`Unknown session registry op at line ${lineNo}`);
|
|
249
277
|
}
|
|
278
|
+
function requireId(row, lineNo) {
|
|
279
|
+
const id = row?.id;
|
|
280
|
+
if (typeof id !== 'string' || !id)
|
|
281
|
+
throw new Error(`Malformed session registry id at line ${lineNo}`);
|
|
282
|
+
return id;
|
|
283
|
+
}
|
|
284
|
+
function requireField(row, key, lineNo) {
|
|
285
|
+
const value = row?.[key];
|
|
286
|
+
if (typeof value !== 'string' || !value)
|
|
287
|
+
throw new Error(`Malformed session registry ${key} at line ${lineNo}`);
|
|
288
|
+
return value;
|
|
289
|
+
}
|
|
290
|
+
function normalizePatchEvent(row, lineNo) {
|
|
291
|
+
const id = requireId(row, lineNo);
|
|
292
|
+
const name = requireField(row, 'name', lineNo);
|
|
293
|
+
return { v: 1, op: 'patch', id, name, fields: assertPatchFields(row.fields), ...normalizeUnset(row.unset, lineNo) };
|
|
294
|
+
}
|
|
295
|
+
function normalizeUnset(raw, lineNo) {
|
|
296
|
+
if (raw === undefined)
|
|
297
|
+
return {};
|
|
298
|
+
if (!Array.isArray(raw) || raw.some(value => !PATCH_KEY_SET.has(value))) {
|
|
299
|
+
throw new Error(`Invalid session registry patch unset at line ${lineNo}`);
|
|
300
|
+
}
|
|
301
|
+
return raw.length ? { unset: raw } : {};
|
|
302
|
+
}
|
|
303
|
+
function normalizeBindEvent(row, lineNo) {
|
|
304
|
+
return {
|
|
305
|
+
v: 1,
|
|
306
|
+
op: 'bind',
|
|
307
|
+
channel: requireField(row, 'channel', lineNo),
|
|
308
|
+
sessionId: requireField(row, 'sessionId', lineNo),
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
function normalizeTurnEvent(row, lineNo) {
|
|
312
|
+
const channel = requireField(row, 'channel', lineNo);
|
|
313
|
+
const kind = row?.kind;
|
|
314
|
+
if (kind === 'begin')
|
|
315
|
+
return { v: 1, op: 'turn', channel, kind, turn: assertTurnRecord(row.turn) };
|
|
316
|
+
if (kind === 'patch')
|
|
317
|
+
return { v: 1, op: 'turn', channel, kind, turnIndex: toNumberValue(row.turnIndex), fields: assertPartialTurn(row.fields) };
|
|
318
|
+
if (kind === 'truncate')
|
|
319
|
+
return { v: 1, op: 'turn', channel, kind, fromIndex: toNumberValue(row.fromIndex) };
|
|
320
|
+
if (kind === 'clear')
|
|
321
|
+
return { v: 1, op: 'turn', channel, kind };
|
|
322
|
+
throw new Error(`Unknown session registry turn kind at line ${lineNo}`);
|
|
323
|
+
}
|
|
324
|
+
function normalizeConversationEvent(row, lineNo) {
|
|
325
|
+
const channel = requireField(row, 'channel', lineNo);
|
|
326
|
+
const kind = row?.kind;
|
|
327
|
+
if (kind === 'set')
|
|
328
|
+
return { v: 1, op: 'conversation', channel, kind, fields: assertConversationFields(row.fields) };
|
|
329
|
+
if (kind === 'clear')
|
|
330
|
+
return { v: 1, op: 'conversation', channel, kind };
|
|
331
|
+
throw new Error(`Unknown session registry conversation kind at line ${lineNo}`);
|
|
332
|
+
}
|
|
250
333
|
function normalizeDeleteCleanup(raw) {
|
|
251
334
|
if (raw === undefined)
|
|
252
335
|
return { claudeBackupPaths: [] };
|
|
@@ -278,6 +361,7 @@ function assertSessionRecord(raw, expectedId) {
|
|
|
278
361
|
scheduleId: toOptionalNullableString(row?.scheduleId),
|
|
279
362
|
commissionId: toOptionalNullableString(row?.commissionId),
|
|
280
363
|
commissionDraft: toOptionalNullableString(row?.commissionDraft),
|
|
364
|
+
commissionBlockFor: toOptionalNullableString(row?.commissionBlockFor),
|
|
281
365
|
contextUsage: row?.contextUsage,
|
|
282
366
|
browser: toOptionalBrowserValue(row?.browser),
|
|
283
367
|
};
|
|
@@ -304,6 +388,7 @@ function assertNewFormatRecord(raw, expectedId) {
|
|
|
304
388
|
scheduleId: toOptionalNullableString(row?.scheduleId),
|
|
305
389
|
commissionId: toOptionalNullableString(row?.commissionId),
|
|
306
390
|
commissionDraft: toOptionalNullableString(row?.commissionDraft),
|
|
391
|
+
commissionBlockFor: toOptionalNullableString(row?.commissionBlockFor),
|
|
307
392
|
contextUsage: row?.contextUsage,
|
|
308
393
|
browser: toOptionalBrowserValue(row?.browser),
|
|
309
394
|
};
|
|
@@ -353,6 +438,134 @@ function toOriginValue(value) {
|
|
|
353
438
|
return value;
|
|
354
439
|
throw new Error('Invalid session registry origin');
|
|
355
440
|
}
|
|
441
|
+
function toNumberValue(value) {
|
|
442
|
+
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
443
|
+
throw new Error('Invalid session registry number field');
|
|
444
|
+
return value;
|
|
445
|
+
}
|
|
446
|
+
/** Strict nullable string for turn fields: `null` stays null, a string stays a string, anything
|
|
447
|
+
* else (including undefined) is rejected. Unlike `toNullableString`, `''` is preserved. */
|
|
448
|
+
function toTurnNullableString(value) {
|
|
449
|
+
if (value === null)
|
|
450
|
+
return null;
|
|
451
|
+
if (typeof value === 'string')
|
|
452
|
+
return value;
|
|
453
|
+
throw new Error('Invalid session registry turn nullable string');
|
|
454
|
+
}
|
|
455
|
+
function toStringArray(value) {
|
|
456
|
+
if (!Array.isArray(value) || value.some(entry => typeof entry !== 'string')) {
|
|
457
|
+
throw new Error('Invalid session registry string array');
|
|
458
|
+
}
|
|
459
|
+
return [...value];
|
|
460
|
+
}
|
|
461
|
+
function toTurnStatus(value) {
|
|
462
|
+
if (value === 'processing' || value === 'completed' || value === 'superseded')
|
|
463
|
+
return value;
|
|
464
|
+
throw new Error('Invalid session registry turn status');
|
|
465
|
+
}
|
|
466
|
+
/** Whitelist for the `patch` payload. Every field a record can carry (minus identity) has a strict
|
|
467
|
+
* converter here; a key not listed is DROPPED on replay (the toOptionalBrowserValue trap, §8.1). */
|
|
468
|
+
const PATCH_FIELD_READERS = {
|
|
469
|
+
projectId: toStringValue,
|
|
470
|
+
channel: toStringValue,
|
|
471
|
+
backend: toStringValue,
|
|
472
|
+
kind: toKindValue,
|
|
473
|
+
origin: toOriginValue,
|
|
474
|
+
createdAt: toStringValue,
|
|
475
|
+
lastUsedAt: toStringValue,
|
|
476
|
+
label: toNullableString,
|
|
477
|
+
profileName: toNullableString,
|
|
478
|
+
backendSessionId: toOptionalNullableString,
|
|
479
|
+
lastReadAt: toOptionalNullableString,
|
|
480
|
+
scheduleId: toOptionalNullableString,
|
|
481
|
+
commissionId: toOptionalNullableString,
|
|
482
|
+
commissionDraft: toOptionalNullableString,
|
|
483
|
+
commissionBlockFor: toOptionalNullableString,
|
|
484
|
+
contextUsage: value => value,
|
|
485
|
+
browser: toOptionalBrowserValue,
|
|
486
|
+
};
|
|
487
|
+
/** Every key a `patch` may carry, derived from the exhaustive reader table so the WRITER (repo
|
|
488
|
+
* `diffRecord`) and the READER can never disagree: adding a field to SessionRecord without a
|
|
489
|
+
* reader is a compile error above, and the writer picks it up from here automatically. */
|
|
490
|
+
export const PATCH_KEYS = Object.keys(PATCH_FIELD_READERS);
|
|
491
|
+
const PATCH_KEY_SET = new Set(PATCH_KEYS);
|
|
492
|
+
function assertPatchFields(raw) {
|
|
493
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
494
|
+
throw new Error('Invalid session registry patch fields');
|
|
495
|
+
const row = raw;
|
|
496
|
+
const fields = {};
|
|
497
|
+
for (const key of Object.keys(row)) {
|
|
498
|
+
const reader = PATCH_FIELD_READERS[key];
|
|
499
|
+
if (!reader)
|
|
500
|
+
throw new Error(`Unknown session registry patch field: ${key}`);
|
|
501
|
+
fields[key] = reader(row[key]);
|
|
502
|
+
}
|
|
503
|
+
return fields;
|
|
504
|
+
}
|
|
505
|
+
function assertTurnRecord(raw) {
|
|
506
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
507
|
+
throw new Error('Invalid session registry turn record');
|
|
508
|
+
const row = raw;
|
|
509
|
+
return {
|
|
510
|
+
turnIndex: toNumberValue(row.turnIndex),
|
|
511
|
+
userMessageTs: toStringValue(row.userMessageTs),
|
|
512
|
+
userMessageText: toStringValue(row.userMessageText),
|
|
513
|
+
statusMessageTs: toTurnNullableString(row.statusMessageTs),
|
|
514
|
+
responseMessageTimestamps: toStringArray(row.responseMessageTimestamps),
|
|
515
|
+
executionId: toTurnNullableString(row.executionId),
|
|
516
|
+
backupPath: toTurnNullableString(row.backupPath),
|
|
517
|
+
status: toTurnStatus(row.status),
|
|
518
|
+
createdAt: toStringValue(row.createdAt),
|
|
519
|
+
updatedAt: toStringValue(row.updatedAt),
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
const TURN_FIELD_READERS = {
|
|
523
|
+
turnIndex: toNumberValue,
|
|
524
|
+
userMessageTs: toStringValue,
|
|
525
|
+
userMessageText: toStringValue,
|
|
526
|
+
statusMessageTs: toTurnNullableString,
|
|
527
|
+
responseMessageTimestamps: toStringArray,
|
|
528
|
+
executionId: toTurnNullableString,
|
|
529
|
+
backupPath: toTurnNullableString,
|
|
530
|
+
status: toTurnStatus,
|
|
531
|
+
createdAt: toStringValue,
|
|
532
|
+
updatedAt: toStringValue,
|
|
533
|
+
};
|
|
534
|
+
function assertPartialTurn(raw) {
|
|
535
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
536
|
+
throw new Error('Invalid session registry turn patch');
|
|
537
|
+
const row = raw;
|
|
538
|
+
const fields = {};
|
|
539
|
+
for (const key of Object.keys(row)) {
|
|
540
|
+
const reader = TURN_FIELD_READERS[key];
|
|
541
|
+
if (!reader)
|
|
542
|
+
throw new Error(`Unknown session registry turn field: ${key}`);
|
|
543
|
+
fields[key] = reader(row[key]);
|
|
544
|
+
}
|
|
545
|
+
return fields;
|
|
546
|
+
}
|
|
547
|
+
/** Whitelist for the `conversation set` payload. A key not listed is DROPPED on replay (the same
|
|
548
|
+
* toOptionalBrowserValue trap that silently lost fields, §8.1) — keep in lock-step with the header. */
|
|
549
|
+
const CONVERSATION_FIELD_READERS = {
|
|
550
|
+
sessionId: toTurnNullableString,
|
|
551
|
+
sessionName: toTurnNullableString,
|
|
552
|
+
backend: toStringValue,
|
|
553
|
+
profileName: toTurnNullableString,
|
|
554
|
+
updatedAt: toStringValue,
|
|
555
|
+
};
|
|
556
|
+
function assertConversationFields(raw) {
|
|
557
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
558
|
+
throw new Error('Invalid session registry conversation fields');
|
|
559
|
+
const row = raw;
|
|
560
|
+
const fields = {};
|
|
561
|
+
for (const key of Object.keys(row)) {
|
|
562
|
+
const reader = CONVERSATION_FIELD_READERS[key];
|
|
563
|
+
if (!reader)
|
|
564
|
+
throw new Error(`Unknown session registry conversation field: ${key}`);
|
|
565
|
+
fields[key] = reader(row[key]);
|
|
566
|
+
}
|
|
567
|
+
return fields;
|
|
568
|
+
}
|
|
356
569
|
function assertAppendableEvent(state, event) {
|
|
357
570
|
if (event.op === 'put')
|
|
358
571
|
assertPutAllowed(state, event.record);
|
|
@@ -360,6 +573,14 @@ function assertAppendableEvent(state, event) {
|
|
|
360
573
|
assertDeleteIntentAppendable(state, event.record);
|
|
361
574
|
if (event.op === 'delete-commit')
|
|
362
575
|
assertDeleteCommitAllowed(state, event.id);
|
|
576
|
+
if (event.op === 'patch')
|
|
577
|
+
assertPatchAppendable(state, event.id);
|
|
578
|
+
// bind / turn / conversation carry no liveness guard: they are channel-scoped and may name a
|
|
579
|
+
// session that is unknown, pending, or already gone (the free-map contract, §1).
|
|
580
|
+
}
|
|
581
|
+
function assertPatchAppendable(state, sessionId) {
|
|
582
|
+
if (!state.live.has(sessionId))
|
|
583
|
+
throw new Error(`Patch for non-live session: ${sessionId}`);
|
|
363
584
|
}
|
|
364
585
|
function assertPutAllowed(state, record) {
|
|
365
586
|
if (state.pending.has(record.sessionId)) {
|
|
@@ -391,7 +612,66 @@ function applyEvent(state, event) {
|
|
|
391
612
|
return applyPut(state, event.record);
|
|
392
613
|
if (event.op === 'delete-intent')
|
|
393
614
|
return applyDeleteIntent(state, event.record, event.cleanup);
|
|
394
|
-
|
|
615
|
+
if (event.op === 'delete-commit')
|
|
616
|
+
return applyDeleteCommit(state, event.id);
|
|
617
|
+
if (event.op === 'patch')
|
|
618
|
+
return applyPatch(state, event);
|
|
619
|
+
if (event.op === 'bind')
|
|
620
|
+
return applyBind(state, event.channel, event.sessionId);
|
|
621
|
+
if (event.op === 'unbind')
|
|
622
|
+
return applyUnbind(state, event.channel);
|
|
623
|
+
if (event.op === 'conversation')
|
|
624
|
+
return applyConversation(state, event);
|
|
625
|
+
applyTurn(state, event);
|
|
626
|
+
}
|
|
627
|
+
/** Lenient replay: a patch whose session is no longer live (deleted later, or a torn compaction
|
|
628
|
+
* reorder) is skipped rather than thrown — the strict guard lives in the append path. */
|
|
629
|
+
function applyPatch(state, event) {
|
|
630
|
+
const record = state.live.get(event.id);
|
|
631
|
+
if (!record)
|
|
632
|
+
return;
|
|
633
|
+
const next = { ...record, ...event.fields };
|
|
634
|
+
for (const key of event.unset ?? [])
|
|
635
|
+
delete next[key];
|
|
636
|
+
state.live.set(event.id, next);
|
|
637
|
+
}
|
|
638
|
+
/** Free-map bind: never gated on liveness — a channel may bind to an unknown, pending, or already
|
|
639
|
+
* committed session id, and it simply stays until unbind or delete-commit. */
|
|
640
|
+
function applyBind(state, channel, sessionId) {
|
|
641
|
+
state.bindings.set(channel, sessionId);
|
|
642
|
+
}
|
|
643
|
+
function applyUnbind(state, channel) {
|
|
644
|
+
state.bindings.delete(channel);
|
|
645
|
+
}
|
|
646
|
+
/** Channel-keyed turns: independent of the session record. `clear` drops the channel's list. */
|
|
647
|
+
function applyTurn(state, event) {
|
|
648
|
+
const turns = state.turns.get(event.channel) ?? [];
|
|
649
|
+
if (event.kind === 'begin') {
|
|
650
|
+
turns.push(event.turn);
|
|
651
|
+
state.turns.set(event.channel, turns);
|
|
652
|
+
}
|
|
653
|
+
else if (event.kind === 'patch') {
|
|
654
|
+
const idx = turns.findIndex(turn => turn.turnIndex === event.turnIndex);
|
|
655
|
+
if (idx >= 0)
|
|
656
|
+
turns[idx] = { ...turns[idx], ...event.fields };
|
|
657
|
+
}
|
|
658
|
+
else if (event.kind === 'truncate') {
|
|
659
|
+
state.turns.set(event.channel, turns.filter(turn => turn.turnIndex < event.fromIndex));
|
|
660
|
+
}
|
|
661
|
+
else {
|
|
662
|
+
state.turns.delete(event.channel);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
/** Channel-keyed conversation header. `set` merges the payload onto the previous header (or onto a
|
|
666
|
+
* null base if the channel had none); `clear` drops the header. */
|
|
667
|
+
function applyConversation(state, event) {
|
|
668
|
+
if (event.kind === 'clear') {
|
|
669
|
+
state.conversations.delete(event.channel);
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
const base = state.conversations.get(event.channel)
|
|
673
|
+
?? { sessionId: null, sessionName: null, backend: '', profileName: null, updatedAt: '' };
|
|
674
|
+
state.conversations.set(event.channel, { ...base, ...event.fields });
|
|
395
675
|
}
|
|
396
676
|
function applyPut(state, record) {
|
|
397
677
|
const previous = state.live.get(record.sessionId);
|
|
@@ -410,6 +690,15 @@ function applyDeleteIntent(state, record, cleanup = { claudeBackupPaths: [] }) {
|
|
|
410
690
|
function applyDeleteCommit(state, sessionId) {
|
|
411
691
|
assertDeleteCommitAllowed(state, sessionId);
|
|
412
692
|
state.pending.delete(sessionId);
|
|
693
|
+
// A committed session keeps nothing on any channel bound to it: binding, turn history and the
|
|
694
|
+
// conversation header are all dropped together (§1, §3). Unbind alone never touches turns/header.
|
|
695
|
+
for (const [channel, boundId] of state.bindings) {
|
|
696
|
+
if (boundId !== sessionId)
|
|
697
|
+
continue;
|
|
698
|
+
state.bindings.delete(channel);
|
|
699
|
+
state.turns.delete(channel);
|
|
700
|
+
state.conversations.delete(channel);
|
|
701
|
+
}
|
|
413
702
|
}
|
|
414
703
|
async function appendLineWithRollback(filePath, line, writer) {
|
|
415
704
|
const handle = await fsp.open(filePath, 'a+');
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { SessionContextUsage } from '../core/types/agent-types.js';
|
|
2
|
-
import { deriveSessionOrigin, type SessionDeleteCleanup, type SessionBrowserOption, type SessionOrigin, type SessionRecord, type SessionRegistryJournalOptions } from './session-registry-journal.js';
|
|
2
|
+
import { deriveSessionOrigin, type ConversationFields, type ConversationHeader, type SessionDeleteCleanup, type SessionBrowserOption, type SessionOrigin, type SessionRecord, type SessionRegistryJournalOptions, type TurnRecord } from './session-registry-journal.js';
|
|
3
3
|
export declare const REGISTRY_FILE: string;
|
|
4
|
-
export { deriveSessionOrigin, type SessionOrigin };
|
|
4
|
+
export { deriveSessionOrigin, type SessionOrigin, type TurnRecord, type ConversationFields, type ConversationHeader, };
|
|
5
|
+
/** In-memory channel→sessionId resolver (never persisted). A resolver that returns a string wins
|
|
6
|
+
* over any persisted bind; returning `null`/`undefined` falls through to the next resolver, then to
|
|
7
|
+
* the persisted bindings index. Registered by conduit-aware platforms (TUI, app.ts). */
|
|
8
|
+
export type ConduitResolver = (channel: string) => string | null | undefined;
|
|
5
9
|
export interface Session extends Omit<SessionRecord, 'contextUsage'> {
|
|
6
10
|
contextUsage?: SessionContextUsage;
|
|
7
11
|
}
|
|
@@ -14,6 +18,39 @@ export type SessionRegistryRepoOptions = SessionRegistryJournalOptions;
|
|
|
14
18
|
type UpdateFields = Partial<Pick<Session, 'lastUsedAt' | 'label' | 'profileName' | 'backendSessionId' | 'contextUsage' | 'browser'>> & {
|
|
15
19
|
sessionId?: never;
|
|
16
20
|
};
|
|
21
|
+
export interface RegisterSessionOpts {
|
|
22
|
+
sessionId: string;
|
|
23
|
+
channel: string;
|
|
24
|
+
backend: string;
|
|
25
|
+
kind: 'local' | 'scheduled';
|
|
26
|
+
origin?: SessionOrigin;
|
|
27
|
+
projectId?: string;
|
|
28
|
+
label?: string | null;
|
|
29
|
+
profileName?: string | null;
|
|
30
|
+
backendSessionId?: string | null;
|
|
31
|
+
scheduleId?: string | null;
|
|
32
|
+
browser?: SessionBrowserOption | null;
|
|
33
|
+
commissionId?: string | null;
|
|
34
|
+
commissionDraft?: string | null;
|
|
35
|
+
}
|
|
36
|
+
/** Mutators available inside `batch(fn)` — each shares the one locked state so several events land
|
|
37
|
+
* in a single critical section (§5). Read APIs are not exposed; read from the returned records. */
|
|
38
|
+
export interface SessionRegistryBatch {
|
|
39
|
+
registerSession(name: string, opts: RegisterSessionOpts): Promise<void>;
|
|
40
|
+
updateSession(name: string, updates: UpdateFields): Promise<void>;
|
|
41
|
+
updateById(sessionId: string, mutate: (record: Session) => Session): Promise<Session | null>;
|
|
42
|
+
bindChannel(channel: string, sessionId: string): Promise<void>;
|
|
43
|
+
unbindChannel(channel: string): Promise<void>;
|
|
44
|
+
beginTurn(channel: string, turn: TurnRecord): Promise<void>;
|
|
45
|
+
patchTurn(channel: string, turnIndex: number, fields: Partial<TurnRecord>): Promise<void>;
|
|
46
|
+
truncateTurns(channel: string, fromIndex: number): Promise<void>;
|
|
47
|
+
clearTurns(channel: string): Promise<void>;
|
|
48
|
+
setConversation(channel: string, fields: ConversationFields): Promise<void>;
|
|
49
|
+
clearConversation(channel: string): Promise<void>;
|
|
50
|
+
/** Synchronous reads off the shared locked state — let a façade find-turn / set-if-missing atomically. */
|
|
51
|
+
getTurns(channel: string): TurnRecord[];
|
|
52
|
+
getConversationHeader(channel: string): ConversationHeader | null;
|
|
53
|
+
}
|
|
17
54
|
export declare function effectiveBackendSessionId(rec: Pick<Session, 'sessionId' | 'backendSessionId'>): string | null;
|
|
18
55
|
export declare class SessionRegistryRepo {
|
|
19
56
|
private readonly filePath;
|
|
@@ -21,28 +58,16 @@ export declare class SessionRegistryRepo {
|
|
|
21
58
|
private readonly options;
|
|
22
59
|
private state;
|
|
23
60
|
private loaded;
|
|
24
|
-
private
|
|
61
|
+
private conduitResolvers;
|
|
25
62
|
constructor(filePath?: string, options?: SessionRegistryRepoOptions);
|
|
26
63
|
generateSessionName(): Promise<string>;
|
|
27
|
-
registerSession(name: string, opts:
|
|
28
|
-
|
|
29
|
-
channel: string;
|
|
30
|
-
backend: string;
|
|
31
|
-
kind: 'local' | 'scheduled';
|
|
32
|
-
origin?: SessionOrigin;
|
|
33
|
-
projectId?: string;
|
|
34
|
-
label?: string | null;
|
|
35
|
-
profileName?: string | null;
|
|
36
|
-
backendSessionId?: string | null;
|
|
37
|
-
scheduleId?: string | null;
|
|
38
|
-
browser?: SessionBrowserOption | null;
|
|
39
|
-
commissionId?: string | null;
|
|
40
|
-
commissionDraft?: string | null;
|
|
41
|
-
}): Promise<void>;
|
|
64
|
+
registerSession(name: string, opts: RegisterSessionOpts): Promise<void>;
|
|
65
|
+
private doRegisterSession;
|
|
42
66
|
convertToDirect(sessionId: string, opts: {
|
|
43
67
|
channel: string;
|
|
44
68
|
}): Promise<Session | null>;
|
|
45
69
|
updateSession(name: string, updates: UpdateFields): Promise<void>;
|
|
70
|
+
private doUpdateSession;
|
|
46
71
|
updateContextUsage(sessionId: string, usage: SessionContextUsage | null): Promise<void>;
|
|
47
72
|
lookupSession(name: string): Promise<Session | null>;
|
|
48
73
|
lookupBySessionId(sessionId: string): Promise<string | null>;
|
|
@@ -51,30 +76,90 @@ export declare class SessionRegistryRepo {
|
|
|
51
76
|
listByProject(projectId: string): Promise<Session[]>;
|
|
52
77
|
listByOrigin(origin: SessionOrigin, projectId?: string): Promise<Session[]>;
|
|
53
78
|
listResumable(projectId?: string): Promise<Session[]>;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
79
|
+
/** Storage primitive behind use-count admission — the in-memory counter and lease semantics live
|
|
80
|
+
* in `@domain/sessions/session-use.ts`. Patches `lastUsedAt=now` iff the session is live and NOT
|
|
81
|
+
* pending deletion; returns whether the touch landed. */
|
|
82
|
+
touchSessionUse(sessionId: string): Promise<boolean>;
|
|
58
83
|
markRead(sessionId: string): Promise<void>;
|
|
59
84
|
/** Bind (or unbind with null) a session to a commission. Called by the commission finalize path
|
|
60
85
|
* (DR-0037) and by commission-mode session creation. Binding also clears commissionDraft: once
|
|
61
|
-
* the contract is named, the draft directory no longer exists under that name.
|
|
86
|
+
* the contract is named, the draft directory no longer exists under that name.
|
|
87
|
+
*
|
|
88
|
+
* `commissionBlockFor` is deliberately left alone: binding CHANGES the key (`draft:x` →
|
|
89
|
+
* `active:id`), and that mismatch is exactly what makes the next turn deliver the active block. */
|
|
62
90
|
bindCommission(sessionId: string, commissionId: string | null): Promise<Session | null>;
|
|
91
|
+
/** Enter (or leave, with null) the drafting half of commission mode. Called by
|
|
92
|
+
* `cortex_commission_start`, by the composer's "new" on a live session, and by session creation.
|
|
93
|
+
* Refuses to touch a session already bound to a commission — that is a terminal state. */
|
|
94
|
+
setCommissionDraft(sessionId: string, draftDir: string | null): Promise<Session | null>;
|
|
95
|
+
/** Record that the `[Commission]` block for `key` is now in this session's backend history. */
|
|
96
|
+
markCommissionBlockDelivered(sessionId: string, key: string): Promise<Session | null>;
|
|
97
|
+
/** Forget the delivery marker so the next turn re-injects the block. Called after compaction,
|
|
98
|
+
* which drops the copy that was in backend history. */
|
|
99
|
+
clearCommissionBlockDelivery(sessionId: string): Promise<Session | null>;
|
|
100
|
+
/** Register an in-memory conduit resolver. Never persisted; a resolver answer wins over a
|
|
101
|
+
* persisted bind (§6). Returns an unregister callback. */
|
|
102
|
+
registerConduitResolver(fn: ConduitResolver): () => void;
|
|
103
|
+
/** Resolve the conversation session for a channel: in-memory resolvers first (a string wins),
|
|
104
|
+
* then the persisted bindings index. */
|
|
105
|
+
getBoundSessionId(channel: string): Promise<string | null>;
|
|
106
|
+
bindChannel(channel: string, sessionId: string): Promise<void>;
|
|
107
|
+
unbindChannel(channel: string): Promise<void>;
|
|
108
|
+
/** Remove every binding pointing at one of `sessionIds`. Used when sessions are torn down.
|
|
109
|
+
* Returns the number of bindings removed. */
|
|
110
|
+
unbindBySessionIds(sessionIds: Iterable<string>): Promise<number>;
|
|
111
|
+
listBindings(): Promise<Array<{
|
|
112
|
+
channel: string;
|
|
113
|
+
sessionId: string;
|
|
114
|
+
}>>;
|
|
115
|
+
beginTurn(channel: string, turn: TurnRecord): Promise<void>;
|
|
116
|
+
patchTurn(channel: string, turnIndex: number, fields: Partial<TurnRecord>): Promise<void>;
|
|
117
|
+
truncateTurns(channel: string, fromIndex: number): Promise<void>;
|
|
118
|
+
clearTurns(channel: string): Promise<void>;
|
|
119
|
+
getTurns(channel: string): Promise<TurnRecord[]>;
|
|
120
|
+
findTurn(channel: string, pred: (turn: TurnRecord) => boolean): Promise<TurnRecord | null>;
|
|
121
|
+
getConversationHeader(channel: string): Promise<ConversationHeader | null>;
|
|
122
|
+
setConversation(channel: string, fields: ConversationFields): Promise<void>;
|
|
123
|
+
clearConversation(channel: string): Promise<void>;
|
|
124
|
+
/** Header + turns for a channel under ONE lock (or null when the channel has no header). */
|
|
125
|
+
readConversation(channel: string): Promise<{
|
|
126
|
+
header: ConversationHeader;
|
|
127
|
+
turns: TurnRecord[];
|
|
128
|
+
} | null>;
|
|
129
|
+
/** Every channel that has a conversation header, with its turns — one lock for the whole scan. */
|
|
130
|
+
listConversations(): Promise<Array<{
|
|
131
|
+
channel: string;
|
|
132
|
+
header: ConversationHeader;
|
|
133
|
+
turns: TurnRecord[];
|
|
134
|
+
}>>;
|
|
135
|
+
/** Run several mutations under ONE admission lock (T2/T3 need put+bind+turn atomically — never a
|
|
136
|
+
* put without its bind, §5). The ops mirror the top-level mutators but share the locked state. */
|
|
137
|
+
batch<T>(fn: (ops: SessionRegistryBatch) => Promise<T>): Promise<T>;
|
|
138
|
+
private batchOps;
|
|
139
|
+
private doBindChannel;
|
|
140
|
+
private doUnbindChannel;
|
|
141
|
+
private doBeginTurn;
|
|
142
|
+
private doPatchTurn;
|
|
143
|
+
private doTruncateTurns;
|
|
144
|
+
private doClearTurns;
|
|
145
|
+
private doSetConversation;
|
|
146
|
+
private doClearConversation;
|
|
63
147
|
listPendingDeletions(): Promise<PendingDeletion[]>;
|
|
64
|
-
beginDeleteExpired(cutoff: number | Date, protectedIds: Iterable<string>, prepareCleanup?: (session: Session) => Promise<SessionDeleteCleanup>): Promise<PendingDeletion[]>;
|
|
148
|
+
beginDeleteExpired(cutoff: number | Date, protectedIds: Iterable<string>, prepareCleanup?: (session: Session, turns: TurnRecord[]) => Promise<SessionDeleteCleanup>): Promise<PendingDeletion[]>;
|
|
65
149
|
commitDeletion(sessionId: string): Promise<boolean>;
|
|
66
|
-
pruneStale(maxAgeMs: number): Promise<number>;
|
|
67
|
-
setOnPruneSession(_fn: ((sessionId: string) => void) | null): void;
|
|
68
150
|
compactNow(): Promise<void>;
|
|
69
|
-
/** `backend` is accepted and ignored — a channel has one session.
|
|
151
|
+
/** `backend` is accepted and ignored — a channel has one session. Pure in-registry lookup:
|
|
152
|
+
* the channel's bound sessionId → the live record's name. */
|
|
70
153
|
getActiveSessionName(channel: string, backend?: string): Promise<string | null>;
|
|
71
154
|
invalidate(): void;
|
|
72
155
|
flush(): Promise<void>;
|
|
73
156
|
private withState;
|
|
74
157
|
private loadState;
|
|
75
|
-
private appendPut;
|
|
76
158
|
private writePut;
|
|
77
159
|
private updateById;
|
|
160
|
+
private doUpdateById;
|
|
161
|
+
/** Append a `patch` for the delta between `current` (live) and `next`. No-op when nothing changed. */
|
|
162
|
+
private writePatch;
|
|
78
163
|
private maybeCompact;
|
|
79
164
|
}
|
|
80
165
|
export declare const sessionStore: SessionRegistryRepo;
|