@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,21 +1,26 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { posix } from 'node:path';
3
3
  import { inspectFrontmatterContext } from '../frontmatter-context-contract.js';
4
+ import { findYoloSpecProhibitedContent, yoloSpecEnvelopeUnsafeReasonCode } from './spec-envelope-rules.js';
5
+ export { findYoloSpecProhibitedContent, isStrictYoloSpecPlaceholder, isYoloSpecEnvelopeUnsafeReasonCode, YOLO_SPEC_ENVELOPE_RULE_IDS, yoloSpecEnvelopeUnsafeReasonCode, } from './spec-envelope-rules.js';
4
6
  // Artifact bytes are intentionally not capped here. The invoke transport owns
5
7
  // the request-level byte guardrail; this contract owns count, shape, content,
6
8
  // target, freshness and digest integrity without a smaller duplicate ceiling.
7
9
  export const YOLO_SPEC_MAX_ARTIFACTS = 12;
8
10
  export const YOLO_SPEC_MAX_AGE_MS = 120_000;
9
11
  export const YOLO_SPEC_FUTURE_SKEW_MS = 30_000;
12
+ /** P226.07: cited foreign stories/epics are public IDs only, never content. */
13
+ export const YOLO_SPEC_MAX_REFERENCED_STORIES = 32;
10
14
  /** Public server capability for both mandatory top-level YOLO invoke fields. */
11
15
  export const YOLO_INVOKE_ENVELOPE_CAPABILITY = 'yolo-invoke-envelope-v1';
12
16
  const HASH = /^[a-f0-9]{64}$/;
13
17
  const HEAD = /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/;
14
18
  const STORY_ID = /^[A-Za-z0-9]+(?:\.[A-Za-z0-9]+)+$/;
15
19
  const EPIC_ID = /^[A-Za-z0-9]+$/;
20
+ const REFERENCED_ID = /^[A-Za-z0-9]+(?:\.[A-Za-z0-9]+)*$/;
21
+ const ENVELOPE_KEYS = ['schemaVersion', 'storyId', 'epicId', 'targetPath', 'inputSha256', 'sourceRevision', 'collectedAt', 'artifacts', 'envelopeSha256'];
16
22
  const KINDS = ['story', 'epic', 'spec', 'contract', 'adr', 'nfr', 'example', 'bdd', 'traceability', 'template'];
17
23
  const ALLOWED_PATH = /^(?:docs\/(?:stories|epics|specs|architecture|examples)\/|core\/templates\/specs\/)[A-Za-z0-9_./-]+$/;
