@ornexus/neocortex 4.60.73 → 4.60.74

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 (241) 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.js +1 -108
  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 -358
  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 +143 -7200
  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 -156
  73. package/packages/client/dist/commands/shared-architecture-non-ui.js +1 -24
  74. package/packages/client/dist/commands/story-checkpoint.js +1 -171
  75. package/packages/client/dist/config/profile-directory.js +1 -13
  76. package/packages/client/dist/config/resolver-selection.js +1 -278
  77. package/packages/client/dist/config/secure-config.js +12 -281
  78. package/packages/client/dist/config.js +2 -223
  79. package/packages/client/dist/constants.js +1 -25
  80. package/packages/client/dist/context/context-collector.js +2 -222
  81. package/packages/client/dist/context/context-sanitizer.js +1 -145
  82. package/packages/client/dist/continuity/autonomous-governance.js +1 -285
  83. package/packages/client/dist/continuity/continuity-client-state-store.js +1 -1587
  84. package/packages/client/dist/continuity/invoke-hooks.js +1 -129
  85. package/packages/client/dist/continuity/migrations/001-initial-schema.js +2 -12
  86. package/packages/client/dist/continuity/migrations/002-processing-output-summary-indexes.js +2 -12
  87. package/packages/client/dist/continuity/migrations/003-headless-execution-attempts.js +2 -12
  88. package/packages/client/dist/continuity/migrations/004-outbox-delivery-state.js +2 -12
  89. package/packages/client/dist/continuity/migrations/005-bounded-headless-queue.js +2 -12
  90. package/packages/client/dist/continuity/migrations/006-native-agent-dispatches.js +2 -10
  91. package/packages/client/dist/continuity/native-agent-store.js +1 -69
  92. package/packages/client/dist/continuity/native-agent-types.js +1 -90
  93. package/packages/client/dist/continuity/outbox.js +1 -117
  94. package/packages/client/dist/continuity/runner-bootstrap-policy.js +1 -172
  95. package/packages/client/dist/continuity/sqlite-store.js +81 -2612
  96. package/packages/client/dist/effects/invoke-effect-gateways.js +1 -62
  97. package/packages/client/dist/errors/error-messages.js +2 -228
  98. package/packages/client/dist/errors/frontmatter-diagnostics.js +1 -125
  99. package/packages/client/dist/evidence/collector.js +1 -347
  100. package/packages/client/dist/evidence/index.js +1 -1
  101. package/packages/client/dist/evidence/types.js +0 -2
  102. package/packages/client/dist/fs/atomic-state-replace.js +1 -152
  103. package/packages/client/dist/generated/command-registry.generated.js +1 -4076
  104. package/packages/client/dist/generated/public-projections.generated.js +1 -149
  105. package/packages/client/dist/git/direct-yolo-c01-retry.js +4 -138
  106. package/packages/client/dist/git/direct-yolo-checkpoint.js +4 -1234
  107. package/packages/client/dist/git/epic-operational-state.js +2 -672
  108. package/packages/client/dist/git/git-lifecycle-step-ids.js +1 -14
  109. package/packages/client/dist/git/git-lifecycle-store.d.ts +23 -0
  110. package/packages/client/dist/git/git-lifecycle-store.js +10 -1981
  111. package/packages/client/dist/git/legacy-story-branch-checkpoint.js +9 -259
  112. package/packages/client/dist/git/legacy-story-branch-setup.js +4 -348
  113. package/packages/client/dist/git/legacy-story-pr.js +70 -3538
  114. package/packages/client/dist/git/secure-filesystem-boundary.js +5 -182
  115. package/packages/client/dist/graph-retrieval/pre-command-hook.js +1 -284
  116. package/packages/client/dist/graph-retrieval/shared-graph-retrieval-contract.js +1 -237
  117. package/packages/client/dist/i18n/first-run.js +2 -60
  118. package/packages/client/dist/index.js +1 -47
  119. package/packages/client/dist/invocation/invoke-input.js +1 -24
  120. package/packages/client/dist/license/index.js +1 -5
  121. package/packages/client/dist/license/license-client.js +1 -304
  122. package/packages/client/dist/machine/fingerprint.js +2 -163
  123. package/packages/client/dist/machine/index.js +1 -5
  124. package/packages/client/dist/memory/project-memory-path-scope.js +1 -62
  125. package/packages/client/dist/memory/project-memory-writer.js +40 -1007
  126. package/packages/client/dist/memory/shared-project-memory-types.js +2 -253
  127. package/packages/client/dist/migrations/epic-lifecycle-backfill.js +3 -1060
  128. package/packages/client/dist/migrations/project-identity-capability.js +1 -50
  129. package/packages/client/dist/migrations/project-identity.js +7 -493
  130. package/packages/client/dist/migrations/state-json.js +4 -393
  131. package/packages/client/dist/policy/architecture-policy.js +2 -184
  132. package/packages/client/dist/policy/index.js +1 -7
  133. package/packages/client/dist/policy/shared-policy-types.js +0 -38
  134. package/packages/client/dist/policy/subagent-approval-policy.js +1 -55
  135. package/packages/client/dist/private-execution/clean-baseline.js +2 -279
  136. package/packages/client/dist/private-execution/codex-executor.js +4 -574
  137. package/packages/client/dist/private-execution/codex-host-runtime.js +1 -137
  138. package/packages/client/dist/private-execution/codex-lifecycle-guard.js +1 -97
  139. package/packages/client/dist/private-execution/codex-scoped-permissions.js +1 -128
  140. package/packages/client/dist/private-execution/delivery.js +13 -410
  141. package/packages/client/dist/private-execution/diagnosis-root-review.js +2 -294
  142. package/packages/client/dist/private-execution/frozen-handoff.js +6 -19
  143. package/packages/client/dist/private-execution/implementation-validation.js +2 -106
  144. package/packages/client/dist/private-execution/isolated-admission.js +23 -1432
  145. package/packages/client/dist/private-execution/isolated-session.js +5 -725
  146. package/packages/client/dist/private-execution/isolated-workspace.js +1 -122
  147. package/packages/client/dist/private-execution/pact-consumer-runtime.js +3 -409
  148. package/packages/client/dist/private-execution/pact-test-source.js +1 -258
  149. package/packages/client/dist/private-execution/pact-toolchain.js +3 -290
  150. package/packages/client/dist/private-execution/pact-write-set.js +1 -172
  151. package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +5 -406
  152. package/packages/client/dist/private-execution/planning-generation-checkpoint.js +5 -462
  153. package/packages/client/dist/private-execution/planning-memory-checkpoint.js +3 -139
  154. package/packages/client/dist/private-execution/planning-research-checkpoint.js +4 -325
  155. package/packages/client/dist/private-execution/private-report-store.js +1 -42
  156. package/packages/client/dist/private-execution/property-test-candidate.js +1 -103
  157. package/packages/client/dist/private-execution/property-test-choices.js +3 -147
  158. package/packages/client/dist/private-execution/property-test-plan.js +7 -271
  159. package/packages/client/dist/private-execution/property-test-review.js +4 -258
  160. package/packages/client/dist/private-execution/property-test-runtime.js +9 -372
  161. package/packages/client/dist/private-execution/property-test-source.js +1 -139
  162. package/packages/client/dist/private-execution/root-checkpoint.js +1 -80
  163. package/packages/client/dist/private-execution/root-memory-git-evidence.js +3 -135
  164. package/packages/client/dist/private-execution/root-memory-recovery.js +1 -93
  165. package/packages/client/dist/private-execution/root-memory-request.js +1 -29
  166. package/packages/client/dist/private-execution/root-memory-scope.js +1 -178
  167. package/packages/client/dist/private-execution/root-memory-writer.js +1 -102
  168. package/packages/client/dist/private-execution/session-lease.js +1 -63
  169. package/packages/client/dist/private-execution/shared-private-admission-types.js +1 -50
  170. package/packages/client/dist/private-execution/shared-project-validation.js +1 -66
  171. package/packages/client/dist/private-execution/shared-root-memory-types.js +1 -61
  172. package/packages/client/dist/private-execution/ux-source-validation.js +1 -372
  173. package/packages/client/dist/private-execution/ux-write-set.js +2 -191
  174. package/packages/client/dist/registry/registry-reconciliation.js +1 -234
  175. package/packages/client/dist/resilience/circuit-breaker.js +1 -170
  176. package/packages/client/dist/resilience/degradation-manager.js +1 -164
  177. package/packages/client/dist/resilience/freshness-indicator.js +1 -100
  178. package/packages/client/dist/resilience/index.js +1 -8
  179. package/packages/client/dist/resilience/recovery-detector.js +1 -74
  180. package/packages/client/dist/resolvers/asset-resolver.js +0 -13
  181. package/packages/client/dist/resolvers/local-resolver.js +8 -255
  182. package/packages/client/dist/resolvers/remote-resolver.js +1 -233
  183. package/packages/client/dist/runner/binary.js +1 -404
  184. package/packages/client/dist/runner/cli.js +17 -1571
  185. package/packages/client/dist/runner/headless/adapters.js +1 -49
  186. package/packages/client/dist/runner/headless/claude-code-adapter.js +1 -79
  187. package/packages/client/dist/runner/headless/continuous-story-workspace.js +11 -1628
  188. package/packages/client/dist/runner/headless/epic-git-reconciliation-inventory.js +1 -69
  189. package/packages/client/dist/runner/headless/epic-merge-candidate-qa.d.ts +1 -1
  190. package/packages/client/dist/runner/headless/epic-merge-candidate-qa.js +2 -110
  191. package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.d.ts +2 -0
  192. package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +10 -1236
  193. package/packages/client/dist/runner/headless/epic-terminal-git-runner.d.ts +18 -2
  194. package/packages/client/dist/runner/headless/epic-terminal-git-runner.js +2 -318
  195. package/packages/client/dist/runner/headless/fake-adapter.js +1 -62
  196. package/packages/client/dist/runner/headless/managed-profile.js +1 -132
  197. package/packages/client/dist/runner/headless/opencode-adapter.js +2 -145
  198. package/packages/client/dist/runner/headless/prepared-story-bundle.js +1 -43
  199. package/packages/client/dist/runner/headless/resolver.js +1 -231
  200. package/packages/client/dist/runner/headless/run-yolo.js +1 -885
  201. package/packages/client/dist/runner/headless/run-yoloop.d.ts +1 -0
  202. package/packages/client/dist/runner/headless/run-yoloop.js +2 -2574
  203. package/packages/client/dist/runner/headless/types.js +2 -574
  204. package/packages/client/dist/runner/local-console.js +13 -396
  205. package/packages/client/dist/runner/portal-sync-worker.js +1 -1487
  206. package/packages/client/dist/runner/project-identity.js +1 -106
  207. package/packages/client/dist/runner/scheduler.js +7 -995
  208. package/packages/client/dist/runner-cli.js +2 -18
  209. package/packages/client/dist/state/invocation-shape.js +1 -13
  210. package/packages/client/dist/state/project-state-snapshot.js +1 -1731
  211. package/packages/client/dist/state/state-json-repair.js +3 -785
  212. package/packages/client/dist/state/structural-dag-projection.js +1 -118
  213. package/packages/client/dist/telemetry/index.js +1 -5
  214. package/packages/client/dist/telemetry/offline-queue.js +1 -131
  215. package/packages/client/dist/tier/index.js +1 -5
  216. package/packages/client/dist/tier/tier-aware-client.js +1 -405
  217. package/packages/client/dist/types/index.js +1 -38
  218. package/packages/client/dist/version.js +1 -27
  219. package/packages/client/dist/yolo/change-evidence-collector.js +1 -126
  220. package/packages/client/dist/yolo/invoke-envelope-capability.js +1 -62
  221. package/packages/client/dist/yolo/spec-envelope-collector.js +5 -184
  222. package/packages/client/dist/yoloop/discovery-hook.js +2 -300
  223. package/packages/client/dist/yoloop/index.js +1 -8
  224. package/packages/client/dist/yoloop/invoke-hooks.js +12 -669
  225. package/packages/client/dist/yoloop/shared-discover-epics.js +1 -1007
  226. package/packages/client/dist/yoloop/shared-yoloop-types.js +1 -33
  227. package/packages/client/dist/yoloop/target-normalization.js +1 -180
  228. package/packages/client/dist/yoloop/yoloop-client-state-store.js +1 -1920
  229. package/packages/shared/dist/yolo/change-evidence.js +1 -1
  230. package/packages/shared/dist/yoloop/epic-terminal-git.js +144 -2
  231. package/targets-stubs/antigravity/gemini.md +1 -1
  232. package/targets-stubs/antigravity/skill/SKILL.md +1 -1
  233. package/targets-stubs/claude-code/neocortex-root.agent.yaml +1 -1
  234. package/targets-stubs/claude-code/neocortex-root.md +2 -2
  235. package/targets-stubs/claude-code/neocortex.agent.yaml +1 -1
  236. package/targets-stubs/claude-code/neocortex.md +2 -2
  237. package/targets-stubs/codex/AGENTS.md +1 -1
  238. package/targets-stubs/cursor/agent.md +2 -2
  239. package/targets-stubs/gemini-cli/agent.md +2 -2
  240. package/targets-stubs/opencode/neocortex-root.md +1 -1
  241. package/targets-stubs/vscode/neocortex.agent.md +2 -2
