@cchistory/lite 0.4.4 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/INSTALL.md +1 -1
- package/apps/lite-cli/dist/agent-contract.d.ts +4 -5
- package/apps/lite-cli/dist/agent-contract.d.ts.map +1 -1
- package/apps/lite-cli/dist/agent-contract.js +35 -28
- package/apps/lite-cli/dist/agent-contract.js.map +1 -1
- package/apps/lite-cli/dist/bin.js +3 -3
- package/apps/lite-cli/dist/bin.js.map +1 -1
- package/apps/lite-cli/dist/index.d.ts.map +1 -1
- package/apps/lite-cli/dist/index.js +155 -81
- package/apps/lite-cli/dist/index.js.map +1 -1
- package/apps/lite-cli/dist/index.test.js +87 -63
- package/apps/lite-cli/dist/index.test.js.map +1 -1
- package/apps/lite-cli/dist/query.d.ts +4 -1
- package/apps/lite-cli/dist/query.d.ts.map +1 -1
- package/apps/lite-cli/dist/query.js +45 -29
- package/apps/lite-cli/dist/query.js.map +1 -1
- package/apps/lite-cli/dist/resource-errors.d.ts +3 -0
- package/apps/lite-cli/dist/resource-errors.d.ts.map +1 -0
- package/apps/lite-cli/dist/resource-errors.js +17 -0
- package/apps/lite-cli/dist/resource-errors.js.map +1 -0
- package/apps/lite-cli/dist/shell.d.ts +12 -2
- package/apps/lite-cli/dist/shell.d.ts.map +1 -1
- package/apps/lite-cli/dist/shell.js +129 -57
- package/apps/lite-cli/dist/shell.js.map +1 -1
- package/apps/lite-cli/dist/sql-query.test.d.ts +2 -0
- package/apps/lite-cli/dist/sql-query.test.d.ts.map +1 -0
- package/apps/lite-cli/dist/sql-query.test.js +290 -0
- package/apps/lite-cli/dist/sql-query.test.js.map +1 -0
- package/apps/lite-cli/dist/version.d.ts +1 -1
- package/apps/lite-cli/dist/version.js +1 -1
- package/apps/lite-tui/dist/bin.js +3 -3
- package/apps/lite-tui/dist/bin.js.map +1 -1
- package/apps/lite-tui/dist/index.d.ts.map +1 -1
- package/apps/lite-tui/dist/index.js +2 -2
- package/apps/lite-tui/dist/index.js.map +1 -1
- package/apps/lite-tui/dist/index.test.js +5 -3
- package/apps/lite-tui/dist/index.test.js.map +1 -1
- package/apps/lite-tui/dist/render.d.ts +1 -1
- package/apps/lite-tui/dist/version.d.ts +1 -1
- package/apps/lite-tui/dist/version.js +1 -1
- package/bin/cchistory-lite-tui.mjs +3 -3
- package/bin/cchistory-lite.mjs +3 -3
- package/docs/guide/for-agents.md +65 -42
- package/docs/guide/lite.md +64 -24
- package/docs/guide/queries/latest-sessions.sql +4 -0
- package/docs/guide/queries/latest-turns.sql +1 -0
- package/docs/guide/queries/list-sessions.sql +2 -0
- package/docs/guide/query.md +153 -0
- package/node_modules/@cchistory/canonical/dist/directory-scope.d.ts +7 -0
- package/node_modules/@cchistory/canonical/dist/directory-scope.d.ts.map +1 -1
- package/node_modules/@cchistory/canonical/dist/directory-scope.js +11 -0
- package/node_modules/@cchistory/canonical/dist/directory-scope.js.map +1 -1
- package/node_modules/@cchistory/canonical/dist/index.d.ts +5 -1
- package/node_modules/@cchistory/canonical/dist/index.d.ts.map +1 -1
- package/node_modules/@cchistory/canonical/dist/index.js +5 -1
- package/node_modules/@cchistory/canonical/dist/index.js.map +1 -1
- package/node_modules/@cchistory/canonical/dist/query.d.ts +15 -0
- package/node_modules/@cchistory/canonical/dist/query.d.ts.map +1 -0
- package/node_modules/@cchistory/canonical/dist/query.js +208 -0
- package/node_modules/@cchistory/canonical/dist/query.js.map +1 -0
- package/node_modules/@cchistory/canonical/dist/session-family.d.ts +1 -0
- package/node_modules/@cchistory/canonical/dist/session-family.d.ts.map +1 -1
- package/node_modules/@cchistory/canonical/dist/session-family.js +3 -0
- package/node_modules/@cchistory/canonical/dist/session-family.js.map +1 -1
- package/node_modules/@cchistory/canonical/dist/session-family.test.js +61 -0
- package/node_modules/@cchistory/canonical/dist/session-family.test.js.map +1 -1
- package/node_modules/@cchistory/canonical/dist/session-interpreter.d.ts +30 -0
- package/node_modules/@cchistory/canonical/dist/session-interpreter.d.ts.map +1 -0
- package/node_modules/@cchistory/canonical/dist/session-interpreter.js +713 -0
- package/node_modules/@cchistory/canonical/dist/session-interpreter.js.map +1 -0
- package/node_modules/@cchistory/canonical/dist/session-interpreter.test.d.ts +2 -0
- package/node_modules/@cchistory/canonical/dist/session-interpreter.test.d.ts.map +1 -0
- package/node_modules/@cchistory/canonical/dist/session-interpreter.test.js +56 -0
- package/node_modules/@cchistory/canonical/dist/session-interpreter.test.js.map +1 -0
- package/node_modules/@cchistory/canonical/package.json +1 -1
- package/node_modules/@cchistory/domain/dist/evidence-atoms.d.ts +7 -0
- package/node_modules/@cchistory/domain/dist/evidence-atoms.d.ts.map +1 -0
- package/node_modules/@cchistory/domain/dist/evidence-atoms.js +36 -0
- package/node_modules/@cchistory/domain/dist/evidence-atoms.js.map +1 -0
- package/node_modules/@cchistory/domain/dist/evidence-values.d.ts +26 -0
- package/node_modules/@cchistory/domain/dist/evidence-values.d.ts.map +1 -0
- package/node_modules/@cchistory/domain/dist/evidence-values.js +80 -0
- package/node_modules/@cchistory/domain/dist/evidence-values.js.map +1 -0
- package/node_modules/@cchistory/domain/dist/index.d.ts +6 -0
- package/node_modules/@cchistory/domain/dist/index.d.ts.map +1 -1
- package/node_modules/@cchistory/domain/dist/index.js +5 -0
- package/node_modules/@cchistory/domain/dist/index.js.map +1 -1
- package/node_modules/@cchistory/domain/dist/masks.d.ts +31 -0
- package/node_modules/@cchistory/domain/dist/masks.d.ts.map +1 -0
- package/node_modules/@cchistory/domain/dist/masks.js +342 -0
- package/node_modules/@cchistory/domain/dist/masks.js.map +1 -0
- package/node_modules/@cchistory/domain/dist/parsed-session.d.ts +58 -0
- package/node_modules/@cchistory/domain/dist/parsed-session.d.ts.map +1 -0
- package/node_modules/@cchistory/domain/dist/parsed-session.js +2 -0
- package/node_modules/@cchistory/domain/dist/parsed-session.js.map +1 -0
- package/node_modules/@cchistory/domain/dist/query.d.ts +67 -0
- package/node_modules/@cchistory/domain/dist/query.d.ts.map +1 -0
- package/node_modules/@cchistory/domain/dist/query.js +2 -0
- package/node_modules/@cchistory/domain/dist/query.js.map +1 -0
- package/node_modules/@cchistory/domain/dist/token-evidence.d.ts +14 -0
- package/node_modules/@cchistory/domain/dist/token-evidence.d.ts.map +1 -0
- package/node_modules/@cchistory/domain/dist/token-evidence.js +247 -0
- package/node_modules/@cchistory/domain/dist/token-evidence.js.map +1 -0
- package/node_modules/@cchistory/domain/package.json +1 -1
- package/node_modules/@cchistory/live-runtime/dist/bootstrap.d.ts +0 -1
- package/node_modules/@cchistory/live-runtime/dist/bootstrap.d.ts.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/bootstrap.js +0 -1
- package/node_modules/@cchistory/live-runtime/dist/bootstrap.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/index.d.ts +30 -9
- package/node_modules/@cchistory/live-runtime/dist/index.d.ts.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/index.js +263 -58
- package/node_modules/@cchistory/live-runtime/dist/index.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/index.test.js +177 -20
- package/node_modules/@cchistory/live-runtime/dist/index.test.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.d.ts +16 -0
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.js +55 -0
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.test.d.ts +2 -0
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.test.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.test.js +192 -0
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.test.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.d.ts +32 -23
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.d.ts.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.js +65 -45
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.test.js +363 -59
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.test.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/selective-query.d.ts +47 -0
- package/node_modules/@cchistory/live-runtime/dist/selective-query.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/selective-query.js +15 -0
- package/node_modules/@cchistory/live-runtime/dist/selective-query.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/selective-query.test.d.ts +2 -0
- package/node_modules/@cchistory/live-runtime/dist/selective-query.test.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/selective-query.test.js +166 -0
- package/node_modules/@cchistory/live-runtime/dist/selective-query.test.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.d.ts +37 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.js +301 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.test.d.ts +2 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.test.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.test.js +67 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.test.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-worker.d.ts +2 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-worker.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-worker.js +14 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-worker.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/system-memory.d.ts +13 -10
- package/node_modules/@cchistory/live-runtime/dist/system-memory.d.ts.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/system-memory.js +61 -34
- package/node_modules/@cchistory/live-runtime/dist/system-memory.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/system-memory.test.d.ts +2 -0
- package/node_modules/@cchistory/live-runtime/dist/system-memory.test.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/system-memory.test.js +76 -0
- package/node_modules/@cchistory/live-runtime/dist/system-memory.test.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/package.json +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/discovery.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/core/discovery.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/factories.d.ts +2 -4
- package/node_modules/@cchistory/source-adapters/dist/core/factories.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/factories.js +1 -23
- package/node_modules/@cchistory/source-adapters/dist/core/factories.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.d.ts +25 -0
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.js +80 -0
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.test.d.ts +2 -0
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.test.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.test.js +122 -0
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.test.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/git-project.d.ts +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/git-project.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/git-project.js +2 -11
- package/node_modules/@cchistory/source-adapters/dist/core/git-project.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/parser.d.ts +2 -1
- package/node_modules/@cchistory/source-adapters/dist/core/parser.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/parser.js +4 -4
- package/node_modules/@cchistory/source-adapters/dist/core/parser.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/probe.d.ts +8 -6
- package/node_modules/@cchistory/source-adapters/dist/core/probe.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/probe.js +54 -36
- package/node_modules/@cchistory/source-adapters/dist/core/probe.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/projections.d.ts +2 -28
- package/node_modules/@cchistory/source-adapters/dist/core/projections.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/projections.js +2 -695
- package/node_modules/@cchistory/source-adapters/dist/core/projections.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/projections.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/core/projections.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.d.ts +18 -0
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.js +27 -0
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.test.d.ts +2 -0
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.test.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.test.js +75 -0
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.test.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.d.ts +6 -0
- package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/source-identity.d.ts +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/source-identity.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/source-identity.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/source-identity.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/token-usage.d.ts +1 -13
- package/node_modules/@cchistory/source-adapters/dist/core/token-usage.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/token-usage.js +1 -246
- package/node_modules/@cchistory/source-adapters/dist/core/token-usage.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/tokens.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/tokens.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/type-guards.d.ts +1 -25
- package/node_modules/@cchistory/source-adapters/dist/core/type-guards.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/type-guards.js +1 -79
- package/node_modules/@cchistory/source-adapters/dist/core/type-guards.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/types.d.ts +6 -35
- package/node_modules/@cchistory/source-adapters/dist/core/types.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/vscode-state.d.ts +2 -1
- package/node_modules/@cchistory/source-adapters/dist/core/vscode-state.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/vscode-state.js +14 -10
- package/node_modules/@cchistory/source-adapters/dist/core/vscode-state.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/index.d.ts +6 -0
- package/node_modules/@cchistory/source-adapters/dist/index.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/index.js +4 -0
- package/node_modules/@cchistory/source-adapters/dist/index.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/index.test.d.ts +2 -0
- package/node_modules/@cchistory/source-adapters/dist/index.test.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/index.test.js +2 -0
- package/node_modules/@cchistory/source-adapters/dist/index.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/masks.d.ts +1 -30
- package/node_modules/@cchistory/source-adapters/dist/masks.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/masks.js +1 -341
- package/node_modules/@cchistory/source-adapters/dist/masks.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/accio.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/accio.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/amp.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/amp.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/claude.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/claude.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/codebuddy.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/codebuddy.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/codex/activity-evidence.d.ts +14 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/codex/activity-evidence.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/codex/activity-evidence.js +103 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/codex/activity-evidence.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/codex.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/codex.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor/runtime.d.ts +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor/runtime.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor/runtime.js +5 -3
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor/runtime.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor-agent.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor-agent.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/factory-droid.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/factory-droid.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/gemini.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/gemini.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/grok.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/grok.js +24 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/grok.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/grok.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/grok.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/kimi.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/kimi.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/lobechat.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/lobechat.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/openclaw.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/openclaw.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/opencode.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/opencode.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.d.ts +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.js +11 -9
- package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/zcode.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/zcode.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/probe-reference.test.d.ts +8 -0
- package/node_modules/@cchistory/source-adapters/dist/probe-reference.test.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/probe-reference.test.js +7 -0
- package/node_modules/@cchistory/source-adapters/dist/probe-reference.test.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/test-helpers.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/package.json +1 -1
- package/node_modules/commander/LICENSE +22 -0
- package/node_modules/commander/Readme.md +428 -0
- package/node_modules/commander/index.js +1224 -0
- package/node_modules/commander/package.json +38 -0
- package/node_modules/commander/typings/index.d.ts +310 -0
- package/node_modules/discontinuous-range/.npmignore +28 -0
- package/node_modules/discontinuous-range/.travis.yml +4 -0
- package/node_modules/discontinuous-range/LICENSE +21 -0
- package/node_modules/discontinuous-range/README.md +23 -0
- package/node_modules/discontinuous-range/index.js +144 -0
- package/node_modules/discontinuous-range/package.json +27 -0
- package/node_modules/discontinuous-range/test/main-test.js +96 -0
- package/node_modules/moo/LICENSE +29 -0
- package/node_modules/moo/README.md +385 -0
- package/node_modules/moo/moo.js +645 -0
- package/node_modules/moo/package.json +29 -0
- package/node_modules/nearley/LICENSE.txt +21 -0
- package/node_modules/nearley/README.md +80 -0
- package/node_modules/nearley/bin/nearley-railroad.js +121 -0
- package/node_modules/nearley/bin/nearley-test.js +64 -0
- package/node_modules/nearley/bin/nearley-unparse.js +29 -0
- package/node_modules/nearley/bin/nearleyc.js +38 -0
- package/node_modules/nearley/builtin/cow.ne +2 -0
- package/node_modules/nearley/builtin/number.ne +51 -0
- package/node_modules/nearley/builtin/postprocessors.ne +36 -0
- package/node_modules/nearley/builtin/string.ne +26 -0
- package/node_modules/nearley/builtin/whitespace.ne +5 -0
- package/node_modules/nearley/lib/compile.js +307 -0
- package/node_modules/nearley/lib/generate.js +244 -0
- package/node_modules/nearley/lib/lint.js +28 -0
- package/node_modules/nearley/lib/nearley-language-bootstrapped.js +132 -0
- package/node_modules/nearley/lib/nearley-language-bootstrapped.ne +126 -0
- package/node_modules/nearley/lib/nearley.js +564 -0
- package/node_modules/nearley/lib/stream.js +18 -0
- package/node_modules/nearley/lib/unparse.js +139 -0
- package/node_modules/nearley/package.json +63 -0
- package/node_modules/pgsql-ast-parser/ast-mapper.d.ts +237 -0
- package/node_modules/pgsql-ast-parser/ast-mapper.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/ast-mapper.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/ast-mapper.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/ast-visitor.d.ts +33 -0
- package/node_modules/pgsql-ast-parser/ast-visitor.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/ast-visitor.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/ast-visitor.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/index.d.ts +11 -0
- package/node_modules/pgsql-ast-parser/index.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/index.js +6484 -0
- package/node_modules/pgsql-ast-parser/index.js.map +1 -0
- package/node_modules/pgsql-ast-parser/interfaces.d.ts +1 -0
- package/node_modules/pgsql-ast-parser/interfaces.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/keywords.d.ts +2 -0
- package/node_modules/pgsql-ast-parser/keywords.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/lexer.d.ts +15 -0
- package/node_modules/pgsql-ast-parser/lexer.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/lexer.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/lexer.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/array-lexer.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/array-lexer.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/array.ne.d.ts +29 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/array.ne.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/array.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/array.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric-lexer.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric-lexer.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric.ne.d.ts +29 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric.ne.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-builder.d.ts +10 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-builder.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-iso-lexer.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-iso-lexer.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-iso.ne.d.ts +29 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-iso.ne.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-lexer.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-lexer.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval.ne.d.ts +29 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval.ne.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/package.json +69 -0
- package/node_modules/pgsql-ast-parser/parser.d.ts +33 -0
- package/node_modules/pgsql-ast-parser/parser.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/pg-escape.d.ts +2 -0
- package/node_modules/pgsql-ast-parser/pg-escape.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/readme.md +255 -0
- package/node_modules/pgsql-ast-parser/src/ast-mapper.spec.ts +296 -0
- package/node_modules/pgsql-ast-parser/src/ast-mapper.ts +1378 -0
- package/node_modules/pgsql-ast-parser/src/ast-visitor.spec.ts +57 -0
- package/node_modules/pgsql-ast-parser/src/ast-visitor.ts +101 -0
- package/node_modules/pgsql-ast-parser/src/index.ts +10 -0
- package/node_modules/pgsql-ast-parser/src/interfaces.ts +0 -0
- package/node_modules/pgsql-ast-parser/src/keywords.ts +8 -0
- package/node_modules/pgsql-ast-parser/src/lexer.spec.ts +245 -0
- package/node_modules/pgsql-ast-parser/src/lexer.ts +267 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/array-lexer.ts +27 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/array.ne +18 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/array.spec.ts +55 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/geometric-lexer.ts +26 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/geometric.ne +88 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/geometric.spec.ts +131 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval-builder.ts +148 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval-iso-lexer.ts +17 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval-iso.ne +53 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval-lexer.ts +26 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval.ne +54 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval.spec.ts +106 -0
- package/node_modules/pgsql-ast-parser/src/parser.ts +142 -0
- package/node_modules/pgsql-ast-parser/src/pg-escape.ts +14 -0
- package/node_modules/pgsql-ast-parser/src/syntax/alter-index.ne +29 -0
- package/node_modules/pgsql-ast-parser/src/syntax/alter-index.spec.ts +35 -0
- package/node_modules/pgsql-ast-parser/src/syntax/alter-table.ne +123 -0
- package/node_modules/pgsql-ast-parser/src/syntax/alter-table.spec.ts +476 -0
- package/node_modules/pgsql-ast-parser/src/syntax/alter-type.ne +33 -0
- package/node_modules/pgsql-ast-parser/src/syntax/alter-type.spec.ts +29 -0
- package/node_modules/pgsql-ast-parser/src/syntax/ast.ts +1150 -0
- package/node_modules/pgsql-ast-parser/src/syntax/base.ne +369 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-extension.ne +17 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-extension.spec.ts +37 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-index.ne +62 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-index.spec.ts +245 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-table.ne +174 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-table.spec.ts +761 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-type.ne +40 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-type.spec.ts +32 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-view.ne +68 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-view.spec.ts +187 -0
- package/node_modules/pgsql-ast-parser/src/syntax/deallocate.ne +13 -0
- package/node_modules/pgsql-ast-parser/src/syntax/deallocate.spec.ts +19 -0
- package/node_modules/pgsql-ast-parser/src/syntax/delete.ne +36 -0
- package/node_modules/pgsql-ast-parser/src/syntax/delete.spec.ts +71 -0
- package/node_modules/pgsql-ast-parser/src/syntax/drop.ne +28 -0
- package/node_modules/pgsql-ast-parser/src/syntax/drop.spec.ts +77 -0
- package/node_modules/pgsql-ast-parser/src/syntax/edge-cases.spec.ts +41 -0
- package/node_modules/pgsql-ast-parser/src/syntax/expr.ne +350 -0
- package/node_modules/pgsql-ast-parser/src/syntax/expr.spec.ts +1638 -0
- package/node_modules/pgsql-ast-parser/src/syntax/functions.ne +114 -0
- package/node_modules/pgsql-ast-parser/src/syntax/functions.spec.ts +235 -0
- package/node_modules/pgsql-ast-parser/src/syntax/insert.ne +63 -0
- package/node_modules/pgsql-ast-parser/src/syntax/insert.spec.ts +292 -0
- package/node_modules/pgsql-ast-parser/src/syntax/main.ne +77 -0
- package/node_modules/pgsql-ast-parser/src/syntax/nearley.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/src/syntax/prepare.ne +8 -0
- package/node_modules/pgsql-ast-parser/src/syntax/prepare.spec.ts +44 -0
- package/node_modules/pgsql-ast-parser/src/syntax/refresh-materialized-view.ne +19 -0
- package/node_modules/pgsql-ast-parser/src/syntax/refresh-materialized-view.spec.ts +42 -0
- package/node_modules/pgsql-ast-parser/src/syntax/select.ne +223 -0
- package/node_modules/pgsql-ast-parser/src/syntax/select.spec.ts +1063 -0
- package/node_modules/pgsql-ast-parser/src/syntax/sequence.ne +101 -0
- package/node_modules/pgsql-ast-parser/src/syntax/sequence.spec.ts +103 -0
- package/node_modules/pgsql-ast-parser/src/syntax/simple-statements.ne +168 -0
- package/node_modules/pgsql-ast-parser/src/syntax/simple-statements.spec.ts +327 -0
- package/node_modules/pgsql-ast-parser/src/syntax/spec-utils.ts +333 -0
- package/node_modules/pgsql-ast-parser/src/syntax/union.ne +18 -0
- package/node_modules/pgsql-ast-parser/src/syntax/union.spec.ts +125 -0
- package/node_modules/pgsql-ast-parser/src/syntax/update.ne +56 -0
- package/node_modules/pgsql-ast-parser/src/syntax/update.spec.ts +87 -0
- package/node_modules/pgsql-ast-parser/src/syntax/with.ne +41 -0
- package/node_modules/pgsql-ast-parser/src/syntax/with.spec.ts +155 -0
- package/node_modules/pgsql-ast-parser/src/to-sql.spec.ts +85 -0
- package/node_modules/pgsql-ast-parser/src/to-sql.ts +1555 -0
- package/node_modules/pgsql-ast-parser/src/utils.ts +47 -0
- package/node_modules/pgsql-ast-parser/syntax/alter-index.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/alter-index.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/alter-table.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/alter-table.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/alter-type.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/alter-type.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/ast.d.ts +826 -0
- package/node_modules/pgsql-ast-parser/syntax/ast.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/create-extension.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/create-extension.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/create-index.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/create-index.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/create-table.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/create-table.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/create-type.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/create-type.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/create-view.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/create-view.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/deallocate.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/deallocate.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/delete.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/delete.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/drop.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/drop.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/edge-cases.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/edge-cases.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/expr.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/expr.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/functions.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/functions.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/insert.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/insert.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/main.ne.d.ts +29 -0
- package/node_modules/pgsql-ast-parser/syntax/main.ne.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/prepare.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/prepare.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/refresh-materialized-view.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/refresh-materialized-view.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/select.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/select.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/sequence.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/sequence.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/simple-statements.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/simple-statements.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/spec-utils.d.ts +35 -0
- package/node_modules/pgsql-ast-parser/syntax/spec-utils.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/union.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/union.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/update.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/update.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/with.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/with.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/to-sql.d.ts +7 -0
- package/node_modules/pgsql-ast-parser/to-sql.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/to-sql.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/to-sql.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/utils.d.ts +16 -0
- package/node_modules/pgsql-ast-parser/utils.d.ts.map +1 -0
- package/node_modules/railroad-diagrams/.gitattributes +22 -0
- package/node_modules/railroad-diagrams/.npmignore +163 -0
- package/node_modules/railroad-diagrams/README.md +86 -0
- package/node_modules/railroad-diagrams/css-example.py-js +183 -0
- package/node_modules/railroad-diagrams/example.html +141 -0
- package/node_modules/railroad-diagrams/generator.html +59 -0
- package/node_modules/railroad-diagrams/package.json +23 -0
- package/node_modules/railroad-diagrams/railroad-diagrams.css +23 -0
- package/node_modules/railroad-diagrams/railroad-diagrams.js +524 -0
- package/node_modules/railroad-diagrams/railroad_diagrams.py +427 -0
- package/node_modules/randexp/LICENSE +19 -0
- package/node_modules/randexp/README.md +134 -0
- package/node_modules/randexp/lib/randexp.js +245 -0
- package/node_modules/randexp/package.json +48 -0
- package/node_modules/ret/LICENSE +19 -0
- package/node_modules/ret/README.md +183 -0
- package/node_modules/ret/lib/index.js +282 -0
- package/node_modules/ret/lib/positions.js +17 -0
- package/node_modules/ret/lib/sets.js +82 -0
- package/node_modules/ret/lib/types.js +10 -0
- package/node_modules/ret/lib/util.js +111 -0
- package/node_modules/ret/package.json +35 -0
- package/package.json +22 -6
- package/schemas/cchistory-lite-agent-v1.schema.json +6 -7
- package/schemas/cchistory-lite-error-v1.schema.json +58 -8
- package/schemas/cchistory-lite-query-result-v2.schema.json +66 -11
- package/schemas/cchistory-lite-query-result-v3.schema.json +219 -0
- package/schemas/cchistory-lite-query-v3.schema.json +57 -0
- package/schemas/cchistory-lite-source-inventory-v1.schema.json +72 -0
- package/skills/using-cchistory-lite/SKILL.md +125 -53
- package/node_modules/@cchistory/live-runtime/dist/node-memory.d.ts +0 -8
- package/node_modules/@cchistory/live-runtime/dist/node-memory.d.ts.map +0 -1
- package/node_modules/@cchistory/live-runtime/dist/node-memory.js +0 -110
- package/node_modules/@cchistory/live-runtime/dist/node-memory.js.map +0 -1
|
@@ -0,0 +1,713 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { joinDisplaySegments, applyMaskTemplates, LITERAL_PROMPT_MASK_TEMPLATE_IDS, stableId, asString, nowIso, truncate, isObject, mergeTokenUsageMetrics, sha1, normalizeGitRemote, normalizeLocalPathIdentity as normalizeWorkspacePath, findLastConversationActivityAtom, isUserTurnAtom, extractTokenUsageFromPayload, extractTokenCountFromPayload, extractStopReasonFromPayload, EVIDENCE_RULE_VERSION as RULE_VERSION, } from "@cchistory/domain";
|
|
3
|
+
const normalizePathSeparators = (value) => value.replace(/\\/g, "/");
|
|
4
|
+
/** Interpret reconciled evidence once. This entry currently constructs complete detail. */
|
|
5
|
+
export function interpretSessionEvidence(evidence) {
|
|
6
|
+
const { draft, atoms, fragments, records, blobs } = evidence;
|
|
7
|
+
const projectCandidates = buildProjectObservationCandidates(draft, atoms, evidence.gitProjectEvidence);
|
|
8
|
+
const submission = buildSubmissionGroups(draft, atoms, evidence.edges);
|
|
9
|
+
const result = buildTurnsAndContext(draft, fragments, records, blobs, atoms, submission.groups, submission.edges);
|
|
10
|
+
const suppressed = draft.source_platform === "codebuddy" && result.turns.length === 0 && atoms.length === 0;
|
|
11
|
+
return {
|
|
12
|
+
session: suppressed ? undefined : result.session,
|
|
13
|
+
candidates: suppressed ? [] : [...projectCandidates, ...submission.groups, ...result.turnCandidates, ...result.contextCandidates],
|
|
14
|
+
turns: suppressed ? [] : result.turns,
|
|
15
|
+
contexts: suppressed ? [] : result.contexts,
|
|
16
|
+
// Preserve the legacy payload's edge multiplicity during this ownership move.
|
|
17
|
+
// The old builder appended submission edges in place, then flattened that array twice.
|
|
18
|
+
edges: [...submission.edges, ...submission.edges],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function buildProjectObservationCandidates(draft, atoms, gitProjectEvidence) {
|
|
22
|
+
const workspaceSignals = new Map();
|
|
23
|
+
for (const atom of atoms) {
|
|
24
|
+
if (atom.content_kind !== "meta_signal") {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (atom.payload.signal_kind !== "workspace_signal") {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const workspacePath = asString(atom.payload.path);
|
|
31
|
+
if (!workspacePath) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const workspacePathNormalized = normalizeWorkspacePath(workspacePath) ?? workspacePath;
|
|
35
|
+
workspaceSignals.set(workspacePathNormalized, atom);
|
|
36
|
+
}
|
|
37
|
+
const workspaceCandidates = [...workspaceSignals.values()].map((atom) => {
|
|
38
|
+
const sourceBackedRepoRoot = normalizeWorkspacePath(asString(atom.payload.repo_root) ?? "");
|
|
39
|
+
const sourceBackedRepoRemote = normalizeGitRemote(asString(atom.payload.repo_remote));
|
|
40
|
+
const observedRepoRoot = sourceBackedRepoRoot ?? gitProjectEvidence?.repoRoot;
|
|
41
|
+
const observedRepoRemote = sourceBackedRepoRemote;
|
|
42
|
+
const observedRepoFingerprint = sourceBackedRepoRemote
|
|
43
|
+
? sha1(Buffer.from(`repo-remote:${sourceBackedRepoRemote}`))
|
|
44
|
+
: undefined;
|
|
45
|
+
const debugSummary = sourceBackedRepoRemote
|
|
46
|
+
? "workspace signal with source-backed repository evidence"
|
|
47
|
+
: sourceBackedRepoRoot
|
|
48
|
+
? "workspace signal with source-backed repository root"
|
|
49
|
+
: observedRepoRoot
|
|
50
|
+
? "workspace signal with git-backed repository root"
|
|
51
|
+
: "workspace signal without git repository evidence";
|
|
52
|
+
return {
|
|
53
|
+
id: stableId("candidate", "project_observation", draft.source_id, draft.id, normalizeWorkspacePath(asString(atom.payload.path) ?? "") ?? String(atom.payload.path)),
|
|
54
|
+
source_id: draft.source_id,
|
|
55
|
+
session_ref: draft.id,
|
|
56
|
+
candidate_kind: "project_observation",
|
|
57
|
+
input_atom_refs: [atom.id],
|
|
58
|
+
started_at: atom.time_key,
|
|
59
|
+
ended_at: atom.time_key,
|
|
60
|
+
rule_version: RULE_VERSION,
|
|
61
|
+
evidence: {
|
|
62
|
+
workspace_path: atom.payload.path,
|
|
63
|
+
workspace_path_normalized: normalizeWorkspacePath(asString(atom.payload.path) ?? ""),
|
|
64
|
+
repo_root: observedRepoRoot,
|
|
65
|
+
repo_remote: observedRepoRemote,
|
|
66
|
+
repo_fingerprint: observedRepoFingerprint,
|
|
67
|
+
source_native_project_ref: draft.source_native_project_ref,
|
|
68
|
+
confidence: 0.5,
|
|
69
|
+
reason: "workspace_signal_detected",
|
|
70
|
+
debug_summary: debugSummary,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
if (workspaceCandidates.length > 0) {
|
|
75
|
+
return workspaceCandidates;
|
|
76
|
+
}
|
|
77
|
+
if (!draft.source_native_project_ref) {
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
const seedAtom = atoms[0];
|
|
81
|
+
const observedAt = seedAtom?.time_key ?? draft.updated_at ?? draft.created_at ?? nowIso();
|
|
82
|
+
return [
|
|
83
|
+
{
|
|
84
|
+
id: stableId("candidate", "project_observation", draft.source_id, draft.id, draft.source_native_project_ref),
|
|
85
|
+
source_id: draft.source_id,
|
|
86
|
+
session_ref: draft.id,
|
|
87
|
+
candidate_kind: "project_observation",
|
|
88
|
+
input_atom_refs: seedAtom ? [seedAtom.id] : [],
|
|
89
|
+
started_at: observedAt,
|
|
90
|
+
ended_at: observedAt,
|
|
91
|
+
rule_version: RULE_VERSION,
|
|
92
|
+
evidence: {
|
|
93
|
+
source_native_project_ref: draft.source_native_project_ref,
|
|
94
|
+
confidence: 0.35,
|
|
95
|
+
reason: "source_native_project_detected",
|
|
96
|
+
debug_summary: "source-native project reference without explicit workspace signal",
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
export function buildSubmissionGroups(draft, atoms, inputEdges) {
|
|
102
|
+
const edges = [...inputEdges];
|
|
103
|
+
const groups = [];
|
|
104
|
+
let currentGroupAtomIds = [];
|
|
105
|
+
let currentStartedAt;
|
|
106
|
+
let currentEndedAt;
|
|
107
|
+
let lastUserAtomId;
|
|
108
|
+
let assistantSeenAfterGroupStart = false;
|
|
109
|
+
let groupIndex = 0;
|
|
110
|
+
const commitGroup = () => {
|
|
111
|
+
if (currentGroupAtomIds.length === 0 || !currentStartedAt || !currentEndedAt) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
groups.push({
|
|
115
|
+
id: stableId("candidate", "submission_group", draft.source_id, draft.id, String(groupIndex)),
|
|
116
|
+
source_id: draft.source_id,
|
|
117
|
+
session_ref: draft.id,
|
|
118
|
+
candidate_kind: "submission_group",
|
|
119
|
+
input_atom_refs: [...currentGroupAtomIds],
|
|
120
|
+
started_at: currentStartedAt,
|
|
121
|
+
ended_at: currentEndedAt,
|
|
122
|
+
rule_version: RULE_VERSION,
|
|
123
|
+
evidence: {
|
|
124
|
+
group_index: groupIndex,
|
|
125
|
+
assistant_seen_after_group_start: assistantSeenAfterGroupStart,
|
|
126
|
+
boundary_reason: assistantSeenAfterGroupStart
|
|
127
|
+
? "assistant reply observed after the current user submission"
|
|
128
|
+
: "consecutive user-authored or injected fragments continued the same submission",
|
|
129
|
+
debug_atom_refs: [...currentGroupAtomIds],
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
groupIndex += 1;
|
|
133
|
+
currentGroupAtomIds = [];
|
|
134
|
+
currentStartedAt = undefined;
|
|
135
|
+
currentEndedAt = undefined;
|
|
136
|
+
lastUserAtomId = undefined;
|
|
137
|
+
assistantSeenAfterGroupStart = false;
|
|
138
|
+
};
|
|
139
|
+
for (const atom of atoms) {
|
|
140
|
+
if (atom.actor_kind === "assistant" && atom.content_kind === "text" && atom.display_policy !== "hide") {
|
|
141
|
+
assistantSeenAfterGroupStart = currentGroupAtomIds.length > 0 || assistantSeenAfterGroupStart;
|
|
142
|
+
}
|
|
143
|
+
if (!isUserTurnAtom(atom)) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const antigravityStartsFreshGroup = draft.source_platform === "antigravity" && atom.origin_kind === "user_authored" && currentGroupAtomIds.length > 0;
|
|
147
|
+
const continuesCurrentGroup = currentGroupAtomIds.length > 0 &&
|
|
148
|
+
!antigravityStartsFreshGroup &&
|
|
149
|
+
(!assistantSeenAfterGroupStart || atom.origin_kind === "injected_user_shaped");
|
|
150
|
+
if (!continuesCurrentGroup) {
|
|
151
|
+
commitGroup();
|
|
152
|
+
}
|
|
153
|
+
if (!currentStartedAt) {
|
|
154
|
+
currentStartedAt = atom.time_key;
|
|
155
|
+
}
|
|
156
|
+
currentEndedAt = atom.time_key;
|
|
157
|
+
currentGroupAtomIds.push(atom.id);
|
|
158
|
+
if (lastUserAtomId) {
|
|
159
|
+
edges.push({
|
|
160
|
+
id: stableId("edge", draft.source_id, draft.id, atom.id, lastUserAtomId, "same_submission"),
|
|
161
|
+
source_id: draft.source_id,
|
|
162
|
+
session_ref: draft.id,
|
|
163
|
+
from_atom_id: atom.id,
|
|
164
|
+
to_atom_id: lastUserAtomId,
|
|
165
|
+
edge_kind: "same_submission",
|
|
166
|
+
});
|
|
167
|
+
if (continuesCurrentGroup) {
|
|
168
|
+
edges.push({
|
|
169
|
+
id: stableId("edge", draft.source_id, draft.id, atom.id, lastUserAtomId, "continuation_of"),
|
|
170
|
+
source_id: draft.source_id,
|
|
171
|
+
session_ref: draft.id,
|
|
172
|
+
from_atom_id: atom.id,
|
|
173
|
+
to_atom_id: lastUserAtomId,
|
|
174
|
+
edge_kind: "continuation_of",
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
lastUserAtomId = atom.id;
|
|
179
|
+
}
|
|
180
|
+
commitGroup();
|
|
181
|
+
return { groups, edges };
|
|
182
|
+
}
|
|
183
|
+
export function buildTurnsAndContext(draft, fragments, records, blobs, atoms, submissionGroups, edges) {
|
|
184
|
+
const turnCandidates = [];
|
|
185
|
+
const contextCandidates = [];
|
|
186
|
+
const turns = [];
|
|
187
|
+
const contexts = [];
|
|
188
|
+
const fragmentById = new Map(fragments.map((fragment) => [fragment.id, fragment]));
|
|
189
|
+
const recordById = new Map(records.map((record) => [record.id, record]));
|
|
190
|
+
const blobById = new Map(blobs.map((blob) => [blob.id, blob]));
|
|
191
|
+
const atomById = new Map();
|
|
192
|
+
const atomIndexById = new Map();
|
|
193
|
+
for (const [index, atom] of atoms.entries()) {
|
|
194
|
+
atomById.set(atom.id, atom);
|
|
195
|
+
atomIndexById.set(atom.id, index);
|
|
196
|
+
}
|
|
197
|
+
const edgeIndex = buildTurnContextEdgeIndex(edges);
|
|
198
|
+
for (const [index, group] of submissionGroups.entries()) {
|
|
199
|
+
const firstAtomId = group.input_atom_refs[0];
|
|
200
|
+
if (!firstAtomId) {
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
const atomIndex = atomIndexById.get(firstAtomId) ?? -1;
|
|
204
|
+
const nextGroup = submissionGroups[index + 1];
|
|
205
|
+
const nextStartAtomId = nextGroup?.input_atom_refs[0];
|
|
206
|
+
const nextIndex = nextStartAtomId ? atomIndexById.get(nextStartAtomId) : undefined;
|
|
207
|
+
const currentGroupAtomSet = new Set(group.input_atom_refs);
|
|
208
|
+
const turnId = stableId("turn", draft.source_id, draft.id, String(index));
|
|
209
|
+
const contextAtoms = [];
|
|
210
|
+
const contextAtomIds = new Set();
|
|
211
|
+
const contextEndIndex = nextIndex === undefined || nextIndex < 0 ? atoms.length : nextIndex;
|
|
212
|
+
if (atomIndex >= 0) {
|
|
213
|
+
for (let atomIndexValue = atomIndex + 1; atomIndexValue < contextEndIndex; atomIndexValue += 1) {
|
|
214
|
+
const atom = atoms[atomIndexValue];
|
|
215
|
+
if (!atom || currentGroupAtomSet.has(atom.id)) {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
contextAtoms.push(atom);
|
|
219
|
+
contextAtomIds.add(atom.id);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const groupAtoms = [];
|
|
223
|
+
for (const atomId of group.input_atom_refs) {
|
|
224
|
+
const atom = atomById.get(atomId);
|
|
225
|
+
if (atom) {
|
|
226
|
+
groupAtoms.push(atom);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const turnCandidateId = stableId("candidate", "turn", draft.source_id, draft.id, String(index));
|
|
230
|
+
const contextCandidateId = stableId("candidate", "context", draft.source_id, draft.id, String(index));
|
|
231
|
+
const userMessages = groupAtoms
|
|
232
|
+
.filter((atom) => atom.content_kind === "text" && (atom.origin_kind === "user_authored" || atom.origin_kind === "injected_user_shaped"))
|
|
233
|
+
.map((atom, userIndex) => {
|
|
234
|
+
const rawText = asString(atom.payload.text) ?? "";
|
|
235
|
+
const isInjected = atom.origin_kind === "injected_user_shaped";
|
|
236
|
+
const masked = applyMaskTemplates(rawText, "user_message", {
|
|
237
|
+
injected: isInjected,
|
|
238
|
+
exclude_template_ids: draft.source_platform === "antigravity" && !isInjected ? LITERAL_PROMPT_MASK_TEMPLATE_IDS : undefined,
|
|
239
|
+
});
|
|
240
|
+
return {
|
|
241
|
+
id: stableId("user-message", draft.source_id, draft.id, atom.id),
|
|
242
|
+
raw_text: rawText,
|
|
243
|
+
sequence: userIndex,
|
|
244
|
+
is_injected: isInjected,
|
|
245
|
+
created_at: atom.time_key,
|
|
246
|
+
atom_refs: [atom.id],
|
|
247
|
+
canonical_text: masked.canonical_text,
|
|
248
|
+
display_segments: masked.display_segments,
|
|
249
|
+
};
|
|
250
|
+
});
|
|
251
|
+
const rawText = userMessages.map((message) => message.raw_text).join("\n\n");
|
|
252
|
+
const displaySegments = joinDisplaySegments(userMessages.map((message) => message.display_segments ?? [{ type: message.is_injected ? "injected" : "text", content: message.raw_text }]));
|
|
253
|
+
const canonicalText = userMessages
|
|
254
|
+
.map((message) => message.canonical_text ?? "")
|
|
255
|
+
.filter((value) => value.length > 0)
|
|
256
|
+
.join("\n\n");
|
|
257
|
+
const contextProjection = buildTurnContext(turnId, draft, groupAtoms, contextAtoms, fragmentById, edges, {
|
|
258
|
+
atomById,
|
|
259
|
+
contextAtomIds,
|
|
260
|
+
edgeIndex,
|
|
261
|
+
});
|
|
262
|
+
const hasAuthoredUserInput = userMessages.some((message) => !message.is_injected);
|
|
263
|
+
if (!hasAuthoredUserInput) {
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
const lastActivityAtom = findLastConversationActivityAtom(contextAtoms) ?? findLastConversationActivityAtom(groupAtoms);
|
|
267
|
+
const lastActivityAt = lastActivityAtom?.time_key ?? group.ended_at;
|
|
268
|
+
turnCandidates.push({
|
|
269
|
+
id: turnCandidateId,
|
|
270
|
+
source_id: draft.source_id,
|
|
271
|
+
session_ref: draft.id,
|
|
272
|
+
candidate_kind: "turn",
|
|
273
|
+
input_atom_refs: groupAtoms.map((atom) => atom.id),
|
|
274
|
+
started_at: group.started_at,
|
|
275
|
+
ended_at: lastActivityAt,
|
|
276
|
+
rule_version: RULE_VERSION,
|
|
277
|
+
evidence: {
|
|
278
|
+
submission_group_id: group.id,
|
|
279
|
+
},
|
|
280
|
+
});
|
|
281
|
+
contextCandidates.push({
|
|
282
|
+
id: contextCandidateId,
|
|
283
|
+
source_id: draft.source_id,
|
|
284
|
+
session_ref: draft.id,
|
|
285
|
+
candidate_kind: "context_span",
|
|
286
|
+
input_atom_refs: contextAtoms.map((atom) => atom.id),
|
|
287
|
+
started_at: group.started_at,
|
|
288
|
+
ended_at: lastActivityAt,
|
|
289
|
+
rule_version: RULE_VERSION,
|
|
290
|
+
evidence: {
|
|
291
|
+
turn_candidate_id: turnCandidateId,
|
|
292
|
+
},
|
|
293
|
+
});
|
|
294
|
+
const allFragmentIds = new Set();
|
|
295
|
+
const allRecordIds = new Set();
|
|
296
|
+
const allBlobIds = new Set();
|
|
297
|
+
for (const atom of [...groupAtoms, ...contextAtoms]) {
|
|
298
|
+
for (const fragmentId of atom.fragment_refs) {
|
|
299
|
+
allFragmentIds.add(fragmentId);
|
|
300
|
+
const recordId = fragmentById.get(fragmentId)?.record_id;
|
|
301
|
+
if (recordId) {
|
|
302
|
+
allRecordIds.add(recordId);
|
|
303
|
+
const blobId = recordById.get(recordId)?.blob_id;
|
|
304
|
+
if (blobId && blobById.get(blobId)) {
|
|
305
|
+
allBlobIds.add(blobId);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
const contextTokenUsage = summarizeAssistantReplyUsage(contextProjection.assistant_replies);
|
|
311
|
+
const hasNoAssistantReply = contextProjection.assistant_replies.length === 0;
|
|
312
|
+
turns.push({
|
|
313
|
+
id: turnId,
|
|
314
|
+
revision_id: `${turnId}:r1`,
|
|
315
|
+
turn_id: turnId,
|
|
316
|
+
turn_revision_id: `${turnId}:r1`,
|
|
317
|
+
user_messages: userMessages,
|
|
318
|
+
raw_text: rawText,
|
|
319
|
+
canonical_text: canonicalText || extractCanonicalFallback(displaySegments),
|
|
320
|
+
display_segments: displaySegments,
|
|
321
|
+
created_at: group.started_at,
|
|
322
|
+
submission_started_at: group.started_at,
|
|
323
|
+
last_context_activity_at: lastActivityAt,
|
|
324
|
+
session_id: draft.id,
|
|
325
|
+
source_id: draft.source_id,
|
|
326
|
+
link_state: "unlinked",
|
|
327
|
+
sync_axis: "current",
|
|
328
|
+
value_axis: "active",
|
|
329
|
+
retention_axis: "keep_raw_and_derived",
|
|
330
|
+
context_ref: contextCandidateId,
|
|
331
|
+
context_summary: {
|
|
332
|
+
assistant_reply_count: contextProjection.assistant_replies.length,
|
|
333
|
+
tool_call_count: contextProjection.tool_calls.length,
|
|
334
|
+
token_usage: contextTokenUsage,
|
|
335
|
+
total_tokens: contextTokenUsage?.total_tokens,
|
|
336
|
+
primary_model: summarizeAssistantReplyPrimaryModel(contextProjection.assistant_replies) ?? draft.model,
|
|
337
|
+
has_errors: contextProjection.assistant_replies.some((reply) => reply.stop_reason === "error"),
|
|
338
|
+
zero_token_reason: hasNoAssistantReply ? "no_assistant_reply" : undefined,
|
|
339
|
+
},
|
|
340
|
+
lineage: {
|
|
341
|
+
atom_refs: [...groupAtoms.map((atom) => atom.id), ...contextAtoms.map((atom) => atom.id)],
|
|
342
|
+
candidate_refs: [turnCandidateId, contextCandidateId],
|
|
343
|
+
fragment_refs: Array.from(allFragmentIds),
|
|
344
|
+
record_refs: Array.from(allRecordIds),
|
|
345
|
+
blob_refs: Array.from(allBlobIds),
|
|
346
|
+
},
|
|
347
|
+
path_text: buildTurnPathText(draft, contextProjection, groupAtoms, contextAtoms),
|
|
348
|
+
});
|
|
349
|
+
contexts.push(contextProjection);
|
|
350
|
+
}
|
|
351
|
+
const session = {
|
|
352
|
+
id: draft.id,
|
|
353
|
+
source_id: draft.source_id,
|
|
354
|
+
host_id: draft.host_id,
|
|
355
|
+
source_platform: draft.source_platform,
|
|
356
|
+
title: draft.title,
|
|
357
|
+
canonical_title: draft.canonical_title ?? canonicalizeSessionTitle(draft.title),
|
|
358
|
+
created_at: draft.created_at ?? atoms[0]?.time_key ?? nowIso(),
|
|
359
|
+
updated_at: draft.updated_at ?? atoms.at(-1)?.time_key ?? nowIso(),
|
|
360
|
+
model: draft.model,
|
|
361
|
+
working_directory: draft.working_directory,
|
|
362
|
+
source_native_project_ref: draft.source_native_project_ref,
|
|
363
|
+
source_session_id: draft.source_session_id,
|
|
364
|
+
resume_command: draft.resume_command,
|
|
365
|
+
resume_working_directory: draft.resume_working_directory,
|
|
366
|
+
resume_command_confidence: draft.resume_command_confidence,
|
|
367
|
+
turn_count: turns.length,
|
|
368
|
+
sync_axis: "current",
|
|
369
|
+
};
|
|
370
|
+
return { session, turnCandidates, contextCandidates, turns, contexts };
|
|
371
|
+
}
|
|
372
|
+
function canonicalizeSessionTitle(title) {
|
|
373
|
+
if (!title)
|
|
374
|
+
return undefined;
|
|
375
|
+
return applyMaskTemplates(title, "user_message").canonical_text || undefined;
|
|
376
|
+
}
|
|
377
|
+
function buildTurnContextEdgeIndex(edges) {
|
|
378
|
+
const spawnedFromAtomIdByToolAtomId = new Map();
|
|
379
|
+
const toolResultAtomIdByToolAtomId = new Map();
|
|
380
|
+
for (const edge of edges) {
|
|
381
|
+
if (edge.edge_kind === "spawned_from" && !spawnedFromAtomIdByToolAtomId.has(edge.from_atom_id)) {
|
|
382
|
+
spawnedFromAtomIdByToolAtomId.set(edge.from_atom_id, edge.to_atom_id);
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
if (edge.edge_kind === "tool_result_for" && !toolResultAtomIdByToolAtomId.has(edge.to_atom_id)) {
|
|
386
|
+
toolResultAtomIdByToolAtomId.set(edge.to_atom_id, edge.from_atom_id);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return {
|
|
390
|
+
spawnedFromAtomIdByToolAtomId,
|
|
391
|
+
toolResultAtomIdByToolAtomId,
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
export function buildTurnContext(turnId, draft, groupAtoms, contextAtoms, fragmentById, edges, buildIndex) {
|
|
395
|
+
const assistantReplies = [];
|
|
396
|
+
const systemMessages = [];
|
|
397
|
+
const toolCalls = [];
|
|
398
|
+
const rawEventRefs = new Set();
|
|
399
|
+
const replyIdByAtomId = new Map();
|
|
400
|
+
const toolCallIdsByReplyId = new Map();
|
|
401
|
+
let toolSequence = 0;
|
|
402
|
+
let activeModel = draft.model;
|
|
403
|
+
const contextIndex = buildIndex ??
|
|
404
|
+
{
|
|
405
|
+
atomById: new Map(contextAtoms.map((atom) => [atom.id, atom])),
|
|
406
|
+
contextAtomIds: new Set(contextAtoms.map((atom) => atom.id)),
|
|
407
|
+
edgeIndex: buildTurnContextEdgeIndex(edges),
|
|
408
|
+
};
|
|
409
|
+
for (const atom of groupAtoms) {
|
|
410
|
+
for (const fragmentId of atom.fragment_refs) {
|
|
411
|
+
const recordId = fragmentById.get(fragmentId)?.record_id;
|
|
412
|
+
if (recordId) {
|
|
413
|
+
rawEventRefs.add(recordId);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
const signalsByReply = new Map();
|
|
418
|
+
// Maps Claude message.id → index of the assistant reply that contains that
|
|
419
|
+
// message's text. Used to attribute token_usage_signal atoms to the correct
|
|
420
|
+
// reply even when the signal atom arrives in the stream before the text atom
|
|
421
|
+
// (which happens because the signal is emitted from the first non-text chunk
|
|
422
|
+
// of a multi-block message, and that chunk precedes the text chunk in JSONL).
|
|
423
|
+
const replyIndexByMessageId = new Map();
|
|
424
|
+
// Signals whose message.id has not yet been seen on a text reply. These are
|
|
425
|
+
// real billed API calls — either they arrive before their own text reply
|
|
426
|
+
// (queued until the reply shows up), or they belong to a tool-only / thinking-
|
|
427
|
+
// only message that has no text reply at all (orphan; attributed to the next
|
|
428
|
+
// reply in the session so their tokens are not silently dropped).
|
|
429
|
+
const pendingSignals = [];
|
|
430
|
+
let currentReplyIndex = -1;
|
|
431
|
+
for (const atom of contextAtoms) {
|
|
432
|
+
for (const fragmentId of atom.fragment_refs) {
|
|
433
|
+
const recordId = fragmentById.get(fragmentId)?.record_id;
|
|
434
|
+
if (recordId) {
|
|
435
|
+
rawEventRefs.add(recordId);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
for (const atom of contextAtoms) {
|
|
440
|
+
if (atom.content_kind === "meta_signal" && atom.payload.signal_kind === "model_signal") {
|
|
441
|
+
const signalModel = asString(atom.payload.model);
|
|
442
|
+
if (signalModel) {
|
|
443
|
+
activeModel = signalModel;
|
|
444
|
+
}
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
447
|
+
if (atom.actor_kind === "system" && atom.content_kind === "text" && atom.display_policy !== "hide") {
|
|
448
|
+
const content = asString(atom.payload.text) ?? "";
|
|
449
|
+
const masked = applyMaskTemplates(content, "system_message");
|
|
450
|
+
systemMessages.push({
|
|
451
|
+
id: stableId("system-message", draft.source_id, draft.id, atom.id),
|
|
452
|
+
content,
|
|
453
|
+
display_segments: masked.display_segments,
|
|
454
|
+
position: "interleaved",
|
|
455
|
+
sequence: systemMessages.length,
|
|
456
|
+
created_at: atom.time_key,
|
|
457
|
+
});
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
460
|
+
if (atom.actor_kind === "assistant" && atom.content_kind === "text" && atom.display_policy !== "hide") {
|
|
461
|
+
const replyId = stableId("assistant-reply", draft.source_id, draft.id, atom.id);
|
|
462
|
+
replyIdByAtomId.set(atom.id, replyId);
|
|
463
|
+
const content = asString(atom.payload.text) ?? "";
|
|
464
|
+
const masked = applyMaskTemplates(content, "assistant_reply");
|
|
465
|
+
const tokenUsage = extractTokenUsageFromPayload(atom.payload);
|
|
466
|
+
const replyModel = asString(atom.payload.model) ??
|
|
467
|
+
tokenUsage?.model ??
|
|
468
|
+
activeModel ??
|
|
469
|
+
draft.model ??
|
|
470
|
+
"unknown";
|
|
471
|
+
const reply = {
|
|
472
|
+
id: replyId,
|
|
473
|
+
content,
|
|
474
|
+
canonical_text: masked.canonical_text,
|
|
475
|
+
display_segments: masked.display_segments,
|
|
476
|
+
content_preview: truncate(masked.canonical_text || content, 140),
|
|
477
|
+
token_usage: tokenUsage,
|
|
478
|
+
token_count: extractTokenCountFromPayload(atom.payload) ?? tokenUsage?.total_tokens,
|
|
479
|
+
model: replyModel,
|
|
480
|
+
created_at: atom.time_key,
|
|
481
|
+
tool_call_ids: [],
|
|
482
|
+
stop_reason: extractStopReasonFromPayload(atom.payload),
|
|
483
|
+
};
|
|
484
|
+
assistantReplies.push(reply);
|
|
485
|
+
currentReplyIndex = assistantReplies.length - 1;
|
|
486
|
+
if (replyModel !== "unknown") {
|
|
487
|
+
activeModel = replyModel;
|
|
488
|
+
}
|
|
489
|
+
const replyMessageId = asString(atom.payload.message_id);
|
|
490
|
+
if (replyMessageId) {
|
|
491
|
+
replyIndexByMessageId.set(replyMessageId, currentReplyIndex);
|
|
492
|
+
}
|
|
493
|
+
// Flush any signals that arrived earlier in the session without a
|
|
494
|
+
// matching text reply — either their own reply (now created) or as
|
|
495
|
+
// orphans attributed to this turn.
|
|
496
|
+
if (pendingSignals.length > 0) {
|
|
497
|
+
const signals = signalsByReply.get(currentReplyIndex) ?? [];
|
|
498
|
+
for (const pending of pendingSignals) {
|
|
499
|
+
signals.push(pending);
|
|
500
|
+
}
|
|
501
|
+
signalsByReply.set(currentReplyIndex, signals);
|
|
502
|
+
pendingSignals.length = 0;
|
|
503
|
+
}
|
|
504
|
+
continue;
|
|
505
|
+
}
|
|
506
|
+
if (atom.content_kind === "meta_signal" &&
|
|
507
|
+
atom.payload.signal_kind === "token_usage_signal") {
|
|
508
|
+
const signalMessageId = asString(atom.payload.message_id);
|
|
509
|
+
const matchedReplyIndex = signalMessageId !== undefined ? replyIndexByMessageId.get(signalMessageId) : undefined;
|
|
510
|
+
if (signalMessageId !== undefined && matchedReplyIndex === undefined) {
|
|
511
|
+
// Signal's message.id has no text reply yet (and may never have one).
|
|
512
|
+
// Queue rather than mis-attribute to the most recent reply.
|
|
513
|
+
pendingSignals.push(atom);
|
|
514
|
+
}
|
|
515
|
+
else {
|
|
516
|
+
const targetReplyIndex = matchedReplyIndex ?? currentReplyIndex;
|
|
517
|
+
if (targetReplyIndex >= 0) {
|
|
518
|
+
let signals = signalsByReply.get(targetReplyIndex);
|
|
519
|
+
if (!signals) {
|
|
520
|
+
signals = [];
|
|
521
|
+
signalsByReply.set(targetReplyIndex, signals);
|
|
522
|
+
}
|
|
523
|
+
signals.push(atom);
|
|
524
|
+
}
|
|
525
|
+
else {
|
|
526
|
+
pendingSignals.push(atom);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
// Trailing orphans: signals whose message.id has no text reply anywhere in
|
|
532
|
+
// the session (tool-only / thinking-only API calls). Attribute them to the
|
|
533
|
+
// last assistant reply so their billing is not silently dropped. If the
|
|
534
|
+
// session has no text reply at all, there is nowhere to anchor the cost and
|
|
535
|
+
// the tokens are dropped — logged as a known limitation.
|
|
536
|
+
if (pendingSignals.length > 0 && assistantReplies.length > 0) {
|
|
537
|
+
const lastReplyIndex = assistantReplies.length - 1;
|
|
538
|
+
const signals = signalsByReply.get(lastReplyIndex) ?? [];
|
|
539
|
+
for (const pending of pendingSignals) {
|
|
540
|
+
signals.push(pending);
|
|
541
|
+
}
|
|
542
|
+
signalsByReply.set(lastReplyIndex, signals);
|
|
543
|
+
pendingSignals.length = 0;
|
|
544
|
+
}
|
|
545
|
+
// Apply token_usage_signal atoms to the most recent preceding assistant reply.
|
|
546
|
+
// Each signal is associated with the reply that precedes it in the atom sequence.
|
|
547
|
+
if (assistantReplies.length > 0 && signalsByReply.size > 0) {
|
|
548
|
+
for (const [replyIndex, signals] of signalsByReply.entries()) {
|
|
549
|
+
const reply = assistantReplies[replyIndex];
|
|
550
|
+
if (!reply || signals.length === 0) {
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
553
|
+
// Check if signals carry delta_token_usage (cumulative mode)
|
|
554
|
+
const hasDeltas = signals.some((s) => isObject(s.payload.delta_token_usage));
|
|
555
|
+
// Codex's `last_token_usage` (without `total_token_usage`) is a cumulative
|
|
556
|
+
// checkpoint within the turn — the last signal already subsumes earlier
|
|
557
|
+
// ones. Claude Code's per-message.id signals are independent API calls
|
|
558
|
+
// that must be summed. We tell them apart by Codex's `source_event_type`.
|
|
559
|
+
const isCodexCumulativeWithinTurn = signals.every((s) => s.payload.source_event_type === "token_count");
|
|
560
|
+
let resolvedUsage;
|
|
561
|
+
if (hasDeltas) {
|
|
562
|
+
// Codex cumulative mode: each signal carries a delta since the prior
|
|
563
|
+
// checkpoint. Sum deltas to recover the total increment for this reply.
|
|
564
|
+
for (const signal of signals) {
|
|
565
|
+
const delta = extractTokenUsageFromPayload(isObject(signal.payload.delta_token_usage) ? { token_usage: signal.payload.delta_token_usage } : {});
|
|
566
|
+
resolvedUsage = mergeTokenUsageMetrics(resolvedUsage, delta);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
else if (isCodexCumulativeWithinTurn) {
|
|
570
|
+
// Codex without total_token_usage: last_token_usage is cumulative
|
|
571
|
+
// within the turn, so the final checkpoint is the turn total.
|
|
572
|
+
const lastSignal = signals.at(-1);
|
|
573
|
+
resolvedUsage = extractTokenUsageFromPayload(lastSignal.payload);
|
|
574
|
+
}
|
|
575
|
+
else {
|
|
576
|
+
// Claude Code mode: each signal is one API call's standalone usage
|
|
577
|
+
// (after upstream dedup by message.id). A turn can chain several API
|
|
578
|
+
// calls behind one text reply (text + tool_use loop + ...), and every
|
|
579
|
+
// call's tokens must be summed — taking only the last signal silently
|
|
580
|
+
// drops every preceding call's billing.
|
|
581
|
+
for (const signal of signals) {
|
|
582
|
+
const u = extractTokenUsageFromPayload(signal.payload);
|
|
583
|
+
resolvedUsage = mergeTokenUsageMetrics(resolvedUsage, u);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
if (resolvedUsage) {
|
|
587
|
+
reply.token_usage = resolvedUsage;
|
|
588
|
+
reply.token_count = resolvedUsage.total_tokens ?? reply.token_count;
|
|
589
|
+
if (resolvedUsage.model && reply.model === "unknown") {
|
|
590
|
+
reply.model = resolvedUsage.model;
|
|
591
|
+
}
|
|
592
|
+
if (!reply.stop_reason) {
|
|
593
|
+
const lastSignal = signals.at(-1);
|
|
594
|
+
reply.stop_reason = extractStopReasonFromPayload(lastSignal.payload);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
const lastAssistantReplyId = () => assistantReplies.at(-1)?.id ?? stableId("assistant-reply", draft.id, "synthetic");
|
|
600
|
+
for (const atom of contextAtoms) {
|
|
601
|
+
if (atom.content_kind !== "tool_call" || atom.display_policy === "hide") {
|
|
602
|
+
continue;
|
|
603
|
+
}
|
|
604
|
+
const spawnedFromAtomId = contextIndex.edgeIndex.spawnedFromAtomIdByToolAtomId.get(atom.id);
|
|
605
|
+
const replyId = spawnedFromAtomId ? replyIdByAtomId.get(spawnedFromAtomId) ?? lastAssistantReplyId() : lastAssistantReplyId();
|
|
606
|
+
const inputJson = JSON.stringify(atom.payload.input ?? {});
|
|
607
|
+
const maskedInput = applyMaskTemplates(inputJson, "tool_input");
|
|
608
|
+
const toolCall = {
|
|
609
|
+
id: stableId("tool-call", draft.source_id, draft.id, atom.id),
|
|
610
|
+
tool_name: asString(atom.payload.tool_name) ?? "tool_call",
|
|
611
|
+
input: isObject(atom.payload.input) ? atom.payload.input : {},
|
|
612
|
+
input_summary: truncate(maskedInput.canonical_text || inputJson, 140),
|
|
613
|
+
input_display_segments: maskedInput.display_segments,
|
|
614
|
+
status: "success",
|
|
615
|
+
reply_id: replyId,
|
|
616
|
+
sequence: toolSequence++,
|
|
617
|
+
created_at: atom.time_key,
|
|
618
|
+
};
|
|
619
|
+
const resultAtomId = contextIndex.edgeIndex.toolResultAtomIdByToolAtomId.get(atom.id);
|
|
620
|
+
const resultAtom = resultAtomId && contextIndex.contextAtomIds.has(resultAtomId)
|
|
621
|
+
? contextIndex.atomById.get(resultAtomId)
|
|
622
|
+
: undefined;
|
|
623
|
+
if (resultAtom) {
|
|
624
|
+
const output = asString(resultAtom.payload.output) ?? "";
|
|
625
|
+
const maskedOutput = applyMaskTemplates(output, "tool_output");
|
|
626
|
+
toolCall.output = output;
|
|
627
|
+
toolCall.output_preview = truncate(maskedOutput.canonical_text || output, 140);
|
|
628
|
+
toolCall.output_display_segments = maskedOutput.display_segments;
|
|
629
|
+
}
|
|
630
|
+
toolCalls.push(toolCall);
|
|
631
|
+
let replyToolCallIds = toolCallIdsByReplyId.get(replyId);
|
|
632
|
+
if (!replyToolCallIds) {
|
|
633
|
+
replyToolCallIds = [];
|
|
634
|
+
toolCallIdsByReplyId.set(replyId, replyToolCallIds);
|
|
635
|
+
}
|
|
636
|
+
replyToolCallIds.push(toolCall.id);
|
|
637
|
+
}
|
|
638
|
+
for (const reply of assistantReplies) {
|
|
639
|
+
reply.tool_call_ids = toolCallIdsByReplyId.get(reply.id) ?? [];
|
|
640
|
+
}
|
|
641
|
+
return {
|
|
642
|
+
turn_id: turnId,
|
|
643
|
+
system_messages: systemMessages,
|
|
644
|
+
assistant_replies: assistantReplies,
|
|
645
|
+
tool_calls: toolCalls,
|
|
646
|
+
raw_event_refs: Array.from(rawEventRefs),
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
function buildTurnPathText(draft, contextProjection, groupAtoms, contextAtoms) {
|
|
650
|
+
const parts = new Set();
|
|
651
|
+
addPathText(parts, draft.working_directory);
|
|
652
|
+
addPathText(parts, draft.source_native_project_ref);
|
|
653
|
+
addPathText(parts, draft.resume_working_directory);
|
|
654
|
+
addPathText(parts, draft.source_native_project_ref ? path.basename(draft.source_native_project_ref) : undefined);
|
|
655
|
+
for (const atom of [...groupAtoms, ...contextAtoms]) {
|
|
656
|
+
const payload = atom.payload;
|
|
657
|
+
addPathText(parts, asString(payload.path));
|
|
658
|
+
addPathText(parts, asString(payload.workspace_path));
|
|
659
|
+
addPathText(parts, asString(payload.repo_root));
|
|
660
|
+
addPathText(parts, asString(payload.source_native_project_ref));
|
|
661
|
+
}
|
|
662
|
+
for (const reply of contextProjection.assistant_replies) {
|
|
663
|
+
for (const segment of reply.display_segments ?? []) {
|
|
664
|
+
if (segment.type === "reference") {
|
|
665
|
+
addPathText(parts, segment.content);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
return [...parts].join(" ").trim() || undefined;
|
|
670
|
+
}
|
|
671
|
+
function addPathText(target, value) {
|
|
672
|
+
if (!value) {
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
const normalized = normalizePathSeparators(value).trim();
|
|
676
|
+
if (!normalized) {
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
target.add(normalized);
|
|
680
|
+
const basename = normalized.split("/").filter(Boolean).at(-1);
|
|
681
|
+
if (basename) {
|
|
682
|
+
target.add(basename);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
export function summarizeAssistantReplyUsage(replies) {
|
|
686
|
+
let total;
|
|
687
|
+
for (const reply of replies) {
|
|
688
|
+
if (reply.token_usage) {
|
|
689
|
+
total = mergeTokenUsageMetrics(total, reply.token_usage);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
return total;
|
|
693
|
+
}
|
|
694
|
+
export function summarizeAssistantReplyPrimaryModel(replies) {
|
|
695
|
+
return replies.find((reply) => reply.model)?.model;
|
|
696
|
+
}
|
|
697
|
+
export function extractCanonicalFallback(segments) {
|
|
698
|
+
return segments
|
|
699
|
+
.map((segment) => {
|
|
700
|
+
if (segment.type === "masked") {
|
|
701
|
+
return `[${segment.mask_label ?? "Masked"}]`;
|
|
702
|
+
}
|
|
703
|
+
if (segment.type === "injected") {
|
|
704
|
+
return "";
|
|
705
|
+
}
|
|
706
|
+
return segment.content;
|
|
707
|
+
})
|
|
708
|
+
.join("")
|
|
709
|
+
.replace(/[ \t]+\n/g, "\n")
|
|
710
|
+
.replace(/\n{3,}/g, "\n\n")
|
|
711
|
+
.trim();
|
|
712
|
+
}
|
|
713
|
+
//# sourceMappingURL=session-interpreter.js.map
|