opencode-agent-harness 0.0.0-stage → 0.2.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/CHANGELOG.md +23 -0
- package/LICENSE +21 -0
- package/README.md +590 -2
- package/bin/agent-harness.js +3059 -0
- package/contrib/global-plugins/README.md +49 -0
- package/contrib/global-plugins/harness-freshness.ts +355 -0
- package/package.json +48 -4
- package/templates/.agents/AGENTS.md +204 -0
- package/templates/.agents/features/INDEX.md +10 -0
- package/templates/.agents/handoffs/README.md +87 -0
- package/templates/.agents/memory/dev-loop.md +59 -0
- package/templates/.agents/memory/domain-map.md +29 -0
- package/templates/.agents/memory/environments.md +35 -0
- package/templates/.agents/memory/flow-map.md +23 -0
- package/templates/.agents/memory/history.md +7 -0
- package/templates/.agents/memory/locations.md +14 -0
- package/templates/.agents/memory/model-routing.md +261 -0
- package/templates/.agents/memory/orchestration.md +183 -0
- package/templates/.agents/memory/owned-files.md +19 -0
- package/templates/.agents/memory/product-principles.md +37 -0
- package/templates/.agents/memory/quality-parameters.md +37 -0
- package/templates/.agents/memory/stack-versions.md +35 -0
- package/templates/.agents/memory/test-design-parameters.md +36 -0
- package/templates/.agents/nightly.json +17 -0
- package/templates/.agents/qa-plans/README.md +70 -0
- package/templates/.agents/qa-runs/README.md +21 -0
- package/templates/.agents/reviews/README.md +47 -0
- package/templates/.agents/rules/00-operating.md +199 -0
- package/templates/.agents/skills/data-engineer/SKILL.md +31 -0
- package/templates/.agents/skills/devops-engineer/SKILL.md +50 -0
- package/templates/.agents/skills/diagnostics-expert/SKILL.md +44 -0
- package/templates/.agents/skills/docs/SKILL.md +140 -0
- package/templates/.agents/skills/features/SKILL.md +187 -0
- package/templates/.agents/skills/frontend-engineer/SKILL.md +81 -0
- package/templates/.agents/skills/handoff/SKILL.md +85 -0
- package/templates/.agents/skills/mobile-engineer/SKILL.md +101 -0
- package/templates/.agents/skills/planner/SKILL.md +112 -0
- package/templates/.agents/skills/product-manager/SKILL.md +115 -0
- package/templates/.agents/skills/qa-architect/SKILL.md +224 -0
- package/templates/.agents/skills/qa-runner/SKILL.md +64 -0
- package/templates/.agents/skills/security-engineer/SKILL.md +53 -0
- package/templates/.agents/skills/system-architect/SKILL.md +42 -0
- package/templates/.agents/skills/ui-designer/SKILL.md +71 -0
- package/templates/.github/workflows/ci.yml +148 -0
- package/templates/.github/workflows/deploy-uat.yml +95 -0
- package/templates/.github/workflows/nightly.yml +83 -0
- package/templates/.github/workflows/uat-health.yml +41 -0
- package/templates/.husky/pre-push +23 -0
- package/templates/.ignore +28 -0
- package/templates/.opencode/agents/data-engineer.md +37 -0
- package/templates/.opencode/agents/devops-engineer.md +37 -0
- package/templates/.opencode/agents/diagnostics-expert.md +37 -0
- package/templates/.opencode/agents/docs.md +37 -0
- package/templates/.opencode/agents/features.md +21 -0
- package/templates/.opencode/agents/frontend-engineer.md +37 -0
- package/templates/.opencode/agents/handoff.md +21 -0
- package/templates/.opencode/agents/mobile-engineer.md +37 -0
- package/templates/.opencode/agents/planner.md +34 -0
- package/templates/.opencode/agents/product-manager.md +29 -0
- package/templates/.opencode/agents/qa-architect.md +27 -0
- package/templates/.opencode/agents/qa-runner.md +17 -0
- package/templates/.opencode/agents/security-engineer.md +37 -0
- package/templates/.opencode/agents/system-architect.md +37 -0
- package/templates/.opencode/agents/ui-designer.md +37 -0
- package/templates/.opencode/commands/board.md +15 -0
- package/templates/.opencode/commands/checkpoint.md +25 -0
- package/templates/.opencode/commands/feature.md +56 -0
- package/templates/.opencode/commands/finish.md +36 -0
- package/templates/.opencode/commands/next.md +49 -0
- package/templates/.opencode/commands/report.md +55 -0
- package/templates/.opencode/commands/resume.md +39 -0
- package/templates/.opencode/commands/switch-model.md +34 -0
- package/templates/.opencode/commands/tidy.md +49 -0
- package/templates/.opencode/plugins/backlog-notify.ts +57 -0
- package/templates/.opencode/plugins/backlog.ts +272 -0
- package/templates/.opencode/plugins/checkpoint.ts +160 -0
- package/templates/.opencode/plugins/context-guard.ts +1164 -0
- package/templates/.opencode/plugins/diff.ts +85 -0
- package/templates/.opencode/plugins/gates.ts +71 -0
- package/templates/.opencode/plugins/job-notify.ts +241 -0
- package/templates/.opencode/plugins/orient.ts +67 -0
- package/templates/.opencode/plugins/session.ts +89 -0
- package/templates/.opencode/plugins/wait.ts +101 -0
- package/templates/.opencode/plugins/where.ts +70 -0
- package/templates/.opencode/skills/bounded-explore/SKILL.md +38 -0
- package/templates/.opencode/skills/dev-loop/SKILL.md +87 -0
- package/templates/.vercelignore +16 -0
- package/templates/AGENTS.md +27 -0
- package/templates/BACKLOG.md +95 -0
- package/templates/docs/ci-cd-pipeline.md +81 -0
- package/templates/docs/gates.md +128 -0
- package/templates/docs/mcp-integrations.md +97 -0
- package/templates/docs/mobile-testing.md +555 -0
- package/templates/docs/nightly-testing.md +106 -0
- package/templates/docs/wsl-optimizations.md +290 -0
- package/templates/opencode.json +188 -0
- package/templates/scripts/agent-report.js +541 -0
- package/templates/scripts/agent-search.sh +117 -0
- package/templates/scripts/backlog.js +1864 -0
- package/templates/scripts/board-service.sh +207 -0
- package/templates/scripts/checkpoint.js +290 -0
- package/templates/scripts/finalize.js +277 -0
- package/templates/scripts/nightly.js +913 -0
- package/templates/scripts/orient.js +514 -0
- package/templates/scripts/qa/board-client.js +260 -0
- package/templates/scripts/qa/board-lib.js +96 -0
- package/templates/scripts/qa/board-sync.js +469 -0
- package/templates/scripts/qa/capacity-lib.js +916 -0
- package/templates/scripts/qa/check-backlog.js +427 -0
- package/templates/scripts/qa/check-capacity.js +85 -0
- package/templates/scripts/qa/check-ci-policy.js +164 -0
- package/templates/scripts/qa/check-concurrency.js +344 -0
- package/templates/scripts/qa/check-dispatch-config.js +296 -0
- package/templates/scripts/qa/check-docs.js +284 -0
- package/templates/scripts/qa/check-integrate.js +98 -0
- package/templates/scripts/qa/check-linger.js +160 -0
- package/templates/scripts/qa/check-prefix-stability.js +183 -0
- package/templates/scripts/qa/check-product.js +177 -0
- package/templates/scripts/qa/check-qa-plan.js +378 -0
- package/templates/scripts/qa/check-qa-scripts.js +85 -0
- package/templates/scripts/qa/check-quality.js +249 -0
- package/templates/scripts/qa/check-test-wiring.js +253 -0
- package/templates/scripts/qa/ci-triage.js +346 -0
- package/templates/scripts/qa/ci-usage-lib.js +185 -0
- package/templates/scripts/qa/ci-wait-lib.js +294 -0
- package/templates/scripts/qa/command-classifier.js +552 -0
- package/templates/scripts/qa/context-guard-core.js +1618 -0
- package/templates/scripts/qa/diff.js +174 -0
- package/templates/scripts/qa/feature-scaffold.js +224 -0
- package/templates/scripts/qa/fixtures/backlog.md +104 -0
- package/templates/scripts/qa/governance.js +174 -0
- package/templates/scripts/qa/hash-file.js +32 -0
- package/templates/scripts/qa/lease-lib.js +263 -0
- package/templates/scripts/qa/merge-backlog.js +324 -0
- package/templates/scripts/qa/mobile-e2e/analyze-timings.js +300 -0
- package/templates/scripts/qa/mobile-e2e/apk-cache.js +420 -0
- package/templates/scripts/qa/mobile-e2e/backend-build-cache.js +203 -0
- package/templates/scripts/qa/mobile-e2e/boot-emulator.sh +432 -0
- package/templates/scripts/qa/mobile-e2e/build-apk.sh +210 -0
- package/templates/scripts/qa/mobile-e2e/check-flows.js +453 -0
- package/templates/scripts/qa/mobile-e2e/config.yaml +18 -0
- package/templates/scripts/qa/mobile-e2e/device-down.sh +88 -0
- package/templates/scripts/qa/mobile-e2e/device-up.sh +258 -0
- package/templates/scripts/qa/mobile-e2e/ios-simulator-down.sh +72 -0
- package/templates/scripts/qa/mobile-e2e/ios-simulator-up.sh +153 -0
- package/templates/scripts/qa/mobile-e2e/job-events.js +181 -0
- package/templates/scripts/qa/mobile-e2e/prewarm.sh +56 -0
- package/templates/scripts/qa/mobile-e2e/run-detached.sh +222 -0
- package/templates/scripts/qa/mobile-e2e/run-maestro.js +1543 -0
- package/templates/scripts/qa/mobile-e2e/ui-dump.js +327 -0
- package/templates/scripts/qa/models.allowlist.txt +32 -0
- package/templates/scripts/qa/provider-stats.js +878 -0
- package/templates/scripts/qa/run-clean.js +83 -0
- package/templates/scripts/qa/run-gates.js +212 -0
- package/templates/scripts/qa/run-loop.js +220 -0
- package/templates/scripts/qa/session-recon.js +512 -0
- package/templates/scripts/qa/store-lib.js +324 -0
- package/templates/scripts/qa/tool-lib.js +134 -0
- package/templates/scripts/qa/where.js +214 -0
- package/templates/scripts/qa/wslconfig-merge.js +157 -0
- package/templates/scripts/serve.js +1328 -0
- package/templates/scripts/setup-nightly.sh +185 -0
- package/templates/scripts/setup-tmpfs.sh +374 -0
- package/templates/scripts/ship.js +586 -0
- package/templates/scripts/switch-reasoning-model.ps1 +101 -0
- package/templates/scripts/switch-reasoning-model.sh +104 -0
- package/templates/scripts/wait-for.js +342 -0
- package/templates/scripts/wsl-gpu.sh +180 -0
- package/templates/scripts/wsl-tune.sh +261 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* mobile E2E — Maestro timing analyzer (harness-owned).
|
|
6
|
+
*
|
|
7
|
+
* The full device matrix is a long sequence of Maestro commands whose cost is
|
|
8
|
+
* invisible in the runner's wall-clock report: a command that does real work and
|
|
9
|
+
* an *optional* assertion that silently waits out its full timeout look the same
|
|
10
|
+
* in a per-flow duration. The difference matters — on the 2026-10-02 26-journey
|
|
11
|
+
* run, optional waits that expired accounted for ~8.7 min of a 35.8 min matrix,
|
|
12
|
+
* and 7.4 min of that was a single `dashboard-profile-button` wait repeated 30x.
|
|
13
|
+
*
|
|
14
|
+
* This module parses the per-invocation `maestro.log` files under
|
|
15
|
+
* `~/.maestro/tests/<run>/` and reduces them to the numbers that drive
|
|
16
|
+
* optimization: per-command-kind latency, *leaf* command time (the sum minus
|
|
17
|
+
* the `runFlow` containers, which otherwise double-count their children), the
|
|
18
|
+
* per-tap phases (pre-tap hierarchy aim vs post-tap settle), and *dead waits*
|
|
19
|
+
* (an `(Optional)` command that ends WARNED, i.e. burned its whole timeout).
|
|
20
|
+
*
|
|
21
|
+
* Pure and dependency-free so the tests can require it. The CLI is read-only:
|
|
22
|
+
*
|
|
23
|
+
* node scripts/qa/mobile-e2e/analyze-timings.js [--prefix 2026-10-02_]
|
|
24
|
+
* node scripts/qa/mobile-e2e/analyze-timings.js --dir ~/.maestro/tests/2026-10-02_080659 --json
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
const fs = require("fs");
|
|
28
|
+
const os = require("os");
|
|
29
|
+
const path = require("path");
|
|
30
|
+
|
|
31
|
+
const LINE_RE =
|
|
32
|
+
/^(\d\d):(\d\d):(\d\d)\.(\d+)\s+\[ INFO\]\s+.*?:\s+(.*?)\s+(RUNNING|COMPLETED|WARNED|FAILED|SKIPPED)$/;
|
|
33
|
+
|
|
34
|
+
/** Seconds-since-midnight for a Maestro log timestamp. */
|
|
35
|
+
function toSeconds(h, m, s, frac) {
|
|
36
|
+
return Number(h) * 3600 + Number(m) * 60 + Number(s) + Number(`0.${frac}`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Coarse command kind used to group latency (keeps the output stable). */
|
|
40
|
+
function classify(command) {
|
|
41
|
+
const c = String(command || "").trim();
|
|
42
|
+
if (/^Run\b/.test(c)) return "runFlow";
|
|
43
|
+
if (/^Tap on\b/.test(c)) return "tapOn";
|
|
44
|
+
if (/^Assert that\b/.test(c)) return "assert";
|
|
45
|
+
if (/^Input text\b/.test(c)) return "inputText";
|
|
46
|
+
if (/^Erase (text|Text)\b/.test(c)) return "eraseText";
|
|
47
|
+
if (/^Hide Keyboard\b/.test(c)) return "hideKeyboard";
|
|
48
|
+
if (/^(Press key|Press back|Back)\b/.test(c)) return "pressKey";
|
|
49
|
+
if (/^(Scroll|Scrolling|Swiping|Swipe)\b/.test(c)) return "scroll";
|
|
50
|
+
if (/^Launch app\b/.test(c)) return "launchApp";
|
|
51
|
+
if (/^Open\b/.test(c)) return "openLink";
|
|
52
|
+
if (/^(Take screenshot|Wait|Toggle|Set|Define|Apply)/.test(c)) return "misc";
|
|
53
|
+
return "other";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Parse one `maestro.log` body into command spans. Commands nest (a `runFlow`
|
|
58
|
+
* container wraps its children), so starts are queued per command text and the
|
|
59
|
+
* oldest open run is closed by the next terminal line of the same text (FIFO).
|
|
60
|
+
*/
|
|
61
|
+
function parseLog(text) {
|
|
62
|
+
const spans = [];
|
|
63
|
+
const open = new Map();
|
|
64
|
+
for (const line of String(text || "").split(/\r?\n/)) {
|
|
65
|
+
const m = LINE_RE.exec(line);
|
|
66
|
+
if (!m) continue;
|
|
67
|
+
const at = toSeconds(m[1], m[2], m[3], m[4]);
|
|
68
|
+
const command = m[5].trim();
|
|
69
|
+
const state = m[6];
|
|
70
|
+
if (state === "RUNNING") {
|
|
71
|
+
if (!open.has(command)) open.set(command, []);
|
|
72
|
+
open.get(command).push(at);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const queue = open.get(command);
|
|
76
|
+
if (!queue || !queue.length) continue;
|
|
77
|
+
const start = queue.shift();
|
|
78
|
+
spans.push({ command, state, durationSec: Math.max(0, at - start) });
|
|
79
|
+
}
|
|
80
|
+
return spans;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Maestro's internal tap markers are plain `logger: message` lines (they do NOT
|
|
85
|
+
* end in RUNNING/COMPLETED, so `LINE_RE` ignores them). Capture the three that
|
|
86
|
+
* split a tap into its pre-tap hierarchy aim and its post-tap settle.
|
|
87
|
+
*/
|
|
88
|
+
const GENERIC_RE =
|
|
89
|
+
/^(\d\d):(\d\d):(\d\d)\.(\d+)\s+\[[^\]]*\]\s+.*?:\s+(.*?)\s*$/;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Pair the internal tap markers with the enclosing `Tap on …` command span to
|
|
93
|
+
* derive the two phases that dominate a tap's cost:
|
|
94
|
+
* aim = command RUNNING -> "Tap aimed via settled hierarchy"
|
|
95
|
+
* settle = "Tapping at …" -> "Something has changed in the UI … Proceed."
|
|
96
|
+
* Returns arrays of seconds. Pure; every phase is clamped at >= 0.
|
|
97
|
+
*/
|
|
98
|
+
function parsePhases(text) {
|
|
99
|
+
const aim = [];
|
|
100
|
+
const settle = [];
|
|
101
|
+
let start = null;
|
|
102
|
+
let aimed = null;
|
|
103
|
+
let dispatched = null;
|
|
104
|
+
for (const line of String(text || "").split(/\r?\n/)) {
|
|
105
|
+
const m = GENERIC_RE.exec(line);
|
|
106
|
+
if (!m) continue;
|
|
107
|
+
const at = toSeconds(m[1], m[2], m[3], m[4]);
|
|
108
|
+
const msg = m[5];
|
|
109
|
+
if (/^Tap on\b/.test(msg) && /\sRUNNING$/.test(msg)) {
|
|
110
|
+
start = at;
|
|
111
|
+
aimed = null;
|
|
112
|
+
dispatched = null;
|
|
113
|
+
} else if (msg.includes("Tap aimed via settled hierarchy")) {
|
|
114
|
+
aimed = at;
|
|
115
|
+
} else if (msg.includes("Tapping at")) {
|
|
116
|
+
dispatched = at;
|
|
117
|
+
} else if (msg.includes("Something has changed in the UI")) {
|
|
118
|
+
if (start !== null && aimed !== null) aim.push(Math.max(0, aimed - start));
|
|
119
|
+
if (dispatched !== null) settle.push(Math.max(0, at - dispatched));
|
|
120
|
+
start = null;
|
|
121
|
+
aimed = null;
|
|
122
|
+
dispatched = null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return { aim, settle };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Reduce spans to per-kind latency + dead-wait totals + leaf time + tap phases. */
|
|
129
|
+
function summarise(spans, phases) {
|
|
130
|
+
const byKind = {};
|
|
131
|
+
const deadWaits = [];
|
|
132
|
+
let deadWaitMs = 0;
|
|
133
|
+
let totalMs = 0;
|
|
134
|
+
for (const span of Array.isArray(spans) ? spans : []) {
|
|
135
|
+
const kind = classify(span.command);
|
|
136
|
+
if (!byKind[kind]) byKind[kind] = { count: 0, totalMs: 0 };
|
|
137
|
+
byKind[kind].count += 1;
|
|
138
|
+
const ms = span.durationSec * 1000;
|
|
139
|
+
byKind[kind].totalMs += ms;
|
|
140
|
+
totalMs += ms;
|
|
141
|
+
if (span.state === "WARNED") {
|
|
142
|
+
deadWaitMs += ms;
|
|
143
|
+
deadWaits.push(span);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
deadWaits.sort((a, b) => b.durationSec - a.durationSec);
|
|
147
|
+
// `runFlow` is the only container command: the parsed spans nest, so a
|
|
148
|
+
// `runFlow` span already includes its children. Subtract the containers to get
|
|
149
|
+
// the non-overlapping leaf time (which the per-kind table otherwise inflates).
|
|
150
|
+
const runFlowMs = byKind.runFlow ? byKind.runFlow.totalMs : 0;
|
|
151
|
+
const leafMs = Math.max(0, totalMs - runFlowMs);
|
|
152
|
+
const tapPhases = phases && Array.isArray(phases.aim)
|
|
153
|
+
? { aim: phases.aim.slice(), settle: (phases.settle || []).slice() }
|
|
154
|
+
: { aim: [], settle: [] };
|
|
155
|
+
return {
|
|
156
|
+
byKind,
|
|
157
|
+
deadWaits,
|
|
158
|
+
deadWaitMs,
|
|
159
|
+
totalMs,
|
|
160
|
+
leafMs,
|
|
161
|
+
spanCount: spans.length,
|
|
162
|
+
tapPhases,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Read one `<dir>/maestro.log` and summarise it (empty result when absent). */
|
|
167
|
+
function analyseDir(dir) {
|
|
168
|
+
let text = "";
|
|
169
|
+
try {
|
|
170
|
+
text = fs.readFileSync(path.join(dir, "maestro.log"), "utf8");
|
|
171
|
+
} catch (_) {
|
|
172
|
+
text = "";
|
|
173
|
+
}
|
|
174
|
+
return summarise(parseLog(text), parsePhases(text));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Every immediate subdirectory of `base` whose name starts with `prefix`. */
|
|
178
|
+
function listRunDirs(base, prefix) {
|
|
179
|
+
let entries = [];
|
|
180
|
+
try {
|
|
181
|
+
entries = fs.readdirSync(base, { withFileTypes: true });
|
|
182
|
+
} catch (_) {
|
|
183
|
+
return [];
|
|
184
|
+
}
|
|
185
|
+
return entries
|
|
186
|
+
.filter((e) => e.isDirectory() && (!prefix || e.name.startsWith(prefix)))
|
|
187
|
+
.map((e) => path.join(base, e.name))
|
|
188
|
+
.sort();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Merge per-dir summaries into one across a whole run. */
|
|
192
|
+
function mergeSummaries(summaries) {
|
|
193
|
+
const byKind = {};
|
|
194
|
+
const deadWaits = [];
|
|
195
|
+
let deadWaitMs = 0;
|
|
196
|
+
let totalMs = 0;
|
|
197
|
+
let leafMs = 0;
|
|
198
|
+
let spanCount = 0;
|
|
199
|
+
const tapAim = [];
|
|
200
|
+
const tapSettle = [];
|
|
201
|
+
for (const s of Array.isArray(summaries) ? summaries : []) {
|
|
202
|
+
for (const [kind, v] of Object.entries(s.byKind || {})) {
|
|
203
|
+
if (!byKind[kind]) byKind[kind] = { count: 0, totalMs: 0 };
|
|
204
|
+
byKind[kind].count += v.count;
|
|
205
|
+
byKind[kind].totalMs += v.totalMs;
|
|
206
|
+
}
|
|
207
|
+
deadWaits.push(...(s.deadWaits || []));
|
|
208
|
+
deadWaitMs += s.deadWaitMs || 0;
|
|
209
|
+
totalMs += s.totalMs || 0;
|
|
210
|
+
leafMs += s.leafMs || 0;
|
|
211
|
+
spanCount += s.spanCount || 0;
|
|
212
|
+
if (s.tapPhases) {
|
|
213
|
+
tapAim.push(...(s.tapPhases.aim || []));
|
|
214
|
+
tapSettle.push(...(s.tapPhases.settle || []));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
deadWaits.sort((a, b) => b.durationSec - a.durationSec);
|
|
218
|
+
return {
|
|
219
|
+
byKind,
|
|
220
|
+
deadWaits,
|
|
221
|
+
deadWaitMs,
|
|
222
|
+
totalMs,
|
|
223
|
+
leafMs,
|
|
224
|
+
spanCount,
|
|
225
|
+
runs: summaries.length,
|
|
226
|
+
tapPhases: { aim: tapAim, settle: tapSettle },
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function fmtSec(ms) {
|
|
231
|
+
return `${(ms / 1000).toFixed(1)}s`;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function mean(list) {
|
|
235
|
+
const a = Array.isArray(list) ? list : [];
|
|
236
|
+
return a.length ? a.reduce((x, y) => x + y, 0) / a.length : 0;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function p90(list) {
|
|
240
|
+
const a = (Array.isArray(list) ? list : []).slice().sort((x, y) => x - y);
|
|
241
|
+
if (!a.length) return 0;
|
|
242
|
+
return a[Math.min(a.length - 1, Math.floor(a.length * 0.9))];
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function main() {
|
|
246
|
+
const argv = process.argv.slice(2);
|
|
247
|
+
const dirs = [];
|
|
248
|
+
const prefixIdx = argv.indexOf("--prefix");
|
|
249
|
+
const dirIdx = argv.indexOf("--dir");
|
|
250
|
+
const json = argv.includes("--json");
|
|
251
|
+
let prefix = "";
|
|
252
|
+
if (prefixIdx >= 0) prefix = argv[prefixIdx + 1] || "";
|
|
253
|
+
if (dirIdx >= 0) {
|
|
254
|
+
for (let i = dirIdx; i < argv.length; i += 1) {
|
|
255
|
+
if (argv[i] === "--dir" && argv[i + 1]) dirs.push(argv[i + 1]);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const base = path.join(os.homedir(), ".maestro", "tests");
|
|
259
|
+
const targets = dirs.length ? dirs : listRunDirs(base, prefix);
|
|
260
|
+
const summary = mergeSummaries(targets.map(analyseDir));
|
|
261
|
+
|
|
262
|
+
if (json) {
|
|
263
|
+
console.log(JSON.stringify({ dirs: targets, ...summary }, null, 2));
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
console.log(`Maestro timing — ${targets.length} invocation(s)`);
|
|
267
|
+
console.log(` accounted command time: ${(summary.totalMs / 60000).toFixed(1)} min (${summary.spanCount} commands)`);
|
|
268
|
+
console.log(` leaf command time: ${(summary.leafMs / 60000).toFixed(1)} min (accounted minus runFlow containers)`);
|
|
269
|
+
console.log(` dead waits (optional timeouts that expired): ${(summary.deadWaitMs / 60000).toFixed(1)} min`);
|
|
270
|
+
const tp = summary.tapPhases || { aim: [], settle: [] };
|
|
271
|
+
if (tp.aim.length || tp.settle.length) {
|
|
272
|
+
console.log(
|
|
273
|
+
` tap phases: aim avg=${fmtSec(mean(tp.aim) * 1000)} p90=${fmtSec(p90(tp.aim) * 1000)} (n=${tp.aim.length})` +
|
|
274
|
+
` · settle avg=${fmtSec(mean(tp.settle) * 1000)} p90=${fmtSec(p90(tp.settle) * 1000)} (n=${tp.settle.length})`
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
console.log(" by kind:");
|
|
278
|
+
for (const [kind, v] of Object.entries(summary.byKind).sort((a, b) => b[1].totalMs - a[1].totalMs)) {
|
|
279
|
+
console.log(` ${kind.padEnd(13)} n=${String(v.count).padStart(4)} ${(v.totalMs / 60000).toFixed(2).padStart(6)} min avg=${fmtSec(v.totalMs / Math.max(v.count, 1))}`);
|
|
280
|
+
}
|
|
281
|
+
if (summary.deadWaits.length) {
|
|
282
|
+
console.log(" top dead waits:");
|
|
283
|
+
for (const w of summary.deadWaits.slice(0, 12)) {
|
|
284
|
+
console.log(` ${fmtSec(w.durationSec * 1000).padStart(8)} ${w.command.slice(0, 80)}`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (require.main === module) main();
|
|
290
|
+
|
|
291
|
+
module.exports = {
|
|
292
|
+
classify,
|
|
293
|
+
parseLog,
|
|
294
|
+
parsePhases,
|
|
295
|
+
summarise,
|
|
296
|
+
analyseDir,
|
|
297
|
+
listRunDirs,
|
|
298
|
+
mergeSummaries,
|
|
299
|
+
toSeconds,
|
|
300
|
+
};
|