18
- const PROHIBITED_CONTENT = /(?:-----BEGIN [A-Z ]*PRIVATE KEY-----|\b(?:bearer|token|password|secret|api[_-]?key)\s*[:=]\s*\S+|\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b|\b(?:sk-|ghp_|github_pat_|npm_)[A-Za-z0-9_-]{12,}\b|(?:^|[\s"'(])\/(?:home|media|root|etc|var|Users)\/)/im;
19
24
  function deny(code) {
20
25
  throw new Error(code);
21
26
  }
@@ -37,12 +42,18 @@ function validPath(value) {
37
42
  && !value.includes('\\') && !value.split('/').includes('..')
38
43
  && posix.normalize(value) === value;
39
44
  }
40
- function normalizeContent(content) {
45
+ /**
46
+ * P226.06: named rules replace the former single regex. `path` is already
47
+ * allow-listed by `validPath`; the reason code carries rule/path/line only and
48
+ * never the matched text.
49
+ */
50
+ function normalizeContent(content, path) {
41
51
  if (content.includes('\0') || /\r(?!\n)/.test(content))
42
52
  deny('yolo-spec-envelope-unsafe');
43
53
  const normalized = content.replaceAll('\r\n', '\n');
44
- if (PROHIBITED_CONTENT.test(normalized))
45
- deny('yolo-spec-envelope-unsafe');
54
+ const finding = findYoloSpecProhibitedContent(normalized);
55
+ if (finding)
56
+ deny(yoloSpecEnvelopeUnsafeReasonCode(finding.ruleId, path, finding.line));
46
57
  return normalized;
47
58
  }
48
59
  function artifactManifestSha256(artifacts) {
@@ -51,6 +62,14 @@ function artifactManifestSha256(artifacts) {
51
62
  function unsignedEnvelopeSha256(value) {
52
63
  return sha256(JSON.stringify(value));
53
64
  }
65
+ function checkReferencedStories(value, storyId, epicId) {
66
+ if (!Array.isArray(value) || value.length < 1 || value.length > YOLO_SPEC_MAX_REFERENCED_STORIES
67
+ || value.some((id, index) => typeof id !== 'string' || id.length > 80 || !REFERENCED_ID.test(id)
68
+ || (index > 0 && !(String(value[index - 1]) < id))))
69
+ deny('yolo-spec-envelope-unsafe');
70
+ if (value.includes(storyId) || value.includes(epicId))
71
+ deny('yolo-spec-envelope-target-mismatch');
72
+ }
54
73
  function checkArtifact(value) {
55
74
  if (!isRecord(value) || !hasExactKeys(value, ['kind', 'path', 'content', 'byteLength', 'sha256'])
56
75
  || !KINDS.includes(String(value.kind)) || !validPath(value.path))
@@ -58,7 +77,7 @@ function checkArtifact(value) {
58
77
  if (typeof value.content !== 'string' || !Number.isSafeInteger(value.byteLength) || !HASH.test(String(value.sha256))) {
59
78
  deny('yolo-spec-envelope-unsafe');
60
79
  }
61
- const content = normalizeContent(value.content);
80
+ const content = normalizeContent(value.content, value.path);
62
81
  const bytes = Buffer.byteLength(content, 'utf8');
63
82
  if (content !== value.content || bytes !== value.byteLength || sha256(content) !== value.sha256) {
64
83
  deny('yolo-spec-envelope-digest-mismatch');
@@ -71,7 +90,7 @@ export function createYoloSpecEnvelopeV1(input) {
71
90
  if (!isRecord(artifact) || !KINDS.includes(String(artifact.kind)) || !validPath(artifact.path)
72
91
  || typeof artifact.content !== 'string')
73
92
  deny('yolo-spec-envelope-path-out-of-scope');
74
- const content = normalizeContent(artifact.content);
93
+ const content = normalizeContent(artifact.content, artifact.path);
75
94
  return {
76
95
  kind: artifact.kind,
77
96
  path: artifact.path,
@@ -89,6 +108,9 @@ export function createYoloSpecEnvelopeV1(input) {
89
108
  sourceRevision: { headSha: input.headSha, manifestSha256: artifactManifestSha256(artifacts) },
90
109
  collectedAt: input.collectedAt,
91
110
  artifacts,
111
+ ...(input.referencedStories && input.referencedStories.length > 0
112
+ ? { referencedStories: [...new Set(input.referencedStories)].sort() }
113
+ : {}),
92
114
  };
93
115
  const envelope = { ...unsigned, envelopeSha256: unsignedEnvelopeSha256(unsigned) };
94
116
  assertYoloSpecEnvelopeV1(envelope, {
@@ -98,7 +120,8 @@ export function createYoloSpecEnvelopeV1(input) {
98
120
  return envelope;
99
121
  }
100
122
  export function assertYoloSpecEnvelopeV1(value, context) {
101
- if (!isRecord(value) || !hasExactKeys(value, ['schemaVersion', 'storyId', 'epicId', 'targetPath', 'inputSha256', 'sourceRevision', 'collectedAt', 'artifacts', 'envelopeSha256'])
123
+ const hasReferences = isRecord(value) && Object.prototype.hasOwnProperty.call(value, 'referencedStories');
124
+ if (!isRecord(value) || !hasExactKeys(value, hasReferences ? [...ENVELOPE_KEYS, 'referencedStories'] : ENVELOPE_KEYS)
102
125
  || value.schemaVersion !== 1 || typeof value.storyId !== 'string' || !STORY_ID.test(value.storyId)
103
126
  || typeof value.epicId !== 'string' || !EPIC_ID.test(value.epicId)
104
127
  || !validPath(value.targetPath) || !HASH.test(String(value.inputSha256))
@@ -108,6 +131,8 @@ export function assertYoloSpecEnvelopeV1(value, context) {
108
131
  || value.targetPath !== context.targetPath || value.inputSha256 !== context.inputSha256
109
132
  || value.targetPath !== `docs/stories/${value.storyId}.story.md`)
110
133
  deny('yolo-spec-envelope-target-mismatch');
134
+ if (hasReferences)
135
+ checkReferencedStories(value.referencedStories, value.storyId, value.epicId);
111
136
  const source = value.sourceRevision;
112
137
  if (!isRecord(source) || !hasExactKeys(source, ['headSha', 'manifestSha256'])
113
138
  || !HEAD.test(String(source.headSha)) || !HASH.test(String(source.manifestSha256)))
@@ -154,6 +179,7 @@ export function assertYoloSpecEnvelopeV1(value, context) {
154
179
  sourceRevision: value.sourceRevision,
155
180
  collectedAt: value.collectedAt,
156
181
  artifacts: value.artifacts,
182
+ ...(hasReferences ? { referencedStories: value.referencedStories } : {}),
157
183
  };
158
184
  if (unsignedEnvelopeSha256(unsigned) !== value.envelopeSha256)
159
185
  deny('yolo-spec-envelope-digest-mismatch');
@@ -1,5 +1,7 @@
1
1
  /** Public contracts and pure safety decisions for epic-owned terminal Git. */
2
2
  import { createHash } from 'node:crypto';
3
+ // P226.05 (AC4/F2): reconciliation coverage delegates to the shared matcher.
4
+ import { storyWriteSetCoversWithControlFiles } from './story-write-scope.js';
3
5
  /**
4
6
  * P205 complete-gate budgets are declared in config/release-gates.v2.json and
5
7
  * mirrored here so installed clients keep the same closed runtime bounds.
@@ -98,6 +100,14 @@ export function epicHeadReconciliationInputDigest(value) {
98
100
  changedPathsDigest: value.changedPathsDigest,
99
101
  allowedWriteSet: value.allowedWriteSet,
100
102
  allowedWriteSetDigest: value.allowedWriteSetDigest,
103
+ // Absent optional fields are omitted by JSON.stringify, so legacy receipts
104
+ // keep a byte-identical digest (P226.15 NFR-COMPAT).
105
+ originSyncHeadSha: value.originSyncHeadSha,
106
+ originSyncCommitShas: value.originSyncCommitShas,
107
+ originSyncPaths: value.originSyncPaths,
108
+ originSyncPathsDigest: value.originSyncPathsDigest,
109
+ originSyncResolvedPaths: value.originSyncResolvedPaths,
110
+ originSyncResolvedPathsDigest: value.originSyncResolvedPathsDigest,
101
111
  aggregateReceiptRef: value.aggregateReceiptRef,
102
112
  aggregateManifestDigest: value.aggregateManifestDigest,
103
113
  aggregateResultDigest: value.aggregateResultDigest,
@@ -141,7 +151,9 @@ export function validateEpicHeadReconciliationReceipt(value, expected) {
141
151
  || !sameOrdered(value.allowedWriteSet, [...new Set(value.allowedWriteSet)].sort())
142
152
  || value.changedPaths.some((path) => !safeRepositoryPath(path))
143
153
  || value.allowedWriteSet.some((path) => !safeWriteScope(path))
144
- || value.changedPaths.some((path) => !value.allowedWriteSet.some((scope) => writeScopeCovers(scope, path)))
154
+ || !validOriginSyncEvidence(value)
155
+ || value.changedPaths.some((path) => !storyWriteSetCoversWithControlFiles(value.allowedWriteSet, value.acceptedCheckpointIds, path) && !(value.originSyncPaths ?? []).includes(path)
156
+ && !(value.originSyncResolvedPaths ?? []).includes(path))
145
157
  || value.commitRangeDigest !== epicHeadReconciliationRangeDigest(value.lastAcceptedCheckpointHeadSha, value.executionHeadSha, value.reconciliationCommitShas)
146
158
  || value.changedPathsDigest !== epicHeadReconciliationPathsDigest(value.changedPaths)
147
159
  || value.allowedWriteSetDigest !== epicHeadReconciliationPathsDigest(value.allowedWriteSet)
@@ -157,6 +169,86 @@ export function validateEpicHeadReconciliationReceipt(value, expected) {
157
169
  && now - revalidatedAt <= P205_RELEASE_GATE_BUDGETS.aggregateValidityMs
158
170
  && revalidatedAt - now <= P205_RELEASE_GATE_BUDGETS.cancellationGraceMs;
159
171
  }
172
+ /** P226.15 bounds for origin-sync evidence in the reconciliation receipt. */
173
+ export const EPIC_HEAD_RECONCILIATION_ORIGIN_SYNC_LIMITS = Object.freeze({
174
+ maxCommits: 256,
175
+ maxResolvedPaths: 64,
176
+ });
177
+ const ORIGIN_SYNC_FIELDS = [
178
+ 'originSyncHeadSha', 'originSyncCommitShas', 'originSyncPaths',
179
+ 'originSyncPathsDigest', 'originSyncResolvedPaths', 'originSyncResolvedPathsDigest',
180
+ ];
181
+ function validOriginSyncEvidence(value) {
182
+ const present = ORIGIN_SYNC_FIELDS.filter((field) => value[field] !== undefined);
183
+ if (present.length === 0)
184
+ return true;
185
+ if (present.length !== ORIGIN_SYNC_FIELDS.length)
186
+ return false;
187
+ const commits = value.originSyncCommitShas;
188
+ const paths = value.originSyncPaths;
189
+ const resolved = value.originSyncResolvedPaths;
190
+ if (typeof value.originSyncHeadSha !== 'string' || !isFullSha(value.originSyncHeadSha)
191
+ || !Array.isArray(commits) || !Array.isArray(paths) || !Array.isArray(resolved)
192
+ || commits.length === 0 || commits.length > EPIC_HEAD_RECONCILIATION_ORIGIN_SYNC_LIMITS.maxCommits
193
+ || resolved.length > EPIC_HEAD_RECONCILIATION_ORIGIN_SYNC_LIMITS.maxResolvedPaths
194
+ || paths.length > 2_048
195
+ || commits.some((sha) => typeof sha !== 'string' || !isFullSha(sha))
196
+ || unique(commits).length !== commits.length)
197
+ return false;
198
+ // Sync merges are first-parent commits of the reconciled range, in order.
199
+ let cursor = 0;
200
+ for (const sha of commits) {
201
+ while (cursor < value.reconciliationCommitShas.length && value.reconciliationCommitShas[cursor] !== sha)
202
+ cursor += 1;
203
+ if (cursor >= value.reconciliationCommitShas.length)
204
+ return false;
205
+ cursor += 1;
206
+ }
207
+ const changed = new Set(value.changedPaths);
208
+ const covered = (path) => storyWriteSetCoversWithControlFiles(value.allowedWriteSet, value.acceptedCheckpointIds, path);
209
+ for (const list of [paths, resolved]) {
210
+ if (list.some((path) => typeof path !== 'string' || !safeRepositoryPath(path) || !changed.has(path) || covered(path))
211
+ || !sameOrdered(list, [...new Set(list)].sort()))
212
+ return false;
213
+ }
214
+ const pathSet = new Set(paths);
215
+ return !resolved.some((path) => pathSet.has(path))
216
+ && value.originSyncPathsDigest === epicHeadReconciliationPathsDigest(paths)
217
+ && value.originSyncResolvedPathsDigest === epicHeadReconciliationPathsDigest(resolved);
218
+ }
219
+ const ORIGIN_BINDING_V1_KEYS = ['schemaVersion', 'originBranch', 'originHeadSha', 'executionBranch', 'capturedFromCurrentCheckout', 'capturedAt'];
220
+ const ORIGIN_BINDING_V2_KEYS = ['schemaVersion', 'originBranch', 'originHeadSha', 'executionBranch', 'capturedFrom', 'capturedAt'];
221
+ /**
222
+ * P226.15 (D-01 from P226.08): accept exactly the v1 or the v2 origin binding.
223
+ * Mixed shapes, extra keys, unknown sources, equal branches or malformed SHAs
224
+ * fail closed. Consumers still prove ancestry physically where they have Git.
225
+ */
226
+ export function isEpicOriginBindingEvidence(value) {
227
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
228
+ return false;
229
+ const item = value;
230
+ const keys = Object.keys(item).sort();
231
+ const common = typeof item.originBranch === 'string' && typeof item.executionBranch === 'string'
232
+ && safeBindingBranch(item.originBranch) && safeBindingBranch(item.executionBranch)
233
+ && item.originBranch !== item.executionBranch
234
+ && typeof item.originHeadSha === 'string' && isFullSha(item.originHeadSha)
235
+ && typeof item.capturedAt === 'string' && Number.isFinite(Date.parse(item.capturedAt));
236
+ if (!common)
237
+ return false;
238
+ if (item.schemaVersion === 1) {
239
+ return sameOrdered(keys, [...ORIGIN_BINDING_V1_KEYS].sort()) && item.capturedFromCurrentCheckout === true;
240
+ }
241
+ if (item.schemaVersion === 2) {
242
+ return sameOrdered(keys, [...ORIGIN_BINDING_V2_KEYS].sort())
243
+ && (item.capturedFrom === 'current-checkout' || item.capturedFrom === 'branch-ref');
244
+ }
245
+ return false;
246
+ }
247
+ function safeBindingBranch(value) {
248
+ return value.length > 0 && value.length <= 240 && !value.startsWith('-') && !value.startsWith('/')
249
+ && !value.endsWith('/') && !value.endsWith('.lock') && !value.includes('..') && !value.includes('\\')
250
+ && !value.includes('@{') && !value.includes('//') && /^[A-Za-z0-9._/-]+$/.test(value);
251
+ }
160
252
  /**
161
253
  * P225.06 ownership of a registered worktree: managed only with both the
162
254
  * journal entry and the nonce marker; anything else is manual and preserved.
@@ -210,8 +302,7 @@ export function validateEpicTerminalGitDirective(directive, actual) {
210
302
  }
211
303
  const originBinding = actual.originBinding;
212
304
  if (!originBinding
213
- || originBinding.schemaVersion !== 1
214
- || originBinding.capturedFromCurrentCheckout !== true
305
+ || !isEpicOriginBindingEvidence(originBinding)
215
306
  || originBinding.originBranch !== directive.originBranch
216
307
  || originBinding.executionBranch !== directive.executionBranch
217
308
  || !isSha(originBinding.originHeadSha)
@@ -404,6 +495,3 @@ function safeWriteScope(value) {
404
495
  return parts.length > 0 && parts.every((part) => part.length > 0 && part !== '.' && part !== '..')
405
496
  && parts[0] !== '.git';
406
497
  }
407
- function writeScopeCovers(scope, path) {
408
- return scope === path || scope.endsWith('/') && path.startsWith(scope);
409
- }
@@ -0,0 +1,212 @@
1
+ /**
2
+ * Story P226.05 (P226-CON-WRITESET) -- shared story write-scope semantics.
3
+ *
4
+ * One pure, deterministic module owns how a story write-set is expanded and
5
+ * matched. The direct checkpoint, the Git lifecycle store and `*create-epic`
6
+ * materialization delegate here so the three decisions are identical.
7
+ *
8
+ * Grammar (closed subset, fail-closed): exact relative path, directory scope
9
+ * ending in `/`, and globs where `*` matches within one segment and a segment
10
+ * equal to `**` matches zero or more whole segments (at most 8 segments).
11
+ * Braces, negation, traversal, absolute paths and drive letters are refused
12
+ * with stable reason codes; brackets and `?` are refused inside globs and
13
+ * matched literally in exact/directory scopes. Matching never compiles a RegExp from
14
+ * the scope and runs in O(segments * path segments). Directory and glob scopes
15
+ * never cover governance paths (`.neocortex/`, `.claude/`, `.git*`,
16
+ * `docs/stories/`); those need an exact scope.
17
+ */
18
+ export const STORY_WRITE_SCOPE_MAX_LENGTH = 1024;
19
+ export const STORY_WRITE_SCOPE_MAX_GLOB_SEGMENTS = 8;
20
+ const STORY_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
21
+ // eslint-disable-next-line no-control-regex
22
+ const CONTROL_CHAR_PATTERN = /[\u0000-\u001f\u007f]/;
23
+ /** The five story control files, in canonical order (WS-01). */
24
+ export function storyControlFiles(storyId) {
25
+ if (!isSafeStoryId(storyId))
26
+ return [];
27
+ return [
28
+ '.neocortex/state.json',
29
+ `docs/stories/${storyId}.story.md`,
30
+ `.neocortex/stories/${storyId}/qa-gate-result.json`,
31
+ `.neocortex/stories/${storyId}/validation-evidence.md`,
32
+ `.neocortex/stories/${storyId}/review.md`,
33
+ ];
34
+ }
35
+ /** Validate one write scope against the closed grammar (WS-03). */
36
+ export function validateStoryWriteScope(scope) {
37
+ if (typeof scope !== 'string' || scope.length === 0)
38
+ return fail('story-write-scope-empty');
39
+ if (scope.length > STORY_WRITE_SCOPE_MAX_LENGTH)
40
+ return fail('story-write-scope-too-long');
41
+ if (CONTROL_CHAR_PATTERN.test(scope) || scope.includes('\\'))
42
+ return fail('story-write-scope-invalid-char');
43
+ if (scope.startsWith('/'))
44
+ return fail('story-write-scope-absolute');
45
+ if (scope.startsWith('-'))
46
+ return fail('story-write-scope-leading-dash');
47
+ if (/^[A-Za-z]:/.test(scope))
48
+ return fail('story-write-scope-drive-letter');
49
+ const body = scope.endsWith('/') ? scope.slice(0, -1) : scope;
50
+ const segments = body.split('/');
51
+ if (segments.some((segment) => segment === '' || segment === '.' || segment === '..')) {
52
+ return fail('story-write-scope-traversal');
53
+ }
54
+ if (segments[0].toLowerCase() === '.git')
55
+ return fail('story-write-scope-git-dir');
56
+ if (scope.includes('{') || scope.includes('}'))
57
+ return fail('story-write-scope-brace');
58
+ if (scope.includes('!'))
59
+ return fail('story-write-scope-negation');
60
+ if (!isGlob(scope))
61
+ return { ok: true };
62
+ // Character classes and `?` are glob syntax outside the supported subset.
63
+ // Exact and directory scopes match them literally (e.g. `app/[id]/page.tsx`),
64
+ // which cannot widen the scope; inside a glob they fail closed.
65
+ if (scope.includes('[') || scope.includes(']'))
66
+ return fail('story-write-scope-bracket');
67
+ if (scope.includes('?'))
68
+ return fail('story-write-scope-wildcard-invalid');
69
+ if (segments.some((segment) => segment.includes('**') && segment !== '**')) {
70
+ return fail('story-write-scope-wildcard-invalid');
71
+ }
72
+ if (segments.length > STORY_WRITE_SCOPE_MAX_GLOB_SEGMENTS)
73
+ return fail('story-write-scope-too-many-segments');
74
+ return { ok: true };
75
+ }
76
+ /** Whether `scope` (exact, `dir/` or bounded glob) covers repository `path` (WS-04). */
77
+ export function storyWriteScopeCovers(scope, path) {
78
+ if (!validateStoryWriteScope(scope).ok || !isSafeRepositoryPath(path))
79
+ return false;
80
+ if (scope === path)
81
+ return true;
82
+ // Governance surfaces are authorized only by an exact scope: a directory or
83
+ // glob never reaches them. Own-story control files come from the exact
84
+ // expansion (P226.05 F3; mirrors the write-set extension path rule).
85
+ if (isGovernancePath(path))
86
+ return false;
87
+ if (scope.endsWith('/') && !isGlob(scope))
88
+ return path.startsWith(scope);
89
+ if (!isGlob(scope) || path.includes('*'))
90
+ return false;
91
+ // A directory glob (`src/*/`) covers at least one entry below the directory.
92
+ const scopeSegments = collapseGlobstars((scope.endsWith('/') ? `${scope}*/**` : scope).split('/'));
93
+ return matchSegments(scopeSegments, path.split('/'));
94
+ }
95
+ /** Paths a non-exact scope never covers: `.neocortex/`, `.claude/`, `.git*` and `docs/stories/`. */
96
+ export function isStoryWriteScopeGovernancePath(path) {
97
+ return isGovernancePath(path);
98
+ }
99
+ /** Whether any scope in `scopes` covers `path`. */
100
+ export function storyWriteSetCovers(scopes, path) {
101
+ return scopes.some((scope) => storyWriteScopeCovers(scope, path));
102
+ }
103
+ /**
104
+ * Aggregate coverage over authored scopes plus the exact control files of the
105
+ * given stories. Used where an epic-level `allowedWriteSet` is the union of
106
+ * authored write-sets, so stories that omit their control files stay covered
107
+ * without changing the persisted `allowedWriteSet` digest.
108
+ */
109
+ export function storyWriteSetCoversWithControlFiles(scopes, storyIds, path) {
110
+ return storyWriteSetCovers(scopes, path) || storyIds.some((storyId) => storyControlFiles(storyId).includes(path));
111
+ }
112
+ /**
113
+ * Expand authored refs with the five control files exactly once, deduplicated
114
+ * and sorted (WS-02). Any invalid ref fails the whole expansion closed.
115
+ */
116
+ export function expandStoryWriteScope(storyId, refs) {
117
+ if (!isSafeStoryId(storyId))
118
+ return fail('story-write-scope-story-id-invalid');
119
+ const normalized = [];
120
+ for (const ref of refs) {
121
+ const value = typeof ref === 'string' ? stripDotSlash(ref) : ref;
122
+ const validation = validateStoryWriteScope(value);
123
+ if (!validation.ok)
124
+ return validation;
125
+ normalized.push(value);
126
+ }
127
+ const scopes = [...new Set([...normalized, ...storyControlFiles(storyId)])].sort(compareCodeUnits);
128
+ return { ok: true, scopes: Object.freeze(scopes) };
129
+ }
130
+ /** Consecutive `**` segments are equivalent to one. */
131
+ function collapseGlobstars(segments) {
132
+ return segments.filter((segment, index) => segment !== '**' || segments[index - 1] !== '**');
133
+ }
134
+ /**
135
+ * Segment matcher as a bottom-up dynamic program over (scope index, path
136
+ * index): O(S * P) segment comparisons, no recursion and no backtracking
137
+ * blow-up for pathological `**` scopes (P226.05 F1).
138
+ */
139
+ function matchSegments(scope, path) {
140
+ const width = path.length + 1;
141
+ // next[pi] = whether scope[si+1..] matches path[pi..]
142
+ let next = new Array(width).fill(false);
143
+ next[path.length] = true;
144
+ for (let si = scope.length - 1; si >= 0; si -= 1) {
145
+ const segment = scope[si];
146
+ const current = new Array(width).fill(false);
147
+ if (segment === '**') {
148
+ // `**` matches zero or more segments: current[pi] = OR_{k>=pi} next[k].
149
+ let any = false;
150
+ for (let pi = path.length; pi >= 0; pi -= 1) {
151
+ any = any || next[pi];
152
+ current[pi] = any;
153
+ }
154
+ }
155
+ else {
156
+ for (let pi = 0; pi < path.length; pi += 1) {
157
+ current[pi] = next[pi + 1] && matchSegment(segment, path[pi]);
158
+ }
159
+ }
160
+ next = current;
161
+ }
162
+ return next[0];
163
+ }
164
+ /** `*` matches zero or more characters inside one segment. */
165
+ function matchSegment(pattern, value) {
166
+ const parts = pattern.split('*');
167
+ if (parts.length === 1)
168
+ return pattern === value;
169
+ const first = parts[0];
170
+ const last = parts[parts.length - 1];
171
+ if (value.length < first.length + last.length || !value.startsWith(first) || !value.endsWith(last))
172
+ return false;
173
+ let cursor = first.length;
174
+ const end = value.length - last.length;
175
+ for (const middle of parts.slice(1, -1)) {
176
+ const found = value.indexOf(middle, cursor);
177
+ if (found < 0 || found + middle.length > end)
178
+ return false;
179
+ cursor = found + middle.length;
180
+ }
181
+ return cursor <= end;
182
+ }
183
+ function isGlob(scope) {
184
+ return scope.includes('*');
185
+ }
186
+ function isSafeRepositoryPath(path) {
187
+ if (typeof path !== 'string' || path.length === 0 || path.length > STORY_WRITE_SCOPE_MAX_LENGTH)
188
+ return false;
189
+ if (CONTROL_CHAR_PATTERN.test(path) || path.includes('\\') || path.startsWith('/') || path.startsWith('-')
190
+ || /^[A-Za-z]:/.test(path))
191
+ return false;
192
+ const segments = path.split('/');
193
+ return !segments.some((segment) => segment === '' || segment === '.' || segment === '..')
194
+ && segments[0].toLowerCase() !== '.git';
195
+ }
196
+ function isGovernancePath(path) {
197
+ const lower = path.toLowerCase();
198
+ const first = lower.split('/')[0];
199
+ return first === '.neocortex' || first === '.claude' || first.startsWith('.git') || lower.startsWith('docs/stories/');
200
+ }
201
+ function isSafeStoryId(storyId) {
202
+ return typeof storyId === 'string' && STORY_ID_PATTERN.test(storyId) && !storyId.includes('..');
203
+ }
204
+ function stripDotSlash(value) {
205
+ return value.startsWith('./') ? value.slice(2) : value;
206
+ }
207
+ function compareCodeUnits(left, right) {
208
+ return left < right ? -1 : left > right ? 1 : 0;
209
+ }
210
+ function fail(reasonCode) {
211
+ return { ok: false, reasonCode };
212
+ }
@@ -1,4 +1,4 @@
1
- # 🧠 Neocortex v4.61.5 | OrNexus Team
1
+ # 🧠 Neocortex v4.62.0 | OrNexus Team
2
2
 
3
3
  This project uses Neocortex, a Development Orchestrator.
4
4
 
@@ -33,13 +33,22 @@ install_antigravity() {
33
33
  echo "[ANTIGRAVITY] Installing Neocortex for Google Antigravity (thin-client mode)..."
34
34
  echo "[ANTIGRAVITY] WARNING: Antigravity is in public preview - APIs may change"
35
35
 
36
+ # P226.13: a global install passes $HOME as the destination; never create
37
+ # the project .agent/skills folder there. Existing folders are kept.
38
+ local global_destination=false
39
+ if neocortex_is_global_destination "$dest_dir"; then
40
+ global_destination=true
41
+ fi
42
+
36
43
  # Create destination directories
37
- mkdir -p "$dest_dir/.agent/skills/neocortex" \
38
- "$gemini_home/antigravity" \
44
+ mkdir -p "$gemini_home/antigravity" \
39
45
  "$gemini_home/config/agents"
46
+ if [ "$global_destination" != true ]; then
47
+ mkdir -p "$dest_dir/.agent/skills/neocortex"
48
+ fi
40
49
 
41
- # 1. Copy SKILL.md stub
42
- if [ -f "$ag_target/skill/SKILL.md" ]; then
50
+ # 1. Copy SKILL.md stub (project installs only)
51
+ if [ "$global_destination" != true ] && [ -f "$ag_target/skill/SKILL.md" ]; then
43
52
  neocortex_managed_profile "$source_dir" "$ag_target/skill/SKILL.md" "$dest_dir/.agent/skills/neocortex/SKILL.md" "$dest_dir" "project-antigravity-skill"
44
53
  neocortex_managed_report "[ANTIGRAVITY]" ".agent/skills/neocortex/SKILL.md (skill stub)"
45
54
  fi
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: neocortex
3
- description: "🧠 Neocortex v4.61.5 | OrNexus Team"
3
+ description: "🧠 Neocortex v4.62.0 | OrNexus Team"
4
4
  ---
5
5
 
6
6
  <!--
@@ -4,7 +4,7 @@ agent:
4
4
  name: 'Neocortex Root Agent'
5
5
  title: 'Development Orchestrator (Root)'
6
6
  icon: '>'
7
- version: '4.61.5'
7
+ version: '4.62.0'
8
8
  architecture: 'thin-client'
9
9
  module: stand-alone
10
10
  hasSidecar: false
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: neocortex-root
3
- description: "🧠 Neocortex Root Agent v4.61.5 | OrNexus Team"
3
+ description: "🧠 Neocortex Root Agent v4.62.0 | OrNexus Team"
4
4
  model: opus
5
5
  color: blue
6
6
  tools:
@@ -108,7 +108,7 @@ SEMPRE que este agente for invocado, imprima o banner abaixo como PRIMEIRO outpu
108
108
  ┌────────────────────────────────────────────────────────────┐
109
109
  │ │
110
110
  │ ####### N E O C O R T E X │
111
- │ ### ######## v4.61.5 │
111
+ │ ### ######## v4.62.0 │
112
112
  │ ######### ##### │
113
113
  │ ## ############## Development Orchestrator │
114
114
  │ ## ### ###### ## OrNexus Team │
@@ -4,7 +4,7 @@ agent:
4
4
  name: 'Neocortex'
5
5
  title: 'Development Orchestrator'
6
6
  icon: '>'
7
- version: '4.61.5'
7
+ version: '4.62.0'
8
8
  architecture: 'thin-client'
9
9
  module: stand-alone
10
10
  hasSidecar: false
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: neocortex
3
- description: "🧠 Neocortex v4.61.5 | OrNexus Team"
3
+ description: "🧠 Neocortex v4.62.0 | OrNexus Team"
4
4
  model: opus
5
5
  color: blue
6
6
  permissionMode: bypassPermissions
@@ -106,7 +106,7 @@ SEMPRE que este agente for invocado, imprima o banner abaixo como PRIMEIRO outpu
106
106
  ┌────────────────────────────────────────────────────────────┐
107
107
  │ │
108
108
  │ ####### N E O C O R T E X │
109
- │ ### ######## v4.61.5 │
109
+ │ ### ######## v4.62.0 │
110
110
  │ ######### ##### │
111
111
  │ ## ############## Development Orchestrator │
112
112
  │ ## ### ###### ## OrNexus Team │
@@ -223,7 +223,8 @@ authorizes delegation (`native_safe`) and returns a root-owned plan:
223
223
  - Each child gets only its server-authored prompt, e.g.
224
224
  `*yolo @docs/stories/<id>.story.md` or the `... branchless-preparation`
225
225
  variant. Never pass the outer `@neocortex *yoloop ...` or any root invocation.
226
- - Serial plans keep one child at a time. Children may delegate further.
226
+ - Serial plans keep one child at a time. Children may delegate further:
227
+ max 1 child level below root, 3 levels total; children never run `*yoloop`.
227
228
  - The root agent keeps yoloop ownership: it waits for all children of the wave,
228
229
  then re-invokes `*yoloop`; server output decides integration and the next
229
230
  wave. Never invent workflow steps.
@@ -363,8 +364,7 @@ Agent (correct):
363
364
  4. Child executions complete; agent re-invokes the loop with the next iteration.
364
365
  5. Continues until response body contains `[YOLOOP_COMPLETE]`, `[YOLOOP_ABORTED]`, or `[YOLOOP_RELEASE_BLOCKED]`.
365
366
 
366
- Agent (INCORRECT, pre-P122): reads the body as plain text and sits idle. The
367
- correct path is mandatory whenever the recognition signals are present.
367
+ Agent (INCORRECT, pre-P122): reads the body as plain text and sits idle.
368
368
 
369
369
  ## Regras
370
370
 
@@ -32,7 +32,7 @@ Codex built-in commands or actions.
32
32
 
33
33
  <!-- END: Plugin Conflict Prevention -->
34
34
 
35
- # Neocortex v4.61.5 | OrNexus Team
35
+ # Neocortex v4.62.0 | OrNexus Team
36
36
 
37
37
  You are a Development Orchestrator. All orchestration logic is delivered by the remote Neocortex server.
38
38
 
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: neocortex
3
- description: "🧠 Neocortex v4.61.5 | OrNexus Team"
3
+ description: "🧠 Neocortex v4.62.0 | OrNexus Team"
4
4
  model: inherit
5
5
  readonly: false
6
6
  is_background: false
@@ -104,7 +104,7 @@ SEMPRE que este agente for invocado, imprima o banner abaixo como PRIMEIRO outpu
104
104
  ┌────────────────────────────────────────────────────────────┐
105
105
  │ │
106
106
  │ ####### N E O C O R T E X │
107
- │ ### ######## v4.61.5 │
107
+ │ ### ######## v4.62.0 │
108
108
  │ ######### ##### │
109
109
  │ ## ############## Development Orchestrator │
110
110
  │ ## ### ###### ## OrNexus Team │
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: neocortex-root
3
- description: "🧠 Neocortex v4.61.5 | OrNexus Team"
3
+ description: "🧠 Neocortex v4.62.0 | OrNexus Team"
4
4
  kind: local
5
5
  tools:
6
6
  # File operations (Gemini CLI built-ins)
@@ -62,7 +62,7 @@ SEMPRE que este agente for invocado, imprima o banner abaixo como PRIMEIRO outpu
62
62
  ┌────────────────────────────────────────────────────────────┐
63
63
  │ │
64
64
  │ ####### N E O C O R T E X │
65
- │ ### ######## v4.61.5 │
65
+ │ ### ######## v4.62.0 │
66
66
  │ ######### ##### │
67
67
  │ ## ############## Development Orchestrator │
68
68
  │ ## ### ###### ## OrNexus Team │