@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,4 +1,3 @@
1
- import { Buffer } from 'node:buffer';
2
1
  export const FRONTMATTER_CONTEXTS = [
3
2
  'wrapper',
4
3
  'delegated-prompt',
@@ -31,6 +30,42 @@ export const FRONTMATTER_LIMITS = Object.freeze({
31
30
  maxListItems: 32,
32
31
  maxValueChars: 512,
33
32
  });
33
+ /**
34
+ * P226.04 / ADR-P226-03: per-field list limits. Every list not named here keeps
35
+ * the global `FRONTMATTER_LIMITS.maxListItems` / `maxValueChars` bounds.
36
+ */
37
+ export const FRONTMATTER_FIELD_LIMITS = Object.freeze({
38
+ files_to_modify: Object.freeze({ maxItems: 256, maxItemChars: 240 }),
39
+ });
40
+ /**
41
+ * Additional envelope budget that only `files_to_modify` items may consume. The
42
+ * envelope is accepted when `lines <= maxLines + min(extraLines, fileLines)` and
43
+ * `bytes <= maxBytes + min(extraBytes, fileBytes)`; excess from any other field
44
+ * remains `frontmatter-oversized`.
45
+ */
46
+ export const FRONTMATTER_FIELD_BUDGET = Object.freeze({
47
+ extraLines: 256,
48
+ extraBytes: 64 * 1024,
49
+ });
50
+ const BUDGET_FIELD = 'files_to_modify';
51
+ const UNLISTED_FIELD_LABEL = 'unlisted-field';
52
+ export const FRONTMATTER_LIST_TOO_LONG_PATTERN = /^frontmatter-list-too-long:(files_to_modify|depends_on|related_epics|unlisted-field):[0-9]{1,6}>[0-9]{1,6}$/;
53
+ export function frontmatterListLimit(field) {
54
+ return field === BUDGET_FIELD ? FRONTMATTER_FIELD_LIMITS.files_to_modify : DEFAULT_LIST_LIMIT;
55
+ }
56
+ const DEFAULT_LIST_LIMIT = Object.freeze({
57
+ maxItems: FRONTMATTER_LIMITS.maxListItems,
58
+ maxItemChars: FRONTMATTER_LIMITS.maxValueChars,
59
+ });
60
+ export function formatFrontmatterListTooLong(field, count, limit) {
61
+ const label = LIST_FIELDS.has(field) ? field : UNLISTED_FIELD_LABEL;
62
+ const safeCount = Number.isSafeInteger(count) && count >= 0 ? Math.min(count, 999_999) : 0;
63
+ const safeLimit = Number.isSafeInteger(limit) && limit >= 0 ? Math.min(limit, 999_999) : 0;
64
+ return `frontmatter-list-too-long:${label}:${safeCount}>${safeLimit}`;
65
+ }
66
+ export function isFrontmatterListTooLongReasonCode(value) {
67
+ return typeof value === 'string' && FRONTMATTER_LIST_TOO_LONG_PATTERN.test(value);
68
+ }
34
69
  const EPIC_TARGET_FIELDS = Object.freeze([
35
70
  'id',
36
71
  'title',
@@ -91,8 +126,29 @@ export const FRONTMATTER_CONTEXT_POLICY = Object.freeze({
91
126
  allowedFields: Object.freeze([]),
92
127
  }),
93
128
  });
129
+ const ENVELOPE_CEILING = Object.freeze({
130
+ maxLines: FRONTMATTER_LIMITS.maxLines + FRONTMATTER_FIELD_BUDGET.extraLines,
131
+ maxBytes: FRONTMATTER_LIMITS.maxBytes + FRONTMATTER_FIELD_BUDGET.extraBytes,
132
+ });
133
+ /**
134
+ * Dependency-free UTF-8 byte count (matches `Buffer.byteLength(..., 'utf8')`,
135
+ * including 3 bytes for lone surrogates) so dependency-free consumers can share
136
+ * this contract without loading `node:*` modules.
137
+ */
94
138
  function byteLength(value) {
95
- return Buffer.byteLength(value, 'utf8');
139
+ let bytes = 0;
140
+ for (const char of value) {
141
+ const codePoint = char.codePointAt(0) ?? 0;
142
+ if (codePoint < 0x80)
143
+ bytes += 1;
144
+ else if (codePoint < 0x800)
145
+ bytes += 2;
146
+ else if (codePoint < 0x10000)
147
+ bytes += 3;
148
+ else
149
+ bytes += 4;
150
+ }
151
+ return bytes;
96
152
  }
97
153
  function scanFrontmatter(source) {
98
154
  if (typeof source !== 'string')
@@ -105,21 +161,25 @@ function scanFrontmatter(source) {
105
161
  const contentStart = opening[0].length;
106
162
  let cursor = contentStart;
107
163
  let lineCount = 1;
164
+ let bytes = contentStart;
108
165
  while (cursor <= source.length) {
109
166
  const newlineIndex = source.indexOf('\n', cursor);
110
167
  const lineEnd = newlineIndex === -1 ? source.length : newlineIndex;
111
168
  const rawLine = source.slice(cursor, lineEnd);
112
169
  const line = rawLine.endsWith('\r') ? rawLine.slice(0, -1) : rawLine;
113
170
  lineCount += 1;
114
- const inspectedEnd = newlineIndex === -1 ? lineEnd : newlineIndex + 1;
115
- if (lineCount > FRONTMATTER_LIMITS.maxLines ||
116
- byteLength(source.slice(0, inspectedEnd)) > FRONTMATTER_LIMITS.maxBytes) {
171
+ bytes += byteLength(rawLine) + (newlineIndex === -1 ? 0 : 1);
172
+ // Absolute structural ceiling; the proportional base budget is enforced
173
+ // after parsing, once the `files_to_modify` contribution is known.
174
+ if (lineCount > ENVELOPE_CEILING.maxLines || bytes > ENVELOPE_CEILING.maxBytes) {
117
175
  return { status: 'oversized' };
118
176
  }
119
177
  if (line === '---') {
120
178
  return {
121
179
  status: 'valid',
122
180
  block: source.slice(contentStart, cursor),
181
+ lines: lineCount,
182
+ bytes,
123
183
  };
124
184
  }
125
185
  if (newlineIndex === -1)
@@ -128,8 +188,8 @@ function scanFrontmatter(source) {
128
188
  }
129
189
  return { status: 'malformed' };
130
190
  }
131
- function unquote(value) {
132
- if (value.length > FRONTMATTER_LIMITS.maxValueChars)
191
+ function unquote(value, maxChars = FRONTMATTER_LIMITS.maxValueChars) {
192
+ if (value.length > maxChars)
133
193
  return null;
134
194
  const first = value[0];
135
195
  const last = value[value.length - 1];
@@ -142,63 +202,93 @@ function unquote(value) {
142
202
  }
143
203
  return value;
144
204
  }
145
- function parseListItem(value) {
146
- const parsed = unquote(value.trim());
205
+ function parseListItem(value, limit) {
206
+ const trimmed = value.trim();
207
+ // Default lists keep the historical raw-length bound. Budget-field items are
208
+ // bounded by content length, so their two quote delimiters are not counted.
209
+ const delimiterAllowance = limit === FRONTMATTER_FIELD_LIMITS.files_to_modify ? 2 : 0;
210
+ if (trimmed.length > limit.maxItemChars + delimiterAllowance)
211
+ return { status: 'oversized' };
212
+ const parsed = unquote(trimmed, limit.maxItemChars + delimiterAllowance);
147
213
  if (parsed === null || parsed.length === 0)
148
- return null;
149
- return parsed;
214
+ return { status: 'malformed' };
215
+ if (parsed.length > limit.maxItemChars)
216
+ return { status: 'oversized' };
217
+ return { status: 'item', value: parsed };
150
218
  }
151
- function parseInlineValue(value) {
219
+ function parseInlineValue(key, value) {
152
220
  const trimmed = value.trim();
153
221
  if (trimmed.length === 0)
154
- return null;
222
+ return { status: 'malformed' };
155
223
  if (trimmed.startsWith('[') || trimmed.endsWith(']')) {
156
224
  if (!trimmed.startsWith('[') || !trimmed.endsWith(']'))
157
- return null;
225
+ return { status: 'malformed' };
158
226
  const body = trimmed.slice(1, -1).trim();
159
227
  if (!body)
160
- return Object.freeze([]);
228
+ return { status: 'value', value: Object.freeze([]) };
229
+ const limit = frontmatterListLimit(key);
161
230
  const rawItems = body.split(',');
162
- if (rawItems.length > FRONTMATTER_LIMITS.maxListItems)
163
- return null;
164
- const items = rawItems.map(parseListItem);
165
- if (items.some((item) => item === null))
166
- return null;
167
- return Object.freeze(items);
231
+ if (rawItems.length > limit.maxItems) {
232
+ return {
233
+ status: 'list-too-long',
234
+ reasonCode: formatFrontmatterListTooLong(key, rawItems.length, limit.maxItems),
235
+ };
236
+ }
237
+ const items = [];
238
+ for (const rawItem of rawItems) {
239
+ const item = parseListItem(rawItem, limit);
240
+ if (item.status !== 'item')
241
+ return item;
242
+ items.push(item.value);
243
+ }
244
+ return { status: 'value', value: Object.freeze(items) };
168
245
  }
246
+ if (trimmed.length > FRONTMATTER_LIMITS.maxValueChars)
247
+ return { status: 'oversized' };
169
248
  const unquoted = unquote(trimmed);
170
249
  if (unquoted === null)
171
- return null;
250
+ return { status: 'malformed' };
172
251
  const quoted = (trimmed.startsWith('"') && trimmed.endsWith('"')) ||
173
252
  (trimmed.startsWith("'") && trimmed.endsWith("'"));
174
253
  if (quoted)
175
- return unquoted;
254
+ return { status: 'value', value: unquoted };
176
255
  if (unquoted === 'true')
177
- return true;
256
+ return { status: 'value', value: true };
178
257
  if (unquoted === 'false')
179
- return false;
258
+ return { status: 'value', value: false };
180
259
  if (/^-?(?:0|[1-9]\d*)$/.test(unquoted)) {
181
260
  const numberValue = Number(unquoted);
182
- if (!Number.isFinite(numberValue) || !Number.isSafeInteger(numberValue))
183
- return null;
184
- return numberValue;
261
+ if (!Number.isFinite(numberValue) || !Number.isSafeInteger(numberValue)) {
262
+ return { status: 'malformed' };
263
+ }
264
+ return { status: 'value', value: numberValue };
185
265
  }
186
- return unquoted;
266
+ return { status: 'value', value: unquoted };
187
267
  }
188
268
  function parseFrontmatterBlock(block) {
189
269
  const fields = {};
190
270
  let fieldCount = 0;
191
271
  let pendingListKey = null;
192
272
  let pendingList = [];
273
+ let pendingCount = 0;
274
+ let budgetLines = 0;
275
+ let budgetBytes = 0;
276
+ // Returns a list-too-long outcome when the committed list exceeds its limit.
193
277
  const commitPendingList = () => {
194
278
  if (!pendingListKey)
195
- return true;
196
- if (pendingList.length > FRONTMATTER_LIMITS.maxListItems)
197
- return false;
279
+ return null;
280
+ const limit = frontmatterListLimit(pendingListKey);
281
+ if (pendingCount > limit.maxItems) {
282
+ return {
283
+ status: 'list-too-long',
284
+ reasonCode: formatFrontmatterListTooLong(pendingListKey, pendingCount, limit.maxItems),
285
+ };
286
+ }
198
287
  fields[pendingListKey] = Object.freeze([...pendingList]);
199
288
  pendingListKey = null;
200
289
  pendingList = [];
201
- return true;
290
+ pendingCount = 0;
291
+ return null;
202
292
  };
203
293
  for (const rawLine of block.split(/\r?\n/)) {
204
294
  if (!rawLine.trim() || rawLine.trimStart().startsWith('#'))
@@ -207,19 +297,26 @@ function parseFrontmatterBlock(block) {
207
297
  if (listMatch) {
208
298
  if (!pendingListKey)
209
299
  return { status: 'malformed', unsupportedValue: true };
210
- if (listMatch[1].trim().length > FRONTMATTER_LIMITS.maxValueChars) {
300
+ const limit = frontmatterListLimit(pendingListKey);
301
+ const item = parseListItem(listMatch[1], limit);
302
+ if (item.status === 'oversized')
211
303
  return { status: 'oversized' };
212
- }
213
- const item = parseListItem(listMatch[1]);
214
- if (item === null)
304
+ if (item.status === 'malformed')
215
305
  return { status: 'malformed', unsupportedValue: true };
216
- pendingList.push(item);
217
- if (pendingList.length > FRONTMATTER_LIMITS.maxListItems)
218
- return { status: 'oversized' };
306
+ pendingCount += 1;
307
+ // Keep counting past the limit so the reason code reports the real size;
308
+ // the structural ceiling bounds the total work. Excess items are dropped.
309
+ if (pendingCount <= limit.maxItems)
310
+ pendingList.push(item.value);
311
+ if (pendingListKey === BUDGET_FIELD) {
312
+ budgetLines += 1;
313
+ budgetBytes += byteLength(rawLine) + 1;
314
+ }
219
315
  continue;
220
316
  }
221
- if (!commitPendingList())
222
- return { status: 'oversized' };
317
+ const committed = commitPendingList();
318
+ if (committed)
319
+ return committed;
223
320
  const fieldMatch = rawLine.match(/^([A-Za-z_][A-Za-z0-9_-]{0,63}):(?:\s*(.*))?$/);
224
321
  if (!fieldMatch)
225
322
  return { status: 'malformed', unsupportedValue: true };
@@ -235,17 +332,29 @@ function parseFrontmatterBlock(block) {
235
332
  pendingListKey = key;
236
333
  continue;
237
334
  }
238
- const value = parseInlineValue(rawValue);
239
- if (value === null) {
240
- return rawValue.length > FRONTMATTER_LIMITS.maxValueChars
241
- ? { status: 'oversized' }
242
- : { status: 'malformed', unsupportedValue: true };
335
+ const value = parseInlineValue(key, rawValue);
336
+ if (value.status === 'list-too-long')
337
+ return value;
338
+ if (value.status === 'oversized')
339
+ return { status: 'oversized' };
340
+ if (value.status === 'malformed')
341
+ return { status: 'malformed', unsupportedValue: true };
342
+ if (key === BUDGET_FIELD && Array.isArray(value.value)) {
343
+ budgetBytes += byteLength(rawValue);
243
344
  }
244
- fields[key] = value;
345
+ fields[key] = value.value;
245
346
  }
246
- if (!commitPendingList())
247
- return { status: 'oversized' };
248
- return { status: 'valid', fields: Object.freeze(fields) };
347
+ const committed = commitPendingList();
348
+ if (committed)
349
+ return committed;
350
+ return { status: 'valid', fields: Object.freeze(fields), budgetLines, budgetBytes };
351
+ }
352
+ function withinProportionalBudget(structural, parsed) {
353
+ const allowedLines = FRONTMATTER_LIMITS.maxLines +
354
+ Math.min(FRONTMATTER_FIELD_BUDGET.extraLines, parsed.budgetLines);
355
+ const allowedBytes = FRONTMATTER_LIMITS.maxBytes +
356
+ Math.min(FRONTMATTER_FIELD_BUDGET.extraBytes, parsed.budgetBytes);
357
+ return structural.lines <= allowedLines && structural.bytes <= allowedBytes;
249
358
  }
250
359
  function result(context, status, reasonCodes, metadata = Object.freeze({})) {
251
360
  return Object.freeze({
@@ -287,7 +396,10 @@ export function inspectFrontmatterContext(source, options) {
287
396
  ...(parsed.unsupportedValue ? ['frontmatter-unsupported-value'] : []),
288
397
  ]);
289
398
  }
290
- if (parsed.status === 'oversized') {
399
+ if (parsed.status === 'list-too-long') {
400
+ return result(options.context, 'oversized', [parsed.reasonCode, 'frontmatter-oversized']);
401
+ }
402
+ if (parsed.status === 'oversized' || !withinProportionalBudget(structural, parsed)) {
291
403
  return result(options.context, 'oversized', ['frontmatter-oversized']);
292
404
  }
293
405
  const policy = FRONTMATTER_CONTEXT_POLICY[options.context];
@@ -0,0 +1,199 @@
1
+ import { createHash } from 'node:crypto';
2
+ /**
3
+ * P226.09 `ProjectManifestProjection/1.0` (P226-CON-MANIFEST-PROJECTION).
4
+ *
5
+ * Planning data only: script *names* and relative manifest paths of the
6
+ * consumer project. Never script bodies, versions, dependencies, registry URLs,
7
+ * environment values or absolute paths. It grants no execution or QA authority.
8
+ */
9
+ export const PROJECT_MANIFEST_PROJECTION_SCHEMA = 'ProjectManifestProjection/1.0';
10
+ /** Public server capability; clients send the optional request field only when advertised. */
11
+ export const PROJECT_MANIFEST_PROJECTION_CAPABILITY = 'project-manifest-projection-v1';
12
+ export const PROJECT_MANIFEST_PROJECTION_MAX_MANIFESTS = 16;
13
+ export const PROJECT_MANIFEST_PROJECTION_MAX_SCRIPTS = 64;
14
+ export const PROJECT_MANIFEST_PROJECTION_MAX_PATH_LENGTH = 256;
15
+ export const PROJECT_MANIFEST_PROJECTION_MAX_MANIFEST_BYTES = 64 * 1024;
16
+ export const PROJECT_MANIFEST_PROJECTION_SCRIPT_NAME = /^[a-z0-9:_.-]{1,64}$/;
17
+ export const PROJECT_MANIFEST_PACKAGE_MANAGERS = ['npm', 'pnpm', 'yarn', 'bun', 'unknown'];
18
+ export const PROJECT_MANIFEST_PROJECTION_OMISSION_KEYS = [
19
+ 'invalidJson',
20
+ 'invalidScriptNames',
21
+ 'outOfScope',
22
+ 'overLimit',
23
+ 'oversize',
24
+ 'symlink',
25
+ ];
26
+ const TOP_KEYS = ['manifests', 'omitted', 'schema'];
27
+ const ENTRY_KEYS = ['packageManager', 'path', 'scriptNames'];
28
+ const ATTACHMENT_KEYS = ['projection', 'sha256'];
29
+ const SHA256 = /^[a-f0-9]{64}$/;
30
+ function isRecord(value) {
31
+ return !!value && typeof value === 'object' && !Array.isArray(value);
32
+ }
33
+ function hasExactKeys(value, keys) {
34
+ const own = Object.keys(value);
35
+ return own.length === keys.length && own.every((key) => keys.includes(key));
36
+ }
37
+ /** Relative POSIX path to a `package.json`, inside the project root. */
38
+ export function isProjectManifestPath(value) {
39
+ if (typeof value !== 'string' || value.length === 0
40
+ || value.length > PROJECT_MANIFEST_PROJECTION_MAX_PATH_LENGTH)
41
+ return false;
42
+ if (value !== 'package.json' && !value.endsWith('/package.json'))
43
+ return false;
44
+ if (value.startsWith('/') || value.includes('\\') || value.includes('//'))
45
+ return false;
46
+ if (/[\u0000-\u001f\u007f]/.test(value))
47
+ return false;
48
+ return value.split('/').every((segment) => segment !== '' && segment !== '.' && segment !== '..');
49
+ }
50
+ /** Root manifest first, then lexicographic by path. */
51
+ export function compareProjectManifestPaths(left, right) {
52
+ if (left === right)
53
+ return 0;
54
+ if (left === 'package.json')
55
+ return -1;
56
+ if (right === 'package.json')
57
+ return 1;
58
+ return left < right ? -1 : 1;
59
+ }
60
+ function canonicalJson(value) {
61
+ if (Array.isArray(value))
62
+ return `[${value.map(canonicalJson).join(',')}]`;
63
+ if (isRecord(value)) {
64
+ return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson(value[key])}`).join(',')}}`;
65
+ }
66
+ return JSON.stringify(value);
67
+ }
68
+ export function projectManifestProjectionSha256(projection) {
69
+ return createHash('sha256').update(canonicalJson(projection), 'utf8').digest('hex');
70
+ }
71
+ /** Closed validator. Reasons are stable and never echo the rejected value. */
72
+ export function validateProjectManifestProjection(value) {
73
+ const fail = (reason) => ({ ok: false, reason });
74
+ if (!isRecord(value))
75
+ return fail('project-manifest-projection-not-object');
76
+ if (!hasExactKeys(value, TOP_KEYS))
77
+ return fail('project-manifest-projection-unknown-field');
78
+ if (value.schema !== PROJECT_MANIFEST_PROJECTION_SCHEMA)
79
+ return fail('project-manifest-projection-schema-mismatch');
80
+ const omitted = value.omitted;
81
+ if (!isRecord(omitted) || !hasExactKeys(omitted, PROJECT_MANIFEST_PROJECTION_OMISSION_KEYS)
82
+ || PROJECT_MANIFEST_PROJECTION_OMISSION_KEYS.some((key) => {
83
+ const count = omitted[key];
84
+ return typeof count !== 'number' || !Number.isSafeInteger(count) || count < 0;
85
+ }))
86
+ return fail('project-manifest-projection-omitted-invalid');
87
+ if (!Array.isArray(value.manifests))
88
+ return fail('project-manifest-projection-not-object');
89
+ if (value.manifests.length > PROJECT_MANIFEST_PROJECTION_MAX_MANIFESTS) {
90
+ return fail('project-manifest-projection-too-many-manifests');
91
+ }
92
+ const seen = new Set();
93
+ let previous;
94
+ for (const entry of value.manifests) {
95
+ if (!isRecord(entry))
96
+ return fail('project-manifest-projection-not-object');
97
+ if (!hasExactKeys(entry, ENTRY_KEYS))
98
+ return fail('project-manifest-projection-unknown-field');
99
+ if (!isProjectManifestPath(entry.path))
100
+ return fail('project-manifest-projection-path-invalid');
101
+ if (seen.has(entry.path))
102
+ return fail('project-manifest-projection-path-duplicate');
103
+ if (previous !== undefined && compareProjectManifestPaths(previous, entry.path) >= 0) {
104
+ return fail('project-manifest-projection-order-invalid');
105
+ }
106
+ seen.add(entry.path);
107
+ previous = entry.path;
108
+ if (typeof entry.packageManager !== 'string'
109
+ || !PROJECT_MANIFEST_PACKAGE_MANAGERS.includes(entry.packageManager)) {
110
+ return fail('project-manifest-projection-package-manager-invalid');
111
+ }
112
+ if (!Array.isArray(entry.scriptNames))
113
+ return fail('project-manifest-projection-script-name-invalid');
114
+ if (entry.scriptNames.length > PROJECT_MANIFEST_PROJECTION_MAX_SCRIPTS) {
115
+ return fail('project-manifest-projection-too-many-scripts');
116
+ }
117
+ let previousName;
118
+ for (const name of entry.scriptNames) {
119
+ if (typeof name !== 'string' || !PROJECT_MANIFEST_PROJECTION_SCRIPT_NAME.test(name)) {
120
+ return fail('project-manifest-projection-script-name-invalid');
121
+ }
122
+ if (previousName !== undefined && previousName >= name) {
123
+ return fail('project-manifest-projection-script-names-unsorted');
124
+ }
125
+ previousName = name;
126
+ }
127
+ }
128
+ return { ok: true, value: value };
129
+ }
130
+ /** Validate a request attachment and its digest binding. */
131
+ export function validateProjectManifestProjectionAttachment(value) {
132
+ if (!isRecord(value))
133
+ return { ok: false, reason: 'project-manifest-projection-not-object' };
134
+ if (!hasExactKeys(value, ATTACHMENT_KEYS))
135
+ return { ok: false, reason: 'project-manifest-projection-unknown-field' };
136
+ const validation = validateProjectManifestProjection(value.projection);
137
+ if (!validation.ok)
138
+ return validation;
139
+ if (typeof value.sha256 !== 'string' || !SHA256.test(value.sha256)
140
+ || projectManifestProjectionSha256(validation.value) !== value.sha256) {
141
+ return { ok: false, reason: 'project-manifest-projection-digest-mismatch' };
142
+ }
143
+ return validation;
144
+ }
145
+ /**
146
+ * Build a frozen, valid projection. Script names outside the public pattern are
147
+ * dropped and counted; names are deduplicated/sorted and capped at 64; manifests
148
+ * are sorted root-first and capped at 16 (excess counted as `overLimit`).
149
+ */
150
+ export function createProjectManifestProjection(input) {
151
+ const omitted = {
152
+ invalidJson: 0, invalidScriptNames: 0, outOfScope: 0, overLimit: 0, oversize: 0, symlink: 0,
153
+ };
154
+ for (const key of PROJECT_MANIFEST_PROJECTION_OMISSION_KEYS) {
155
+ const count = input.omitted?.[key];
156
+ if (count !== undefined) {
157
+ if (!Number.isSafeInteger(count) || count < 0)
158
+ throw new Error('project-manifest-projection-omitted-invalid');
159
+ omitted[key] = count;
160
+ }
161
+ }
162
+ const byPath = new Map();
163
+ for (const entry of input.manifests) {
164
+ if (!isProjectManifestPath(entry.path)) {
165
+ omitted.outOfScope += 1;
166
+ continue;
167
+ }
168
+ if (byPath.has(entry.path))
169
+ continue;
170
+ const valid = [...new Set(entry.scriptNames)].filter((name) => PROJECT_MANIFEST_PROJECTION_SCRIPT_NAME.test(name)).sort();
171
+ omitted.invalidScriptNames += new Set(entry.scriptNames).size - valid.length;
172
+ if (valid.length > PROJECT_MANIFEST_PROJECTION_MAX_SCRIPTS) {
173
+ omitted.invalidScriptNames += valid.length - PROJECT_MANIFEST_PROJECTION_MAX_SCRIPTS;
174
+ }
175
+ byPath.set(entry.path, Object.freeze({
176
+ path: entry.path,
177
+ packageManager: PROJECT_MANIFEST_PACKAGE_MANAGERS.includes(entry.packageManager)
178
+ ? entry.packageManager : 'unknown',
179
+ scriptNames: Object.freeze(valid.slice(0, PROJECT_MANIFEST_PROJECTION_MAX_SCRIPTS)),
180
+ }));
181
+ }
182
+ const sorted = [...byPath.values()].sort((left, right) => compareProjectManifestPaths(left.path, right.path));
183
+ omitted.overLimit += Math.max(0, sorted.length - PROJECT_MANIFEST_PROJECTION_MAX_MANIFESTS);
184
+ const projection = Object.freeze({
185
+ schema: PROJECT_MANIFEST_PROJECTION_SCHEMA,
186
+ manifests: Object.freeze(sorted.slice(0, PROJECT_MANIFEST_PROJECTION_MAX_MANIFESTS)),
187
+ omitted: Object.freeze(omitted),
188
+ });
189
+ const validation = validateProjectManifestProjection(projection);
190
+ if (!validation.ok)
191
+ throw new Error(validation.reason);
192
+ return projection;
193
+ }
194
+ export function createProjectManifestProjectionAttachment(projection) {
195
+ const validation = validateProjectManifestProjection(projection);
196
+ if (!validation.ok)
197
+ throw new Error(validation.reason);
198
+ return Object.freeze({ projection, sha256: projectManifestProjectionSha256(projection) });
199
+ }
@@ -2,6 +2,19 @@
2
2
  * These are planning data, never permission to execute or independent QA.
3
3
  */
4
4
  export const PROJECT_VALIDATION_KINDS = ['unit', 'integration', 'contract', 'bdd-example', 'e2e'];
5
+ /** Literal argv-shaped command: no shell language, quoted substitutions,
6
+ * inline secrets, private URLs or parent-directory traversal. Shared by
7
+ * declared commands and server-derived commands (P226.10). */
8
+ export function isSafeProjectValidationCommand(command) {
9
+ return command.length >= 1 && command.length <= 220
10
+ && /^[A-Za-z0-9_./-]+(?: [A-Za-z0-9_./:@%+=,-]+)*$/.test(command)
11
+ && !/(?:token|password|license_key|secret|credential)=|(?:https?|ssh):\/\/|@[^ /]+\.[A-Za-z]/i.test(command)
12
+ && !command.split(' ').some(arg => arg.split('/').includes('..'));
13
+ }
14
+ /** Reads `## Validation Commands` declarations. A kind that is simply not
15
+ * declared is not an error (P226.10): the planner derives it or records
16
+ * `project-validation-commands-undeclared` debt for that kind only. `invalid`
17
+ * is reserved for malformed, unsafe or conflicting declarations. */
5
18
  export function readProjectValidationCommands(storyId, sources) {
6
19
  const byKind = new Map();
7
20
  let declared = false, invalid = false;
@@ -45,11 +58,8 @@ export function readProjectValidationCommands(storyId, sources) {
45
58
  continue;
46
59
  }
47
60
  const kind = match[1], command = match[2];
48
- // No shell language, quoted substitutions, inline secrets or private URLs.
49
61
  // A command stays a literal argv-shaped string throughout this planner.
50
- if (!/^[A-Za-z0-9_./-]+(?: [A-Za-z0-9_./:@%+=,-]+)*$/.test(command)
51
- || /(?:token|password|license_key|secret|credential)=|(?:https?|ssh):\/\/|@[^ /]+\.[A-Za-z]/i.test(command)
52
- || command.split(' ').some(arg => arg.split('/').includes('..'))) {
62
+ if (!isSafeProjectValidationCommand(command)) {
53
63
  invalid = true;
54
64
  continue;
55
65
  }
@@ -68,7 +78,5 @@ export function readProjectValidationCommands(storyId, sources) {
68
78
  if (active && entries === 0)
69
79
  invalid = true;
70
80
  }
71
- if (declared && !byKind.has('unit'))
72
- invalid = true;
73
81
  return { declared, invalid, commands: [...byKind.values()] };
74
82
  }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * P226.06 named content rules for the YOLO spec envelope.
3
+ *
4
+ * Each rule keeps the exact body and flags of the former single
5
+ * `PROHIBITED_CONTENT` alternative, so every previously blocked input stays
6
+ * blocked. The only exception is an `inline-credential-assignment` whose whole
7
+ * value is a strict placeholder. Findings expose a rule id and a 1-based line,
8
+ * never the matched text.
9
+ */
10
+ export const YOLO_SPEC_ENVELOPE_RULE_IDS = [
11
+ 'private-key-pem',
12
+ 'inline-credential-assignment',
13
+ 'email-address',
14
+ 'vendor-key-prefix',
15
+ 'absolute-home-path',
16
+ ];
17
+ const RULES = [
18
+ { id: 'private-key-pem', source: '-----BEGIN [A-Z ]*PRIVATE KEY-----', priority: 0 },
19
+ { id: 'vendor-key-prefix', source: '\\b(?:sk-|ghp_|github_pat_|npm_)[A-Za-z0-9_-]{12,}\\b', priority: 1 },
20
+ { id: 'inline-credential-assignment', source: '\\b(?:bearer|token|password|secret|api[_-]?key)\\s*[:=]\\s*(\\S+)', priority: 2 },
21
+ { id: 'email-address', source: '\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,}\\b', priority: 3 },
22
+ { id: 'absolute-home-path', source: '(?:^|[\\s"\'(])\\/(?:home|media|root|etc|var|Users)\\/', priority: 4 },
23
+ ];
24
+ /**
25
+ * A whole value that is exactly `<UPPER_SNAKE>`, `${UPPER_SNAKE}` or
26
+ * `{{ identifier }}`, optionally wrapped by one identical pair of quotes or
27
+ * backticks and followed by at most one closing delimiter. Case-sensitive.
28
+ */
29
+ const STRICT_PLACEHOLDER_VALUE = /^(["'`]?)(?:<[A-Z][A-Z0-9_]*>|\$\{[A-Z][A-Z0-9_]*\}|\{\{[ \t]*[A-Za-z_][A-Za-z0-9_.-]*[ \t]*\}\})\1[`"'),;.]?(?=[ \t]|$)/;
30
+ /** True only when the value (rest of its line) starts with a strict placeholder token. */
31
+ export function isStrictYoloSpecPlaceholder(value) {
32
+ const line = value.split('\n', 1)[0] ?? '';
33
+ return STRICT_PLACEHOLDER_VALUE.test(line);
34
+ }
35
+ function lineAt(content, index) {
36
+ let line = 1;
37
+ for (let cursor = content.indexOf('\n'); cursor !== -1 && cursor < index; cursor = content.indexOf('\n', cursor + 1)) {
38
+ line += 1;
39
+ }
40
+ return line;
41
+ }
42
+ function firstFindingIndex(rule, content) {
43
+ const pattern = new RegExp(rule.source, 'gim');
44
+ for (let match = pattern.exec(content); match; match = pattern.exec(content)) {
45
+ if (rule.id === 'inline-credential-assignment') {
46
+ const value = match[1] ?? '';
47
+ const valueStart = match.index + match[0].length - value.length;
48
+ if (isStrictYoloSpecPlaceholder(content.slice(valueStart))) {
49
+ // Re-scan from the next character so an overlapping assignment is never hidden.
50
+ pattern.lastIndex = match.index + 1;
51
+ continue;
52
+ }
53
+ }
54
+ const leading = /^\s*/.exec(match[0])?.[0].length ?? 0;
55
+ return match.index + leading;
56
+ }
57
+ return null;
58
+ }
59
+ /**
60
+ * Return the reported prohibited-content finding for normalized content, or
61
+ * `null`. Lowest line wins; same-line ties follow rule priority.
62
+ */
63
+ export function findYoloSpecProhibitedContent(content) {
64
+ let best = null;
65
+ for (const rule of RULES) {
66
+ const index = firstFindingIndex(rule, content);
67
+ if (index === null)
68
+ continue;
69
+ const line = lineAt(content, index);
70
+ if (!best || line < best.line || (line === best.line && rule.priority < best.priority)) {
71
+ best = { ruleId: rule.id, line, priority: rule.priority };
72
+ }
73
+ }
74
+ return best ? { ruleId: best.ruleId, line: best.line } : null;
75
+ }
76
+ const UNSAFE_REASON_CODE = new RegExp(`^yolo-spec-envelope-unsafe:(?:${YOLO_SPEC_ENVELOPE_RULE_IDS.join('|')}):[A-Za-z0-9_./-]{1,240}:[1-9][0-9]{0,8}$`);
77
+ /** `yolo-spec-envelope-unsafe:<rule>:<path>:<line>`; callers pass an allow-listed relative path. */
78
+ export function yoloSpecEnvelopeUnsafeReasonCode(ruleId, path, line) {
79
+ const code = `yolo-spec-envelope-unsafe:${ruleId}:${path}:${line}`;
80
+ return UNSAFE_REASON_CODE.test(code) ? code : 'yolo-spec-envelope-unsafe';
81
+ }
82
+ /** Strict recognizer for the qualified unsafe reason code. */
83
+ export function isYoloSpecEnvelopeUnsafeReasonCode(value) {
84
+ return typeof value === 'string' && UNSAFE_REASON_CODE.test(value);
85
+ }