teamsmith 0.0.0-stage → 0.1.2
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/LICENSE +21 -0
- package/README.md +158 -2
- package/bin/team.mjs +59 -0
- package/install.sh +94 -0
- package/package.json +37 -4
- package/skills/teamsmith/CHANGELOG.md +763 -0
- package/skills/teamsmith/SKILL.md +312 -0
- package/skills/teamsmith/extension/team-bg.ts +435 -0
- package/skills/teamsmith/extension/team-inbox-watch.ts +1412 -0
- package/skills/teamsmith/extension/team-notify.ts +663 -0
- package/skills/teamsmith/references/agent-adapters.md +643 -0
- package/skills/teamsmith/references/config.md +477 -0
- package/skills/teamsmith/references/meeting.md +124 -0
- package/skills/teamsmith/references/memory.md +133 -0
- package/skills/teamsmith/references/migration.md +227 -0
- package/skills/teamsmith/references/openspec.md +222 -0
- package/skills/teamsmith/references/philosophy.md +95 -0
- package/skills/teamsmith/references/protocol.md +712 -0
- package/skills/teamsmith/references/troubleshooting.md +1384 -0
- package/skills/teamsmith/references/workflows.md +448 -0
- package/skills/teamsmith/scripts/lib/cmd-agents.sh +1709 -0
- package/skills/teamsmith/scripts/lib/cmd-bg.sh +284 -0
- package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +311 -0
- package/skills/teamsmith/scripts/lib/cmd-config.sh +1156 -0
- package/skills/teamsmith/scripts/lib/cmd-death.sh +562 -0
- package/skills/teamsmith/scripts/lib/cmd-docs.sh +149 -0
- package/skills/teamsmith/scripts/lib/cmd-draft.sh +124 -0
- package/skills/teamsmith/scripts/lib/cmd-init.sh +212 -0
- package/skills/teamsmith/scripts/lib/cmd-meeting.sh +904 -0
- package/skills/teamsmith/scripts/lib/cmd-outbox.sh +196 -0
- package/skills/teamsmith/scripts/lib/cmd-project.sh +642 -0
- package/skills/teamsmith/scripts/lib/cmd-review.sh +1393 -0
- package/skills/teamsmith/scripts/lib/cmd-status.sh +1399 -0
- package/skills/teamsmith/scripts/lib/cmd-update.sh +191 -0
- package/skills/teamsmith/scripts/lib/cmd-watch.sh +1681 -0
- package/skills/teamsmith/scripts/lib/common.sh +4964 -0
- package/skills/teamsmith/scripts/lib/draft-entry.sh +51 -0
- package/skills/teamsmith/scripts/lib/outbox.sh +2042 -0
- package/skills/teamsmith/scripts/lib/tmux-argv.sh +165 -0
- package/skills/teamsmith/scripts/monitor.mjs +616 -0
- package/skills/teamsmith/scripts/panel/README.md +192 -0
- package/skills/teamsmith/scripts/panel/build.sh +47 -0
- package/skills/teamsmith/scripts/panel/bun.lock +109 -0
- package/skills/teamsmith/scripts/panel/draft-send.sh +68 -0
- package/skills/teamsmith/scripts/panel/package.json +24 -0
- package/skills/teamsmith/scripts/panel/panel.js +388 -0
- package/skills/teamsmith/scripts/panel/src/App.tsx +2150 -0
- package/skills/teamsmith/scripts/panel/src/clipboard.ts +154 -0
- package/skills/teamsmith/scripts/panel/src/compose.ts +691 -0
- package/skills/teamsmith/scripts/panel/src/data.ts +555 -0
- package/skills/teamsmith/scripts/panel/src/format.ts +50 -0
- package/skills/teamsmith/scripts/panel/src/layout.ts +2562 -0
- package/skills/teamsmith/scripts/panel/src/main.tsx +894 -0
- package/skills/teamsmith/scripts/panel/src/markdown.ts +340 -0
- package/skills/teamsmith/scripts/panel/src/sanitize.ts +42 -0
- package/skills/teamsmith/scripts/panel/src/settings.ts +154 -0
- package/skills/teamsmith/scripts/panel/src/strings/en.ts +416 -0
- package/skills/teamsmith/scripts/panel/src/strings/index.ts +65 -0
- package/skills/teamsmith/scripts/panel/src/strings/types.ts +9 -0
- package/skills/teamsmith/scripts/panel/src/strings/zh.ts +414 -0
- package/skills/teamsmith/scripts/panel/src/theme.ts +116 -0
- package/skills/teamsmith/scripts/panel/src/types.ts +652 -0
- package/skills/teamsmith/scripts/panel/src/width.ts +105 -0
- package/skills/teamsmith/scripts/panel/tsconfig.json +16 -0
- package/skills/teamsmith/scripts/shim/signal-gate +156 -0
- package/skills/teamsmith/scripts/shim/tmux +403 -0
- package/skills/teamsmith/scripts/team +143 -0
- package/skills/teamsmith/templates/AGENTS.section.md.tmpl +147 -0
- package/skills/teamsmith/templates/BOARD.md.tmpl +18 -0
- package/skills/teamsmith/templates/DECISIONS.md.tmpl +22 -0
- package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +25 -0
- package/skills/teamsmith/templates/PROTOCOL.md.tmpl +84 -0
- package/skills/teamsmith/templates/ROADMAP.md.tmpl +29 -0
- package/skills/teamsmith/templates/config.sh.tmpl +106 -0
- package/skills/teamsmith/templates/memory-seed.md.tmpl +46 -0
- package/skills/teamsmith/templates/pm-prompt.md.tmpl +110 -0
- package/skills/teamsmith/templates/report.md.tmpl +36 -0
- package/skills/teamsmith/templates/task.md.tmpl +65 -0
- package/skills/teamsmith/templates/threads-README.md +17 -0
- package/skills/teamsmith/tests/bg-ledger-harness.mjs +682 -0
- package/skills/teamsmith/tests/bg-ledger.sh +307 -0
- package/skills/teamsmith/tests/checkout-shape-probe.sh +800 -0
- package/skills/teamsmith/tests/config-cli.sh +1562 -0
- package/skills/teamsmith/tests/container-tmux.sh +493 -0
- package/skills/teamsmith/tests/coverage-inventory.sh +173 -0
- package/skills/teamsmith/tests/death-cause.sh +564 -0
- package/skills/teamsmith/tests/delivery-truth.sh +1231 -0
- package/skills/teamsmith/tests/fake-tui.py +450 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/README.md +60 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/judge-second.py +139 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/mock-server.py +29 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/observe.ts +20 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/run-case.sh +79 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +175 -0
- package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +229 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/README.md +22 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/dev2.seen +8 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/dev2.wake +9 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/pm-nudges.wake +3 -0
- package/skills/teamsmith/tests/fixtures/signal-lint-cases.txt +40 -0
- package/skills/teamsmith/tests/flip-glue.sh +162 -0
- package/skills/teamsmith/tests/flip-m12-26c.sh +129 -0
- package/skills/teamsmith/tests/flip-m12.sh +185 -0
- package/skills/teamsmith/tests/flip-m16.sh +166 -0
- package/skills/teamsmith/tests/flip-m17.sh +204 -0
- package/skills/teamsmith/tests/flip-m33.sh +284 -0
- package/skills/teamsmith/tests/flip-m34.sh +96 -0
- package/skills/teamsmith/tests/flip-m37.sh +185 -0
- package/skills/teamsmith/tests/flip-m4.3.sh +375 -0
- package/skills/teamsmith/tests/flip-m43.sh +128 -0
- package/skills/teamsmith/tests/flip-m44.sh +262 -0
- package/skills/teamsmith/tests/flip-m45.sh +244 -0
- package/skills/teamsmith/tests/flip-m46.sh +238 -0
- package/skills/teamsmith/tests/flip-m48.sh +304 -0
- package/skills/teamsmith/tests/flip-m6.2.sh +205 -0
- package/skills/teamsmith/tests/flip-m6.3.sh +283 -0
- package/skills/teamsmith/tests/flip-m6.4.sh +267 -0
- package/skills/teamsmith/tests/flip-m6.5.sh +113 -0
- package/skills/teamsmith/tests/flip-m7.1.sh +135 -0
- package/skills/teamsmith/tests/flip-m7.2.sh +321 -0
- package/skills/teamsmith/tests/flip-p144.sh +112 -0
- package/skills/teamsmith/tests/flip-p156.sh +133 -0
- package/skills/teamsmith/tests/flip-p158.sh +301 -0
- package/skills/teamsmith/tests/flip-p160.sh +182 -0
- package/skills/teamsmith/tests/flip-p171.sh +249 -0
- package/skills/teamsmith/tests/flip-p18.1.sh +95 -0
- package/skills/teamsmith/tests/flip-p20.sh +286 -0
- package/skills/teamsmith/tests/flip-p201.sh +249 -0
- package/skills/teamsmith/tests/flip-p210.sh +239 -0
- package/skills/teamsmith/tests/flip-p211.sh +152 -0
- package/skills/teamsmith/tests/flip-p217.sh +288 -0
- package/skills/teamsmith/tests/flip-p22.sh +123 -0
- package/skills/teamsmith/tests/flip-p23.sh +239 -0
- package/skills/teamsmith/tests/flip-p25.sh +165 -0
- package/skills/teamsmith/tests/flip-p71.sh +184 -0
- package/skills/teamsmith/tests/flip-p72.sh +202 -0
- package/skills/teamsmith/tests/frames/README.md +176 -0
- package/skills/teamsmith/tests/frames/p78-conversation-rule-below-box.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-cursor-mid-draft.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-below-cursor-line.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-below-cursor.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-blank-region.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-only.txt +5 -0
- package/skills/teamsmith/tests/frames/p78-spinner-row-below-cursor.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-wider-rule-below-cursor.txt +6 -0
- package/skills/teamsmith/tests/frames/p86-f1-mixed-width-disjoint-box.txt +8 -0
- package/skills/teamsmith/tests/frames/p86-f1-narrower-width-disjoint-box.txt +8 -0
- package/skills/teamsmith/tests/frames/p86-f1-spinner-top-disjoint-box.txt +8 -0
- package/skills/teamsmith/tests/frames/pi-0.85.1-update-banner.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-draft-half-sentence.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-empty-box.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-one-line-draft.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-project-trust-prompt.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.99.2-empty-editor.txt +32 -0
- package/skills/teamsmith/tests/frames/pi-0.99.2-human-draft.txt +32 -0
- package/skills/teamsmith/tests/frames/pi-1.0.0-git-error-in-box.txt +32 -0
- package/skills/teamsmith/tests/gate-guard.sh +112 -0
- package/skills/teamsmith/tests/guard-matrix.sh +233 -0
- package/skills/teamsmith/tests/install-shape.sh +731 -0
- package/skills/teamsmith/tests/ledger-ban.sh +612 -0
- package/skills/teamsmith/tests/lib/box-judge.sh +68 -0
- package/skills/teamsmith/tests/lib/checkout-shape.sh +129 -0
- package/skills/teamsmith/tests/lib/loop-scan.awk +114 -0
- package/skills/teamsmith/tests/lib/pty-wait.sh +676 -0
- package/skills/teamsmith/tests/lib/section-guard.sh +855 -0
- package/skills/teamsmith/tests/lib/shell-lex.pl +261 -0
- package/skills/teamsmith/tests/lib/tmp-root.sh +528 -0
- package/skills/teamsmith/tests/lib/tmux-cap.sh +35 -0
- package/skills/teamsmith/tests/lib/tmux-iso-call-probe.sh +81 -0
- package/skills/teamsmith/tests/lib/tmux-iso-probe.sh +46 -0
- package/skills/teamsmith/tests/lib/tmux-iso.sh +381 -0
- package/skills/teamsmith/tests/load-experiment.sh +290 -0
- package/skills/teamsmith/tests/loop-inventory.tsv +84 -0
- package/skills/teamsmith/tests/panel-b2-slow-stub.sh +19 -0
- package/skills/teamsmith/tests/panel-b2.sh +1183 -0
- package/skills/teamsmith/tests/panel-b3-pty-mouse.py +240 -0
- package/skills/teamsmith/tests/panel-b3-pty-tmux-mouse.py +138 -0
- package/skills/teamsmith/tests/panel-b3-stub.sh +279 -0
- package/skills/teamsmith/tests/panel-b3.sh +1301 -0
- package/skills/teamsmith/tests/panel-choices.sh +572 -0
- package/skills/teamsmith/tests/panel-clipboard-model.ts +187 -0
- package/skills/teamsmith/tests/panel-compose-model.ts +290 -0
- package/skills/teamsmith/tests/panel-contrast.mjs +81 -0
- package/skills/teamsmith/tests/panel-cpu-premise.sh +173 -0
- package/skills/teamsmith/tests/panel-cpu.sh +391 -0
- package/skills/teamsmith/tests/panel-flip-m54.sh +207 -0
- package/skills/teamsmith/tests/panel-flip-p123.sh +278 -0
- package/skills/teamsmith/tests/panel-flip-p125.sh +318 -0
- package/skills/teamsmith/tests/panel-flip-p128.sh +259 -0
- package/skills/teamsmith/tests/panel-keyprobe-pty.py +99 -0
- package/skills/teamsmith/tests/panel-keyprobe-stub.sh +41 -0
- package/skills/teamsmith/tests/panel-keyprobe.sh +82 -0
- package/skills/teamsmith/tests/panel-keyprobe.tsx +116 -0
- package/skills/teamsmith/tests/panel-knobs.sh +83 -0
- package/skills/teamsmith/tests/panel-p21.sh +2181 -0
- package/skills/teamsmith/tests/panel-snapshots.sh +802 -0
- package/skills/teamsmith/tests/panel-strings.mjs +195 -0
- package/skills/teamsmith/tests/perf.sh +740 -0
- package/skills/teamsmith/tests/pm-box-real.sh +350 -0
- package/skills/teamsmith/tests/pulse-nudge-key.sh +563 -0
- package/skills/teamsmith/tests/routes.sh +1652 -0
- package/skills/teamsmith/tests/section-budgets.tsv +150 -0
- package/skills/teamsmith/tests/section-guard.sh +231 -0
- package/skills/teamsmith/tests/section-needs-audit.sh +94 -0
- package/skills/teamsmith/tests/section-paths.tsv +142 -0
- package/skills/teamsmith/tests/section-select.sh +655 -0
- package/skills/teamsmith/tests/signal-gate.sh +366 -0
- package/skills/teamsmith/tests/signal-lint-legacy.txt +14 -0
- package/skills/teamsmith/tests/signal-lint.pl +416 -0
- package/skills/teamsmith/tests/skill-load.mjs +65 -0
- package/skills/teamsmith/tests/smoke.sh +19711 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-120-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-120-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-120.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-160-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-160.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-59-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-59-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-59.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-99-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-99.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-120-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-120-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-120.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-160-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-160.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-59-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-59-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-59.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-99-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-99.txt +32 -0
- package/skills/teamsmith/tests/spec-ledger-refs.tsv +78 -0
- package/skills/teamsmith/tests/spec-refs.sh +826 -0
- package/skills/teamsmith/tests/task-header-model.sh +267 -0
- package/skills/teamsmith/tests/team-bg-flip.sh +239 -0
- package/skills/teamsmith/tests/team-bg-harness.mjs +392 -0
- package/skills/teamsmith/tests/team-bg-stop.sh +434 -0
- package/skills/teamsmith/tests/team-inbox-watch-flip.sh +191 -0
- package/skills/teamsmith/tests/team-inbox-watch-harness.mjs +1559 -0
- package/skills/teamsmith/tests/tmp-hygiene.sh +1190 -0
- package/skills/teamsmith/tests/tmux-lint-legacy.txt +31 -0
- package/skills/teamsmith/tests/tmux-lint.pl +604 -0
- package/skills/teamsmith-init/SKILL.md +100 -0
- package/skills/teamsmith-init/references/bootstrap.md +74 -0
- package/skills/teamsmith-init/templates/bootstrap-prompt.md.tmpl +46 -0
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
// The panel's only data path.
|
|
2
|
+
//
|
|
3
|
+
// Three subprocesses families, none of them blocking the event loop:
|
|
4
|
+
// * one `team __panel-data --block <name>` child per block — the bash readers
|
|
5
|
+
// (`team_pm_state`, `team_pending_*`, the queue directory, `team_git_cols`,
|
|
6
|
+
// `team_session_tokens_est`, the capacity log) split so a broken or slow source takes only its
|
|
7
|
+
// own block down. Each child has its own timeout; a block that fails, dies or overruns renders
|
|
8
|
+
// as `—` and never delays the rest of the frame.
|
|
9
|
+
// * the tick (`team watch --once`) — owned by the run, one async child per due tick.
|
|
10
|
+
//
|
|
11
|
+
// The renderer reads a snapshot of an in-memory cache; nothing on the render path waits for a
|
|
12
|
+
// child. `monitor.mjs` is spawned by the activity block, not here: it stays the data layer, its
|
|
13
|
+
// `--json` contract untouched, and the panel consumes its result as a value inside the same
|
|
14
|
+
// object.
|
|
15
|
+
//
|
|
16
|
+
// The cadence is the design's performance contract: the fast blocks rebuild every tick, the
|
|
17
|
+
// expensive ones (the report scan, the per-agent git reads) carry a longer TTL, so idle cost stays
|
|
18
|
+
// off the input path.
|
|
19
|
+
|
|
20
|
+
import { spawn } from 'node:child_process'
|
|
21
|
+
import { appendFileSync, existsSync, readFileSync, writeFileSync } from 'node:fs'
|
|
22
|
+
import { dirname, join, resolve } from 'node:path'
|
|
23
|
+
import { fileURLToPath } from 'node:url'
|
|
24
|
+
import { sanitizeDeep } from './sanitize.js'
|
|
25
|
+
import type { ActivityBlock, PanelBlocks, PanelData } from './types.js'
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* M40 — the panel's identity is its own root (`--root`, else cwd), never an inherited `TEAM_*`.
|
|
29
|
+
*
|
|
30
|
+
* The panel is a long-running process that spawns the CLI in many forms; every one of them is given
|
|
31
|
+
* `--root` explicitly and runs with `cwd = root`, so an inherited identity can only ever *contradict*
|
|
32
|
+
* the panel's own. It must not reach a child: the CLI derives the child's identity from its directory
|
|
33
|
+
* and would then see a conflict (two real incidents on 2026-09-19: a pulse started from another
|
|
34
|
+
* project's shell rendered the wrong board). Children therefore get a copy of the environment with
|
|
35
|
+
* the identity locators removed.
|
|
36
|
+
*/
|
|
37
|
+
export const IDENTITY_ENV_VARS = [
|
|
38
|
+
'TEAM_ROOT',
|
|
39
|
+
'TEAM_MAIN_ROOT',
|
|
40
|
+
'TEAM_PROJECT',
|
|
41
|
+
'TEAM_SESSION',
|
|
42
|
+
'TEAM_SESSION_FROM',
|
|
43
|
+
'TEAM_CONFIG_FILE',
|
|
44
|
+
] as const
|
|
45
|
+
|
|
46
|
+
export function cleanIdentityEnv(env: NodeJS.ProcessEnv = process.env): NodeJS.ProcessEnv {
|
|
47
|
+
const out: NodeJS.ProcessEnv = { ...env }
|
|
48
|
+
for (const name of IDENTITY_ENV_VARS) delete out[name]
|
|
49
|
+
// `TEAM_IDENTITY_*` are the CLI's per-process decision inputs (lock + inherited snapshot); they
|
|
50
|
+
// must never reach a child, or the child would judge its own identity from the parent's conflicts.
|
|
51
|
+
for (const name of Object.keys(out)) if (name.startsWith('TEAM_IDENTITY')) delete out[name]
|
|
52
|
+
return out
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The blocks the bash data command serves, one child each. */
|
|
56
|
+
export const BLOCK_NAMES = [
|
|
57
|
+
'frame',
|
|
58
|
+
'pm',
|
|
59
|
+
'pending',
|
|
60
|
+
'outbox',
|
|
61
|
+
'capacity',
|
|
62
|
+
'agents',
|
|
63
|
+
'recent',
|
|
64
|
+
'activity',
|
|
65
|
+
// pulse-console B3: the console-only readers (the machine exits never render them).
|
|
66
|
+
'board',
|
|
67
|
+
'changes',
|
|
68
|
+
'specs',
|
|
69
|
+
'decisions',
|
|
70
|
+
'outbox_list',
|
|
71
|
+
'inbox',
|
|
72
|
+
'patrol',
|
|
73
|
+
'health',
|
|
74
|
+
// P18/B3: the detail view's on-demand reader. It is in the block set but **never wanted** unless
|
|
75
|
+
// `opts.detailId` is set, so a parked console spawns no `detail` child (design §8).
|
|
76
|
+
'detail',
|
|
77
|
+
// P22/B2: the project-settings view's on-demand reader (`team config list --json`). Same rule:
|
|
78
|
+
// never wanted unless the view is open.
|
|
79
|
+
'settings',
|
|
80
|
+
] as const
|
|
81
|
+
export type BlockName = (typeof BLOCK_NAMES)[number]
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The blocks the **machine exits** (`--print` / `--json`) assemble: the original eight plus the
|
|
85
|
+
* four the overview renders (progress, changes, specs, decisions). The page-2/3-only readers
|
|
86
|
+
* (`outbox_list`, `inbox`, `patrol`, `health`) are console-only: `--print`/`--json` never render
|
|
87
|
+
* them, so they are not spawned there — `--json`'s cost and keys stay exactly as before, and a
|
|
88
|
+
* `doctor` run never sits on a machine exit's path.
|
|
89
|
+
*/
|
|
90
|
+
export const MACHINE_BLOCKS = [
|
|
91
|
+
'frame',
|
|
92
|
+
'pm',
|
|
93
|
+
'pending',
|
|
94
|
+
'outbox',
|
|
95
|
+
'capacity',
|
|
96
|
+
'agents',
|
|
97
|
+
'recent',
|
|
98
|
+
'activity',
|
|
99
|
+
'board',
|
|
100
|
+
'changes',
|
|
101
|
+
'specs',
|
|
102
|
+
'decisions',
|
|
103
|
+
] as const satisfies readonly BlockName[]
|
|
104
|
+
|
|
105
|
+
export interface DataOptions {
|
|
106
|
+
root: string
|
|
107
|
+
/** Explicit path to the teamsmith CLI; resolved from panel.js's own location when omitted. */
|
|
108
|
+
teamCli?: string
|
|
109
|
+
activity: boolean
|
|
110
|
+
events: number
|
|
111
|
+
timeoutMs?: number
|
|
112
|
+
/** Which blocks to assemble; default = every block (the console's set, minus `detail`). */
|
|
113
|
+
blocks?: readonly BlockName[]
|
|
114
|
+
/** The detail view's entry id; while set, `detail` joins the wanted set (null/absent = parked). */
|
|
115
|
+
detailId?: string | null
|
|
116
|
+
/** True while the project-settings view is open; only then does `settings` join the wanted set. */
|
|
117
|
+
settingsOpen?: boolean
|
|
118
|
+
/** The detail file to serve with `--file` (must be one of the discovered paths). */
|
|
119
|
+
detailFile?: string | null
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface DataResult {
|
|
123
|
+
ok: boolean
|
|
124
|
+
data?: PanelData
|
|
125
|
+
activity?: ActivityBlock[]
|
|
126
|
+
/** The console-only readers (`board`, `changes`, …), keyed by block name. */
|
|
127
|
+
blocks?: PanelBlocks
|
|
128
|
+
/** Blocks whose source failed, timed out or is unreadable in this snapshot (rendered as `—`). */
|
|
129
|
+
degraded?: BlockName[]
|
|
130
|
+
/** Why each degraded block is degraded (diagnostics; never rendered as data). */
|
|
131
|
+
errors?: Partial<Record<BlockName, string>>
|
|
132
|
+
error?: string
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
interface BlockSpec {
|
|
136
|
+
/** How long a cached value stays fresh; the panel's tick rebuilds the expired ones. */
|
|
137
|
+
ttlMs: number
|
|
138
|
+
timeoutMs: number
|
|
139
|
+
extraArgs?: (opts: DataOptions) => string[]
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const BLOCK_SPECS: Record<BlockName, BlockSpec> = {
|
|
143
|
+
// The banner and the queue — the console's "is there work" surface. The three actions invalidate
|
|
144
|
+
// the cache explicitly (`refreshNow`), so the TTL only has to feel live, not be 3s.
|
|
145
|
+
// The banner (project/interval/standby/clock): the cheapest block (~0.04s, one `date`) and the one
|
|
146
|
+
// a human watches for the effect of an action. A TTL below the shortest cadence means every
|
|
147
|
+
// cadence re-assembles it, so an outside change to the banner shows up within one cadence.
|
|
148
|
+
frame: { ttlMs: 500, timeoutMs: 10000 },
|
|
149
|
+
pm: { ttlMs: 9000, timeoutMs: 10000 },
|
|
150
|
+
pending: { ttlMs: 15000, timeoutMs: 10000 },
|
|
151
|
+
outbox: { ttlMs: 9000, timeoutMs: 10000 },
|
|
152
|
+
capacity: { ttlMs: 9000, timeoutMs: 10000 },
|
|
153
|
+
agents: { ttlMs: 15000, timeoutMs: 15000 },
|
|
154
|
+
recent: { ttlMs: 9000, timeoutMs: 10000 },
|
|
155
|
+
// The activity column is the design's 3s live view (the one block that must keep the cadence);
|
|
156
|
+
// everything else trades freshness for the <1%-of-one-core red line. Measured on the reference
|
|
157
|
+
// checkout: rebuilding every block on the 3s cadence put the pane process at ~1.2%, one Ink
|
|
158
|
+
// `rerender` per cadence alone cost ~20ms, and the expensive readers (the report scan, the
|
|
159
|
+
// per-agent git reads, `doctor`) each burn 0.2-0.5s of child CPU per rebuild.
|
|
160
|
+
activity: {
|
|
161
|
+
ttlMs: 3000,
|
|
162
|
+
timeoutMs: 15000,
|
|
163
|
+
extraArgs: (opts) => (opts.activity ? [] : ['--no-activity']),
|
|
164
|
+
},
|
|
165
|
+
// Console-only readers: the board parses every row of BOARD.md (73 rows on the reference
|
|
166
|
+
// checkout), the patrol log grows every 15 minutes, and the OpenSpec-CLI blocks plus `doctor` are
|
|
167
|
+
// the heaviest of all — they are far apart on purpose.
|
|
168
|
+
board: { ttlMs: 15000, timeoutMs: 10000 },
|
|
169
|
+
changes: { ttlMs: 180000, timeoutMs: 20000 },
|
|
170
|
+
specs: { ttlMs: 180000, timeoutMs: 20000 },
|
|
171
|
+
decisions: { ttlMs: 60000, timeoutMs: 10000 },
|
|
172
|
+
outbox_list: { ttlMs: 9000, timeoutMs: 10000 },
|
|
173
|
+
inbox: { ttlMs: 60000, timeoutMs: 10000 },
|
|
174
|
+
patrol: { ttlMs: 15000, timeoutMs: 10000 },
|
|
175
|
+
health: { ttlMs: 600000, timeoutMs: 30000 },
|
|
176
|
+
// The detail reader rides the open view: the App forces it on open and on a tab switch, so its TTL
|
|
177
|
+
// only covers a stale refresh while the view stays open. The `--id`/`--file` arguments come from
|
|
178
|
+
// the live options; both are cleared when the view closes.
|
|
179
|
+
detail: {
|
|
180
|
+
ttlMs: 15000,
|
|
181
|
+
timeoutMs: 10000,
|
|
182
|
+
extraArgs: (opts) => {
|
|
183
|
+
if (!opts.detailId) return []
|
|
184
|
+
const args = ['--id', String(opts.detailId)]
|
|
185
|
+
if (opts.detailFile) args.push('--file', String(opts.detailFile))
|
|
186
|
+
return args
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
// The project-settings reader rides the open view exactly like `detail` (P22/B2).
|
|
190
|
+
settings: { ttlMs: 15000, timeoutMs: 10000 },
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Find `scripts/team` relative to the bundle. `panel.js` lives at `<skill>/scripts/panel/panel.js`;
|
|
197
|
+
* running from source (`src/main.tsx`) is one directory deeper. `.js` and `.ts` sources share this.
|
|
198
|
+
*/
|
|
199
|
+
export function findTeamCli(here: string): string | null {
|
|
200
|
+
for (const rel of ['../team', '../../team', '../../../team']) {
|
|
201
|
+
const cand = resolve(join(here, rel))
|
|
202
|
+
if (existsSync(cand)) return cand
|
|
203
|
+
}
|
|
204
|
+
return null
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function panelDirOf(importMetaUrl: string): string {
|
|
208
|
+
return dirname(fileURLToPath(importMetaUrl))
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
interface BlockOutcome {
|
|
212
|
+
ok: boolean
|
|
213
|
+
value?: unknown
|
|
214
|
+
error?: string
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** One block, one child, one timeout. Never throws and never blocks the loop. */
|
|
218
|
+
function runBlock(
|
|
219
|
+
spec: BlockSpec,
|
|
220
|
+
name: BlockName,
|
|
221
|
+
opts: DataOptions,
|
|
222
|
+
cli: string,
|
|
223
|
+
children?: Set<ReturnType<typeof spawn>>,
|
|
224
|
+
): Promise<BlockOutcome> {
|
|
225
|
+
const timeoutMs = opts.timeoutMs ?? spec.timeoutMs
|
|
226
|
+
const extra = spec.extraArgs ? spec.extraArgs(opts) : []
|
|
227
|
+
const args = [cli, '--root', opts.root, '__panel-data', '--block', name, '--events', String(opts.events), ...extra]
|
|
228
|
+
return new Promise((resolve) => {
|
|
229
|
+
let child: ReturnType<typeof spawn>
|
|
230
|
+
try {
|
|
231
|
+
child = spawn('bash', args, { cwd: opts.root, env: cleanIdentityEnv(), stdio: ['ignore', 'pipe', 'pipe'] })
|
|
232
|
+
children?.add(child)
|
|
233
|
+
} catch (e) {
|
|
234
|
+
resolve({ ok: false, error: (e as Error).message })
|
|
235
|
+
return
|
|
236
|
+
}
|
|
237
|
+
let out = ''
|
|
238
|
+
let err = ''
|
|
239
|
+
let settled = false
|
|
240
|
+
const done = (outcome: BlockOutcome): void => {
|
|
241
|
+
if (settled) return
|
|
242
|
+
settled = true
|
|
243
|
+
clearTimeout(timer)
|
|
244
|
+
children?.delete(child)
|
|
245
|
+
resolve(outcome)
|
|
246
|
+
}
|
|
247
|
+
const timer = setTimeout(() => {
|
|
248
|
+
try {
|
|
249
|
+
child.kill('SIGKILL')
|
|
250
|
+
} catch {
|
|
251
|
+
/* already gone */
|
|
252
|
+
}
|
|
253
|
+
done({ ok: false, error: `timed out after ${timeoutMs}ms` })
|
|
254
|
+
}, timeoutMs)
|
|
255
|
+
child.stdout?.on('data', (d: Buffer) => {
|
|
256
|
+
out += String(d)
|
|
257
|
+
if (out.length > 32 * 1024 * 1024) {
|
|
258
|
+
try {
|
|
259
|
+
child.kill('SIGKILL')
|
|
260
|
+
} catch {
|
|
261
|
+
/* already gone */
|
|
262
|
+
}
|
|
263
|
+
done({ ok: false, error: 'block output exceeded 32MB' })
|
|
264
|
+
}
|
|
265
|
+
})
|
|
266
|
+
child.stderr?.on('data', (d: Buffer) => {
|
|
267
|
+
err += String(d)
|
|
268
|
+
})
|
|
269
|
+
child.on('error', (e) => done({ ok: false, error: e.message }))
|
|
270
|
+
child.on('close', (code) => {
|
|
271
|
+
if (settled) return
|
|
272
|
+
const tail = err.trim().split('\n').filter(Boolean).slice(-2).join(' · ')
|
|
273
|
+
if (code !== 0) {
|
|
274
|
+
done({ ok: false, error: `rc=${code ?? '?'}${tail ? `: ${tail}` : ''}` })
|
|
275
|
+
return
|
|
276
|
+
}
|
|
277
|
+
const raw = out.trim()
|
|
278
|
+
if (!raw) {
|
|
279
|
+
done({ ok: false, error: 'no output' })
|
|
280
|
+
return
|
|
281
|
+
}
|
|
282
|
+
try {
|
|
283
|
+
done({ ok: true, value: sanitizeDeep(JSON.parse(raw)) })
|
|
284
|
+
} catch (e) {
|
|
285
|
+
done({ ok: false, error: `invalid JSON: ${(e as Error).message}` })
|
|
286
|
+
}
|
|
287
|
+
})
|
|
288
|
+
})
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** Write one block's value into the panel object it owns. */
|
|
292
|
+
function applyBlock(data: PanelData, name: BlockName, value: unknown): void {
|
|
293
|
+
const v = (value ?? {}) as Record<string, unknown>
|
|
294
|
+
switch (name) {
|
|
295
|
+
case 'frame': {
|
|
296
|
+
if (typeof v.project === 'string') data.project = v.project
|
|
297
|
+
if (typeof v.timestamp === 'string') data.timestamp = v.timestamp
|
|
298
|
+
if (typeof v.interval === 'number') data.interval = v.interval
|
|
299
|
+
if (v.standby && typeof v.standby === 'object') data.standby = v.standby as PanelData['standby']
|
|
300
|
+
if (typeof v.activity_source === 'string') data.activity_source = v.activity_source
|
|
301
|
+
return
|
|
302
|
+
}
|
|
303
|
+
case 'pm':
|
|
304
|
+
data.pm = v as unknown as PanelData['pm']
|
|
305
|
+
return
|
|
306
|
+
case 'pending':
|
|
307
|
+
data.pending = v as unknown as PanelData['pending']
|
|
308
|
+
return
|
|
309
|
+
case 'outbox':
|
|
310
|
+
data.outbox = v as unknown as PanelData['outbox']
|
|
311
|
+
return
|
|
312
|
+
case 'capacity':
|
|
313
|
+
data.capacity = v as unknown as PanelData['capacity']
|
|
314
|
+
return
|
|
315
|
+
case 'agents':
|
|
316
|
+
data.agents = Array.isArray(v) ? (v as PanelData['agents']) : []
|
|
317
|
+
return
|
|
318
|
+
case 'recent':
|
|
319
|
+
data.recent = Array.isArray(v) ? (v as string[]) : []
|
|
320
|
+
return
|
|
321
|
+
case 'activity':
|
|
322
|
+
return // merged separately (it is the data layer's blocks, not a panel field)
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* `elapsed` / `idle` / the event count come from the data layer's block for the same agent. They
|
|
328
|
+
* are JSON-only fields: the table never shows the uptime token (the requirement pins that), but
|
|
329
|
+
* `team monitor --json` keeps them.
|
|
330
|
+
*/
|
|
331
|
+
export function mergeActivity(panel: PanelData, activity: ActivityBlock[]): void {
|
|
332
|
+
const byName = new Map(activity.map((b) => [String(b?.name ?? ''), b]))
|
|
333
|
+
for (const a of panel.agents ?? []) {
|
|
334
|
+
const b = byName.get(String(a.name))
|
|
335
|
+
if (!b) continue
|
|
336
|
+
if (typeof b.elapsed === 'string') a.elapsed = b.elapsed
|
|
337
|
+
if (typeof b.idle === 'string') a.idle = b.idle
|
|
338
|
+
if (typeof b.count === 'number') a.events = b.count
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
interface BlockState {
|
|
343
|
+
value?: unknown
|
|
344
|
+
/** Epoch ms of the last successful build (0 = never). */
|
|
345
|
+
at: number
|
|
346
|
+
error?: string
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const PANEL_BLOCK_NAMES: readonly BlockName[] = [
|
|
350
|
+
'board',
|
|
351
|
+
'changes',
|
|
352
|
+
'specs',
|
|
353
|
+
'decisions',
|
|
354
|
+
'outbox_list',
|
|
355
|
+
'inbox',
|
|
356
|
+
'patrol',
|
|
357
|
+
'health',
|
|
358
|
+
'detail',
|
|
359
|
+
'settings',
|
|
360
|
+
]
|
|
361
|
+
|
|
362
|
+
function isPanelBlock(name: BlockName): boolean {
|
|
363
|
+
return PANEL_BLOCK_NAMES.includes(name)
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function emptyPanel(): PanelData {
|
|
367
|
+
return { project: '', timestamp: '', interval: 0 }
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
export interface PanelCache {
|
|
371
|
+
/** The current frame data. Pure: reads memory, never spawns anything. */
|
|
372
|
+
snapshot(): DataResult
|
|
373
|
+
/** Rebuild the expired blocks (or all of them with `force`), in parallel. */
|
|
374
|
+
refresh(refreshOpts?: { force?: boolean; only?: readonly BlockName[] }): Promise<DataResult>
|
|
375
|
+
/** Kill anything still in flight (process exit, tests). */
|
|
376
|
+
dispose(): void
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export function createPanelCache(opts: DataOptions): PanelCache {
|
|
380
|
+
const cli = opts.teamCli || findTeamCli(panelDirOf(import.meta.url))
|
|
381
|
+
/**
|
|
382
|
+
* The wanted set is read live: the `detail` and `settings` blocks join it only while their views
|
|
383
|
+
* are open, so the idle cost of a parked console is exactly what it was before those views
|
|
384
|
+
* existed (design §8).
|
|
385
|
+
*/
|
|
386
|
+
const wantedSet = (): readonly BlockName[] => {
|
|
387
|
+
if (opts.blocks) return opts.blocks
|
|
388
|
+
const live = new Set<BlockName>()
|
|
389
|
+
if (opts.detailId) live.add('detail')
|
|
390
|
+
if (opts.settingsOpen) live.add('settings')
|
|
391
|
+
return BLOCK_NAMES.filter((name) => (name === 'detail' || name === 'settings' ? live.has(name) : true))
|
|
392
|
+
}
|
|
393
|
+
const state: Record<string, BlockState> = {}
|
|
394
|
+
for (const name of BLOCK_NAMES) state[name] = { at: 0 }
|
|
395
|
+
let inFlight: Partial<Record<BlockName, Promise<void>>> = {}
|
|
396
|
+
const children = new Set<ReturnType<typeof spawn>>()
|
|
397
|
+
|
|
398
|
+
function snapshot(): DataResult {
|
|
399
|
+
if (!cli) {
|
|
400
|
+
return { ok: false, error: 'panel: cannot locate the teamsmith CLI next to the bundle (scripts/team)' }
|
|
401
|
+
}
|
|
402
|
+
const data = emptyPanel()
|
|
403
|
+
const blocks: PanelBlocks = {}
|
|
404
|
+
const degraded: BlockName[] = []
|
|
405
|
+
const errors: Partial<Record<BlockName, string>> = {}
|
|
406
|
+
let activity: ActivityBlock[] = []
|
|
407
|
+
for (const name of BLOCK_NAMES) {
|
|
408
|
+
if (!wantedSet().includes(name)) continue
|
|
409
|
+
const s = state[name]
|
|
410
|
+
const fresh = s.at > 0 && !s.error
|
|
411
|
+
if (!fresh) {
|
|
412
|
+
degraded.push(name)
|
|
413
|
+
if (s.error) errors[name] = s.error
|
|
414
|
+
continue
|
|
415
|
+
}
|
|
416
|
+
if (name === 'activity') {
|
|
417
|
+
activity = Array.isArray(s.value) ? (s.value as ActivityBlock[]) : []
|
|
418
|
+
continue
|
|
419
|
+
}
|
|
420
|
+
if (isPanelBlock(name)) {
|
|
421
|
+
;(blocks as Record<string, unknown>)[name] = s.value
|
|
422
|
+
continue
|
|
423
|
+
}
|
|
424
|
+
applyBlock(data, name, s.value)
|
|
425
|
+
}
|
|
426
|
+
mergeActivity(data, activity)
|
|
427
|
+
return { ok: true, data, activity, blocks, degraded, errors }
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function build(name: BlockName): Promise<void> {
|
|
431
|
+
return runBlock(BLOCK_SPECS[name], name, opts, cli as string, children).then((outcome) => {
|
|
432
|
+
const s = state[name]
|
|
433
|
+
if (outcome.ok) {
|
|
434
|
+
s.value = outcome.value
|
|
435
|
+
s.at = Date.now()
|
|
436
|
+
s.error = undefined
|
|
437
|
+
} else {
|
|
438
|
+
// A block that failed is not dressed in last week's number: it renders `—` until the
|
|
439
|
+
// next successful build (the design's stale-data trade-off, made explicit).
|
|
440
|
+
s.error = outcome.error || 'failed'
|
|
441
|
+
}
|
|
442
|
+
})
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
async function refresh(refreshOpts: { force?: boolean; only?: readonly BlockName[] } = {}): Promise<DataResult> {
|
|
446
|
+
if (!cli) return snapshot()
|
|
447
|
+
const only = refreshOpts.only ? new Set(refreshOpts.only) : null
|
|
448
|
+
const wanted = wantedSet()
|
|
449
|
+
const now = Date.now()
|
|
450
|
+
for (const name of BLOCK_NAMES) {
|
|
451
|
+
if (!wanted.includes(name)) continue
|
|
452
|
+
if (only && !only.has(name)) continue
|
|
453
|
+
const s = state[name]
|
|
454
|
+
const due = refreshOpts.force || s.at === 0 || now - s.at >= BLOCK_SPECS[name].ttlMs
|
|
455
|
+
if (!due) continue
|
|
456
|
+
if (inFlight[name]) continue
|
|
457
|
+
inFlight[name] = build(name).finally(() => {
|
|
458
|
+
delete inFlight[name]
|
|
459
|
+
})
|
|
460
|
+
}
|
|
461
|
+
// Already-running builds count as this refresh's work: the caller wants a settled snapshot.
|
|
462
|
+
await Promise.all(BLOCK_NAMES.filter((name) => (!only || only.has(name)) && inFlight[name]).map((name) => inFlight[name]))
|
|
463
|
+
return snapshot()
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
return {
|
|
467
|
+
snapshot,
|
|
468
|
+
refresh,
|
|
469
|
+
dispose(): void {
|
|
470
|
+
for (const child of children) {
|
|
471
|
+
try {
|
|
472
|
+
child.kill('SIGKILL')
|
|
473
|
+
} catch {
|
|
474
|
+
/* already gone */
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
children.clear()
|
|
478
|
+
},
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* One complete assembly: every block, in parallel, with each block's own timeout. This is the
|
|
484
|
+
* one-shot path (`--print` / `--json` / the first TUI frame) and the entry the fixtures drive.
|
|
485
|
+
*/
|
|
486
|
+
export async function loadPanelData(opts: DataOptions): Promise<DataResult> {
|
|
487
|
+
const cli = opts.teamCli || findTeamCli(panelDirOf(import.meta.url))
|
|
488
|
+
if (!cli) {
|
|
489
|
+
return { ok: false, error: 'panel: cannot locate the teamsmith CLI next to the bundle (scripts/team)' }
|
|
490
|
+
}
|
|
491
|
+
const cache = createPanelCache({ ...opts, teamCli: cli })
|
|
492
|
+
const res = await cache.refresh({ force: true })
|
|
493
|
+
cache.dispose()
|
|
494
|
+
if (!res.ok) return res
|
|
495
|
+
return res
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* One patrol tick: `team watch --once`, output appended to the tick log and the log trimmed at
|
|
500
|
+
* 200 lines — the same tick (and the same trim) the bash loop performed, now owned by the run
|
|
501
|
+
* that draws the panel. Asynchronous for the same reason the readers are: a tick must not freeze
|
|
502
|
+
* the input line.
|
|
503
|
+
*/
|
|
504
|
+
export function runTick(
|
|
505
|
+
cli: string,
|
|
506
|
+
root: string,
|
|
507
|
+
tickLog: string,
|
|
508
|
+
timeoutMs = 180000,
|
|
509
|
+
): Promise<{ ok: boolean; output: string }> {
|
|
510
|
+
return new Promise((resolve) => {
|
|
511
|
+
let child: ReturnType<typeof spawn>
|
|
512
|
+
try {
|
|
513
|
+
child = spawn('bash', [cli, '--root', root, 'watch', '--once'], {
|
|
514
|
+
cwd: root,
|
|
515
|
+
env: cleanIdentityEnv(),
|
|
516
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
517
|
+
})
|
|
518
|
+
} catch (e) {
|
|
519
|
+
resolve({ ok: false, output: (e as Error).message })
|
|
520
|
+
return
|
|
521
|
+
}
|
|
522
|
+
let out = ''
|
|
523
|
+
let settled = false
|
|
524
|
+
const done = (ok: boolean): void => {
|
|
525
|
+
if (settled) return
|
|
526
|
+
settled = true
|
|
527
|
+
clearTimeout(timer)
|
|
528
|
+
try {
|
|
529
|
+
appendFileSync(tickLog, out)
|
|
530
|
+
const lines = readFileSync(tickLog, 'utf8').split('\n')
|
|
531
|
+
if (lines.length > 200) writeFileSync(tickLog, `${lines.slice(-201).join('\n')}`)
|
|
532
|
+
} catch {
|
|
533
|
+
// A tick that cannot write its log must not kill the panel; the tick's own state writes
|
|
534
|
+
// are what the contract pins.
|
|
535
|
+
}
|
|
536
|
+
resolve({ ok, output: out })
|
|
537
|
+
}
|
|
538
|
+
const timer = setTimeout(() => {
|
|
539
|
+
try {
|
|
540
|
+
child.kill('SIGKILL')
|
|
541
|
+
} catch {
|
|
542
|
+
/* already gone */
|
|
543
|
+
}
|
|
544
|
+
done(false)
|
|
545
|
+
}, timeoutMs)
|
|
546
|
+
child.stdout?.on('data', (d: Buffer) => {
|
|
547
|
+
out += String(d)
|
|
548
|
+
})
|
|
549
|
+
child.stderr?.on('data', (d: Buffer) => {
|
|
550
|
+
out += String(d)
|
|
551
|
+
})
|
|
552
|
+
child.on('error', () => done(false))
|
|
553
|
+
child.on('close', (code) => done(code === 0))
|
|
554
|
+
})
|
|
555
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Small formatters shared by the text frame and the Ink frame.
|
|
2
|
+
|
|
3
|
+
export const GLYPH: Record<string, string> = {
|
|
4
|
+
running: '●',
|
|
5
|
+
starting: '…',
|
|
6
|
+
exited: '○',
|
|
7
|
+
absent: '·',
|
|
8
|
+
foreign: '○',
|
|
9
|
+
unknown: '○',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function fmtMB(mb: number | null | undefined): string {
|
|
13
|
+
if (mb == null || Number.isNaN(mb)) return '?'
|
|
14
|
+
return mb >= 1024 ? `${(mb / 1024).toFixed(1)}G` : `${Math.round(mb)}M`
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function fmtAge(s: number | null | undefined): string {
|
|
18
|
+
if (s == null || Number.isNaN(s)) return '-'
|
|
19
|
+
if (s < 60) return `${Math.floor(s)}s`
|
|
20
|
+
if (s < 3600) return `${Math.floor(s / 60)}m`
|
|
21
|
+
return `${Math.floor(s / 3600)}h`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const SPARK = '▁▂▃▄▅▆▇█'
|
|
25
|
+
|
|
26
|
+
/** Mini chart from a series (last `width` samples); '' when there is nothing to draw. */
|
|
27
|
+
export function sparkline(values: number[], width: number): string {
|
|
28
|
+
if (!values || !values.length || width <= 0) return ''
|
|
29
|
+
const v = values.slice(-width).filter((n) => typeof n === 'number' && !Number.isNaN(n))
|
|
30
|
+
if (!v.length) return ''
|
|
31
|
+
const lo = Math.min(...v)
|
|
32
|
+
const hi = Math.max(...v)
|
|
33
|
+
const span = hi - lo || 1
|
|
34
|
+
return v
|
|
35
|
+
.map((n) => SPARK[Math.min(SPARK.length - 1, Math.floor(((n - lo) / span) * (SPARK.length - 1)))])
|
|
36
|
+
.join('')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** 'HH:MM:SS' out of the panel's timestamp (`2026-09-16T10:00:00Z`); the raw string when it does not fit. */
|
|
40
|
+
export function clockOf(timestamp: string): string {
|
|
41
|
+
const m = /T(\d{2}:\d{2}:\d{2})/.exec(timestamp || '')
|
|
42
|
+
return m ? m[1] : timestamp
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Shorten a branch name for the table (path prefixes are noise; the tail is the identity). */
|
|
46
|
+
export function shortBranch(branch: string, max: number): string {
|
|
47
|
+
if (!branch || branch === '-') return '-'
|
|
48
|
+
const b = branch.replace(/^(refs\/heads\/|task\/|agent\/)/, '')
|
|
49
|
+
return b.length > max ? `…${b.slice(b.length - (max - 1))}` : b
|
|
50
|
+
}
|