@ornexus/neocortex 4.60.72 → 4.60.73
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.
- package/dist/release-source.json +1 -1
- package/dist/sbom.cdx.json +24 -24
- package/install.ps1 +1 -1
- package/install.sh +1 -1
- package/package.json +2 -2
- package/packages/client/dist/adapters/adapter-registry.js +108 -1
- package/packages/client/dist/adapters/antigravity-adapter.js +77 -2
- package/packages/client/dist/adapters/claude-code-adapter.js +79 -3
- package/packages/client/dist/adapters/codex-adapter.js +80 -2
- package/packages/client/dist/adapters/cursor-adapter.js +115 -4
- package/packages/client/dist/adapters/gemini-adapter.js +71 -2
- package/packages/client/dist/adapters/grok-adapter.js +42 -2
- package/packages/client/dist/adapters/index.js +22 -1
- package/packages/client/dist/adapters/platform-detector.js +212 -1
- package/packages/client/dist/adapters/target-adapter.js +12 -0
- package/packages/client/dist/adapters/vscode-adapter.js +72 -2
- package/packages/client/dist/agent/refresh-stubs.js +417 -2
- package/packages/client/dist/agent/update-agent-yaml.js +102 -1
- package/packages/client/dist/agent/update-description.js +251 -1
- package/packages/client/dist/cache/crypto-utils.js +78 -1
- package/packages/client/dist/cache/encrypted-cache.js +108 -1
- package/packages/client/dist/cache/in-memory-asset-cache.js +73 -1
- package/packages/client/dist/cache/index.js +13 -1
- package/packages/client/dist/cache/protected-pi-boundary.js +44 -1
- package/packages/client/dist/checkpoint/checkpoint-client-reader.js +127 -2
- package/packages/client/dist/checkpoint/index.js +11 -1
- package/packages/client/dist/checkpoint/shared-checkpoint-types.js +32 -1
- package/packages/client/dist/cli.js +358 -5
- package/packages/client/dist/commands/activate.js +394 -8
- package/packages/client/dist/commands/architecture-answers.js +274 -7
- package/packages/client/dist/commands/architecture-memory-terminal.js +253 -4
- package/packages/client/dist/commands/architecture-non-ui-continuation.js +100 -1
- package/packages/client/dist/commands/architecture-root-binding.js +51 -1
- package/packages/client/dist/commands/cache-status.js +112 -2
- package/packages/client/dist/commands/config.js +88 -1
- package/packages/client/dist/commands/doctor.js +635 -2
- package/packages/client/dist/commands/invoke.js +7200 -143
- package/packages/client/dist/commands/legacy-epic-terminal.js +71 -1
- package/packages/client/dist/commands/legacy-story-branch.js +96 -1
- package/packages/client/dist/commands/legacy-story-pr.js +276 -1
- package/packages/client/dist/commands/mutation-qa-checkpoint.js +285 -5
- package/packages/client/dist/commands/mutation-qa-gate.js +54 -1
- package/packages/client/dist/commands/mutation-qa-git.js +41 -1
- package/packages/client/dist/commands/mutation-qa-policy.js +102 -1
- package/packages/client/dist/commands/mutation-qa-run.js +219 -3
- package/packages/client/dist/commands/mutation-qa-verdict.js +149 -1
- package/packages/client/dist/commands/mutation-qa.js +220 -1
- package/packages/client/dist/commands/native-agent.js +136 -2
- package/packages/client/dist/commands/planning-diagnosis.js +43 -1
- package/packages/client/dist/commands/planning-generation.js +53 -1
- package/packages/client/dist/commands/planning-memory.js +40 -1
- package/packages/client/dist/commands/planning-research.js +42 -1
- package/packages/client/dist/commands/private-session.js +75 -1
- package/packages/client/dist/commands/property-qa.js +139 -1
- package/packages/client/dist/commands/qa-control.js +16 -1
- package/packages/client/dist/commands/qa-scan-browser-launch.js +55 -1
- package/packages/client/dist/commands/qa-scan-browser-route.js +28 -1
- package/packages/client/dist/commands/qa-scan-capture.js +663 -5
- package/packages/client/dist/commands/qa-scan-discovery.js +376 -3
- package/packages/client/dist/commands/qa-scan-review.js +826 -5
- package/packages/client/dist/commands/qa-synthetic-backend-capture.js +266 -1
- package/packages/client/dist/commands/qa-synthetic-backend-review.js +297 -1
- package/packages/client/dist/commands/qa-synthetic-backend.js +340 -2
- package/packages/client/dist/commands/qa-synthetic-broker-port.js +85 -1
- package/packages/client/dist/commands/qa-synthetic-browser.js +39 -1
- package/packages/client/dist/commands/refactor-characterization.js +671 -21
- package/packages/client/dist/commands/refactor-commit.js +399 -13
- package/packages/client/dist/commands/refactor-control.js +142 -3
- package/packages/client/dist/commands/refactor-cpp-assertions.js +93 -3
- package/packages/client/dist/commands/refactor-review.js +283 -5
- package/packages/client/dist/commands/refactor-root.js +588 -7
- package/packages/client/dist/commands/refresh-memory.js +156 -3
- package/packages/client/dist/commands/shared-architecture-non-ui.js +24 -1
- package/packages/client/dist/commands/story-checkpoint.js +171 -1
- package/packages/client/dist/config/profile-directory.js +13 -1
- package/packages/client/dist/config/resolver-selection.js +278 -1
- package/packages/client/dist/config/secure-config.js +281 -12
- package/packages/client/dist/config.js +223 -2
- package/packages/client/dist/constants.js +25 -1
- package/packages/client/dist/context/context-collector.js +222 -2
- package/packages/client/dist/context/context-sanitizer.js +145 -1
- package/packages/client/dist/continuity/autonomous-governance.js +285 -1
- package/packages/client/dist/continuity/continuity-client-state-store.js +1587 -1
- package/packages/client/dist/continuity/invoke-hooks.js +129 -1
- package/packages/client/dist/continuity/migrations/001-initial-schema.js +12 -2
- package/packages/client/dist/continuity/migrations/002-processing-output-summary-indexes.js +12 -2
- package/packages/client/dist/continuity/migrations/003-headless-execution-attempts.js +12 -2
- package/packages/client/dist/continuity/migrations/004-outbox-delivery-state.js +12 -2
- package/packages/client/dist/continuity/migrations/005-bounded-headless-queue.js +12 -2
- package/packages/client/dist/continuity/migrations/006-native-agent-dispatches.js +10 -2
- package/packages/client/dist/continuity/native-agent-store.js +69 -1
- package/packages/client/dist/continuity/native-agent-types.js +90 -1
- package/packages/client/dist/continuity/outbox.js +117 -1
- package/packages/client/dist/continuity/runner-bootstrap-policy.js +172 -1
- package/packages/client/dist/continuity/sqlite-store.d.ts +22 -1
- package/packages/client/dist/continuity/sqlite-store.js +2612 -81
- package/packages/client/dist/effects/invoke-effect-gateways.js +62 -1
- package/packages/client/dist/errors/error-messages.js +228 -2
- package/packages/client/dist/errors/frontmatter-diagnostics.js +125 -1
- package/packages/client/dist/evidence/collector.js +347 -1
- package/packages/client/dist/evidence/index.js +1 -1
- package/packages/client/dist/evidence/types.js +2 -0
- package/packages/client/dist/fs/atomic-state-replace.js +152 -1
- package/packages/client/dist/generated/command-registry.generated.js +4076 -1
- package/packages/client/dist/generated/public-projections.generated.js +149 -1
- package/packages/client/dist/git/direct-yolo-c01-retry.js +138 -4
- package/packages/client/dist/git/direct-yolo-checkpoint.js +1234 -4
- package/packages/client/dist/git/epic-operational-state.d.ts +198 -0
- package/packages/client/dist/git/epic-operational-state.js +672 -0
- package/packages/client/dist/git/git-lifecycle-step-ids.js +14 -1
- package/packages/client/dist/git/git-lifecycle-store.d.ts +9 -1
- package/packages/client/dist/git/git-lifecycle-store.js +1981 -9
- package/packages/client/dist/git/legacy-story-branch-checkpoint.js +259 -9
- package/packages/client/dist/git/legacy-story-branch-setup.js +348 -4
- package/packages/client/dist/git/legacy-story-pr.js +3538 -70
- package/packages/client/dist/git/secure-filesystem-boundary.js +182 -5
- package/packages/client/dist/graph-retrieval/pre-command-hook.js +284 -1
- package/packages/client/dist/graph-retrieval/shared-graph-retrieval-contract.js +237 -1
- package/packages/client/dist/i18n/first-run.js +60 -2
- package/packages/client/dist/index.js +47 -1
- package/packages/client/dist/invocation/invoke-input.js +24 -1
- package/packages/client/dist/license/index.js +5 -1
- package/packages/client/dist/license/license-client.js +304 -1
- package/packages/client/dist/machine/fingerprint.js +163 -2
- package/packages/client/dist/machine/index.js +5 -1
- package/packages/client/dist/memory/project-memory-path-scope.js +62 -1
- package/packages/client/dist/memory/project-memory-writer.js +1007 -40
- package/packages/client/dist/memory/shared-project-memory-types.js +253 -2
- package/packages/client/dist/migrations/epic-lifecycle-backfill.d.ts +97 -0
- package/packages/client/dist/migrations/epic-lifecycle-backfill.js +1060 -0
- package/packages/client/dist/migrations/project-identity-capability.js +50 -1
- package/packages/client/dist/migrations/project-identity.js +493 -7
- package/packages/client/dist/migrations/state-json.d.ts +22 -0
- package/packages/client/dist/migrations/state-json.js +393 -4
- package/packages/client/dist/policy/architecture-policy.js +184 -2
- package/packages/client/dist/policy/index.js +7 -1
- package/packages/client/dist/policy/shared-policy-types.js +38 -0
- package/packages/client/dist/policy/subagent-approval-policy.js +55 -1
- package/packages/client/dist/private-execution/clean-baseline.js +279 -2
- package/packages/client/dist/private-execution/codex-executor.js +574 -4
- package/packages/client/dist/private-execution/codex-host-runtime.js +137 -1
- package/packages/client/dist/private-execution/codex-lifecycle-guard.js +97 -1
- package/packages/client/dist/private-execution/codex-scoped-permissions.js +128 -1
- package/packages/client/dist/private-execution/delivery.js +410 -13
- package/packages/client/dist/private-execution/diagnosis-root-review.js +294 -2
- package/packages/client/dist/private-execution/frozen-handoff.js +19 -6
- package/packages/client/dist/private-execution/implementation-validation.js +106 -2
- package/packages/client/dist/private-execution/isolated-admission.js +1432 -23
- package/packages/client/dist/private-execution/isolated-session.js +725 -5
- package/packages/client/dist/private-execution/isolated-workspace.js +122 -1
- package/packages/client/dist/private-execution/pact-consumer-runtime.js +409 -3
- package/packages/client/dist/private-execution/pact-test-source.js +258 -1
- package/packages/client/dist/private-execution/pact-toolchain.js +290 -3
- package/packages/client/dist/private-execution/pact-write-set.js +172 -1
- package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +406 -5
- package/packages/client/dist/private-execution/planning-generation-checkpoint.js +462 -5
- package/packages/client/dist/private-execution/planning-memory-checkpoint.js +139 -3
- package/packages/client/dist/private-execution/planning-research-checkpoint.js +325 -4
- package/packages/client/dist/private-execution/private-report-store.js +42 -1
- package/packages/client/dist/private-execution/property-test-candidate.js +103 -1
- package/packages/client/dist/private-execution/property-test-choices.js +147 -3
- package/packages/client/dist/private-execution/property-test-plan.js +271 -7
- package/packages/client/dist/private-execution/property-test-review.js +258 -4
- package/packages/client/dist/private-execution/property-test-runtime.js +372 -9
- package/packages/client/dist/private-execution/property-test-source.js +139 -1
- package/packages/client/dist/private-execution/root-checkpoint.js +80 -1
- package/packages/client/dist/private-execution/root-memory-git-evidence.js +135 -3
- package/packages/client/dist/private-execution/root-memory-recovery.js +93 -1
- package/packages/client/dist/private-execution/root-memory-request.js +29 -1
- package/packages/client/dist/private-execution/root-memory-scope.js +178 -1
- package/packages/client/dist/private-execution/root-memory-writer.js +102 -1
- package/packages/client/dist/private-execution/session-lease.js +63 -1
- package/packages/client/dist/private-execution/shared-private-admission-types.js +50 -1
- package/packages/client/dist/private-execution/shared-project-validation.js +66 -1
- package/packages/client/dist/private-execution/shared-root-memory-types.js +61 -1
- package/packages/client/dist/private-execution/ux-source-validation.js +372 -1
- package/packages/client/dist/private-execution/ux-write-set.js +191 -2
- package/packages/client/dist/registry/registry-reconciliation.js +234 -1
- package/packages/client/dist/resilience/circuit-breaker.js +170 -1
- package/packages/client/dist/resilience/degradation-manager.js +164 -1
- package/packages/client/dist/resilience/freshness-indicator.js +100 -1
- package/packages/client/dist/resilience/index.js +8 -1
- package/packages/client/dist/resilience/recovery-detector.js +74 -1
- package/packages/client/dist/resolvers/asset-resolver.js +13 -0
- package/packages/client/dist/resolvers/local-resolver.js +255 -8
- package/packages/client/dist/resolvers/remote-resolver.js +233 -1
- package/packages/client/dist/runner/binary.js +404 -1
- package/packages/client/dist/runner/cli.js +1571 -17
- package/packages/client/dist/runner/headless/adapters.js +49 -1
- package/packages/client/dist/runner/headless/claude-code-adapter.js +79 -1
- package/packages/client/dist/runner/headless/continuous-story-workspace.js +1628 -11
- package/packages/client/dist/runner/headless/epic-git-reconciliation-inventory.js +69 -1
- package/packages/client/dist/runner/headless/epic-merge-candidate-qa.js +110 -2
- package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +1236 -8
- package/packages/client/dist/runner/headless/epic-terminal-git-runner.js +318 -2
- package/packages/client/dist/runner/headless/fake-adapter.js +62 -1
- package/packages/client/dist/runner/headless/managed-profile.js +132 -1
- package/packages/client/dist/runner/headless/opencode-adapter.js +145 -2
- package/packages/client/dist/runner/headless/prepared-story-bundle.js +43 -1
- package/packages/client/dist/runner/headless/resolver.js +231 -1
- package/packages/client/dist/runner/headless/run-yolo.js +885 -1
- package/packages/client/dist/runner/headless/run-yoloop.js +2574 -2
- package/packages/client/dist/runner/headless/types.js +574 -2
- package/packages/client/dist/runner/local-console.js +396 -13
- package/packages/client/dist/runner/portal-sync-worker.js +1487 -1
- package/packages/client/dist/runner/project-identity.js +106 -1
- package/packages/client/dist/runner/scheduler.js +995 -7
- package/packages/client/dist/runner-cli.js +18 -2
- package/packages/client/dist/state/invocation-shape.js +13 -1
- package/packages/client/dist/state/project-state-snapshot.d.ts +8 -0
- package/packages/client/dist/state/project-state-snapshot.js +1731 -1
- package/packages/client/dist/state/state-json-repair.js +785 -3
- package/packages/client/dist/state/structural-dag-projection.js +118 -1
- package/packages/client/dist/telemetry/index.js +5 -1
- package/packages/client/dist/telemetry/offline-queue.js +131 -1
- package/packages/client/dist/tier/index.js +5 -1
- package/packages/client/dist/tier/tier-aware-client.js +405 -1
- package/packages/client/dist/types/index.js +38 -1
- package/packages/client/dist/version.js +27 -1
- package/packages/client/dist/yolo/change-evidence-collector.js +126 -1
- package/packages/client/dist/yolo/invoke-envelope-capability.js +62 -1
- package/packages/client/dist/yolo/spec-envelope-collector.js +184 -5
- package/packages/client/dist/yoloop/discovery-hook.js +300 -2
- package/packages/client/dist/yoloop/index.js +8 -1
- package/packages/client/dist/yoloop/invoke-hooks.js +669 -12
- package/packages/client/dist/yoloop/shared-discover-epics.js +1007 -1
- package/packages/client/dist/yoloop/shared-yoloop-types.d.ts +65 -1
- package/packages/client/dist/yoloop/shared-yoloop-types.js +33 -1
- package/packages/client/dist/yoloop/target-normalization.js +180 -1
- package/packages/client/dist/yoloop/yoloop-client-state-store.d.ts +8 -0
- package/packages/client/dist/yoloop/yoloop-client-state-store.js +1920 -1
- package/packages/shared/dist/yolo/spec-envelope.js +3 -6
- package/targets-stubs/antigravity/gemini.md +1 -1
- package/targets-stubs/antigravity/skill/SKILL.md +1 -1
- package/targets-stubs/claude-code/neocortex-root.agent.yaml +1 -1
- package/targets-stubs/claude-code/neocortex-root.md +2 -2
- package/targets-stubs/claude-code/neocortex.agent.yaml +1 -1
- package/targets-stubs/claude-code/neocortex.md +2 -2
- package/targets-stubs/codex/AGENTS.md +1 -1
- package/targets-stubs/cursor/agent.md +2 -2
- package/targets-stubs/gemini-cli/agent.md +2 -2
- package/targets-stubs/opencode/neocortex-root.md +1 -1
- package/targets-stubs/vscode/neocortex.agent.md +2 -2
|
@@ -1 +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,2 +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
|
+
}
|