@ornexus/neocortex 4.61.4 → 4.61.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (254) hide show
  1. package/dist/release-source.json +1 -1
  2. package/dist/sbom.cdx.json +1193 -1193
  3. package/install.ps1 +1 -1
  4. package/install.sh +1 -1
  5. package/package.json +2 -2
  6. package/packages/client/dist/adapters/adapter-registry.js +1 -108
  7. package/packages/client/dist/adapters/antigravity-adapter.js +2 -77
  8. package/packages/client/dist/adapters/claude-code-adapter.js +3 -79
  9. package/packages/client/dist/adapters/codex-adapter.js +2 -80
  10. package/packages/client/dist/adapters/cursor-adapter.js +4 -115
  11. package/packages/client/dist/adapters/gemini-adapter.js +2 -71
  12. package/packages/client/dist/adapters/grok-adapter.js +2 -42
  13. package/packages/client/dist/adapters/index.js +1 -22
  14. package/packages/client/dist/adapters/platform-detector.js +1 -220
  15. package/packages/client/dist/adapters/target-adapter.js +0 -12
  16. package/packages/client/dist/adapters/vscode-adapter.js +2 -72
  17. package/packages/client/dist/agent/refresh-stubs.js +2 -443
  18. package/packages/client/dist/agent/update-agent-yaml.js +1 -102
  19. package/packages/client/dist/agent/update-description.js +1 -260
  20. package/packages/client/dist/cache/crypto-utils.js +1 -78
  21. package/packages/client/dist/cache/encrypted-cache.js +1 -338
  22. package/packages/client/dist/cache/in-memory-asset-cache.js +1 -73
  23. package/packages/client/dist/cache/index.js +1 -13
  24. package/packages/client/dist/cache/protected-pi-boundary.js +1 -44
  25. package/packages/client/dist/checkpoint/checkpoint-client-reader.js +2 -127
  26. package/packages/client/dist/checkpoint/index.js +1 -11
  27. package/packages/client/dist/checkpoint/shared-checkpoint-types.js +1 -32
  28. package/packages/client/dist/cli.js +5 -364
  29. package/packages/client/dist/commands/activate.js +8 -394
  30. package/packages/client/dist/commands/architecture-answers.js +7 -274
  31. package/packages/client/dist/commands/architecture-memory-terminal.js +4 -253
  32. package/packages/client/dist/commands/architecture-non-ui-continuation.js +1 -100
  33. package/packages/client/dist/commands/architecture-root-binding.js +1 -51
  34. package/packages/client/dist/commands/cache-status.js +2 -112
  35. package/packages/client/dist/commands/config.js +1 -88
  36. package/packages/client/dist/commands/doctor.js +2 -635
  37. package/packages/client/dist/commands/invoke.js +148 -7822
  38. package/packages/client/dist/commands/legacy-epic-terminal.js +1 -71
  39. package/packages/client/dist/commands/legacy-story-branch.js +1 -96
  40. package/packages/client/dist/commands/legacy-story-pr.js +1 -276
  41. package/packages/client/dist/commands/mutation-qa-checkpoint.js +5 -285
  42. package/packages/client/dist/commands/mutation-qa-gate.js +1 -54
  43. package/packages/client/dist/commands/mutation-qa-git.js +1 -41
  44. package/packages/client/dist/commands/mutation-qa-policy.js +1 -102
  45. package/packages/client/dist/commands/mutation-qa-run.js +3 -219
  46. package/packages/client/dist/commands/mutation-qa-verdict.js +1 -149
  47. package/packages/client/dist/commands/mutation-qa.js +1 -220
  48. package/packages/client/dist/commands/native-agent.js +2 -136
  49. package/packages/client/dist/commands/planning-diagnosis.js +1 -43
  50. package/packages/client/dist/commands/planning-generation.js +1 -53
  51. package/packages/client/dist/commands/planning-memory.js +1 -40
  52. package/packages/client/dist/commands/planning-research.js +1 -42
  53. package/packages/client/dist/commands/private-session.js +1 -75
  54. package/packages/client/dist/commands/property-qa.js +1 -139
  55. package/packages/client/dist/commands/qa-control.js +1 -16
  56. package/packages/client/dist/commands/qa-scan-browser-launch.js +1 -55
  57. package/packages/client/dist/commands/qa-scan-browser-route.js +1 -28
  58. package/packages/client/dist/commands/qa-scan-capture.js +5 -663
  59. package/packages/client/dist/commands/qa-scan-discovery.js +3 -376
  60. package/packages/client/dist/commands/qa-scan-review.js +5 -826
  61. package/packages/client/dist/commands/qa-synthetic-backend-capture.js +1 -266
  62. package/packages/client/dist/commands/qa-synthetic-backend-review.js +1 -297
  63. package/packages/client/dist/commands/qa-synthetic-backend.js +2 -340
  64. package/packages/client/dist/commands/qa-synthetic-broker-port.js +1 -85
  65. package/packages/client/dist/commands/qa-synthetic-browser.js +1 -39
  66. package/packages/client/dist/commands/refactor-characterization.js +21 -671
  67. package/packages/client/dist/commands/refactor-commit.js +13 -399
  68. package/packages/client/dist/commands/refactor-control.js +3 -142
  69. package/packages/client/dist/commands/refactor-cpp-assertions.js +3 -93
  70. package/packages/client/dist/commands/refactor-review.js +5 -283
  71. package/packages/client/dist/commands/refactor-root.js +7 -588
  72. package/packages/client/dist/commands/refresh-memory.js +3 -174
  73. package/packages/client/dist/commands/shared-architecture-non-ui.js +1 -24
  74. package/packages/client/dist/commands/story-checkpoint.d.ts +5 -1
  75. package/packages/client/dist/commands/story-checkpoint.js +1 -203
  76. package/packages/client/dist/commands/story-worktree.js +5 -258
  77. package/packages/client/dist/config/host-auth-broker.js +1 -60
  78. package/packages/client/dist/config/host-auth-reference.js +1 -93
  79. package/packages/client/dist/config/profile-directory.js +1 -13
  80. package/packages/client/dist/config/resolver-selection.js +1 -278
  81. package/packages/client/dist/config/secure-config.js +12 -281
  82. package/packages/client/dist/config.js +2 -224
  83. package/packages/client/dist/constants.js +1 -25
  84. package/packages/client/dist/context/context-collector.js +2 -222
  85. package/packages/client/dist/context/context-sanitizer.js +1 -145
  86. package/packages/client/dist/continuity/autonomous-governance.js +1 -285
  87. package/packages/client/dist/continuity/continuity-client-state-store.js +1 -1587
  88. package/packages/client/dist/continuity/invoke-hooks.js +1 -129
  89. package/packages/client/dist/continuity/migrations/001-initial-schema.js +2 -12
  90. package/packages/client/dist/continuity/migrations/002-processing-output-summary-indexes.js +2 -12
  91. package/packages/client/dist/continuity/migrations/003-headless-execution-attempts.js +2 -12
  92. package/packages/client/dist/continuity/migrations/004-outbox-delivery-state.js +2 -12
  93. package/packages/client/dist/continuity/migrations/005-bounded-headless-queue.js +2 -12
  94. package/packages/client/dist/continuity/migrations/006-native-agent-dispatches.js +2 -10
  95. package/packages/client/dist/continuity/native-agent-store.js +1 -69
  96. package/packages/client/dist/continuity/native-agent-types.js +1 -105
  97. package/packages/client/dist/continuity/outbox.js +1 -117
  98. package/packages/client/dist/continuity/runner-bootstrap-policy.js +1 -172
  99. package/packages/client/dist/continuity/sqlite-store.js +81 -2612
  100. package/packages/client/dist/effects/invoke-effect-gateways.js +1 -62
  101. package/packages/client/dist/errors/error-messages.js +2 -258
  102. package/packages/client/dist/errors/frontmatter-diagnostics.js +1 -125
  103. package/packages/client/dist/evidence/collector.js +1 -347
  104. package/packages/client/dist/evidence/index.js +1 -1
  105. package/packages/client/dist/evidence/types.js +0 -2
  106. package/packages/client/dist/fs/atomic-state-replace.js +1 -152
  107. package/packages/client/dist/generated/command-registry.generated.js +1 -4076
  108. package/packages/client/dist/generated/public-projections.generated.js +1 -149
  109. package/packages/client/dist/git/direct-yolo-c01-retry.js +4 -138
  110. package/packages/client/dist/git/direct-yolo-checkpoint.d.ts +70 -0
  111. package/packages/client/dist/git/direct-yolo-checkpoint.js +4 -1592
  112. package/packages/client/dist/git/epic-operational-state.js +2 -672
  113. package/packages/client/dist/git/git-lifecycle-step-ids.js +1 -14
  114. package/packages/client/dist/git/git-lifecycle-store.d.ts +22 -0
  115. package/packages/client/dist/git/git-lifecycle-store.js +8 -2500
  116. package/packages/client/dist/git/legacy-story-branch-checkpoint.js +9 -259
  117. package/packages/client/dist/git/legacy-story-branch-setup.js +4 -348
  118. package/packages/client/dist/git/legacy-story-pr.js +70 -3538
  119. package/packages/client/dist/git/neocortex-trailers.js +2 -53
  120. package/packages/client/dist/git/secure-filesystem-boundary.js +5 -182
  121. package/packages/client/dist/git/story-worktree-cleanup.js +4 -1058
  122. package/packages/client/dist/git/story-worktree-integration.d.ts +62 -0
  123. package/packages/client/dist/git/story-worktree-integration.js +3 -603
  124. package/packages/client/dist/git/story-worktree-manager.js +3 -843
  125. package/packages/client/dist/git/story-worktree-paths.js +1 -150
  126. package/packages/client/dist/git/story-write-set-extension.d.ts +44 -0
  127. package/packages/client/dist/git/story-write-set-extension.js +1 -0
  128. package/packages/client/dist/graph-retrieval/pre-command-hook.js +1 -284
  129. package/packages/client/dist/graph-retrieval/shared-graph-retrieval-contract.js +1 -237
  130. package/packages/client/dist/i18n/first-run.js +2 -60
  131. package/packages/client/dist/index.js +1 -50
  132. package/packages/client/dist/invocation/invoke-input.js +1 -24
  133. package/packages/client/dist/license/host-auth-recovery.js +1 -401
  134. package/packages/client/dist/license/index.js +1 -5
  135. package/packages/client/dist/license/license-client.js +1 -337
  136. package/packages/client/dist/machine/fingerprint.js +2 -163
  137. package/packages/client/dist/machine/index.js +1 -5
  138. package/packages/client/dist/memory/project-memory-path-scope.js +1 -62
  139. package/packages/client/dist/memory/project-memory-writer.js +41 -1117
  140. package/packages/client/dist/memory/shared-project-memory-types.js +2 -259
  141. package/packages/client/dist/migrations/epic-lifecycle-backfill.js +3 -1060
  142. package/packages/client/dist/migrations/project-identity-capability.js +1 -50
  143. package/packages/client/dist/migrations/project-identity.js +7 -493
  144. package/packages/client/dist/migrations/state-json.js +4 -393
  145. package/packages/client/dist/policy/architecture-policy.js +2 -184
  146. package/packages/client/dist/policy/index.js +1 -7
  147. package/packages/client/dist/policy/shared-policy-types.js +0 -38
  148. package/packages/client/dist/policy/subagent-approval-policy.js +1 -57
  149. package/packages/client/dist/private-execution/clean-baseline.js +2 -279
  150. package/packages/client/dist/private-execution/codex-executor.js +4 -574
  151. package/packages/client/dist/private-execution/codex-host-runtime.js +1 -137
  152. package/packages/client/dist/private-execution/codex-lifecycle-guard.js +1 -97
  153. package/packages/client/dist/private-execution/codex-scoped-permissions.js +1 -128
  154. package/packages/client/dist/private-execution/delivery.js +13 -410
  155. package/packages/client/dist/private-execution/diagnosis-root-review.js +2 -294
  156. package/packages/client/dist/private-execution/frozen-handoff.js +6 -19
  157. package/packages/client/dist/private-execution/implementation-validation.js +2 -106
  158. package/packages/client/dist/private-execution/isolated-admission.js +23 -1432
  159. package/packages/client/dist/private-execution/isolated-session.js +5 -725
  160. package/packages/client/dist/private-execution/isolated-workspace.js +1 -122
  161. package/packages/client/dist/private-execution/pact-consumer-runtime.js +3 -409
  162. package/packages/client/dist/private-execution/pact-test-source.js +1 -258
  163. package/packages/client/dist/private-execution/pact-toolchain.js +3 -290
  164. package/packages/client/dist/private-execution/pact-write-set.js +1 -172
  165. package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +5 -406
  166. package/packages/client/dist/private-execution/planning-generation-checkpoint.js +5 -462
  167. package/packages/client/dist/private-execution/planning-memory-checkpoint.js +3 -139
  168. package/packages/client/dist/private-execution/planning-research-checkpoint.js +4 -325
  169. package/packages/client/dist/private-execution/private-report-store.js +1 -42
  170. package/packages/client/dist/private-execution/property-test-candidate.js +1 -103
  171. package/packages/client/dist/private-execution/property-test-choices.js +3 -147
  172. package/packages/client/dist/private-execution/property-test-plan.js +7 -271
  173. package/packages/client/dist/private-execution/property-test-review.js +4 -258
  174. package/packages/client/dist/private-execution/property-test-runtime.js +9 -372
  175. package/packages/client/dist/private-execution/property-test-source.js +1 -139
  176. package/packages/client/dist/private-execution/root-checkpoint.js +1 -80
  177. package/packages/client/dist/private-execution/root-memory-git-evidence.js +3 -135
  178. package/packages/client/dist/private-execution/root-memory-recovery.js +1 -93
  179. package/packages/client/dist/private-execution/root-memory-request.js +1 -29
  180. package/packages/client/dist/private-execution/root-memory-scope.js +1 -178
  181. package/packages/client/dist/private-execution/root-memory-writer.js +1 -102
  182. package/packages/client/dist/private-execution/session-lease.js +1 -63
  183. package/packages/client/dist/private-execution/shared-private-admission-types.js +1 -50
  184. package/packages/client/dist/private-execution/shared-project-validation.js +1 -66
  185. package/packages/client/dist/private-execution/shared-root-memory-types.js +1 -61
  186. package/packages/client/dist/private-execution/ux-source-validation.js +1 -372
  187. package/packages/client/dist/private-execution/ux-write-set.js +2 -191
  188. package/packages/client/dist/registry/registry-reconciliation.js +1 -234
  189. package/packages/client/dist/resilience/circuit-breaker.js +1 -170
  190. package/packages/client/dist/resilience/degradation-manager.js +1 -164
  191. package/packages/client/dist/resilience/freshness-indicator.js +1 -100
  192. package/packages/client/dist/resilience/index.js +1 -8
  193. package/packages/client/dist/resilience/recovery-detector.js +1 -74
  194. package/packages/client/dist/resolvers/asset-resolver.js +0 -13
  195. package/packages/client/dist/resolvers/local-resolver.js +8 -255
  196. package/packages/client/dist/resolvers/remote-resolver.js +1 -233
  197. package/packages/client/dist/runner/binary.js +1 -404
  198. package/packages/client/dist/runner/cli.js +17 -1571
  199. package/packages/client/dist/runner/epic-background-dispatcher.js +1 -124
  200. package/packages/client/dist/runner/headless/adapters.js +1 -49
  201. package/packages/client/dist/runner/headless/background-root.js +1 -85
  202. package/packages/client/dist/runner/headless/claude-code-adapter.js +1 -79
  203. package/packages/client/dist/runner/headless/continuous-story-workspace.js +11 -1776
  204. package/packages/client/dist/runner/headless/epic-git-reconciliation-inventory.js +1 -69
  205. package/packages/client/dist/runner/headless/epic-merge-candidate-qa.js +2 -111
  206. package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +10 -1464
  207. package/packages/client/dist/runner/headless/epic-terminal-git-runner.js +2 -357
  208. package/packages/client/dist/runner/headless/fake-adapter.js +1 -62
  209. package/packages/client/dist/runner/headless/managed-environment-cleanup.js +1 -274
  210. package/packages/client/dist/runner/headless/managed-profile.js +1 -149
  211. package/packages/client/dist/runner/headless/opencode-adapter.js +2 -145
  212. package/packages/client/dist/runner/headless/prepared-story-bundle.js +1 -43
  213. package/packages/client/dist/runner/headless/resolver.js +1 -231
  214. package/packages/client/dist/runner/headless/run-yolo.js +1 -886
  215. package/packages/client/dist/runner/headless/run-yoloop.js +2 -2657
  216. package/packages/client/dist/runner/headless/types.js +2 -575
  217. package/packages/client/dist/runner/host-capacity.js +1 -59
  218. package/packages/client/dist/runner/local-console.js +13 -396
  219. package/packages/client/dist/runner/portal-sync-worker.js +1 -1487
  220. package/packages/client/dist/runner/project-identity.js +1 -106
  221. package/packages/client/dist/runner/scheduler.js +7 -995
  222. package/packages/client/dist/runner-cli.js +2 -18
  223. package/packages/client/dist/state/invocation-shape.js +1 -13
  224. package/packages/client/dist/state/project-state-snapshot.js +1 -1754
  225. package/packages/client/dist/state/state-json-repair.js +3 -785
  226. package/packages/client/dist/state/structural-dag-projection.js +1 -118
  227. package/packages/client/dist/telemetry/index.js +1 -5
  228. package/packages/client/dist/telemetry/offline-queue.js +1 -131
  229. package/packages/client/dist/tier/index.js +1 -5
  230. package/packages/client/dist/tier/tier-aware-client.js +1 -405
  231. package/packages/client/dist/types/index.js +1 -38
  232. package/packages/client/dist/version.js +1 -27
  233. package/packages/client/dist/yolo/change-evidence-collector.d.ts +10 -0
  234. package/packages/client/dist/yolo/change-evidence-collector.js +1 -245
  235. package/packages/client/dist/yolo/invoke-envelope-capability.js +1 -65
  236. package/packages/client/dist/yolo/spec-envelope-collector.js +5 -184
  237. package/packages/client/dist/yoloop/discovery-hook.js +2 -300
  238. package/packages/client/dist/yoloop/index.js +1 -8
  239. package/packages/client/dist/yoloop/invoke-hooks.js +12 -669
  240. package/packages/client/dist/yoloop/shared-discover-epics.js +1 -1007
  241. package/packages/client/dist/yoloop/shared-yoloop-types.js +1 -33
  242. package/packages/client/dist/yoloop/target-normalization.js +1 -180
  243. package/packages/client/dist/yoloop/yoloop-client-state-store.js +1 -1920
  244. package/targets-stubs/antigravity/gemini.md +1 -1
  245. package/targets-stubs/antigravity/skill/SKILL.md +1 -1
  246. package/targets-stubs/claude-code/neocortex-root.agent.yaml +1 -1
  247. package/targets-stubs/claude-code/neocortex-root.md +2 -2
  248. package/targets-stubs/claude-code/neocortex.agent.yaml +1 -1
  249. package/targets-stubs/claude-code/neocortex.md +2 -2
  250. package/targets-stubs/codex/AGENTS.md +1 -1
  251. package/targets-stubs/cursor/agent.md +2 -2
  252. package/targets-stubs/gemini-cli/agent.md +2 -2
  253. package/targets-stubs/opencode/neocortex-root.md +1 -1
  254. package/targets-stubs/vscode/neocortex.agent.md +2 -2
