@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,3 +1,93 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/** Preserve line numbers while excluding C++ comments and quoted/raw string data. */
|
|
2
|
+
export function cppRefactorExecutableLines(text) {
|
|
3
|
+
let code = '', i = 0, state = 'code';
|
|
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,5 +1,283 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/** Explicit root semantic QA for one physically characterized refactor candidate. */
|
|
2
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
3
|
+
import { closeSync, existsSync, fsyncSync, linkSync, lstatSync, openSync, readFileSync, realpathSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { join, resolve } from 'node:path';
|
|
5
|
+
import { readRootRefactorBaseline, runRootRefactorCharacterization } from './refactor-characterization.js';
|
|
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
|
+
}
|