77 lines
8.5 KiB
JavaScript
77 lines
8.5 KiB
JavaScript
// Build a read-only source index from already sealed AD evidence. No model,
|
|
// task, command, approval, retry, Git write or native-v2 envelope is produced.
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import assert from 'node:assert/strict';
|
|
import { execFileSync } from 'node:child_process';
|
|
import { createHash } from 'node:crypto';
|
|
|
|
const repository = process.cwd(), evidence = path.resolve('.qa/live-validation-ad');
|
|
const output = path.resolve('.qa/coordination-readonly-2026-11-11-engineering-ad-r2');
|
|
assert.equal(fs.existsSync(output), false, 'Do not overwrite a source handoff.');
|
|
const sha = bytes => createHash('sha256').update(bytes).digest('hex');
|
|
const parse = file => JSON.parse(fs.readFileSync(path.join(evidence, file), 'utf8'));
|
|
const originalManifestBytes = fs.readFileSync(path.join(evidence, 'FINAL-MANIFEST.json'));
|
|
const originalManifest = JSON.parse(originalManifestBytes), members = new Map(originalManifest.files.map(value => [value.path, value]));
|
|
const result = parse('node/result.json'), state = parse('node/session.json'), frozen = parse('current.json');
|
|
const ids = { projectId: state.projectId, sessionId: state.id, taskId: state.execution.task.id, runId: state.execution.run.id };
|
|
assert.equal(ids.taskId, result.taskId); assert.equal(ids.sessionId, result.sessionId);
|
|
assert.equal(state.execution.run.taskId, ids.taskId);
|
|
fs.mkdirSync(output); const sources = [], missing = [];
|
|
const addSealed = relative => {
|
|
const member = members.get(relative); assert.ok(member, 'Original manifest member: ' + relative);
|
|
const file = path.join(evidence, relative), bytes = fs.readFileSync(file);
|
|
assert.equal(bytes.length, member.bytes); assert.equal(sha(bytes), member.sha256);
|
|
sources.push({ path: file, bytes: bytes.length, sha256: sha(bytes), origin: 'original-ad-seal', originalRelative: relative });
|
|
};
|
|
for (const file of ['node/goal.txt', 'node/contract.json', 'node/source-before.json', 'node/result.json', 'node/session.json', 'node/export.json', 'node/attempts.json', 'node/git-log.txt', 'node/git-status.txt',
|
|
'node/baseline/test.txt', 'node/baseline/build.txt', 'node/baseline/result.json', 'node/independent-final/test.txt', 'node/independent-final/build.txt', 'node/independent-final/result.json',
|
|
'node/expense-project/package.json', 'node/expense-project/test/expense.test.mjs', 'node/expense-project/scripts/build.mjs', ...result.committedPaths.map(file => 'node/expense-project/' + file), ...result.captures.map(value => value.path)]) addSealed(file);
|
|
const plan = execFileSync('git', ['show', frozen.driverCommit + ':docs/LIVE-VALIDATION-AD-PLAN.md'], { windowsHide: true });
|
|
const planPath = path.join(output, 'original-predeclared-plan.md'); fs.writeFileSync(planPath, plan, { flag: 'wx' });
|
|
sources.push({ path: planPath, bytes: plan.length, sha256: sha(plan), origin: 'original-git-blob', commit: frozen.driverCommit, repositoryPath: 'docs/LIVE-VALIDATION-AD-PLAN.md' });
|
|
const artifactIds = new Set(state.execution.checks.flatMap(value => (value.results ?? []).map(row => row.logArtifactId)).filter(Boolean));
|
|
for (const value of state.execution.artifacts) if (/^delivery-report/.test(value.kind)) artifactIds.add(value.id);
|
|
const originalArtifacts = [];
|
|
for (const id of artifactIds) {
|
|
const artifact = state.execution.artifacts.find(value => value.id === id);
|
|
if (!artifact) { missing.push({ artifactId: id, reason: 'Check log descriptor absent from the sealed session artifact preview; independent-final logs remain in the read scope.' }); continue; }
|
|
for (const [key, expected] of Object.entries(ids)) assert.equal(artifact[key], expected, 'Artifact ownership: ' + key);
|
|
assert.match(artifact.relative, /^[a-f0-9]{2}\/[a-f0-9]{64}\.blob$/);
|
|
const originalPath = path.join(frozen.host.identity.dataRoot, 'artifacts', artifact.relative);
|
|
if (!fs.existsSync(originalPath)) { missing.push({ artifactId: id, kind: artifact.kind, reason: 'Original artifact file unavailable', expectedSha256: artifact.sha256 }); continue; }
|
|
const bytes = fs.readFileSync(originalPath); assert.equal(bytes.length, artifact.bytes); assert.equal(sha(bytes), artifact.sha256);
|
|
const target = path.join(output, id + (artifact.mediaType === 'application/json' ? '.json' : '.txt'));
|
|
fs.writeFileSync(target, bytes, { flag: 'wx' });
|
|
sources.push({ path: target, bytes: bytes.length, sha256: sha(bytes), origin: 'byte-exact-copy-of-original-owned-artifact', artifactId: id, kind: artifact.kind });
|
|
originalArtifacts.push({ ...artifact, sharedPath: target, originalPath, copiedBytesExact: true });
|
|
}
|
|
const report = originalArtifacts.find(value => value.kind === 'delivery-report');
|
|
const reportBody = report ? JSON.parse(fs.readFileSync(report.sharedPath, 'utf8')) : null;
|
|
const metadata = {
|
|
schemaVersion: 1, kind: 'workbench-readonly-engineering-source-index', generatedAt: new Date().toISOString(),
|
|
sourceName: 'agent-workbench/ad/node/' + ids.taskId + '/' + ids.runId, ids, originalVersion: '1.25.8', originalDriverCommit: frozen.driverCommit,
|
|
purpose: 'Read-only acceptance of an existing independent Node task. No incoming restricted delegation or new M4 task is represented.',
|
|
goalPath: path.join(evidence, 'node/goal.txt'), predeclaredPlanPath: planPath, originalTaskContract: state.execution.task.contract,
|
|
originalStructuredAcceptance: state.execution.task.acceptance,
|
|
originalReportArtifact: report ? { id: report.id, path: report.sharedPath, sha256: report.sha256, bytes: report.bytes, status: reportBody?.status ?? null } : null,
|
|
reportMetadata: originalArtifacts.filter(value => /^delivery-report/.test(value.kind)), checkLogMetadata: originalArtifacts.filter(value => artifactIds.has(value.id) && !/^delivery-report/.test(value.kind)),
|
|
engineering: { sourceRoot: result.sourceRoot, initialHead: result.initialHead, commit: result.commit, committedPaths: result.committedPaths, committedCurrent: result.committedCurrent,
|
|
actualIndependentChecks: result.final, ownerBytesAndIndexPreserved: result.allOriginalOwnerBytesAndIndexPreserved, supervisorContinuations: result.supervisionContinuations },
|
|
originalOutcome: { independentEngineeringSuccess: result.success, sessionStatus: state.status, taskStatus: state.execution.task.status, runStatus: state.execution.run.status,
|
|
terminalGitObserved: true, nativeDeliveryRows: state.execution.deliveries.length, internalDeliveryReportStatus: reportBody?.status ?? 'missing',
|
|
taskVerification: state.execution.task.verification, productStopReason: result.productStopReason, failure: result.failure, usage: result.usage,
|
|
missing, batchNetworkAndClaudeErrors: 'Preserved separately in QA-LIVE-VALIDATION-AD.md; the Node subset does not replace the whole-batch outcome.' },
|
|
readiness: { originalTaskAndRunAvailable: true, originalReportsCopied: !!report, nativeEngineeringEvidenceV2Envelope: false, restrictedDelegationReceiver: 'not_established_by_this_source',
|
|
originalKeyLookup: 'not_established_by_this_source', currentM4Engineering: 'not_dispatched_at_source_index_creation', allConsumerContractFieldsSatisfied: false,
|
|
gaps: ['No producer-native mnemo.engineering-evidence.v2 envelope or receipt is claimed.', 'The original task structured acceptance array is empty; the raw goal, predeclared plan and original tests carry its conditions.', 'Original terminal Git success and internal in_progress report remain distinct.'] },
|
|
readScope: { mode: 'read-only-existing-evidence', allowedFiles: sources, originalManifestPath: path.join(evidence, 'FINAL-MANIFEST.json'), originalManifestSha256: sha(originalManifestBytes),
|
|
excludes: ['Any credential value or credential store', 'Whole formal data directory or SQLite database', 'Other user projects or unrelated sessions', 'Replay, retry, execution, write or native-v2 certification'] },
|
|
actions: { realModelRequests: 0, engineeringDispatches: 0, gitWrites: 0, originalArtifactsChanged: false, keysReadOrResaved: false, messagesSentToOtherThreads: 0 },
|
|
};
|
|
const metadataPath = path.join(repository, 'docs/integration/WORKBENCH-AD-NODE-READONLY-SOURCE-2026-11-11.json');
|
|
fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2) + '\n', { flag: 'wx' });
|
|
const metadataBytes = fs.readFileSync(metadataPath);
|
|
fs.writeFileSync(path.join(output, 'SOURCE-MANIFEST.json'), JSON.stringify({ schemaVersion: 1, metadataPath, metadataSha256: sha(metadataBytes), sources, originalArtifacts, missing }, null, 2) + '\n', { flag: 'wx' });
|
|
console.log(JSON.stringify({ metadataPath, output, sourceName: metadata.sourceName, reportStatus: metadata.originalOutcome.internalDeliveryReportStatus, terminalGit: result.commit, nativeV2Envelope: false, allowedFiles: sources.length, missing: missing.length, realModelRequests: 0 }));
|