@tekyzinc/gsd-t 3.29.11 → 4.0.12

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.
Files changed (108) hide show
  1. package/CHANGELOG.md +146 -0
  2. package/bin/gsd-t-parallel.cjs +64 -13
  3. package/bin/gsd-t.js +48 -376
  4. package/bin/journey-coverage.cjs +6 -3
  5. package/bin/parallel-cli.cjs +13 -1
  6. package/commands/gsd-t-debug.md +47 -533
  7. package/commands/gsd-t-design-decompose.md +24 -497
  8. package/commands/gsd-t-doc-ripple.md +23 -139
  9. package/commands/gsd-t-execute.md +41 -958
  10. package/commands/gsd-t-help.md +0 -2
  11. package/commands/gsd-t-impact.md +26 -295
  12. package/commands/gsd-t-integrate.md +44 -369
  13. package/commands/gsd-t-milestone.md +25 -124
  14. package/commands/gsd-t-partition.md +28 -539
  15. package/commands/gsd-t-plan.md +26 -472
  16. package/commands/gsd-t-prd.md +25 -311
  17. package/commands/gsd-t-quick.md +1 -1
  18. package/commands/gsd-t-resume.md +0 -33
  19. package/commands/gsd-t-verify.md +52 -569
  20. package/commands/gsd-t-wave.md +41 -430
  21. package/package.json +1 -1
  22. package/scripts/gsd-t-calibration-hook.js +3 -1
  23. package/scripts/hooks/pre-commit-journey-coverage +0 -2
  24. package/scripts/hooks/pre-commit-playwright-gate +0 -2
  25. package/templates/CLAUDE-global.md +43 -173
  26. package/templates/CLAUDE-project.md +118 -104
  27. package/templates/prompts/design-verify-subagent.md +3 -0
  28. package/templates/prompts/qa-subagent.md +3 -0
  29. package/templates/prompts/red-team-subagent.md +5 -2
  30. package/templates/workflows/_lib.js +176 -0
  31. package/templates/workflows/gsd-t-debug.workflow.js +86 -0
  32. package/templates/workflows/gsd-t-execute.workflow.js +206 -0
  33. package/templates/workflows/gsd-t-integrate.workflow.js +71 -0
  34. package/templates/workflows/gsd-t-phase.workflow.js +94 -0
  35. package/templates/workflows/gsd-t-quick.workflow.js +72 -0
  36. package/templates/workflows/gsd-t-verify.workflow.js +348 -0
  37. package/templates/workflows/gsd-t-wave.workflow.js +43 -0
  38. package/bin/check-headless-sessions.js +0 -140
  39. package/bin/context-budget-audit.cjs +0 -447
  40. package/bin/context-meter-config.cjs +0 -101
  41. package/bin/context-meter-config.test.cjs +0 -101
  42. package/bin/event-stream.cjs +0 -205
  43. package/bin/gsd-t-benchmark-orchestrator.js +0 -437
  44. package/bin/gsd-t-capture-lint.cjs +0 -440
  45. package/bin/gsd-t-economics.cjs +0 -315
  46. package/bin/gsd-t-in-session-usage.cjs +0 -213
  47. package/bin/gsd-t-orchestrator-config.cjs +0 -161
  48. package/bin/gsd-t-orchestrator-queue.cjs +0 -180
  49. package/bin/gsd-t-orchestrator-recover.cjs +0 -231
  50. package/bin/gsd-t-orchestrator-worker.cjs +0 -219
  51. package/bin/gsd-t-orchestrator.js +0 -535
  52. package/bin/gsd-t-parallel-probe.cjs +0 -132
  53. package/bin/gsd-t-ratelimit-probe-worker.cjs +0 -237
  54. package/bin/gsd-t-ratelimit-probe.cjs +0 -648
  55. package/bin/gsd-t-report-tokens.cjs +0 -549
  56. package/bin/gsd-t-stream-feed-client.cjs +0 -151
  57. package/bin/gsd-t-token-backfill.cjs +0 -366
  58. package/bin/gsd-t-token-capture.cjs +0 -321
  59. package/bin/gsd-t-token-dashboard.cjs +0 -353
  60. package/bin/gsd-t-token-regenerate-log.cjs +0 -129
  61. package/bin/gsd-t-tool-attribution.cjs +0 -377
  62. package/bin/gsd-t-tool-cost.cjs +0 -195
  63. package/bin/gsd-t-transcript-tee.cjs +0 -246
  64. package/bin/gsd-t-unattended-heartbeat.cjs +0 -188
  65. package/bin/gsd-t-unattended-platform.cjs +0 -551
  66. package/bin/gsd-t-unattended-platform.js +0 -381
  67. package/bin/gsd-t-unattended-safety.cjs +0 -773
  68. package/bin/gsd-t-unattended-safety.js +0 -788
  69. package/bin/gsd-t-unattended.cjs +0 -2109
  70. package/bin/gsd-t-unattended.js +0 -1367
  71. package/bin/gsd-t-worker-dispatch.cjs +0 -211
  72. package/bin/handoff-lock.cjs +0 -249
  73. package/bin/handoff-lock.js +0 -249
  74. package/bin/headless-auto-spawn.cjs +0 -711
  75. package/bin/headless-auto-spawn.js +0 -373
  76. package/bin/headless-exit-codes.cjs +0 -67
  77. package/bin/live-activity-report.cjs +0 -615
  78. package/bin/log-tail.cjs +0 -81
  79. package/bin/m44-proof-measure.cjs +0 -285
  80. package/bin/m46-iter-proof.cjs +0 -149
  81. package/bin/m46-worker-proof.cjs +0 -201
  82. package/bin/m55-substrate-proof.cjs +0 -134
  83. package/bin/metrics-rollup.js +0 -200
  84. package/bin/model-windows.cjs +0 -99
  85. package/bin/model-windows.test.cjs +0 -75
  86. package/bin/parallelism-report.cjs +0 -535
  87. package/bin/runway-estimator.cjs +0 -242
  88. package/bin/spawn-plan-derive.cjs +0 -163
  89. package/bin/spawn-plan-status-updater.cjs +0 -292
  90. package/bin/spawn-plan-writer.cjs +0 -204
  91. package/bin/supervisor-pid-fingerprint.cjs +0 -126
  92. package/bin/token-budget.cjs +0 -265
  93. package/bin/unattended-watch-format.cjs +0 -178
  94. package/bin/watch-progress.js +0 -155
  95. package/commands/gsd-t-unattended-stop.md +0 -85
  96. package/commands/gsd-t-unattended-watch.md +0 -465
  97. package/commands/gsd-t-unattended.md +0 -476
  98. package/commands/gsd-t-visualize.md +0 -116
  99. package/scripts/gsd-t-context-meter.e2e.test.js +0 -364
  100. package/scripts/gsd-t-context-meter.js +0 -341
  101. package/scripts/gsd-t-context-meter.test.js +0 -471
  102. package/scripts/gsd-t-dashboard-server.js +0 -1203
  103. package/scripts/gsd-t-post-commit-spawn-plan.sh +0 -86
  104. package/scripts/gsd-t-transcript.html +0 -1821
  105. package/scripts/hooks/gsd-t-conversation-capture.js +0 -439
  106. package/scripts/hooks/gsd-t-in-session-usage-hook.js +0 -84
  107. package/scripts/spawn-plan-fmt-tokens.cjs +0 -80
  108. package/templates/hooks/post-commit-spawn-plan.sh +0 -85
