@ornexus/neocortex 4.61.5 → 4.62.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) hide show
  1. package/dist/release-source.json +1 -1
  2. package/dist/sbom.cdx.json +1193 -1193
  3. package/install.ps1 +31 -34
  4. package/install.sh +1 -1
  5. package/package.json +5 -2
  6. package/packages/client/dist/adapters/adapter-registry.js +1 -108
  7. package/packages/client/dist/adapters/antigravity-adapter.js +2 -77
  8. package/packages/client/dist/adapters/claude-code-adapter.js +3 -79
  9. package/packages/client/dist/adapters/codex-adapter.js +2 -80
  10. package/packages/client/dist/adapters/cursor-adapter.js +4 -115
  11. package/packages/client/dist/adapters/gemini-adapter.js +2 -71
  12. package/packages/client/dist/adapters/grok-adapter.js +2 -42
  13. package/packages/client/dist/adapters/index.js +1 -22
  14. package/packages/client/dist/adapters/platform-detector.js +1 -220
  15. package/packages/client/dist/adapters/target-adapter.js +0 -12
  16. package/packages/client/dist/adapters/vscode-adapter.js +2 -72
  17. package/packages/client/dist/agent/refresh-stubs.js +2 -443
  18. package/packages/client/dist/agent/update-agent-yaml.js +1 -102
  19. package/packages/client/dist/agent/update-description.d.ts +8 -1
  20. package/packages/client/dist/agent/update-description.js +2 -260
  21. package/packages/client/dist/cache/crypto-utils.js +1 -78
  22. package/packages/client/dist/cache/encrypted-cache.js +1 -338
  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 -364
  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 +17 -0
  39. package/packages/client/dist/commands/invoke.js +148 -7822
  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 -174
  75. package/packages/client/dist/commands/shared-architecture-non-ui.js +1 -24
  76. package/packages/client/dist/commands/story-checkpoint.d.ts +5 -1
  77. package/packages/client/dist/commands/story-checkpoint.js +1 -203
  78. package/packages/client/dist/commands/story-worktree.js +5 -258
  79. package/packages/client/dist/config/host-auth-broker.js +1 -60
  80. package/packages/client/dist/config/host-auth-reference.js +1 -93
  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 -224
  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.js +1 -105
  99. package/packages/client/dist/continuity/outbox.js +1 -117
  100. package/packages/client/dist/continuity/runner-bootstrap-policy.js +1 -172
  101. package/packages/client/dist/continuity/sqlite-store.js +81 -2612
  102. package/packages/client/dist/effects/invoke-effect-gateways.js +1 -62
  103. package/packages/client/dist/errors/error-messages.js +2 -258
  104. package/packages/client/dist/errors/frontmatter-diagnostics.d.ts +10 -1
  105. package/packages/client/dist/errors/frontmatter-diagnostics.js +1 -125
  106. package/packages/client/dist/evidence/collector.js +1 -347
  107. package/packages/client/dist/evidence/index.js +1 -1
  108. package/packages/client/dist/evidence/types.js +0 -2
  109. package/packages/client/dist/fs/atomic-state-replace.js +1 -152
  110. package/packages/client/dist/generated/command-registry.generated.js +1 -4076
  111. package/packages/client/dist/generated/public-projections.generated.js +1 -149
  112. package/packages/client/dist/git/direct-yolo-c01-retry.js +4 -138
  113. package/packages/client/dist/git/direct-yolo-checkpoint.d.ts +94 -9
  114. package/packages/client/dist/git/direct-yolo-checkpoint.js +3 -1592
  115. package/packages/client/dist/git/epic-operational-state.js +2 -672
  116. package/packages/client/dist/git/git-lifecycle-step-ids.js +1 -14
  117. package/packages/client/dist/git/git-lifecycle-store.d.ts +88 -0
  118. package/packages/client/dist/git/git-lifecycle-store.js +9 -2529
  119. package/packages/client/dist/git/legacy-story-branch-checkpoint.js +9 -259
  120. package/packages/client/dist/git/legacy-story-branch-setup.js +4 -348
  121. package/packages/client/dist/git/legacy-story-pr.js +70 -3538
  122. package/packages/client/dist/git/neocortex-trailers.js +2 -53
  123. package/packages/client/dist/git/release-gate-env.d.ts +62 -0
  124. package/packages/client/dist/git/release-gate-env.js +1 -0
  125. package/packages/client/dist/git/secure-filesystem-boundary.d.ts +24 -0
  126. package/packages/client/dist/git/secure-filesystem-boundary.js +20 -186
  127. package/packages/client/dist/git/story-worktree-cleanup.js +4 -1058
  128. package/packages/client/dist/git/story-worktree-integration.d.ts +62 -0
  129. package/packages/client/dist/git/story-worktree-integration.js +3 -603
  130. package/packages/client/dist/git/story-worktree-manager.js +3 -843
  131. package/packages/client/dist/git/story-worktree-paths.js +1 -150
  132. package/packages/client/dist/git/story-write-set-extension.d.ts +44 -0
  133. package/packages/client/dist/git/story-write-set-extension.js +1 -0
  134. package/packages/client/dist/graph-retrieval/pre-command-hook.js +1 -284
  135. package/packages/client/dist/graph-retrieval/shared-graph-retrieval-contract.js +1 -237
  136. package/packages/client/dist/i18n/first-run.js +2 -60
  137. package/packages/client/dist/index.js +1 -50
  138. package/packages/client/dist/invocation/invoke-input.js +1 -24
  139. package/packages/client/dist/license/host-auth-recovery.js +1 -401
  140. package/packages/client/dist/license/index.js +1 -5
  141. package/packages/client/dist/license/license-client.js +1 -337
  142. package/packages/client/dist/machine/fingerprint.js +2 -163
  143. package/packages/client/dist/machine/index.js +1 -5
  144. package/packages/client/dist/memory/project-memory-path-scope.js +1 -62
  145. package/packages/client/dist/memory/project-memory-writer.js +41 -1117
  146. package/packages/client/dist/memory/shared-project-memory-types.js +2 -259
  147. package/packages/client/dist/migrations/epic-lifecycle-backfill.js +3 -1060
  148. package/packages/client/dist/migrations/project-identity-capability.js +1 -50
  149. package/packages/client/dist/migrations/project-identity.js +7 -493
  150. package/packages/client/dist/migrations/state-json.js +4 -393
  151. package/packages/client/dist/policy/architecture-policy.js +2 -184
  152. package/packages/client/dist/policy/index.js +1 -7
  153. package/packages/client/dist/policy/shared-policy-types.js +0 -38
  154. package/packages/client/dist/policy/subagent-approval-policy.js +1 -57
  155. package/packages/client/dist/private-execution/clean-baseline.js +2 -279
  156. package/packages/client/dist/private-execution/codex-executor.js +4 -574
  157. package/packages/client/dist/private-execution/codex-host-runtime.js +1 -137
  158. package/packages/client/dist/private-execution/codex-lifecycle-guard.js +1 -97
  159. package/packages/client/dist/private-execution/codex-scoped-permissions.js +1 -128
  160. package/packages/client/dist/private-execution/delivery.js +13 -410
  161. package/packages/client/dist/private-execution/diagnosis-root-review.js +2 -294
  162. package/packages/client/dist/private-execution/frozen-handoff.js +6 -19
  163. package/packages/client/dist/private-execution/implementation-validation.js +2 -106
  164. package/packages/client/dist/private-execution/isolated-admission.js +23 -1432
  165. package/packages/client/dist/private-execution/isolated-session.js +5 -725
  166. package/packages/client/dist/private-execution/isolated-workspace.js +1 -122
  167. package/packages/client/dist/private-execution/pact-consumer-runtime.js +3 -409
  168. package/packages/client/dist/private-execution/pact-test-source.js +1 -258
  169. package/packages/client/dist/private-execution/pact-toolchain.js +3 -290
  170. package/packages/client/dist/private-execution/pact-write-set.js +1 -172
  171. package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +5 -406
  172. package/packages/client/dist/private-execution/planning-generation-checkpoint.js +5 -462
  173. package/packages/client/dist/private-execution/planning-memory-checkpoint.js +3 -139
  174. package/packages/client/dist/private-execution/planning-research-checkpoint.js +4 -325
  175. package/packages/client/dist/private-execution/private-report-store.js +1 -42
  176. package/packages/client/dist/private-execution/property-test-candidate.js +1 -103
  177. package/packages/client/dist/private-execution/property-test-choices.js +3 -147
  178. package/packages/client/dist/private-execution/property-test-plan.js +7 -271
  179. package/packages/client/dist/private-execution/property-test-review.js +4 -258
  180. package/packages/client/dist/private-execution/property-test-runtime.js +9 -372
  181. package/packages/client/dist/private-execution/property-test-source.js +1 -139
  182. package/packages/client/dist/private-execution/root-checkpoint.js +1 -80
  183. package/packages/client/dist/private-execution/root-memory-git-evidence.js +3 -135
  184. package/packages/client/dist/private-execution/root-memory-recovery.js +1 -93
  185. package/packages/client/dist/private-execution/root-memory-request.js +1 -29
  186. package/packages/client/dist/private-execution/root-memory-scope.js +1 -178
  187. package/packages/client/dist/private-execution/root-memory-writer.js +1 -102
  188. package/packages/client/dist/private-execution/session-lease.js +1 -63
  189. package/packages/client/dist/private-execution/shared-private-admission-types.js +1 -50
  190. package/packages/client/dist/private-execution/shared-project-validation.js +1 -66
  191. package/packages/client/dist/private-execution/shared-root-memory-types.js +1 -61
  192. package/packages/client/dist/private-execution/ux-source-validation.js +1 -372
  193. package/packages/client/dist/private-execution/ux-write-set.js +2 -191
  194. package/packages/client/dist/registry/registry-reconciliation.js +1 -234
  195. package/packages/client/dist/resilience/circuit-breaker.js +1 -170
  196. package/packages/client/dist/resilience/degradation-manager.js +1 -164
  197. package/packages/client/dist/resilience/freshness-indicator.js +1 -100
  198. package/packages/client/dist/resilience/index.js +1 -8
  199. package/packages/client/dist/resilience/recovery-detector.js +1 -74
  200. package/packages/client/dist/resolvers/asset-resolver.js +0 -13
  201. package/packages/client/dist/resolvers/local-resolver.js +8 -255
  202. package/packages/client/dist/resolvers/remote-resolver.js +1 -233
  203. package/packages/client/dist/runner/binary.js +1 -404
  204. package/packages/client/dist/runner/cli.js +17 -1571
  205. package/packages/client/dist/runner/epic-background-dispatcher.js +1 -124
  206. package/packages/client/dist/runner/headless/adapters.js +1 -49
  207. package/packages/client/dist/runner/headless/background-root.js +1 -85
  208. package/packages/client/dist/runner/headless/child-env.d.ts +92 -0
  209. package/packages/client/dist/runner/headless/child-env.js +1 -0
  210. package/packages/client/dist/runner/headless/claude-code-adapter.js +1 -79
  211. package/packages/client/dist/runner/headless/continuous-story-workspace.js +11 -1776
  212. package/packages/client/dist/runner/headless/epic-git-reconciliation-inventory.js +1 -69
  213. package/packages/client/dist/runner/headless/epic-merge-candidate-qa.js +2 -111
  214. package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.d.ts +1 -0
  215. package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +10 -1464
  216. package/packages/client/dist/runner/headless/epic-terminal-git-runner.js +2 -357
  217. package/packages/client/dist/runner/headless/fake-adapter.js +1 -62
  218. package/packages/client/dist/runner/headless/managed-environment-cleanup.js +1 -274
  219. package/packages/client/dist/runner/headless/managed-profile.js +1 -149
  220. package/packages/client/dist/runner/headless/opencode-adapter.js +2 -145
  221. package/packages/client/dist/runner/headless/prepared-story-bundle.js +1 -43
  222. package/packages/client/dist/runner/headless/resolver.js +1 -231
  223. package/packages/client/dist/runner/headless/run-yolo.js +1 -886
  224. package/packages/client/dist/runner/headless/run-yoloop.js +2 -2657
  225. package/packages/client/dist/runner/headless/types.js +2 -575
  226. package/packages/client/dist/runner/host-capacity.js +1 -59
  227. package/packages/client/dist/runner/local-console.js +13 -396
  228. package/packages/client/dist/runner/portal-sync-worker.js +1 -1487
  229. package/packages/client/dist/runner/project-identity.js +1 -106
  230. package/packages/client/dist/runner/scheduler.js +7 -995
  231. package/packages/client/dist/runner-cli.js +2 -18
  232. package/packages/client/dist/state/invocation-shape.js +1 -13
  233. package/packages/client/dist/state/project-state-snapshot.js +1 -1754
  234. package/packages/client/dist/state/state-json-repair.js +3 -785
  235. package/packages/client/dist/state/structural-dag-projection.js +1 -118
  236. package/packages/client/dist/telemetry/index.js +1 -5
  237. package/packages/client/dist/telemetry/offline-queue.js +1 -131
  238. package/packages/client/dist/tier/index.js +1 -5
  239. package/packages/client/dist/tier/tier-aware-client.js +1 -405
  240. package/packages/client/dist/types/index.js +1 -38
  241. package/packages/client/dist/version.js +1 -27
  242. package/packages/client/dist/yolo/change-evidence-collector.d.ts +10 -0
  243. package/packages/client/dist/yolo/change-evidence-collector.js +1 -262
  244. package/packages/client/dist/yolo/invoke-envelope-capability.d.ts +2 -0
  245. package/packages/client/dist/yolo/invoke-envelope-capability.js +1 -65
  246. package/packages/client/dist/yolo/project-manifest-projection-collector.d.ts +28 -0
  247. package/packages/client/dist/yolo/project-manifest-projection-collector.js +1 -0
  248. package/packages/client/dist/yolo/spec-envelope-collector.d.ts +9 -0
  249. package/packages/client/dist/yolo/spec-envelope-collector.js +5 -184
  250. package/packages/client/dist/yoloop/discovery-hook.js +2 -300
  251. package/packages/client/dist/yoloop/index.js +1 -8
  252. package/packages/client/dist/yoloop/invoke-hooks.js +12 -669
  253. package/packages/client/dist/yoloop/shared-discover-epics.d.ts +16 -0
  254. package/packages/client/dist/yoloop/shared-discover-epics.js +1 -1007
  255. package/packages/client/dist/yoloop/shared-yoloop-types.js +1 -33
  256. package/packages/client/dist/yoloop/target-normalization.js +1 -180
  257. package/packages/client/dist/yoloop/yoloop-client-state-store.js +1 -1920
  258. package/packages/shared/dist/frontmatter-context-contract.js +164 -52
  259. package/packages/shared/dist/project-manifest-projection.js +199 -0
  260. package/packages/shared/dist/project-validation-commands.js +14 -6
  261. package/packages/shared/dist/yolo/spec-envelope-rules.js +85 -0
  262. package/packages/shared/dist/yolo/spec-envelope.js +33 -7
  263. package/packages/shared/dist/yoloop/epic-terminal-git.js +94 -6
  264. package/packages/shared/dist/yoloop/story-write-scope.js +212 -0
  265. package/targets-stubs/antigravity/gemini.md +1 -1
  266. package/targets-stubs/antigravity/install-antigravity.sh +13 -4
  267. package/targets-stubs/antigravity/skill/SKILL.md +1 -1
  268. package/targets-stubs/claude-code/neocortex-root.agent.yaml +1 -1
  269. package/targets-stubs/claude-code/neocortex-root.md +2 -2
  270. package/targets-stubs/claude-code/neocortex.agent.yaml +1 -1
  271. package/targets-stubs/claude-code/neocortex.md +5 -5
  272. package/targets-stubs/codex/AGENTS.md +1 -1
  273. package/targets-stubs/cursor/agent.md +2 -2
  274. package/targets-stubs/gemini-cli/agent.md +2 -2
  275. package/targets-stubs/lib/managed-config-merge.js +77 -1
  276. package/targets-stubs/lib/managed-profile.sh +7 -0
  277. package/targets-stubs/opencode/neocortex-root.md +1 -1
  278. package/targets-stubs/vscode/install-vscode.sh +21 -0
  279. package/targets-stubs/vscode/neocortex.agent.md +2 -2
