@ornexus/neocortex 4.61.4 → 4.61.6

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 (254) hide show
  1. package/dist/release-source.json +1 -1
  2. package/dist/sbom.cdx.json +1193 -1193
  3. package/install.ps1 +1 -1
  4. package/install.sh +1 -1
  5. package/package.json +2 -2
  6. package/packages/client/dist/adapters/adapter-registry.js +1 -108
  7. package/packages/client/dist/adapters/antigravity-adapter.js +2 -77
  8. package/packages/client/dist/adapters/claude-code-adapter.js +3 -79
  9. package/packages/client/dist/adapters/codex-adapter.js +2 -80
  10. package/packages/client/dist/adapters/cursor-adapter.js +4 -115
  11. package/packages/client/dist/adapters/gemini-adapter.js +2 -71
  12. package/packages/client/dist/adapters/grok-adapter.js +2 -42
  13. package/packages/client/dist/adapters/index.js +1 -22
  14. package/packages/client/dist/adapters/platform-detector.js +1 -220
  15. package/packages/client/dist/adapters/target-adapter.js +0 -12
  16. package/packages/client/dist/adapters/vscode-adapter.js +2 -72
  17. package/packages/client/dist/agent/refresh-stubs.js +2 -443
  18. package/packages/client/dist/agent/update-agent-yaml.js +1 -102
  19. package/packages/client/dist/agent/update-description.js +1 -260
  20. package/packages/client/dist/cache/crypto-utils.js +1 -78
  21. package/packages/client/dist/cache/encrypted-cache.js +1 -338
  22. package/packages/client/dist/cache/in-memory-asset-cache.js +1 -73
  23. package/packages/client/dist/cache/index.js +1 -13
  24. package/packages/client/dist/cache/protected-pi-boundary.js +1 -44
  25. package/packages/client/dist/checkpoint/checkpoint-client-reader.js +2 -127
  26. package/packages/client/dist/checkpoint/index.js +1 -11
  27. package/packages/client/dist/checkpoint/shared-checkpoint-types.js +1 -32
  28. package/packages/client/dist/cli.js +5 -364
  29. package/packages/client/dist/commands/activate.js +8 -394
  30. package/packages/client/dist/commands/architecture-answers.js +7 -274
  31. package/packages/client/dist/commands/architecture-memory-terminal.js +4 -253
  32. package/packages/client/dist/commands/architecture-non-ui-continuation.js +1 -100
  33. package/packages/client/dist/commands/architecture-root-binding.js +1 -51
  34. package/packages/client/dist/commands/cache-status.js +2 -112
  35. package/packages/client/dist/commands/config.js +1 -88
  36. package/packages/client/dist/commands/doctor.js +2 -635
  37. package/packages/client/dist/commands/invoke.js +148 -7822
  38. package/packages/client/dist/commands/legacy-epic-terminal.js +1 -71
  39. package/packages/client/dist/commands/legacy-story-branch.js +1 -96
  40. package/packages/client/dist/commands/legacy-story-pr.js +1 -276
  41. package/packages/client/dist/commands/mutation-qa-checkpoint.js +5 -285
  42. package/packages/client/dist/commands/mutation-qa-gate.js +1 -54
  43. package/packages/client/dist/commands/mutation-qa-git.js +1 -41
  44. package/packages/client/dist/commands/mutation-qa-policy.js +1 -102
  45. package/packages/client/dist/commands/mutation-qa-run.js +3 -219
  46. package/packages/client/dist/commands/mutation-qa-verdict.js +1 -149
  47. package/packages/client/dist/commands/mutation-qa.js +1 -220
  48. package/packages/client/dist/commands/native-agent.js +2 -136
  49. package/packages/client/dist/commands/planning-diagnosis.js +1 -43
  50. package/packages/client/dist/commands/planning-generation.js +1 -53
  51. package/packages/client/dist/commands/planning-memory.js +1 -40
  52. package/packages/client/dist/commands/planning-research.js +1 -42
  53. package/packages/client/dist/commands/private-session.js +1 -75
  54. package/packages/client/dist/commands/property-qa.js +1 -139
  55. package/packages/client/dist/commands/qa-control.js +1 -16
  56. package/packages/client/dist/commands/qa-scan-browser-launch.js +1 -55
  57. package/packages/client/dist/commands/qa-scan-browser-route.js +1 -28
  58. package/packages/client/dist/commands/qa-scan-capture.js +5 -663
  59. package/packages/client/dist/commands/qa-scan-discovery.js +3 -376
  60. package/packages/client/dist/commands/qa-scan-review.js +5 -826
  61. package/packages/client/dist/commands/qa-synthetic-backend-capture.js +1 -266
  62. package/packages/client/dist/commands/qa-synthetic-backend-review.js +1 -297
  63. package/packages/client/dist/commands/qa-synthetic-backend.js +2 -340
  64. package/packages/client/dist/commands/qa-synthetic-broker-port.js +1 -85
  65. package/packages/client/dist/commands/qa-synthetic-browser.js +1 -39
  66. package/packages/client/dist/commands/refactor-characterization.js +21 -671
  67. package/packages/client/dist/commands/refactor-commit.js +13 -399
  68. package/packages/client/dist/commands/refactor-control.js +3 -142
  69. package/packages/client/dist/commands/refactor-cpp-assertions.js +3 -93
  70. package/packages/client/dist/commands/refactor-review.js +5 -283
  71. package/packages/client/dist/commands/refactor-root.js +7 -588
  72. package/packages/client/dist/commands/refresh-memory.js +3 -174
  73. package/packages/client/dist/commands/shared-architecture-non-ui.js +1 -24
  74. package/packages/client/dist/commands/story-checkpoint.d.ts +5 -1
  75. package/packages/client/dist/commands/story-checkpoint.js +1 -203
  76. package/packages/client/dist/commands/story-worktree.js +5 -258
  77. package/packages/client/dist/config/host-auth-broker.js +1 -60
  78. package/packages/client/dist/config/host-auth-reference.js +1 -93
  79. package/packages/client/dist/config/profile-directory.js +1 -13
  80. package/packages/client/dist/config/resolver-selection.js +1 -278
  81. package/packages/client/dist/config/secure-config.js +12 -281
  82. package/packages/client/dist/config.js +2 -224
  83. package/packages/client/dist/constants.js +1 -25
  84. package/packages/client/dist/context/context-collector.js +2 -222
  85. package/packages/client/dist/context/context-sanitizer.js +1 -145
  86. package/packages/client/dist/continuity/autonomous-governance.js +1 -285
  87. package/packages/client/dist/continuity/continuity-client-state-store.js +1 -1587
  88. package/packages/client/dist/continuity/invoke-hooks.js +1 -129
  89. package/packages/client/dist/continuity/migrations/001-initial-schema.js +2 -12
  90. package/packages/client/dist/continuity/migrations/002-processing-output-summary-indexes.js +2 -12
  91. package/packages/client/dist/continuity/migrations/003-headless-execution-attempts.js +2 -12
  92. package/packages/client/dist/continuity/migrations/004-outbox-delivery-state.js +2 -12
  93. package/packages/client/dist/continuity/migrations/005-bounded-headless-queue.js +2 -12
  94. package/packages/client/dist/continuity/migrations/006-native-agent-dispatches.js +2 -10
  95. package/packages/client/dist/continuity/native-agent-store.js +1 -69
  96. package/packages/client/dist/continuity/native-agent-types.js +1 -105
  97. package/packages/client/dist/continuity/outbox.js +1 -117
  98. package/packages/client/dist/continuity/runner-bootstrap-policy.js +1 -172
  99. package/packages/client/dist/continuity/sqlite-store.js +81 -2612
  100. package/packages/client/dist/effects/invoke-effect-gateways.js +1 -62
  101. package/packages/client/dist/errors/error-messages.js +2 -258
  102. package/packages/client/dist/errors/frontmatter-diagnostics.js +1 -125
  103. package/packages/client/dist/evidence/collector.js +1 -347
  104. package/packages/client/dist/evidence/index.js +1 -1
  105. package/packages/client/dist/evidence/types.js +0 -2
  106. package/packages/client/dist/fs/atomic-state-replace.js +1 -152
  107. package/packages/client/dist/generated/command-registry.generated.js +1 -4076
  108. package/packages/client/dist/generated/public-projections.generated.js +1 -149
  109. package/packages/client/dist/git/direct-yolo-c01-retry.js +4 -138
  110. package/packages/client/dist/git/direct-yolo-checkpoint.d.ts +70 -0
  111. package/packages/client/dist/git/direct-yolo-checkpoint.js +4 -1592
  112. package/packages/client/dist/git/epic-operational-state.js +2 -672
  113. package/packages/client/dist/git/git-lifecycle-step-ids.js +1 -14
  114. package/packages/client/dist/git/git-lifecycle-store.d.ts +22 -0
  115. package/packages/client/dist/git/git-lifecycle-store.js +8 -2500
  116. package/packages/client/dist/git/legacy-story-branch-checkpoint.js +9 -259
  117. package/packages/client/dist/git/legacy-story-branch-setup.js +4 -348
  118. package/packages/client/dist/git/legacy-story-pr.js +70 -3538
  119. package/packages/client/dist/git/neocortex-trailers.js +2 -53
  120. package/packages/client/dist/git/secure-filesystem-boundary.js +5 -182
  121. package/packages/client/dist/git/story-worktree-cleanup.js +4 -1058
  122. package/packages/client/dist/git/story-worktree-integration.d.ts +62 -0
  123. package/packages/client/dist/git/story-worktree-integration.js +3 -603
  124. package/packages/client/dist/git/story-worktree-manager.js +3 -843
  125. package/packages/client/dist/git/story-worktree-paths.js +1 -150
  126. package/packages/client/dist/git/story-write-set-extension.d.ts +44 -0
  127. package/packages/client/dist/git/story-write-set-extension.js +1 -0
  128. package/packages/client/dist/graph-retrieval/pre-command-hook.js +1 -284
  129. package/packages/client/dist/graph-retrieval/shared-graph-retrieval-contract.js +1 -237
  130. package/packages/client/dist/i18n/first-run.js +2 -60
  131. package/packages/client/dist/index.js +1 -50
  132. package/packages/client/dist/invocation/invoke-input.js +1 -24
  133. package/packages/client/dist/license/host-auth-recovery.js +1 -401
  134. package/packages/client/dist/license/index.js +1 -5
  135. package/packages/client/dist/license/license-client.js +1 -337
  136. package/packages/client/dist/machine/fingerprint.js +2 -163
  137. package/packages/client/dist/machine/index.js +1 -5
  138. package/packages/client/dist/memory/project-memory-path-scope.js +1 -62
  139. package/packages/client/dist/memory/project-memory-writer.js +41 -1117
  140. package/packages/client/dist/memory/shared-project-memory-types.js +2 -259
  141. package/packages/client/dist/migrations/epic-lifecycle-backfill.js +3 -1060
  142. package/packages/client/dist/migrations/project-identity-capability.js +1 -50
  143. package/packages/client/dist/migrations/project-identity.js +7 -493
  144. package/packages/client/dist/migrations/state-json.js +4 -393
  145. package/packages/client/dist/policy/architecture-policy.js +2 -184
  146. package/packages/client/dist/policy/index.js +1 -7
  147. package/packages/client/dist/policy/shared-policy-types.js +0 -38
  148. package/packages/client/dist/policy/subagent-approval-policy.js +1 -57
  149. package/packages/client/dist/private-execution/clean-baseline.js +2 -279
  150. package/packages/client/dist/private-execution/codex-executor.js +4 -574
  151. package/packages/client/dist/private-execution/codex-host-runtime.js +1 -137
  152. package/packages/client/dist/private-execution/codex-lifecycle-guard.js +1 -97
  153. package/packages/client/dist/private-execution/codex-scoped-permissions.js +1 -128
  154. package/packages/client/dist/private-execution/delivery.js +13 -410
  155. package/packages/client/dist/private-execution/diagnosis-root-review.js +2 -294
  156. package/packages/client/dist/private-execution/frozen-handoff.js +6 -19
  157. package/packages/client/dist/private-execution/implementation-validation.js +2 -106
  158. package/packages/client/dist/private-execution/isolated-admission.js +23 -1432
  159. package/packages/client/dist/private-execution/isolated-session.js +5 -725
  160. package/packages/client/dist/private-execution/isolated-workspace.js +1 -122
  161. package/packages/client/dist/private-execution/pact-consumer-runtime.js +3 -409
  162. package/packages/client/dist/private-execution/pact-test-source.js +1 -258
  163. package/packages/client/dist/private-execution/pact-toolchain.js +3 -290
  164. package/packages/client/dist/private-execution/pact-write-set.js +1 -172
  165. package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +5 -406
  166. package/packages/client/dist/private-execution/planning-generation-checkpoint.js +5 -462
  167. package/packages/client/dist/private-execution/planning-memory-checkpoint.js +3 -139
  168. package/packages/client/dist/private-execution/planning-research-checkpoint.js +4 -325
  169. package/packages/client/dist/private-execution/private-report-store.js +1 -42
  170. package/packages/client/dist/private-execution/property-test-candidate.js +1 -103
  171. package/packages/client/dist/private-execution/property-test-choices.js +3 -147
  172. package/packages/client/dist/private-execution/property-test-plan.js +7 -271
  173. package/packages/client/dist/private-execution/property-test-review.js +4 -258
  174. package/packages/client/dist/private-execution/property-test-runtime.js +9 -372
  175. package/packages/client/dist/private-execution/property-test-source.js +1 -139
  176. package/packages/client/dist/private-execution/root-checkpoint.js +1 -80
  177. package/packages/client/dist/private-execution/root-memory-git-evidence.js +3 -135
  178. package/packages/client/dist/private-execution/root-memory-recovery.js +1 -93
  179. package/packages/client/dist/private-execution/root-memory-request.js +1 -29
  180. package/packages/client/dist/private-execution/root-memory-scope.js +1 -178
  181. package/packages/client/dist/private-execution/root-memory-writer.js +1 -102
  182. package/packages/client/dist/private-execution/session-lease.js +1 -63
  183. package/packages/client/dist/private-execution/shared-private-admission-types.js +1 -50
  184. package/packages/client/dist/private-execution/shared-project-validation.js +1 -66
  185. package/packages/client/dist/private-execution/shared-root-memory-types.js +1 -61
  186. package/packages/client/dist/private-execution/ux-source-validation.js +1 -372
  187. package/packages/client/dist/private-execution/ux-write-set.js +2 -191
  188. package/packages/client/dist/registry/registry-reconciliation.js +1 -234
  189. package/packages/client/dist/resilience/circuit-breaker.js +1 -170
  190. package/packages/client/dist/resilience/degradation-manager.js +1 -164
  191. package/packages/client/dist/resilience/freshness-indicator.js +1 -100
  192. package/packages/client/dist/resilience/index.js +1 -8
  193. package/packages/client/dist/resilience/recovery-detector.js +1 -74
  194. package/packages/client/dist/resolvers/asset-resolver.js +0 -13
  195. package/packages/client/dist/resolvers/local-resolver.js +8 -255
  196. package/packages/client/dist/resolvers/remote-resolver.js +1 -233
  197. package/packages/client/dist/runner/binary.js +1 -404
  198. package/packages/client/dist/runner/cli.js +17 -1571
  199. package/packages/client/dist/runner/epic-background-dispatcher.js +1 -124
  200. package/packages/client/dist/runner/headless/adapters.js +1 -49
  201. package/packages/client/dist/runner/headless/background-root.js +1 -85
  202. package/packages/client/dist/runner/headless/claude-code-adapter.js +1 -79
  203. package/packages/client/dist/runner/headless/continuous-story-workspace.js +11 -1776
  204. package/packages/client/dist/runner/headless/epic-git-reconciliation-inventory.js +1 -69
  205. package/packages/client/dist/runner/headless/epic-merge-candidate-qa.js +2 -111
  206. package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +10 -1464
  207. package/packages/client/dist/runner/headless/epic-terminal-git-runner.js +2 -357
  208. package/packages/client/dist/runner/headless/fake-adapter.js +1 -62
  209. package/packages/client/dist/runner/headless/managed-environment-cleanup.js +1 -274
  210. package/packages/client/dist/runner/headless/managed-profile.js +1 -149
  211. package/packages/client/dist/runner/headless/opencode-adapter.js +2 -145
  212. package/packages/client/dist/runner/headless/prepared-story-bundle.js +1 -43
  213. package/packages/client/dist/runner/headless/resolver.js +1 -231
  214. package/packages/client/dist/runner/headless/run-yolo.js +1 -886
  215. package/packages/client/dist/runner/headless/run-yoloop.js +2 -2657
  216. package/packages/client/dist/runner/headless/types.js +2 -575
  217. package/packages/client/dist/runner/host-capacity.js +1 -59
  218. package/packages/client/dist/runner/local-console.js +13 -396
  219. package/packages/client/dist/runner/portal-sync-worker.js +1 -1487
  220. package/packages/client/dist/runner/project-identity.js +1 -106
  221. package/packages/client/dist/runner/scheduler.js +7 -995
  222. package/packages/client/dist/runner-cli.js +2 -18
  223. package/packages/client/dist/state/invocation-shape.js +1 -13
  224. package/packages/client/dist/state/project-state-snapshot.js +1 -1754
  225. package/packages/client/dist/state/state-json-repair.js +3 -785
  226. package/packages/client/dist/state/structural-dag-projection.js +1 -118
  227. package/packages/client/dist/telemetry/index.js +1 -5
  228. package/packages/client/dist/telemetry/offline-queue.js +1 -131
  229. package/packages/client/dist/tier/index.js +1 -5
  230. package/packages/client/dist/tier/tier-aware-client.js +1 -405
  231. package/packages/client/dist/types/index.js +1 -38
  232. package/packages/client/dist/version.js +1 -27
  233. package/packages/client/dist/yolo/change-evidence-collector.d.ts +10 -0
  234. package/packages/client/dist/yolo/change-evidence-collector.js +1 -245
  235. package/packages/client/dist/yolo/invoke-envelope-capability.js +1 -65
  236. package/packages/client/dist/yolo/spec-envelope-collector.js +5 -184
  237. package/packages/client/dist/yoloop/discovery-hook.js +2 -300
  238. package/packages/client/dist/yoloop/index.js +1 -8
  239. package/packages/client/dist/yoloop/invoke-hooks.js +12 -669
  240. package/packages/client/dist/yoloop/shared-discover-epics.js +1 -1007
  241. package/packages/client/dist/yoloop/shared-yoloop-types.js +1 -33
  242. package/packages/client/dist/yoloop/target-normalization.js +1 -180
  243. package/packages/client/dist/yoloop/yoloop-client-state-store.js +1 -1920
  244. package/targets-stubs/antigravity/gemini.md +1 -1
  245. package/targets-stubs/antigravity/skill/SKILL.md +1 -1
  246. package/targets-stubs/claude-code/neocortex-root.agent.yaml +1 -1
  247. package/targets-stubs/claude-code/neocortex-root.md +2 -2
  248. package/targets-stubs/claude-code/neocortex.agent.yaml +1 -1
  249. package/targets-stubs/claude-code/neocortex.md +2 -2
  250. package/targets-stubs/codex/AGENTS.md +1 -1
  251. package/targets-stubs/cursor/agent.md +2 -2
  252. package/targets-stubs/gemini-cli/agent.md +2 -2
  253. package/targets-stubs/opencode/neocortex-root.md +1 -1
  254. package/targets-stubs/vscode/neocortex.agent.md +2 -2
