axstack 0.67.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 +2 -2
- package/docs/host-operations.md +3 -6
- package/docs/installation.md +8 -8
- package/docs/workflows.md +5 -9
- package/package.json +2 -2
- package/skills/axstack/references/automations.md +3 -14
- package/skills/axstack/references/autopilot.md +1 -0
- package/skills/axstack/references/capture-receipts.md +22 -0
- package/skills/axstack/references/lifecycle.md +1 -1
- package/skills/axstack/references/live-run.md +59 -0
- package/skills/axstack/references/pr-shape.md +13 -16
- package/skills/axstack/references/review-manager-prompt.md +21 -19
- package/skills/axstack/references/run-record.md +2 -2
- 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 +3 -0
- 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 +54 -29
- 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 +5 -3
- 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 +10 -4
- package/skills/axstack-watch/references/proven-verification.md +3 -2
- package/skills/axstack-watch/references/readiness.md +56 -61
|
@@ -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
|
+
}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { gitArgv } from './git-argv.js';
|
|
1
|
+
import { gitArgv, gitEnv } from './git-argv.js';
|
|
2
2
|
import { existsSync, readFileSync } from 'node:fs';
|
|
3
3
|
|
|
4
4
|
const lockfiles = ['bun.lock', 'bun.lockb', 'package-lock.json', 'npm-shrinkwrap.json', 'pnpm-lock.yaml', 'yarn.lock'];
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const sandboxDirectory = 'skills/axstack/sandbox';
|
|
6
|
+
const sandboxPrefix = `${sandboxDirectory}/`;
|
|
7
|
+
const help = `Usage: bun scripts/pr-shape.js --base <ref> --head <ref> --repo <path>
|
|
8
|
+
Example: bun scripts/pr-shape.js --base main --head HEAD --repo /path/to/repo
|
|
7
9
|
|
|
8
10
|
--base Required actual PR base (parent branch for a stacked child)
|
|
9
11
|
--head Required candidate commit or branch
|
|
12
|
+
--repo Required Git checkout path; run the installed helper from a trusted cwd
|
|
10
13
|
--source Optional source ref for the read-only sync term; no source means n/a
|
|
11
14
|
--help Show flags, example, bucket definitions and exit codes
|
|
12
15
|
|
|
@@ -14,6 +17,7 @@ Read-only Git; writes nothing, retains no state. Prints a bounded JSON summary:
|
|
|
14
17
|
input refs and resolved SHAs, merge-base, full additions/deletions, rename and
|
|
15
18
|
binary counts, and overlapping lockfile/generated buckets, with status and
|
|
16
19
|
reproducing argv plus calculation instructions. No path inventory is emitted.
|
|
20
|
+
For untrusted checkouts, use --repo from a trusted cwd with bun --no-env-file.
|
|
17
21
|
Lockfiles match these exact basenames at any depth: ${lockfiles.join(', ')}.
|
|
18
22
|
Generated means linguist-generated set or true in .gitattributes at the head;
|
|
19
23
|
uses the destination path for renames. Unset, false and unspecified are excluded.
|
|
@@ -21,6 +25,10 @@ Ignores system/global attributes; local info/attributes causes an unknown bucket
|
|
|
21
25
|
Never subtract buckets; formatter-only changes require manual disclosure.
|
|
22
26
|
Sync reports B <= H AND (H <= S OR (B <= S AND H tree == S tree)).
|
|
23
27
|
Ancestor exit 1 means fail; other Git errors or missing source objects mean unknown.
|
|
28
|
+
Shape term sandbox-path: fail (user-merge hold) when either rename endpoint or
|
|
29
|
+
another changed path equals ${sandboxDirectory} or starts with ${sandboxPrefix}; otherwise pass.
|
|
30
|
+
Shape diff overrides submodule-ignore settings so committed gitlink changes stay visible.
|
|
31
|
+
Unavailable path evidence is unknown, including Git errors (existing exits retained).
|
|
24
32
|
No term grants authority. No cohesion or approval verdict.
|
|
25
33
|
Exit codes: 0 measured (including failed terms), 1 input/Git error,
|
|
26
34
|
2 incomplete (unknown sync, no merge-base or unavailable committed-attribute evidence).
|
|
@@ -28,24 +36,26 @@ Exit codes: 0 measured (including failed terms), 1 input/Git error,
|
|
|
28
36
|
|
|
29
37
|
function optionsFrom(argv) {
|
|
30
38
|
const options = {};
|
|
39
|
+
const missing = (flag) => new Error(flag === '--repo'
|
|
40
|
+
? 'missing path; pass --repo <Git-checkout-path>' : `missing ref; pass ${flag} <commit-or-branch>`);
|
|
31
41
|
for (let i = 0; i < argv.length; i += 2) {
|
|
32
42
|
const flag = argv[i];
|
|
33
|
-
if (!['--base', '--head', '--source'].includes(flag)) throw new Error(`unexpected argument ${flag}; use --help`);
|
|
43
|
+
if (!['--base', '--head', '--source', '--repo'].includes(flag)) throw new Error(`unexpected argument ${flag}; use --help`);
|
|
34
44
|
const value = argv[i + 1];
|
|
35
|
-
if (!value || value.startsWith('-')) throw
|
|
45
|
+
if (!value || value.startsWith('-')) throw missing(flag);
|
|
36
46
|
if (flag in options) throw new Error(`duplicate ${flag}; pass it once`);
|
|
37
47
|
options[flag] = value;
|
|
38
48
|
}
|
|
39
|
-
for (const flag of ['--base', '--head']) {
|
|
40
|
-
if (!options[flag]) throw
|
|
49
|
+
for (const flag of ['--base', '--head', '--repo']) {
|
|
50
|
+
if (!options[flag]) throw missing(flag);
|
|
41
51
|
}
|
|
42
52
|
return options;
|
|
43
53
|
}
|
|
44
54
|
|
|
45
|
-
const command = (...args) => gitArgv('-c', 'core.attributesFile=/dev/null', ...args);
|
|
55
|
+
const command = (repo, ...args) => gitArgv('-c', 'core.attributesFile=/dev/null', '-C', repo, ...args);
|
|
46
56
|
function run(argv, input) {
|
|
47
57
|
const result = Bun.spawnSync(argv, { stdin: input === undefined ? 'ignore' : new TextEncoder().encode(input),
|
|
48
|
-
stdout: 'pipe', stderr: 'pipe', env: { ...
|
|
58
|
+
stdout: 'pipe', stderr: 'pipe', env: { ...gitEnv(), GIT_ATTR_NOSYSTEM: '1' } });
|
|
49
59
|
return { code: result.exitCode, stdout: result.stdout.toString(), stderr: result.stderr.toString() };
|
|
50
60
|
}
|
|
51
61
|
|
|
@@ -85,8 +95,9 @@ function numstat(text) {
|
|
|
85
95
|
const added = tokens[i].slice(0, firstTab), deleted = tokens[i].slice(firstTab + 1, secondTab);
|
|
86
96
|
let path = tokens[i].slice(secondTab + 1);
|
|
87
97
|
const renamed = path === '';
|
|
88
|
-
|
|
89
|
-
|
|
98
|
+
let sourcePath;
|
|
99
|
+
if (renamed) { sourcePath = tokens[++i]; path = tokens[++i]; } // -z rename: empty path, old path, new path.
|
|
100
|
+
rows.push({ path, sourcePath, renamed, binary: added === '-', additions: added === '-' ? 0 : Number(added),
|
|
90
101
|
deletions: deleted === '-' ? 0 : Number(deleted) });
|
|
91
102
|
}
|
|
92
103
|
return rows;
|
|
@@ -108,7 +119,7 @@ function summarize(rows, evidence) {
|
|
|
108
119
|
|
|
109
120
|
const proofFields = { files: 'Files', additions: 'Lines added', deletions: 'Lines removed',
|
|
110
121
|
commits: 'Commits', head: 'Head SHA', base: 'Base SHA' };
|
|
111
|
-
const proofHelp = `Usage: bun scripts/pr-shape.js --proof --base <ref> --head <ref> [--body <path>]
|
|
122
|
+
const proofHelp = `Usage: bun scripts/pr-shape.js --proof --repo <path> --base <ref> --head <ref> [--body <path>]
|
|
112
123
|
bun scripts/pr-shape.js --proof --pr <number> --repo <owner/repo> [--body <path>]
|
|
113
124
|
|
|
114
125
|
--proof Render/check PR Proof facts (separate from the unchanged shape mode)
|
|
@@ -116,7 +127,7 @@ const proofHelp = `Usage: bun scripts/pr-shape.js --proof --base <ref> --head <r
|
|
|
116
127
|
--head Current candidate ref, resolved with read-only Git
|
|
117
128
|
--body Optional UTF-8 PR body file to check; never modified
|
|
118
129
|
--pr Positive PR number; read-only gh api fetches current facts and body
|
|
119
|
-
--repo
|
|
130
|
+
--repo Required Git checkout path, or owner/repo with --pr; --pr excludes --base/--head
|
|
120
131
|
--help Show this mode's flags, output and exit codes
|
|
121
132
|
|
|
122
133
|
JSON: block (Markdown or null if facts unavailable), terms (each status, value,
|
|
@@ -149,8 +160,8 @@ function proofOptions(argv) {
|
|
|
149
160
|
if (options['--pr']) {
|
|
150
161
|
if (!/^[1-9]\d*$/.test(options['--pr']) || !/^[\w.-]+\/[\w.-]+$/.test(options['--repo'] ?? '') ||
|
|
151
162
|
options['--base'] || options['--head']) throw Error('--pr requires --repo owner/repo and excludes --base/--head');
|
|
152
|
-
} else if (!options['--base'] || !options['--head'] || options['--repo']) {
|
|
153
|
-
throw Error('proof requires --base and --head, or --pr
|
|
163
|
+
} else if (!options['--base'] || !options['--head'] || !options['--repo']) {
|
|
164
|
+
throw Error('proof requires --repo with --base and --head, or --pr');
|
|
154
165
|
}
|
|
155
166
|
return options;
|
|
156
167
|
}
|
|
@@ -159,7 +170,7 @@ function proof(argv, io) {
|
|
|
159
170
|
if (argv.includes('--help')) { io.stdout(proofHelp); return 0; }
|
|
160
171
|
const options = proofOptions(argv);
|
|
161
172
|
const terms = Object.keys(proofFields).map((id) => ({ id, status: 'unknown', value: null,
|
|
162
|
-
evidence: { cwd: process.cwd(), commands: [], results: [], reason: 'data unavailable' } }));
|
|
173
|
+
evidence: { cwd: options['--pr'] ? process.cwd() : options['--repo'], commands: [], results: [], reason: 'data unavailable' } }));
|
|
163
174
|
const term = (id) => terms.find((t) => t.id === id);
|
|
164
175
|
const query = (ids, args) => {
|
|
165
176
|
for (const id of ids) term(id).evidence.commands.push(args);
|
|
@@ -209,19 +220,20 @@ function proof(argv, io) {
|
|
|
209
220
|
else bodyError = 'PR body unavailable in gh response';
|
|
210
221
|
} catch { bodyError = 'invalid gh JSON response'; }
|
|
211
222
|
} else {
|
|
223
|
+
const gitCommand = (...args) => command(options['--repo'], ...args);
|
|
212
224
|
for (const id of ['base', 'head']) {
|
|
213
|
-
const raw = query([id],
|
|
225
|
+
const raw = query([id], gitCommand('rev-parse', '--verify', '--end-of-options', `${options[`--${id}`]}^{commit}`));
|
|
214
226
|
if (raw !== null) assign(id, raw.trim());
|
|
215
227
|
}
|
|
216
228
|
const counts = ['files', 'additions', 'deletions', 'commits'];
|
|
217
229
|
if (term('base').value && term('head').value) {
|
|
218
230
|
const base = term('base').value, head = term('head').value;
|
|
219
|
-
const commits = query(['commits'],
|
|
231
|
+
const commits = query(['commits'], gitCommand('rev-list', '--count', `${base}..${head}`, '--'));
|
|
220
232
|
if (commits !== null && /^\d+\s*$/.test(commits)) assign('commits', Number(commits));
|
|
221
233
|
const ids = counts.slice(0, 3);
|
|
222
|
-
const merge = query(ids,
|
|
234
|
+
const merge = query(ids, gitCommand('merge-base', base, head));
|
|
223
235
|
if (merge !== null) {
|
|
224
|
-
const diff = query(ids,
|
|
236
|
+
const diff = query(ids, gitCommand('diff', '-M', '--no-relative', '--no-ext-diff', '--no-textconv', '--numstat', '-z', `${merge.trim()}..${head}`, '--'));
|
|
225
237
|
if (diff !== null) {
|
|
226
238
|
const rows = numstat(diff);
|
|
227
239
|
assign('files', rows.length);
|
|
@@ -265,16 +277,19 @@ function proof(argv, io) {
|
|
|
265
277
|
}
|
|
266
278
|
|
|
267
279
|
export function main(argv, io = { stdout: (text) => process.stdout.write(text), stderr: (text) => process.stderr.write(text) }) {
|
|
280
|
+
let sandboxPath;
|
|
268
281
|
try {
|
|
269
282
|
if (argv[0] === '--proof') return proof(argv.slice(1), io);
|
|
270
283
|
if (argv.includes('--help')) { io.stdout(`${help}\n${proofHelp}`); return 0; }
|
|
271
284
|
const options = optionsFrom(argv);
|
|
272
|
-
|
|
273
|
-
|
|
285
|
+
sandboxPath = { status: 'unknown', evidence: { prefix: sandboxPrefix, commands: [] } };
|
|
286
|
+
const query = (argv) => { sandboxPath.evidence.commands.push(argv); return run(argv); };
|
|
287
|
+
const root = query(command(options['--repo'], 'rev-parse', '--show-toplevel'));
|
|
288
|
+
if (root.code) throw new Error('invalid --repo; pass --repo <Git-checkout-path>');
|
|
274
289
|
const repo = root.stdout.replace(/\n$/, '');
|
|
275
|
-
const gitCommand = (...args) => command(
|
|
290
|
+
const gitCommand = (...args) => command(repo, ...args);
|
|
276
291
|
const resolve = (flag) => {
|
|
277
|
-
const result =
|
|
292
|
+
const result = query(gitCommand('rev-parse', '--verify', '--end-of-options', `${options[flag]}^{commit}`));
|
|
278
293
|
if (result.code) throw new Error(`unresolved ${flag}; pass ${flag} <existing-commit-or-branch>`);
|
|
279
294
|
return result.stdout.trim();
|
|
280
295
|
};
|
|
@@ -282,18 +297,24 @@ export function main(argv, io = { stdout: (text) => process.stdout.write(text),
|
|
|
282
297
|
if (options['--source']) inputs.sourceRef = options['--source'];
|
|
283
298
|
const sync = syncTerm(inputs, gitCommand);
|
|
284
299
|
const mergeCommand = gitCommand('merge-base', inputs.base, inputs.head);
|
|
285
|
-
const merge =
|
|
300
|
+
const merge = query(mergeCommand);
|
|
286
301
|
if (merge.code) {
|
|
287
302
|
const unknown = { status: 'unknown', evidence: { commands: [mergeCommand], reason: merge.stderr.trim() || 'no common ancestor' } };
|
|
288
303
|
io.stdout(`${JSON.stringify({ inputs, sync, mergeBase: { ...unknown, value: null }, totals: unknown,
|
|
289
|
-
buckets: { lockfiles: unknown, generated: unknown }
|
|
304
|
+
buckets: { lockfiles: unknown, generated: unknown },
|
|
305
|
+
'sandbox-path': { ...unknown, evidence: { ...unknown.evidence, prefix: sandboxPrefix } } })}\n`);
|
|
290
306
|
return 2;
|
|
291
307
|
}
|
|
292
308
|
const mergeBase = merge.stdout.trim();
|
|
293
|
-
const diffCommand = gitCommand('diff', '-M', '--no-relative', '--no-ext-diff', '--no-textconv', '--numstat', '-z', `${mergeBase}..${inputs.head}`, '--');
|
|
294
|
-
const diff =
|
|
309
|
+
const diffCommand = gitCommand('diff', '-M', '--no-relative', '--no-ext-diff', '--no-textconv', '--ignore-submodules=none', '--numstat', '-z', `${mergeBase}..${inputs.head}`, '--');
|
|
310
|
+
const diff = query(diffCommand);
|
|
295
311
|
if (diff.code) throw new Error(`diff unavailable; verify --base and --head refer to readable commits: ${diff.stderr.trim()}`);
|
|
296
312
|
const rows = numstat(diff.stdout);
|
|
313
|
+
const sandboxFiles = rows.filter((row) => [row.sourcePath, row.path]
|
|
314
|
+
.some((path) => path === sandboxDirectory || path?.startsWith(sandboxPrefix))).length;
|
|
315
|
+
sandboxPath = { status: sandboxFiles ? 'fail' : 'pass', evidence: { commands: [diffCommand],
|
|
316
|
+
prefix: sandboxPrefix, files: sandboxFiles,
|
|
317
|
+
reason: sandboxFiles ? 'sandbox paths touched; user merge required on the forge' : 'no sandbox paths touched' } };
|
|
297
318
|
const attrCommand = gitCommand('check-attr', `--source=${inputs.head}`, '--stdin', '-z', 'linguist-generated');
|
|
298
319
|
const attrEvidence = { commands: [diffCommand, attrCommand], environment: { GIT_ATTR_NOSYSTEM: '1' },
|
|
299
320
|
stdin: 'feed check-attr the NUL-separated destination paths from the full numstat records',
|
|
@@ -312,7 +333,8 @@ export function main(argv, io = { stdout: (text) => process.stdout.write(text),
|
|
|
312
333
|
}
|
|
313
334
|
generated = summarize(rows.filter((row) => paths.has(row.path)), attrEvidence);
|
|
314
335
|
}
|
|
315
|
-
io.stdout(`${JSON.stringify({ inputs, sync,
|
|
336
|
+
io.stdout(`${JSON.stringify({ inputs, sync, 'sandbox-path': sandboxPath,
|
|
337
|
+
mergeBase: { status: 'pass', value: mergeBase, evidence: { commands: [mergeCommand] } },
|
|
316
338
|
totals: summarize(rows, { commands: [diffCommand], select: 'all records; no exclusions' }),
|
|
317
339
|
buckets: { lockfiles: summarize(rows.filter((row) => lockfiles.includes(row.path.split('/').at(-1))),
|
|
318
340
|
{ commands: [diffCommand], select: 'destination basename is exactly one of lockfileNames', lockfileNames: lockfiles }), generated },
|
|
@@ -320,6 +342,9 @@ export function main(argv, io = { stdout: (text) => process.stdout.write(text),
|
|
|
320
342
|
})}\n`);
|
|
321
343
|
return generated.status === 'unknown' || sync.status === 'unknown' ? 2 : 0;
|
|
322
344
|
} catch (error) {
|
|
345
|
+
if (sandboxPath) io.stdout(`${JSON.stringify({ 'sandbox-path': {
|
|
346
|
+
status: 'unknown', evidence: { ...sandboxPath.evidence, reason: error.message },
|
|
347
|
+
} })}\n`);
|
|
323
348
|
io.stderr(`pr-shape error: ${error.message}\n`);
|
|
324
349
|
return 1;
|
|
325
350
|
}
|