@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,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const agent_subtask_js_1 = require("./agent-subtask.js");
|
|
5
|
+
const worker_packet_js_1 = require("../worker-packet.js");
|
|
6
|
+
function makePacket(overrides = {}) {
|
|
7
|
+
return {
|
|
8
|
+
schema_version: "1.0",
|
|
9
|
+
run_id: "run-001",
|
|
10
|
+
cluster_id: "POL-105",
|
|
11
|
+
active_child: "POL-110",
|
|
12
|
+
state_file: "/repo/.taskchain_artifacts/polaris-run/current-state.json",
|
|
13
|
+
telemetry_file: "/repo/.taskchain_artifacts/polaris-run/runs/run-001/telemetry.jsonl",
|
|
14
|
+
context: { branch: "feature/pol-105" },
|
|
15
|
+
...overrides,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
(0, vitest_1.describe)("AgentSubtaskAdapter", () => {
|
|
19
|
+
(0, vitest_1.it)("dispatches an ephemeral bootstrap packet through the native subtask dispatcher", async () => {
|
|
20
|
+
const packet = makePacket();
|
|
21
|
+
const adapter = new agent_subtask_js_1.AgentSubtaskAdapter(async (request) => {
|
|
22
|
+
(0, vitest_1.expect)(request.packet).toEqual(packet);
|
|
23
|
+
(0, vitest_1.expect)(request.instructions).toContain("ephemeral");
|
|
24
|
+
(0, vitest_1.expect)(request.instructions).toContain("POL-110");
|
|
25
|
+
(0, vitest_1.expect)(request.returnContract).toEqual([
|
|
26
|
+
"child_id",
|
|
27
|
+
"status",
|
|
28
|
+
"commit_hash",
|
|
29
|
+
"validation_summary",
|
|
30
|
+
"next_action",
|
|
31
|
+
"warnings",
|
|
32
|
+
]);
|
|
33
|
+
return {
|
|
34
|
+
child_id: "POL-110",
|
|
35
|
+
status: "done",
|
|
36
|
+
commit_hash: "abc1234",
|
|
37
|
+
validation_summary: "passed",
|
|
38
|
+
next_action: "resume-parent",
|
|
39
|
+
warnings: [],
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
const result = await adapter.dispatch(packet, { provider: "agent-subtask" });
|
|
43
|
+
(0, vitest_1.expect)(result).toMatchObject({
|
|
44
|
+
exit_code: 0,
|
|
45
|
+
provider_used: "agent-subtask",
|
|
46
|
+
command_run: "agent-subtask:POL-110",
|
|
47
|
+
});
|
|
48
|
+
(0, vitest_1.expect)(JSON.parse(result.summary ?? "{}")).toMatchObject({
|
|
49
|
+
child_id: "POL-110",
|
|
50
|
+
status: "done",
|
|
51
|
+
commit_hash: "abc1234",
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
(0, vitest_1.it)("returns a dispatch error result when native subtask dispatch fails", async () => {
|
|
55
|
+
const adapter = new agent_subtask_js_1.AgentSubtaskAdapter(async () => {
|
|
56
|
+
throw new Error("native dispatch unavailable");
|
|
57
|
+
});
|
|
58
|
+
const result = await adapter.dispatch(makePacket(), { provider: "agent-subtask" });
|
|
59
|
+
(0, vitest_1.expect)(result.exit_code).toBe(1);
|
|
60
|
+
(0, vitest_1.expect)(result.provider_used).toBe("agent-subtask");
|
|
61
|
+
(0, vitest_1.expect)(result.stderr).toContain("native dispatch unavailable");
|
|
62
|
+
(0, vitest_1.expect)(result.summary).toContain("native dispatch unavailable");
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
// ── WorkerPacket (compiled) dispatch ──────────────────────────────────────────
|
|
66
|
+
const WORKER_PACKET_BASE = {
|
|
67
|
+
runId: "run-001",
|
|
68
|
+
clusterId: "POL-120",
|
|
69
|
+
branch: "feature/pol-120",
|
|
70
|
+
stateFile: "/repo/.taskchain_artifacts/polaris-run/current-state.json",
|
|
71
|
+
telemetryFile: "/repo/.taskchain_artifacts/polaris-run/runs/run-001/telemetry.jsonl",
|
|
72
|
+
};
|
|
73
|
+
(0, vitest_1.describe)("AgentSubtaskAdapter — compiled WorkerPacket", () => {
|
|
74
|
+
(0, vitest_1.it)("uses pre-compiled instructions from WorkerPacket instead of generating them", async () => {
|
|
75
|
+
const packet = (0, worker_packet_js_1.compileImplPacket)({ ...WORKER_PACKET_BASE, childId: "POL-121" });
|
|
76
|
+
let capturedInstructions = "";
|
|
77
|
+
const adapter = new agent_subtask_js_1.AgentSubtaskAdapter(async (request) => {
|
|
78
|
+
capturedInstructions = request.instructions;
|
|
79
|
+
return {
|
|
80
|
+
child_id: "POL-121",
|
|
81
|
+
status: "done",
|
|
82
|
+
commit_hash: "abc1234",
|
|
83
|
+
validation_summary: "passed",
|
|
84
|
+
next_action: "resume-parent",
|
|
85
|
+
warnings: [],
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
const result = await adapter.dispatch(packet, { provider: "agent-subtask" });
|
|
89
|
+
(0, vitest_1.expect)(result.exit_code).toBe(0);
|
|
90
|
+
// Compiled instructions must contain the primary_goal, not generic "ephemeral" boilerplate
|
|
91
|
+
(0, vitest_1.expect)(capturedInstructions).toContain(packet.instructions.primary_goal);
|
|
92
|
+
(0, vitest_1.expect)(capturedInstructions).toContain("impl");
|
|
93
|
+
(0, vitest_1.expect)(capturedInstructions).toContain("TERMINATE");
|
|
94
|
+
});
|
|
95
|
+
(0, vitest_1.it)("includes lifecycle teardown notice in compiled instructions", async () => {
|
|
96
|
+
const packet = (0, worker_packet_js_1.compileImplPacket)({ ...WORKER_PACKET_BASE, childId: "POL-121" });
|
|
97
|
+
let capturedInstructions = "";
|
|
98
|
+
const adapter = new agent_subtask_js_1.AgentSubtaskAdapter(async (request) => {
|
|
99
|
+
capturedInstructions = request.instructions;
|
|
100
|
+
return { child_id: "POL-121", status: "done" };
|
|
101
|
+
});
|
|
102
|
+
await adapter.dispatch(packet, { provider: "agent-subtask" });
|
|
103
|
+
(0, vitest_1.expect)(capturedInstructions).toContain("LIFECYCLE CONTRACT");
|
|
104
|
+
(0, vitest_1.expect)(capturedInstructions).toContain("TERMINATE THIS SESSION IMMEDIATELY");
|
|
105
|
+
});
|
|
106
|
+
(0, vitest_1.it)("uses the return_contract from WorkerPacket, not the legacy fallback", async () => {
|
|
107
|
+
const packet = (0, worker_packet_js_1.compileImplPacket)({ ...WORKER_PACKET_BASE, childId: "POL-121" });
|
|
108
|
+
let capturedContract = [];
|
|
109
|
+
const adapter = new agent_subtask_js_1.AgentSubtaskAdapter(async (request) => {
|
|
110
|
+
capturedContract = request.returnContract;
|
|
111
|
+
return { child_id: "POL-121", status: "done" };
|
|
112
|
+
});
|
|
113
|
+
await adapter.dispatch(packet, { provider: "agent-subtask" });
|
|
114
|
+
(0, vitest_1.expect)(capturedContract).toEqual(packet.return_contract);
|
|
115
|
+
// Compiled contract must not contain legacy-only fields
|
|
116
|
+
(0, vitest_1.expect)(capturedContract).not.toContain("commit_hash");
|
|
117
|
+
});
|
|
118
|
+
(0, vitest_1.it)("dispatches finalize worker with empty active_child correctly", async () => {
|
|
119
|
+
const packet = (0, worker_packet_js_1.compileFinalizePacket)(WORKER_PACKET_BASE);
|
|
120
|
+
const adapter = new agent_subtask_js_1.AgentSubtaskAdapter(async (request) => {
|
|
121
|
+
// Finalize worker returns run_id instead of child_id
|
|
122
|
+
(0, vitest_1.expect)(request.instructions).toContain("finalize");
|
|
123
|
+
return { run_id: "run-001", status: "done", pr_url: "https://example.com/pr/1" };
|
|
124
|
+
});
|
|
125
|
+
// Finalize packet has active_child = "" — validation should not check child_id mismatch
|
|
126
|
+
const result = await adapter.dispatch(packet, { provider: "agent-subtask" });
|
|
127
|
+
(0, vitest_1.expect)(result.exit_code).toBe(0);
|
|
128
|
+
});
|
|
129
|
+
(0, vitest_1.it)("accepts lifecycle sealed-result status values for finalize workers", async () => {
|
|
130
|
+
const packet = (0, worker_packet_js_1.compileFinalizePacket)(WORKER_PACKET_BASE);
|
|
131
|
+
const adapter = new agent_subtask_js_1.AgentSubtaskAdapter(async () => ({
|
|
132
|
+
run_id: "run-001",
|
|
133
|
+
role: "finalize",
|
|
134
|
+
status: "success",
|
|
135
|
+
tracker_reconciliation_ready: true,
|
|
136
|
+
}));
|
|
137
|
+
const result = await adapter.dispatch(packet, { provider: "agent-subtask" });
|
|
138
|
+
(0, vitest_1.expect)(result.exit_code).toBe(0);
|
|
139
|
+
(0, vitest_1.expect)(JSON.parse(result.summary ?? "{}")).toMatchObject({
|
|
140
|
+
role: "finalize",
|
|
141
|
+
status: "success",
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
(0, vitest_1.it)("returns exit_code 1 with error when no dispatcher is configured", async () => {
|
|
145
|
+
const packet = (0, worker_packet_js_1.compileImplPacket)({ ...WORKER_PACKET_BASE, childId: "POL-121" });
|
|
146
|
+
const adapter = new agent_subtask_js_1.AgentSubtaskAdapter(undefined);
|
|
147
|
+
const result = await adapter.dispatch(packet, { provider: "agent-subtask" });
|
|
148
|
+
(0, vitest_1.expect)(result.exit_code).toBe(1);
|
|
149
|
+
(0, vitest_1.expect)(result.stderr).toContain("unavailable");
|
|
150
|
+
});
|
|
151
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.installCliSubtaskBridge = installCliSubtaskBridge;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const loader_js_1 = require("../../config/loader.js");
|
|
7
|
+
const terminal_cli_js_1 = require("./terminal-cli.js");
|
|
8
|
+
function selectBridgeProvider(providers) {
|
|
9
|
+
const preferred = process.env.POLARIS_NATIVE_SUBTASK_PROVIDER?.trim();
|
|
10
|
+
if (preferred && preferred.length > 0 && Object.prototype.hasOwnProperty.call(providers, preferred)) {
|
|
11
|
+
return preferred;
|
|
12
|
+
}
|
|
13
|
+
if (Object.prototype.hasOwnProperty.call(providers, "copilot")) {
|
|
14
|
+
return "copilot";
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
function parseSummaryObject(summary) {
|
|
19
|
+
const trimmed = summary.trim();
|
|
20
|
+
if (trimmed.length === 0) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const parsed = JSON.parse(trimmed);
|
|
25
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)
|
|
26
|
+
? parsed
|
|
27
|
+
: null;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
const firstBrace = trimmed.indexOf("{");
|
|
31
|
+
const lastBrace = trimmed.lastIndexOf("}");
|
|
32
|
+
if (firstBrace >= 0 && lastBrace > firstBrace) {
|
|
33
|
+
const candidate = trimmed.slice(firstBrace, lastBrace + 1);
|
|
34
|
+
try {
|
|
35
|
+
const parsed = JSON.parse(candidate);
|
|
36
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)
|
|
37
|
+
? parsed
|
|
38
|
+
: null;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function normalizeSealedStatus(raw) {
|
|
48
|
+
const status = typeof raw === "string" ? raw.trim().toLowerCase() : "";
|
|
49
|
+
if (status === "done" || status === "success") {
|
|
50
|
+
return "success";
|
|
51
|
+
}
|
|
52
|
+
if (status === "blocked") {
|
|
53
|
+
return "blocked";
|
|
54
|
+
}
|
|
55
|
+
return "failure";
|
|
56
|
+
}
|
|
57
|
+
function writeSealedResultFromSummary(packet, parsedSummary) {
|
|
58
|
+
const resultFile = packet.result_file_contract?.result_file;
|
|
59
|
+
if (!resultFile) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const commit = (typeof parsedSummary["commit"] === "string" && parsedSummary["commit"]) ||
|
|
63
|
+
(typeof parsedSummary["commit_hash"] === "string" && parsedSummary["commit_hash"]) ||
|
|
64
|
+
undefined;
|
|
65
|
+
const validation = parsedSummary["validation"] ?? parsedSummary["validation_summary"];
|
|
66
|
+
const sealedResult = {
|
|
67
|
+
run_id: packet.run_id,
|
|
68
|
+
child_id: packet.active_child,
|
|
69
|
+
status: normalizeSealedStatus(parsedSummary["status"]),
|
|
70
|
+
};
|
|
71
|
+
if (commit) {
|
|
72
|
+
sealedResult["commit"] = commit;
|
|
73
|
+
}
|
|
74
|
+
if (validation !== undefined) {
|
|
75
|
+
sealedResult["validation"] = validation;
|
|
76
|
+
}
|
|
77
|
+
(0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(resultFile), { recursive: true });
|
|
78
|
+
(0, node_fs_1.writeFileSync)(resultFile, JSON.stringify(sealedResult, null, 2), "utf-8");
|
|
79
|
+
}
|
|
80
|
+
function installCliSubtaskBridge(repoRoot) {
|
|
81
|
+
const host = globalThis;
|
|
82
|
+
if (host.__POLARIS_AGENT_SUBTASK_DISPATCH__) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const config = (0, loader_js_1.loadConfig)(repoRoot);
|
|
86
|
+
const execution = config.execution;
|
|
87
|
+
if (!execution || !execution.providers) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const provider = selectBridgeProvider(execution.providers);
|
|
91
|
+
if (!provider) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const adapter = new terminal_cli_js_1.TerminalCliAdapter(execution);
|
|
95
|
+
host.__POLARIS_AGENT_SUBTASK_DISPATCH__ = async ({ packet }) => {
|
|
96
|
+
const result = await adapter.dispatch(packet, { provider });
|
|
97
|
+
const summary = result.summary ?? result.stdout ?? result.stderr ?? "";
|
|
98
|
+
if (result.exit_code !== 0) {
|
|
99
|
+
throw new Error(`CLI subtask bridge provider "${provider}" failed: ${summary || "no summary available"}`);
|
|
100
|
+
}
|
|
101
|
+
const parsedSummary = parseSummaryObject(summary);
|
|
102
|
+
if (!parsedSummary) {
|
|
103
|
+
throw new Error(`CLI subtask bridge provider "${provider}" returned non-JSON summary required for sealed result contract`);
|
|
104
|
+
}
|
|
105
|
+
writeSealedResultFromSummary(packet, parsedSummary);
|
|
106
|
+
return parsedSummary;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAdapter = exports.AgentSubtaskAdapter = exports.TerminalCliAdapter = void 0;
|
|
4
|
+
var terminal_cli_js_1 = require("./terminal-cli.js");
|
|
5
|
+
Object.defineProperty(exports, "TerminalCliAdapter", { enumerable: true, get: function () { return terminal_cli_js_1.TerminalCliAdapter; } });
|
|
6
|
+
var agent_subtask_js_1 = require("./agent-subtask.js");
|
|
7
|
+
Object.defineProperty(exports, "AgentSubtaskAdapter", { enumerable: true, get: function () { return agent_subtask_js_1.AgentSubtaskAdapter; } });
|
|
8
|
+
var registry_js_1 = require("./registry.js");
|
|
9
|
+
Object.defineProperty(exports, "createAdapter", { enumerable: true, get: function () { return registry_js_1.createAdapter; } });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAdapter = createAdapter;
|
|
4
|
+
const agent_subtask_js_1 = require("./agent-subtask.js");
|
|
5
|
+
const terminal_cli_js_1 = require("./terminal-cli.js");
|
|
6
|
+
const SUPPORTED_ADAPTERS = ['terminal-cli', 'agent-subtask'];
|
|
7
|
+
function createAdapter(adapterName, config) {
|
|
8
|
+
switch (adapterName) {
|
|
9
|
+
case 'terminal-cli':
|
|
10
|
+
return new terminal_cli_js_1.TerminalCliAdapter(config);
|
|
11
|
+
case 'agent-subtask':
|
|
12
|
+
return new agent_subtask_js_1.AgentSubtaskAdapter();
|
|
13
|
+
default:
|
|
14
|
+
throw new Error(`Unknown adapter "${adapterName}". ` +
|
|
15
|
+
`Supported adapters: ${SUPPORTED_ADAPTERS.join(', ')}.`);
|
|
16
|
+
}
|
|
17
|
+
}
|