axstack 0.66.0 → 0.68.0
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/README.md +3 -3
- package/docs/host-operations.md +8 -8
- package/docs/installation.md +8 -8
- package/docs/workflows.md +5 -9
- package/package.json +2 -2
- package/skills/axstack/references/automations.md +11 -19
- package/skills/axstack/references/autopilot.md +1 -0
- package/skills/axstack/references/candidate-publication.md +7 -12
- package/skills/axstack/references/capture-receipts.md +22 -0
- package/skills/axstack/references/fleet-verification.md +3 -3
- package/skills/axstack/references/lifecycle.md +2 -2
- package/skills/axstack/references/live-run.md +59 -0
- package/skills/axstack/references/pr-shape.md +14 -9
- package/skills/axstack/references/review-manager-prompt.md +37 -19
- package/skills/axstack/references/run-record.md +2 -2
- package/skills/axstack/references/schedule-policy.json +123 -0
- package/skills/axstack/references/t3-runtime.md +5 -5
- package/skills/axstack/references/test-audit-weekly.md +1 -2
- package/skills/axstack/references/ui-verification.md +5 -3
- package/skills/axstack/references/workspace-hygiene.md +12 -3
- package/skills/axstack/sandbox/Dockerfile +28 -0
- package/skills/axstack/sandbox/host-execution.md +14 -0
- package/skills/axstack/sandbox/inventory.json +503 -0
- package/skills/axstack/sandbox/launcher-capture.js +63 -0
- package/skills/axstack/sandbox/launcher-contract.schema.json +341 -0
- package/skills/axstack/sandbox/launcher-contracts.js +35 -0
- package/skills/axstack/sandbox/launcher-docker.js +75 -0
- package/skills/axstack/sandbox/launcher-host-budget.json +10 -0
- package/skills/axstack/sandbox/launcher-host.js +165 -0
- package/skills/axstack/sandbox/launcher-host.json +5 -0
- package/skills/axstack/sandbox/launcher-image.json +4 -0
- package/skills/axstack/sandbox/launcher-interface.md +7 -0
- package/skills/axstack/sandbox/launcher-policy.js +135 -0
- package/skills/axstack/sandbox/launcher-policy.json +121 -0
- package/skills/axstack/sandbox/launcher-runtime.js +157 -0
- package/skills/axstack/sandbox/launcher-source.js +72 -0
- package/skills/axstack/sandbox/launcher.js +106 -0
- package/skills/axstack/sandbox/network-address.js +39 -0
- package/skills/axstack/sandbox/network-firewall.js +81 -0
- package/skills/axstack/sandbox/network-rules.js +86 -0
- package/skills/axstack/sandbox/network-runtime.js +109 -0
- package/skills/axstack/sandbox/network.js +49 -0
- package/skills/axstack/sandbox/probes-android-platform.xml +17 -0
- package/skills/axstack/sandbox/probes-check.js +185 -0
- package/skills/axstack/sandbox/probes-exec.js +20 -0
- package/skills/axstack/sandbox/probes-image-build.js +129 -0
- package/skills/axstack/sandbox/probes-image-pins.json +370 -0
- package/skills/axstack/sandbox/probes-link-local.js +25 -0
- package/skills/axstack/sandbox/probes-storage.js +33 -0
- package/skills/axstack/sandbox/probes-udp.js +44 -0
- package/skills/axstack/sandbox/probes.js +239 -0
- package/skills/axstack/sandbox/proxy-command.js +6 -0
- package/skills/axstack/sandbox/proxy-config.json +9 -0
- package/skills/axstack/sandbox/proxy-dns.js +114 -0
- package/skills/axstack/sandbox/proxy-policy.js +22 -0
- package/skills/axstack/sandbox/proxy.js +119 -0
- package/skills/axstack/sandbox/reap.md +7 -0
- package/skills/axstack/sandbox/sidecars.json +153 -0
- package/skills/axstack/sandbox/storage-checks.js +39 -0
- package/skills/axstack/sandbox/storage-cleanup.js +49 -0
- package/skills/axstack/sandbox/storage-execution.js +110 -0
- package/skills/axstack/sandbox/storage-plan.js +78 -0
- package/skills/axstack/sandbox/storage-support.js +91 -0
- package/skills/axstack/sandbox/storage.js +75 -0
- package/skills/axstack/scripts/archive-evidence.js +2 -2
- package/skills/axstack/scripts/capture-identity.js +122 -0
- package/skills/axstack/scripts/check-run.js +248 -0
- package/skills/axstack/scripts/check-staged-file-tokens.js +6 -3
- package/skills/axstack/scripts/command-capture.js +81 -0
- package/skills/axstack/scripts/evidence-inspector.js +182 -0
- package/skills/axstack/scripts/git-argv.js +6 -0
- package/skills/axstack/scripts/image-evidence.js +183 -0
- package/skills/axstack/scripts/pr-shape.js +206 -22
- package/skills/axstack/scripts/readiness-run.js +3 -75
- package/skills/axstack/scripts/readiness.js +2 -2
- package/skills/axstack/scripts/run-init.js +13 -11
- package/skills/axstack/scripts/schedule-drift.js +132 -0
- package/skills/axstack/scripts/scratch.js +201 -0
- package/skills/axstack-audit/SKILL.md +2 -0
- package/skills/axstack-audit/references/record.md +1 -1
- package/skills/axstack-explain/references/inline-pages.md +8 -4
- package/skills/axstack-implement/SKILL.md +6 -5
- package/skills/axstack-review/references/candidate-brief.md +12 -21
- package/skills/axstack-review/references/codebase-brief.md +1 -0
- package/skills/axstack-review/references/codebase-mode.md +4 -1
- package/skills/axstack-review/references/codebase-report.md +2 -1
- package/skills/axstack-review/references/review-candidate.md +2 -2
- package/skills/axstack-review/references/review-receipt.md +8 -3
- package/skills/axstack-verify/SKILL.md +18 -5
- package/skills/axstack-watch/references/proven-verification.md +3 -2
- package/skills/axstack-watch/references/readiness.md +56 -61
- package/skills/voa/references/verification.md +5 -2
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { readFileSync, realpathSync } from 'node:fs';
|
|
3
|
+
import { captureTerms, sha256 } from './capture-identity.js';
|
|
4
|
+
import { validate } from '../sandbox/launcher-policy.js';
|
|
5
|
+
|
|
6
|
+
const kinds = ['runtime', 'fixture', 'instruction-contract'];
|
|
7
|
+
const text = value => typeof value === 'string' && value.trim().length > 0;
|
|
8
|
+
const sha = value => typeof value === 'string' && /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(value);
|
|
9
|
+
const time = value => typeof value === 'string' && /^\d{4}-\d\d-\d\dT.*(?:Z|[+-]\d\d:\d\d)$/.test(value) ? Date.parse(value) : NaN;
|
|
10
|
+
const rules = {
|
|
11
|
+
fail: 'open, conflicting/invalid disposition, sibling, stale binding, rejected kind, old/reused evidence, invalid/failed capture',
|
|
12
|
+
unknown: 'missing disposition/receipt/decision, unavailable log, incomplete capture, chronology or source coverage',
|
|
13
|
+
};
|
|
14
|
+
export const help = `Usage: evidence-inspector.js --input PATH [--help]
|
|
15
|
+
Read-only, stateless schema-v1 limitation reconciliation. Flags:
|
|
16
|
+
--input PATH JSON packet with schemaVersion:1, repository, full head/base SHAs,
|
|
17
|
+
items and dispositions. Relative receipt paths resolve beside input.
|
|
18
|
+
--help Show this schema, rules and effects; reads no packet.
|
|
19
|
+
Optional review:{mode:peer|authored, localTests:boolean, sandboxReceipt:<envelope
|
|
20
|
+
object or JSON path>, limitation, hold}. Review consumers must supply it even
|
|
21
|
+
with no limitations (items/dispositions may then be empty). Authored yields n/a.
|
|
22
|
+
Peer local test claims without an envelope fail; unavailable/held sandbox without
|
|
23
|
+
a test claim is unknown with limitation/hold retained. The peer-sandbox term
|
|
24
|
+
revalidates the envelope schema, containment/cleanup terms, capture digest,
|
|
25
|
+
repository/head/base, log/source identity and sandbox tool/test/image binding.
|
|
26
|
+
This measures receipt consistency, not authenticated isolation or test success.
|
|
27
|
+
Capture cwd is not checked: the envelope lacks an expected source path.
|
|
28
|
+
Items: unique stable id, head, base, boundary, changedAt, raisedAt (ISO times),
|
|
29
|
+
acceptedProofKinds (runtime | fixture | instruction-contract), sourceScope
|
|
30
|
+
(tracked+untracked-nonignored | ignored | external), optional expectedExitCode
|
|
31
|
+
(default 0), previousEvidence:[{id,logSha256}] (default []). Keep original item
|
|
32
|
+
IDs, boundaries and prior evidence when supplying a new disposition.
|
|
33
|
+
Dispositions: id, head, base, boundary, status: proved | withdrawn-by-reviewer |
|
|
34
|
+
user-accepted-unproven | open. Exactly one per item; none is unknown.
|
|
35
|
+
Proved: proof:{id,itemId,kind,observedAt,receipt}. receipt is a capture schema-v1
|
|
36
|
+
object or JSON path. Revalidates captureTerms with packet repository/head/base
|
|
37
|
+
and reads its logPath; never trusts cached terms. New evidence must postdate both
|
|
38
|
+
change and limitation, and cannot reuse a previous ID or log digest. A named
|
|
39
|
+
proof or captured log cannot belong to multiple items. Its kind
|
|
40
|
+
must be accepted by that item. Sibling logs are compared by digest; identical honest logs fail closed. expectedExitCode belongs to the item policy.
|
|
41
|
+
Decisions: decision:{itemId,repository,head,base,boundary,role,by,at,reason,reference}.
|
|
42
|
+
role must be reviewer for withdrawal, user for acceptance. These are caller-
|
|
43
|
+
supplied decision records, not authenticated identities or proof of behavior.
|
|
44
|
+
Decision must postdate change and limitation. Acceptance stays explicitly unproven.
|
|
45
|
+
Source-dependent proof needs snapshotScope.files=tracked+untracked-nonignored.
|
|
46
|
+
Ignored bytes are never covered by the capture source term. Missing scope stays
|
|
47
|
+
unknown; external boundaries do not rely on source coverage. Timestamps and proof
|
|
48
|
+
kind are caller declarations: capture v1 does not attest chronology or proof kind.
|
|
49
|
+
Fail: ${rules.fail}.
|
|
50
|
+
Unknown: ${rules.unknown}. Invalid packet/flags are errors.
|
|
51
|
+
Effects: reads input, named receipt JSON and captured log files only; stdout JSON
|
|
52
|
+
has one term per item, stable reasonCode, accepted kinds, rules, evidence and
|
|
53
|
+
status counts only. Consumers must read each term's disposition: summary.pass
|
|
54
|
+
includes proved, reviewer-withdrawn and user-accepted-unproven records; it does
|
|
55
|
+
not count proven behaviors. Rebind item head/base to current packet revisions
|
|
56
|
+
while preserving original IDs, boundaries and previousEvidence.
|
|
57
|
+
No writes, subprocesses, network, retained state, dispatch, retry or cleanup.
|
|
58
|
+
Pass measures consistency, not semantic sufficiency. Reviewer owns judgment;
|
|
59
|
+
this cannot grant review/merge authority or an aggregate verdict.
|
|
60
|
+
Exit: 0 measured (including fail), 1 input error, 2 incomplete (any unknown).
|
|
61
|
+
`;
|
|
62
|
+
|
|
63
|
+
function readReceipt(receipt, directory) {
|
|
64
|
+
if (typeof receipt !== 'string') return receipt;
|
|
65
|
+
return JSON.parse(readFileSync(receipt.startsWith('/') ? receipt : `${directory}/${receipt}`, 'utf8'));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function evaluate(item, dispositions, expected, directory, allDispositions) {
|
|
69
|
+
const outcome = (status, reasonCode, reason, details = null) => ({ status, reasonCode, evidence: { reason, details } });
|
|
70
|
+
if (item.head !== expected.head || item.base !== expected.base) return outcome('fail', 'item-revision-mismatch', 'item head/base is stale');
|
|
71
|
+
if (!text(item.boundary)) return outcome('unknown', 'item-boundary-missing', 'missing item boundary');
|
|
72
|
+
if (dispositions.length === 0) return outcome('unknown', 'disposition-missing', 'missing disposition');
|
|
73
|
+
if (dispositions.length !== 1) return outcome('fail', 'disposition-conflict', 'multiple dispositions');
|
|
74
|
+
const d = dispositions[0];
|
|
75
|
+
if (d.head !== expected.head || d.base !== expected.base) return outcome('fail', 'disposition-revision-mismatch', 'disposition head/base is stale');
|
|
76
|
+
if (d.boundary !== item.boundary) return outcome('fail', 'disposition-boundary-mismatch', 'disposition boundary differs');
|
|
77
|
+
if (d.status === 'open') return outcome('fail', 'limitation-open', 'limitation remains open');
|
|
78
|
+
if (!['proved', 'withdrawn-by-reviewer', 'user-accepted-unproven'].includes(d.status)) return outcome('fail', 'disposition-invalid', 'invalid disposition');
|
|
79
|
+
const decision = d.status !== 'proved';
|
|
80
|
+
const proof = decision ? d.decision : d.proof;
|
|
81
|
+
if (!proof || typeof proof !== 'object') return outcome('unknown', decision ? 'decision-missing' : 'proof-missing', decision ? 'missing decision receipt' : 'missing proof receipt');
|
|
82
|
+
if (proof.itemId !== item.id) return outcome('fail', 'evidence-item-mismatch', 'evidence belongs to another item');
|
|
83
|
+
const at = time(decision ? proof.at : proof.observedAt), changed = time(item.changedAt), raised = time(item.raisedAt);
|
|
84
|
+
if (![at, changed, raised].every(Number.isFinite)) return outcome('unknown', 'chronology-invalid', 'missing/invalid declared chronology');
|
|
85
|
+
if (at <= Math.max(changed, raised)) return outcome('fail', 'evidence-predates-limitation', 'evidence predates change or limitation', { at, changed, raised });
|
|
86
|
+
if (decision) {
|
|
87
|
+
const role = d.status === 'withdrawn-by-reviewer' ? 'reviewer' : 'user';
|
|
88
|
+
if (proof.repository !== expected.repository || proof.head !== expected.head || proof.base !== expected.base || proof.boundary !== item.boundary) return outcome('fail', 'decision-binding-mismatch', 'decision repository/head/base/boundary differs');
|
|
89
|
+
if (proof.role !== role) return outcome('fail', 'decision-role-invalid', 'invalid decision role');
|
|
90
|
+
if (![proof.by, proof.reason, proof.reference].every(text)) return outcome('unknown', 'decision-incomplete', 'incomplete decision receipt');
|
|
91
|
+
return outcome('pass', d.status === 'user-accepted-unproven' ? 'user-accepted-unproven' : 'reviewer-withdrawn', d.status === 'user-accepted-unproven' ? 'recorded user acceptance; behavior remains unproven' : 'recorded reviewer withdrawal', proof);
|
|
92
|
+
}
|
|
93
|
+
if (!Array.isArray(item.acceptedProofKinds) || !item.acceptedProofKinds.length || item.acceptedProofKinds.some(k => !kinds.includes(k))) return outcome('unknown', 'accepted-kinds-invalid', 'missing/invalid accepted proof kinds');
|
|
94
|
+
if (!kinds.includes(proof.kind) || !item.acceptedProofKinds.includes(proof.kind)) return outcome('fail', 'proof-kind-rejected', 'proof kind is not accepted');
|
|
95
|
+
if (!text(proof.id)) return outcome('unknown', 'proof-id-missing', 'missing named evidence ID');
|
|
96
|
+
const siblings = allDispositions.filter(other => other.id !== item.id && other.status === 'proved' && other.proof);
|
|
97
|
+
if (siblings.some(other => other.proof.id === proof.id)) return outcome('fail', 'sibling-proof-reused', 'named proof assigned to another item');
|
|
98
|
+
if (!Array.isArray(item.previousEvidence ?? []) || (item.previousEvidence ?? []).some(p => !p || typeof p !== 'object' || Array.isArray(p))) return outcome('unknown', 'previous-evidence-invalid', 'invalid previous evidence inventory');
|
|
99
|
+
if ((item.previousEvidence ?? []).some(p => p.id === proof.id)) return outcome('fail', 'previous-proof-reused', 'reused evidence without changed disposition');
|
|
100
|
+
let receipt = proof.receipt;
|
|
101
|
+
if (!receipt) return outcome('unknown', 'capture-receipt-missing', 'missing capture receipt');
|
|
102
|
+
try { receipt = readReceipt(receipt, directory); }
|
|
103
|
+
catch (error) { return outcome(error instanceof SyntaxError ? 'fail' : 'unknown', error instanceof SyntaxError ? 'capture-json-invalid' : 'capture-receipt-unavailable', 'invalid or unavailable capture receipt', error.message); }
|
|
104
|
+
if (!receipt || typeof receipt !== 'object' || Array.isArray(receipt)) return outcome('fail', 'capture-receipt-invalid', 'invalid capture receipt');
|
|
105
|
+
const terms = captureTerms(receipt, expected);
|
|
106
|
+
// captureTerms intentionally reports malformed schema as unknown; here it is
|
|
107
|
+
// a supplied invalid receipt, distinct from an unavailable log/capture tail.
|
|
108
|
+
if (terms[0].status === 'unknown') return outcome('fail', 'capture-schema-invalid', 'invalid capture receipt schema', terms);
|
|
109
|
+
if (terms.some(t => t.status === 'fail')) return outcome('fail', 'capture-validation-failed', 'capture validation failed', terms);
|
|
110
|
+
if (terms.some(t => t.status === 'unknown')) return outcome('unknown', 'capture-validation-incomplete', 'capture validation incomplete', terms);
|
|
111
|
+
for (const other of siblings) {
|
|
112
|
+
try {
|
|
113
|
+
const sibling = readReceipt(other.proof.receipt, directory);
|
|
114
|
+
if (sibling?.logSha256 === receipt.logSha256 || (sibling?.logPath && realpathSync(sibling.logPath) === realpathSync(receipt.logPath))) return outcome('fail', 'sibling-log-reused', 'capture log assigned to another item');
|
|
115
|
+
} catch { /* That item's own term reports its unavailable/invalid receipt. */ }
|
|
116
|
+
}
|
|
117
|
+
if ((item.previousEvidence ?? []).some(p => p.logSha256 === receipt.logSha256)) return outcome('fail', 'previous-log-reused', 'reused log evidence without changed disposition');
|
|
118
|
+
if (!Number.isInteger(item.expectedExitCode ?? 0)) return outcome('unknown', 'expected-exit-invalid', 'invalid expected exit code');
|
|
119
|
+
if (receipt.exitCode !== (item.expectedExitCode ?? 0)) return outcome('fail', 'capture-exit-mismatch', 'captured exit differs from item policy', { actual: receipt.exitCode, expected: item.expectedExitCode ?? 0 });
|
|
120
|
+
if (item.sourceScope === 'ignored') return outcome('unknown', 'source-ignored', 'ignored bytes are not bound by source capture');
|
|
121
|
+
if (!['external', 'tracked+untracked-nonignored'].includes(item.sourceScope)) return outcome('unknown', 'source-scope-invalid', 'missing/invalid source scope');
|
|
122
|
+
if (item.sourceScope !== 'external' && receipt.snapshotScope?.files !== 'tracked+untracked-nonignored') return outcome('unknown', 'snapshot-scope-missing', 'capture snapshot scope unavailable');
|
|
123
|
+
return outcome('pass', 'capture-consistent', 'new item-bound capture is consistent; semantic sufficiency requires reviewer judgment', { id: proof.id, kind: proof.kind, declaredObservedAt: proof.observedAt, chronology: 'caller-declared, not capture-attested', terms });
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function peerSandbox(review, expected, directory) {
|
|
127
|
+
const result = (status, reasonCode, evidence = {}) => ({ id: 'peer-sandbox', status, reasonCode, evidence });
|
|
128
|
+
if (review?.mode === 'authored') return result('n/a', 'authored-local-checks');
|
|
129
|
+
if (review?.mode !== 'peer' || typeof review.localTests !== 'boolean') return result('unknown', 'review-mode-missing');
|
|
130
|
+
if (!review.sandboxReceipt) return review.localTests
|
|
131
|
+
? result('fail', 'sandbox-receipt-missing')
|
|
132
|
+
: result('unknown', 'sandbox-unavailable', { limitation: review.limitation ?? null, hold: review.hold ?? null });
|
|
133
|
+
try {
|
|
134
|
+
const envelope = readReceipt(review.sandboxReceipt, directory);
|
|
135
|
+
validate('receipt', envelope);
|
|
136
|
+
if ([...envelope.terms, ...envelope.probeResults].some(t => !['pass', 'n/a'].includes(t.status))) throw Error('containment/cleanup incomplete');
|
|
137
|
+
const path = envelope.capture.receiptPath;
|
|
138
|
+
const bytes = readFileSync(path.startsWith('/') ? path : `${directory}/${path}`);
|
|
139
|
+
if (sha256(bytes) !== envelope.capture.receiptSha256) throw Error('capture digest differs');
|
|
140
|
+
const capture = JSON.parse(bytes.toString()), terms = captureTerms(capture, expected);
|
|
141
|
+
if (terms.some(t => t.status === 'fail')) throw Error('capture identity/log/source differs');
|
|
142
|
+
if (capture.tool?.name !== 'axstack-sandbox' || capture.tool.version !== '1.0.0'
|
|
143
|
+
|| capture.kind !== 'sandbox-test' || !envelope.imageDigests.includes(capture.sandboxImageDigest)
|
|
144
|
+
|| capture.spawnArgv?.[0] !== 'docker' || capture.spawnArgv?.[1] !== 'exec'
|
|
145
|
+
|| !capture.spawnArgv.includes(`${envelope.runId}-test`)) throw Error('capture is not the sandbox test');
|
|
146
|
+
if (terms.some(t => t.status === 'unknown')) return result('unknown', 'sandbox-capture-incomplete', { terms });
|
|
147
|
+
return result('pass', 'sandbox-consistent', { capture: envelope.capture, terms, exitCode: capture.exitCode });
|
|
148
|
+
} catch (error) {
|
|
149
|
+
return result((error.code === 'ENOENT' || error.code === 'EACCES') && !review.localTests ? 'unknown' : 'fail',
|
|
150
|
+
error.code === 'ENOENT' || error.code === 'EACCES' ? 'sandbox-receipt-unavailable' : 'sandbox-validation-failed', { reason: error.message });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function inspectEvidence(packet, directory = '.') {
|
|
155
|
+
if (packet?.schemaVersion !== 1 || !text(packet.repository) || !sha(packet.head) || !sha(packet.base)
|
|
156
|
+
|| !Array.isArray(packet.items) || (!packet.items.length && !packet.review) || !Array.isArray(packet.dispositions)) throw Error('schema v1 requires repository, full head/base, items and dispositions arrays (nonempty items unless review supplied)');
|
|
157
|
+
const ids = packet.items.map(item => item?.id);
|
|
158
|
+
if (!ids.every(text) || new Set(ids).size !== ids.length) throw Error('item IDs must be nonempty and unique');
|
|
159
|
+
if (packet.dispositions.some(d => !d || !ids.includes(d.id))) throw Error('disposition references an unknown item');
|
|
160
|
+
const expected = { repository: packet.repository, head: packet.head, base: packet.base };
|
|
161
|
+
const terms = packet.items.map(item => {
|
|
162
|
+
const dispositions = packet.dispositions.filter(d => d.id === item.id);
|
|
163
|
+
return { id: item.id, boundary: item.boundary, disposition: dispositions.length === 1 ? dispositions[0].status : null,
|
|
164
|
+
acceptedProofKinds: item.acceptedProofKinds ?? [], rules, ...evaluate(item, dispositions, expected, directory, packet.dispositions) };
|
|
165
|
+
});
|
|
166
|
+
if (packet.review) terms.push(peerSandbox(packet.review, expected, directory));
|
|
167
|
+
const summary = { pass: 0, fail: 0, unknown: 0, 'n/a': 0 };
|
|
168
|
+
for (const term of terms) summary[term.status]++;
|
|
169
|
+
return { schemaVersion: 1, terms, summary };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function main(args, io = { stdout: console.log, stderr: console.error }) {
|
|
173
|
+
if (args.includes('--help')) { io.stdout(help); return 0; }
|
|
174
|
+
try {
|
|
175
|
+
if (args.length !== 2 || args[0] !== '--input' || !args[1] || args[1].startsWith('--')) throw Error('expected --input PATH; use --help');
|
|
176
|
+
const path = realpathSync(args[1]);
|
|
177
|
+
const report = inspectEvidence(JSON.parse(readFileSync(path, 'utf8')), path.slice(0, path.lastIndexOf('/')) || '/');
|
|
178
|
+
io.stdout(JSON.stringify(report, null, 2));
|
|
179
|
+
return report.summary.unknown ? 2 : 0;
|
|
180
|
+
} catch (error) { io.stderr(`Evidence inspector: ${error.message}`); return 1; }
|
|
181
|
+
}
|
|
182
|
+
if (import.meta.main) process.exit(main(process.argv.slice(2)));
|
|
@@ -2,3 +2,9 @@
|
|
|
2
2
|
export function gitArgv(...args) {
|
|
3
3
|
return ['git', '--no-optional-locks', '-c', 'core.hooksPath=/dev/null', '-c', 'core.fsmonitor=false', ...args];
|
|
4
4
|
}
|
|
5
|
+
|
|
6
|
+
// Scrubs inherited GIT_* only; trusted cwd + --no-env-file block peer .env
|
|
7
|
+
// (including non-Git controls such as XDG_CONFIG_HOME or LD_PRELOAD).
|
|
8
|
+
export function gitEnv(env = process.env) {
|
|
9
|
+
return Object.fromEntries(Object.entries(env).filter(([key]) => !key.startsWith('GIT_')));
|
|
10
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
const help = `Usage: bun image-evidence.js --page FILE [--observations FILE]
|
|
4
|
+
--page FILE Exact final UTF-8 HTML bytes before delivery; SHA-256 precedes parsing.
|
|
5
|
+
--observations FILE Saved Playwright MCP JSON: {sha256,resources:[{url,status,evidence}]}.
|
|
6
|
+
status: pass/fail/unknown; evidence: nonempty tool-result reference/detail.
|
|
7
|
+
url is the decoded authored URL, not the resolved/currentSrc URL.
|
|
8
|
+
--help Show flags, input schema, limits and effects; takes precedence over other args.
|
|
9
|
+
Fact mode: static img/src/srcset, picture/source/srcset, input/image, video/poster,
|
|
10
|
+
SVG image/feImage/use, object/embed, image link href/imagesrcset, legacy background,
|
|
11
|
+
inline CSS url()/image-set(). CSS imports, font-face URLs and local fragments are excluded.
|
|
12
|
+
Locations identify each occurrence; unmatched observations have source "observation-only".
|
|
13
|
+
No script execution, CSS cascade, external stylesheet traversal or browser/network access.
|
|
14
|
+
Dynamic resources and unsupported named HTML entities require reviewer coverage; unobserved
|
|
15
|
+
and unselected candidates, stale digests or conflicting observations stay unknown.
|
|
16
|
+
Reviewer uses Playwright MCP on exactly these final bytes before delivery, checks load AND image decode
|
|
17
|
+
(complete/naturalWidth or decode()), including CSS images; an HTTP 200 alone is insufficient.
|
|
18
|
+
Scroll lazy images; exercise relevant states. Inaccessible/unobservable resources stay unknown.
|
|
19
|
+
Output: per-resource facts with evidence, SHA-256 and counts only; never an aggregate verdict.
|
|
20
|
+
Side effects: reads only named files; writes JSON to stdout, errors to stderr. No subprocess,
|
|
21
|
+
dispatch, scheduling, retries, merge, persistent state or cleanup.
|
|
22
|
+
Exit: 0 measured (including fail), 1 invalid input/error, 2 incomplete (unknown resources).
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
const entities = { amp: '&', quot: '"', apos: "'", lt: '<', gt: '>', Tab: '\t', NewLine: '\n' };
|
|
26
|
+
const scalar = (point) => String.fromCodePoint(point > 0 && point <= 0x10ffff
|
|
27
|
+
&& !(point >= 0xd800 && point <= 0xdfff) ? point : 0xfffd);
|
|
28
|
+
function htmlValue(value) {
|
|
29
|
+
return value.replace(/&(#x[\da-f]+|#\d+|[a-z][\da-z]+);/gi, (whole, key) => {
|
|
30
|
+
if (!key.startsWith('#')) return Object.hasOwn(entities, key) ? entities[key] : whole;
|
|
31
|
+
const point = key[1].toLowerCase() === 'x' ? Number.parseInt(key.slice(2), 16) : Number(key.slice(1));
|
|
32
|
+
return scalar(point);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function candidates(value) {
|
|
37
|
+
const urls = [];
|
|
38
|
+
let rest = value;
|
|
39
|
+
while (rest) {
|
|
40
|
+
rest = rest.replace(/^[\s,]+/, '');
|
|
41
|
+
const match = /^\S+/.exec(rest);
|
|
42
|
+
if (!match) break;
|
|
43
|
+
const token = match[0];
|
|
44
|
+
urls.push(token.replace(/,+$/, ''));
|
|
45
|
+
rest = rest.slice(token.length);
|
|
46
|
+
if (!token.endsWith(',')) rest = rest.replace(/^[^,]*(?:,|$)/, '');
|
|
47
|
+
}
|
|
48
|
+
return urls;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function cssUrls(css) {
|
|
52
|
+
const urls = [];
|
|
53
|
+
const add = (value) => {
|
|
54
|
+
const url = value.trim().replace(
|
|
55
|
+
/\\([\da-f]{1,6}[\t\n\f\r ]?|[\s\S])/gi,
|
|
56
|
+
(_, escaped) => /^[\da-f]/i.test(escaped)
|
|
57
|
+
? scalar(Number.parseInt(escaped.trim(), 16))
|
|
58
|
+
: escaped.replace(/[\n\r\f]/g, ''),
|
|
59
|
+
);
|
|
60
|
+
if (!url.startsWith('#')) urls.push(url);
|
|
61
|
+
};
|
|
62
|
+
// Tokenize strings/comments atomically; only image-set candidate strings are URLs.
|
|
63
|
+
const tokens = /\/\*[\s\S]*?\*\/|(?<![\w-])url\(\s*(?:"((?:\\[\s\S]|[^"\\])*)"|'((?:\\[\s\S]|[^'\\])*)'|((?:\\[\s\S]|[^)\\])*))\s*\)|"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'|(?<![\w-])(?:-webkit-)?image-set\(|@import\b|@font-face\b|[{}();,]/gi;
|
|
64
|
+
const functions = [];
|
|
65
|
+
let depth = 0, fontDepth = null, fontPending = false, importing = false;
|
|
66
|
+
for (const token of css.matchAll(tokens)) {
|
|
67
|
+
const text = token[0], lower = text.toLowerCase();
|
|
68
|
+
if (text.startsWith('/*')) continue;
|
|
69
|
+
if (lower === '@import') { importing = true; continue; }
|
|
70
|
+
if (lower === '@font-face') { fontPending = true; continue; }
|
|
71
|
+
if (text === '{') { depth++; if (fontPending) fontDepth = depth; fontPending = false; continue; }
|
|
72
|
+
if (text === '}') { if (fontDepth === depth) fontDepth = null; depth--; continue; }
|
|
73
|
+
if (text === ';') { importing = false; functions.length = 0; continue; }
|
|
74
|
+
if (importing || fontDepth !== null) continue;
|
|
75
|
+
if (lower.endsWith('image-set(')) { functions.push({ imageSet: true, candidate: true }); continue; }
|
|
76
|
+
if (text === '(') { functions.push({ imageSet: false, candidate: false }); continue; }
|
|
77
|
+
if (text === ')') { functions.pop(); continue; }
|
|
78
|
+
const current = functions.at(-1);
|
|
79
|
+
if (text === ',') { if (current) current.candidate = true; continue; }
|
|
80
|
+
const url = token[1] ?? token[2] ?? token[3];
|
|
81
|
+
if (url !== undefined) add(url);
|
|
82
|
+
else if (current?.imageSet && current.candidate && /^["']/.test(text)) add(text.slice(1, -1));
|
|
83
|
+
if (current) current.candidate = false;
|
|
84
|
+
}
|
|
85
|
+
return urls;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function expectedResources(bytes) {
|
|
89
|
+
const expected = new Map();
|
|
90
|
+
const add = (url, location) => {
|
|
91
|
+
url = url.trim();
|
|
92
|
+
if (!expected.has(url)) expected.set(url, { url, locations: [] });
|
|
93
|
+
expected.get(url).locations.push(location);
|
|
94
|
+
};
|
|
95
|
+
const styles = [];
|
|
96
|
+
let index = 0;
|
|
97
|
+
await new HTMLRewriter().on('*', { element(element) {
|
|
98
|
+
const tag = element.tagName.toLowerCase(), location = `${tag}[${++index}]`;
|
|
99
|
+
const attr = (name) => {
|
|
100
|
+
const value = element.getAttribute(name);
|
|
101
|
+
return value === null ? null : htmlValue(value);
|
|
102
|
+
};
|
|
103
|
+
const single = (name) => { const value = attr(name); if (value !== null) add(value, `${location}@${name}`); };
|
|
104
|
+
const set = (name) => { for (const url of candidates(attr(name) ?? '')) add(url, `${location}@${name}`); };
|
|
105
|
+
if (tag === 'img' && attr('src') === null && !attr('srcset')?.trim()) add('', `${location}@src (absent)`);
|
|
106
|
+
if (['img', 'image', 'embed'].includes(tag) || tag === 'input' && attr('type')?.toLowerCase() === 'image') single('src');
|
|
107
|
+
if (['img', 'source'].includes(tag)) set('srcset');
|
|
108
|
+
if (tag === 'video') single('poster');
|
|
109
|
+
if (tag === 'object') single('data');
|
|
110
|
+
if (['body', 'table', 'td', 'th'].includes(tag)) single('background');
|
|
111
|
+
if (['image', 'feimage', 'use'].includes(tag)) {
|
|
112
|
+
const name = attr('href') !== null ? 'href' : 'xlink:href';
|
|
113
|
+
if (tag !== 'use' || !attr(name)?.trim().startsWith('#')) single(name);
|
|
114
|
+
}
|
|
115
|
+
if (tag === 'link' && (/\bicon\b/i.test(attr('rel') ?? '') || attr('as')?.toLowerCase() === 'image')) {
|
|
116
|
+
single('href'); set('imagesrcset');
|
|
117
|
+
}
|
|
118
|
+
for (const url of cssUrls(attr('style') ?? '')) add(url, `${location}@style`);
|
|
119
|
+
} }).on('style', {
|
|
120
|
+
element() { styles.push(''); },
|
|
121
|
+
text(chunk) { styles[styles.length - 1] += chunk.text; },
|
|
122
|
+
}).transform(new Response(bytes)).text();
|
|
123
|
+
for (const [i, style] of styles.entries()) for (const url of cssUrls(style)) add(url, `style[${i + 1}]`);
|
|
124
|
+
return [...expected.values()];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export async function imageEvidence(bytes, observations) {
|
|
128
|
+
const sha256 = new Bun.CryptoHasher('sha256').update(bytes).digest('hex');
|
|
129
|
+
if (observations !== undefined) {
|
|
130
|
+
if (!/^[a-f\d]{64}$/.test(observations?.sha256 ?? '') || !Array.isArray(observations.resources)) {
|
|
131
|
+
throw new Error('observations require sha256 and resources array');
|
|
132
|
+
}
|
|
133
|
+
for (const row of observations.resources) {
|
|
134
|
+
if (typeof row?.url !== 'string' || !['pass', 'fail', 'unknown'].includes(row.status)) {
|
|
135
|
+
throw new Error('observation url/status invalid');
|
|
136
|
+
}
|
|
137
|
+
if (typeof row.evidence !== 'string' || !row.evidence.trim()) throw new Error('observation evidence required');
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const expected = await expectedResources(bytes);
|
|
141
|
+
const known = new Set(expected.map((resource) => resource.url));
|
|
142
|
+
for (const row of observations?.resources ?? []) {
|
|
143
|
+
if (known.has(row.url)) continue;
|
|
144
|
+
known.add(row.url);
|
|
145
|
+
expected.push({ ...row, source: 'observation-only', locations: ['observation-only'] });
|
|
146
|
+
}
|
|
147
|
+
const resources = expected.map((resource) => {
|
|
148
|
+
const matches = observations?.resources.filter((row) => row.url === resource.url) ?? [];
|
|
149
|
+
let status = 'unknown', evidence = 'No observation: absent or unobservable resource';
|
|
150
|
+
if (observations && observations.sha256 !== sha256) evidence = 'SHA-256 differs from observed page bytes';
|
|
151
|
+
else if (/&[a-z][\da-z]+;/i.test(resource.url)) evidence = 'Unsupported named HTML entity; browser URL needs review';
|
|
152
|
+
else if (new Set(matches.map((row) => row.status)).size > 1) evidence = 'Conflicting observations; needs review';
|
|
153
|
+
else if (matches.length) { status = matches[0].status; evidence = matches.map((row) => row.evidence).join('; '); }
|
|
154
|
+
return { ...resource, status, evidence };
|
|
155
|
+
});
|
|
156
|
+
const summary = { pass: 0, fail: 0, unknown: 0, 'n/a': 0 };
|
|
157
|
+
for (const resource of resources) summary[resource.status]++;
|
|
158
|
+
return { sha256, resources, summary };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (import.meta.main) {
|
|
162
|
+
try {
|
|
163
|
+
const argv = process.argv.slice(2), args = {};
|
|
164
|
+
if (argv.includes('--help')) console.log(help);
|
|
165
|
+
else {
|
|
166
|
+
for (let i = 0; i < argv.length; i += 2) {
|
|
167
|
+
if (!['--page', '--observations'].includes(argv[i]) || !argv[i + 1] || args[argv[i]]) {
|
|
168
|
+
throw new Error(`invalid argument: ${argv[i]}`);
|
|
169
|
+
}
|
|
170
|
+
args[argv[i]] = argv[i + 1];
|
|
171
|
+
}
|
|
172
|
+
if (!args['--page']) throw new Error('--page is required (see --help)');
|
|
173
|
+
const bytes = new Uint8Array(await Bun.file(args['--page']).arrayBuffer());
|
|
174
|
+
const observations = args['--observations'] ? await Bun.file(args['--observations']).json() : undefined;
|
|
175
|
+
const report = await imageEvidence(bytes, observations);
|
|
176
|
+
console.log(JSON.stringify(report, null, 2));
|
|
177
|
+
process.exitCode = report.summary.unknown ? 2 : 0;
|
|
178
|
+
}
|
|
179
|
+
} catch (error) {
|
|
180
|
+
console.error(`Image evidence: ${error.message}`);
|
|
181
|
+
process.exitCode = 1;
|
|
182
|
+
}
|
|
183
|
+
}
|