@getrift/rift 0.0.0 → 0.1.0-beta.1
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.dev.md +110 -0
- package/dist/src/auth/keychain.d.ts +25 -0
- package/dist/src/auth/keychain.d.ts.map +1 -0
- package/dist/src/auth/keychain.js +113 -0
- package/dist/src/auth/keychain.js.map +1 -0
- package/dist/src/auth/middleware.d.ts +20 -0
- package/dist/src/auth/middleware.d.ts.map +1 -0
- package/dist/src/auth/middleware.js +49 -0
- package/dist/src/auth/middleware.js.map +1 -0
- package/dist/src/auth/rate-limit.d.ts +16 -0
- package/dist/src/auth/rate-limit.d.ts.map +1 -0
- package/dist/src/auth/rate-limit.js +38 -0
- package/dist/src/auth/rate-limit.js.map +1 -0
- package/dist/src/auth/rotation.d.ts +67 -0
- package/dist/src/auth/rotation.d.ts.map +1 -0
- package/dist/src/auth/rotation.js +190 -0
- package/dist/src/auth/rotation.js.map +1 -0
- package/dist/src/backfill/project-context-batch-constructor.d.ts +127 -0
- package/dist/src/backfill/project-context-batch-constructor.d.ts.map +1 -0
- package/dist/src/backfill/project-context-batch-constructor.js +210 -0
- package/dist/src/backfill/project-context-batch-constructor.js.map +1 -0
- package/dist/src/capture/auto-capture.d.ts +162 -0
- package/dist/src/capture/auto-capture.d.ts.map +1 -0
- package/dist/src/capture/auto-capture.js +601 -0
- package/dist/src/capture/auto-capture.js.map +1 -0
- package/dist/src/capture/batch-budget.d.ts +90 -0
- package/dist/src/capture/batch-budget.d.ts.map +1 -0
- package/dist/src/capture/batch-budget.js +148 -0
- package/dist/src/capture/batch-budget.js.map +1 -0
- package/dist/src/capture/codex-cli-triage-provider.d.ts +17 -0
- package/dist/src/capture/codex-cli-triage-provider.d.ts.map +1 -0
- package/dist/src/capture/codex-cli-triage-provider.js +109 -0
- package/dist/src/capture/codex-cli-triage-provider.js.map +1 -0
- package/dist/src/capture/observability.d.ts +42 -0
- package/dist/src/capture/observability.d.ts.map +1 -0
- package/dist/src/capture/observability.js +87 -0
- package/dist/src/capture/observability.js.map +1 -0
- package/dist/src/capture/openai-triage-provider.d.ts +92 -0
- package/dist/src/capture/openai-triage-provider.d.ts.map +1 -0
- package/dist/src/capture/openai-triage-provider.js +267 -0
- package/dist/src/capture/openai-triage-provider.js.map +1 -0
- package/dist/src/capture/review-queue-index.d.ts +51 -0
- package/dist/src/capture/review-queue-index.d.ts.map +1 -0
- package/dist/src/capture/review-queue-index.js +204 -0
- package/dist/src/capture/review-queue-index.js.map +1 -0
- package/dist/src/capture/review-queue.d.ts +43 -0
- package/dist/src/capture/review-queue.d.ts.map +1 -0
- package/dist/src/capture/review-queue.js +116 -0
- package/dist/src/capture/review-queue.js.map +1 -0
- package/dist/src/capture/sources.d.ts +7 -0
- package/dist/src/capture/sources.d.ts.map +1 -0
- package/dist/src/capture/sources.js +3 -0
- package/dist/src/capture/sources.js.map +1 -0
- package/dist/src/capture/triage-lane.d.ts +39 -0
- package/dist/src/capture/triage-lane.d.ts.map +1 -0
- package/dist/src/capture/triage-lane.js +217 -0
- package/dist/src/capture/triage-lane.js.map +1 -0
- package/dist/src/capture/triage-provider.d.ts +75 -0
- package/dist/src/capture/triage-provider.d.ts.map +1 -0
- package/dist/src/capture/triage-provider.js +120 -0
- package/dist/src/capture/triage-provider.js.map +1 -0
- package/dist/src/capture/triage.d.ts +30 -0
- package/dist/src/capture/triage.d.ts.map +1 -0
- package/dist/src/capture/triage.js +48 -0
- package/dist/src/capture/triage.js.map +1 -0
- package/dist/src/cli/commands/backfill.d.ts +3 -0
- package/dist/src/cli/commands/backfill.d.ts.map +1 -0
- package/dist/src/cli/commands/backfill.js +1376 -0
- package/dist/src/cli/commands/backfill.js.map +1 -0
- package/dist/src/cli/commands/bulk-ingest.d.ts +3 -0
- package/dist/src/cli/commands/bulk-ingest.d.ts.map +1 -0
- package/dist/src/cli/commands/bulk-ingest.js +126 -0
- package/dist/src/cli/commands/bulk-ingest.js.map +1 -0
- package/dist/src/cli/commands/capture.d.ts +12 -0
- package/dist/src/cli/commands/capture.d.ts.map +1 -0
- package/dist/src/cli/commands/capture.js +123 -0
- package/dist/src/cli/commands/capture.js.map +1 -0
- package/dist/src/cli/commands/compact.d.ts +3 -0
- package/dist/src/cli/commands/compact.d.ts.map +1 -0
- package/dist/src/cli/commands/compact.js +70 -0
- package/dist/src/cli/commands/compact.js.map +1 -0
- package/dist/src/cli/commands/feedback.d.ts +22 -0
- package/dist/src/cli/commands/feedback.d.ts.map +1 -0
- package/dist/src/cli/commands/feedback.js +125 -0
- package/dist/src/cli/commands/feedback.js.map +1 -0
- package/dist/src/cli/commands/hooks-install.d.ts +19 -0
- package/dist/src/cli/commands/hooks-install.d.ts.map +1 -0
- package/dist/src/cli/commands/hooks-install.js +103 -0
- package/dist/src/cli/commands/hooks-install.js.map +1 -0
- package/dist/src/cli/commands/import.d.ts +19 -0
- package/dist/src/cli/commands/import.d.ts.map +1 -0
- package/dist/src/cli/commands/import.js +258 -0
- package/dist/src/cli/commands/import.js.map +1 -0
- package/dist/src/cli/commands/ingest.d.ts +3 -0
- package/dist/src/cli/commands/ingest.d.ts.map +1 -0
- package/dist/src/cli/commands/ingest.js +80 -0
- package/dist/src/cli/commands/ingest.js.map +1 -0
- package/dist/src/cli/commands/mcp-install.d.ts +25 -0
- package/dist/src/cli/commands/mcp-install.d.ts.map +1 -0
- package/dist/src/cli/commands/mcp-install.js +134 -0
- package/dist/src/cli/commands/mcp-install.js.map +1 -0
- package/dist/src/cli/commands/onboard.d.ts +98 -0
- package/dist/src/cli/commands/onboard.d.ts.map +1 -0
- package/dist/src/cli/commands/onboard.js +823 -0
- package/dist/src/cli/commands/onboard.js.map +1 -0
- package/dist/src/cli/commands/rebuild.d.ts +12 -0
- package/dist/src/cli/commands/rebuild.d.ts.map +1 -0
- package/dist/src/cli/commands/rebuild.js +164 -0
- package/dist/src/cli/commands/rebuild.js.map +1 -0
- package/dist/src/cli/commands/reconcile.d.ts +3 -0
- package/dist/src/cli/commands/reconcile.d.ts.map +1 -0
- package/dist/src/cli/commands/reconcile.js +56 -0
- package/dist/src/cli/commands/reconcile.js.map +1 -0
- package/dist/src/cli/commands/reindex.d.ts +3 -0
- package/dist/src/cli/commands/reindex.d.ts.map +1 -0
- package/dist/src/cli/commands/reindex.js +66 -0
- package/dist/src/cli/commands/reindex.js.map +1 -0
- package/dist/src/cli/commands/review.d.ts +13 -0
- package/dist/src/cli/commands/review.d.ts.map +1 -0
- package/dist/src/cli/commands/review.js +383 -0
- package/dist/src/cli/commands/review.js.map +1 -0
- package/dist/src/cli/commands/save.d.ts +3 -0
- package/dist/src/cli/commands/save.d.ts.map +1 -0
- package/dist/src/cli/commands/save.js +111 -0
- package/dist/src/cli/commands/save.js.map +1 -0
- package/dist/src/cli/commands/search.d.ts +35 -0
- package/dist/src/cli/commands/search.d.ts.map +1 -0
- package/dist/src/cli/commands/search.js +88 -0
- package/dist/src/cli/commands/search.js.map +1 -0
- package/dist/src/cli/commands/stats.d.ts +3 -0
- package/dist/src/cli/commands/stats.d.ts.map +1 -0
- package/dist/src/cli/commands/stats.js +42 -0
- package/dist/src/cli/commands/stats.js.map +1 -0
- package/dist/src/cli/commands/status.d.ts +15 -0
- package/dist/src/cli/commands/status.d.ts.map +1 -0
- package/dist/src/cli/commands/status.js +89 -0
- package/dist/src/cli/commands/status.js.map +1 -0
- package/dist/src/cli/commands/token-issue.d.ts +3 -0
- package/dist/src/cli/commands/token-issue.d.ts.map +1 -0
- package/dist/src/cli/commands/token-issue.js +25 -0
- package/dist/src/cli/commands/token-issue.js.map +1 -0
- package/dist/src/cli/commands/triage.d.ts +3 -0
- package/dist/src/cli/commands/triage.d.ts.map +1 -0
- package/dist/src/cli/commands/triage.js +125 -0
- package/dist/src/cli/commands/triage.js.map +1 -0
- package/dist/src/cli/commands/uninstall.d.ts +3 -0
- package/dist/src/cli/commands/uninstall.d.ts.map +1 -0
- package/dist/src/cli/commands/uninstall.js +238 -0
- package/dist/src/cli/commands/uninstall.js.map +1 -0
- package/dist/src/cli/feedback/feedback-config.d.ts +21 -0
- package/dist/src/cli/feedback/feedback-config.d.ts.map +1 -0
- package/dist/src/cli/feedback/feedback-config.js +43 -0
- package/dist/src/cli/feedback/feedback-config.js.map +1 -0
- package/dist/src/cli/feedback/feedback-history.d.ts +4 -0
- package/dist/src/cli/feedback/feedback-history.d.ts.map +1 -0
- package/dist/src/cli/feedback/feedback-history.js +115 -0
- package/dist/src/cli/feedback/feedback-history.js.map +1 -0
- package/dist/src/cli/feedback/feedback-payload.d.ts +53 -0
- package/dist/src/cli/feedback/feedback-payload.d.ts.map +1 -0
- package/dist/src/cli/feedback/feedback-payload.js +10 -0
- package/dist/src/cli/feedback/feedback-payload.js.map +1 -0
- package/dist/src/cli/feedback/feedback-relay.d.ts +15 -0
- package/dist/src/cli/feedback/feedback-relay.d.ts.map +1 -0
- package/dist/src/cli/feedback/feedback-relay.js +47 -0
- package/dist/src/cli/feedback/feedback-relay.js.map +1 -0
- package/dist/src/cli/feedback/feedback-status.d.ts +11 -0
- package/dist/src/cli/feedback/feedback-status.d.ts.map +1 -0
- package/dist/src/cli/feedback/feedback-status.js +122 -0
- package/dist/src/cli/feedback/feedback-status.js.map +1 -0
- package/dist/src/cli/hooks-writers/claude-code-policy-script.d.ts +25 -0
- package/dist/src/cli/hooks-writers/claude-code-policy-script.d.ts.map +1 -0
- package/dist/src/cli/hooks-writers/claude-code-policy-script.js +85 -0
- package/dist/src/cli/hooks-writers/claude-code-policy-script.js.map +1 -0
- package/dist/src/cli/hooks-writers/claude-code.d.ts +12 -0
- package/dist/src/cli/hooks-writers/claude-code.d.ts.map +1 -0
- package/dist/src/cli/hooks-writers/claude-code.js +228 -0
- package/dist/src/cli/hooks-writers/claude-code.js.map +1 -0
- package/dist/src/cli/hooks-writers/errors.d.ts +16 -0
- package/dist/src/cli/hooks-writers/errors.d.ts.map +1 -0
- package/dist/src/cli/hooks-writers/errors.js +24 -0
- package/dist/src/cli/hooks-writers/errors.js.map +1 -0
- package/dist/src/cli/hooks-writers/index.d.ts +13 -0
- package/dist/src/cli/hooks-writers/index.d.ts.map +1 -0
- package/dist/src/cli/hooks-writers/index.js +26 -0
- package/dist/src/cli/hooks-writers/index.js.map +1 -0
- package/dist/src/cli/hooks-writers/types.d.ts +27 -0
- package/dist/src/cli/hooks-writers/types.d.ts.map +1 -0
- package/dist/src/cli/hooks-writers/types.js +9 -0
- package/dist/src/cli/hooks-writers/types.js.map +1 -0
- package/dist/src/cli/http-client.d.ts +36 -0
- package/dist/src/cli/http-client.d.ts.map +1 -0
- package/dist/src/cli/http-client.js +153 -0
- package/dist/src/cli/http-client.js.map +1 -0
- package/dist/src/cli/index.d.ts +4 -0
- package/dist/src/cli/index.d.ts.map +1 -0
- package/dist/src/cli/index.js +68 -0
- package/dist/src/cli/index.js.map +1 -0
- package/dist/src/cli/job-poller.d.ts +13 -0
- package/dist/src/cli/job-poller.d.ts.map +1 -0
- package/dist/src/cli/job-poller.js +29 -0
- package/dist/src/cli/job-poller.js.map +1 -0
- package/dist/src/cli/mcp-config-writers/codex-toml.d.ts +10 -0
- package/dist/src/cli/mcp-config-writers/codex-toml.d.ts.map +1 -0
- package/dist/src/cli/mcp-config-writers/codex-toml.js +410 -0
- package/dist/src/cli/mcp-config-writers/codex-toml.js.map +1 -0
- package/dist/src/cli/mcp-config-writers/errors.d.ts +17 -0
- package/dist/src/cli/mcp-config-writers/errors.d.ts.map +1 -0
- package/dist/src/cli/mcp-config-writers/errors.js +13 -0
- package/dist/src/cli/mcp-config-writers/errors.js.map +1 -0
- package/dist/src/cli/mcp-config-writers/index.d.ts +18 -0
- package/dist/src/cli/mcp-config-writers/index.d.ts.map +1 -0
- package/dist/src/cli/mcp-config-writers/index.js +49 -0
- package/dist/src/cli/mcp-config-writers/index.js.map +1 -0
- package/dist/src/cli/mcp-config-writers/json-config.d.ts +12 -0
- package/dist/src/cli/mcp-config-writers/json-config.d.ts.map +1 -0
- package/dist/src/cli/mcp-config-writers/json-config.js +177 -0
- package/dist/src/cli/mcp-config-writers/json-config.js.map +1 -0
- package/dist/src/cli/mcp-config-writers/redact.d.ts +28 -0
- package/dist/src/cli/mcp-config-writers/redact.d.ts.map +1 -0
- package/dist/src/cli/mcp-config-writers/redact.js +48 -0
- package/dist/src/cli/mcp-config-writers/redact.js.map +1 -0
- package/dist/src/cli/mcp-config-writers/types.d.ts +32 -0
- package/dist/src/cli/mcp-config-writers/types.d.ts.map +1 -0
- package/dist/src/cli/mcp-config-writers/types.js +5 -0
- package/dist/src/cli/mcp-config-writers/types.js.map +1 -0
- package/dist/src/cli/output.d.ts +8 -0
- package/dist/src/cli/output.d.ts.map +1 -0
- package/dist/src/cli/output.js +34 -0
- package/dist/src/cli/output.js.map +1 -0
- package/dist/src/cli/status/friend-header.d.ts +33 -0
- package/dist/src/cli/status/friend-header.d.ts.map +1 -0
- package/dist/src/cli/status/friend-header.js +108 -0
- package/dist/src/cli/status/friend-header.js.map +1 -0
- package/dist/src/cli/status/local-signals.d.ts +14 -0
- package/dist/src/cli/status/local-signals.d.ts.map +1 -0
- package/dist/src/cli/status/local-signals.js +73 -0
- package/dist/src/cli/status/local-signals.js.map +1 -0
- package/dist/src/cli/token.d.ts +37 -0
- package/dist/src/cli/token.d.ts.map +1 -0
- package/dist/src/cli/token.js +105 -0
- package/dist/src/cli/token.js.map +1 -0
- package/dist/src/cli/uninstall/mcp-uninstall.d.ts +33 -0
- package/dist/src/cli/uninstall/mcp-uninstall.d.ts.map +1 -0
- package/dist/src/cli/uninstall/mcp-uninstall.js +181 -0
- package/dist/src/cli/uninstall/mcp-uninstall.js.map +1 -0
- package/dist/src/config/loader.d.ts +9 -0
- package/dist/src/config/loader.d.ts.map +1 -0
- package/dist/src/config/loader.js +73 -0
- package/dist/src/config/loader.js.map +1 -0
- package/dist/src/config/schema.d.ts +635 -0
- package/dist/src/config/schema.d.ts.map +1 -0
- package/dist/src/config/schema.js +208 -0
- package/dist/src/config/schema.js.map +1 -0
- package/dist/src/ingestion/bulk-ingest.d.ts +11 -0
- package/dist/src/ingestion/bulk-ingest.d.ts.map +1 -0
- package/dist/src/ingestion/bulk-ingest.js +11 -0
- package/dist/src/ingestion/bulk-ingest.js.map +1 -0
- package/dist/src/ingestion/extractor.d.ts +16 -0
- package/dist/src/ingestion/extractor.d.ts.map +1 -0
- package/dist/src/ingestion/extractor.js +85 -0
- package/dist/src/ingestion/extractor.js.map +1 -0
- package/dist/src/ingestion/extractors/docx.d.ts +3 -0
- package/dist/src/ingestion/extractors/docx.d.ts.map +1 -0
- package/dist/src/ingestion/extractors/docx.js +20 -0
- package/dist/src/ingestion/extractors/docx.js.map +1 -0
- package/dist/src/ingestion/extractors/pdf.d.ts +3 -0
- package/dist/src/ingestion/extractors/pdf.d.ts.map +1 -0
- package/dist/src/ingestion/extractors/pdf.js +32 -0
- package/dist/src/ingestion/extractors/pdf.js.map +1 -0
- package/dist/src/ingestion/historical-campaign.d.ts +340 -0
- package/dist/src/ingestion/historical-campaign.d.ts.map +1 -0
- package/dist/src/ingestion/historical-campaign.js +1010 -0
- package/dist/src/ingestion/historical-campaign.js.map +1 -0
- package/dist/src/ingestion/ignored-paths.d.ts +20 -0
- package/dist/src/ingestion/ignored-paths.d.ts.map +1 -0
- package/dist/src/ingestion/ignored-paths.js +45 -0
- package/dist/src/ingestion/ignored-paths.js.map +1 -0
- package/dist/src/ingestion/inbox-watcher.d.ts +12 -0
- package/dist/src/ingestion/inbox-watcher.d.ts.map +1 -0
- package/dist/src/ingestion/inbox-watcher.js +99 -0
- package/dist/src/ingestion/inbox-watcher.js.map +1 -0
- package/dist/src/ingestion/indexer.d.ts +32 -0
- package/dist/src/ingestion/indexer.d.ts.map +1 -0
- package/dist/src/ingestion/indexer.js +68 -0
- package/dist/src/ingestion/indexer.js.map +1 -0
- package/dist/src/ingestion/metadata-extraction.d.ts +53 -0
- package/dist/src/ingestion/metadata-extraction.d.ts.map +1 -0
- package/dist/src/ingestion/metadata-extraction.js +132 -0
- package/dist/src/ingestion/metadata-extraction.js.map +1 -0
- package/dist/src/ingestion/parsers/chatgpt-web.d.ts +29 -0
- package/dist/src/ingestion/parsers/chatgpt-web.d.ts.map +1 -0
- package/dist/src/ingestion/parsers/chatgpt-web.js +100 -0
- package/dist/src/ingestion/parsers/chatgpt-web.js.map +1 -0
- package/dist/src/ingestion/parsers/claude-code-jsonl.d.ts +16 -0
- package/dist/src/ingestion/parsers/claude-code-jsonl.d.ts.map +1 -0
- package/dist/src/ingestion/parsers/claude-code-jsonl.js +123 -0
- package/dist/src/ingestion/parsers/claude-code-jsonl.js.map +1 -0
- package/dist/src/ingestion/parsers/claude-web.d.ts +24 -0
- package/dist/src/ingestion/parsers/claude-web.d.ts.map +1 -0
- package/dist/src/ingestion/parsers/claude-web.js +78 -0
- package/dist/src/ingestion/parsers/claude-web.js.map +1 -0
- package/dist/src/ingestion/parsers/codex-jsonl.d.ts +18 -0
- package/dist/src/ingestion/parsers/codex-jsonl.d.ts.map +1 -0
- package/dist/src/ingestion/parsers/codex-jsonl.js +125 -0
- package/dist/src/ingestion/parsers/codex-jsonl.js.map +1 -0
- package/dist/src/ingestion/parsers/gemini-web.d.ts +16 -0
- package/dist/src/ingestion/parsers/gemini-web.d.ts.map +1 -0
- package/dist/src/ingestion/parsers/gemini-web.js +170 -0
- package/dist/src/ingestion/parsers/gemini-web.js.map +1 -0
- package/dist/src/ingestion/parsers/grok-web.d.ts +40 -0
- package/dist/src/ingestion/parsers/grok-web.d.ts.map +1 -0
- package/dist/src/ingestion/parsers/grok-web.js +67 -0
- package/dist/src/ingestion/parsers/grok-web.js.map +1 -0
- package/dist/src/ingestion/parsers/types.d.ts +34 -0
- package/dist/src/ingestion/parsers/types.d.ts.map +1 -0
- package/dist/src/ingestion/parsers/types.js +26 -0
- package/dist/src/ingestion/parsers/types.js.map +1 -0
- package/dist/src/ingestion/scanner.d.ts +48 -0
- package/dist/src/ingestion/scanner.d.ts.map +1 -0
- package/dist/src/ingestion/scanner.js +131 -0
- package/dist/src/ingestion/scanner.js.map +1 -0
- package/dist/src/ingestion/staging.d.ts +109 -0
- package/dist/src/ingestion/staging.d.ts.map +1 -0
- package/dist/src/ingestion/staging.js +411 -0
- package/dist/src/ingestion/staging.js.map +1 -0
- package/dist/src/ingestion/watcher.d.ts +65 -0
- package/dist/src/ingestion/watcher.d.ts.map +1 -0
- package/dist/src/ingestion/watcher.js +182 -0
- package/dist/src/ingestion/watcher.js.map +1 -0
- package/dist/src/jobs/codex-override-handler.d.ts +3 -0
- package/dist/src/jobs/codex-override-handler.d.ts.map +1 -0
- package/dist/src/jobs/codex-override-handler.js +16 -0
- package/dist/src/jobs/codex-override-handler.js.map +1 -0
- package/dist/src/jobs/handlers/compact.d.ts +30 -0
- package/dist/src/jobs/handlers/compact.d.ts.map +1 -0
- package/dist/src/jobs/handlers/compact.js +329 -0
- package/dist/src/jobs/handlers/compact.js.map +1 -0
- package/dist/src/jobs/handlers/ingest.d.ts +13 -0
- package/dist/src/jobs/handlers/ingest.d.ts.map +1 -0
- package/dist/src/jobs/handlers/ingest.js +255 -0
- package/dist/src/jobs/handlers/ingest.js.map +1 -0
- package/dist/src/jobs/handlers/reconcile.d.ts +29 -0
- package/dist/src/jobs/handlers/reconcile.d.ts.map +1 -0
- package/dist/src/jobs/handlers/reconcile.js +476 -0
- package/dist/src/jobs/handlers/reconcile.js.map +1 -0
- package/dist/src/jobs/handlers/reindex.d.ts +38 -0
- package/dist/src/jobs/handlers/reindex.d.ts.map +1 -0
- package/dist/src/jobs/handlers/reindex.js +52 -0
- package/dist/src/jobs/handlers/reindex.js.map +1 -0
- package/dist/src/jobs/handlers/save.d.ts +10 -0
- package/dist/src/jobs/handlers/save.d.ts.map +1 -0
- package/dist/src/jobs/handlers/save.js +206 -0
- package/dist/src/jobs/handlers/save.js.map +1 -0
- package/dist/src/jobs/handlers/triage.d.ts +47 -0
- package/dist/src/jobs/handlers/triage.d.ts.map +1 -0
- package/dist/src/jobs/handlers/triage.js +95 -0
- package/dist/src/jobs/handlers/triage.js.map +1 -0
- package/dist/src/jobs/queue.d.ts +107 -0
- package/dist/src/jobs/queue.d.ts.map +1 -0
- package/dist/src/jobs/queue.js +319 -0
- package/dist/src/jobs/queue.js.map +1 -0
- package/dist/src/jobs/types.d.ts +39 -0
- package/dist/src/jobs/types.d.ts.map +1 -0
- package/dist/src/jobs/types.js +29 -0
- package/dist/src/jobs/types.js.map +1 -0
- package/dist/src/jobs/worker-entry.d.ts +10 -0
- package/dist/src/jobs/worker-entry.d.ts.map +1 -0
- package/dist/src/jobs/worker-entry.js +210 -0
- package/dist/src/jobs/worker-entry.js.map +1 -0
- package/dist/src/jobs/worker-process.d.ts +50 -0
- package/dist/src/jobs/worker-process.d.ts.map +1 -0
- package/dist/src/jobs/worker-process.js +186 -0
- package/dist/src/jobs/worker-process.js.map +1 -0
- package/dist/src/jobs/worker.d.ts +11 -0
- package/dist/src/jobs/worker.d.ts.map +1 -0
- package/dist/src/jobs/worker.js +14 -0
- package/dist/src/jobs/worker.js.map +1 -0
- package/dist/src/main.d.ts +2 -0
- package/dist/src/main.d.ts.map +1 -0
- package/dist/src/main.js +425 -0
- package/dist/src/main.js.map +1 -0
- package/dist/src/mcp/errors.d.ts +8 -0
- package/dist/src/mcp/errors.d.ts.map +1 -0
- package/dist/src/mcp/errors.js +50 -0
- package/dist/src/mcp/errors.js.map +1 -0
- package/dist/src/mcp/server.d.ts +10 -0
- package/dist/src/mcp/server.d.ts.map +1 -0
- package/dist/src/mcp/server.js +94 -0
- package/dist/src/mcp/server.js.map +1 -0
- package/dist/src/mcp/tools/context-pack.d.ts +35 -0
- package/dist/src/mcp/tools/context-pack.d.ts.map +1 -0
- package/dist/src/mcp/tools/context-pack.js +97 -0
- package/dist/src/mcp/tools/context-pack.js.map +1 -0
- package/dist/src/mcp/tools/conversations-search.d.ts +38 -0
- package/dist/src/mcp/tools/conversations-search.d.ts.map +1 -0
- package/dist/src/mcp/tools/conversations-search.js +73 -0
- package/dist/src/mcp/tools/conversations-search.js.map +1 -0
- package/dist/src/mcp/tools/save.d.ts +32 -0
- package/dist/src/mcp/tools/save.d.ts.map +1 -0
- package/dist/src/mcp/tools/save.js +60 -0
- package/dist/src/mcp/tools/save.js.map +1 -0
- package/dist/src/mcp/tools/search.d.ts +33 -0
- package/dist/src/mcp/tools/search.d.ts.map +1 -0
- package/dist/src/mcp/tools/search.js +58 -0
- package/dist/src/mcp/tools/search.js.map +1 -0
- package/dist/src/mcp/tools/status.d.ts +17 -0
- package/dist/src/mcp/tools/status.d.ts.map +1 -0
- package/dist/src/mcp/tools/status.js +12 -0
- package/dist/src/mcp/tools/status.js.map +1 -0
- package/dist/src/observability/coverage.d.ts +100 -0
- package/dist/src/observability/coverage.d.ts.map +1 -0
- package/dist/src/observability/coverage.js +180 -0
- package/dist/src/observability/coverage.js.map +1 -0
- package/dist/src/observability/rift-context.d.ts +47 -0
- package/dist/src/observability/rift-context.d.ts.map +1 -0
- package/dist/src/observability/rift-context.js +118 -0
- package/dist/src/observability/rift-context.js.map +1 -0
- package/dist/src/observability/staleness.d.ts +43 -0
- package/dist/src/observability/staleness.d.ts.map +1 -0
- package/dist/src/observability/staleness.js +74 -0
- package/dist/src/observability/staleness.js.map +1 -0
- package/dist/src/observability/tool-usage-stats.d.ts +23 -0
- package/dist/src/observability/tool-usage-stats.d.ts.map +1 -0
- package/dist/src/observability/tool-usage-stats.js +83 -0
- package/dist/src/observability/tool-usage-stats.js.map +1 -0
- package/dist/src/observability/tool-usage.d.ts +68 -0
- package/dist/src/observability/tool-usage.d.ts.map +1 -0
- package/dist/src/observability/tool-usage.js +207 -0
- package/dist/src/observability/tool-usage.js.map +1 -0
- package/dist/src/onboarding/daemon-control.d.ts +33 -0
- package/dist/src/onboarding/daemon-control.d.ts.map +1 -0
- package/dist/src/onboarding/daemon-control.js +92 -0
- package/dist/src/onboarding/daemon-control.js.map +1 -0
- package/dist/src/onboarding/env-file.d.ts +18 -0
- package/dist/src/onboarding/env-file.d.ts.map +1 -0
- package/dist/src/onboarding/env-file.js +89 -0
- package/dist/src/onboarding/env-file.js.map +1 -0
- package/dist/src/onboarding/voyage-validate.d.ts +16 -0
- package/dist/src/onboarding/voyage-validate.d.ts.map +1 -0
- package/dist/src/onboarding/voyage-validate.js +85 -0
- package/dist/src/onboarding/voyage-validate.js.map +1 -0
- package/dist/src/providers/anthropic-digest.d.ts +23 -0
- package/dist/src/providers/anthropic-digest.d.ts.map +1 -0
- package/dist/src/providers/anthropic-digest.js +91 -0
- package/dist/src/providers/anthropic-digest.js.map +1 -0
- package/dist/src/providers/codex-cli-digest.d.ts +12 -0
- package/dist/src/providers/codex-cli-digest.d.ts.map +1 -0
- package/dist/src/providers/codex-cli-digest.js +70 -0
- package/dist/src/providers/codex-cli-digest.js.map +1 -0
- package/dist/src/providers/codex-cli-metadata-extraction.d.ts +14 -0
- package/dist/src/providers/codex-cli-metadata-extraction.d.ts.map +1 -0
- package/dist/src/providers/codex-cli-metadata-extraction.js +101 -0
- package/dist/src/providers/codex-cli-metadata-extraction.js.map +1 -0
- package/dist/src/providers/codex-cli-runner.d.ts +14 -0
- package/dist/src/providers/codex-cli-runner.d.ts.map +1 -0
- package/dist/src/providers/codex-cli-runner.js +272 -0
- package/dist/src/providers/codex-cli-runner.js.map +1 -0
- package/dist/src/providers/conversation-generation.d.ts +10 -0
- package/dist/src/providers/conversation-generation.d.ts.map +1 -0
- package/dist/src/providers/conversation-generation.js +54 -0
- package/dist/src/providers/conversation-generation.js.map +1 -0
- package/dist/src/providers/ollama-embed.d.ts +22 -0
- package/dist/src/providers/ollama-embed.d.ts.map +1 -0
- package/dist/src/providers/ollama-embed.js +133 -0
- package/dist/src/providers/ollama-embed.js.map +1 -0
- package/dist/src/providers/ollama.d.ts +42 -0
- package/dist/src/providers/ollama.d.ts.map +1 -0
- package/dist/src/providers/ollama.js +169 -0
- package/dist/src/providers/ollama.js.map +1 -0
- package/dist/src/providers/openai-metadata-extraction.d.ts +73 -0
- package/dist/src/providers/openai-metadata-extraction.d.ts.map +1 -0
- package/dist/src/providers/openai-metadata-extraction.js +161 -0
- package/dist/src/providers/openai-metadata-extraction.js.map +1 -0
- package/dist/src/providers/operator-overrides.d.ts +24 -0
- package/dist/src/providers/operator-overrides.d.ts.map +1 -0
- package/dist/src/providers/operator-overrides.js +84 -0
- package/dist/src/providers/operator-overrides.js.map +1 -0
- package/dist/src/providers/stub.d.ts +17 -0
- package/dist/src/providers/stub.d.ts.map +1 -0
- package/dist/src/providers/stub.js +72 -0
- package/dist/src/providers/stub.js.map +1 -0
- package/dist/src/providers/types.d.ts +82 -0
- package/dist/src/providers/types.d.ts.map +1 -0
- package/dist/src/providers/types.js +52 -0
- package/dist/src/providers/types.js.map +1 -0
- package/dist/src/providers/voyage.d.ts +23 -0
- package/dist/src/providers/voyage.d.ts.map +1 -0
- package/dist/src/providers/voyage.js +135 -0
- package/dist/src/providers/voyage.js.map +1 -0
- package/dist/src/retrieval/compact.d.ts +89 -0
- package/dist/src/retrieval/compact.d.ts.map +1 -0
- package/dist/src/retrieval/compact.js +348 -0
- package/dist/src/retrieval/compact.js.map +1 -0
- package/dist/src/retrieval/context-pack.d.ts +123 -0
- package/dist/src/retrieval/context-pack.d.ts.map +1 -0
- package/dist/src/retrieval/context-pack.js +553 -0
- package/dist/src/retrieval/context-pack.js.map +1 -0
- package/dist/src/retrieval/cwd.d.ts +25 -0
- package/dist/src/retrieval/cwd.d.ts.map +1 -0
- package/dist/src/retrieval/cwd.js +48 -0
- package/dist/src/retrieval/cwd.js.map +1 -0
- package/dist/src/retrieval/degraded.d.ts +20 -0
- package/dist/src/retrieval/degraded.d.ts.map +1 -0
- package/dist/src/retrieval/degraded.js +43 -0
- package/dist/src/retrieval/degraded.js.map +1 -0
- package/dist/src/retrieval/hybrid.d.ts +38 -0
- package/dist/src/retrieval/hybrid.d.ts.map +1 -0
- package/dist/src/retrieval/hybrid.js +82 -0
- package/dist/src/retrieval/hybrid.js.map +1 -0
- package/dist/src/retrieval/lexical.d.ts +28 -0
- package/dist/src/retrieval/lexical.d.ts.map +1 -0
- package/dist/src/retrieval/lexical.js +301 -0
- package/dist/src/retrieval/lexical.js.map +1 -0
- package/dist/src/retrieval/post-filter.d.ts +32 -0
- package/dist/src/retrieval/post-filter.d.ts.map +1 -0
- package/dist/src/retrieval/post-filter.js +57 -0
- package/dist/src/retrieval/post-filter.js.map +1 -0
- package/dist/src/retrieval/reranker.d.ts +72 -0
- package/dist/src/retrieval/reranker.d.ts.map +1 -0
- package/dist/src/retrieval/reranker.js +129 -0
- package/dist/src/retrieval/reranker.js.map +1 -0
- package/dist/src/retrieval/vector.d.ts +47 -0
- package/dist/src/retrieval/vector.d.ts.map +1 -0
- package/dist/src/retrieval/vector.js +112 -0
- package/dist/src/retrieval/vector.js.map +1 -0
- package/dist/src/runtime/legacy-migration.d.ts +27 -0
- package/dist/src/runtime/legacy-migration.d.ts.map +1 -0
- package/dist/src/runtime/legacy-migration.js +140 -0
- package/dist/src/runtime/legacy-migration.js.map +1 -0
- package/dist/src/runtime/legacy-name-guard.d.ts +35 -0
- package/dist/src/runtime/legacy-name-guard.d.ts.map +1 -0
- package/dist/src/runtime/legacy-name-guard.js +58 -0
- package/dist/src/runtime/legacy-name-guard.js.map +1 -0
- package/dist/src/runtime/rift-env.d.ts +14 -0
- package/dist/src/runtime/rift-env.d.ts.map +1 -0
- package/dist/src/runtime/rift-env.js +79 -0
- package/dist/src/runtime/rift-env.js.map +1 -0
- package/dist/src/runtime/watcher-startup.d.ts +2 -0
- package/dist/src/runtime/watcher-startup.d.ts.map +1 -0
- package/dist/src/runtime/watcher-startup.js +4 -0
- package/dist/src/runtime/watcher-startup.js.map +1 -0
- package/dist/src/security/archive.d.ts +23 -0
- package/dist/src/security/archive.d.ts.map +1 -0
- package/dist/src/security/archive.js +163 -0
- package/dist/src/security/archive.js.map +1 -0
- package/dist/src/security/paths.d.ts +21 -0
- package/dist/src/security/paths.d.ts.map +1 -0
- package/dist/src/security/paths.js +67 -0
- package/dist/src/security/paths.js.map +1 -0
- package/dist/src/server/app.d.ts +29 -0
- package/dist/src/server/app.d.ts.map +1 -0
- package/dist/src/server/app.js +226 -0
- package/dist/src/server/app.js.map +1 -0
- package/dist/src/server/build-info.d.ts +8 -0
- package/dist/src/server/build-info.d.ts.map +1 -0
- package/dist/src/server/build-info.js +61 -0
- package/dist/src/server/build-info.js.map +1 -0
- package/dist/src/server/lifecycle.d.ts +30 -0
- package/dist/src/server/lifecycle.d.ts.map +1 -0
- package/dist/src/server/lifecycle.js +59 -0
- package/dist/src/server/lifecycle.js.map +1 -0
- package/dist/src/server/middleware/multipart.d.ts +51 -0
- package/dist/src/server/middleware/multipart.d.ts.map +1 -0
- package/dist/src/server/middleware/multipart.js +86 -0
- package/dist/src/server/middleware/multipart.js.map +1 -0
- package/dist/src/server/routes/compact.d.ts +37 -0
- package/dist/src/server/routes/compact.d.ts.map +1 -0
- package/dist/src/server/routes/compact.js +77 -0
- package/dist/src/server/routes/compact.js.map +1 -0
- package/dist/src/server/routes/context.d.ts +5 -0
- package/dist/src/server/routes/context.d.ts.map +1 -0
- package/dist/src/server/routes/context.js +50 -0
- package/dist/src/server/routes/context.js.map +1 -0
- package/dist/src/server/routes/conversations-search.d.ts +4 -0
- package/dist/src/server/routes/conversations-search.d.ts.map +1 -0
- package/dist/src/server/routes/conversations-search.js +243 -0
- package/dist/src/server/routes/conversations-search.js.map +1 -0
- package/dist/src/server/routes/friend-status.d.ts +72 -0
- package/dist/src/server/routes/friend-status.d.ts.map +1 -0
- package/dist/src/server/routes/friend-status.js +71 -0
- package/dist/src/server/routes/friend-status.js.map +1 -0
- package/dist/src/server/routes/ingest.d.ts +15 -0
- package/dist/src/server/routes/ingest.d.ts.map +1 -0
- package/dist/src/server/routes/ingest.js +139 -0
- package/dist/src/server/routes/ingest.js.map +1 -0
- package/dist/src/server/routes/jobs.d.ts +10 -0
- package/dist/src/server/routes/jobs.d.ts.map +1 -0
- package/dist/src/server/routes/jobs.js +29 -0
- package/dist/src/server/routes/jobs.js.map +1 -0
- package/dist/src/server/routes/mcp-usage.d.ts +13 -0
- package/dist/src/server/routes/mcp-usage.d.ts.map +1 -0
- package/dist/src/server/routes/mcp-usage.js +17 -0
- package/dist/src/server/routes/mcp-usage.js.map +1 -0
- package/dist/src/server/routes/reconcile.d.ts +4 -0
- package/dist/src/server/routes/reconcile.d.ts.map +1 -0
- package/dist/src/server/routes/reconcile.js +43 -0
- package/dist/src/server/routes/reconcile.js.map +1 -0
- package/dist/src/server/routes/reindex.d.ts +4 -0
- package/dist/src/server/routes/reindex.d.ts.map +1 -0
- package/dist/src/server/routes/reindex.js +74 -0
- package/dist/src/server/routes/reindex.js.map +1 -0
- package/dist/src/server/routes/save.d.ts +40 -0
- package/dist/src/server/routes/save.d.ts.map +1 -0
- package/dist/src/server/routes/save.js +112 -0
- package/dist/src/server/routes/save.js.map +1 -0
- package/dist/src/server/routes/search.d.ts +5 -0
- package/dist/src/server/routes/search.d.ts.map +1 -0
- package/dist/src/server/routes/search.js +400 -0
- package/dist/src/server/routes/search.js.map +1 -0
- package/dist/src/server/routes/stats.d.ts +10 -0
- package/dist/src/server/routes/stats.d.ts.map +1 -0
- package/dist/src/server/routes/stats.js +15 -0
- package/dist/src/server/routes/stats.js.map +1 -0
- package/dist/src/server/routes/status.d.ts +20 -0
- package/dist/src/server/routes/status.d.ts.map +1 -0
- package/dist/src/server/routes/status.js +31 -0
- package/dist/src/server/routes/status.js.map +1 -0
- package/dist/src/server/routes/triage.d.ts +4 -0
- package/dist/src/server/routes/triage.d.ts.map +1 -0
- package/dist/src/server/routes/triage.js +94 -0
- package/dist/src/server/routes/triage.js.map +1 -0
- package/dist/src/server/save-quality.d.ts +21 -0
- package/dist/src/server/save-quality.d.ts.map +1 -0
- package/dist/src/server/save-quality.js +51 -0
- package/dist/src/server/save-quality.js.map +1 -0
- package/dist/src/storage/atomic.d.ts +8 -0
- package/dist/src/storage/atomic.d.ts.map +1 -0
- package/dist/src/storage/atomic.js +22 -0
- package/dist/src/storage/atomic.js.map +1 -0
- package/dist/src/storage/db.d.ts +15 -0
- package/dist/src/storage/db.d.ts.map +1 -0
- package/dist/src/storage/db.js +43 -0
- package/dist/src/storage/db.js.map +1 -0
- package/dist/src/storage/integrity.d.ts +11 -0
- package/dist/src/storage/integrity.d.ts.map +1 -0
- package/dist/src/storage/integrity.js +66 -0
- package/dist/src/storage/integrity.js.map +1 -0
- package/dist/src/storage/rebuild.d.ts +37 -0
- package/dist/src/storage/rebuild.d.ts.map +1 -0
- package/dist/src/storage/rebuild.js +353 -0
- package/dist/src/storage/rebuild.js.map +1 -0
- package/dist/src/storage/shadow-swap.d.ts +20 -0
- package/dist/src/storage/shadow-swap.d.ts.map +1 -0
- package/dist/src/storage/shadow-swap.js +163 -0
- package/dist/src/storage/shadow-swap.js.map +1 -0
- package/dist/src/storage/tables.d.ts +77 -0
- package/dist/src/storage/tables.d.ts.map +1 -0
- package/dist/src/storage/tables.js +196 -0
- package/dist/src/storage/tables.js.map +1 -0
- package/package.json +45 -14
- package/index.js +0 -3
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slice 3: ContextPack retrieval primitive.
|
|
3
|
+
*
|
|
4
|
+
* Builds a compact, bucketed view of prior context for an active task.
|
|
5
|
+
* Reuses hybrid search; never returns raw transcripts.
|
|
6
|
+
*
|
|
7
|
+
* Buckets:
|
|
8
|
+
* - decisions: strings pulled from matching conversations' `decisions` JSON
|
|
9
|
+
* - constraints: MUST/NEVER/DO-NOT style lines pulled from matching docs
|
|
10
|
+
* - examples: compact pointers to prior conversations (title+summary+expand)
|
|
11
|
+
* - rules: compact pointers to project docs (title+snippet+expand)
|
|
12
|
+
*
|
|
13
|
+
* Hard caps (locked contract):
|
|
14
|
+
* - each text item <= 200 chars
|
|
15
|
+
* - each snippet <= 200 chars
|
|
16
|
+
* - max_per_bucket default 3, ceiling 10
|
|
17
|
+
* - max_bytes default 4096, ceiling 16384
|
|
18
|
+
*
|
|
19
|
+
* Nothing here embeds or writes — pure assembly on top of hybridSearch
|
|
20
|
+
* plus direct row lookups for the decisions/constraints extraction.
|
|
21
|
+
*/
|
|
22
|
+
import type { EmbeddingProvider } from "../providers/types.js";
|
|
23
|
+
import type { SourceDir } from "../config/schema.js";
|
|
24
|
+
import { type RankedResult } from "./reranker.js";
|
|
25
|
+
export declare const ITEM_TEXT_MAX = 200;
|
|
26
|
+
export declare const SNIPPET_MAX = 200;
|
|
27
|
+
export declare const DEFAULT_MAX_PER_BUCKET = 3;
|
|
28
|
+
export declare const MAX_PER_BUCKET_CEILING = 10;
|
|
29
|
+
export declare const DEFAULT_MAX_BYTES = 4096;
|
|
30
|
+
export declare const MAX_BYTES_CEILING = 16384;
|
|
31
|
+
/** Request `task` is echoed in the response, so it counts against `max_bytes`. Capped to keep the envelope small. */
|
|
32
|
+
export declare const TASK_MAX = 1024;
|
|
33
|
+
/**
|
|
34
|
+
* Minimum `S_sim` for a ranked candidate to feed the `decisions` /
|
|
35
|
+
* `examples` buckets. Below this floor we prefer an empty bucket over
|
|
36
|
+
* confidently-worded unrelated content — Slice 5 validation showed
|
|
37
|
+
* that when the task has no real match in the corpus, decisions from
|
|
38
|
+
* the top-ranked-but-unrelated row still come back, and an agent has
|
|
39
|
+
* no way to tell they're noise.
|
|
40
|
+
*
|
|
41
|
+
* `S_sim` is cosine similarity in [0,1] for vector / hybrid results
|
|
42
|
+
* and max-normalized BM25 for lexical-only. The floor is deliberately
|
|
43
|
+
* low (0.3): genuine weak matches still pass, but rows that are
|
|
44
|
+
* essentially keyword-free or cosine-orthogonal drop out. Constraints
|
|
45
|
+
* and rules are already heavily filtered (marker matching + engine-
|
|
46
|
+
* owned-path exclusion), so we only apply the floor to the two
|
|
47
|
+
* "free-text content" buckets where noise is most costly.
|
|
48
|
+
*/
|
|
49
|
+
export declare const DECISIONS_RELEVANCE_FLOOR = 0.3;
|
|
50
|
+
export declare const EXAMPLES_RELEVANCE_FLOOR = 0.3;
|
|
51
|
+
export interface DecisionCard {
|
|
52
|
+
text: string;
|
|
53
|
+
source_id: string;
|
|
54
|
+
source: string;
|
|
55
|
+
timestamp?: string;
|
|
56
|
+
}
|
|
57
|
+
export interface ConstraintCard {
|
|
58
|
+
text: string;
|
|
59
|
+
source_id: string;
|
|
60
|
+
source_path?: string;
|
|
61
|
+
}
|
|
62
|
+
export interface ExampleCard {
|
|
63
|
+
id: string;
|
|
64
|
+
title: string;
|
|
65
|
+
source: string;
|
|
66
|
+
summary: string;
|
|
67
|
+
timestamp?: string;
|
|
68
|
+
expand: {
|
|
69
|
+
route: string;
|
|
70
|
+
params: Record<string, unknown>;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export interface RuleCard {
|
|
74
|
+
id: string;
|
|
75
|
+
title: string;
|
|
76
|
+
snippet: string;
|
|
77
|
+
source_path?: string;
|
|
78
|
+
expand: {
|
|
79
|
+
route: string;
|
|
80
|
+
params: Record<string, unknown>;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export interface ContextPack {
|
|
84
|
+
task: string;
|
|
85
|
+
decisions: DecisionCard[];
|
|
86
|
+
constraints: ConstraintCard[];
|
|
87
|
+
examples: ExampleCard[];
|
|
88
|
+
rules: RuleCard[];
|
|
89
|
+
total_bytes: number;
|
|
90
|
+
truncated: boolean;
|
|
91
|
+
degraded: boolean;
|
|
92
|
+
degraded_reason?: string;
|
|
93
|
+
}
|
|
94
|
+
export interface BuildContextPackOptions {
|
|
95
|
+
task: string;
|
|
96
|
+
embedding: EmbeddingProvider;
|
|
97
|
+
cwd?: string;
|
|
98
|
+
sources?: readonly SourceDir[];
|
|
99
|
+
since?: string;
|
|
100
|
+
maxPerBucket?: number;
|
|
101
|
+
maxBytes?: number;
|
|
102
|
+
}
|
|
103
|
+
export declare function buildContextPack(opts: BuildContextPackOptions): Promise<ContextPack>;
|
|
104
|
+
/**
|
|
105
|
+
* Drop candidates whose best available relevance signal falls below
|
|
106
|
+
* `floor`. Combines semantic similarity (`S_sim`) and normalized BM25
|
|
107
|
+
* via `max()` so a strong keyword match keeps a row that happens to
|
|
108
|
+
* score weakly on the embedding axis, and a strong semantic match
|
|
109
|
+
* keeps a row that happens to share no tokens. Both signals live in
|
|
110
|
+
* `[0,1]`. Exported so tests can exercise the floor directly with
|
|
111
|
+
* synthetic `RankedResult`s.
|
|
112
|
+
*/
|
|
113
|
+
export declare function filterByRelevance(ranked: RankedResult[], floor: number): RankedResult[];
|
|
114
|
+
export declare function extractConstraintLines(content: string): string[];
|
|
115
|
+
/**
|
|
116
|
+
* True when `source_path` points into a `data/raw/conversations/**` directory.
|
|
117
|
+
* Those are raw conversation JSON snapshots that sometimes get indexed as
|
|
118
|
+
* `structured_docs` because they live under a watched source path; they are
|
|
119
|
+
* not project rule documents and must not populate `rules` / `constraints`.
|
|
120
|
+
*/
|
|
121
|
+
export declare function isRawConversationPath(p: unknown): boolean;
|
|
122
|
+
export declare function shouldExcludeDocFromRules(p: unknown): boolean;
|
|
123
|
+
//# sourceMappingURL=context-pack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-pack.d.ts","sourceRoot":"","sources":["../../../src/retrieval/context-pack.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAU,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAM1D,eAAO,MAAM,aAAa,MAAM,CAAC;AACjC,eAAO,MAAM,WAAW,MAAM,CAAC;AAC/B,eAAO,MAAM,sBAAsB,IAAI,CAAC;AACxC,eAAO,MAAM,sBAAsB,KAAK,CAAC;AACzC,eAAO,MAAM,iBAAiB,OAAO,CAAC;AACtC,eAAO,MAAM,iBAAiB,QAAQ,CAAC;AACvC,qHAAqH;AACrH,eAAO,MAAM,QAAQ,OAAO,CAAC;AAE7B;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,yBAAyB,MAAM,CAAC;AAC7C,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAQ5C,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC;CAC5D;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC;CAC5D;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,WAAW,EAAE,cAAc,EAAE,CAAC;IAC9B,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,iBAAiB,CAAC;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAID,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,uBAAuB,GAC5B,OAAO,CAAC,WAAW,CAAC,CA0GtB;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,YAAY,EAAE,EACtB,KAAK,EAAE,MAAM,GACZ,YAAY,EAAE,CAIhB;AAoLD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAYhE;AA2OD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAEzD;AAwCD,wBAAgB,yBAAyB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAG7D"}
|
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
import { hybridSearch } from "./hybrid.js";
|
|
2
|
+
import { rerank } from "./reranker.js";
|
|
3
|
+
import { getTable } from "../storage/tables.js";
|
|
4
|
+
import { resolveCwdRoot } from "./cwd.js";
|
|
5
|
+
// --- Locked caps ---
|
|
6
|
+
export const ITEM_TEXT_MAX = 200;
|
|
7
|
+
export const SNIPPET_MAX = 200;
|
|
8
|
+
export const DEFAULT_MAX_PER_BUCKET = 3;
|
|
9
|
+
export const MAX_PER_BUCKET_CEILING = 10;
|
|
10
|
+
export const DEFAULT_MAX_BYTES = 4096;
|
|
11
|
+
export const MAX_BYTES_CEILING = 16384;
|
|
12
|
+
/** Request `task` is echoed in the response, so it counts against `max_bytes`. Capped to keep the envelope small. */
|
|
13
|
+
export const TASK_MAX = 1024;
|
|
14
|
+
/**
|
|
15
|
+
* Minimum `S_sim` for a ranked candidate to feed the `decisions` /
|
|
16
|
+
* `examples` buckets. Below this floor we prefer an empty bucket over
|
|
17
|
+
* confidently-worded unrelated content — Slice 5 validation showed
|
|
18
|
+
* that when the task has no real match in the corpus, decisions from
|
|
19
|
+
* the top-ranked-but-unrelated row still come back, and an agent has
|
|
20
|
+
* no way to tell they're noise.
|
|
21
|
+
*
|
|
22
|
+
* `S_sim` is cosine similarity in [0,1] for vector / hybrid results
|
|
23
|
+
* and max-normalized BM25 for lexical-only. The floor is deliberately
|
|
24
|
+
* low (0.3): genuine weak matches still pass, but rows that are
|
|
25
|
+
* essentially keyword-free or cosine-orthogonal drop out. Constraints
|
|
26
|
+
* and rules are already heavily filtered (marker matching + engine-
|
|
27
|
+
* owned-path exclusion), so we only apply the floor to the two
|
|
28
|
+
* "free-text content" buckets where noise is most costly.
|
|
29
|
+
*/
|
|
30
|
+
export const DECISIONS_RELEVANCE_FLOOR = 0.3;
|
|
31
|
+
export const EXAMPLES_RELEVANCE_FLOOR = 0.3;
|
|
32
|
+
// Fetch more candidates than we keep so we have headroom to extract
|
|
33
|
+
// decisions/constraints from multiple sources and dedupe downstream.
|
|
34
|
+
const CANDIDATE_FETCH_MULTIPLIER = 4;
|
|
35
|
+
// --- Public entry ---
|
|
36
|
+
export async function buildContextPack(opts) {
|
|
37
|
+
const maxPerBucket = clamp(opts.maxPerBucket ?? DEFAULT_MAX_PER_BUCKET, 1, MAX_PER_BUCKET_CEILING);
|
|
38
|
+
const maxBytes = clamp(opts.maxBytes ?? DEFAULT_MAX_BYTES, 512, MAX_BYTES_CEILING);
|
|
39
|
+
const cwdMatch = opts.cwd && opts.sources ? resolveCwdRoot(opts.cwd, opts.sources) : null;
|
|
40
|
+
const sourcePathPrefix = cwdMatch?.rootPath;
|
|
41
|
+
// Fetch candidates in two scopes in parallel: conversations and documents.
|
|
42
|
+
// These feed different buckets, so running them separately lets each bucket
|
|
43
|
+
// draw on its own candidate pool without one starving the other.
|
|
44
|
+
//
|
|
45
|
+
// The docs fetch uses scope="all" and filters to doc tables afterwards,
|
|
46
|
+
// because scope="documents" would also require `source_scope='document'`
|
|
47
|
+
// — excluding project-scoped files like CLAUDE.md / AGENTS.md / PRD.md
|
|
48
|
+
// that are the whole point of the `rules` bucket.
|
|
49
|
+
const fetchK = maxPerBucket * CANDIDATE_FETCH_MULTIPLIER;
|
|
50
|
+
const [convRes, docRes] = await Promise.all([
|
|
51
|
+
hybridSearch(opts.task, opts.embedding, {
|
|
52
|
+
scope: "conversations",
|
|
53
|
+
top_k: fetchK,
|
|
54
|
+
...(opts.since ? { since: opts.since } : {}),
|
|
55
|
+
}),
|
|
56
|
+
hybridSearch(opts.task, opts.embedding, {
|
|
57
|
+
scope: "all",
|
|
58
|
+
top_k: fetchK,
|
|
59
|
+
...(opts.since ? { since: opts.since } : {}),
|
|
60
|
+
...(sourcePathPrefix ? { sourcePathPrefix } : {}),
|
|
61
|
+
}),
|
|
62
|
+
]);
|
|
63
|
+
const degraded = convRes.degraded || docRes.degraded;
|
|
64
|
+
const degradedReason = convRes.degraded_reason ?? docRes.degraded_reason;
|
|
65
|
+
const convRanked = rerank(toRerankInput(convRes.candidates)).slice(0, fetchK);
|
|
66
|
+
const docRanked = rerank(toRerankInput(docRes.candidates.filter((c) => c.source_table === "structured_docs" ||
|
|
67
|
+
c.source_table === "structured_docs_local"))).slice(0, fetchK);
|
|
68
|
+
// Fetch raw rows for the top ranked results so we can pull `decisions`,
|
|
69
|
+
// `content`, `metadata.title`, `source_path`, etc.
|
|
70
|
+
const [convRows, docRows] = await Promise.all([
|
|
71
|
+
fetchRowsById(convRanked),
|
|
72
|
+
fetchRowsById(docRanked),
|
|
73
|
+
]);
|
|
74
|
+
// Drop any doc candidates whose source_path points into engine-internal or
|
|
75
|
+
// build-artifact directories. These rows are not project rules — they are
|
|
76
|
+
// raw conversation snapshots, embedding cache files, quarantine drops,
|
|
77
|
+
// compiled JS/TS, node_modules, worktree copies, etc. — and they crowd
|
|
78
|
+
// real project-rule files (CLAUDE.md / AGENTS.md / PROJECT_STATE.md /
|
|
79
|
+
// TODO.md) out of the `rules` and `constraints` buckets. Conversation
|
|
80
|
+
// content is still reachable via `convRanked`.
|
|
81
|
+
const docRankedClean = docRanked.filter((r) => !shouldExcludeDocFromRules(docRows.get(r.id)?.["source_path"]));
|
|
82
|
+
const decisions = extractDecisions(filterByRelevance(convRanked, DECISIONS_RELEVANCE_FLOOR), convRows, maxPerBucket);
|
|
83
|
+
const examples = buildExamples(filterByRelevance(convRanked, EXAMPLES_RELEVANCE_FLOOR), convRows, maxPerBucket);
|
|
84
|
+
const rules = buildRules(docRankedClean, docRows, maxPerBucket);
|
|
85
|
+
const constraints = extractConstraints(docRankedClean, docRows, maxPerBucket);
|
|
86
|
+
const assembled = enforceBudget({ decisions, constraints, examples, rules }, {
|
|
87
|
+
maxBytes,
|
|
88
|
+
task: opts.task,
|
|
89
|
+
degraded,
|
|
90
|
+
...(degradedReason ? { degradedReason } : {}),
|
|
91
|
+
});
|
|
92
|
+
const pack = {
|
|
93
|
+
task: opts.task,
|
|
94
|
+
decisions: assembled.decisions,
|
|
95
|
+
constraints: assembled.constraints,
|
|
96
|
+
examples: assembled.examples,
|
|
97
|
+
rules: assembled.rules,
|
|
98
|
+
total_bytes: assembled.totalBytes,
|
|
99
|
+
truncated: assembled.truncated,
|
|
100
|
+
degraded,
|
|
101
|
+
};
|
|
102
|
+
if (degradedReason)
|
|
103
|
+
pack.degraded_reason = degradedReason;
|
|
104
|
+
return pack;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Drop candidates whose best available relevance signal falls below
|
|
108
|
+
* `floor`. Combines semantic similarity (`S_sim`) and normalized BM25
|
|
109
|
+
* via `max()` so a strong keyword match keeps a row that happens to
|
|
110
|
+
* score weakly on the embedding axis, and a strong semantic match
|
|
111
|
+
* keeps a row that happens to share no tokens. Both signals live in
|
|
112
|
+
* `[0,1]`. Exported so tests can exercise the floor directly with
|
|
113
|
+
* synthetic `RankedResult`s.
|
|
114
|
+
*/
|
|
115
|
+
export function filterByRelevance(ranked, floor) {
|
|
116
|
+
return ranked.filter((r) => Math.max(r.factors.S_sim, r.bm25_normalized) >= floor);
|
|
117
|
+
}
|
|
118
|
+
// --- Bucket builders ---
|
|
119
|
+
function extractDecisions(ranked, rows, cap) {
|
|
120
|
+
const out = [];
|
|
121
|
+
const seen = new Set();
|
|
122
|
+
for (const r of ranked) {
|
|
123
|
+
if (out.length >= cap)
|
|
124
|
+
break;
|
|
125
|
+
const row = rows.get(r.id);
|
|
126
|
+
if (!row)
|
|
127
|
+
continue;
|
|
128
|
+
const raw = row["decisions"];
|
|
129
|
+
const list = parseJsonStringArray(raw);
|
|
130
|
+
if (list.length === 0)
|
|
131
|
+
continue;
|
|
132
|
+
const timestamp = row["indexed_at"] || undefined;
|
|
133
|
+
const source = row["source"] || "conversation";
|
|
134
|
+
for (const d of list) {
|
|
135
|
+
if (out.length >= cap)
|
|
136
|
+
break;
|
|
137
|
+
const text = truncate(collapseWhitespace(d), ITEM_TEXT_MAX);
|
|
138
|
+
if (!text)
|
|
139
|
+
continue;
|
|
140
|
+
const key = text.toLowerCase();
|
|
141
|
+
if (seen.has(key))
|
|
142
|
+
continue;
|
|
143
|
+
seen.add(key);
|
|
144
|
+
const card = { text, source_id: r.id, source };
|
|
145
|
+
if (timestamp)
|
|
146
|
+
card.timestamp = timestamp;
|
|
147
|
+
out.push(card);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
function buildExamples(ranked, rows, cap) {
|
|
153
|
+
const out = [];
|
|
154
|
+
for (const r of ranked) {
|
|
155
|
+
if (out.length >= cap)
|
|
156
|
+
break;
|
|
157
|
+
const row = rows.get(r.id);
|
|
158
|
+
const summary = truncate(collapseWhitespace(row?.["summary"] || row?.["content"] || r.content), SNIPPET_MAX);
|
|
159
|
+
if (!summary)
|
|
160
|
+
continue;
|
|
161
|
+
const title = deriveExampleTitle(row, summary);
|
|
162
|
+
const source = row?.["source"] || "conversation";
|
|
163
|
+
const timestamp = row?.["indexed_at"] || undefined;
|
|
164
|
+
const card = {
|
|
165
|
+
id: r.id,
|
|
166
|
+
title,
|
|
167
|
+
source,
|
|
168
|
+
summary,
|
|
169
|
+
expand: {
|
|
170
|
+
route: "/search",
|
|
171
|
+
params: {
|
|
172
|
+
id: r.id,
|
|
173
|
+
tier: r.source_table === "conversations_cold" ? "cold" : "hot",
|
|
174
|
+
source_table: r.source_table,
|
|
175
|
+
detail: "full",
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
if (timestamp)
|
|
180
|
+
card.timestamp = timestamp;
|
|
181
|
+
out.push(card);
|
|
182
|
+
}
|
|
183
|
+
return out;
|
|
184
|
+
}
|
|
185
|
+
function buildRules(ranked, rows, cap) {
|
|
186
|
+
const out = [];
|
|
187
|
+
for (const r of ranked) {
|
|
188
|
+
if (out.length >= cap)
|
|
189
|
+
break;
|
|
190
|
+
const row = rows.get(r.id);
|
|
191
|
+
const content = row?.["content"] || r.content;
|
|
192
|
+
const snippet = truncate(collapseWhitespace(content), SNIPPET_MAX);
|
|
193
|
+
if (!snippet)
|
|
194
|
+
continue;
|
|
195
|
+
const sourcePath = row?.["source_path"] || "";
|
|
196
|
+
const title = deriveRuleTitle(row, sourcePath, snippet);
|
|
197
|
+
const card = {
|
|
198
|
+
id: r.id,
|
|
199
|
+
title,
|
|
200
|
+
snippet,
|
|
201
|
+
expand: {
|
|
202
|
+
route: "/search",
|
|
203
|
+
params: {
|
|
204
|
+
id: r.id,
|
|
205
|
+
tier: "structured_doc",
|
|
206
|
+
source_table: r.source_table,
|
|
207
|
+
detail: "full",
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
if (sourcePath)
|
|
212
|
+
card.source_path = sourcePath;
|
|
213
|
+
out.push(card);
|
|
214
|
+
}
|
|
215
|
+
return out;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Pull constraint-shaped lines out of the matching rule documents. Looks
|
|
219
|
+
* for classic imperative markers (MUST/MUST NOT/NEVER/DO NOT/ALWAYS/AVOID)
|
|
220
|
+
* which are the idiom for CLAUDE.md / AGENTS.md / PRD-style project rules.
|
|
221
|
+
* Falls back silently if none found — constraints is the bucket most
|
|
222
|
+
* likely to be empty, by design.
|
|
223
|
+
*/
|
|
224
|
+
function extractConstraints(ranked, rows, cap) {
|
|
225
|
+
const out = [];
|
|
226
|
+
const seen = new Set();
|
|
227
|
+
for (const r of ranked) {
|
|
228
|
+
if (out.length >= cap)
|
|
229
|
+
break;
|
|
230
|
+
const row = rows.get(r.id);
|
|
231
|
+
const content = row?.["content"] || r.content;
|
|
232
|
+
if (!content)
|
|
233
|
+
continue;
|
|
234
|
+
const lines = extractConstraintLines(content);
|
|
235
|
+
if (lines.length === 0)
|
|
236
|
+
continue;
|
|
237
|
+
const sourcePath = row?.["source_path"] || undefined;
|
|
238
|
+
for (const line of lines) {
|
|
239
|
+
if (out.length >= cap)
|
|
240
|
+
break;
|
|
241
|
+
const text = truncate(line, ITEM_TEXT_MAX);
|
|
242
|
+
const key = text.toLowerCase();
|
|
243
|
+
if (seen.has(key))
|
|
244
|
+
continue;
|
|
245
|
+
seen.add(key);
|
|
246
|
+
const card = { text, source_id: r.id };
|
|
247
|
+
if (sourcePath)
|
|
248
|
+
card.source_path = sourcePath;
|
|
249
|
+
out.push(card);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return out;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* The idiom we are matching is project-law: "MUST run pnpm check",
|
|
256
|
+
* "NEVER commit secrets", "Do not modify files outside this repo".
|
|
257
|
+
* Real constraints put the imperative word at the start of the line.
|
|
258
|
+
* Mid-line occurrences are almost always narrative prose, JSON values,
|
|
259
|
+
* or quoted excerpts — we'd rather drop those than admit them.
|
|
260
|
+
*/
|
|
261
|
+
const MARKER_AT_START = /^(?:MUST(?:\s+NOT)?|NEVER|DO\s+NOT|DON'T|ALWAYS|AVOID|REQUIRED|FORBIDDEN)\b/i;
|
|
262
|
+
/** Bullet or numbered list prefix, stripped before checking for the marker. */
|
|
263
|
+
const LIST_PREFIX = /^\s*(?:[-*+]|\d+[.)]|\(\d+\))\s+/;
|
|
264
|
+
/** Leading markdown emphasis (`**`, `__`), stripped before checking. */
|
|
265
|
+
const EMPHASIS_PREFIX = /^(?:\*+|_+)\s*/;
|
|
266
|
+
/**
|
|
267
|
+
* Reject lines that look like a JSON/YAML fragment, a quoted transcript
|
|
268
|
+
* snippet, or other structured-data debris. These are the classic
|
|
269
|
+
* false-positive shapes from Slice 5 validation: raw conversation JSON
|
|
270
|
+
* and excerpt blobs that happen to contain marker words inside quoted
|
|
271
|
+
* values get pulled into the `constraints` bucket as if they were
|
|
272
|
+
* project law.
|
|
273
|
+
*/
|
|
274
|
+
function looksLikeStructuredFragment(line) {
|
|
275
|
+
// JSON key-value: `"content": "..."`, `"excerpt": "..."`, etc.
|
|
276
|
+
if (/^"[^"]+"\s*:/.test(line))
|
|
277
|
+
return true;
|
|
278
|
+
// JSON structural punctuation anywhere — a real constraint line would
|
|
279
|
+
// not contain `{` or `}`.
|
|
280
|
+
if (/[{}]/.test(line))
|
|
281
|
+
return true;
|
|
282
|
+
// Line opens with a quote or backtick → quoted transcript/code snippet.
|
|
283
|
+
if (/^["'`]/.test(line))
|
|
284
|
+
return true;
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
export function extractConstraintLines(content) {
|
|
288
|
+
const out = [];
|
|
289
|
+
for (const raw of content.split(/\r?\n/)) {
|
|
290
|
+
const trimmed = raw.trim();
|
|
291
|
+
if (!trimmed)
|
|
292
|
+
continue;
|
|
293
|
+
if (looksLikeStructuredFragment(trimmed))
|
|
294
|
+
continue;
|
|
295
|
+
const body = trimmed.replace(LIST_PREFIX, "").replace(EMPHASIS_PREFIX, "");
|
|
296
|
+
if (!MARKER_AT_START.test(body))
|
|
297
|
+
continue;
|
|
298
|
+
const cleaned = collapseWhitespace(body.replace(/[.?!]+\s*$/, ""));
|
|
299
|
+
out.push(cleaned);
|
|
300
|
+
}
|
|
301
|
+
return out;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Greedy round-robin fill: start with empty buckets, pull one item at a
|
|
305
|
+
* time from each input bucket in a fixed order, add only if it fits in
|
|
306
|
+
* the remaining budget. Guarantees each bucket gets a fair shot even
|
|
307
|
+
* when one bucket's items would otherwise crowd the budget.
|
|
308
|
+
*
|
|
309
|
+
* `totalBytes` is seeded from the serialized response envelope (task +
|
|
310
|
+
* degraded flags + empty-bucket overhead) so the returned value reflects
|
|
311
|
+
* the whole payload, not just bucket contents — `max_bytes` is a contract
|
|
312
|
+
* on response size.
|
|
313
|
+
*/
|
|
314
|
+
function enforceBudget(input, ctx) {
|
|
315
|
+
const { maxBytes } = ctx;
|
|
316
|
+
const order = [
|
|
317
|
+
"decisions",
|
|
318
|
+
"constraints",
|
|
319
|
+
"rules",
|
|
320
|
+
"examples",
|
|
321
|
+
];
|
|
322
|
+
const queues = {
|
|
323
|
+
decisions: [...input.decisions],
|
|
324
|
+
constraints: [...input.constraints],
|
|
325
|
+
examples: [...input.examples],
|
|
326
|
+
rules: [...input.rules],
|
|
327
|
+
};
|
|
328
|
+
const output = {
|
|
329
|
+
decisions: [],
|
|
330
|
+
constraints: [],
|
|
331
|
+
examples: [],
|
|
332
|
+
rules: [],
|
|
333
|
+
};
|
|
334
|
+
let totalBytes = envelopeBytes(output, ctx);
|
|
335
|
+
let truncated = false;
|
|
336
|
+
let progressed = true;
|
|
337
|
+
while (progressed) {
|
|
338
|
+
progressed = false;
|
|
339
|
+
for (const key of order) {
|
|
340
|
+
const q = queues[key];
|
|
341
|
+
if (q.length === 0)
|
|
342
|
+
continue;
|
|
343
|
+
const item = q[0];
|
|
344
|
+
const addedBytes = itemBytes(item);
|
|
345
|
+
if (totalBytes + addedBytes > maxBytes) {
|
|
346
|
+
truncated = true;
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
q.shift();
|
|
350
|
+
output[key].push(item);
|
|
351
|
+
totalBytes += addedBytes;
|
|
352
|
+
progressed = true;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
// Any items still sitting in the queues were dropped for budget.
|
|
356
|
+
for (const key of order) {
|
|
357
|
+
if (queues[key].length > 0) {
|
|
358
|
+
truncated = true;
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return {
|
|
363
|
+
decisions: output.decisions,
|
|
364
|
+
constraints: output.constraints,
|
|
365
|
+
examples: output.examples,
|
|
366
|
+
rules: output.rules,
|
|
367
|
+
totalBytes,
|
|
368
|
+
truncated,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
function envelopeBytes(buckets, ctx) {
|
|
372
|
+
// Full serialized response envelope, including echoed `task`, `degraded`
|
|
373
|
+
// flags, and a worst-case integer placeholder for `total_bytes`. Used as
|
|
374
|
+
// the starting-point byte count so `max_bytes` bounds the whole payload,
|
|
375
|
+
// not just the bucket contents.
|
|
376
|
+
const envelope = {
|
|
377
|
+
task: ctx.task,
|
|
378
|
+
decisions: buckets.decisions,
|
|
379
|
+
constraints: buckets.constraints,
|
|
380
|
+
examples: buckets.examples,
|
|
381
|
+
rules: buckets.rules,
|
|
382
|
+
total_bytes: ctx.maxBytes,
|
|
383
|
+
truncated: true,
|
|
384
|
+
degraded: ctx.degraded,
|
|
385
|
+
};
|
|
386
|
+
if (ctx.degradedReason)
|
|
387
|
+
envelope["degraded_reason"] = ctx.degradedReason;
|
|
388
|
+
return Buffer.byteLength(JSON.stringify(envelope), "utf-8");
|
|
389
|
+
}
|
|
390
|
+
function itemBytes(item) {
|
|
391
|
+
return Buffer.byteLength(JSON.stringify(item), "utf-8") + 1; // +1 for comma
|
|
392
|
+
}
|
|
393
|
+
// --- Utilities ---
|
|
394
|
+
function toRerankInput(cands) {
|
|
395
|
+
return cands.map((c) => {
|
|
396
|
+
const entry = {
|
|
397
|
+
id: c.id,
|
|
398
|
+
content: c.content,
|
|
399
|
+
raw_sim: c.raw_sim,
|
|
400
|
+
raw_bm25: c.raw_bm25,
|
|
401
|
+
source_table: c.source_table,
|
|
402
|
+
retrieval_method: c.retrieval_method,
|
|
403
|
+
};
|
|
404
|
+
if (c.indexed_at)
|
|
405
|
+
entry.indexed_at = c.indexed_at;
|
|
406
|
+
if (c.quality)
|
|
407
|
+
entry.quality = c.quality;
|
|
408
|
+
return entry;
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
async function fetchRowsById(ranked) {
|
|
412
|
+
const byTable = new Map();
|
|
413
|
+
for (const r of ranked) {
|
|
414
|
+
const arr = byTable.get(r.source_table) ?? [];
|
|
415
|
+
arr.push(r.id);
|
|
416
|
+
byTable.set(r.source_table, arr);
|
|
417
|
+
}
|
|
418
|
+
const out = new Map();
|
|
419
|
+
for (const [tableName, ids] of byTable) {
|
|
420
|
+
if (ids.length === 0)
|
|
421
|
+
continue;
|
|
422
|
+
const quoted = ids.map((i) => `'${i.replace(/'/g, "''")}'`).join(",");
|
|
423
|
+
const rows = (await getTable(tableName)
|
|
424
|
+
.query()
|
|
425
|
+
.where(`id IN (${quoted})`)
|
|
426
|
+
.limit(ids.length)
|
|
427
|
+
.toArray());
|
|
428
|
+
for (const row of rows) {
|
|
429
|
+
out.set(row["id"], row);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
return out;
|
|
433
|
+
}
|
|
434
|
+
function parseJsonStringArray(raw) {
|
|
435
|
+
if (typeof raw !== "string" || !raw)
|
|
436
|
+
return [];
|
|
437
|
+
try {
|
|
438
|
+
const parsed = JSON.parse(raw);
|
|
439
|
+
if (!Array.isArray(parsed))
|
|
440
|
+
return [];
|
|
441
|
+
return parsed.filter((x) => typeof x === "string" && !!x.trim());
|
|
442
|
+
}
|
|
443
|
+
catch {
|
|
444
|
+
return [];
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
function deriveExampleTitle(row, summary) {
|
|
448
|
+
const topics = parseJsonStringArray(row?.["topics"]);
|
|
449
|
+
if (topics.length > 0)
|
|
450
|
+
return truncate(topics.slice(0, 3).join(", "), 120);
|
|
451
|
+
return truncate(firstLine(summary) || "(conversation)", 120);
|
|
452
|
+
}
|
|
453
|
+
function deriveRuleTitle(row, sourcePath, snippet) {
|
|
454
|
+
const metaTitle = readMetadataTitle(row);
|
|
455
|
+
if (metaTitle)
|
|
456
|
+
return truncate(metaTitle, 120);
|
|
457
|
+
if (sourcePath) {
|
|
458
|
+
const base = sourcePath.split("/").filter(Boolean).pop();
|
|
459
|
+
if (base)
|
|
460
|
+
return truncate(base, 120);
|
|
461
|
+
}
|
|
462
|
+
return truncate(firstLine(snippet) || "(document)", 120);
|
|
463
|
+
}
|
|
464
|
+
function readMetadataTitle(row) {
|
|
465
|
+
const meta = row?.["metadata"];
|
|
466
|
+
if (typeof meta !== "string" || !meta)
|
|
467
|
+
return null;
|
|
468
|
+
try {
|
|
469
|
+
const parsed = JSON.parse(meta);
|
|
470
|
+
const t = parsed["title"];
|
|
471
|
+
if (typeof t === "string" && t.trim())
|
|
472
|
+
return t.trim();
|
|
473
|
+
}
|
|
474
|
+
catch {
|
|
475
|
+
// ignore
|
|
476
|
+
}
|
|
477
|
+
return null;
|
|
478
|
+
}
|
|
479
|
+
function firstLine(text) {
|
|
480
|
+
for (const line of text.split(/\r?\n/)) {
|
|
481
|
+
const t = line.trim();
|
|
482
|
+
if (t)
|
|
483
|
+
return t.replace(/^#+\s*/, "").replace(/^[-*]\s+/, "");
|
|
484
|
+
}
|
|
485
|
+
return "";
|
|
486
|
+
}
|
|
487
|
+
function truncate(text, max) {
|
|
488
|
+
if (text.length <= max)
|
|
489
|
+
return text;
|
|
490
|
+
return text.slice(0, max);
|
|
491
|
+
}
|
|
492
|
+
function collapseWhitespace(text) {
|
|
493
|
+
return text.replace(/\s+/g, " ").trim();
|
|
494
|
+
}
|
|
495
|
+
function clamp(n, lo, hi) {
|
|
496
|
+
if (n < lo)
|
|
497
|
+
return lo;
|
|
498
|
+
if (n > hi)
|
|
499
|
+
return hi;
|
|
500
|
+
return n;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* True when `source_path` points into a `data/raw/conversations/**` directory.
|
|
504
|
+
* Those are raw conversation JSON snapshots that sometimes get indexed as
|
|
505
|
+
* `structured_docs` because they live under a watched source path; they are
|
|
506
|
+
* not project rule documents and must not populate `rules` / `constraints`.
|
|
507
|
+
*/
|
|
508
|
+
export function isRawConversationPath(p) {
|
|
509
|
+
return typeof p === "string" && /\/data\/raw\/conversations\//.test(p);
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Paths that should never populate the `rules` / `constraints` buckets.
|
|
513
|
+
* Explicitly enumerate engine-owned subdirectories under `data/` rather
|
|
514
|
+
* than matching `data/` wholesale, so user-facing locations the daemon
|
|
515
|
+
* legitimately watches (notably `data/imports/`) remain eligible:
|
|
516
|
+
* - `/data/raw/` — raw conversation snapshots
|
|
517
|
+
* - `/data/embeddings/` — cloud embedding cache
|
|
518
|
+
* - `/data/embeddings-local/` — local embedding cache
|
|
519
|
+
* - `/data/quarantine/` — failed ingest drops
|
|
520
|
+
* - `/data/review-queue/` — review-pipeline state
|
|
521
|
+
* - `/data/inbox/` — pre-ingest staging
|
|
522
|
+
* - `/data/observability/` — metrics / logs
|
|
523
|
+
* - `/data/triage-results/` — batch triage output
|
|
524
|
+
* - `/data/lancedb/` — the vector store itself
|
|
525
|
+
* - `/dist/` — compiled JS/TS build artifacts
|
|
526
|
+
* - `/node_modules/` — third-party dependencies
|
|
527
|
+
* - `/.git/` — git internals
|
|
528
|
+
* - `/.codex-worktrees/` — ephemeral worktrees created by codex runs
|
|
529
|
+
* Rule-bearing human-authored files under `src/`, `docs/`, `reports/`,
|
|
530
|
+
* `data/imports/`, or at the project root (CLAUDE.md, AGENTS.md,
|
|
531
|
+
* PROJECT_STATE.md, TODO.md, …) are untouched.
|
|
532
|
+
*/
|
|
533
|
+
const EXCLUDED_RULE_PATH_PATTERNS = [
|
|
534
|
+
/\/data\/raw\//,
|
|
535
|
+
/\/data\/embeddings\//,
|
|
536
|
+
/\/data\/embeddings-local\//,
|
|
537
|
+
/\/data\/quarantine\//,
|
|
538
|
+
/\/data\/review-queue\//,
|
|
539
|
+
/\/data\/inbox\//,
|
|
540
|
+
/\/data\/observability\//,
|
|
541
|
+
/\/data\/triage-results\//,
|
|
542
|
+
/\/data\/lancedb\//,
|
|
543
|
+
/\/dist\//,
|
|
544
|
+
/\/node_modules\//,
|
|
545
|
+
/\/\.git\//,
|
|
546
|
+
/\/\.codex-worktrees\//,
|
|
547
|
+
];
|
|
548
|
+
export function shouldExcludeDocFromRules(p) {
|
|
549
|
+
if (typeof p !== "string")
|
|
550
|
+
return false;
|
|
551
|
+
return EXCLUDED_RULE_PATH_PATTERNS.some((rx) => rx.test(p));
|
|
552
|
+
}
|
|
553
|
+
//# sourceMappingURL=context-pack.js.map
|