@lsctech/polaris 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -0
- package/dist/__mocks__/tool-server-linear.js +34 -0
- package/dist/cli/adopt-approve.js +60 -0
- package/dist/cli/adopt-cognition.js +199 -0
- package/dist/cli/adopt-instructions.js +143 -0
- package/dist/cli/adopt-rules.js +169 -0
- package/dist/cli/adopt-scan.js +25 -0
- package/dist/cli/adopt-smartdocs.js +192 -0
- package/dist/cli/adoption-inventory.js +350 -0
- package/dist/cli/adoption-plan.js +222 -0
- package/dist/cli/args.js +28 -0
- package/dist/cli/args.test.js +30 -0
- package/dist/cli/branding.js +41 -0
- package/dist/cli/graph.js +358 -0
- package/dist/cli/index.js +127 -0
- package/dist/cli/index.test.js +162 -0
- package/dist/cli/init-detect.js +61 -0
- package/dist/cli/init.js +492 -0
- package/dist/cli/init.test.js +259 -0
- package/dist/cli/librarian.js +32 -0
- package/dist/cli/medic.js +96 -0
- package/dist/cli/startup.test.js +23 -0
- package/dist/cli/tracker.js +130 -0
- package/dist/cli/tracker.test.js +126 -0
- package/dist/cli/version.js +10 -0
- package/dist/cli/version.test.js +11 -0
- package/dist/cli/worker.js +287 -0
- package/dist/cluster-state/fixtures/test-clusters.json +19 -0
- package/dist/cluster-state/store.js +302 -0
- package/dist/cluster-state/store.test.js +145 -0
- package/dist/cluster-state/types.js +2 -0
- package/dist/cognition/archive.js +158 -0
- package/dist/cognition/closeout-librarian-types.js +161 -0
- package/dist/cognition/cognition.test.js +623 -0
- package/dist/cognition/index.js +41 -0
- package/dist/cognition/librarian-dispatch.js +391 -0
- package/dist/cognition/librarian-dispatch.test.js +247 -0
- package/dist/cognition/librarian-packet.js +313 -0
- package/dist/cognition/librarian-types.js +57 -0
- package/dist/cognition/route-cognition-delta.js +350 -0
- package/dist/cognition/summary-delta.js +279 -0
- package/dist/cognition/validate.js +162 -0
- package/dist/config/defaults.js +98 -0
- package/dist/config/doctor.js +273 -0
- package/dist/config/index.js +14 -0
- package/dist/config/loader.js +58 -0
- package/dist/config/provider-detect.js +60 -0
- package/dist/config/provider-detect.test.js +119 -0
- package/dist/config/schema.js +2 -0
- package/dist/config/show.js +44 -0
- package/dist/config/show.test.js +42 -0
- package/dist/config/validator.js +675 -0
- package/dist/config/validator.test.js +77 -0
- package/dist/docs/canon-check.js +334 -0
- package/dist/docs/canon-check.test.js +207 -0
- package/dist/docs/doctrine.js +133 -0
- package/dist/docs/doctrine.test.js +139 -0
- package/dist/docs/index.js +168 -0
- package/dist/docs/index.test.js +83 -0
- package/dist/docs/ingest.js +295 -0
- package/dist/docs/ingest.test.js +71 -0
- package/dist/docs/migrate.js +165 -0
- package/dist/docs/migrate.test.js +136 -0
- package/dist/docs/seed-instructions.js +147 -0
- package/dist/docs/seed-instructions.test.js +137 -0
- package/dist/docs/validate-instructions.js +267 -0
- package/dist/docs/validate-instructions.test.js +238 -0
- package/dist/finalize/artifact-policy.js +214 -0
- package/dist/finalize/artifact-policy.test.js +84 -0
- package/dist/finalize/delivery-integrity.js +141 -0
- package/dist/finalize/finalize.test.js +210 -0
- package/dist/finalize/github.js +41 -0
- package/dist/finalize/index.js +474 -0
- package/dist/finalize/linear.js +213 -0
- package/dist/finalize/run-report.js +47 -0
- package/dist/finalize/steps/01-map-update.js +11 -0
- package/dist/finalize/steps/02-map-validate.js +11 -0
- package/dist/finalize/steps/03-schema-validate.js +11 -0
- package/dist/finalize/steps/04-run-checks.js +118 -0
- package/dist/finalize/steps/05-generate-report.js +14 -0
- package/dist/finalize/steps/06-commit.js +39 -0
- package/dist/finalize/steps/07-push.js +10 -0
- package/dist/finalize/steps/08-create-pr.js +9 -0
- package/dist/finalize/steps/09-update-state.js +9 -0
- package/dist/finalize/steps/10-append-jsonl.js +23 -0
- package/dist/finalize/steps/11-update-linear.js +22 -0
- package/dist/finalize/steps/12-archive.js +21 -0
- package/dist/graph/adapter/c/adapter.js +45 -0
- package/dist/graph/adapter/c/extract.js +135 -0
- package/dist/graph/adapter/c/index.js +10 -0
- package/dist/graph/adapter/c/runtime.js +67 -0
- package/dist/graph/adapter/cpp/adapter.js +45 -0
- package/dist/graph/adapter/cpp/extract.js +159 -0
- package/dist/graph/adapter/cpp/index.js +10 -0
- package/dist/graph/adapter/cpp/runtime.js +61 -0
- package/dist/graph/adapter/csharp/adapter.js +45 -0
- package/dist/graph/adapter/csharp/extract.js +127 -0
- package/dist/graph/adapter/csharp/index.js +10 -0
- package/dist/graph/adapter/csharp/runtime.js +61 -0
- package/dist/graph/adapter/dart/adapter.js +56 -0
- package/dist/graph/adapter/dart/extract.js +130 -0
- package/dist/graph/adapter/dart/index.js +10 -0
- package/dist/graph/adapter/dart/runtime.js +61 -0
- package/dist/graph/adapter/go/adapter.js +45 -0
- package/dist/graph/adapter/go/extract.js +112 -0
- package/dist/graph/adapter/go/index.js +10 -0
- package/dist/graph/adapter/go/runtime.js +58 -0
- package/dist/graph/adapter/kotlin-java/extract-common.js +83 -0
- package/dist/graph/adapter/kotlin-java/index.js +15 -0
- package/dist/graph/adapter/kotlin-java/java-adapter.js +45 -0
- package/dist/graph/adapter/kotlin-java/java-extract.js +42 -0
- package/dist/graph/adapter/kotlin-java/kotlin-adapter.js +48 -0
- package/dist/graph/adapter/kotlin-java/kotlin-extract.js +58 -0
- package/dist/graph/adapter/kotlin-java/runtime.js +75 -0
- package/dist/graph/adapter/python/adapter.js +45 -0
- package/dist/graph/adapter/python/extract.js +121 -0
- package/dist/graph/adapter/python/index.js +10 -0
- package/dist/graph/adapter/python/runtime.js +70 -0
- package/dist/graph/adapter/registry.js +82 -0
- package/dist/graph/adapter/rust/adapter.js +45 -0
- package/dist/graph/adapter/rust/extract.js +110 -0
- package/dist/graph/adapter/rust/index.js +10 -0
- package/dist/graph/adapter/rust/runtime.js +74 -0
- package/dist/graph/adapter/shell/adapter.js +34 -0
- package/dist/graph/adapter/shell/extract.js +98 -0
- package/dist/graph/adapter/shell/index.js +8 -0
- package/dist/graph/adapter/svelte/adapter.js +91 -0
- package/dist/graph/adapter/svelte/extract.js +41 -0
- package/dist/graph/adapter/svelte/index.js +8 -0
- package/dist/graph/adapter/swift/adapter.js +45 -0
- package/dist/graph/adapter/swift/extract.js +120 -0
- package/dist/graph/adapter/swift/index.js +10 -0
- package/dist/graph/adapter/swift/runtime.js +70 -0
- package/dist/graph/adapter/types.js +2 -0
- package/dist/graph/adapter/typescript-javascript/adapter.js +72 -0
- package/dist/graph/adapter/typescript-javascript/extract.js +115 -0
- package/dist/graph/adapter/typescript-javascript/index.js +10 -0
- package/dist/graph/adapter/typescript-javascript/runtime.js +97 -0
- package/dist/graph/capability/index.js +105 -0
- package/dist/graph/governance.js +104 -0
- package/dist/graph/parser/extract.js +5 -0
- package/dist/graph/parser/loader.js +2 -0
- package/dist/graph/parser/pipeline.js +194 -0
- package/dist/graph/query/index.js +277 -0
- package/dist/graph/query/types.js +5 -0
- package/dist/graph/resolver/build-edges.js +211 -0
- package/dist/graph/resolver/index.js +23 -0
- package/dist/graph/resolver/resolve-imports.js +168 -0
- package/dist/graph/store/adapter.js +132 -0
- package/dist/graph/store/queries.js +124 -0
- package/dist/graph/store/types.js +4 -0
- package/dist/ignore/defaults.js +41 -0
- package/dist/ignore/parser.js +39 -0
- package/dist/lint/map-reference-validator.js +72 -0
- package/dist/loop/abort.js +188 -0
- package/dist/loop/abort.test.js +151 -0
- package/dist/loop/adapters/__tests__/terminal-cli.test.js +92 -0
- package/dist/loop/adapters/agent-subtask.js +137 -0
- package/dist/loop/adapters/agent-subtask.test.js +151 -0
- package/dist/loop/adapters/cli-subtask-bridge.js +108 -0
- package/dist/loop/adapters/index.js +9 -0
- package/dist/loop/adapters/registry.js +17 -0
- package/dist/loop/adapters/terminal-cli.js +403 -0
- package/dist/loop/adapters/types.js +2 -0
- package/dist/loop/adapters/worker-instructions.js +85 -0
- package/dist/loop/body-parser.js +226 -0
- package/dist/loop/bootstrap-packet.js +97 -0
- package/dist/loop/bootstrap-packet.test.js +171 -0
- package/dist/loop/branch-governance.js +54 -0
- package/dist/loop/budget.js +63 -0
- package/dist/loop/budget.test.js +163 -0
- package/dist/loop/checkpoint.js +325 -0
- package/dist/loop/compact-return.js +59 -0
- package/dist/loop/continue.js +645 -0
- package/dist/loop/continue.test.js +337 -0
- package/dist/loop/dispatch-boundary.js +335 -0
- package/dist/loop/dispatch-state.js +223 -0
- package/dist/loop/dispatch-state.test.js +186 -0
- package/dist/loop/dispatch.js +1236 -0
- package/dist/loop/dispatch.test.js +499 -0
- package/dist/loop/ephemeral-smoke.test.js +160 -0
- package/dist/loop/evidence-backfill.js +216 -0
- package/dist/loop/execution-adapter.js +141 -0
- package/dist/loop/execution-adapter.test.js +66 -0
- package/dist/loop/finalize-evidence.js +169 -0
- package/dist/loop/git-custody.js +250 -0
- package/dist/loop/impl-packet-input.js +38 -0
- package/dist/loop/index.js +270 -0
- package/dist/loop/ledger.js +49 -0
- package/dist/loop/ledger.test.js +127 -0
- package/dist/loop/lifecycle-dispatch.js +348 -0
- package/dist/loop/lifecycle-dispatch.test.js +318 -0
- package/dist/loop/lifecycle.js +93 -0
- package/dist/loop/lifecycle.test.js +150 -0
- package/dist/loop/orphan-recovery.js +276 -0
- package/dist/loop/orphan-recovery.test.js +236 -0
- package/dist/loop/parent.js +1566 -0
- package/dist/loop/parent.test.js +738 -0
- package/dist/loop/provider-sealed-packet.test.js +164 -0
- package/dist/loop/resume.js +295 -0
- package/dist/loop/resume.test.js +172 -0
- package/dist/loop/run-bootstrap.js +234 -0
- package/dist/loop/run-preflight.js +203 -0
- package/dist/loop/status.js +665 -0
- package/dist/loop/status.test.js +235 -0
- package/dist/loop/wait.js +86 -0
- package/dist/loop/worker-packet.js +406 -0
- package/dist/loop/worker-packet.test.js +243 -0
- package/dist/loop/worker-prompt.js +260 -0
- package/dist/loop/worker-prompt.test.js +247 -0
- package/dist/loop/worker.js +498 -0
- package/dist/loop/worker.test.js +372 -0
- package/dist/map/atlas.js +77 -0
- package/dist/map/backfill.js +171 -0
- package/dist/map/backfill.test.js +120 -0
- package/dist/map/index.js +255 -0
- package/dist/map/inference.js +73 -0
- package/dist/map/inference.test.js +35 -0
- package/dist/map/query.js +157 -0
- package/dist/map/query.test.js +174 -0
- package/dist/map/update.js +355 -0
- package/dist/map/update.test.js +67 -0
- package/dist/map/validate.js +153 -0
- package/dist/map/validate.test.js +90 -0
- package/dist/map/welfare.js +86 -0
- package/dist/mcp/lib/invoke.js +35 -0
- package/dist/mcp/lib/redact.js +24 -0
- package/dist/mcp/lib/redact.test.js +112 -0
- package/dist/mcp/lib/root.js +41 -0
- package/dist/mcp/lib/root.test.js +114 -0
- package/dist/mcp/server.js +15 -0
- package/dist/mcp/tools/claim-child.js +119 -0
- package/dist/mcp/tools/claim-child.test.js +69 -0
- package/dist/mcp/tools/current-state.js +73 -0
- package/dist/mcp/tools/current-state.test.js +114 -0
- package/dist/mcp/tools/dispatch-result.js +186 -0
- package/dist/mcp/tools/dispatch-result.test.js +109 -0
- package/dist/mcp/tools/index.js +222 -0
- package/dist/mcp/tools/index.test.js +172 -0
- package/dist/mcp/tools/linear.js +74 -0
- package/dist/mcp/tools/loop-continue.js +159 -0
- package/dist/mcp/tools/loop-continue.test.js +186 -0
- package/dist/mcp/tools/loop-dry-run.js +15 -0
- package/dist/mcp/tools/status.js +65 -0
- package/dist/medic/chart-id.js +75 -0
- package/dist/medic/chart-schema.js +139 -0
- package/dist/runs/index.js +119 -0
- package/dist/runs/index.test.js +184 -0
- package/dist/runs/ledger-tail.js +15 -0
- package/dist/runs/list.js +29 -0
- package/dist/runs/reconcile.js +74 -0
- package/dist/runs/show.js +10 -0
- package/dist/runtime/audit/logger.js +15 -0
- package/dist/runtime/audit/reader.js +42 -0
- package/dist/runtime/checkpoint.js +89 -0
- package/dist/runtime/continuation/confirmed.js +225 -0
- package/dist/runtime/continuation/confirmed.test.js +421 -0
- package/dist/runtime/continuation/dry-run.js +74 -0
- package/dist/runtime/execution-window.js +106 -0
- package/dist/runtime/scheduling/child-selector.js +16 -0
- package/dist/runtime/state.js +43 -0
- package/dist/runtime/status.js +46 -0
- package/dist/runtime/verification/envelope.js +80 -0
- package/dist/runtime/verification/fingerprint.js +26 -0
- package/dist/skill-packet/cli.test.js +105 -0
- package/dist/skill-packet/generator.js +225 -0
- package/dist/skill-packet/generator.test.js +159 -0
- package/dist/skill-packet/index.js +49 -0
- package/dist/skill-packet/types.js +2 -0
- package/dist/smartdocs-engine/audit.js +194 -0
- package/dist/smartdocs-engine/audit.test.js +122 -0
- package/dist/smartdocs-engine/canon-check.js +340 -0
- package/dist/smartdocs-engine/canon-check.test.js +234 -0
- package/dist/smartdocs-engine/doctrine.js +633 -0
- package/dist/smartdocs-engine/doctrine.test.js +374 -0
- package/dist/smartdocs-engine/index.js +456 -0
- package/dist/smartdocs-engine/index.test.js +82 -0
- package/dist/smartdocs-engine/ingest.js +495 -0
- package/dist/smartdocs-engine/ingest.test.js +163 -0
- package/dist/smartdocs-engine/migrate.js +217 -0
- package/dist/smartdocs-engine/migrate.test.js +200 -0
- package/dist/smartdocs-engine/seed-instructions.js +335 -0
- package/dist/smartdocs-engine/seed-instructions.test.js +275 -0
- package/dist/smartdocs-engine/smartdoc-ignore.js +258 -0
- package/dist/smartdocs-engine/smartdoc-ignore.test.js +146 -0
- package/dist/smartdocs-engine/validate-instructions.js +366 -0
- package/dist/smartdocs-engine/validate-instructions.test.js +283 -0
- package/dist/tracker/adapters/github/index.js +305 -0
- package/dist/tracker/adapters/jira/index.js +293 -0
- package/dist/tracker/adapters/linear/http-errors.test.js +51 -0
- package/dist/tracker/adapters/linear/index.js +621 -0
- package/dist/tracker/adapters/linear/index.test.js +238 -0
- package/dist/tracker/adapters/linear.js +50 -0
- package/dist/tracker/adapters/local/index.js +10 -0
- package/dist/tracker/adapters/local-file/index.js +159 -0
- package/dist/tracker/adapters/mcp-bridge.js +158 -0
- package/dist/tracker/adapters/mcp-bridge.test.js +12 -0
- package/dist/tracker/adapters/spec/index.js +146 -0
- package/dist/tracker/capabilities.js +2 -0
- package/dist/tracker/index.js +49 -0
- package/dist/tracker/lifecycle-policy.js +139 -0
- package/dist/tracker/lifecycle-transition.js +164 -0
- package/dist/tracker/local-graph.js +98 -0
- package/dist/tracker/migration.js +56 -0
- package/dist/tracker/schema.js +86 -0
- package/dist/tracker/sync/index.js +404 -0
- package/dist/tracker/sync/queue-store.js +95 -0
- package/dist/tracker/sync/queue-store.test.js +104 -0
- package/dist/tracker/types.js +11 -0
- package/dist/types/linear.js +3 -0
- package/dist/types/result-packet.js +12 -0
- package/dist/types/runtime-state.js +2 -0
- package/dist/types/work-contract.js +2 -0
- package/dist/utils/monotonic-timestamp.js +13 -0
- package/dist/utils/monotonic-timestamp.test.js +19 -0
- package/package.json +64 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Route-local cognition delta — public API.
|
|
4
|
+
*
|
|
5
|
+
* Exposes delta logic for POLARIS.md and SUMMARY.md updates, validation,
|
|
6
|
+
* and seed-draft generation used by map update and Smart Docs ingest.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.validateAndApplyLibrarianResult = exports.dispatchCognitionLibrarian = exports.validateCognitionLibrarianResult = exports.archiveCognitionNotes = exports.looksLikePolarisChurn = exports.getSummaryFileSize = exports.validateSummaryFile = exports.validateCognitionSurfaces = exports.SUMMARY_MAX_BYTES = exports.readSummarymd = exports.hasDoctrineBled = exports.isSummaryOversized = exports.detectMissingSummaries = exports.findNearestSummarymd = exports.detectPrecedenceLevel = exports.detectSummaryReasons = exports.applySummaryDelta = exports.assessRouteHealth = exports.readRoutePolarismd = exports.POLARIS_OWNED_COGNITION_FOLDERS = exports.isUserCreatedCognitionSurface = exports.isPolarisOwnedFolder = exports.isCognitionSkippedFolder = exports.findNearestRoutePolarismd = exports.detectOperationalReasons = exports.applyRouteCognitionDelta = void 0;
|
|
10
|
+
var route_cognition_delta_js_1 = require("./route-cognition-delta.js");
|
|
11
|
+
Object.defineProperty(exports, "applyRouteCognitionDelta", { enumerable: true, get: function () { return route_cognition_delta_js_1.applyRouteCognitionDelta; } });
|
|
12
|
+
Object.defineProperty(exports, "detectOperationalReasons", { enumerable: true, get: function () { return route_cognition_delta_js_1.detectOperationalReasons; } });
|
|
13
|
+
Object.defineProperty(exports, "findNearestRoutePolarismd", { enumerable: true, get: function () { return route_cognition_delta_js_1.findNearestRoutePolarismd; } });
|
|
14
|
+
Object.defineProperty(exports, "isCognitionSkippedFolder", { enumerable: true, get: function () { return route_cognition_delta_js_1.isCognitionSkippedFolder; } });
|
|
15
|
+
Object.defineProperty(exports, "isPolarisOwnedFolder", { enumerable: true, get: function () { return route_cognition_delta_js_1.isPolarisOwnedFolder; } });
|
|
16
|
+
Object.defineProperty(exports, "isUserCreatedCognitionSurface", { enumerable: true, get: function () { return route_cognition_delta_js_1.isUserCreatedCognitionSurface; } });
|
|
17
|
+
Object.defineProperty(exports, "POLARIS_OWNED_COGNITION_FOLDERS", { enumerable: true, get: function () { return route_cognition_delta_js_1.POLARIS_OWNED_COGNITION_FOLDERS; } });
|
|
18
|
+
Object.defineProperty(exports, "readRoutePolarismd", { enumerable: true, get: function () { return route_cognition_delta_js_1.readRoutePolarismd; } });
|
|
19
|
+
Object.defineProperty(exports, "assessRouteHealth", { enumerable: true, get: function () { return route_cognition_delta_js_1.assessRouteHealth; } });
|
|
20
|
+
var summary_delta_js_1 = require("./summary-delta.js");
|
|
21
|
+
Object.defineProperty(exports, "applySummaryDelta", { enumerable: true, get: function () { return summary_delta_js_1.applySummaryDelta; } });
|
|
22
|
+
Object.defineProperty(exports, "detectSummaryReasons", { enumerable: true, get: function () { return summary_delta_js_1.detectSummaryReasons; } });
|
|
23
|
+
Object.defineProperty(exports, "detectPrecedenceLevel", { enumerable: true, get: function () { return summary_delta_js_1.detectPrecedenceLevel; } });
|
|
24
|
+
Object.defineProperty(exports, "findNearestSummarymd", { enumerable: true, get: function () { return summary_delta_js_1.findNearestSummarymd; } });
|
|
25
|
+
Object.defineProperty(exports, "detectMissingSummaries", { enumerable: true, get: function () { return summary_delta_js_1.detectMissingSummaries; } });
|
|
26
|
+
Object.defineProperty(exports, "isSummaryOversized", { enumerable: true, get: function () { return summary_delta_js_1.isSummaryOversized; } });
|
|
27
|
+
Object.defineProperty(exports, "hasDoctrineBled", { enumerable: true, get: function () { return summary_delta_js_1.hasDoctrineBled; } });
|
|
28
|
+
Object.defineProperty(exports, "readSummarymd", { enumerable: true, get: function () { return summary_delta_js_1.readSummarymd; } });
|
|
29
|
+
Object.defineProperty(exports, "SUMMARY_MAX_BYTES", { enumerable: true, get: function () { return summary_delta_js_1.SUMMARY_MAX_BYTES; } });
|
|
30
|
+
var validate_js_1 = require("./validate.js");
|
|
31
|
+
Object.defineProperty(exports, "validateCognitionSurfaces", { enumerable: true, get: function () { return validate_js_1.validateCognitionSurfaces; } });
|
|
32
|
+
Object.defineProperty(exports, "validateSummaryFile", { enumerable: true, get: function () { return validate_js_1.validateSummaryFile; } });
|
|
33
|
+
Object.defineProperty(exports, "getSummaryFileSize", { enumerable: true, get: function () { return validate_js_1.getSummaryFileSize; } });
|
|
34
|
+
Object.defineProperty(exports, "looksLikePolarisChurn", { enumerable: true, get: function () { return validate_js_1.looksLikePolarisChurn; } });
|
|
35
|
+
var archive_js_1 = require("./archive.js");
|
|
36
|
+
Object.defineProperty(exports, "archiveCognitionNotes", { enumerable: true, get: function () { return archive_js_1.archiveCognitionNotes; } });
|
|
37
|
+
var librarian_types_js_1 = require("./librarian-types.js");
|
|
38
|
+
Object.defineProperty(exports, "validateCognitionLibrarianResult", { enumerable: true, get: function () { return librarian_types_js_1.validateCognitionLibrarianResult; } });
|
|
39
|
+
var librarian_dispatch_js_1 = require("./librarian-dispatch.js");
|
|
40
|
+
Object.defineProperty(exports, "dispatchCognitionLibrarian", { enumerable: true, get: function () { return librarian_dispatch_js_1.dispatchCognitionLibrarian; } });
|
|
41
|
+
Object.defineProperty(exports, "validateAndApplyLibrarianResult", { enumerable: true, get: function () { return librarian_dispatch_js_1.validateAndApplyLibrarianResult; } });
|
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Foreman-side cognition-librarian dispatch and patch validation.
|
|
4
|
+
*
|
|
5
|
+
* dispatchCognitionLibrarian — groups pending work notes by folder, dispatches
|
|
6
|
+
* a cognition-librarian session per folder, waits for the sealed result, and
|
|
7
|
+
* calls validateAndApplyLibrarianResult on each.
|
|
8
|
+
*
|
|
9
|
+
* validateAndApplyLibrarianResult — enforces the 5 validation rules from spec
|
|
10
|
+
* §6 and writes approved patches to disk.
|
|
11
|
+
*
|
|
12
|
+
* Spec: smartdocs/specs/active/folder-cognition-staging-librarian.md §6
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.dispatchCognitionLibrarian = dispatchCognitionLibrarian;
|
|
16
|
+
exports.validateAndApplyLibrarianResult = validateAndApplyLibrarianResult;
|
|
17
|
+
const node_fs_1 = require("node:fs");
|
|
18
|
+
const node_path_1 = require("node:path");
|
|
19
|
+
const node_crypto_1 = require("node:crypto");
|
|
20
|
+
const summary_delta_js_1 = require("./summary-delta.js");
|
|
21
|
+
const route_cognition_delta_js_1 = require("./route-cognition-delta.js");
|
|
22
|
+
const librarian_types_js_1 = require("./librarian-types.js");
|
|
23
|
+
const DEFAULT_TIMEOUT_MS = 120_000;
|
|
24
|
+
const POLL_INTERVAL_MS = 500;
|
|
25
|
+
// ── Internal helpers ─────────────────────────────────────────────────────────
|
|
26
|
+
/** Extract key–value pairs from a YAML frontmatter block. */
|
|
27
|
+
function parseNoteFrontmatter(content) {
|
|
28
|
+
const match = /^---[ \t]*\r?\n([\s\S]*?)\r?\n---/m.exec(content);
|
|
29
|
+
if (!match?.[1])
|
|
30
|
+
return null;
|
|
31
|
+
const result = {};
|
|
32
|
+
for (const line of match[1].split(/\r?\n/)) {
|
|
33
|
+
const colonIdx = line.indexOf(":");
|
|
34
|
+
if (colonIdx < 1)
|
|
35
|
+
continue;
|
|
36
|
+
const key = line.slice(0, colonIdx).trim();
|
|
37
|
+
const value = line.slice(colonIdx + 1).trim();
|
|
38
|
+
if (key)
|
|
39
|
+
result[key] = value;
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
function appendTelemetry(telemetryFile, event) {
|
|
44
|
+
(0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(telemetryFile), { recursive: true });
|
|
45
|
+
(0, node_fs_1.appendFileSync)(telemetryFile, JSON.stringify(event) + "\n", "utf-8");
|
|
46
|
+
}
|
|
47
|
+
/** Poll until result file appears or timeout expires. */
|
|
48
|
+
async function waitForResultFile(resultPath, timeoutMs) {
|
|
49
|
+
const deadline = Date.now() + timeoutMs;
|
|
50
|
+
do {
|
|
51
|
+
if ((0, node_fs_1.existsSync)(resultPath))
|
|
52
|
+
return true;
|
|
53
|
+
await new Promise((res) => setTimeout(res, POLL_INTERVAL_MS));
|
|
54
|
+
} while (Date.now() < deadline);
|
|
55
|
+
return (0, node_fs_1.existsSync)(resultPath);
|
|
56
|
+
}
|
|
57
|
+
// ── Public API ────────────────────────────────────────────────────────────────
|
|
58
|
+
/**
|
|
59
|
+
* Dispatch a cognition-librarian session for each folder that has pending work
|
|
60
|
+
* notes with docs_impact ≠ "none". Non-blocking to cluster execution — a
|
|
61
|
+
* librarian failure does not halt the cluster.
|
|
62
|
+
*/
|
|
63
|
+
async function dispatchCognitionLibrarian(options) {
|
|
64
|
+
const { runId, clusterId, workNotePaths, repoRoot, adapter, provider, telemetryFile, timeoutMs = DEFAULT_TIMEOUT_MS, dryRun = false, } = options;
|
|
65
|
+
const groups = new Map();
|
|
66
|
+
for (const notePath of workNotePaths) {
|
|
67
|
+
const absPath = (0, node_path_1.resolve)(repoRoot, notePath);
|
|
68
|
+
let content;
|
|
69
|
+
try {
|
|
70
|
+
content = (0, node_fs_1.readFileSync)(absPath, "utf-8");
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const meta = parseNoteFrontmatter(content);
|
|
76
|
+
if (!meta)
|
|
77
|
+
continue;
|
|
78
|
+
const folderSlug = meta["folder_slug"] ?? "";
|
|
79
|
+
const folder = meta["folder"] ?? "";
|
|
80
|
+
const docsImpact = meta["docs_impact"] ?? "none";
|
|
81
|
+
if (!folderSlug || docsImpact === "none")
|
|
82
|
+
continue;
|
|
83
|
+
if (!groups.has(folderSlug)) {
|
|
84
|
+
groups.set(folderSlug, { folder, folder_slug: folderSlug, note_paths: [] });
|
|
85
|
+
}
|
|
86
|
+
groups.get(folderSlug).note_paths.push(notePath);
|
|
87
|
+
}
|
|
88
|
+
if (groups.size === 0) {
|
|
89
|
+
return { dispatched: 0, outcomes: [] };
|
|
90
|
+
}
|
|
91
|
+
const outcomes = [];
|
|
92
|
+
let dispatched = 0;
|
|
93
|
+
for (const group of groups.values()) {
|
|
94
|
+
const dispatchId = (0, node_crypto_1.randomUUID)();
|
|
95
|
+
const cognitionDir = (0, node_path_1.join)(repoRoot, ".polaris", "cognition");
|
|
96
|
+
const packetPath = (0, node_path_1.join)(cognitionDir, "packets", `${dispatchId}.json`);
|
|
97
|
+
const resultPath = (0, node_path_1.join)(cognitionDir, "results", `${dispatchId}.json`);
|
|
98
|
+
const polarisMdPath = (0, node_path_1.join)(group.folder, "POLARIS.md");
|
|
99
|
+
const summaryMdAbsPath = (0, node_path_1.join)(repoRoot, group.folder, "SUMMARY.md");
|
|
100
|
+
const summaryMdPath = (0, node_fs_1.existsSync)(summaryMdAbsPath)
|
|
101
|
+
? (0, node_path_1.join)(group.folder, "SUMMARY.md")
|
|
102
|
+
: null;
|
|
103
|
+
const cognitionIndexPath = (0, node_path_1.join)(".polaris", "cognition", "archive", group.folder_slug, "cognition-index.json");
|
|
104
|
+
const allowedFiles = [polarisMdPath];
|
|
105
|
+
if (summaryMdPath)
|
|
106
|
+
allowedFiles.push(summaryMdPath);
|
|
107
|
+
const packet = {
|
|
108
|
+
run_id: runId,
|
|
109
|
+
dispatch_id: dispatchId,
|
|
110
|
+
role: "cognition-librarian",
|
|
111
|
+
folder: group.folder,
|
|
112
|
+
folder_slug: group.folder_slug,
|
|
113
|
+
note_paths: group.note_paths,
|
|
114
|
+
polaris_md_path: polarisMdPath,
|
|
115
|
+
summary_md_path: summaryMdPath,
|
|
116
|
+
cognition_index_path: cognitionIndexPath,
|
|
117
|
+
result_path: resultPath,
|
|
118
|
+
constraints: {
|
|
119
|
+
max_polaris_addition_lines: 20,
|
|
120
|
+
max_summary_addition_lines: 30,
|
|
121
|
+
require_confidence_threshold: 0.80,
|
|
122
|
+
allowed_files: allowedFiles,
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
if (!dryRun) {
|
|
126
|
+
(0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(packetPath), { recursive: true });
|
|
127
|
+
(0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(resultPath), { recursive: true });
|
|
128
|
+
(0, node_fs_1.writeFileSync)(packetPath, JSON.stringify(packet, null, 2), "utf-8");
|
|
129
|
+
appendTelemetry(telemetryFile, {
|
|
130
|
+
event: "cognition-librarian-dispatched",
|
|
131
|
+
run_id: runId,
|
|
132
|
+
cluster_id: clusterId,
|
|
133
|
+
dispatch_id: dispatchId,
|
|
134
|
+
folder: group.folder,
|
|
135
|
+
folder_slug: group.folder_slug,
|
|
136
|
+
note_count: group.note_paths.length,
|
|
137
|
+
packet_path: packetPath,
|
|
138
|
+
result_path: resultPath,
|
|
139
|
+
timestamp: new Date().toISOString(),
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
await adapter.dispatch({
|
|
144
|
+
schema_version: "2.1",
|
|
145
|
+
run_id: runId,
|
|
146
|
+
cluster_id: clusterId,
|
|
147
|
+
active_child: `cognition-librarian:${group.folder_slug}`,
|
|
148
|
+
state_file: packetPath,
|
|
149
|
+
telemetry_file: telemetryFile,
|
|
150
|
+
dispatch_id: dispatchId,
|
|
151
|
+
context: {
|
|
152
|
+
role: "cognition-librarian",
|
|
153
|
+
cognition_librarian_packet_path: packetPath,
|
|
154
|
+
},
|
|
155
|
+
}, { provider, dryRun });
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
159
|
+
if (!dryRun) {
|
|
160
|
+
appendTelemetry(telemetryFile, {
|
|
161
|
+
event: "cognition-librarian-patch-rejected",
|
|
162
|
+
run_id: runId,
|
|
163
|
+
dispatch_id: dispatchId,
|
|
164
|
+
folder: group.folder,
|
|
165
|
+
folder_slug: group.folder_slug,
|
|
166
|
+
reason: "dispatch-error",
|
|
167
|
+
error: msg,
|
|
168
|
+
timestamp: new Date().toISOString(),
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
outcomes.push({
|
|
172
|
+
folder: group.folder,
|
|
173
|
+
folder_slug: group.folder_slug,
|
|
174
|
+
outcome: null,
|
|
175
|
+
error: msg,
|
|
176
|
+
});
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
dispatched += 1;
|
|
180
|
+
if (dryRun) {
|
|
181
|
+
outcomes.push({ folder: group.folder, folder_slug: group.folder_slug, outcome: null });
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
// Wait for result file — dispatch should have written it, poll as safety net.
|
|
185
|
+
const resultExists = await waitForResultFile(resultPath, timeoutMs);
|
|
186
|
+
if (!resultExists) {
|
|
187
|
+
const errMsg = `Cognition librarian result not found at ${resultPath} after ${timeoutMs}ms`;
|
|
188
|
+
appendTelemetry(telemetryFile, {
|
|
189
|
+
event: "cognition-librarian-patch-rejected",
|
|
190
|
+
run_id: runId,
|
|
191
|
+
dispatch_id: dispatchId,
|
|
192
|
+
folder: group.folder,
|
|
193
|
+
folder_slug: group.folder_slug,
|
|
194
|
+
reason: "result-timeout",
|
|
195
|
+
timestamp: new Date().toISOString(),
|
|
196
|
+
});
|
|
197
|
+
outcomes.push({
|
|
198
|
+
folder: group.folder,
|
|
199
|
+
folder_slug: group.folder_slug,
|
|
200
|
+
outcome: null,
|
|
201
|
+
error: errMsg,
|
|
202
|
+
});
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
let result;
|
|
206
|
+
try {
|
|
207
|
+
result = JSON.parse((0, node_fs_1.readFileSync)(resultPath, "utf-8"));
|
|
208
|
+
}
|
|
209
|
+
catch (err) {
|
|
210
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
211
|
+
outcomes.push({
|
|
212
|
+
folder: group.folder,
|
|
213
|
+
folder_slug: group.folder_slug,
|
|
214
|
+
outcome: null,
|
|
215
|
+
error: `Failed to parse librarian result: ${msg}`,
|
|
216
|
+
});
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
appendTelemetry(telemetryFile, {
|
|
220
|
+
event: "cognition-librarian-result-received",
|
|
221
|
+
run_id: runId,
|
|
222
|
+
dispatch_id: dispatchId,
|
|
223
|
+
folder: group.folder,
|
|
224
|
+
folder_slug: group.folder_slug,
|
|
225
|
+
status: result.status,
|
|
226
|
+
confidence: result.confidence,
|
|
227
|
+
notes_reconciled_count: result.notes_reconciled?.length ?? 0,
|
|
228
|
+
timestamp: new Date().toISOString(),
|
|
229
|
+
});
|
|
230
|
+
const outcome = validateAndApplyLibrarianResult(result, repoRoot, packet);
|
|
231
|
+
for (const rejected of outcome.patches_rejected) {
|
|
232
|
+
if (!rejected.reason.startsWith("COGNITION_USER_SURFACE_PROTECTED"))
|
|
233
|
+
continue;
|
|
234
|
+
appendTelemetry(telemetryFile, {
|
|
235
|
+
event: "cognition-user-surface-protected",
|
|
236
|
+
run_id: runId,
|
|
237
|
+
dispatch_id: dispatchId,
|
|
238
|
+
folder: group.folder,
|
|
239
|
+
folder_slug: group.folder_slug,
|
|
240
|
+
file: rejected.patch.file,
|
|
241
|
+
reason: rejected.reason,
|
|
242
|
+
timestamp: new Date().toISOString(),
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
if (outcome.approved) {
|
|
246
|
+
appendTelemetry(telemetryFile, {
|
|
247
|
+
event: "cognition-librarian-patch-applied",
|
|
248
|
+
run_id: runId,
|
|
249
|
+
dispatch_id: dispatchId,
|
|
250
|
+
folder: group.folder,
|
|
251
|
+
folder_slug: group.folder_slug,
|
|
252
|
+
files_written: outcome.files_written,
|
|
253
|
+
patches_applied_count: outcome.patches_applied.length,
|
|
254
|
+
timestamp: new Date().toISOString(),
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
appendTelemetry(telemetryFile, {
|
|
259
|
+
event: "cognition-librarian-patch-rejected",
|
|
260
|
+
run_id: runId,
|
|
261
|
+
dispatch_id: dispatchId,
|
|
262
|
+
folder: group.folder,
|
|
263
|
+
folder_slug: group.folder_slug,
|
|
264
|
+
reason: outcome.rejection_reason,
|
|
265
|
+
timestamp: new Date().toISOString(),
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
outcomes.push({ folder: group.folder, folder_slug: group.folder_slug, outcome });
|
|
269
|
+
}
|
|
270
|
+
return { dispatched, outcomes };
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Validate a cognition-librarian result against all 5 foreman safety rules
|
|
274
|
+
* (spec §6) and write approved patches to disk.
|
|
275
|
+
*
|
|
276
|
+
* Rules that reject the ENTIRE result (approved: false, no writes):
|
|
277
|
+
* - Invalid schema
|
|
278
|
+
* - Confidence below packet threshold (§6.4)
|
|
279
|
+
* - Any patch targets a file outside allowed_files (§6.1)
|
|
280
|
+
*
|
|
281
|
+
* Rules that reject a SPECIFIC PATCH only (other patches still applied):
|
|
282
|
+
* - SUMMARY.md patch contains doctrine bleed patterns (§6.2)
|
|
283
|
+
* - Proposed content exceeds size constraints (§6.3)
|
|
284
|
+
*/
|
|
285
|
+
function validateAndApplyLibrarianResult(result, repoRoot, packet) {
|
|
286
|
+
// Rule: Schema validation — reject entire result on failure.
|
|
287
|
+
const schemaErrors = (0, librarian_types_js_1.validateCognitionLibrarianResult)(result);
|
|
288
|
+
if (schemaErrors.length > 0) {
|
|
289
|
+
return {
|
|
290
|
+
approved: false,
|
|
291
|
+
rejection_reason: `SCHEMA_INVALID: ${schemaErrors.join("; ")}`,
|
|
292
|
+
files_written: [],
|
|
293
|
+
patches_applied: [],
|
|
294
|
+
patches_rejected: [],
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
// Rule §6.4: Confidence threshold — reject entire result if below threshold.
|
|
298
|
+
if (result.confidence < packet.constraints.require_confidence_threshold) {
|
|
299
|
+
return {
|
|
300
|
+
approved: false,
|
|
301
|
+
rejection_reason: `COGNITION_LOW_CONFIDENCE: confidence ${result.confidence} below threshold ${packet.constraints.require_confidence_threshold}`,
|
|
302
|
+
files_written: [],
|
|
303
|
+
patches_applied: [],
|
|
304
|
+
patches_rejected: [],
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
// Rule §6.1: File scope check — reject entire result if any patch targets an out-of-scope file.
|
|
308
|
+
for (const patch of result.proposed_patches) {
|
|
309
|
+
if (!packet.constraints.allowed_files.includes(patch.file)) {
|
|
310
|
+
return {
|
|
311
|
+
approved: false,
|
|
312
|
+
rejection_reason: `COGNITION_SCOPE_VIOLATION: file "${patch.file}" not in allowed_files`,
|
|
313
|
+
files_written: [],
|
|
314
|
+
patches_applied: [],
|
|
315
|
+
patches_rejected: result.proposed_patches.map((p) => ({
|
|
316
|
+
patch: p,
|
|
317
|
+
reason: "result rejected due to scope violation",
|
|
318
|
+
})),
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
// No patches proposed — approved as no-change, notes can be archived.
|
|
323
|
+
if (result.proposed_patches.length === 0) {
|
|
324
|
+
return {
|
|
325
|
+
approved: true,
|
|
326
|
+
files_written: [],
|
|
327
|
+
patches_applied: [],
|
|
328
|
+
patches_rejected: [],
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
// Per-patch checks (doctrine bleed §6.2 and size guard §6.3).
|
|
332
|
+
// These reject the individual patch and continue applying the rest.
|
|
333
|
+
const patchesApplied = [];
|
|
334
|
+
const patchesRejected = [];
|
|
335
|
+
const filesWritten = [];
|
|
336
|
+
for (const patch of result.proposed_patches) {
|
|
337
|
+
const isSummaryPatch = patch.file === packet.summary_md_path;
|
|
338
|
+
const isPolarisPath = patch.file === packet.polaris_md_path;
|
|
339
|
+
if ((0, route_cognition_delta_js_1.isUserCreatedCognitionSurface)(patch.file, repoRoot)) {
|
|
340
|
+
patchesRejected.push({
|
|
341
|
+
patch,
|
|
342
|
+
reason: `COGNITION_USER_SURFACE_PROTECTED: "${patch.file}" is protected as user-created cognition surface`,
|
|
343
|
+
});
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
// Rule §6.2: Doctrine bleed — SUMMARY.md must not contain operational imperatives.
|
|
347
|
+
if (isSummaryPatch && (0, summary_delta_js_1.hasDoctrineBled)(patch.proposed_content)) {
|
|
348
|
+
patchesRejected.push({
|
|
349
|
+
patch,
|
|
350
|
+
reason: "COGNITION_DOCTRINE_BLEED: SUMMARY.md patch contains operational doctrine patterns",
|
|
351
|
+
});
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
// Rule §6.3: Size guard.
|
|
355
|
+
if (isPolarisPath) {
|
|
356
|
+
const lineCount = patch.proposed_content.split("\n").length;
|
|
357
|
+
if (lineCount > packet.constraints.max_polaris_addition_lines) {
|
|
358
|
+
patchesRejected.push({
|
|
359
|
+
patch,
|
|
360
|
+
reason: `COGNITION_SIZE_GUARD: POLARIS.md has ${lineCount} lines, max ${packet.constraints.max_polaris_addition_lines}`,
|
|
361
|
+
});
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
else if (isSummaryPatch && (0, summary_delta_js_1.isSummaryOversized)(patch.proposed_content)) {
|
|
366
|
+
patchesRejected.push({
|
|
367
|
+
patch,
|
|
368
|
+
reason: "COGNITION_SIZE_GUARD: SUMMARY.md patch exceeds SUMMARY_MAX_BYTES",
|
|
369
|
+
});
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
// All checks passed — write proposed content.
|
|
373
|
+
const absPath = (0, node_path_1.resolve)(repoRoot, patch.file);
|
|
374
|
+
(0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(absPath), { recursive: true });
|
|
375
|
+
(0, node_fs_1.writeFileSync)(absPath, patch.proposed_content, "utf-8");
|
|
376
|
+
filesWritten.push(patch.file);
|
|
377
|
+
patchesApplied.push(patch);
|
|
378
|
+
}
|
|
379
|
+
// approved = true when at least one patch was applied, or when there were no
|
|
380
|
+
// rejections (all patches passed — even if empty after early-return guard).
|
|
381
|
+
const approved = patchesApplied.length > 0 || patchesRejected.length === 0;
|
|
382
|
+
return {
|
|
383
|
+
approved,
|
|
384
|
+
...(patchesApplied.length === 0 && patchesRejected.length > 0
|
|
385
|
+
? { rejection_reason: "all patches rejected" }
|
|
386
|
+
: {}),
|
|
387
|
+
files_written: filesWritten,
|
|
388
|
+
patches_applied: patchesApplied,
|
|
389
|
+
patches_rejected: patchesRejected,
|
|
390
|
+
};
|
|
391
|
+
}
|