synabun 2.4.3 → 2.4.4
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/CHANGELOG.md +19 -0
- package/README.md +1 -1
- package/docs/browser-extension-bridge.md +61 -32
- package/mcp-server/dist/http.d.ts.map +1 -1
- package/mcp-server/dist/http.js +8 -1
- package/mcp-server/dist/http.js.map +1 -1
- package/mcp-server/dist/services/identity.d.ts +2 -0
- package/mcp-server/dist/services/identity.d.ts.map +1 -1
- package/mcp-server/dist/services/identity.js +4 -0
- package/mcp-server/dist/services/identity.js.map +1 -1
- package/mcp-server/dist/services/memory-client.d.ts +5 -0
- package/mcp-server/dist/services/memory-client.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-client.js +21 -2
- package/mcp-server/dist/services/memory-client.js.map +1 -1
- package/mcp-server/dist/services/memory-writer.d.ts +3 -0
- package/mcp-server/dist/services/memory-writer.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-writer.js +7 -1
- package/mcp-server/dist/services/memory-writer.js.map +1 -1
- package/mcp-server/dist/services/neural-interface.d.ts +11 -1
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +67 -17
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/services/typesafe-config.d.ts +38 -2
- package/mcp-server/dist/services/typesafe-config.d.ts.map +1 -1
- package/mcp-server/dist/services/typesafe-config.js +260 -8
- package/mcp-server/dist/services/typesafe-config.js.map +1 -1
- package/mcp-server/dist/tools/agent-definition.d.ts +2 -2
- package/mcp-server/dist/tools/agents.d.ts +3 -1
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +11 -6
- package/mcp-server/dist/tools/agents.js.map +1 -1
- package/mcp-server/dist/tools/browser-observe.d.ts +11 -0
- package/mcp-server/dist/tools/browser-observe.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-observe.js +113 -27
- package/mcp-server/dist/tools/browser-observe.js.map +1 -1
- package/mcp-server/dist/tools/browser-readers.d.ts +6 -0
- package/mcp-server/dist/tools/browser-readers.d.ts.map +1 -0
- package/mcp-server/dist/tools/browser-readers.js +17 -0
- package/mcp-server/dist/tools/browser-readers.js.map +1 -0
- package/mcp-server/dist/tools/remember.d.ts.map +1 -1
- package/mcp-server/dist/tools/remember.js +6 -2
- package/mcp-server/dist/tools/remember.js.map +1 -1
- package/mcp-server/dist/tools/youtube/analytics.d.ts +4 -0
- package/mcp-server/dist/tools/youtube/analytics.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/analytics.js +25 -20
- package/mcp-server/dist/tools/youtube/analytics.js.map +1 -1
- package/mcp-server/dist/tools/youtube/helpers.d.ts +5 -1
- package/mcp-server/dist/tools/youtube/helpers.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/helpers.js +7 -3
- package/mcp-server/dist/tools/youtube/helpers.js.map +1 -1
- package/mcp-server/dist/tools/youtube/navigate.d.ts +2 -0
- package/mcp-server/dist/tools/youtube/navigate.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/navigate.js +5 -3
- package/mcp-server/dist/tools/youtube/navigate.js.map +1 -1
- package/mcp-server/dist/tools/youtube/playlist.js +2 -2
- package/mcp-server/dist/tools/youtube/playlist.js.map +1 -1
- package/mcp-server/dist/tools/youtube/readers.d.ts +4 -0
- package/mcp-server/dist/tools/youtube/readers.d.ts.map +1 -0
- package/mcp-server/dist/tools/youtube/readers.js +15 -0
- package/mcp-server/dist/tools/youtube/readers.js.map +1 -0
- package/mcp-server/package-lock.json +2 -2
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/http.ts +8 -1
- package/mcp-server/src/services/identity.ts +5 -0
- package/mcp-server/src/services/memory-client.ts +32 -12
- package/mcp-server/src/services/memory-writer.ts +5 -2
- package/mcp-server/src/services/neural-interface.ts +65 -18
- package/mcp-server/src/services/typesafe-config.ts +268 -7
- package/mcp-server/src/tools/agents.ts +12 -6
- package/mcp-server/src/tools/browser-observe.ts +117 -28
- package/mcp-server/src/tools/browser-readers.ts +19 -0
- package/mcp-server/src/tools/remember.ts +6 -1
- package/mcp-server/src/tools/youtube/analytics.ts +26 -28
- package/mcp-server/src/tools/youtube/helpers.ts +8 -2
- package/mcp-server/src/tools/youtube/navigate.ts +6 -7
- package/mcp-server/src/tools/youtube/playlist.ts +2 -2
- package/mcp-server/src/tools/youtube/readers.ts +15 -0
- package/neural-interface/i18n/en.json +139 -0
- package/neural-interface/i18n/pt-BR.json +139 -0
- package/neural-interface/lib/assistant-api.js +90 -0
- package/neural-interface/lib/assistant-brains/claude.js +10 -0
- package/neural-interface/lib/assistant-dispatch.js +276 -42
- package/neural-interface/lib/assistant-memory.js +3 -1
- package/neural-interface/lib/assistant-persona.js +6 -0
- package/neural-interface/lib/assistant-router.js +18 -8
- package/neural-interface/lib/assistant-runtime.js +87 -1
- package/neural-interface/lib/assistant-task-prompt.js +15 -2
- package/neural-interface/lib/browser-connection-state.js +20 -0
- package/neural-interface/lib/browser-extension-adapter.js +221 -15
- package/neural-interface/lib/browser-extension-bridge.js +40 -7
- package/neural-interface/lib/browser-extension-folder.js +50 -11
- package/neural-interface/lib/browser-extension-package.js +6 -5
- package/neural-interface/lib/browser-extension-pin.json +15 -13
- package/neural-interface/lib/browser-extension-protocol.js +111 -13
- package/neural-interface/lib/browser-extension-setup.js +7 -5
- package/neural-interface/lib/browser-extension-update.js +104 -0
- package/neural-interface/lib/browser-extraction.js +38 -14
- package/neural-interface/lib/claude-bg-tasks.js +183 -0
- package/neural-interface/lib/claude-history.js +12 -1
- package/neural-interface/lib/confined-fs.js +25 -0
- package/neural-interface/lib/coordination/operations.js +2 -0
- package/neural-interface/lib/db.js +39 -16
- package/neural-interface/lib/editor-completion-opencode.js +2 -2
- package/neural-interface/lib/git-bash/manager.js +28 -3
- package/neural-interface/lib/git-status-runner.js +31 -3
- package/neural-interface/lib/loop-inventory.js +162 -0
- package/neural-interface/lib/loop-stall.js +74 -4
- package/neural-interface/lib/memory-session-capture.js +157 -66
- package/neural-interface/lib/native-loop-providers.js +73 -13
- package/neural-interface/lib/native-loop-runtime.js +3 -0
- package/neural-interface/lib/opencode-protocol.js +4 -2
- package/neural-interface/lib/peer-identity.js +62 -16
- package/neural-interface/lib/session-cache-builder.js +66 -18
- package/neural-interface/lib/session-capture-gate.js +42 -0
- package/neural-interface/lib/session-indexer.js +28 -20
- package/neural-interface/lib/teams/scheduler.js +3 -2
- package/neural-interface/lib/ui-blob-api.js +14 -5
- package/neural-interface/lib/ui-blob-store.js +302 -39
- package/neural-interface/package-lock.json +2 -2
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/extension-setup.html +1 -0
- package/neural-interface/public/shared/assistant/asst-agents-dock.js +4 -0
- package/neural-interface/public/shared/assistant/asst-api.js +42 -0
- package/neural-interface/public/shared/assistant/asst-composer.js +85 -12
- package/neural-interface/public/shared/assistant/asst-panel.js +285 -10
- package/neural-interface/public/shared/assistant/asst-render.js +205 -4
- package/neural-interface/public/shared/assistant/asst-scenes.js +12 -0
- package/neural-interface/public/shared/assistant/asst-sidepanel.js +18 -1
- package/neural-interface/public/shared/assistant/asst-state.js +241 -2
- package/neural-interface/public/shared/assistant/asst-steer.js +294 -0
- package/neural-interface/public/shared/assistant/asst-styles.js +20 -0
- package/neural-interface/public/shared/bg-tasks/bg-tasks-claude.js +147 -0
- package/neural-interface/public/shared/bg-tasks/bg-tasks-model.js +527 -0
- package/neural-interface/public/shared/bg-tasks/bg-tasks-panel.js +161 -0
- package/neural-interface/public/shared/bg-tasks/bg-tasks-view.js +508 -0
- package/neural-interface/public/shared/browser-extension-updates.js +88 -0
- package/neural-interface/public/shared/cp/cp-bg-tasks.js +130 -0
- package/neural-interface/public/shared/extension-setup/es-page.js +18 -11
- package/neural-interface/public/shared/extension-update-view.js +34 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-logic.js +8 -4
- package/neural-interface/public/shared/settings/settings-browser-extension.js +10 -4
- package/neural-interface/public/shared/settings/settings-extension-update.js +114 -0
- package/neural-interface/public/shared/styles.css +4 -0
- package/neural-interface/public/shared/ui-claude-panel.js +110 -1
- package/neural-interface/public/shared/ui-notifications.js +23 -4
- package/neural-interface/public/shared/ui-settings-entry.js +6 -0
- package/neural-interface/public/shared/ui-tray-columns.js +9 -2
- package/neural-interface/public/shared/worker-end.js +18 -0
- package/neural-interface/scripts/patch-node-pty.mjs +151 -0
- package/neural-interface/scripts/rebuild-pty.js +10 -0
- package/neural-interface/server.js +483 -280
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -709,6 +709,12 @@ export async function createClaudeNativeLoopAdapter(options = {}) {
|
|
|
709
709
|
let alive = true;
|
|
710
710
|
let sessionId = null;
|
|
711
711
|
let activeTurn = null;
|
|
712
|
+
// Results the CLI still owes for turns a steer cut (abort('steered')): each interrupted prompt ends with one result
|
|
713
|
+
// of its own, which must not settle the turn sent after it.
|
|
714
|
+
let staleResults = 0;
|
|
715
|
+
// A turn still waiting to start (the MCP scope check) has no prompt at the CLI yet: an abort then ends it before
|
|
716
|
+
// the prompt goes ({ reason } while it waits, read once runTurn may send).
|
|
717
|
+
let startingTurn = null;
|
|
712
718
|
// The session's live background tasks (shells, Monitors, agents): what a turn of this run waits for.
|
|
713
719
|
const bgTasks = createBackgroundTasks();
|
|
714
720
|
const holdLimits = backgroundHold && typeof backgroundHold === 'object' ? { ...BACKGROUND_HOLD_DEFAULTS, ...backgroundHold } : BACKGROUND_HOLD_DEFAULTS;
|
|
@@ -1087,6 +1093,7 @@ export async function createClaudeNativeLoopAdapter(options = {}) {
|
|
|
1087
1093
|
}
|
|
1088
1094
|
emitEvent(event);
|
|
1089
1095
|
bgTasks.apply(event, Date.now());
|
|
1096
|
+
if (event?.type === 'result' && staleResults > 0) { staleResults -= 1; continue; }
|
|
1090
1097
|
if (event?.type === 'result' && activeTurn) {
|
|
1091
1098
|
const turn = activeTurn;
|
|
1092
1099
|
const cost = turnCost(event);
|
|
@@ -1158,24 +1165,50 @@ export async function createClaudeNativeLoopAdapter(options = {}) {
|
|
|
1158
1165
|
});
|
|
1159
1166
|
});
|
|
1160
1167
|
|
|
1168
|
+
// The MCP scope check (only the servers this run may use are connected) before a prompt goes to the CLI. A CLI that
|
|
1169
|
+
// exited at once fails it too, with the CLI's own reason when it gave one.
|
|
1170
|
+
const scopeCheck = async () => {
|
|
1171
|
+
if (held) return;
|
|
1172
|
+
try { await waitForClaudeMcpScope(q, externalScopeNames); }
|
|
1173
|
+
catch {
|
|
1174
|
+
input.close(); q.close?.(); await endProcess();
|
|
1175
|
+
// A CLI that ended by itself said why: a resumed session with nothing saved is that, not an MCP problem.
|
|
1176
|
+
const ended = await Promise.race([pump.then(() => null, (error) => error), new Promise((done) => { const timer = setTimeout(done, 1000, null); timer.unref?.(); })]);
|
|
1177
|
+
const noConversation = /No conversation found with session ID[^\n]*/i.exec(`${ended?.message || ''}\n${stderrTail}`);
|
|
1178
|
+
if (noConversation) throw new Error(`Claude Code returned an error result: ${noConversation[0].trim()}`);
|
|
1179
|
+
throw Object.assign(new Error('Claude MCP scope could not be enforced before the first turn'), { code: 'MCP_SCOPE_UNENFORCED' });
|
|
1180
|
+
}
|
|
1181
|
+
};
|
|
1182
|
+
// ready()'s check, which the first turn takes instead of checking again (every later turn checks as before).
|
|
1183
|
+
let readyCheck = null;
|
|
1184
|
+
|
|
1161
1185
|
return {
|
|
1162
1186
|
identity: () => ({ providerSessionId: sessionId }),
|
|
1163
1187
|
isAlive: () => alive,
|
|
1188
|
+
// Review round 3, I1c-b: the runtime awaits this inside its startup window before it reports the run started
|
|
1189
|
+
// (NativeLoopRuntime._bootstrap), as the Codex, OpenCode and Antigravity factories finish their own startup before
|
|
1190
|
+
// they return. Without it a Claude worker read as started before its CLI had proved it runs with its MCP scope,
|
|
1191
|
+
// and a boot failure came only with the first turn, after the dispatcher had committed its single route.
|
|
1192
|
+
ready() {
|
|
1193
|
+
if (!readyCheck) { readyCheck = scopeCheck(); readyCheck.catch(() => {}); }
|
|
1194
|
+
return readyCheck;
|
|
1195
|
+
},
|
|
1164
1196
|
// The CLI's process while it runs ({ pid }), else null.
|
|
1165
1197
|
processInfo: () => (child?.pid && !processEnded() ? { pid: child.pid } : null),
|
|
1166
1198
|
describe: () => ({ provider: 'claude-code', permissionPolicy, capability, askMode, ...(held ? { confinement: held.kind, root: held.root, ...(evaluated ? { role: evaluated.role, skills: [...evalOptions.skills], plugins: evalOptions.plugins.map((plugin) => plugin.path) } : {}) } : {}), ...(guard ? { guard: { mode: guard.mode, capability: guard.capability, writable: [...guard.writable] } } : {}) }),
|
|
1167
1199
|
async runTurn(prompt, meta = {}) {
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
throw Object.assign(new Error('Claude MCP scope could not be enforced before the first turn'), { code: 'MCP_SCOPE_UNENFORCED' });
|
|
1177
|
-
}
|
|
1200
|
+
const starting = { reason: null };
|
|
1201
|
+
startingTurn = starting;
|
|
1202
|
+
const check = readyCheck || scopeCheck();
|
|
1203
|
+
readyCheck = null;
|
|
1204
|
+
try { await check; }
|
|
1205
|
+
catch (error) {
|
|
1206
|
+
if (startingTurn === starting) startingTurn = null;
|
|
1207
|
+
throw error;
|
|
1178
1208
|
}
|
|
1209
|
+
if (startingTurn === starting) startingTurn = null;
|
|
1210
|
+
// Aborted while it waited to start: the prompt never went to the CLI (no result is owed for it).
|
|
1211
|
+
if (starting.reason) throw Object.assign(asAbortError(starting.reason), { notSent: true });
|
|
1179
1212
|
if (!alive) return Promise.reject(new Error('Claude native loop is closed'));
|
|
1180
1213
|
if (activeTurn) return Promise.reject(new Error('Claude native loop already has an active turn'));
|
|
1181
1214
|
onEvent({
|
|
@@ -1201,10 +1234,13 @@ export async function createClaudeNativeLoopAdapter(options = {}) {
|
|
|
1201
1234
|
});
|
|
1202
1235
|
},
|
|
1203
1236
|
async abort(reason = 'aborted') {
|
|
1237
|
+
if (startingTurn && !activeTurn) { startingTurn.reason = reason; return true; }
|
|
1204
1238
|
if (activeTurn) {
|
|
1205
1239
|
const turn = activeTurn; activeTurn = null;
|
|
1206
1240
|
turn.hold?.cancel();
|
|
1207
1241
|
turn.reject(asAbortError(reason));
|
|
1242
|
+
// A steer keeps the session for the next prompt: the cut prompt's own result is not that one's.
|
|
1243
|
+
if (reason === 'steered' && alive) staleResults += 1;
|
|
1208
1244
|
}
|
|
1209
1245
|
if (!alive) return true;
|
|
1210
1246
|
try {
|
|
@@ -1338,6 +1374,12 @@ export async function createOpenCodeNativeLoopAdapter(options = {}) {
|
|
|
1338
1374
|
let alive = true;
|
|
1339
1375
|
let activeAbort = null;
|
|
1340
1376
|
let activeTurn = null;
|
|
1377
|
+
// The serve's end of a turn a steer cut, still owed ({ until, error }): see the event handler.
|
|
1378
|
+
let steerEcho = null;
|
|
1379
|
+
const isAbortEcho = (event) => {
|
|
1380
|
+
const error = event?.error || event?.info?.error || event?.data?.error || {};
|
|
1381
|
+
return /abort/i.test(String(error?.name || '')) || /turn was stopped/i.test(String(error?.data?.message || error?.message || ''));
|
|
1382
|
+
};
|
|
1341
1383
|
const eventSource = client.onEvent ? client : client.event;
|
|
1342
1384
|
let sessionId = null;
|
|
1343
1385
|
// Assistant text assembled from the SSE stream (message.updated gives roles,
|
|
@@ -1501,6 +1543,20 @@ export async function createOpenCodeNativeLoopAdapter(options = {}) {
|
|
|
1501
1543
|
// synchronous fetch open and misclassifying a long, healthy turn as
|
|
1502
1544
|
// `native:iteration-error | fetch failed`.
|
|
1503
1545
|
const ownsTurnEvent = !!sid && sid === sessionId;
|
|
1546
|
+
// A steer's abort (abort('steered')) ends the cut turn at the serve with "The turn was stopped (user)" and an
|
|
1547
|
+
// idle, which can arrive after the steer's own turn was sent: they are that cut turn's end, never this one's.
|
|
1548
|
+
if (ownsTurnEvent && steerEcho && Date.now() > steerEcho.until) steerEcho = null;
|
|
1549
|
+
if (ownsTurnEvent && steerEcho && /^session[.:]error$/i.test(eventType) && isAbortEcho(event)) {
|
|
1550
|
+
steerEcho.error = true;
|
|
1551
|
+
steerEcho.until = Math.min(steerEcho.until, Date.now() + 2000);
|
|
1552
|
+
onEvent({ provider: 'opencode', runId, eventType, event, steerEcho: true });
|
|
1553
|
+
return;
|
|
1554
|
+
}
|
|
1555
|
+
if (ownsTurnEvent && steerEcho?.error && /^session[.:]idle$/i.test(eventType)) {
|
|
1556
|
+
steerEcho = null;
|
|
1557
|
+
onEvent({ provider: 'opencode', runId, eventType, event, steerEcho: true });
|
|
1558
|
+
return;
|
|
1559
|
+
}
|
|
1504
1560
|
if (ownsTurnEvent && /^session[.:]idle$/i.test(eventType)) finishTurnWithText();
|
|
1505
1561
|
if (ownsTurnEvent && /^session[.:]error$/i.test(eventType)) {
|
|
1506
1562
|
const detail = providerErrorMessage(
|
|
@@ -1568,7 +1624,7 @@ export async function createOpenCodeNativeLoopAdapter(options = {}) {
|
|
|
1568
1624
|
activeAbort = controller;
|
|
1569
1625
|
const checkReady = async () => {
|
|
1570
1626
|
await client.waitUntilConnected?.(10_000);
|
|
1571
|
-
if (!alive || controller.signal.aborted) throw asAbortError('aborted');
|
|
1627
|
+
if (!alive || controller.signal.aborted) throw Object.assign(asAbortError('aborted'), { notSent: true });
|
|
1572
1628
|
const ready = await waitForSynabunTools(client, {
|
|
1573
1629
|
...(options.mcpWait || {}), directory: cwd || undefined,
|
|
1574
1630
|
expected: options.synabunExpected !== false && !held, signal: controller.signal,
|
|
@@ -1579,7 +1635,7 @@ export async function createOpenCodeNativeLoopAdapter(options = {}) {
|
|
|
1579
1635
|
onEvent({ provider: 'opencode', runId, eventType: 'synabun.mcp.status', event: { sessionID: sessionId, text } });
|
|
1580
1636
|
},
|
|
1581
1637
|
});
|
|
1582
|
-
if (!ready || controller.signal.aborted || !alive) throw asAbortError('aborted');
|
|
1638
|
+
if (!ready || controller.signal.aborted || !alive) throw Object.assign(asAbortError('aborted'), { notSent: true });
|
|
1583
1639
|
};
|
|
1584
1640
|
const request = {
|
|
1585
1641
|
sessionID: sessionId,
|
|
@@ -1653,6 +1709,9 @@ export async function createOpenCodeNativeLoopAdapter(options = {}) {
|
|
|
1653
1709
|
}
|
|
1654
1710
|
},
|
|
1655
1711
|
async abort(reason = 'aborted') {
|
|
1712
|
+
// Only a turn the serve already has ends there with an echo (a prompt not sent yet has nothing to stop).
|
|
1713
|
+
const sentTurn = !!activeTurn && (activeTurn.mode === 'sync' || activeTurn.sent);
|
|
1714
|
+
steerEcho = reason === 'steered' && sentTurn ? { until: Date.now() + 10_000, error: false } : null;
|
|
1656
1715
|
if (activeAbort) activeAbort.abort(asAbortError(reason));
|
|
1657
1716
|
settleActiveTurn(asAbortError(reason));
|
|
1658
1717
|
try {
|
|
@@ -1661,7 +1720,8 @@ export async function createOpenCodeNativeLoopAdapter(options = {}) {
|
|
|
1661
1720
|
// background, and its end wakes no model turn in a session nobody owns any more.
|
|
1662
1721
|
// What it gave up on goes back to the runtime (lib/native-loop-runtime.js stop), which keeps it on the run:
|
|
1663
1722
|
// its result, its tab and the brain then say that the command may still be running (review 29cd51fe).
|
|
1664
|
-
|
|
1723
|
+
// A steer cuts the turn only: the session goes on, so a command in the background is left to it (no force).
|
|
1724
|
+
const answer = await settleWithin(client.session.abort({ sessionID: sessionId, directory: cwd || undefined, ...(reason === 'steered' ? {} : { force: true }) }));
|
|
1665
1725
|
const abandoned = Array.isArray(answer?.data?.abandoned) ? answer.data.abandoned : [];
|
|
1666
1726
|
if (abandoned.length) {
|
|
1667
1727
|
return { stopped: true, abandoned: abandoned.map((shell) => ({ id: String(shell?.id || ''), command: String(shell?.command || '').slice(0, 200) })) };
|
|
@@ -626,6 +626,9 @@ export class NativeLoopRuntime {
|
|
|
626
626
|
await cleanupCandidate(adapter, 'invalid_adapter');
|
|
627
627
|
throw new Error(`${state.profile} native provider did not return a runnable adapter`);
|
|
628
628
|
}
|
|
629
|
+
// An adapter whose factory returns before its provider proved it runs (Claude Code: the CLI and its MCP scope)
|
|
630
|
+
// finishes its startup here, inside the same startup window and cancellation, before the run reads as started.
|
|
631
|
+
if (typeof adapter.ready === 'function') await Promise.race([adapter.ready(), startupTimeout, startupCancelled]);
|
|
629
632
|
if (record.status !== 'starting' || record.stopping) {
|
|
630
633
|
await cleanupCandidate(adapter, record.stoppedReason || 'startup_cancelled');
|
|
631
634
|
const cancelled = new Error(`${state.profile} native loop was stopped during provider startup`);
|
|
@@ -228,12 +228,14 @@ async function readJson(res) {
|
|
|
228
228
|
* 'error' something answered, but not OpenCode 2's API
|
|
229
229
|
* Never throws.
|
|
230
230
|
*/
|
|
231
|
-
export async function checkOpencodeServer({ port, password = null, fetchImpl = globalThis.fetch, timeoutMs = 2000, host = '127.0.0.1' } = {}) {
|
|
231
|
+
export async function checkOpencodeServer({ port, password = null, fetchImpl = globalThis.fetch, timeoutMs = 2000, host = '127.0.0.1', signal = null } = {}) {
|
|
232
232
|
let res;
|
|
233
233
|
try {
|
|
234
|
+
const timeout = AbortSignal.timeout(timeoutMs);
|
|
235
|
+
const reqSignal = signal ? AbortSignal.any([timeout, signal]) : timeout;
|
|
234
236
|
res = await fetchImpl(`http://${host}:${port}/api/info`, {
|
|
235
237
|
headers: { accept: 'application/json', ...(password ? { authorization: basicAuthHeader(password) } : {}) },
|
|
236
|
-
signal:
|
|
238
|
+
signal: reqSignal,
|
|
237
239
|
});
|
|
238
240
|
} catch (error) {
|
|
239
241
|
return { ok: false, version: null, state: 'down', error: String(error?.message || error) };
|
|
@@ -87,6 +87,11 @@ export const LOOKUP_CAP_MS = 2500;
|
|
|
87
87
|
/** How long a failed lookup is kept on its connection: a burst of requests is not looked up again each, an open tab
|
|
88
88
|
* is soon. */
|
|
89
89
|
export const NEGATIVE_TTL_MS = 2000;
|
|
90
|
+
/** The start probe's waits before it asks again after a failure that may pass (a timeout on a busy machine): only then
|
|
91
|
+
* is the server reported degraded. A denial (EPERM) is never asked again. */
|
|
92
|
+
export const PROBE_RETRY_DELAYS_MS = Object.freeze([250, 1000, 3000]);
|
|
93
|
+
/** While degraded by a failure that may pass, the probe runs again this often until it answers (or a denial follows). */
|
|
94
|
+
export const PROBE_RECHECK_MS = 5000;
|
|
90
95
|
const PS_SNAPSHOT_TTL_MS = 2000;
|
|
91
96
|
// A process's parents and command line do not change while it lives (a parent that exits leaves it to launchd, which
|
|
92
97
|
// only ever takes an agent or a browser out of the chain, never puts one in): kept half an hour, checked against
|
|
@@ -647,6 +652,8 @@ function defaultRun(file, args, { timeout, stderr: withStderr = false }) {
|
|
|
647
652
|
});
|
|
648
653
|
}
|
|
649
654
|
|
|
655
|
+
const defaultSleep = (ms) => new Promise((resolve) => { const t = setTimeout(resolve, ms); t.unref?.(); });
|
|
656
|
+
|
|
650
657
|
function thisMachineAddresses() {
|
|
651
658
|
const out = new Set(['127.0.0.1', '::1']);
|
|
652
659
|
try {
|
|
@@ -669,8 +676,11 @@ function thisMachineAddresses() {
|
|
|
669
676
|
* @param {(path:string) => string} [o.realpath] fs.realpathSync (tests inject one).
|
|
670
677
|
* @param {number} [o.lookupCapMs] the cap of one attempt (LOOKUP_CAP_MS; tests shorten it).
|
|
671
678
|
* @param {number} [o.negativeTtlMs] how long a failed lookup is kept on its connection (NEGATIVE_TTL_MS).
|
|
679
|
+
* @param {number[]} [o.probeRetryDelaysMs] waits between start-probe attempts after a failure that may pass.
|
|
680
|
+
* @param {number} [o.probeRecheckMs] how often a retryable-degraded server probes again (0: never).
|
|
681
|
+
* @param {(ms:number) => Promise<void>} [o.sleep] waits (tests inject one).
|
|
672
682
|
*/
|
|
673
|
-
export function createPeerIdentity({ platform = process.platform, selfPid = process.pid, run = defaultRun, localAddresses = null, log = () => {}, now = Date.now, disabled = false, synabunRoots = [], realpath = realpathSync, debugClient = null, lookupCapMs = LOOKUP_CAP_MS, negativeTtlMs = NEGATIVE_TTL_MS } = {}) {
|
|
683
|
+
export function createPeerIdentity({ platform = process.platform, selfPid = process.pid, run = defaultRun, localAddresses = null, log = () => {}, now = Date.now, disabled = false, synabunRoots = [], realpath = realpathSync, debugClient = null, lookupCapMs = LOOKUP_CAP_MS, negativeTtlMs = NEGATIVE_TTL_MS, probeRetryDelaysMs = PROBE_RETRY_DELAYS_MS, probeRecheckMs = PROBE_RECHECK_MS, sleep = defaultSleep } = {}) {
|
|
674
684
|
const supported = platform === 'darwin' && !disabled;
|
|
675
685
|
const capMs = Number.isFinite(lookupCapMs) && lookupCapMs > 0 ? lookupCapMs : LOOKUP_CAP_MS;
|
|
676
686
|
const ttlMs = Number.isFinite(negativeTtlMs) && negativeTtlMs >= 0 ? negativeTtlMs : NEGATIVE_TTL_MS;
|
|
@@ -748,31 +758,67 @@ export function createPeerIdentity({ platform = process.platform, selfPid = proc
|
|
|
748
758
|
function authorityState() {
|
|
749
759
|
return { state: authority.state, reason: authority.reason, retryable: authority.retryable === true, since: authority.since };
|
|
750
760
|
}
|
|
761
|
+
/** One sample of netstat and ps: `{ failures, retryable }` (retryable only when every failure may pass). */
|
|
762
|
+
async function probeOnce() {
|
|
763
|
+
const failures = [];
|
|
764
|
+
let transient = true;
|
|
765
|
+
try { await readNetstat(); } catch (error) {
|
|
766
|
+
failures.push(error?.netstatTable ? error.message : netstatFailure(error));
|
|
767
|
+
transient = transient && isTransientLookupError(error);
|
|
768
|
+
}
|
|
769
|
+
try {
|
|
770
|
+
const parents = parsePsParents(await run(PS, ['-Ao', 'pid=,ppid=,ucomm='], { timeout: PS_TIMEOUT_MS }));
|
|
771
|
+
if (!parents.size) { failures.push('ps listed no processes'); transient = false; }
|
|
772
|
+
else if (!parents.has(selfPid)) { failures.push('ps did not list this server'); transient = false; }
|
|
773
|
+
} catch (error) { failures.push(`ps: ${failureText(error)}`); transient = transient && isTransientLookupError(error); }
|
|
774
|
+
return { failures, retryable: failures.length > 0 && transient };
|
|
775
|
+
}
|
|
776
|
+
const retryDelays = (Array.isArray(probeRetryDelaysMs) ? probeRetryDelaysMs : PROBE_RETRY_DELAYS_MS).filter((ms) => Number.isFinite(ms) && ms >= 0);
|
|
777
|
+
const recheckMs = Number.isFinite(probeRecheckMs) && probeRecheckMs > 0 ? probeRecheckMs : 0;
|
|
778
|
+
let recheckTimer = null;
|
|
779
|
+
/** Probe again later while degraded by a failure that may pass; a later answer restores, a denial ends it. */
|
|
780
|
+
function scheduleRecheck() {
|
|
781
|
+
if (!recheckMs || recheckTimer) return;
|
|
782
|
+
recheckTimer = setTimeout(async () => {
|
|
783
|
+
recheckTimer = null;
|
|
784
|
+
if (authority.state !== 'degraded' || !authority.retryable) return;
|
|
785
|
+
let r;
|
|
786
|
+
try { r = await probeOnce(); } catch (error) { r = { failures: [`the probe failed (${error?.message || error})`], retryable: false }; }
|
|
787
|
+
if (authority.state !== 'degraded') return; // a lookup settled it meanwhile
|
|
788
|
+
if (!r.failures.length) restore('probe recheck');
|
|
789
|
+
else {
|
|
790
|
+
degrade(r.failures.join('; '), { retryable: r.retryable, source: 'probe recheck' });
|
|
791
|
+
if (authority.retryable) scheduleRecheck();
|
|
792
|
+
}
|
|
793
|
+
}, recheckMs);
|
|
794
|
+
recheckTimer.unref?.();
|
|
795
|
+
}
|
|
751
796
|
/**
|
|
752
|
-
* The start probe (server.js runs it once, at start): netstat and ps, as a lookup runs them. A failure
|
|
753
|
-
*
|
|
754
|
-
*
|
|
797
|
+
* The start probe (server.js runs it once, at start): netstat and ps, as a lookup runs them. A failure that may pass
|
|
798
|
+
* (a timeout under load) is asked again after each of `probeRetryDelaysMs`; only a failure that lasts is the degraded
|
|
799
|
+
* state, with its reason in the log and in GET /api/health, before any owner's request meets it; while it may still
|
|
800
|
+
* pass, the probe runs again every `probeRecheckMs` until it answers. A denial (EPERM) degrades at once and is never
|
|
801
|
+
* retried: the server keeps failing closed. Off macOS (or off) there is nothing to probe. Never rejects; asked
|
|
802
|
+
* twice, it runs once.
|
|
755
803
|
*/
|
|
756
804
|
function probe() {
|
|
757
805
|
if (!supported) return Promise.resolve(authorityState());
|
|
758
806
|
if (probed) return probed;
|
|
759
807
|
probed = (async () => {
|
|
760
|
-
|
|
761
|
-
let
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
808
|
+
let r = await probeOnce();
|
|
809
|
+
for (let i = 0; r.failures.length && r.retryable && i < retryDelays.length; i++) {
|
|
810
|
+
if (authority.state !== 'pending') break;
|
|
811
|
+
stats.retries++;
|
|
812
|
+
await sleep(retryDelays[i]);
|
|
813
|
+
r = await probeOnce();
|
|
765
814
|
}
|
|
766
|
-
try {
|
|
767
|
-
const parents = parsePsParents(await run(PS, ['-Ao', 'pid=,ppid=,ucomm='], { timeout: PS_TIMEOUT_MS }));
|
|
768
|
-
if (!parents.size) failures.push('ps listed no processes');
|
|
769
|
-
else if (!parents.has(selfPid)) failures.push('ps did not list this server');
|
|
770
|
-
} catch (error) { failures.push(`ps: ${failureText(error)}`); retryable = retryable || isTransientLookupError(error); }
|
|
771
815
|
// A request can finish its full lookup while this boot-time sample is in flight.
|
|
772
816
|
// Its observed outcome takes precedence over the preflight in either direction.
|
|
773
817
|
if (authority.state !== 'pending') return authorityState();
|
|
774
|
-
if (failures.length)
|
|
775
|
-
|
|
818
|
+
if (r.failures.length) {
|
|
819
|
+
degrade(r.failures.join('; '), { retryable: r.retryable, source: 'start probe' });
|
|
820
|
+
if (r.retryable) scheduleRecheck();
|
|
821
|
+
} else {
|
|
776
822
|
say('[peer-identity] start probe: netstat and ps answer; the owner\'s authority is checked against the calling process');
|
|
777
823
|
restore('start probe');
|
|
778
824
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { queueMemoryCapture } from './memory-session-capture.js';
|
|
2
|
+
import { fileIdentityOf, isSessionFileUnchanged, mtimeIsoOf } from './session-capture-gate.js';
|
|
2
3
|
import { normalizeMemoryEvents, ingestMemoryEvents, CAPTURE_TRANSACTION_MS, CAPTURE_PAUSE_MS } from '../../mcp-server/dist/services/memory-sessions.js';
|
|
3
4
|
import { detectProject } from '../../mcp-server/dist/config.js';
|
|
4
5
|
/**
|
|
@@ -200,20 +201,42 @@ function* scanClaudeCache({ project, onProgress }) {
|
|
|
200
201
|
total++;
|
|
201
202
|
const filePath = join(projDir.path, file);
|
|
202
203
|
let stat;
|
|
203
|
-
try { stat = statSync(filePath); } catch { continue; }
|
|
204
|
-
|
|
205
|
-
|
|
204
|
+
try { stat = statSync(filePath, { bigint: true }); } catch { continue; }
|
|
205
|
+
const fileSize = Number(stat.size);
|
|
206
206
|
const sessionId = file.replace('.jsonl', '');
|
|
207
|
-
queueMemoryCapture({host:'claude-code',sessionId,filePath,project:projDir.name});
|
|
208
207
|
const existing = getSessionCacheEntry(sessionId, 'claude-code');
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
208
|
+
|
|
209
|
+
// Decide memory capture from the capture checkpoint, independent of the search cache
|
|
210
|
+
// and its 50 MiB parser size limit.
|
|
211
|
+
queueMemoryCapture({
|
|
212
|
+
host: 'claude-code',
|
|
213
|
+
sessionId,
|
|
214
|
+
filePath,
|
|
215
|
+
cwd: existing?.project_path || undefined,
|
|
216
|
+
project: projDir.name,
|
|
217
|
+
size: fileSize,
|
|
218
|
+
stat,
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
if (fileSize > MAX_CLAUDE_FILE) continue;
|
|
222
|
+
|
|
223
|
+
if (isSessionFileUnchanged(existing, stat)) continue;
|
|
212
224
|
|
|
213
225
|
const parsed = parseClaudeSession(filePath);
|
|
214
226
|
if (!parsed) continue;
|
|
215
227
|
|
|
216
|
-
|
|
228
|
+
if (parsed.sessionId !== sessionId || (parsed.cwd && parsed.cwd !== existing?.project_path)) {
|
|
229
|
+
queueMemoryCapture({
|
|
230
|
+
host: 'claude-code',
|
|
231
|
+
sessionId: parsed.sessionId,
|
|
232
|
+
filePath,
|
|
233
|
+
cwd: parsed.cwd,
|
|
234
|
+
project: projDir.name,
|
|
235
|
+
size: fileSize,
|
|
236
|
+
stat,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
|
|
217
240
|
const entry = {
|
|
218
241
|
session_id: parsed.sessionId,
|
|
219
242
|
provider: 'claude-code',
|
|
@@ -223,10 +246,12 @@ function* scanClaudeCache({ project, onProgress }) {
|
|
|
223
246
|
first_prompt: parsed.firstPrompt,
|
|
224
247
|
message_count: parsed.messageCount,
|
|
225
248
|
created: parsed.earliest,
|
|
226
|
-
modified: parsed.latest || stat
|
|
249
|
+
modified: parsed.latest || mtimeIsoOf(stat),
|
|
227
250
|
file_path: filePath,
|
|
228
|
-
file_size:
|
|
229
|
-
file_mtime: stat
|
|
251
|
+
file_size: fileSize,
|
|
252
|
+
file_mtime: mtimeIsoOf(stat),
|
|
253
|
+
file_identity: fileIdentityOf(stat),
|
|
254
|
+
|
|
230
255
|
body_size: parsed.body.length,
|
|
231
256
|
deleted: 0,
|
|
232
257
|
};
|
|
@@ -334,7 +359,7 @@ function* scanCodexCache({ project, projects, accounts, onProgress }) {
|
|
|
334
359
|
const projLower = project ? String(project).toLowerCase() : null;
|
|
335
360
|
const d = getDb();
|
|
336
361
|
const probeStmt = d.prepare(
|
|
337
|
-
'SELECT session_id, file_size, file_mtime FROM session_cache WHERE file_path = ? AND provider = ?'
|
|
362
|
+
'SELECT session_id, file_size, file_mtime, file_identity FROM session_cache WHERE file_path = ? AND provider = ?'
|
|
338
363
|
);
|
|
339
364
|
|
|
340
365
|
let total = 0;
|
|
@@ -347,14 +372,25 @@ function* scanCodexCache({ project, projects, accounts, onProgress }) {
|
|
|
347
372
|
if (!filePath) continue;
|
|
348
373
|
total++;
|
|
349
374
|
let stat;
|
|
350
|
-
try { stat = statSync(filePath); } catch { continue; }
|
|
375
|
+
try { stat = statSync(filePath, { bigint: true }); } catch { continue; }
|
|
376
|
+
const fileSize = Number(stat.size);
|
|
351
377
|
|
|
352
378
|
if (projLower && session.cwd && !session.cwd.toLowerCase().includes(projLower)) continue;
|
|
353
379
|
liveSessionIds.add(session.sessionId);
|
|
354
380
|
|
|
355
|
-
|
|
381
|
+
// Decide memory capture from the capture checkpoint, independent of session_cache hits
|
|
382
|
+
// and the 50 MiB search-cache parser limit (parseCodexSession rejects >50 MiB rollouts).
|
|
383
|
+
queueMemoryCapture({
|
|
384
|
+
host: 'codex',
|
|
385
|
+
sessionId: session.sessionId,
|
|
386
|
+
filePath,
|
|
387
|
+
cwd: session.cwd || session.projectPath,
|
|
388
|
+
size: fileSize,
|
|
389
|
+
stat,
|
|
390
|
+
});
|
|
391
|
+
|
|
356
392
|
const probe = probeStmt.get(filePath, 'codex');
|
|
357
|
-
if (probe
|
|
393
|
+
if (isSessionFileUnchanged(probe, stat)) {
|
|
358
394
|
const cached = getSessionCacheEntry(session.sessionId, 'codex');
|
|
359
395
|
if (cached?.deleted || cached?.account_id !== session.accountId) {
|
|
360
396
|
upsertSessionCache({
|
|
@@ -371,7 +407,17 @@ function* scanCodexCache({ project, projects, accounts, onProgress }) {
|
|
|
371
407
|
const parsed = parseCodexSession(filePath);
|
|
372
408
|
if (!parsed) continue;
|
|
373
409
|
|
|
374
|
-
|
|
410
|
+
if (parsed.sessionId !== session.sessionId || (parsed.cwd && parsed.cwd !== (session.cwd || session.projectPath))) {
|
|
411
|
+
queueMemoryCapture({
|
|
412
|
+
host: 'codex',
|
|
413
|
+
sessionId: parsed.sessionId,
|
|
414
|
+
filePath,
|
|
415
|
+
cwd: parsed.cwd || session.cwd || session.projectPath,
|
|
416
|
+
size: fileSize,
|
|
417
|
+
stat,
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
|
|
375
421
|
const entry = {
|
|
376
422
|
session_id: parsed.sessionId,
|
|
377
423
|
provider: 'codex',
|
|
@@ -383,8 +429,10 @@ function* scanCodexCache({ project, projects, accounts, onProgress }) {
|
|
|
383
429
|
created: session.created || parsed.created,
|
|
384
430
|
modified: session.modified || parsed.modified,
|
|
385
431
|
file_path: filePath,
|
|
386
|
-
file_size:
|
|
387
|
-
file_mtime:
|
|
432
|
+
file_size: fileSize,
|
|
433
|
+
file_mtime: mtimeIsoOf(stat),
|
|
434
|
+
file_identity: fileIdentityOf(stat),
|
|
435
|
+
|
|
388
436
|
body_size: parsed.body.length,
|
|
389
437
|
deleted: 0,
|
|
390
438
|
account_id: session.accountId,
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export function mtimeIsoOf(stat) {
|
|
2
|
+
if (!stat) return null;
|
|
3
|
+
if (typeof stat.mtimeIso === 'string' && stat.mtimeIso) return stat.mtimeIso;
|
|
4
|
+
if (typeof stat.mtime?.toISOString === 'function') return stat.mtime.toISOString();
|
|
5
|
+
if (stat.mtimeMs != null && Number.isFinite(Number(stat.mtimeMs))) {
|
|
6
|
+
return new Date(Number(stat.mtimeMs)).toISOString();
|
|
7
|
+
}
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Deterministic persisted file identity combining device, inode, ctime, and mtime
|
|
13
|
+
* (nanosecond resolution when BigInt stats are used). Returns null for minimal
|
|
14
|
+
* stat mocks that only carry size + mtime.
|
|
15
|
+
*/
|
|
16
|
+
export function fileIdentityOf(stat) {
|
|
17
|
+
if (stat?.dev == null || stat.ino == null) return null;
|
|
18
|
+
const ctime = stat.ctimeNs != null ? `ns:${stat.ctimeNs}` : (stat.ctimeMs != null ? `ms:${stat.ctimeMs}` : '');
|
|
19
|
+
const mtime = stat.mtimeNs != null ? `ns:${stat.mtimeNs}` : (stat.mtimeMs != null ? `ms:${stat.mtimeMs}` : '');
|
|
20
|
+
return `${stat.dev}:${stat.ino}:${ctime}:${mtime}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Older checkpoints already encode dev:ino:ctime:mtime. The first two fields identify
|
|
24
|
+
// the file across appends. The complete stamp detects same-size edits, even if mtime is restored.
|
|
25
|
+
export function captureStartOffset(row, size, identity, mtime) {
|
|
26
|
+
const offset = Number(row.byte_offset);
|
|
27
|
+
const previousSize = row.file_size ?? offset;
|
|
28
|
+
if (size != null && (size < offset || size < previousSize)) return 0;
|
|
29
|
+
if (!row.file_identity || !identity) return offset;
|
|
30
|
+
if (size > previousSize) {
|
|
31
|
+
const fileKey = stamp => stamp.split(':', 2).join(':');
|
|
32
|
+
return fileKey(identity) === fileKey(row.file_identity) ? offset : 0;
|
|
33
|
+
}
|
|
34
|
+
if (identity !== row.file_identity
|
|
35
|
+
|| (mtime && row.file_mtime && mtime !== row.file_mtime)) return 0;
|
|
36
|
+
return offset;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function isSessionFileUnchanged(cached, stat) {
|
|
40
|
+
return !!cached?.file_identity && cached.file_identity === fileIdentityOf(stat)
|
|
41
|
+
&& Number(cached.file_size) === Number(stat.size) && cached.file_mtime === mtimeIsoOf(stat);
|
|
42
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { captureMemoryFileBatch } from './memory-session-capture.js';
|
|
2
2
|
import { withMemoryWrite } from '../../mcp-server/dist/services/sqlite-write.js';
|
|
3
3
|
import { runSessionJob } from './session-cache-worker.js';
|
|
4
|
+
import { fileIdentityOf, isSessionFileUnchanged, mtimeIsoOf } from './session-capture-gate.js';
|
|
4
5
|
/**
|
|
5
6
|
* Session Indexer — Pipeline orchestrator for indexing Claude Code session transcripts.
|
|
6
7
|
* Queues local JSONL files through the shared, incremental memory event intake.
|
|
@@ -130,29 +131,28 @@ export async function startIndexing(options = {}) {
|
|
|
130
131
|
|
|
131
132
|
if (options.sessionIds && !options.sessionIds.includes(sessionId)) continue;
|
|
132
133
|
|
|
134
|
+
let stat;
|
|
135
|
+
try {
|
|
136
|
+
stat = statSync(filePath, { bigint: true });
|
|
137
|
+
} catch { continue; }
|
|
138
|
+
const fileSize = Number(stat.size);
|
|
139
|
+
const fileMtime = mtimeIsoOf(stat);
|
|
140
|
+
const fileIdentity = fileIdentityOf(stat);
|
|
141
|
+
|
|
133
142
|
if (!options.reindex && state.sessions[sessionId]) {
|
|
134
143
|
const entry = state.sessions[sessionId];
|
|
135
|
-
if (entry.status === 'complete')
|
|
136
|
-
try {
|
|
137
|
-
const stat = statSync(filePath);
|
|
138
|
-
if (stat.size === entry.file_size && stat.mtime.toISOString() === entry.file_mtime) {
|
|
139
|
-
continue;
|
|
140
|
-
}
|
|
141
|
-
} catch { continue; }
|
|
142
|
-
}
|
|
144
|
+
if (entry.status === 'complete' && isSessionFileUnchanged(entry, stat)) continue;
|
|
143
145
|
}
|
|
144
146
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
});
|
|
155
|
-
} catch { continue; }
|
|
147
|
+
if (fileSize === 0) continue;
|
|
148
|
+
sessionsToIndex.push({
|
|
149
|
+
sessionId,
|
|
150
|
+
filePath,
|
|
151
|
+
fileSize,
|
|
152
|
+
fileMtime,
|
|
153
|
+
fileIdentity,
|
|
154
|
+
projectDir: projDir.name,
|
|
155
|
+
});
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
|
|
@@ -179,7 +179,14 @@ export async function startIndexing(options = {}) {
|
|
|
179
179
|
// Preserve this entry point and its UI progress events for Claude hooks.
|
|
180
180
|
const target = { host: 'claude-code', sessionId: session.sessionId };
|
|
181
181
|
const project = detectProjectFromDir(session.projectDir);
|
|
182
|
-
await runSessionJob('queue-capture', {
|
|
182
|
+
await runSessionJob('queue-capture', {
|
|
183
|
+
...target,
|
|
184
|
+
filePath: session.filePath,
|
|
185
|
+
project,
|
|
186
|
+
size: session.fileSize,
|
|
187
|
+
fileMtime: session.fileMtime,
|
|
188
|
+
fileIdentity: session.fileIdentity,
|
|
189
|
+
});
|
|
183
190
|
let complete = false;
|
|
184
191
|
while (!isCancelled?.()) {
|
|
185
192
|
const outcome = await captureMemoryFileBatch(target, { reportProgress: true });
|
|
@@ -193,6 +200,7 @@ export async function startIndexing(options = {}) {
|
|
|
193
200
|
const chunkIds = await runSessionJob('capture-chunks', target);
|
|
194
201
|
totalChunks += chunkIds.length;
|
|
195
202
|
state.sessions[session.sessionId]={session_id:session.sessionId,file_path:session.filePath,file_size:session.fileSize,file_mtime:session.fileMtime,
|
|
203
|
+
file_identity:session.fileIdentity,
|
|
196
204
|
chunk_count:chunkIds.length,chunk_ids:chunkIds,indexed_at:new Date().toISOString(),project,
|
|
197
205
|
status:complete ? 'complete' : 'partial',last_line_indexed:0};
|
|
198
206
|
saveState(state);
|
|
@@ -119,6 +119,7 @@ function dispatchDefaults(input = {}) {
|
|
|
119
119
|
take('effort', 'effort');
|
|
120
120
|
take('accountId', 'accountId', 'account_id');
|
|
121
121
|
take('tools', 'tools');
|
|
122
|
+
take('usesBrowser', 'usesBrowser', 'uses_browser');
|
|
122
123
|
take('maxMinutes', 'maxMinutes', 'max_minutes');
|
|
123
124
|
take('budgetUsd', 'budgetUsd', 'budget_usd');
|
|
124
125
|
take('permissionPolicy', 'permissionPolicy', 'permission_policy');
|
|
@@ -702,7 +703,7 @@ export function createTeamScheduler({
|
|
|
702
703
|
mine.doneAt = iso(now());
|
|
703
704
|
await emit(record, 'slice_done', { sliceId, runId: mine.runId, text: cleanup.removed ? 'Read-only worker ended; worktree removed.' : `Worktree kept: ${cleanup.kept?.path || cleanup.path} (${cleanup.kept?.reason || cleanup.code}).` });
|
|
704
705
|
if (!cleanup.ok || cleanup.kept) await attention(record, { code: 'READ_ONLY_WORKTREE_KEPT', sliceId, message: `Read-only worker worktree kept at ${cleanup.kept?.path || cleanup.path}: ${cleanup.kept?.reason || cleanup.message}. Inspect it; no changes were committed or landed.`, report: cleanup });
|
|
705
|
-
else if (failed) await attention(record, { code: 'SLICE_WORKER_ENDED', sliceId, message: 'Read-only worker ended before reporting done; its clean worktree was removed.' });
|
|
706
|
+
else if (failed) await attention(record, { code: 'SLICE_WORKER_ENDED', sliceId, message: run?.completionReason === 'browser_unavailable' && run.error ? run.error : 'Read-only worker ended before reporting done; its clean worktree was removed.' });
|
|
706
707
|
if (Object.values(record.slices).every(s => s.released) && record.status !== 'needs_attention') {
|
|
707
708
|
record.status = 'completed';
|
|
708
709
|
await emit(record, 'team_completed', { text: 'All read-only workers finished. Synthesize their results; no integration or landing is needed.' });
|
|
@@ -935,7 +936,7 @@ export function createTeamScheduler({
|
|
|
935
936
|
if (state === 'done' && canFinish(run)) return;
|
|
936
937
|
mine.phase = 'failed';
|
|
937
938
|
await attention(record, { code: 'SLICE_WORKER_ENDED', sliceId,
|
|
938
|
-
message: `The worker of slice ${sliceId} ended (${run.completionReason || run.state}) before its slice was done. Its files are in its worktree. agent_team integrate gives the slice to a new worker; agent_team discard gives the team up.` });
|
|
939
|
+
message: run.completionReason === 'browser_unavailable' && run.error ? run.error : `The worker of slice ${sliceId} ended (${run.completionReason || run.state}) before its slice was done. Its files are in its worktree. agent_team integrate gives the slice to a new worker; agent_team discard gives the team up.` });
|
|
939
940
|
} else if (run.outcome !== 'done') {
|
|
940
941
|
mine.phase = 'blocked';
|
|
941
942
|
mine.lastReport = { code: 'WORKER_BLOCKED', message: clip(run.lastResult?.summary || run.lastResult?.question || run.outcome || 'no result', 400), at: iso(now()) };
|
|
@@ -53,11 +53,19 @@ export function createUiBlobRouter({ namespaces, store, ownerNamespace = null, o
|
|
|
53
53
|
return ns;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
router.get('/api/ui-blobs/:ns', (req, res) => {
|
|
56
|
+
router.get('/api/ui-blobs/:ns', async (req, res) => {
|
|
57
57
|
const ns = namespaceOf(req, res);
|
|
58
58
|
if (!ns) return;
|
|
59
|
-
try {
|
|
60
|
-
|
|
59
|
+
try {
|
|
60
|
+
if (typeof store.getNamespaceJsonAsync === 'function') {
|
|
61
|
+
const json = await store.getNamespaceJsonAsync(ns);
|
|
62
|
+
res.type('application/json').send(json);
|
|
63
|
+
} else if (typeof store.getNamespaceAsync === 'function') {
|
|
64
|
+
res.json(await store.getNamespaceAsync(ns));
|
|
65
|
+
} else {
|
|
66
|
+
res.json(store.getNamespace(ns));
|
|
67
|
+
}
|
|
68
|
+
} catch (err) { res.status(500).json({ error: err.message }); }
|
|
61
69
|
});
|
|
62
70
|
|
|
63
71
|
router.get('/api/ui-blobs/:ns/:id', (req, res) => {
|
|
@@ -83,8 +91,9 @@ export function createUiBlobRouter({ namespaces, store, ownerNamespace = null, o
|
|
|
83
91
|
order.applied(ns, req.params.id, revision);
|
|
84
92
|
const maxEntries = parseInt(req.query.maxEntries, 10) || 0;
|
|
85
93
|
const maxChars = parseInt(req.query.maxChars, 10) || 0;
|
|
86
|
-
|
|
87
|
-
|
|
94
|
+
const evicted = maxEntries > 0 || maxChars > 0
|
|
95
|
+
? store.prune(ns, { maxEntries, maxTotalChars: maxChars })
|
|
96
|
+
: [];
|
|
88
97
|
res.json({ ok: true, evicted });
|
|
89
98
|
} catch (err) { res.status(500).json({ error: err.message }); }
|
|
90
99
|
}
|