@ethlete/agent-rules 0.1.0-next.5 → 0.1.0-next.51

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 (242) hide show
  1. package/AGENTS.md +28 -0
  2. package/CHANGELOG.md +759 -0
  3. package/CLAUDE.md +1 -0
  4. package/README.md +434 -25
  5. package/THIRD-PARTY-LICENSES.md +35 -0
  6. package/content/defaults.json +1 -1
  7. package/content/git-hooks/post-checkout.sh +10 -0
  8. package/content/git-hooks/pre-push.sh +5 -0
  9. package/content/hooks/away-mode.py +327 -0
  10. package/content/hooks/background-design-commands.py +228 -0
  11. package/content/hooks/builder-idle-check.py +397 -0
  12. package/content/hooks/context-warning.py +694 -134
  13. package/content/hooks/design-live-check.py +136 -0
  14. package/content/hooks/git-safety.py +213 -0
  15. package/content/hooks/human-wait-check.py +167 -0
  16. package/content/hooks/subagent-model-policy.py +261 -0
  17. package/content/mods/.claude-plugin/marketplace.json +26 -0
  18. package/content/mods/plugins/codex-runs/.claude-plugin/plugin.json +6 -0
  19. package/content/mods/plugins/codex-runs/hooks/hooks.json +1 -0
  20. package/content/mods/plugins/codex-runs/hooks/progress.ts +130 -0
  21. package/content/mods/plugins/codex-runs/hooks/register.tsx +103 -0
  22. package/content/mods/plugins/codex-runs/tsconfig.json +4 -0
  23. package/content/mods/plugins/codex-runs/types/index.d.ts +19 -0
  24. package/content/mods/plugins/e2e-progress/.claude-plugin/plugin.json +6 -0
  25. package/content/mods/plugins/e2e-progress/hooks/hooks.json +1 -0
  26. package/content/mods/plugins/e2e-progress/hooks/progress.ts +160 -0
  27. package/content/mods/plugins/e2e-progress/hooks/register.tsx +442 -0
  28. package/content/mods/plugins/e2e-progress/tsconfig.json +3 -0
  29. package/content/mods/plugins/e2e-progress/types/index.d.ts +26 -0
  30. package/content/mods/plugins/status-line/.claude-plugin/plugin.json +6 -0
  31. package/content/mods/plugins/status-line/hooks/hooks.json +1 -0
  32. package/content/mods/plugins/status-line/hooks/line.ts +74 -0
  33. package/content/mods/plugins/status-line/hooks/register.tsx +141 -0
  34. package/content/mods/plugins/status-line/types/index.d.ts +5 -0
  35. package/content/mods/plugins/usage-line/.claude-plugin/plugin.json +6 -0
  36. package/content/mods/plugins/usage-line/hooks/codex.ts +52 -0
  37. package/content/mods/plugins/usage-line/hooks/format.ts +24 -0
  38. package/content/mods/plugins/usage-line/hooks/hooks.json +1 -0
  39. package/content/mods/plugins/usage-line/hooks/register.tsx +67 -0
  40. package/content/mods/plugins/usage-line/tsconfig.json +4 -0
  41. package/content/mods/plugins/usage-line/types/index.d.ts +5 -0
  42. package/content/output-styles/ste-clarity.md +131 -0
  43. package/content/rules/agent-sessions-wake-up.md +11 -0
  44. package/content/rules/app-styling.md +66 -0
  45. package/content/rules/comments.md +4 -1
  46. package/content/rules/lint-and-format.md +7 -5
  47. package/content/rules/nx-layout.md +53 -0
  48. package/content/rules/reactive-state.md +1 -1
  49. package/content/rules/styling.md +19 -10
  50. package/content/rules/subagent-models.md +42 -0
  51. package/content/rules/waiting-on-the-human.md +17 -0
  52. package/content/skills/agent-sessions/SKILL.md +100 -0
  53. package/content/skills/agent-sessions/agent-sessions.mjs +1420 -0
  54. package/content/skills/angular-patterns/SKILL.md +31 -7
  55. package/content/skills/api-source/SKILL.md +156 -0
  56. package/content/skills/app-testing/SKILL.md +141 -0
  57. package/content/skills/codex-subagent/SKILL.md +96 -0
  58. package/content/skills/codex-subagent/codex-agent.mjs +229 -0
  59. package/content/skills/codex-subagent/codex-limit.mjs +106 -0
  60. package/content/skills/design-exploration/SKILL.md +203 -0
  61. package/content/skills/design-exploration/check-story.mjs +139 -0
  62. package/content/skills/design-exploration/reference-check-and-notes.md +101 -0
  63. package/content/skills/design-exploration/reference-flows.md +38 -0
  64. package/content/skills/design-exploration/reference-inbox-and-mcp.md +54 -0
  65. package/content/skills/design-exploration/reference-order-and-design-system.md +120 -0
  66. package/content/skills/design-exploration/reference-products-and-sketches.md +250 -0
  67. package/content/skills/design-exploration/reference-shots.md +25 -0
  68. package/content/skills/design-exploration/shoot-template.mjs +61 -0
  69. package/content/skills/domain-modeling/CONTEXT-FORMAT.md +60 -0
  70. package/content/skills/domain-modeling/SKILL.md +71 -0
  71. package/content/skills/e2e-triage/SKILL.md +80 -0
  72. package/content/skills/figma-export/SKILL.md +16 -18
  73. package/content/skills/git-commit/SKILL.md +21 -7
  74. package/content/skills/git-flow/SKILL.md +87 -0
  75. package/content/skills/grill-with-docs/SKILL.md +13 -0
  76. package/content/skills/grilling/SKILL.md +52 -0
  77. package/content/skills/handoff/SKILL.md +29 -69
  78. package/content/skills/handoff/save.md +187 -0
  79. package/content/skills/query/SKILL.md +165 -70
  80. package/content/skills/report/SKILL.md +26 -0
  81. package/content/skills/rxjs-signals/SKILL.md +33 -4
  82. package/content/skills/sdk-docs/SKILL.md +50 -14
  83. package/content/skills/sdk-local-build/SKILL.md +26 -8
  84. package/content/skills/sdk-local-build/sdk-local-baseline.mjs +64 -0
  85. package/content/skills/sdk-source/SKILL.md +37 -34
  86. package/content/skills/sdk-update/SKILL.md +103 -0
  87. package/content/skills/story-styling/SKILL.md +12 -10
  88. package/content/skills/styleguide/SKILL.md +13 -8
  89. package/content/skills/styleguide/assets.md +54 -0
  90. package/content/skills/styleguide/changesets.md +17 -0
  91. package/content/skills/styleguide/file-structure.md +73 -0
  92. package/content/skills/styleguide/lint-rule-lookup.md +52 -0
  93. package/content/skills/styleguide/storybook-structure.md +25 -0
  94. package/content/skills/theming/SKILL.md +76 -49
  95. package/content/skills/timetrack/SKILL.md +324 -0
  96. package/content/skills/verify-in-app/SKILL.md +107 -0
  97. package/content/skills/verify-in-storybook/SKILL.md +1 -1
  98. package/migrations/list-state-query-form.md +20 -0
  99. package/migrations/nx-layout.md +29 -0
  100. package/migrations/sdk-components-over-hand-built-ui.md +27 -0
  101. package/migrations/search-query-field.md +52 -0
  102. package/migrations.json +39 -0
  103. package/package.json +19 -3
  104. package/src/index.js +99 -32
  105. package/src/index.js.map +1 -1
  106. package/src/lib/cli-args.d.ts +9 -0
  107. package/src/lib/cli-args.js +48 -0
  108. package/src/lib/cli-args.js.map +1 -0
  109. package/src/lib/commitlint.d.ts +10 -0
  110. package/src/lib/commitlint.js +51 -0
  111. package/src/lib/commitlint.js.map +1 -0
  112. package/src/lib/config.d.ts +68 -6
  113. package/src/lib/config.js +141 -11
  114. package/src/lib/config.js.map +1 -1
  115. package/src/lib/filter.d.ts +2 -0
  116. package/src/lib/filter.js +4 -4
  117. package/src/lib/filter.js.map +1 -1
  118. package/src/lib/frontmatter.d.ts +2 -0
  119. package/src/lib/frontmatter.js +33 -5
  120. package/src/lib/frontmatter.js.map +1 -1
  121. package/src/lib/git-flow/build.d.ts +35 -0
  122. package/src/lib/git-flow/build.js +24 -0
  123. package/src/lib/git-flow/build.js.map +1 -0
  124. package/src/lib/git-flow/config.d.ts +59 -0
  125. package/src/lib/git-flow/config.js +50 -0
  126. package/src/lib/git-flow/config.js.map +1 -0
  127. package/src/lib/git-flow/index.d.ts +6 -0
  128. package/src/lib/git-flow/index.js +23 -0
  129. package/src/lib/git-flow/index.js.map +1 -0
  130. package/src/lib/git-flow/parse.d.ts +49 -0
  131. package/src/lib/git-flow/parse.js +300 -0
  132. package/src/lib/git-flow/parse.js.map +1 -0
  133. package/src/lib/git-flow/rename.d.ts +24 -0
  134. package/src/lib/git-flow/rename.js +70 -0
  135. package/src/lib/git-flow/rename.js.map +1 -0
  136. package/src/lib/git-flow/start.d.ts +49 -0
  137. package/src/lib/git-flow/start.js +57 -0
  138. package/src/lib/git-flow/start.js.map +1 -0
  139. package/src/lib/git-flow/validate.d.ts +34 -0
  140. package/src/lib/git-flow/validate.js +72 -0
  141. package/src/lib/git-flow/validate.js.map +1 -0
  142. package/src/lib/git-flow-command.d.ts +4 -0
  143. package/src/lib/git-flow-command.js +165 -0
  144. package/src/lib/git-flow-command.js.map +1 -0
  145. package/src/lib/git-flow-repair.d.ts +17 -0
  146. package/src/lib/git-flow-repair.js +165 -0
  147. package/src/lib/git-flow-repair.js.map +1 -0
  148. package/src/lib/git-flow-start.d.ts +20 -0
  149. package/src/lib/git-flow-start.js +140 -0
  150. package/src/lib/git-flow-start.js.map +1 -0
  151. package/src/lib/git-test-env.fixtures.d.ts +11 -0
  152. package/src/lib/git-test-env.fixtures.js +31 -0
  153. package/src/lib/git-test-env.fixtures.js.map +1 -0
  154. package/src/lib/git.d.ts +64 -0
  155. package/src/lib/git.js +131 -0
  156. package/src/lib/git.js.map +1 -0
  157. package/src/lib/gitlab.d.ts +35 -0
  158. package/src/lib/gitlab.js +116 -0
  159. package/src/lib/gitlab.js.map +1 -0
  160. package/src/lib/index.d.ts +2 -0
  161. package/src/lib/index.js +26 -11
  162. package/src/lib/index.js.map +1 -1
  163. package/src/lib/migrate.js +8 -2
  164. package/src/lib/migrate.js.map +1 -1
  165. package/src/lib/output-style-command.d.ts +3 -0
  166. package/src/lib/output-style-command.js +69 -0
  167. package/src/lib/output-style-command.js.map +1 -0
  168. package/src/lib/output-style.d.ts +38 -0
  169. package/src/lib/output-style.js +134 -0
  170. package/src/lib/output-style.js.map +1 -0
  171. package/src/lib/owned-paths.js +8 -2
  172. package/src/lib/owned-paths.js.map +1 -1
  173. package/src/lib/package-runner.d.ts +4 -0
  174. package/src/lib/package-runner.js +86 -0
  175. package/src/lib/package-runner.js.map +1 -0
  176. package/src/lib/peer-path.d.ts +12 -0
  177. package/src/lib/peer-path.js +39 -0
  178. package/src/lib/peer-path.js.map +1 -0
  179. package/src/lib/plain-text.d.ts +9 -0
  180. package/src/lib/plain-text.js +22 -0
  181. package/src/lib/plain-text.js.map +1 -0
  182. package/src/lib/plan.d.ts +6 -6
  183. package/src/lib/plan.js +167 -39
  184. package/src/lib/plan.js.map +1 -1
  185. package/src/lib/prettier.d.ts +21 -0
  186. package/src/lib/prettier.js +51 -0
  187. package/src/lib/prettier.js.map +1 -0
  188. package/src/lib/prompt.d.ts +8 -0
  189. package/src/lib/prompt.js +35 -0
  190. package/src/lib/prompt.js.map +1 -0
  191. package/src/lib/render.d.ts +26 -2
  192. package/src/lib/render.js +45 -10
  193. package/src/lib/render.js.map +1 -1
  194. package/src/lib/report-command.d.ts +34 -0
  195. package/src/lib/report-command.js +316 -0
  196. package/src/lib/report-command.js.map +1 -0
  197. package/src/lib/sessions-command.d.ts +4 -0
  198. package/src/lib/sessions-command.js +16 -0
  199. package/src/lib/sessions-command.js.map +1 -0
  200. package/src/lib/sync.d.ts +1 -2
  201. package/src/lib/sync.js +37 -17
  202. package/src/lib/sync.js.map +1 -1
  203. package/src/lib/targets/agents-skills.js +1 -1
  204. package/src/lib/targets/agents-skills.js.map +1 -1
  205. package/src/lib/targets/claude-hooks.d.ts +5 -0
  206. package/src/lib/targets/claude-hooks.js +27 -4
  207. package/src/lib/targets/claude-hooks.js.map +1 -1
  208. package/src/lib/targets/claude-mods.d.ts +20 -0
  209. package/src/lib/targets/claude-mods.js +47 -0
  210. package/src/lib/targets/claude-mods.js.map +1 -0
  211. package/src/lib/targets/claude.js +2 -3
  212. package/src/lib/targets/claude.js.map +1 -1
  213. package/src/lib/targets/codex-hooks.js +4 -2
  214. package/src/lib/targets/codex-hooks.js.map +1 -1
  215. package/src/lib/targets/codex.js +4 -4
  216. package/src/lib/targets/codex.js.map +1 -1
  217. package/src/lib/targets/copilot.js +4 -4
  218. package/src/lib/targets/copilot.js.map +1 -1
  219. package/src/lib/targets/cursor.js +3 -3
  220. package/src/lib/targets/cursor.js.map +1 -1
  221. package/src/lib/targets/git-hooks.d.ts +25 -0
  222. package/src/lib/targets/git-hooks.js +71 -0
  223. package/src/lib/targets/git-hooks.js.map +1 -0
  224. package/src/lib/targets/hooks-shared.d.ts +29 -5
  225. package/src/lib/targets/hooks-shared.js +130 -36
  226. package/src/lib/targets/hooks-shared.js.map +1 -1
  227. package/src/lib/targets/mcp.d.ts +16 -0
  228. package/src/lib/targets/mcp.js +72 -0
  229. package/src/lib/targets/mcp.js.map +1 -0
  230. package/src/lib/targets/shared.d.ts +1 -9
  231. package/src/lib/targets/shared.js +4 -8
  232. package/src/lib/targets/shared.js.map +1 -1
  233. package/src/lib/timetrack-command.d.ts +11 -0
  234. package/src/lib/timetrack-command.js +1262 -0
  235. package/src/lib/timetrack-command.js.map +1 -0
  236. package/src/lib/timetrack-snapshot.d.ts +66 -0
  237. package/src/lib/timetrack-snapshot.js +146 -0
  238. package/src/lib/timetrack-snapshot.js.map +1 -0
  239. package/src/lib/timetrack.d.ts +607 -0
  240. package/src/lib/timetrack.js +285 -0
  241. package/src/lib/timetrack.js.map +1 -0
  242. package/content/skills/styleguide/STYLEGUIDE.md +0 -520