@@ -1,174 +1,3 @@
1
- import { createHash } from 'node:crypto';
2
- import { lstatSync, readFileSync } from 'node:fs';
3
- import { join, resolve } from 'node:path';
4
- import { getProjectMemoryTarget, isProjectMemoryTargetId, listProjectMemoryTargets } from '../memory/shared-project-memory-types.js';
5
- import { LEGACY_AGENT_PATH_WRAPPER_TRACKED_REASON, writeProjectMemoryTargetFiles, } from '../memory/project-memory-writer.js';
6
- function parseCsv(value) {
7
- return (value ?? '').split(',').map((entry) => entry.trim()).filter(Boolean);
8
- }
9
- export function parseRefreshMemoryArgs(args) {
10
- let projectRoot = process.cwd();
11
- let dryRun = false;
12
- let verify = false;
13
- const requestedTargets = [];
14
- const memoryNotes = [];
15
- for (let index = 0; index < args.length; index++) {
16
- const arg = args[index];
17
- if (arg === '--dry-run' || arg === '--preview') {
18
- dryRun = true;
19
- }
20
- else if (arg === '--verify') {
21
- verify = true;
22
- dryRun = true;
23
- }
24
- else if (arg === '--project-root') {
25
- projectRoot = args[++index] ?? projectRoot;
26
- }
27
- else if (arg.startsWith('--project-root=')) {
28
- projectRoot = arg.slice('--project-root='.length);
29
- }
30
- else if (arg === '--target' || arg === '--targets') {
31
- requestedTargets.push(...parseCsv(args[++index]));
32
- }
33
- else if (arg.startsWith('--target=')) {
34
- requestedTargets.push(...parseCsv(arg.slice('--target='.length)));
35
- }
36
- else if (arg.startsWith('--targets=')) {
37
- requestedTargets.push(...parseCsv(arg.slice('--targets='.length)));
38
- }
39
- else if (arg === '--note' || arg === '--memory-note' || arg === '--change') {
40
- const note = args[++index];
41
- if (note)
42
- memoryNotes.push(note);
43
- }
44
- else if (arg.startsWith('--note=')) {
45
- memoryNotes.push(arg.slice('--note='.length));
46
- }
47
- else if (arg.startsWith('--memory-note=')) {
48
- memoryNotes.push(arg.slice('--memory-note='.length));
49
- }
50
- else if (arg.startsWith('--change=')) {
51
- memoryNotes.push(arg.slice('--change='.length));
52
- }
53
- }
54
- if (verify && (requestedTargets.length > 0 || memoryNotes.length > 0)) {
55
- throw new Error('Project memory verification requires all targets and no update notes.');
56
- }
57
- const targetIds = requestedTargets.length > 0
58
- ? requestedTargets.map((target) => {
59
- if (!isProjectMemoryTargetId(target))
60
- throw new Error(`Unknown project-memory target: ${target}`);
61
- return target;
62
- })
63
- : ['canonical', ...listProjectMemoryTargets().map((target) => target.targetId)];
64
- return { projectRoot: resolve(projectRoot), targetIds: Array.from(new Set(targetIds)), dryRun, verify, memoryNotes };
65
- }
66
- export function refreshProjectMemoryTargets(options) {
67
- return options.targetIds.map((targetId) => writeProjectMemoryTargetFiles({
68
- projectRoot: options.projectRoot,
69
- targetId,
70
- dryRun: options.dryRun,
71
- memoryNotes: options.memoryNotes ?? [],
72
- backupDirectory: options.backupDirectory,
73
- }));
74
- }
75
- /** Deduplicated (by path) tracked legacy wrappers that refresh refused to delete. */
76
- export function trackedLegacyAgentPathWrappers(results) {
77
- const byPath = new Map();
78
- for (const entry of results.flatMap((result) => result.legacyAgentPathWrappers ?? [])) {
79
- if (entry.status === 'tracked-blocked' && !byPath.has(entry.relativeFile))
80
- byPath.set(entry.relativeFile, entry);
81
- }
82
- return [...byPath.values()].sort((a, b) => a.relativeFile.localeCompare(b.relativeFile));
83
- }
84
- /** Root-only, read-only physical check; this is not independent stage QA or server authority. */
85
- export function verifyProjectMemoryTargets(options) {
86
- if (!options.verify || !options.dryRun || options.memoryNotes?.length
87
- || options.targetIds.join(',') !== ['canonical', ...listProjectMemoryTargets().map((target) => target.targetId)].join(',')) {
88
- throw new Error('Project memory verification requires the complete read-only target set.');
89
- }
90
- const canonicalPath = join(options.projectRoot, 'NEOCORTEX.md');
91
- let entry;
92
- try {
93
- entry = lstatSync(canonicalPath);
94
- }
95
- catch {
96
- throw new Error('Canonical project memory is missing or unsafe.');
97
- }
98
- if (!entry.isFile() || entry.isSymbolicLink())
99
- throw new Error('Canonical project memory must be a regular file.');
100
- const canonical = readFileSync(canonicalPath, 'utf8');
101
- const start = '<!-- NEOCORTEX-MEMORY-START -->';
102
- const end = '<!-- NEOCORTEX-MEMORY-END -->';
103
- const budget = getProjectMemoryTarget('canonical').budget;
104
- if (canonical.split(start).length !== 2 || canonical.split(end).length !== 2
105
- || canonical.indexOf(start) >= canonical.indexOf(end)
106
- || Buffer.byteLength(canonical, 'utf8') > budget.maxBytes
107
- || canonical.split('\n').length > budget.maxLines) {
108
- throw new Error('Canonical project memory markers or budget are invalid.');
109
- }
110
- const refreshed = refreshProjectMemoryTargets(options);
111
- const files = refreshed.flatMap((result) => result.files);
112
- const trackedBlocked = trackedLegacyAgentPathWrappers(refreshed);
113
- if (trackedBlocked.length > 0) {
114
- throw new Error(`Project memory verification blocked: ${LEGACY_AGENT_PATH_WRAPPER_TRACKED_REASON} ${trackedBlocked.map((entry) => `${entry.relativeFile} hint=${entry.remediation ?? `git rm ${entry.relativeFile}`}`).join('; ')}`);
115
- }
116
- if (refreshed.some((result) => (result.retiredFiles?.length ?? 0) > 0) || files.some((file) => file.changed || file.mode === 'compatibility-materialized-fallback'
117
- || file.fallbackReason || file.remediationDebt)) {
118
- throw new Error('Project memory verification found stale or fallback targets.');
119
- }
120
- let projection;
121
- try {
122
- projection = [...new Set(files.map((file) => file.relativeFile))].sort()
123
- .map((relativeFile) => {
124
- const bytes = readFileSync(join(options.projectRoot, relativeFile));
125
- const mode = files.find((file) => file.relativeFile === relativeFile).mode;
126
- return `${relativeFile}:${mode}:${createHash('sha256').update(bytes).digest('hex')}`;
127
- });
128
- if (readFileSync(canonicalPath, 'utf8') !== canonical
129
- || refreshProjectMemoryTargets(options).some((result) => result.changed)) {
130
- throw new Error('project-memory-verification-race');
131
- }
132
- }
133
- catch {
134
- throw new Error('Project memory changed during verification.');
135
- }
136
- return {
137
- schemaVersion: 'ProjectMemoryVerification/1',
138
- canonicalSha256: createHash('sha256').update(canonical).digest('hex'),
139
- projectionSha256: createHash('sha256').update(projection.join('\n')).digest('hex'),
140
- fileCount: projection.length,
141
- publicSafe: true,
142
- };
143
- }
144
- export async function refreshMemoryCliHandler(args) {
145
- try {
146
- const options = parseRefreshMemoryArgs(args);
147
- if (options.verify) {
148
- const verification = verifyProjectMemoryTargets(options);
149
- console.log(`Project memory verified: files=${verification.fileCount} canonical_sha256=${verification.canonicalSha256} projection_sha256=${verification.projectionSha256}`);
150
- return 0;
151
- }
152
- const results = refreshProjectMemoryTargets(options);
153
- const rows = results.flatMap((result) => result.files.map((file) => [
154
- file.changed ? (options.dryRun ? 'would-change' : 'changed') : 'unchanged',
155
- file.mode,
156
- file.relativeFile,
157
- file.fallbackReason ? `warning=${file.fallbackReason}` : undefined,
158
- file.remediationDebt ? `debt=${file.remediationDebt}` : undefined,
159
- file.reasonCodes && file.reasonCodes.length > 0 ? `reasons=${file.reasonCodes.join(',')}` : undefined,
160
- ].filter(Boolean).join(' ')));
161
- const retiredRows = [...new Set(results.flatMap((result) => result.retiredFiles ?? []))]
162
- .map((relativeFile) => `${options.dryRun ? 'would-retire' : 'retired'} legacy-agent-path-wrapper ${relativeFile}`);
163
- const blockedRows = trackedLegacyAgentPathWrappers(results)
164
- .map((entry) => `blocked ${LEGACY_AGENT_PATH_WRAPPER_TRACKED_REASON} ${entry.relativeFile} hint=${entry.remediation ?? `git rm ${entry.relativeFile}`}`);
165
- console.log(`${options.dryRun ? 'Project memory preview' : 'Project memory refreshed'}: ${options.projectRoot}`);
166
- for (const row of [...rows, ...retiredRows, ...blockedRows])
167
- console.log(row);
168
- return 0;
169
- }
170
- catch (error) {
171
- console.error(error instanceof Error ? error.message : String(error));
172
- return 1;
173
- }
174
- }
1
+ import{createHash as h}from"node:crypto";import{lstatSync as E,readFileSync as f}from"node:fs";import{join as u,resolve as $}from"node:path";import{getProjectMemoryTarget as P,isProjectMemoryTargetId as k,listProjectMemoryTargets as y}from"../memory/shared-project-memory-types.js";import{LEGACY_AGENT_PATH_WRAPPER_TRACKED_REASON as j,writeProjectMemoryTargetFiles as M}from"../memory/project-memory-writer.js";function g(t){return(t??"").split(",").map(e=>e.trim()).filter(Boolean)}function C(t){let e=process.cwd(),i=!1,s=!1;const c=[],l=[];for(let r=0;r<t.length;r++){const o=t[r];if(o==="--dry-run"||o==="--preview")i=!0;else if(o==="--verify")s=!0,i=!0;else if(o==="--project-root")e=t[++r]??e;else if(o.startsWith("--project-root="))e=o.slice(15);else if(o==="--target"||o==="--targets")c.push(...g(t[++r]));else if(o.startsWith("--target="))c.push(...g(o.slice(9)));else if(o.startsWith("--targets="))c.push(...g(o.slice(10)));else if(o==="--note"||o==="--memory-note"||o==="--change"){const m=t[++r];m&&l.push(m)}else o.startsWith("--note=")?l.push(o.slice(7)):o.startsWith("--memory-note=")?l.push(o.slice(14)):o.startsWith("--change=")&&l.push(o.slice(9))}if(s&&(c.length>0||l.length>0))throw new Error("Project memory verification requires all targets and no update notes.");const a=c.length>0?c.map(r=>{if(!k(r))throw new Error(`Unknown project-memory target: ${r}`);return r}):["canonical",...y().map(r=>r.targetId)];return{projectRoot:$(e),targetIds:Array.from(new Set(a)),dryRun:i,verify:s,memoryNotes:l}}function p(t){return t.targetIds.map(e=>M({projectRoot:t.projectRoot,targetId:e,dryRun:t.dryRun,memoryNotes:t.memoryNotes??[],backupDirectory:t.backupDirectory}))}function w(t){const e=new Map;for(const i of t.flatMap(s=>s.legacyAgentPathWrappers??[]))i.status==="tracked-blocked"&&!e.has(i.relativeFile)&&e.set(i.relativeFile,i);return[...e.values()].sort((i,s)=>i.relativeFile.localeCompare(s.relativeFile))}function T(t){if(!t.verify||!t.dryRun||t.memoryNotes?.length||t.targetIds.join(",")!==["canonical",...y().map(n=>n.targetId)].join(","))throw new Error("Project memory verification requires the complete read-only target set.");const e=u(t.projectRoot,"NEOCORTEX.md");let i;try{i=E(e)}catch{throw new Error("Canonical project memory is missing or unsafe.")}if(!i.isFile()||i.isSymbolicLink())throw new Error("Canonical project memory must be a regular file.");const s=f(e,"utf8"),c="<!-- NEOCORTEX-MEMORY-START -->",l="<!-- NEOCORTEX-MEMORY-END -->",a=P("canonical").budget;if(s.split(c).length!==2||s.split(l).length!==2||s.indexOf(c)>=s.indexOf(l)||Buffer.byteLength(s,"utf8")>a.maxBytes||s.split(`
2
+ `).length>a.maxLines)throw new Error("Canonical project memory markers or budget are invalid.");const r=p(t),o=r.flatMap(n=>n.files),m=w(r);if(m.length>0)throw new Error(`Project memory verification blocked: ${j} ${m.map(n=>`${n.relativeFile} hint=${n.remediation??`git rm ${n.relativeFile}`}`).join("; ")}`);if(r.some(n=>(n.retiredFiles?.length??0)>0)||o.some(n=>n.changed||n.mode==="compatibility-materialized-fallback"||n.fallbackReason||n.remediationDebt))throw new Error("Project memory verification found stale or fallback targets.");let d;try{if(d=[...new Set(o.map(n=>n.relativeFile))].sort().map(n=>{const R=f(u(t.projectRoot,n)),v=o.find(b=>b.relativeFile===n).mode;return`${n}:${v}:${h("sha256").update(R).digest("hex")}`}),f(e,"utf8")!==s||p(t).some(n=>n.changed))throw new Error("project-memory-verification-race")}catch{throw new Error("Project memory changed during verification.")}return{schemaVersion:"ProjectMemoryVerification/1",canonicalSha256:h("sha256").update(s).digest("hex"),projectionSha256:h("sha256").update(d.join(`
3
+ `)).digest("hex"),fileCount:d.length,publicSafe:!0}}async function N(t){try{const e=C(t);if(e.verify){const a=T(e);return console.log(`Project memory verified: files=${a.fileCount} canonical_sha256=${a.canonicalSha256} projection_sha256=${a.projectionSha256}`),0}const i=p(e),s=i.flatMap(a=>a.files.map(r=>[r.changed?e.dryRun?"would-change":"changed":"unchanged",r.mode,r.relativeFile,r.fallbackReason?`warning=${r.fallbackReason}`:void 0,r.remediationDebt?`debt=${r.remediationDebt}`:void 0,r.reasonCodes&&r.reasonCodes.length>0?`reasons=${r.reasonCodes.join(",")}`:void 0].filter(Boolean).join(" "))),c=[...new Set(i.flatMap(a=>a.retiredFiles??[]))].map(a=>`${e.dryRun?"would-retire":"retired"} legacy-agent-path-wrapper ${a}`),l=w(i).map(a=>`blocked ${j} ${a.relativeFile} hint=${a.remediation??`git rm ${a.relativeFile}`}`);console.log(`${e.dryRun?"Project memory preview":"Project memory refreshed"}: ${e.projectRoot}`);for(const a of[...s,...c,...l])console.log(a);return 0}catch(e){return console.error(e instanceof Error?e.message:String(e)),1}}export{C as parseRefreshMemoryArgs,N as refreshMemoryCliHandler,p as refreshProjectMemoryTargets,w as trackedLegacyAgentPathWrappers,T as verifyProjectMemoryTargets};
@@ -1,24 +1 @@
1
- export const ARCHITECTURE_PUBLIC_COMMANDS = Object.freeze([
2
- 'arch-prd', 'arch-architecture', 'arch-fitness-functions', 'arch-api-contracts', 'generate-pacts',
3
- 'arch-api-integrations', 'arch-database', 'arch-security', 'arch-design-system', 'arch-ux-design',
4
- 'arch-performance', 'arch-testing', 'arch-infrastructure', 'arch-review', 'update-memory',
5
- ]);
6
- export const ARCHITECTURE_NON_UI_COMMANDS = Object.freeze(ARCHITECTURE_PUBLIC_COMMANDS
7
- .filter(command => command !== 'arch-design-system' && command !== 'arch-ux-design'));
8
- const EXCLUDED = Object.freeze(['arch-design-system', 'arch-ux-design']);
9
- export function parseArchitectureNonUiScopeReceipt(value) {
10
- if (!value || typeof value !== 'object' || Array.isArray(value))
11
- return undefined;
12
- const receipt = value;
13
- if (Object.keys(receipt).sort().join(',') !== ['schemaVersion', 'kind', 'licenseHash', 'projectHash', 'targetEpicId',
14
- 'graphRevision', 'rootInputSha256', 'accountingId', 'applicability', 'excludedStageCommands', 'macSha256', 'publicSafe'].sort().join(',')
15
- || receipt.schemaVersion !== 1 || receipt.kind !== 'ArchitectureNonUiScope/1' || receipt.publicSafe !== true
16
- || receipt.applicability !== 'non-ui' || typeof receipt.targetEpicId !== 'string'
17
- || !/^P[1-9][0-9]{0,11}$/.test(receipt.targetEpicId) || typeof receipt.accountingId !== 'string'
18
- || !/^arch-accounting-[a-f0-9]{32}$/.test(receipt.accountingId)
19
- || !['licenseHash', 'projectHash', 'graphRevision', 'rootInputSha256', 'macSha256'].every(key => typeof receipt[key] === 'string' && /^[a-f0-9]{64}$/.test(receipt[key]))
20
- || !Array.isArray(receipt.excludedStageCommands) || receipt.excludedStageCommands.length !== EXCLUDED.length
21
- || !receipt.excludedStageCommands.every((command, index) => command === EXCLUDED[index]))
22
- return undefined;
23
- return Object.freeze({ ...receipt, excludedStageCommands: EXCLUDED });
24
- }
1
+ const i=Object.freeze(["arch-prd","arch-architecture","arch-fitness-functions","arch-api-contracts","generate-pacts","arch-api-integrations","arch-database","arch-security","arch-design-system","arch-ux-design","arch-performance","arch-testing","arch-infrastructure","arch-review","update-memory"]),n=Object.freeze(i.filter(t=>t!=="arch-design-system"&&t!=="arch-ux-design")),c=Object.freeze(["arch-design-system","arch-ux-design"]);function s(t){if(!t||typeof t!="object"||Array.isArray(t))return;const e=t;if(!(Object.keys(e).sort().join(",")!==["schemaVersion","kind","licenseHash","projectHash","targetEpicId","graphRevision","rootInputSha256","accountingId","applicability","excludedStageCommands","macSha256","publicSafe"].sort().join(",")||e.schemaVersion!==1||e.kind!=="ArchitectureNonUiScope/1"||e.publicSafe!==!0||e.applicability!=="non-ui"||typeof e.targetEpicId!="string"||!/^P[1-9][0-9]{0,11}$/.test(e.targetEpicId)||typeof e.accountingId!="string"||!/^arch-accounting-[a-f0-9]{32}$/.test(e.accountingId)||!["licenseHash","projectHash","graphRevision","rootInputSha256","macSha256"].every(r=>typeof e[r]=="string"&&/^[a-f0-9]{64}$/.test(e[r]))||!Array.isArray(e.excludedStageCommands)||e.excludedStageCommands.length!==c.length||!e.excludedStageCommands.every((r,a)=>r===c[a])))return Object.freeze({...e,excludedStageCommands:c})}export{n as ARCHITECTURE_NON_UI_COMMANDS,i as ARCHITECTURE_PUBLIC_COMMANDS,s as parseArchitectureNonUiScopeReceipt};
@@ -1,4 +1,4 @@
1
- type StoryCheckpointAction = 'setup' | 'accept-setup' | 'handoff' | 'begin' | 'finalize' | 'recover' | 'retry-c01' | 'integrate-worktree';
1
+ type StoryCheckpointAction = 'setup' | 'accept-setup' | 'handoff' | 'begin' | 'finalize' | 'recover' | 'retry-c01' | 'integrate-worktree' | 'extend-write-set';
2
2
  interface StoryCheckpointCliOptions {
3
3
  readonly action: StoryCheckpointAction;
4
4
  readonly storyId: string;
@@ -12,6 +12,10 @@ interface StoryCheckpointCliOptions {
12
12
  readonly expectedHeadSha?: string;
13
13
  readonly apply?: boolean;
14
14
  readonly leaseId?: string;
15
+ /** `integrate-worktree --stories A,B,C`: one P205 per wave (hotfix 4.61.6). */
16
+ readonly storyIds?: readonly string[];
17
+ /** `extend-write-set --paths a,b`: root-authorized write-set extension (hotfix 4.61.6). */
18
+ readonly paths?: readonly string[];
15
19
  }
16
20
  export declare function parseStoryCheckpointArgs(args: readonly string[]): StoryCheckpointCliOptions;
17
21
  export declare function storyCheckpointCliHandler(args: readonly string[]): Promise<number>;
@@ -1,203 +1 @@
1
- import { readFile } from 'node:fs/promises';
2
- import { resolve } from 'node:path';
3
- import { acceptDirectYoloSetupCheckpoint, beginDirectYoloStoryCommit, finalizeDirectYoloStoryCheckpoint, issueDirectYoloSetupLeaseHandoff, prepareDirectYoloSetup, recoverLegacyDirectYoloStoryCheckpoint, } from '../git/direct-yolo-checkpoint.js';
4
- import { applyDirectYoloC01Retry, inspectDirectYoloC01Retry } from '../git/direct-yolo-c01-retry.js';
5
- import { integrateStoryWorktree } from '../git/story-worktree-integration.js';
6
- export function parseStoryCheckpointArgs(args) {
7
- const action = args[0];
8
- if (action !== 'setup' && action !== 'accept-setup' && action !== 'handoff' && action !== 'begin' && action !== 'finalize'
9
- && action !== 'recover' && action !== 'retry-c01' && action !== 'integrate-worktree') {
10
- throw new Error('story-checkpoint-action-invalid');
11
- }
12
- let storyId = '';
13
- let projectRoot = process.cwd();
14
- let commitSha;
15
- let remote = 'origin';
16
- let push = false;
17
- let format = 'plain';
18
- let setupHandoffSessionId;
19
- let setupHandoffTokenFile;
20
- let expectedHeadSha;
21
- let apply = false;
22
- let leaseId;
23
- for (let index = 1; index < args.length; index++) {
24
- const arg = args[index];
25
- const next = () => args[++index] ?? '';
26
- if (arg === '--story')
27
- storyId = next();
28
- else if (arg.startsWith('--story='))
29
- storyId = arg.slice('--story='.length);
30
- else if (arg === '--project-root')
31
- projectRoot = next() || projectRoot;
32
- else if (arg.startsWith('--project-root='))
33
- projectRoot = arg.slice('--project-root='.length);
34
- else if (arg === '--commit')
35
- commitSha = next();
36
- else if (arg.startsWith('--commit='))
37
- commitSha = arg.slice('--commit='.length);
38
- else if (arg === '--remote')
39
- remote = next();
40
- else if (arg.startsWith('--remote='))
41
- remote = arg.slice('--remote='.length);
42
- else if (arg === '--push' || arg === '--require-remote')
43
- push = true;
44
- else if (arg === '--setup-handoff-session')
45
- setupHandoffSessionId = next();
46
- else if (arg.startsWith('--setup-handoff-session='))
47
- setupHandoffSessionId = arg.slice('--setup-handoff-session='.length);
48
- else if (arg === '--setup-handoff-token-file')
49
- setupHandoffTokenFile = next();
50
- else if (arg.startsWith('--setup-handoff-token-file='))
51
- setupHandoffTokenFile = arg.slice('--setup-handoff-token-file='.length);
52
- else if (arg === '--expected-head')
53
- expectedHeadSha = next();
54
- else if (arg.startsWith('--expected-head='))
55
- expectedHeadSha = arg.slice('--expected-head='.length);
56
- else if (arg === '--apply')
57
- apply = true;
58
- else if (arg === '--lease')
59
- leaseId = next();
60
- else if (arg.startsWith('--lease='))
61
- leaseId = arg.slice('--lease='.length);
62
- else if (arg === '--format') {
63
- const value = next();
64
- if (value !== 'json' && value !== 'plain')
65
- throw new Error('story-checkpoint-format-invalid');
66
- format = value;
67
- }
68
- else if (arg.startsWith('--format=')) {
69
- const value = arg.slice('--format='.length);
70
- if (value !== 'json' && value !== 'plain')
71
- throw new Error('story-checkpoint-format-invalid');
72
- format = value;
73
- }
74
- else {
75
- throw new Error('story-checkpoint-argument-invalid');
76
- }
77
- }
78
- if (!storyId)
79
- throw new Error('story-checkpoint-story-required');
80
- if (action === 'recover' && !commitSha)
81
- throw new Error('story-checkpoint-commit-required');
82
- if (action === 'recover' && !push)
83
- throw new Error('story-checkpoint-remote-proof-required');
84
- if (action === 'finalize' && !push)
85
- throw new Error('story-checkpoint-push-required');
86
- if (action === 'integrate-worktree' && (!push || commitSha))
87
- throw new Error(push ? 'story-checkpoint-option-invalid' : 'story-checkpoint-push-required');
88
- if (leaseId !== undefined && (action !== 'integrate-worktree' || !/^swt-[a-f0-9]{24}$/.test(leaseId))) {
89
- throw new Error('story-checkpoint-option-invalid');
90
- }
91
- if (action === 'begin' && (commitSha || push || remote !== 'origin'))
92
- throw new Error('story-checkpoint-option-invalid');
93
- if ((action === 'setup' || action === 'accept-setup' || action === 'handoff') && (commitSha || push || remote !== 'origin')) {
94
- throw new Error('story-checkpoint-option-invalid');
95
- }
96
- if (action === 'finalize' && commitSha)
97
- throw new Error('story-checkpoint-option-invalid');
98
- if ((setupHandoffSessionId === undefined) !== (setupHandoffTokenFile === undefined)) {
99
- throw new Error('story-checkpoint-setup-handoff-incomplete');
100
- }
101
- if (action !== 'begin' && (setupHandoffSessionId || setupHandoffTokenFile)) {
102
- throw new Error('story-checkpoint-option-invalid');
103
- }
104
- if (action !== 'retry-c01' && (expectedHeadSha || apply))
105
- throw new Error('story-checkpoint-option-invalid');
106
- if (action === 'retry-c01' && (commitSha || push || remote !== 'origin'
107
- || apply && !/^[a-f0-9]{40,64}$/.test(expectedHeadSha ?? '')))
108
- throw new Error('story-checkpoint-option-invalid');
109
- return {
110
- action, storyId, projectRoot: resolve(projectRoot), commitSha, remote, push, format,
111
- ...(expectedHeadSha ? { expectedHeadSha } : {}), ...(apply ? { apply } : {}), ...(leaseId ? { leaseId } : {}),
112
- ...(setupHandoffSessionId ? { setupHandoffSessionId } : {}),
113
- ...(setupHandoffTokenFile ? { setupHandoffTokenFile: resolve(setupHandoffTokenFile) } : {}),
114
- };
115
- }
116
- export async function storyCheckpointCliHandler(args) {
117
- let options;
118
- try {
119
- options = parseStoryCheckpointArgs(args);
120
- }
121
- catch (error) {
122
- console.error(error instanceof Error ? error.message : 'story-checkpoint-arguments-invalid');
123
- return 1;
124
- }
125
- if (options.action === 'retry-c01') {
126
- try {
127
- const result = options.apply
128
- ? await applyDirectYoloC01Retry(options.projectRoot, options.storyId, options.expectedHeadSha)
129
- : await inspectDirectYoloC01Retry(options.projectRoot, options.storyId);
130
- console.log(options.format === 'json' ? JSON.stringify(result, null, 2)
131
- : `story-checkpoint retry-c01: ${options.apply ? 'committed' : 'eligible'}`);
132
- return 0;
133
- }
134
- catch (error) {
135
- console.error(error instanceof Error ? error.message : 'direct-yolo-retry-unverified');
136
- return 1;
137
- }
138
- }
139
- let setupLeaseHandoff;
140
- if (options.setupHandoffSessionId && options.setupHandoffTokenFile) {
141
- try {
142
- setupLeaseHandoff = {
143
- sessionId: options.setupHandoffSessionId,
144
- token: (await readFile(options.setupHandoffTokenFile, 'utf8')).trim(),
145
- };
146
- }
147
- catch {
148
- console.error('story-checkpoint-setup-handoff-read-failed');
149
- return 1;
150
- }
151
- }
152
- if (options.action === 'integrate-worktree') {
153
- const integrated = await integrateStoryWorktree({
154
- projectRoot: options.projectRoot, storyId: options.storyId, push: options.push, remote: options.remote,
155
- ...(options.leaseId ? { leaseId: options.leaseId } : {}),
156
- });
157
- if (options.format === 'json') {
158
- console.log(JSON.stringify({ action: options.action, ...integrated }, null, 2));
159
- }
160
- else if (integrated.ok) {
161
- console.log(`story-checkpoint ${options.action}: ${integrated.value.outcome}`);
162
- if (integrated.value.checkpointHeadSha)
163
- console.log(`head=${integrated.value.checkpointHeadSha}`);
164
- for (const path of integrated.value.conflictPaths ?? [])
165
- console.log(`conflict=${path}`);
166
- }
167
- else {
168
- console.error(`story-checkpoint ${options.action}: ${integrated.reasonCode}`);
169
- }
170
- return integrated.ok ? 0 : 1;
171
- }
172
- const result = options.action === 'setup'
173
- ? await prepareDirectYoloSetup(options)
174
- : options.action === 'accept-setup'
175
- ? await acceptDirectYoloSetupCheckpoint(options)
176
- : options.action === 'handoff'
177
- ? await issueDirectYoloSetupLeaseHandoff(options)
178
- : options.action === 'begin'
179
- ? await beginDirectYoloStoryCommit({ ...options, ...(setupLeaseHandoff ? { setupLeaseHandoff } : {}) })
180
- : options.action === 'finalize'
181
- ? await finalizeDirectYoloStoryCheckpoint(options)
182
- : await recoverLegacyDirectYoloStoryCheckpoint({
183
- ...options,
184
- commitSha: options.commitSha,
185
- });
186
- if (options.format === 'json') {
187
- console.log(JSON.stringify({ action: options.action, ...result }, null, 2));
188
- }
189
- else if (result.ok) {
190
- console.log(`story-checkpoint ${options.action}: ok`);
191
- if (options.action === 'begin' && 'trailers' in result.value) {
192
- for (const trailer of result.value.trailers)
193
- console.log(trailer);
194
- }
195
- else if ('headSha' in result.value) {
196
- console.log(`head=${result.value.headSha}`);
197
- }
198
- }
199
- else {
200
- console.error(`story-checkpoint ${options.action}: ${result.reasonCode}`);
201
- }
202
- return result.ok ? 0 : 1;
203
- }
1
+ import{readFile as S}from"node:fs/promises";import{resolve as $}from"node:path";import{acceptDirectYoloSetupCheckpoint as E,beginDirectYoloStoryCommit as I,finalizeDirectYoloStoryCheckpoint as j,issueDirectYoloSetupLeaseHandoff as C,prepareDirectYoloSetup as x,recoverLegacyDirectYoloStoryCheckpoint as H}from"../git/direct-yolo-checkpoint.js";import{applyDirectYoloC01Retry as R,inspectDirectYoloC01Retry as W}from"../git/direct-yolo-c01-retry.js";import{integrateStoryWorktree as z,integrateStoryWorktreeWave as D}from"../git/story-worktree-integration.js";import{extendStoryWriteSet as Y}from"../git/story-write-set-extension.js";function b(h){const e=h[0];if(e!=="setup"&&e!=="accept-setup"&&e!=="handoff"&&e!=="begin"&&e!=="finalize"&&e!=="recover"&&e!=="retry-c01"&&e!=="integrate-worktree"&&e!=="extend-write-set")throw new Error("story-checkpoint-action-invalid");let c="",n=process.cwd(),o,r="origin",i=!1,v="plain",d,u,y,w=!1,l,k,g;for(let s=1;s<h.length;s++){const t=h[s],a=()=>h[++s]??"";if(t==="--story")c=a();else if(t.startsWith("--story="))c=t.slice(8);else if(t==="--paths")g=a();else if(t.startsWith("--paths="))g=t.slice(8);else if(t==="--stories")k=a();else if(t.startsWith("--stories="))k=t.slice(10);else if(t==="--project-root")n=a()||n;else if(t.startsWith("--project-root="))n=t.slice(15);else if(t==="--commit")o=a();else if(t.startsWith("--commit="))o=t.slice(9);else if(t==="--remote")r=a();else if(t.startsWith("--remote="))r=t.slice(9);else if(t==="--push"||t==="--require-remote")i=!0;else if(t==="--setup-handoff-session")d=a();else if(t.startsWith("--setup-handoff-session="))d=t.slice(24);else if(t==="--setup-handoff-token-file")u=a();else if(t.startsWith("--setup-handoff-token-file="))u=t.slice(27);else if(t==="--expected-head")y=a();else if(t.startsWith("--expected-head="))y=t.slice(16);else if(t==="--apply")w=!0;else if(t==="--lease")l=a();else if(t.startsWith("--lease="))l=t.slice(8);else if(t==="--format"){const p=a();if(p!=="json"&&p!=="plain")throw new Error("story-checkpoint-format-invalid");v=p}else if(t.startsWith("--format=")){const p=t.slice(9);if(p!=="json"&&p!=="plain")throw new Error("story-checkpoint-format-invalid");v=p}else throw new Error("story-checkpoint-argument-invalid")}let f;if(k!==void 0){if(e!=="integrate-worktree"||c||l!==void 0)throw new Error("story-checkpoint-option-invalid");if(f=k.split(",").map(s=>s.trim()),f.length===0||f.some(s=>!/^P[1-9][0-9]*(?:\.[0-9]+)+$/.test(s))||new Set(f).size!==f.length)throw new Error("story-checkpoint-stories-invalid")}if(!c&&!f)throw new Error("story-checkpoint-story-required");let m;if(e==="extend-write-set"){if(g===void 0)throw new Error("story-checkpoint-paths-required");if(o||i||r!=="origin"||l!==void 0)throw new Error("story-checkpoint-option-invalid");if(m=g.split(",").map(s=>s.trim()),m.length===0||m.some(s=>s.length===0))throw new Error("story-checkpoint-paths-invalid")}else if(g!==void 0)throw new Error("story-checkpoint-option-invalid");if(e==="recover"&&!o)throw new Error("story-checkpoint-commit-required");if(e==="recover"&&!i)throw new Error("story-checkpoint-remote-proof-required");if(e==="finalize"&&!i)throw new Error("story-checkpoint-push-required");if(e==="integrate-worktree"&&(!i||o))throw new Error(i?"story-checkpoint-option-invalid":"story-checkpoint-push-required");if(l!==void 0&&(e!=="integrate-worktree"||!/^swt-[a-f0-9]{24}$/.test(l)))throw new Error("story-checkpoint-option-invalid");if(e==="begin"&&(o||i||r!=="origin"))throw new Error("story-checkpoint-option-invalid");if((e==="setup"||e==="accept-setup"||e==="handoff")&&(o||i||r!=="origin"))throw new Error("story-checkpoint-option-invalid");if(e==="finalize"&&o)throw new Error("story-checkpoint-option-invalid");if(d===void 0!=(u===void 0))throw new Error("story-checkpoint-setup-handoff-incomplete");if(e!=="begin"&&(d||u))throw new Error("story-checkpoint-option-invalid");if(e!=="retry-c01"&&(y||w))throw new Error("story-checkpoint-option-invalid");if(e==="retry-c01"&&(o||i||r!=="origin"||w&&!/^[a-f0-9]{40,64}$/.test(y??"")))throw new Error("story-checkpoint-option-invalid");return{action:e,storyId:c,projectRoot:$(n),commitSha:o,remote:r,push:i,format:v,...y?{expectedHeadSha:y}:{},...w?{apply:w}:{},...l?{leaseId:l}:{},...f?{storyIds:f}:{},...m?{paths:m}:{},...d?{setupHandoffSessionId:d}:{},...u?{setupHandoffTokenFile:$(u)}:{}}}async function P(h){let e;try{e=b(h)}catch(o){return console.error(o instanceof Error?o.message:"story-checkpoint-arguments-invalid"),1}if(e.action==="retry-c01")try{const o=e.apply?await R(e.projectRoot,e.storyId,e.expectedHeadSha):await W(e.projectRoot,e.storyId);return console.log(e.format==="json"?JSON.stringify(o,null,2):`story-checkpoint retry-c01: ${e.apply?"committed":"eligible"}`),0}catch(o){return console.error(o instanceof Error?o.message:"direct-yolo-retry-unverified"),1}let c;if(e.setupHandoffSessionId&&e.setupHandoffTokenFile)try{c={sessionId:e.setupHandoffSessionId,token:(await S(e.setupHandoffTokenFile,"utf8")).trim()}}catch{return console.error("story-checkpoint-setup-handoff-read-failed"),1}if(e.action==="extend-write-set"){const o=await Y({projectRoot:e.projectRoot,storyId:e.storyId,paths:e.paths??[]});return e.format==="json"?console.log(JSON.stringify({action:e.action,...o},null,2)):o.ok?(console.log(`story-checkpoint ${e.action}: ${o.value.outcome}`),console.log(`paths=${o.value.extensionPathCount} authorized=${o.value.authorizedPathCount}`),console.log(`claim=${o.value.claimRevision}`)):console.error(`story-checkpoint ${e.action}: ${o.reasonCode}`),o.ok?0:1}if(e.action==="integrate-worktree"&&e.storyIds){const o=await D({projectRoot:e.projectRoot,storyIds:e.storyIds,push:e.push,remote:e.remote});if(e.format==="json")console.log(JSON.stringify({action:e.action,mode:"wave",...o},null,2));else if(o.ok){const r=o.value;console.log(`story-checkpoint ${e.action}: wave ${r.outcome}`),console.log(`integrated=${r.integratedStoryIds.length} gate-runs=${r.gateRuns}/${r.gateRunCap}`),console.log(`head=${r.epicHeadAfterSha}`);for(const i of r.stories)console.log(`story=${i.storyId} ${i.outcome}${i.reasonCode?` ${i.reasonCode}`:""}`)}else console.error(`story-checkpoint ${e.action}: ${o.reasonCode}`);return o.ok&&o.value.outcome!=="gate-failed"?0:1}if(e.action==="integrate-worktree"){const o=await z({projectRoot:e.projectRoot,storyId:e.storyId,push:e.push,remote:e.remote,...e.leaseId?{leaseId:e.leaseId}:{}});if(e.format==="json")console.log(JSON.stringify({action:e.action,...o},null,2));else if(o.ok){console.log(`story-checkpoint ${e.action}: ${o.value.outcome}`),o.value.checkpointHeadSha&&console.log(`head=${o.value.checkpointHeadSha}`);for(const r of o.value.conflictPaths??[])console.log(`conflict=${r}`)}else console.error(`story-checkpoint ${e.action}: ${o.reasonCode}`);return o.ok?0:1}const n=e.action==="setup"?await x(e):e.action==="accept-setup"?await E(e):e.action==="handoff"?await C(e):e.action==="begin"?await I({...e,...c?{setupLeaseHandoff:c}:{}}):e.action==="finalize"?await j(e):await H({...e,commitSha:e.commitSha});if(e.format==="json")console.log(JSON.stringify({action:e.action,...n},null,2));else if(n.ok)if(console.log(`story-checkpoint ${e.action}: ok`),e.action==="begin"&&"trailers"in n.value)for(const o of n.value.trailers)console.log(o);else"headSha"in n.value&&console.log(`head=${n.value.headSha}`);else console.error(`story-checkpoint ${e.action}: ${n.reasonCode}`);return n.ok?0:1}export{b as parseStoryCheckpointArgs,P as storyCheckpointCliHandler};