@ornexus/neocortex 4.60.73 → 4.60.75

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 (269) hide show
  1. package/dist/release-source.json +1 -1
  2. package/dist/sbom.cdx.json +1216 -1210
  3. package/install.ps1 +1 -1
  4. package/install.sh +1 -1
  5. package/package.json +2 -2
  6. package/packages/client/dist/adapters/adapter-registry.js +1 -108
  7. package/packages/client/dist/adapters/antigravity-adapter.js +2 -77
  8. package/packages/client/dist/adapters/claude-code-adapter.js +3 -79
  9. package/packages/client/dist/adapters/codex-adapter.js +2 -80
  10. package/packages/client/dist/adapters/cursor-adapter.js +4 -115
  11. package/packages/client/dist/adapters/gemini-adapter.js +2 -71
  12. package/packages/client/dist/adapters/grok-adapter.js +2 -42
  13. package/packages/client/dist/adapters/index.js +1 -22
  14. package/packages/client/dist/adapters/platform-detector.js +1 -212
  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 -417
  18. package/packages/client/dist/agent/update-agent-yaml.js +1 -102
  19. package/packages/client/dist/agent/update-description.js +1 -251
  20. package/packages/client/dist/cache/crypto-utils.js +1 -78
  21. package/packages/client/dist/cache/encrypted-cache.d.ts +27 -0
  22. package/packages/client/dist/cache/encrypted-cache.js +1 -108
  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 -358
  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 +38 -1
  39. package/packages/client/dist/commands/invoke.js +143 -7200
  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 -156
  75. package/packages/client/dist/commands/shared-architecture-non-ui.js +1 -24
  76. package/packages/client/dist/commands/story-checkpoint.js +1 -171
  77. package/packages/client/dist/config/host-auth-broker.d.ts +31 -0
  78. package/packages/client/dist/config/host-auth-broker.js +1 -0
  79. package/packages/client/dist/config/host-auth-reference.d.ts +32 -0
  80. package/packages/client/dist/config/host-auth-reference.js +1 -0
  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 -223
  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.d.ts +11 -0
  99. package/packages/client/dist/continuity/native-agent-types.js +1 -90
  100. package/packages/client/dist/continuity/outbox.js +1 -117
  101. package/packages/client/dist/continuity/runner-bootstrap-policy.js +1 -172
  102. package/packages/client/dist/continuity/sqlite-store.js +81 -2612
  103. package/packages/client/dist/effects/invoke-effect-gateways.js +1 -62
  104. package/packages/client/dist/errors/error-messages.d.ts +3 -0
  105. package/packages/client/dist/errors/error-messages.js +2 -228
  106. package/packages/client/dist/errors/frontmatter-diagnostics.js +1 -125
  107. package/packages/client/dist/evidence/collector.js +1 -347
  108. package/packages/client/dist/evidence/index.js +1 -1
  109. package/packages/client/dist/evidence/types.js +0 -2
  110. package/packages/client/dist/fs/atomic-state-replace.js +1 -152
  111. package/packages/client/dist/generated/command-registry.generated.js +1 -4076
  112. package/packages/client/dist/generated/public-projections.generated.js +1 -149
  113. package/packages/client/dist/git/direct-yolo-c01-retry.js +4 -138
  114. package/packages/client/dist/git/direct-yolo-checkpoint.d.ts +11 -1
  115. package/packages/client/dist/git/direct-yolo-checkpoint.js +4 -1234
  116. package/packages/client/dist/git/epic-operational-state.js +2 -672
  117. package/packages/client/dist/git/git-lifecycle-step-ids.js +1 -14
  118. package/packages/client/dist/git/git-lifecycle-store.d.ts +23 -0
  119. package/packages/client/dist/git/git-lifecycle-store.js +10 -1981
  120. package/packages/client/dist/git/legacy-story-branch-checkpoint.js +9 -259
  121. package/packages/client/dist/git/legacy-story-branch-setup.js +4 -348
  122. package/packages/client/dist/git/legacy-story-pr.js +70 -3538
  123. package/packages/client/dist/git/secure-filesystem-boundary.js +5 -182
  124. package/packages/client/dist/graph-retrieval/pre-command-hook.js +1 -284
  125. package/packages/client/dist/graph-retrieval/shared-graph-retrieval-contract.js +1 -237
  126. package/packages/client/dist/i18n/first-run.js +2 -60
  127. package/packages/client/dist/index.d.ts +2 -0
  128. package/packages/client/dist/index.js +1 -47
  129. package/packages/client/dist/invocation/invoke-input.js +1 -24
  130. package/packages/client/dist/license/host-auth-recovery.d.ts +158 -0
  131. package/packages/client/dist/license/host-auth-recovery.js +1 -0
  132. package/packages/client/dist/license/index.js +1 -5
  133. package/packages/client/dist/license/license-client.d.ts +10 -1
  134. package/packages/client/dist/license/license-client.js +1 -304
  135. package/packages/client/dist/machine/fingerprint.js +2 -163
  136. package/packages/client/dist/machine/index.js +1 -5
  137. package/packages/client/dist/memory/project-memory-path-scope.js +1 -62
  138. package/packages/client/dist/memory/project-memory-writer.js +40 -1007
  139. package/packages/client/dist/memory/shared-project-memory-types.js +2 -253
  140. package/packages/client/dist/migrations/epic-lifecycle-backfill.js +3 -1060
  141. package/packages/client/dist/migrations/project-identity-capability.js +1 -50
  142. package/packages/client/dist/migrations/project-identity.js +7 -493
  143. package/packages/client/dist/migrations/state-json.js +4 -393
  144. package/packages/client/dist/policy/architecture-policy.js +2 -184
  145. package/packages/client/dist/policy/index.js +1 -7
  146. package/packages/client/dist/policy/shared-policy-types.js +0 -38
  147. package/packages/client/dist/policy/subagent-approval-policy.js +1 -55
  148. package/packages/client/dist/private-execution/clean-baseline.js +2 -279
  149. package/packages/client/dist/private-execution/codex-executor.js +4 -574
  150. package/packages/client/dist/private-execution/codex-host-runtime.js +1 -137
  151. package/packages/client/dist/private-execution/codex-lifecycle-guard.js +1 -97
  152. package/packages/client/dist/private-execution/codex-scoped-permissions.js +1 -128
  153. package/packages/client/dist/private-execution/delivery.js +13 -410
  154. package/packages/client/dist/private-execution/diagnosis-root-review.js +2 -294
  155. package/packages/client/dist/private-execution/frozen-handoff.js +6 -19
  156. package/packages/client/dist/private-execution/implementation-validation.js +2 -106
  157. package/packages/client/dist/private-execution/isolated-admission.js +23 -1432
  158. package/packages/client/dist/private-execution/isolated-session.js +5 -725
  159. package/packages/client/dist/private-execution/isolated-workspace.js +1 -122
  160. package/packages/client/dist/private-execution/pact-consumer-runtime.js +3 -409
  161. package/packages/client/dist/private-execution/pact-test-source.js +1 -258
  162. package/packages/client/dist/private-execution/pact-toolchain.js +3 -290
  163. package/packages/client/dist/private-execution/pact-write-set.js +1 -172
  164. package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +5 -406
  165. package/packages/client/dist/private-execution/planning-generation-checkpoint.js +5 -462
  166. package/packages/client/dist/private-execution/planning-memory-checkpoint.js +3 -139
  167. package/packages/client/dist/private-execution/planning-research-checkpoint.js +4 -325
  168. package/packages/client/dist/private-execution/private-report-store.js +1 -42
  169. package/packages/client/dist/private-execution/property-test-candidate.js +1 -103
  170. package/packages/client/dist/private-execution/property-test-choices.js +3 -147
  171. package/packages/client/dist/private-execution/property-test-plan.js +7 -271
  172. package/packages/client/dist/private-execution/property-test-review.js +4 -258
  173. package/packages/client/dist/private-execution/property-test-runtime.js +9 -372
  174. package/packages/client/dist/private-execution/property-test-source.js +1 -139
  175. package/packages/client/dist/private-execution/root-checkpoint.js +1 -80
  176. package/packages/client/dist/private-execution/root-memory-git-evidence.js +3 -135
  177. package/packages/client/dist/private-execution/root-memory-recovery.js +1 -93
  178. package/packages/client/dist/private-execution/root-memory-request.js +1 -29
  179. package/packages/client/dist/private-execution/root-memory-scope.js +1 -178
  180. package/packages/client/dist/private-execution/root-memory-writer.js +1 -102
  181. package/packages/client/dist/private-execution/session-lease.js +1 -63
  182. package/packages/client/dist/private-execution/shared-private-admission-types.js +1 -50
  183. package/packages/client/dist/private-execution/shared-project-validation.js +1 -66
  184. package/packages/client/dist/private-execution/shared-root-memory-types.js +1 -61
  185. package/packages/client/dist/private-execution/ux-source-validation.js +1 -372
  186. package/packages/client/dist/private-execution/ux-write-set.js +2 -191
  187. package/packages/client/dist/registry/registry-reconciliation.js +1 -234
  188. package/packages/client/dist/resilience/circuit-breaker.js +1 -170
  189. package/packages/client/dist/resilience/degradation-manager.js +1 -164
  190. package/packages/client/dist/resilience/freshness-indicator.js +1 -100
  191. package/packages/client/dist/resilience/index.js +1 -8
  192. package/packages/client/dist/resilience/recovery-detector.js +1 -74
  193. package/packages/client/dist/resolvers/asset-resolver.js +0 -13
  194. package/packages/client/dist/resolvers/local-resolver.js +8 -255
  195. package/packages/client/dist/resolvers/remote-resolver.js +1 -233
  196. package/packages/client/dist/runner/binary.js +1 -404
  197. package/packages/client/dist/runner/cli.js +17 -1571
  198. package/packages/client/dist/runner/epic-background-dispatcher.d.ts +61 -0
  199. package/packages/client/dist/runner/epic-background-dispatcher.js +1 -0
  200. package/packages/client/dist/runner/headless/adapters.js +1 -49
  201. package/packages/client/dist/runner/headless/background-root.d.ts +65 -0
  202. package/packages/client/dist/runner/headless/background-root.js +1 -0
  203. package/packages/client/dist/runner/headless/claude-code-adapter.js +1 -79
  204. package/packages/client/dist/runner/headless/continuous-story-workspace.js +11 -1628
  205. package/packages/client/dist/runner/headless/epic-git-reconciliation-inventory.js +1 -69
  206. package/packages/client/dist/runner/headless/epic-merge-candidate-qa.d.ts +1 -1
  207. package/packages/client/dist/runner/headless/epic-merge-candidate-qa.js +2 -110
  208. package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.d.ts +2 -0
  209. package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +10 -1236
  210. package/packages/client/dist/runner/headless/epic-terminal-git-runner.d.ts +27 -2
  211. package/packages/client/dist/runner/headless/epic-terminal-git-runner.js +2 -318
  212. package/packages/client/dist/runner/headless/fake-adapter.js +1 -62
  213. package/packages/client/dist/runner/headless/managed-environment-cleanup.d.ts +95 -0
  214. package/packages/client/dist/runner/headless/managed-environment-cleanup.js +1 -0
  215. package/packages/client/dist/runner/headless/managed-profile.js +1 -132
  216. package/packages/client/dist/runner/headless/opencode-adapter.js +2 -145
  217. package/packages/client/dist/runner/headless/prepared-story-bundle.js +1 -43
  218. package/packages/client/dist/runner/headless/resolver.js +1 -231
  219. package/packages/client/dist/runner/headless/run-yolo.js +1 -885
  220. package/packages/client/dist/runner/headless/run-yoloop.d.ts +1 -0
  221. package/packages/client/dist/runner/headless/run-yoloop.js +2 -2574
  222. package/packages/client/dist/runner/headless/types.js +2 -574
  223. package/packages/client/dist/runner/local-console.js +13 -396
  224. package/packages/client/dist/runner/portal-sync-worker.js +1 -1487
  225. package/packages/client/dist/runner/project-identity.js +1 -106
  226. package/packages/client/dist/runner/scheduler.js +7 -995
  227. package/packages/client/dist/runner-cli.js +2 -18
  228. package/packages/client/dist/state/invocation-shape.js +1 -13
  229. package/packages/client/dist/state/project-state-snapshot.d.ts +7 -0
  230. package/packages/client/dist/state/project-state-snapshot.js +1 -1731
  231. package/packages/client/dist/state/state-json-repair.js +3 -785
  232. package/packages/client/dist/state/structural-dag-projection.js +1 -118
  233. package/packages/client/dist/telemetry/index.js +1 -5
  234. package/packages/client/dist/telemetry/offline-queue.js +1 -131
  235. package/packages/client/dist/tier/index.js +1 -5
  236. package/packages/client/dist/tier/tier-aware-client.js +1 -405
  237. package/packages/client/dist/types/index.js +1 -38
  238. package/packages/client/dist/version.js +1 -27
  239. package/packages/client/dist/yolo/change-evidence-collector.d.ts +21 -1
  240. package/packages/client/dist/yolo/change-evidence-collector.js +1 -126
  241. package/packages/client/dist/yolo/invoke-envelope-capability.js +1 -62
  242. package/packages/client/dist/yolo/spec-envelope-collector.js +5 -184
  243. package/packages/client/dist/yoloop/discovery-hook.js +2 -300
  244. package/packages/client/dist/yoloop/index.js +1 -8
  245. package/packages/client/dist/yoloop/invoke-hooks.js +12 -669
  246. package/packages/client/dist/yoloop/shared-discover-epics.js +1 -1007
  247. package/packages/client/dist/yoloop/shared-yoloop-types.js +1 -33
  248. package/packages/client/dist/yoloop/target-normalization.js +1 -180
  249. package/packages/client/dist/yoloop/yoloop-client-state-store.js +1 -1920
  250. package/packages/shared/dist/invocation/explicit-intent-recovery.d.ts +83 -0
  251. package/packages/shared/dist/invocation/explicit-intent-recovery.js +187 -0
  252. package/packages/shared/dist/invocation/index.d.ts +7 -0
  253. package/packages/shared/dist/invocation/index.js +22 -0
  254. package/packages/shared/dist/yolo/change-evidence.js +1 -1
  255. package/packages/shared/dist/yoloop/epic-terminal-git.js +144 -2
  256. package/targets-stubs/antigravity/gemini.md +1 -1
  257. package/targets-stubs/antigravity/skill/SKILL.md +1 -1
  258. package/targets-stubs/claude-code/neocortex-root.agent.yaml +1 -1
  259. package/targets-stubs/claude-code/neocortex-root.md +2 -2
  260. package/targets-stubs/claude-code/neocortex.agent.yaml +1 -1
  261. package/targets-stubs/claude-code/neocortex.md +2 -2
  262. package/targets-stubs/codex/AGENTS.md +24 -21
  263. package/targets-stubs/codex/README.md +6 -1
  264. package/targets-stubs/codex/neocortex.toml +7 -2
  265. package/targets-stubs/cursor/agent.md +2 -2
  266. package/targets-stubs/gemini-cli/agent.md +2 -2
  267. package/targets-stubs/opencode/neocortex-root.md +16 -1
  268. package/targets-stubs/opencode/neocortex.md +6 -0
  269. package/targets-stubs/vscode/neocortex.agent.md +2 -2