@@ -1,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};
@@ -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 b}from"node:child_process";import{randomBytes as B}from"node:crypto";import{lstat as w,stat as x}from"node:fs/promises";const T=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,8 +93,7 @@ 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
+ `,k=String.raw`
111
97
  const fs = require('node:fs');
112
98
  const cp = require('node:child_process');
113
99
  const [expectedParentDev, expectedParentIno, name, expectedChildDev, expectedChildIno, encodedArgs, handshake, binary] = process.argv.slice(1);
@@ -159,169 +145,6 @@ if (result.error) fail('secure-git-command-error:' + String(result.error.code ||
159
145
  if (result.status !== 0) fail('secure-git-command-failed:' + String(Number.isInteger(result.status) ? result.status : 1));
160
146
  if (result.stdout && result.stdout.length > maxOutputBytes) fail('secure-git-output-too-large');
161
147
  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
- }
148
+ `;function v(r=process.platform){return r!=="win32"}async function G(r,t,e,i={}){const s=`.${t}.${process.pid}.${B(8).toString("hex")}.tmp`;await y(r,["write",t,s],Buffer.isBuffer(e)?e:Buffer.from(e),i)}async function P(r,t,e,i,s={}){const n=`.${t}.${process.pid}.${B(8).toString("hex")}.tmp`;await y(r,["write-cas",t,n,i],Buffer.isBuffer(e)?e:Buffer.from(e),s)}async function H(r,t,e={}){await y(r,["remove",t],void 0,e)}async function W(r,t,e={}){await y(r,["mkdir",t],void 0,e)}async function $(r,t){const i=(await y(r,["mkdir-exclusive",t])).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 X(r){if(!v())throw new Error("secure-filesystem-platform-unsupported");const t=await w(r,{bigint:!0}),e=await x(r,{bigint:!0});if(t.isSymbolicLink()||!t.isDirectory()||!e.isDirectory()||t.dev!==e.dev||t.ino!==e.ino)throw new Error("secure-filesystem-directory-unsafe");return Object.freeze({dev:String(e.dev),ino:String(e.ino)})}async function Y(r,t,e,i,s,n={}){return O("git",r,t,e,i,s,n)}async function M(r,t,e,i,s,n={}){return O("node",r,t,e,i,s,n)}async function K(r,t,e,i){return O("npm",r,t,e,i)}async function O(r,t,e,i,s,n,f={}){if(!v(f.platform??process.platform))throw new Error("secure-filesystem-platform-unsupported");if(s.length===0||s.length>512||s.some(a=>typeof a!="string"||a.length>4096||a.includes("\0")))throw new Error("secure-git-args-invalid");const d=await x(t,{bigint:!0}),o=await w(t,{bigint:!0});if(!d.isDirectory()||o.isSymbolicLink()||!o.isDirectory()||d.dev!==o.dev||d.ino!==o.ino)throw new Error("secure-filesystem-parent-invalid");await f.beforeHandoff?.();const m=r==="git"?16*1024*1024:64*1024*1024;return await new Promise((a,p)=>{const l=f.afterHandoff?"1":"0",g=Buffer.from(JSON.stringify([...s])).toString("base64url"),c=b(process.execPath,["-e",k,String(d.dev),String(d.ino),e,i.dev,i.ino,g,l,r],{cwd:t,stdio:["pipe","pipe","pipe"]}),h=[],E=[];let S=0,_=!f.afterHandoff,I=!1;const N=async()=>{if(!I){I=!0;try{await f.afterHandoff?.(),_=!0,c.stdin.end(n===void 0?void 0:Buffer.isBuffer(n)?n:Buffer.from(n))}catch(u){c.kill(),p(u)}}};c.stdout.on("data",u=>{S+=u.length,S>m?c.kill():h.push(u)}),c.stderr.on("data",u=>{E.push(u),!_&&Buffer.concat(E).includes(Buffer.from(`secure-git-handoff-ready
149
+ `))&&N()}),c.once("error",p),c.once("close",u=>{if(u===0&&S<=m)return a(Buffer.concat(h));const R=Buffer.concat(E).toString("utf8").split(`
150
+ `).find(D=>D.startsWith("secure-git-")&&D!=="secure-git-handoff-ready")??(S>m?"secure-git-output-too-large":"secure-git-helper-failed");p(new Error(R))}),f.afterHandoff||N()})}async function q(r,t,e){await y(r,["create-owned-directory",t],Buffer.isBuffer(e)?e:Buffer.from(e))}async function J(r,t,e,i={}){await y(r,["rename-directory",t,e],void 0,i)}async function U(r,t,e={}){await y(r,["remove-directory",t],void 0,e)}async function y(r,t,e,i={}){if(!v(i.platform??process.platform))throw new Error("secure-filesystem-platform-unsupported");const s=await x(r,{bigint:!0});if(!s.isDirectory())throw new Error("secure-filesystem-parent-invalid");if((await w(r,{bigint:!0})).isSymbolicLink())throw new Error("secure-filesystem-parent-symlink");return await i.beforeHandoff?.(),await new Promise((f,d)=>{const o=b(process.execPath,["-e",T,...t.slice(0,1),String(s.dev),String(s.ino),...t.slice(1)],{cwd:r,stdio:["pipe","pipe","pipe"]}),m=[];let a=0;const p=[];o.stdout.on("data",l=>{a+=l.length,a>1024?o.kill():m.push(l)}),o.stderr.on("data",l=>p.push(l)),o.once("error",d),o.once("close",l=>{if(l===0&&a<=1024)return f(Buffer.concat(m));const g=Buffer.concat(p).toString("utf8")||"secure-filesystem-helper-failed",c=new Error(g),h=g.match(/^secure-filesystem-os:(E[A-Z0-9]+)$/)?.[1];h&&(c.code=h),g==="secure-filesystem-entry-exists"&&(c.code="EEXIST"),d(c)}),o.stdin.end(e)})}export{G as anchoredAtomicWriteFile,P as anchoredCompareAndSwapFile,$ as anchoredCreateDirectory,q as anchoredCreateOwnedDirectory,X as anchoredDirectoryIdentity,W as anchoredEnsureDirectory,Y as anchoredExecuteGit,M as anchoredExecuteNode,K as anchoredExecuteNpm,U as anchoredRemoveDirectory,H as anchoredRemoveFile,J as anchoredRenameDirectory,v as secureFilesystemBoundaryAvailable};