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

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 (61) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +16 -53
  3. package/content/hooks/away-mode.py +90 -7
  4. package/content/hooks/{background-design-commands.py → background-commands.py} +14 -65
  5. package/content/hooks/builder-idle-check.py +146 -15
  6. package/content/mods/plugins/codex-runs/.claude-plugin/plugin.json +1 -1
  7. package/content/mods/plugins/codex-runs/hooks/agent-runs.ts +310 -0
  8. package/content/mods/plugins/codex-runs/hooks/register.tsx +171 -12
  9. package/content/mods/plugins/codex-runs/types/index.d.ts +18 -0
  10. package/content/mods/plugins/e2e-progress/.claude-plugin/plugin.json +1 -1
  11. package/content/mods/plugins/status-line/.claude-plugin/plugin.json +1 -1
  12. package/content/mods/plugins/usage-line/.claude-plugin/plugin.json +1 -1
  13. package/content/mods/plugins/usage-line/hooks/rate-limits.ts +23 -0
  14. package/content/mods/plugins/usage-line/hooks/register.tsx +16 -0
  15. package/content/skills/agent-sessions/SKILL.md +1 -1
  16. package/content/skills/codex-subagent/SKILL.md +8 -2
  17. package/content/skills/codex-subagent/codex-agent.mjs +33 -2
  18. package/content/skills/design-exploration/SKILL.md +22 -104
  19. package/content/skills/design-exploration/reference-shots.md +1 -11
  20. package/content/skills/handoff/SKILL.md +2 -0
  21. package/content/skills/handoff/save.md +2 -0
  22. package/migrations/studio-claude-plugin.md +27 -0
  23. package/migrations.json +8 -0
  24. package/package.json +1 -1
  25. package/src/index.js +0 -6
  26. package/src/index.js.map +1 -1
  27. package/src/lib/config.d.ts +4 -7
  28. package/src/lib/config.js +12 -9
  29. package/src/lib/config.js.map +1 -1
  30. package/src/lib/filter.d.ts +1 -0
  31. package/src/lib/filter.js +3 -1
  32. package/src/lib/filter.js.map +1 -1
  33. package/src/lib/plan.js +6 -3
  34. package/src/lib/plan.js.map +1 -1
  35. package/src/lib/report-command.js +8 -2
  36. package/src/lib/report-command.js.map +1 -1
  37. package/src/lib/targets/hooks-shared.d.ts +5 -0
  38. package/src/lib/targets/hooks-shared.js +12 -10
  39. package/src/lib/targets/hooks-shared.js.map +1 -1
  40. package/src/lib/targets/mcp.d.ts +10 -1
  41. package/src/lib/targets/mcp.js +43 -1
  42. package/src/lib/targets/mcp.js.map +1 -1
  43. package/src/lib/timetrack.d.ts +0 -591
  44. package/src/lib/timetrack.js +3 -139
  45. package/src/lib/timetrack.js.map +1 -1
  46. package/content/hooks/design-live-check.py +0 -136
  47. package/content/skills/design-exploration/reference-check-and-notes.md +0 -101
  48. package/content/skills/design-exploration/reference-flows.md +0 -38
  49. package/content/skills/design-exploration/reference-inbox-and-mcp.md +0 -54
  50. package/content/skills/design-exploration/reference-order-and-design-system.md +0 -120
  51. package/content/skills/design-exploration/reference-products-and-sketches.md +0 -250
  52. package/content/skills/timetrack/SKILL.md +0 -324
  53. package/src/lib/peer-path.d.ts +0 -12
  54. package/src/lib/peer-path.js +0 -39
  55. package/src/lib/peer-path.js.map +0 -1
  56. package/src/lib/timetrack-command.d.ts +0 -11
  57. package/src/lib/timetrack-command.js +0 -1262
  58. package/src/lib/timetrack-command.js.map +0 -1
  59. package/src/lib/timetrack-snapshot.d.ts +0 -66
  60. package/src/lib/timetrack-snapshot.js +0 -146
  61. package/src/lib/timetrack-snapshot.js.map +0 -1
@@ -1,16 +1,106 @@
1
1
  import { atom, read, update } from 'claude-code';
2
2
  import type { EngineInterface, Register, Timer } from 'claude-code';
3
3
 
4
+ import {
5
+ agentRunOf,
6
+ claimRuns,
7
+ durationOf as agentDurationOf,
8
+ finishNotices,
9
+ isCodexAgentCommand,
10
+ isRunNamed,
11
+ parseRunIndex,
12
+ parseTrace,
13
+ shortIdOf,
14
+ statusOf,
15
+ } from './agent-runs';
16
+ import type { AgentRun, Trace } from './agent-runs';
4
17
  import { discoverRuns, durationOf } from './progress';
5
18
 
6
19
  const PANE = 'codex-runs';
7
- const POLL_MS = 5000;
20
+ const POLL_MS = 3000;
8
21
  const PROCESS_TIMEOUT_MS = 2000;
22
+ const KEEP_AGENT_RUNS_MS = 6 * 60 * 60_000;
23
+ const MAX_AGENT_RUNS = 20;
24
+ const MAX_TRACE_BYTES = 4 * 1024 * 1024;
9
25
  const runs = atom({ plugin: 'codex-runs', key: 'runs' } as const, []);