@@ -1,285 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- /**
5
- * M44 Proof Measurement Driver (backlog #15 — T/2 criterion)
6
- *
7
- * Goal: prove v3.19.00's parallel dispatcher actually fans out concurrently.
8
- *
9
- * Method:
10
- * 1. Build a temp project with a 4-task file-disjoint tasks.md fixture.
11
- * 2. Inject a synthetic spawner into bin/gsd-t-parallel.cjs::runDispatch
12
- * that launches test/fixtures/m44-proof/worker-sim.js as a detached
13
- * child (same contract as the real autoSpawnHeadless).
14
- * 3. Measure:
15
- * T_seq = sum of per-worker durations when called sequentially.
16
- * T_par = wall-clock span from first spawn_started to last .done
17
- * marker when dispatched via runDispatch.
18
- * 4. Criterion: T_par ≤ T_seq / 2 ( = parallelism_factor ≥ 2 for N=4 )
19
- *
20
- * This proves the DISPATCHER. It does NOT prove that 4 Claude workers
21
- * produce correct code in T/2. That is a separate, API-budget-intensive
22
- * experiment (backlog #15 follow-up). The dispatcher is the shipped code
23
- * in v3.19.00, and its mechanics are what the tag certifies.
24
- */
25
-
26
- const fs = require('fs');
27
- const path = require('path');
28
- const os = require('os');
29
- const { spawn } = require('child_process');
30
-
31
- const { runDispatch } = require(path.join(__dirname, 'gsd-t-parallel.cjs'));
32
- const { writeSpawnPlan } = require(path.join(__dirname, 'spawn-plan-writer.cjs'));
33
- const { markTaskDone, markSpawnEnded } = require(path.join(__dirname, 'spawn-plan-status-updater.cjs'));
34
-
35
- // When invoked with --visualize, write spawn-plan files into the REAL project
36
- // directory (not the temp fixture dir) so the live dashboard at :7455 can
37
- // render the fan-out in real time. Off by default to keep the measurement
38
- // directory clean.
39
- const VISUALIZE = process.argv.includes('--visualize');
40
- const REAL_PROJECT_DIR = path.resolve(__dirname, '..');
41
-
42
- // ── fixture setup ───────────────────────────────────────────────────────────
43
-
44
- function buildFixtureProject(workDurationMs) {
45
- const root = fs.mkdtempSync(path.join(os.tmpdir(), 'm44-proof-'));
46
- fs.mkdirSync(path.join(root, '.gsd-t', 'domains', 'm99-d1-proof'), { recursive: true });
47
- fs.mkdirSync(path.join(root, '.gsd-t', 'spawns'), { recursive: true });
48
- fs.mkdirSync(path.join(root, '.gsd-t', 'events'), { recursive: true });
49
-
50
- const tasksMd = fs.readFileSync(
51
- path.join(__dirname, '..', 'test', 'fixtures', 'm44-proof', 'fixture.tasks.md'),
52
- 'utf8',
53
- );
54
- fs.writeFileSync(path.join(root, '.gsd-t', 'domains', 'm99-d1-proof', 'tasks.md'), tasksMd);
55
-
56
- const partitionMd = [
57
- '# Partition — M99',
58
- '',
59
- '## Wave 1',
60
- '- m99-d1-proof (all tasks disjoint, no deps)',
61
- '',
62
- ].join('\n');
63
- fs.writeFileSync(path.join(root, '.gsd-t', 'partition.md'), partitionMd);
64
-
65
- return root;
66
- }
67
-
68
- function cleanup(root) {
69
- try { fs.rmSync(root, { recursive: true, force: true }); } catch (_) { /* ignore */ }
70
- }
71
-
72
- // ── spawner (injected into runDispatch) ────────────────────────────────────
73
-
74
- function makeSpawner({ outDir, workerDurationMs }) {
75
- const launched = [];
76
- const spawner = ({ env }) => {
77
- const childEnv = Object.assign({}, process.env, env, {
78
- OUT_DIR: outDir,
79
- WORKER_DURATION_MS: String(workerDurationMs),
80
- });
81
- const workerPath = path.join(__dirname, '..', 'test', 'fixtures', 'm44-proof', 'worker-sim.js');
82
- const child = spawn(process.execPath, [workerPath], {
83
- env: childEnv, detached: true, stdio: 'ignore',
84
- });
85
- child.unref();
86
- const spawnId = 'm44-proof-' + env.GSD_T_WORKER_INDEX + '-' + Date.now();
87
- const taskIds = env.GSD_T_WORKER_TASK_IDS.split(',');
88
-
89
- if (VISUALIZE) {
90
- try {
91
- writeSpawnPlan({
92
- spawnId,
93
- kind: 'headless-detached',
94
- milestone: 'M99',
95
- wave: 'wave-1',
96
- domains: ['m99-d1-proof'],
97
- tasks: taskIds.map((id) => ({ id, title: 'Proof ' + id, status: 'in_flight' })),
98
- projectDir: REAL_PROJECT_DIR,
99
- });
100
- } catch (e) { process.stderr.write('[visualize] writeSpawnPlan failed: ' + e.message + '\n'); }
101
- }
102
-
103
- launched.push({
104
- spawnId, pid: child.pid,
105
- taskIds,
106
- launchedAt: process.hrtime.bigint(),
107
- });
108
- return { id: spawnId, pid: child.pid, logPath: null };
109
- };
110
- return { spawner, launched };
111
- }
112
-
113
- function markLaunchedDone(launched) {
114
- if (!VISUALIZE) return;
115
- for (const l of launched) {
116
- try {
117
- for (const id of l.taskIds) {
118
- markTaskDone({ spawnId: l.spawnId, taskId: id, projectDir: REAL_PROJECT_DIR, commit: 'proof-sim', tokens: null });
119
- }
120
- markSpawnEnded({ spawnId: l.spawnId, projectDir: REAL_PROJECT_DIR });
121
- } catch (e) { process.stderr.write('[visualize] mark-done failed: ' + e.message + '\n'); }
122
- }
123
- }
124
-
125
- // ── wait for all .done markers ─────────────────────────────────────────────
126
-
127
- async function waitForMarkers(outDir, expectedCount, timeoutMs = 60000) {
128
- const deadline = Date.now() + timeoutMs;
129
- while (Date.now() < deadline) {
130
- let present;
131
- try { present = fs.readdirSync(outDir).filter((n) => n.endsWith('.done')); }
132
- catch { present = []; }
133
- if (present.length >= expectedCount) return present;
134
- await new Promise((r) => setTimeout(r, 100));
135
- }
136
- throw new Error('timeout waiting for ' + expectedCount + ' .done markers in ' + outDir);
137
- }
138
-
139
- function readMarkers(outDir) {
140
- return fs.readdirSync(outDir)
141
- .filter((n) => n.endsWith('.done'))
142
- .map((n) => JSON.parse(fs.readFileSync(path.join(outDir, n), 'utf8')))
143
- .sort((a, b) => a.workerIndex - b.workerIndex);
144
- }
145
-
146
- // ── runs ────────────────────────────────────────────────────────────────────
147
-
148
- async function runParallelPass(workerDurationMs) {
149
- const projectDir = buildFixtureProject(workerDurationMs);
150
- const outDir = path.join(projectDir, 'worker-out');
151
- fs.mkdirSync(outDir, { recursive: true });
152
-
153
- const { spawner, launched } = makeSpawner({ outDir, workerDurationMs });
154
-
155
- const t0 = process.hrtime.bigint();
156
- const result = runDispatch({
157
- projectDir,
158
- command: 'gsd-t-execute',
159
- mode: 'unattended',
160
- env: { GSD_T_UNATTENDED: '1' },
161
- spawnHeadlessImpl: spawner,
162
- });
163
- const dispatchReturnedAt = process.hrtime.bigint();
164
-
165
- if (result.fanOutCount < 2) {
166
- cleanup(projectDir);
167
- throw new Error('parallel dispatch did not fan out (decision=' + result.decision + ', fanOutCount=' + result.fanOutCount + ')');
168
- }
169
-
170
- await waitForMarkers(outDir, result.fanOutCount);
171
- const t1 = process.hrtime.bigint();
172
-
173
- markLaunchedDone(launched);
174
-
175
- const markers = readMarkers(outDir);
176
- const wallClockMs = Number(t1 - t0) / 1e6;
177
- const dispatchOverheadMs = Number(dispatchReturnedAt - t0) / 1e6;
178
- const perWorkerDurationMs = markers.map((m) => m.durationMs);
179
- const sumWorkerDurationMs = perWorkerDurationMs.reduce((a, b) => a + b, 0);
180
-
181
- cleanup(projectDir);
182
- return {
183
- mode: 'parallel',
184
- fanOutCount: result.fanOutCount,
185
- launched: launched.length,
186
- wallClockMs,
187
- dispatchOverheadMs,
188
- perWorkerDurationMs,
189
- sumWorkerDurationMs,
190
- workerPids: markers.map((m) => m.pid),
191
- markers,
192
- };
193
- }
194
-
195
- async function runSequentialPass(workerDurationMs, taskCount = 4) {
196
- // Sequential baseline: run N workers back-to-back, same worker-sim.js.
197
- // This is what a single-worker supervisor would do before v3.19.00.
198
- const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'm44-proof-seq-'));
199
- const outDir = path.join(tmp, 'worker-out');
200
- fs.mkdirSync(outDir, { recursive: true });
201
-
202
- const t0 = process.hrtime.bigint();
203
- for (let i = 0; i < taskCount; i++) {
204
- await new Promise((resolve, reject) => {
205
- const child = spawn(process.execPath, [
206
- path.join(__dirname, '..', 'test', 'fixtures', 'm44-proof', 'worker-sim.js'),
207
- ], {
208
- env: Object.assign({}, process.env, {
209
- OUT_DIR: outDir,
210
- WORKER_DURATION_MS: String(workerDurationMs),
211
- GSD_T_WORKER_INDEX: String(i),
212
- GSD_T_WORKER_TOTAL: String(taskCount),
213
- GSD_T_WORKER_TASK_IDS: 'M99-D1-T' + (i + 1),
214
- }),
215
- stdio: 'ignore',
216
- });
217
- child.on('exit', (code) => code === 0 ? resolve() : reject(new Error('worker exit ' + code)));
218
- child.on('error', reject);
219
- });
220
- }
221
- const t1 = process.hrtime.bigint();
222
- const markers = readMarkers(outDir);
223
- const wallClockMs = Number(t1 - t0) / 1e6;
224
- cleanup(tmp);
225
-
226
- return {
227
- mode: 'sequential',
228
- taskCount,
229
- wallClockMs,
230
- perWorkerDurationMs: markers.map((m) => m.durationMs),
231
- sumWorkerDurationMs: markers.map((m) => m.durationMs).reduce((a, b) => a + b, 0),
232
- };
233
- }
234
-
235
- // ── main ────────────────────────────────────────────────────────────────────
236
-
237
- async function main() {
238
- const workerDurationMs = parseInt(process.env.WORKER_DURATION_MS || '8000', 10);
239
- process.stdout.write('M44 Proof Measurement (worker duration=' + workerDurationMs + 'ms)\n');
240
- process.stdout.write('─'.repeat(60) + '\n');
241
-
242
- const seq = await runSequentialPass(workerDurationMs);
243
- process.stdout.write('Sequential (N=4 workers run back-to-back)\n');
244
- process.stdout.write(' T_seq (wall-clock): ' + seq.wallClockMs.toFixed(1) + ' ms\n');
245
- process.stdout.write(' sum(worker durations): ' + seq.sumWorkerDurationMs.toFixed(1) + ' ms\n');
246
- process.stdout.write('\n');
247
-
248
- const par = await runParallelPass(workerDurationMs);
249
- process.stdout.write('Parallel (runDispatch, N=' + par.fanOutCount + ' concurrent workers)\n');
250
- process.stdout.write(' T_par (wall-clock): ' + par.wallClockMs.toFixed(1) + ' ms\n');
251
- process.stdout.write(' dispatch overhead: ' + par.dispatchOverheadMs.toFixed(1) + ' ms\n');
252
- process.stdout.write(' sum(worker durations): ' + par.sumWorkerDurationMs.toFixed(1) + ' ms\n');
253
- process.stdout.write(' per-worker durations: [' + par.perWorkerDurationMs.map((x) => x.toFixed(0)).join(', ') + '] ms\n');
254
- process.stdout.write(' worker pids: [' + par.workerPids.join(', ') + ']\n');
255
- process.stdout.write('\n');
256
-
257
- const ratio = par.wallClockMs / seq.wallClockMs;
258
- const speedup = seq.wallClockMs / par.wallClockMs;
259
- const parallelismFactor = par.sumWorkerDurationMs / par.wallClockMs;
260
- const criterion = par.wallClockMs <= seq.wallClockMs / 2;
261
-
262
- process.stdout.write('─'.repeat(60) + '\n');
263
- process.stdout.write('Result\n');
264
- process.stdout.write(' T_par / T_seq = ' + ratio.toFixed(3) + '\n');
265
- process.stdout.write(' speedup = ' + speedup.toFixed(2) + '×\n');
266
- process.stdout.write(' parallelism_factor = ' + parallelismFactor.toFixed(2) + ' (ideal = ' + par.fanOutCount + ')\n');
267
- process.stdout.write(' T/2 criterion = ' + (criterion ? 'MET ✓' : 'NOT MET ✗') + ' (T_par ≤ T_seq/2)\n');
268
-
269
- const report = {
270
- generatedAt: new Date().toISOString(),
271
- workerDurationMs,
272
- sequential: seq,
273
- parallel: par,
274
- ratio, speedup, parallelismFactor,
275
- criterionMet: criterion,
276
- };
277
- const reportPath = path.join(process.cwd(), '.gsd-t', 'm44-proof-report.json');
278
- fs.mkdirSync(path.dirname(reportPath), { recursive: true });
279
- fs.writeFileSync(reportPath, JSON.stringify(report, null, 2));
280
- process.stdout.write('\nReport written: ' + reportPath + '\n');
281
-
282
- process.exit(criterion ? 0 : 1);
283
- }
284
-
285
- main().catch((e) => { process.stderr.write('ERROR: ' + (e && e.stack || e) + '\n'); process.exit(2); });
@@ -1,149 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- /**
5
- * M46-D1 Iter-Parallel Proof Harness (T10)
6
- *
7
- * Measures the parallelism speedup of `_runIterParallel` vs. a serial
8
- * baseline using a synthetic 10-iter workload where each iter sleeps
9
- * 200ms and returns a successful IterResult.
10
- *
11
- * Method:
12
- * 1. Serial baseline (batchSize=1): run 10 iters one at a time via
13
- * `_runIterParallel(..., batchSize=1)` in a loop. Expect ~2000ms.
14
- * 2. Parallel (batchSize=4): run 10 iters in batches of 4+4+2 via the
15
- * same helper. Expect ~600ms (3 batches × 200ms).
16
- * 3. Compute speedup = T_serial / T_par,
17
- * parallelism_factor = (10 × 200) / T_par.
18
- * 4. Pass iff T_par/T_serial ≤ 0.35 AND speedup ≥ 3.0.
19
- *
20
- * Output: .gsd-t/metrics/m46-iter-proof.json + human summary on stdout.
21
- * Exit: 0 on pass, 1 on fail.
22
- */
23
-
24
- const fs = require('fs');
25
- const path = require('path');
26
-
27
- const ITER_COUNT = 10;
28
- const ITER_SLEEP_MS = 200;
29
- const BATCH_SERIAL = 1;
30
- const BATCH_PARALLEL = 4;
31
- const THRESHOLD_RATIO = 0.35;
32
- const THRESHOLD_SPEEDUP = 3.0;
33
-
34
- const { _runIterParallel } = require(path.join(__dirname, 'gsd-t-unattended.cjs')).__test__;
35
-
36
- // ── synthetic iterFn ───────────────────────────────────────────────────────
37
-
38
- let iterSeq = 0;
39
- function makeIterFn(sleepMs) {
40
- return async function fakeIter(_state, _opts) {
41
- const id = iterSeq++;
42
- await new Promise((r) => setTimeout(r, sleepMs));
43
- return {
44
- status: 'ok',
45
- tasksDone: ['t' + id],
46
- verifyNeeded: false,
47
- artifacts: [],
48
- };
49
- };
50
- }
51
-
52
- // ── runners ────────────────────────────────────────────────────────────────
53
-
54
- async function runSerial(total, sleepMs) {
55
- const iterFn = makeIterFn(sleepMs);
56
- const state = {};
57
- const opts = {};
58
- const t0 = process.hrtime.bigint();
59
- const results = [];
60
- for (let i = 0; i < total; i++) {
61
- const batch = await _runIterParallel(state, opts, iterFn, BATCH_SERIAL);
62
- results.push(...batch);
63
- }
64
- const t1 = process.hrtime.bigint();
65
- return {
66
- wallClockMs: Number(t1 - t0) / 1e6,
67
- results,
68
- };
69
- }
70
-
71
- async function runParallel(total, batchSize, sleepMs) {
72
- const iterFn = makeIterFn(sleepMs);
73
- const state = {};
74
- const opts = {};
75
- const t0 = process.hrtime.bigint();
76
- const results = [];
77
- let remaining = total;
78
- while (remaining > 0) {
79
- const n = Math.min(batchSize, remaining);
80
- const batch = await _runIterParallel(state, opts, iterFn, n);
81
- results.push(...batch);
82
- remaining -= n;
83
- }
84
- const t1 = process.hrtime.bigint();
85
- return {
86
- wallClockMs: Number(t1 - t0) / 1e6,
87
- results,
88
- };
89
- }
90
-
91
- // ── main ───────────────────────────────────────────────────────────────────
92
-
93
- async function main() {
94
- process.stdout.write(
95
- `M46-D1 Iter-Parallel Proof (N=${ITER_COUNT} iters, sleep=${ITER_SLEEP_MS}ms each)\n`,
96
- );
97
- process.stdout.write('─'.repeat(60) + '\n');
98
-
99
- iterSeq = 0;
100
- const serial = await runSerial(ITER_COUNT, ITER_SLEEP_MS);
101
- process.stdout.write(`Serial baseline (batchSize=${BATCH_SERIAL}, ${ITER_COUNT} iters sequentially)\n`);
102
- process.stdout.write(` T_serial (wall-clock): ${serial.wallClockMs.toFixed(1)} ms\n`);
103
- process.stdout.write(` results: ${serial.results.length} (ok=${serial.results.filter((r) => r.status === 'ok').length})\n\n`);
104
-
105
- iterSeq = 0;
106
- const parallel = await runParallel(ITER_COUNT, BATCH_PARALLEL, ITER_SLEEP_MS);
107
- process.stdout.write(`Parallel (batchSize=${BATCH_PARALLEL}, batches of 4+4+2)\n`);
108
- process.stdout.write(` T_par (wall-clock): ${parallel.wallClockMs.toFixed(1)} ms\n`);
109
- process.stdout.write(` results: ${parallel.results.length} (ok=${parallel.results.filter((r) => r.status === 'ok').length})\n\n`);
110
-
111
- const ratio = parallel.wallClockMs / serial.wallClockMs;
112
- const speedup = serial.wallClockMs / parallel.wallClockMs;
113
- const parallelismFactor = (ITER_COUNT * ITER_SLEEP_MS) / parallel.wallClockMs;
114
- const passed = ratio <= THRESHOLD_RATIO && speedup >= THRESHOLD_SPEEDUP;
115
-
116
- process.stdout.write('─'.repeat(60) + '\n');
117
- process.stdout.write('Result\n');
118
- process.stdout.write(` T_par / T_serial = ${ratio.toFixed(3)} (threshold ≤ ${THRESHOLD_RATIO})\n`);
119
- process.stdout.write(` speedup = ${speedup.toFixed(2)}× (threshold ≥ ${THRESHOLD_SPEEDUP})\n`);
120
- process.stdout.write(` parallelism_factor = ${parallelismFactor.toFixed(2)} (ideal ≈ ${BATCH_PARALLEL})\n`);
121
- process.stdout.write(` verdict = ${passed ? 'PASS ✓' : 'FAIL ✗'}\n`);
122
-
123
- const report = {
124
- timestamp: new Date().toISOString(),
125
- iter_count: ITER_COUNT,
126
- iter_sleep_ms: ITER_SLEEP_MS,
127
- batch_size_serial: BATCH_SERIAL,
128
- batch_size_parallel: BATCH_PARALLEL,
129
- T_serial_ms: serial.wallClockMs,
130
- T_par_ms: parallel.wallClockMs,
131
- speedup,
132
- parallelism_factor: parallelismFactor,
133
- threshold_T_par_over_T_serial: THRESHOLD_RATIO,
134
- threshold_speedup: THRESHOLD_SPEEDUP,
135
- passed,
136
- };
137
- const reportDir = path.join(process.cwd(), '.gsd-t', 'metrics');
138
- fs.mkdirSync(reportDir, { recursive: true });
139
- const reportPath = path.join(reportDir, 'm46-iter-proof.json');
140
- fs.writeFileSync(reportPath, JSON.stringify(report, null, 2));
141
- process.stdout.write(`\nReport written: ${reportPath}\n`);
142
-
143
- process.exit(passed ? 0 : 1);
144
- }
145
-
146
- main().catch((e) => {
147
- process.stderr.write(`ERROR: ${(e && e.stack) || e}\n`);
148
- process.exit(2);
149
- });
@@ -1,201 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- /**
5
- * M46-D2 Worker Sub-Dispatch Proof Harness (T7)
6
- *
7
- * Measures the parallelism speedup of `dispatchWorkerTasks` vs. a serial
8
- * baseline using a synthetic 6-task file-disjoint workload.
9
- *
10
- * Method:
11
- * 1. Serial baseline: run 6 `sleep 2 && echo done > …` tasks one by one
12
- * via `child_process.execSync`. Record `T_serial` (wall-clock ms).
13
- * 2. Parallel via `dispatchWorkerTasks`: stub the dispatcher's
14
- * `runDispatch` boundary (via a mocked `gsd-t-parallel.cjs` in
15
- * require.cache) to execute tasks concurrently with
16
- * `child_process.exec` + `Promise.all`. This measures the dispatch
17
- * SCHEDULER's fan-out behaviour, not real headless claude-p spawns.
18
- * 3. Compute speedup and parallelism_factor. Pass iff speedup ≥ 2.5.
19
- *
20
- * Output: .gsd-t/metrics/m46-worker-proof.json + human summary on stdout.
21
- * Exit: 0 on pass, 1 on fail.
22
- */
23
-
24
- const fs = require('fs');
25
- const os = require('os');
26
- const path = require('path');
27
- const { exec, execSync } = require('child_process');
28
-
29
- const THRESHOLD = 2.5;
30
- const TASK_COUNT = 6;
31
- const PID = process.pid;
32
- const TMP_DIR = path.join(os.tmpdir(), `m46-proof-${PID}`);
33
-
34
- function ensureTmpDir() {
35
- fs.mkdirSync(TMP_DIR, { recursive: true });
36
- }
37
-
38
- function cleanupTmpDir() {
39
- try { fs.rmSync(TMP_DIR, { recursive: true, force: true }); } catch (_) { /* ignore */ }
40
- }
41
-
42
- function buildTasks() {
43
- const tasks = [];
44
- for (let i = 0; i < TASK_COUNT; i++) {
45
- const outPath = path.join(TMP_DIR, `task-${i}.out`);
46
- tasks.push({
47
- taskId: `T-${i}`,
48
- files: [outPath],
49
- command: `sleep 2 && echo done > ${outPath}`,
50
- });
51
- }
52
- return tasks;
53
- }
54
-
55
- // ── serial baseline ────────────────────────────────────────────────────────
56
-
57
- function runSerial(tasks) {
58
- const perTaskMs = [];
59
- const t0 = process.hrtime.bigint();
60
- for (const task of tasks) {
61
- const ts = process.hrtime.bigint();
62
- execSync(task.command, { stdio: 'ignore' });
63
- const te = process.hrtime.bigint();
64
- perTaskMs.push(Number(te - ts) / 1e6);
65
- }
66
- const t1 = process.hrtime.bigint();
67
- return {
68
- wallClockMs: Number(t1 - t0) / 1e6,
69
- perTaskMs,
70
- meanTaskMs: perTaskMs.reduce((a, b) => a + b, 0) / perTaskMs.length,
71
- };
72
- }
73
-
74
- // ── parallel via stubbed runDispatch ──────────────────────────────────────
75
-
76
- function installParallelStub() {
77
- // Pre-populate require.cache for bin/gsd-t-parallel.cjs with a stub whose
78
- // `runDispatch` executes the task `command` field concurrently via exec +
79
- // Promise.all. This isolates measurement to the dispatcher scheduler and
80
- // avoids invoking real claude-p children.
81
- const parallelPath = require.resolve(path.join(__dirname, 'gsd-t-parallel.cjs'));
82
- const stubModule = {
83
- exports: {
84
- runDispatch: async ({ tasks }) => {
85
- const workerResults = await Promise.all(tasks.map((task) => new Promise((resolve) => {
86
- const started = Date.now();
87
- exec(task.command, (err) => {
88
- resolve({
89
- taskId: task.taskId,
90
- exitCode: err ? (err.code || 1) : 0,
91
- durationMs: Date.now() - started,
92
- });
93
- });
94
- })));
95
- return {
96
- decision: 'fan-out',
97
- fanOutCount: tasks.length,
98
- workerResults,
99
- };
100
- },
101
- },
102
- loaded: true,
103
- id: parallelPath,
104
- filename: parallelPath,
105
- paths: [],
106
- children: [],
107
- };
108
- require.cache[parallelPath] = stubModule;
109
- }
110
-
111
- async function runParallel(tasks) {
112
- installParallelStub();
113
- // Fresh require after stub install, in case worker-dispatch was pre-loaded.
114
- const dispatchPath = require.resolve(path.join(__dirname, 'gsd-t-worker-dispatch.cjs'));
115
- delete require.cache[dispatchPath];
116
- const { dispatchWorkerTasks } = require(dispatchPath);
117
-
118
- const t0 = process.hrtime.bigint();
119
- const result = await dispatchWorkerTasks({
120
- projectDir: TMP_DIR,
121
- parentSessionId: `m46-proof-${PID}`,
122
- tasks,
123
- maxParallel: TASK_COUNT,
124
- });
125
- const t1 = process.hrtime.bigint();
126
-
127
- return {
128
- wallClockMs: Number(t1 - t0) / 1e6,
129
- parallel: result.parallel,
130
- reason: result.reason,
131
- taskResults: result.taskResults,
132
- };
133
- }
134
-
135
- // ── main ────────────────────────────────────────────────────────────────────
136
-
137
- async function main() {
138
- ensureTmpDir();
139
- process.stdout.write(`M46-D2 Worker Sub-Dispatch Proof (N=${TASK_COUNT} tasks, tmp=${TMP_DIR})\n`);
140
- process.stdout.write('─'.repeat(60) + '\n');
141
-
142
- const tasks = buildTasks();
143
-
144
- const serial = runSerial(tasks);
145
- process.stdout.write('Serial baseline (execSync, tasks run back-to-back)\n');
146
- process.stdout.write(` T_serial (wall-clock): ${serial.wallClockMs.toFixed(1)} ms\n`);
147
- process.stdout.write(` per-task durations: [${serial.perTaskMs.map((x) => x.toFixed(0)).join(', ')}] ms\n`);
148
- process.stdout.write(` mean(task duration): ${serial.meanTaskMs.toFixed(1)} ms\n\n`);
149
-
150
- // Reset task output files before parallel run so exec doesn't race on
151
- // leftovers (each task writes its own file so this is just hygiene).
152
- for (let i = 0; i < TASK_COUNT; i++) {
153
- const p = path.join(TMP_DIR, `task-${i}.out`);
154
- try { fs.unlinkSync(p); } catch (_) { /* ignore */ }
155
- }
156
-
157
- const parallel = await runParallel(tasks);
158
- process.stdout.write(`Parallel via dispatchWorkerTasks (runDispatch stub, concurrent exec)\n`);
159
- process.stdout.write(` T_par (wall-clock): ${parallel.wallClockMs.toFixed(1)} ms\n`);
160
- process.stdout.write(` parallel dispatched: ${parallel.parallel} (reason=${parallel.reason})\n`);
161
- process.stdout.write(` per-task results: ${parallel.taskResults.length} tasks\n\n`);
162
-
163
- const speedup = serial.wallClockMs / parallel.wallClockMs;
164
- const parallelismFactor = (TASK_COUNT * serial.meanTaskMs) / parallel.wallClockMs;
165
- const passed = speedup >= THRESHOLD;
166
-
167
- process.stdout.write('─'.repeat(60) + '\n');
168
- process.stdout.write('Result\n');
169
- process.stdout.write(` speedup = ${speedup.toFixed(2)}× (threshold ≥ ${THRESHOLD})\n`);
170
- process.stdout.write(` parallelism_factor = ${parallelismFactor.toFixed(2)} (ideal = ${TASK_COUNT})\n`);
171
- process.stdout.write(` verdict = ${passed ? 'PASS ✓' : 'FAIL ✗'}\n`);
172
-
173
- const report = {
174
- timestamp: new Date().toISOString(),
175
- task_count: TASK_COUNT,
176
- T_serial_ms: serial.wallClockMs,
177
- T_par_ms: parallel.wallClockMs,
178
- speedup,
179
- parallelism_factor: parallelismFactor,
180
- threshold: THRESHOLD,
181
- passed,
182
- };
183
- const reportDir = path.join(process.cwd(), '.gsd-t', 'metrics');
184
- fs.mkdirSync(reportDir, { recursive: true });
185
- const reportPath = path.join(reportDir, 'm46-worker-proof.json');
186
- fs.writeFileSync(reportPath, JSON.stringify(report, null, 2));
187
- process.stdout.write(`\nReport written: ${reportPath}\n`);
188
-
189
- cleanupTmpDir();
190
- process.exit(passed ? 0 : 1);
191
- }
192
-
193
- process.on('exit', cleanupTmpDir);
194
- process.on('SIGINT', () => { cleanupTmpDir(); process.exit(130); });
195
- process.on('SIGTERM', () => { cleanupTmpDir(); process.exit(143); });
196
-
197
- main().catch((e) => {
198
- process.stderr.write(`ERROR: ${(e && e.stack) || e}\n`);
199
- cleanupTmpDir();
200
- process.exit(2);
201
- });