@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,53 +1,2 @@
1
- /**
2
- * Single-valued `Neocortex-*` story checkpoint trailers.
3
- *
4
- * Agents may paste the trailer block and also pass it through `--trailer`, or
5
- * append a separate `Co-Authored-By` paragraph. Parsing is therefore line
6
- * based over the whole commit body: identical repeated lines collapse into one
7
- * value, non-`Neocortex-` lines are ignored, and a key repeated with a
8
- * different value is ambiguous and fails closed. Keys are reported in
9
- * lowercase; they are fixed public identifiers, never user content.
10
- */
11
- export const STORY_CHECKPOINT_TRAILER_KEYS = Object.freeze([
12
- 'Neocortex-Story',
13
- 'Neocortex-Epic',
14
- 'Neocortex-Execution-Branch',
15
- 'Neocortex-Prepared-Base',
16
- 'Neocortex-Bundle-Digest',
17
- 'Neocortex-Review-Artifact-Digest',
18
- 'Neocortex-Graph-Revision',
19
- 'Neocortex-Claim-Revision',
20
- 'Neocortex-Root-Memory-Effect',
21
- 'Neocortex-Dispatch',
22
- 'Neocortex-Bundle',
23
- ]);
24
- const TRAILER_LINE = /^(neocortex-[a-z0-9][a-z0-9-]{0,63}):[ \t]*(.*?)[ \t]*$/i;
25
- /** Lowercase public key used in `direct-yolo-trailer-*:<key>` reason codes. */
26
- export function trailerReasonKey(key) {
27
- return key.toLowerCase();
28
- }
29
- /**
30
- * Collect the single value of each tracked key. Keys outside `keys` (for
31
- * example multi-valued review-reconciliation trailers) are ignored.
32
- */
33
- export function parseNeocortexTrailers(body, keys = STORY_CHECKPOINT_TRAILER_KEYS) {
34
- const tracked = new Set(keys.map(trailerReasonKey));
35
- const values = new Map();
36
- for (const raw of body.split('\n')) {
37
- const match = TRAILER_LINE.exec(raw.trim());
38
- if (!match)
39
- continue;
40
- const key = trailerReasonKey(match[1]);
41
- if (!tracked.has(key))
42
- continue;
43
- const value = match[2];
44
- const previous = values.get(key);
45
- if (previous !== undefined && previous !== value)
46
- return { ok: false, key };
47
- values.set(key, value);
48
- }
49
- return { ok: true, values };
50
- }
51
- export function trailerValue(values, key) {
52
- return values.get(trailerReasonKey(key));
53
- }
1
+ const u=Object.freeze(["Neocortex-Story","Neocortex-Epic","Neocortex-Execution-Branch","Neocortex-Prepared-Base","Neocortex-Bundle-Digest","Neocortex-Review-Artifact-Digest","Neocortex-Graph-Revision","Neocortex-Claim-Revision","Neocortex-Root-Memory-Effect","Neocortex-Dispatch","Neocortex-Bundle"]),f=/^(neocortex-[a-z0-9][a-z0-9-]{0,63}):[ \t]*(.*?)[ \t]*$/i;function n(e){return e.toLowerCase()}function N(e,t=u){const s=new Set(t.map(n)),r=new Map;for(const x of e.split(`
2
+ `)){const c=f.exec(x.trim());if(!c)continue;const o=n(c[1]);if(!s.has(o))continue;const i=c[2],a=r.get(o);if(a!==void 0&&a!==i)return{ok:!1,key:o};r.set(o,i)}return{ok:!0,values:r}}function p(e,t){return e.get(n(t))}export{u as STORY_CHECKPOINT_TRAILER_KEYS,N as parseNeocortexTrailers,n as trailerReasonKey,p as trailerValue};
@@ -0,0 +1,62 @@
1
+ export declare const RELEASE_GATE_ENV_CONTRACT_ID: "P205-CI-02-ENV";
2
+ export declare const RELEASE_GATE_ENV_CONTRACT_PATH: "config/release-gates.env.v1.json";
3
+ export declare const RELEASE_GATE_ENV_CONTRACT_MAX_BYTES: number;
4
+ export declare const RELEASE_GATE_ENV_MAX_NAMES_PER_LIST = 64;
5
+ export declare const RELEASE_GATE_ENV_NAME_PATTERN: RegExp;
6
+ export declare const RELEASE_GATE_MINIMAL_ENV: readonly string[];
7
+ export declare const P205_GATE_ENV_CONTRACT_INVALID: "p205-gate-env-contract-invalid";
8
+ export declare const P205_GATE_ENV_CONTRACT_UNDECLARED: "p205-gate-env-contract-undeclared";
9
+ export declare const P205_DATASOURCE_MISSING_PREFIX: "p205-datasource-missing:";
10
+ export type P205DatasourceMissingReason = `${typeof P205_DATASOURCE_MISSING_PREFIX}${string}`;
11
+ export interface ReleaseGateEnvContract {
12
+ readonly schemaVersion: 1;
13
+ readonly contract: typeof RELEASE_GATE_ENV_CONTRACT_ID;
14
+ readonly required: readonly string[];
15
+ readonly optional: readonly string[];
16
+ }
17
+ export type ReleaseGateEnvContractValidation = {
18
+ readonly ok: true;
19
+ readonly contract: ReleaseGateEnvContract;
20
+ } | {
21
+ readonly ok: false;
22
+ readonly reason: typeof P205_GATE_ENV_CONTRACT_INVALID;
23
+ };
24
+ export type ReleaseGateEnvProjection = {
25
+ readonly ok: true;
26
+ readonly env: Readonly<Record<string, string>>;
27
+ readonly forwardedNames: readonly string[];
28
+ readonly debt: readonly (typeof P205_GATE_ENV_CONTRACT_UNDECLARED)[];
29
+ } | {
30
+ readonly ok: false;
31
+ readonly reason: P205DatasourceMissingReason;
32
+ readonly missing: readonly string[];
33
+ };
34
+ export interface ProjectReleaseGateEnvInput {
35
+ readonly contract: ReleaseGateEnvContract | null;
36
+ readonly parentEnv: Readonly<Record<string, string | undefined>>;
37
+ readonly platform: string;
38
+ }
39
+ export type ReleaseGateEnvContractRead = {
40
+ readonly kind: 'absent';
41
+ } | {
42
+ readonly kind: 'present';
43
+ readonly contract: ReleaseGateEnvContract;
44
+ } | {
45
+ readonly kind: 'invalid';
46
+ readonly reason: typeof P205_GATE_ENV_CONTRACT_INVALID;
47
+ };
48
+ export type ResolvedReleaseGateEnv = ReleaseGateEnvProjection | {
49
+ readonly ok: false;
50
+ readonly reason: typeof P205_GATE_ENV_CONTRACT_INVALID;
51
+ };
52
+ export declare function validateReleaseGateEnvContract(value: unknown): ReleaseGateEnvContractValidation;
53
+ export declare function parseReleaseGateEnvContract(text: string): ReleaseGateEnvContractValidation;
54
+ export declare function projectReleaseGateEnv(input: ProjectReleaseGateEnvInput): ReleaseGateEnvProjection;
55
+ /**
56
+ * Reads `config/release-gates.env.v1.json` under `projectRoot` with a fixed
57
+ * relative path. Absent -> `absent`; symlink, non-regular file, oversize,
58
+ * read failure or invalid content -> `p205-gate-env-contract-invalid`.
59
+ */
60
+ export declare function readReleaseGateEnvContract(projectRoot: string): ReleaseGateEnvContractRead;
61
+ /** Reads the sibling contract and projects the gate env before any spawn. */
62
+ export declare function resolveReleaseGateEnv(projectRoot: string, parentEnv?: Readonly<Record<string, string | undefined>>, platform?: string): ResolvedReleaseGateEnv;
@@ -0,0 +1 @@
1
+ import{closeSync as N,constants as d,fstatSync as b,lstatSync as R,openSync as y,readSync as S}from"node:fs";import{join as C}from"node:path";const l="P205-CI-02-ENV",j="config/release-gates.env.v1.json",E=16*1024,h=64,m=/^[A-Z][A-Za-z0-9_]{0,63}$/,z=Object.freeze(["PATH","HOME","USERPROFILE","SystemRoot","ComSpec","PATHEXT","TEMP","TMP","TMPDIR","LANG","LC_ALL","TZ","CI"]),p="p205-gate-env-contract-invalid",L="p205-gate-env-contract-undeclared",k="p205-datasource-missing:",A=Object.freeze(["contract","optional","required","schemaVersion"]),f=Object.freeze({ok:!1,reason:p});function _(t){return!Array.isArray(t)||t.length>h?!1:t.every(e=>typeof e=="string"&&m.test(e))}function v(t){if(!t||typeof t!="object"||Array.isArray(t))return f;const e=t,o=Object.keys(e).sort();if(o.length!==A.length||o.some((n,s)=>n!==A[s])||e.schemaVersion!==1||e.contract!==l||!_(e.required)||!_(e.optional))return f;const r=[...e.required,...e.optional];return new Set(r).size!==r.length?f:Object.freeze({ok:!0,contract:Object.freeze({schemaVersion:1,contract:l,required:Object.freeze([...e.required]),optional:Object.freeze([...e.optional])})})}function I(t){let e;try{e=JSON.parse(t)}catch{return f}return v(e)}function O(t,e,o){const r=t[e];if(r!==void 0||!o)return r;const n=e.toUpperCase(),s=Object.keys(t).sort().find(a=>a.toUpperCase()===n);return s===void 0?void 0:t[s]}function x(t){const e=t.platform==="win32",o=t.contract;if(o){const c=o.required.filter(i=>O(t.parentEnv,i,e)===void 0);if(c.length>0)return Object.freeze({ok:!1,reason:`${k}${c[0]}`,missing:Object.freeze(c)})}const r=[],n=new Set;for(const c of[...z,...o?.required??[],...o?.optional??[]]){const i=e?c.toUpperCase():c;n.has(i)||(n.add(i),r.push(c))}const s={},a=[];for(const c of r){const i=O(t.parentEnv,c,e);i!==void 0&&(s[c]=i,a.push(c))}return Object.freeze({ok:!0,env:Object.freeze(s),forwardedNames:Object.freeze(a),debt:Object.freeze(o?[]:[L])})}function T(t){const e=t?.code;return e==="ENOENT"||e==="ENOTDIR"}function g(t){const e=Object.freeze({kind:"invalid",reason:p}),o=C(t,...j.split("/"));try{const n=R(o);if(n.isSymbolicLink()||!n.isFile()||n.size>E)return e}catch(n){return T(n)?Object.freeze({kind:"absent"}):e}let r;try{r=y(o,d.O_RDONLY|(d.O_NOFOLLOW??0))}catch(n){return T(n)?Object.freeze({kind:"absent"}):e}try{const n=b(r);if(!n.isFile()||n.size>E)return e;const s=Buffer.alloc(E+1);let a=0;for(;a<s.length;){const u=S(r,s,a,s.length-a,a);if(u===0)break;a+=u}if(a>E)return e;let c;try{c=new TextDecoder("utf-8",{fatal:!0}).decode(s.subarray(0,a))}catch{return e}const i=I(c);return i.ok?Object.freeze({kind:"present",contract:i.contract}):e}catch{return e}finally{N(r)}}function V(t,e=process.env,o=process.platform){const r=g(t);return r.kind==="invalid"?f:x({contract:r.kind==="present"?r.contract:null,parentEnv:e,platform:o})}export{k as P205_DATASOURCE_MISSING_PREFIX,p as P205_GATE_ENV_CONTRACT_INVALID,L as P205_GATE_ENV_CONTRACT_UNDECLARED,l as RELEASE_GATE_ENV_CONTRACT_ID,E as RELEASE_GATE_ENV_CONTRACT_MAX_BYTES,j as RELEASE_GATE_ENV_CONTRACT_PATH,h as RELEASE_GATE_ENV_MAX_NAMES_PER_LIST,m as RELEASE_GATE_ENV_NAME_PATTERN,z as RELEASE_GATE_MINIMAL_ENV,I as parseReleaseGateEnvContract,x as projectReleaseGateEnv,g as readReleaseGateEnvContract,V as resolveReleaseGateEnv,v as validateReleaseGateEnvContract};
@@ -6,6 +6,22 @@ export interface AnchoredFilesystemTestOptions {
6
6
  /** Test-only platform seam; production always uses process.platform. */
7
7
  readonly platform?: NodeJS.Platform;
8
8
  }