10
26
  const selected = atom({ plugin: 'codex-runs', key: 'selected' } as const, null);
27
+ const agentRuns = atom({ plugin: 'codex-runs', key: 'agentRuns' } as const, []);
28
+ const toolRuns = atom({ plugin: 'codex-runs', key: 'toolRuns' } as const, {});
29
+ const waitingCalls = atom({ plugin: 'codex-runs', key: 'waitingCalls' } as const, []);
11
30
 
12
31
  let timer: Timer | undefined;
13
32
  let pending: Promise<void> | undefined;
33
+ let shownStatus: string | undefined | null = null;
34
+ const traces = new Map<string, { size: number; mtimeMs: number; trace: Trace }>();
35
+
36
+ async function logDirs($: EngineInterface) {
37
+ const tmp = (await $.env.get('TMPDIR'))?.replace(/\/$/, '');
38
+ return [...new Set([tmp ? `${tmp}/codex-agent` : '', '/tmp/codex-agent'].filter(Boolean))];
39
+ }
40
+
41
+ async function traceOf($: EngineInterface, path: string, size: number, mtimeMs: number) {
42
+ const cached = traces.get(path);
43
+ if (cached && cached.size === size && cached.mtimeMs === mtimeMs) return cached.trace;
44
+ const offset = Math.max(0, size - MAX_TRACE_BYTES);
45
+ const text = await $.fs.read(path, { offset, length: size - offset }).catch(() => '');
46
+ const trace = parseTrace(offset > 0 ? text.slice(text.indexOf('\n') + 1) : text);
47
+ traces.set(path, { size, mtimeMs, trace });
48
+ return trace;
49
+ }
50
+
51
+ async function isAlive($: EngineInterface, pid: number) {
52
+ if (!pid) return null;
53
+ const result = await $.process.run(['kill', '-0', String(pid)], { timeoutMs: PROCESS_TIMEOUT_MS }).catch(() => null);
54
+ return result ? result.exitCode === 0 : null;
55
+ }
56
+
57
+ async function scanAgentRuns($: EngineInterface, now: number) {
58
+ const found: AgentRun[] = [];
59
+ for (const dir of await logDirs($)) {
60
+ const entries = await $.fs.list(dir).catch(() => []);
61
+ const indexes = new Set(entries.filter((entry) => entry.name.endsWith('.run.json')).map((entry) => entry.name));
62
+ for (const entry of entries) {
63
+ if (entry.kind !== 'file' || !entry.name.endsWith('.jsonl')) continue;
64
+ const id = entry.name.slice(0, -'.jsonl'.length);
65
+ const hasIndex = indexes.has(`${id}.run.json`);
66
+ if (!hasIndex && now - entry.mtimeMs > KEEP_AGENT_RUNS_MS) continue;
67
+ const index = hasIndex ? parseRunIndex(await $.fs.read(`${dir}/${id}.run.json`).catch(() => '')) : null;
68
+ if (index?.endedAt && now - index.endedAt > KEEP_AGENT_RUNS_MS) continue;
69
+ const log = `${dir}/${entry.name}`;
70
+ const trace = await traceOf($, log, entry.size, entry.mtimeMs);
71
+ const alive = index && index.endedAt === undefined ? await isAlive($, index.pid) : null;
72
+ found.push(agentRunOf({ id, log, index, trace, logChangedAt: entry.mtimeMs, isAlive: alive, now }));
73
+ }
74
+ }
75
+ return found
76
+ .filter((run) => run.state === 'running' || now - (run.endedAt ?? now) <= KEEP_AGENT_RUNS_MS)
77
+ .sort((a, b) => b.startedAt - a.startedAt)
78
+ .slice(0, MAX_AGENT_RUNS);
79
+ }
80
+
81
+ function setStatus($: EngineInterface, text: string | undefined) {
82
+ if (text === shownStatus) return;
83
+ shownStatus = text;
84
+ $.ui.status(text);
85
+ }
86
+
87
+ async function refreshAgentRuns($: EngineInterface, sessionId: string, now: number) {
88
+ const [previous, claimed, waiting] = await Promise.all([
89
+ read($, agentRuns),
90
+ read($, toolRuns),
91
+ read($, waitingCalls),
92
+ ]);
93
+ const next = await scanAgentRuns($, now);
94
+ if (JSON.stringify(next) !== JSON.stringify(previous)) await update($, agentRuns, () => next);
95
+ for (const text of finishNotices(previous, next, sessionId, now)) $.ui.toast(text);
96
+ if (waiting.length > 0) {
97
+ const paired = claimRuns(waiting, claimed, next, sessionId);
98
+ const open = paired.waiting.filter((call) => now - call.at < 60_000);
99
+ await update($, toolRuns, () => paired.claimed);
100
+ await update($, waitingCalls, () => open);
101
+ }
102
+ setStatus($, statusOf(next, now));
103
+ }
14
104
 
