pincer-workflow 0.2.3 → 0.4.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 +19 -14
- package/bin/pincer.js +47 -11
- package/package.json +2 -2
- package/template/.agents/skills/pincer-code/SKILL.md +62 -17
- package/template/.agents/skills/pincer-evaluate/SKILL.md +85 -15
- package/template/.agents/skills/pincer-narrow/SKILL.md +67 -22
- package/template/.agents/skills/pincer-plan/SKILL.md +62 -25
- package/template/.agents/skills/pincer-release/SKILL.md +31 -12
- package/template/.agents/skills/pincer-status/SKILL.md +5 -3
- package/template/.claude/commands/pincer-code.md +61 -16
- package/template/.claude/commands/pincer-evaluate.md +85 -15
- package/template/.claude/commands/pincer-narrow.md +65 -20
- package/template/.claude/commands/pincer-plan.md +57 -20
- package/template/.claude/commands/pincer-release.md +30 -11
- package/template/.claude/commands/pincer-status.md +5 -3
- package/template/.claude/hooks/block-dangerous.sh +7 -18
- package/template/.claude/hooks/hook-policy.cjs +351 -0
- package/template/.claude/hooks/ticket-guard.sh +6 -63
- package/template/.claude/references/prd-template.md +41 -9
- package/template/.claude/references/ticket-template.md +37 -4
- package/template/.codex/README.md +4 -4
- package/template/.github/prompts/pincer-code.prompt.md +61 -16
- package/template/.github/prompts/pincer-evaluate.prompt.md +85 -15
- package/template/.github/prompts/pincer-narrow.prompt.md +65 -20
- package/template/.github/prompts/pincer-plan.prompt.md +57 -20
- package/template/.github/prompts/pincer-release.prompt.md +30 -11
- package/template/.github/prompts/pincer-status.prompt.md +5 -3
- package/template/AGENTS.md +11 -5
- package/template/docs/dry-run-checklist.md +143 -27
- package/template/docs/release-checklist.md +35 -0
- package/template/scripts/pincer-evidence.cjs +292 -0
- package/template/scripts/pincer-status.sh +83 -26
- package/template/scripts/pincer-ticket-lib.sh +321 -0
- package/template/scripts/pincer-ticket.sh +58 -47
- package/template/scripts/sync-prompts.sh +6 -1
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
// PINCER evidence — read-only validator for candidate evidence manifests
|
|
4
|
+
// (evidence schema 1). Dependency-free; runs under `node` on any platform.
|
|
5
|
+
//
|
|
6
|
+
// node scripts/pincer-evidence.cjs validate .prd/evidence/prd-vN/<candidate>/manifest.json \
|
|
7
|
+
// [--candidate <sha>] [--base <sha>] [--prd .prd/prd-vN.md] [--files]
|
|
8
|
+
// node scripts/pincer-evidence.cjs digest <file>...
|
|
9
|
+
//
|
|
10
|
+
// `validate` exits 0 and prints `ok <candidate>` when the manifest is
|
|
11
|
+
// consistent; with --files it also lists the manifest and every artifact path
|
|
12
|
+
// (repository-relative, one per line). Otherwise it prints one
|
|
13
|
+
// `evidence: <manifest>: <reason>` line per problem to stderr and exits 1.
|
|
14
|
+
// Usage errors exit 2. Nothing is ever written.
|
|
15
|
+
//
|
|
16
|
+
// What validation establishes: that the locally authored record is internally
|
|
17
|
+
// consistent — schema, references, candidate association, required results,
|
|
18
|
+
// artifact existence and digests, repository containment. It is NOT independent
|
|
19
|
+
// attestation that the recorded commands ran or that images depict the stated
|
|
20
|
+
// application; that judgment stays with the reviewer.
|
|
21
|
+
const fs = require('node:fs');
|
|
22
|
+
const path = require('node:path');
|
|
23
|
+
const crypto = require('node:crypto');
|
|
24
|
+
const { execFileSync } = require('node:child_process');
|
|
25
|
+
|
|
26
|
+
const SCHEMA = 1;
|
|
27
|
+
const HEX40 = /^[0-9a-f]{40}$/;
|
|
28
|
+
const SHA256 = /^[0-9a-f]{64}$/;
|
|
29
|
+
const ISO_UTC = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/;
|
|
30
|
+
const PRD_REF = /^\.prd\/prd-v([1-9][0-9]{0,8})\.md$/;
|
|
31
|
+
const MANIFEST_AT = /^\.prd\/evidence\/prd-v([1-9][0-9]{0,8})\/([0-9a-f]{40})\/manifest\.json$/;
|
|
32
|
+
// Requirement IDs are the PRD's own: R-01 from the template, or a supplied PRD's
|
|
33
|
+
// REQ-1 / AC-12 style, kept verbatim rather than renamed.
|
|
34
|
+
const REQ_ID = /^[A-Z][A-Z0-9]{0,7}-[0-9]{1,6}$/;
|
|
35
|
+
const TICKET_ID = /^T-[0-9]{2,6}$/;
|
|
36
|
+
const CHECK_ID = /^C-[0-9]{2,6}$/;
|
|
37
|
+
const IMAGE = /\.(png|jpe?g|webp)$/i;
|
|
38
|
+
const MAX_TEXT = 2000; // guard against pasted environment dumps
|
|
39
|
+
const TOP_KEYS = ['schema', 'prd', 'base', 'candidate', 'created', 'environment', 'coverage_review', 'requirements', 'checks', 'visual_review', 'artifacts'];
|
|
40
|
+
const ENV_KEYS = ['os', 'node', 'tools', 'limitations'];
|
|
41
|
+
const REQ_KEYS = ['id', 'disposition', 'tickets', 'checks', 'note', 'authorized_by'];
|
|
42
|
+
const CHECK_KEYS = ['id', 'kind', 'required', 'result', 'command', 'timestamp', 'artifacts', 'scenario', 'viewport', 'observed', 'note'];
|
|
43
|
+
const DISPOSITIONS = ['delivered', 'blocked', 'deferred'];
|
|
44
|
+
const KINDS = ['command', 'visual', 'review'];
|
|
45
|
+
const RESULTS = ['passed', 'failed', 'unverified'];
|
|
46
|
+
|
|
47
|
+
const isObject = v => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
48
|
+
const shortText = v => typeof v === 'string' && v.length <= MAX_TEXT;
|
|
49
|
+
const nonempty = v => shortText(v) && v.trim() !== '';
|
|
50
|
+
const toPosix = p => p.split(path.sep).join('/');
|
|
51
|
+
|
|
52
|
+
function repoRoot() {
|
|
53
|
+
if (process.env.CLAUDE_PROJECT_DIR) return path.resolve(process.env.CLAUDE_PROJECT_DIR);
|
|
54
|
+
try {
|
|
55
|
+
return execFileSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
|
|
56
|
+
} catch {
|
|
57
|
+
return process.cwd();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Resolve through symlinks above the repository (macOS /var -> /private/var)
|
|
62
|
+
// without requiring the leaf to exist yet.
|
|
63
|
+
function realpathDeep(p) {
|
|
64
|
+
try { return fs.realpathSync(p); } catch {
|
|
65
|
+
const parent = path.dirname(p);
|
|
66
|
+
return parent === p ? p : path.join(realpathDeep(parent), path.basename(p));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function digestFile(file) {
|
|
71
|
+
return crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Why a repository-relative path is unsafe, or null when it is acceptable.
|
|
75
|
+
function unsafePath(p) {
|
|
76
|
+
if (p.startsWith('/')) return 'absolute paths are not allowed';
|
|
77
|
+
if (/^[A-Za-z]:/.test(p)) return 'drive-letter paths are not allowed';
|
|
78
|
+
if (p.includes('\\')) return 'backslashes are not allowed; use repository-relative POSIX paths';
|
|
79
|
+
if (p.split('/').some(s => s === '' || s === '.' || s === '..')) return 'path must be normalized and repository-relative (no "..", "." or empty segments)';
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function validate(manifestArg, opts) {
|
|
84
|
+
const root = realpathDeep(repoRoot());
|
|
85
|
+
const abs = realpathDeep(path.resolve(manifestArg));
|
|
86
|
+
const rel = toPosix(path.relative(root, abs));
|
|
87
|
+
const at = rel.match(MANIFEST_AT);
|
|
88
|
+
if (!at) return [`manifest must live at .prd/evidence/prd-vN/<candidate>/manifest.json inside the repository (got ${rel})`];
|
|
89
|
+
const [, dirVersion, dirCandidate] = at;
|
|
90
|
+
const dirRel = path.posix.dirname(rel);
|
|
91
|
+
|
|
92
|
+
let raw;
|
|
93
|
+
try { raw = fs.readFileSync(abs, 'utf8'); } catch { return ['missing — run /pincer-evaluate to write evidence for this candidate']; }
|
|
94
|
+
let doc;
|
|
95
|
+
try { doc = JSON.parse(raw); } catch (error) { return [`malformed JSON (${error.message})`]; }
|
|
96
|
+
if (!isObject(doc)) return ['malformed: the manifest must be a JSON object'];
|
|
97
|
+
if (doc.schema !== SCHEMA) return [`unknown evidence schema ${JSON.stringify(doc.schema)} — this runtime validates schema ${SCHEMA}`];
|
|
98
|
+
|
|
99
|
+
const problems = [];
|
|
100
|
+
const problem = message => problems.push(message);
|
|
101
|
+
for (const key of Object.keys(doc)) if (!TOP_KEYS.includes(key)) problem(`unknown top-level key "${key}"`);
|
|
102
|
+
for (const key of TOP_KEYS) if (!(key in doc)) problem(`missing "${key}"`);
|
|
103
|
+
|
|
104
|
+
const prd = typeof doc.prd === 'string' ? doc.prd.match(PRD_REF) : null;
|
|
105
|
+
if (!prd) problem('prd must be a reference of the form .prd/prd-vN.md');
|
|
106
|
+
else if (prd[1] !== dirVersion) problem(`wrong PRD: manifest names ${doc.prd} but lives under prd-v${dirVersion}`);
|
|
107
|
+
if (opts.prd && doc.prd !== opts.prd) problem(`wrong PRD: manifest is for ${doc.prd}, expected ${opts.prd}`);
|
|
108
|
+
|
|
109
|
+
for (const key of ['base', 'candidate']) {
|
|
110
|
+
if (typeof doc[key] !== 'string' || !HEX40.test(doc[key])) problem(`${key} must be a full 40-hex commit ID`);
|
|
111
|
+
}
|
|
112
|
+
if (typeof doc.candidate === 'string' && HEX40.test(doc.candidate) && doc.candidate !== dirCandidate) {
|
|
113
|
+
problem(`wrong candidate: manifest names ${doc.candidate} but lives under ${dirCandidate}`);
|
|
114
|
+
}
|
|
115
|
+
if (opts.candidate && doc.candidate !== opts.candidate) problem(`wrong candidate: manifest is for ${doc.candidate}, expected ${opts.candidate}`);
|
|
116
|
+
if (opts.base && doc.base !== opts.base) problem(`wrong base: manifest records ${doc.base}, expected ${opts.base}`);
|
|
117
|
+
if (typeof doc.created !== 'string' || !ISO_UTC.test(doc.created)) problem('created must be an ISO-8601 UTC timestamp (YYYY-MM-DDTHH:MM:SSZ)');
|
|
118
|
+
|
|
119
|
+
const env = doc.environment;
|
|
120
|
+
if (!isObject(env)) problem('environment must be an object with os, node, tools and limitations');
|
|
121
|
+
else {
|
|
122
|
+
for (const key of ['os', 'node']) if (!nonempty(env[key])) problem(`environment.${key} must be a short nonempty string (redacted summary, not a dump)`);
|
|
123
|
+
for (const key of ['tools', 'limitations']) {
|
|
124
|
+
if (!Array.isArray(env[key]) || !env[key].every(nonempty)) problem(`environment.${key} must be an array of short strings`);
|
|
125
|
+
}
|
|
126
|
+
for (const key of Object.keys(env)) if (!ENV_KEYS.includes(key)) problem(`environment.${key} is not allowed — persist redacted summaries only`);
|
|
127
|
+
}
|
|
128
|
+
if (!nonempty(doc.coverage_review)) problem('coverage_review must be a nonempty string recording the reviewer judgment on requirement coverage');
|
|
129
|
+
|
|
130
|
+
// Artifacts: repository-contained regular files with matching digests.
|
|
131
|
+
const artifacts = new Map();
|
|
132
|
+
if (!Array.isArray(doc.artifacts)) problem('artifacts must be an array of {path, sha256}');
|
|
133
|
+
else doc.artifacts.forEach((entry, index) => {
|
|
134
|
+
const label = `artifacts[${index}]`;
|
|
135
|
+
if (!isObject(entry)) { problem(`${label} must be an object {path, sha256}`); return; }
|
|
136
|
+
for (const key of Object.keys(entry)) if (!['path', 'sha256'].includes(key)) problem(`${label}.${key} is not allowed`);
|
|
137
|
+
const p = entry.path;
|
|
138
|
+
if (typeof p !== 'string' || p === '') { problem(`${label}.path must be a nonempty string`); return; }
|
|
139
|
+
if (artifacts.has(p)) problem(`duplicate artifact path ${p}`);
|
|
140
|
+
artifacts.set(p, false);
|
|
141
|
+
const why = unsafePath(p);
|
|
142
|
+
if (why) { problem(`artifact ${p}: ${why}`); return; }
|
|
143
|
+
if (!p.startsWith(`${dirRel}/`)) { problem(`artifact ${p}: outside the evidence directory ${dirRel}/`); return; }
|
|
144
|
+
const digestOk = typeof entry.sha256 === 'string' && SHA256.test(entry.sha256);
|
|
145
|
+
if (!digestOk) problem(`artifact ${p}: sha256 must be a full 64-hex digest`);
|
|
146
|
+
const segments = p.split('/');
|
|
147
|
+
let current = root;
|
|
148
|
+
for (let i = 0; i < segments.length; i++) {
|
|
149
|
+
current = path.join(current, segments[i]);
|
|
150
|
+
let stat;
|
|
151
|
+
try { stat = fs.lstatSync(current); } catch { problem(`artifact ${p}: missing`); return; }
|
|
152
|
+
const last = i === segments.length - 1;
|
|
153
|
+
if (stat.isSymbolicLink()) {
|
|
154
|
+
problem(last ? `artifact ${p}: is a symlink (only regular files inside the repository are accepted)` : `artifact ${p}: path component ${segments.slice(0, i + 1).join('/')} is a symlink`);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (!last && !stat.isDirectory()) { problem(`artifact ${p}: ${segments.slice(0, i + 1).join('/')} is not a directory`); return; }
|
|
158
|
+
if (last && !stat.isFile()) { problem(`artifact ${p}: not a regular file`); return; }
|
|
159
|
+
}
|
|
160
|
+
if (digestOk && digestFile(current) !== entry.sha256) problem(`artifact ${p}: digest mismatch — the file changed after the evidence was recorded`);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// Checks: what was run or judged, with results and artifact references.
|
|
164
|
+
const checks = new Map();
|
|
165
|
+
let visualChecks = 0;
|
|
166
|
+
if (!Array.isArray(doc.checks)) problem('checks must be an array');
|
|
167
|
+
else doc.checks.forEach((check, index) => {
|
|
168
|
+
const label = `checks[${index}]`;
|
|
169
|
+
if (!isObject(check)) { problem(`${label} must be an object`); return; }
|
|
170
|
+
const id = typeof check.id === 'string' && CHECK_ID.test(check.id) ? check.id : null;
|
|
171
|
+
if (!id) problem(`${label}.id must be a check ID such as C-01`);
|
|
172
|
+
else if (checks.has(id)) problem(`duplicate check ID ${id}`);
|
|
173
|
+
else checks.set(id, check);
|
|
174
|
+
const name = id || label;
|
|
175
|
+
for (const key of Object.keys(check)) if (!CHECK_KEYS.includes(key)) problem(`check ${name}: unknown key "${key}"`);
|
|
176
|
+
if (!KINDS.includes(check.kind)) problem(`check ${name}: kind must be one of ${KINDS.join(', ')}`);
|
|
177
|
+
if (typeof check.required !== 'boolean') problem(`check ${name}: required must be true or false`);
|
|
178
|
+
if (!RESULTS.includes(check.result)) problem(`check ${name}: result must be one of ${RESULTS.join(', ')}`);
|
|
179
|
+
if (typeof check.timestamp !== 'string' || !ISO_UTC.test(check.timestamp)) problem(`check ${name}: timestamp must be an ISO-8601 UTC timestamp`);
|
|
180
|
+
if (check.kind === 'command' && !nonempty(check.command)) problem(`check ${name}: command kind requires the command that was run`);
|
|
181
|
+
for (const key of ['command', 'scenario', 'viewport', 'observed', 'note']) {
|
|
182
|
+
if (key in check && !shortText(check[key])) problem(`check ${name}: ${key} must be a short string`);
|
|
183
|
+
}
|
|
184
|
+
let images = 0;
|
|
185
|
+
if (!Array.isArray(check.artifacts)) problem(`check ${name}: artifacts must be an array of repository-relative paths`);
|
|
186
|
+
else for (const p of check.artifacts) {
|
|
187
|
+
if (typeof p !== 'string') { problem(`check ${name}: artifact reference must be a string`); continue; }
|
|
188
|
+
if (!artifacts.has(p)) problem(`check ${name}: references unlisted artifact ${p} (dangling reference)`);
|
|
189
|
+
else artifacts.set(p, true);
|
|
190
|
+
if (IMAGE.test(p)) images++;
|
|
191
|
+
}
|
|
192
|
+
if (check.kind === 'visual') {
|
|
193
|
+
visualChecks++;
|
|
194
|
+
for (const key of ['scenario', 'viewport', 'observed']) if (!nonempty(check[key])) problem(`check ${name}: visual check requires ${key}`);
|
|
195
|
+
// A passed visual check must show its image; an unverified one (tool
|
|
196
|
+
// unavailable) is recorded honestly without one and, when required, blocks.
|
|
197
|
+
if (check.result === 'passed' && images === 0) problem(`check ${name}: a passed visual check requires a saved image artifact (.png, .jpg or .webp)`);
|
|
198
|
+
}
|
|
199
|
+
if (check.required === true && check.result !== 'passed') {
|
|
200
|
+
problem(`required check ${name} is ${check.result} — readiness is blocked until it passes on a new candidate or the requirement is deferred with authorization`);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
for (const [p, referenced] of artifacts) if (!referenced) problem(`artifact ${p}: not referenced by any check`);
|
|
204
|
+
|
|
205
|
+
// Requirements: every ID dispositioned; deferrals authorized; checks resolve.
|
|
206
|
+
const requirements = new Set();
|
|
207
|
+
if (!Array.isArray(doc.requirements) || doc.requirements.length === 0) problem('requirements must be a nonempty array — every PRD requirement needs a disposition');
|
|
208
|
+
else doc.requirements.forEach((req, index) => {
|
|
209
|
+
const label = `requirements[${index}]`;
|
|
210
|
+
if (!isObject(req)) { problem(`${label} must be an object`); return; }
|
|
211
|
+
const id = typeof req.id === 'string' && REQ_ID.test(req.id) ? req.id : null;
|
|
212
|
+
if (!id) problem(`${label}.id must be a requirement ID such as R-01 or the PRD's own REQ-1 (uppercase prefix, dash, digits)`);
|
|
213
|
+
else if (requirements.has(id)) problem(`duplicate requirement ID ${id}`);
|
|
214
|
+
else requirements.add(id);
|
|
215
|
+
const name = id || label;
|
|
216
|
+
for (const key of Object.keys(req)) if (!REQ_KEYS.includes(key)) problem(`requirement ${name}: unknown key "${key}"`);
|
|
217
|
+
if (!DISPOSITIONS.includes(req.disposition)) problem(`requirement ${name}: disposition must be one of ${DISPOSITIONS.join(', ')}`);
|
|
218
|
+
if (!Array.isArray(req.tickets) || !req.tickets.every(t => typeof t === 'string' && TICKET_ID.test(t))) problem(`requirement ${name}: tickets must be an array of ticket IDs such as T-01`);
|
|
219
|
+
if (!Array.isArray(req.checks)) problem(`requirement ${name}: checks must be an array of check IDs`);
|
|
220
|
+
else for (const c of req.checks) {
|
|
221
|
+
if (typeof c !== 'string' || !checks.has(c)) problem(`requirement ${name}: references unknown check ${JSON.stringify(c)} (dangling reference)`);
|
|
222
|
+
}
|
|
223
|
+
for (const key of ['note', 'authorized_by']) if (key in req && !shortText(req[key])) problem(`requirement ${name}: ${key} must be a short string`);
|
|
224
|
+
if (req.disposition === 'deferred' && !nonempty(req.authorized_by)) problem(`requirement ${name}: deferred requires authorized_by naming the explicit user authorization`);
|
|
225
|
+
if (req.disposition === 'delivered' && Array.isArray(req.checks) && req.checks.length === 0) problem(`requirement ${name}: delivered requires at least one check`);
|
|
226
|
+
if (req.disposition === 'blocked') problem(`requirement ${name} is blocked — readiness is blocked until it is delivered on a new candidate or deferred with authorization`);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
const visual = doc.visual_review;
|
|
230
|
+
if (!isObject(visual) || typeof visual.applicable !== 'boolean') problem('visual_review must be {applicable: boolean, reason?: string}');
|
|
231
|
+
else {
|
|
232
|
+
for (const key of Object.keys(visual)) if (!['applicable', 'reason'].includes(key)) problem(`visual_review.${key} is not allowed`);
|
|
233
|
+
if (visual.applicable === false && !nonempty(visual.reason)) problem('visual_review.reason is required when visual review is not applicable (say why)');
|
|
234
|
+
if (visual.applicable === true && visualChecks === 0) problem('visual_review.applicable is true but no visual check is recorded');
|
|
235
|
+
if ('reason' in visual && !shortText(visual.reason)) problem('visual_review.reason must be a short string');
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (problems.length === 0 && opts.files) {
|
|
239
|
+
opts.list = [rel, ...doc.artifacts.map(a => a.path)];
|
|
240
|
+
}
|
|
241
|
+
return problems;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function usage(message) {
|
|
245
|
+
if (message) process.stderr.write(`pincer-evidence: ${message}\n`);
|
|
246
|
+
process.stderr.write('usage: pincer-evidence.cjs validate <manifest> [--candidate <sha>] [--base <sha>] [--prd .prd/prd-vN.md] [--files]\n pincer-evidence.cjs digest <file>...\n');
|
|
247
|
+
process.exit(2);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function main(argv) {
|
|
251
|
+
const [command, ...rest] = argv;
|
|
252
|
+
if (command === 'validate') {
|
|
253
|
+
const opts = { files: false };
|
|
254
|
+
let manifest = null;
|
|
255
|
+
for (let i = 0; i < rest.length; i++) {
|
|
256
|
+
const arg = rest[i];
|
|
257
|
+
if (arg === '--files') opts.files = true;
|
|
258
|
+
else if (arg === '--candidate' || arg === '--base' || arg === '--prd') {
|
|
259
|
+
const value = rest[++i];
|
|
260
|
+
if (value === undefined) usage(`${arg} requires a value`);
|
|
261
|
+
opts[arg.slice(2)] = value;
|
|
262
|
+
} else if (arg.startsWith('--')) usage(`unknown option ${arg}`);
|
|
263
|
+
else if (manifest === null) manifest = arg;
|
|
264
|
+
else usage('validate takes exactly one manifest path');
|
|
265
|
+
}
|
|
266
|
+
if (manifest === null) usage('validate requires a manifest path');
|
|
267
|
+
if (opts.candidate !== undefined && !HEX40.test(opts.candidate)) usage('--candidate must be a full 40-hex commit ID');
|
|
268
|
+
if (opts.base !== undefined && !HEX40.test(opts.base)) usage('--base must be a full 40-hex commit ID');
|
|
269
|
+
if (opts.prd !== undefined && !PRD_REF.test(opts.prd)) usage('--prd must be of the form .prd/prd-vN.md');
|
|
270
|
+
const problems = validate(manifest, opts);
|
|
271
|
+
if (problems.length > 0) {
|
|
272
|
+
for (const p of problems) process.stderr.write(`evidence: ${manifest}: ${p}\n`);
|
|
273
|
+
process.exit(1);
|
|
274
|
+
}
|
|
275
|
+
const doc = JSON.parse(fs.readFileSync(path.resolve(manifest), 'utf8'));
|
|
276
|
+
process.stdout.write(`ok ${doc.candidate}\n`);
|
|
277
|
+
if (opts.files) for (const p of opts.list) process.stdout.write(`${p}\n`);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (command === 'digest') {
|
|
281
|
+
if (rest.length === 0) usage('digest requires at least one file');
|
|
282
|
+
for (const file of rest) {
|
|
283
|
+
let digest;
|
|
284
|
+
try { digest = digestFile(file); } catch (error) { process.stderr.write(`pincer-evidence: ${file}: ${error.code === 'ENOENT' ? 'missing' : error.message}\n`); process.exit(1); }
|
|
285
|
+
process.stdout.write(`${digest} ${file}\n`);
|
|
286
|
+
}
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
usage(command ? `unknown command ${command}` : undefined);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
main(process.argv.slice(2));
|
|
@@ -5,24 +5,18 @@
|
|
|
5
5
|
# scripts/pincer-status.sh
|
|
6
6
|
#
|
|
7
7
|
# Elapsed times come from the `started` / `finished` stamps that
|
|
8
|
-
# scripts/pincer-ticket.sh writes, i.e. from the clock — never estimated
|
|
9
|
-
#
|
|
8
|
+
# scripts/pincer-ticket.sh writes, i.e. from the wall clock — never estimated
|
|
9
|
+
# and never a measure of active execution time. The build-wide elapsed line is
|
|
10
|
+
# printed only while a ticket is in progress or an explicit budget is set.
|
|
11
|
+
# Optional build budget: PINCER_BUILD_BUDGET_MIN.
|
|
10
12
|
set -uo pipefail
|
|
11
13
|
|
|
14
|
+
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/pincer-ticket-lib.sh"
|
|
12
15
|
ROOT=${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null || pwd)}
|
|
13
16
|
cd "$ROOT"
|
|
14
|
-
BUDGET=${PINCER_BUILD_BUDGET_MIN:-
|
|
17
|
+
BUDGET=${PINCER_BUILD_BUDGET_MIN:-}
|
|
15
18
|
NOW=$(date -u +%s)
|
|
16
19
|
|
|
17
|
-
fm_get() { # file key -> value with any inline comment stripped; empty if absent
|
|
18
|
-
awk -v k="$2" '
|
|
19
|
-
NR == 1 && $0 != "---" { exit }
|
|
20
|
-
NR > 1 && $0 == "---" { exit }
|
|
21
|
-
NR > 1 && index($0, k ":") == 1 {
|
|
22
|
-
v = substr($0, length(k) + 2); sub(/#.*/, "", v)
|
|
23
|
-
gsub(/^[ \t]+|[ \t]+$/, "", v); print v; exit
|
|
24
|
-
}' "$1"
|
|
25
|
-
}
|
|
26
20
|
to_epoch() { # ISO-8601 UTC -> seconds (GNU date, then BSD date)
|
|
27
21
|
date -u -d "$1" +%s 2>/dev/null || date -u -j -f '%Y-%m-%dT%H:%M:%SZ' "$1" +%s 2>/dev/null || echo 0
|
|
28
22
|
}
|
|
@@ -32,26 +26,57 @@ hhmm() { [ -n "$1" ] && printf '%s' "$1" | cut -c12-16 || printf '—'; }
|
|
|
32
26
|
echo "PINCER status · $(date -u +%Y-%m-%dT%H:%MZ) · $ROOT"
|
|
33
27
|
|
|
34
28
|
# ── PRD ──
|
|
35
|
-
prd=$(
|
|
29
|
+
if ! prd=$(latest_prd 2>&1); then
|
|
30
|
+
printf 'WARN invalid PRD: %s\n' "$prd"
|
|
31
|
+
echo 'Next repair PRD input before continuing'
|
|
32
|
+
exit 1
|
|
33
|
+
fi
|
|
36
34
|
prd_status=""
|
|
37
35
|
if [ -z "$prd" ]; then
|
|
38
36
|
echo "PRD none"
|
|
39
37
|
else
|
|
40
38
|
prd_status=$(fm_get "$prd" status)
|
|
41
|
-
echo "PRD $prd · status: ${prd_status:-?} · date: $(fm_get "$prd" date)"
|
|
39
|
+
echo "PRD $prd · status: ${prd_status:-?} · profile: $(prd_profile "$prd") · date: $(fm_get "$prd" date)"
|
|
40
|
+
fi
|
|
41
|
+
|
|
42
|
+
# Reject malformed/ambiguous tickets instead of treating unknown states as open.
|
|
43
|
+
if ! errors=$(validate_ticket_set 2>&1); then
|
|
44
|
+
printf 'WARN invalid tickets: %s\n' "$errors"
|
|
45
|
+
echo "Next repair ticket input before continuing"
|
|
46
|
+
exit 1
|
|
42
47
|
fi
|
|
43
48
|
|
|
44
49
|
# ── Tickets ──
|
|
45
|
-
n_open=0; n_prog=0; n_done=0; first_start=""; in_prog=""; next_open=""; warn=""
|
|
46
|
-
files
|
|
50
|
+
n_open=0; n_prog=0; n_done=0; first_start=""; in_prog=""; next_open=""; warn=""; reverify=""
|
|
51
|
+
files=""; historical=0; unresolved=0
|
|
52
|
+
for f in tickets/T-*.md; do
|
|
53
|
+
[ -e "$f" ] || continue
|
|
54
|
+
if ! associated=$(ticket_prd "$f" 2>&1); then
|
|
55
|
+
printf 'WARN unresolved ticket PRD: %s\n' "$associated"
|
|
56
|
+
unresolved=$((unresolved + 1)); continue
|
|
57
|
+
fi
|
|
58
|
+
if [ "$associated" = "$prd" ]; then
|
|
59
|
+
files="$files$f
|
|
60
|
+
"
|
|
61
|
+
else
|
|
62
|
+
historical=$((historical + 1))
|
|
63
|
+
fi
|
|
64
|
+
done
|
|
65
|
+
[ "$historical" -eq 0 ] || echo "History $historical ticket(s) associated with other PRDs"
|
|
47
66
|
if [ -z "$files" ]; then
|
|
48
67
|
echo "Tickets none"
|
|
49
68
|
else
|
|
50
69
|
rows=""
|
|
51
|
-
|
|
70
|
+
while IFS= read -r f; do
|
|
71
|
+
[ -n "$f" ] || continue
|
|
52
72
|
id=$(fm_get "$f" ticket); [ -n "$id" ] || id=$(basename "$f" | cut -c1-4)
|
|
53
73
|
st=$(fm_get "$f" status); size=$(fm_get "$f" size)
|
|
54
74
|
started=$(fm_get "$f" started); verified=$(fm_get "$f" verified); finished=$(fm_get "$f" finished)
|
|
75
|
+
attempt=$(fm_get "$f" last_check)
|
|
76
|
+
# Done tickets report through ticket_readiness below, so each problem is printed once.
|
|
77
|
+
if [ "$st" != done ] && [ -n "$attempt" ] && ! printf '%s' "$attempt" | grep -q ' passed '; then
|
|
78
|
+
warn="$warn WARN $id latest verification: $attempt — re-run verify\n"
|
|
79
|
+
fi
|
|
55
80
|
deps=$(fm_get "$f" depends_on | grep -oE 'T-[0-9]+' | tr '\n' ' ' || true)
|
|
56
81
|
if [ -n "$started" ]; then
|
|
57
82
|
se=$(to_epoch "$started")
|
|
@@ -62,7 +87,10 @@ else
|
|
|
62
87
|
n_done=$((n_done + 1))
|
|
63
88
|
detail="started $(hhmm "$started") · finished $(hhmm "$finished")"
|
|
64
89
|
[ -n "$started" ] && [ -n "$finished" ] && detail="$detail ($(mins "$(to_epoch "$started")" "$(to_epoch "$finished")"))"
|
|
65
|
-
|
|
90
|
+
if ! readiness=$(ticket_readiness "$f"); then
|
|
91
|
+
warn="$warn WARN $id $readiness\n"
|
|
92
|
+
reverify="$reverify $id"
|
|
93
|
+
fi
|
|
66
94
|
;;
|
|
67
95
|
in_progress)
|
|
68
96
|
n_prog=$((n_prog + 1)); in_prog="$in_prog $id"
|
|
@@ -74,38 +102,67 @@ else
|
|
|
74
102
|
n_open=$((n_open + 1)); st=${st:-open}
|
|
75
103
|
blocked=""
|
|
76
104
|
for d in $deps; do
|
|
77
|
-
df=$(
|
|
78
|
-
|
|
105
|
+
df=$(ticket_file "$d" 2>/dev/null || true)
|
|
106
|
+
dep_prd=""
|
|
107
|
+
[ -z "$df" ] || dep_prd=$(ticket_prd "$df" 2>/dev/null || true)
|
|
108
|
+
if [ -z "$df" ] || [ "$(fm_get "$df" status)" != done ] ||
|
|
109
|
+
[ "$dep_prd" != "$prd" ] || ! usable_ticket_prd "$df" >/dev/null 2>&1 ||
|
|
110
|
+
! ticket_readiness "$df" >/dev/null; then
|
|
111
|
+
blocked="$blocked $d"
|
|
112
|
+
fi
|
|
79
113
|
done
|
|
80
114
|
if [ -n "$blocked" ]; then detail="blocked by${blocked}"; else detail="ready"; [ -n "$next_open" ] || next_open=$id; fi
|
|
81
115
|
;;
|
|
82
116
|
esac
|
|
83
117
|
rows="$rows$(printf ' %-5s %-12s %-2s %s' "$id" "$st" "${size:-?}" "$detail")\n"
|
|
84
|
-
done
|
|
118
|
+
done <<< "$files"
|
|
85
119
|
echo "Tickets $((n_open + n_prog + n_done)) total · $n_done done · $n_prog in progress · $n_open open"
|
|
86
120
|
printf '%b' "$rows"
|
|
87
121
|
printf '%b' "$warn"
|
|
88
|
-
|
|
89
|
-
|
|
122
|
+
# Wall-clock elapsed is shown only while work is active or against an explicit
|
|
123
|
+
# budget; on a finished build it is noise and it never measures execution time.
|
|
124
|
+
if [ -n "$first_start" ] && { [ "$n_prog" -gt 0 ] || [ -n "$BUDGET" ]; }; then
|
|
125
|
+
build="Build wall-clock elapsed $(mins "$first_start" "$NOW") since the first ticket started (not active execution time)"
|
|
126
|
+
[ -z "$BUDGET" ] || build="$build · budget ${BUDGET}m"
|
|
127
|
+
echo "$build"
|
|
90
128
|
fi
|
|
91
129
|
fi
|
|
92
130
|
|
|
93
|
-
|
|
131
|
+
notes_valid=no
|
|
132
|
+
if notes=$(notes_current "$prd"); then notes_valid=yes; fi
|
|
94
133
|
echo "Notes NOTES.md: $notes"
|
|
134
|
+
# The evidence line reports the shared validator's verdict for the manifest the
|
|
135
|
+
# notes name, independent of whether the candidate is still current.
|
|
136
|
+
manifest=""
|
|
137
|
+
[ -f NOTES.md ] && validate_metadata NOTES.md >/dev/null 2>&1 && manifest=$(fm_get NOTES.md evidence)
|
|
138
|
+
if [ -n "$manifest" ]; then
|
|
139
|
+
if ev=$(evidence_validate "$manifest" "$(fm_get NOTES.md candidate)" "$(fm_get NOTES.md base)" "$prd"); then
|
|
140
|
+
echo "Evidence $manifest · ok"
|
|
141
|
+
else
|
|
142
|
+
echo "Evidence $manifest · $(evidence_reason "$ev")"
|
|
143
|
+
fi
|
|
144
|
+
fi
|
|
95
145
|
|
|
96
146
|
# ── Next action ──
|
|
97
147
|
if [ -z "$prd" ]; then
|
|
98
148
|
next="/pincer-plan <brief> — no PRD yet"
|
|
149
|
+
elif [ "$unresolved" -gt 0 ]; then
|
|
150
|
+
next="resolve PRD association with pincer-ticket.sh bind T-NN .prd/prd-vN.md before continuing"
|
|
151
|
+
elif [ "$prd_status" = draft ]; then
|
|
152
|
+
next="/pincer-narrow — current PRD is draft; earlier tickets and notes do not complete it"
|
|
99
153
|
elif [ -z "$files" ]; then
|
|
100
154
|
next="/pincer-narrow — PRD exists, no tickets yet"
|
|
101
155
|
elif [ -n "$in_prog" ]; then
|
|
102
156
|
next="resume${in_prog}: /pincer-code${in_prog} (check git status for uncommitted work; then verify → done)"
|
|
103
157
|
elif [ "$n_open" -gt 0 ]; then
|
|
104
158
|
next="/pincer-code — next ready ticket: ${next_open:-none (all remaining are blocked — check depends_on)}"
|
|
105
|
-
elif [ "$
|
|
159
|
+
elif [ -n "$reverify" ]; then
|
|
160
|
+
next="/pincer-code — re-run verify for${reverify}; resolve readiness warnings before evaluation or release"
|
|
161
|
+
elif [ "$notes_valid" = no ] || [ "$prd_status" != built ]; then
|
|
106
162
|
next="/pincer-evaluate — all tickets done"
|
|
107
163
|
[ "$prd_status" = built ] || next="$next (PRD status is '${prd_status:-?}', expected 'built')"
|
|
108
164
|
else
|
|
109
|
-
next="/pincer-release —
|
|
165
|
+
next="/pincer-release — evaluation matches the current PRD and candidate; audit the artifacts"
|
|
110
166
|
fi
|
|
111
167
|
echo "Next $next"
|
|
168
|
+
[ "$unresolved" -eq 0 ] || exit 1
|