@lsctech/polaris 0.3.29 → 0.4.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.
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadInterview = loadInterview;
4
+ exports.saveInterview = saveInterview;
5
+ exports.loadOrCreate = loadOrCreate;
6
+ exports.applyAnswers = applyAnswers;
7
+ exports.markApproved = markApproved;
8
+ exports.nextUnansweredQuestion = nextUnansweredQuestion;
9
+ const node_fs_1 = require("node:fs");
10
+ const node_path_1 = require("node:path");
11
+ const schema_js_1 = require("./schema.js");
12
+ function interviewPath(repoRoot) {
13
+ return (0, node_path_1.join)(repoRoot, ".polaris", "setup", "interview.json");
14
+ }
15
+ /**
16
+ * Load an existing interview record from disk.
17
+ * Returns null if the file does not exist or cannot be parsed.
18
+ */
19
+ function loadInterview(repoRoot) {
20
+ const path = interviewPath(repoRoot);
21
+ if (!(0, node_fs_1.existsSync)(path))
22
+ return null;
23
+ try {
24
+ return JSON.parse((0, node_fs_1.readFileSync)(path, "utf-8"));
25
+ }
26
+ catch {
27
+ return null;
28
+ }
29
+ }
30
+ /** Persist an interview record to .polaris/setup/interview.json. */
31
+ function saveInterview(repoRoot, record) {
32
+ const path = interviewPath(repoRoot);
33
+ (0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(path), { recursive: true });
34
+ (0, node_fs_1.writeFileSync)(path, `${JSON.stringify(record, null, 2)}\n`, "utf-8");
35
+ }
36
+ /**
37
+ * Load an existing record or create a fresh one.
38
+ * Supports --resume: caller passes the return value to continueInterview.
39
+ */
40
+ function loadOrCreate(repoRoot, now = new Date()) {
41
+ return loadInterview(repoRoot) ?? (0, schema_js_1.createInterviewRecord)(now);
42
+ }
43
+ /** Merge new answers into the record and transition status to "answered" if appropriate. */
44
+ function applyAnswers(record, answers) {
45
+ return {
46
+ ...record,
47
+ answers: { ...record.answers, ...answers },
48
+ status: record.status === "approved" ? "approved" : "answered",
49
+ };
50
+ }
51
+ /** Transition record to "approved" status, recording the approval timestamp. */
52
+ function markApproved(record, now = new Date()) {
53
+ return {
54
+ ...record,
55
+ status: "approved",
56
+ approved_at: now.toISOString(),
57
+ };
58
+ }
59
+ /**
60
+ * Return the next unanswered required question key, or null if all are answered.
61
+ * Used to resume at the right question after a partial run.
62
+ */
63
+ function nextUnansweredQuestion(record) {
64
+ const required = [
65
+ "project_purpose",
66
+ "source_roots",
67
+ "languages",
68
+ "canonical_doc_folders",
69
+ "never_touch",
70
+ "providers_by_role",
71
+ ];
72
+ return required.find((key) => record.answers[key] === undefined) ?? null;
73
+ }
@@ -42,7 +42,7 @@ function getBranch(repoRoot) {
42
42
  }
43
43
  }
44
44
  function normalizeBranchName(branch) {
45
- return branch.toLowerCase().replace(/_/g, "-");
45
+ return branch.toLowerCase().replace(/[_/]/g, "-");
46
46
  }