15
105
  async function refresh($: EngineInterface) {
16
106
  const [sessionId, root, now, previous] = await Promise.all([
@@ -31,7 +121,9 @@ async function refresh($: EngineInterface) {
31
121
  previous,
32
122
  now,
33
123
  });
34
- if ((await $.session.id()) === sessionId) await update($, runs, () => next);
124
+ if ((await $.session.id()) !== sessionId) return;
125
+ await update($, runs, () => next);
126
+ await refreshAgentRuns($, sessionId, now);
35
127
  }
36
128
 
37
129
  function poll($: EngineInterface) {
@@ -60,32 +152,99 @@ export const register: Register = (on) => {
60
152
  return next(e);
61
153
  });
62
154
 
155
+ on('tool.call', { tool: 'Bash' }, async ($, e, next) => {
156
+ if (isCodexAgentCommand(e.command)) {
157
+ const at = await $.clock.now();
158
+ await update($, waitingCalls, (calls) => [...calls, { toolUseId: e.tool_use_id, at }]);
159
+ }
160
+ return next(e);
161
+ });
162
+
163
+ on('ui.render', { component: 'ToolUse' }, async ($, e, next) => {
164
+ const input = e.props.input as { command?: unknown } | undefined;
165
+ if (e.props.tool !== 'Bash' || !isCodexAgentCommand(input?.command)) return next(e);
166
+ const [row, claimed, shown, now] = await Promise.all([
167
+ next(e),
168
+ read($, toolRuns),
169
+ read($, agentRuns),
170
+ $.clock.now(),
171
+ ]);
172
+ const run = shown.find((run) => run.id === claimed[e.props.tool_use_id]);
173
+ if (!run) return row;
174
+ const { Box, Text } = $.ui.resolve(e);
175
+ const detail = run.state === 'failed' ? run.error : run.progress;
176
+ return (
177
+ <Box flexDirection="column">
178
+ {row}
179
+ <Text dimColor wrap="truncate-end">
180
+ {` ⎿ codex ${run.state} · ${agentDurationOf(run, now)} · ${detail} · /codex-runs ${shortIdOf(run.id)}`}
181
+ </Text>
182
+ </Box>
183
+ );
184
+ });
185
+
63
186
  on('command.run', { command: PANE }, async ($, e) => {
64
187
  await poll($);
65
188
  const name = e.args.trim();
66
- const run = name
67
- ? (await runsForSession($)).find((run) => run.name === name || run.name.startsWith(`${name}@`))
68
- : undefined;
69
- if (name && !run) return { text: `No visible Codex run named ${name}.` };
70
-
71
- await update($, selected, () => run?.id ?? null);
72
- await $.ui.open({ id: PANE, title: 'Codex runs' });
73
- return { text: run ? `Showing recent output for ${run.name}.` : 'Codex runs pane opened.' };
189
+ const agentRun = name ? (await read($, agentRuns)).find((run) => isRunNamed(run, name)) : undefined;
190
+ const run =
191
+ name && !agentRun
192
+ ? (await runsForSession($)).find((run) => run.name === name || run.name.startsWith(`${name}@`))
193
+ : undefined;
194
+ if (name && !run && !agentRun) return { text: `No visible Codex run named ${name}.` };
195
+
196
+ await update($, selected, () => agentRun?.id ?? run?.id ?? null);
197
+ await $.ui.open({ id: PANE, title: 'Codex' });
198
+ if (agentRun) return { text: `Showing the trace of the Codex run ${name}.` };
199
+ return { text: run ? `Showing recent output for ${run.name}.` : 'Codex pane opened.' };
74
200
  });
75
201
 
76
202
  on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
77
203
  const { Box, Text } = $.ui.resolve(e);
78
- const [shown, selectedId, now] = await Promise.all([runsForSession($), read($, selected), $.clock.now()]);
79
- if (shown.length === 0) return <Text dimColor>No Codex runs found.</Text>;
204
+ const [shown, agents, selectedId, sessionId, now] = await Promise.all([
205
+ runsForSession($),
206
+ read($, agentRuns),
207
+ read($, selected),
208
+ $.session.id(),
209
+ $.clock.now(),
210
+ ]);
211
+ if (shown.length === 0 && agents.length === 0) return <Text dimColor>No Codex runs found.</Text>;
80
212
 
81
213
  const run = shown.find((run) => run.id === selectedId);
214
+ const traced =
215
+ agents.find((agent) => agent.id === selectedId) ??
216
+ (run ? undefined : (agents.find((agent) => agent.state === 'running') ?? agents[0]));
82
217
  return (
83
218
  <Box flexDirection="column">
219
+ {agents.map((agent) => (
220
+ <Text key={agent.id} wrap="truncate-end" bold={agent.id === traced?.id}>
221
+ {`${shortIdOf(agent.id)} ${agent.state} · ${agentDurationOf(agent, now)} · ${agent.label}`}
222
+ {agent.session && agent.session !== sessionId ? ' · other session' : ''}
223
+ {` · ${agent.prompt || agent.progress}`}
224
+ </Text>
225
+ ))}
84
226
  {shown.map((run) => (
85
227
  <Text key={run.id} wrap="truncate-end">
86
228
  {run.name} · {run.state} · {durationOf(run, now)}
87
229
  </Text>
88
230
  ))}
231
+ {traced && (
232
+ <Box flexDirection="column" marginTop={1}>
233
+ <Text bold wrap="truncate-end">
234
+ {`${shortIdOf(traced.id)} trace · ${traced.progress}`}
235
+ </Text>
236
+ {traced.error && <Text color="red">{traced.error}</Text>}
237
+ {traced.trace.length === 0 && <Text dimColor>No trace yet.</Text>}
238
+ {traced.trace.slice(-20).map((line, index) => (
239
+ <Text key={String(index)} wrap="truncate-end" dimColor={line.kind === 'command'}>
240
+ {line.kind === 'command' ? `$ ${line.text}` : line.kind === 'files' ? `~ ${line.text}` : line.text}
241
+ </Text>
242
+ ))}
243
+ <Text dimColor wrap="truncate-end">
244
+ {traced.log}
245
+ </Text>
246
+ </Box>
247
+ )}
89
248
  {run && (
90
249
  <Box flexDirection="column" marginTop={1}>
91
250
  <Text bold>{run.name} output</Text>
@@ -9,11 +9,29 @@ export type CodexRun = {
9
9
  tail: string[];
10
10
  };
11
11
 
12
+ export type AgentRun = {
13
+ id: string;
14
+ log: string;
15
+ session: string;
16
+ cwd: string;
17
+ label: string;
18
+ prompt: string;
19
+ startedAt: number;
20
+ endedAt: number | null;
21
+ state: 'running' | 'done' | 'failed';
22
+ error: string;
23
+ progress: string;
24
+ trace: { kind: 'command' | 'files' | 'message' | 'error'; text: string }[];
25
+ };
26
+
12
27
  declare module 'claude-code' {
13
28
  interface PluginState {
14
29
  'codex-runs': {
15
30
  runs: CodexRun[];
16
31
  selected: string | null;
32
+ agentRuns: AgentRun[];
33
+ toolRuns: Record<string, string>;
34
+ waitingCalls: { toolUseId: string; at: number }[];
17
35
  };
18
36
  }
19
37
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "e2e-progress",
3
- "version": "0.1.0-next.51",
3
+ "version": "0.1.0-next.53",
4
4
  "description": "Live Playwright e2e progress from a run log, as a status line entry and a pane",
5
5
  "types": "./types/index.d.ts"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "status-line",
3
- "version": "0.1.0-next.51",
3
+ "version": "0.1.0-next.53",
4
4
  "description": "Always-visible band with the running task, its duration, the open queue, open questions and a CI blocked mark",
5
5
  "types": "./types/index.d.ts"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "usage-line",
3
- "version": "0.1.0-next.51",
3
+ "version": "0.1.0-next.53",
4
4
  "description": "Status line entry with the 5 hour and weekly usage, the reset time of the 5 hour window and the Codex limit",
5
5
  "types": "./types/index.d.ts"
6
6
  }
@@ -0,0 +1,23 @@
1
+ type RateLimit = { kind: string; percentUsed: number; resetsAt?: string };
2
+
3
+ export type RateLimitsFile = {
4
+ updatedAt: string;
5
+ limits: { kind: string; usedPercent: number; resetsAt: string | null }[];
6
+ };
7
+
8
+ export const RATE_LIMITS_FILE = 'state/rate-limits.json';
9
+
10
+ export function rateLimitsFileOf(limits: readonly RateLimit[], now: number): RateLimitsFile {
11
+ return {
12
+ updatedAt: new Date(now).toISOString(),
13
+ limits: limits.map(({ kind, percentUsed, resetsAt }) => ({
14
+ kind,
15
+ usedPercent: percentUsed,
16
+ resetsAt: resetsAt ?? null,
17
+ })),
18
+ };
19
+ }
20
+
21
+ export function rateLimitsKey(limits: readonly RateLimit[]) {
22
+ return JSON.stringify(limits.map(({ kind, percentUsed, resetsAt }) => [kind, percentUsed, resetsAt ?? null]));
23
+ }
@@ -4,6 +4,7 @@ import type { EngineInterface, Register } from 'claude-code';
4
4
  import { latestCodexSample, formatCodex } from './codex';
5
5
  import type { CodexSample } from './codex';
6
6
  import { formatUsage, statusTextOf } from './format';
7
+ import { RATE_LIMITS_FILE, rateLimitsFileOf, rateLimitsKey } from './rate-limits';
7
8
 
8
9
  const usage = atom({ plugin: 'usage-line', key: 'usage' } as const, null);
9
10
 
@@ -13,6 +14,7 @@ const CODEX_SCAN_FILES = 3;
13
14
 
14
15
  let codexSample: CodexSample | undefined;
15
16
  let codexCheckedAt = 0;
17
+ let writtenLimits = '';
16
18
 
17
19
  async function newestDirectory($: EngineInterface, path: string) {
18
20
  const entries = await $.fs.list(path).catch(() => []);
@@ -50,9 +52,23 @@ async function refreshCodex($: EngineInterface, now: number) {
50
52
  codexSample = latest ?? codexSample;
51
53
  }
52
54
 
55
+ async function writeRateLimits($: EngineInterface, limits: Parameters<typeof rateLimitsFileOf>[0], now: number) {
56
+ const key = rateLimitsKey(limits);
57
+ if (limits.length === 0 || key === writtenLimits) return;
58
+ const home = await $.env.get('HOME');
59
+ const configDir = (await $.env.get('CLAUDE_CONFIG_DIR')) ?? (home ? `${home}/.claude` : '');
60
+ if (!configDir) return;
61
+ const path = `${configDir.replace(/\/$/, '')}/${RATE_LIMITS_FILE}`;
62
+ const temp = `${path}.${now}.tmp`;
63
+ await $.fs.write(temp, `${JSON.stringify(rateLimitsFileOf(limits, now), null, 2)}\n`);
64
+ const moved = await $.process.run(['mv', '-f', temp, path], { timeoutMs: 2000 });
65
+ if (moved.exitCode === 0) writtenLimits = key;
66
+ }
67
+
53
68
  export const register: Register = (on) => {
54
69
  on('session.measure', async ($, e, next) => {
55
70
  const now = await $.clock.now();
71
+ await writeRateLimits($, e.rateLimits, now).catch(() => undefined);
56
72
  await refreshCodex($, now).catch(() => undefined);
57
73
  const parts = [formatUsage(e.rateLimits), formatCodex(codexSample, now)].filter(Boolean);
58
74
  const text = parts.length > 0 ? parts.join(' · ') : null;
@@ -97,4 +97,4 @@ A claim is advisory, not a lock. `--force` claims over another agent: use it onl
97
97
 
98
98
  ## Stop own processes
99
99
 
100
- `stop-own [--dry-run]` stops what a session leaves behind, with no raw `kill`: processes that carry the caller's `CLAUDE_PID` but are reparented (no longer below that Claude process), and orphans of a dead session whose cwd lies in this checkout or its scratch dir, each with its whole subtree. Background tasks still attached to a live Claude process always stay: stop those with TaskStop first. Subagents share their session's `CLAUDE_PID`, so a process below the live session is never touched, and a reparented process counts as own only when its `ET_AGENT_ID` (stamped on every subagent Bash call by the `background-design-commands` hook) equals the caller's: a subagent never stops a sibling's runs, and the main session never stops a subagent's. `--dry-run` lists without signalling; otherwise SIGTERM, up to 5 s, then SIGKILL. Linux only, same uid.
100
+ `stop-own [--dry-run]` stops what a session leaves behind, with no raw `kill`: processes that carry the caller's `CLAUDE_PID` but are reparented (no longer below that Claude process), and orphans of a dead session whose cwd lies in this checkout or its scratch dir, each with its whole subtree. Background tasks still attached to a live Claude process always stay: stop those with TaskStop first. Subagents share their session's `CLAUDE_PID`, so a process below the live session is never touched, and a reparented process counts as own only when its `ET_AGENT_ID` (stamped on every subagent Bash call by the `background-commands` hook) equals the caller's: a subagent never stops a sibling's runs, and the main session never stops a subagent's. `--dry-run` lists without signalling; otherwise SIGTERM, up to 5 s, then SIGKILL. Linux only, same uid.
@@ -39,6 +39,12 @@ Options: `-m` model, `-e` effort (`low`, `medium`, `high`, `xhigh`), `-C` workin
39
39
  `--write`, `--resume <thread>`, `--prompt-file <file>`, `--schema <json-schema-file>`,
40
40
  `--timeout <seconds>`, `--trace`. Run it with `--help` for the full list.
41
41
 
42
+ Start every run with the Bash tool's `run_in_background`, even a short lookup. The answer comes
43
+ back as the task's notification, and the user watches the run while it works: the `codex-runs`
44
+ mod draws a progress line under the call, `/codex-runs` opens the Codex pane with every run and
45
+ its trace, and the status line counts the running runs. The wrapper writes the trace to
46
+ `$TMPDIR/codex-agent/<stamp>.jsonl` and the run's state to `<stamp>.run.json` beside it.
47
+
42
48
  The run prints a footer with the model, the sandbox, the time, the output tokens, the resume
43
49
  id and the log path. Read the log only when a run fails.
44
50
 
@@ -69,8 +75,8 @@ started read-only stays read-only, so start a new run when you need write access
69
75
 
70
76
  ## Run several at once
71
77
 
72
- The wrapper blocks until the agent is done, which takes minutes for real work. Start each run
73
- as a background command, and collect the answers when they arrive. Give each run its own
78
+ The wrapper blocks until the agent is done, which takes minutes for real work. Each run is a
79
+ background command already, so start several and collect the answers when they arrive. Give each run its own
74
80
  question. Two agents on one question waste a model.
75
81
 
76
82
  ## Write the prompt for a stranger
@@ -9,7 +9,7 @@
9
9
  */
10
10
 
11
11
  import { spawn } from 'node:child_process';
12
- import { createWriteStream, mkdirSync, readFileSync, rmSync } from 'node:fs';
12
+ import { createWriteStream, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
13
13
  import { tmpdir } from 'node:os';
14
14
  import { join } from 'node:path';
15
15
  import { createInterface } from 'node:readline';
@@ -118,6 +118,15 @@ const duration = (milliseconds) => {
118
118
  return seconds < 60 ? `${seconds}s` : `${Math.floor(seconds / 60)}m${String(seconds % 60).padStart(2, '0')}s`;
119
119
  };
120
120
 
121
+ const writeIndex = (file, index) => {
122
+ try {
123
+ writeFileSync(`${file}.tmp`, `${JSON.stringify(index)}\n`);
124
+ renameSync(`${file}.tmp`, file);
125
+ } catch {
126
+ // The index only feeds the codex-runs mod; a run never fails over it.
127
+ }
128
+ };
129
+
121
130
  const run = async () => {
122
131
  const options = parseArgs(process.argv.slice(2));
123
132
 
@@ -139,6 +148,7 @@ const run = async () => {
139
148
  const stamp = new Date().toISOString().replace(/[:.]/g, '-');
140
149
  const logFile = join(logDir, `${stamp}.jsonl`);
141
150
  const lastMessageFile = join(logDir, `${stamp}.last.md`);
151
+ const indexFile = join(logDir, `${stamp}.run.json`);
142
152
  const log = createWriteStream(logFile);
143
153
  const started = Date.now();
144
154
 
@@ -149,6 +159,19 @@ const run = async () => {
149
159
 
150
160
  child.stdin.end(options.prompt);
151
161
 
162
+ const index = {
163
+ pid: process.pid,
164
+ session: process.env.CLAUDE_CODE_SESSION_ID ?? '',
165
+ cwd: options.cd,
166
+ model: options.model,
167
+ effort: options.effort,
168
+ sandbox: options.write ? 'workspace-write' : 'read-only',
169
+ prompt: options.prompt.trim().split('\n')[0].slice(0, 160),
170
+ startedAt: started,
171
+ log: logFile,
172
+ };
173
+ writeIndex(indexFile, index);
174
+
152
175
  const state = { thread: '', usage: null, errors: [], trace: [], failed: false };
153
176
 
154
177
  createInterface({ input: child.stdout }).on('line', (line) => {
@@ -194,12 +217,20 @@ const run = async () => {
194
217
  }
195
218
 
196
219
  const failed = code !== 0 || state.failed || (!finalMessage && state.errors.length > 0);
220
+ const reason = state.errors.join('\n') || stderrText.trim() || `codex exited with code ${code}`;
221
+
222
+ writeIndex(indexFile, {
223
+ ...index,
224
+ endedAt: Date.now(),
225
+ exitCode: code,
226
+ failed,
227
+ error: failed ? reason.split('\n')[0].slice(0, 300) : '',
228
+ });
197
229
 
198
230
  if (options.trace && state.trace.length > 0) process.stdout.write(`${state.trace.join('\n')}\n\n`);
199
231
  if (finalMessage) process.stdout.write(`${finalMessage}\n`);
200
232
 
201
233
  if (failed) {
202
- const reason = state.errors.join('\n') || stderrText.trim() || `codex exited with code ${code}`;
203
234
  process.stdout.write(`\ncodex agent FAILED: ${reason}\n`);
204
235
  }
205
236
 
@@ -53,9 +53,7 @@ Confirm the step size once, at the start. A task is not finished while the user
53
53
  - Nothing else. No next step, no second finding.
54
54
 
55
55
  **Do not send a screenshot.** The user keeps the call open. Screenshot only for your own check that a
56
- variant renders: `et design shot <layer>/<name> --states [--variants]` draws one contact sheet. Every
57
- flag, the motion shots and the raw screenshot script are in {%resource:reference-shots.md%}. Do not
58
- write a scratch script for batch shots.
56
+ variant renders. Do not write a scratch script for batch shots.
59
57
 
60
58
  If a second defect appears, add it to the open list and give it one line. Do not draw it.
61
59
 
@@ -63,121 +61,41 @@ If a second defect appears, add it to the open list and give it one line. Do not
63
61
 
64
62
  The exploration's plan file names the tool. Two shapes exist.
65
63
 
66
- **A repository with a `.ethlete/design` folder** keeps one design system per **product**, and the
67
- user reads and decides in Ethlete Studio. The tool is `et design`, from `@ethlete/cli`; run
68
- `et design --help` for every command, `et design <command> [<subcommand>] --help` for one.
69
- In the SDK checkout, `yarn design` builds the CLI before each call; in a check-and-shot loop,
70
- build once and call `node dist/libs/cli/src/index.js design`.
71
- Ask the user, then run `et design studio open` to show your checkout in Studio. If it is not
72
- running, the request is kept for 7 days and Studio adds the checkout at its next start (exit 3, queued). In a client run (`CLEAN_SLATE_SANDBOX` is set) the
73
- command refuses: a run must not write the user's Studio roots, so the user opens the run's checkout.
64
+ **A repository with a `.ethlete/design` folder** keeps one design system per product, drawn and decided in Ethlete
65
+ Studio. Use the Studio design MCP server (`ethlete-design`): its server instructions and its `design_guide` tool
66
+ carry the commands, the rules for products and sketches, the checks and the shots. Without that server in your tool
67
+ list, ask the user to add it.
74
68
 
75
- ```
76
- .ethlete/design/
77
- config.json the port and one `products` entry each
78
- <product>/<layer>/<part>/ layer: foundations, components, elements, pages
79
- <product>/flows/<name>.json a flow: pages and their states joined by lines
80
- <product>/sketches/<layer>-<name>/ an open sketch: sketch.json and one folder per variant
81
- <product>/comments/<id>.json a comment the user wrote in Studio
82
- calls/ old calls: Legacy, read-only
83
- ```
84
-
85
- Studio takes no new calls. **New work goes to a product**, never `et design new`. Old calls stay in
86
- the Legacy tab as reference for moving them into a product, with no picks and no new variants.
87
-
88
- ## Hard rules for products and sketches
89
-
90
- - A change to a merged part, also a small one, is a **sketch**; never edit a merged part directly. When
91
- nothing is to choose, the sketch has one variant (`--variants a`). Variants are alternatives, never a state
92
- of another variant. Two to four variants, each with its cost; run `sketch check` before `sketch ready`.
93
- - **Never run `sketch merge` or `sketch discard`, and never pick a variant, unless your role has its own picks; discarding the mood sketch is the one exception.** Studio merges on the user's
94
- click. After a pick or discard, do not merge. Run `sketch reject` or `reopen` only when the user did.
95
- - Mark a sketch `ready` only when no change waits on anything; otherwise `sketch hold`. The pick of another
96
- sketch is not a wait: draw with the part as merged now.
97
- - Every write command takes `--by <model id>`. **Never guess your id**: use the one your prompt names, or ask
98
- before you write.
99
- - `design check` opens an edit sketch for a direct edit of a merged part; the user picks in Studio. Remove a part only with `et design part remove`, never `git rm`.
100
- - Share code between variants in the sketch's `shared/` folder only. An asset is one file in `<product>/assets/`.
101
- - A user comment to combine variants is a new variant in a new round (`sketch variant --from --round --note`).
102
- - Read the inbox at the start of a session and after each `ready`. Answer with `inbox done <id> --note`,
103
- ask with `comment reply --question` only when you cannot go on. Only the user resolves a thread.
104
- - Use the `ethlete-design` MCP tools when they are in your tool list, and call `sketch_report` before every
105
- variant edit.
106
- - Draw from the design system, never invent a button or field: the product's parts, then SDK components via
107
- `ng()`, then new. Colours come from the SDK theming systems. A part exists only because the user picked a sketch.
108
- - **A new product starts with one real screen** (a film app: the overview) in two or three finished moods:
109
- real colours, real type, real content from the product's data. The user picks no mood and nothing merges:
110
- he collects by commenting on what he likes. Wait for his "collected enough", then draw the first real
111
- page from his comments as a new sketch and discard the mood sketch. Menu, navigation
112
- and layout are your call, shown only inside the finished screen: draw the masthead, menu and navigation as
113
- `elements/shell-<purpose>` inside each mood's variant folder, and let the page import it, never an inline
114
- `<header>` or `<nav>` in the page. Never draw a wireframe or a layout round of grey boxes.
115
- - Do not start a design stage before the one above it is settled: foundations, logo and
116
- CI, components, elements, pages, prototype.
117
- - A logo is explored small and elaborated after the pick: a logo sketch variant shows only the mark, at one size,
118
- so ten variants stay ten quick looks. Only after the merge of the picked variant, draw the six sections of
119
- `foundations/logo`: anatomy, clear space, minimum size, colour variants, misuse and motion (one state each:
120
- `anatomy`, `clear-space`, `minimum-size`, `colour-variants`, `misuse`, `motion`). The design check reports a missing section on a merged logo.
121
- - Mark a sketch `ready` only after you looked at a shot of each variant ({%resource:reference-shots.md%}).
122
- - Talk to the user about the product: screens, moods, content. Never name tools, commands or file paths.
123
- A variant note is at most two short sentences in the words of the screen, never a field or prop name.
124
- - Work only from your repo and what the user hands you; never search the machine or other folders for
125
- material. When an image or other material is missing, ask for it in one plain sentence.
126
- - Every interactive part (a poster card, a search field, a chip, a button) draws its own hover and focus-visible
127
- states next to rest. A page has none: it imports those parts and shows theirs, so never write a hover or
128
- focus rule only in a page's CSS.
129
- - A state must read as different from rest at a glance: change colour, surface, outline or shadow. A lift or move
130
- of a few px alone barely differs, and `sketch check` and `sketch ready` warn about it.
131
- - The app shell (masthead, menu, navigation, and any header or footer every page shares) is one element each
132
- page imports, never drawn inside a page. This holds in the first sketch too.
133
-
134
- Details, commands and examples, read on demand:
135
-
136
- - {%resource:reference-products-and-sketches.md%}: creating a product, every `sketch` command, shared code,
137
- assets, rounds, `--by`, the merge and accept flow. Read before the first sketch command.
138
- - {%resource:reference-inbox-and-mcp.md%}: reading and answering comments, thread states, the MCP tools.
139
- - {%resource:reference-flows.md%}: flow JSON, `embedPage`, the shell.
140
- - {%resource:reference-check-and-notes.md%}: `design check` rules and warnings, drawing-file constraints,
141
- `setup`, `ngStates`, notes.
142
- - {%resource:reference-order-and-design-system.md%}: the stage order, component states and
143
- `interactionRows`, `ng()` and form fields, theming rules.
144
- - {%resource:reference-shots.md%}: every `shot` flag, motion shots, the screenshot script.
145
-
146
- ## Check before you look
69
+ **A repository with a sketch Storybook** draws every variant in the **same** story, side by side, under the real
70
+ geometry the thing ships in. The default Storybook is {%storybookUrl%}; an app with its own sketch Storybook names its
71
+ port in the plan file.
147
72
 
148
- A broken build draws an overlay, so a screenshot of it looks like a design. **One check
149
- covers that, and it is the whole gate.** Name the files you changed, never a whole project,
150
- which is far slower and can fight the user's own editor.
73
+ Details, read on demand:
151
74
 
152
- With `et design`, run the checker from the checkout it draws:
75
+ - {%resource:reference-shots.md%}: screenshots of a Storybook story, with forced pseudo-states.
153
76
 
154
- ```bash
155
- et design check --lint <changed files> --tsconfig
156
- ```
157
-
158
- `--tsconfig` with no path types every call of the checkout. `--tsconfig` also types each variant of
159
- an open sketch and prints the tsc output of a failing one. `--checkout <path>` names another
160
- one.
77
+ ## Check before you look
161
78
 
162
- With a Storybook, copy {%resource:check-story.mjs%} to the **repository root** first:
79
+ A broken build draws an overlay, so a screenshot of it looks like a design. **One check covers that, and it is the
80
+ whole gate.** Name the files you changed, never a whole project, which is far slower and can fight the user's own
81
+ editor. In a Studio repository, run the check the MCP server describes. With a Storybook, copy
82
+ {%resource:check-story.mjs%} to the **repository root** first:
163
83
 
164
84
  ```bash
165
85
  node check-story.mjs --lint <changed files> --tsconfig apps/<app>/.storybook/tsconfig.json
166
86
  ```
167
87
 
168
- Both take about four seconds and need no dev server. Open a browser only when the check passes and
169
- the drawing still does not appear:
88
+ It takes about four seconds and needs no dev server. Open a browser only when the check passes and the drawing still
89
+ does not appear:
170
90
 
171
91
  ```bash
172
- et design check --call <slug> # every variant of the call
173
- et design check --call <slug> --variant b # one of them
174
92
  node check-story.mjs --tsconfig <path> --story <story-id>
175
93
  ```
176
94
 
177
- A passing check says the variant builds, not that it looks good. Before `sketch ready`, look at
178
- each variant at a readable scale and in its whole host page, and critique its hierarchy, spacing,
179
- nesting and host context together. Drop a visually weak variant before the user sees it. In your summary, say "renders correctly", never "good" or "approved":
180
- the user decides that.
95
+ A passing check says the variant builds, not that it looks good. Before the user sees a variant, look at it at a
96
+ readable scale and in its whole host page, and critique its hierarchy, spacing, nesting and host context together.
97
+ Drop a visually weak variant before the user sees it. In your summary, say "renders correctly", never "good" or
98
+ "approved": the user decides that.
181
99
 
182
100
  ## Delegating a sketch
183
101
 
@@ -193,7 +111,7 @@ command." You know the id because you chose the model; the sub-agent does not, a
193
111
  2. **One check-and-fix agent, after the drawing agents return.** Give it the changed files
194
112
  and the call slug. It runs the check above, fixes what it reports, and repeats until the
195
113
  check says `ok`. It may not change what a variant draws, only what stops it rendering.
196
- 3. **One write-up agent, once the user settles the sketch in Studio.** Give it the verdict in the
114
+ 3. **One write-up agent, once the user settles the sketch.** Give it the verdict in the
197
115
  user's own words and the plan file. It records what won, what lost and why, it sets each
198
116
  variant's `verdict` in an old call's `call.ts` (a product sketch needs none; the merge sets the note). It runs while you open
199
117
  the next call.
@@ -1,14 +1,4 @@
1
- # Design exploration: shots and screenshots
2
-
3
- **Do not send a screenshot.** The user keeps the call open. Screenshot only for your own
4
- check that a variant renders. In a repository with `et design`, take it with
5
- `et design shot <layer>/<name> --states [--variants]`: one contact sheet of every state, and
6
- every variant of the open sketch, with a label per cell; below each variant row, a diff row marks
7
- the pixels that differ from the merged state in red, or says "no pixel change" (with ", but the markup differs" when only the markup changed, e.g. both sides miss the same content). It prints the PNG path last. `--scale 2` enlarges a small part; `--crop x,y,w,h` cuts each cell to that CSS-pixel box, to judge hairlines. `--interaction hover` forces an interaction on every cell. `--state a,b` draws only those states, to compare them side by side. With `--variants`, `--round r2` or `--variant i,j` draws only those variants next to the merged row, so the current round stays readable; it filters the picture, never the checks. With `--variants`, `--diff-props` compares each variant with the merged part drawn with the variant's state props, so changed props do not paint the diff red. It draws
8
- undimmed, whatever Studio shows. Do not write a scratch script for batch shots.
9
- `et design motion shots <layer>/<name> <motion>` draws a motion at its keyframes, in full and reduced motion, into one sheet, and writes its tracks (element, properties, start, duration, easing) as JSON next to it.
10
-
11
- ## Screenshots
1
+ # Design exploration: screenshots
12
2
 
13
3
  **Off by default.** The user has the call open and sends you a picture when something looks
14
4
  wrong. Take one only when the code cannot tell you whether two variants really differ, and
@@ -39,6 +39,8 @@ Before you save, or when the `context-warning` hook names handoff mode, read {%r
39
39
  and stop.
40
40
  2. Read the file fully. If its first line starts with `Restarted because:`, show that line to the
41
41
  user first, then delete it from the file.
42
+ Then show each question under `## Open questions` to the user in full. It stays open until
43
+ the user answers it.
42
44
  3. Verify reality still matches: current branch, `git status`, last commit. If
43
45
  they diverge from the handoff (e.g. someone committed in between), say what
44
46
  changed and adapt - the repo is the truth, the handoff is the guide. Read each