@cassiomc1/forgeloop 1.3.0 → 1.6.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.
Files changed (163) hide show
  1. package/.github/copilot-instructions.md +1 -0
  2. package/AGENTS.md +1 -0
  3. package/CLAUDE.md +1 -0
  4. package/DOCS_INDEX.md +20 -8
  5. package/EXECUTION_STATE.md +60 -0
  6. package/LOOP_ENGINEERING.md +135 -5
  7. package/LOOP_SYSTEM_DESIGN.md +54 -1
  8. package/PROTOCOL_INTEGRATION.md +87 -0
  9. package/QUALITY_SCORECARD.md +2 -0
  10. package/README.md +69 -9
  11. package/TERMINOLOGY.md +15 -0
  12. package/THIRD_PARTY_NOTICES.md +30 -0
  13. package/THREAT_MODEL.md +59 -1
  14. package/docs/ARTIFACT_REFERENCE.md +183 -0
  15. package/docs/CLI_REFERENCE.md +391 -6
  16. package/docs/CROSS_HARNESS_CONTINUITY.md +23 -0
  17. package/docs/DIAGNOSTIC_MODEL.md +181 -0
  18. package/docs/DOCUMENTATION_GUIDE.md +36 -13
  19. package/docs/EXECUTION_TRACE.md +76 -0
  20. package/docs/GETTING_STARTED.md +1 -0
  21. package/docs/MCP.md +159 -0
  22. package/docs/RECIPES.md +149 -0
  23. package/docs/RELEASE_CHECKLIST_1_4.md +38 -0
  24. package/docs/RELEASE_CHECKLIST_1_5_MCP.md +78 -0
  25. package/docs/TROUBLESHOOTING.md +217 -3
  26. package/docs/UNIVERSAL_INTEGRATION.md +48 -0
  27. package/docs/assets/diagrams/forgeloop-engineering-flow.html +13797 -0
  28. package/docs/assets/diagrams/forgeloop-engineering-flow.receipt.json +37 -0
  29. package/docs/assets/diagrams/forgeloop-engineering-flow.svg +5002 -0
  30. package/docs/diagrams/README.md +55 -0
  31. package/docs/diagrams/forgeloop-engineering-flow.workflow.json +122 -0
  32. package/docs/diagrams/manifest.json +42 -0
  33. package/docs/diagrams/reviews/forgeloop-engineering-flow.review.json +20 -0
  34. package/package.json +21 -8
  35. package/schemas/action.schema.json +100 -0
  36. package/schemas/approval.schema.json +51 -0
  37. package/schemas/capability-policy.schema.json +41 -0
  38. package/schemas/diagnostic-case.schema.json +85 -0
  39. package/schemas/execution-receipt.schema.json +16 -0
  40. package/schemas/hypothesis-disposition.schema.json +16 -0
  41. package/schemas/intervention.schema.json +27 -0
  42. package/schemas/policy-lock.schema.json +1 -0
  43. package/schemas/policy-snapshot.schema.json +2 -0
  44. package/schemas/task-recovery.schema.json +61 -0
  45. package/schemas/trajectory-evaluation.schema.json +64 -0
  46. package/schemas/trajectory-scenario.schema.json +42 -0
  47. package/src/cli.js +267 -347
  48. package/src/commands/action-authorize.js +41 -0
  49. package/src/commands/action-propose.js +10 -0
  50. package/src/commands/action-reconcile.js +10 -0
  51. package/src/commands/action-record.js +47 -0
  52. package/src/commands/action-show.js +10 -0
  53. package/src/commands/action-verify.js +10 -0
  54. package/src/commands/advance.js +7 -2
  55. package/src/commands/approval-request.js +64 -0
  56. package/src/commands/approval-resolve.js +10 -0
  57. package/src/commands/audit.js +5 -0
  58. package/src/commands/baseline.js +3 -3
  59. package/src/commands/eval.js +6 -0
  60. package/src/commands/history.js +18 -0
  61. package/src/commands/init.js +2 -2
  62. package/src/commands/inspect.js +55 -0
  63. package/src/commands/metrics.js +7 -0
  64. package/src/commands/next.js +8 -2
  65. package/src/commands/policy-discover.js +2 -2
  66. package/src/commands/progress.js +6 -2
  67. package/src/commands/record-diagnosis.js +37 -1
  68. package/src/commands/record-hypothesis-disposition.js +45 -0
  69. package/src/commands/record-intervention.js +35 -0
  70. package/src/commands/reflect.js +38 -0
  71. package/src/commands/report.js +9 -1
  72. package/src/commands/run-action.js +18 -0
  73. package/src/commands/status.js +17 -0
  74. package/src/commands/task-create.js +39 -1
  75. package/src/commands/task-list.js +14 -1
  76. package/src/commands/task-lock-status.js +2 -2
  77. package/src/commands/task-recover.js +202 -0
  78. package/src/commands/task-repair-legacy-recovery.js +417 -0
  79. package/src/commands/task-resume.js +172 -0
  80. package/src/commands/task-scope.js +23 -4
  81. package/src/commands/task-show.js +18 -4
  82. package/src/commands/trace.js +34 -0
  83. package/src/commands/validate-protocol.js +40 -15
  84. package/src/core/action-authorization.js +106 -0
  85. package/src/core/action-constants.js +86 -0
  86. package/src/core/action-execution.js +105 -0
  87. package/src/core/action-ledger-projection.js +302 -0
  88. package/src/core/action-model.js +581 -0
  89. package/src/core/action-readiness.js +141 -0
  90. package/src/core/action-reconciliation-policy.js +49 -0
  91. package/src/core/action-reconciliation.js +66 -0
  92. package/src/core/action-verification.js +111 -0
  93. package/src/core/actions.js +462 -0
  94. package/src/core/approvals.js +405 -0
  95. package/src/core/artifact-registry.js +60 -0
  96. package/src/core/audit.js +45 -4
  97. package/src/core/bundles.js +30 -0
  98. package/src/core/capability-policy.js +226 -0
  99. package/src/core/cli-command-definitions.js +260 -5
  100. package/src/core/command-executors.js +543 -0
  101. package/src/core/command-input.js +107 -0
  102. package/src/core/command-runtime.js +117 -0
  103. package/src/core/completion-artifacts.js +39 -15
  104. package/src/core/completion-ownership.js +88 -0
  105. package/src/core/completion-recovery-rebind.js +194 -0
  106. package/src/core/completion.js +70 -0
  107. package/src/core/continuity-reconciliation.js +24 -5
  108. package/src/core/diagnostic-model.js +396 -0
  109. package/src/core/diagnostic-projection.js +51 -0
  110. package/src/core/diagnostic-record.js +360 -0
  111. package/src/core/error-codes.js +461 -1
  112. package/src/core/events.js +171 -2
  113. package/src/core/execution-prerequisites.js +4 -1
  114. package/src/core/execution.js +26 -188
  115. package/src/core/failure-signature.js +70 -0
  116. package/src/core/failure-surface.js +57 -0
  117. package/src/core/filesystem.js +55 -6
  118. package/src/core/history.js +110 -0
  119. package/src/core/hypothesis-projection.js +85 -0
  120. package/src/core/information-gain-projection.js +283 -0
  121. package/src/core/information-gain.js +138 -0
  122. package/src/core/inspect.js +132 -7
  123. package/src/core/integration-invocation-policy.js +217 -0
  124. package/src/core/integration-limits.js +20 -0
  125. package/src/core/integration-resources.js +178 -0
  126. package/src/core/next-action-model.js +94 -0
  127. package/src/core/next-action.js +490 -3
  128. package/src/core/phase.js +42 -22
  129. package/src/core/policy-engine.js +113 -6
  130. package/src/core/preflight-consistency.js +31 -5
  131. package/src/core/preflight.js +19 -2
  132. package/src/core/prepared-execution.js +227 -0
  133. package/src/core/progress.js +41 -4
  134. package/src/core/project-root.js +21 -0
  135. package/src/core/protocol-info.js +61 -0
  136. package/src/core/protocol.js +14 -0
  137. package/src/core/receipt.js +1 -0
  138. package/src/core/reconcile-closure.js +35 -10
  139. package/src/core/recovery-history.js +116 -0
  140. package/src/core/reflection.js +305 -0
  141. package/src/core/resumability.js +57 -3
  142. package/src/core/schema-validation.js +9 -0
  143. package/src/core/strategy-analysis.js +97 -0
  144. package/src/core/task-claim-state.js +272 -0
  145. package/src/core/task-command.js +5 -1
  146. package/src/core/task-conflict-inspection.js +321 -0
  147. package/src/core/task-context.js +32 -29
  148. package/src/core/task-discovery.js +14 -1
  149. package/src/core/task-lock.js +216 -22
  150. package/src/core/task-paths.js +31 -2
  151. package/src/core/task-recovery-migration.js +192 -0
  152. package/src/core/task-recovery.js +205 -0
  153. package/src/core/task-scope.js +33 -1
  154. package/src/core/task-snapshot.js +53 -0
  155. package/src/core/templates.js +9 -0
  156. package/src/core/trace.js +548 -0
  157. package/src/core/trajectory-evaluation.js +71 -0
  158. package/src/core/trajectory-metrics.js +80 -0
  159. package/src/core/transaction.js +36 -2
  160. package/src/core/work-state.js +10 -5
  161. package/src/integration.js +47 -0
  162. package/docs/assets/forgeloop-flow.svg +0 -1
  163. package/docs/forgeloop-flow.mmd +0 -51
