nlm-memory 0.20.1 → 0.21.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -12
- package/assets/replay-eval-dark.svg +26 -0
- package/assets/replay-eval-light.svg +26 -0
- package/dist/cli/digest.js +69 -4
- package/dist/cli/digest.js.map +1 -1
- package/dist/cli/nlm.d.ts +14 -0
- package/dist/cli/nlm.js +556 -71
- package/dist/cli/nlm.js.map +1 -1
- package/dist/cli/reprocess-job-adapters.d.ts +35 -0
- package/dist/cli/reprocess-job-adapters.js +80 -0
- package/dist/cli/reprocess-job-adapters.js.map +1 -0
- package/dist/cli/scope-backfill.d.ts +34 -0
- package/dist/cli/scope-backfill.js +237 -0
- package/dist/cli/scope-backfill.js.map +1 -0
- package/dist/cli/scope-coverage.d.ts +44 -0
- package/dist/cli/scope-coverage.js +208 -0
- package/dist/cli/scope-coverage.js.map +1 -0
- package/dist/cli/supersede.js +8 -7
- package/dist/cli/supersede.js.map +1 -1
- package/dist/core/actions/actions-log.d.ts +65 -8
- package/dist/core/actions/actions-log.js +134 -17
- package/dist/core/actions/actions-log.js.map +1 -1
- package/dist/core/actions/overlay.d.ts +11 -2
- package/dist/core/actions/overlay.js +18 -6
- package/dist/core/actions/overlay.js.map +1 -1
- package/dist/core/adapters/claude-code.d.ts +14 -0
- package/dist/core/adapters/claude-code.js +30 -0
- package/dist/core/adapters/claude-code.js.map +1 -1
- package/dist/core/adapters/from-source.js +11 -3
- package/dist/core/adapters/from-source.js.map +1 -1
- package/dist/core/adapters/fs-wiki-writer.d.ts +44 -0
- package/dist/core/adapters/fs-wiki-writer.js +132 -0
- package/dist/core/adapters/fs-wiki-writer.js.map +1 -0
- package/dist/core/adapters/hermes-agent.d.ts +15 -2
- package/dist/core/adapters/hermes-agent.js +57 -11
- package/dist/core/adapters/hermes-agent.js.map +1 -1
- package/dist/core/adapters/memory-wiki-writer.d.ts +8 -0
- package/dist/core/adapters/memory-wiki-writer.js +16 -0
- package/dist/core/adapters/memory-wiki-writer.js.map +1 -0
- package/dist/core/adapters/muse.d.ts +51 -0
- package/dist/core/adapters/muse.js +271 -0
- package/dist/core/adapters/muse.js.map +1 -0
- package/dist/core/adapters/opencode.d.ts +11 -4
- package/dist/core/adapters/opencode.js +41 -7
- package/dist/core/adapters/opencode.js.map +1 -1
- package/dist/core/alerts/alert-state.d.ts +17 -0
- package/dist/core/alerts/alert-state.js +45 -0
- package/dist/core/alerts/alert-state.js.map +1 -0
- package/dist/core/alerts/check-and-alert.d.ts +28 -0
- package/dist/core/alerts/check-and-alert.js +53 -0
- package/dist/core/alerts/check-and-alert.js.map +1 -0
- package/dist/core/alerts/drift-transition.d.ts +27 -0
- package/dist/core/alerts/drift-transition.js +56 -0
- package/dist/core/alerts/drift-transition.js.map +1 -0
- package/dist/core/alerts/embedder-transition.d.ts +23 -0
- package/dist/core/alerts/embedder-transition.js +40 -0
- package/dist/core/alerts/embedder-transition.js.map +1 -0
- package/dist/core/alerts/fire-alert.d.ts +24 -0
- package/dist/core/alerts/fire-alert.js +72 -0
- package/dist/core/alerts/fire-alert.js.map +1 -0
- package/dist/core/alerts/job-alert.d.ts +12 -0
- package/dist/core/alerts/job-alert.js +37 -0
- package/dist/core/alerts/job-alert.js.map +1 -0
- package/dist/core/alerts/types.d.ts +104 -0
- package/dist/core/alerts/types.js +11 -0
- package/dist/core/alerts/types.js.map +1 -0
- package/dist/core/alerts/wiki-alert.d.ts +15 -0
- package/dist/core/alerts/wiki-alert.js +31 -0
- package/dist/core/alerts/wiki-alert.js.map +1 -0
- package/dist/core/classifier/prompt.d.ts +13 -0
- package/dist/core/classifier/prompt.js +52 -2
- package/dist/core/classifier/prompt.js.map +1 -1
- package/dist/core/dataset/build-dataset.d.ts +16 -1
- package/dist/core/dataset/build-dataset.js +46 -13
- package/dist/core/dataset/build-dataset.js.map +1 -1
- package/dist/core/digest/compose.d.ts +11 -3
- package/dist/core/digest/compose.js +70 -17
- package/dist/core/digest/compose.js.map +1 -1
- package/dist/core/digest/hook-injection.d.ts +43 -0
- package/dist/core/digest/hook-injection.js +87 -0
- package/dist/core/digest/hook-injection.js.map +1 -0
- package/dist/core/digest/hook-version-parity.d.ts +31 -0
- package/dist/core/digest/hook-version-parity.js +56 -0
- package/dist/core/digest/hook-version-parity.js.map +1 -0
- package/dist/core/embedding/pg-embed-backfill.js +1 -1
- package/dist/core/embedding/pg-embed-backfill.js.map +1 -1
- package/dist/core/exemplars/capture-from-session.d.ts +2 -1
- package/dist/core/exemplars/capture-from-session.js +4 -4
- package/dist/core/exemplars/capture-from-session.js.map +1 -1
- package/dist/core/exemplars/embed-backfill.d.ts +9 -0
- package/dist/core/exemplars/embed-backfill.js +9 -1
- package/dist/core/exemplars/embed-backfill.js.map +1 -1
- package/dist/core/exemplars/extract-exemplar.d.ts +2 -0
- package/dist/core/exemplars/extract-exemplar.js +7 -1
- package/dist/core/exemplars/extract-exemplar.js.map +1 -1
- package/dist/core/exemplars/ingest-exemplar.d.ts +1 -0
- package/dist/core/exemplars/ingest-exemplar.js +1 -0
- package/dist/core/exemplars/ingest-exemplar.js.map +1 -1
- package/dist/core/exemplars/recall-code.d.ts +1 -1
- package/dist/core/exemplars/recall-code.js +2 -2
- package/dist/core/exemplars/recall-code.js.map +1 -1
- package/dist/core/facts/backfill-facts.d.ts +1 -1
- package/dist/core/facts/backfill-facts.js +4 -4
- package/dist/core/facts/backfill-facts.js.map +1 -1
- package/dist/core/facts/embed-backfill.d.ts +54 -0
- package/dist/core/facts/embed-backfill.js +109 -0
- package/dist/core/facts/embed-backfill.js.map +1 -0
- package/dist/core/facts/reconcile-facts.d.ts +42 -0
- package/dist/core/facts/reconcile-facts.js +133 -0
- package/dist/core/facts/reconcile-facts.js.map +1 -0
- package/dist/core/health/embed-failure-state.d.ts +4 -0
- package/dist/core/health/embed-failure-state.js +12 -0
- package/dist/core/health/embed-failure-state.js.map +1 -0
- package/dist/core/health/warmup-retry.d.ts +27 -0
- package/dist/core/health/warmup-retry.js +53 -0
- package/dist/core/health/warmup-retry.js.map +1 -0
- package/dist/core/health/warmup-state.d.ts +15 -0
- package/dist/core/health/warmup-state.js +15 -1
- package/dist/core/health/warmup-state.js.map +1 -1
- package/dist/core/hook/cite-memo.d.ts +11 -7
- package/dist/core/hook/cite-memo.js +25 -17
- package/dist/core/hook/cite-memo.js.map +1 -1
- package/dist/core/hook/claude-settings.d.ts +1 -1
- package/dist/core/hook/claude-settings.js +0 -1
- package/dist/core/hook/claude-settings.js.map +1 -1
- package/dist/core/hook/hook-log.d.ts +13 -2
- package/dist/core/hook/hook-log.js +16 -8
- package/dist/core/hook/hook-log.js.map +1 -1
- package/dist/core/hook/memo.d.ts +10 -6
- package/dist/core/hook/memo.js +25 -17
- package/dist/core/hook/memo.js.map +1 -1
- package/dist/core/hook/pointer-block.d.ts +8 -1
- package/dist/core/hook/pointer-block.js +17 -4
- package/dist/core/hook/pointer-block.js.map +1 -1
- package/dist/core/hook/resolve-conversation-by-query.d.ts +6 -5
- package/dist/core/hook/resolve-conversation-by-query.js +24 -12
- package/dist/core/hook/resolve-conversation-by-query.js.map +1 -1
- package/dist/core/ingest/backfill-derivables.d.ts +92 -0
- package/dist/core/ingest/backfill-derivables.js +175 -0
- package/dist/core/ingest/backfill-derivables.js.map +1 -0
- package/dist/core/ingest/ingest-session.d.ts +1 -1
- package/dist/core/ingest/ingest-session.js +23 -3
- package/dist/core/ingest/ingest-session.js.map +1 -1
- package/dist/core/ingest/reclassify-oversized.d.ts +1 -1
- package/dist/core/ingest/reclassify-oversized.js +8 -2
- package/dist/core/ingest/reclassify-oversized.js.map +1 -1
- package/dist/core/ingest/reprocess.d.ts +1 -1
- package/dist/core/ingest/reprocess.js +7 -2
- package/dist/core/ingest/reprocess.js.map +1 -1
- package/dist/core/ingest/transcript-derivables.d.ts +27 -0
- package/dist/core/ingest/transcript-derivables.js +138 -0
- package/dist/core/ingest/transcript-derivables.js.map +1 -0
- package/dist/core/jobs/job-supervisor.d.ts +168 -0
- package/dist/core/jobs/job-supervisor.js +335 -0
- package/dist/core/jobs/job-supervisor.js.map +1 -0
- package/dist/core/learner/model.d.ts +63 -0
- package/dist/core/learner/model.js +30 -0
- package/dist/core/learner/model.js.map +1 -0
- package/dist/core/learner/service.d.ts +42 -0
- package/dist/core/learner/service.js +74 -0
- package/dist/core/learner/service.js.map +1 -0
- package/dist/core/learner/summary.d.ts +28 -0
- package/dist/core/learner/summary.js +70 -0
- package/dist/core/learner/summary.js.map +1 -0
- package/dist/core/learner/validate.d.ts +18 -0
- package/dist/core/learner/validate.js +95 -0
- package/dist/core/learner/validate.js.map +1 -0
- package/dist/core/metrics/re-derivation.d.ts +31 -2
- package/dist/core/metrics/re-derivation.js +36 -4
- package/dist/core/metrics/re-derivation.js.map +1 -1
- package/dist/core/outcome/coverage.d.ts +33 -0
- package/dist/core/outcome/coverage.js +46 -0
- package/dist/core/outcome/coverage.js.map +1 -0
- package/dist/core/outcome/rollup.d.ts +33 -0
- package/dist/core/outcome/rollup.js +113 -0
- package/dist/core/outcome/rollup.js.map +1 -0
- package/dist/core/providers/provider-registry.d.ts +40 -23
- package/dist/core/providers/provider-registry.js +99 -81
- package/dist/core/providers/provider-registry.js.map +1 -1
- package/dist/core/recall/citation-log.d.ts +10 -5
- package/dist/core/recall/citation-log.js +21 -10
- package/dist/core/recall/citation-log.js.map +1 -1
- package/dist/core/recall/hook-recall-log.d.ts +7 -4
- package/dist/core/recall/hook-recall-log.js +14 -8
- package/dist/core/recall/hook-recall-log.js.map +1 -1
- package/dist/core/recall/miss-log.d.ts +7 -4
- package/dist/core/recall/miss-log.js +18 -11
- package/dist/core/recall/miss-log.js.map +1 -1
- package/dist/core/recall/query-log.d.ts +8 -5
- package/dist/core/recall/query-log.js +16 -9
- package/dist/core/recall/query-log.js.map +1 -1
- package/dist/core/recall/recall-service.d.ts +10 -1
- package/dist/core/recall/recall-service.js +31 -12
- package/dist/core/recall/recall-service.js.map +1 -1
- package/dist/core/recall/recent-log.d.ts +6 -1
- package/dist/core/recall/recent-log.js +13 -5
- package/dist/core/recall/recent-log.js.map +1 -1
- package/dist/core/recall/related-concepts.d.ts +29 -0
- package/dist/core/recall/related-concepts.js +67 -0
- package/dist/core/recall/related-concepts.js.map +1 -0
- package/dist/core/recall/related-exemplars.d.ts +1 -1
- package/dist/core/recall/related-exemplars.js +2 -2
- package/dist/core/recall/related-exemplars.js.map +1 -1
- package/dist/core/recall/related-facts.d.ts +1 -1
- package/dist/core/recall/related-facts.js +3 -3
- package/dist/core/recall/related-facts.js.map +1 -1
- package/dist/core/recall-facts/fact-query-log.d.ts +8 -4
- package/dist/core/recall-facts/fact-query-log.js +16 -8
- package/dist/core/recall-facts/fact-query-log.js.map +1 -1
- package/dist/core/recall-facts/fact-recall-service.d.ts +2 -2
- package/dist/core/recall-facts/fact-recall-service.js +13 -12
- package/dist/core/recall-facts/fact-recall-service.js.map +1 -1
- package/dist/core/scheduler/scan-once.js +15 -12
- package/dist/core/scheduler/scan-once.js.map +1 -1
- package/dist/core/scheduler/scheduler.d.ts +3 -0
- package/dist/core/scheduler/scheduler.js +45 -10
- package/dist/core/scheduler/scheduler.js.map +1 -1
- package/dist/core/scope/alias-map.d.ts +10 -0
- package/dist/core/scope/alias-map.js +41 -0
- package/dist/core/scope/alias-map.js.map +1 -0
- package/dist/core/scope/derive-scope.d.ts +8 -0
- package/dist/core/scope/derive-scope.js +54 -0
- package/dist/core/scope/derive-scope.js.map +1 -0
- package/dist/core/scope/scope-clause.d.ts +16 -0
- package/dist/core/scope/scope-clause.js +21 -0
- package/dist/core/scope/scope-clause.js.map +1 -0
- package/dist/core/scope/stamp-flag.d.ts +1 -0
- package/dist/core/scope/stamp-flag.js +4 -0
- package/dist/core/scope/stamp-flag.js.map +1 -0
- package/dist/core/signals/code-signal.d.ts +1 -0
- package/dist/core/signals/code-signal.js +1 -0
- package/dist/core/signals/code-signal.js.map +1 -1
- package/dist/core/signals/failure-mode-recall.d.ts +1 -1
- package/dist/core/signals/failure-mode-recall.js +2 -2
- package/dist/core/signals/failure-mode-recall.js.map +1 -1
- package/dist/core/signals/ingest-signal.d.ts +1 -1
- package/dist/core/signals/ingest-signal.js +3 -1
- package/dist/core/signals/ingest-signal.js.map +1 -1
- package/dist/core/signals/stamp-scope.d.ts +18 -0
- package/dist/core/signals/stamp-scope.js +28 -0
- package/dist/core/signals/stamp-scope.js.map +1 -0
- package/dist/core/sources/source-registry.d.ts +49 -28
- package/dist/core/sources/source-registry.js +113 -70
- package/dist/core/sources/source-registry.js.map +1 -1
- package/dist/core/storage/pg-code-exemplar-store.d.ts +19 -10
- package/dist/core/storage/pg-code-exemplar-store.js +62 -27
- package/dist/core/storage/pg-code-exemplar-store.js.map +1 -1
- package/dist/core/storage/pg-entity-store.d.ts +6 -1
- package/dist/core/storage/pg-entity-store.js +33 -18
- package/dist/core/storage/pg-entity-store.js.map +1 -1
- package/dist/core/storage/pg-fact-ingest.d.ts +1 -1
- package/dist/core/storage/pg-fact-ingest.js +10 -7
- package/dist/core/storage/pg-fact-ingest.js.map +1 -1
- package/dist/core/storage/pg-fact-store.d.ts +29 -17
- package/dist/core/storage/pg-fact-store.js +99 -46
- package/dist/core/storage/pg-fact-store.js.map +1 -1
- package/dist/core/storage/pg-learner-store.d.ts +27 -0
- package/dist/core/storage/pg-learner-store.js +174 -0
- package/dist/core/storage/pg-learner-store.js.map +1 -0
- package/dist/core/storage/pg-session-store.d.ts +25 -21
- package/dist/core/storage/pg-session-store.js +186 -114
- package/dist/core/storage/pg-session-store.js.map +1 -1
- package/dist/core/storage/pg-signal-store.d.ts +10 -5
- package/dist/core/storage/pg-signal-store.js +26 -13
- package/dist/core/storage/pg-signal-store.js.map +1 -1
- package/dist/core/storage/pg-storage.d.ts +4 -0
- package/dist/core/storage/pg-storage.js +6 -0
- package/dist/core/storage/pg-storage.js.map +1 -1
- package/dist/core/storage/pg-workstream-store.d.ts +17 -11
- package/dist/core/storage/pg-workstream-store.js +47 -29
- package/dist/core/storage/pg-workstream-store.js.map +1 -1
- package/dist/core/storage/sqlite-code-exemplar-store.d.ts +24 -10
- package/dist/core/storage/sqlite-code-exemplar-store.js +86 -40
- package/dist/core/storage/sqlite-code-exemplar-store.js.map +1 -1
- package/dist/core/storage/sqlite-entity-store.d.ts +8 -1
- package/dist/core/storage/sqlite-entity-store.js +46 -27
- package/dist/core/storage/sqlite-entity-store.js.map +1 -1
- package/dist/core/storage/sqlite-fact-store.d.ts +45 -19
- package/dist/core/storage/sqlite-fact-store.js +175 -64
- package/dist/core/storage/sqlite-fact-store.js.map +1 -1
- package/dist/core/storage/sqlite-learner-store.d.ts +33 -0
- package/dist/core/storage/sqlite-learner-store.js +178 -0
- package/dist/core/storage/sqlite-learner-store.js.map +1 -0
- package/dist/core/storage/sqlite-outcome-store.d.ts +104 -0
- package/dist/core/storage/sqlite-outcome-store.js +211 -0
- package/dist/core/storage/sqlite-outcome-store.js.map +1 -0
- package/dist/core/storage/sqlite-session-store.d.ts +50 -21
- package/dist/core/storage/sqlite-session-store.js +233 -149
- package/dist/core/storage/sqlite-session-store.js.map +1 -1
- package/dist/core/storage/sqlite-signal-store.d.ts +12 -5
- package/dist/core/storage/sqlite-signal-store.js +29 -15
- package/dist/core/storage/sqlite-signal-store.js.map +1 -1
- package/dist/core/storage/sqlite-storage.d.ts +4 -0
- package/dist/core/storage/sqlite-storage.js +10 -2
- package/dist/core/storage/sqlite-storage.js.map +1 -1
- package/dist/core/storage/sqlite-workstream-store.d.ts +17 -11
- package/dist/core/storage/sqlite-workstream-store.js +53 -31
- package/dist/core/storage/sqlite-workstream-store.js.map +1 -1
- package/dist/core/storage/supersedence-log.d.ts +10 -7
- package/dist/core/storage/supersedence-log.js +21 -14
- package/dist/core/storage/supersedence-log.js.map +1 -1
- package/dist/core/telemetry/probe-filter.d.ts +35 -0
- package/dist/core/telemetry/probe-filter.js +56 -0
- package/dist/core/telemetry/probe-filter.js.map +1 -0
- package/dist/core/tenancy/default-team.d.ts +6 -0
- package/dist/core/tenancy/default-team.js +7 -0
- package/dist/core/tenancy/default-team.js.map +1 -0
- package/dist/core/tenancy/hosted-mode.d.ts +9 -0
- package/dist/core/tenancy/hosted-mode.js +12 -0
- package/dist/core/tenancy/hosted-mode.js.map +1 -0
- package/dist/core/tenancy/team-auth.d.ts +16 -0
- package/dist/core/tenancy/team-auth.js +22 -0
- package/dist/core/tenancy/team-auth.js.map +1 -0
- package/dist/core/tenancy/team-token-store.d.ts +45 -0
- package/dist/core/tenancy/team-token-store.js +52 -0
- package/dist/core/tenancy/team-token-store.js.map +1 -0
- package/dist/core/tenancy/tenant-clause.d.ts +37 -0
- package/dist/core/tenancy/tenant-clause.js +11 -0
- package/dist/core/tenancy/tenant-clause.js.map +1 -0
- package/dist/core/tenancy/tenant-state-path.d.ts +28 -0
- package/dist/core/tenancy/tenant-state-path.js +49 -0
- package/dist/core/tenancy/tenant-state-path.js.map +1 -0
- package/dist/core/update-check/check.d.ts +6 -0
- package/dist/core/update-check/check.js +35 -0
- package/dist/core/update-check/check.js.map +1 -1
- package/dist/core/wiki/project.d.ts +17 -0
- package/dist/core/wiki/project.js +37 -0
- package/dist/core/wiki/project.js.map +1 -0
- package/dist/core/wiki/reconcile.d.ts +15 -0
- package/dist/core/wiki/reconcile.js +14 -0
- package/dist/core/wiki/reconcile.js.map +1 -0
- package/dist/core/wiki/render.d.ts +5 -0
- package/dist/core/wiki/render.js +84 -0
- package/dist/core/wiki/render.js.map +1 -0
- package/dist/core/wiki/rollup.d.ts +28 -0
- package/dist/core/wiki/rollup.js +91 -0
- package/dist/core/wiki/rollup.js.map +1 -0
- package/dist/core/wiki/select.d.ts +8 -0
- package/dist/core/wiki/select.js +7 -0
- package/dist/core/wiki/select.js.map +1 -0
- package/dist/core/wiki/slug.d.ts +36 -0
- package/dist/core/wiki/slug.js +71 -0
- package/dist/core/wiki/slug.js.map +1 -0
- package/dist/core/wiki/types.d.ts +37 -0
- package/dist/core/wiki/types.js +2 -0
- package/dist/core/wiki/types.js.map +1 -0
- package/dist/core/work-digest/build-work-digest.d.ts +1 -1
- package/dist/core/work-digest/build-work-digest.js +3 -3
- package/dist/core/work-digest/build-work-digest.js.map +1 -1
- package/dist/core/workstream/bind.d.ts +3 -2
- package/dist/core/workstream/bind.js +29 -10
- package/dist/core/workstream/bind.js.map +1 -1
- package/dist/core/workstream/model.d.ts +1 -0
- package/dist/core/workstream/model.js.map +1 -1
- package/dist/core/workstream/rollup.d.ts +1 -1
- package/dist/core/workstream/rollup.js +6 -6
- package/dist/core/workstream/rollup.js.map +1 -1
- package/dist/hook/hook-helpers.d.ts +14 -0
- package/dist/hook/hook-helpers.js +29 -2
- package/dist/hook/hook-helpers.js.map +1 -1
- package/dist/hook/pre-compact-hook.js +8 -5
- package/dist/hook/pre-compact-hook.js.map +1 -1
- package/dist/hook/prompt-recall-hook.d.ts +7 -3
- package/dist/hook/prompt-recall-hook.js +35 -20
- package/dist/hook/prompt-recall-hook.js.map +1 -1
- package/dist/hook/recall-over-http.d.ts +28 -3
- package/dist/hook/recall-over-http.js +58 -12
- package/dist/hook/recall-over-http.js.map +1 -1
- package/dist/hook/session-end-hook.js +7 -5
- package/dist/hook/session-end-hook.js.map +1 -1
- package/dist/hook/session-start-hook.d.ts +14 -1
- package/dist/hook/session-start-hook.js +57 -16
- package/dist/hook/session-start-hook.js.map +1 -1
- package/dist/hook/stop-hook.js +11 -8
- package/dist/hook/stop-hook.js.map +1 -1
- package/dist/http/app.d.ts +47 -3
- package/dist/http/app.js +379 -132
- package/dist/http/app.js.map +1 -1
- package/dist/install/claude-code.d.ts +17 -0
- package/dist/install/claude-code.js +44 -5
- package/dist/install/claude-code.js.map +1 -1
- package/dist/install/codex.d.ts +23 -2
- package/dist/install/codex.js +111 -14
- package/dist/install/codex.js.map +1 -1
- package/dist/install/cursor.d.ts +2 -2
- package/dist/install/cursor.js +7 -7
- package/dist/install/cursor.js.map +1 -1
- package/dist/install/hermes.d.ts +8 -0
- package/dist/install/hermes.js +28 -5
- package/dist/install/hermes.js.map +1 -1
- package/dist/install/local-source.d.ts +20 -0
- package/dist/install/local-source.js +28 -0
- package/dist/install/local-source.js.map +1 -0
- package/dist/install/mcp-block.d.ts +77 -0
- package/dist/install/mcp-block.js +99 -0
- package/dist/install/mcp-block.js.map +1 -0
- package/dist/install/pi.d.ts +26 -0
- package/dist/install/pi.js +43 -0
- package/dist/install/pi.js.map +1 -1
- package/dist/install/setup.js +6 -0
- package/dist/install/setup.js.map +1 -1
- package/dist/install/windsurf.d.ts +2 -2
- package/dist/install/windsurf.js +7 -7
- package/dist/install/windsurf.js.map +1 -1
- package/dist/llm/classifier-box.d.ts +5 -0
- package/dist/llm/classifier-box.js +5 -0
- package/dist/llm/classifier-box.js.map +1 -1
- package/dist/mcp/server.d.ts +94 -15
- package/dist/mcp/server.js +402 -79
- package/dist/mcp/server.js.map +1 -1
- package/dist/ports/clock.d.ts +12 -0
- package/dist/ports/clock.js +10 -0
- package/dist/ports/clock.js.map +1 -0
- package/dist/ports/code-exemplar-store.d.ts +13 -13
- package/dist/ports/entity-store.d.ts +5 -1
- package/dist/ports/fact-store.d.ts +0 -0
- package/dist/ports/fact-store.js +0 -0
- package/dist/ports/fact-store.js.map +1 -1
- package/dist/ports/learner-store.d.ts +80 -0
- package/dist/ports/learner-store.js +19 -0
- package/dist/ports/learner-store.js.map +1 -0
- package/dist/ports/outcome.d.ts +85 -0
- package/dist/ports/outcome.js +11 -0
- package/dist/ports/outcome.js.map +1 -0
- package/dist/ports/session-store.d.ts +20 -20
- package/dist/ports/session-store.js +5 -0
- package/dist/ports/session-store.js.map +1 -1
- package/dist/ports/signal-store.d.ts +12 -8
- package/dist/ports/spawn-child.d.ts +14 -0
- package/dist/ports/spawn-child.js +10 -0
- package/dist/ports/spawn-child.js.map +1 -0
- package/dist/ports/storage.d.ts +6 -0
- package/dist/ports/transcript-adapter.d.ts +11 -0
- package/dist/ports/wiki-writer.d.ts +19 -0
- package/dist/ports/wiki-writer.js +12 -0
- package/dist/ports/wiki-writer.js.map +1 -0
- package/dist/ports/workstream-store.d.ts +20 -12
- package/dist/shared/net.d.ts +3 -0
- package/dist/shared/net.js +4 -0
- package/dist/shared/net.js.map +1 -0
- package/dist/shared/types.d.ts +55 -0
- package/dist/shared/types.js +4 -1
- package/dist/shared/types.js.map +1 -1
- package/dist/shared/version.d.ts +9 -0
- package/dist/shared/version.js +11 -0
- package/dist/shared/version.js.map +1 -0
- package/dist/ui/assets/index-D6F3xAis.js +11 -0
- package/dist/ui/index.html +1 -1
- package/migrations/029_project_scope.sql +21 -0
- package/migrations/032_session_derivables.sql +11 -0
- package/migrations/033_actions_kind_check.sql +58 -0
- package/migrations/034_tenancy_teams_and_stamps.sql +40 -0
- package/migrations/035_tenancy_entity_rekey.sql +75 -0
- package/migrations/036_tenant_name_uniqueness.sql +59 -0
- package/migrations/037_sessions_covering_index.sql +25 -0
- package/migrations/038_sources_muse.sql +33 -0
- package/migrations/039_learner_evidence.sql +51 -0
- package/migrations/pg/030_project_scope.sql +23 -0
- package/migrations/pg/031_widen_session_edges_kind.sql +11 -0
- package/migrations/pg/032_session_derivables.sql +17 -0
- package/migrations/pg/033_actions_kind_check.sql +17 -0
- package/migrations/pg/034_tenancy.sql +77 -0
- package/migrations/pg/035_tenant_name_uniqueness.sql +15 -0
- package/migrations/pg/036_sources_muse.sql +12 -0
- package/migrations/pg/037_learner_evidence.sql +55 -0
- package/nlm/index.js +258 -59
- package/package.json +10 -5
- package/plugin/.codex-plugin/plugin.json +1 -1
- package/plugin/scripts/prompt-recall-hook.mjs +256 -58
- package/plugin/scripts/session-start-hook.mjs +283 -55
- package/plugin/scripts/stop-hook.mjs +199 -38
- package/dist/hook/subagent-start-hook.d.ts +0 -28
- package/dist/hook/subagent-start-hook.js +0 -81
- package/dist/hook/subagent-start-hook.js.map +0 -1
- package/dist/ui/assets/index-CMpQkbQy.js +0 -11
package/dist/core/hook/memo.js
CHANGED
|
@@ -3,26 +3,34 @@
|
|
|
3
3
|
* conversation holds the set of session ids already surfaced, so each is
|
|
4
4
|
* surfaced at most once per conversation.
|
|
5
5
|
*
|
|
6
|
-
* State dir
|
|
7
|
-
*
|
|
6
|
+
* State dir is tenant-derived (core/tenancy/tenant-state-path.ts): the
|
|
7
|
+
* default team's memo dir is ~/.nlm/hook-state/, overridable via
|
|
8
|
+
* NLM_HOOK_STATE_DIR (testability — mirrors query-log.ts); every other
|
|
9
|
+
* tenant is isolated under ~/.nlm/tenants/<tenantId>/hook-state/ and
|
|
10
|
+
* ignores the env override (see the path contract note in
|
|
11
|
+
* tenant-state-path.ts).
|
|
8
12
|
*
|
|
9
13
|
* Every function is defensive: a missing or corrupt file yields an empty
|
|
10
14
|
* memo, and a write failure is swallowed. The hook must never break on memo
|
|
11
15
|
* I/O.
|
|
12
16
|
*/
|
|
13
17
|
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync, } from "node:fs";
|
|
14
|
-
import { homedir } from "node:os";
|
|
15
18
|
import { join } from "node:path";
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
import { tenantStatePath } from "../tenancy/tenant-state-path.js";
|
|
20
|
+
import { DEFAULT_TEAM_ID } from "../tenancy/default-team.js";
|
|
21
|
+
function stateDir(tenantId) {
|
|
22
|
+
if (tenantId === DEFAULT_TEAM_ID) {
|
|
23
|
+
return process.env["NLM_HOOK_STATE_DIR"] ?? tenantStatePath(tenantId, "hook-state");
|
|
24
|
+
}
|
|
25
|
+
return tenantStatePath(tenantId, "hook-state");
|
|
18
26
|
}
|
|
19
|
-
function memoPath(conversationId) {
|
|
27
|
+
function memoPath(tenantId, conversationId) {
|
|
20
28
|
const safe = conversationId.replace(/[^A-Za-z0-9_-]/g, "_") || "unknown";
|
|
21
|
-
return join(stateDir(), `${safe}.json`);
|
|
29
|
+
return join(stateDir(tenantId), `${safe}.json`);
|
|
22
30
|
}
|
|
23
|
-
export function loadSurfaced(conversationId) {
|
|
31
|
+
export function loadSurfaced(tenantId, conversationId) {
|
|
24
32
|
try {
|
|
25
|
-
const path = memoPath(conversationId);
|
|
33
|
+
const path = memoPath(tenantId, conversationId);
|
|
26
34
|
if (!existsSync(path))
|
|
27
35
|
return new Set();
|
|
28
36
|
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
@@ -34,13 +42,13 @@ export function loadSurfaced(conversationId) {
|
|
|
34
42
|
return new Set();
|
|
35
43
|
}
|
|
36
44
|
}
|
|
37
|
-
export function recordSurfaced(conversationId, ids) {
|
|
45
|
+
export function recordSurfaced(tenantId, conversationId, ids) {
|
|
38
46
|
try {
|
|
39
|
-
const merged = loadSurfaced(conversationId);
|
|
47
|
+
const merged = loadSurfaced(tenantId, conversationId);
|
|
40
48
|
for (const id of ids)
|
|
41
49
|
merged.add(id);
|
|
42
|
-
mkdirSync(stateDir(), { recursive: true });
|
|
43
|
-
writeFileSync(memoPath(conversationId), JSON.stringify([...merged]), "utf8");
|
|
50
|
+
mkdirSync(stateDir(tenantId), { recursive: true });
|
|
51
|
+
writeFileSync(memoPath(tenantId, conversationId), JSON.stringify([...merged]), "utf8");
|
|
44
52
|
}
|
|
45
53
|
catch {
|
|
46
54
|
// Memo write failure must never break the hook.
|
|
@@ -57,9 +65,9 @@ export function recordSurfaced(conversationId, ids) {
|
|
|
57
65
|
*
|
|
58
66
|
* Defensive: any I/O error yields null so cite_session never breaks.
|
|
59
67
|
*/
|
|
60
|
-
export function resolveConversationForSession(sessionId) {
|
|
68
|
+
export function resolveConversationForSession(tenantId, sessionId) {
|
|
61
69
|
try {
|
|
62
|
-
const dir = stateDir();
|
|
70
|
+
const dir = stateDir(tenantId);
|
|
63
71
|
if (!existsSync(dir))
|
|
64
72
|
return null;
|
|
65
73
|
let best = null;
|
|
@@ -91,9 +99,9 @@ export function resolveConversationForSession(sessionId) {
|
|
|
91
99
|
* hook so memo files don't accumulate forever. Returns true if a file was
|
|
92
100
|
* removed, false otherwise — callers may want to log the outcome.
|
|
93
101
|
*/
|
|
94
|
-
export function clearSurfaced(conversationId) {
|
|
102
|
+
export function clearSurfaced(tenantId, conversationId) {
|
|
95
103
|
try {
|
|
96
|
-
const path = memoPath(conversationId);
|
|
104
|
+
const path = memoPath(tenantId, conversationId);
|
|
97
105
|
if (!existsSync(path))
|
|
98
106
|
return false;
|
|
99
107
|
rmSync(path);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memo.js","sourceRoot":"","sources":["../../../src/core/hook/memo.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"memo.js","sourceRoot":"","sources":["../../../src/core/hook/memo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,UAAU,EACV,SAAS,EACT,WAAW,EACX,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,SAAS,QAAQ,CAAC,QAAgB;IAChC,IAAI,QAAQ,KAAK,eAAe,EAAE,CAAC;QACjC,OAAO,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,IAAI,eAAe,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IACtF,CAAC;IACD,OAAO,eAAe,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;AACjD,CAAC;AAED,SAAS,QAAQ,CAAC,QAAgB,EAAE,cAAsB;IACxD,MAAM,IAAI,GAAG,cAAc,CAAC,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,IAAI,SAAS,CAAC;IACzE,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,GAAG,IAAI,OAAO,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,QAAgB,EAAE,cAAsB;IACnE,IAAI,CAAC;QACH,MAAM,IAAI,GAA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IAAI,CAAC,CAAC;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -29,5 +29,12 @@ export interface PointerExemplar {
|
|
|
29
29
|
readonly repo: string;
|
|
30
30
|
readonly taskContext: string;
|
|
31
31
|
}
|
|
32
|
+
export interface PointerConcept {
|
|
33
|
+
readonly concept: string;
|
|
34
|
+
readonly status: string;
|
|
35
|
+
readonly attemptCount: number;
|
|
36
|
+
/** Owning enrollment's latest next_step (shared across its concepts). */
|
|
37
|
+
readonly nextStep: string | null;
|
|
38
|
+
}
|
|
32
39
|
export declare function truncateSummary(s: string, max?: number): string;
|
|
33
|
-
export declare function formatPointerBlock(hits: ReadonlyArray<PointerHit>, facts?: ReadonlyArray<PointerFact>, exemplars?: ReadonlyArray<PointerExemplar>): string;
|
|
40
|
+
export declare function formatPointerBlock(hits: ReadonlyArray<PointerHit>, facts?: ReadonlyArray<PointerFact>, exemplars?: ReadonlyArray<PointerExemplar>, concepts?: ReadonlyArray<PointerConcept>): string;
|
|
@@ -32,8 +32,8 @@ export function truncateSummary(s, max = 200) {
|
|
|
32
32
|
}
|
|
33
33
|
return window + " ...";
|
|
34
34
|
}
|
|
35
|
-
export function formatPointerBlock(hits, facts = [], exemplars = []) {
|
|
36
|
-
if (hits.length === 0 && facts.length === 0 && exemplars.length === 0)
|
|
35
|
+
export function formatPointerBlock(hits, facts = [], exemplars = [], concepts = []) {
|
|
36
|
+
if (hits.length === 0 && facts.length === 0 && exemplars.length === 0 && concepts.length === 0)
|
|
37
37
|
return "";
|
|
38
38
|
const out = [];
|
|
39
39
|
if (hits.length > 0) {
|
|
@@ -66,9 +66,22 @@ export function formatPointerBlock(hits, facts = [], exemplars = []) {
|
|
|
66
66
|
out.push(`- [${e.outcome}] ${langPart}${e.repo} - ${truncateSummary(e.taskContext)}`);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
+
if (concepts.length > 0) {
|
|
70
|
+
if (out.length > 0)
|
|
71
|
+
out.push("");
|
|
72
|
+
out.push("## Learning state (nlm-memory)");
|
|
73
|
+
for (const c of concepts) {
|
|
74
|
+
const n = c.attemptCount === 1 ? "1 attempt" : `${c.attemptCount} attempts`;
|
|
75
|
+
out.push(`- [${c.status}] ${c.concept} (${n})`);
|
|
76
|
+
}
|
|
77
|
+
const nextSteps = [...new Set(concepts.map((c) => c.nextStep).filter((s) => !!s))].slice(0, 2);
|
|
78
|
+
for (const next of nextSteps) {
|
|
79
|
+
out.push(`Next: ${truncateSummary(next, 120)}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
69
82
|
const tools = exemplars.length > 0
|
|
70
|
-
? "NLM tools: recall_sessions (search), get_session (full transcript), recall_facts (prior decisions), get_fact_history (how a decision evolved), recall_code (pull the full code for a related exemplar)."
|
|
71
|
-
: "NLM tools: recall_sessions (search), get_session (full transcript), recall_facts (prior decisions), get_fact_history (how a decision evolved).";
|
|
83
|
+
? "NLM tools: recall_sessions (search), get_session (full transcript), recall_facts (prior decisions), get_fact_history (how a decision evolved), recall_code (pull the full code for a related exemplar), learner_summary (concept mastery + next step)."
|
|
84
|
+
: "NLM tools: recall_sessions (search), get_session (full transcript), recall_facts (prior decisions), get_fact_history (how a decision evolved), learner_summary (concept mastery + next step).";
|
|
72
85
|
out.push(tools);
|
|
73
86
|
return out.join("\n");
|
|
74
87
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pointer-block.js","sourceRoot":"","sources":["../../../src/core/hook/pointer-block.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;
|
|
1
|
+
{"version":3,"file":"pointer-block.js","sourceRoot":"","sources":["../../../src/core/hook/pointer-block.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA+BH,MAAM,UAAU,eAAe,CAAC,CAAS,EAAE,GAAG,GAAG,GAAG;IAClD,IAAI,CAAC,CAAC,MAAM,IAAI,GAAG;Q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AAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC5G,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;YAC7B,GAAG,CAAC,IAAI,CAAC,SAAS,eAAe,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;IACD,MAAM,KAAK,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC;QAChC,CAAC,CAAC,wPAAwP;QAC1P,CAAC,CAAC,+LAA+L,CAAC;IACpM,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChB,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Resolve which
|
|
3
|
-
*
|
|
4
|
-
* for the exact query string.
|
|
2
|
+
* Resolve which conversation triggered a recall pull, by scanning the N
|
|
3
|
+
* most-recently-modified transcript JSONL files across the local runtimes'
|
|
4
|
+
* transcript stores for the exact query string.
|
|
5
5
|
*
|
|
6
6
|
* When an agent calls a recall tool, the runtime has already written the
|
|
7
7
|
* tool_use block (containing the query string) to its transcript before the
|
|
@@ -9,12 +9,13 @@
|
|
|
9
9
|
* deterministic, cheap join between a pull log entry and its source
|
|
10
10
|
* conversation, without requiring the agent to pass conversation_id explicitly.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
* resolve to
|
|
12
|
+
* Claude Code conversations resolve to their bare transcript id; other
|
|
13
|
+
* runtimes resolve to `<runtime>:<id>` so their ids can't collide.
|
|
14
14
|
*
|
|
15
15
|
* Fail-open: any I/O error returns null so the recall path never breaks.
|
|
16
16
|
*/
|
|
17
17
|
export interface ResolveByQueryOpts {
|
|
18
|
+
/** Scan only this directory, as Claude Code transcripts. */
|
|
18
19
|
readonly rootDir?: string;
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Resolve which
|
|
3
|
-
*
|
|
4
|
-
* for the exact query string.
|
|
2
|
+
* Resolve which conversation triggered a recall pull, by scanning the N
|
|
3
|
+
* most-recently-modified transcript JSONL files across the local runtimes'
|
|
4
|
+
* transcript stores for the exact query string.
|
|
5
5
|
*
|
|
6
6
|
* When an agent calls a recall tool, the runtime has already written the
|
|
7
7
|
* tool_use block (containing the query string) to its transcript before the
|
|
@@ -9,19 +9,30 @@
|
|
|
9
9
|
* deterministic, cheap join between a pull log entry and its source
|
|
10
10
|
* conversation, without requiring the agent to pass conversation_id explicitly.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
* resolve to
|
|
12
|
+
* Claude Code conversations resolve to their bare transcript id; other
|
|
13
|
+
* runtimes resolve to `<runtime>:<id>` so their ids can't collide.
|
|
14
14
|
*
|
|
15
15
|
* Fail-open: any I/O error returns null so the recall path never breaks.
|
|
16
16
|
*/
|
|
17
17
|
import { closeSync, fstatSync, openSync, readdirSync, readSync, statSync } from "node:fs";
|
|
18
|
-
import { join } from "node:path";
|
|
18
|
+
import { basename, dirname, join } from "node:path";
|
|
19
19
|
import { homedir } from "node:os";
|
|
20
20
|
const MIN_QUERY_LEN = 12;
|
|
21
21
|
const TAIL_BYTES = 64 * 1024;
|
|
22
22
|
const MAX_CANDIDATES = 5;
|
|
23
|
-
function
|
|
24
|
-
|
|
23
|
+
function defaultRoots() {
|
|
24
|
+
const home = homedir();
|
|
25
|
+
const dataHome = process.env["XDG_DATA_HOME"] || join(home, ".local", "share");
|
|
26
|
+
return [
|
|
27
|
+
{
|
|
28
|
+
dir: process.env["NLM_CLAUDE_PROJECTS_ROOT"] ?? join(home, ".claude", "projects"),
|
|
29
|
+
idOf: (_path, stem) => stem,
|
|
30
|
+
},
|
|
31
|
+
{ dir: join(home, ".codex", "sessions"), idOf: (_path, stem) => `codex:${stem}` },
|
|
32
|
+
{ dir: join(home, ".pi", "agent", "sessions"), idOf: (_path, stem) => `pi:${stem}` },
|
|
33
|
+
// Muse names every transcript session.jsonl; the session is its directory.
|
|
34
|
+
{ dir: join(dataHome, "muse", "sessions"), idOf: (path) => `muse:${basename(dirname(path))}` },
|
|
35
|
+
];
|
|
25
36
|
}
|
|
26
37
|
function tailRead(path, maxBytes) {
|
|
27
38
|
const fd = openSync(path, "r");
|
|
@@ -75,15 +86,16 @@ export function resolveConversationByQuery(query, opts) {
|
|
|
75
86
|
try {
|
|
76
87
|
if (query.length < MIN_QUERY_LEN)
|
|
77
88
|
return null;
|
|
78
|
-
const
|
|
79
|
-
const files =
|
|
89
|
+
const roots = opts?.rootDir ? [{ dir: opts.rootDir, idOf: (_p, stem) => stem }] : defaultRoots();
|
|
90
|
+
const files = roots
|
|
91
|
+
.flatMap((root) => collectJsonlFiles(root.dir).map((f) => ({ ...f, root })))
|
|
80
92
|
.sort((a, b) => b.mtimeMs - a.mtimeMs)
|
|
81
93
|
.slice(0, MAX_CANDIDATES);
|
|
82
|
-
for (const { path, stem } of files) {
|
|
94
|
+
for (const { path, stem, root } of files) {
|
|
83
95
|
try {
|
|
84
96
|
const tail = tailRead(path, TAIL_BYTES);
|
|
85
97
|
if (tail.includes(query))
|
|
86
|
-
return stem;
|
|
98
|
+
return root.idOf(path, stem);
|
|
87
99
|
}
|
|
88
100
|
catch {
|
|
89
101
|
// skip unreadable or vanished files
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-conversation-by-query.js","sourceRoot":"","sources":["../../../src/core/hook/resolve-conversation-by-query.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;A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AAE,IAAI,EAAE,CAAC,CAAC,CAAC;aAC3E,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC;aACrC,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;QAC5B,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,KAAK,EAAE,CAAC;YACzC,IAAI,CAAC;gBACH,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;gBACxC,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;oBAAE,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACzD,CAAC;YAAC,MAAM,CAAC;gBACP,oCAAoC;YACtC,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* backfill-derivables — one-time retroactive stamp of agent_persona +
|
|
3
|
+
* parent_session_id (#352 phase 2) onto sessions ingested before the
|
|
4
|
+
* scheduler started stamping them at classify time (see
|
|
5
|
+
* src/core/scheduler/scheduler.ts, commit 34968a8).
|
|
6
|
+
*
|
|
7
|
+
* Mirrors the live stamp site exactly so backfilled rows match
|
|
8
|
+
* freshly-ingested ones: claude-code rows go through deriveSubagentMeta
|
|
9
|
+
* (reversing the `<parent>/agent-<id>` runtimeSessionId + `[subagent <slug>]`
|
|
10
|
+
* label encoding); every other runtime has no subagent concept, so persona
|
|
11
|
+
* is just the runtime name and parent is null.
|
|
12
|
+
*
|
|
13
|
+
* Idempotent: selection is WHERE agent_persona IS NULL, so a re-run only
|
|
14
|
+
* touches rows a prior run (or live ingest) hasn't stamped yet.
|
|
15
|
+
*
|
|
16
|
+
* Known data quirk (Task 2 review): some subagent transcripts encode a
|
|
17
|
+
* literal `unknown` parent (`unknown/agent-<id>`), which derives
|
|
18
|
+
* parentSessionId = "unknown" — a non-joining placeholder, not a real
|
|
19
|
+
* session id. The backfill still writes it, for consistency with live
|
|
20
|
+
* stamping, but counts it separately (`unknownParent`) so operators can see
|
|
21
|
+
* how much of the corpus has an unresolvable parent link.
|
|
22
|
+
*
|
|
23
|
+
* Persona is frequently unrecoverable for pre-existing subagent rows: the
|
|
24
|
+
* live stamp site derives persona from the transient pre-classification
|
|
25
|
+
* chunk.label (which carries the `[subagent <slug>]` prefix), but the
|
|
26
|
+
* `label` column this backfill reads is the classifier's generated title —
|
|
27
|
+
* that prefix is already gone by the time a row lands in `sessions`. In
|
|
28
|
+
* practice this means most historical subagent rows get parent_session_id
|
|
29
|
+
* populated but agent_persona stays NULL. Only genuinely new ingests (which
|
|
30
|
+
* derive from the live chunk before classification overwrites it) get both.
|
|
31
|
+
* Such rows stay selectable (agent_persona IS NULL) forever, so the run
|
|
32
|
+
* compares derived values against stored ones and counts a row `updated`
|
|
33
|
+
* only when the write would change something; a re-run over a fully
|
|
34
|
+
* backfilled corpus reports updated=0 with the unrecoverable rows under
|
|
35
|
+
* `skippedNoop`.
|
|
36
|
+
*
|
|
37
|
+
* Task 5 addition: `--with-transcript-scan` optionally also re-scans each
|
|
38
|
+
* candidate's transcript file for primary_model/total_tokens/skill via
|
|
39
|
+
* scanTranscriptDerivables. Off by default — scanning streams every
|
|
40
|
+
* candidate's transcript off disk and is far slower than the persona/parent
|
|
41
|
+
* derivation above, which only touches already-loaded columns. When the
|
|
42
|
+
* flag is set, candidacy widens beyond WHERE agent_persona IS NULL with an
|
|
43
|
+
* OR arm keyed on the scan's own columns (claude-code-jsonl rows with a
|
|
44
|
+
* transcript_path and all three scan columns still NULL) — otherwise a row
|
|
45
|
+
* whose persona was stamped by an earlier flagless run would never be
|
|
46
|
+
* scannable, leaving the flag shipped but effectively unwired for exactly
|
|
47
|
+
* the rows Task 3 already processed. Rows selected only via that arm get a
|
|
48
|
+
* scan-only write (persona/parent untouched); either way the scan columns
|
|
49
|
+
* COALESCE-preserve, and a re-run reports updated=0: a stamped scan column
|
|
50
|
+
* excludes the row from the OR arm on the next pass, and rows that stay
|
|
51
|
+
* selectable via the persona arm (persona-unrecoverable subagent rows) skip
|
|
52
|
+
* the re-scan once any scan column is stamped and count as no-op when the
|
|
53
|
+
* scan cannot change the row (all-null result, or derivables already
|
|
54
|
+
* stored).
|
|
55
|
+
*/
|
|
56
|
+
import type { Database } from "better-sqlite3";
|
|
57
|
+
export interface BackfillOptions {
|
|
58
|
+
readonly dryRun?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Also scan each candidate's transcript file for
|
|
61
|
+
* primary_model/total_tokens/skill (#352 phase 2, Task 5). Off by
|
|
62
|
+
* default: slower than the persona/parent derivation (streams every
|
|
63
|
+
* candidate's transcript off disk).
|
|
64
|
+
*/
|
|
65
|
+
readonly withTranscriptScan?: boolean;
|
|
66
|
+
}
|
|
67
|
+
export interface BackfillReport {
|
|
68
|
+
/** All rows in the sessions table, stamped or not. */
|
|
69
|
+
readonly total: number;
|
|
70
|
+
/** Rows whose write would change something (or did, when not --dry-run). */
|
|
71
|
+
readonly updated: number;
|
|
72
|
+
/**
|
|
73
|
+
* Rows not selected at all: agent_persona already stamped and (when
|
|
74
|
+
* withTranscriptScan) not eligible for the scan arm either.
|
|
75
|
+
*/
|
|
76
|
+
readonly skippedAlreadyStamped: number;
|
|
77
|
+
/**
|
|
78
|
+
* Selected rows whose derived values match what's already stored — persona
|
|
79
|
+
* unrecoverable (NULL derives NULL), parent either already stamped by a
|
|
80
|
+
* prior run or also underivable, and (when withTranscriptScan) the
|
|
81
|
+
* transcript scan derived nothing either. Attempted, nothing to write.
|
|
82
|
+
*/
|
|
83
|
+
readonly skippedNoop: number;
|
|
84
|
+
/** Of the selected rows, how many derived a real parent link (subagent-shaped runtimeSessionId). */
|
|
85
|
+
readonly subagentCandidates: number;
|
|
86
|
+
/** Of the selected rows, how many derived a literal "unknown" parent placeholder. */
|
|
87
|
+
readonly unknownParent: number;
|
|
88
|
+
/** Rows whose transcript was scanned and derived at least one non-null
|
|
89
|
+
* field. Always 0 when withTranscriptScan is not set. */
|
|
90
|
+
readonly transcriptScanned: number;
|
|
91
|
+
}
|
|
92
|
+
export declare function backfillDerivables(db: Database, opts?: BackfillOptions): Promise<BackfillReport>;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* backfill-derivables — one-time retroactive stamp of agent_persona +
|
|
3
|
+
* parent_session_id (#352 phase 2) onto sessions ingested before the
|
|
4
|
+
* scheduler started stamping them at classify time (see
|
|
5
|
+
* src/core/scheduler/scheduler.ts, commit 34968a8).
|
|
6
|
+
*
|
|
7
|
+
* Mirrors the live stamp site exactly so backfilled rows match
|
|
8
|
+
* freshly-ingested ones: claude-code rows go through deriveSubagentMeta
|
|
9
|
+
* (reversing the `<parent>/agent-<id>` runtimeSessionId + `[subagent <slug>]`
|
|
10
|
+
* label encoding); every other runtime has no subagent concept, so persona
|
|
11
|
+
* is just the runtime name and parent is null.
|
|
12
|
+
*
|
|
13
|
+
* Idempotent: selection is WHERE agent_persona IS NULL, so a re-run only
|
|
14
|
+
* touches rows a prior run (or live ingest) hasn't stamped yet.
|
|
15
|
+
*
|
|
16
|
+
* Known data quirk (Task 2 review): some subagent transcripts encode a
|
|
17
|
+
* literal `unknown` parent (`unknown/agent-<id>`), which derives
|
|
18
|
+
* parentSessionId = "unknown" — a non-joining placeholder, not a real
|
|
19
|
+
* session id. The backfill still writes it, for consistency with live
|
|
20
|
+
* stamping, but counts it separately (`unknownParent`) so operators can see
|
|
21
|
+
* how much of the corpus has an unresolvable parent link.
|
|
22
|
+
*
|
|
23
|
+
* Persona is frequently unrecoverable for pre-existing subagent rows: the
|
|
24
|
+
* live stamp site derives persona from the transient pre-classification
|
|
25
|
+
* chunk.label (which carries the `[subagent <slug>]` prefix), but the
|
|
26
|
+
* `label` column this backfill reads is the classifier's generated title —
|
|
27
|
+
* that prefix is already gone by the time a row lands in `sessions`. In
|
|
28
|
+
* practice this means most historical subagent rows get parent_session_id
|
|
29
|
+
* populated but agent_persona stays NULL. Only genuinely new ingests (which
|
|
30
|
+
* derive from the live chunk before classification overwrites it) get both.
|
|
31
|
+
* Such rows stay selectable (agent_persona IS NULL) forever, so the run
|
|
32
|
+
* compares derived values against stored ones and counts a row `updated`
|
|
33
|
+
* only when the write would change something; a re-run over a fully
|
|
34
|
+
* backfilled corpus reports updated=0 with the unrecoverable rows under
|
|
35
|
+
* `skippedNoop`.
|
|
36
|
+
*
|
|
37
|
+
* Task 5 addition: `--with-transcript-scan` optionally also re-scans each
|
|
38
|
+
* candidate's transcript file for primary_model/total_tokens/skill via
|
|
39
|
+
* scanTranscriptDerivables. Off by default — scanning streams every
|
|
40
|
+
* candidate's transcript off disk and is far slower than the persona/parent
|
|
41
|
+
* derivation above, which only touches already-loaded columns. When the
|
|
42
|
+
* flag is set, candidacy widens beyond WHERE agent_persona IS NULL with an
|
|
43
|
+
* OR arm keyed on the scan's own columns (claude-code-jsonl rows with a
|
|
44
|
+
* transcript_path and all three scan columns still NULL) — otherwise a row
|
|
45
|
+
* whose persona was stamped by an earlier flagless run would never be
|
|
46
|
+
* scannable, leaving the flag shipped but effectively unwired for exactly
|
|
47
|
+
* the rows Task 3 already processed. Rows selected only via that arm get a
|
|
48
|
+
* scan-only write (persona/parent untouched); either way the scan columns
|
|
49
|
+
* COALESCE-preserve, and a re-run reports updated=0: a stamped scan column
|
|
50
|
+
* excludes the row from the OR arm on the next pass, and rows that stay
|
|
51
|
+
* selectable via the persona arm (persona-unrecoverable subagent rows) skip
|
|
52
|
+
* the re-scan once any scan column is stamped and count as no-op when the
|
|
53
|
+
* scan cannot change the row (all-null result, or derivables already
|
|
54
|
+
* stored).
|
|
55
|
+
*/
|
|
56
|
+
import { deriveSubagentMeta } from "../adapters/claude-code.js";
|
|
57
|
+
import { scanTranscriptDerivables } from "./transcript-derivables.js";
|
|
58
|
+
const BATCH_SIZE = 500;
|
|
59
|
+
const NULL_TRANSCRIPT_DERIVABLES = {
|
|
60
|
+
primaryModel: null,
|
|
61
|
+
totalTokens: null,
|
|
62
|
+
skill: null,
|
|
63
|
+
};
|
|
64
|
+
// Widened OR arm for --with-transcript-scan: rows already persona-stamped
|
|
65
|
+
// (e.g. by an earlier flagless Task 3 run) but never transcript-scanned.
|
|
66
|
+
// Scoped to claude-code-jsonl since scanTranscriptDerivables derives nothing
|
|
67
|
+
// for any other kind; requires ALL three scan columns NULL so any stamped
|
|
68
|
+
// scan column excludes the row on the next pass (re-run idempotency).
|
|
69
|
+
const SCAN_CANDIDATE_ARM = " OR (transcript_path IS NOT NULL AND transcript_kind = 'claude-code-jsonl'" +
|
|
70
|
+
" AND primary_model IS NULL AND total_tokens IS NULL AND skill IS NULL)";
|
|
71
|
+
function selectCandidates(db, withTranscriptScan) {
|
|
72
|
+
return db
|
|
73
|
+
.prepare("SELECT id, runtime, runtime_session_id, label, agent_persona, parent_session_id, transcript_path, transcript_kind, primary_model, total_tokens, skill" +
|
|
74
|
+
" FROM sessions WHERE agent_persona IS NULL" +
|
|
75
|
+
(withTranscriptScan ? SCAN_CANDIDATE_ARM : ""))
|
|
76
|
+
.all();
|
|
77
|
+
}
|
|
78
|
+
// The sessions.runtime column stores the adapter's versioned runtime string
|
|
79
|
+
// (e.g. "claude-code/1.0", "hermes/1.0" — see each adapter's runtimeVersion
|
|
80
|
+
// field), but the live stamp site in scheduler.ts branches on the bare
|
|
81
|
+
// adapter name ("claude-code", "hermes", ...). Strip the version suffix so
|
|
82
|
+
// the backfill branches identically to a fresh ingest.
|
|
83
|
+
function bareRuntimeName(runtime) {
|
|
84
|
+
const slash = runtime.indexOf("/");
|
|
85
|
+
return slash === -1 ? runtime : runtime.slice(0, slash);
|
|
86
|
+
}
|
|
87
|
+
function deriveMeta(row) {
|
|
88
|
+
const runtimeName = bareRuntimeName(row.runtime);
|
|
89
|
+
if (runtimeName === "claude-code") {
|
|
90
|
+
return deriveSubagentMeta(row.runtime_session_id ?? "", row.label);
|
|
91
|
+
}
|
|
92
|
+
return { persona: runtimeName, parentSessionId: null };
|
|
93
|
+
}
|
|
94
|
+
export async function backfillDerivables(db, opts = {}) {
|
|
95
|
+
const total = db.prepare("SELECT COUNT(*) AS n FROM sessions").get().n;
|
|
96
|
+
const candidates = selectCandidates(db, Boolean(opts.withTranscriptScan));
|
|
97
|
+
const skippedAlreadyStamped = total - candidates.length;
|
|
98
|
+
let subagentCandidates = 0;
|
|
99
|
+
let unknownParent = 0;
|
|
100
|
+
let skippedNoop = 0;
|
|
101
|
+
let transcriptScanned = 0;
|
|
102
|
+
const toWrite = [];
|
|
103
|
+
for (const row of candidates) {
|
|
104
|
+
const meta = row.agent_persona === null ? deriveMeta(row) : null;
|
|
105
|
+
if (meta) {
|
|
106
|
+
if (meta.parentSessionId !== null)
|
|
107
|
+
subagentCandidates++;
|
|
108
|
+
if (meta.parentSessionId === "unknown")
|
|
109
|
+
unknownParent++;
|
|
110
|
+
}
|
|
111
|
+
// Any non-null stored scan column means a completed prior scan already
|
|
112
|
+
// stamped every field this transcript can derive (all three co-derive
|
|
113
|
+
// from the same pass, at ingest and here) - re-scanning would only
|
|
114
|
+
// re-derive values COALESCE discards. Skipping is what keeps
|
|
115
|
+
// persona-unrecoverable rows (agent_persona NULL forever, re-selected
|
|
116
|
+
// every run via the persona arm) from re-streaming their transcript and
|
|
117
|
+
// churning as "updated" on every pass.
|
|
118
|
+
const scanAlreadyRan = row.primary_model !== null || row.total_tokens !== null || row.skill !== null;
|
|
119
|
+
let transcript = NULL_TRANSCRIPT_DERIVABLES;
|
|
120
|
+
if (opts.withTranscriptScan && row.transcript_path && !scanAlreadyRan) {
|
|
121
|
+
transcript = await scanTranscriptDerivables(row.transcript_path, row.transcript_kind ?? "");
|
|
122
|
+
if (transcript.primaryModel !== null || transcript.totalTokens !== null || transcript.skill !== null) {
|
|
123
|
+
transcriptScanned++;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// Persona-null rows: the meta write is a no-op exactly when the derived
|
|
127
|
+
// persona is also NULL and the derived parent matches what a prior run
|
|
128
|
+
// already stamped (or is equally NULL). Scan-only rows have nothing to
|
|
129
|
+
// write for meta by definition.
|
|
130
|
+
const metaIsNoop = meta === null || (meta.persona === null && meta.parentSessionId === row.parent_session_id);
|
|
131
|
+
// The scan write is COALESCE-guarded, so it changes the row only where a
|
|
132
|
+
// stored column is NULL and the scan derived a value for it. An all-null
|
|
133
|
+
// scan (missing/unreadable transcript) or a scan whose derivables are
|
|
134
|
+
// already stored is a no-op - counting those as "updated" was the run-N
|
|
135
|
+
// churn bug (updated=N repeating forever with byte-identical results).
|
|
136
|
+
const transcriptWrites = (row.primary_model === null && transcript.primaryModel !== null) ||
|
|
137
|
+
(row.total_tokens === null && transcript.totalTokens !== null) ||
|
|
138
|
+
(row.skill === null && transcript.skill !== null);
|
|
139
|
+
if (metaIsNoop && !transcriptWrites) {
|
|
140
|
+
skippedNoop++;
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
toWrite.push({ id: row.id, meta, transcript });
|
|
144
|
+
}
|
|
145
|
+
if (opts.dryRun) {
|
|
146
|
+
return { total, updated: toWrite.length, skippedAlreadyStamped, skippedNoop, subagentCandidates, unknownParent, transcriptScanned };
|
|
147
|
+
}
|
|
148
|
+
const metaAndScanStmt = db.prepare(`UPDATE sessions SET
|
|
149
|
+
agent_persona = ?, parent_session_id = ?,
|
|
150
|
+
primary_model = COALESCE(primary_model, ?),
|
|
151
|
+
total_tokens = COALESCE(total_tokens, ?),
|
|
152
|
+
skill = COALESCE(skill, ?)
|
|
153
|
+
WHERE id = ? AND agent_persona IS NULL`);
|
|
154
|
+
const scanOnlyStmt = db.prepare(`UPDATE sessions SET
|
|
155
|
+
primary_model = COALESCE(primary_model, ?),
|
|
156
|
+
total_tokens = COALESCE(total_tokens, ?),
|
|
157
|
+
skill = COALESCE(skill, ?)
|
|
158
|
+
WHERE id = ?`);
|
|
159
|
+
for (let i = 0; i < toWrite.length; i += BATCH_SIZE) {
|
|
160
|
+
const batch = toWrite.slice(i, i + BATCH_SIZE);
|
|
161
|
+
const runBatch = db.transaction((rows) => {
|
|
162
|
+
for (const row of rows) {
|
|
163
|
+
if (row.meta) {
|
|
164
|
+
metaAndScanStmt.run(row.meta.persona, row.meta.parentSessionId, row.transcript.primaryModel, row.transcript.totalTokens, row.transcript.skill, row.id);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
scanOnlyStmt.run(row.transcript.primaryModel, row.transcript.totalTokens, row.transcript.skill, row.id);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
runBatch(batch);
|
|
172
|
+
}
|
|
173
|
+
return { total, updated: toWrite.length, skippedAlreadyStamped, skippedNoop, subagentCandidates, unknownParent, transcriptScanned };
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=backfill-derivables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backfill-derivables.js","sourceRoot":"","sources":["../../../src/core/ingest/backfill-derivables.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,wBAAwB,EAA6B,MAAM,4BAA4B,CAAC;AAEjG,MAAM,UAAU,GAAG,GAAG,CAAC;AAEvB,MAAM,0BAA0B,GAAyB;IACvD,YAAY,EAAE,IAAI;IAClB,WAAW,EAAE,IAAI;IACjB,KAAK,EAAE,IAAI;CACZ,CAAC;AAqDF,0EAA0E;AAC1E,yEAAyE;AACzE,6EAA6E;AAC7E,0EAA0E;AAC1E,sEAAsE;AACtE,MAAM,kBAAkB,GACtB,4EAA4E;IAC5E,wEAAwE,CAAC;AAE3E,SAAS,gBAAgB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GAAG,EAAE,CAAC,WAAW,CAAC,CAAC,IAAkB,EAAE,EAAE;YACrD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;gBACvB,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;oBACb,eAAe,CAAC,GAAG,CACjB,GAAG,CAAC,IAAI,CAAC,OAAO,EAChB,GAAG,CAAC,IAAI,CAAC,eAAe,EACxB,GAAG,CAAC,UAAU,CAAC,YAAY,EAC3B,GAAG,CAAC,UAAU,CAAC,WAAW,EAC1B,GAAG,CAAC,UAAU,CAAC,KAAK,EACpB,GAAG,CAAC,EAAE,CACP,CAAC;gBACJ,CAAC;qBAAM,CAAC;oBACN,YAAY,CAAC,GAAG,CACd,GAAG,CAAC,UAAU,CAAC,YAAY,EAC3B,GAAG,CAAC,UAAU,CAAC,WAAW,EAC1B,GAAG,CAAC,UAAU,CAAC,KAAK,EACpB,GAAG,CAAC,EAAE,CACP,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QACH,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,qBAAqB,EAAE,WAAW,EAAE,kBAAkB,EAAE,aAAa,EAAE,iBAAiB,EAAE,CAAC;AACtI,CAAC"}
|
|
@@ -44,4 +44,4 @@ export interface IngestResult {
|
|
|
44
44
|
readonly error?: string;
|
|
45
45
|
}
|
|
46
46
|
export declare function deriveSessionId(runtime: string, startedAt: string, text: string): string;
|
|
47
|
-
export declare function ingestSession(input: IngestInput, deps: IngestDeps): Promise<IngestResult>;
|
|
47
|
+
export declare function ingestSession(input: IngestInput, deps: IngestDeps, tenantId: string): Promise<IngestResult>;
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { createHash } from "node:crypto";
|
|
10
10
|
import { extractFacts } from "../facts/extract-facts.js";
|
|
11
|
+
import { scanTranscriptDerivables } from "../ingest/transcript-derivables.js";
|
|
11
12
|
import { PgSessionStore } from "../storage/pg-session-store.js";
|
|
12
13
|
const BODY_CAP = 200_000;
|
|
13
14
|
const CONFIDENCE_FLOOR = 0.3;
|
|
@@ -22,7 +23,7 @@ export function deriveSessionId(runtime, startedAt, text) {
|
|
|
22
23
|
.slice(0, 16);
|
|
23
24
|
return `webhook_${hash}`;
|
|
24
25
|
}
|
|
25
|
-
export async function ingestSession(input, deps) {
|
|
26
|
+
export async function ingestSession(input, deps, tenantId) {
|
|
26
27
|
const startedAt = input.startedAt ?? new Date().toISOString();
|
|
27
28
|
const id = input.id ?? deriveSessionId(input.runtime, startedAt, input.text);
|
|
28
29
|
const log = deps.log ?? ((m) => console.error(m));
|
|
@@ -44,6 +45,14 @@ export async function ingestSession(input, deps) {
|
|
|
44
45
|
confidence: classification.confidence,
|
|
45
46
|
};
|
|
46
47
|
}
|
|
48
|
+
// Task #352 phase 2 (Task 5): scan the transcript file (if any) for
|
|
49
|
+
// primary_model/total_tokens/skill. Webhook pushes carry transcriptKind
|
|
50
|
+
// "webhook", not "claude-code-jsonl", so this always resolves all-null
|
|
51
|
+
// today -- wired for parity with the scheduler stamp site and any future
|
|
52
|
+
// webhook kind that does carry a scannable transcript.
|
|
53
|
+
const transcriptDerivables = input.transcriptPath
|
|
54
|
+
? await scanTranscriptDerivables(input.transcriptPath, "webhook")
|
|
55
|
+
: { primaryModel: null, totalTokens: null, skill: null };
|
|
47
56
|
const record = {
|
|
48
57
|
id,
|
|
49
58
|
runtime: input.runtime,
|
|
@@ -62,6 +71,17 @@ export async function ingestSession(input, deps) {
|
|
|
62
71
|
entities: classification.entities,
|
|
63
72
|
decisions: classification.decisions,
|
|
64
73
|
openQuestions: classification.open,
|
|
74
|
+
// Push ingest carries no project directory; the scope backfill command
|
|
75
|
+
// derives it later from the transcript when evidence exists.
|
|
76
|
+
scope: null,
|
|
77
|
+
// Webhook pushes have no adapter chunk to derive subagent lineage from;
|
|
78
|
+
// stamp the runtime name as persona, matching every non-claude-code
|
|
79
|
+
// adapter at the scheduler stamp site (#352 phase 2).
|
|
80
|
+
agentPersona: input.runtime,
|
|
81
|
+
parentSessionId: null,
|
|
82
|
+
primaryModel: transcriptDerivables.primaryModel,
|
|
83
|
+
totalTokens: transcriptDerivables.totalTokens,
|
|
84
|
+
skill: transcriptDerivables.skill,
|
|
65
85
|
...(deps.classifierDescriptor !== undefined
|
|
66
86
|
? { classifier: { ...deps.classifierDescriptor, confidence: classification.confidence } }
|
|
67
87
|
: {}),
|
|
@@ -72,10 +92,10 @@ export async function ingestSession(input, deps) {
|
|
|
72
92
|
// Store + factStore come from the same backend (see buildStack); the cast
|
|
73
93
|
// is sound — TS can't correlate the two union members at one call site.
|
|
74
94
|
if (deps.store instanceof PgSessionStore) {
|
|
75
|
-
await deps.store.insertSession(record, deps.embedder, null, deps.factStore ? { factStore: deps.factStore, facts } : null);
|
|
95
|
+
await deps.store.insertSession(tenantId, record, deps.embedder, null, deps.factStore ? { factStore: deps.factStore, facts } : null);
|
|
76
96
|
}
|
|
77
97
|
else {
|
|
78
|
-
await deps.store.insertSession(record, deps.embedder, null, deps.factStore ? { factStore: deps.factStore, facts } : null);
|
|
98
|
+
await deps.store.insertSession(tenantId, record, deps.embedder, null, deps.factStore ? { factStore: deps.factStore, facts } : null);
|
|
79
99
|
}
|
|
80
100
|
return { id, status: "ingested", latencyMs: Date.now() - t0, confidence: classification.confidence };
|
|
81
101
|
}
|