harness-everything 1.0.1 → 1.1.1
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +22 -0
- package/benchmarks/results/live-host/agy-2026-11-25/README.md +32 -0
- package/ci/mechanism-394-ledger-match.test.js +219 -0
- package/ci/mechanism-496-claude-capture.test.js +342 -0
- package/ci/mechanism-496-codex-capture.test.js +508 -0
- package/ci/mechanism-496-local-error-cli-edges.test.js +234 -0
- package/ci/mechanism-496-local-error-cli.test.js +517 -0
- package/ci/mechanism-496-local-error-store.test.js +731 -0
- package/ci/mechanism-496-opencode-capture.test.js +483 -0
- package/ci/mechanism-496-review-fixes.test.js +278 -0
- package/ci/mechanism-516-windows-verify-and-shell.test.js +328 -0
- package/docs/platform-capabilities.md +2 -2
- package/docs/platform-compatibility.json +2 -2
- package/hooks/scripts/codex-ledger-lesson.js +103 -27
- package/hooks/scripts/ledger-lesson.js +94 -23
- package/hooks/scripts/lib/ledger-match.js +39 -3
- package/hooks/scripts/lib/local-error-source.js +127 -0
- package/hooks/scripts/lib/local-errors.js +597 -0
- package/hooks/scripts/lib/observations.js +1 -1
- package/hooks/scripts/lib/workflow-isolation.js +1 -1
- package/opencode-plugin/index.mjs +86 -1
- package/opencode-plugin/plugin.json +1 -1
- package/package.json +2 -1
- package/plugins/harness-everything/.antigravity-plugin/plugin.json +1 -1
- package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
- package/plugins/harness-everything/hooks/scripts/codex-ledger-lesson.js +103 -27
- package/plugins/harness-everything/hooks/scripts/ledger-lesson.js +94 -23
- package/plugins/harness-everything/hooks/scripts/lib/ledger-match.js +39 -3
- package/plugins/harness-everything/hooks/scripts/lib/local-error-source.js +127 -0
- package/plugins/harness-everything/hooks/scripts/lib/local-errors.js +597 -0
- package/plugins/harness-everything/hooks/scripts/lib/observations.js +1 -1
- package/plugins/harness-everything/hooks/scripts/lib/workflow-isolation.js +1 -1
- package/plugins/harness-everything/plugin.json +1 -1
- package/plugins/harness-everything/scripts/lib/verification-contract.js +68 -12
- package/sbom.cdx.json +7 -7
- package/scripts/errors-local.js +357 -0
- package/scripts/lib/verification-contract.js +68 -12
|
@@ -201,6 +201,12 @@ function detectRoot(root) {
|
|
|
201
201
|
}
|
|
202
202
|
if (fs.existsSync(path.join(root, 'tox.ini'))) addCandidate(candidates, seen, { source: 'tox', run: 'tox', cwd: root });
|
|
203
203
|
if (fs.existsSync(path.join(root, 'noxfile.py'))) addCandidate(candidates, seen, { source: 'nox', run: 'nox', cwd: root });
|
|
204
|
+
if (fs.existsSync(path.join(root, 'mkdocs.yml')) || fs.existsSync(path.join(root, 'mkdocs.yaml'))) {
|
|
205
|
+
addCandidate(candidates, seen, { source: 'mkdocs', run: 'mkdocs build --strict', cwd: root });
|
|
206
|
+
if (/\[tool\.poetry(?:\.|\])/m.test(pyproject)) {
|
|
207
|
+
addCandidate(candidates, seen, { source: 'mkdocs:poetry', run: 'poetry run mkdocs build --strict', cwd: root });
|
|
208
|
+
}
|
|
209
|
+
}
|
|
204
210
|
if (fs.existsSync(path.join(root, 'Cargo.toml'))) addCandidate(candidates, seen, { source: 'cargo', run: 'cargo test', cwd: root });
|
|
205
211
|
if (fs.existsSync(path.join(root, 'go.mod'))) addCandidate(candidates, seen, { source: 'go', run: 'go test ./...', cwd: root });
|
|
206
212
|
|
|
@@ -245,6 +251,10 @@ function normalizeCommand(command) {
|
|
|
245
251
|
return String(command || '').trim().replace(/\s+/g, ' ');
|
|
246
252
|
}
|
|
247
253
|
|
|
254
|
+
function stripWindowsCmdShim(command) {
|
|
255
|
+
return String(command || '').replace(/^(npm|pnpm|yarn|bun|npx)\.cmd(?=\s|$)/i, '$1');
|
|
256
|
+
}
|
|
257
|
+
|
|
248
258
|
function hasControlOperators(command) {
|
|
249
259
|
return /(?:&&|\|\||[;|\r\n])/.test(command);
|
|
250
260
|
}
|
|
@@ -253,7 +263,9 @@ function commandMatches(command, expected) {
|
|
|
253
263
|
const actual = normalizeCommand(command);
|
|
254
264
|
const target = normalizeCommand(expected);
|
|
255
265
|
if (!actual || !target || hasControlOperators(actual)) return false;
|
|
256
|
-
|
|
266
|
+
const normalizedActual = stripWindowsCmdShim(actual);
|
|
267
|
+
const normalizedTarget = stripWindowsCmdShim(target);
|
|
268
|
+
return normalizedActual === normalizedTarget || normalizedActual.startsWith(normalizedTarget + ' ');
|
|
257
269
|
}
|
|
258
270
|
|
|
259
271
|
function isGitCommit(command) {
|
|
@@ -274,9 +286,28 @@ function bypassesHooks(command) {
|
|
|
274
286
|
);
|
|
275
287
|
}
|
|
276
288
|
|
|
289
|
+
const NODE_TEST_RE = /^node\s+--test(?:\s|$)/i;
|
|
290
|
+
const DOC_BUILD_RE = /^(?:(?:uv|poetry)\s+run\s+mkdocs(?:\.exe)?\s+build|(?:(?:\.?[/\\])?(?:\.?venv|env)[/\\](?:Scripts|bin)[/\\])?(?:mkdocs(?:\.exe)?\s+build|sphinx-build(?:\.exe)?))(?:\s|$)/i;
|
|
291
|
+
|
|
292
|
+
function isVerifierInfoQuery(command) {
|
|
293
|
+
const nodeTest = NODE_TEST_RE.exec(command);
|
|
294
|
+
const verifier = nodeTest || DOC_BUILD_RE.exec(command);
|
|
295
|
+
if (!verifier) return false;
|
|
296
|
+
|
|
297
|
+
// Keep quoted argument values together, while recognizing quoted switches.
|
|
298
|
+
const args = command.slice(verifier[0].length).match(/(?:[^\s"'\x60\\]|\\.|\x60.|"[^"]*"|'[^']*')+/g) || [];
|
|
299
|
+
const options = args.map(arg => arg.replace(/["']/g, '').replace(/(?:\\|\x60)(?=[A-Za-z-])/g, ''));
|
|
300
|
+
if (options[0] === '-M' && options[1] === 'help' && /sphinx-build(?:\.exe)?\s*$/i.test(verifier[0])) return true;
|
|
301
|
+
const versionFlag = nodeTest ? '-v' : '-V';
|
|
302
|
+
return options.some(option =>
|
|
303
|
+
option === '--help' || option === '--version' || option === '-h' || option === versionFlag
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
|
|
277
307
|
function legacyVerificationCommand(command) {
|
|
278
|
-
const value = normalizeCommand(command);
|
|
279
|
-
|
|
308
|
+
const value = stripWindowsCmdShim(normalizeCommand(command));
|
|
309
|
+
if (NODE_TEST_RE.test(value) || DOC_BUILD_RE.test(value)) return !isVerifierInfoQuery(value);
|
|
310
|
+
return /^(?:(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?(?:test|lint|build|typecheck|check|verify)\b|npx\s+(?:jest|vitest|mocha|tsc|eslint)\b|(?:jest|vitest|mocha|pytest|rspec|phpunit)\b|(?:uv|poetry)\s+run\s+(?:pytest|ruff)\b|(?:make|just)\s+(?:test|check|lint|ci)\b|cargo\s+(?:test|check)\b|go\s+test\b|dotnet\s+(?:test|build)\b)/i.test(value);
|
|
280
311
|
}
|
|
281
312
|
|
|
282
313
|
function verificationCommandSet(cwd, options = {}) {
|
|
@@ -334,6 +365,9 @@ function verificationCommandSet(cwd, options = {}) {
|
|
|
334
365
|
// command must be one plain command: no further control operators,
|
|
335
366
|
// redirection, substitution, expansion, subshell, or background syntax.
|
|
336
367
|
const CWD_PRELUDE_RE = /^cd\s+(?:"([^"]*)"|'([^']*)'|([A-Za-z0-9_./:@%+,-]+))\s*&&\s*([\s\S]+)$/;
|
|
368
|
+
// PowerShell 7 must stop on a failed location change before running the
|
|
369
|
+
// verifier. Match only a single-quoted filesystem path with explicit flags.
|
|
370
|
+
const PS_CWD_PRELUDE_RE = /^Set-Location[ \t]+-LiteralPath[ \t]+'([^'\r\n]+)'[ \t]+-ErrorAction[ \t]+Stop[ \t]*&&[ \t]*([^\r\n]+)$/i;
|
|
337
371
|
const UNSAFE_WRAPPED_RE = /[`$<>&|;()\r\n]/;
|
|
338
372
|
const UNSAFE_DOUBLE_QUOTED_RE = /[$`!]|\\[\\"$`]|\\$/;
|
|
339
373
|
|
|
@@ -355,22 +389,44 @@ function stableCdTarget(target, platform = process.platform) {
|
|
|
355
389
|
return target.startsWith('/');
|
|
356
390
|
}
|
|
357
391
|
|
|
392
|
+
function stablePowerShellTarget(target, platform = process.platform) {
|
|
393
|
+
const start = platform === 'win32' ? /^(?:[A-Za-z]:|\.)[/\\]/ : /^(?:\.)?\//;
|
|
394
|
+
if (target === '.') return true;
|
|
395
|
+
if (!start.test(target) || (platform !== 'win32' && target.includes('\\'))) return false;
|
|
396
|
+
// Restrict segments to unambiguous filesystem names. In particular, a
|
|
397
|
+
// parent component after a symlink can resolve differently from path.resolve.
|
|
398
|
+
return target.replace(start, '').split(/[/\\]/).every(part =>
|
|
399
|
+
/^[A-Za-z0-9_. -]*[A-Za-z0-9_-]$/.test(part) && !part.startsWith(' ')
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
|
|
358
403
|
function parseCwdPrelude(command, options = {}) {
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
const
|
|
362
|
-
|
|
404
|
+
const trimmed = String(command || '').trim();
|
|
405
|
+
const bash = trimmed.match(CWD_PRELUDE_RE);
|
|
406
|
+
const powerShell = bash ? null : trimmed.match(PS_CWD_PRELUDE_RE);
|
|
407
|
+
if (!bash && !powerShell) return null;
|
|
408
|
+
let target;
|
|
409
|
+
let restRaw;
|
|
410
|
+
if (bash) {
|
|
411
|
+
const [, doubleQuoted, singleQuoted, bare, bashRest] = bash;
|
|
412
|
+
target = doubleQuoted ?? singleQuoted ?? bare;
|
|
413
|
+
if (!target || (doubleQuoted !== undefined && UNSAFE_DOUBLE_QUOTED_RE.test(target))) return null;
|
|
414
|
+
if (!stableCdTarget(target, options.platform)) return null;
|
|
415
|
+
target = hostPathToNative(target, options.platform);
|
|
416
|
+
restRaw = bashRest;
|
|
417
|
+
} else {
|
|
418
|
+
[, target, restRaw] = powerShell;
|
|
419
|
+
if (!stablePowerShellTarget(target, options.platform)) return null;
|
|
420
|
+
}
|
|
363
421
|
const rest = restRaw.trim();
|
|
364
|
-
if (!
|
|
365
|
-
if (doubleQuoted !== undefined && UNSAFE_DOUBLE_QUOTED_RE.test(target)) return null;
|
|
422
|
+
if (!rest) return null;
|
|
366
423
|
if (UNSAFE_WRAPPED_RE.test(rest) || hasControlOperators(rest)) return null;
|
|
367
|
-
if (!stableCdTarget(target, options.platform)) return null;
|
|
368
424
|
|
|
369
425
|
const cwd = path.resolve(options.cwd || process.cwd());
|
|
370
426
|
let resolved;
|
|
371
427
|
let root;
|
|
372
428
|
try {
|
|
373
|
-
resolved = fs.realpathSync.native(path.resolve(cwd,
|
|
429
|
+
resolved = fs.realpathSync.native(path.resolve(cwd, target));
|
|
374
430
|
if (!fs.statSync(resolved).isDirectory()) return null;
|
|
375
431
|
root = fs.realpathSync.native(path.resolve(options.root || findGitRoot(cwd)));
|
|
376
432
|
} catch (_) {
|
|
@@ -395,7 +451,7 @@ function cwdKey(dir) {
|
|
|
395
451
|
function isPlainVerificationCommand(command, options = {}) {
|
|
396
452
|
const cwd = path.resolve(options.cwd || process.cwd());
|
|
397
453
|
const actual = normalizeCommand(command);
|
|
398
|
-
if (!actual || hasControlOperators(actual)) return false;
|
|
454
|
+
if (!actual || hasControlOperators(actual) || isVerifierInfoQuery(actual)) return false;
|
|
399
455
|
const set = verificationCommandSet(cwd, options);
|
|
400
456
|
if (set.contractInvalid) return false;
|
|
401
457
|
|
package/sbom.cdx.json
CHANGED
|
@@ -2,23 +2,23 @@
|
|
|
2
2
|
"$schema": "https://cyclonedx.org/schema/bom-1.7.schema.json",
|
|
3
3
|
"bomFormat": "CycloneDX",
|
|
4
4
|
"specVersion": "1.7",
|
|
5
|
-
"serialNumber": "urn:uuid:
|
|
5
|
+
"serialNumber": "urn:uuid:cc86a84d-8231-574c-a714-4a870b59f395",
|
|
6
6
|
"version": 1,
|
|
7
7
|
"metadata": {
|
|
8
|
-
"timestamp": "2026-11-
|
|
8
|
+
"timestamp": "2026-11-25T13:09:46.678Z",
|
|
9
9
|
"tools": [
|
|
10
10
|
{
|
|
11
11
|
"vendor": "Harness Everything",
|
|
12
12
|
"name": "generate-sbom.js",
|
|
13
|
-
"version": "1.
|
|
13
|
+
"version": "1.1.1"
|
|
14
14
|
}
|
|
15
15
|
],
|
|
16
16
|
"component": {
|
|
17
17
|
"type": "application",
|
|
18
|
-
"bom-ref": "pkg:npm/harness-everything@1.
|
|
18
|
+
"bom-ref": "pkg:npm/harness-everything@1.1.1",
|
|
19
19
|
"name": "harness-everything",
|
|
20
|
-
"version": "1.
|
|
21
|
-
"purl": "pkg:npm/harness-everything@1.
|
|
20
|
+
"version": "1.1.1",
|
|
21
|
+
"purl": "pkg:npm/harness-everything@1.1.1"
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"components": [
|
|
@@ -2033,7 +2033,7 @@
|
|
|
2033
2033
|
]
|
|
2034
2034
|
},
|
|
2035
2035
|
{
|
|
2036
|
-
"ref": "pkg:npm/harness-everything@1.
|
|
2036
|
+
"ref": "pkg:npm/harness-everything@1.1.1",
|
|
2037
2037
|
"dependsOn": [
|
|
2038
2038
|
"pkg:npm/%40commitlint/cli@19.8.1",
|
|
2039
2039
|
"pkg:npm/%40commitlint/config-conventional@19.8.1",
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
// Local error CLI (#496 C2): add provisional local lessons, list workspace-scoped
|
|
4
|
+
// records, and export bounded redacted JSONL for triage / #498 bootstrap input.
|
|
5
|
+
// Exit codes: 0 ok, 2 usage/validation error, 1 runtime error.
|
|
6
|
+
|
|
7
|
+
const crypto = require('node:crypto');
|
|
8
|
+
const path = require('node:path');
|
|
9
|
+
const localErrors = require(path.join(__dirname, '..', 'hooks', 'scripts', 'lib', 'local-errors.js'));
|
|
10
|
+
const observations = require(path.join(__dirname, '..', 'hooks', 'scripts', 'lib', 'observations.js'));
|
|
11
|
+
|
|
12
|
+
const IDENTIFIER_PATTERN = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
13
|
+
const KINDS = new Set(['occurrence', 'provisional-lesson']);
|
|
14
|
+
const DESTINATIONS = new Set(localErrors.DESTINATIONS);
|
|
15
|
+
|
|
16
|
+
class UsageError extends Error {
|
|
17
|
+
constructor(message) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = 'UsageError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function usageText() {
|
|
24
|
+
return [
|
|
25
|
+
'Usage:',
|
|
26
|
+
' node scripts/errors-local.js add (--match-json <json> | --executable <id> --subcommand <id> [--diagnostic <id>...]) --lesson <text> [--cue <text>] [--issue <https-url>] [--destination harness|project|unknown] [--signature <id>] [--promotion-id <E-xxxx>] [--json]',
|
|
27
|
+
' node scripts/errors-local.js list [--kind occurrence|provisional-lesson] [--destination harness|project|unknown] [--signature <id>] [--limit <n>] [--json]',
|
|
28
|
+
' node scripts/errors-local.js export [--kind occurrence|provisional-lesson] [--destination harness|project|unknown] [--signature <id>] [--limit <n>]',
|
|
29
|
+
].join('\n');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function requireValue(argv, index, flag) {
|
|
33
|
+
if (index + 1 >= argv.length) throw new UsageError(`missing value for ${flag}`);
|
|
34
|
+
return argv[index + 1];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function parseLimit(raw) {
|
|
38
|
+
if (!/^\d+$/.test(String(raw))) throw new UsageError(`invalid --limit: ${raw}`);
|
|
39
|
+
const value = Number.parseInt(raw, 10);
|
|
40
|
+
if (!Number.isSafeInteger(value) || value < 1) throw new UsageError(`invalid --limit: ${raw}`);
|
|
41
|
+
return Math.min(value, localErrors.LIMITS.maxRecordsPerWorkspace);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function deriveSignature(match, lesson, env = process.env) {
|
|
45
|
+
const redactedLesson = localErrors.redactErrorText(String(lesson || '').trim(), env)
|
|
46
|
+
.slice(0, localErrors.LIMITS.maxLessonChars);
|
|
47
|
+
const firstRule = (match.failures && match.failures[0]) || (match.actions && match.actions[0]);
|
|
48
|
+
const hash = crypto.createHash('sha256').update(JSON.stringify([match, redactedLesson])).digest('hex').slice(0, 8);
|
|
49
|
+
if (firstRule && firstRule.executable && firstRule.subcommand) {
|
|
50
|
+
const base = `local-${firstRule.executable}-${firstRule.subcommand}-${hash}`;
|
|
51
|
+
if (base.length <= 64 && IDENTIFIER_PATTERN.test(base)) return base;
|
|
52
|
+
}
|
|
53
|
+
return `local-${hash}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function isValidationError(error) {
|
|
57
|
+
return error instanceof Error && !error.code && typeof error.message === 'string' && /^invalid\b/i.test(error.message);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function sanitizeExportRecord(record, env) {
|
|
61
|
+
const limits = localErrors.LIMITS;
|
|
62
|
+
if (!record || typeof record !== 'object') return null;
|
|
63
|
+
|
|
64
|
+
if (record.kind === 'provisional-lesson') {
|
|
65
|
+
const out = {
|
|
66
|
+
schemaVersion: record.schemaVersion,
|
|
67
|
+
kind: 'provisional-lesson',
|
|
68
|
+
provisionalId: record.provisionalId,
|
|
69
|
+
workspaceKey: record.workspaceKey,
|
|
70
|
+
destination: record.destination,
|
|
71
|
+
createdAt: record.createdAt,
|
|
72
|
+
signature: record.signature,
|
|
73
|
+
match: record.match,
|
|
74
|
+
lesson: localErrors.redactErrorText(String(record.lesson || ''), env).slice(0, limits.maxLessonChars),
|
|
75
|
+
issueUrl: record.issueUrl ?? null,
|
|
76
|
+
promotionId: record.promotionId ?? null,
|
|
77
|
+
};
|
|
78
|
+
if (typeof record.cue === 'string') {
|
|
79
|
+
out.cue = localErrors.redactErrorText(record.cue, env).slice(0, limits.maxCueChars);
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (record.kind === 'occurrence') {
|
|
85
|
+
const redactedExcerpt = localErrors.redactErrorText(String(record.outputExcerpt || ''), env);
|
|
86
|
+
return {
|
|
87
|
+
schemaVersion: record.schemaVersion,
|
|
88
|
+
kind: 'occurrence',
|
|
89
|
+
provisionalId: record.provisionalId,
|
|
90
|
+
workspaceKey: record.workspaceKey,
|
|
91
|
+
destination: record.destination,
|
|
92
|
+
createdAt: record.createdAt,
|
|
93
|
+
signature: record.signature,
|
|
94
|
+
source: record.source,
|
|
95
|
+
host: record.host,
|
|
96
|
+
sessionKey: record.sessionKey ?? null,
|
|
97
|
+
toolUseId: record.toolUseId ?? null,
|
|
98
|
+
commandClass: record.commandClass,
|
|
99
|
+
exitCode: Number.isInteger(record.exitCode) ? record.exitCode : null,
|
|
100
|
+
outputExcerpt: observations.tailBytes(redactedExcerpt, limits.maxExcerptBytes),
|
|
101
|
+
matchedLedgerIds: Array.isArray(record.matchedLedgerIds) ? record.matchedLedgerIds.slice(0, limits.maxMatchedLedgerIds) : [],
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function parseAddArgs(argv, env = process.env) {
|
|
109
|
+
const opts = {
|
|
110
|
+
matchJson: null,
|
|
111
|
+
executable: null,
|
|
112
|
+
subcommand: null,
|
|
113
|
+
diagnostics: [],
|
|
114
|
+
lesson: null,
|
|
115
|
+
cue: undefined,
|
|
116
|
+
issueUrl: undefined,
|
|
117
|
+
destination: 'unknown',
|
|
118
|
+
signature: null,
|
|
119
|
+
promotionId: undefined,
|
|
120
|
+
json: false,
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
124
|
+
const arg = argv[i];
|
|
125
|
+
if (arg === '--match-json') { opts.matchJson = requireValue(argv, i, arg); i += 1; }
|
|
126
|
+
else if (arg === '--executable') { opts.executable = requireValue(argv, i, arg); i += 1; }
|
|
127
|
+
else if (arg === '--subcommand') { opts.subcommand = requireValue(argv, i, arg); i += 1; }
|
|
128
|
+
else if (arg === '--diagnostic') { opts.diagnostics.push(requireValue(argv, i, arg)); i += 1; }
|
|
129
|
+
else if (arg === '--lesson') { opts.lesson = requireValue(argv, i, arg); i += 1; }
|
|
130
|
+
else if (arg === '--cue') { opts.cue = requireValue(argv, i, arg); i += 1; }
|
|
131
|
+
else if (arg === '--issue') { opts.issueUrl = requireValue(argv, i, arg); i += 1; }
|
|
132
|
+
else if (arg === '--destination') { opts.destination = requireValue(argv, i, arg); i += 1; }
|
|
133
|
+
else if (arg === '--signature') { opts.signature = requireValue(argv, i, arg); i += 1; }
|
|
134
|
+
else if (arg === '--promotion-id') { opts.promotionId = requireValue(argv, i, arg); i += 1; }
|
|
135
|
+
else if (arg === '--json') { opts.json = true; }
|
|
136
|
+
else if (arg === '--help' || arg === '-h') { return { help: true }; }
|
|
137
|
+
else { throw new UsageError(`unknown option for add: ${arg}`); }
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const hasMatchJson = opts.matchJson !== null;
|
|
141
|
+
const hasFlagRule = opts.executable !== null || opts.subcommand !== null || opts.diagnostics.length > 0;
|
|
142
|
+
if (hasMatchJson && hasFlagRule) {
|
|
143
|
+
throw new UsageError('use either --match-json or --executable/--subcommand[/--diagnostic], not both');
|
|
144
|
+
}
|
|
145
|
+
if (!hasMatchJson && !hasFlagRule) {
|
|
146
|
+
throw new UsageError('match rule required: provide --match-json or --executable and --subcommand');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
let match;
|
|
150
|
+
if (hasMatchJson) {
|
|
151
|
+
try {
|
|
152
|
+
match = JSON.parse(opts.matchJson);
|
|
153
|
+
} catch (error) {
|
|
154
|
+
throw new UsageError(`invalid --match-json: ${error.message}`);
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
if (!opts.executable || !opts.subcommand) {
|
|
158
|
+
throw new UsageError('both --executable and --subcommand are required');
|
|
159
|
+
}
|
|
160
|
+
if (opts.diagnostics.length > 0) {
|
|
161
|
+
match = {
|
|
162
|
+
failures: [{
|
|
163
|
+
tool: 'shell',
|
|
164
|
+
executable: opts.executable,
|
|
165
|
+
subcommand: opts.subcommand,
|
|
166
|
+
diagnostics: opts.diagnostics,
|
|
167
|
+
}],
|
|
168
|
+
};
|
|
169
|
+
} else {
|
|
170
|
+
match = {
|
|
171
|
+
actions: [{
|
|
172
|
+
tool: 'shell',
|
|
173
|
+
executable: opts.executable,
|
|
174
|
+
subcommand: opts.subcommand,
|
|
175
|
+
}],
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
try {
|
|
181
|
+
match = localErrors.validateMatch(match);
|
|
182
|
+
} catch (error) {
|
|
183
|
+
throw new UsageError(error.message);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (typeof opts.lesson !== 'string' || !opts.lesson.trim()) {
|
|
187
|
+
throw new UsageError('--lesson is required and must be non-empty');
|
|
188
|
+
}
|
|
189
|
+
if (!DESTINATIONS.has(opts.destination)) {
|
|
190
|
+
throw new UsageError(`invalid --destination: ${opts.destination} (expected harness|project|unknown)`);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const signature = opts.signature || deriveSignature(match, opts.lesson.trim(), env);
|
|
194
|
+
if (!IDENTIFIER_PATTERN.test(signature)) {
|
|
195
|
+
throw new UsageError(`invalid --signature: ${signature}`);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return { ...opts, match, signature };
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function parseQueryArgs(subcommand, argv, allowJson) {
|
|
202
|
+
const opts = {
|
|
203
|
+
kind: null,
|
|
204
|
+
destination: null,
|
|
205
|
+
signature: null,
|
|
206
|
+
limit: localErrors.LIMITS.maxRecordsPerWorkspace,
|
|
207
|
+
json: false,
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
211
|
+
const arg = argv[i];
|
|
212
|
+
if (arg === '--kind') {
|
|
213
|
+
const value = requireValue(argv, i, arg);
|
|
214
|
+
if (!KINDS.has(value)) throw new UsageError(`invalid --kind: ${value} (expected occurrence|provisional-lesson)`);
|
|
215
|
+
opts.kind = value;
|
|
216
|
+
i += 1;
|
|
217
|
+
} else if (arg === '--destination') {
|
|
218
|
+
const value = requireValue(argv, i, arg);
|
|
219
|
+
if (!DESTINATIONS.has(value)) throw new UsageError(`invalid --destination: ${value} (expected harness|project|unknown)`);
|
|
220
|
+
opts.destination = value;
|
|
221
|
+
i += 1;
|
|
222
|
+
} else if (arg === '--signature') {
|
|
223
|
+
opts.signature = requireValue(argv, i, arg);
|
|
224
|
+
i += 1;
|
|
225
|
+
} else if (arg === '--limit') {
|
|
226
|
+
opts.limit = parseLimit(requireValue(argv, i, arg));
|
|
227
|
+
i += 1;
|
|
228
|
+
} else if (allowJson && arg === '--json') {
|
|
229
|
+
opts.json = true;
|
|
230
|
+
} else if (arg === '--help' || arg === '-h') {
|
|
231
|
+
return { help: true };
|
|
232
|
+
} else {
|
|
233
|
+
throw new UsageError(`unknown option for ${subcommand}: ${arg}`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return opts;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function handleAdd(argv, env, cwd) {
|
|
241
|
+
const opts = parseAddArgs(argv, env);
|
|
242
|
+
if (opts.help) {
|
|
243
|
+
process.stdout.write(`${usageText()}\n`);
|
|
244
|
+
return 0;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
let res;
|
|
248
|
+
try {
|
|
249
|
+
res = localErrors.addProvisionalLesson({
|
|
250
|
+
workspaceRoot: cwd,
|
|
251
|
+
destination: opts.destination,
|
|
252
|
+
signature: opts.signature,
|
|
253
|
+
match: opts.match,
|
|
254
|
+
lesson: opts.lesson,
|
|
255
|
+
...(opts.cue !== undefined ? { cue: opts.cue } : {}),
|
|
256
|
+
...(opts.issueUrl !== undefined ? { issueUrl: opts.issueUrl } : {}),
|
|
257
|
+
...(opts.promotionId !== undefined ? { promotionId: opts.promotionId } : {}),
|
|
258
|
+
}, { env });
|
|
259
|
+
} catch (error) {
|
|
260
|
+
if (isValidationError(error)) {
|
|
261
|
+
throw new UsageError(error.message);
|
|
262
|
+
}
|
|
263
|
+
throw error;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (res.status === 'lock-timeout' || !res.record) {
|
|
267
|
+
process.stderr.write(`error: could not acquire local error store lock\n`);
|
|
268
|
+
return 1;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const sanitized = sanitizeExportRecord(res.record, env);
|
|
272
|
+
if (opts.json) {
|
|
273
|
+
process.stdout.write(`${JSON.stringify({ status: res.status, record: sanitized })}\n`);
|
|
274
|
+
} else {
|
|
275
|
+
process.stdout.write(`${res.status} ${sanitized.provisionalId} ${sanitized.signature} (${sanitized.destination})\n`);
|
|
276
|
+
}
|
|
277
|
+
return 0;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function handleList(argv, env, cwd) {
|
|
281
|
+
const opts = parseQueryArgs('list', argv, true);
|
|
282
|
+
if (opts.help) {
|
|
283
|
+
process.stdout.write(`${usageText()}\n`);
|
|
284
|
+
return 0;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const records = localErrors.listRecords({
|
|
288
|
+
env,
|
|
289
|
+
workspaceRoot: cwd,
|
|
290
|
+
...(opts.kind ? { kind: opts.kind } : {}),
|
|
291
|
+
...(opts.destination ? { destination: opts.destination } : {}),
|
|
292
|
+
...(opts.signature ? { signature: opts.signature } : {}),
|
|
293
|
+
limit: opts.limit,
|
|
294
|
+
}).map(r => sanitizeExportRecord(r, env)).filter(Boolean);
|
|
295
|
+
|
|
296
|
+
if (opts.json) {
|
|
297
|
+
process.stdout.write(`${JSON.stringify(records)}\n`);
|
|
298
|
+
return 0;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
for (const record of records) {
|
|
302
|
+
const summary = record.kind === 'provisional-lesson'
|
|
303
|
+
? record.lesson.replace(/\s+/g, ' ').slice(0, 120)
|
|
304
|
+
: `${record.commandClass} exit=${record.exitCode === null ? 'unknown' : record.exitCode}`;
|
|
305
|
+
process.stdout.write(`${record.provisionalId}\t${record.kind}\t${record.destination}\t${record.signature}\t${summary}\n`);
|
|
306
|
+
}
|
|
307
|
+
return 0;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function handleExport(argv, env, cwd) {
|
|
311
|
+
const opts = parseQueryArgs('export', argv, false);
|
|
312
|
+
if (opts.help) {
|
|
313
|
+
process.stdout.write(`${usageText()}\n`);
|
|
314
|
+
return 0;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const records = localErrors.listRecords({
|
|
318
|
+
env,
|
|
319
|
+
workspaceRoot: cwd,
|
|
320
|
+
...(opts.kind ? { kind: opts.kind } : {}),
|
|
321
|
+
...(opts.destination ? { destination: opts.destination } : {}),
|
|
322
|
+
...(opts.signature ? { signature: opts.signature } : {}),
|
|
323
|
+
limit: opts.limit,
|
|
324
|
+
}).map(r => sanitizeExportRecord(r, env)).filter(Boolean);
|
|
325
|
+
|
|
326
|
+
for (const record of records) {
|
|
327
|
+
process.stdout.write(`${JSON.stringify(record)}\n`);
|
|
328
|
+
}
|
|
329
|
+
return 0;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function main(argv = process.argv.slice(2), env = process.env, cwd = process.cwd()) {
|
|
333
|
+
try {
|
|
334
|
+
const [subcommand, ...rest] = argv;
|
|
335
|
+
if (!subcommand || subcommand === '--help' || subcommand === '-h') {
|
|
336
|
+
process.stdout.write(`${usageText()}\n`);
|
|
337
|
+
return subcommand ? 0 : 2;
|
|
338
|
+
}
|
|
339
|
+
if (subcommand === 'add') return handleAdd(rest, env, cwd);
|
|
340
|
+
if (subcommand === 'list') return handleList(rest, env, cwd);
|
|
341
|
+
if (subcommand === 'export') return handleExport(rest, env, cwd);
|
|
342
|
+
throw new UsageError(`unknown subcommand: ${subcommand}`);
|
|
343
|
+
} catch (error) {
|
|
344
|
+
if (error instanceof UsageError) {
|
|
345
|
+
process.stderr.write(`usage error: ${error.message}\n`);
|
|
346
|
+
return 2;
|
|
347
|
+
}
|
|
348
|
+
process.stderr.write(`error: ${error && error.message ? error.message : String(error)}\n`);
|
|
349
|
+
return 1;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (require.main === module) {
|
|
354
|
+
process.exit(main());
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
module.exports = { main, sanitizeExportRecord };
|
|
@@ -201,6 +201,12 @@ function detectRoot(root) {
|
|
|
201
201
|
}
|
|
202
202
|
if (fs.existsSync(path.join(root, 'tox.ini'))) addCandidate(candidates, seen, { source: 'tox', run: 'tox', cwd: root });
|
|
203
203
|
if (fs.existsSync(path.join(root, 'noxfile.py'))) addCandidate(candidates, seen, { source: 'nox', run: 'nox', cwd: root });
|
|
204
|
+
if (fs.existsSync(path.join(root, 'mkdocs.yml')) || fs.existsSync(path.join(root, 'mkdocs.yaml'))) {
|
|
205
|
+
addCandidate(candidates, seen, { source: 'mkdocs', run: 'mkdocs build --strict', cwd: root });
|
|
206
|
+
if (/\[tool\.poetry(?:\.|\])/m.test(pyproject)) {
|
|
207
|
+
addCandidate(candidates, seen, { source: 'mkdocs:poetry', run: 'poetry run mkdocs build --strict', cwd: root });
|
|
208
|
+
}
|
|
209
|
+
}
|
|
204
210
|
if (fs.existsSync(path.join(root, 'Cargo.toml'))) addCandidate(candidates, seen, { source: 'cargo', run: 'cargo test', cwd: root });
|
|
205
211
|
if (fs.existsSync(path.join(root, 'go.mod'))) addCandidate(candidates, seen, { source: 'go', run: 'go test ./...', cwd: root });
|
|
206
212
|
|
|
@@ -245,6 +251,10 @@ function normalizeCommand(command) {
|
|
|
245
251
|
return String(command || '').trim().replace(/\s+/g, ' ');
|
|
246
252
|
}
|
|
247
253
|
|
|
254
|
+
function stripWindowsCmdShim(command) {
|
|
255
|
+
return String(command || '').replace(/^(npm|pnpm|yarn|bun|npx)\.cmd(?=\s|$)/i, '$1');
|
|
256
|
+
}
|
|
257
|
+
|
|
248
258
|
function hasControlOperators(command) {
|
|
249
259
|
return /(?:&&|\|\||[;|\r\n])/.test(command);
|
|
250
260
|
}
|
|
@@ -253,7 +263,9 @@ function commandMatches(command, expected) {
|
|
|
253
263
|
const actual = normalizeCommand(command);
|
|
254
264
|
const target = normalizeCommand(expected);
|
|
255
265
|
if (!actual || !target || hasControlOperators(actual)) return false;
|
|
256
|
-
|
|
266
|
+
const normalizedActual = stripWindowsCmdShim(actual);
|
|
267
|
+
const normalizedTarget = stripWindowsCmdShim(target);
|
|
268
|
+
return normalizedActual === normalizedTarget || normalizedActual.startsWith(normalizedTarget + ' ');
|
|
257
269
|
}
|
|
258
270
|
|
|
259
271
|
function isGitCommit(command) {
|
|
@@ -274,9 +286,28 @@ function bypassesHooks(command) {
|
|
|
274
286
|
);
|
|
275
287
|
}
|
|
276
288
|
|
|
289
|
+
const NODE_TEST_RE = /^node\s+--test(?:\s|$)/i;
|
|
290
|
+
const DOC_BUILD_RE = /^(?:(?:uv|poetry)\s+run\s+mkdocs(?:\.exe)?\s+build|(?:(?:\.?[/\\])?(?:\.?venv|env)[/\\](?:Scripts|bin)[/\\])?(?:mkdocs(?:\.exe)?\s+build|sphinx-build(?:\.exe)?))(?:\s|$)/i;
|
|
291
|
+
|
|
292
|
+
function isVerifierInfoQuery(command) {
|
|
293
|
+
const nodeTest = NODE_TEST_RE.exec(command);
|
|
294
|
+
const verifier = nodeTest || DOC_BUILD_RE.exec(command);
|
|
295
|
+
if (!verifier) return false;
|
|
296
|
+
|
|
297
|
+
// Keep quoted argument values together, while recognizing quoted switches.
|
|
298
|
+
const args = command.slice(verifier[0].length).match(/(?:[^\s"'\x60\\]|\\.|\x60.|"[^"]*"|'[^']*')+/g) || [];
|
|
299
|
+
const options = args.map(arg => arg.replace(/["']/g, '').replace(/(?:\\|\x60)(?=[A-Za-z-])/g, ''));
|
|
300
|
+
if (options[0] === '-M' && options[1] === 'help' && /sphinx-build(?:\.exe)?\s*$/i.test(verifier[0])) return true;
|
|
301
|
+
const versionFlag = nodeTest ? '-v' : '-V';
|
|
302
|
+
return options.some(option =>
|
|
303
|
+
option === '--help' || option === '--version' || option === '-h' || option === versionFlag
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
|
|
277
307
|
function legacyVerificationCommand(command) {
|
|
278
|
-
const value = normalizeCommand(command);
|
|
279
|
-
|
|
308
|
+
const value = stripWindowsCmdShim(normalizeCommand(command));
|
|
309
|
+
if (NODE_TEST_RE.test(value) || DOC_BUILD_RE.test(value)) return !isVerifierInfoQuery(value);
|
|
310
|
+
return /^(?:(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?(?:test|lint|build|typecheck|check|verify)\b|npx\s+(?:jest|vitest|mocha|tsc|eslint)\b|(?:jest|vitest|mocha|pytest|rspec|phpunit)\b|(?:uv|poetry)\s+run\s+(?:pytest|ruff)\b|(?:make|just)\s+(?:test|check|lint|ci)\b|cargo\s+(?:test|check)\b|go\s+test\b|dotnet\s+(?:test|build)\b)/i.test(value);
|
|
280
311
|
}
|
|
281
312
|
|
|
282
313
|
function verificationCommandSet(cwd, options = {}) {
|
|
@@ -334,6 +365,9 @@ function verificationCommandSet(cwd, options = {}) {
|
|
|
334
365
|
// command must be one plain command: no further control operators,
|
|
335
366
|
// redirection, substitution, expansion, subshell, or background syntax.
|
|
336
367
|
const CWD_PRELUDE_RE = /^cd\s+(?:"([^"]*)"|'([^']*)'|([A-Za-z0-9_./:@%+,-]+))\s*&&\s*([\s\S]+)$/;
|
|
368
|
+
// PowerShell 7 must stop on a failed location change before running the
|
|
369
|
+
// verifier. Match only a single-quoted filesystem path with explicit flags.
|
|
370
|
+
const PS_CWD_PRELUDE_RE = /^Set-Location[ \t]+-LiteralPath[ \t]+'([^'\r\n]+)'[ \t]+-ErrorAction[ \t]+Stop[ \t]*&&[ \t]*([^\r\n]+)$/i;
|
|
337
371
|
const UNSAFE_WRAPPED_RE = /[`$<>&|;()\r\n]/;
|
|
338
372
|
const UNSAFE_DOUBLE_QUOTED_RE = /[$`!]|\\[\\"$`]|\\$/;
|
|
339
373
|
|
|
@@ -355,22 +389,44 @@ function stableCdTarget(target, platform = process.platform) {
|
|
|
355
389
|
return target.startsWith('/');
|
|
356
390
|
}
|
|
357
391
|
|
|
392
|
+
function stablePowerShellTarget(target, platform = process.platform) {
|
|
393
|
+
const start = platform === 'win32' ? /^(?:[A-Za-z]:|\.)[/\\]/ : /^(?:\.)?\//;
|
|
394
|
+
if (target === '.') return true;
|
|
395
|
+
if (!start.test(target) || (platform !== 'win32' && target.includes('\\'))) return false;
|
|
396
|
+
// Restrict segments to unambiguous filesystem names. In particular, a
|
|
397
|
+
// parent component after a symlink can resolve differently from path.resolve.
|
|
398
|
+
return target.replace(start, '').split(/[/\\]/).every(part =>
|
|
399
|
+
/^[A-Za-z0-9_. -]*[A-Za-z0-9_-]$/.test(part) && !part.startsWith(' ')
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
|
|
358
403
|
function parseCwdPrelude(command, options = {}) {
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
const
|
|
362
|
-
|
|
404
|
+
const trimmed = String(command || '').trim();
|
|
405
|
+
const bash = trimmed.match(CWD_PRELUDE_RE);
|
|
406
|
+
const powerShell = bash ? null : trimmed.match(PS_CWD_PRELUDE_RE);
|
|
407
|
+
if (!bash && !powerShell) return null;
|
|
408
|
+
let target;
|
|
409
|
+
let restRaw;
|
|
410
|
+
if (bash) {
|
|
411
|
+
const [, doubleQuoted, singleQuoted, bare, bashRest] = bash;
|
|
412
|
+
target = doubleQuoted ?? singleQuoted ?? bare;
|
|
413
|
+
if (!target || (doubleQuoted !== undefined && UNSAFE_DOUBLE_QUOTED_RE.test(target))) return null;
|
|
414
|
+
if (!stableCdTarget(target, options.platform)) return null;
|
|
415
|
+
target = hostPathToNative(target, options.platform);
|
|
416
|
+
restRaw = bashRest;
|
|
417
|
+
} else {
|
|
418
|
+
[, target, restRaw] = powerShell;
|
|
419
|
+
if (!stablePowerShellTarget(target, options.platform)) return null;
|
|
420
|
+
}
|
|
363
421
|
const rest = restRaw.trim();
|
|
364
|
-
if (!
|
|
365
|
-
if (doubleQuoted !== undefined && UNSAFE_DOUBLE_QUOTED_RE.test(target)) return null;
|
|
422
|
+
if (!rest) return null;
|
|
366
423
|
if (UNSAFE_WRAPPED_RE.test(rest) || hasControlOperators(rest)) return null;
|
|
367
|
-
if (!stableCdTarget(target, options.platform)) return null;
|
|
368
424
|
|
|
369
425
|
const cwd = path.resolve(options.cwd || process.cwd());
|
|
370
426
|
let resolved;
|
|
371
427
|
let root;
|
|
372
428
|
try {
|
|
373
|
-
resolved = fs.realpathSync.native(path.resolve(cwd,
|
|
429
|
+
resolved = fs.realpathSync.native(path.resolve(cwd, target));
|
|
374
430
|
if (!fs.statSync(resolved).isDirectory()) return null;
|
|
375
431
|
root = fs.realpathSync.native(path.resolve(options.root || findGitRoot(cwd)));
|
|
376
432
|
} catch (_) {
|
|
@@ -395,7 +451,7 @@ function cwdKey(dir) {
|
|
|
395
451
|
function isPlainVerificationCommand(command, options = {}) {
|
|
396
452
|
const cwd = path.resolve(options.cwd || process.cwd());
|
|
397
453
|
const actual = normalizeCommand(command);
|
|
398
|
-
if (!actual || hasControlOperators(actual)) return false;
|
|
454
|
+
if (!actual || hasControlOperators(actual) || isVerifierInfoQuery(actual)) return false;
|
|
399
455
|
const set = verificationCommandSet(cwd, options);
|
|
400
456
|
if (set.contractInvalid) return false;
|
|
401
457
|
|