package/src/cli.js CHANGED
@@ -4,53 +4,71 @@ import { readFile } from "node:fs/promises";
4
4
  import path from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
 
7
- import { runDoctor } from "./commands/doctor.js";
8
- import { formatStatusResult, runStatus } from "./commands/status.js";
9
- import { formatValidateStateResult, runValidateState } from "./commands/validate-state.js";
10
- import { formatClearStateResult, runClearState } from "./commands/clear-state.js";
11
- import { formatInspectResult, inspectTarget } from "./commands/inspect.js";
12
- import { runInit } from "./commands/init.js";
13
- import { formatRouteResult, runRoute } from "./commands/route.js";
14
- import { runValidateReceipt } from "./commands/validate-receipt.js";
15
- import { formatValidateProtocolResult, runValidateProtocol } from "./commands/validate-protocol.js";
16
- import { runUpdate } from "./commands/update.js";
17
- import { formatActivateResult, runActivate } from "./commands/activate.js";
18
- import { formatAdvanceResult, runAdvance } from "./commands/advance.js";
19
- import { formatPreflightResult, runPreflight } from "./commands/preflight.js";
20
- import { formatCompleteResult, runComplete } from "./commands/complete.js";
21
- import { formatAuditResult, runAudit } from "./commands/audit.js";
22
- import { formatReportResult, runReport } from "./commands/report.js";
23
- import { formatPolicyResult, runPolicy } from "./commands/policy.js";
24
- import { formatPolicyDiscoverResult, runPolicyDiscover } from "./commands/policy-discover.js";
25
- import { formatPolicyStatusResult, runPolicyStatus } from "./commands/policy-status.js";
26
- import { formatPolicyDiffResult, runPolicyDiff } from "./commands/policy-diff.js";
27
- import { formatRuleVerifyResult, runRuleVerify } from "./commands/rule-verify.js";
28
- import { formatBaselineResult, runBaseline } from "./commands/baseline.js";
29
- import { formatProfileInterviewResult, runProfileInterview } from "./commands/profile-interview.js";
30
- import { formatBundleResult, runBundle } from "./commands/bundle.js";
31
- import { formatPrepareCompletionResult, runPrepareCompletion } from "./commands/prepare-completion.js";
32
- import { formatRecordCheckResult, runRecordCheck } from "./commands/record-check.js";
33
- import { formatRunCheckResult, runCheck } from "./commands/run-check.js";
34
- import { formatReconcileClosureResult, reconcileClosure } from "./commands/reconcile-closure.js";
35
- import { formatRecordTerminalResult, runRecordTerminalResult } from "./commands/record-terminal-result.js";
36
- import { formatRecordDiagnosisResult, runRecordDiagnosis } from "./commands/record-diagnosis.js";
37
- import { formatProgressResult, runProgress } from "./commands/progress.js";
38
- import { formatRecordDecisionCriterionResult, runRecordDecisionCriterion } from "./commands/record-decision-criterion.js";
39
- import { formatNextActionResult, runNext } from "./commands/next.js";
40
- import { formatContinuityResult, runContinuity } from "./commands/continuity.js";
41
- import { formatRecordContinuityResult, runRecordContinuity } from "./commands/record-continuity.js";
42
- import { formatReconcileContinuityResult, runReconcileContinuity } from "./commands/reconcile-continuity.js";
43
- import { formatClearContinuityResult, runClearContinuity } from "./commands/clear-continuity.js";
44
- import { formatTaskCreateResult, runTaskCreate } from "./commands/task-create.js";
45
- import { formatTaskListResult, runTaskList } from "./commands/task-list.js";
46
- import { formatTaskShowResult, runTaskShow } from "./commands/task-show.js";
47
- import { formatTaskScopeResult, runTaskScope } from "./commands/task-scope.js";
48
- import { formatTaskMigrateResult, runTaskMigrate } from "./commands/task-migrate.js";
49
- import { formatMigrateProtocolResult, runMigrateProtocol } from "./commands/migrate-protocol.js";
50
- import { formatTaskUnlockResult, runTaskUnlock } from "./commands/task-unlock.js";
51
- import { formatTaskLockStatusResult, runTaskLockStatus } from "./commands/task-lock-status.js";
52
- import { formatProtocolInfoResult, runProtocolInfo } from "./commands/protocol-info.js";
53
- import { continuityOptionDefaults, validateContinuityOptions } from "./core/continuity-cli-options.js";
7
+ import { formatStatusResult } from "./commands/status.js";
8
+ import { formatValidateStateResult } from "./commands/validate-state.js";
9
+ import { formatClearStateResult } from "./commands/clear-state.js";
10
+ import { formatInspectResult } from "./commands/inspect.js";
11
+ import { formatRouteResult } from "./commands/route.js";
12
+ import { formatValidateProtocolResult } from "./commands/validate-protocol.js";
13
+ import { formatActivateResult } from "./commands/activate.js";
14
+ import { formatAdvanceResult } from "./commands/advance.js";
15
+ import { formatPreflightResult } from "./commands/preflight.js";
16
+ import { formatCompleteResult } from "./commands/complete.js";
17
+ import { formatAuditResult } from "./commands/audit.js";
18
+ import { formatReportResult } from "./commands/report.js";
19
+ import { formatPolicyResult } from "./commands/policy.js";
20
+ import { formatPolicyDiscoverResult } from "./commands/policy-discover.js";
21
+ import { formatPolicyStatusResult } from "./commands/policy-status.js";
22
+ import { formatPolicyDiffResult } from "./commands/policy-diff.js";
23
+ import { formatRuleVerifyResult } from "./commands/rule-verify.js";
24
+ import { formatBaselineResult } from "./commands/baseline.js";
25
+ import { formatProfileInterviewResult } from "./commands/profile-interview.js";
26
+ import { formatBundleResult } from "./commands/bundle.js";
27
+ import { formatPrepareCompletionResult } from "./commands/prepare-completion.js";
28
+ import { formatRecordCheckResult } from "./commands/record-check.js";
29
+ import { formatRunCheckResult } from "./commands/run-check.js";
30
+ import { formatRunActionResult } from "./commands/run-action.js";
31
+ import { formatActionProposeResult } from "./commands/action-propose.js";
32
+ import { formatActionRecordResult } from "./commands/action-record.js";
33
+ import { formatActionAuthorizeResult } from "./commands/action-authorize.js";
34
+ import { formatActionVerifyResult } from "./commands/action-verify.js";
35
+ import { formatActionShowResult } from "./commands/action-show.js";
36
+ import { formatActionReconcileResult } from "./commands/action-reconcile.js";
37
+ import { formatMetricsResult } from "./commands/metrics.js";
38
+ import { formatEvalResult } from "./commands/eval.js";
39
+ import { formatApprovalRequestResult } from "./commands/approval-request.js";
40
+ import { formatApprovalResolveResult } from "./commands/approval-resolve.js";
41
+ import { formatReconcileClosureResult } from "./commands/reconcile-closure.js";
42
+ import { formatRecordTerminalResult } from "./commands/record-terminal-result.js";
43
+ import { formatRecordDiagnosisResult } from "./commands/record-diagnosis.js";
44
+ import { formatRecordInterventionResult } from "./commands/record-intervention.js";
45
+ import { formatRecordHypothesisDispositionResult } from "./commands/record-hypothesis-disposition.js";
46
+ import { formatHistoryResult } from "./commands/history.js";
47
+ import { formatTraceResult } from "./commands/trace.js";
48
+ import { formatReflectResult } from "./commands/reflect.js";
49
+ import { formatProgressResult } from "./commands/progress.js";
50
+ import { formatRecordDecisionCriterionResult } from "./commands/record-decision-criterion.js";
51
+ import { formatNextActionResult } from "./commands/next.js";
52
+ import { formatContinuityResult } from "./commands/continuity.js";
53
+ import { formatRecordContinuityResult } from "./commands/record-continuity.js";
54
+ import { formatReconcileContinuityResult } from "./commands/reconcile-continuity.js";
55
+ import { formatClearContinuityResult } from "./commands/clear-continuity.js";
56
+ import { formatTaskCreateResult } from "./commands/task-create.js";
57
+ import { formatTaskListResult } from "./commands/task-list.js";
58
+ import { formatTaskShowResult } from "./commands/task-show.js";
59
+ import { formatTaskScopeResult } from "./commands/task-scope.js";
60
+ import { formatTaskMigrateResult } from "./commands/task-migrate.js";
61
+ import { formatMigrateProtocolResult } from "./commands/migrate-protocol.js";
62
+ import { formatTaskUnlockResult } from "./commands/task-unlock.js";
63
+ import { formatTaskRecoverResult } from "./commands/task-recover.js";
64
+ import { formatTaskResumeResult } from "./commands/task-resume.js";
65
+ import {
66
+ formatTaskRepairLegacyRecoveryResult,
67
+ } from "./commands/task-repair-legacy-recovery.js";
68
+ import { formatTaskLockStatusResult } from "./commands/task-lock-status.js";
69
+ import { formatProtocolInfoResult } from "./commands/protocol-info.js";
70
+ import { defaultCommandInputValues, validateForgeLoopCommandInput } from "./core/command-input.js";
71
+ import { COMMAND_EXECUTORS } from "./core/command-executors.js";
54
72
  import { resolveTarget } from "./core/filesystem.js";
