@opengsd/gsd-core 1.7.0 → 1.8.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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.opencode/plugins/gsd-core.js +14 -0
- package/README.md +2 -0
- package/agents/gsd-debug-session-manager.md +42 -4
- package/agents/gsd-debugger.md +87 -29
- package/agents/gsd-executor.md +29 -2
- package/agents/gsd-planner.md +29 -36
- package/agents/gsd-verifier.md +2 -2
- package/bin/install.js +1152 -80
- package/commands/gsd/ai-integration-phase.md +1 -1
- package/commands/gsd/mempalace-capture.md +9 -5
- package/commands/gsd/new-milestone.md +1 -1
- package/commands/gsd/plan-phase.md +5 -3
- package/commands/gsd/plan-review-convergence.md +3 -2
- package/gsd-core/bin/gsd-tools.cjs +1878 -2507
- package/gsd-core/bin/lib/adapter-imperative.cjs +8 -1
- package/gsd-core/bin/lib/agent-command-router.cjs +20 -5
- package/gsd-core/bin/lib/api-coverage.cjs +338 -45
- package/gsd-core/bin/lib/broken-windows.cjs +716 -0
- package/gsd-core/bin/lib/capability-command-router.cjs +733 -0
- package/gsd-core/bin/lib/capability-registry.cjs +155 -86
- package/gsd-core/bin/lib/capability-writer.cjs +6 -1
- package/gsd-core/bin/lib/check-command-router.cjs +128 -25
- package/gsd-core/bin/lib/claude-orchestration-command-router.cjs +115 -27
- package/gsd-core/bin/lib/claude-orchestration.cjs +84 -9
- package/gsd-core/bin/lib/command-aliases.cjs +14 -0
- package/gsd-core/bin/lib/commands.cjs +81 -4
- package/gsd-core/bin/lib/config-loader.cjs +14 -2
- package/gsd-core/bin/lib/config.cjs +69 -18
- package/gsd-core/bin/lib/core-utils.cjs +6 -1
- package/gsd-core/bin/lib/decisions.cjs +32 -8
- package/gsd-core/bin/lib/docs.cjs +6 -0
- package/gsd-core/bin/lib/external-descriptor-trust.cjs +14 -2
- package/gsd-core/bin/lib/gap-checker.cjs +17 -2
- package/gsd-core/bin/lib/init.cjs +111 -47
- package/gsd-core/bin/lib/install-engine.cjs +298 -23
- package/gsd-core/bin/lib/install-profiles.cjs +239 -1
- package/gsd-core/bin/lib/installer-migrations/005-opencode-baseline-commands-dir.cjs +146 -0
- package/gsd-core/bin/lib/installer-migrations/006-pi-extension-cjs-to-js.cjs +91 -0
- package/gsd-core/bin/lib/installer-migrations.cjs +44 -5
- package/gsd-core/bin/lib/markdown-sectionizer.cjs +107 -0
- package/gsd-core/bin/lib/milestone.cjs +246 -12
- package/gsd-core/bin/lib/model-catalog.cjs +19 -4
- package/gsd-core/bin/lib/model-resolver.cjs +189 -7
- package/gsd-core/bin/lib/onboard-projection.cjs +11 -8
- package/gsd-core/bin/lib/phase-id.cjs +26 -4
- package/gsd-core/bin/lib/phase.cjs +201 -12
- package/gsd-core/bin/lib/plan-scan.cjs +70 -2
- package/gsd-core/bin/lib/roadmap-parser.cjs +7 -4
- package/gsd-core/bin/lib/roadmap.cjs +13 -3
- package/gsd-core/bin/lib/runtime-artifact-conversion.cjs +7 -1
- package/gsd-core/bin/lib/runtime-artifact-layout.cjs +22 -8
- package/gsd-core/bin/lib/runtime-hooks-surface.cjs +16 -0
- package/gsd-core/bin/lib/smart-entry.cjs +69 -4
- package/gsd-core/bin/lib/state-document.cjs +7 -4
- package/gsd-core/bin/lib/state-transition.cjs +22 -1
- package/gsd-core/bin/lib/state.cjs +65 -11
- package/gsd-core/bin/lib/surface.cjs +51 -9
- package/gsd-core/bin/lib/uat.cjs +420 -5
- package/gsd-core/bin/lib/validate.cjs +12 -8
- package/gsd-core/bin/lib/verification.cjs +112 -17
- package/gsd-core/bin/lib/verify.cjs +220 -22
- package/gsd-core/bin/shared/config-schema.manifest.json +3 -2
- package/gsd-core/references/api-coverage.md +37 -7
- package/gsd-core/references/checkpoints.md +1 -1
- package/gsd-core/references/common-bug-patterns.md +13 -0
- package/gsd-core/references/debugger-bug-taxonomy.md +111 -0
- package/gsd-core/references/debugger-fix-acceptance.md +157 -0
- package/gsd-core/references/debugger-philosophy.md +1 -0
- package/gsd-core/references/debugger-prevention.md +98 -0
- package/gsd-core/references/debugger-rca-branching.md +98 -0
- package/gsd-core/references/debugger-repro-hardening.md +130 -0
- package/gsd-core/references/debugger-sbfl.md +110 -0
- package/gsd-core/references/debugger-semantic-recall.md +81 -0
- package/gsd-core/references/execute-phase-quota-recovery.md +55 -0
- package/gsd-core/references/execute-phase-requirement-revert.md +8 -0
- package/gsd-core/references/execute-phase-response-language.md +7 -0
- package/gsd-core/references/planner-antipatterns.md +6 -0
- package/gsd-core/references/planner-mvp-mode.md +12 -13
- package/gsd-core/references/planner-preconditions.md +156 -0
- package/gsd-core/references/planner-reversibility.md +132 -0
- package/gsd-core/references/reviewer-instances.md +9 -7
- package/gsd-core/references/skeleton-template.md +1 -1
- package/gsd-core/references/thinking-models-planning.md +3 -1
- package/gsd-core/templates/DEBUG.md +5 -3
- package/gsd-core/workflows/add-phase.md +2 -0
- package/gsd-core/workflows/add-tests.md +3 -1
- package/gsd-core/workflows/add-todo.md +32 -1
- package/gsd-core/workflows/ai-integration-phase.md +4 -2
- package/gsd-core/workflows/audit-fix.md +2 -2
- package/gsd-core/workflows/check-todos.md +3 -1
- package/gsd-core/workflows/cleanup.md +7 -1
- package/gsd-core/workflows/code-review.md +17 -5
- package/gsd-core/workflows/complete-milestone.md +3 -0
- package/gsd-core/workflows/debug.md +25 -5
- package/gsd-core/workflows/diagnose-issues.md +1 -1
- package/gsd-core/workflows/discovery-phase.md +7 -0
- package/gsd-core/workflows/discuss-phase/templates/context.md +16 -2
- package/gsd-core/workflows/discuss-phase-assumptions.md +3 -0
- package/gsd-core/workflows/do.md +7 -1
- package/gsd-core/workflows/docs-update.md +1 -0
- package/gsd-core/workflows/eval-review.md +3 -0
- package/gsd-core/workflows/execute-phase/steps/post-merge-gate.md +4 -4
- package/gsd-core/workflows/execute-phase/steps/regression-gate.md +2 -2
- package/gsd-core/workflows/execute-phase.md +25 -34
- package/gsd-core/workflows/execute-plan.md +15 -4
- package/gsd-core/workflows/graduation.md +3 -0
- package/gsd-core/workflows/health.md +7 -1
- package/gsd-core/workflows/help/modes/full.md +6 -2
- package/gsd-core/workflows/import.md +8 -2
- package/gsd-core/workflows/inbox.md +7 -0
- package/gsd-core/workflows/ingest-docs.md +15 -10
- package/gsd-core/workflows/manager.md +3 -1
- package/gsd-core/workflows/map-codebase.md +4 -4
- package/gsd-core/workflows/mvp-phase.md +3 -0
- package/gsd-core/workflows/new-milestone.md +69 -21
- package/gsd-core/workflows/new-project.md +17 -15
- package/gsd-core/workflows/new-workspace.md +3 -1
- package/gsd-core/workflows/onboard.md +3 -0
- package/gsd-core/workflows/plan-phase.md +14 -5
- package/gsd-core/workflows/plan-review-convergence.md +48 -3
- package/gsd-core/workflows/plant-seed.md +3 -0
- package/gsd-core/workflows/profile-user.md +7 -1
- package/gsd-core/workflows/progress.md +31 -3
- package/gsd-core/workflows/quick.md +19 -7
- package/gsd-core/workflows/remove-workspace.md +3 -0
- package/gsd-core/workflows/review.md +89 -73
- package/gsd-core/workflows/scan.md +1 -1
- package/gsd-core/workflows/secure-phase.md +3 -0
- package/gsd-core/workflows/settings-integrations.md +3 -0
- package/gsd-core/workflows/settings.md +3 -0
- package/gsd-core/workflows/ship.md +50 -3
- package/gsd-core/workflows/sketch.md +3 -0
- package/gsd-core/workflows/smart-entry.md +3 -0
- package/gsd-core/workflows/spike.md +7 -1
- package/gsd-core/workflows/ui-phase.md +3 -1
- package/gsd-core/workflows/ui-review.md +3 -0
- package/gsd-core/workflows/undo.md +7 -0
- package/gsd-core/workflows/update.md +2 -0
- package/gsd-core/workflows/validate-phase.md +3 -0
- package/gsd-core/workflows/verify-phase.md +2 -2
- package/gsd-core/workflows/verify-work.md +7 -3
- package/hooks/dist/gsd-context-monitor.js +27 -9
- package/hooks/dist/gsd-statusline.js +88 -3
- package/hooks/gsd-context-monitor.js +27 -9
- package/hooks/gsd-statusline.js +88 -3
- package/package.json +6 -4
- package/pi/gsd.cjs +8 -2
- package/scripts/changeset/lint.cjs +1 -0
- package/scripts/changeset/parse.cjs +26 -0
- package/scripts/check-glossary-refs.cjs +220 -0
- package/scripts/ci-rebase-check.cjs +48 -4
- package/scripts/gen-adr-index.cjs +526 -0
- package/scripts/gen-test-timings.cjs +201 -0
- package/scripts/lint-portable-timeout.cjs +140 -0
- package/scripts/lint-test-file-count.allowlist.json +1 -0
- package/scripts/release-tarball-smoke.cjs +18 -11
- package/scripts/run-tests.cjs +420 -58
- package/skills/gsd-ai-integration-phase/SKILL.md +1 -1
- package/skills/gsd-mempalace-capture/SKILL.md +9 -5
- package/skills/gsd-new-milestone/SKILL.md +1 -1
- package/skills/gsd-plan-phase/SKILL.md +5 -3
- package/skills/gsd-plan-review-convergence/SKILL.md +3 -2
- package/vscode/package.json +1 -1
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Regenerate the per-file test timing table used to weight chunk packing in
|
|
3
|
+
// scripts/run-tests.cjs (issue #2456).
|
|
4
|
+
//
|
|
5
|
+
// The chunk packer needs to know what each test file actually COSTS. Before
|
|
6
|
+
// #2456 it guessed from the filename (`^(?:install|codex-)` scored 12x,
|
|
7
|
+
// everything else 1) and was wrong in both directions — installer-migration-
|
|
8
|
+
// authoring.test.cjs scored 12x but runs ~0.1s, while the two heaviest files in
|
|
9
|
+
// the suite (run-tests-harness.test.cjs and release-tarball-smoke.install
|
|
10
|
+
// .test.cjs) both scored 1. This script replaces the guess with measurement.
|
|
11
|
+
//
|
|
12
|
+
// Input is one or more node:test reporter event streams as emitted by
|
|
13
|
+
// `gsd-test` (`~/.local/state/gsd-test/runs/<run-id>/test-events-<os>-node<v>
|
|
14
|
+
// .jsonl`). Each stream carries one `test:summary` event per test FILE, whose
|
|
15
|
+
// `data.duration_ms` is that file's total wall-clock and whose `data.file` is
|
|
16
|
+
// its absolute in-container path.
|
|
17
|
+
//
|
|
18
|
+
// Usage:
|
|
19
|
+
// node scripts/gen-test-timings.cjs <events.jsonl> [<events.jsonl> ...]
|
|
20
|
+
// node scripts/gen-test-timings.cjs ~/.local/state/gsd-test/runs/*/test-events-*.jsonl
|
|
21
|
+
// node scripts/gen-test-timings.cjs events.jsonl --out tests/test-timings.json
|
|
22
|
+
//
|
|
23
|
+
// When several streams are supplied (multiple lanes, e.g. node22 + node24), a
|
|
24
|
+
// file's recorded time is the MAX across them, not the mean: the packer exists
|
|
25
|
+
// to keep the SLOWEST lane's slowest chunk away from the per-chunk timeout, so
|
|
26
|
+
// the conservative bound is the right one to balance against.
|
|
27
|
+
//
|
|
28
|
+
// The table is ADVISORY and deliberately un-gated — there is no `--check` mode
|
|
29
|
+
// and no CI lint that fails on staleness, because timing data legitimately
|
|
30
|
+
// varies run to run. A file missing from the table falls back to the table's
|
|
31
|
+
// median weight, so a stale table degrades chunk BALANCE gracefully instead of
|
|
32
|
+
// failing the build. Regenerate it when the suite's cost profile has visibly
|
|
33
|
+
// drifted, not on a schedule.
|
|
34
|
+
'use strict';
|
|
35
|
+
|
|
36
|
+
const fs = require('fs');
|
|
37
|
+
const { basename, dirname, join } = require('path');
|
|
38
|
+
const { ExitError, runMain } = require('./lib/cli-exit.cjs');
|
|
39
|
+
|
|
40
|
+
const DEFAULT_OUT = join(__dirname, '..', 'tests', 'test-timings.json');
|
|
41
|
+
const SCHEMA_VERSION = 1;
|
|
42
|
+
|
|
43
|
+
function parseArgs(argv) {
|
|
44
|
+
const inputs = [];
|
|
45
|
+
let out = DEFAULT_OUT;
|
|
46
|
+
for (let i = 0; i < argv.length; i++) {
|
|
47
|
+
const arg = argv[i];
|
|
48
|
+
if (arg === '--out') {
|
|
49
|
+
const value = argv[++i];
|
|
50
|
+
if (!value) return { error: '--out requires a path' };
|
|
51
|
+
out = value;
|
|
52
|
+
} else if (arg.startsWith('--out=')) {
|
|
53
|
+
const value = arg.slice('--out='.length);
|
|
54
|
+
if (!value) return { error: '--out requires a path' };
|
|
55
|
+
out = value;
|
|
56
|
+
} else if (arg.startsWith('-')) {
|
|
57
|
+
return { error: `unknown flag "${arg}"` };
|
|
58
|
+
} else {
|
|
59
|
+
inputs.push(arg);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (inputs.length === 0) {
|
|
63
|
+
return { error: 'usage: gen-test-timings.cjs <reporter-events.jsonl> [...] [--out <path>]' };
|
|
64
|
+
}
|
|
65
|
+
return { inputs, out };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Fold one reporter event stream into `acc`, keeping the MAX duration seen for
|
|
69
|
+
// each test file. Returns per-stream counters plus any basename collisions
|
|
70
|
+
// found WITHIN this stream.
|
|
71
|
+
//
|
|
72
|
+
// Keying is by BASENAME, matching how run-tests.cjs weights a selected file:
|
|
73
|
+
// the reporter reports absolute in-container paths (/work/tests/foo.test.cjs)
|
|
74
|
+
// while the harness carries paths relative to its test dir, so the basename is
|
|
75
|
+
// the only stable join key between the two. A basename seen in two different
|
|
76
|
+
// directories would make the table ambiguous, so it must fail loudly.
|
|
77
|
+
//
|
|
78
|
+
// Collision detection is scoped to a SINGLE stream deliberately. Every lane
|
|
79
|
+
// writes its own stream under its own container root (`/work/tests` on Linux,
|
|
80
|
+
// `C:/work/tests` on Windows), so comparing directories ACROSS streams reports
|
|
81
|
+
// every shared basename as a collision — which is the script's own documented
|
|
82
|
+
// usage (globbing `test-events-*.jsonl` across lanes). Within one stream the
|
|
83
|
+
// root is constant, so a differing directory is a real collision.
|
|
84
|
+
function foldStream(text, acc) {
|
|
85
|
+
const dirsByBase = new Map();
|
|
86
|
+
let files = 0;
|
|
87
|
+
let malformed = 0;
|
|
88
|
+
for (const line of text.split('\n')) {
|
|
89
|
+
if (line.trim() === '') continue;
|
|
90
|
+
let event;
|
|
91
|
+
try {
|
|
92
|
+
event = JSON.parse(line);
|
|
93
|
+
} catch {
|
|
94
|
+
malformed++;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (!event || event.type !== 'test:summary') continue;
|
|
98
|
+
const data = event.data;
|
|
99
|
+
if (!data || typeof data.file !== 'string') continue;
|
|
100
|
+
const ms = data.duration_ms;
|
|
101
|
+
if (typeof ms !== 'number' || !Number.isFinite(ms) || ms < 0) continue;
|
|
102
|
+
const path = data.file.replace(/\\/g, '/');
|
|
103
|
+
const base = basename(path);
|
|
104
|
+
if (!dirsByBase.has(base)) dirsByBase.set(base, new Set());
|
|
105
|
+
dirsByBase.get(base).add(dirname(path));
|
|
106
|
+
const prev = acc.get(base);
|
|
107
|
+
if (prev === undefined || ms > prev) acc.set(base, ms);
|
|
108
|
+
files++;
|
|
109
|
+
}
|
|
110
|
+
const collisions = [...dirsByBase.entries()]
|
|
111
|
+
.filter(([, dirs]) => dirs.size > 1)
|
|
112
|
+
.map(([base, dirs]) => `${base} (${[...dirs].sort().join(', ')})`);
|
|
113
|
+
return { files, malformed, collisions };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function main() {
|
|
117
|
+
const parsed = parseArgs(process.argv.slice(2));
|
|
118
|
+
if (parsed.error) throw new ExitError(2, `gen-test-timings: ${parsed.error}`);
|
|
119
|
+
|
|
120
|
+
const acc = new Map();
|
|
121
|
+
const allCollisions = new Set();
|
|
122
|
+
const sources = [];
|
|
123
|
+
for (const input of parsed.inputs) {
|
|
124
|
+
let text;
|
|
125
|
+
try {
|
|
126
|
+
text = fs.readFileSync(input, 'utf8');
|
|
127
|
+
} catch (err) {
|
|
128
|
+
throw new ExitError(2, `gen-test-timings: cannot read "${input}": ${err.message}`);
|
|
129
|
+
}
|
|
130
|
+
const { files, malformed, collisions } = foldStream(text, acc);
|
|
131
|
+
for (const c of collisions) allCollisions.add(c);
|
|
132
|
+
sources.push(basename(input));
|
|
133
|
+
console.error(
|
|
134
|
+
`gen-test-timings: ${basename(input)} — ${files} file summaries` +
|
|
135
|
+
(malformed > 0 ? `, ${malformed} unparseable lines skipped` : ''),
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (acc.size === 0) {
|
|
140
|
+
throw new ExitError(
|
|
141
|
+
2,
|
|
142
|
+
'gen-test-timings: no `test:summary` events with a file and duration_ms were found. ' +
|
|
143
|
+
'Check that the input is a node:test reporter event stream (test-events-<os>-node<v>.jsonl).',
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// A basename that resolves to two different directories within one lane makes
|
|
148
|
+
// the table ambiguous: run-tests.cjs joins on basename alone, so one file's
|
|
149
|
+
// measured cost would silently be applied to the other. Fail rather than emit
|
|
150
|
+
// a table that lies.
|
|
151
|
+
if (allCollisions.size > 0) {
|
|
152
|
+
throw new ExitError(
|
|
153
|
+
2,
|
|
154
|
+
`gen-test-timings: basename collision — the table cannot key on basename alone:\n ${[...allCollisions].sort().join('\n ')}`,
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Every key must be a plain test-file basename. This is a data-integrity
|
|
159
|
+
// check on a stream we do not control (the reporter emits whatever path the
|
|
160
|
+
// runner saw), and it structurally excludes a computed key like `__proto__`
|
|
161
|
+
// or `constructor` from being written into the table object below — the
|
|
162
|
+
// `js/prototype-polluting-assignment` shape, even though the value here is
|
|
163
|
+
// always a number and could not actually pollute.
|
|
164
|
+
const SAFE_BASENAME_RE = /^[A-Za-z0-9._-]+\.test\.cjs$/;
|
|
165
|
+
const rejected = [...acc.keys()].filter((base) => !SAFE_BASENAME_RE.test(base));
|
|
166
|
+
if (rejected.length > 0) {
|
|
167
|
+
throw new ExitError(
|
|
168
|
+
2,
|
|
169
|
+
`gen-test-timings: refusing to emit non-test-file keys: ${rejected.sort().join(', ')}`,
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Sorted keys keep the checked-in diff reviewable: a regeneration shows only
|
|
174
|
+
// the files whose cost actually moved, not a reshuffled object.
|
|
175
|
+
const timings = Object.create(null);
|
|
176
|
+
for (const base of [...acc.keys()].sort()) {
|
|
177
|
+
timings[base] = Math.round(acc.get(base));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const payload = {
|
|
181
|
+
schema_version: SCHEMA_VERSION,
|
|
182
|
+
generated_by: 'scripts/gen-test-timings.cjs',
|
|
183
|
+
unit: 'ms',
|
|
184
|
+
sources: sources.sort(),
|
|
185
|
+
file_count: acc.size,
|
|
186
|
+
timings,
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
fs.writeFileSync(parsed.out, `${JSON.stringify(payload, null, 2)}\n`, 'utf8');
|
|
190
|
+
const totalMs = [...acc.values()].reduce((sum, ms) => sum + ms, 0);
|
|
191
|
+
console.error(
|
|
192
|
+
`gen-test-timings: wrote ${parsed.out} — ${acc.size} files, ${(totalMs / 1000).toFixed(1)}s total`,
|
|
193
|
+
);
|
|
194
|
+
return 0;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (require.main === module) {
|
|
198
|
+
runMain(main);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
module.exports = { parseArgs, foldStream };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* lint-portable-timeout.cjs — ban hardcoded GNU-`timeout` in gsd
|
|
6
|
+
* workflow / agent / reference / command markdown (#2351).
|
|
7
|
+
*
|
|
8
|
+
* ## Why
|
|
9
|
+
*
|
|
10
|
+
* `timeout` and `gtimeout` are GNU coreutils. Stock macOS ships NEITHER
|
|
11
|
+
* (`brew install coreutils` only provides `gtimeout`, and only if installed).
|
|
12
|
+
* A hardcoded `timeout <n> <cmd>` inside an executable workflow snippet exits
|
|
13
|
+
* 127 ("command not found") on such a host, and the gate that runs it — which
|
|
14
|
+
* only distinguishes 0 (pass) / 124 (timeout) / other (fail) — misreports a
|
|
15
|
+
* perfectly good build or test command as a FAILURE (#2351).
|
|
16
|
+
*
|
|
17
|
+
* The portable, coreutils-independent replacement is the
|
|
18
|
+
* `gsd_run run-with-timeout <secs> [--] <cmd…>` verb (gsd-core/bin/gsd-tools.cjs):
|
|
19
|
+
* a Node-based wall-clock cap that keeps GNU `timeout`'s exit-code contract
|
|
20
|
+
* (124 on timeout) on every platform. The resolution lives there ONCE and is
|
|
21
|
+
* reused by every call site instead of a per-file `command -v timeout` probe.
|
|
22
|
+
*
|
|
23
|
+
* This ratchet fails the build if a NEW bare `timeout`/`gtimeout` execution
|
|
24
|
+
* slips into any of these surfaces.
|
|
25
|
+
*
|
|
26
|
+
* ## What PASSES
|
|
27
|
+
*
|
|
28
|
+
* - `gsd_run run-with-timeout 300 -- bash -c "$CMD"` — the approved verb.
|
|
29
|
+
* - `command -v timeout` / `command -v gtimeout` / `which timeout` capability
|
|
30
|
+
* PROBES — portable: they detect the binary, they do not unconditionally
|
|
31
|
+
* execute it (see gsd-core/workflows/review.md's `_AGY_KILLER` fallback).
|
|
32
|
+
* - Prose ("timed out after 5 minutes"), config keys
|
|
33
|
+
* (`workflow.test_gate_timeout`), CI `timeout-minutes:`, the agy
|
|
34
|
+
* `--print-timeout` flag, `$TIMEOUT`-style variable names — none of which is
|
|
35
|
+
* a bare timeout command invocation.
|
|
36
|
+
*
|
|
37
|
+
* ## What FAILS
|
|
38
|
+
*
|
|
39
|
+
* A bare `timeout <duration> …` / `gtimeout <duration> …` command invocation,
|
|
40
|
+
* where `<duration>` is a number, a `"$VAR"`, or a `${VAR}` (optionally with a
|
|
41
|
+
* leading `-k`/`-s` option).
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
const fs = require('fs');
|
|
45
|
+
const path = require('path');
|
|
46
|
+
const { ExitError, runMain } = require('./lib/cli-exit.cjs');
|
|
47
|
+
|
|
48
|
+
const ROOT = path.join(__dirname, '..');
|
|
49
|
+
|
|
50
|
+
// Surfaces whose markdown carries agent-executed bash. Kept broad so the guard
|
|
51
|
+
// catches a regression anywhere a workflow snippet could bound a command.
|
|
52
|
+
const DEFAULT_ROOTS = ['gsd-core/workflows', 'gsd-core/references', 'agents', 'commands'];
|
|
53
|
+
|
|
54
|
+
// Capability probes to strip BEFORE testing for an invocation, so a portable
|
|
55
|
+
// `command -v timeout` on the same line is never mistaken for a bare execution.
|
|
56
|
+
const PROBE_RE = /command\s+-v\s+g?timeout|which\s+g?timeout/g;
|
|
57
|
+
|
|
58
|
+
// A `timeout`/`gtimeout` token INVOKED AS A COMMAND with a duration argument.
|
|
59
|
+
// Anchored to a command position — line start or right after `| & ; ( ` {` — so
|
|
60
|
+
// prose ("increase the timeout 30 seconds") and the `--print-timeout` flag / the
|
|
61
|
+
// approved `run-with-timeout` verb (no separator before "timeout") never match.
|
|
62
|
+
// Between the token and the duration, allow any number of leading options in
|
|
63
|
+
// short OR long form (`-k5`, `-k 5`, `--kill-after=5`, `--foreground`,
|
|
64
|
+
// `--signal=KILL`). The duration is a digit, `$((arith))`, a `$VAR`, or `${VAR}`.
|
|
65
|
+
const EXEC_RE = /(?:^|[|&;(`{])[ \t]*g?timeout[ \t]+(?:-{1,2}[\w-]+(?:=\S+)?[ \t]+)*["']?(?:\$\{?[A-Za-z_]|\$\(\(|\d)/;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Locate bare `timeout`/`gtimeout` invocations in a block of text.
|
|
69
|
+
*
|
|
70
|
+
* Pure (no I/O): callers pass the file contents; the caller reads files. Returns
|
|
71
|
+
* structured findings so tests assert on typed values, never on grepped text.
|
|
72
|
+
*
|
|
73
|
+
* @param {string} text file contents
|
|
74
|
+
* @returns {{ line: number, snippet: string }[]} findings (empty array = clean)
|
|
75
|
+
*/
|
|
76
|
+
function findRawTimeoutInvocations(text) {
|
|
77
|
+
const findings = [];
|
|
78
|
+
const lines = String(text).split(/\r?\n/);
|
|
79
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
80
|
+
const stripped = lines[i].replace(PROBE_RE, '');
|
|
81
|
+
if (EXEC_RE.test(stripped)) findings.push({ line: i + 1, snippet: lines[i].trim() });
|
|
82
|
+
}
|
|
83
|
+
return findings;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function walkMarkdown(dir) {
|
|
87
|
+
const out = [];
|
|
88
|
+
let entries;
|
|
89
|
+
try {
|
|
90
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
91
|
+
} catch {
|
|
92
|
+
return out; // a missing root is not an error — some surfaces are optional
|
|
93
|
+
}
|
|
94
|
+
for (const entry of entries) {
|
|
95
|
+
const full = path.join(dir, entry.name);
|
|
96
|
+
if (entry.isDirectory()) out.push(...walkMarkdown(full));
|
|
97
|
+
else if (entry.isFile() && entry.name.endsWith('.md')) out.push(full);
|
|
98
|
+
}
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Scan the given roots (repo-relative) for bare timeout invocations.
|
|
104
|
+
* @param {string[]} roots
|
|
105
|
+
* @returns {{ file: string, line: number, snippet: string }[]}
|
|
106
|
+
*/
|
|
107
|
+
function scan(roots = DEFAULT_ROOTS) {
|
|
108
|
+
const offenders = [];
|
|
109
|
+
for (const rel of roots) {
|
|
110
|
+
const abs = path.isAbsolute(rel) ? rel : path.join(ROOT, rel);
|
|
111
|
+
for (const file of walkMarkdown(abs)) {
|
|
112
|
+
const findings = findRawTimeoutInvocations(fs.readFileSync(file, 'utf8'));
|
|
113
|
+
for (const f of findings) {
|
|
114
|
+
offenders.push({ file: path.relative(ROOT, file), line: f.line, snippet: f.snippet });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return offenders;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function main() {
|
|
122
|
+
const rootsEnv = process.env.GSD_LINT_PORTABLE_TIMEOUT_ROOTS;
|
|
123
|
+
const roots = rootsEnv ? rootsEnv.split(path.delimiter).filter(Boolean) : DEFAULT_ROOTS;
|
|
124
|
+
const offenders = scan(roots);
|
|
125
|
+
if (offenders.length > 0) {
|
|
126
|
+
const detail = offenders.map((o) => ` ${o.file}:${o.line} ${o.snippet}`).join('\n');
|
|
127
|
+
throw new ExitError(
|
|
128
|
+
1,
|
|
129
|
+
'lint-portable-timeout: hardcoded `timeout`/`gtimeout` is not portable — stock\n' +
|
|
130
|
+
'macOS ships no coreutils, so these exit 127 and misreport a passing command as a\n' +
|
|
131
|
+
'failure. Use `gsd_run run-with-timeout <secs> [--] <cmd…>` instead (#2351):\n' +
|
|
132
|
+
detail,
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
console.log(`ok lint-portable-timeout: no hardcoded timeout invocations in ${roots.length} root(s)`);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
module.exports = { findRawTimeoutInvocations, scan, DEFAULT_ROOTS };
|
|
139
|
+
|
|
140
|
+
if (require.main === module) runMain(main);
|
|
@@ -47,16 +47,23 @@ const os = require('os');
|
|
|
47
47
|
const path = require('path');
|
|
48
48
|
const { PACKAGE_NAME } = require('../gsd-core/bin/lib/package-identity.cjs');
|
|
49
49
|
const { ExitError, runMain } = require('./lib/cli-exit.cjs');
|
|
50
|
-
// 120 s proved too tight
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
//
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
|
|
50
|
+
// 120 s proved too tight for cold-cache `npm install -g` of a 1499-file tarball:
|
|
51
|
+
// spawnSync fires SIGTERM at the deadline and returns { status: null, stdout: '',
|
|
52
|
+
// stderr: '' } (Node docs: status is null when a subprocess is terminated by a
|
|
53
|
+
// signal). The INSTALL_FAILED branch checks `status !== 0`, which null satisfies,
|
|
54
|
+
// so the test sees empty stdout/stderr and a spurious INSTALL_FAILED (surfaced as
|
|
55
|
+
// `installError: spawnSync npm ETIMEDOUT`).
|
|
56
|
+
//
|
|
57
|
+
// First observed on Windows GitHub-hosted runners, which are slower for
|
|
58
|
+
// filesystem-heavy work
|
|
59
|
+
// (https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories),
|
|
60
|
+
// then again on a slow Linux bench (cartographer: cold disk, constrained CPU) —
|
|
61
|
+
// the same failure the before() helper's SLOW_HOST_TIMEOUT already guards for
|
|
62
|
+
// pack+install. The slow-host reality is not platform-specific, so the ceiling is
|
|
63
|
+
// now uniform 600 s across all platforms AND shared with before() via this
|
|
64
|
+
// exported constant, so the two surfaces cannot diverge again. 600 s stays well
|
|
65
|
+
// clear of a real cold install (3–6 min) without masking a genuine hang.
|
|
66
|
+
const CHILD_TIMEOUT_MS = 600_000;
|
|
60
67
|
const QUIET_NPM_ENV = Object.freeze({
|
|
61
68
|
npm_config_loglevel: 'error',
|
|
62
69
|
npm_config_update_notifier: 'false',
|
|
@@ -628,7 +635,7 @@ function cleanup(...dirs) {
|
|
|
628
635
|
// Exports
|
|
629
636
|
// ---------------------------------------------------------------------------
|
|
630
637
|
|
|
631
|
-
module.exports = { SMOKE, runSmoke, binInvocation };
|
|
638
|
+
module.exports = { SMOKE, runSmoke, binInvocation, CHILD_TIMEOUT_MS };
|
|
632
639
|
|
|
633
640
|
if (require.main === module) {
|
|
634
641
|
runMain(cliMain);
|