synabun 2.4.2 → 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 +39 -0
- package/README.md +1 -1
- package/docs/browser-extension-bridge.md +83 -34
- package/lib/release-npm-ci.mjs +23 -1
- 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 +68 -18
- 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-extension-setup.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-extension-setup.js +8 -2
- package/mcp-server/dist/tools/browser-extension-setup.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 +5 -5
- 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 +66 -19
- 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-extension-setup.ts +8 -2
- 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 +189 -1
- package/neural-interface/i18n/pt-BR.json +196 -8
- package/neural-interface/lib/assistant-api.js +123 -0
- package/neural-interface/lib/assistant-brains/claude.js +10 -0
- package/neural-interface/lib/assistant-brains/opencode.js +121 -7
- package/neural-interface/lib/assistant-dispatch.js +302 -44
- package/neural-interface/lib/assistant-envelope.js +40 -0
- 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 +182 -11
- 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 -17
- package/neural-interface/lib/browser-extension-archive.js +149 -0
- package/neural-interface/lib/browser-extension-bridge.js +46 -10
- package/neural-interface/lib/browser-extension-folder.js +635 -76
- package/neural-interface/lib/browser-extension-package.js +201 -0
- package/neural-interface/lib/browser-extension-pin.js +84 -0
- package/neural-interface/lib/browser-extension-pin.json +35 -0
- package/{browser-extension/protocol.js → neural-interface/lib/browser-extension-protocol.js} +111 -13
- package/neural-interface/lib/browser-extension-setup.js +108 -19
- 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/cli-install.js +23 -3
- package/neural-interface/lib/cli-update-planner.js +67 -4
- 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 +82 -13
- package/neural-interface/lib/native-loop-runtime.js +23 -2
- package/neural-interface/lib/opencode-protocol.js +4 -2
- package/neural-interface/lib/opencode-shell-read.js +107 -0
- package/neural-interface/lib/opencode-stop-failures.js +40 -0
- package/neural-interface/lib/opencode-turn-release.js +173 -0
- package/neural-interface/lib/opencode-v2-client.js +4 -1
- package/neural-interface/lib/opencode-v2-ws-requests.js +34 -0
- package/neural-interface/lib/opencode2-client.js +341 -6
- package/neural-interface/lib/opencode2-translate.js +161 -4
- 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/terminal-token-redaction.js +83 -0
- package/neural-interface/lib/ui-blob-api.js +14 -5
- package/neural-interface/lib/ui-blob-store.js +302 -39
- package/neural-interface/lib/whatsapp/bridge.js +52 -6
- package/neural-interface/package-lock.json +5 -5
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/extension-setup.html +6 -2
- package/neural-interface/public/shared/agy/agy-panel.js +38 -10
- package/neural-interface/public/shared/assistant/asst-agents-dock.js +4 -0
- package/neural-interface/public/shared/assistant/asst-api.js +67 -0
- package/neural-interface/public/shared/assistant/asst-composer.js +85 -12
- package/neural-interface/public/shared/assistant/asst-panel.js +354 -11
- package/neural-interface/public/shared/assistant/asst-rack-styles.js +23 -0
- package/neural-interface/public/shared/assistant/asst-render.js +343 -10
- package/neural-interface/public/shared/assistant/asst-scenes.js +12 -0
- package/neural-interface/public/shared/assistant/asst-shell-logic.js +200 -0
- package/neural-interface/public/shared/assistant/asst-shell.js +111 -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 +21 -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/cdx/cdx-tabs.js +25 -0
- package/neural-interface/public/shared/cp/cp-bg-tasks.js +130 -0
- package/neural-interface/public/shared/extension-setup/es-page.js +25 -12
- package/neural-interface/public/shared/extension-setup/es-view.js +25 -10
- package/neural-interface/public/shared/extension-update-view.js +34 -0
- package/neural-interface/public/shared/mtc/mtc-panel.js +17 -2
- package/neural-interface/public/shared/ocp-v2/ocp-v2-events.js +5 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-manager.js +1 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +34 -2
- package/neural-interface/public/shared/ocp-v2/ocp-v2-rehydrate.js +7 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +26 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +39 -6
- package/neural-interface/public/shared/ocp-v2/ocp-v2-session-actions.js +20 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-block.js +165 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-logic.js +350 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell.js +108 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-state.js +49 -3
- package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +40 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-tools-logic.js +20 -5
- package/neural-interface/public/shared/ocp-v2/ocp-v2-tools.js +7 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +7 -2
- package/neural-interface/public/shared/settings/settings-browser-extension.js +61 -13
- package/neural-interface/public/shared/settings/settings-extension-update.js +114 -0
- package/neural-interface/public/shared/shell-stop-view.js +83 -0
- package/neural-interface/public/shared/styles.css +4 -0
- package/neural-interface/public/shared/tour/tour-actor.js +14 -3
- package/neural-interface/public/shared/tray-auto-close.js +36 -6
- package/neural-interface/public/shared/ui-claude-panel.js +130 -1
- package/neural-interface/public/shared/ui-native-loop-router.js +45 -3
- package/neural-interface/public/shared/ui-notifications.js +23 -4
- package/neural-interface/public/shared/ui-scroll-follow.js +4 -0
- 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 +725 -308
- package/npm-shrinkwrap.json +5 -5
- package/package.json +1 -2
- package/browser-extension/content.js +0 -231
- package/browser-extension/engine.js +0 -658
- package/browser-extension/icons/icon-128.png +0 -0
- package/browser-extension/icons/icon-16.png +0 -0
- package/browser-extension/icons/icon-32.png +0 -0
- package/browser-extension/icons/icon-48.png +0 -0
- package/browser-extension/icons/status-off-16.png +0 -0
- package/browser-extension/icons/status-off-32.png +0 -0
- package/browser-extension/icons/status-off-48.png +0 -0
- package/browser-extension/icons/status-on-16.png +0 -0
- package/browser-extension/icons/status-on-32.png +0 -0
- package/browser-extension/icons/status-on-48.png +0 -0
- package/browser-extension/manifest.json +0 -58
- package/browser-extension/popup-strings.js +0 -250
- package/browser-extension/popup-view.js +0 -151
- package/browser-extension/popup.css +0 -166
- package/browser-extension/popup.html +0 -108
- package/browser-extension/popup.js +0 -359
- package/browser-extension/service-worker.js +0 -283
- package/browser-extension/setup-content.js +0 -36
- package/browser-extension/tokens.css +0 -326
|
@@ -633,17 +633,51 @@ export function createEventTranslator({ version = '', directory: defaultDirector
|
|
|
633
633
|
const inbox = new Map(); // inboxID → { sessionID, item }
|
|
634
634
|
const permissions = new Map(); // requestID → sessionID
|
|
635
635
|
const forms = new Map(); // formID → form
|
|
636
|
+
// The shell commands of tool calls (OpenCode 2 runs each as a "shell" with an
|
|
637
|
+
// id of its own): shellID → { id, sessionID, messageID, callID, command,
|
|
638
|
+
// started, ended, status, exit, linked, background, waited }. A command that
|
|
639
|
+
// outlives its tool call runs on "in the background": OpenCode ends the tool
|
|
640
|
+
// call (and, once the model has nothing else to do, the turn) while the
|
|
641
|
+
// command still runs, and starts the session again by itself when it exits.
|
|
642
|
+
const shells = new Map();
|
|
643
|
+
const detached = new Set(); // `${messageID}:${callID}` of calls the model itself sent to the background
|
|
636
644
|
const MAX_MESSAGES = 400;
|
|
637
645
|
const MAX_INBOX = 200;
|
|
646
|
+
const MAX_SHELLS = 200;
|
|
647
|
+
let released = 0;
|
|
638
648
|
|
|
639
649
|
const sessionState = (sessionID) => {
|
|
640
650
|
let state = sessions.get(sessionID);
|
|
641
651
|
if (!state) {
|
|
642
|
-
state = { info: null, directory: '', lastUser: '', compacting: 0 };
|
|
652
|
+
state = { info: null, directory: '', lastUser: '', compacting: 0, executing: false, held: false };
|
|
643
653
|
sessions.set(sessionID, state);
|
|
644
654
|
}
|
|
645
655
|
return state;
|
|
646
656
|
};
|
|
657
|
+
|
|
658
|
+
const shellView = (shell) => ({
|
|
659
|
+
id: shell.id,
|
|
660
|
+
sessionID: shell.sessionID,
|
|
661
|
+
messageID: shell.messageID,
|
|
662
|
+
callID: shell.callID,
|
|
663
|
+
command: shell.command,
|
|
664
|
+
status: shell.status,
|
|
665
|
+
background: shell.background,
|
|
666
|
+
waited: shell.waited,
|
|
667
|
+
time: shell.ended ? { started: shell.started, ended: shell.ended } : { started: shell.started },
|
|
668
|
+
...(shell.exit != null ? { exit: shell.exit } : {}),
|
|
669
|
+
});
|
|
670
|
+
/** The commands of `sessionID` still running after their tool call ended; `waited`: only those the model did not send there itself. */
|
|
671
|
+
const backgroundShells = (sessionID, { waited = false } = {}) => [...shells.values()]
|
|
672
|
+
.filter((shell) => shell.sessionID === sessionID && shell.linked && shell.status === 'running' && shell.background && (!waited || shell.waited));
|
|
673
|
+
const trimShells = () => {
|
|
674
|
+
if (shells.size <= MAX_SHELLS) return;
|
|
675
|
+
// A command that ended goes first; one still running is never forgotten for a newer one.
|
|
676
|
+
for (const [id, shell] of shells) {
|
|
677
|
+
if (shells.size <= MAX_SHELLS) break;
|
|
678
|
+
if (shell.status !== 'running') shells.delete(id);
|
|
679
|
+
}
|
|
680
|
+
};
|
|
647
681
|
const directoryOf = (event, sessionID) => str(event?.location?.directory)
|
|
648
682
|
|| (sessionID ? sessions.get(sessionID)?.directory : '')
|
|
649
683
|
|| defaultDirectory;
|
|
@@ -735,8 +769,23 @@ export function createEventTranslator({ version = '', directory: defaultDirector
|
|
|
735
769
|
const { created, ...rest } = part;
|
|
736
770
|
return rest;
|
|
737
771
|
};
|
|
738
|
-
const
|
|
772
|
+
const updateShell = (shell) => {
|
|
773
|
+
if (shell.linked && shell.sessionID) emit('shell.updated', { sessionID: shell.sessionID, shell: shellView(shell) });
|
|
774
|
+
};
|
|
775
|
+
// An execution that ended is the end of the turn, except one that succeeded
|
|
776
|
+
// while a command the model waits for still runs in the background: OpenCode
|
|
777
|
+
// starts the session again by itself when that command exits, so the session
|
|
778
|
+
// is still at work and nobody is told it went idle (`held`). A command the
|
|
779
|
+
// model sent to the background itself (a server it started) holds nothing.
|
|
780
|
+
const turnEnd = (error = null, { hold = false } = {}) => {
|
|
781
|
+
const state = sessionState(sessionID);
|
|
782
|
+
state.executing = false;
|
|
783
|
+
state.held = hold && backgroundShells(sessionID, { waited: true }).length > 0;
|
|
739
784
|
if (error) emit('session.error', { sessionID, error });
|
|
785
|
+
if (state.held) {
|
|
786
|
+
emit('session.status', { sessionID, status: { type: 'busy', background: true } });
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
740
789
|
emit('session.status', { sessionID, status: { type: 'idle' } });
|
|
741
790
|
emit('session.idle', { sessionID });
|
|
742
791
|
};
|
|
@@ -802,6 +851,7 @@ export function createEventTranslator({ version = '', directory: defaultDirector
|
|
|
802
851
|
case 'session.deleted': {
|
|
803
852
|
const info = sessionInfo(sessionID);
|
|
804
853
|
sessions.delete(sessionID);
|
|
854
|
+
for (const [id, shell] of shells) if (shell.sessionID === sessionID) shells.delete(id);
|
|
805
855
|
emit('session.deleted', { sessionID, info });
|
|
806
856
|
break;
|
|
807
857
|
}
|
|
@@ -841,14 +891,18 @@ export function createEventTranslator({ version = '', directory: defaultDirector
|
|
|
841
891
|
}
|
|
842
892
|
|
|
843
893
|
// ── A turn ──
|
|
844
|
-
case 'session.execution.started':
|
|
894
|
+
case 'session.execution.started': {
|
|
895
|
+
const state = sessionState(sessionID);
|
|
896
|
+
state.executing = true;
|
|
897
|
+
state.held = false;
|
|
845
898
|
emit('session.status', { sessionID, status: { type: 'busy' } });
|
|
846
899
|
break;
|
|
900
|
+
}
|
|
847
901
|
case 'session.retry.scheduled':
|
|
848
902
|
emit('session.status', { sessionID, status: { type: 'retry', attempt: num(data.attempt), message: str(data.error?.message) || 'Retrying', next: num(data.at) } });
|
|
849
903
|
break;
|
|
850
904
|
case 'session.execution.succeeded':
|
|
851
|
-
turnEnd(null);
|
|
905
|
+
turnEnd(null, { hold: true });
|
|
852
906
|
break;
|
|
853
907
|
case 'session.execution.failed':
|
|
854
908
|
turnEnd(errorToV1(data.error));
|
|
@@ -948,6 +1002,10 @@ export function createEventTranslator({ version = '', directory: defaultDirector
|
|
|
948
1002
|
case 'session.tool.called': {
|
|
949
1003
|
const part = toolOf(data);
|
|
950
1004
|
part.state = { status: 'running', input: obj(data.input), time: { start: at } };
|
|
1005
|
+
if (obj(data.input).background === true) {
|
|
1006
|
+
detached.add(`${part.messageID}:${part.callID}`);
|
|
1007
|
+
trim(detached, MAX_SHELLS);
|
|
1008
|
+
}
|
|
951
1009
|
updatePart(publicTool(part));
|
|
952
1010
|
break;
|
|
953
1011
|
}
|
|
@@ -956,6 +1014,21 @@ export function createEventTranslator({ version = '', directory: defaultDirector
|
|
|
956
1014
|
const start = num(part.state.time?.start, at);
|
|
957
1015
|
part.state = { ...part.state, status: 'running', metadata: { ...obj(part.state.metadata), ...obj(data.metadata) }, time: { start } };
|
|
958
1016
|
updatePart(publicTool(part));
|
|
1017
|
+
// The shell tool says which command it started: from here on its output
|
|
1018
|
+
// can be read while it runs (GET /api/shell/:id/output).
|
|
1019
|
+
const shellID = str(obj(data.metadata).shellID);
|
|
1020
|
+
if (shellID) {
|
|
1021
|
+
let shell = shells.get(shellID);
|
|
1022
|
+
if (!shell) {
|
|
1023
|
+
shell = { id: shellID, sessionID, messageID: '', callID: '', command: '', started: at, ended: 0, status: 'running', exit: null, linked: false, background: false, waited: false };
|
|
1024
|
+
shells.set(shellID, shell);
|
|
1025
|
+
trimShells();
|
|
1026
|
+
}
|
|
1027
|
+
if (!shell.linked) {
|
|
1028
|
+
Object.assign(shell, { linked: true, sessionID, messageID: part.messageID, callID: part.callID, command: shell.command || str(obj(part.state.input).command) });
|
|
1029
|
+
updateShell(shell);
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
959
1032
|
break;
|
|
960
1033
|
}
|
|
961
1034
|
case 'session.tool.success':
|
|
@@ -965,8 +1038,40 @@ export function createEventTranslator({ version = '', directory: defaultDirector
|
|
|
965
1038
|
const state = event.type === 'session.tool.success'
|
|
966
1039
|
? { status: 'completed', input: obj(part.state.input), content: data.content, metadata: data.metadata }
|
|
967
1040
|
: { status: 'error', input: obj(part.state.input), error: data.error, metadata: data.metadata };
|
|
1041
|
+
const shellID = str(obj(data.metadata).shellID) || str(obj(part.state.metadata).shellID);
|
|
968
1042
|
part.state = toolStateToV1(state, { name: part.tool, times: { ran: start, completed: at }, base: { sessionID, messageID: part.messageID, callID: part.callID } });
|
|
1043
|
+
// The call's command, for a reader of the part (a transcript read later has it only for a command that went
|
|
1044
|
+
// to the background: OpenCode keeps no shell id on one that finished inside its call).
|
|
1045
|
+
if (shellID && !part.state.metadata?.shellID) part.state = { ...part.state, metadata: { ...obj(part.state.metadata), shellID } };
|
|
969
1046
|
updatePart(publicTool(part));
|
|
1047
|
+
const shell = shellID ? shells.get(shellID) : null;
|
|
1048
|
+
// "Succeeded" with a command still running: the call is over, the command is not.
|
|
1049
|
+
if (shell && shell.status === 'running' && event.type === 'session.tool.success' && obj(data.metadata).status === 'running') {
|
|
1050
|
+
shell.background = true;
|
|
1051
|
+
shell.waited = !detached.has(`${part.messageID}:${part.callID}`);
|
|
1052
|
+
updateShell(shell);
|
|
1053
|
+
}
|
|
1054
|
+
detached.delete(`${part.messageID}:${part.callID}`);
|
|
1055
|
+
break;
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
// ── Shell commands ──
|
|
1059
|
+
case 'shell.created': {
|
|
1060
|
+
const info = obj(data.info);
|
|
1061
|
+
const id = str(info.id);
|
|
1062
|
+
if (!id || shells.has(id)) break;
|
|
1063
|
+
shells.set(id, { id, sessionID: str(obj(info.metadata).sessionID), messageID: '', callID: '', command: str(info.command), started: num(obj(info.time).started, at), ended: 0, status: 'running', exit: null, linked: false, background: false, waited: false });
|
|
1064
|
+
trimShells();
|
|
1065
|
+
break;
|
|
1066
|
+
}
|
|
1067
|
+
case 'shell.exited':
|
|
1068
|
+
case 'shell.deleted': {
|
|
1069
|
+
const shell = shells.get(str(data.id));
|
|
1070
|
+
if (!shell || shell.status !== 'running') break;
|
|
1071
|
+
shell.status = event.type === 'shell.deleted' ? 'killed' : (str(data.status) || 'exited');
|
|
1072
|
+
shell.ended = at;
|
|
1073
|
+
if (typeof data.exit === 'number') shell.exit = data.exit;
|
|
1074
|
+
updateShell(shell);
|
|
970
1075
|
break;
|
|
971
1076
|
}
|
|
972
1077
|
|
|
@@ -1051,6 +1156,58 @@ export function createEventTranslator({ version = '', directory: defaultDirector
|
|
|
1051
1156
|
noteForm: (form) => { if (form?.id) { forms.set(str(form.id), form); trim(forms, MAX_INBOX); } },
|
|
1052
1157
|
notePermission: (requestID, sessionID) => { if (requestID && sessionID) { permissions.set(str(requestID), str(sessionID)); trim(permissions, MAX_INBOX); } },
|
|
1053
1158
|
sessionDirectory: (sessionID) => sessions.get(str(sessionID))?.directory || '',
|
|
1159
|
+
/** The shell commands of a session's tool calls this stream has seen, oldest first (`{ id, status, command, callID, background, … }`). */
|
|
1160
|
+
shells: (sessionID) => [...shells.values()].filter((shell) => shell.linked && shell.sessionID === str(sessionID)).map(shellView),
|
|
1161
|
+
/** One of them by its id, or null. */
|
|
1162
|
+
shell: (shellID) => { const shell = shells.get(str(shellID)); return shell?.linked ? shellView(shell) : null; },
|
|
1163
|
+
/** The commands of a session that run on after their tool call ended. */
|
|
1164
|
+
backgroundShells: (sessionID, options) => backgroundShells(str(sessionID), options).map(shellView),
|
|
1165
|
+
/** The ids of the commands a held turn of `sessionID` waits for (still running, not sent to the background by the model). */
|
|
1166
|
+
heldShellIds: (sessionID) => backgroundShells(str(sessionID), { waited: true }).map((shell) => shell.id),
|
|
1167
|
+
/** A session whose execution ended while a command the model waits for still runs: reported busy, not idle. */
|
|
1168
|
+
held: (sessionID) => sessions.get(str(sessionID))?.held === true,
|
|
1169
|
+
heldSessions: () => [...sessions].filter(([, state]) => state.held).map(([id]) => id),
|
|
1170
|
+
/**
|
|
1171
|
+
* Commands a "Stop anyway" gave up on: still listed as running (they may be), but no turn of their session waits
|
|
1172
|
+
* for them from now on. → the events that say so.
|
|
1173
|
+
*/
|
|
1174
|
+
unhold(shellIDs = []) {
|
|
1175
|
+
const out = [];
|
|
1176
|
+
for (const id of shellIDs) {
|
|
1177
|
+
const shell = shells.get(str(id));
|
|
1178
|
+
if (!shell || !shell.waited) continue;
|
|
1179
|
+
shell.waited = false;
|
|
1180
|
+
const directory = sessions.get(shell.sessionID)?.directory || defaultDirectory;
|
|
1181
|
+
out.push({ directory, payload: { id: `synabun-release-${++released}`, type: 'shell.updated', properties: { sessionID: shell.sessionID, shell: shellView(shell) } } });
|
|
1182
|
+
}
|
|
1183
|
+
return out;
|
|
1184
|
+
},
|
|
1185
|
+
/**
|
|
1186
|
+
* End a held turn OpenCode will not end by itself (its commands were stopped, or the session never started
|
|
1187
|
+
* again): the events of that end, none when the session is not held. `aborted`: as a stopped turn.
|
|
1188
|
+
* `running`: the ids of commands a "Stop anyway" could not end. They stay listed as running (they may well be),
|
|
1189
|
+
* and are left as they are (`unhold` says they hold nothing).
|
|
1190
|
+
*/
|
|
1191
|
+
release(sessionID, { aborted = false, running = [] } = {}) {
|
|
1192
|
+
const id = str(sessionID);
|
|
1193
|
+
const state = sessions.get(id);
|
|
1194
|
+
if (!state?.held) return [];
|
|
1195
|
+
state.held = false;
|
|
1196
|
+
const directory = state.directory || defaultDirectory;
|
|
1197
|
+
const event = (type, properties) => ({ directory, payload: { id: `synabun-release-${++released}`, type, properties } });
|
|
1198
|
+
const left = new Set((Array.isArray(running) ? running : []).map(str));
|
|
1199
|
+
// A command still listed as running is not: OpenCode holds none of this session any more.
|
|
1200
|
+
const ended = backgroundShells(id).filter((shell) => !left.has(shell.id)).map((shell) => {
|
|
1201
|
+
Object.assign(shell, { status: aborted ? 'killed' : 'exited', ended: Date.now() });
|
|
1202
|
+
return event('shell.updated', { sessionID: id, shell: shellView(shell) });
|
|
1203
|
+
});
|
|
1204
|
+
return [
|
|
1205
|
+
...ended,
|
|
1206
|
+
...(aborted ? [event('session.error', { sessionID: id, error: { name: 'MessageAbortedError', data: { message: 'The turn was stopped (user).' } } })] : []),
|
|
1207
|
+
event('session.status', { sessionID: id, status: { type: 'idle' } }),
|
|
1208
|
+
event('session.idle', { sessionID: id }),
|
|
1209
|
+
];
|
|
1210
|
+
},
|
|
1054
1211
|
};
|
|
1055
1212
|
}
|
|
1056
1213
|
|
|
@@ -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()) };
|