55
73
  import { getPackageRoot } from "./core/templates.js";
56
74
  import { CLI_COMMAND_DEFINITIONS, buildOptionLookup, getPositionalDefinitions } from "./core/cli-command-definitions.js";
@@ -196,48 +214,7 @@ export function discoverCommand(argv) {
196
214
  }
197
215
 
198
216
  export function parseCliSyntax(argv) {
199
- const options = {
200
- path: ".",
201
- dryRun: false,
202
- json: false,
203
- strict: false,
204
- fix: false,
205
- adopt: [],
206
- work: null,
207
- surfaces: [],
208
- risks: [],
209
- platforms: [],
210
- behaviorChange: false,
211
- executableChange: false,
212
- to: null,
213
- file: null,
214
- contractFile: null,
215
- routeFile: null,
216
- stateFile: null,
217
- receiptFile: null,
218
- continuityFile: null,
219
- ...continuityOptionDefaults(),
220
- taskBriefFiles: [],
221
- delegatedResultFiles: [],
222
- checkId: null,
223
- checkKind: null,
224
- checkRequirement: null,
225
- checkStatus: null,
226
- checkEvidenceKind: null,
227
- checkCommand: null,
228
- checkResult: null,
229
- checkExitCode: null,
230
- checkDetails: null,
231
- checkExecutionRef: null,
232
- checkProvenance: null,
233
- commandArgv: [],
234
- checkType: null,
235
- checkSource: null,
236
- policy: null,
237
- task: null,
238
- help: false,
239
- version: false,
240
- };
217
+ const options = defaultCommandInputValues();
241
218
 
242
219
  const command = discoverCommand(argv);
243
220
  const bootstrapLookup = buildOptionLookup(null);
@@ -314,53 +291,7 @@ export function parseCliSyntax(argv) {
314
291
  }
315
292
 
316
293
  export function validateCliSemantics({ command, options } = {}) {
317
- if (!command) return;
318
-
319
- if (command === "policy" && !options.policy) {
320
- throw new Error("policy requires a name");
321
- }
322
- if (command !== "policy" && options.policy) {
323
- throw new Error(`Policy name is not valid for ${command}`);
324
- }
325
- if (command === "bundle" && !options.task) {
326
- throw new Error("bundle requires --task");
327
- }
328
- if (command === "task-create" && !options.task) {
329
- throw new Error("task-create requires --task");
330
- }
331
-
332
- validateContinuityOptions(command, options);
333
-
334
- if (command === "record-check" && !options.help) {
335
- if (!options.checkId) throw new Error("record-check requires --id");
336
- if (!options.checkRequirement) throw new Error("record-check requires --requirement");
337
- if (!options.checkStatus) throw new Error("record-check requires --status");
338
- if (!options.checkEvidenceKind) throw new Error("record-check requires --evidence-kind");
339
- if (!options.checkCommand && !options.checkResult) throw new Error("record-check requires --command or --result");
340
- }
341
- if (command === "run-check" && !options.help) {
342
- if (!options.checkId) throw new Error("run-check requires --id");
343
- if (!options.checkRequirement) throw new Error("run-check requires --requirement");
344
- if (options.checkKind || options.checkStatus || options.checkEvidenceKind || options.checkCommand
345
- || options.checkResult || options.checkExitCode !== null || options.checkExecutionRef || options.checkProvenance) {
346
- throw new Error("run-check accepts only --id, --requirement, --details, --timeout-ms, and -- <argv>");
347
- }
348
- if (!Array.isArray(options.commandArgv) || options.commandArgv.length === 0) {
349
- throw new Error("run-check requires -- followed by an exact command argv");
350
- }
351
- }
352
- if (command === "reconcile-closure" && !options.help) {
353
- if (!options.task) throw new Error("reconcile-closure requires --task");
354
- if (!options.checkId) throw new Error("reconcile-closure requires --id");
355
- if (!options.checkRequirement) throw new Error("reconcile-closure requires --requirement");
356
- if (options.checkKind || options.checkStatus || options.checkEvidenceKind || options.checkCommand
357
- || options.checkResult || options.checkExitCode !== null || options.checkExecutionRef || options.checkProvenance) {
358
- throw new Error("reconcile-closure accepts only --id, --requirement, --details, and -- <argv>");
359
- }
360
- if (!Array.isArray(options.commandArgv) || options.commandArgv.length === 0) {
361
- throw new Error("reconcile-closure requires -- followed by an exact command argv");
362
- }
363
- }
294
+ validateForgeLoopCommandInput({ command, input: options, help: options?.help ?? false });
364
295
  }
365
296
 
366
297
  export function parseArgs(argv) {
@@ -383,25 +314,23 @@ function printActions(actions) {
383
314
  }
384
315
  }
385
316
 
317
+ function renderJsonOr(options, result, formatter) {
318
+ console.log(options.json ? JSON.stringify(result, null, 2) : formatter(result));
319
+ }
320
+
386
321
  export const COMMAND_HANDLERS = Object.freeze({
387
322
  "protocol-info": async ({ packageVersion, options }) => {
388
- const result = await runProtocolInfo({ packageVersion });
389
- console.log(options.json ? JSON.stringify(result, null, 2) : formatProtocolInfoResult(result));
323
+ const { result } = await COMMAND_EXECUTORS["protocol-info"]({ packageVersion, options });
324
+ renderJsonOr(options, result, formatProtocolInfoResult);
390
325
  return 0;
391
326
  },
392
327
  init: async ({ target, packageRoot, packageVersion, options }) => {
393
- const result = await runInit({ target, dryRun: options.dryRun, packageRoot, packageVersion });
328
+ const { result } = await COMMAND_EXECUTORS.init({ target, packageRoot, packageVersion, options });
394
329
  printActions(result.actions);
395
330
  return 0;
396
331
  },
397
332
  doctor: async ({ target, packageRoot, options }) => {
398
- const result = await runDoctor({
399
- target,
400
- packageRoot,
401
- adoptPaths: options.adopt,
402
- strict: options.strict,
403
- fix: options.fix,
404
- });
333
+ const { result } = await COMMAND_EXECUTORS.doctor({ target, packageRoot, options });
405
334
  if (options.json) {
406
335
  console.log(JSON.stringify(result, null, 2));
407
336
  } else {
@@ -413,328 +342,319 @@ export const COMMAND_HANDLERS = Object.freeze({
413
342
  return result.ok ? 0 : 1;
414
343
  },
415
344
  route: async ({ target, packageRoot, options }) => {
416
- const result = await runRoute({
417
- target,
418
- packageRoot,
419
- workType: options.work,
420
- surfaces: options.surfaces,
421
- risks: options.risks,
422
- platforms: options.platforms,
423
- behaviorChange: options.behaviorChange,
424
- executableChange: options.executableChange,
425
- taskId: options.task,
426
- });
427
- console.log(options.json ? JSON.stringify(result, null, 2) : formatRouteResult(result));
345
+ const { result } = await COMMAND_EXECUTORS.route({ target, packageRoot, options });
346
+ renderJsonOr(options, result, formatRouteResult);
428
347
  return 0;
429
348
  },
430
349
  activate: async ({ target, packageRoot, options }) => {
431
- const result = await runActivate({ target, packageRoot });
432
- console.log(options.json ? JSON.stringify(result, null, 2) : formatActivateResult(result));
350
+ const { result } = await COMMAND_EXECUTORS.activate({ target, packageRoot, options });
351
+ renderJsonOr(options, result, formatActivateResult);
433
352
  return 0;
434
353
  },
435
354
  preflight: async ({ target, packageRoot, options }) => {
436
- const result = await runPreflight({ target, packageRoot, strict: options.strict, taskId: options.task });
437
- console.log(options.json ? JSON.stringify(result, null, 2) : formatPreflightResult(result));
438
- return result.status === "READY" ? 0 : 1;
355
+ const { result, exitCode } = await COMMAND_EXECUTORS.preflight({ target, packageRoot, options });
356
+ renderJsonOr(options, result, formatPreflightResult);
357
+ return exitCode;
439
358
  },
440
359
  advance: async ({ target, packageRoot, options }) => {
441
- const result = await runAdvance({ target, packageRoot, to: options.to, taskId: options.task });
442
- console.log(options.json ? JSON.stringify(result, null, 2) : formatAdvanceResult(result));
360
+ const { result } = await COMMAND_EXECUTORS.advance({ target, packageRoot, options });
361
+ renderJsonOr(options, result, formatAdvanceResult);
443
362
  return 0;
444
363
  },
445
364
  next: async ({ target, packageRoot, options }) => {
446
- const result = await runNext({ target, packageRoot, taskId: options.task });
447
- console.log(options.json ? JSON.stringify(result, null, 2) : formatNextActionResult(result));
365
+ const { result } = await COMMAND_EXECUTORS.next({ target, packageRoot, options });
366
+ renderJsonOr(options, result, formatNextActionResult);
448
367
  return 0;
449
368
  },
450
369
  continuity: async ({ target, packageRoot, options }) => {
451
- const result = await runContinuity({ target, packageRoot, taskId: options.task });
452
- console.log(options.json ? JSON.stringify(result, null, 2) : formatContinuityResult(result));
370
+ const { result } = await COMMAND_EXECUTORS.continuity({ target, packageRoot, options });
371
+ renderJsonOr(options, result, formatContinuityResult);
453
372
  return 0;
454
373
  },
455
374
  "record-continuity": async ({ target, packageRoot, options }) => {
456
- const result = await runRecordContinuity({
457
- target, packageRoot,
458
- focusId: options.continuityFocusId,
459
- focusSummary: options.continuityFocusSummary,
460
- remaining: options.continuityRemaining,
461
- knownIssues: options.continuityKnownIssues,
462
- changedAreas: options.continuityChangedAreas,
463
- inspectFirst: options.continuityInspectFirst,
464
- resumeNote: options.continuityResumeNote,
465
- taskId: options.task,
466
- });
467
- console.log(options.json ? JSON.stringify(result, null, 2) : formatRecordContinuityResult(result));
375
+ const { result } = await COMMAND_EXECUTORS["record-continuity"]({ target, packageRoot, options });
376
+ renderJsonOr(options, result, formatRecordContinuityResult);
468
377
  return 0;
469
378
  },
470
379
  "reconcile-continuity": async ({ target, packageRoot, options }) => {
471
- const result = await runReconcileContinuity({ target, packageRoot, taskId: options.task });
472
- console.log(options.json ? JSON.stringify(result, null, 2) : formatReconcileContinuityResult(result));
380
+ const { result } = await COMMAND_EXECUTORS["reconcile-continuity"]({ target, packageRoot, options });
381
+ renderJsonOr(options, result, formatReconcileContinuityResult);
473
382
  return 0;
474
383
  },
475
384
  "clear-continuity": async ({ target, options }) => {
476
- const result = await runClearContinuity({ target, taskId: options.task });
477
- console.log(options.json ? JSON.stringify(result, null, 2) : formatClearContinuityResult(result));
385
+ const { result } = await COMMAND_EXECUTORS["clear-continuity"]({ target, options });
386
+ renderJsonOr(options, result, formatClearContinuityResult);
478
387
  return 0;
479
388
  },
480
389
  "prepare-completion": async ({ target, packageRoot, options }) => {
481
- const result = await runPrepareCompletion({ target, packageRoot, taskId: options.task });
482
- console.log(options.json ? JSON.stringify(result, null, 2) : formatPrepareCompletionResult(result));
390
+ const { result } = await COMMAND_EXECUTORS["prepare-completion"]({ target, packageRoot, options });
391
+ renderJsonOr(options, result, formatPrepareCompletionResult);
483
392
  return 0;
484
393
  },
485
394
  "run-check": async ({ target, packageRoot, options }) => {
486
- const result = await runCheck({
487
- target,
488
- packageRoot,
489
- id: options.checkId,
490
- requirement: options.checkRequirement,
491
- argv: options.commandArgv,
492
- details: options.checkDetails ?? undefined,
493
- timeoutMs: options.timeoutMs ?? undefined,
494
- taskId: options.task,
495
- });
496
- console.log(options.json ? JSON.stringify(result, null, 2) : formatRunCheckResult(result));
497
- return result.check.status === "passed" ? 0 : 1;
395
+ const { result, exitCode } = await COMMAND_EXECUTORS["run-check"]({ target, packageRoot, options });
396
+ renderJsonOr(options, result, formatRunCheckResult);
397
+ return exitCode;
398
+ },
399
+ "run-action": async ({ target, packageRoot, options }) => {
400
+ const { result, exitCode } = await COMMAND_EXECUTORS["run-action"]({ target, packageRoot, options });
401
+ renderJsonOr(options, result, formatRunActionResult);
402
+ return exitCode;
403
+ },
404
+ "action-propose": async ({ target, packageRoot, options }) => {
405
+ const { result } = await COMMAND_EXECUTORS["action-propose"]({ target, packageRoot, options });
406
+ renderJsonOr(options, result, formatActionProposeResult); return 0;
407
+ },
408
+ "action-authorize": async ({ target, packageRoot, options }) => {
409
+ const { result } = await COMMAND_EXECUTORS["action-authorize"]({ target, packageRoot, options });
410
+ renderJsonOr(options, result, formatActionAuthorizeResult); return 0;
411
+ },
412
+ "action-record": async ({ target, packageRoot, options }) => {
413
+ const { result } = await COMMAND_EXECUTORS["action-record"]({ target, packageRoot, options });
414
+ renderJsonOr(options, result, formatActionRecordResult); return 0;
415
+ },
416
+ "action-verify": async ({ target, packageRoot, options }) => {
417
+ const { result } = await COMMAND_EXECUTORS["action-verify"]({ target, packageRoot, options });
418
+ renderJsonOr(options, result, formatActionVerifyResult); return 0;
419
+ },
420
+ "action-show": async ({ target, packageRoot, options }) => {
421
+ const { result } = await COMMAND_EXECUTORS["action-show"]({ target, packageRoot, options });
422
+ renderJsonOr(options, result, formatActionShowResult); return 0;
498
423
  },
424
+ "action-reconcile": async ({ target, packageRoot, options }) => {
425
+ const { result } = await COMMAND_EXECUTORS["action-reconcile"]({ target, packageRoot, options });
426
+ renderJsonOr(options, result, formatActionReconcileResult); return 0;
427
+ },
428
+ metrics: async ({ target, packageRoot, options }) => {
429
+ const { result } = await COMMAND_EXECUTORS.metrics({ target, packageRoot, options });
430
+ renderJsonOr(options, result, formatMetricsResult); return 0;
431
+ },
432
+ eval: async ({ target, packageRoot, options }) => {
433
+ const { result, exitCode } = await COMMAND_EXECUTORS.eval({ target, packageRoot, options });
434
+ renderJsonOr(options, result, formatEvalResult); return exitCode;
435
+ },
436
+ "approval-request": async ({ target, packageRoot, options }) => { const { result } = await COMMAND_EXECUTORS["approval-request"]({ target, packageRoot, options }); renderJsonOr(options, result, formatApprovalRequestResult); return 0; },
437
+ "approval-resolve": async ({ target, packageRoot, options }) => { const { result } = await COMMAND_EXECUTORS["approval-resolve"]({ target, packageRoot, options }); renderJsonOr(options, result, formatApprovalResolveResult); return 0; },
499
438
  "record-check": async ({ target, packageRoot, options }) => {
500
- const result = await runRecordCheck({
501
- target,
502
- packageRoot,
503
- id: options.checkId,
504
- kind: options.checkKind ?? "command",
505
- requirement: options.checkRequirement,
506
- status: options.checkStatus,
507
- evidenceKind: options.checkEvidenceKind,
508
- command: options.checkCommand ?? undefined,
509
- result: options.checkResult ?? undefined,
510
- ...(options.checkExitCode === null ? {} : { exitCode: options.checkExitCode }),
511
- details: options.checkDetails ?? undefined,
512
- executionRef: options.checkExecutionRef ?? undefined,
513
- provenance: options.checkProvenance ?? undefined,
514
- taskId: options.task,
515
- });
516
- console.log(options.json ? JSON.stringify(result, null, 2) : formatRecordCheckResult(result));
439
+ const { result } = await COMMAND_EXECUTORS["record-check"]({ target, packageRoot, options });
440
+ renderJsonOr(options, result, formatRecordCheckResult);
517
441
  return 0;
518
442
  },
519
443
  "record-terminal-result": async ({ target, packageRoot, options }) => {
520
- const result = await runRecordTerminalResult({
521
- target,
522
- packageRoot,
523
- requirement: options.checkRequirement,
524
- type: options.checkType,
525
- status: options.checkStatus,
526
- source: options.checkSource ?? options.checkCommand,
527
- result: options.checkResult,
528
- details: options.checkDetails ?? undefined,
529
- taskId: options.task,
530
- });
531
- console.log(options.json ? JSON.stringify(result, null, 2) : formatRecordTerminalResult(result));
444
+ const { result } = await COMMAND_EXECUTORS["record-terminal-result"]({ target, packageRoot, options });
445
+ renderJsonOr(options, result, formatRecordTerminalResult);
532
446
  return 0;
533
447
  },
534
448
  "record-diagnosis": async ({ target, packageRoot, options }) => {
535
- const result = await runRecordDiagnosis({
536
- target,
537
- packageRoot,
538
- hypothesis: options.hypothesis,
539
- failureClass: options.failureClass,
540
- evidenceRefs: options.evidenceRefs,
541
- settledBy: options.settledBy,
542
- nextSafeAction: options.nextSafeAction,
543
- taskId: options.task,
544
- });
545
- console.log(options.json ? JSON.stringify(result, null, 2) : formatRecordDiagnosisResult(result));
449
+ const { result } = await COMMAND_EXECUTORS["record-diagnosis"]({ target, packageRoot, options });
450
+ renderJsonOr(options, result, formatRecordDiagnosisResult);
451
+ return 0;
452
+ },
453
+ "record-intervention": async ({ target, packageRoot, options }) => {
454
+ const { result } = await COMMAND_EXECUTORS["record-intervention"]({ target, packageRoot, options });
455
+ renderJsonOr(options, result, formatRecordInterventionResult);
456
+ return 0;
457
+ },
458
+ "record-hypothesis-disposition": async ({ target, packageRoot, options }) => {
459
+ const { result } = await COMMAND_EXECUTORS["record-hypothesis-disposition"]({ target, packageRoot, options });
460
+ renderJsonOr(options, result, formatRecordHypothesisDispositionResult);
546
461
  return 0;
547
462
  },
463
+ history: async ({ target, packageRoot, options }) => {
464
+ const { result, exitCode } = await COMMAND_EXECUTORS.history({ target, packageRoot, options });
465
+ if (options.json) {
466
+ console.log(JSON.stringify(result, null, 2));
467
+ } else if (options.compact) {
468
+ for (const event of result.events) {
469
+ console.log(`${event.timestamp ?? "--:--:--"} ${event.type}`);
470
+ }
471
+ } else if (options.verbose) {
472
+ console.log(formatHistoryResult(result));
473
+ for (const event of result.events) {
474
+ console.log(`--- ${event.sequence} ${event.type} ---`);
475
+ console.log(JSON.stringify(event.data, null, 2));
476
+ }
477
+ } else {
478
+ console.log(formatHistoryResult(result));
479
+ }
480
+ return exitCode;
481
+ },
482
+ trace: async ({ target, packageRoot, options }) => {
483
+ const { result, exitCode } = await COMMAND_EXECUTORS.trace({ target, packageRoot, options });
484
+ renderJsonOr(options, result, formatTraceResult);
485
+ return exitCode;
486
+ },
487
+ reflect: async ({ target, packageRoot, options }) => {
488
+ const { result, exitCode } = await COMMAND_EXECUTORS.reflect({ target, packageRoot, options });
489
+ renderJsonOr(options, result, formatReflectResult);
490
+ return exitCode;
491
+ },
548
492
  progress: async ({ target, packageRoot, options }) => {
549
- const result = await runProgress({ target, packageRoot, taskId: options.task });
550
- console.log(options.json ? JSON.stringify(result, null, 2) : formatProgressResult(result));
551
- return result.status === "STALLED" ? 1 : 0;
493
+ const { result, exitCode } = await COMMAND_EXECUTORS.progress({ target, packageRoot, options });
494
+ renderJsonOr(options, result, formatProgressResult);
495
+ return exitCode;
552
496
  },
553
497
  "record-decision-criterion": async ({ target, packageRoot, options }) => {
554
- const result = await runRecordDecisionCriterion({
555
- target,
556
- packageRoot,
557
- decision: options.decision,
558
- settledBy: options.settledBy,
559
- taskId: options.task,
560
- });
561
- console.log(options.json ? JSON.stringify(result, null, 2) : formatRecordDecisionCriterionResult(result));
498
+ const { result } = await COMMAND_EXECUTORS["record-decision-criterion"]({ target, packageRoot, options });
499
+ renderJsonOr(options, result, formatRecordDecisionCriterionResult);
562
500
  return 0;
563
501
  },
564
502
  complete: async ({ target, packageRoot, options }) => {
565
- const result = await runComplete({ target, packageRoot, strict: options.strict, taskId: options.task });
566
- console.log(options.json ? JSON.stringify(result, null, 2) : formatCompleteResult(result));
567
- return result.status === "VALID" ? 0 : 1;
503
+ const { result, exitCode } = await COMMAND_EXECUTORS.complete({ target, packageRoot, options });
504
+ renderJsonOr(options, result, formatCompleteResult);
505
+ return exitCode;
568
506
  },
569
507
  audit: async ({ target, packageRoot, options }) => {
570
- const result = await runAudit({ target, packageRoot, strict: options.strict, taskId: options.task });
571
- console.log(options.json ? JSON.stringify(result, null, 2) : formatAuditResult(result));
572
- return result.status === "VALID" ? 0 : 1;
508
+ const { result, exitCode } = await COMMAND_EXECUTORS.audit({ target, packageRoot, options });
509
+ renderJsonOr(options, result, formatAuditResult);
510
+ return exitCode;
573
511
  },
574
512
  report: async ({ target, packageRoot, options }) => {
575
- const result = await runReport({ target, packageRoot, strict: options.strict, taskId: options.task });
576
- console.log(options.json ? JSON.stringify(result, null, 2) : formatReportResult(result));
577
- return result.verdict === "VALID" ? 0 : 1;
513
+ const { result, exitCode } = await COMMAND_EXECUTORS.report({ target, packageRoot, options });
514
+ renderJsonOr(options, result, formatReportResult);
515
+ return exitCode;
578
516
  },
579
517
  policy: async ({ target, packageRoot, options }) => {
580
- const result = await runPolicy({ target, packageRoot, name: options.policy, taskId: options.task });
581
- console.log(options.json ? JSON.stringify(result, null, 2) : formatPolicyResult(result));
518
+ const { result } = await COMMAND_EXECUTORS.policy({ target, packageRoot, options });
519
+ renderJsonOr(options, result, formatPolicyResult);
582
520
  return 0;
583
521
  },
584
522
  "policy-discover": async ({ target, packageRoot, options }) => {
585
- const result = await runPolicyDiscover({ target, packageRoot, write: options.write });
586
- console.log(options.json ? JSON.stringify(result, null, 2) : formatPolicyDiscoverResult(result));
523
+ const { result } = await COMMAND_EXECUTORS["policy-discover"]({ target, packageRoot, options });
524
+ renderJsonOr(options, result, formatPolicyDiscoverResult);
587
525
  return 0;
588
526
  },
589
527
  "policy-status": async ({ target, packageRoot, options }) => {
590
- const result = await runPolicyStatus({ target, packageRoot, taskId: options.task });
591
- console.log(options.json ? JSON.stringify(result, null, 2) : formatPolicyStatusResult(result));
592
- return result.status === "VALID" ? 0 : 1;
528
+ const { result, exitCode } = await COMMAND_EXECUTORS["policy-status"]({ target, packageRoot, options });
529
+ renderJsonOr(options, result, formatPolicyStatusResult);
530
+ return exitCode;
593
531
  },
594
532
  "policy-diff": async ({ target, packageRoot, options }) => {
595
- const result = await runPolicyDiff({ target, packageRoot, taskId: options.task, before: options.before, after: options.after });
596
- console.log(options.json ? JSON.stringify(result, null, 2) : formatPolicyDiffResult(result));
533
+ const { result } = await COMMAND_EXECUTORS["policy-diff"]({ target, packageRoot, options });
534
+ renderJsonOr(options, result, formatPolicyDiffResult);
597
535
  return 0;
598
536
  },
599
537
  "rule-verify": async ({ target, packageRoot, options }) => {
600
- const result = await runRuleVerify({ target, packageRoot, rule: options.rule });
601
- console.log(options.json ? JSON.stringify(result, null, 2) : formatRuleVerifyResult(result));
602
- return result.status === "VALID" ? 0 : 1;
538
+ const { result, exitCode } = await COMMAND_EXECUTORS["rule-verify"]({ target, packageRoot, options });
539
+ renderJsonOr(options, result, formatRuleVerifyResult);
540
+ return exitCode;
603
541
  },
604
542
  baseline: async ({ target, packageRoot, options }) => {
605
- const result = await runBaseline({
606
- target,
607
- packageRoot,
608
- record: options.record,
609
- update: options.update,
610
- policyResetAuthorized: options.policyResetAuthorized,
611
- });
612
- console.log(options.json ? JSON.stringify(result, null, 2) : formatBaselineResult(result));
543
+ const { result } = await COMMAND_EXECUTORS.baseline({ target, packageRoot, options });
544
+ renderJsonOr(options, result, formatBaselineResult);
613
545
  return 0;
614
546
  },
615
547
  "profile-interview": async ({ target, packageRoot, options }) => {
616
- const result = await runProfileInterview({ target, packageRoot, dryRun: options.dryRun });
617
- console.log(options.json ? JSON.stringify(result, null, 2) : formatProfileInterviewResult(result));
548
+ const { result } = await COMMAND_EXECUTORS["profile-interview"]({ target, packageRoot, options });
549
+ renderJsonOr(options, result, formatProfileInterviewResult);
618
550
  return 0;
619
551
  },
620
552
  bundle: async ({ target, packageRoot, options }) => {
621
- const result = await runBundle({ target, packageRoot, taskId: options.task });
622
- console.log(options.json ? JSON.stringify(result, null, 2) : formatBundleResult(result));
553
+ const { result } = await COMMAND_EXECUTORS.bundle({ target, packageRoot, options });
554
+ renderJsonOr(options, result, formatBundleResult);
623
555
  return 0;
624
556
  },
625
557
  inspect: async ({ target, packageRoot, options }) => {
626
- const result = await inspectTarget({ target, packageRoot, contractFile: options.contractFile, taskId: options.task });
627
- console.log(options.json ? JSON.stringify(result, null, 2) : formatInspectResult(result));
628
- return result.ok ? 0 : 1;
558
+ const { result, exitCode } = await COMMAND_EXECUTORS.inspect({ target, packageRoot, options });
559
+ renderJsonOr(options, result, formatInspectResult);
560
+ return exitCode;
629
561
  },
630
562
  "validate-receipt": async ({ target, packageRoot, options }) => {
631
- const result = await runValidateReceipt({ target, packageRoot, file: options.file, taskId: options.task });
563
+ const { result } = await COMMAND_EXECUTORS["validate-receipt"]({ target, packageRoot, options });
632
564
  console.log(options.json ? JSON.stringify(result, null, 2) : "valid: execution receipt");
633
565
  return 0;
634
566
  },
635
567
  "validate-protocol": async ({ target, packageRoot, options }) => {
636
- const result = await runValidateProtocol({
637
- target,
638
- packageRoot,
639
- stateFile: options.stateFile,
640
- receiptFile: options.receiptFile,
641
- routeFile: options.routeFile,
642
- contractFile: options.contractFile,
643
- continuityFile: options.continuityFile,
644
- taskBriefFiles: options.taskBriefFiles,
645
- delegatedResultFiles: options.delegatedResultFiles,
646
- taskId: options.task,
647
- });
648
- console.log(options.json ? JSON.stringify(result, null, 2) : formatValidateProtocolResult(result));
649
- return result.status === "VALID" ? 0 : 1;
568
+ const { result, exitCode } = await COMMAND_EXECUTORS["validate-protocol"]({ target, packageRoot, options });
569
+ renderJsonOr(options, result, formatValidateProtocolResult);
570
+ return exitCode;
650
571
  },
651
572
  status: async ({ target, packageRoot, options }) => {
652
- const result = await runStatus({ target, packageRoot, contractFile: options.contractFile, taskId: options.task });
653
- console.log(options.json ? JSON.stringify(result, null, 2) : formatStatusResult(result));
573
+ const { result } = await COMMAND_EXECUTORS.status({ target, packageRoot, options });
574
+ renderJsonOr(options, result, formatStatusResult);
654
575
  return 0;
655
576
  },
656
577
  "validate-state": async ({ target, packageRoot, options }) => {
657
- const result = await runValidateState({ target, packageRoot, taskId: options.task });
658
- console.log(options.json ? JSON.stringify(result, null, 2) : formatValidateStateResult(result));
659
- return result.ok ? 0 : 1;
578
+ const { result, exitCode } = await COMMAND_EXECUTORS["validate-state"]({ target, packageRoot, options });
579
+ renderJsonOr(options, result, formatValidateStateResult);
580
+ return exitCode;
660
581
  },
661
582
  "clear-state": async ({ target, options }) => {
662
- const result = await runClearState({ target, taskId: options.task });
663
- console.log(options.json ? JSON.stringify(result, null, 2) : formatClearStateResult(result));
583
+ const { result } = await COMMAND_EXECUTORS["clear-state"]({ target, options });
584
+ renderJsonOr(options, result, formatClearStateResult);
664
585
  return 0;
665
586
  },
666
587
  "task-create": async ({ target, packageRoot, options }) => {
667
- const result = await runTaskCreate({
668
- target,
669
- packageRoot,
670
- taskId: options.task,
671
- claims: options.claims,
672
- contractFile: options.contractFile,
673
- });
674
- console.log(options.json ? JSON.stringify(result, null, 2) : formatTaskCreateResult(result));
588
+ const { result } = await COMMAND_EXECUTORS["task-create"]({ target, packageRoot, options });
589
+ renderJsonOr(options, result, formatTaskCreateResult);
675
590
  return 0;
676
591
  },
677
592
  "task-list": async ({ target, packageRoot, options }) => {
678
- const result = await runTaskList({ target, packageRoot });
679
- console.log(options.json ? JSON.stringify(result, null, 2) : formatTaskListResult(result));
593
+ const { result } = await COMMAND_EXECUTORS["task-list"]({ target, packageRoot, options });
594
+ renderJsonOr(options, result, formatTaskListResult);
680
595
  return 0;
681
596
  },
682
597
  "task-show": async ({ target, packageRoot, options }) => {
683
- const result = await runTaskShow({ target, packageRoot, taskId: options.task });
684
- console.log(options.json ? JSON.stringify(result, null, 2) : formatTaskShowResult(result));
598
+ const { result } = await COMMAND_EXECUTORS["task-show"]({ target, packageRoot, options });
599
+ renderJsonOr(options, result, formatTaskShowResult);
685
600
  return 0;
686
601
  },
687
602
  "task-lock-status": async ({ target, packageRoot, options }) => {
688
- const result = await runTaskLockStatus({ target, packageRoot, taskId: options.task });
689
- console.log(options.json ? JSON.stringify(result, null, 2) : formatTaskLockStatusResult(result));
603
+ const { result } = await COMMAND_EXECUTORS["task-lock-status"]({ target, packageRoot, options });
604
+ renderJsonOr(options, result, formatTaskLockStatusResult);
690
605
  return 0;
691
606
  },
692
607
  "task-scope": async ({ target, packageRoot, options }) => {
693
- const result = await runTaskScope({
694
- target,
695
- packageRoot,
696
- taskId: options.task,
697
- claims: options.claims,
698
- });
699
- console.log(options.json ? JSON.stringify(result, null, 2) : formatTaskScopeResult(result));
608
+ const { result } = await COMMAND_EXECUTORS["task-scope"]({ target, packageRoot, options });
609
+ renderJsonOr(options, result, formatTaskScopeResult);
700
610
  return 0;
701
611
  },
702
612
  "task-migrate": async ({ target, packageRoot, options }) => {
703
- const result = await runTaskMigrate({ target, packageRoot, dryRun: options.dryRun });
704
- console.log(options.json ? JSON.stringify(result, null, 2) : formatTaskMigrateResult(result));
613
+ const { result } = await COMMAND_EXECUTORS["task-migrate"]({ target, packageRoot, options });
614
+ renderJsonOr(options, result, formatTaskMigrateResult);
705
615
  return 0;
706
616
  },
707
617
  "migrate-protocol": async ({ target, packageRoot, options }) => {
708
- const result = await runMigrateProtocol({ target, packageRoot, to: options.to, dryRun: options.dryRun });
709
- console.log(options.json ? JSON.stringify(result, null, 2) : formatMigrateProtocolResult(result));
618
+ const { result } = await COMMAND_EXECUTORS["migrate-protocol"]({ target, packageRoot, options });
619
+ renderJsonOr(options, result, formatMigrateProtocolResult);
710
620
  return 0;
711
621
  },
712
622
  "task-unlock": async ({ target, packageRoot, options }) => {
713
- const result = await runTaskUnlock({ target, packageRoot, taskId: options.task, force: options.force, staleOnly: options.staleOnly });
714
- console.log(options.json ? JSON.stringify(result, null, 2) : formatTaskUnlockResult(result));
623
+ const { result } = await COMMAND_EXECUTORS["task-unlock"]({ target, packageRoot, options });
624
+ renderJsonOr(options, result, formatTaskUnlockResult);
625
+ return 0;
626
+ },
627
+ "task-recover": async ({ target, packageRoot, options }) => {
628
+ if (options.operatorAuthorized && !options.acknowledgeRecovery) {
629
+ console.error("DEPRECATION: --operator-authorized is caller acknowledgement, not host attestation; use --acknowledge-recovery.");
630
+ }
631
+ const { result } = await COMMAND_EXECUTORS["task-recover"]({ target, packageRoot, options });
632
+ renderJsonOr(options, result, formatTaskRecoverResult);
633
+ return 0;
634
+ },
635
+ "task-resume": async ({ target, packageRoot, options }) => {
636
+ const { result } = await COMMAND_EXECUTORS["task-resume"]({ target, packageRoot, options });
637
+ renderJsonOr(options, result, formatTaskResumeResult);
638
+ return 0;
639
+ },
640
+ "task-repair-legacy-recovery": async ({ target, packageRoot, options }) => {
641
+ const { result } = await COMMAND_EXECUTORS["task-repair-legacy-recovery"]({ target, packageRoot, options });
642
+ renderJsonOr(options, result, formatTaskRepairLegacyRecoveryResult);
715
643
  return 0;
716
644
  },
717
645
  "reconcile-closure": async ({ target, packageRoot, options }) => {
718
- const result = await reconcileClosure({
719
- target,
720
- packageRoot,
721
- taskId: options.task,
722
- checkId: options.checkId,
723
- checkRequirement: options.checkRequirement,
724
- checkDetails: options.checkDetails,
725
- commandArgv: options.commandArgv,
726
- });
727
- console.log(options.json ? JSON.stringify(result, null, 2) : formatReconcileClosureResult(result));
646
+ const { result } = await COMMAND_EXECUTORS["reconcile-closure"]({ target, packageRoot, options });
647
+ renderJsonOr(options, result, formatReconcileClosureResult);
728
648
  return 0;
729
649
  },
730
650
  update: async ({ target, packageRoot, packageVersion, options }) => {
731
- const result = await runUpdate({ target, dryRun: options.dryRun, packageRoot, packageVersion });
651
+ const { result, exitCode } = await COMMAND_EXECUTORS.update({ target, packageRoot, packageVersion, options });
732
652
  printActions(result.actions);
733
653
  for (const conflict of result.conflicts) {
734
654
  const code = conflict.code ? `${conflict.code}: ` : "";
735
655
  console.log(`conflict: ${code}${conflict.path} - ${conflict.message}`);
736
656
  }
737
- return result.conflicts.length === 0 ? 0 : 1;
657
+ return exitCode;
738
658
  },
739
659
  });
740
660