@@ -1,372 +1 @@
1
- /**
2
- * Static, non-executing A08 admission screen. Passing this check admits a
3
- * candidate patch only; schema validation, Storybook, play and a11y execution
4
- * still require separate root-owned evidence before A08 can complete.
5
- */
6
- import { parse } from '@babel/parser';
7
- import { lstatSync, readFileSync } from 'node:fs';
8
- import { join, posix } from 'node:path';
9
- const MAX_FILE_BYTES = 1024 * 1024;
10
- const MAX_AST_NODES = 100_000;
11
- const SAFE_ID = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
12
- function fail() { throw new Error('private-execution-ux-source-unverified'); }
13
- function object(value) {
14
- return value !== null && typeof value === 'object' && !Array.isArray(value);
15
- }
16
- function source(root, path) {
17
- const stat = lstatSync(join(root, path));
18
- if (!stat.isFile() || stat.isSymbolicLink() || stat.size < 1 || stat.size > MAX_FILE_BYTES)
19
- fail();
20
- const text = new TextDecoder('utf-8', { fatal: true }).decode(readFileSync(join(root, path)));
21
- if (!text.trim() || text.includes('\0'))
22
- fail();
23
- return text;
24
- }
25
- function ast(root, path) {
26
- const parsed = parse(source(root, path), { sourceType: 'module',
27
- plugins: ['typescript', 'jsx'], errorRecovery: false });
28
- let count = 0;
29
- const pending = [parsed];
30
- while (pending.length > 0) {
31
- const value = pending.pop();
32
- if (!object(value))
33
- continue;
34
- if (++count > MAX_AST_NODES)
35
- fail();
36
- for (const [key, child] of Object.entries(value)) {
37
- if (key === 'loc' || key === 'tokens' || key === 'comments' || key === 'errors')
38
- continue;
39
- if (Array.isArray(child))
40
- pending.push(...child);
41
- else if (object(child))
42
- pending.push(child);
43
- }
44
- }
45
- return parsed;
46
- }
47
- function body(tree) {
48
- const program = tree.program;
49
- if (!object(program) || !Array.isArray(program.body))
50
- fail();
51
- return program.body.filter(object);
52
- }
53
- function prop(value, name) {
54
- if (!object(value) || value.type !== 'ObjectExpression' || !Array.isArray(value.properties))
55
- return undefined;
56
- const matches = value.properties.filter((entry) => object(entry)
57
- && entry.type === 'ObjectProperty' && entry.computed !== true && object(entry.key)
58
- && (entry.key.name === name || entry.key.value === name));
59
- return matches.length === 1 && object(matches[0]) ? matches[0].value : undefined;
60
- }
61
- function literal(value) {
62
- return object(value) && value.type === 'StringLiteral' && typeof value.value === 'string'
63
- ? value.value : undefined;
64
- }
65
- function identifier(value) {
66
- return object(value) && value.type === 'Identifier' && typeof value.name === 'string'
67
- ? value.name : undefined;
68
- }
69
- function declarations(node) {
70
- return node.type === 'VariableDeclaration' && Array.isArray(node.declarations)
71
- ? node.declarations.filter(object) : [];
72
- }
73
- function unwrap(value) {
74
- let current = value;
75
- for (let index = 0; index < 4 && object(current)
76
- && ['TSAsExpression', 'TSSatisfiesExpression', 'TSTypeAssertion', 'ParenthesizedExpression']
77
- .includes(String(current.type)); index++)
78
- current = current.expression;
79
- return current;
80
- }
81
- function localVariable(statements, name) {
82
- const matches = statements.flatMap(declarations)
83
- .filter((item) => identifier(item.id) === name);
84
- return matches.length === 1 ? unwrap(matches[0].init) : undefined;
85
- }
86
- function exported(root, name) {
87
- for (const statement of root) {
88
- if (statement.type !== 'ExportNamedDeclaration' || !object(statement.declaration))
89
- continue;
90
- const declaration = statement.declaration;
91
- if (declaration.type === 'FunctionDeclaration' && object(declaration.id)
92
- && declaration.id.name === name)
93
- return declaration;
94
- const variable = declarations(declaration).find((item) => object(item.id) && item.id.name === name);
95
- if (variable)
96
- return unwrap(variable.init);
97
- }
98
- return undefined;
99
- }
100
- function nodes(value, type) {
101
- const found = [];
102
- const pending = [value];
103
- while (pending.length > 0) {
104
- const current = pending.pop();
105
- if (!object(current))
106
- continue;
107
- if (current.type === type)
108
- found.push(current);
109
- for (const [key, child] of Object.entries(current)) {
110
- if (key === 'loc' || key === 'comments')
111
- continue;
112
- if (Array.isArray(child))
113
- pending.push(...child);
114
- else if (object(child))
115
- pending.push(child);
116
- }
117
- }
118
- return found;
119
- }
120
- function stem(screen) {
121
- return screen.screenId.toLowerCase().replace(/[^a-z0-9]+/g, '-')
122
- .replace(/^-+|-+$/g, '').slice(0, 64);
123
- }
124
- function pascal(value) {
125
- return value.split(/[^A-Za-z0-9]+/).filter(Boolean)
126
- .map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1).toLowerCase()}`).join('');
127
- }
128
- function importsView(statements, fromPath, screen) {
129
- const matched = [];
130
- for (const statement of statements) {
131
- if (statement.type !== 'ImportDeclaration' || statement.importKind === 'type'
132
- || !object(statement.source) || typeof statement.source.value !== 'string'
133
- || !statement.source.value.startsWith('./') && !statement.source.value.startsWith('../'))
134
- continue;
135
- const resolved = posix.normalize(posix.join(posix.dirname(fromPath), statement.source.value));
136
- if (resolved !== screen.screenViewPath && resolved !== screen.screenViewPath.replace(/\.tsx$/, ''))
137
- continue;
138
- for (const specifier of Array.isArray(statement.specifiers) ? statement.specifiers : []) {
139
- if (object(specifier) && specifier.type === 'ImportSpecifier'
140
- && object(specifier.imported) && specifier.imported.name === screen.screenViewExport
141
- && specifier.importKind !== 'type' && object(specifier.local)
142
- && typeof specifier.local.name === 'string')
143
- matched.push(specifier.local.name);
144
- }
145
- }
146
- if (matched.length !== 1)
147
- fail();
148
- return matched[0];
149
- }
150
- function hasJsx(tree, name) {
151
- return nodes(tree, 'JSXOpeningElement').some((item) => object(item.name) && item.name.name === name);
152
- }
153
- function importedName(statements, module, name) {
154
- const matches = statements.filter((item) => item.type === 'ImportDeclaration'
155
- && object(item.source) && item.source.value === module)
156
- .flatMap((item) => Array.isArray(item.specifiers) ? item.specifiers : [])
157
- .filter((item) => object(item) && item.type === 'ImportSpecifier'
158
- && object(item.imported) && item.imported.name === name && object(item.local)
159
- && typeof item.local.name === 'string')
160
- .map((item) => item.local);
161
- return matches.length === 1 ? matches[0].name : undefined;
162
- }
163
- function calledMember(value, objectName, memberName) {
164
- return object(value) && value.type === 'CallExpression' && object(value.callee)
165
- && value.callee.type === 'MemberExpression' && value.callee.computed !== true
166
- && identifier(value.callee.object) === objectName
167
- && identifier(value.callee.property) === memberName;
168
- }
169
- /** A syntactic interaction contract, never a substitute for executing Storybook play. */
170
- function hasCanvasKeyboardAssertion(play, statements) {
171
- const withinName = importedName(statements, 'storybook/test', 'within');
172
- const userEventName = importedName(statements, 'storybook/test', 'userEvent');
173
- const expectName = importedName(statements, 'storybook/test', 'expect');
174
- if (!withinName || !userEventName || !expectName || !Array.isArray(play.params)
175
- || !object(play.params[0]) || play.params[0].type !== 'ObjectPattern'
176
- || !Array.isArray(play.params[0].properties)
177
- || !play.params[0].properties.some((item) => object(item)
178
- && object(item.key) && item.key.name === 'canvasElement'
179
- && object(item.value) && item.value.name === 'canvasElement'))
180
- return false;
181
- const variables = nodes(play.body, 'VariableDeclarator');
182
- const canvasNames = variables.filter((item) => object(item.init)
183
- && item.init.type === 'CallExpression' && identifier(item.init.callee) === withinName
184
- && Array.isArray(item.init.arguments) && item.init.arguments.length === 1
185
- && identifier(item.init.arguments[0]) === 'canvasElement')
186
- .map((item) => identifier(item.id)).filter((name) => !!name);
187
- const actionNames = variables.filter((item) => canvasNames.some((name) => calledMember(item.init, name, 'getByRole') && Array.isArray(item.init.arguments)
188
- && literal(item.init.arguments[0]) === 'button'
189
- && typeof literal(prop(item.init.arguments[1], 'name')) === 'string'
190
- && !!literal(prop(item.init.arguments[1], 'name'))?.trim()))
191
- .map((item) => identifier(item.id)).filter((name) => !!name);
192
- if (actionNames.length === 0)
193
- return false;
194
- const awaited = nodes(play.body, 'AwaitExpression').map((item) => item.argument);
195
- const tabbed = awaited.some((value) => calledMember(value, userEventName, 'tab')
196
- && Array.isArray(value.arguments) && value.arguments.length === 0);
197
- const focused = awaited.some((value) => object(value) && value.type === 'CallExpression'
198
- && object(value.callee) && value.callee.type === 'MemberExpression'
199
- && identifier(value.callee.property) === 'toHaveFocus'
200
- && object(value.callee.object) && value.callee.object.type === 'CallExpression'
201
- && identifier(value.callee.object.callee) === expectName
202
- && Array.isArray(value.callee.object.arguments)
203
- && actionNames.includes(identifier(value.callee.object.arguments[0]) ?? ''));
204
- return tabbed && focused;
205
- }
206
- function verifyScreen(root, screen, adapterId) {
207
- const base = `src/screens/${stem(screen)}/${stem(screen)}`;
208
- const view = ast(root, screen.screenViewPath);
209
- const component = exported(body(view), screen.screenViewExport);
210
- if (!component || nodes(component, 'JSXElement').length + nodes(component, 'JSXFragment').length === 0)
211
- fail();
212
- const route = ast(root, screen.appRoutePath);
213
- const routeName = importsView(body(route), screen.appRoutePath, screen);
214
- if (!hasJsx(route, routeName))
215
- fail();
216
- const storiesPath = `${base}.stories.tsx`;
217
- const stories = ast(root, storiesPath);
218
- const storyStatements = body(stories);
219
- const adapterModule = adapterId === 'storybook-react-vite'
220
- ? '@storybook/react-vite' : '@storybook/nextjs-vite';
221
- if (!importedName(storyStatements, adapterModule, 'Meta')
222
- || !importedName(storyStatements, adapterModule, 'StoryObj'))
223
- fail();
224
- const storyViewName = importsView(storyStatements, storiesPath, screen);
225
- const defaults = storyStatements.filter((item) => item.type === 'ExportDefaultDeclaration');
226
- if (defaults.length !== 1)
227
- fail();
228
- const defaultValue = unwrap(defaults[0].declaration);
229
- const meta = identifier(defaultValue) ? localVariable(storyStatements, identifier(defaultValue))
230
- : defaultValue;
231
- if (identifier(prop(meta, 'component')) !== storyViewName
232
- || literal(prop(meta, 'title')) !== `Screens/${screen.screenId}`)
233
- fail();
234
- const expected = new Set();
235
- for (const state of screen.states)
236
- for (const viewport of screen.viewports) {
237
- const name = `${pascal(state)}${pascal(viewport)}`;
238
- expected.add(name);
239
- const story = exported(storyStatements, name);
240
- if (!object(story) || story.type !== 'ObjectExpression'
241
- || literal(prop(prop(story, 'args'), 'state')) !== state
242
- || literal(prop(prop(prop(story, 'parameters'), 'viewport'), 'defaultViewport')) !== viewport)
243
- fail();
244
- if (screen.critical && (state === 'success' || state === 'recovery')) {
245
- const play = prop(story, 'play');
246
- if (!object(play) || !['ArrowFunctionExpression', 'FunctionExpression'].includes(String(play.type))
247
- || !hasCanvasKeyboardAssertion(play, storyStatements))
248
- fail();
249
- }
250
- }
251
- const namedExports = storyStatements.filter((item) => item.type === 'ExportNamedDeclaration');
252
- if (namedExports.some((item) => !object(item.declaration)
253
- || declarations(item.declaration).length !== 1
254
- || Array.isArray(item.specifiers) && item.specifiers.length > 0))
255
- fail();
256
- const actual = namedExports.flatMap((item) => declarations(item.declaration))
257
- .map((item) => identifier(item.id)).filter((name) => !!name);
258
- if (actual.length !== expected.size || actual.some((name) => !expected.has(name)))
259
- fail();
260
- const fixture = ast(root, `${base}.fixtures.ts`);
261
- const fixtures = body(fixture).filter((item) => item.type === 'ExportNamedDeclaration')
262
- .flatMap((item) => object(item.declaration) ? declarations(item.declaration) : []);
263
- if (!fixtures.some((item) => {
264
- const synthetic = prop(item.init, 'synthetic');
265
- return object(synthetic) && synthetic.type === 'BooleanLiteral'
266
- && synthetic.value === true && prop(item.init, 'data') !== undefined;
267
- }))
268
- fail();
269
- const handlers = ast(root, `${base}.handlers.ts`);
270
- const handlerBody = body(handlers);
271
- if (!handlerBody.some((item) => item.type === 'ImportDeclaration'
272
- && object(item.source) && item.source.value === 'msw'
273
- && Array.isArray(item.specifiers) && item.specifiers.some((specifier) => object(specifier)
274
- && object(specifier.imported) && specifier.imported.name === 'http'))
275
- || !handlerBody.some((item) => item.type === 'ExportNamedDeclaration'
276
- && object(item.declaration) && declarations(item.declaration).some((decl) => object(decl.init)
277
- && decl.init.type === 'ArrayExpression' && Array.isArray(decl.init.elements)
278
- && decl.init.elements.length > 0))
279
- || !nodes(handlers, 'CallExpression').some((call) => object(call.callee)
280
- && call.callee.type === 'MemberExpression' && object(call.callee.object)
281
- && call.callee.object.name === 'http'))
282
- fail();
283
- const mdx = source(root, `${base}.mdx`);
284
- const mdxStoryImport = new RegExp(`import\\s+\\*\\s+as\\s+([A-Za-z_$][\\w$]*)\\s+from\\s+['"]\\./${stem(screen)}\\.stories(?:\\.tsx)?['"];?\\r?\\n(?:[ \\t]*\\r?\\n)+`)
285
- .exec(mdx);
286
- if (!/import\s+\{\s*Meta\s*\}\s+from\s+['"]@storybook\/addon-docs\/blocks['"]/.test(mdx)
287
- || !mdxStoryImport || !mdx.includes(`<Meta of={${mdxStoryImport[1]}} />`))
288
- fail();
289
- }
290
- function stableSerialize(value) {
291
- if (Array.isArray(value))
292
- return `[${value.map(stableSerialize).join(',')}]`;
293
- if (value && typeof value === 'object')
294
- return `{${Object.entries(value)
295
- .sort(([left], [right]) => left.localeCompare(right))
296
- .map(([key, nested]) => `${JSON.stringify(key)}:${stableSerialize(nested)}`).join(',')}}`;
297
- return JSON.stringify(value) ?? 'null';
298
- }
299
- function fingerprint(entries) {
300
- const serialized = stableSerialize(entries);
301
- let hash = 0x811c9dc5;
302
- for (let index = 0; index < serialized.length; index++) {
303
- hash ^= serialized.charCodeAt(index);
304
- hash = Math.imul(hash, 0x01000193);
305
- }
306
- return `uxm-${(hash >>> 0).toString(16).padStart(8, '0')}`;
307
- }
308
- function verifyManifest(root, writeSet) {
309
- let manifest;
310
- try {
311
- manifest = JSON.parse(source(root, 'docs/architecture/ux-coverage-manifest.json'));
312
- }
313
- catch {
314
- fail();
315
- }
316
- if (!object(manifest) || manifest.schemaVersion !== 1
317
- || manifest.manifestId !== 'P201-UX-MANIFEST-01'
318
- || !Array.isArray(manifest.entries) || typeof manifest.fingerprint !== 'string'
319
- || Object.keys(manifest).sort().join(',') !== 'entries,fingerprint,manifestId,schemaVersion'
320
- || manifest.fingerprint !== fingerprint(manifest.entries))
321
- fail();
322
- const expected = new Map();
323
- for (const screen of writeSet.screens)
324
- for (const state of screen.states)
325
- for (const viewport of screen.viewports) {
326
- expected.set(`Screens/${screen.screenId}/${state}/${viewport}`, { screen, state, viewport });
327
- }
328
- if (manifest.entries.length !== expected.size)
329
- fail();
330
- const seen = new Set();
331
- let prior = '';
332
- for (const row of manifest.entries) {
333
- if (!object(row) || typeof row.storyId !== 'string' || seen.has(row.storyId))
334
- fail();
335
- if (prior && prior.localeCompare(row.storyId) >= 0)
336
- fail();
337
- prior = row.storyId;
338
- if (Object.keys(row).sort().join(',') !== 'approvalEvidenceIds,fixtureId,handlerIds,journeyIds,screenId,screenViewPath,state,storyId,viewport')
339
- fail();
340
- seen.add(row.storyId);
341
- const match = expected.get(row.storyId);
342
- if (!match || row.screenId !== match.screen.screenId || row.state !== match.state
343
- || row.viewport !== match.viewport || row.screenViewPath !== match.screen.screenViewPath
344
- || !Array.isArray(row.approvalEvidenceIds)
345
- || stableSerialize([...row.approvalEvidenceIds].sort())
346
- !== stableSerialize([...match.screen.approvalEvidenceIds].sort())
347
- || !Array.isArray(row.journeyIds) || row.journeyIds.length < 1
348
- || row.journeyIds.some((id) => typeof id !== 'string' || !SAFE_ID.test(id))
349
- || new Set(row.journeyIds).size !== row.journeyIds.length
350
- || typeof row.fixtureId !== 'string' || !SAFE_ID.test(row.fixtureId)
351
- || !Array.isArray(row.handlerIds) || row.handlerIds.length < 1
352
- || row.handlerIds.some((id) => typeof id !== 'string' || !SAFE_ID.test(id))
353
- || new Set(row.handlerIds).size !== row.handlerIds.length)
354
- fail();
355
- }
356
- }
357
- export function validateUxCandidateSource(projectRoot, writeSet) {
358
- try {
359
- for (const [path, marker] of [
360
- ['docs/architecture/ux-design.md', 'P201-UX-STORYBOOK-01'],
361
- ['docs/architecture/storybook-ux-contract.md', 'P201-UX-STORYBOOK-01'],
362
- ])
363
- if (!source(projectRoot, path).includes(marker))
364
- fail();
365
- for (const screen of writeSet.screens)
366
- verifyScreen(projectRoot, screen, writeSet.adapterId);
367
- verifyManifest(projectRoot, writeSet);
368
- }
369
- catch {
370
- fail();
371
- }
372
- }
1
+ import{parse as H}from"@babel/parser";import{lstatSync as q,readFileSync as G}from"node:fs";import{join as K,posix as V}from"node:path";const Q=1024*1024,ee=1e5,z=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;function p(){throw new Error("private-execution-ux-source-unverified")}function o(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function j(e,t){const r=q(K(e,t));(!r.isFile()||r.isSymbolicLink()||r.size<1||r.size>Q)&&p();const s=new TextDecoder("utf-8",{fatal:!0}).decode(G(K(e,t)));return(!s.trim()||s.includes("\0"))&&p(),s}function I(e,t){const r=H(j(e,t),{sourceType:"module",plugins:["typescript","jsx"],errorRecovery:!1});let s=0;const i=[r];for(;i.length>0;){const l=i.pop();if(o(l)){++s>ee&&p();for(const[n,f]of Object.entries(l))n==="loc"||n==="tokens"||n==="comments"||n==="errors"||(Array.isArray(f)?i.push(...f):o(f)&&i.push(f))}}return r}function E(e){const t=e.program;return(!o(t)||!Array.isArray(t.body))&&p(),t.body.filter(o)}function m(e,t){if(!o(e)||e.type!=="ObjectExpression"||!Array.isArray(e.properties))return;const r=e.properties.filter(s=>o(s)&&s.type==="ObjectProperty"&&s.computed!==!0&&o(s.key)&&(s.key.name===t||s.key.value===t));return r.length===1&&o(r[0])?r[0].value:void 0}function g(e){return o(e)&&e.type==="StringLiteral"&&typeof e.value=="string"?e.value:void 0}function y(e){return o(e)&&e.type==="Identifier"&&typeof e.name=="string"?e.name:void 0}function x(e){return e.type==="VariableDeclaration"&&Array.isArray(e.declarations)?e.declarations.filter(o):[]}function D(e){let t=e;for(let r=0;r<4&&o(t)&&["TSAsExpression","TSSatisfiesExpression","TSTypeAssertion","ParenthesizedExpression"].includes(String(t.type));r++)t=t.expression;return t}function te(e,t){const r=e.flatMap(x).filter(s=>y(s.id)===t);return r.length===1?D(r[0].init):void 0}function R(e,t){for(const r of e){if(r.type!=="ExportNamedDeclaration"||!o(r.declaration))continue;const s=r.declaration;if(s.type==="FunctionDeclaration"&&o(s.id)&&s.id.name===t)return s;const i=x(s).find(l=>o(l.id)&&l.id.name===t);if(i)return D(i.init)}}function A(e,t){const r=[],s=[e];for(;s.length>0;){const i=s.pop();if(o(i)){i.type===t&&r.push(i);for(const[l,n]of Object.entries(i))l==="loc"||l==="comments"||(Array.isArray(n)?s.push(...n):o(n)&&s.push(n))}}return r}function P(e){return e.screenId.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,64)}function U(e){return e.split(/[^A-Za-z0-9]+/).filter(Boolean).map(t=>`${t.charAt(0).toUpperCase()}${t.slice(1).toLowerCase()}`).join("")}function Z(e,t,r){const s=[];for(const i of e){if(i.type!=="ImportDeclaration"||i.importKind==="type"||!o(i.source)||typeof i.source.value!="string"||!i.source.value.startsWith("./")&&!i.source.value.startsWith("../"))continue;const l=V.normalize(V.join(V.dirname(t),i.source.value));if(!(l!==r.screenViewPath&&l!==r.screenViewPath.replace(/\.tsx$/,"")))for(const n of Array.isArray(i.specifiers)?i.specifiers:[])o(n)&&n.type==="ImportSpecifier"&&o(n.imported)&&n.imported.name===r.screenViewExport&&n.importKind!=="type"&&o(n.local)&&typeof n.local.name=="string"&&s.push(n.local.name)}return s.length!==1&&p(),s[0]}function re(e,t){return A(e,"JSXOpeningElement").some(r=>o(r.name)&&r.name.name===t)}function w(e,t,r){const s=e.filter(i=>i.type==="ImportDeclaration"&&o(i.source)&&i.source.value===t).flatMap(i=>Array.isArray(i.specifiers)?i.specifiers:[]).filter(i=>o(i)&&i.type==="ImportSpecifier"&&o(i.imported)&&i.imported.name===r&&o(i.local)&&typeof i.local.name=="string").map(i=>i.local);return s.length===1?s[0].name:void 0}function Y(e,t,r){return o(e)&&e.type==="CallExpression"&&o(e.callee)&&e.callee.type==="MemberExpression"&&e.callee.computed!==!0&&y(e.callee.object)===t&&y(e.callee.property)===r}function ne(e,t){const r=w(t,"storybook/test","within"),s=w(t,"storybook/test","userEvent"),i=w(t,"storybook/test","expect");if(!r||!s||!i||!Array.isArray(e.params)||!o(e.params[0])||e.params[0].type!=="ObjectPattern"||!Array.isArray(e.params[0].properties)||!e.params[0].properties.some(a=>o(a)&&o(a.key)&&a.key.name==="canvasElement"&&o(a.value)&&a.value.name==="canvasElement"))return!1;const l=A(e.body,"VariableDeclarator"),n=l.filter(a=>o(a.init)&&a.init.type==="CallExpression"&&y(a.init.callee)===r&&Array.isArray(a.init.arguments)&&a.init.arguments.length===1&&y(a.init.arguments[0])==="canvasElement").map(a=>y(a.id)).filter(a=>!!a),f=l.filter(a=>n.some(k=>Y(a.init,k,"getByRole")&&Array.isArray(a.init.arguments)&&g(a.init.arguments[0])==="button"&&typeof g(m(a.init.arguments[1],"name"))=="string"&&!!g(m(a.init.arguments[1],"name"))?.trim())).map(a=>y(a.id)).filter(a=>!!a);if(f.length===0)return!1;const u=A(e.body,"AwaitExpression").map(a=>a.argument),$=u.some(a=>Y(a,s,"tab")&&Array.isArray(a.arguments)&&a.arguments.length===0),h=u.some(a=>o(a)&&a.type==="CallExpression"&&o(a.callee)&&a.callee.type==="MemberExpression"&&y(a.callee.property)==="toHaveFocus"&&o(a.callee.object)&&a.callee.object.type==="CallExpression"&&y(a.callee.object.callee)===i&&Array.isArray(a.callee.object.arguments)&&f.includes(y(a.callee.object.arguments[0])??""));return $&&h}function se(e,t,r){const s=`src/screens/${P(t)}/${P(t)}`,i=I(e,t.screenViewPath),l=R(E(i),t.screenViewExport);(!l||A(l,"JSXElement").length+A(l,"JSXFragment").length===0)&&p();const n=I(e,t.appRoutePath),f=Z(E(n),t.appRoutePath,t);re(n,f)||p();const u=`${s}.stories.tsx`,$=I(e,u),h=E($),a=r==="storybook-react-vite"?"@storybook/react-vite":"@storybook/nextjs-vite";(!w(h,a,"Meta")||!w(h,a,"StoryObj"))&&p();const k=Z(h,u,t),C=h.filter(c=>c.type==="ExportDefaultDeclaration");C.length!==1&&p();const O=D(C[0].declaration),T=y(O)?te(h,y(O)):O;(y(m(T,"component"))!==k||g(m(T,"title"))!==`Screens/${t.screenId}`)&&p();const v=new Set;for(const c of t.states)for(const d of t.viewports){const L=`${U(c)}${U(d)}`;v.add(L);const b=R(h,L);if((!o(b)||b.type!=="ObjectExpression"||g(m(m(b,"args"),"state"))!==c||g(m(m(m(b,"parameters"),"viewport"),"defaultViewport"))!==d)&&p(),t.critical&&(c==="success"||c==="recovery")){const N=m(b,"play");(!o(N)||!["ArrowFunctionExpression","FunctionExpression"].includes(String(N.type))||!ne(N,h))&&p()}}const F=h.filter(c=>c.type==="ExportNamedDeclaration");F.some(c=>!o(c.declaration)||x(c.declaration).length!==1||Array.isArray(c.specifiers)&&c.specifiers.length>0)&&p();const X=F.flatMap(c=>x(c.declaration)).map(c=>y(c.id)).filter(c=>!!c);(X.length!==v.size||X.some(c=>!v.has(c)))&&p();const W=I(e,`${s}.fixtures.ts`);E(W).filter(c=>c.type==="ExportNamedDeclaration").flatMap(c=>o(c.declaration)?x(c.declaration):[]).some(c=>{const d=m(c.init,"synthetic");return o(d)&&d.type==="BooleanLiteral"&&d.value===!0&&m(c.init,"data")!==void 0})||p();const _=I(e,`${s}.handlers.ts`),B=E(_);(!B.some(c=>c.type==="ImportDeclaration"&&o(c.source)&&c.source.value==="msw"&&Array.isArray(c.specifiers)&&c.specifiers.some(d=>o(d)&&o(d.imported)&&d.imported.name==="http"))||!B.some(c=>c.type==="ExportNamedDeclaration"&&o(c.declaration)&&x(c.declaration).some(d=>o(d.init)&&d.init.type==="ArrayExpression"&&Array.isArray(d.init.elements)&&d.init.elements.length>0))||!A(_,"CallExpression").some(c=>o(c.callee)&&c.callee.type==="MemberExpression"&&o(c.callee.object)&&c.callee.object.name==="http"))&&p();const M=j(e,`${s}.mdx`),J=new RegExp(`import\\s+\\*\\s+as\\s+([A-Za-z_$][\\w$]*)\\s+from\\s+['"]\\./${P(t)}\\.stories(?:\\.tsx)?['"];?\\r?\\n(?:[ \\t]*\\r?\\n)+`).exec(M);(!/import\s+\{\s*Meta\s*\}\s+from\s+['"]@storybook\/addon-docs\/blocks['"]/.test(M)||!J||!M.includes(`<Meta of={${J[1]}} />`))&&p()}function S(e){return Array.isArray(e)?`[${e.map(S).join(",")}]`:e&&typeof e=="object"?`{${Object.entries(e).sort(([t],[r])=>t.localeCompare(r)).map(([t,r])=>`${JSON.stringify(t)}:${S(r)}`).join(",")}}`:JSON.stringify(e)??"null"}function oe(e){const t=S(e);let r=2166136261;for(let s=0;s<t.length;s++)r^=t.charCodeAt(s),r=Math.imul(r,16777619);return`uxm-${(r>>>0).toString(16).padStart(8,"0")}`}function ie(e,t){let r;try{r=JSON.parse(j(e,"docs/architecture/ux-coverage-manifest.json"))}catch{p()}(!o(r)||r.schemaVersion!==1||r.manifestId!=="P201-UX-MANIFEST-01"||!Array.isArray(r.entries)||typeof r.fingerprint!="string"||Object.keys(r).sort().join(",")!=="entries,fingerprint,manifestId,schemaVersion"||r.fingerprint!==oe(r.entries))&&p();const s=new Map;for(const n of t.screens)for(const f of n.states)for(const u of n.viewports)s.set(`Screens/${n.screenId}/${f}/${u}`,{screen:n,state:f,viewport:u});r.entries.length!==s.size&&p();const i=new Set;let l="";for(const n of r.entries){(!o(n)||typeof n.storyId!="string"||i.has(n.storyId))&&p(),l&&l.localeCompare(n.storyId)>=0&&p(),l=n.storyId,Object.keys(n).sort().join(",")!=="approvalEvidenceIds,fixtureId,handlerIds,journeyIds,screenId,screenViewPath,state,storyId,viewport"&&p(),i.add(n.storyId);const f=s.get(n.storyId);(!f||n.screenId!==f.screen.screenId||n.state!==f.state||n.viewport!==f.viewport||n.screenViewPath!==f.screen.screenViewPath||!Array.isArray(n.approvalEvidenceIds)||S([...n.approvalEvidenceIds].sort())!==S([...f.screen.approvalEvidenceIds].sort())||!Array.isArray(n.journeyIds)||n.journeyIds.length<1||n.journeyIds.some(u=>typeof u!="string"||!z.test(u))||new Set(n.journeyIds).size!==n.journeyIds.length||typeof n.fixtureId!="string"||!z.test(n.fixtureId)||!Array.isArray(n.handlerIds)||n.handlerIds.length<1||n.handlerIds.some(u=>typeof u!="string"||!z.test(u))||new Set(n.handlerIds).size!==n.handlerIds.length)&&p()}}function fe(e,t){try{for(const[r,s]of[["docs/architecture/ux-design.md","P201-UX-STORYBOOK-01"],["docs/architecture/storybook-ux-contract.md","P201-UX-STORYBOOK-01"]])j(e,r).includes(s)||p();for(const r of t.screens)se(e,r,t.adapterId);ie(e,t)}catch{p()}}export{fe as validateUxCandidateSource};
@@ -1,191 +1,2 @@
1
- /**
2
- * P222.26 A08: root-only derivation of an exact UX execution write set.
3
- * This is path authority, not semantic A08 acceptance or an agent grant.
4
- * The source must be an immutable, tracked approval contract at HEAD; the
5
- * private child cannot add screens or paths after its lease is issued.
6
- */
7
- import { execFileSync } from 'node:child_process';
8
- import { createHash } from 'node:crypto';
9
- import { lstatSync, readFileSync, realpathSync } from 'node:fs';
10
- import { join, resolve } from 'node:path';
11
- export const UX_WRITE_AUTHORITY_PATH = 'docs/architecture/ux-execution-authority.json';
12
- const MAX_AUTHORITY_BYTES = 256 * 1024;
13
- const MAX_SOURCE_BYTES = 16 * 1024 * 1024;
14
- const MAX_SCREENS = 48;
15
- const REQUIRED_STATES = ['loading', 'empty', 'error', 'success', 'permission', 'recovery'];
16
- const REQUIRED_VIEWPORTS = ['mobile', 'tablet', 'desktop'];
17
- const ID = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
18
- const REPO_PATH = /^[A-Za-z0-9._@/-]{1,240}$/;
19
- function fail() { throw new Error('private-execution-ux-write-set-unverified'); }
20
- function digest(bytes) { return createHash('sha256').update(bytes).digest('hex'); }
21
- function object(value) {
22
- return value !== null && typeof value === 'object' && !Array.isArray(value)
23
- && Object.getPrototypeOf(value) === Object.prototype;
24
- }
25
- function keys(value, expected) {
26
- return Object.keys(value).length === expected.length
27
- && expected.every((key) => Object.hasOwn(value, key));
28
- }
29
- function safePath(value) {
30
- return typeof value === 'string' && REPO_PATH.test(value)
31
- && value.split('/').every((part) => part !== '' && part !== '.' && part !== '..' && part !== '.git');
32
- }
33
- function sourcePath(value, route) {
34
- return safePath(value) && value.endsWith('.tsx')
35
- && (route ? /^(?:src\/(?:routes|app|pages)\/|app\/|pages\/)/.test(value)
36
- : value.startsWith('src/') || value.startsWith('app/'));
37
- }
38
- function exactSet(value, expected) {
39
- return Array.isArray(value) && value.length === expected.length
40
- && value.every((item) => typeof item === 'string')
41
- && new Set(value).size === expected.length
42
- && expected.every((item) => value.includes(item));
43
- }
44
- function subset(value, allowed) {
45
- return Array.isArray(value) && value.length > 0 && value.length <= allowed.length
46
- && value.every((item) => typeof item === 'string' && allowed.includes(item))
47
- && new Set(value).size === value.length;
48
- }
49
- function regularOrAbsent(root, path) {
50
- let cursor = root;
51
- const parts = path.split('/');
52
- for (let index = 0; index < parts.length; index++) {
53
- cursor = join(cursor, parts[index]);
54
- try {
55
- const entry = lstatSync(cursor);
56
- if (entry.isSymbolicLink() || (index === parts.length - 1
57
- ? !entry.isFile() || entry.size > MAX_SOURCE_BYTES : !entry.isDirectory()))
58
- fail();
59
- if (index === parts.length - 1)
60
- return true;
61
- }
62
- catch (error) {
63
- if (error.code === 'ENOENT')
64
- return false;
65
- fail();
66
- }
67
- }
68
- return false;
69
- }
70
- function headFile(root, path) {
71
- try {
72
- const mode = execFileSync('git', ['ls-tree', 'HEAD', '--', path], {
73
- cwd: root, encoding: 'utf8', timeout: 10_000, maxBuffer: 1024,
74
- });
75
- if (!mode)
76
- return null;
77
- const match = /^([0-7]{6}) blob [a-f0-9]{40,64}\t(.+)\n$/.exec(mode);
78
- if (!match || match[1] !== '100644' && match[1] !== '100755' || match[2] !== path)
79
- fail();
80
- return execFileSync('git', ['show', `HEAD:${path}`], {
81
- cwd: root, timeout: 10_000, maxBuffer: MAX_SOURCE_BYTES + 1,
82
- });
83
- }
84
- catch {
85
- fail();
86
- }
87
- }
88
- /** No filesystem mutation. A missing/uncommitted/changed approval file fails closed. */
89
- function derive(projectRoot, targetEpicId, candidate) {
90
- if (!/^P[1-9][0-9]{0,11}$/.test(targetEpicId))
91
- fail();
92
- const root = resolve(projectRoot);
93
- try {
94
- if (realpathSync(root) !== root || !lstatSync(root).isDirectory()
95
- || !regularOrAbsent(root, UX_WRITE_AUTHORITY_PATH))
96
- fail();
97
- }
98
- catch {
99
- fail();
100
- }
101
- const source = readFileSync(join(root, UX_WRITE_AUTHORITY_PATH));
102
- const atHead = headFile(root, UX_WRITE_AUTHORITY_PATH);
103
- if (!atHead || source.length < 1 || source.length > MAX_AUTHORITY_BYTES || !source.equals(atHead))
104
- fail();
105
- let parsed;
106
- try {
107
- parsed = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(source));
108
- if (`${JSON.stringify(parsed, null, 2)}\n` !== source.toString('utf8'))
109
- fail();
110
- }
111
- catch {
112
- fail();
113
- }
114
- if (!object(parsed) || !keys(parsed, ['schemaVersion', 'contractId', 'targetEpicId', 'adapterId', 'screens'])
115
- || parsed.schemaVersion !== 1 || parsed.contractId !== 'P201-UX-STORYBOOK-01'
116
- || parsed.targetEpicId !== targetEpicId
117
- || !['storybook-react-vite', 'storybook-nextjs-vite'].includes(String(parsed.adapterId))
118
- || !Array.isArray(parsed.screens) || parsed.screens.length < 1 || parsed.screens.length > MAX_SCREENS)
119
- fail();
120
- const paths = ['docs/architecture/ux-design.md', 'docs/architecture/storybook-ux-contract.md',
121
- 'docs/architecture/ux-coverage-manifest.json'];
122
- const routeNames = new Set();
123
- const screenIds = new Set();
124
- const screens = [];
125
- for (const screen of parsed.screens) {
126
- if (!object(screen) || !keys(screen, ['screenId', 'critical', 'route', 'appRoutePath', 'screenViewPath',
127
- 'screenViewExport', 'approvalStatus', 'approvalEvidenceIds', 'states', 'viewports'])
128
- || typeof screen.screenId !== 'string' || !ID.test(screen.screenId)
129
- || typeof screen.critical !== 'boolean'
130
- || typeof screen.route !== 'string'
131
- || !/^\/[A-Za-z0-9._~!$&'()*+,;=:@%/-]*$/.test(screen.route)
132
- || !sourcePath(screen.appRoutePath, true) || !sourcePath(screen.screenViewPath, false)
133
- || typeof screen.screenViewExport !== 'string'
134
- || !/^[A-Za-z_$][A-Za-z0-9_$]{0,127}$/.test(screen.screenViewExport)
135
- || screen.approvalStatus !== 'approved'
136
- || !Array.isArray(screen.approvalEvidenceIds) || screen.approvalEvidenceIds.length < 1
137
- || screen.approvalEvidenceIds.length > 16
138
- || screen.approvalEvidenceIds.some((id) => typeof id !== 'string' || !ID.test(id))
139
- || new Set(screen.approvalEvidenceIds).size !== screen.approvalEvidenceIds.length
140
- || !(screen.critical ? exactSet(screen.states, REQUIRED_STATES)
141
- : subset(screen.states, REQUIRED_STATES))
142
- || !(screen.critical ? exactSet(screen.viewports, REQUIRED_VIEWPORTS)
143
- : subset(screen.viewports, REQUIRED_VIEWPORTS))
144
- || screenIds.has(screen.screenId) || routeNames.has(screen.route))
145
- fail();
146
- screenIds.add(screen.screenId);
147
- routeNames.add(screen.route);
148
- const stem = screen.screenId.toLowerCase().replace(/[^a-z0-9]+/g, '-')
149
- .replace(/^-+|-+$/g, '').slice(0, 64);
150
- if (!stem)
151
- fail();
152
- screens.push(Object.freeze({ screenId: screen.screenId,
153
- critical: screen.critical, route: screen.route,
154
- appRoutePath: screen.appRoutePath,
155
- screenViewPath: screen.screenViewPath,
156
- screenViewExport: screen.screenViewExport,
157
- approvalEvidenceIds: Object.freeze([...screen.approvalEvidenceIds]),
158
- states: Object.freeze([...screen.states]),
159
- viewports: Object.freeze([...screen.viewports]),
160
- }));
161
- paths.push(screen.screenViewPath, screen.appRoutePath, `src/screens/${stem}/${stem}.fixtures.ts`, `src/screens/${stem}/${stem}.handlers.ts`, `src/screens/${stem}/${stem}.stories.tsx`, `src/screens/${stem}/${stem}.mdx`);
162
- }
163
- if (paths.some((path) => !safePath(path))
164
- || new Set(paths.map((path) => path.toLowerCase())).size !== paths.length)
165
- fail();
166
- paths.sort();
167
- const baselineSha256 = Object.create(null);
168
- for (const path of paths) {
169
- const committed = headFile(root, path);
170
- const exists = regularOrAbsent(root, path);
171
- if (!candidate && exists !== (committed !== null))
172
- fail();
173
- const current = exists ? readFileSync(join(root, path)) : null;
174
- if (!candidate && current && (!committed || !current.equals(committed)))
175
- fail();
176
- baselineSha256[path] = committed ? digest(committed) : null;
177
- }
178
- return Object.freeze({ schemaVersion: 1, authorityPath: UX_WRITE_AUTHORITY_PATH,
179
- targetEpicId, adapterId: parsed.adapterId,
180
- authoritySha256: digest(source), pathsSha256: digest(JSON.stringify(paths)),
181
- screenCount: parsed.screens.length, pathCount: paths.length,
182
- paths: Object.freeze(paths), screens: Object.freeze(screens),
183
- baselineSha256: Object.freeze(baselineSha256) });
184
- }
185
- export function deriveUxWriteSet(projectRoot, targetEpicId) {
186
- return derive(projectRoot, targetEpicId, false);
187
- }
188
- /** Clone-only projection; admission still verifies every effect before applying it to root. */
189
- export function deriveUxCandidateWriteSet(projectRoot, targetEpicId) {
190
- return derive(projectRoot, targetEpicId, true);
191
- }
1
+ import{execFileSync as I}from"node:child_process";import{createHash as D}from"node:crypto";import{lstatSync as w,readFileSync as b,realpathSync as H}from"node:fs";import{join as h,resolve as k}from"node:path";const d="docs/architecture/ux-execution-authority.json",C=256*1024,x=16*1024*1024,N=48,O=["loading","empty","error","success","permission","recovery"],A=["mobile","tablet","desktop"],v=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/,W=/^[A-Za-z0-9._@/-]{1,240}$/;function c(){throw new Error("private-execution-ux-write-set-unverified")}function l(t){return D("sha256").update(t).digest("hex")}function z(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)&&Object.getPrototypeOf(t)===Object.prototype}function P(t,r){return Object.keys(t).length===r.length&&r.every(n=>Object.hasOwn(t,n))}function $(t){return typeof t=="string"&&W.test(t)&&t.split("/").every(r=>r!==""&&r!=="."&&r!==".."&&r!==".git")}function j(t,r){return $(t)&&t.endsWith(".tsx")&&(r?/^(?:src\/(?:routes|app|pages)\/|app\/|pages\/)/.test(t):t.startsWith("src/")||t.startsWith("app/"))}function _(t,r){return Array.isArray(t)&&t.length===r.length&&t.every(n=>typeof n=="string")&&new Set(t).size===r.length&&r.every(n=>t.includes(n))}function R(t,r){return Array.isArray(t)&&t.length>0&&t.length<=r.length&&t.every(n=>typeof n=="string"&&r.includes(n))&&new Set(t).size===t.length}function T(t,r){let n=t;const s=r.split("/");for(let a=0;a<s.length;a++){n=h(n,s[a]);try{const p=w(n);if((p.isSymbolicLink()||(a===s.length-1?!p.isFile()||p.size>x:!p.isDirectory()))&&c(),a===s.length-1)return!0}catch(p){if(p.code==="ENOENT")return!1;c()}}return!1}function V(t,r){try{const n=I("git",["ls-tree","HEAD","--",r],{cwd:t,encoding:"utf8",timeout:1e4,maxBuffer:1024});if(!n)return null;const s=/^([0-7]{6}) blob [a-f0-9]{40,64}\t(.+)\n$/.exec(n);return(!s||s[1]!=="100644"&&s[1]!=="100755"||s[2]!==r)&&c(),I("git",["show",`HEAD:${r}`],{cwd:t,timeout:1e4,maxBuffer:x+1})}catch{c()}}function U(t,r,n){/^P[1-9][0-9]{0,11}$/.test(r)||c();const s=k(t);try{(H(s)!==s||!w(s).isDirectory()||!T(s,d))&&c()}catch{c()}const a=b(h(s,d)),p=V(s,d);(!p||a.length<1||a.length>C||!a.equals(p))&&c();let i;try{i=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(a)),`${JSON.stringify(i,null,2)}
2
+ `!==a.toString("utf8")&&c()}catch{c()}(!z(i)||!P(i,["schemaVersion","contractId","targetEpicId","adapterId","screens"])||i.schemaVersion!==1||i.contractId!=="P201-UX-STORYBOOK-01"||i.targetEpicId!==r||!["storybook-react-vite","storybook-nextjs-vite"].includes(String(i.adapterId))||!Array.isArray(i.screens)||i.screens.length<1||i.screens.length>N)&&c();const u=["docs/architecture/ux-design.md","docs/architecture/storybook-ux-contract.md","docs/architecture/ux-coverage-manifest.json"],y=new Set,g=new Set,S=[];for(const e of i.screens){(!z(e)||!P(e,["screenId","critical","route","appRoutePath","screenViewPath","screenViewExport","approvalStatus","approvalEvidenceIds","states","viewports"])||typeof e.screenId!="string"||!v.test(e.screenId)||typeof e.critical!="boolean"||typeof e.route!="string"||!/^\/[A-Za-z0-9._~!$&'()*+,;=:@%/-]*$/.test(e.route)||!j(e.appRoutePath,!0)||!j(e.screenViewPath,!1)||typeof e.screenViewExport!="string"||!/^[A-Za-z_$][A-Za-z0-9_$]{0,127}$/.test(e.screenViewExport)||e.approvalStatus!=="approved"||!Array.isArray(e.approvalEvidenceIds)||e.approvalEvidenceIds.length<1||e.approvalEvidenceIds.length>16||e.approvalEvidenceIds.some(f=>typeof f!="string"||!v.test(f))||new Set(e.approvalEvidenceIds).size!==e.approvalEvidenceIds.length||!(e.critical?_(e.states,O):R(e.states,O))||!(e.critical?_(e.viewports,A):R(e.viewports,A))||g.has(e.screenId)||y.has(e.route))&&c(),g.add(e.screenId),y.add(e.route);const o=e.screenId.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,64);o||c(),S.push(Object.freeze({screenId:e.screenId,critical:e.critical,route:e.route,appRoutePath:e.appRoutePath,screenViewPath:e.screenViewPath,screenViewExport:e.screenViewExport,approvalEvidenceIds:Object.freeze([...e.approvalEvidenceIds]),states:Object.freeze([...e.states]),viewports:Object.freeze([...e.viewports])})),u.push(e.screenViewPath,e.appRoutePath,`src/screens/${o}/${o}.fixtures.ts`,`src/screens/${o}/${o}.handlers.ts`,`src/screens/${o}/${o}.stories.tsx`,`src/screens/${o}/${o}.mdx`)}(u.some(e=>!$(e))||new Set(u.map(e=>e.toLowerCase())).size!==u.length)&&c(),u.sort();const E=Object.create(null);for(const e of u){const o=V(s,e),f=T(s,e);!n&&f!==(o!==null)&&c();const m=f?b(h(s,e)):null;!n&&m&&(!o||!m.equals(o))&&c(),E[e]=o?l(o):null}return Object.freeze({schemaVersion:1,authorityPath:d,targetEpicId:r,adapterId:i.adapterId,authoritySha256:l(a),pathsSha256:l(JSON.stringify(u)),screenCount:i.screens.length,pathCount:u.length,paths:Object.freeze(u),screens:Object.freeze(S),baselineSha256:Object.freeze(E)})}function F(t,r){return U(t,r,!1)}function J(t,r){return U(t,r,!0)}export{d as UX_WRITE_AUTHORITY_PATH,J as deriveUxCandidateWriteSet,F as deriveUxWriteSet};