@ornexus/neocortex 4.60.73 → 4.60.75

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 (269) hide show
  1. package/dist/release-source.json +1 -1
  2. package/dist/sbom.cdx.json +1216 -1210
  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 -212
  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 -417
  18. package/packages/client/dist/agent/update-agent-yaml.js +1 -102
  19. package/packages/client/dist/agent/update-description.js +1 -251
  20. package/packages/client/dist/cache/crypto-utils.js +1 -78
  21. package/packages/client/dist/cache/encrypted-cache.d.ts +27 -0
  22. package/packages/client/dist/cache/encrypted-cache.js +1 -108
  23. package/packages/client/dist/cache/in-memory-asset-cache.js +1 -73
  24. package/packages/client/dist/cache/index.js +1 -13
  25. package/packages/client/dist/cache/protected-pi-boundary.js +1 -44
  26. package/packages/client/dist/checkpoint/checkpoint-client-reader.js +2 -127
  27. package/packages/client/dist/checkpoint/index.js +1 -11
  28. package/packages/client/dist/checkpoint/shared-checkpoint-types.js +1 -32
  29. package/packages/client/dist/cli.js +5 -358
  30. package/packages/client/dist/commands/activate.js +8 -394
  31. package/packages/client/dist/commands/architecture-answers.js +7 -274
  32. package/packages/client/dist/commands/architecture-memory-terminal.js +4 -253
  33. package/packages/client/dist/commands/architecture-non-ui-continuation.js +1 -100
  34. package/packages/client/dist/commands/architecture-root-binding.js +1 -51
  35. package/packages/client/dist/commands/cache-status.js +2 -112
  36. package/packages/client/dist/commands/config.js +1 -88
  37. package/packages/client/dist/commands/doctor.js +2 -635
  38. package/packages/client/dist/commands/invoke.d.ts +38 -1
  39. package/packages/client/dist/commands/invoke.js +143 -7200
  40. package/packages/client/dist/commands/legacy-epic-terminal.js +1 -71
  41. package/packages/client/dist/commands/legacy-story-branch.js +1 -96
  42. package/packages/client/dist/commands/legacy-story-pr.js +1 -276
  43. package/packages/client/dist/commands/mutation-qa-checkpoint.js +5 -285
  44. package/packages/client/dist/commands/mutation-qa-gate.js +1 -54
  45. package/packages/client/dist/commands/mutation-qa-git.js +1 -41
  46. package/packages/client/dist/commands/mutation-qa-policy.js +1 -102
  47. package/packages/client/dist/commands/mutation-qa-run.js +3 -219
  48. package/packages/client/dist/commands/mutation-qa-verdict.js +1 -149
  49. package/packages/client/dist/commands/mutation-qa.js +1 -220
  50. package/packages/client/dist/commands/native-agent.js +2 -136
  51. package/packages/client/dist/commands/planning-diagnosis.js +1 -43
  52. package/packages/client/dist/commands/planning-generation.js +1 -53
  53. package/packages/client/dist/commands/planning-memory.js +1 -40
  54. package/packages/client/dist/commands/planning-research.js +1 -42
  55. package/packages/client/dist/commands/private-session.js +1 -75
  56. package/packages/client/dist/commands/property-qa.js +1 -139
  57. package/packages/client/dist/commands/qa-control.js +1 -16
  58. package/packages/client/dist/commands/qa-scan-browser-launch.js +1 -55
  59. package/packages/client/dist/commands/qa-scan-browser-route.js +1 -28
  60. package/packages/client/dist/commands/qa-scan-capture.js +5 -663
  61. package/packages/client/dist/commands/qa-scan-discovery.js +3 -376
  62. package/packages/client/dist/commands/qa-scan-review.js +5 -826
  63. package/packages/client/dist/commands/qa-synthetic-backend-capture.js +1 -266
  64. package/packages/client/dist/commands/qa-synthetic-backend-review.js +1 -297
  65. package/packages/client/dist/commands/qa-synthetic-backend.js +2 -340
  66. package/packages/client/dist/commands/qa-synthetic-broker-port.js +1 -85
  67. package/packages/client/dist/commands/qa-synthetic-browser.js +1 -39
  68. package/packages/client/dist/commands/refactor-characterization.js +21 -671
  69. package/packages/client/dist/commands/refactor-commit.js +13 -399
  70. package/packages/client/dist/commands/refactor-control.js +3 -142
  71. package/packages/client/dist/commands/refactor-cpp-assertions.js +3 -93
  72. package/packages/client/dist/commands/refactor-review.js +5 -283
  73. package/packages/client/dist/commands/refactor-root.js +7 -588
  74. package/packages/client/dist/commands/refresh-memory.js +3 -156
  75. package/packages/client/dist/commands/shared-architecture-non-ui.js +1 -24
  76. package/packages/client/dist/commands/story-checkpoint.js +1 -171
  77. package/packages/client/dist/config/host-auth-broker.d.ts +31 -0
  78. package/packages/client/dist/config/host-auth-broker.js +1 -0
  79. package/packages/client/dist/config/host-auth-reference.d.ts +32 -0
  80. package/packages/client/dist/config/host-auth-reference.js +1 -0
  81. package/packages/client/dist/config/profile-directory.js +1 -13
  82. package/packages/client/dist/config/resolver-selection.js +1 -278
  83. package/packages/client/dist/config/secure-config.js +12 -281
  84. package/packages/client/dist/config.js +2 -223
  85. package/packages/client/dist/constants.js +1 -25
  86. package/packages/client/dist/context/context-collector.js +2 -222
  87. package/packages/client/dist/context/context-sanitizer.js +1 -145
  88. package/packages/client/dist/continuity/autonomous-governance.js +1 -285
  89. package/packages/client/dist/continuity/continuity-client-state-store.js +1 -1587
  90. package/packages/client/dist/continuity/invoke-hooks.js +1 -129
  91. package/packages/client/dist/continuity/migrations/001-initial-schema.js +2 -12
  92. package/packages/client/dist/continuity/migrations/002-processing-output-summary-indexes.js +2 -12
  93. package/packages/client/dist/continuity/migrations/003-headless-execution-attempts.js +2 -12
  94. package/packages/client/dist/continuity/migrations/004-outbox-delivery-state.js +2 -12
  95. package/packages/client/dist/continuity/migrations/005-bounded-headless-queue.js +2 -12
  96. package/packages/client/dist/continuity/migrations/006-native-agent-dispatches.js +2 -10
  97. package/packages/client/dist/continuity/native-agent-store.js +1 -69
  98. package/packages/client/dist/continuity/native-agent-types.d.ts +11 -0
  99. package/packages/client/dist/continuity/native-agent-types.js +1 -90
  100. package/packages/client/dist/continuity/outbox.js +1 -117
  101. package/packages/client/dist/continuity/runner-bootstrap-policy.js +1 -172
  102. package/packages/client/dist/continuity/sqlite-store.js +81 -2612
  103. package/packages/client/dist/effects/invoke-effect-gateways.js +1 -62
  104. package/packages/client/dist/errors/error-messages.d.ts +3 -0
  105. package/packages/client/dist/errors/error-messages.js +2 -228
  106. package/packages/client/dist/errors/frontmatter-diagnostics.js +1 -125
  107. package/packages/client/dist/evidence/collector.js +1 -347
  108. package/packages/client/dist/evidence/index.js +1 -1
  109. package/packages/client/dist/evidence/types.js +0 -2
  110. package/packages/client/dist/fs/atomic-state-replace.js +1 -152
  111. package/packages/client/dist/generated/command-registry.generated.js +1 -4076
  112. package/packages/client/dist/generated/public-projections.generated.js +1 -149
  113. package/packages/client/dist/git/direct-yolo-c01-retry.js +4 -138
  114. package/packages/client/dist/git/direct-yolo-checkpoint.d.ts +11 -1
  115. package/packages/client/dist/git/direct-yolo-checkpoint.js +4 -1234
  116. package/packages/client/dist/git/epic-operational-state.js +2 -672
  117. package/packages/client/dist/git/git-lifecycle-step-ids.js +1 -14
  118. package/packages/client/dist/git/git-lifecycle-store.d.ts +23 -0
  119. package/packages/client/dist/git/git-lifecycle-store.js +10 -1981
  120. package/packages/client/dist/git/legacy-story-branch-checkpoint.js +9 -259
  121. package/packages/client/dist/git/legacy-story-branch-setup.js +4 -348
  122. package/packages/client/dist/git/legacy-story-pr.js +70 -3538
  123. package/packages/client/dist/git/secure-filesystem-boundary.js +5 -182
  124. package/packages/client/dist/graph-retrieval/pre-command-hook.js +1 -284
  125. package/packages/client/dist/graph-retrieval/shared-graph-retrieval-contract.js +1 -237
  126. package/packages/client/dist/i18n/first-run.js +2 -60
  127. package/packages/client/dist/index.d.ts +2 -0
  128. package/packages/client/dist/index.js +1 -47
  129. package/packages/client/dist/invocation/invoke-input.js +1 -24
  130. package/packages/client/dist/license/host-auth-recovery.d.ts +158 -0
  131. package/packages/client/dist/license/host-auth-recovery.js +1 -0
  132. package/packages/client/dist/license/index.js +1 -5
  133. package/packages/client/dist/license/license-client.d.ts +10 -1
  134. package/packages/client/dist/license/license-client.js +1 -304
  135. package/packages/client/dist/machine/fingerprint.js +2 -163
  136. package/packages/client/dist/machine/index.js +1 -5
  137. package/packages/client/dist/memory/project-memory-path-scope.js +1 -62
  138. package/packages/client/dist/memory/project-memory-writer.js +40 -1007
  139. package/packages/client/dist/memory/shared-project-memory-types.js +2 -253
  140. package/packages/client/dist/migrations/epic-lifecycle-backfill.js +3 -1060
  141. package/packages/client/dist/migrations/project-identity-capability.js +1 -50
  142. package/packages/client/dist/migrations/project-identity.js +7 -493
  143. package/packages/client/dist/migrations/state-json.js +4 -393
  144. package/packages/client/dist/policy/architecture-policy.js +2 -184
  145. package/packages/client/dist/policy/index.js +1 -7
  146. package/packages/client/dist/policy/shared-policy-types.js +0 -38
  147. package/packages/client/dist/policy/subagent-approval-policy.js +1 -55
  148. package/packages/client/dist/private-execution/clean-baseline.js +2 -279
  149. package/packages/client/dist/private-execution/codex-executor.js +4 -574
  150. package/packages/client/dist/private-execution/codex-host-runtime.js +1 -137
  151. package/packages/client/dist/private-execution/codex-lifecycle-guard.js +1 -97
  152. package/packages/client/dist/private-execution/codex-scoped-permissions.js +1 -128
  153. package/packages/client/dist/private-execution/delivery.js +13 -410
  154. package/packages/client/dist/private-execution/diagnosis-root-review.js +2 -294
  155. package/packages/client/dist/private-execution/frozen-handoff.js +6 -19
  156. package/packages/client/dist/private-execution/implementation-validation.js +2 -106
  157. package/packages/client/dist/private-execution/isolated-admission.js +23 -1432
  158. package/packages/client/dist/private-execution/isolated-session.js +5 -725
  159. package/packages/client/dist/private-execution/isolated-workspace.js +1 -122
  160. package/packages/client/dist/private-execution/pact-consumer-runtime.js +3 -409
  161. package/packages/client/dist/private-execution/pact-test-source.js +1 -258
  162. package/packages/client/dist/private-execution/pact-toolchain.js +3 -290
  163. package/packages/client/dist/private-execution/pact-write-set.js +1 -172
  164. package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +5 -406
  165. package/packages/client/dist/private-execution/planning-generation-checkpoint.js +5 -462
  166. package/packages/client/dist/private-execution/planning-memory-checkpoint.js +3 -139
  167. package/packages/client/dist/private-execution/planning-research-checkpoint.js +4 -325
  168. package/packages/client/dist/private-execution/private-report-store.js +1 -42
  169. package/packages/client/dist/private-execution/property-test-candidate.js +1 -103
  170. package/packages/client/dist/private-execution/property-test-choices.js +3 -147
  171. package/packages/client/dist/private-execution/property-test-plan.js +7 -271
  172. package/packages/client/dist/private-execution/property-test-review.js +4 -258
  173. package/packages/client/dist/private-execution/property-test-runtime.js +9 -372
  174. package/packages/client/dist/private-execution/property-test-source.js +1 -139
  175. package/packages/client/dist/private-execution/root-checkpoint.js +1 -80
  176. package/packages/client/dist/private-execution/root-memory-git-evidence.js +3 -135
  177. package/packages/client/dist/private-execution/root-memory-recovery.js +1 -93
  178. package/packages/client/dist/private-execution/root-memory-request.js +1 -29
  179. package/packages/client/dist/private-execution/root-memory-scope.js +1 -178
  180. package/packages/client/dist/private-execution/root-memory-writer.js +1 -102
  181. package/packages/client/dist/private-execution/session-lease.js +1 -63
  182. package/packages/client/dist/private-execution/shared-private-admission-types.js +1 -50
  183. package/packages/client/dist/private-execution/shared-project-validation.js +1 -66
  184. package/packages/client/dist/private-execution/shared-root-memory-types.js +1 -61
  185. package/packages/client/dist/private-execution/ux-source-validation.js +1 -372
  186. package/packages/client/dist/private-execution/ux-write-set.js +2 -191
  187. package/packages/client/dist/registry/registry-reconciliation.js +1 -234
  188. package/packages/client/dist/resilience/circuit-breaker.js +1 -170
  189. package/packages/client/dist/resilience/degradation-manager.js +1 -164
  190. package/packages/client/dist/resilience/freshness-indicator.js +1 -100
  191. package/packages/client/dist/resilience/index.js +1 -8
  192. package/packages/client/dist/resilience/recovery-detector.js +1 -74
  193. package/packages/client/dist/resolvers/asset-resolver.js +0 -13
  194. package/packages/client/dist/resolvers/local-resolver.js +8 -255
  195. package/packages/client/dist/resolvers/remote-resolver.js +1 -233
  196. package/packages/client/dist/runner/binary.js +1 -404
  197. package/packages/client/dist/runner/cli.js +17 -1571
  198. package/packages/client/dist/runner/epic-background-dispatcher.d.ts +61 -0
  199. package/packages/client/dist/runner/epic-background-dispatcher.js +1 -0
  200. package/packages/client/dist/runner/headless/adapters.js +1 -49
  201. package/packages/client/dist/runner/headless/background-root.d.ts +65 -0
  202. package/packages/client/dist/runner/headless/background-root.js +1 -0
  203. package/packages/client/dist/runner/headless/claude-code-adapter.js +1 -79
  204. package/packages/client/dist/runner/headless/continuous-story-workspace.js +11 -1628
  205. package/packages/client/dist/runner/headless/epic-git-reconciliation-inventory.js +1 -69
  206. package/packages/client/dist/runner/headless/epic-merge-candidate-qa.d.ts +1 -1
  207. package/packages/client/dist/runner/headless/epic-merge-candidate-qa.js +2 -110
  208. package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.d.ts +2 -0
  209. package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +10 -1236
  210. package/packages/client/dist/runner/headless/epic-terminal-git-runner.d.ts +27 -2
  211. package/packages/client/dist/runner/headless/epic-terminal-git-runner.js +2 -318
  212. package/packages/client/dist/runner/headless/fake-adapter.js +1 -62
  213. package/packages/client/dist/runner/headless/managed-environment-cleanup.d.ts +95 -0
  214. package/packages/client/dist/runner/headless/managed-environment-cleanup.js +1 -0
  215. package/packages/client/dist/runner/headless/managed-profile.js +1 -132
  216. package/packages/client/dist/runner/headless/opencode-adapter.js +2 -145
  217. package/packages/client/dist/runner/headless/prepared-story-bundle.js +1 -43
  218. package/packages/client/dist/runner/headless/resolver.js +1 -231
  219. package/packages/client/dist/runner/headless/run-yolo.js +1 -885
  220. package/packages/client/dist/runner/headless/run-yoloop.d.ts +1 -0
  221. package/packages/client/dist/runner/headless/run-yoloop.js +2 -2574
  222. package/packages/client/dist/runner/headless/types.js +2 -574
  223. package/packages/client/dist/runner/local-console.js +13 -396
  224. package/packages/client/dist/runner/portal-sync-worker.js +1 -1487
  225. package/packages/client/dist/runner/project-identity.js +1 -106
  226. package/packages/client/dist/runner/scheduler.js +7 -995
  227. package/packages/client/dist/runner-cli.js +2 -18
  228. package/packages/client/dist/state/invocation-shape.js +1 -13
  229. package/packages/client/dist/state/project-state-snapshot.d.ts +7 -0
  230. package/packages/client/dist/state/project-state-snapshot.js +1 -1731
  231. package/packages/client/dist/state/state-json-repair.js +3 -785
  232. package/packages/client/dist/state/structural-dag-projection.js +1 -118
  233. package/packages/client/dist/telemetry/index.js +1 -5
  234. package/packages/client/dist/telemetry/offline-queue.js +1 -131
  235. package/packages/client/dist/tier/index.js +1 -5
  236. package/packages/client/dist/tier/tier-aware-client.js +1 -405
  237. package/packages/client/dist/types/index.js +1 -38
  238. package/packages/client/dist/version.js +1 -27
  239. package/packages/client/dist/yolo/change-evidence-collector.d.ts +21 -1
  240. package/packages/client/dist/yolo/change-evidence-collector.js +1 -126
  241. package/packages/client/dist/yolo/invoke-envelope-capability.js +1 -62
  242. package/packages/client/dist/yolo/spec-envelope-collector.js +5 -184
  243. package/packages/client/dist/yoloop/discovery-hook.js +2 -300
  244. package/packages/client/dist/yoloop/index.js +1 -8
  245. package/packages/client/dist/yoloop/invoke-hooks.js +12 -669
  246. package/packages/client/dist/yoloop/shared-discover-epics.js +1 -1007
  247. package/packages/client/dist/yoloop/shared-yoloop-types.js +1 -33
  248. package/packages/client/dist/yoloop/target-normalization.js +1 -180
  249. package/packages/client/dist/yoloop/yoloop-client-state-store.js +1 -1920
  250. package/packages/shared/dist/invocation/explicit-intent-recovery.d.ts +83 -0
  251. package/packages/shared/dist/invocation/explicit-intent-recovery.js +187 -0
  252. package/packages/shared/dist/invocation/index.d.ts +7 -0
  253. package/packages/shared/dist/invocation/index.js +22 -0
  254. package/packages/shared/dist/yolo/change-evidence.js +1 -1
  255. package/packages/shared/dist/yoloop/epic-terminal-git.js +144 -2
  256. package/targets-stubs/antigravity/gemini.md +1 -1
  257. package/targets-stubs/antigravity/skill/SKILL.md +1 -1
  258. package/targets-stubs/claude-code/neocortex-root.agent.yaml +1 -1
  259. package/targets-stubs/claude-code/neocortex-root.md +2 -2
  260. package/targets-stubs/claude-code/neocortex.agent.yaml +1 -1
  261. package/targets-stubs/claude-code/neocortex.md +2 -2
  262. package/targets-stubs/codex/AGENTS.md +24 -21
  263. package/targets-stubs/codex/README.md +6 -1
  264. package/targets-stubs/codex/neocortex.toml +7 -2
  265. package/targets-stubs/cursor/agent.md +2 -2
  266. package/targets-stubs/gemini-cli/agent.md +2 -2
  267. package/targets-stubs/opencode/neocortex-root.md +16 -1
  268. package/targets-stubs/opencode/neocortex.md +6 -0
  269. package/targets-stubs/vscode/neocortex.agent.md +2 -2