@@ -0,0 +1,160 @@
1
+ import type { Progress } from '../types';
2
+
3
+ export const count = (text: string, re: RegExp) => (text.match(re) ?? []).length;
4
+ export const summary = (text: string, word: string) => {
5
+ const hit = text.match(new RegExp(`^\\s+(\\d+) ${word}\\b`, 'm'));
6
+ return hit ? Number(hit[1]) : undefined;
7
+ };
8
+
9
+ export const doneOf = (p: Progress) => p.passed + p.failed + p.skipped;
10
+
11
+ const FAIL_LISTED = /(?:✘|^\s+x)\s+\d+\s+\[/;
12
+ export const FAIL_LINE = /(?:✘|^\s+x)\s+\d+\s+\[[^\]]+\]\s+›\s+(\S+?):(\d+):\d+\s+›\s+(.*)$/;
13
+
14
+ export const parse = (
15
+ path: string,
16
+ text: string,
17
+ expected: Set<string>,
18
+ mtimeMs: number,
19
+ nowMs: number,
20
+ last: Progress | null,
21
+ ): Progress => {
22
+ const isDone = /^\s+\d+ (passed|failed|did not run)\b/m.test(text) || /^EXIT \d+/m.test(text);
23
+ const lines = text.split('\n');
24
+ const listFailures = lines
25
+ .filter((line) => FAIL_LISTED.test(line) && !expected.has(line))
26
+ .map((line) => line.replace(/^(?:.*?✘|\s+x)\s+\d+\s+\[[^\]]+\]\s+›\s+/, '').replace(/\s+@\S+.*$/, ''));
27
+ const lineFailures = new Map<string, string>();
28
+ for (const line of lines) {
29
+ const hit = line.match(/^\s+(\d+)\) \[[^\]]+\] › (.*)$/);
30
+ if (hit?.[1] && hit[2]) lineFailures.set(hit[1], hit[2].replace(/\s+@\S+.*$/, '').replace(/\s*─+\s*$/, ''));
31
+ }
32
+ const failures = isDone && lineFailures.size > 0 ? [...lineFailures.values()] : listFailures;
33
+ const started = Math.max(0, ...[...text.matchAll(/^\[(\d+)\/\d+\]/gm)].map((m) => Number(m[1])));
34
+ const ticks = count(text, /✓/g) + count(text, /^\s+ok\s+\d+\s+\[/gm);
35
+ const p = {
36
+ path,
37
+ kind: 'e2e' as const,
38
+ total: Number(text.match(/Running (\d+) tests?/)?.[1] ?? 0),
39
+ passed: summary(text, 'passed') ?? (ticks > 0 ? ticks + expected.size : Math.max(0, started - failures.length)),
40
+ failed: summary(text, 'failed') ?? failures.length,
41
+ skipped: summary(text, 'skipped') ?? (ticks > 0 ? count(text, /^\s+-\s+\d+\s/gm) : 0),
42
+ flaky: summary(text, 'flaky') ?? 0,
43
+ didNotRun: summary(text, 'did not run') ?? 0,
44
+ workers: Number(text.match(/Running \d+ tests? using (\d+) workers?/)?.[1] ?? 1),
45
+ duration: text.match(/^\s+\d+ passed \(([^)]+)\)/m)?.[1],
46
+ expected: expected.size,
47
+ isDone,
48
+ failures,
49
+ mtimeMs,
50
+ firstSeenMs: nowMs,
51
+ firstDone: 0,
52
+ };
53
+ const isSameRun =
54
+ last !== null &&
55
+ last.path === path &&
56
+ !last.isDone &&
57
+ Number.isFinite(last.firstSeenMs) &&
58
+ Number.isFinite(last.firstDone) &&
59
+ doneOf(p) >= last.firstDone;
60
+ return isSameRun
61
+ ? { ...p, firstSeenMs: last.firstSeenMs, firstDone: last.firstDone }
62
+ : { ...p, firstDone: doneOf(p) };
63
+ };
64
+
65
+ const ANSI = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, 'g');
66
+ const numberAfter = (text: string, re: RegExp) => {
67
+ const hit = text.match(re);
68
+ return hit ? Number(hit[1]) : undefined;
69
+ };
70
+ const sumOf = (text: string, re: RegExp) => [...text.matchAll(re)].reduce((n, m) => n + Number(m[1]), 0);
71
+
72
+ export const parseUnit = (path: string, raw: string, mtimeMs: number, nowMs: number, isEnded: boolean): Progress => {
73
+ const text = raw.replace(ANSI, '');
74
+ const vitest = text.match(/^\s*Tests\s+(.*)\((\d+)\)\s*$/m);
75
+ const nodeTotal = numberAfter(text, /^[ℹ#] tests (\d+)/m);
76
+ const passed = vitest
77
+ ? (numberAfter(vitest[1] ?? '', /(\d+) passed/) ?? 0)
78
+ : (numberAfter(text, /^[ℹ#] pass (\d+)/m) ??
79
+ sumOf(text, /^\s*✓ .*\((\d+) tests?\)/gm) + count(text, /^(?:✔ .*\([\d.]+m?s\)$|ok \d+ )/gm));
80
+ const failed = vitest
81
+ ? (numberAfter(vitest[1] ?? '', /(\d+) failed/) ?? 0)
82
+ : (numberAfter(text, /^[ℹ#] fail (\d+)/m) ?? count(text, /^(?:✖ .*\([\d.]+m?s\)$|not ok \d+ |\s*FAIL\s)/gm));
83
+ const skipped = vitest
84
+ ? (numberAfter(vitest[1] ?? '', /(\d+) skipped/) ?? 0)
85
+ : (numberAfter(text, /^[ℹ#] skipped (\d+)/m) ?? 0);
86
+ const failures = [
87
+ ...new Set(
88
+ [...text.matchAll(/^(?:✖ (?!failing tests)|not ok \d+ - |\s*FAIL\s+)(.+?)(?: \([\d.]+m?s\))?$/gm)].map((m) =>
89
+ (m[1] ?? '').trim(),
90
+ ),
91
+ ),
92
+ ];
93
+ const total = vitest ? Number(vitest[2]) : (nodeTotal ?? 0);
94
+ return {
95
+ path,
96
+ kind: 'unit',
97
+ total,
98
+ passed,
99
+ failed,
100
+ skipped,
101
+ flaky: 0,
102
+ didNotRun: 0,
103
+ workers: 1,
104
+ duration: text.match(/^\s*Duration\s+(\S+)/m)?.[1],
105
+ expected: 0,
106
+ isDone: isEnded || vitest !== null || nodeTotal !== undefined,
107
+ failures,
108
+ mtimeMs,
109
+ firstSeenMs: nowMs,
110
+ firstDone: 0,
111
+ };
112
+ };
113
+
114
+ export const REGISTRY = '/tmp/ethlete-runs';
115
+ export const HIDE_AFTER_MS = 60_000;
116
+
117
+ type RegistryFileSystem = {
118
+ list(path: string): Promise<{ name: string; kind: string }[]>;
119
+ read(path: string): Promise<string>;
120
+ stat(path: string): Promise<{ mtimeMs: number }>;
121
+ };
122
+
123
+ type RegistryEntry = {
124
+ log: string;
125
+ machine: string;
126
+ label: string;
127
+ pid: number;
128
+ cwd?: string;
129
+ sessionId?: string;
130
+ endedAt?: number;
131
+ };
132
+ export type RegistryRun = { entry: RegistryEntry; mtimeMs: number };
133
+
134
+ type RegistryScope = { nowMs: number; projectRoot: string; sessionId: string };
135
+
136
+ export async function registryRuns(
137
+ fs: RegistryFileSystem,
138
+ { nowMs, projectRoot, sessionId }: RegistryScope,
139
+ ): Promise<RegistryRun[]> {
140
+ const root = projectRoot.replace(/\/+$/, '');
141
+ const files = await fs.list(REGISTRY).catch(() => []);
142
+ const found = await Promise.all(
143
+ files
144
+ .filter((f) => f.kind === 'file' && f.name.endsWith('.json'))
145
+ .map(async (f): Promise<RegistryRun | undefined> => {
146
+ const entry = await fs.read(`${REGISTRY}/${f.name}`).then(
147
+ (t) => JSON.parse(t) as RegistryEntry,
148
+ () => undefined,
149
+ );
150
+ if (!entry?.log || typeof entry.cwd !== 'string' || entry.sessionId !== sessionId) return undefined;
151
+ if (entry.cwd !== root && !entry.cwd.startsWith(`${root}/`)) return undefined;
152
+ if (entry.endedAt === undefined && !(await fs.stat(`/proc/${entry.pid}`).catch(() => undefined)))
153
+ return undefined;
154
+ if (entry.endedAt !== undefined && nowMs - entry.endedAt > HIDE_AFTER_MS) return undefined;
155
+ const stat = await fs.stat(entry.log).catch(() => undefined);
156
+ return { entry, mtimeMs: stat?.mtimeMs ?? 0 };
157
+ }),
158
+ );
159
+ return found.filter((r) => r !== undefined);
160
+ }
@@ -0,0 +1,442 @@
1
+ import { atom, read, update } from 'claude-code';
2
+ import type { EngineInterface, Register, Timer } from 'claude-code';
3
+
4
+ import type { Progress } from '../types';
5
+ import { FAIL_LINE, HIDE_AFTER_MS, REGISTRY, doneOf, parse, parseUnit, registryRuns, summary } from './progress';
6
+ import type { RegistryRun } from './progress';
7
+
8
+ const PANE = 'e2e-progress';
9
+ const HANDOFFS = ['.claude/handoffs', '.agents/handoffs'];
10
+ const WORKTREES = '.claude/worktrees';
11
+ const TICK_MS = 5000;
12
+ const STALE_MS = 15_000;
13
+ const MIN_ETA_TESTS = 5;
14
+ const MIN_ETA_MS = 30_000;
15
+ const MAX_CANDIDATES = 12;
16
+ const STALLED_MS = 15 * 60_000;
17
+ const runs = atom({ plugin: 'e2e-progress', key: 'runs' } as const, []);
18
+ const pinnedPath = atom({ plugin: 'e2e-progress', key: 'path' } as const, null);
19
+
20
+ const TEST_DECLARATION = /\btest(\.\w+)?\(/;
21
+ const indentOf = (line: string) => line.length - line.trimStart().length;
22
+
23
+ const titleOf = (rest: string) =>
24
+ (
25
+ rest
26
+ .replace(/\s+@\S+.*$/, '')
27
+ .replace(/\s+\([\d.]+m?s\)$/, '')
28
+ .split(' › ')
29
+ .pop() ?? ''
30
+ ).trim();
31
+
32
+ const declaresAt = (source: string[], index: number, title: string) => {
33
+ if (!TEST_DECLARATION.test(source[index] ?? '')) return false;
34
+ const head = source.slice(index, index + 3).join('\n');
35
+ return head.includes(title.slice(0, 25)) || head.includes('`');
36
+ };
37
+
38
+ const callsTestFail = (source: string[], index: number) => {
39
+ const declaration = source[index] ?? '';
40
+ if (/\btest\.fail\(/.test(declaration)) return true;
41
+ const indent = indentOf(declaration);
42
+ for (const line of source.slice(index + 1)) {
43
+ if (line.trim() !== '' && indentOf(line) <= indent && !/=>\s*\{\s*$/.test(line)) return false;
44
+ if (/\btest\.fail\(/.test(line)) return true;
45
+ }
46
+ return false;
47
+ };
48
+
49
+ const sourceCache = new Map<string, string[] | null>();
50
+
51
+ async function sourceOf($: EngineInterface, path: string) {
52
+ if (!sourceCache.has(path))
53
+ sourceCache.set(
54
+ path,
55
+ await $.fs.read(path).then(
56
+ (t) => t.split('\n'),
57
+ () => null,
58
+ ),
59
+ );
60
+ return sourceCache.get(path) ?? null;
61
+ }
62
+
63
+ async function rootsFor($: EngineInterface, logPath: string) {
64
+ const at = Math.max(...HANDOFFS.map((dir) => logPath.indexOf(dir)));
65
+ const own = at > 0 ? logPath.slice(0, at) : '';
66
+ const worktrees = await $.fs.list(WORKTREES).catch(() => []);
67
+ const all = [own, '', ...worktrees.filter((d) => d.kind === 'dir').map((d) => `${WORKTREES}/${d.name}/`)];
68
+ return [...new Set(all)];
69
+ }
70
+
71
+ async function expectedFailures($: EngineInterface, logPath: string, text: string) {
72
+ const expected = new Set<string>();
73
+ const failLines = text.split('\n').filter((line) => FAIL_LINE.test(line));
74
+ if (failLines.length === 0) return expected;
75
+ const roots = await rootsFor($, logPath);
76
+ for (const line of failLines) {
77
+ const [, file = '', lineNo = '0', rest = ''] = line.match(FAIL_LINE) ?? [];
78
+ const index = Number(lineNo) - 1;
79
+ const title = titleOf(rest);
80
+ for (const root of roots) {
81
+ const source = await sourceOf($, `${root}${file}`);
82
+ if (source === null || !declaresAt(source, index, title)) continue;
83
+ if (callsTestFail(source, index)) expected.add(line);
84
+ break;
85
+ }
86
+ }
87
+ return expected;
88
+ }
89
+
90
+ const FAILURES_FILE_LINE = /^\[failure-reporter\] Writing failures to (.+)$/m;
91
+
92
+ type FailureRecord = { test: string; location: string; error?: string; detail?: string | null };
93
+
94
+ const recordsOf = (text: string): FailureRecord[] =>
95
+ text.split('\n').flatMap((line) => {
96
+ if (line.trim() === '') return [];
97
+ try {
98
+ const record = JSON.parse(line);
99
+ return typeof record?.test === 'string' && typeof record?.location === 'string' ? [record] : [];
100
+ } catch {
101
+ return [];
102
+ }
103
+ });
104
+
105
+ const firstErrorLine = (error: string | undefined) =>
106
+ (error ?? '')
107
+ .split('\n')
108
+ .find((line) => line.trim() !== '')
109
+ ?.replace(/^Error:\s*/, '')
110
+ .trim() ?? '';
111
+
112
+ const failuresOf = (records: FailureRecord[]) => {
113
+ const latest = new Map<string, FailureRecord>();
114
+ for (const record of records) latest.set(`${record.location} › ${record.test}`, record);
115
+ return [...latest].map(([key, record]) => {
116
+ const error = firstErrorLine(record.error);
117
+ const line = error ? `${key} — ${error}` : key;
118
+ return record.detail ? `${line} (${record.detail})` : line;
119
+ });
120
+ };
121
+
122
+ async function withRecords($: EngineInterface, p: Progress, text: string): Promise<Progress> {
123
+ const file = text.match(FAILURES_FILE_LINE)?.[1]?.trim();
124
+ if (!file) return p;
125
+ const records = await $.fs.read(file).then(recordsOf, () => undefined);
126
+ if (records === undefined) return p;
127
+ const failures = failuresOf(records);
128
+ return { ...p, failures, failed: summary(text, 'failed') ?? failures.length };
129
+ }
130
+
131
+ const remainingMs = (p: Progress, nowMs: number) => {
132
+ const doneSince = doneOf(p) - p.firstDone;
133
+ const elapsed = nowMs - p.firstSeenMs;
134
+ if (p.isDone || p.total <= 0 || doneSince < MIN_ETA_TESTS || elapsed < MIN_ETA_MS) return undefined;
135
+ return ((p.total - doneOf(p)) / doneSince) * elapsed;
136
+ };
137
+
138
+ const formatEta = (ms: number | undefined) => {
139
+ if (ms === undefined) return '';
140
+ const minutes = Math.round(ms / 60_000);
141
+ return minutes < 1 ? ' ~<1m left' : ` ~${minutes}m left`;
142
+ };
143
+
144
+ type LogFile = { path: string; mtimeMs: number };
145
+
146
+ async function logsUnder($: EngineInterface, dir: string, depth: number): Promise<LogFile[]> {
147
+ const entries = await $.fs.list(dir).catch(() => []);
148
+ const files = entries
149
+ .filter((f) => f.kind === 'file' && f.name.endsWith('.log'))
150
+ .map((f) => ({ path: `${dir}/${f.name}`, mtimeMs: f.mtimeMs }));
151
+ if (depth === 0) return files;
152
+ const nested = await Promise.all(
153
+ entries.filter((d) => d.kind === 'dir').map((d) => logsUnder($, `${dir}/${d.name}`, depth - 1)),
154
+ );
155
+ return [...files, ...nested.flat()];
156
+ }
157
+
158
+ async function baseDirs($: EngineInterface) {
159
+ const bases = new Set([await $.session.root()]);
160
+ let dir = await $.session.cwd();
161
+ for (let up = 0; up <= 3 && dir !== ''; up++) {
162
+ bases.add(dir);
163
+ dir = dir.slice(0, dir.lastIndexOf('/'));
164
+ }
165
+ return [...bases];
166
+ }
167
+
168
+ async function handoffDirs($: EngineInterface) {
169
+ const perBase = await Promise.all(
170
+ (await baseDirs($)).map(async (base) => {
171
+ const worktrees = await $.fs.list(`${base}/${WORKTREES}`).catch(() => []);
172
+ const roots = [base, ...worktrees.filter((d) => d.kind === 'dir').map((d) => `${base}/${WORKTREES}/${d.name}`)];
173
+ return roots.flatMap((root) => HANDOFFS.map((dir) => `${root}/${dir}`));
174
+ }),
175
+ );
176
+ return perBase.flat();
177
+ }
178
+
179
+ const nameOf = (path: string) => (path.split('/').pop() ?? path).replace(/\.log$/, '');
180
+
181
+ const MAX_LABEL = 40;
182
+ const shortLabel = (label: string) => {
183
+ const words = label
184
+ .split(/\s+/)
185
+ .filter((w) => !/^(npx|yarn|node|sh|-c|--)$/.test(w) && !w.includes('='))
186
+ .map((w) => (w.includes('/') ? (w.split('/').pop() ?? w) : w))
187
+ .join(' ');
188
+ return words.length > MAX_LABEL ? `${words.slice(0, MAX_LABEL - 1)}…` : words;
189
+ };
190
+ const titleOfRun = (p: Progress) =>
191
+ `${p.machine ? `${p.machine} ` : ''}${p.label ? shortLabel(p.label) : nameOf(p.path)}`;
192
+
193
+ async function progressOfRegistryRun(
194
+ $: EngineInterface,
195
+ { entry, mtimeMs }: RegistryRun,
196
+ previous: Progress | undefined,
197
+ nowMs: number,
198
+ ): Promise<Progress> {
199
+ const isEnded = entry.endedAt !== undefined;
200
+ const tag = { machine: entry.machine, label: entry.label };
201
+ if (previous?.mtimeMs === mtimeMs && previous.isDone === isEnded) return { ...previous, ...tag };
202
+ const text = mtimeMs === 0 ? '' : await $.fs.read(entry.log).catch(() => '');
203
+ if (isRunLog(text)) {
204
+ sourceCache.clear();
205
+ const parsed = parse(entry.log, text, await expectedFailures($, entry.log, text), mtimeMs, nowMs, previous ?? null);
206
+ return { ...(await withRecords($, parsed, text)), isDone: parsed.isDone || isEnded, ...tag };
207
+ }
208
+ const unit = parseUnit(entry.log, text, mtimeMs, nowMs, isEnded);
209
+ return {
210
+ ...unit,
211
+ firstSeenMs: previous?.firstSeenMs ?? nowMs,
212
+ mtimeMs: isEnded ? (entry.endedAt ?? mtimeMs) : mtimeMs,
213
+ ...tag,
214
+ };
215
+ }
216
+
217
+ const isRunLog = (text: string) => /^Running \d+ tests?/m.test(text);
218
+
219
+ const notRunLogs = new Map<string, number>();
220
+
221
+ async function candidateLogs($: EngineInterface) {
222
+ const perDir = await Promise.all((await handoffDirs($)).map((dir) => logsUnder($, dir, 2)));
223
+ const unique = new Map(perDir.flat().map((log) => [log.path, log]));
224
+ return [...unique.values()].sort((a, b) => b.mtimeMs - a.mtimeMs).slice(0, MAX_CANDIDATES);
225
+ }
226
+
227
+ async function newestLog($: EngineInterface) {
228
+ for (const log of await candidateLogs($)) {
229
+ if (isRunLog(await $.fs.read(log.path).catch(() => ''))) return log;
230
+ }
231
+ return undefined;
232
+ }
233
+
234
+ async function pinnedLog($: EngineInterface): Promise<LogFile | undefined> {
235
+ const pinned = await read($, pinnedPath);
236
+ if (pinned === null) return undefined;
237
+ const stat = await $.fs.stat(pinned).catch(() => undefined);
238
+ const newest = await newestLog($);
239
+ if (newest !== undefined && newest.path !== pinned && (stat === undefined || newest.mtimeMs > stat.mtimeMs)) {
240
+ await update($, pinnedPath, () => null);
241
+ return undefined;
242
+ }
243
+ return stat === undefined ? undefined : { path: pinned, mtimeMs: stat.mtimeMs };
244
+ }
245
+
246
+ const isVisible = (p: Progress, nowMs: number) =>
247
+ p.isDone ? nowMs - p.mtimeMs <= HIDE_AFTER_MS : nowMs - p.mtimeMs <= STALLED_MS;
248
+
249
+ let isHidden = false;
250
+ let timer: Timer | undefined;
251
+ let lastTickMs = 0;
252
+ let shownStatus: string | undefined | null = null;
253
+
254
+ function setStatus($: EngineInterface, text: string | undefined) {
255
+ if (text === shownStatus) return;
256
+ shownStatus = text;
257
+ $.ui.status(text);
258
+ }
259
+
260
+ const unitStatusOf = (p: Progress) =>
261
+ `${titleOfRun(p)} ${p.isDone ? 'done' : p.passed + p.failed === 0 ? 'running' : `${p.passed + p.failed}${p.total ? `/${p.total}` : ''}`} ✓${p.passed} ✘${p.failed}`;
262
+
263
+ const statusOf = (p: Progress, nowMs: number) =>
264
+ p.kind === 'unit'
265
+ ? unitStatusOf(p)
266
+ : `${titleOfRun(p)} w${p.workers} ${p.isDone ? `done ${p.duration ?? ''}`.trim() : `${doneOf(p)}/${p.total}`} ✓${p.passed} ✘${p.failed}` +
267
+ `${p.flaky ? ` ~${p.flaky}` : ''}${p.skipped ? ` -${p.skipped}` : ''}${p.didNotRun ? ` ⊘${p.didNotRun}` : ''}${formatEta(remainingMs(p, nowMs))}`;
268
+
269
+ async function tick($: EngineInterface) {
270
+ const nowMs = await $.clock.now();
271
+ const pinned = await pinnedLog($);
272
+ const logs = pinned ? [pinned] : await candidateLogs($);
273
+ const last = new Map((await read($, runs)).map((p) => [p.path, p]));
274
+ const next: Progress[] = [];
275
+ for (const log of logs) {
276
+ const previous = last.get(log.path);
277
+ if (previous?.mtimeMs === log.mtimeMs) {
278
+ next.push(previous);
279
+ continue;
280
+ }
281
+ if (notRunLogs.get(log.path) === log.mtimeMs) continue;
282
+ const text = await $.fs.read(log.path).catch(() => '');
283
+ if (!isRunLog(text)) {
284
+ notRunLogs.set(log.path, log.mtimeMs);
285
+ continue;
286
+ }
287
+ sourceCache.clear();
288
+ const parsed = parse(
289
+ log.path,
290
+ text,
291
+ await expectedFailures($, log.path, text),
292
+ log.mtimeMs,
293
+ nowMs,
294
+ previous ?? null,
295
+ );
296
+ next.push(await withRecords($, parsed, text));
297
+ }
298
+ if (!pinned) {
299
+ const [root, sessionId] = await Promise.all([$.session.root(), $.session.id()]);
300
+ const stat = await $.fs.stat(root, { resolve: true }).catch(() => undefined);
301
+ const projectRoot = stat?.realPath ?? root;
302
+ const known = new Set(next.map((p) => p.path));
303
+ for (const run of await registryRuns(
304
+ {
305
+ list: (path) => $.fs.list(path),
306
+ read: (path) => $.fs.read(path),
307
+ stat: (path) => $.fs.stat(path),
308
+ },
309
+ { nowMs, projectRoot, sessionId },
310
+ )) {
311
+ if (known.has(run.entry.log)) continue;
312
+ next.push(await progressOfRegistryRun($, run, last.get(run.entry.log), nowMs));
313
+ }
314
+ }
315
+ const visible = next.filter((p) => isVisible(p, nowMs)).sort((a, b) => a.path.localeCompare(b.path));
316
+ await update($, runs, () => visible);
317
+
318
+ if (visible.length === 0) {
319
+ setStatus($, undefined);
320
+ if (!isHidden) {
321
+ isHidden = true;
322
+ await $.ui.close({ id: PANE }).catch(() => undefined);
323
+ }
324
+ return;
325
+ }
326
+
327
+ isHidden = false;
328
+ setStatus($, `runs ${visible.map((p) => statusOf(p, nowMs)).join(' │ ')}`);
329
+ }
330
+
331
+ async function run($: EngineInterface) {
332
+ lastTickMs = await $.clock.now();
333
+ try {
334
+ await tick($);
335
+ } catch (error) {
336
+ setStatus($, `e2e-progress failed: ${String(error)}`);
337
+ }
338
+ }
339
+
340
+ function start($: EngineInterface) {
341
+ timer?.cancel();
342
+ timer = $.clock.every(TICK_MS, () => run($));
343
+ }
344
+
345
+ async function revive($: EngineInterface) {
346
+ if ((await $.clock.now()) - lastTickMs < STALE_MS) return;
347
+ start($);
348
+ await run($);
349
+ }
350
+
351
+ export const register: Register = (on) => {
352
+ on('session.start', async ($, e, next) => {
353
+ await $.command.register({
354
+ name: 'e2e',
355
+ description:
356
+ 'Show e2e run progress. Optional arg: a log path to pin; "auto" removes the pin; "off" clears the status',
357
+ });
358
+ start($);
359
+ return next(e);
360
+ });
361
+
362
+ on('prompt.submit', async ($, e, next) => {
363
+ await revive($);
364
+ return next(e);
365
+ });
366
+
367
+ on('tool.call', async ($, e, next) => {
368
+ await revive($);
369
+ return next(e);
370
+ });
371
+
372
+ on('turn.complete', async ($, e, next) => {
373
+ await revive($);
374
+ return next(e);
375
+ });
376
+
377
+ on('command.run', { command: 'e2e' }, async ($, e) => {
378
+ const arg = e.args.trim();
379
+ if (arg === 'off') {
380
+ setStatus($, undefined);
381
+ return { text: 'e2e status cleared until the log changes.' };
382
+ }
383
+ if (arg === 'auto') {
384
+ await update($, pinnedPath, () => null);
385
+ start($);
386
+ await run($);
387
+ return { text: `Pin removed. Watching the newest logs under ${HANDOFFS.join(' and ')}.` };
388
+ }
389
+ if (arg !== '') await update($, pinnedPath, () => arg);
390
+ start($);
391
+ await $.ui.open({ id: PANE, title: 'E2E progress' });
392
+ return { text: arg ? `Watching ${arg}.` : 'E2E progress pane opened.' };
393
+ });
394
+
395
+ on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
396
+ const { Box, Text } = $.ui.resolve(e);
397
+ const shown = await read($, runs);
398
+ if (shown.length === 0)
399
+ return (
400
+ <Text dimColor>
401
+ No active run in {REGISTRY} and no run log under {HANDOFFS.join(' or ')}, also in {WORKTREES}/*.
402
+ </Text>
403
+ );
404
+
405
+ const nowMs = await $.clock.now();
406
+ const room = Math.max(1, Math.floor(((e.viewport?.rows ?? 24) - 6 * shown.length) / shown.length));
407
+ return (
408
+ <Box flexDirection="column">
409
+ {shown.map((p) => {
410
+ const done = doneOf(p);
411
+ return (
412
+ <Box flexDirection="column" marginBottom={1}>
413
+ <Text bold>
414
+ {titleOfRun(p)} <Text dimColor>· {p.kind === 'unit' ? 'unit' : `${p.workers} workers`}</Text>
415
+ </Text>
416
+ <Text dimColor wrap="truncate-start">
417
+ {p.path}
418
+ </Text>
419
+ <Text>
420
+ {p.isDone ? `finished in ${p.duration ?? '?'}` : p.total > 0 ? `${done} / ${p.total}` : `${done} done`}
421
+ {p.total > 0 && !p.isDone ? ` (${Math.round((done / p.total) * 100)}%)` : ''}
422
+ {formatEta(remainingMs(p, nowMs))}
423
+ </Text>
424
+ <Text>
425
+ <Text color="green">✓ {p.passed}</Text> <Text color="red">✘ {p.failed}</Text>{' '}
426
+ <Text dimColor>- {p.skipped} skipped</Text>
427
+ {p.didNotRun > 0 ? <Text color="yellow"> ⊘ {p.didNotRun} did not run</Text> : ''}
428
+ {p.flaky > 0 ? <Text color="yellow"> ~ {p.flaky} flaky</Text> : ''}
429
+ </Text>
430
+ {p.expected > 0 && <Text dimColor>{p.expected} expected failures (test.fail) counted as passed</Text>}
431
+ {p.failures.slice(-room).map((f) => (
432
+ <Text color="red" wrap="truncate-end">
433
+ ✘ {f}
434
+ </Text>
435
+ ))}
436
+ </Box>
437
+ );
438
+ })}
439
+ </Box>
440
+ );
441
+ });
442
+ };
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "./.claude-plugin/types/tsconfig.json"
3
+ }
@@ -0,0 +1,26 @@
1
+ export type Progress = {
2
+ path: string;
3
+ kind: 'e2e' | 'unit';
4
+ machine?: string;
5
+ label?: string;
6
+ total: number;
7
+ passed: number;
8
+ failed: number;
9
+ skipped: number;
10
+ flaky: number;
11
+ didNotRun: number;
12
+ workers: number;
13
+ duration: string | undefined;
14
+ expected: number;
15
+ isDone: boolean;
16
+ failures: string[];
17
+ mtimeMs: number;
18
+ firstSeenMs: number;
19
+ firstDone: number;
20
+ };
21
+
22
+ declare module 'claude-code' {
23
+ interface PluginState {
24
+ 'e2e-progress': { runs: Progress[]; path: string | null };
25
+ }
26
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "status-line",
3
+ "version": "0.1.0-next.51",
4
+ "description": "Always-visible band with the running task, its duration, the open queue, open questions and a CI blocked mark",
5
+ "types": "./types/index.d.ts"
6
+ }
@@ -0,0 +1 @@
1
+ { "modules": ["./register.tsx"] }