@ornexus/neocortex 4.60.73 → 4.60.74
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 +1216 -1210
- package/install.ps1 +1 -1
- package/install.sh +1 -1
- package/package.json +2 -2
- package/packages/client/dist/adapters/adapter-registry.js +1 -108
- package/packages/client/dist/adapters/antigravity-adapter.js +2 -77
- package/packages/client/dist/adapters/claude-code-adapter.js +3 -79
- package/packages/client/dist/adapters/codex-adapter.js +2 -80
- package/packages/client/dist/adapters/cursor-adapter.js +4 -115
- package/packages/client/dist/adapters/gemini-adapter.js +2 -71
- package/packages/client/dist/adapters/grok-adapter.js +2 -42
- package/packages/client/dist/adapters/index.js +1 -22
- package/packages/client/dist/adapters/platform-detector.js +1 -212
- package/packages/client/dist/adapters/target-adapter.js +0 -12
- package/packages/client/dist/adapters/vscode-adapter.js +2 -72
- package/packages/client/dist/agent/refresh-stubs.js +2 -417
- package/packages/client/dist/agent/update-agent-yaml.js +1 -102
- package/packages/client/dist/agent/update-description.js +1 -251
- package/packages/client/dist/cache/crypto-utils.js +1 -78
- package/packages/client/dist/cache/encrypted-cache.js +1 -108
- package/packages/client/dist/cache/in-memory-asset-cache.js +1 -73
- package/packages/client/dist/cache/index.js +1 -13
- package/packages/client/dist/cache/protected-pi-boundary.js +1 -44
- package/packages/client/dist/checkpoint/checkpoint-client-reader.js +2 -127
- package/packages/client/dist/checkpoint/index.js +1 -11
- package/packages/client/dist/checkpoint/shared-checkpoint-types.js +1 -32
- package/packages/client/dist/cli.js +5 -358
- package/packages/client/dist/commands/activate.js +8 -394
- package/packages/client/dist/commands/architecture-answers.js +7 -274
- package/packages/client/dist/commands/architecture-memory-terminal.js +4 -253
- package/packages/client/dist/commands/architecture-non-ui-continuation.js +1 -100
- package/packages/client/dist/commands/architecture-root-binding.js +1 -51
- package/packages/client/dist/commands/cache-status.js +2 -112
- package/packages/client/dist/commands/config.js +1 -88
- package/packages/client/dist/commands/doctor.js +2 -635
- package/packages/client/dist/commands/invoke.js +143 -7200
- package/packages/client/dist/commands/legacy-epic-terminal.js +1 -71
- package/packages/client/dist/commands/legacy-story-branch.js +1 -96
- package/packages/client/dist/commands/legacy-story-pr.js +1 -276
- package/packages/client/dist/commands/mutation-qa-checkpoint.js +5 -285
- package/packages/client/dist/commands/mutation-qa-gate.js +1 -54
- package/packages/client/dist/commands/mutation-qa-git.js +1 -41
- package/packages/client/dist/commands/mutation-qa-policy.js +1 -102
- package/packages/client/dist/commands/mutation-qa-run.js +3 -219
- package/packages/client/dist/commands/mutation-qa-verdict.js +1 -149
- package/packages/client/dist/commands/mutation-qa.js +1 -220
- package/packages/client/dist/commands/native-agent.js +2 -136
- package/packages/client/dist/commands/planning-diagnosis.js +1 -43
- package/packages/client/dist/commands/planning-generation.js +1 -53
- package/packages/client/dist/commands/planning-memory.js +1 -40
- package/packages/client/dist/commands/planning-research.js +1 -42
- package/packages/client/dist/commands/private-session.js +1 -75
- package/packages/client/dist/commands/property-qa.js +1 -139
- package/packages/client/dist/commands/qa-control.js +1 -16
- package/packages/client/dist/commands/qa-scan-browser-launch.js +1 -55
- package/packages/client/dist/commands/qa-scan-browser-route.js +1 -28
- package/packages/client/dist/commands/qa-scan-capture.js +5 -663
- package/packages/client/dist/commands/qa-scan-discovery.js +3 -376
- package/packages/client/dist/commands/qa-scan-review.js +5 -826
- package/packages/client/dist/commands/qa-synthetic-backend-capture.js +1 -266
- package/packages/client/dist/commands/qa-synthetic-backend-review.js +1 -297
- package/packages/client/dist/commands/qa-synthetic-backend.js +2 -340
- package/packages/client/dist/commands/qa-synthetic-broker-port.js +1 -85
- package/packages/client/dist/commands/qa-synthetic-browser.js +1 -39
- package/packages/client/dist/commands/refactor-characterization.js +21 -671
- package/packages/client/dist/commands/refactor-commit.js +13 -399
- package/packages/client/dist/commands/refactor-control.js +3 -142
- package/packages/client/dist/commands/refactor-cpp-assertions.js +3 -93
- package/packages/client/dist/commands/refactor-review.js +5 -283
- package/packages/client/dist/commands/refactor-root.js +7 -588
- package/packages/client/dist/commands/refresh-memory.js +3 -156
- package/packages/client/dist/commands/shared-architecture-non-ui.js +1 -24
- package/packages/client/dist/commands/story-checkpoint.js +1 -171
- package/packages/client/dist/config/profile-directory.js +1 -13
- package/packages/client/dist/config/resolver-selection.js +1 -278
- package/packages/client/dist/config/secure-config.js +12 -281
- package/packages/client/dist/config.js +2 -223
- package/packages/client/dist/constants.js +1 -25
- package/packages/client/dist/context/context-collector.js +2 -222
- package/packages/client/dist/context/context-sanitizer.js +1 -145
- package/packages/client/dist/continuity/autonomous-governance.js +1 -285
- package/packages/client/dist/continuity/continuity-client-state-store.js +1 -1587
- package/packages/client/dist/continuity/invoke-hooks.js +1 -129
- package/packages/client/dist/continuity/migrations/001-initial-schema.js +2 -12
- package/packages/client/dist/continuity/migrations/002-processing-output-summary-indexes.js +2 -12
- package/packages/client/dist/continuity/migrations/003-headless-execution-attempts.js +2 -12
- package/packages/client/dist/continuity/migrations/004-outbox-delivery-state.js +2 -12
- package/packages/client/dist/continuity/migrations/005-bounded-headless-queue.js +2 -12
- package/packages/client/dist/continuity/migrations/006-native-agent-dispatches.js +2 -10
- package/packages/client/dist/continuity/native-agent-store.js +1 -69
- package/packages/client/dist/continuity/native-agent-types.js +1 -90
- package/packages/client/dist/continuity/outbox.js +1 -117
- package/packages/client/dist/continuity/runner-bootstrap-policy.js +1 -172
- package/packages/client/dist/continuity/sqlite-store.js +81 -2612
- package/packages/client/dist/effects/invoke-effect-gateways.js +1 -62
- package/packages/client/dist/errors/error-messages.js +2 -228
- package/packages/client/dist/errors/frontmatter-diagnostics.js +1 -125
- package/packages/client/dist/evidence/collector.js +1 -347
- package/packages/client/dist/evidence/index.js +1 -1
- package/packages/client/dist/evidence/types.js +0 -2
- package/packages/client/dist/fs/atomic-state-replace.js +1 -152
- package/packages/client/dist/generated/command-registry.generated.js +1 -4076
- package/packages/client/dist/generated/public-projections.generated.js +1 -149
- package/packages/client/dist/git/direct-yolo-c01-retry.js +4 -138
- package/packages/client/dist/git/direct-yolo-checkpoint.js +4 -1234
- package/packages/client/dist/git/epic-operational-state.js +2 -672
- package/packages/client/dist/git/git-lifecycle-step-ids.js +1 -14
- package/packages/client/dist/git/git-lifecycle-store.d.ts +23 -0
- package/packages/client/dist/git/git-lifecycle-store.js +10 -1981
- package/packages/client/dist/git/legacy-story-branch-checkpoint.js +9 -259
- package/packages/client/dist/git/legacy-story-branch-setup.js +4 -348
- package/packages/client/dist/git/legacy-story-pr.js +70 -3538
- package/packages/client/dist/git/secure-filesystem-boundary.js +5 -182
- package/packages/client/dist/graph-retrieval/pre-command-hook.js +1 -284
- package/packages/client/dist/graph-retrieval/shared-graph-retrieval-contract.js +1 -237
- package/packages/client/dist/i18n/first-run.js +2 -60
- package/packages/client/dist/index.js +1 -47
- package/packages/client/dist/invocation/invoke-input.js +1 -24
- package/packages/client/dist/license/index.js +1 -5
- package/packages/client/dist/license/license-client.js +1 -304
- package/packages/client/dist/machine/fingerprint.js +2 -163
- package/packages/client/dist/machine/index.js +1 -5
- package/packages/client/dist/memory/project-memory-path-scope.js +1 -62
- package/packages/client/dist/memory/project-memory-writer.js +40 -1007
- package/packages/client/dist/memory/shared-project-memory-types.js +2 -253
- package/packages/client/dist/migrations/epic-lifecycle-backfill.js +3 -1060
- package/packages/client/dist/migrations/project-identity-capability.js +1 -50
- package/packages/client/dist/migrations/project-identity.js +7 -493
- package/packages/client/dist/migrations/state-json.js +4 -393
- package/packages/client/dist/policy/architecture-policy.js +2 -184
- package/packages/client/dist/policy/index.js +1 -7
- package/packages/client/dist/policy/shared-policy-types.js +0 -38
- package/packages/client/dist/policy/subagent-approval-policy.js +1 -55
- package/packages/client/dist/private-execution/clean-baseline.js +2 -279
- package/packages/client/dist/private-execution/codex-executor.js +4 -574
- package/packages/client/dist/private-execution/codex-host-runtime.js +1 -137
- package/packages/client/dist/private-execution/codex-lifecycle-guard.js +1 -97
- package/packages/client/dist/private-execution/codex-scoped-permissions.js +1 -128
- package/packages/client/dist/private-execution/delivery.js +13 -410
- package/packages/client/dist/private-execution/diagnosis-root-review.js +2 -294
- package/packages/client/dist/private-execution/frozen-handoff.js +6 -19
- package/packages/client/dist/private-execution/implementation-validation.js +2 -106
- package/packages/client/dist/private-execution/isolated-admission.js +23 -1432
- package/packages/client/dist/private-execution/isolated-session.js +5 -725
- package/packages/client/dist/private-execution/isolated-workspace.js +1 -122
- package/packages/client/dist/private-execution/pact-consumer-runtime.js +3 -409
- package/packages/client/dist/private-execution/pact-test-source.js +1 -258
- package/packages/client/dist/private-execution/pact-toolchain.js +3 -290
- package/packages/client/dist/private-execution/pact-write-set.js +1 -172
- package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +5 -406
- package/packages/client/dist/private-execution/planning-generation-checkpoint.js +5 -462
- package/packages/client/dist/private-execution/planning-memory-checkpoint.js +3 -139
- package/packages/client/dist/private-execution/planning-research-checkpoint.js +4 -325
- package/packages/client/dist/private-execution/private-report-store.js +1 -42
- package/packages/client/dist/private-execution/property-test-candidate.js +1 -103
- package/packages/client/dist/private-execution/property-test-choices.js +3 -147
- package/packages/client/dist/private-execution/property-test-plan.js +7 -271
- package/packages/client/dist/private-execution/property-test-review.js +4 -258
- package/packages/client/dist/private-execution/property-test-runtime.js +9 -372
- package/packages/client/dist/private-execution/property-test-source.js +1 -139
- package/packages/client/dist/private-execution/root-checkpoint.js +1 -80
- package/packages/client/dist/private-execution/root-memory-git-evidence.js +3 -135
- package/packages/client/dist/private-execution/root-memory-recovery.js +1 -93
- package/packages/client/dist/private-execution/root-memory-request.js +1 -29
- package/packages/client/dist/private-execution/root-memory-scope.js +1 -178
- package/packages/client/dist/private-execution/root-memory-writer.js +1 -102
- package/packages/client/dist/private-execution/session-lease.js +1 -63
- package/packages/client/dist/private-execution/shared-private-admission-types.js +1 -50
- package/packages/client/dist/private-execution/shared-project-validation.js +1 -66
- package/packages/client/dist/private-execution/shared-root-memory-types.js +1 -61
- package/packages/client/dist/private-execution/ux-source-validation.js +1 -372
- package/packages/client/dist/private-execution/ux-write-set.js +2 -191
- package/packages/client/dist/registry/registry-reconciliation.js +1 -234
- package/packages/client/dist/resilience/circuit-breaker.js +1 -170
- package/packages/client/dist/resilience/degradation-manager.js +1 -164
- package/packages/client/dist/resilience/freshness-indicator.js +1 -100
- package/packages/client/dist/resilience/index.js +1 -8
- package/packages/client/dist/resilience/recovery-detector.js +1 -74
- package/packages/client/dist/resolvers/asset-resolver.js +0 -13
- package/packages/client/dist/resolvers/local-resolver.js +8 -255
- package/packages/client/dist/resolvers/remote-resolver.js +1 -233
- package/packages/client/dist/runner/binary.js +1 -404
- package/packages/client/dist/runner/cli.js +17 -1571
- package/packages/client/dist/runner/headless/adapters.js +1 -49
- package/packages/client/dist/runner/headless/claude-code-adapter.js +1 -79
- package/packages/client/dist/runner/headless/continuous-story-workspace.js +11 -1628
- package/packages/client/dist/runner/headless/epic-git-reconciliation-inventory.js +1 -69
- package/packages/client/dist/runner/headless/epic-merge-candidate-qa.d.ts +1 -1
- package/packages/client/dist/runner/headless/epic-merge-candidate-qa.js +2 -110
- package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.d.ts +2 -0
- package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +10 -1236
- package/packages/client/dist/runner/headless/epic-terminal-git-runner.d.ts +18 -2
- package/packages/client/dist/runner/headless/epic-terminal-git-runner.js +2 -318
- package/packages/client/dist/runner/headless/fake-adapter.js +1 -62
- package/packages/client/dist/runner/headless/managed-profile.js +1 -132
- package/packages/client/dist/runner/headless/opencode-adapter.js +2 -145
- package/packages/client/dist/runner/headless/prepared-story-bundle.js +1 -43
- package/packages/client/dist/runner/headless/resolver.js +1 -231
- package/packages/client/dist/runner/headless/run-yolo.js +1 -885
- package/packages/client/dist/runner/headless/run-yoloop.d.ts +1 -0
- package/packages/client/dist/runner/headless/run-yoloop.js +2 -2574
- package/packages/client/dist/runner/headless/types.js +2 -574
- package/packages/client/dist/runner/local-console.js +13 -396
- package/packages/client/dist/runner/portal-sync-worker.js +1 -1487
- package/packages/client/dist/runner/project-identity.js +1 -106
- package/packages/client/dist/runner/scheduler.js +7 -995
- package/packages/client/dist/runner-cli.js +2 -18
- package/packages/client/dist/state/invocation-shape.js +1 -13
- package/packages/client/dist/state/project-state-snapshot.js +1 -1731
- package/packages/client/dist/state/state-json-repair.js +3 -785
- package/packages/client/dist/state/structural-dag-projection.js +1 -118
- package/packages/client/dist/telemetry/index.js +1 -5
- package/packages/client/dist/telemetry/offline-queue.js +1 -131
- package/packages/client/dist/tier/index.js +1 -5
- package/packages/client/dist/tier/tier-aware-client.js +1 -405
- package/packages/client/dist/types/index.js +1 -38
- package/packages/client/dist/version.js +1 -27
- package/packages/client/dist/yolo/change-evidence-collector.js +1 -126
- package/packages/client/dist/yolo/invoke-envelope-capability.js +1 -62
- package/packages/client/dist/yolo/spec-envelope-collector.js +5 -184
- package/packages/client/dist/yoloop/discovery-hook.js +2 -300
- package/packages/client/dist/yoloop/index.js +1 -8
- package/packages/client/dist/yoloop/invoke-hooks.js +12 -669
- package/packages/client/dist/yoloop/shared-discover-epics.js +1 -1007
- package/packages/client/dist/yoloop/shared-yoloop-types.js +1 -33
- package/packages/client/dist/yoloop/target-normalization.js +1 -180
- package/packages/client/dist/yoloop/yoloop-client-state-store.js +1 -1920
- package/packages/shared/dist/yolo/change-evidence.js +1 -1
- package/packages/shared/dist/yoloop/epic-terminal-git.js +144 -2
- 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,93 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
let quote = '', escaped = false, rawEnd = '';
|
|
5
|
-
while (i < text.length) {
|
|
6
|
-
const char = text[i];
|
|
7
|
-
if (char === '\n') {
|
|
8
|
-
code += '\n';
|
|
9
|
-
i++;
|
|
10
|
-
if (state === 'line')
|
|
11
|
-
state = 'code';
|
|
12
|
-
if (state === 'quote')
|
|
13
|
-
escaped = false;
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
|
-
if (state === 'line') {
|
|
17
|
-
i++;
|
|
18
|
-
continue;
|
|
19
|
-
}
|
|
20
|
-
if (state === 'block') {
|
|
21
|
-
if (text.startsWith('*/', i)) {
|
|
22
|
-
state = 'code';
|
|
23
|
-
i += 2;
|
|
24
|
-
}
|
|
25
|
-
else
|
|
26
|
-
i++;
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
if (state === 'quote') {
|
|
30
|
-
if (escaped)
|
|
31
|
-
escaped = false;
|
|
32
|
-
else if (char === '\\')
|
|
33
|
-
escaped = true;
|
|
34
|
-
else if (char === quote)
|
|
35
|
-
state = 'code';
|
|
36
|
-
i++;
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
if (state === 'raw') {
|
|
40
|
-
if (text.startsWith(rawEnd, i)) {
|
|
41
|
-
state = 'code';
|
|
42
|
-
i += rawEnd.length;
|
|
43
|
-
}
|
|
44
|
-
else
|
|
45
|
-
i++;
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
if (text.startsWith('//', i)) {
|
|
49
|
-
state = 'line';
|
|
50
|
-
i += 2;
|
|
51
|
-
code += ' ';
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
if (text.startsWith('/*', i)) {
|
|
55
|
-
state = 'block';
|
|
56
|
-
i += 2;
|
|
57
|
-
code += ' ';
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
const raw = /^(?:u8|u|U|L)?R"([^\s()\\]{0,16})\(/.exec(text.slice(i, i + 24));
|
|
61
|
-
if (raw) {
|
|
62
|
-
rawEnd = `)${raw[1]}"`;
|
|
63
|
-
state = 'raw';
|
|
64
|
-
i += raw[0].length;
|
|
65
|
-
code += ' ';
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
if (char === '"' || char === "'") {
|
|
69
|
-
quote = char;
|
|
70
|
-
state = 'quote';
|
|
71
|
-
escaped = false;
|
|
72
|
-
i++;
|
|
73
|
-
code += ' ';
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
// Consume identifiers and numeric tokens so prefixed characters and digit separators stay distinct.
|
|
77
|
-
if (/[A-Za-z_0-9]/.test(char)) {
|
|
78
|
-
const start = i++, numeric = /[0-9]/.test(char);
|
|
79
|
-
while (i < text.length && (numeric ? /[A-Za-z_0-9.']/.test(text[i]) : /[A-Za-z_0-9]/.test(text[i])))
|
|
80
|
-
i++;
|
|
81
|
-
code += text.slice(start, i);
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
code += char;
|
|
85
|
-
i++;
|
|
86
|
-
}
|
|
87
|
-
return code.split(/\r?\n/);
|
|
88
|
-
}
|
|
89
|
-
/** Syntactic anchor only; independent root review checks the failure body and behavior. */
|
|
90
|
-
export function isCppRefactorAssertionSite(line) {
|
|
91
|
-
return !/^\s*#/.test(line) && (/\bassert\s*\(/.test(line)
|
|
92
|
-
|| /\bthrow\s+\S/.test(line) || /^\s*(?:else\s+)?if\s*\(/.test(line));
|
|
93
|
-
}
|
|
1
|
+
function u(t){let n="",e=0,s="code",r="",c=!1,o="";for(;e<t.length;){const i=t[e];if(i===`
|
|
2
|
+
`){n+=`
|
|
3
|
+
`,e++,s==="line"&&(s="code"),s==="quote"&&(c=!1);continue}if(s==="line"){e++;continue}if(s==="block"){t.startsWith("*/",e)?(s="code",e+=2):e++;continue}if(s==="quote"){c?c=!1:i==="\\"?c=!0:i===r&&(s="code"),e++;continue}if(s==="raw"){t.startsWith(o,e)?(s="code",e+=o.length):e++;continue}if(t.startsWith("//",e)){s="line",e+=2,n+=" ";continue}if(t.startsWith("/*",e)){s="block",e+=2,n+=" ";continue}const f=/^(?:u8|u|U|L)?R"([^\s()\\]{0,16})\(/.exec(t.slice(e,e+24));if(f){o=`)${f[1]}"`,s="raw",e+=f[0].length,n+=" ";continue}if(i==='"'||i==="'"){r=i,s="quote",c=!1,e++,n+=" ";continue}if(/[A-Za-z_0-9]/.test(i)){const a=e++,l=/[0-9]/.test(i);for(;e<t.length&&(l?/[A-Za-z_0-9.']/.test(t[e]):/[A-Za-z_0-9]/.test(t[e]));)e++;n+=t.slice(a,e);continue}n+=i,e++}return n.split(/\r?\n/)}function h(t){return!/^\s*#/.test(t)&&(/\bassert\s*\(/.test(t)||/\bthrow\s+\S/.test(t)||/^\s*(?:else\s+)?if\s*\(/.test(t))}export{u as cppRefactorExecutableLines,h as isCppRefactorAssertionSite};
|
|
@@ -1,283 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { cppRefactorExecutableLines, isCppRefactorAssertionSite } from './refactor-cpp-assertions.js';
|
|
7
|
-
import { privateRefactorDirectory, readPrivateRefactorAdmission, verifyRootRefactor } from './refactor-root.js';
|
|
8
|
-
const SHA256 = /^[a-f0-9]{64}$/;
|
|
9
|
-
const MAX_REVIEW_BYTES = 128 * 1024;
|
|
10
|
-
function sha(value) {
|
|
11
|
-
return createHash('sha256').update(value).digest('hex');
|
|
12
|
-
}
|
|
13
|
-
function exact(value, keys) {
|
|
14
|
-
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
15
|
-
&& Object.keys(value).sort().join('\0') === [...keys].sort().join('\0');
|
|
16
|
-
}
|
|
17
|
-
function rationale(value, maximum) {
|
|
18
|
-
return typeof value === 'string' && value.length >= 30 && value.length <= maximum
|
|
19
|
-
&& !/[\x00-\x1f\x7f]/.test(value);
|
|
20
|
-
}
|
|
21
|
-
/** Re-execute the unchanged suite; a saved observation is not QA authority. */
|
|
22
|
-
function currentCandidate(projectRoot, admissionSha256, baselineSha256) {
|
|
23
|
-
if (!SHA256.test(admissionSha256) || !SHA256.test(baselineSha256)) {
|
|
24
|
-
throw new Error('refactor-root-review-unverified');
|
|
25
|
-
}
|
|
26
|
-
const root = resolve(projectRoot);
|
|
27
|
-
const admission = readPrivateRefactorAdmission(root, admissionSha256);
|
|
28
|
-
const baseline = readRootRefactorBaseline(root, baselineSha256);
|
|
29
|
-
const containment = verifyRootRefactor(root, admissionSha256);
|
|
30
|
-
const observation = runRootRefactorCharacterization(root, admissionSha256, baseline.testFiles.map((file) => file.path), baseline.dependencies.map((file) => file.path), 'after', true, baseline.causalPath, baselineSha256, baseline.schemaVersion === 2 ? baseline.runner : 'native');
|
|
31
|
-
if (baseline.admissionSha256 !== admissionSha256 || baseline.sourceHead !== admission.sourceHead
|
|
32
|
-
|| observation.baselineSha256 !== baselineSha256 || !observation.testsPassedObserved
|
|
33
|
-
|| !observation.causalFailureObserved || containment.changedFileCount < 2) {
|
|
34
|
-
throw new Error('refactor-root-review-unverified');
|
|
35
|
-
}
|
|
36
|
-
return Object.freeze({ root, storyId: admission.storyId, sourceHead: admission.sourceHead,
|
|
37
|
-
admissionSha256, baselineSha256, candidateSha256: observation.candidateSha256,
|
|
38
|
-
testFiles: baseline.testFiles, changedFileCount: containment.changedFileCount });
|
|
39
|
-
}
|
|
40
|
-
function validatedReview(current, report) {
|
|
41
|
-
if (!exact(report, ['schemaVersion', 'kind', 'storyId', 'sourceHead', 'admissionSha256',
|
|
42
|
-
'baselineSha256', 'candidateSha256', 'verdict', 'behaviorRationale', 'assertions'])
|
|
43
|
-
|| report.schemaVersion !== 1 || report.kind !== 'root-refactor-semantic-review'
|
|
44
|
-
|| report.storyId !== current.storyId || report.sourceHead !== current.sourceHead
|
|
45
|
-
|| report.admissionSha256 !== current.admissionSha256
|
|
46
|
-
|| report.baselineSha256 !== current.baselineSha256
|
|
47
|
-
|| report.candidateSha256 !== current.candidateSha256 || report.verdict !== 'approved'
|
|
48
|
-
|| !rationale(report.behaviorRationale, 1000)
|
|
49
|
-
|| !Array.isArray(report.assertions)
|
|
50
|
-
|| report.assertions.length < current.testFiles.length || report.assertions.length > 64
|
|
51
|
-
|| Buffer.byteLength(JSON.stringify(report)) > MAX_REVIEW_BYTES) {
|
|
52
|
-
throw new Error('refactor-root-review-unverified');
|
|
53
|
-
}
|
|
54
|
-
const expected = new Map(current.testFiles.map((file) => [file.path, file.sha256]));
|
|
55
|
-
const lines = new Map();
|
|
56
|
-
const cppLines = new Map();
|
|
57
|
-
for (const [path, expectedSha] of expected) {
|
|
58
|
-
const physicalPath = join(current.root, path);
|
|
59
|
-
const stat = lstatSync(physicalPath);
|
|
60
|
-
if (!stat.isFile() || stat.isSymbolicLink() || realpathSync(physicalPath) !== physicalPath
|
|
61
|
-
|| stat.size < 1 || stat.size > 8 * 1024 * 1024) {
|
|
62
|
-
throw new Error('refactor-root-review-unverified');
|
|
63
|
-
}
|
|
64
|
-
const bytes = readFileSync(physicalPath);
|
|
65
|
-
if (sha(bytes) !== expectedSha)
|
|
66
|
-
throw new Error('refactor-root-review-unverified');
|
|
67
|
-
const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
68
|
-
lines.set(path, text.split(/\r?\n/));
|
|
69
|
-
if (path.endsWith('.cpp'))
|
|
70
|
-
cppLines.set(path, cppRefactorExecutableLines(text));
|
|
71
|
-
}
|
|
72
|
-
const seen = new Set();
|
|
73
|
-
const covered = new Set();
|
|
74
|
-
for (const assertion of report.assertions) {
|
|
75
|
-
if (!exact(assertion, ['testPath', 'assertionLine', 'rationale'])
|
|
76
|
-
|| typeof assertion.testPath !== 'string' || !expected.has(assertion.testPath)
|
|
77
|
-
|| !Number.isSafeInteger(assertion.assertionLine) || Number(assertion.assertionLine) < 1
|
|
78
|
-
|| Number(assertion.assertionLine) > (lines.get(assertion.testPath)?.length ?? 0)
|
|
79
|
-
|| !rationale(assertion.rationale, 500)) {
|
|
80
|
-
throw new Error('refactor-root-review-unverified');
|
|
81
|
-
}
|
|
82
|
-
const key = `${assertion.testPath}:${assertion.assertionLine}`;
|
|
83
|
-
if (seen.has(key))
|
|
84
|
-
throw new Error('refactor-root-review-unverified');
|
|
85
|
-
seen.add(key);
|
|
86
|
-
covered.add(assertion.testPath);
|
|
87
|
-
const line = lines.get(assertion.testPath)[Number(assertion.assertionLine) - 1];
|
|
88
|
-
const activeLine = assertion.testPath.endsWith('.py')
|
|
89
|
-
? (line.split('#')[0] ?? '').trimStart() : line.split('//')[0] ?? '';
|
|
90
|
-
const hasAssertion = assertion.testPath.endsWith('.cpp')
|
|
91
|
-
? isCppRefactorAssertionSite(cppLines.get(assertion.testPath)?.[Number(assertion.assertionLine) - 1] ?? '')
|
|
92
|
-
: assertion.testPath.endsWith('.py')
|
|
93
|
-
? /^self\.assert[A-Z][A-Za-z0-9_]*\s*\(/.test(activeLine)
|
|
94
|
-
|| /^assert\s+\S/.test(activeLine)
|
|
95
|
-
: /\b(?:assert|expect|throw)\b/.test(activeLine);
|
|
96
|
-
if (!hasAssertion) {
|
|
97
|
-
throw new Error('refactor-root-review-unverified');
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
if (covered.size !== expected.size)
|
|
101
|
-
throw new Error('refactor-root-review-unverified');
|
|
102
|
-
return report;
|
|
103
|
-
}
|
|
104
|
-
function receipt(current, report) {
|
|
105
|
-
return Object.freeze({ schemaVersion: 1, kind: 'root-refactor-semantic-acceptance',
|
|
106
|
-
storyId: current.storyId, sourceHead: current.sourceHead,
|
|
107
|
-
admissionSha256: current.admissionSha256, baselineSha256: current.baselineSha256,
|
|
108
|
-
candidateSha256: current.candidateSha256,
|
|
109
|
-
reviewSha256: sha(`root-refactor-semantic-review-v1\0${JSON.stringify(report)}`),
|
|
110
|
-
testFileCount: current.testFiles.length, assertionCount: report.assertions.length,
|
|
111
|
-
changedFileCount: current.changedFileCount, executionVerified: true,
|
|
112
|
-
qaAccepted: true, gitCommitAuthorized: false, publicSafe: true });
|
|
113
|
-
}
|
|
114
|
-
function recordPath(root, admissionSha256, candidateSha256) {
|
|
115
|
-
return join(privateRefactorDirectory(root), `review-${admissionSha256}-${candidateSha256}.json`);
|
|
116
|
-
}
|
|
117
|
-
function readRecord(path) {
|
|
118
|
-
const stat = lstatSync(path);
|
|
119
|
-
if (!stat.isFile() || stat.isSymbolicLink() || stat.uid !== process.getuid?.()
|
|
120
|
-
|| (stat.mode & 0o077) !== 0 || stat.size < 100 || stat.size > MAX_REVIEW_BYTES + 4096) {
|
|
121
|
-
throw new Error('refactor-root-review-unverified');
|
|
122
|
-
}
|
|
123
|
-
const raw = readFileSync(path);
|
|
124
|
-
const record = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(raw));
|
|
125
|
-
if (!exact(record, ['schemaVersion', 'kind', 'report', 'receipt', 'checksumSha256'])
|
|
126
|
-
|| record.schemaVersion !== 1 || record.kind !== 'root-refactor-semantic-record'
|
|
127
|
-
|| typeof record.checksumSha256 !== 'string' || !SHA256.test(record.checksumSha256)
|
|
128
|
-
|| !raw.equals(Buffer.from(`${JSON.stringify(record)}\n`))
|
|
129
|
-
|| record.checksumSha256 !== sha(`root-refactor-semantic-record-v1\0${JSON.stringify({
|
|
130
|
-
report: record.report, receipt: record.receipt,
|
|
131
|
-
})}`)) {
|
|
132
|
-
throw new Error('refactor-root-review-unverified');
|
|
133
|
-
}
|
|
134
|
-
return record;
|
|
135
|
-
}
|
|
136
|
-
export function acceptRootRefactorSemanticReview(projectRoot, admissionSha256, baselineSha256, report) {
|
|
137
|
-
try {
|
|
138
|
-
const current = currentCandidate(projectRoot, admissionSha256, baselineSha256);
|
|
139
|
-
const approved = validatedReview(current, report);
|
|
140
|
-
const accepted = receipt(current, approved);
|
|
141
|
-
const target = recordPath(current.root, admissionSha256, current.candidateSha256);
|
|
142
|
-
const payload = { report: approved, receipt: accepted };
|
|
143
|
-
const record = { schemaVersion: 1, kind: 'root-refactor-semantic-record', ...payload,
|
|
144
|
-
checksumSha256: sha(`root-refactor-semantic-record-v1\0${JSON.stringify(payload)}`) };
|
|
145
|
-
const bytes = Buffer.from(`${JSON.stringify(record)}\n`);
|
|
146
|
-
if (existsSync(target)) {
|
|
147
|
-
const existing = readRecord(target);
|
|
148
|
-
if (JSON.stringify(existing.report) !== JSON.stringify(approved)
|
|
149
|
-
|| JSON.stringify(existing.receipt) !== JSON.stringify(accepted)) {
|
|
150
|
-
throw new Error('refactor-root-review-conflict');
|
|
151
|
-
}
|
|
152
|
-
return accepted;
|
|
153
|
-
}
|
|
154
|
-
const directory = privateRefactorDirectory(current.root);
|
|
155
|
-
const temporary = join(directory, `review-${randomUUID()}.tmp`);
|
|
156
|
-
const handle = openSync(temporary, 'wx', 0o600);
|
|
157
|
-
try {
|
|
158
|
-
writeFileSync(handle, bytes);
|
|
159
|
-
fsyncSync(handle);
|
|
160
|
-
}
|
|
161
|
-
finally {
|
|
162
|
-
closeSync(handle);
|
|
163
|
-
}
|
|
164
|
-
try {
|
|
165
|
-
const physical = currentCandidate(current.root, admissionSha256, baselineSha256);
|
|
166
|
-
if (physical.candidateSha256 !== accepted.candidateSha256) {
|
|
167
|
-
throw new Error('refactor-root-review-unverified');
|
|
168
|
-
}
|
|
169
|
-
linkSync(temporary, target);
|
|
170
|
-
const directoryHandle = openSync(directory, 'r');
|
|
171
|
-
try {
|
|
172
|
-
fsyncSync(directoryHandle);
|
|
173
|
-
}
|
|
174
|
-
finally {
|
|
175
|
-
closeSync(directoryHandle);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
finally {
|
|
179
|
-
if (existsSync(temporary))
|
|
180
|
-
unlinkSync(temporary);
|
|
181
|
-
}
|
|
182
|
-
readRecord(target);
|
|
183
|
-
return accepted;
|
|
184
|
-
}
|
|
185
|
-
catch (error) {
|
|
186
|
-
if (error instanceof Error && error.message === 'refactor-root-review-conflict')
|
|
187
|
-
throw error;
|
|
188
|
-
throw new Error('refactor-root-review-unverified');
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
export function readRootRefactorSemanticReview(projectRoot, admissionSha256, baselineSha256) {
|
|
192
|
-
try {
|
|
193
|
-
const current = currentCandidate(projectRoot, admissionSha256, baselineSha256);
|
|
194
|
-
const record = readRecord(recordPath(current.root, admissionSha256, current.candidateSha256));
|
|
195
|
-
if (!exact(record, ['schemaVersion', 'kind', 'report', 'receipt', 'checksumSha256'])) {
|
|
196
|
-
throw new Error('refactor-root-review-unverified');
|
|
197
|
-
}
|
|
198
|
-
const approved = validatedReview(current, record.report);
|
|
199
|
-
const expected = receipt(current, approved);
|
|
200
|
-
if (JSON.stringify(record.receipt) !== JSON.stringify(expected)) {
|
|
201
|
-
throw new Error('refactor-root-review-unverified');
|
|
202
|
-
}
|
|
203
|
-
return expected;
|
|
204
|
-
}
|
|
205
|
-
catch {
|
|
206
|
-
throw new Error('refactor-root-review-unverified');
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
/** The report travels only over stdin and is never echoed on public CLI output. */
|
|
210
|
-
export async function refactorReviewCliHandler(args) {
|
|
211
|
-
const action = args[0];
|
|
212
|
-
let projectRoot = '';
|
|
213
|
-
let admissionSha256 = '';
|
|
214
|
-
let baselineSha256 = '';
|
|
215
|
-
let authorizeRun = false;
|
|
216
|
-
let authorizeReview = false;
|
|
217
|
-
let format = 'plain';
|
|
218
|
-
const seen = new Set();
|
|
219
|
-
try {
|
|
220
|
-
if (action !== 'review-accept' && action !== 'review-status') {
|
|
221
|
-
throw new Error('refactor-root-review-arguments-invalid');
|
|
222
|
-
}
|
|
223
|
-
for (let index = 1; index < args.length; index++) {
|
|
224
|
-
const token = args[index];
|
|
225
|
-
if (seen.has(token))
|
|
226
|
-
throw new Error('refactor-root-review-arguments-invalid');
|
|
227
|
-
seen.add(token);
|
|
228
|
-
const next = () => {
|
|
229
|
-
const value = args[++index];
|
|
230
|
-
if (!value || value.startsWith('--'))
|
|
231
|
-
throw new Error('refactor-root-review-arguments-invalid');
|
|
232
|
-
return value;
|
|
233
|
-
};
|
|
234
|
-
if (token === '--project-root')
|
|
235
|
-
projectRoot = next();
|
|
236
|
-
else if (token === '--admission-sha')
|
|
237
|
-
admissionSha256 = next();
|
|
238
|
-
else if (token === '--baseline-sha')
|
|
239
|
-
baselineSha256 = next();
|
|
240
|
-
else if (token === '--authorize-run')
|
|
241
|
-
authorizeRun = true;
|
|
242
|
-
else if (token === '--authorize-root-review')
|
|
243
|
-
authorizeReview = true;
|
|
244
|
-
else if (token === '--format')
|
|
245
|
-
format = next();
|
|
246
|
-
else
|
|
247
|
-
throw new Error('refactor-root-review-arguments-invalid');
|
|
248
|
-
}
|
|
249
|
-
if (!projectRoot || !SHA256.test(admissionSha256) || !SHA256.test(baselineSha256)
|
|
250
|
-
|| !['plain', 'json'].includes(format) || !authorizeRun
|
|
251
|
-
|| authorizeReview !== (action === 'review-accept')) {
|
|
252
|
-
throw new Error('refactor-root-review-arguments-invalid');
|
|
253
|
-
}
|
|
254
|
-
let accepted;
|
|
255
|
-
if (action === 'review-accept') {
|
|
256
|
-
let input = '';
|
|
257
|
-
for await (const chunk of process.stdin) {
|
|
258
|
-
input += String(chunk);
|
|
259
|
-
if (Buffer.byteLength(input) > MAX_REVIEW_BYTES) {
|
|
260
|
-
throw new Error('refactor-root-review-unverified');
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
const { parseDocument } = await import('yaml');
|
|
264
|
-
const document = parseDocument(input, { strict: true, uniqueKeys: true,
|
|
265
|
-
schema: 'core', customTags: [] });
|
|
266
|
-
if (document.errors.length || document.warnings.length) {
|
|
267
|
-
throw new Error('refactor-root-review-unverified');
|
|
268
|
-
}
|
|
269
|
-
accepted = acceptRootRefactorSemanticReview(projectRoot, admissionSha256, baselineSha256, JSON.parse(input));
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
accepted = readRootRefactorSemanticReview(projectRoot, admissionSha256, baselineSha256);
|
|
273
|
-
}
|
|
274
|
-
process.stdout.write(`${JSON.stringify({ ok: true, acceptance: accepted })}\n`);
|
|
275
|
-
return 0;
|
|
276
|
-
}
|
|
277
|
-
catch (error) {
|
|
278
|
-
const reasonCode = error instanceof Error && /^refactor-root-[a-z-]+$/.test(error.message)
|
|
279
|
-
? error.message : 'refactor-root-review-unverified';
|
|
280
|
-
process.stdout.write(`${JSON.stringify({ ok: false, reasonCode })}\n`);
|
|
281
|
-
return 1;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
1
|
+
import{createHash as $,randomUUID as C}from"node:crypto";import{closeSync as R,existsSync as k,fsyncSync as x,linkSync as H,lstatSync as N,openSync as O,readFileSync as F,realpathSync as j,unlinkSync as I,writeFileSync as V}from"node:fs";import{join as y,resolve as B}from"node:path";import{readRootRefactorBaseline as W,runRootRefactorCharacterization as D}from"./refactor-characterization.js";import{cppRefactorExecutableLines as M,isCppRefactorAssertionSite as T}from"./refactor-cpp-assertions.js";import{privateRefactorDirectory as z,readPrivateRefactorAdmission as q,verifyRootRefactor as _}from"./refactor-root.js";const l=/^[a-f0-9]{64}$/,S=128*1024;function v(t){return $("sha256").update(t).digest("hex")}function p(t,e){return t!==null&&typeof t=="object"&&!Array.isArray(t)&&Object.keys(t).sort().join("\0")===[...e].sort().join("\0")}function J(t,e){return typeof t=="string"&&t.length>=30&&t.length<=e&&!/[\x00-\x1f\x7f]/.test(t)}function g(t,e,n){if(!l.test(e)||!l.test(n))throw new Error("refactor-root-review-unverified");const o=B(t),i=q(o,e),a=W(o,n),c=_(o,e),r=D(o,e,a.testFiles.map(u=>u.path),a.dependencies.map(u=>u.path),"after",!0,a.causalPath,n,a.schemaVersion===2?a.runner:"native");if(a.admissionSha256!==e||a.sourceHead!==i.sourceHead||r.baselineSha256!==n||!r.testsPassedObserved||!r.causalFailureObserved||c.changedFileCount<2)throw new Error("refactor-root-review-unverified");return Object.freeze({root:o,storyId:i.storyId,sourceHead:i.sourceHead,admissionSha256:e,baselineSha256:n,candidateSha256:r.candidateSha256,testFiles:a.testFiles,changedFileCount:c.changedFileCount})}function P(t,e){if(!p(e,["schemaVersion","kind","storyId","sourceHead","admissionSha256","baselineSha256","candidateSha256","verdict","behaviorRationale","assertions"])||e.schemaVersion!==1||e.kind!=="root-refactor-semantic-review"||e.storyId!==t.storyId||e.sourceHead!==t.sourceHead||e.admissionSha256!==t.admissionSha256||e.baselineSha256!==t.baselineSha256||e.candidateSha256!==t.candidateSha256||e.verdict!=="approved"||!J(e.behaviorRationale,1e3)||!Array.isArray(e.assertions)||e.assertions.length<t.testFiles.length||e.assertions.length>64||Buffer.byteLength(JSON.stringify(e))>S)throw new Error("refactor-root-review-unverified");const n=new Map(t.testFiles.map(r=>[r.path,r.sha256])),o=new Map,i=new Map;for(const[r,u]of n){const f=y(t.root,r),s=N(f);if(!s.isFile()||s.isSymbolicLink()||j(f)!==f||s.size<1||s.size>8*1024*1024)throw new Error("refactor-root-review-unverified");const d=F(f);if(v(d)!==u)throw new Error("refactor-root-review-unverified");const h=new TextDecoder("utf-8",{fatal:!0}).decode(d);o.set(r,h.split(/\r?\n/)),r.endsWith(".cpp")&&i.set(r,M(h))}const a=new Set,c=new Set;for(const r of e.assertions){if(!p(r,["testPath","assertionLine","rationale"])||typeof r.testPath!="string"||!n.has(r.testPath)||!Number.isSafeInteger(r.assertionLine)||Number(r.assertionLine)<1||Number(r.assertionLine)>(o.get(r.testPath)?.length??0)||!J(r.rationale,500))throw new Error("refactor-root-review-unverified");const u=`${r.testPath}:${r.assertionLine}`;if(a.has(u))throw new Error("refactor-root-review-unverified");a.add(u),c.add(r.testPath);const f=o.get(r.testPath)[Number(r.assertionLine)-1],s=r.testPath.endsWith(".py")?(f.split("#")[0]??"").trimStart():f.split("//")[0]??"";if(!(r.testPath.endsWith(".cpp")?T(i.get(r.testPath)?.[Number(r.assertionLine)-1]??""):r.testPath.endsWith(".py")?/^self\.assert[A-Z][A-Za-z0-9_]*\s*\(/.test(s)||/^assert\s+\S/.test(s):/\b(?:assert|expect|throw)\b/.test(s)))throw new Error("refactor-root-review-unverified")}if(c.size!==n.size)throw new Error("refactor-root-review-unverified");return e}function A(t,e){return Object.freeze({schemaVersion:1,kind:"root-refactor-semantic-acceptance",storyId:t.storyId,sourceHead:t.sourceHead,admissionSha256:t.admissionSha256,baselineSha256:t.baselineSha256,candidateSha256:t.candidateSha256,reviewSha256:v(`root-refactor-semantic-review-v1\0${JSON.stringify(e)}`),testFileCount:t.testFiles.length,assertionCount:e.assertions.length,changedFileCount:t.changedFileCount,executionVerified:!0,qaAccepted:!0,gitCommitAuthorized:!1,publicSafe:!0})}function L(t,e,n){return y(z(t),`review-${e}-${n}.json`)}function E(t){const e=N(t);if(!e.isFile()||e.isSymbolicLink()||e.uid!==process.getuid?.()||(e.mode&63)!==0||e.size<100||e.size>S+4096)throw new Error("refactor-root-review-unverified");const n=F(t),o=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(n));if(!p(o,["schemaVersion","kind","report","receipt","checksumSha256"])||o.schemaVersion!==1||o.kind!=="root-refactor-semantic-record"||typeof o.checksumSha256!="string"||!l.test(o.checksumSha256)||!n.equals(Buffer.from(`${JSON.stringify(o)}
|
|
2
|
+
`))||o.checksumSha256!==v(`root-refactor-semantic-record-v1\0${JSON.stringify({report:o.report,receipt:o.receipt})}`))throw new Error("refactor-root-review-unverified");return o}function U(t,e,n,o){try{const i=g(t,e,n),a=P(i,o),c=A(i,a),r=L(i.root,e,i.candidateSha256),u={report:a,receipt:c},f={schemaVersion:1,kind:"root-refactor-semantic-record",...u,checksumSha256:v(`root-refactor-semantic-record-v1\0${JSON.stringify(u)}`)},s=Buffer.from(`${JSON.stringify(f)}
|
|
3
|
+
`);if(k(r)){const m=E(r);if(JSON.stringify(m.report)!==JSON.stringify(a)||JSON.stringify(m.receipt)!==JSON.stringify(c))throw new Error("refactor-root-review-conflict");return c}const d=z(i.root),h=y(d,`review-${C()}.tmp`),w=O(h,"wx",384);try{V(w,s),x(w)}finally{R(w)}try{if(g(i.root,e,n).candidateSha256!==c.candidateSha256)throw new Error("refactor-root-review-unverified");H(h,r);const b=O(d,"r");try{x(b)}finally{R(b)}}finally{k(h)&&I(h)}return E(r),c}catch(i){throw i instanceof Error&&i.message==="refactor-root-review-conflict"?i:new Error("refactor-root-review-unverified")}}function Z(t,e,n){try{const o=g(t,e,n),i=E(L(o.root,e,o.candidateSha256));if(!p(i,["schemaVersion","kind","report","receipt","checksumSha256"]))throw new Error("refactor-root-review-unverified");const a=P(o,i.report),c=A(o,a);if(JSON.stringify(i.receipt)!==JSON.stringify(c))throw new Error("refactor-root-review-unverified");return c}catch{throw new Error("refactor-root-review-unverified")}}async function te(t){const e=t[0];let n="",o="",i="",a=!1,c=!1,r="plain";const u=new Set;try{if(e!=="review-accept"&&e!=="review-status")throw new Error("refactor-root-review-arguments-invalid");for(let s=1;s<t.length;s++){const d=t[s];if(u.has(d))throw new Error("refactor-root-review-arguments-invalid");u.add(d);const h=()=>{const w=t[++s];if(!w||w.startsWith("--"))throw new Error("refactor-root-review-arguments-invalid");return w};if(d==="--project-root")n=h();else if(d==="--admission-sha")o=h();else if(d==="--baseline-sha")i=h();else if(d==="--authorize-run")a=!0;else if(d==="--authorize-root-review")c=!0;else if(d==="--format")r=h();else throw new Error("refactor-root-review-arguments-invalid")}if(!n||!l.test(o)||!l.test(i)||!["plain","json"].includes(r)||!a||c!==(e==="review-accept"))throw new Error("refactor-root-review-arguments-invalid");let f;if(e==="review-accept"){let s="";for await(const w of process.stdin)if(s+=String(w),Buffer.byteLength(s)>S)throw new Error("refactor-root-review-unverified");const{parseDocument:d}=await import("yaml"),h=d(s,{strict:!0,uniqueKeys:!0,schema:"core",customTags:[]});if(h.errors.length||h.warnings.length)throw new Error("refactor-root-review-unverified");f=U(n,o,i,JSON.parse(s))}else f=Z(n,o,i);return process.stdout.write(`${JSON.stringify({ok:!0,acceptance:f})}
|
|
4
|
+
`),0}catch(f){const s=f instanceof Error&&/^refactor-root-[a-z-]+$/.test(f.message)?f.message:"refactor-root-review-unverified";return process.stdout.write(`${JSON.stringify({ok:!1,reasonCode:s})}
|
|
5
|
+
`),1}}export{U as acceptRootRefactorSemanticReview,Z as readRootRefactorSemanticReview,te as refactorReviewCliHandler};
|