@@ -1,127 +1,2 @@
1
- /**
2
- * Epic P109.05: Checkpoint client-side reader (fail-soft).
3
- *
4
- * Reads `.neocortex/checkpoint-pending.json` (written by agent per P109.04
5
- * step prompt instructions), validates shape against ImplementCheckpointSnapshot
6
- * (P109.02), and consumes (deletes) the file to prevent re-send.
7
- *
8
- * Cross-refs: P107.02 (architecture-policy reader pattern), P101.06 (atomic
9
- * file ops), P63.01 (UTF-8 BOM strip), P103.06 (CRLF normalize).
10
- */
11
- import { promises as fs } from 'node:fs';
12
- import path from 'node:path';
13
- import { MAX_SNAPSHOT_SIZE_BYTES } from './shared-checkpoint-types.js';
14
- /**
15
- * Canonical pending-checkpoint path (relative to projectRoot).
16
- * Matches P109.04 step prompt instruction literal.
17
- */
18
- export const CHECKPOINT_PENDING_PATH = '.neocortex/checkpoint-pending.json';
19
- /**
20
- * Size buffer over the server-enforced MAX_SNAPSHOT_SIZE_BYTES to account for
21
- * JSON structural overhead (field names, quotes, commas). Guards against
22
- * pathological huge files before parse attempts.
23
- */
24
- const SIZE_BUFFER_BYTES = 10000;
25
- const VALID_PHASES = ['FASE_1', 'FASE_2', 'FASE_3', 'FASE_4'];
26
- /**
27
- * Pure validation (zero I/O). Deterministic.
28
- *
29
- * Checks all required fields of ImplementCheckpointSnapshot shape. Extra fields
30
- * are ignored (forward-compat). Does NOT enforce MAX_SNAPSHOT_SIZE_BYTES on
31
- * snapshotMd length -- that is the reader's responsibility and server's
32
- * final truncation (P109.06).
33
- */
34
- export function validateSnapshot(candidate) {
35
- if (candidate === null || typeof candidate !== 'object') {
36
- return { valid: false, errors: ['payload must be object'] };
37
- }
38
- const obj = candidate;
39
- const errors = [];
40
- if (typeof obj.storyId !== 'string' || obj.storyId.length === 0) {
41
- errors.push('storyId must be non-empty string');
42
- }
43
- if (typeof obj.turn !== 'number' || !Number.isFinite(obj.turn) || obj.turn < 0) {
44
- errors.push('turn must be non-negative finite number');
45
- }
46
- if (!Array.isArray(obj.filesModified) ||
47
- !obj.filesModified.every((x) => typeof x === 'string')) {
48
- errors.push('filesModified must be string[]');
49
- }
50
- if (!Array.isArray(obj.testsModified) ||
51
- !obj.testsModified.every((x) => typeof x === 'string')) {
52
- errors.push('testsModified must be string[]');
53
- }
54
- if (typeof obj.currentPhase !== 'string' ||
55
- !VALID_PHASES.includes(obj.currentPhase)) {
56
- errors.push(`currentPhase must be one of ${VALID_PHASES.join('|')}`);
57
- }
58
- if (typeof obj.snapshotMd !== 'string') {
59
- errors.push('snapshotMd must be string');
60
- }
61
- return { valid: errors.length === 0, errors: Object.freeze(errors) };
62
- }
63
- /**
64
- * Read + validate + consume (delete) the pending checkpoint file.
65
- *
66
- * Fail-soft contract:
67
- * - ENOENT (common case -- no checkpoint pending) -> undefined, silent.
68
- * - Any other read error -> undefined + console.warn.
69
- * - Malformed JSON or schema invalid -> undefined + console.warn.
70
- * - Oversized file -> undefined + console.warn.
71
- * - Unlink failure -> caller still receives snapshot; warn logged.
72
- *
73
- * **File consume is critical (AC4)**: after first successful read (regardless
74
- * of validation outcome), the file is deleted to prevent re-send on next
75
- * invoke. This avoids infinite checkpoint-loop scenarios from malformed
76
- * agent-produced content.
77
- */
78
- export async function readAndConsumeCheckpoint(projectRoot) {
79
- const fullPath = path.join(projectRoot, CHECKPOINT_PENDING_PATH);
80
- let raw;
81
- try {
82
- raw = await fs.readFile(fullPath, 'utf-8');
83
- }
84
- catch (err) {
85
- if (err.code === 'ENOENT') {
86
- // Common case: no checkpoint pending. Silent (zero warn).
87
- return undefined;
88
- }
89
- // eslint-disable-next-line no-console
90
- console.warn(`[Neocortex] checkpoint read failed: ${err instanceof Error ? err.message : String(err)}`);
91
- return undefined;
92
- }
93
- // Consume before returning so the enclosing capability drains the physical
94
- // unlink before an invocation receipt can complete.
95
- try {
96
- await fs.unlink(fullPath);
97
- }
98
- catch (unlinkErr) {
99
- // eslint-disable-next-line no-console
100
- console.warn(`[Neocortex] checkpoint unlink failed: ${unlinkErr instanceof Error ? unlinkErr.message : String(unlinkErr)}`);
101
- }
102
- // Encoding defense: BOM strip (P63.01) + CRLF normalize (P103.06).
103
- const normalized = raw.replace(/^/, '').replace(/\r\n/g, '\n');
104
- // Size guard (AC5): reject pathologically large files before parse.
105
- if (normalized.length > MAX_SNAPSHOT_SIZE_BYTES + SIZE_BUFFER_BYTES) {
106
- // eslint-disable-next-line no-console
107
- console.warn(`[Neocortex] checkpoint oversized (${normalized.length} bytes), skipping`);
108
- return undefined;
109
- }
110
- let parsed;
111
- try {
112
- parsed = JSON.parse(normalized);
113
- }
114
- catch (err) {
115
- // eslint-disable-next-line no-console
116
- console.warn(`[Neocortex] checkpoint malformed JSON: ${err instanceof Error ? err.message : String(err)}`);
117
- return undefined;
118
- }
119
- const validation = validateSnapshot(parsed);
120
- if (!validation.valid) {
121
- // eslint-disable-next-line no-console
122
- console.warn(`[Neocortex] checkpoint schema invalid: ${validation.errors.join('; ')}`);
123
- return undefined;
124
- }
125
- // Safe to cast after validation.
126
- return parsed;
127
- }
1
+ import{promises as a}from"node:fs";import f from"node:path";import{MAX_SNAPSHOT_SIZE_BYTES as u}from"./shared-checkpoint-types.js";const d=".neocortex/checkpoint-pending.json",p=1e4,c=["FASE_1","FASE_2","FASE_3","FASE_4"];function l(o){if(o===null||typeof o!="object")return{valid:!1,errors:["payload must be object"]};const e=o,n=[];return(typeof e.storyId!="string"||e.storyId.length===0)&&n.push("storyId must be non-empty string"),(typeof e.turn!="number"||!Number.isFinite(e.turn)||e.turn<0)&&n.push("turn must be non-negative finite number"),(!Array.isArray(e.filesModified)||!e.filesModified.every(t=>typeof t=="string"))&&n.push("filesModified must be string[]"),(!Array.isArray(e.testsModified)||!e.testsModified.every(t=>typeof t=="string"))&&n.push("testsModified must be string[]"),(typeof e.currentPhase!="string"||!c.includes(e.currentPhase))&&n.push(`currentPhase must be one of ${c.join("|")}`),typeof e.snapshotMd!="string"&&n.push("snapshotMd must be string"),{valid:n.length===0,errors:Object.freeze(n)}}async function y(o){const e=f.join(o,d);let n;try{n=await a.readFile(e,"utf-8")}catch(r){if(r.code==="ENOENT")return;console.warn(`[Neocortex] checkpoint read failed: ${r instanceof Error?r.message:String(r)}`);return}try{await a.unlink(e)}catch(r){console.warn(`[Neocortex] checkpoint unlink failed: ${r instanceof Error?r.message:String(r)}`)}const t=n.replace(/^/,"").replace(/\r\n/g,`
2
+ `);if(t.length>u+p){console.warn(`[Neocortex] checkpoint oversized (${t.length} bytes), skipping`);return}let i;try{i=JSON.parse(t)}catch(r){console.warn(`[Neocortex] checkpoint malformed JSON: ${r instanceof Error?r.message:String(r)}`);return}const s=l(i);if(!s.valid){console.warn(`[Neocortex] checkpoint schema invalid: ${s.errors.join("; ")}`);return}return i}export{d as CHECKPOINT_PENDING_PATH,y as readAndConsumeCheckpoint,l as validateSnapshot};
@@ -1,11 +1 @@
1
- /**
2
- * Epic P109.05: Checkpoint client-side module barrel.
3
- *
4
- * Exports the fail-soft reader + validator + canonical path const.
5
- * Re-exports wire-format types from local SSoT-Shadow inline (P117.01) so
6
- * the published client tarball never references `@neocortex/shared` at
7
- * runtime. Type identity stays in sync with `@neocortex/shared` via
8
- * `checkpoint-shared-sync.test.ts` drift test.
9
- */
10
- export * from './checkpoint-client-reader.js';
11
- export { MAX_SNAPSHOT_SIZE_BYTES } from './shared-checkpoint-types.js';
1
+ export*from"./checkpoint-client-reader.js";import{MAX_SNAPSHOT_SIZE_BYTES as _}from"./shared-checkpoint-types.js";export{_ as MAX_SNAPSHOT_SIZE_BYTES};
@@ -1,32 +1 @@
1
- /**
2
- * P117.01: Inlined byte-identical types from `@neocortex/shared/checkpoints`.
3
- *
4
- * SSoT-Shadow pattern (P92.01 server precedent — server `shared-types.ts` does
5
- * the same for tier-config). Client tarball is published standalone via
6
- * `@ornexus/neocortex` and does NOT include `@neocortex/shared` as a runtime
7
- * dependency (workspace package, excluded from tarball per `.npmignore` +
8
- * `tsconfig.build.json`). Any non-erased import of `@neocortex/shared` in
9
- * `packages/client/dist/**` causes runtime `ERR_MODULE_NOT_FOUND` on globally
10
- * installed `@ornexus/neocortex`.
11
- *
12
- * Live regression reproduced 2026-04-25 (Epic P117 origin):
13
- * `[Neocortex] checkpoint hook failed: Cannot find package '@neocortex/shared'
14
- * imported from .../checkpoint/checkpoint-client-reader.js. Proceeding without
15
- * checkpoint.`
16
- *
17
- * Sync responsibility: `shared-types-sync.test.ts` (P117.01 describe block) +
18
- * `checkpoint-shared-sync.test.ts` (client-side drift test). Drift test fails
19
- * CI if these diverge from SSoT.
20
- *
21
- * Defense-in-depth: `validate-pre-publish.js` ships
22
- * `validateClientNoSharedImport()` (P117.01) scanning client dist for
23
- * `@neocortex/shared` runtime references — match = exit 1 (publish blocked).
24
- *
25
- * DO NOT EDIT WITHOUT also editing `packages/shared/src/checkpoints/types.ts`.
26
- */
27
- /**
28
- * Snapshot size guard: prevents PG bloat from pathological code-paste scenarios.
29
- * Truncate snapshot_md at this byte count (P109.06 enforces).
30
- */
31
- export const MAX_SNAPSHOT_SIZE_BYTES = 50000;
32
- // === END P117.01 ===
1
+ const S=5e4;export{S as MAX_SNAPSHOT_SIZE_BYTES};
@@ -1,37 +1,5 @@
1
1
  #!/usr/bin/env node