@@ -1,258 +1,5 @@
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
- * P225.05 -- `neocortex-client story-worktree` (P225-CON-WORKTREE).
15
- * P225.06 -- `cleanup`, `recover`, `record-push` and `--dry-run`.
16
- *
17
- * Closed argument grammar; stdout is public-safe JSON (opaque IDs, SHAs,
18
- * repository-relative paths, reason codes). The private absolute worktree path
19
- * is written only to an explicit new `--path-file` (0600), never printed.
20
- * Exit codes: 0 success, 1 refused, 2 invalid arguments.
21
- */
22
- import { readFile, stat, writeFile } from 'node:fs/promises';
23
- import { dirname, isAbsolute, resolve } from 'node:path';
24
- import { STORY_WORKTREE_CLEANUP_TRIGGERS, StoryWorktreeCleanup, } from '../git/story-worktree-cleanup.js';
25
- import { StoryWorktreeManager } from '../git/story-worktree-manager.js';
26
- export const STORY_WORKTREE_ACTIONS = Object.freeze([
27
- 'create', 'adopt', 'sync', 'status', 'release', 'cleanup', 'recover', 'record-push',
28
- ]);
29
- /** Triggers accepted by `cleanup`; `orphan-recovery` is reserved to `recover`. */
30
- const CLI_CLEANUP_TRIGGERS = STORY_WORKTREE_CLEANUP_TRIGGERS
31
- .filter((trigger) => trigger !== 'orphan-recovery');
32
- const VALUE_FLAGS = Object.freeze({
33
- '--project-root': 'projectRoot',
34
- '--format': 'format',
35
- '--epic': 'epicId',
36
- '--story': 'storyId',
37
- '--dispatch': 'dispatchId',
38
- '--base-sha': 'baseSha',
39
- '--graph-revision': 'graphRevision',
40
- '--owner': 'ownerId',
41
- '--lease': 'leaseId',
42
- '--sha': 'sha',
43
- '--directive-file': 'directiveFile',
44
- '--worktree-path': 'worktreePath',
45
- '--path-file': 'pathFile',
46
- '--trigger': 'trigger',
47
- '--remote': 'remote',
48
- });
49
- const BOOLEAN_FLAGS = Object.freeze({
50
- '--dry-run': 'dryRun',
51
- });
52
- const REQUIRED = Object.freeze({
53
- create: ['epicId', 'storyId', 'dispatchId', 'baseSha', 'graphRevision'],
54
- adopt: ['epicId', 'storyId', 'dispatchId', 'baseSha', 'graphRevision', 'worktreePath'],
55
- sync: ['leaseId'],
56
- status: [],
57
- release: ['leaseId'],
58
- cleanup: ['leaseId', 'trigger'],
59
- recover: [],
60
- 'record-push': ['leaseId', 'remote'],
61
- });
62
- const ALLOWED = Object.freeze({
63
- create: [...REQUIRED.create, 'ownerId', 'pathFile'],
64
- adopt: [...REQUIRED.adopt, 'ownerId', 'pathFile'],
65
- sync: ['leaseId', 'sha', 'directiveFile'],
66
- status: ['leaseId', 'epicId'],
67
- release: ['leaseId'],
68
- cleanup: ['leaseId', 'trigger', 'dryRun'],
69
- recover: ['epicId', 'dryRun'],
70
- 'record-push': ['leaseId', 'remote'],
71
- });
72
- export class StoryWorktreeArgumentError extends Error {
73
- reasonCode;
74
- constructor(reasonCode) {
75
- super(reasonCode);
76
- this.reasonCode = reasonCode;
77
- }
78
- }
79
- export function parseStoryWorktreeArgs(args, cwd = process.cwd()) {
80
- const action = args[0];
81
- if (!STORY_WORKTREE_ACTIONS.includes(action))
82
- throw new StoryWorktreeArgumentError('story-worktree-action-invalid');
83
- const values = {};
84
- for (let index = 1; index < args.length; index++) {
85
- const arg = args[index];
86
- const booleanKey = BOOLEAN_FLAGS[arg];
87
- if (booleanKey) {
88
- if (values[booleanKey] !== undefined)
89
- throw new StoryWorktreeArgumentError('story-worktree-argument-invalid');
90
- values[booleanKey] = 'true';
91
- continue;
92
- }
93
- const equals = arg.indexOf('=');
94
- const flag = equals > 0 ? arg.slice(0, equals) : arg;
95
- const key = VALUE_FLAGS[flag];
96
- if (!key)
97
- throw new StoryWorktreeArgumentError('story-worktree-argument-invalid');
98
- const value = equals > 0 ? arg.slice(equals + 1) : args[++index];
99
- if (value === undefined || value === '' || values[key] !== undefined) {
100
- throw new StoryWorktreeArgumentError('story-worktree-argument-invalid');
101
- }
102
- values[key] = value;
103
- }
104
- const typedAction = action;
105
- const allowed = new Set([...ALLOWED[typedAction], 'projectRoot', 'format']);
106
- if (Object.keys(values).some((key) => !allowed.has(key)))
107
- throw new StoryWorktreeArgumentError('story-worktree-option-invalid');
108
- if (REQUIRED[typedAction].some((key) => values[key] === undefined)) {
109
- throw new StoryWorktreeArgumentError('story-worktree-option-required');
110
- }
111
- if (typedAction === 'sync' && (values.sha === undefined) === (values.directiveFile === undefined)) {
112
- throw new StoryWorktreeArgumentError('story-worktree-sync-source-invalid');
113
- }
114
- if (typedAction === 'status' && (values.leaseId === undefined) === (values.epicId === undefined)) {
115
- throw new StoryWorktreeArgumentError('story-worktree-status-selector-invalid');
116
- }
117
- if (typedAction === 'cleanup' && !CLI_CLEANUP_TRIGGERS.includes(values.trigger)) {
118
- throw new StoryWorktreeArgumentError('story-worktree-trigger-invalid');
119
- }
120
- const format = values.format ?? 'json';
121
- if (format !== 'json' && format !== 'plain')
122
- throw new StoryWorktreeArgumentError('story-worktree-format-invalid');
123
- for (const key of ['directiveFile', 'worktreePath', 'pathFile']) {
124
- if (values[key] !== undefined && !isAbsolute(values[key]))
125
- throw new StoryWorktreeArgumentError('story-worktree-path-argument-invalid');
126
- }
127
- const { dryRun, ...stringValues } = values;
128
- return {
129
- ...stringValues,
130
- ...(dryRun ? { dryRun: true } : {}),
131
- action: typedAction,
132
- projectRoot: resolve(cwd, values.projectRoot ?? '.'),
133
- format,
134
- };
135
- }
136
- async function assertPathFileWritable(path) {
137
- try {
138
- await stat(path);
139
- }
140
- catch {
141
- try {
142
- if ((await stat(dirname(path))).isDirectory())
143
- return;
144
- }
145
- catch {
146
- // fall through
147
- }
148
- throw new StoryWorktreeArgumentError('story-worktree-path-file-invalid');
149
- }
150
- throw new StoryWorktreeArgumentError('story-worktree-path-file-exists');
151
- }
152
- /** Execute one parsed command and return the public payload plus exit code. */
153
- export async function runStoryWorktreeCommand(options, manager = new StoryWorktreeManager({ projectRoot: options.projectRoot }), cleanup = new StoryWorktreeCleanup({ projectRoot: options.projectRoot, manager })) {
154
- if (options.pathFile)
155
- await assertPathFileWritable(options.pathFile);
156
- let result;
157
- switch (options.action) {
158
- case 'create':
159
- result = await manager.create({
160
- epicId: options.epicId, storyId: options.storyId, dispatchId: options.dispatchId,
161
- baseSha: options.baseSha, graphRevision: options.graphRevision,
162
- ...(options.ownerId ? { ownerId: options.ownerId } : {}),
163
- });
164
- break;
165
- case 'adopt':
166
- result = await manager.adopt({
167
- epicId: options.epicId, storyId: options.storyId, dispatchId: options.dispatchId,
168
- baseSha: options.baseSha, graphRevision: options.graphRevision, worktreePath: options.worktreePath,
169
- ...(options.ownerId ? { ownerId: options.ownerId } : {}),
170
- });
171
- break;
172
- case 'sync': {
173
- let directive;
174
- if (options.directiveFile) {
175
- try {
176
- directive = JSON.parse(await readFile(options.directiveFile, 'utf8'));
177
- }
178
- catch {
179
- return { exitCode: 1, payload: { action: 'sync', ok: false, reasonCode: 'story-worktree-directive-invalid' } };
180
- }
181
- }
182
- result = await manager.sync({
183
- leaseId: options.leaseId,
184
- ...(options.sha ? { integratedSha: options.sha } : {}),
185
- ...(directive !== undefined ? { directive } : {}),
186
- });
187
- break;
188
- }
189
- case 'status':
190
- result = await manager.status(options.leaseId ? { leaseId: options.leaseId } : { epicId: options.epicId });
191
- break;
192
- case 'release':
193
- result = await manager.release({ leaseId: options.leaseId });
194
- break;
195
- case 'cleanup':
196
- result = await cleanup.cleanup({
197
- leaseId: options.leaseId, trigger: options.trigger,
198
- ...(options.dryRun ? { dryRun: true } : {}),
199
- });
200
- break;
201
- case 'recover':
202
- result = await cleanup.sweep({
203
- ...(options.epicId ? { epicId: options.epicId } : {}), ...(options.dryRun ? { dryRun: true } : {}),
204
- });
205
- break;
206
- case 'record-push':
207
- result = await cleanup.recordPush({ leaseId: options.leaseId, remote: options.remote });
208
- break;
209
- }
210
- if (!result.ok) {
211
- return {
212
- exitCode: 1,
213
- payload: {
214
- action: options.action, ok: false, reasonCode: result.reasonCode,
215
- ...(result.conflictPaths ? { conflictPaths: result.conflictPaths } : {}),
216
- },
217
- };
218
- }
219
- if (options.pathFile && result.privatePath) {
220
- try {
221
- await writeFile(options.pathFile, `${result.privatePath}\n`, { flag: 'wx', mode: 0o600 });
222
- }
223
- catch {
224
- return { exitCode: 1, payload: { action: options.action, ok: false, reasonCode: 'story-worktree-path-file-invalid' } };
225
- }
226
- }
227
- return { exitCode: 0, payload: { action: options.action, ok: true, value: result.value } };
228
- }
229
- function render(payload, format) {
230
- if (format === 'json')
231
- return JSON.stringify(payload, null, 2);
232
- const parts = [`story-worktree ${String(payload.action)}: ${payload.ok ? 'ok' : 'refused'}`];
233
- if (payload.reasonCode)
234
- parts.push(`reason=${String(payload.reasonCode)}`);
235
- return parts.join(' ');
236
- }
237
- export async function storyWorktreeCliHandler(args) {
238
- let options;
239
- try {
240
- options = parseStoryWorktreeArgs(args);
241
- }
242
- catch (error) {
243
- const reasonCode = error instanceof StoryWorktreeArgumentError ? error.reasonCode : 'story-worktree-argument-invalid';
244
- const action = STORY_WORKTREE_ACTIONS.includes(args[0]) ? args[0] : null;
245
- process.stdout.write(`${JSON.stringify({ action, ok: false, reasonCode })}\n`);
246
- return 2;
247
- }
248
- try {
249
- const { exitCode, payload } = await runStoryWorktreeCommand(options);
250
- process.stdout.write(`${render(payload, options.format)}\n`);
251
- return exitCode;
252
- }
253
- catch (error) {
254
- const reasonCode = error instanceof StoryWorktreeArgumentError ? error.reasonCode : 'story-worktree-internal-error';
255
- process.stdout.write(`${render({ action: options.action, ok: false, reasonCode }, options.format)}\n`);
256
- return error instanceof StoryWorktreeArgumentError ? 2 : 1;
257
- }
258
- }
1
+ import{readFile as g,stat as f,writeFile as m}from"node:fs/promises";import{dirname as S,isAbsolute as b,resolve as C}from"node:path";import{STORY_WORKTREE_CLEANUP_TRIGGERS as j,StoryWorktreeCleanup as F}from"../git/story-worktree-cleanup.js";import{StoryWorktreeManager as O}from"../git/story-worktree-manager.js";const y=Object.freeze(["create","adopt","sync","status","release","cleanup","recover","record-push"]),x=j.filter(e=>e!=="orphan-recovery"),E=Object.freeze({"--project-root":"projectRoot","--format":"format","--epic":"epicId","--story":"storyId","--dispatch":"dispatchId","--base-sha":"baseSha","--graph-revision":"graphRevision","--owner":"ownerId","--lease":"leaseId","--sha":"sha","--directive-file":"directiveFile","--worktree-path":"worktreePath","--path-file":"pathFile","--trigger":"trigger","--remote":"remote"}),P=Object.freeze({"--dry-run":"dryRun"}),h=Object.freeze({create:["epicId","storyId","dispatchId","baseSha","graphRevision"],adopt:["epicId","storyId","dispatchId","baseSha","graphRevision","worktreePath"],sync:["leaseId"],status:[],release:["leaseId"],cleanup:["leaseId","trigger"],recover:[],"record-push":["leaseId","remote"]}),A=Object.freeze({create:[...h.create,"ownerId","pathFile"],adopt:[...h.adopt,"ownerId","pathFile"],sync:["leaseId","sha","directiveFile"],status:["leaseId","epicId"],release:["leaseId"],cleanup:["leaseId","trigger","dryRun"],recover:["epicId","dryRun"],"record-push":["leaseId","remote"]});class o extends Error{reasonCode;constructor(t){super(t),this.reasonCode=t}}function W(e,t=process.cwd()){const a=e[0];if(!y.includes(a))throw new o("story-worktree-action-invalid");const r={};for(let s=1;s<e.length;s++){const n=e[s],l=P[n];if(l){if(r[l]!==void 0)throw new o("story-worktree-argument-invalid");r[l]="true";continue}const c=n.indexOf("="),R=c>0?n.slice(0,c):n,u=E[R];if(!u)throw new o("story-worktree-argument-invalid");const w=c>0?n.slice(c+1):e[++s];if(w===void 0||w===""||r[u]!==void 0)throw new o("story-worktree-argument-invalid");r[u]=w}const i=a,p=new Set([...A[i],"projectRoot","format"]);if(Object.keys(r).some(s=>!p.has(s)))throw new o("story-worktree-option-invalid");if(h[i].some(s=>r[s]===void 0))throw new o("story-worktree-option-required");if(i==="sync"&&r.sha===void 0==(r.directiveFile===void 0))throw new o("story-worktree-sync-source-invalid");if(i==="status"&&r.leaseId===void 0==(r.epicId===void 0))throw new o("story-worktree-status-selector-invalid");if(i==="cleanup"&&!x.includes(r.trigger))throw new o("story-worktree-trigger-invalid");const d=r.format??"json";if(d!=="json"&&d!=="plain")throw new o("story-worktree-format-invalid");for(const s of["directiveFile","worktreePath","pathFile"])if(r[s]!==void 0&&!b(r[s]))throw new o("story-worktree-path-argument-invalid");const{dryRun:k,...v}=r;return{...v,...k?{dryRun:!0}:{},action:i,projectRoot:C(t,r.projectRoot??"."),format:d}}async function L(e){try{await f(e)}catch{try{if((await f(S(e))).isDirectory())return}catch{}throw new o("story-worktree-path-file-invalid")}throw new o("story-worktree-path-file-exists")}async function _(e,t=new O({projectRoot:e.projectRoot}),a=new F({projectRoot:e.projectRoot,manager:t})){e.pathFile&&await L(e.pathFile);let r;switch(e.action){case"create":r=await t.create({epicId:e.epicId,storyId:e.storyId,dispatchId:e.dispatchId,baseSha:e.baseSha,graphRevision:e.graphRevision,...e.ownerId?{ownerId:e.ownerId}:{}});break;case"adopt":r=await t.adopt({epicId:e.epicId,storyId:e.storyId,dispatchId:e.dispatchId,baseSha:e.baseSha,graphRevision:e.graphRevision,worktreePath:e.worktreePath,...e.ownerId?{ownerId:e.ownerId}:{}});break;case"sync":{let i;if(e.directiveFile)try{i=JSON.parse(await g(e.directiveFile,"utf8"))}catch{return{exitCode:1,payload:{action:"sync",ok:!1,reasonCode:"story-worktree-directive-invalid"}}}r=await t.sync({leaseId:e.leaseId,...e.sha?{integratedSha:e.sha}:{},...i!==void 0?{directive:i}:{}});break}case"status":r=await t.status(e.leaseId?{leaseId:e.leaseId}:{epicId:e.epicId});break;case"release":r=await t.release({leaseId:e.leaseId});break;case"cleanup":r=await a.cleanup({leaseId:e.leaseId,trigger:e.trigger,...e.dryRun?{dryRun:!0}:{}});break;case"recover":r=await a.sweep({...e.epicId?{epicId:e.epicId}:{},...e.dryRun?{dryRun:!0}:{}});break;case"record-push":r=await a.recordPush({leaseId:e.leaseId,remote:e.remote});break}if(!r.ok)return{exitCode:1,payload:{action:e.action,ok:!1,reasonCode:r.reasonCode,...r.conflictPaths?{conflictPaths:r.conflictPaths}:{}}};if(e.pathFile&&r.privatePath)try{await m(e.pathFile,`${r.privatePath}
2
+ `,{flag:"wx",mode:384})}catch{return{exitCode:1,payload:{action:e.action,ok:!1,reasonCode:"story-worktree-path-file-invalid"}}}return{exitCode:0,payload:{action:e.action,ok:!0,value:r.value}}}function I(e,t){if(t==="json")return JSON.stringify(e,null,2);const a=[`story-worktree ${String(e.action)}: ${e.ok?"ok":"refused"}`];return e.reasonCode&&a.push(`reason=${String(e.reasonCode)}`),a.join(" ")}async function z(e){let t;try{t=W(e)}catch(a){const r=a instanceof o?a.reasonCode:"story-worktree-argument-invalid",i=y.includes(e[0])?e[0]:null;return process.stdout.write(`${JSON.stringify({action:i,ok:!1,reasonCode:r})}
3
+ `),2}try{const{exitCode:a,payload:r}=await _(t);return process.stdout.write(`${I(r,t.format)}
4
+ `),a}catch(a){const r=a instanceof o?a.reasonCode:"story-worktree-internal-error";return process.stdout.write(`${I({action:t.action,ok:!1,reasonCode:r},t.format)}
5
+ `),a instanceof o?2:1}}export{y as STORY_WORKTREE_ACTIONS,o as StoryWorktreeArgumentError,W as parseStoryWorktreeArgs,_ as runStoryWorktreeCommand,z as storyWorktreeCliHandler};
@@ -1,60 +1 @@
1
- import { timingSafeEqual } from 'node:crypto';
2
- import { parseHostAuthReference, } from './host-auth-reference.js';
3
- function sameDigest(actual, expected) {
4
- if (!/^[a-f0-9]{64}$/.test(actual) || !/^[a-f0-9]{64}$/.test(expected))
5
- return false;
6
- return timingSafeEqual(Buffer.from(actual, 'hex'), Buffer.from(expected, 'hex'));
7
- }
8
- export function createHostAuthBroker(adapter) {
9
- const capability = Object.freeze(Object.create(null));
10
- const authorities = new WeakSet([capability]);
11
- let active = false;
12
- const broker = Object.freeze({
13
- async execute(request) {
14
- if (!request.capability || !authorities.has(request.capability) || request.caller !== 'host-runtime') {
15
- return { status: 'denied', reasonCode: 'host-auth-origin-denied' };
16
- }
17
- let reference;
18
- try {
19
- reference = parseHostAuthReference(request.reference);
20
- }
21
- catch (error) {
22
- return { status: 'denied', reasonCode: error instanceof Error ? error.message : 'host-auth-reference-invalid' };
23
- }
24
- if (!sameDigest(reference.subjectDigest, request.expectedSubjectDigest)
25
- || !sameDigest(reference.policyDigest, request.expectedPolicyDigest)
26
- || !sameDigest(reference.dispatchDigest, request.expectedDispatchDigest)) {
27
- return { status: 'denied', reasonCode: 'host-auth-reference-invalid' };
28
- }
29
- if (reference.revocationEpoch < request.minimumRevocationEpoch) {
30
- return { status: 'denied', reasonCode: 'host-auth-reference-revoked' };
31
- }
32
- if (!request.requiredScopes.every((scope) => reference.scopes.includes(scope))) {
33
- return { status: 'denied', reasonCode: 'host-auth-scope-denied' };
34
- }
35
- if (!adapter)
36
- return { status: 'unavailable', reasonCode: 'host-auth-capability-unavailable' };
37
- if (adapter.provider !== reference.provider || adapter.target !== reference.target) {
38
- return { status: 'denied', reasonCode: 'host-auth-target-denied' };
39
- }
40
- const operation = adapter.operations[reference.operation];
41
- if (!operation)
42
- return { status: 'denied', reasonCode: 'host-auth-operation-denied' };
43
- if (active)
44
- return { status: 'unavailable', reasonCode: 'host-auth-capability-unavailable' };
45
- active = true;
46
- try {
47
- // Mutable reference checks are deliberately repeated immediately before effect.
48
- parseHostAuthReference(reference);
49
- if (reference.revocationEpoch < request.minimumRevocationEpoch) {
50
- return { status: 'denied', reasonCode: 'host-auth-reference-revoked' };
51
- }
52
- return await operation(reference);
53
- }
54
- finally {
55
- active = false;
56
- }
57
- },
58
- });
59
- return Object.freeze({ broker, capability });
60
- }
1
+ import{timingSafeEqual as f}from"node:crypto";import{parseHostAuthReference as c}from"./host-auth-reference.js";function n(r,a){return!/^[a-f0-9]{64}$/.test(r)||!/^[a-f0-9]{64}$/.test(a)?!1:f(Buffer.from(r,"hex"),Buffer.from(a,"hex"))}function p(r){const a=Object.freeze(Object.create(null)),u=new WeakSet([a]);let o=!1;const d=Object.freeze({async execute(t){if(!t.capability||!u.has(t.capability)||t.caller!=="host-runtime")return{status:"denied",reasonCode:"host-auth-origin-denied"};let e;try{e=c(t.reference)}catch(i){return{status:"denied",reasonCode:i instanceof Error?i.message:"host-auth-reference-invalid"}}if(!n(e.subjectDigest,t.expectedSubjectDigest)||!n(e.policyDigest,t.expectedPolicyDigest)||!n(e.dispatchDigest,t.expectedDispatchDigest))return{status:"denied",reasonCode:"host-auth-reference-invalid"};if(e.revocationEpoch<t.minimumRevocationEpoch)return{status:"denied",reasonCode:"host-auth-reference-revoked"};if(!t.requiredScopes.every(i=>e.scopes.includes(i)))return{status:"denied",reasonCode:"host-auth-scope-denied"};if(!r)return{status:"unavailable",reasonCode:"host-auth-capability-unavailable"};if(r.provider!==e.provider||r.target!==e.target)return{status:"denied",reasonCode:"host-auth-target-denied"};const s=r.operations[e.operation];if(!s)return{status:"denied",reasonCode:"host-auth-operation-denied"};if(o)return{status:"unavailable",reasonCode:"host-auth-capability-unavailable"};o=!0;try{return c(e),e.revocationEpoch<t.minimumRevocationEpoch?{status:"denied",reasonCode:"host-auth-reference-revoked"}:await s(e)}finally{o=!1}}});return Object.freeze({broker:d,capability:a})}export{p as createHostAuthBroker};
@@ -1,93 +1 @@
1
- import { randomBytes } from 'node:crypto';
2
- export const HOST_AUTH_REFERENCE_SCHEMA = 'HostAuthReference/1.0';
3
- export const HOST_AUTH_REFERENCE_MAX_BYTES = 4_096;
4
- export const HOST_AUTH_REFERENCE_MAX_TTL_MS = 60_000;
5
- const DIGEST = /^[a-f0-9]{64}$/;
6
- const ID = /^[A-Za-z0-9_-]{16,128}$/;
7
- const TARGET = /^[a-z0-9][a-z0-9._:-]{0,127}$/;
8
- const SCOPE = /^[a-z][a-z0-9._:-]{0,79}$/;
9
- const PROVIDERS = new Set(['codex', 'opencode']);
10
- const OPERATIONS = new Set([
11
- 'inspect-session',
12
- 'prepare-license-auth',
13
- 'reconcile-license-auth',
14
- 'authorize-business-replay',
15
- ]);
16
- const KEYS = [
17
- 'schemaVersion', 'referenceId', 'provider', 'authDomain', 'target', 'operation',
18
- 'scopes', 'issuedAt', 'expiresAt', 'revocationEpoch', 'subjectDigest',
19
- 'policyDigest', 'dispatchDigest',
20
- ];
21
- export class HostAuthReferenceError extends Error {
22
- reasonCode;
23
- constructor(reasonCode) {
24
- super(reasonCode);
25
- this.reasonCode = reasonCode;
26
- this.name = 'HostAuthReferenceError';
27
- }
28
- }
29
- function deny(reasonCode) {
30
- throw new HostAuthReferenceError(reasonCode);
31
- }
32
- export function parseHostAuthReference(input, options = {}) {
33
- let value = input;
34
- if (typeof input === 'string') {
35
- if (Buffer.byteLength(input, 'utf8') > HOST_AUTH_REFERENCE_MAX_BYTES)
36
- deny('host-auth-reference-oversized');
37
- try {
38
- value = JSON.parse(input);
39
- }
40
- catch {
41
- deny('host-auth-reference-invalid');
42
- }
43
- }
44
- if (!value || typeof value !== 'object' || Array.isArray(value))
45
- deny('host-auth-reference-invalid');
46
- const raw = value;
47
- const keys = Object.keys(raw);
48
- if (keys.length !== KEYS.length || keys.some((key) => !KEYS.includes(key))) {
49
- deny('host-auth-reference-invalid');
50
- }
51
- if (raw.schemaVersion !== HOST_AUTH_REFERENCE_SCHEMA || raw.authDomain !== 'model-provider')
52
- deny('host-auth-reference-invalid');
53
- if (typeof raw.provider !== 'string' || !PROVIDERS.has(raw.provider))
54
- deny('host-auth-reference-invalid');
55
- if (typeof raw.operation !== 'string' || !OPERATIONS.has(raw.operation))
56
- deny('host-auth-operation-denied');
57
- if (typeof raw.referenceId !== 'string' || !ID.test(raw.referenceId)
58
- || typeof raw.target !== 'string' || !TARGET.test(raw.target)
59
- || typeof raw.subjectDigest !== 'string' || !DIGEST.test(raw.subjectDigest)
60
- || typeof raw.policyDigest !== 'string' || !DIGEST.test(raw.policyDigest)
61
- || typeof raw.dispatchDigest !== 'string' || !DIGEST.test(raw.dispatchDigest))
62
- deny('host-auth-reference-invalid');
63
- if (!Array.isArray(raw.scopes) || raw.scopes.length === 0 || raw.scopes.length > 16
64
- || raw.scopes.some((scope) => typeof scope !== 'string' || !SCOPE.test(scope))
65
- || new Set(raw.scopes).size !== raw.scopes.length)
66
- deny('host-auth-scope-denied');
67
- if (!Number.isSafeInteger(raw.revocationEpoch) || raw.revocationEpoch < 0)
68
- deny('host-auth-reference-invalid');
69
- const issuedAt = Date.parse(String(raw.issuedAt));
70
- const expiresAt = Date.parse(String(raw.expiresAt));
71
- if (!Number.isFinite(issuedAt) || !Number.isFinite(expiresAt) || expiresAt <= issuedAt
72
- || expiresAt - issuedAt > HOST_AUTH_REFERENCE_MAX_TTL_MS)
73
- deny('host-auth-reference-invalid');
74
- const now = options.now ?? Date.now();
75
- if (issuedAt > now + 30_000 || (!options.allowExpired && expiresAt <= now))
76
- deny('host-auth-reference-expired');
77
- const encoded = JSON.stringify(raw);
78
- if (Buffer.byteLength(encoded, 'utf8') > HOST_AUTH_REFERENCE_MAX_BYTES)
79
- deny('host-auth-reference-oversized');
80
- return Object.freeze({ ...raw, scopes: Object.freeze([...raw.scopes]) });
81
- }
82
- export function createHostAuthReference(input) {
83
- const now = input.now ?? Date.now();
84
- const ttlMs = input.ttlMs ?? 30_000;
85
- const { now: _now, ttlMs: _ttl, ...fields } = input;
86
- return parseHostAuthReference({
87
- schemaVersion: HOST_AUTH_REFERENCE_SCHEMA,
88
- referenceId: randomBytes(18).toString('base64url'),
89
- ...fields,
90
- issuedAt: new Date(now).toISOString(),
91
- expiresAt: new Date(now + ttlMs).toISOString(),
92
- }, { now });
93
- }
1
+ import{randomBytes as l}from"node:crypto";const p="HostAuthReference/1.0",u=4096,E=6e4,f=/^[a-f0-9]{64}$/,y=/^[A-Za-z0-9_-]{16,128}$/,A=/^[a-z0-9][a-z0-9._:-]{0,127}$/,S=/^[a-z][a-z0-9._:-]{0,79}$/,_=new Set(["codex","opencode"]),D=new Set(["inspect-session","prepare-license-auth","reconcile-license-auth","authorize-business-replay"]),d=["schemaVersion","referenceId","provider","authDomain","target","operation","scopes","issuedAt","expiresAt","revocationEpoch","subjectDigest","policyDigest","dispatchDigest"];class v extends Error{reasonCode;constructor(r){super(r),this.reasonCode=r,this.name="HostAuthReferenceError"}}function t(s){throw new v(s)}function w(s,r={}){let o=s;if(typeof s=="string"){Buffer.byteLength(s,"utf8")>u&&t("host-auth-reference-oversized");try{o=JSON.parse(s)}catch{t("host-auth-reference-invalid")}}(!o||typeof o!="object"||Array.isArray(o))&&t("host-auth-reference-invalid");const e=o,a=Object.keys(e);(a.length!==d.length||a.some(c=>!d.includes(c)))&&t("host-auth-reference-invalid"),(e.schemaVersion!==p||e.authDomain!=="model-provider")&&t("host-auth-reference-invalid"),(typeof e.provider!="string"||!_.has(e.provider))&&t("host-auth-reference-invalid"),(typeof e.operation!="string"||!D.has(e.operation))&&t("host-auth-operation-denied"),(typeof e.referenceId!="string"||!y.test(e.referenceId)||typeof e.target!="string"||!A.test(e.target)||typeof e.subjectDigest!="string"||!f.test(e.subjectDigest)||typeof e.policyDigest!="string"||!f.test(e.policyDigest)||typeof e.dispatchDigest!="string"||!f.test(e.dispatchDigest))&&t("host-auth-reference-invalid"),(!Array.isArray(e.scopes)||e.scopes.length===0||e.scopes.length>16||e.scopes.some(c=>typeof c!="string"||!S.test(c))||new Set(e.scopes).size!==e.scopes.length)&&t("host-auth-scope-denied"),(!Number.isSafeInteger(e.revocationEpoch)||e.revocationEpoch<0)&&t("host-auth-reference-invalid");const n=Date.parse(String(e.issuedAt)),i=Date.parse(String(e.expiresAt));(!Number.isFinite(n)||!Number.isFinite(i)||i<=n||i-n>E)&&t("host-auth-reference-invalid");const h=r.now??Date.now();(n>h+3e4||!r.allowExpired&&i<=h)&&t("host-auth-reference-expired");const g=JSON.stringify(e);return Buffer.byteLength(g,"utf8")>u&&t("host-auth-reference-oversized"),Object.freeze({...e,scopes:Object.freeze([...e.scopes])})}function R(s){const r=s.now??Date.now(),o=s.ttlMs??3e4,{now:e,ttlMs:a,...n}=s;return w({schemaVersion:p,referenceId:l(18).toString("base64url"),...n,issuedAt:new Date(r).toISOString(),expiresAt:new Date(r+o).toISOString()},{now:r})}export{u as HOST_AUTH_REFERENCE_MAX_BYTES,E as HOST_AUTH_REFERENCE_MAX_TTL_MS,p as HOST_AUTH_REFERENCE_SCHEMA,v as HostAuthReferenceError,R as createHostAuthReference,w as parseHostAuthReference};
@@ -1,13 +1 @@
1
- import { homedir } from 'node:os';
2
- import { basename, isAbsolute, join, normalize } from 'node:path';
3
- /** Explicit isolated profile for local integration runs; the default remains unchanged. */
4
- export function neocortexProfileDirectory() {
5
- const override = process.env.NEOCORTEX_PROFILE_DIR;
6
- if (override === undefined)
7
- return join(homedir(), '.neocortex');
8
- const normalized = normalize(override);
9
- if (!isAbsolute(override) || /[\r\n\0]/.test(override) || basename(normalized) !== '.neocortex') {
10
- throw new Error('neocortex-profile-dir-invalid');
11
- }
12
- return normalized;
13
- }
1
+ import{homedir as o}from"node:os";import{basename as n,isAbsolute as i,join as t,normalize as c}from"node:path";function s(){const r=process.env.NEOCORTEX_PROFILE_DIR;if(r===void 0)return t(o(),".neocortex");const e=c(r);if(!i(r)||/[\r\n\0]/.test(r)||n(e)!==".neocortex")throw new Error("neocortex-profile-dir-invalid");return e}export{s as neocortexProfileDirectory};