9
+ /** P226.02 supervised gate execution inside the anchored sandbox. */
10
+ export interface AnchoredGateExecutionOptions {
11
+ /** Exact environment for the helper and its gate child (never merged with process.env). */
12
+ readonly env: NodeJS.ProcessEnv;
13
+ /** SIGTERM the process group after this many milliseconds. */
14
+ readonly timeoutMs: number;
15
+ /** SIGKILL the process group this many milliseconds after SIGTERM. */
16
+ readonly graceMs: number;
17
+ }
18
+ /** Bounded stderr tail retained for the gate failure parser only. */
19
+ export declare const ANCHORED_GATE_STDERR_TAIL_BYTES: number;
20
+ /**
21
+ * Read the bounded gate stderr tail attached to an anchored failure. The tail
22
+ * is a non-enumerable symbol property so it never serializes with the error.
23
+ */
24
+ export declare function anchoredGateStderrTail(error: unknown): string | undefined;
9
25
  export interface AnchoredDirectoryIdentity {
10
26
  readonly dev: string;
11
27
  readonly ino: string;
@@ -22,6 +38,14 @@ export declare function anchoredDirectoryIdentity(path: string): Promise<Anchore
22
38
  export declare function anchoredExecuteGit(parent: string, name: string, expectedChild: AnchoredDirectoryIdentity, args: readonly string[], input?: Buffer | string, options?: AnchoredFilesystemTestOptions): Promise<Buffer>;
23
39
  /** Gate commands inherit a pinned cwd, never a mutable sandbox pathname. */
24
40
  export declare function anchoredExecuteNode(parent: string, name: string, expectedChild: AnchoredDirectoryIdentity, args: readonly string[], input?: Buffer | string, options?: AnchoredFilesystemTestOptions): Promise<Buffer>;
41
+ /**
42
+ * P226.02: run the P205 gate under the pinned cwd with an exact environment,
43
+ * a process-group timeout (SIGTERM, then SIGKILL after grace) and a bounded
44
+ * stderr tail for the strict failure parser. Timeout rejects with
45
+ * `secure-git-command-timeout`; a failed gate rejects with
46
+ * `secure-git-command-failed:<n>` carrying the tail via `anchoredGateStderrTail`.
47
+ */
48
+ export declare function anchoredExecuteGate(parent: string, name: string, expectedChild: AnchoredDirectoryIdentity, args: readonly string[], gate: AnchoredGateExecutionOptions): Promise<Buffer>;
25
49
  export declare function anchoredExecuteNpm(parent: string, name: string, expectedChild: AnchoredDirectoryIdentity, args: readonly string[]): Promise<Buffer>;
26
50
  export declare function anchoredCreateOwnedDirectory(parent: string, name: string, owner: Buffer | string): Promise<void>;
27
51
  export declare function anchoredRenameDirectory(parent: string, sourceName: string, destinationName: string, options?: AnchoredFilesystemTestOptions): Promise<void>;
@@ -1,17 +1,4 @@
1
- /**
2
- * Handle-anchored filesystem mutations for private lifecycle namespaces.
3
- *
4
- * Node does not expose openat(2). A short-lived helper is started with the
5
- * validated parent as its cwd, verifies the cwd device/inode before effects,
6
- * and performs every final mutation with relative basenames. Once the OS has
7
- * handed the cwd to the helper, renaming/replacing the public parent path can
8
- * no longer redirect the effect. Platforms without that POSIX guarantee fail
9
- * closed instead of using a pathname fallback.
10
- */
11
- import { spawn } from 'node:child_process';
12
- import { randomBytes } from 'node:crypto';
13
- import { lstat, stat } from 'node:fs/promises';
14
- const HELPER = String.raw `
1
+ import{spawn as G}from"node:child_process";import{randomBytes as F}from"node:crypto";import{lstat as _,stat as I}from"node:fs/promises";const X=String.raw`
15
2
  const fs = require('node:fs');
16
3
  const crypto = require('node:crypto');
17
4
  const [op, expectedDev, expectedIno, name, temporary, expectedSha] = process.argv.slice(1);
@@ -106,11 +93,10 @@ if (op === 'mkdir' || op === 'mkdir-exclusive') {
106
93
  if (safeExisting(name, 'directory')) fail('secure-filesystem-directory-remained');
107
94
  } else fail('secure-filesystem-operation-invalid');
108
95
  try { const parent = fs.openSync('.', fs.constants.O_RDONLY); fs.fsyncSync(parent); fs.closeSync(parent); } catch {}
109
- `;
110
- const GIT_HELPER = String.raw `
96
+ `,$=64*1024,M=Symbol.for("neocortex.p226.gateStderrTail"),T="secure-git-command-stderr:";function U(t){if(!(t instanceof Error))return;const e=t[M];return typeof e=="string"?e:void 0}const Y=String.raw`
111
97
  const fs = require('node:fs');
112
98
  const cp = require('node:child_process');
113
- const [expectedParentDev, expectedParentIno, name, expectedChildDev, expectedChildIno, encodedArgs, handshake, binary] = process.argv.slice(1);
99
+ const [expectedParentDev, expectedParentIno, name, expectedChildDev, expectedChildIno, encodedArgs, handshake, binary, captureStderr] = process.argv.slice(1);
114
100
  const fail = (code) => { process.stderr.write(code); process.exit(73); };
115
101
  process.on('uncaughtException', (error) => fail('secure-git-os:' + String(error && error.code || 'UNKNOWN')));
116
102
  const safeName = typeof name === 'string' && name.length > 0 && name.length <= 255
@@ -141,12 +127,17 @@ if (!Array.isArray(args) || args.length === 0 || args.length > 512
141
127
  process.umask(0o077);
142
128
  if (!['git', 'node', 'npm'].includes(binary)) fail('secure-git-command-invalid');
143
129
  const maxOutputBytes = binary === 'git' ? 16 * 1024 * 1024 : 64 * 1024 * 1024;
144
- const gitEnv = { ...process.env, GIT_OPTIONAL_LOCKS: '1' };
130
+ // P226.02 gate mode: the caller already projected and denylisted the exact
131
+ // environment; apply the same removals defensively but add nothing, so the
132
+ // anchored and plain gate paths see byte-identical environments.
133
+ const gateMode = captureStderr === '1';
134
+ const gitEnv = gateMode ? { ...process.env } : { ...process.env, GIT_OPTIONAL_LOCKS: '1' };
135
+ for (const key of Object.keys(gitEnv)) if (gateMode && key.toUpperCase().startsWith('GIT_')) delete gitEnv[key];
145
136
  for (const key of ['GIT_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE', 'GIT_OBJECT_DIRECTORY',
146
137
  'GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_COMMON_DIR', 'GIT_NAMESPACE', 'GIT_CEILING_DIRECTORIES']) delete gitEnv[key];
147
138
  if (binary !== 'git') {
148
139
  for (const key of ['NODE_OPTIONS', 'NODE_PATH', 'NEOCORTEX_RELEASE_GATE_MANIFEST', 'NEOCORTEX_PROFILE_DIR']) delete gitEnv[key];
149
- gitEnv.npm_config_global = 'false';
140
+ if (!gateMode) gitEnv.npm_config_global = 'false';
150
141
  }
151
142
  const result = cp.spawnSync(binary === 'node' ? process.execPath : binary, args, {
152
143
  input,
@@ -156,172 +147,15 @@ const result = cp.spawnSync(binary === 'node' ? process.execPath : binary, args,
156
147
  env: gitEnv,
157
148
  });
158
149
  if (result.error) fail('secure-git-command-error:' + String(result.error.code || 'UNKNOWN'));
159
- if (result.status !== 0) fail('secure-git-command-failed:' + String(Number.isInteger(result.status) ? result.status : 1));
150
+ if (result.status !== 0) {
151
+ if (captureStderr === '1' && result.stderr && result.stderr.length > 0) {
152
+ const tail = result.stderr.subarray(Math.max(0, result.stderr.length - 65536));
153
+ process.stderr.write('secure-git-command-stderr:' + tail.toString('base64url') + '\n');
154
+ }
155
+ fail('secure-git-command-failed:' + String(Number.isInteger(result.status) ? result.status : 1));
156
+ }
160
157
  if (result.stdout && result.stdout.length > maxOutputBytes) fail('secure-git-output-too-large');
161
158
  if (result.stdout) process.stdout.write(result.stdout);
162
- `;
163
- export function secureFilesystemBoundaryAvailable(platform = process.platform) {
164
- return platform !== 'win32';
165
- }
166
- export async function anchoredAtomicWriteFile(parent, name, content, options = {}) {
167
- const temporary = `.${name}.${process.pid}.${randomBytes(8).toString('hex')}.tmp`;
168
- await runAnchored(parent, ['write', name, temporary], Buffer.isBuffer(content) ? content : Buffer.from(content), options);
169
- }
170
- /** Replace a regular tracked file only while its exact preimage still matches. */
171
- export async function anchoredCompareAndSwapFile(parent, name, content, expectedSha256, options = {}) {
172
- const temporary = `.${name}.${process.pid}.${randomBytes(8).toString('hex')}.tmp`;
173
- await runAnchored(parent, ['write-cas', name, temporary, expectedSha256], Buffer.isBuffer(content) ? content : Buffer.from(content), options);
174
- }
175
- export async function anchoredRemoveFile(parent, name, options = {}) {
176
- await runAnchored(parent, ['remove', name], undefined, options);
177
- }
178
- export async function anchoredEnsureDirectory(parent, name, options = {}) {
179
- await runAnchored(parent, ['mkdir', name], undefined, options);
180
- }
181
- export async function anchoredCreateDirectory(parent, name) {
182
- const output = (await runAnchored(parent, ['mkdir-exclusive', name])).toString('utf8');
183
- const match = output.match(/^secure-filesystem-identity:([0-9]+):([0-9]+)$/);
184
- if (!match)
185
- throw new Error('secure-filesystem-created-identity-missing');
186
- return Object.freeze({ dev: match[1], ino: match[2] });
187
- }
188
- export async function anchoredDirectoryIdentity(path) {
189
- if (!secureFilesystemBoundaryAvailable())
190
- throw new Error('secure-filesystem-platform-unsupported');
191
- const entry = await lstat(path, { bigint: true });
192
- const identity = await stat(path, { bigint: true });
193
- if (entry.isSymbolicLink() || !entry.isDirectory() || !identity.isDirectory()
194
- || entry.dev !== identity.dev || entry.ino !== identity.ino) {
195
- throw new Error('secure-filesystem-directory-unsafe');
196
- }
197
- return Object.freeze({ dev: String(identity.dev), ino: String(identity.ino) });
198
- }
199
- /** Execute Git only after a helper owns and revalidates the sandbox directory cwd. */
200
- export async function anchoredExecuteGit(parent, name, expectedChild, args, input, options = {}) {
201
- return runAnchoredCommand('git', parent, name, expectedChild, args, input, options);
202
- }
203
- /** Gate commands inherit a pinned cwd, never a mutable sandbox pathname. */
204
- export async function anchoredExecuteNode(parent, name, expectedChild, args, input, options = {}) {
205
- return runAnchoredCommand('node', parent, name, expectedChild, args, input, options);
206
- }
207
- export async function anchoredExecuteNpm(parent, name, expectedChild, args) {
208
- return runAnchoredCommand('npm', parent, name, expectedChild, args);
209
- }
210
- async function runAnchoredCommand(binary, parent, name, expectedChild, args, input, options = {}) {
211
- if (!secureFilesystemBoundaryAvailable(options.platform ?? process.platform)) {
212
- throw new Error('secure-filesystem-platform-unsupported');
213
- }
214
- if (args.length === 0 || args.length > 512
215
- || args.some((arg) => typeof arg !== 'string' || arg.length > 4096 || arg.includes('\0'))) {
216
- throw new Error('secure-git-args-invalid');
217
- }
218
- const identity = await stat(parent, { bigint: true });
219
- const entry = await lstat(parent, { bigint: true });
220
- if (!identity.isDirectory() || entry.isSymbolicLink() || !entry.isDirectory()
221
- || identity.dev !== entry.dev || identity.ino !== entry.ino) {
222
- throw new Error('secure-filesystem-parent-invalid');
223
- }
224
- await options.beforeHandoff?.();
225
- const maxOutputBytes = binary === 'git' ? 16 * 1024 * 1024 : 64 * 1024 * 1024;
226
- return await new Promise((resolveProcess, rejectProcess) => {
227
- const handshake = options.afterHandoff ? '1' : '0';
228
- const encodedArgs = Buffer.from(JSON.stringify([...args])).toString('base64url');
229
- const child = spawn(process.execPath, [
230
- '-e', GIT_HELPER, String(identity.dev), String(identity.ino), name,
231
- expectedChild.dev, expectedChild.ino, encodedArgs, handshake, binary,
232
- ], { cwd: parent, stdio: ['pipe', 'pipe', 'pipe'] });
233
- const output = [];
234
- const errors = [];
235
- let outputBytes = 0;
236
- let handoffObserved = !options.afterHandoff;
237
- let hookStarted = false;
238
- const finishInput = async () => {
239
- if (hookStarted)
240
- return;
241
- hookStarted = true;
242
- try {
243
- await options.afterHandoff?.();
244
- handoffObserved = true;
245
- child.stdin.end(input === undefined ? undefined : Buffer.isBuffer(input) ? input : Buffer.from(input));
246
- }
247
- catch (error) {
248
- child.kill();
249
- rejectProcess(error);
250
- }
251
- };
252
- child.stdout.on('data', (chunk) => {
253
- outputBytes += chunk.length;
254
- if (outputBytes > maxOutputBytes)
255
- child.kill();
256
- else
257
- output.push(chunk);
258
- });
259
- child.stderr.on('data', (chunk) => {
260
- errors.push(chunk);
261
- if (!handoffObserved && Buffer.concat(errors).includes(Buffer.from('secure-git-handoff-ready\n')))
262
- void finishInput();
263
- });
264
- child.once('error', rejectProcess);
265
- child.once('close', (code) => {
266
- if (code === 0 && outputBytes <= maxOutputBytes)
267
- return resolveProcess(Buffer.concat(output));
268
- const raw = Buffer.concat(errors).toString('utf8');
269
- const reason = raw.split('\n').find((line) => line.startsWith('secure-git-') && line !== 'secure-git-handoff-ready')
270
- ?? (outputBytes > maxOutputBytes ? 'secure-git-output-too-large' : 'secure-git-helper-failed');
271
- rejectProcess(new Error(reason));
272
- });
273
- if (!options.afterHandoff)
274
- void finishInput();
275
- });
276
- }
277
- export async function anchoredCreateOwnedDirectory(parent, name, owner) {
278
- await runAnchored(parent, ['create-owned-directory', name], Buffer.isBuffer(owner) ? owner : Buffer.from(owner));
279
- }
280
- export async function anchoredRenameDirectory(parent, sourceName, destinationName, options = {}) {
281
- await runAnchored(parent, ['rename-directory', sourceName, destinationName], undefined, options);
282
- }
283
- export async function anchoredRemoveDirectory(parent, name, options = {}) {
284
- await runAnchored(parent, ['remove-directory', name], undefined, options);
285
- }
286
- async function runAnchored(parent, args, input, options = {}) {
287
- if (!secureFilesystemBoundaryAvailable(options.platform ?? process.platform))
288
- throw new Error('secure-filesystem-platform-unsupported');
289
- const identity = await stat(parent, { bigint: true });
290
- if (!identity.isDirectory())
291
- throw new Error('secure-filesystem-parent-invalid');
292
- const entry = await lstat(parent, { bigint: true });
293
- if (entry.isSymbolicLink())
294
- throw new Error('secure-filesystem-parent-symlink');
295
- await options.beforeHandoff?.();
296
- return await new Promise((resolveProcess, rejectProcess) => {
297
- const child = spawn(process.execPath, ['-e', HELPER, ...args.slice(0, 1), String(identity.dev), String(identity.ino), ...args.slice(1)], {
298
- cwd: parent,
299
- stdio: ['pipe', 'pipe', 'pipe'],
300
- });
301
- const output = [];
302
- let outputBytes = 0;
303
- const errors = [];
304
- child.stdout.on('data', (chunk) => {
305
- outputBytes += chunk.length;
306
- if (outputBytes > 1024)
307
- child.kill();
308
- else
309
- output.push(chunk);
310
- });
311
- child.stderr.on('data', (chunk) => errors.push(chunk));
312
- child.once('error', rejectProcess);
313
- child.once('close', (code) => {
314
- if (code === 0 && outputBytes <= 1024)
315
- return resolveProcess(Buffer.concat(output));
316
- const message = Buffer.concat(errors).toString('utf8') || 'secure-filesystem-helper-failed';
317
- const error = new Error(message);
318
- const osCode = message.match(/^secure-filesystem-os:(E[A-Z0-9]+)$/)?.[1];
319
- if (osCode)
320
- error.code = osCode;
321
- if (message === 'secure-filesystem-entry-exists')
322
- error.code = 'EEXIST';
323
- rejectProcess(error);
324
- });
325
- child.stdin.end(input);
326
- });
327
- }
159
+ `;function b(t=process.platform){return t!=="win32"}async function j(t,e,r,i={}){const s=`.${e}.${process.pid}.${F(8).toString("hex")}.tmp`;await m(t,["write",e,s],Buffer.isBuffer(r)?r:Buffer.from(r),i)}async function z(t,e,r,i,s={}){const a=`.${e}.${process.pid}.${F(8).toString("hex")}.tmp`;await m(t,["write-cas",e,a,i],Buffer.isBuffer(r)?r:Buffer.from(r),s)}async function Z(t,e,r={}){await m(t,["remove",e],void 0,r)}async function Q(t,e,r={}){await m(t,["mkdir",e],void 0,r)}async function V(t,e){const i=(await m(t,["mkdir-exclusive",e])).toString("utf8").match(/^secure-filesystem-identity:([0-9]+):([0-9]+)$/);if(!i)throw new Error("secure-filesystem-created-identity-missing");return Object.freeze({dev:i[1],ino:i[2]})}async function ee(t){if(!b())throw new Error("secure-filesystem-platform-unsupported");const e=await _(t,{bigint:!0}),r=await I(t,{bigint:!0});if(e.isSymbolicLink()||!e.isDirectory()||!r.isDirectory()||e.dev!==r.dev||e.ino!==r.ino)throw new Error("secure-filesystem-directory-unsafe");return Object.freeze({dev:String(r.dev),ino:String(r.ino)})}async function te(t,e,r,i,s,a={}){return w("git",t,e,r,i,s,a)}async function re(t,e,r,i,s,a={}){return w("node",t,e,r,i,s,a)}async function ie(t,e,r,i,s){if(!Number.isSafeInteger(s.timeoutMs)||s.timeoutMs<=0||!Number.isSafeInteger(s.graceMs)||s.graceMs<=0)throw new Error("secure-git-gate-budget-invalid");return w("node",t,e,r,i,void 0,{},s)}async function se(t,e,r,i){return w("npm",t,e,r,i)}async function w(t,e,r,i,s,a,l={},d){if(!b(l.platform??process.platform))throw new Error("secure-filesystem-platform-unsupported");if(s.length===0||s.length>512||s.some(u=>typeof u!="string"||u.length>4096||u.includes("\0")))throw new Error("secure-git-args-invalid");const c=await I(e,{bigint:!0}),y=await _(e,{bigint:!0});if(!c.isDirectory()||y.isSymbolicLink()||!y.isDirectory()||c.dev!==y.dev||c.ino!==y.ino)throw new Error("secure-filesystem-parent-invalid");await l.beforeHandoff?.();const p=t==="git"?16*1024*1024:64*1024*1024;return await new Promise((u,f)=>{const h=l.afterHandoff?"1":"0",S=Buffer.from(JSON.stringify([...s])).toString("base64url"),o=G(process.execPath,["-e",Y,String(c.dev),String(c.ino),r,i.dev,i.ino,S,h,t,d?"1":"0"],{cwd:e,stdio:["pipe","pipe","pipe"],...d?{env:{...d.env},detached:!0}:{}}),N=[],x=[];let E=0,R=!1;const v=[],O=n=>{try{o.pid!==void 0&&process.kill(-o.pid,n)}catch{o.kill(n)}};d&&v.push(setTimeout(()=>{R=!0,O("SIGTERM"),v.push(setTimeout(()=>O("SIGKILL"),d.graceMs))},d.timeoutMs));const D=()=>{for(const n of v)clearTimeout(n)};let k=!l.afterHandoff,B=!1;const L=async()=>{if(!B){B=!0;try{await l.afterHandoff?.(),k=!0,o.stdin.end(a===void 0?void 0:Buffer.isBuffer(a)?a:Buffer.from(a))}catch(n){o.kill(),f(n)}}};o.stdout.on("data",n=>{E+=n.length,E>p?o.kill():N.push(n)}),o.stderr.on("data",n=>{x.push(n),!k&&Buffer.concat(x).includes(Buffer.from(`secure-git-handoff-ready
160
+ `))&&L()}),o.once("error",n=>{D(),f(n)}),o.once("close",n=>{if(D(),R)return O("SIGKILL"),f(new Error("secure-git-command-timeout"));if(n===0&&E<=p)return u(Buffer.concat(N));const A=Buffer.concat(x).toString("utf8").split(`
161
+ `),P=A.find(g=>g.startsWith("secure-git-")&&g!=="secure-git-handoff-ready"&&!g.startsWith(T))??(E>p?"secure-git-output-too-large":"secure-git-helper-failed"),C=new Error(P);if(d){const g=A.find(H=>H.startsWith(T)),W=g===void 0?"":Buffer.from(g.slice(T.length),"base64url").subarray(-$).toString("utf8");Object.defineProperty(C,M,{value:W,enumerable:!1})}f(C)}),l.afterHandoff||L()})}async function ne(t,e,r){await m(t,["create-owned-directory",e],Buffer.isBuffer(r)?r:Buffer.from(r))}async function oe(t,e,r,i={}){await m(t,["rename-directory",e,r],void 0,i)}async function ce(t,e,r={}){await m(t,["remove-directory",e],void 0,r)}async function m(t,e,r,i={}){if(!b(i.platform??process.platform))throw new Error("secure-filesystem-platform-unsupported");const s=await I(t,{bigint:!0});if(!s.isDirectory())throw new Error("secure-filesystem-parent-invalid");if((await _(t,{bigint:!0})).isSymbolicLink())throw new Error("secure-filesystem-parent-symlink");return await i.beforeHandoff?.(),await new Promise((l,d)=>{const c=G(process.execPath,["-e",X,...e.slice(0,1),String(s.dev),String(s.ino),...e.slice(1)],{cwd:t,stdio:["pipe","pipe","pipe"]}),y=[];let p=0;const u=[];c.stdout.on("data",f=>{p+=f.length,p>1024?c.kill():y.push(f)}),c.stderr.on("data",f=>u.push(f)),c.once("error",d),c.once("close",f=>{if(f===0&&p<=1024)return l(Buffer.concat(y));const h=Buffer.concat(u).toString("utf8")||"secure-filesystem-helper-failed",S=new Error(h),o=h.match(/^secure-filesystem-os:(E[A-Z0-9]+)$/)?.[1];o&&(S.code=o),h==="secure-filesystem-entry-exists"&&(S.code="EEXIST"),d(S)}),c.stdin.end(r)})}export{$ as ANCHORED_GATE_STDERR_TAIL_BYTES,j as anchoredAtomicWriteFile,z as anchoredCompareAndSwapFile,V as anchoredCreateDirectory,ne as anchoredCreateOwnedDirectory,ee as anchoredDirectoryIdentity,Q as anchoredEnsureDirectory,ie as anchoredExecuteGate,te as anchoredExecuteGit,re as anchoredExecuteNode,se as anchoredExecuteNpm,U as anchoredGateStderrTail,ce as anchoredRemoveDirectory,Z as anchoredRemoveFile,oe as anchoredRenameDirectory,b as secureFilesystemBoundaryAvailable};