@ornexus/neocortex 4.60.67 → 4.60.68
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 +1194 -1194
- 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 +290 -3
- 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 +7140 -142
- 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.js +2536 -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/git-lifecycle-step-ids.js +14 -1
- package/packages/client/dist/git/git-lifecycle-store.js +1938 -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/project-identity-capability.js +50 -1
- package/packages/client/dist/migrations/project-identity.js +493 -7
- package/packages/client/dist/migrations/state-json.js +344 -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/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.js +1677 -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 +185 -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.js +33 -1
- package/packages/client/dist/yoloop/target-normalization.js +180 -1
- package/packages/client/dist/yoloop/yoloop-client-state-store.js +1723 -1
- 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,376 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/** Root-owned, synthetic-loopback Q01 reachable-link inventory and bound Q01–Q03 evidence. */
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { performance } from 'node:perf_hooks';
|
|
4
|
+
import { closeSync, constants, fstatSync, fsyncSync, openSync, readFileSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { dirname, join, resolve } from 'node:path';
|
|
6
|
+
import { aggregateRootQaScanReviews, planRootQaScan, rootQaScanEvidenceDirectory } from './qa-scan-review.js';
|
|
7
|
+
import { routeRootQaScanRequest } from './qa-scan-browser-route.js';
|
|
8
|
+
import { launchRootQaBrowser } from './qa-scan-browser-launch.js';
|
|
9
|
+
import { launchSyntheticBackendBrowser } from './qa-synthetic-browser.js';
|
|
10
|
+
import { openSyntheticBackendSession } from './qa-synthetic-backend.js';
|
|
11
|
+
const SHA256 = /^[a-f0-9]{64}$/;
|
|
12
|
+
const MAX_TARGETS = 16;
|
|
13
|
+
const MAX_URL_BYTES = 1024;
|
|
14
|
+
const MAX_RECORD_BYTES = 32_768;
|
|
15
|
+
const MAX_AGE_MS = 60 * 60_000;
|
|
16
|
+
// A load event can precede SPA hydration. Observe a bounded quiet window
|
|
17
|
+
// before treating rendered links as the Q01 inventory; never claim that an
|
|
18
|
+
// indefinitely changing page has a complete route set.
|
|
19
|
+
const LINK_QUIET_MS = 500;
|
|
20
|
+
const LINK_SETTLE_LIMIT_MS = 2_000;
|
|
21
|
+
const LINK_POLL_MS = 50;
|
|
22
|
+
function sha(value) {
|
|
23
|
+
return createHash('sha256').update(value).digest('hex');
|
|
24
|
+
}
|
|
25
|
+
function object(value) {
|
|
26
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
27
|
+
}
|
|
28
|
+
function exact(value, keys) {
|
|
29
|
+
return object(value) && Object.keys(value).sort().join('\0') === [...keys].sort().join('\0');
|
|
30
|
+
}
|
|
31
|
+
function privateRecord(root, prefix, id) {
|
|
32
|
+
if (!SHA256.test(id))
|
|
33
|
+
throw new Error('qa-scan-discovery-unverified');
|
|
34
|
+
return join(rootQaScanEvidenceDirectory(root), `${prefix}-${id}.json`);
|
|
35
|
+
}
|
|
36
|
+
function saveImmutable(path, value) {
|
|
37
|
+
const bytes = Buffer.from(`${JSON.stringify(value)}\n`);
|
|
38
|
+
const handle = openSync(path, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL
|
|
39
|
+
| (constants.O_NOFOLLOW ?? 0), 0o600);
|
|
40
|
+
try {
|
|
41
|
+
writeFileSync(handle, bytes);
|
|
42
|
+
fsyncSync(handle);
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
closeSync(handle);
|
|
46
|
+
}
|
|
47
|
+
const directoryHandle = openSync(dirname(path), constants.O_RDONLY | (constants.O_DIRECTORY ?? 0));
|
|
48
|
+
try {
|
|
49
|
+
fsyncSync(directoryHandle);
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
closeSync(directoryHandle);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function readImmutable(path, maxBytes) {
|
|
56
|
+
const handle = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
57
|
+
let raw;
|
|
58
|
+
let expectedSize;
|
|
59
|
+
try {
|
|
60
|
+
const stat = fstatSync(handle);
|
|
61
|
+
if (!stat.isFile() || stat.uid !== process.getuid?.()
|
|
62
|
+
|| (stat.mode & 0o077) !== 0 || stat.size < 1 || stat.size > maxBytes) {
|
|
63
|
+
throw new Error('qa-scan-discovery-unverified');
|
|
64
|
+
}
|
|
65
|
+
expectedSize = stat.size;
|
|
66
|
+
raw = readFileSync(handle);
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
closeSync(handle);
|
|
70
|
+
}
|
|
71
|
+
if (raw.length !== expectedSize || raw.length > maxBytes)
|
|
72
|
+
throw new Error('qa-scan-discovery-unverified');
|
|
73
|
+
const parsed = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(raw));
|
|
74
|
+
if (!raw.equals(Buffer.from(`${JSON.stringify(parsed)}\n`))) {
|
|
75
|
+
throw new Error('qa-scan-discovery-unverified');
|
|
76
|
+
}
|
|
77
|
+
return parsed;
|
|
78
|
+
}
|
|
79
|
+
function discoveryReceipt(body, discoverySha256) {
|
|
80
|
+
return Object.freeze({ schemaVersion: 2, kind: 'root-qa-scan-link-discovery',
|
|
81
|
+
sourceHead: body.sourceHead, seedSha256: body.seedSha256, discoverySha256,
|
|
82
|
+
targetCount: body.targetUrls.length, inventoryScope: 'reachable-rendered-same-origin-links',
|
|
83
|
+
qaAccepted: false, workflowContinuationAuthorized: false,
|
|
84
|
+
localOnly: true, publicSafe: true });
|
|
85
|
+
}
|
|
86
|
+
async function settledRenderedLinks(page) {
|
|
87
|
+
let previous;
|
|
88
|
+
let quietSince = performance.now();
|
|
89
|
+
const deadline = quietSince + LINK_SETTLE_LIMIT_MS;
|
|
90
|
+
while (performance.now() <= deadline) {
|
|
91
|
+
const links = await page.locator('a[href]').evaluateAll((anchors) => anchors.map((anchor) => anchor.href));
|
|
92
|
+
const serialized = JSON.stringify(links);
|
|
93
|
+
if (serialized !== previous) {
|
|
94
|
+
previous = serialized;
|
|
95
|
+
quietSince = performance.now();
|
|
96
|
+
}
|
|
97
|
+
else if (performance.now() - quietSince >= LINK_QUIET_MS) {
|
|
98
|
+
return links;
|
|
99
|
+
}
|
|
100
|
+
await page.waitForTimeout(LINK_POLL_MS);
|
|
101
|
+
}
|
|
102
|
+
throw new Error('qa-scan-discovery-scope-unverified');
|
|
103
|
+
}
|
|
104
|
+
/** Navigation itself may have application-defined GET effects. Opt in only
|
|
105
|
+
* for a purpose-built synthetic app; never borrow a browser profile/cookies. */
|
|
106
|
+
export async function discoverRootQaScanLinks(options) {
|
|
107
|
+
if (!options.authorizeDiscovery)
|
|
108
|
+
throw new Error('qa-scan-discovery-authorization-required');
|
|
109
|
+
const root = resolve(options.projectRoot);
|
|
110
|
+
const plan = planRootQaScan(root, 'discovery', options.seedUrl);
|
|
111
|
+
const seed = new URL(options.seedUrl);
|
|
112
|
+
if (Buffer.byteLength(seed.href) > MAX_URL_BYTES) {
|
|
113
|
+
throw new Error('qa-scan-discovery-scope-too-large');
|
|
114
|
+
}
|
|
115
|
+
let browser;
|
|
116
|
+
const backend = options.syntheticBackend ? await openSyntheticBackendSession({ projectRoot: root,
|
|
117
|
+
surface: 'discovery', targetUrl: options.seedUrl, ...options.syntheticBackend }) : undefined;
|
|
118
|
+
try {
|
|
119
|
+
browser = backend ? await launchSyntheticBackendBrowser() : await launchRootQaBrowser();
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
throw new Error('qa-scan-discovery-browser-unavailable');
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
const context = await browser.newContext({ serviceWorkers: 'block', acceptDownloads: false,
|
|
126
|
+
permissions: [], ignoreHTTPSErrors: false });
|
|
127
|
+
let denied = 0;
|
|
128
|
+
let failed = 0;
|
|
129
|
+
let navigations = 0;
|
|
130
|
+
let popups = 0;
|
|
131
|
+
await context.route('**/*', async (route) => {
|
|
132
|
+
let allowed = false;
|
|
133
|
+
try {
|
|
134
|
+
const request = route.request();
|
|
135
|
+
const url = new URL(request.url());
|
|
136
|
+
allowed = url.protocol === 'http:' && url.origin === seed.origin
|
|
137
|
+
&& (request.method() === 'GET' || request.method() === 'HEAD');
|
|
138
|
+
}
|
|
139
|
+
catch { /* Refuse malformed and opaque browser requests. */ }
|
|
140
|
+
if (backend) {
|
|
141
|
+
try {
|
|
142
|
+
if (!allowed)
|
|
143
|
+
throw new Error('denied');
|
|
144
|
+
const request = route.request();
|
|
145
|
+
const response = await backend.request(request.url(), request.method(), request.postData(), await request.allHeaders());
|
|
146
|
+
await route.fulfill({ status: response.status, body: response.body,
|
|
147
|
+
headers: { 'content-type': response.contentType, 'cache-control': 'no-store' } });
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
denied++;
|
|
151
|
+
await route.abort('blockedbyclient').catch(() => undefined);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else
|
|
155
|
+
await routeRootQaScanRequest(route, allowed, () => { denied++; });
|
|
156
|
+
});
|
|
157
|
+
await context.routeWebSocket(/.*/, async (socket) => {
|
|
158
|
+
denied++;
|
|
159
|
+
await socket.close({ code: 1008, reason: 'blocked' });
|
|
160
|
+
});
|
|
161
|
+
const page = await context.newPage();
|
|
162
|
+
context.on('page', (opened) => { if (opened !== page) {
|
|
163
|
+
popups++;
|
|
164
|
+
void opened.close();
|
|
165
|
+
} });
|
|
166
|
+
page.on('framenavigated', (frame) => {
|
|
167
|
+
if (frame === page.mainFrame() && frame.url() !== 'about:blank')
|
|
168
|
+
navigations++;
|
|
169
|
+
});
|
|
170
|
+
page.on('requestfailed', () => { failed++; });
|
|
171
|
+
page.on('response', (response) => { if (response.status() >= 400)
|
|
172
|
+
failed++; });
|
|
173
|
+
const targets = new Set([seed.href]);
|
|
174
|
+
const visited = new Set();
|
|
175
|
+
let anchorCount = 0;
|
|
176
|
+
while (visited.size < targets.size) {
|
|
177
|
+
const next = [...targets].filter((url) => !visited.has(url))
|
|
178
|
+
.sort((a, b) => Buffer.from(a).compare(Buffer.from(b)))[0];
|
|
179
|
+
if (!next || targets.size > MAX_TARGETS)
|
|
180
|
+
throw new Error('qa-scan-discovery-scope-too-large');
|
|
181
|
+
let response;
|
|
182
|
+
try {
|
|
183
|
+
response = await page.goto(next, { waitUntil: 'load', timeout: 15_000 });
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
throw new Error('qa-scan-discovery-target-unavailable');
|
|
187
|
+
}
|
|
188
|
+
if (!response || response.status() >= 400 || page.url() !== next
|
|
189
|
+
|| navigations !== visited.size + 1 || denied !== 0 || failed !== 0 || popups !== 0) {
|
|
190
|
+
throw new Error('qa-scan-discovery-target-unavailable');
|
|
191
|
+
}
|
|
192
|
+
const hrefs = await settledRenderedLinks(page);
|
|
193
|
+
anchorCount += hrefs.length;
|
|
194
|
+
if (anchorCount > 256)
|
|
195
|
+
throw new Error('qa-scan-discovery-scope-too-large');
|
|
196
|
+
for (const href of hrefs) {
|
|
197
|
+
if (typeof href !== 'string' || Buffer.byteLength(href) > MAX_URL_BYTES) {
|
|
198
|
+
throw new Error('qa-scan-discovery-scope-too-large');
|
|
199
|
+
}
|
|
200
|
+
let url;
|
|
201
|
+
try {
|
|
202
|
+
url = new URL(href);
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
throw new Error('qa-scan-discovery-target-unavailable');
|
|
206
|
+
}
|
|
207
|
+
if (url.origin !== seed.origin || url.protocol !== 'http:')
|
|
208
|
+
continue;
|
|
209
|
+
if (url.username || url.password || url.search || url.hash) {
|
|
210
|
+
throw new Error('qa-scan-discovery-target-unavailable');
|
|
211
|
+
}
|
|
212
|
+
targets.add(url.href);
|
|
213
|
+
if (targets.size > MAX_TARGETS)
|
|
214
|
+
throw new Error('qa-scan-discovery-scope-too-large');
|
|
215
|
+
}
|
|
216
|
+
const finalHrefs = await page.locator('a[href]').evaluateAll((anchors) => anchors.map((anchor) => anchor.href));
|
|
217
|
+
if (JSON.stringify(finalHrefs) !== JSON.stringify(hrefs)
|
|
218
|
+
|| page.url() !== next || navigations !== visited.size + 1
|
|
219
|
+
|| denied !== 0 || failed !== 0 || popups !== 0) {
|
|
220
|
+
throw new Error('qa-scan-discovery-scope-unverified');
|
|
221
|
+
}
|
|
222
|
+
visited.add(next);
|
|
223
|
+
}
|
|
224
|
+
const targetUrls = [...targets].sort((a, b) => Buffer.from(a).compare(Buffer.from(b)));
|
|
225
|
+
if (targetUrls.length < 1 || targetUrls.length > MAX_TARGETS
|
|
226
|
+
|| visited.size !== targets.size || navigations !== visited.size
|
|
227
|
+
|| denied !== 0 || failed !== 0 || popups !== 0) {
|
|
228
|
+
throw new Error('qa-scan-discovery-scope-unverified');
|
|
229
|
+
}
|
|
230
|
+
const fresh = planRootQaScan(root, 'discovery', options.seedUrl);
|
|
231
|
+
if (backend)
|
|
232
|
+
await backend.verify();
|
|
233
|
+
if (fresh.planSha256 !== plan.planSha256)
|
|
234
|
+
throw new Error('qa-scan-discovery-source-drift');
|
|
235
|
+
const body = { schemaVersion: 2, sourceHead: plan.sourceHead,
|
|
236
|
+
seedUrl: seed.href, seedSha256: plan.targetSha256,
|
|
237
|
+
capturedAt: new Date().toISOString(), targetUrls, pageCount: visited.size };
|
|
238
|
+
const discoverySha256 = sha(JSON.stringify(body));
|
|
239
|
+
const path = privateRecord(root, 'discovery', discoverySha256);
|
|
240
|
+
if (Buffer.byteLength(JSON.stringify({ ...body, discoverySha256 })) + 1 > MAX_RECORD_BYTES) {
|
|
241
|
+
throw new Error('qa-scan-discovery-scope-too-large');
|
|
242
|
+
}
|
|
243
|
+
saveImmutable(path, { ...body, discoverySha256 });
|
|
244
|
+
return discoveryReceipt(body, discoverySha256);
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
if (error instanceof Error && error.message.startsWith('qa-scan-discovery-'))
|
|
248
|
+
throw error;
|
|
249
|
+
throw new Error('qa-scan-discovery-unverified');
|
|
250
|
+
}
|
|
251
|
+
finally {
|
|
252
|
+
await browser.close().catch(() => undefined);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function readDiscovery(root, id) {
|
|
256
|
+
const value = readImmutable(privateRecord(root, 'discovery', id), MAX_RECORD_BYTES);
|
|
257
|
+
if (!exact(value, ['schemaVersion', 'sourceHead', 'seedUrl', 'seedSha256',
|
|
258
|
+
'capturedAt', 'targetUrls', 'pageCount', 'discoverySha256']) || value.schemaVersion !== 2
|
|
259
|
+
|| value.discoverySha256 !== id || typeof value.seedUrl !== 'string'
|
|
260
|
+
|| typeof value.sourceHead !== 'string' || typeof value.seedSha256 !== 'string'
|
|
261
|
+
|| Buffer.byteLength(value.seedUrl) > MAX_URL_BYTES
|
|
262
|
+
|| !SHA256.test(value.seedSha256) || !Array.isArray(value.targetUrls)
|
|
263
|
+
|| value.targetUrls.length < 1 || value.targetUrls.length > MAX_TARGETS
|
|
264
|
+
|| value.pageCount !== value.targetUrls.length
|
|
265
|
+
|| typeof value.capturedAt !== 'string')
|
|
266
|
+
throw new Error('qa-scan-discovery-unverified');
|
|
267
|
+
const age = Date.now() - Date.parse(value.capturedAt);
|
|
268
|
+
if (!Number.isFinite(age) || new Date(value.capturedAt).toISOString() !== value.capturedAt
|
|
269
|
+
|| age < -5 * 60_000 || age > MAX_AGE_MS) {
|
|
270
|
+
throw new Error('qa-scan-discovery-unverified');
|
|
271
|
+
}
|
|
272
|
+
const plan = planRootQaScan(root, 'discovery', value.seedUrl);
|
|
273
|
+
if (value.sourceHead !== plan.sourceHead || value.seedSha256 !== plan.targetSha256) {
|
|
274
|
+
throw new Error('qa-scan-discovery-unverified');
|
|
275
|
+
}
|
|
276
|
+
const seed = new URL(value.seedUrl);
|
|
277
|
+
const urls = value.targetUrls;
|
|
278
|
+
if (!urls.every((item) => typeof item === 'string' && Buffer.byteLength(item) <= MAX_URL_BYTES && (() => {
|
|
279
|
+
try {
|
|
280
|
+
const url = new URL(item);
|
|
281
|
+
return url.origin === seed.origin && url.protocol === 'http:'
|
|
282
|
+
&& !url.username && !url.password && !url.search && !url.hash && url.href === item;
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
})()) || !urls.includes(seed.href)
|
|
288
|
+
|| JSON.stringify(urls) !== JSON.stringify([...new Set(urls)].sort((a, b) => Buffer.from(String(a)).compare(Buffer.from(String(b)))))) {
|
|
289
|
+
throw new Error('qa-scan-discovery-unverified');
|
|
290
|
+
}
|
|
291
|
+
const { discoverySha256: _digest, ...body } = value;
|
|
292
|
+
if (sha(JSON.stringify(body)) !== id)
|
|
293
|
+
throw new Error('qa-scan-discovery-unverified');
|
|
294
|
+
return body;
|
|
295
|
+
}
|
|
296
|
+
export function readRootQaScanDiscovery(projectRoot, id) {
|
|
297
|
+
try {
|
|
298
|
+
return discoveryReceipt(readDiscovery(resolve(projectRoot), id), id);
|
|
299
|
+
}
|
|
300
|
+
catch {
|
|
301
|
+
throw new Error('qa-scan-discovery-unverified');
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
/** Root/worker evidence verification only; reopening validates source and the complete inventory. */
|
|
305
|
+
export function readRootQaScanDiscoveryTargets(projectRoot, id) {
|
|
306
|
+
try {
|
|
307
|
+
return Object.freeze([...readDiscovery(resolve(projectRoot), id).targetUrls]);
|
|
308
|
+
}
|
|
309
|
+
catch {
|
|
310
|
+
throw new Error('qa-scan-discovery-unverified');
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
function discoveredPhase(root, id, input) {
|
|
314
|
+
if (!exact(input, ['schemaVersion', 'targets']) || input.schemaVersion !== 1
|
|
315
|
+
|| !Array.isArray(input.targets))
|
|
316
|
+
throw new Error('qa-scan-discovery-phase-unverified');
|
|
317
|
+
const discovery = readDiscovery(root, id);
|
|
318
|
+
const targetUrls = input.targets.map((target) => {
|
|
319
|
+
if (!exact(target, ['surface', 'targetUrl']) || typeof target.targetUrl !== 'string') {
|
|
320
|
+
throw new Error('qa-scan-discovery-phase-unverified');
|
|
321
|
+
}
|
|
322
|
+
return target.targetUrl;
|
|
323
|
+
}).sort((a, b) => Buffer.from(a).compare(Buffer.from(b)));
|
|
324
|
+
if (JSON.stringify(targetUrls) !== JSON.stringify(discovery.targetUrls)) {
|
|
325
|
+
throw new Error('qa-scan-discovery-phase-unverified');
|
|
326
|
+
}
|
|
327
|
+
const aggregate = aggregateRootQaScanReviews(root, input);
|
|
328
|
+
if (aggregate.sourceHead !== discovery.sourceHead
|
|
329
|
+
|| (aggregate.qaAccepted && (aggregate.verdict !== 'approved' || aggregate.issueCount !== 0))
|
|
330
|
+
|| (!aggregate.qaAccepted && (aggregate.verdict !== 'issues-found' || aggregate.issueCount < 1))) {
|
|
331
|
+
throw new Error('qa-scan-discovery-phase-unverified');
|
|
332
|
+
}
|
|
333
|
+
return Object.freeze({ schemaVersion: 2, kind: 'root-qa-scan-discovered-phase-checkpoint',
|
|
334
|
+
sourceHead: discovery.sourceHead, discoverySha256: id,
|
|
335
|
+
aggregateSha256: aggregate.aggregateSha256, surfaceCount: aggregate.surfaceCount,
|
|
336
|
+
inventoryScope: 'reachable-rendered-same-origin-links', qaAccepted: aggregate.qaAccepted,
|
|
337
|
+
workflowContinuationAuthorized: false, localOnly: true, publicSafe: true });
|
|
338
|
+
}
|
|
339
|
+
export function acceptRootQaScanDiscoveredPhase(projectRoot, id, input) {
|
|
340
|
+
try {
|
|
341
|
+
const root = resolve(projectRoot);
|
|
342
|
+
const receipt = discoveredPhase(root, id, input);
|
|
343
|
+
const record = { receipt, checksumSha256: sha(`qa-scan-discovered-phase-v2\0${JSON.stringify(receipt)}`) };
|
|
344
|
+
const path = privateRecord(root, 'discovered-phase', sha(`${id}\0${receipt.aggregateSha256}`));
|
|
345
|
+
try {
|
|
346
|
+
saveImmutable(path, record);
|
|
347
|
+
}
|
|
348
|
+
catch (error) {
|
|
349
|
+
if (error.code !== 'EEXIST')
|
|
350
|
+
throw error;
|
|
351
|
+
}
|
|
352
|
+
if (JSON.stringify(readRootQaScanDiscoveredPhase(root, id, input)) !== JSON.stringify(receipt)) {
|
|
353
|
+
throw new Error('qa-scan-discovery-phase-unverified');
|
|
354
|
+
}
|
|
355
|
+
return receipt;
|
|
356
|
+
}
|
|
357
|
+
catch {
|
|
358
|
+
throw new Error('qa-scan-discovery-phase-unverified');
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
export function readRootQaScanDiscoveredPhase(projectRoot, id, input) {
|
|
362
|
+
try {
|
|
363
|
+
const root = resolve(projectRoot);
|
|
364
|
+
const expected = discoveredPhase(root, id, input);
|
|
365
|
+
const value = readImmutable(privateRecord(root, 'discovered-phase', sha(`${id}\0${expected.aggregateSha256}`)), 4096);
|
|
366
|
+
if (!exact(value, ['receipt', 'checksumSha256'])
|
|
367
|
+
|| value.checksumSha256 !== sha(`qa-scan-discovered-phase-v2\0${JSON.stringify(value.receipt)}`)
|
|
368
|
+
|| JSON.stringify(value.receipt) !== JSON.stringify(expected)) {
|
|
369
|
+
throw new Error('qa-scan-discovery-phase-unverified');
|
|
370
|
+
}
|
|
371
|
+
return expected;
|
|
372
|
+
}
|
|
373
|
+
catch {
|
|
374
|
+
throw new Error('qa-scan-discovery-phase-unverified');
|
|
375
|
+
}
|
|
376
|
+
}
|