2
- /**
3
- * @license FSL-1.1
4
- * Copyright (c) 2026 OrNexus AI
5
- *
6
- * This file is part of Neocortex CLI, licensed under the
7
- * Functional Source License, Version 1.1 (FSL-1.1).
8
- *
9
- * Change Date: February 20, 2029
10
- * Change License: MIT
11
- *
12
- * See the LICENSE file in the project root for full license text.
13
- */
14
- /**
15
- * @neocortex/client - CLI Entry Point
16
- *
17
- * Routes subcommands to their respective handlers:
18
- * neocortex-client invoke --args "..."
19
- * neocortex-client activate YOUR-LICENSE-KEY
20
- * neocortex-client config status
21
- * neocortex-client cache-status
22
- * neocortex-client doctor [--offline] [--json]
23
- * neocortex-client --help
24
- * neocortex-client --version
25
- *
26
- * Story 46.2 - AC1-AC7
27
- */
28
- import { getClientVersion } from './version.js';
29
- import { spawnSync } from 'node:child_process';
30
- import { COMMAND_REGISTRY_CHECKSUM, COMMAND_REGISTRY_VERSION, } from './generated/command-registry.generated.js';
31
- import { readProjectRegistryIdentity, reconcileRegistry, RegistryReconciliationError, REGISTRY_RECONCILIATION_REASON_CODES, } from './registry/registry-reconciliation.js';
32
- // ── Version Resolution ─────────────────────────────────────────────────────
33
- // ── Help Text ──────────────────────────────────────────────────────────────
34
- const HELP_TEXT = `
2
+ import{getClientVersion as l}from"./version.js";import{spawnSync as v}from"node:child_process";import{COMMAND_REGISTRY_CHECKSUM as p,COMMAND_REGISTRY_VERSION as d}from"./generated/command-registry.generated.js";import{readProjectRegistryIdentity as j,reconcileRegistry as m,RegistryReconciliationError as u,REGISTRY_RECONCILIATION_REASON_CODES as h}from"./registry/registry-reconciliation.js";const f=`
35
3
  neocortex-client - Neocortex Client CLI