47
47
  function extractClusterSlug(clusterId) {
48
48
  const match = clusterId.match(/([A-Z]+-\d+)/);
@@ -161,13 +161,14 @@ function checkLibrarianGate(repoRoot, clusterId) {
161
161
  const filesCommitted = result.files_committed ?? [];
162
162
  for (const file of filesCommitted) {
163
163
  const absFile = (0, node_path_1.resolve)(repoRoot, file);
164
+ // Allowed takes precedence over prohibited — a specific allowed path wins over a broad prohibition.
165
+ const allowedMatch = allowedWritePaths.find((pattern) => (0, git_custody_js_1.patternMatchesPath)(pattern, absFile));
166
+ if (allowedMatch)
167
+ continue;
164
168
  const prohibitedMatch = prohibitedWritePaths.find((pattern) => (0, git_custody_js_1.patternMatchesPath)(pattern, absFile));
165
169
  if (prohibitedMatch) {
166
170
  return `Librarian wrote to prohibited path: ${file} (matched pattern: ${prohibitedMatch})`;
167
171
  }
168
- const allowedMatch = allowedWritePaths.find((pattern) => (0, git_custody_js_1.patternMatchesPath)(pattern, absFile));
169
- if (allowedMatch)
170
- continue; // explicitly allowed
171
172
  return `Librarian wrote to out-of-scope path: ${file} (not in allowed_write_paths)`;
172
173
  }
173
174
  try {
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ /**
3
+ * Foreman dispatch — launches the assigned Foreman with a setup-bootstrap
4
+ * packet through the configured execution adapter.
5
+ *
6
+ * Provider selection comes from config (`execution.providerPolicy.foreman`);
7
+ * no provider-specific logic lives here — the adapter handles that.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.dispatchForeman = dispatchForeman;
11
+ const terminal_cli_js_1 = require("./terminal-cli.js");
12
+ /**
13
+ * Validate that the setup-bootstrap packet has checkpoint gate enforcement.
14
+ *
15
+ * This is the "by construction" guard: a packet without a valid checkpoint_gate
16
+ * (or with self_approval_prohibited !== true) cannot be dispatched. Because
17
+ * `generateSetupBootstrapPacket` always sets self_approval_prohibited to true,
18
+ * any packet that fails this check was manually constructed — and is rejected.
19
+ *
20
+ * @throws {Error} if checkpoint_gate is absent or self_approval_prohibited is not true.
21
+ */
22
+ function assertCheckpointGateEnforced(packet) {
23
+ if (!packet.checkpoint_gate || packet.checkpoint_gate.self_approval_prohibited !== true) {
24
+ throw new Error(`Cannot dispatch setup-bootstrap packet "${packet.packet_id}": ` +
25
+ `checkpoint_gate.self_approval_prohibited must be true. ` +
26
+ `Use generateSetupBootstrapPacket() to produce a valid packet.`);
27
+ }
28
+ }
29
+ /**
30
+ * Wraps a SetupBootstrapPacket into a BootstrapPacket-compatible shape
31
+ * that existing adapters can dispatch. The setup-bootstrap fields are
32
+ * carried as context so the foreman receives the full packet.
33
+ */
34
+ function toBootstrapPacket(packet) {
35
+ return {
36
+ schema_version: "1.0",
37
+ run_id: `setup-${packet.mode}-${packet.packet_id}`,
38
+ cluster_id: `setup-${packet.mode}`,
39
+ active_child: "",
40
+ state_file: "",
41
+ telemetry_file: "",
42
+ context: {
43
+ setup_bootstrap: packet,
44
+ },
45
+ };
46
+ }
47
+ /**
48
+ * Dispatch the Foreman with the setup-bootstrap packet.
49
+ *
50
+ * Enforces checkpoint gate presence before dispatch — a packet without
51
+ * self_approval_prohibited: true is rejected, making self-approval
52
+ * impossible by construction.
53
+ *
54
+ * Uses the existing TerminalCliAdapter so provider-specific logic stays
55
+ * in provider configs — this function is provider-neutral.
56
+ */
57
+ async function dispatchForeman(input) {
58
+ assertCheckpointGateEnforced(input.packet);
59
+ const adapter = new terminal_cli_js_1.TerminalCliAdapter(input.executionConfig);
60
+ const bootstrapPacket = toBootstrapPacket(input.packet);
61
+ return adapter.dispatch(bootstrapPacket, {
62
+ provider: input.provider,
63
+ dryRun: input.dryRun,
64
+ });
65
+ }
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createAdapter = exports.AgentSubtaskAdapter = exports.TerminalCliAdapter = void 0;
3
+ exports.dispatchForeman = exports.createAdapter = exports.AgentSubtaskAdapter = exports.TerminalCliAdapter = void 0;
4
4
  var terminal_cli_js_1 = require("./terminal-cli.js");
5
5
  Object.defineProperty(exports, "TerminalCliAdapter", { enumerable: true, get: function () { return terminal_cli_js_1.TerminalCliAdapter; } });
6
6
  var agent_subtask_js_1 = require("./agent-subtask.js");
7
7
  Object.defineProperty(exports, "AgentSubtaskAdapter", { enumerable: true, get: function () { return agent_subtask_js_1.AgentSubtaskAdapter; } });
8
8
  var registry_js_1 = require("./registry.js");
9
9
  Object.defineProperty(exports, "createAdapter", { enumerable: true, get: function () { return registry_js_1.createAdapter; } });
10
+ var foreman_dispatch_js_1 = require("./foreman-dispatch.js");
11
+ Object.defineProperty(exports, "dispatchForeman", { enumerable: true, get: function () { return foreman_dispatch_js_1.dispatchForeman; } });
@@ -250,7 +250,7 @@ function compileImplPacket(input) {
250
250
  `Create exactly ONE git commit: [${input.childId}] ${childTitle}.`,
251
251
  `Do NOT modify open_children or completed_children in ${input.stateFile}. The parent runtime (loop continue) owns that state transition.`,
252
252
  `Append a telemetry event to ${input.telemetryFile}.`,
253
- `Write compact return JSON to stdout (fields: ${exports.IMPL_RETURN_CONTRACT.join(', ')}).`,
253
+ `Write compact return JSON to stdout (fields: ${exports.IMPL_RETURN_CONTRACT.join(', ')}). next_recommended_action MUST be exactly "continue" on success, "stop" on unresolvable blocker, or "investigate" if manual review is needed.`,
254
254
  `TERMINATE SESSION IMMEDIATELY. Do not select or execute the next child.`,
255
255
  ];
256
256
  // Build compact or full prompt; primary_goal uses the structured template.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SUPPORTED_SKILLS = exports.SKILL_ROLE_MAP = void 0;
4
+ exports.generateSetupBootstrapPacket = generateSetupBootstrapPacket;
4
5
  exports.generateSkillPacket = generateSkillPacket;
5
6
  const node_crypto_1 = require("node:crypto");
6
7
  exports.SKILL_ROLE_MAP = {
@@ -10,6 +11,8 @@ exports.SKILL_ROLE_MAP = {
10
11
  promote: "Librarian",
11
12
  triage: "Librarian",
12
13
  review: "Librarian",
14
+ catalog: "Librarian",
15
+ reconcile: "Librarian",
13
16
  };
14
17
  const ROLE_SUMMARIES = {
15
18
  Analyst: "The Analyst gathers evidence, assesses feasibility, and produces implementation-ready plans. The Analyst shapes work but never executes it.",
@@ -258,6 +261,136 @@ function buildReviewPacket() {
258
261
  ],
259
262
  };
260
263
  }
264
+ const SETUP_BOOTSTRAP_CHECKPOINTS = [
265
+ "canon",
266
+ "doc-movement",
267
+ "instruction-files",
268
+ "graph-root",
269
+ "route-scaffold",
270
+ "source-mutation",
271
+ ];
272
+ /**
273
+ * Builds the checkpoint gate that is embedded in every setup-bootstrap packet.
274
+ *
275
+ * Each checkpoint gate entry is a halt instruction — the Foreman MUST stop
276
+ * and surface the gate to the operator before proceeding. Self-approval is
277
+ * structurally impossible: `self_approval_prohibited` is typed as `true` and
278
+ * this function never sets it to anything else.
279
+ */
280
+ function buildCheckpointGate() {
281
+ const gateInstruction = (name) => `HALT at checkpoint "${name}": stop, surface this gate to the operator, and wait for explicit approval before proceeding. You may not self-approve.`;
282
+ return {
283
+ gates: {
284
+ canon: gateInstruction("canon"),
285
+ "doc-movement": gateInstruction("doc-movement"),
286
+ "instruction-files": gateInstruction("instruction-files"),
287
+ "graph-root": gateInstruction("graph-root"),
288
+ "route-scaffold": gateInstruction("route-scaffold"),
289
+ "source-mutation": gateInstruction("source-mutation"),
290
+ },
291
+ self_approval_prohibited: true,
292
+ enforcement_note: "Checkpoint gates are non-optional. The Foreman must halt and surface each gate to the operator. " +
293
+ "Proceeding without explicit operator approval is a protocol violation.",
294
+ };
295
+ }
296
+ function generateSetupBootstrapPacket(mode) {
297
+ return {
298
+ packet_id: (0, node_crypto_1.randomUUID)(),
299
+ packet_kind: "setup-bootstrap",
300
+ active_role: "Foreman",
301
+ role_file: ".polaris/skills/polaris-run/SKILL.md",
302
+ mode,
303
+ authority_boundaries: [
304
+ "Read repository structure and existing configuration files",
305
+ "Create or update Polaris configuration and scaffold files",
306
+ "Dispatch Workers for bounded setup sub-tasks",
307
+ "Coordinate approval checkpoints before advancing to the next setup phase",
308
+ "Write to .polaris/ directories as part of init or adopt setup",
309
+ "Update POLARIS.md and SUMMARY.md within the project root",
310
+ ],
311
+ prohibited_actions: [
312
+ "Mutate source files without an approved checkpoint (unapproved mutation is forbidden)",
313
+ "Implement features directly — all implementation must be delegated to a Worker",
314
+ "Advance past an approval checkpoint without explicit user confirmation",
315
+ "Self-approve any checkpoint — operator approval is mandatory and cannot be delegated to the Foreman",
316
+ "Modify tracker state or issue descriptions during setup",
317
+ ],
318
+ approval_checkpoints: SETUP_BOOTSTRAP_CHECKPOINTS,
319
+ checkpoint_gate: buildCheckpointGate(),
320
+ stop_conditions: [
321
+ "All setup phases complete and scaffold is valid",
322
+ "An approval checkpoint is reached — pause and await user confirmation",
323
+ "A required configuration value is missing and cannot be inferred",
324
+ "A Worker returns a failure result during setup",
325
+ ],
326
+ generated_at: new Date().toISOString(),
327
+ };
328
+ }
329
+ function buildCatalogPacket() {
330
+ return {
331
+ authority_boundaries: [
332
+ "Read packet-scoped POLARIS.md and SUMMARY.md files",
333
+ "Update cognition files only within packet-allowed write paths",
334
+ "Read smartdocs/raw/ and classify documents through supported Polaris CLI commands",
335
+ "Auto-place only high-confidence documents",
336
+ "Leave low-confidence documents in raw when unattended or request operator direction",
337
+ ],
338
+ prohibited_actions: [
339
+ "Modify implementation source code, tests, or configuration",
340
+ "Write outside packet-allowed paths",
341
+ "Auto-place low-confidence documents",
342
+ "Move or copy SmartDocs directly instead of using supported CLI commands",
343
+ "Call polaris loop continue or polaris finalize",
344
+ "Git push or create a pull request",
345
+ ],
346
+ allowed_outputs: [
347
+ "Updated POLARIS.md and SUMMARY.md files in packet-allowed paths",
348
+ "Classified documents placed through supported Polaris CLI commands",
349
+ "A sealed local cognition and document commit",
350
+ "A report of deferred low-confidence documents",
351
+ ],
352
+ deliverables: [
353
+ "Packet-scoped cognition reconciled",
354
+ "Raw documents classified or explicitly deferred",
355
+ "All changes recorded in one sealed local commit",
356
+ ],
357
+ stop_conditions: [
358
+ "All packet-scoped cognition and raw documents processed",
359
+ "A required command is unsupported by the installed CLI",
360
+ "A requested write falls outside packet-allowed paths",
361
+ "An unresolved conflict requires operator direction",
362
+ ],
363
+ };
364
+ }
365
+ function buildReconcilePacket() {
366
+ return {
367
+ authority_boundaries: [
368
+ "Read packet-scoped folders and their POLARIS.md and SUMMARY.md files",
369
+ "Update cognition files only within packet-allowed write paths",
370
+ "Create one sealed local cognition commit",
371
+ ],
372
+ prohibited_actions: [
373
+ "Modify implementation source code, tests, or configuration",
374
+ "Move, ingest, classify, or promote documents",
375
+ "Write outside packet-allowed paths",
376
+ "Call polaris loop continue or polaris finalize",
377
+ "Git push or create a pull request",
378
+ ],
379
+ allowed_outputs: [
380
+ "Updated POLARIS.md and SUMMARY.md files in packet-allowed paths",
381
+ "A sealed local cognition commit",
382
+ ],
383
+ deliverables: [
384
+ "Packet-scoped cognition reconciled with completed work",
385
+ "All cognition changes recorded in one sealed local commit",
386
+ ],
387
+ stop_conditions: [
388
+ "All packet-scoped cognition reconciled",
389
+ "A requested write falls outside packet-allowed paths",
390
+ "Work evidence is missing or contradictory",
391
+ ],
392
+ };
393
+ }
261
394
  function generateSkillPacket(skillName, config) {
262
395
  const active_role = exports.SKILL_ROLE_MAP[skillName];
263
396
  const role_summary = ROLE_SUMMARIES[active_role];
@@ -288,6 +421,12 @@ function generateSkillPacket(skillName, config) {
288
421
  case "review":
289
422
  body = buildReviewPacket();
290
423
  break;
424
+ case "catalog":
425
+ body = buildCatalogPacket();
426
+ break;
427
+ case "reconcile":
428
+ body = buildReconcilePacket();
429
+ break;
291
430
  }
292
431
  return {
293
432
  packet_id,
@@ -299,4 +438,13 @@ function generateSkillPacket(skillName, config) {
299
438
  generated_at,
300
439
  };
301
440
  }
302
- exports.SUPPORTED_SKILLS = ["analyze", "run", "ingest", "promote", "triage", "review"];
441
+ exports.SUPPORTED_SKILLS = [
442
+ "analyze",
443
+ "run",
444
+ "ingest",
445
+ "promote",
446
+ "triage",
447
+ "review",
448
+ "catalog",
449
+ "reconcile",
450
+ ];
@@ -10,11 +10,9 @@
10
10
  * node tools.js polaris_loop_status
11
11
  */
12
12
 
13
- 'use strict';
14
-
15
- const { spawnSync } = require('child_process');
16
- const fs = require('fs');
17
- const path = require('path');
13
+ let spawnSync;
14
+ let fs;
15
+ let path;
18
16
 
19
17
  // ── binary resolution ──────────────────────────────────────────────────────
20
18
 
@@ -171,21 +169,32 @@ function unknownTool(tool) {
171
169
 
172
170
  // ── dispatch ───────────────────────────────────────────────────────────────
173
171
 
174
- const [, , tool, ...rest] = process.argv;
175
-
176
- switch (tool) {
177
- case 'polaris_run':
178
- operatorOnly('polaris_run', 'polaris run <issue_id>');
179
- break;
180
- case 'polaris_loop_continue':
181
- operatorOnly('polaris_loop_continue', 'polaris loop continue');
182
- break;
183
- case 'polaris_status':
184
- polarisStatus('polaris_status', ['status', '--json']);
185
- break;
186
- case 'polaris_loop_status':
187
- polarisStatus('polaris_loop_status', ['loop', 'status', '--json']);
188
- break;
189
- default:
190
- unknownTool(tool);
172
+ async function main() {
173
+ ({ spawnSync } = await import('node:child_process'));
174
+ fs = await import('node:fs');
175
+ path = await import('node:path');
176
+
177
+ const [, , tool] = process.argv;
178
+
179
+ switch (tool) {
180
+ case 'polaris_run':
181
+ operatorOnly('polaris_run', 'polaris run <issue_id>');
182
+ break;
183
+ case 'polaris_loop_continue':
184
+ operatorOnly('polaris_loop_continue', 'polaris loop continue');
185
+ break;
186
+ case 'polaris_status':
187
+ polarisStatus('polaris_status', ['status', '--json']);
188
+ break;
189
+ case 'polaris_loop_status':
190
+ polarisStatus('polaris_loop_status', ['loop', 'status', '--json']);
191
+ break;
192
+ default:
193
+ unknownTool(tool);
194
+ }
191
195
  }
196
+
197
+ main().catch((error) => {
198
+ console.log(JSON.stringify({ error: error instanceof Error ? error.message : String(error) }));
199
+ process.exit(1);
200
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lsctech/polaris",
3
- "version": "0.3.29",
3
+ "version": "0.4.0",
4
4
  "description": "Polaris — standalone taskchain orchestration framework for governed AI agent workflows",
5
5
  "bin": {
6
6
  "polaris": "dist/cli/index.js",
@@ -22,7 +22,7 @@
22
22
  "node": ">=22.0.0"
23
23
  },
24
24
  "scripts": {
25
- "build": "tsc && rm -rf dist/workspace && cp -r src/workspace dist/workspace",
25
+ "build": "tsc && rm -rf dist/workspace && cp -r src/workspace dist/workspace && cp .codex/plugins/polaris/skills/polaris-tools/tools.js dist/workspace/.polaris/skills/polaris-tools/tools.js",
26
26
  "lint": "tsc --noEmit",
27
27
  "typecheck": "tsc --noEmit --project tsconfig.typecheck.json",
28
28
  "test": "vitest run",