@@ -1,405 +1 @@
1
- /**
2
- * @license FSL-1.1
3
- * Copyright (c) 2026 OrNexus AI
4
- *
5
- * This file is part of Neocortex CLI, licensed under the
6
- * Functional Source License, Version 1.1 (FSL-1.1).
7
- *
8
- * Change Date: February 20, 2029
9
- * Change License: MIT
10
- *
11
- * See the LICENSE file in the project root for full license text.
12
- */
13
- import { GENERATED_CLIENT_COMMANDS } from '../generated/command-registry.generated.js';
14
- // ── Constants ────────────────────────────────────────────────────────────
15
- const TIER_CACHE_KEY = 'neocortex:tier';
16
- const QUOTA_CACHE_KEY_PREFIX = 'neocortex:quota:';
17
- const QUOTA_TTL_MS = 5 * 60 * 1000; // 5 minutes
18
- const TIER_CACHE_TTL_MS = 60 * 60 * 1000; // 1 hour (Story 31.05: reduced from 24h to align with short-lived JWTs)
19
- const VALID_TIERS = new Set(['free', 'pro', 'enterprise']);
20
- const DEFAULT_TIER = 'free';
21
- // ── Trigger Gates (inlined from shared tier-config to avoid import issues) ─
22
- const LEGACY_TRIGGER_GATES = {
23
- 'status': 'free',
24
- 'create-epic': 'free',
25
- 'idea-diagnose': 'free',
26
- 'idea-research': 'free',
27
- 'generate-epic': 'free',
28
- 'exec': 'pro',
29
- 'yolo': 'pro',
30
- 'epic': 'pro',
31
- 'setup-branch': 'free',
32
- 'diagnose': 'free',
33
- 'research': 'free',
34
- 'write-spec': 'free',
35
- 'create-tasks': 'free',
36
- 'implement': 'free',
37
- 'update-memory': 'free',
38
- 'commit': 'free',
39
- 'sync': 'free',
40
- 'create-pr': 'free',
41
- 'review': 'pro',
42
- 'merge': 'free',
43
- 'fix-blocked': 'free',
44
- 'finalize-epic': 'free',
45
- 'cleanup': 'free',
46
- 'resolve-conflicts': 'free',
47
- 'audit': 'free',
48
- 'menu': 'free',
49
- 'plans': 'free',
50
- 'billing': 'free',
51
- 'subscribe': 'free',
52
- 'arch-plan': 'free',
53
- 'arch-prd': 'free',
54
- 'arch-architecture': 'free',
55
- 'arch-api-contracts': 'free',
56
- 'arch-api-integrations': 'free',
57
- 'arch-database': 'free',
58
- 'arch-security': 'free',
59
- 'arch-design-system': 'free',
60
- 'arch-ux-design': 'free',
61
- 'arch-review': 'free',
62
- 'arch-fitness-functions': 'pro',
63
- 'arch-performance': 'pro',
64
- 'arch-testing': 'pro',
65
- 'arch-infrastructure': 'pro',
66
- 'refactor': 'pro',
67
- 'tech-debt': 'free',
68
- 'tech-debt-scan': 'pro',
69
- 'qa-scan': 'pro',
70
- 'mutation-test': 'pro',
71
- 'yoloop': 'pro',
72
- 'migrate-state': 'free',
73
- 'policy-audit': 'pro',
74
- 'sync-openapi': 'free',
75
- 'generate-pacts': 'pro',
76
- 'verify-pacts': 'free',
77
- 'property-test': 'pro',
78
- 'chaos-plan': 'pro',
79
- 'ui-ux-review': 'pro',
80
- 'solyd-system': 'enterprise',
81
- 'goal': 'enterprise',
82
- 'goal-tick': 'enterprise',
83
- 'loop': 'enterprise',
84
- 'loop-tick': 'enterprise',
85
- 'jobs': 'enterprise',
86
- 'runner': 'enterprise',
87
- };
88
- const TRIGGER_GATES = Object.freeze(Object.fromEntries(GENERATED_CLIENT_COMMANDS.map((entry) => [entry.id, entry.policy.minimumTier])));
89
- void LEGACY_TRIGGER_GATES;
90
- // P126.07: runtime mirror of shared COMMAND_REGISTRY command identity only.
91
- // Keep this small to avoid a runtime @neocortex/shared dependency in the
92
- // standalone client package; flexible-preflight.test.ts validates drift.
93
- const LEGACY_CLIENT_PREFLIGHT_COMMAND_REGISTRY = [
94
- { id: 'status', number: 1, aliases: ['st'] },
95
- { id: 'arch-plan', number: 3, aliases: ['arquitetura', 'architecture', 'arch'] },
96
- { id: 'arch-prd', number: 4, aliases: ['prd', 'product-requirements'] },
97
- { id: 'arch-architecture', number: 5, aliases: ['arch-doc', 'tech-architecture'] },
98
- { id: 'arch-api-contracts', number: 6, aliases: ['api-contracts', 'api-contract'] },
99
- { id: 'arch-api-integrations', number: 7, aliases: ['api-integrations', 'api-int'] },
100
- { id: 'arch-database', number: 8, aliases: ['database-schema', 'db-schema', 'db'] },
101
- { id: 'arch-security', number: 9, aliases: ['cyber-security', 'security', 'sec'] },
102
- { id: 'arch-design-system', number: 10, aliases: ['design-system', 'ds', 'atomic-design'] },
103
- { id: 'arch-ux-design', number: 11, aliases: ['ux-design', 'ux', 'wireframes', 'wireframe', 'user-flows'] },
104
- { id: 'arch-performance', number: 12, aliases: ['performance', 'perf', 'capacity-planning', 'capacity', 'arch-perf', 'performance-strategy'] },
105
- { id: 'arch-testing', number: 13, aliases: ['testing-strategy', 'test-plan', 'test-strategy', 'arch-test'] },
106
- { id: 'arch-infrastructure', number: 14, aliases: ['infrastructure', 'infra', 'deploy-plan', 'deployment', 'arch-infra', 'arch-deploy'] },
107
- { id: 'arch-review', number: 15, aliases: ['review-consolidation', 'consolidation', 'architecture-review', 'arch-consolidation'] },
108
- { id: 'arch-fitness-functions', number: 16, aliases: ['fitness', 'fitness-functions', 'archfit', 'arch-fit', 'fit-funcs'] },
109
- { id: 'create-epic', number: 17, aliases: ['criar-epic', 'planejamento'] },
110
- { id: 'idea-diagnose', number: 18, aliases: ['idea-diag'] },
111
- { id: 'idea-research', number: 19, aliases: ['idea-pesq'] },
112
- { id: 'generate-epic', number: 20, aliases: ['gerar-epic'] },
113
- { id: 'exec', number: 21, aliases: ['executar', 'pipeline'] },
114
- { id: 'yolo', number: 22, aliases: [] },
115
- { id: 'epic', number: 23, aliases: ['parallel-epic'] },
116
- { id: 'setup-branch', number: 24, aliases: ['setup', 'branch'] },
117
- { id: 'diagnose', number: 25, aliases: ['diag', 'diagnostico', 'c02'] },
118
- { id: 'research', number: 26, aliases: ['pesquisar', 'pesq', 'research-fix', 'c03'] },
119
- { id: 'write-spec', number: 27, aliases: ['spec', 'especificacao', 'c04'] },
120
- { id: 'create-tasks', number: 28, aliases: ['tasks', 'tarefas', 'c05'] },
121
- { id: 'implement', number: 29, aliases: ['impl', 'implementar', 'c06'] },
122
- { id: 'commit', number: 30, aliases: ['push', 'commit-push', 'commit_push', 'cp', 'c07'] },
123
- { id: 'sync', number: 31, aliases: ['sincronizar', 'c08'] },
124
- { id: 'create-pr', number: 32, aliases: ['pr', 'c09'] },
125
- { id: 'review', number: 33, aliases: ['revisar', 'c11'] },
126
- { id: 'merge', number: 34, aliases: ['mesclar', 'c12'] },
127
- { id: 'fix-blocked', number: 35, aliases: ['fix', 'corrigir'] },
128
- { id: 'finalize-epic', number: 36, aliases: ['finalizar'] },
129
- { id: 'resolve-conflicts', number: 37, aliases: ['conflitos'] },
130
- { id: 'update-memory', number: 38, aliases: ['memoria'] },
131
- { id: 'refactor', number: 39, aliases: ['refactoring', 'refact', 'refac', 'rf', 'cleanup-code', 'code-cleanup', 'code-quality', 'improve-code', 'modernize', 'modernization', 'legacy', 'legacy-code', 'debt-pay', 'pay-debt', 'debt-reduction', 'smell-fix', 'fix-smells', 'code-smells', 'strangler', 'strangler-fig'] },
132
- { id: 'cleanup', number: 40, aliases: ['limpar', 'limpeza'] },
133
- { id: 'audit', number: 41, aliases: ['auditar', 'auditoria'] },
134
- { id: 'tech-debt', number: 42, aliases: ['debt', 'debts', 'debt-list', 'tech-debts', 'td'] },
135
- { id: 'menu', number: 43, aliases: ['help', 'ajuda', '?', 'commands', 'cmds'] },
136
- { id: 'plans', number: 44, aliases: ['planos', 'pricing'] },
137
- { id: 'billing', number: 45, aliases: ['bill', 'subscription', 'sub'] },
138
- { id: 'subscribe', number: 46, aliases: ['upgrade', 'checkout'] },
139
- { id: 'qa-scan', number: 47, aliases: ['qa', 'qa-test', 'visual-qa', 'e2e-scan', 'troubleshoot', 'debug-ui', 'scan', 'a11y', 'accessibility', 'wcag'] },
140
- { id: 'yoloop', number: 48, aliases: ['auto-yolo', 'epic-runner', 'story-runner', 'loop-yolo', 'auto-epic'] },
141
- { id: 'migrate-state', number: 49, aliases: ['migrate', 'state-migrate', 'schema-migrate'] },
142
- { id: 'policy-audit', number: 50, aliases: ['policy', 'audit-policy', 'policy-history', 'policies'] },
143
- { id: 'mutation-test', number: 51, aliases: ['mutation', 'stryker', 'kill-mutants'] },
144
- { id: 'sync-openapi', number: 52, aliases: ['openapi-sync', 'api-sync', 'spec-sync', 'regen-openapi'] },
145
- { id: 'generate-pacts', number: 53, aliases: ['pacts', 'gen-pacts', 'regen-pacts', 'create-pacts'] },
146
- { id: 'verify-pacts', number: 54, aliases: ['verify-pact', 'pact-verify', 'check-pacts', 'pact-check'] },
147
- { id: 'property-test', number: 55, aliases: ['property', 'pbt', 'proptest', 'property-tests', 'invariant-test'] },
148
- { id: 'chaos-plan', number: 56, aliases: ['chaos', 'gameday', 'resilience-test'] },
149
- { id: 'ui-ux-review', number: 57, aliases: ['ux-review', 'design-review', 'visual-review', 'product-polish'] },
150
- { id: 'solyd-system', number: 58, aliases: ['security-system', 'authorized-security', 'sec-system'] },
151
- { id: 'goal', number: 59, aliases: ['goals', 'durable-goal', 'continuity-goal'] },
152
- { id: 'loop', number: 60, aliases: ['loops', 'durable-loop', 'continuity-loop'] },
153
- { id: 'jobs', number: 61, aliases: ['job', 'continuity-jobs'] },
154
- { id: 'runner', number: 62, aliases: ['neocortex-runner', 'continuity-runner'] },
155
- ];
156
- export const CLIENT_PREFLIGHT_COMMAND_REGISTRY = Object.freeze(GENERATED_CLIENT_COMMANDS.map((entry) => Object.freeze({
157
- id: entry.id,
158
- number: entry.number,
159
- aliases: entry.aliases,
160
- })));
161
- void LEGACY_CLIENT_PREFLIGHT_COMMAND_REGISTRY;
162
- const CLIENT_COMMAND_BY_ID = new Map(CLIENT_PREFLIGHT_COMMAND_REGISTRY.map((entry) => [entry.id, entry]));
163
- const CLIENT_COMMAND_BY_NUMBER = new Map(CLIENT_PREFLIGHT_COMMAND_REGISTRY.map((entry) => [entry.number, entry]));
164
- const CLIENT_COMMAND_ALIAS_MAP = new Map(CLIENT_PREFLIGHT_COMMAND_REGISTRY.flatMap((entry) => entry.aliases.map((alias) => [normalizeCommandToken(alias), entry.id])));
165
- export function normalizeCommandToken(input) {
166
- if (/[^\x20-\x7e]/.test(input))
167
- return '';
168
- const trimmed = input.replace(/^[\t\n\r ]+|[\t\n\r ]+$/g, '');
169
- if (!trimmed || trimmed.startsWith('**'))
170
- return '';
171
- const token = (trimmed.startsWith('*') ? trimmed.slice(1) : trimmed)
172
- .replace(/[A-Z]/g, (letter) => letter.toLowerCase());
173
- return /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(token) || token === '?' ? token : '';
174
- }
175
- export function resolveClientPreFlightTrigger(input) {
176
- const trimmed = input.trim();
177
- if (/^@?epic-[a-z0-9][a-z0-9._-]*$/i.test(trimmed))
178
- return 'epic';
179
- // P179.02: local pre-flight mirrors invoke's leading-token command contract
180
- // so Free/Pro users are gated before remote invocation for `58 plan` and
181
- // Solyd alias-with-mode forms. Only the first public token is considered.
182
- const leadingToken = trimmed.split(/\s+/, 1)[0] ?? '';
183
- const numericToken = leadingToken.trim().replace(/^\*/, '');
184
- if (/^\d+$/.test(numericToken)) {
185
- return CLIENT_COMMAND_BY_NUMBER.get(Number.parseInt(numericToken, 10))?.id ?? null;
186
- }
187
- const token = normalizeCommandToken(leadingToken);
188
- if (!token)
189
- return null;
190
- if (token === 'goal-tick')
191
- return 'goal';
192
- if (token === 'loop-tick')
193
- return 'loop';
194
- if (CLIENT_COMMAND_BY_ID.has(token))
195
- return token;
196
- return CLIENT_COMMAND_ALIAS_MAP.get(token) ?? null;
197
- }
198
- const TIER_HIERARCHY = {
199
- free: 0,
200
- pro: 1,
201
- enterprise: 2,
202
- };
203
- // ── TierAwareClient ──────────────────────────────────────────────────────
204
- export class TierAwareClient {
205
- cache;
206
- licenseClient;
207
- cachedTier = null;
208
- constructor(options) {
209
- this.cache = options.cacheProvider;
210
- this.licenseClient = options.licenseClient;
211
- }
212
- // ── Story 60.1: Tier Extraction from JWT + Cache ────────────────────
213
- /**
214
- * Get the current tier. Checks in-memory, then cache, then JWT token.
215
- * NEVER throws - returns 'free' on failure (fail-open).
216
- */
217
- async getCachedTier() {
218
- try {
219
- // 1. In-memory
220
- if (this.cachedTier)
221
- return this.cachedTier;
222
- // 2. EncryptedCache
223
- const cached = await this.cache.get(TIER_CACHE_KEY);
224
- if (cached && VALID_TIERS.has(cached)) {
225
- this.cachedTier = cached;
226
- return this.cachedTier;
227
- }
228
- // 3. Extract from JWT
229
- const token = await this.licenseClient.getToken();
230
- if (token) {
231
- const tier = this.extractTierFromJwt(token);
232
- this.cachedTier = tier;
233
- await this.cache.set(TIER_CACHE_KEY, tier, TIER_CACHE_TTL_MS).catch(() => { });
234
- return tier;
235
- }
236
- return DEFAULT_TIER;
237
- }
238
- catch {
239
- return DEFAULT_TIER;
240
- }
241
- }
242
- /**
243
- * Update cached tier (called when server returns tier info).
244
- */
245
- async updateTier(tier) {
246
- try {
247
- if (!VALID_TIERS.has(tier))
248
- return;
249
- this.cachedTier = tier;
250
- await this.cache.set(TIER_CACHE_KEY, tier, TIER_CACHE_TTL_MS).catch(() => { });
251
- }
252
- catch {
253
- // Non-critical
254
- }
255
- }
256
- // ── Story 18.8: Tier Cache Invalidation ──────────────────────────────
257
- /**
258
- * Invalidate all tier and quota caches.
259
- * Called when a tier change is detected to ensure fresh data.
260
- * NEVER throws.
261
- */
262
- async invalidateTierCache() {
263
- try {
264
- this.cachedTier = null;
265
- await this.cache.clear().catch(() => { });
266
- }
267
- catch {
268
- // Non-critical
269
- }
270
- }
271
- // ── Story 60.2: Pre-flight Trigger Check ────────────────────────────
272
- /**
273
- * Check if a trigger is allowed for the current tier WITHOUT calling the server.
274
- * Returns immediately (in-memory lookup).
275
- * NEVER throws - returns { allowed: true } on failure (fail-open).
276
- */
277
- async preFlightCheck(trigger, tier) {
278
- try {
279
- const userTier = tier ?? await this.getCachedTier();
280
- const canonicalTrigger = resolveClientPreFlightTrigger(trigger) ?? trigger;
281
- const requiredTier = TRIGGER_GATES[canonicalTrigger] ?? 'free';
282
- if (TIER_HIERARCHY[userTier] >= TIER_HIERARCHY[requiredTier]) {
283
- return { allowed: true };
284
- }
285
- const message = this.buildUpgradeMessage(canonicalTrigger, userTier, requiredTier);
286
- return { allowed: false, message };
287
- }
288
- catch {
289
- // Fail-open: allow on error
290
- return { allowed: true };
291
- }
292
- }
293
- // ── Story 60.3: Quota Cache from Response ───────────────────────────
294
- /**
295
- * Update cached quota from server response metadata.
296
- * Called after each successful invoke.
297
- */
298
- async updateQuotaFromResponse(metadata) {
299
- try {
300
- const quotaRemaining = metadata.quotaRemaining;
301
- if (!quotaRemaining)
302
- return;
303
- const snapshot = {
304
- stepsRemaining: quotaRemaining.stepsRemaining ?? 0,
305
- invocationsRemaining: quotaRemaining.invocationsRemaining ?? 0,
306
- stepsLimit: quotaRemaining.stepsLimit ?? 0,
307
- invocationsLimit: quotaRemaining.invocationsLimit ?? 0,
308
- cachedAt: Date.now(),
309
- };
310
- const dateKey = this.getQuotaCacheKey();
311
- await this.cache.set(dateKey, JSON.stringify(snapshot), QUOTA_TTL_MS).catch(() => { });
312
- }
313
- catch {
314
- // Non-critical
315
- }
316
- }
317
- /**
318
- * Get cached quota for today.
319
- * NEVER throws - returns null if cache empty or expired.
320
- */
321
- async getCachedQuota() {
322
- try {
323
- const dateKey = this.getQuotaCacheKey();
324
- const raw = await this.cache.get(dateKey);
325
- if (!raw)
326
- return null;
327
- const snapshot = JSON.parse(raw);
328
- // Validate TTL (EncryptedCache already handles this, but double-check)
329
- if (Date.now() - snapshot.cachedAt > QUOTA_TTL_MS)
330
- return null;
331
- return snapshot;
332
- }
333
- catch {
334
- return null;
335
- }
336
- }
337
- // ── Story 60.4: Offline Enforcement ─────────────────────────────────
338
- /**
339
- * Check quota in offline mode using cached data.
340
- * NEVER throws - returns { allowed: true } on failure (fail-open).
341
- *
342
- * @param isOffline - Whether the circuit breaker is in L2+ degradation
343
- */
344
- async offlineQuotaCheck(isOffline = false) {
345
- try {
346
- if (!isOffline)
347
- return { allowed: true };
348
- const quota = await this.getCachedQuota();
349
- // Fail-open: if no cached quota, allow
350
- if (!quota)
351
- return { allowed: true };
352
- // Check steps
353
- if (quota.stepsRemaining <= 0 && quota.stepsLimit > 0) {
354
- return {
355
- allowed: false,
356
- message: `Daily step limit reached (${quota.stepsLimit}/${quota.stepsLimit}). Resets at 00:00 UTC.`,
357
- };
358
- }
359
- // Check invocations
360
- if (quota.invocationsRemaining <= 0 && quota.invocationsLimit > 0) {
361
- return {
362
- allowed: false,
363
- message: `Daily invocation limit reached (${quota.invocationsLimit}/${quota.invocationsLimit}). Resets at 00:00 UTC.`,
364
- };
365
- }
366
- return { allowed: true };
367
- }
368
- catch {
369
- // Fail-open
370
- return { allowed: true };
371
- }
372
- }
373
- // ── Private Helpers ─────────────────────────────────────────────────
374
- /**
375
- * Extract tier from JWT payload via base64url decode.
376
- * No cryptographic verification - client-side is UX only.
377
- */
378
- extractTierFromJwt(token) {
379
- try {
380
- const parts = token.split('.');
381
- if (parts.length !== 3)
382
- return DEFAULT_TIER;
383
- // Decode base64url payload
384
- const payload = parts[1];
385
- const decoded = Buffer.from(payload, 'base64url').toString('utf8');
386
- const claims = JSON.parse(decoded);
387
- const tier = claims.tier;
388
- if (tier && VALID_TIERS.has(tier)) {
389
- return tier;
390
- }
391
- return DEFAULT_TIER;
392
- }
393
- catch {
394
- return DEFAULT_TIER;
395
- }
396
- }
397
- buildUpgradeMessage(trigger, currentTier, requiredTier) {
398
- return `The *${trigger} command requires ${requiredTier.toUpperCase()} plan. Your current plan: ${currentTier.toUpperCase()}. Upgrade: https://neocortex.sh/portal/dashboard/plans`;
399
- }
400
- getQuotaCacheKey() {
401
- const now = new Date();
402
- const dateStr = now.toISOString().slice(0, 10); // YYYY-MM-DD UTC
403
- return `${QUOTA_CACHE_KEY_PREFIX}${dateStr}`;
404
- }
405
- }
1
+ import{GENERATED_CLIENT_COMMANDS as p}from"../generated/command-registry.generated.js";const o="neocortex:tier",b="neocortex:quota:",d=300*1e3,m=3600*1e3,l=new Set(["free","pro","enterprise"]),s="free",g={status:"free","create-epic":"free","idea-diagnose":"free","idea-research":"free","generate-epic":"free",exec:"pro",yolo:"pro",epic:"pro","setup-branch":"free",diagnose:"free",research:"free","write-spec":"free","create-tasks":"free",implement:"free","update-memory":"free",commit:"free",sync:"free","create-pr":"free",review:"pro",merge:"free","fix-blocked":"free","finalize-epic":"free",cleanup:"free","resolve-conflicts":"free",audit:"free",menu:"free",plans:"free",billing:"free",subscribe:"free","arch-plan":"free","arch-prd":"free","arch-architecture":"free","arch-api-contracts":"free","arch-api-integrations":"free","arch-database":"free","arch-security":"free","arch-design-system":"free","arch-ux-design":"free","arch-review":"free","arch-fitness-functions":"pro","arch-performance":"pro","arch-testing":"pro","arch-infrastructure":"pro",refactor:"pro","tech-debt":"free","tech-debt-scan":"pro","qa-scan":"pro","mutation-test":"pro",yoloop:"pro","migrate-state":"free","policy-audit":"pro","sync-openapi":"free","generate-pacts":"pro","verify-pacts":"free","property-test":"pro","chaos-plan":"pro","ui-ux-review":"pro","solyd-system":"enterprise",goal:"enterprise","goal-tick":"enterprise",loop:"enterprise","loop-tick":"enterprise",jobs:"enterprise",runner:"enterprise"},y=Object.freeze(Object.fromEntries(p.map(r=>[r.id,r.policy.minimumTier]))),T=[{id:"status",number:1,aliases:["st"]},{id:"arch-plan",number:3,aliases:["arquitetura","architecture","arch"]},{id:"arch-prd",number:4,aliases:["prd","product-requirements"]},{id:"arch-architecture",number:5,aliases:["arch-doc","tech-architecture"]},{id:"arch-api-contracts",number:6,aliases:["api-contracts","api-contract"]},{id:"arch-api-integrations",number:7,aliases:["api-integrations","api-int"]},{id:"arch-database",number:8,aliases:["database-schema","db-schema","db"]},{id:"arch-security",number:9,aliases:["cyber-security","security","sec"]},{id:"arch-design-system",number:10,aliases:["design-system","ds","atomic-design"]},{id:"arch-ux-design",number:11,aliases:["ux-design","ux","wireframes","wireframe","user-flows"]},{id:"arch-performance",number:12,aliases:["performance","perf","capacity-planning","capacity","arch-perf","performance-strategy"]},{id:"arch-testing",number:13,aliases:["testing-strategy","test-plan","test-strategy","arch-test"]},{id:"arch-infrastructure",number:14,aliases:["infrastructure","infra","deploy-plan","deployment","arch-infra","arch-deploy"]},{id:"arch-review",number:15,aliases:["review-consolidation","consolidation","architecture-review","arch-consolidation"]},{id:"arch-fitness-functions",number:16,aliases:["fitness","fitness-functions","archfit","arch-fit","fit-funcs"]},{id:"create-epic",number:17,aliases:["criar-epic","planejamento"]},{id:"idea-diagnose",number:18,aliases:["idea-diag"]},{id:"idea-research",number:19,aliases:["idea-pesq"]},{id:"generate-epic",number:20,aliases:["gerar-epic"]},{id:"exec",number:21,aliases:["executar","pipeline"]},{id:"yolo",number:22,aliases:[]},{id:"epic",number:23,aliases:["parallel-epic"]},{id:"setup-branch",number:24,aliases:["setup","branch"]},{id:"diagnose",number:25,aliases:["diag","diagnostico","c02"]},{id:"research",number:26,aliases:["pesquisar","pesq","research-fix","c03"]},{id:"write-spec",number:27,aliases:["spec","especificacao","c04"]},{id:"create-tasks",number:28,aliases:["tasks","tarefas","c05"]},{id:"implement",number:29,aliases:["impl","implementar","c06"]},{id:"commit",number:30,aliases:["push","commit-push","commit_push","cp","c07"]},{id:"sync",number:31,aliases:["sincronizar","c08"]},{id:"create-pr",number:32,aliases:["pr","c09"]},{id:"review",number:33,aliases:["revisar","c11"]},{id:"merge",number:34,aliases:["mesclar","c12"]},{id:"fix-blocked",number:35,aliases:["fix","corrigir"]},{id:"finalize-epic",number:36,aliases:["finalizar"]},{id:"resolve-conflicts",number:37,aliases:["conflitos"]},{id:"update-memory",number:38,aliases:["memoria"]},{id:"refactor",number:39,aliases:["refactoring","refact","refac","rf","cleanup-code","code-cleanup","code-quality","improve-code","modernize","modernization","legacy","legacy-code","debt-pay","pay-debt","debt-reduction","smell-fix","fix-smells","code-smells","strangler","strangler-fig"]},{id:"cleanup",number:40,aliases:["limpar","limpeza"]},{id:"audit",number:41,aliases:["auditar","auditoria"]},{id:"tech-debt",number:42,aliases:["debt","debts","debt-list","tech-debts","td"]},{id:"menu",number:43,aliases:["help","ajuda","?","commands","cmds"]},{id:"plans",number:44,aliases:["planos","pricing"]},{id:"billing",number:45,aliases:["bill","subscription","sub"]},{id:"subscribe",number:46,aliases:["upgrade","checkout"]},{id:"qa-scan",number:47,aliases:["qa","qa-test","visual-qa","e2e-scan","troubleshoot","debug-ui","scan","a11y","accessibility","wcag"]},{id:"yoloop",number:48,aliases:["auto-yolo","epic-runner","story-runner","loop-yolo","auto-epic"]},{id:"migrate-state",number:49,aliases:["migrate","state-migrate","schema-migrate"]},{id:"policy-audit",number:50,aliases:["policy","audit-policy","policy-history","policies"]},{id:"mutation-test",number:51,aliases:["mutation","stryker","kill-mutants"]},{id:"sync-openapi",number:52,aliases:["openapi-sync","api-sync","spec-sync","regen-openapi"]},{id:"generate-pacts",number:53,aliases:["pacts","gen-pacts","regen-pacts","create-pacts"]},{id:"verify-pacts",number:54,aliases:["verify-pact","pact-verify","check-pacts","pact-check"]},{id:"property-test",number:55,aliases:["property","pbt","proptest","property-tests","invariant-test"]},{id:"chaos-plan",number:56,aliases:["chaos","gameday","resilience-test"]},{id:"ui-ux-review",number:57,aliases:["ux-review","design-review","visual-review","product-polish"]},{id:"solyd-system",number:58,aliases:["security-system","authorized-security","sec-system"]},{id:"goal",number:59,aliases:["goals","durable-goal","continuity-goal"]},{id:"loop",number:60,aliases:["loops","durable-loop","continuity-loop"]},{id:"jobs",number:61,aliases:["job","continuity-jobs"]},{id:"runner",number:62,aliases:["neocortex-runner","continuity-runner"]}],u=Object.freeze(p.map(r=>Object.freeze({id:r.id,number:r.number,aliases:r.aliases}))),w=new Map(u.map(r=>[r.id,r])),C=new Map(u.map(r=>[r.number,r])),v=new Map(u.flatMap(r=>r.aliases.map(a=>[h(a),r.id])));function h(r){if(/[^\x20-\x7e]/.test(r))return"";const a=r.replace(/^[\t\n\r ]+|[\t\n\r ]+$/g,"");if(!a||a.startsWith("**"))return"";const e=(a.startsWith("*")?a.slice(1):a).replace(/[A-Z]/g,i=>i.toLowerCase());return/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(e)||e==="?"?e:""}function _(r){const a=r.trim();if(/^@?epic-[a-z0-9][a-z0-9._-]*$/i.test(a))return"epic";const e=a.split(/\s+/,1)[0]??"",i=e.trim().replace(/^\*/,"");if(/^\d+$/.test(i))return C.get(Number.parseInt(i,10))?.id??null;const t=h(e);return t?t==="goal-tick"?"goal":t==="loop-tick"?"loop":w.has(t)?t:v.get(t)??null:null}const f={free:0,pro:1,enterprise:2};class R{cache;licenseClient;cachedTier=null;constructor(a){this.cache=a.cacheProvider,this.licenseClient=a.licenseClient}async getCachedTier(){try{if(this.cachedTier)return this.cachedTier;const a=await this.cache.get(o);if(a&&l.has(a))return this.cachedTier=a,this.cachedTier;const e=await this.licenseClient.getToken();if(e){const i=this.extractTierFromJwt(e);return this.cachedTier=i,await this.cache.set(o,i,m).catch(()=>{}),i}return s}catch{return s}}async updateTier(a){try{if(!l.has(a))return;this.cachedTier=a,await this.cache.set(o,a,m).catch(()=>{})}catch{}}async invalidateTierCache(){try{this.cachedTier=null,await this.cache.clear().catch(()=>{})}catch{}}async preFlightCheck(a,e){try{const i=e??await this.getCachedTier(),t=_(a)??a,n=y[t]??"free";return f[i]>=f[n]?{allowed:!0}:{allowed:!1,message:this.buildUpgradeMessage(t,i,n)}}catch{return{allowed:!0}}}async updateQuotaFromResponse(a){try{const e=a.quotaRemaining;if(!e)return;const i={stepsRemaining:e.stepsRemaining??0,invocationsRemaining:e.invocationsRemaining??0,stepsLimit:e.stepsLimit??0,invocationsLimit:e.invocationsLimit??0,cachedAt:Date.now()},t=this.getQuotaCacheKey();await this.cache.set(t,JSON.stringify(i),d).catch(()=>{})}catch{}}async getCachedQuota(){try{const a=this.getQuotaCacheKey(),e=await this.cache.get(a);if(!e)return null;const i=JSON.parse(e);return Date.now()-i.cachedAt>d?null:i}catch{return null}}async offlineQuotaCheck(a=!1){try{if(!a)return{allowed:!0};const e=await this.getCachedQuota();return e?e.stepsRemaining<=0&&e.stepsLimit>0?{allowed:!1,message:`Daily step limit reached (${e.stepsLimit}/${e.stepsLimit}). Resets at 00:00 UTC.`}:e.invocationsRemaining<=0&&e.invocationsLimit>0?{allowed:!1,message:`Daily invocation limit reached (${e.invocationsLimit}/${e.invocationsLimit}). Resets at 00:00 UTC.`}:{allowed:!0}:{allowed:!0}}catch{return{allowed:!0}}}extractTierFromJwt(a){try{const e=a.split(".");if(e.length!==3)return s;const i=e[1],t=Buffer.from(i,"base64url").toString("utf8"),c=JSON.parse(t).tier;return c&&l.has(c)?c:s}catch{return s}}buildUpgradeMessage(a,e,i){return`The *${a} command requires ${i.toUpperCase()} plan. Your current plan: ${e.toUpperCase()}. Upgrade: https://neocortex.sh/portal/dashboard/plans`}getQuotaCacheKey(){const e=new Date().toISOString().slice(0,10);return`${b}${e}`}}export{u as CLIENT_PREFLIGHT_COMMAND_REGISTRY,R as TierAwareClient,h as normalizeCommandToken,_ as resolveClientPreFlightTrigger};
@@ -1,38 +1 @@
1
- /**
2
- * @license FSL-1.1
3
- * Copyright (c) 2026 OrNexus AI
4
- *
5
- * This file is part of Neocortex CLI, licensed under the
6
- * Functional Source License, Version 1.1 (FSL-1.1).
7
- *
8
- * Change Date: February 20, 2029
9
- * Change License: MIT
10
- *
11
- * See the LICENSE file in the project root for full license text.
12
- */
13
- /**
14
- * @neocortex/client - Type Definitions
15
- *
16
- * All types for the asset resolution abstraction layer.
17
- */
18
- // ── Resolver Mode ────────────────────────────────────────────────────────
19
- /** Mode of asset resolution */
20
- export var ResolverMode;
21
- (function (ResolverMode) {
22
- /** Read assets from local filesystem (development) */
23
- ResolverMode["LOCAL"] = "local";
24
- /** Fetch assets from remote IP Protection Server (production) */
25
- ResolverMode["REMOTE"] = "remote";
26
- })(ResolverMode || (ResolverMode = {}));
27
- /** No-op cache implementation for development/fallback */
28
- export class NoOpCache {
29
- async get() {
30
- return null;
31
- }
32
- async set() {
33
- // No-op: cache disabled
34
- }
35
- async clear() {
36
- // No-op: nothing to clear
37
- }
38
- }
1
+ var a;(function(e){e.LOCAL="local",e.REMOTE="remote"})(a||(a={}));class c{async get(){return null}async set(){}async clear(){}}export{c as NoOpCache,a as ResolverMode};
@@ -1,27 +1 @@
1
- import { readFileSync } from 'node:fs';
2
- import { fileURLToPath } from 'node:url';
3
- import { dirname, join } from 'node:path';
4
- /** Resolve the installed package version for both source and packed runtimes. */
5
- export function getClientVersion(fromUrl = import.meta.url) {
6
- try {
7
- let directory = dirname(fileURLToPath(fromUrl));
8
- for (let depth = 0; depth < 6; depth += 1) {
9
- try {
10
- const pkg = JSON.parse(readFileSync(join(directory, 'package.json'), 'utf8'));
11
- if ((pkg.name === '@ornexus/neocortex' || pkg.name === '@neocortex/client') &&
12
- typeof pkg.version === 'string' &&
13
- /^\d+\.\d+\.\d+(?:[-+][A-Za-z0-9.-]+)?$/.test(pkg.version))
14
- return pkg.version;
15
- }
16
- catch {
17
- // Continue toward the package root.
18
- }
19
- directory = dirname(directory);
20
- }
21
- }
22
- catch {
23
- // Fall through to the explicit unavailable value.
24
- }
25
- return '0.0.0';
26
- }
27
- export const CLIENT_VERSION = getClientVersion();
1
+ import{readFileSync as i}from"node:fs";import{fileURLToPath as c}from"node:url";import{dirname as o,join as a}from"node:path";function m(n=import.meta.url){try{let t=o(c(n));for(let r=0;r<6;r+=1){try{const e=JSON.parse(i(a(t,"package.json"),"utf8"));if((e.name==="@ornexus/neocortex"||e.name==="@neocortex/client")&&typeof e.version=="string"&&/^\d+\.\d+\.\d+(?:[-+][A-Za-z0-9.-]+)?$/.test(e.version))return e.version}catch{}t=o(t)}}catch{}return"0.0.0"}const d=m();export{d as CLIENT_VERSION,m as getClientVersion};
@@ -1,126 +1 @@
1
- import { execFileSync } from 'node:child_process';
2
- import { realpathSync } from 'node:fs';
3
- import { createYoloChangeEvidence } from '../../../shared/dist/yolo/change-evidence.js';
4
- import { readGitLifecycleRuntimeSync } from '../git/git-lifecycle-store.js';
5
- /** Reacquire only an expired setup lease for this exact story through P207's CAS boundary. */
6
- export async function reconcileYoloChangeEvidenceLease(options) {
7
- let lease;
8
- try {
9
- lease = readGitLifecycleRuntimeSync(options.projectRoot, { required: true })
10
- .epics[options.epicId]?.branch_lease;
11
- }
12
- catch (error) {
13
- // C01 can legitimately precede first-use sidecar materialization. Only
14
- // that exact absence falls through to the existing remote/base evidence.
15
- if (error instanceof Error && error.message === 'git-lifecycle-runtime-missing')
16
- return;
17
- throw new Error('yolo-change-evidence-unavailable');
18
- }
19
- if (lease === null || lease === undefined)
20
- return;
21
- if (typeof lease !== 'object' || Array.isArray(lease)
22
- || lease.ownerStoryId !== options.storyId
23
- || typeof lease.expiresAt !== 'string') {
24
- throw new Error('yolo-change-evidence-unavailable');
25
- }
26
- const expiry = Date.parse(lease.expiresAt);
27
- if (!Number.isFinite(expiry))
28
- throw new Error('yolo-change-evidence-unavailable');
29
- if (expiry > Date.now())
30
- return;
31
- if (typeof lease.sessionId !== 'string'
32
- || !/^setup-[a-f0-9]{64}$/.test(lease.sessionId)
33
- || lease.idempotencyKey !== lease.sessionId) {
34
- throw new Error('yolo-change-evidence-unavailable');
35
- }
36
- const { prepareDirectYoloSetup } = await import('../git/direct-yolo-checkpoint.js');
37
- const result = await prepareDirectYoloSetup(options);
38
- if (!result.ok || result.value.storyId !== options.storyId
39
- || result.value.epicId !== options.epicId
40
- || Date.parse(result.value.leaseExpiresAt) <= Date.now()) {
41
- throw new Error('yolo-change-evidence-unavailable');
42
- }
43
- }
44
- function git(root, args) {
45
- try {
46
- return execFileSync('git', ['-C', root, ...args], {
47
- encoding: 'utf8', timeout: 3_000, maxBuffer: 1024 * 1024, stdio: ['ignore', 'pipe', 'ignore'],
48
- });
49
- }
50
- catch {
51
- throw new Error('yolo-change-evidence-unavailable');
52
- }
53
- }
54
- export function collectYoloChangeEvidence(options) {
55
- if (!/^[A-Za-z0-9][A-Za-z0-9_./-]{0,119}$/.test(options.defaultBranch)
56
- || options.defaultBranch.includes('..'))
57
- throw new Error('yolo-change-evidence-unavailable');
58
- const repositoryRoot = git(options.projectRoot, ['rev-parse', '--show-toplevel']).trim();
59
- if (realpathSync(repositoryRoot) !== realpathSync(options.projectRoot))
60
- throw new Error('yolo-change-evidence-unavailable');
61
- const headSha = git(options.projectRoot, ['rev-parse', 'HEAD']).trim();
62
- if (headSha !== options.expectedHeadSha)
63
- throw new Error('yolo-change-evidence-stale');
64
- let baseSha;
65
- let activeStoryLease = false;
66
- let executionBranch = null;
67
- if (options.storyId && options.epicId) {
68
- try {
69
- const runtime = readGitLifecycleRuntimeSync(options.projectRoot);
70
- const epic = runtime.epics[options.epicId];
71
- const lease = epic?.branch_lease;
72
- const currentBranch = git(options.projectRoot, ['symbolic-ref', '--quiet', '--short', 'HEAD']).trim();
73
- if (epic?.branch_mode === 'epic' && epic.execution_branch === currentBranch) {
74
- executionBranch = currentBranch;
75
- }
76
- if (lease && typeof lease === 'object' && !Array.isArray(lease)) {
77
- const item = lease;
78
- if (item.ownerStoryId !== options.storyId
79
- || typeof item.expiresAt !== 'string' || Date.parse(item.expiresAt) <= Date.now()
80
- || executionBranch === null) {
81
- throw new Error('yolo-change-evidence-unavailable');
82
- }
83
- activeStoryLease = true;
84
- }
85
- }
86
- catch {
87
- throw new Error('yolo-change-evidence-unavailable');
88
- }
89
- }
90
- if (activeStoryLease) {
91
- // Before the root C08 commit, the setup lease owns the current checkout.
92
- // Earlier epic commits are not part of this story's implementation diff.
93
- // A manually pre-committed change cannot satisfy the staged C08 checkpoint.
94
- baseSha = headSha;
95
- }
96
- else {
97
- // Before C01 has acquired a story lease, compare this epic checkout with
98
- // its published tip. Historical epic commits are not new story changes,
99
- // while local unpushed commits must remain visible to the evidence gate.
100
- const remoteLine = executionBranch === null ? '' : git(options.projectRoot, [
101
- 'ls-remote', '--heads', 'origin', `refs/heads/${executionBranch}`,
102
- ]).trim();
103
- if (remoteLine) {
104
- const match = /^([a-f0-9]{40})\trefs\/heads\/([^\n]+)$/.exec(remoteLine);
105
- if (!match || match[2] !== executionBranch
106
- || git(options.projectRoot, ['merge-base', 'HEAD', match[1]]).trim() !== match[1]) {
107
- throw new Error('yolo-change-evidence-unavailable');
108
- }
109
- baseSha = match[1];
110
- }
111
- else {
112
- try {
113
- baseSha = git(options.projectRoot, ['merge-base', 'HEAD', options.defaultBranch]).trim();
114
- }
115
- catch {
116
- baseSha = git(options.projectRoot, ['merge-base', 'HEAD', `refs/remotes/origin/${options.defaultBranch}`]).trim();
117
- }
118
- }
119
- }
120
- const tracked = git(options.projectRoot, ['diff', '--name-only', '-z', baseSha, '--']).split('\0').filter(Boolean);
121
- const untracked = git(options.projectRoot, ['ls-files', '--others', '--exclude-standard', '-z']).split('\0').filter(Boolean);
122
- const evidence = createYoloChangeEvidence({ baseSha, headSha, changedPaths: [...tracked, ...untracked] });
123
- if (git(options.projectRoot, ['rev-parse', 'HEAD']).trim() !== headSha)
124
- throw new Error('yolo-change-evidence-stale');
125
- return evidence;
126
- }
1
+ import{execFileSync as p}from"node:child_process";import{realpathSync as f}from"node:fs";import{createYoloChangeEvidence as w}from"../../../shared/dist/yolo/change-evidence.js";import{readGitLifecycleRuntimeSync as u}from"../git/git-lifecycle-store.js";async function j(e){let r;try{r=u(e.projectRoot,{required:!0}).epics[e.epicId]?.branch_lease}catch(c){if(c instanceof Error&&c.message==="git-lifecycle-runtime-missing")return;throw new Error("yolo-change-evidence-unavailable")}if(r==null)return;if(typeof r!="object"||Array.isArray(r)||r.ownerStoryId!==e.storyId||typeof r.expiresAt!="string")throw new Error("yolo-change-evidence-unavailable");const n=Date.parse(r.expiresAt);if(!Number.isFinite(n))throw new Error("yolo-change-evidence-unavailable");if(n>Date.now())return;if(typeof r.sessionId!="string"||!/^setup-[a-f0-9]{64}$/.test(r.sessionId)||r.idempotencyKey!==r.sessionId)throw new Error("yolo-change-evidence-unavailable");const{prepareDirectYoloSetup:o}=await import("../git/direct-yolo-checkpoint.js"),i=await o(e);if(!i.ok||i.value.storyId!==e.storyId||i.value.epicId!==e.epicId||Date.parse(i.value.leaseExpiresAt)<=Date.now())throw new Error("yolo-change-evidence-unavailable")}function t(e,r){try{return p("git",["-C",e,...r],{encoding:"utf8",timeout:3e3,maxBuffer:1024*1024,stdio:["ignore","pipe","ignore"]})}catch{throw new Error("yolo-change-evidence-unavailable")}}function x(e){if(!/^[A-Za-z0-9][A-Za-z0-9_./-]{0,119}$/.test(e.defaultBranch)||e.defaultBranch.includes(".."))throw new Error("yolo-change-evidence-unavailable");const r=t(e.projectRoot,["rev-parse","--show-toplevel"]).trim();if(f(r)!==f(e.projectRoot))throw new Error("yolo-change-evidence-unavailable");const n=t(e.projectRoot,["rev-parse","HEAD"]).trim();if(n!==e.expectedHeadSha)throw new Error("yolo-change-evidence-stale");let o,i=!1,c=null;if(e.storyId&&e.epicId)try{const a=u(e.projectRoot).epics[e.epicId],l=a?.branch_lease,h=t(e.projectRoot,["symbolic-ref","--quiet","--short","HEAD"]).trim();if(a?.branch_mode==="epic"&&a.execution_branch===h&&(c=h),l&&typeof l=="object"&&!Array.isArray(l)){const d=l;if(d.ownerStoryId!==e.storyId||typeof d.expiresAt!="string"||Date.parse(d.expiresAt)<=Date.now()||c===null)throw new Error("yolo-change-evidence-unavailable");i=!0}}catch{throw new Error("yolo-change-evidence-unavailable")}if(i)o=n;else{const s=c===null?"":t(e.projectRoot,["ls-remote","--heads","origin",`refs/heads/${c}`]).trim();if(s){const a=/^([a-f0-9]{40})\trefs\/heads\/([^\n]+)$/.exec(s);if(!a||a[2]!==c||t(e.projectRoot,["merge-base","HEAD",a[1]]).trim()!==a[1])throw new Error("yolo-change-evidence-unavailable");o=a[1]}else try{o=t(e.projectRoot,["merge-base","HEAD",e.defaultBranch]).trim()}catch{o=t(e.projectRoot,["merge-base","HEAD",`refs/remotes/origin/${e.defaultBranch}`]).trim()}}const y=t(e.projectRoot,["diff","--name-only","-z",o,"--"]).split("\0").filter(Boolean),m=t(e.projectRoot,["ls-files","--others","--exclude-standard","-z"]).split("\0").filter(Boolean),v=w({baseSha:o,headSha:n,changedPaths:[...y,...m]});if(t(e.projectRoot,["rev-parse","HEAD"]).trim()!==n)throw new Error("yolo-change-evidence-stale");return v}export{x as collectYoloChangeEvidence,j as reconcileYoloChangeEvidenceLease};