36
4
 
37
5
  Usage:
@@ -251,328 +219,7 @@ Invocation payload boundary:
251
219
 
252
220
  License:
253
221
  Licensed under BSL-1.1 (Business Source License 1.1)
254
- `.trim();
255
- // ── Main ───────────────────────────────────────────────────────────────────
256
- // ── npm Lifecycle Guard ──────────────────────────────────────────────────
257
- // Epic 67 - Story 67.2: On Windows, npm lifecycle can invoke bin entries
258
- // with stray arguments like "pm", "install", "postinstall" etc.
259
- // Silently ignore these to avoid "Unknown command" warnings during npm install.
260
- const NPM_LIFECYCLE_ARGS = new Set([
261
- 'pm', 'install', 'postinstall', 'preinstall', 'prepublish',
262
- 'postpublish', 'preuninstall', 'postuninstall', 'preprepare',
263
- 'prepare', 'postprepare',
264
- ]);
265
- function optionValue(args, name) {
266
- const index = args.indexOf(name);
267
- return index >= 0 ? args[index + 1] : undefined;
268
- }
269
- function printRegistryReconciliationError(error) {
270
- if (error instanceof RegistryReconciliationError) {
271
- process.stderr.write(`[Neocortex] ${error.reasonCode}: ${error.remediation}\n`);
272
- return;
273
- }
274
- process.stderr.write(`[Neocortex] ${REGISTRY_RECONCILIATION_REASON_CODES.ARTIFACT_UNAVAILABLE}: registry reconciliation could not be completed safely; no invoke request was sent.\n`);
275
- }
276
- function installedRegistryIdentity() {
277
- return { version: COMMAND_REGISTRY_VERSION, checksum: COMMAND_REGISTRY_CHECKSUM };
278
- }
279
- function projectMatchesInstalled(projectRoot) {
280
- const project = readProjectRegistryIdentity(projectRoot);
281
- return !project || (project.version === COMMAND_REGISTRY_VERSION && project.checksum === COMMAND_REGISTRY_CHECKSUM);
282
- }
283
- function runReconciledInvoke(cliArgs, subArgs) {
284
- const projectRoot = optionValue(subArgs, '--project-root') || process.cwd();
285
- try {
286
- if (process.env.NEOCORTEX_REGISTRY_REEXECUTED === '1' && !projectMatchesInstalled(projectRoot)) {
287
- throw new RegistryReconciliationError(REGISTRY_RECONCILIATION_REASON_CODES.ARTIFACT_MISMATCH, 'The reinstalled client still does not match the trusted local projection; no invoke request was sent.');
288
- }
289
- const result = reconcileRegistry({
290
- projectRoot,
291
- installedVersion: getClientVersion(),
292
- installedIdentity: installedRegistryIdentity(),
293
- });
294
- if (result.status !== 'updated')
295
- return undefined;
296
- const child = spawnSync(process.execPath, [process.argv[1], ...cliArgs], {
297
- stdio: 'inherit',
298
- env: { ...process.env, NEOCORTEX_REGISTRY_REEXECUTED: '1' },
299
- shell: false,
300
- });
301
- return child.error ? 1 : child.status ?? 1;
302
- }
303
- catch (error) {
304
- printRegistryReconciliationError(error);
305
- return 1;
306
- }
307
- }
308
- async function main() {
309
- const args = process.argv.slice(2);
310
- const command = args[0];
311
- // Silently exit if invoked with npm lifecycle arguments (Epic 67 - Story 67.2)
312
- if (command && NPM_LIFECYCLE_ARGS.has(command.toLowerCase())) {
313
- process.exit(0);
314
- }
315
- if (!command || command === '--help' || command === '-h') {
316
- console.log(HELP_TEXT);
317
- process.exit(0);
318
- }
319
- if (command === '--version' || command === '-v') {
320
- // Epic P72 - Story P72.04: include BSL-1.1 license notice in --version output.
321
- // Printed to stderr so scripts that parse `neocortex-client --version` continue
322
- // to work correctly (they consume stdout only).
323
- console.log(getClientVersion());
324
- process.stderr.write('Licensed under BSL-1.1 (Business Source License 1.1)\n');
325
- process.exit(0);
326
- }
327
- const subArgs = args.slice(1);
328
- switch (command) {
329
- case 'invoke': {
330
- const reconciledExitCode = runReconciledInvoke(args, subArgs);
331
- if (reconciledExitCode !== undefined) {
332
- process.exitCode = reconciledExitCode;
333
- break;
334
- }
335
- const { invokeCliHandler, flushInvokeCliOutput } = await import('./commands/invoke.js');
336
- const exitCode = await invokeCliHandler(subArgs);
337
- const outputComplete = await flushInvokeCliOutput();
338
- // Let pending stdout/stderr writes and HTTP handles finish closing.
339
- // A forced exit can race libuv's async-handle teardown on Windows.
340
- process.exitCode = outputComplete ? exitCode : 1;
341
- break;
342
- }
343
- case 'reconcile-registry': {
344
- const projectRoot = optionValue(subArgs, '--project-root') || process.cwd();
345
- try {
346
- reconcileRegistry({
347
- projectRoot,
348
- installedVersion: getClientVersion(),
349
- installedIdentity: installedRegistryIdentity(),
350
- checkLatest: subArgs.includes('--check-latest'),
351
- });
352
- process.exitCode = 0;
353
- }
354
- catch (error) {
355
- printRegistryReconciliationError(error);
356
- process.exitCode = 1;
357
- }
358
- break;
359
- }
360
- case 'activate': {
361
- const { activate } = await import('./commands/activate.js');
362
- // Parse activate args
363
- let licenseKey;
364
- let serverUrl;
365
- let nonInteractive = false;
366
- for (let i = 0; i < subArgs.length; i++) {
367
- const arg = subArgs[i];
368
- if (arg === '--server-url') {
369
- serverUrl = subArgs[++i];
370
- }
371
- else if (arg === '--non-interactive') {
372
- nonInteractive = true;
373
- }
374
- else if (arg === '--help' || arg === '-h') {
375
- console.log(HELP_TEXT);
376
- process.exit(0);
377
- }
378
- else if (!arg.startsWith('-')) {
379
- licenseKey = arg;
380
- }
381
- }
382
- if (!licenseKey) {
383
- console.error('Error: License key is required.');
384
- console.error('Usage: neocortex-client activate <license-key>');
385
- console.error('Example: neocortex-client activate NX-PRO-ABC-123');
386
- process.exit(1);
387
- }
388
- try {
389
- const result = await activate({
390
- licenseKey,
391
- serverUrl,
392
- nonInteractive,
393
- });
394
- if (result.success) {
395
- console.log(result.message);
396
- process.exit(0);
397
- }
398
- else {
399
- console.error(result.message);
400
- process.exit(1);
401
- }
402
- }
403
- catch (err) {
404
- const message = err instanceof Error ? err.message : String(err);
405
- console.error(`Activation failed: ${message}`);
406
- process.exit(1);
407
- }
408
- break;
409
- }
410
- case 'cache-status': {
411
- // cache-status requires initialized circuit breaker and telemetry queue.
412
- // For CLI use, we provide a simplified status report.
413
- console.log('Cache status requires an active client session.');
414
- console.log('Use this command within a running Neocortex client context.');
415
- process.exit(0);
416
- break;
417
- }
418
- case 'doctor': {
419
- const { doctorCliHandler } = await import('./commands/doctor.js');
420
- const exitCode = await doctorCliHandler(subArgs);
421
- process.exit(exitCode);
422
- break;
423
- }
424
- case 'config': {
425
- const { configCliHandler } = await import('./commands/config.js');
426
- const exitCode = await configCliHandler(subArgs);
427
- process.exit(exitCode);
428
- break;
429
- }
430
- case 'refresh-memory': {
431
- const { refreshMemoryCliHandler } = await import('./commands/refresh-memory.js');
432
- const exitCode = await refreshMemoryCliHandler(subArgs);
433
- process.exit(exitCode);
434
- break;
435
- }
436
- case 'architecture-memory': {
437
- const { architectureMemoryTerminalCliHandler } = await import('./commands/architecture-memory-terminal.js');
438
- const exitCode = await architectureMemoryTerminalCliHandler(subArgs);
439
- process.exit(exitCode);
440
- break;
441
- }
442
- case 'planning-diagnosis': {
443
- const { planningDiagnosisCliHandler } = await import('./commands/planning-diagnosis.js');
444
- const exitCode = await planningDiagnosisCliHandler(subArgs);
445
- process.exit(exitCode);
446
- break;
447
- }
448
- case 'planning-research': {
449
- const { planningResearchCliHandler } = await import('./commands/planning-research.js');
450
- const exitCode = await planningResearchCliHandler(subArgs);
451
- process.exit(exitCode);
452
- break;
453
- }
454
- case 'private-session': {
455
- const { privateSessionCliHandler } = await import('./commands/private-session.js');
456
- const exitCode = await privateSessionCliHandler(subArgs);
457
- process.exit(exitCode);
458
- break;
459
- }
460
- case 'planning-memory': {
461
- const { planningMemoryCliHandler } = await import('./commands/planning-memory.js');
462
- const exitCode = await planningMemoryCliHandler(subArgs);
463
- process.exit(exitCode);
464
- break;
465
- }
466
- case 'planning-generation': {
467
- const { planningGenerationCliHandler } = await import('./commands/planning-generation.js');
468
- const exitCode = await planningGenerationCliHandler(subArgs);
469
- process.exit(exitCode);
470
- break;
471
- }
472
- case 'story-checkpoint': {
473
- const { storyCheckpointCliHandler } = await import('./commands/story-checkpoint.js');
474
- const exitCode = await storyCheckpointCliHandler(subArgs);
475
- process.exit(exitCode);
476
- break;
477
- }
478
- case 'legacy-story-branch': {
479
- const { legacyStoryBranchCliHandler } = await import('./commands/legacy-story-branch.js');
480
- const exitCode = await legacyStoryBranchCliHandler(subArgs);
481
- process.exit(exitCode);
482
- break;
483
- }
484
- case 'legacy-story-pr': {
485
- const { legacyStoryPrCliHandler } = await import('./commands/legacy-story-pr.js');
486
- const exitCode = await legacyStoryPrCliHandler(subArgs);
487
- process.exit(exitCode);
488
- break;
489
- }
490
- case 'legacy-epic-terminal': {
491
- const { legacyEpicTerminalCliHandler } = await import('./commands/legacy-epic-terminal.js');
492
- const exitCode = await legacyEpicTerminalCliHandler(subArgs);
493
- process.exit(exitCode);
494
- break;
495
- }
496
- case 'mutation-qa': {
497
- const { mutationQaCliHandler } = await import('./commands/mutation-qa.js');
498
- const exitCode = await mutationQaCliHandler(subArgs);
499
- process.exit(exitCode);
500
- break;
501
- }
502
- case 'property-qa': {
503
- const { propertyQaCliHandler } = await import('./commands/property-qa.js');
504
- const exitCode = await propertyQaCliHandler(subArgs);
505
- process.exit(exitCode);
506
- break;
507
- }
508
- case 'qa-synthetic-backend': {
509
- const { syntheticBackendCliHandler } = await import('./commands/qa-synthetic-backend.js');
510
- process.exitCode = await syntheticBackendCliHandler(args.slice(1));
511
- break;
512
- }
513
- case 'qa-scan-review': {
514
- const { qaScanReviewCliHandler } = await import('./commands/qa-scan-review.js');
515
- const exitCode = await qaScanReviewCliHandler(subArgs);
516
- process.exit(exitCode);
517
- break;
518
- }
519
- case 'qa-root': {
520
- const { qaControlCliHandler } = await import('./commands/qa-control.js');
521
- process.exit(await qaControlCliHandler(subArgs));
522
- break;
523
- }
524
- case 'refactor-root': {
525
- if (subArgs[0] === 'control') {
526
- const { refactorControlCliHandler } = await import('./commands/refactor-control.js');
527
- process.exit(await refactorControlCliHandler(subArgs));
528
- }
529
- if (subArgs[0] === 'characterize') {
530
- const { refactorCharacterizationCliHandler } = await import('./commands/refactor-characterization.js');
531
- process.exit(refactorCharacterizationCliHandler(subArgs));
532
- }
533
- if (subArgs[0] === 'review-accept' || subArgs[0] === 'review-status') {
534
- const { refactorReviewCliHandler } = await import('./commands/refactor-review.js');
535
- process.exit(await refactorReviewCliHandler(subArgs));
536
- }
537
- if (subArgs[0]?.startsWith('commit-')) {
538
- const { refactorCommitCliHandler } = await import('./commands/refactor-commit.js');
539
- process.exit(refactorCommitCliHandler(subArgs));
540
- }
541
- const { refactorRootCliHandler } = await import('./commands/refactor-root.js');
542
- const exitCode = refactorRootCliHandler(subArgs);
543
- process.exit(exitCode);
544
- break;
545
- }
546
- case 'native-agent': {
547
- const { nativeAgentCliHandler } = await import('./commands/native-agent.js');
548
- const exitCode = await nativeAgentCliHandler(subArgs);
549
- process.exit(exitCode);
550
- break;
551
- }
552
- case 'architecture-answers': {
553
- const { architectureAnswersCliHandler } = await import('./commands/architecture-answers.js');
554
- const exitCode = await architectureAnswersCliHandler(subArgs);
555
- process.exit(exitCode);
556
- break;
557
- }
558
- case 'update': {
559
- // P86.08: Redirect to `neocortex update` which handles npm install -g
560
- console.log('To update Neocortex, run:');
561
- console.log(' neocortex update');
562
- console.log('');
563
- console.log('Or manually:');
564
- console.log(' npm install -g @ornexus/neocortex@latest');
565
- process.exit(0);
566
- break;
567
- }
568
- default: {
569
- console.error(`Unknown command: ${command}`);
570
- console.error('Run "neocortex-client --help" for usage information.');
571
- process.exit(1);
572
- }
573
- }
574
- }
575
- main().catch((err) => {
576
- console.error(`Fatal error: ${err instanceof Error ? err.message : String(err)}`);
577
- process.exit(1);
578
- });
222
+ `.trim(),w=new Set(["pm","install","postinstall","preinstall","prepublish","postpublish","preuninstall","postuninstall","preprepare","prepare","postprepare"]);function y(r,a){const o=r.indexOf(a);return o>=0?r[o+1]:void 0}function g(r){if(r instanceof u){process.stderr.write(`[Neocortex] ${r.reasonCode}: ${r.remediation}
223
+ `);return}process.stderr.write(`[Neocortex] ${h.ARTIFACT_UNAVAILABLE}: registry reconciliation could not be completed safely; no invoke request was sent.
224
+ `)}function x(){return{version:d,checksum:p}}function b(r){const a=j(r);return!a||a.version===d&&a.checksum===p}function k(r,a){const o=y(a,"--project-root")||process.cwd();try{if(process.env.NEOCORTEX_REGISTRY_REEXECUTED==="1"&&!b(o))throw new u(h.ARTIFACT_MISMATCH,"The reinstalled client still does not match the trusted local projection; no invoke request was sent.");if(m({projectRoot:o,installedVersion:l(),installedIdentity:x()}).status!=="updated")return;const t=v(process.execPath,[process.argv[1],...r],{stdio:"inherit",env:{...process.env,NEOCORTEX_REGISTRY_REEXECUTED:"1"},shell:!1});return t.error?1:t.status??1}catch(e){return g(e),1}}async function C(){const r=process.argv.slice(2),a=r[0];a&&w.has(a.toLowerCase())&&process.exit(0),(!a||a==="--help"||a==="-h")&&(console.log(f),process.exit(0)),(a==="--version"||a==="-v")&&(console.log(l()),process.stderr.write(`Licensed under BSL-1.1 (Business Source License 1.1)
225
+ `),process.exit(0));const o=r.slice(1);switch(a){case"invoke":{const e=k(r,o);if(e!==void 0){process.exitCode=e;break}const{invokeCliHandler:t,flushInvokeCliOutput:c}=await import("./commands/invoke.js"),s=await t(o),n=await c();process.exitCode=n?s:1;break}case"reconcile-registry":{const e=y(o,"--project-root")||process.cwd();try{m({projectRoot:e,installedVersion:l(),installedIdentity:x(),checkLatest:o.includes("--check-latest")}),process.exitCode=0}catch(t){g(t),process.exitCode=1}break}case"activate":{const{activate:e}=await import("./commands/activate.js");let t,c,s=!1;for(let n=0;n<o.length;n++){const i=o[n];i==="--server-url"?c=o[++n]:i==="--non-interactive"?s=!0:i==="--help"||i==="-h"?(console.log(f),process.exit(0)):i.startsWith("-")||(t=i)}t||(console.error("Error: License key is required."),console.error("Usage: neocortex-client activate <license-key>"),console.error("Example: neocortex-client activate NX-PRO-ABC-123"),process.exit(1));try{const n=await e({licenseKey:t,serverUrl:c,nonInteractive:s});n.success?(console.log(n.message),process.exit(0)):(console.error(n.message),process.exit(1))}catch(n){const i=n instanceof Error?n.message:String(n);console.error(`Activation failed: ${i}`),process.exit(1)}break}case"cache-status":{console.log("Cache status requires an active client session."),console.log("Use this command within a running Neocortex client context."),process.exit(0);break}case"doctor":{const{doctorCliHandler:e}=await import("./commands/doctor.js"),t=await e(o);process.exit(t);break}case"config":{const{configCliHandler:e}=await import("./commands/config.js"),t=await e(o);process.exit(t);break}case"refresh-memory":{const{refreshMemoryCliHandler:e}=await import("./commands/refresh-memory.js"),t=await e(o);process.exit(t);break}case"architecture-memory":{const{architectureMemoryTerminalCliHandler:e}=await import("./commands/architecture-memory-terminal.js"),t=await e(o);process.exit(t);break}case"planning-diagnosis":{const{planningDiagnosisCliHandler:e}=await import("./commands/planning-diagnosis.js"),t=await e(o);process.exit(t);break}case"planning-research":{const{planningResearchCliHandler:e}=await import("./commands/planning-research.js"),t=await e(o);process.exit(t);break}case"private-session":{const{privateSessionCliHandler:e}=await import("./commands/private-session.js"),t=await e(o);process.exit(t);break}case"planning-memory":{const{planningMemoryCliHandler:e}=await import("./commands/planning-memory.js"),t=await e(o);process.exit(t);break}case"planning-generation":{const{planningGenerationCliHandler:e}=await import("./commands/planning-generation.js"),t=await e(o);process.exit(t);break}case"story-checkpoint":{const{storyCheckpointCliHandler:e}=await import("./commands/story-checkpoint.js"),t=await e(o);process.exit(t);break}case"legacy-story-branch":{const{legacyStoryBranchCliHandler:e}=await import("./commands/legacy-story-branch.js"),t=await e(o);process.exit(t);break}case"legacy-story-pr":{const{legacyStoryPrCliHandler:e}=await import("./commands/legacy-story-pr.js"),t=await e(o);process.exit(t);break}case"legacy-epic-terminal":{const{legacyEpicTerminalCliHandler:e}=await import("./commands/legacy-epic-terminal.js"),t=await e(o);process.exit(t);break}case"mutation-qa":{const{mutationQaCliHandler:e}=await import("./commands/mutation-qa.js"),t=await e(o);process.exit(t);break}case"property-qa":{const{propertyQaCliHandler:e}=await import("./commands/property-qa.js"),t=await e(o);process.exit(t);break}case"qa-synthetic-backend":{const{syntheticBackendCliHandler:e}=await import("./commands/qa-synthetic-backend.js");process.exitCode=await e(r.slice(1));break}case"qa-scan-review":{const{qaScanReviewCliHandler:e}=await import("./commands/qa-scan-review.js"),t=await e(o);process.exit(t);break}case"qa-root":{const{qaControlCliHandler:e}=await import("./commands/qa-control.js");process.exit(await e(o));break}case"refactor-root":{if(o[0]==="control"){const{refactorControlCliHandler:c}=await import("./commands/refactor-control.js");process.exit(await c(o))}if(o[0]==="characterize"){const{refactorCharacterizationCliHandler:c}=await import("./commands/refactor-characterization.js");process.exit(c(o))}if(o[0]==="review-accept"||o[0]==="review-status"){const{refactorReviewCliHandler:c}=await import("./commands/refactor-review.js");process.exit(await c(o))}if(o[0]?.startsWith("commit-")){const{refactorCommitCliHandler:c}=await import("./commands/refactor-commit.js");process.exit(c(o))}const{refactorRootCliHandler:e}=await import("./commands/refactor-root.js"),t=e(o);process.exit(t);break}case"native-agent":{const{nativeAgentCliHandler:e}=await import("./commands/native-agent.js"),t=await e(o);process.exit(t);break}case"architecture-answers":{const{architectureAnswersCliHandler:e}=await import("./commands/architecture-answers.js"),t=await e(o);process.exit(t);break}case"update":{console.log("To update Neocortex, run:"),console.log(" neocortex update"),console.log(""),console.log("Or manually:"),console.log(" npm install -g @ornexus/neocortex@latest"),process.exit(0);break}default:console.error(`Unknown command: ${a}`),console.error('Run "neocortex-client --help" for usage information.'),process.exit(1)}}C().catch(r=>{console.error(`Fatal error: ${r instanceof Error?r.message:String(r)}`),process.exit(1)});