@ethlete/agent-rules 0.1.0-next.6 → 0.1.0-next.60

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 (220) hide show
  1. package/AGENTS.md +28 -0
  2. package/CHANGELOG.md +841 -0
  3. package/CLAUDE.md +1 -0
  4. package/README.md +244 -36
  5. package/THIRD-PARTY-LICENSES.md +35 -0
  6. package/content/defaults.json +1 -1
  7. package/content/hooks/away-mode.py +410 -0
  8. package/content/hooks/background-commands.py +177 -0
  9. package/content/hooks/builder-idle-check.py +529 -0
  10. package/content/hooks/context-warning.py +666 -134
  11. package/content/hooks/git-safety.py +213 -0
  12. package/content/hooks/human-wait-check.py +167 -0
  13. package/content/hooks/subagent-model-policy.py +261 -0
  14. package/content/mods/.claude-plugin/marketplace.json +26 -0
  15. package/content/mods/plugins/codex-runs/.claude-plugin/plugin.json +6 -0
  16. package/content/mods/plugins/codex-runs/hooks/agent-runs.ts +310 -0
  17. package/content/mods/plugins/codex-runs/hooks/hooks.json +1 -0
  18. package/content/mods/plugins/codex-runs/hooks/progress.ts +130 -0
  19. package/content/mods/plugins/codex-runs/hooks/register.tsx +283 -0
  20. package/content/mods/plugins/codex-runs/tests/pane.test.ts +21 -0
  21. package/content/mods/plugins/codex-runs/tsconfig.json +4 -0
  22. package/content/mods/plugins/codex-runs/types/index.d.ts +37 -0
  23. package/content/mods/plugins/e2e-progress/.claude-plugin/plugin.json +6 -0
  24. package/content/mods/plugins/e2e-progress/hooks/hooks.json +1 -0
  25. package/content/mods/plugins/e2e-progress/hooks/progress.ts +205 -0
  26. package/content/mods/plugins/e2e-progress/hooks/register.tsx +498 -0
  27. package/content/mods/plugins/e2e-progress/tsconfig.json +3 -0
  28. package/content/mods/plugins/e2e-progress/types/index.d.ts +27 -0
  29. package/content/mods/plugins/status-line/.claude-plugin/plugin.json +6 -0
  30. package/content/mods/plugins/status-line/hooks/hooks.json +1 -0
  31. package/content/mods/plugins/status-line/hooks/line.ts +74 -0
  32. package/content/mods/plugins/status-line/hooks/register.tsx +141 -0
  33. package/content/mods/plugins/status-line/types/index.d.ts +5 -0
  34. package/content/mods/plugins/usage-line/.claude-plugin/plugin.json +6 -0
  35. package/content/mods/plugins/usage-line/hooks/codex.ts +52 -0
  36. package/content/mods/plugins/usage-line/hooks/format.ts +24 -0
  37. package/content/mods/plugins/usage-line/hooks/hooks.json +1 -0
  38. package/content/mods/plugins/usage-line/hooks/rate-limits.ts +23 -0
  39. package/content/mods/plugins/usage-line/hooks/register.tsx +83 -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 +101 -0
  53. package/content/skills/agent-sessions/agent-sessions.mjs +1462 -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 +102 -0
  58. package/content/skills/codex-subagent/codex-agent.mjs +260 -0
  59. package/content/skills/codex-subagent/codex-limit.mjs +106 -0
  60. package/content/skills/design-exploration/SKILL.md +121 -0
  61. package/content/skills/design-exploration/check-story.mjs +139 -0
  62. package/content/skills/design-exploration/reference-shots.md +15 -0
  63. package/content/skills/design-exploration/shoot-template.mjs +61 -0
  64. package/content/skills/domain-modeling/CONTEXT-FORMAT.md +60 -0
  65. package/content/skills/domain-modeling/SKILL.md +71 -0
  66. package/content/skills/e2e-triage/SKILL.md +80 -0
  67. package/content/skills/figma-export/SKILL.md +16 -18
  68. package/content/skills/git-commit/SKILL.md +21 -7
  69. package/content/skills/git-flow/SKILL.md +9 -5
  70. package/content/skills/grill-with-docs/SKILL.md +13 -0
  71. package/content/skills/grilling/SKILL.md +52 -0
  72. package/content/skills/handoff/SKILL.md +30 -72
  73. package/content/skills/handoff/save.md +189 -0
  74. package/content/skills/query/SKILL.md +165 -74
  75. package/content/skills/report/SKILL.md +26 -0
  76. package/content/skills/rxjs-signals/SKILL.md +33 -4
  77. package/content/skills/sdk-docs/SKILL.md +50 -14
  78. package/content/skills/sdk-local-build/SKILL.md +26 -8
  79. package/content/skills/sdk-local-build/sdk-local-baseline.mjs +64 -0
  80. package/content/skills/sdk-source/SKILL.md +37 -34
  81. package/content/skills/sdk-update/SKILL.md +103 -0
  82. package/content/skills/story-styling/SKILL.md +12 -10
  83. package/content/skills/styleguide/SKILL.md +13 -8
  84. package/content/skills/styleguide/assets.md +54 -0
  85. package/content/skills/styleguide/changesets.md +17 -0
  86. package/content/skills/styleguide/file-structure.md +73 -0
  87. package/content/skills/styleguide/lint-rule-lookup.md +52 -0
  88. package/content/skills/styleguide/storybook-structure.md +25 -0
  89. package/content/skills/theming/SKILL.md +76 -49
  90. package/content/skills/verify-in-app/SKILL.md +107 -0
  91. package/content/skills/verify-in-storybook/SKILL.md +1 -1
  92. package/content/skills/verify-on-apple-devices/SKILL.md +100 -0
  93. package/content/skills/verify-on-apple-devices/apple-remote.sh +421 -0
  94. package/content/skills/verify-on-apple-devices/sim-edge-back.m +159 -0
  95. package/migrations/list-state-query-form.md +20 -0
  96. package/migrations/nx-layout.md +29 -0
  97. package/migrations/sdk-components-over-hand-built-ui.md +27 -0
  98. package/migrations/search-query-field.md +52 -0
  99. package/migrations/studio-claude-plugin.md +27 -0
  100. package/migrations.json +47 -0
  101. package/package.json +8 -3
  102. package/src/index.js +84 -28
  103. package/src/index.js.map +1 -1
  104. package/src/lib/cli-args.d.ts +9 -0
  105. package/src/lib/cli-args.js +48 -0
  106. package/src/lib/cli-args.js.map +1 -0
  107. package/src/lib/commitlint.d.ts +10 -0
  108. package/src/lib/commitlint.js +51 -0
  109. package/src/lib/commitlint.js.map +1 -0
  110. package/src/lib/config.d.ts +53 -22
  111. package/src/lib/config.js +128 -12
  112. package/src/lib/config.js.map +1 -1
  113. package/src/lib/filter.d.ts +3 -0
  114. package/src/lib/filter.js +7 -5
  115. package/src/lib/filter.js.map +1 -1
  116. package/src/lib/frontmatter.d.ts +2 -0
  117. package/src/lib/frontmatter.js +33 -5
  118. package/src/lib/frontmatter.js.map +1 -1
  119. package/src/lib/git-flow/config.js +1 -1
  120. package/src/lib/git-flow/config.js.map +1 -1
  121. package/src/lib/git-flow/index.d.ts +1 -0
  122. package/src/lib/git-flow/index.js +20 -6
  123. package/src/lib/git-flow/index.js.map +1 -1
  124. package/src/lib/git-flow/parse.js +38 -12
  125. package/src/lib/git-flow/parse.js.map +1 -1
  126. package/src/lib/git-flow/rename.d.ts +24 -0
  127. package/src/lib/git-flow/rename.js +70 -0
  128. package/src/lib/git-flow/rename.js.map +1 -0
  129. package/src/lib/git-flow/start.d.ts +27 -0
  130. package/src/lib/git-flow/start.js +34 -1
  131. package/src/lib/git-flow/start.js.map +1 -1
  132. package/src/lib/git-flow-command.js +10 -2
  133. package/src/lib/git-flow-command.js.map +1 -1
  134. package/src/lib/git-flow-repair.d.ts +1 -1
  135. package/src/lib/git-flow-repair.js +30 -15
  136. package/src/lib/git-flow-repair.js.map +1 -1
  137. package/src/lib/git-flow-start.d.ts +1 -1
  138. package/src/lib/git-flow-start.js +25 -32
  139. package/src/lib/git-flow-start.js.map +1 -1
  140. package/src/lib/git.d.ts +37 -0
  141. package/src/lib/git.js +85 -3
  142. package/src/lib/git.js.map +1 -1
  143. package/src/lib/gitlab.js +24 -6
  144. package/src/lib/gitlab.js.map +1 -1
  145. package/src/lib/index.d.ts +2 -0
  146. package/src/lib/index.js +26 -11
  147. package/src/lib/index.js.map +1 -1
  148. package/src/lib/migrate.js +8 -2
  149. package/src/lib/migrate.js.map +1 -1
  150. package/src/lib/output-style-command.d.ts +3 -0
  151. package/src/lib/output-style-command.js +69 -0
  152. package/src/lib/output-style-command.js.map +1 -0
  153. package/src/lib/output-style.d.ts +38 -0
  154. package/src/lib/output-style.js +134 -0
  155. package/src/lib/output-style.js.map +1 -0
  156. package/src/lib/owned-paths.js +8 -2
  157. package/src/lib/owned-paths.js.map +1 -1
  158. package/src/lib/package-runner.d.ts +4 -0
  159. package/src/lib/package-runner.js +86 -0
  160. package/src/lib/package-runner.js.map +1 -0
  161. package/src/lib/plain-text.d.ts +9 -0
  162. package/src/lib/plain-text.js +22 -0
  163. package/src/lib/plain-text.js.map +1 -0
  164. package/src/lib/plan.d.ts +6 -6
  165. package/src/lib/plan.js +153 -40
  166. package/src/lib/plan.js.map +1 -1
  167. package/src/lib/prettier.d.ts +21 -0
  168. package/src/lib/prettier.js +51 -0
  169. package/src/lib/prettier.js.map +1 -0
  170. package/src/lib/prompt.js +10 -2
  171. package/src/lib/prompt.js.map +1 -1
  172. package/src/lib/render.d.ts +14 -1
  173. package/src/lib/render.js +23 -5
  174. package/src/lib/render.js.map +1 -1
  175. package/src/lib/report-command.d.ts +34 -0
  176. package/src/lib/report-command.js +322 -0
  177. package/src/lib/report-command.js.map +1 -0
  178. package/src/lib/sessions-command.d.ts +4 -0
  179. package/src/lib/sessions-command.js +16 -0
  180. package/src/lib/sessions-command.js.map +1 -0
  181. package/src/lib/sync.d.ts +1 -2
  182. package/src/lib/sync.js +37 -17
  183. package/src/lib/sync.js.map +1 -1
  184. package/src/lib/targets/agents-skills.js +1 -1
  185. package/src/lib/targets/agents-skills.js.map +1 -1
  186. package/src/lib/targets/claude-hooks.d.ts +5 -0
  187. package/src/lib/targets/claude-hooks.js +27 -4
  188. package/src/lib/targets/claude-hooks.js.map +1 -1
  189. package/src/lib/targets/claude-mods.d.ts +20 -0
  190. package/src/lib/targets/claude-mods.js +47 -0
  191. package/src/lib/targets/claude-mods.js.map +1 -0
  192. package/src/lib/targets/claude.js +2 -3
  193. package/src/lib/targets/claude.js.map +1 -1
  194. package/src/lib/targets/codex-hooks.js +4 -2
  195. package/src/lib/targets/codex-hooks.js.map +1 -1
  196. package/src/lib/targets/codex.js +4 -4
  197. package/src/lib/targets/codex.js.map +1 -1
  198. package/src/lib/targets/copilot.js +4 -4
  199. package/src/lib/targets/copilot.js.map +1 -1
  200. package/src/lib/targets/cursor.js +3 -3
  201. package/src/lib/targets/cursor.js.map +1 -1
  202. package/src/lib/targets/git-hooks.d.ts +1 -1
  203. package/src/lib/targets/git-hooks.js +6 -5
  204. package/src/lib/targets/git-hooks.js.map +1 -1
  205. package/src/lib/targets/hooks-shared.d.ts +34 -5
  206. package/src/lib/targets/hooks-shared.js +132 -36
  207. package/src/lib/targets/hooks-shared.js.map +1 -1
  208. package/src/lib/targets/mcp.d.ts +25 -0
  209. package/src/lib/targets/mcp.js +114 -0
  210. package/src/lib/targets/mcp.js.map +1 -0
  211. package/src/lib/targets/shared.d.ts +1 -9
  212. package/src/lib/targets/shared.js +4 -8
  213. package/src/lib/targets/shared.js.map +1 -1
  214. package/src/lib/timetrack.d.ts +16 -0
  215. package/src/lib/timetrack.js +149 -0
  216. package/src/lib/timetrack.js.map +1 -0
  217. package/content/skills/styleguide/STYLEGUIDE.md +0 -520
  218. package/src/lib/jira.d.ts +0 -28
  219. package/src/lib/jira.js +0 -83
  220. package/src/lib/jira.js.map +0 -1
@@ -0,0 +1,260 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Run one Codex agent to completion and print only its final message.
4
+ *
5
+ * `codex exec` streams its whole reasoning and command trace to stdout. That trace costs a
6
+ * calling agent more context than the answer is worth, so it stays in a log file here.
7
+ *
8
+ * Usage: node codex-agent.mjs [options] "<prompt>"
9
+ */
10
+
11
+ import { spawn } from 'node:child_process';
12
+ import { createWriteStream, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
13
+ import { tmpdir } from 'node:os';
14
+ import { join } from 'node:path';
15
+ import { createInterface } from 'node:readline';
16
+
17
+ const DEFAULT_MODEL = 'gpt-6.2-sol';
18
+ const DEFAULT_TIMEOUT_SECONDS = 900;
19
+
20
+ const USAGE = `Usage: node codex-agent.mjs [options] "<prompt>"
21
+
22
+ -m, --model <id> Model id (default ${DEFAULT_MODEL})
23
+ -e, --effort <level> Reasoning effort: low | medium | high | xhigh
24
+ -w, --write Let the agent edit the working tree (default: read-only)
25
+ -C, --cd <dir> Working root for the agent (default: the current directory)
26
+ --resume <thread> Continue an earlier thread instead of starting one
27
+ --prompt-file <f> Read the prompt from a file
28
+ --schema <file> JSON Schema the final message must match
29
+ --timeout <sec> Give up after this many seconds (default ${DEFAULT_TIMEOUT_SECONDS})
30
+ --trace Also print the command and file-change trace
31
+ -h, --help Print this help`;
32
+
33
+ const parseArgs = (argv) => {
34
+ const options = {
35
+ model: DEFAULT_MODEL,
36
+ effort: '',
37
+ write: false,
38
+ cd: process.cwd(),
39
+ resume: '',
40
+ promptFile: '',
41
+ schema: '',
42
+ timeout: DEFAULT_TIMEOUT_SECONDS,
43
+ trace: false,
44
+ prompt: '',
45
+ };
46
+
47
+ const rest = [];
48
+
49
+ for (let index = 0; index < argv.length; index += 1) {
50
+ const arg = argv[index];
51
+ const next = () => {
52
+ index += 1;
53
+ if (index >= argv.length) throw new Error(`${arg} needs a value.`);
54
+ return argv[index];
55
+ };
56
+
57
+ if (arg === '-m' || arg === '--model') options.model = next();
58
+ else if (arg === '-e' || arg === '--effort') options.effort = next();
59
+ else if (arg === '-w' || arg === '--write') options.write = true;
60
+ else if (arg === '-C' || arg === '--cd') options.cd = next();
61
+ else if (arg === '--resume') options.resume = next();
62
+ else if (arg === '--prompt-file') options.promptFile = next();
63
+ else if (arg === '--schema') options.schema = next();
64
+ else if (arg === '--timeout') options.timeout = Number(next());
65
+ else if (arg === '--trace') options.trace = true;
66
+ else if (arg === '-h' || arg === '--help') options.help = true;
67
+ else if (arg.startsWith('-') && arg !== '-') throw new Error(`Unknown option ${arg}.`);
68
+ else rest.push(arg);
69
+ }
70
+
71
+ options.prompt = options.promptFile ? readFileSync(options.promptFile, 'utf8') : rest.join(' ');
72
+
73
+ return options;
74
+ };
75
+
76
+ const readStdin = () =>
77
+ new Promise((resolve) => {
78
+ let buffer = '';
79
+ process.stdin.setEncoding('utf8');
80
+ process.stdin.on('data', (chunk) => (buffer += chunk));
81
+ process.stdin.on('end', () => resolve(buffer));
82
+ });
83
+
84
+ const buildArgs = (options, lastMessageFile) => {
85
+ const args = ['exec'];
86
+
87
+ if (options.resume) args.push('resume');
88
+
89
+ args.push('--json', '--skip-git-repo-check', '-o', lastMessageFile, '-m', options.model);
90
+
91
+ // `codex exec resume` carries the sandbox and the working root of the session it resumes,
92
+ // and rejects both flags, so only a fresh run may pass them.
93
+ if (!options.resume) {
94
+ args.push('-C', options.cd, '--sandbox', options.write ? 'workspace-write' : 'read-only');
95
+ }
96
+
97
+ if (options.effort) args.push('-c', `model_reasoning_effort="${options.effort}"`);
98
+ if (options.schema) args.push('--output-schema', options.schema);
99
+ if (options.resume) args.push(options.resume);
100
+
101
+ args.push('-');
102
+
103
+ return args;
104
+ };
105
+
106
+ const describeItem = (item) => {
107
+ if (item.type === 'command_execution') return `$ ${String(item.command ?? '').split('\n')[0]}`;
108
+ if (item.type === 'file_change') {
109
+ const changes = Array.isArray(item.changes) ? item.changes : [];
110
+ return `~ ${changes.map((change) => `${change.kind ?? 'edit'} ${change.path ?? ''}`).join(', ')}`;
111
+ }
112
+ if (item.type === 'error') return `! ${item.message ?? 'unknown error'}`;
113
+ return '';
114
+ };
115
+
116
+ const duration = (milliseconds) => {
117
+ const seconds = Math.round(milliseconds / 1000);
118
+ return seconds < 60 ? `${seconds}s` : `${Math.floor(seconds / 60)}m${String(seconds % 60).padStart(2, '0')}s`;
119
+ };
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
+
130
+ const run = async () => {
131
+ const options = parseArgs(process.argv.slice(2));
132
+
133
+ if (options.help) {
134
+ process.stdout.write(`${USAGE}\n`);
135
+ return 0;
136
+ }
137
+
138
+ if (!options.prompt.trim() && !process.stdin.isTTY) options.prompt = await readStdin();
139
+
140
+ if (!options.prompt.trim()) {
141
+ process.stderr.write(`${USAGE}\n`);
142
+ return 2;
143
+ }
144
+
145
+ const logDir = join(tmpdir(), 'codex-agent');
146
+ mkdirSync(logDir, { recursive: true });
147
+
148
+ const stamp = new Date().toISOString().replace(/[:.]/g, '-');
149
+ const logFile = join(logDir, `${stamp}.jsonl`);
150
+ const lastMessageFile = join(logDir, `${stamp}.last.md`);
151
+ const indexFile = join(logDir, `${stamp}.run.json`);
152
+ const log = createWriteStream(logFile);
153
+ const started = Date.now();
154
+
155
+ const child = spawn('codex', buildArgs(options, lastMessageFile), {
156
+ stdio: ['pipe', 'pipe', 'pipe'],
157
+ env: process.env,
158
+ });
159
+
160
+ child.stdin.end(options.prompt);
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
+
175
+ const state = { thread: '', usage: null, errors: [], trace: [], failed: false };
176
+
177
+ createInterface({ input: child.stdout }).on('line', (line) => {
178
+ log.write(`${line}\n`);
179
+
180
+ let event;
181
+
182
+ try {
183
+ event = JSON.parse(line);
184
+ } catch {
185
+ return;
186
+ }
187
+
188
+ if (event.type === 'thread.started') state.thread = event.thread_id ?? '';
189
+ else if (event.type === 'turn.completed') state.usage = event.usage ?? null;
190
+ else if (event.type === 'turn.failed') {
191
+ state.failed = true;
192
+ state.errors.push(event.error?.message ?? 'the turn failed');
193
+ } else if (event.type === 'item.completed') {
194
+ const description = describeItem(event.item ?? {});
195
+ if (description) state.trace.push(description);
196
+ if (event.item?.type === 'error') state.errors.push(event.item.message ?? 'unknown error');
197
+ }
198
+ });
199
+
200
+ let stderrText = '';
201
+ child.stderr.setEncoding('utf8');
202
+ child.stderr.on('data', (chunk) => (stderrText += chunk));
203
+
204
+ const timer = setTimeout(() => child.kill('SIGKILL'), Math.max(1, options.timeout) * 1000);
205
+ const code = await new Promise((resolve) => child.on('close', resolve));
206
+
207
+ clearTimeout(timer);
208
+ log.end();
209
+
210
+ let finalMessage;
211
+
212
+ try {
213
+ finalMessage = readFileSync(lastMessageFile, 'utf8').trim();
214
+ rmSync(lastMessageFile, { force: true });
215
+ } catch {
216
+ finalMessage = '';
217
+ }
218
+
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
+ });
229
+
230
+ if (options.trace && state.trace.length > 0) process.stdout.write(`${state.trace.join('\n')}\n\n`);
231
+ if (finalMessage) process.stdout.write(`${finalMessage}\n`);
232
+
233
+ if (failed) {
234
+ process.stdout.write(`\ncodex agent FAILED: ${reason}\n`);
235
+ }
236
+
237
+ const parts = [
238
+ `codex ${options.model}`,
239
+ options.write ? 'workspace-write' : 'read-only',
240
+ duration(Date.now() - started),
241
+ ];
242
+
243
+ if (state.usage) parts.push(`${state.usage.output_tokens ?? 0} out tok`);
244
+
245
+ process.stdout.write(`\n--- ${parts.join(' · ')}\n`);
246
+
247
+ if (state.thread) process.stdout.write(`resume: --resume ${state.thread}\n`);
248
+
249
+ process.stdout.write(`log: ${logFile}\n`);
250
+
251
+ return failed ? 1 : 0;
252
+ };
253
+
254
+ run().then(
255
+ (code) => process.exit(code),
256
+ (error) => {
257
+ process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
258
+ process.exit(2);
259
+ },
260
+ );
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Print how much of the Codex 5h and weekly limit is left and when each resets.
4
+ * Exit code 1 at 5% or less of the 5h window or at the weekly limit, 2 without data, and 0 otherwise.
5
+ *
6
+ * Usage: node codex-limit.mjs [--json]
7
+ */
8
+
9
+ import { readdirSync, readFileSync, statSync } from 'node:fs';
10
+ import { homedir } from 'node:os';
11
+ import { join } from 'node:path';
12
+ import { pathToFileURL } from 'node:url';
13
+
14
+ const SCAN_FILES = 12;
15
+ const FIVE_HOUR_RESERVE_PERCENT = 5;
16
+
17
+ /** Reads the `codex` rate limits out of one rollout line, or undefined when the line carries none. */
18
+ export function parseRateLimitLine(line) {
19
+ if (!line.includes('"rate_limits"')) return undefined;
20
+ let event;
21
+ try {
22
+ event = JSON.parse(line);
23
+ } catch {
24
+ return undefined;
25
+ }
26
+ const limits = event?.payload?.rate_limits;
27
+ if (!limits?.primary || limits.limit_id !== 'codex') return undefined;
28
+ const at = Date.parse(event.timestamp);
29
+ if (Number.isNaN(at)) return undefined;
30
+ return { at, primary: limits.primary, secondary: limits.secondary };
31
+ }
32
+
33
+ /** Turns a window into what is left now: a window past its reset is full again. */
34
+ export function windowStatus(window, now) {
35
+ if (!window) return undefined;
36
+ const resetsAt = window.resets_at * 1000;
37
+ const leftPercent = resetsAt <= now ? 100 : Math.max(0, 100 - window.used_percent);
38
+ const reservePercent = window.window_minutes === 5 * 60 ? FIVE_HOUR_RESERVE_PERCENT : 0;
39
+ return { leftPercent, resetsAt, exhausted: leftPercent <= reservePercent };
40
+ }
41
+
42
+ export function limitStatus(sample, now) {
43
+ if (!sample) return undefined;
44
+ const fiveHour = windowStatus(sample.primary, now);
45
+ const week = windowStatus(sample.secondary, now);
46
+ return { fiveHour, week, exhausted: Boolean(fiveHour?.exhausted || week?.exhausted), sampledAt: sample.at };
47
+ }
48
+
49
+ function rolloutFiles(root) {
50
+ const found = [];
51
+ const walk = (dir) => {
52
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
53
+ const path = join(dir, entry.name);
54
+ if (entry.isDirectory()) walk(path);
55
+ else if (entry.name.endsWith('.jsonl')) found.push({ path, mtime: statSync(path).mtimeMs });
56
+ }
57
+ };
58
+ try {
59
+ walk(root);
60
+ } catch {
61
+ return [];
62
+ }
63
+ return found.sort((a, b) => b.mtime - a.mtime).slice(0, SCAN_FILES);
64
+ }
65
+
66
+ /** The newest rate-limit sample in the most recently written rollout files. */
67
+ export function latestSample(sessionsRoot) {
68
+ let latest;
69
+ for (const file of rolloutFiles(sessionsRoot)) {
70
+ for (const line of readFileSync(file.path, 'utf8').split('\n')) {
71
+ const sample = parseRateLimitLine(line);
72
+ if (sample && (!latest || sample.at >= latest.at)) latest = sample;
73
+ }
74
+ }
75
+ return latest;
76
+ }
77
+
78
+ const pad = (value) => String(value).padStart(2, '0');
79
+
80
+ function clock(ms, now) {
81
+ const date = new Date(ms);
82
+ const time = `${pad(date.getHours())}:${pad(date.getMinutes())}`;
83
+ const sameDay = date.toDateString() === new Date(now).toDateString();
84
+ return sameDay ? time : `${pad(date.getDate())}.${pad(date.getMonth() + 1)}. ${time}`;
85
+ }
86
+
87
+ export function formatStatus(status, now) {
88
+ const part = (label, window) =>
89
+ window ? `${label} ${window.leftPercent}% left, resets ${clock(window.resetsAt, now)}` : `${label} unknown`;
90
+ const verdict = status.exhausted ? 'exhausted: use a Claude subagent' : 'ok';
91
+ return `${part('5h', status.fiveHour)}\n${part('week', status.week)}\nverdict: ${verdict}`;
92
+ }
93
+
94
+ function main() {
95
+ const now = Date.now();
96
+ const sample = latestSample(join(process.env.CODEX_HOME ?? join(homedir(), '.codex'), 'sessions'));
97
+ const status = limitStatus(sample, now);
98
+ if (!status) {
99
+ console.log('verdict: unknown (no Codex rate-limit data found), treat Codex as available');
100
+ process.exit(2);
101
+ }
102
+ console.log(process.argv.includes('--json') ? JSON.stringify(status) : formatStatus(status, now));
103
+ process.exit(status.exhausted ? 1 : 0);
104
+ }
105
+
106
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) main();
@@ -0,0 +1,121 @@
1
+ ---
2
+ name: design-exploration
3
+ description: 'How a visual design exploration runs: step size, what to show the user at each stop, when you may commit. Read BEFORE any visual design work on a sketch, prototype, theme, palette or component look.'
4
+ kind: skill
5
+ scope: both
6
+ vars: [storybookUrl]
7
+ ---
8
+
9
+ # Design exploration
10
+
11
+ A design exploration is a dialog. **The user is the designer. You find and frame. The user
12
+ chooses.** A finding is not a licence to pick the fix.
13
+
14
+ One exception: where the rules of the project give your role its own picks, build your recommendation, record the
15
+ pick with `--by <model id>` and report it. Do not stop for a choice then.
16
+
17
+ The unit of work is one open question, with every answer drawn side by side at the same
18
+ geometry: a **sketch** on a product, or a **call** in a repository with the old setup. A variant wins
19
+ or loses only against the other variants of its question.
20
+
21
+ ## The rules
22
+
23
+ 1. **One open call at a time.** Take one question. Draw its variants. Stop.
24
+ 2. **Put the variants in the call, then name your pick.** Two to four variants, drawn for
25
+ real, side by side, labelled, with what each one costs. Your pick is a proposal. Never ask
26
+ the user what they want or a yes/no question about content: deliver strong variants.
27
+ 3. **Commit only when the user says commit.** A merge in Ethlete Studio counts as
28
+ that word for the merged part: commit the part, not open sketches.
29
+ 4. **A clear rejection starts the next call.** Settle and record it, then draw
30
+ the next focused question, within the user's original scope. Stop only when the
31
+ user asks to pause or end the exploration, or when their feedback leaves no grounded next
32
+ question.
33
+ 5. **Keep the answer short.** 120 words at most.
34
+ 6. **A reference informs, it is not a template.** Before you show a round led by a reference
35
+ (a Figma file, another product), state the problem the reference solves, the principle you take
36
+ from it, and how each variant differs in concept. Then review the variants beside the reference
37
+ for literal copies. Derive the composition from the product's own visual language; a new palette
38
+ or spacing on the reference's layout is not a different concept.
39
+
40
+ 7. **Visible UI is built only from a sketch the user picked.** A new or changed element, label,
41
+ badge or layout needs a picked sketch, and the build brief names its id. "Decision" and
42
+ "regression" items are no exception. Without a picked sketch, build data and specs only and
43
+ stop at the UI.
44
+
45
+ Confirm the step size once, at the start. A task is not finished while the user is still talking about it.
46
+
47
+ ## What one stop looks like
48
+
49
+ - The question, in one sentence.
50
+ - The sketch (or call slug) to look at.
51
+ - The variants, labelled A, B, C, one line each.
52
+ - Your pick, one line on why.
53
+ - Nothing else. No next step, no second finding.
54
+
55
+ **Do not send a screenshot.** The user keeps the call open. Screenshot only for your own check that a
56
+ variant renders. Do not write a scratch script for batch shots.
57
+
58
+ If a second defect appears, add it to the open list and give it one line. Do not draw it.
59
+
60
+ ## Where the variants are drawn
61
+
62
+ The exploration's plan file names the tool. Two shapes exist.
63
+
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.
68
+
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.
72
+
73
+ Details, read on demand:
74
+
75
+ - {%resource:reference-shots.md%}: screenshots of a Storybook story, with forced pseudo-states.
76
+
77
+ ## Check before you look
78
+
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:
83
+
84
+ ```bash
85
+ node check-story.mjs --lint <changed files> --tsconfig apps/<app>/.storybook/tsconfig.json
86
+ ```
87
+
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:
90
+
91
+ ```bash
92
+ node check-story.mjs --tsconfig <path> --story <story-id>
93
+ ```
94
+
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.
99
+
100
+ ## Delegating a sketch
101
+
102
+ Every brief names `model: opus`, and every prompt names the exact model id the sub-agent runs on,
103
+ for example "Your model id is `claude-opus-5-5`; pass `--by claude-opus-5-5` to every write
104
+ command." You know the id because you chose the model; the sub-agent does not, and must not guess.
105
+
106
+ 1. **One agent per sketch.** It draws all the variants of the sketch. Give it the sketch folder, the
107
+ fixture it must not change, and the claim of each variant. Do not spawn one agent per
108
+ variant: each would re-read the skill, the call, the fixture and the example, about 45-57k
109
+ tokens each, so the cost is several times higher. Calls are independent, so several calls
110
+ can run at once, one agent each.
111
+ 2. **One check-and-fix agent, after the drawing agents return.** Give it the changed files
112
+ and the call slug. It runs the check above, fixes what it reports, and repeats until the
113
+ check says `ok`. It may not change what a variant draws, only what stops it rendering.
114
+ 3. **One write-up agent, once the user settles the sketch.** Give it the verdict in the
115
+ user's own words and the plan file. It records what won, what lost and why, it sets each
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
117
+ the next call.
118
+
119
+ ## Writing it down
120
+
121
+ Every settled call goes in the exploration's plan file: what won, what lost, and why, plus an **Open** list. After a clear rejection, draw the next call from that record without waiting.
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Find out why a story does not render, in the cheapest order.
3
+ *
4
+ * A compile error renders as an overlay on top of the story, so a screenshot of it looks
5
+ * like a design. Run this first, and never screenshot before it says `ok`.
6
+ *
7
+ * Copy to the repository root - Node resolves `playwright` from the working directory.
8
+ *
9
+ * node check-story.mjs --lint <file>… --tsconfig <path> # ~4s, no browser
10
+ * node check-story.mjs --tsconfig <path> --story <story-id> # + the render
11
+ * SB_URL=http://localhost:4401 node check-story.mjs --story <story-id>
12
+ *
13
+ * Three stages, because they cost three different amounts:
14
+ *
15
+ * 1. `eslint` on the files you changed, about a second. Name the files - never a whole
16
+ * project, which is far slower and can fight the user's own editor.
17
+ * 2. `tsc --noEmit` reads the source. It needs no dev server, waits for no rebuild, and
18
+ * catches every syntax and type error in about three seconds. Almost everything you
19
+ * break is caught here.
20
+ * 3. The browser catches what the source cannot: an Angular template error, a runtime
21
+ * throw, a missing story id. It costs a browser launch, and it can only see a build the
22
+ * dev server has already finished, so a fresh edit needs a few seconds first.
23
+ *
24
+ * A type error does not stop this repo's Storybook - it transpiles without checking - so
25
+ * stage 2 alone will report `ok` on a file that does not compile. That is why stage 1 exists.
26
+ */
27
+ import { execFileSync } from 'node:child_process';
28
+
29
+ const BASE = process.env.SB_URL ?? 'http://localhost:4400';
30
+
31
+ /**
32
+ * The type checker to run. `tsc` resolves the one the repository installed. Set
33
+ * `TSC=@typescript/native-preview` for the Go port, which is about a third faster - but it
34
+ * rejects a `baseUrl` in the config, so a repository that still uses one cannot run it.
35
+ */
36
+ const TSC = process.env.TSC ?? null;
37
+
38
+ const flags = { '--lint': [], '--tsconfig': [], '--story': [] };
39
+ let current = null;
40
+
41
+ for (const arg of process.argv.slice(2)) {
42
+ if (arg in flags) current = arg;
43
+ else if (current) flags[current].push(arg);
44
+ }
45
+
46
+ const lintFiles = flags['--lint'];
47
+ const [tsconfig] = flags['--tsconfig'];
48
+ const [id] = flags['--story'];
49
+
50
+ if (lintFiles.length === 0 && !tsconfig && !id) {
51
+ console.error('usage: node check-story.mjs [--lint <file>…] [--tsconfig <path>] [--story <id>]');
52
+ process.exit(2);
53
+ }
54
+
55
+ /** A bundler stack runs to hundreds of frames and says nothing. Keep the message. */
56
+ const trim = (text) =>
57
+ [...new Set(text.split('\n').filter((line) => !/^\s+at /.test(line) && line.trim() !== ''))].slice(0, 12).join('\n');
58
+
59
+ if (lintFiles.length > 0) {
60
+ try {
61
+ execFileSync('npx', ['eslint', ...lintFiles], { encoding: 'utf8', stdio: 'pipe' });
62
+ } catch (error) {
63
+ console.error(`LINT\n${trim(`${error.stdout ?? ''}${error.stderr ?? ''}`)}`);
64
+ process.exit(1);
65
+ }
66
+ }
67
+
68
+ if (tsconfig) {
69
+ try {
70
+ const cmd = TSC ? ['-y', TSC] : ['tsc'];
71
+ execFileSync('npx', [...cmd, '--noEmit', '-p', tsconfig], { encoding: 'utf8', stdio: 'pipe' });
72
+ } catch (error) {
73
+ console.error(`TYPE ERROR\n${trim(`${error.stdout ?? ''}${error.stderr ?? ''}`)}`);
74
+ process.exit(1);
75
+ }
76
+ }
77
+
78
+ if (!id) {
79
+ console.log('ok');
80
+ process.exit(0);
81
+ }
82
+
83
+ const { chromium } = await import('playwright');
84
+
85
+ const browser = await chromium.launch();
86
+ const page = await browser.newPage({ viewport: { width: 1400, height: 900 } });
87
+
88
+ /** Angular throws at render time; the overlay never shows those, so read the console too. */
89
+ const consoleErrors = [];
90
+ page.on('console', (m) => m.type() === 'error' && consoleErrors.push(m.text()));
91
+ page.on('pageerror', (e) => consoleErrors.push(e.message));
92
+
93
+ await page.goto(`${BASE}/iframe.html?id=${id}&viewMode=story`, { waitUntil: 'domcontentloaded' });
94
+
95
+ const rendered = await page
96
+ .locator('#storybook-root > *')
97
+ .first()
98
+ .waitFor({ timeout: 15000 })
99
+ .then(
100
+ () => true,
101
+ () => false,
102
+ );
103
+
104
+ /** The webpack overlay is an iframe, so its text is only reachable through a frame locator. */
105
+ const webpackOverlayText =
106
+ (await page.locator('#webpack-dev-server-client-overlay').count()) > 0
107
+ ? await page
108
+ .frameLocator('#webpack-dev-server-client-overlay')
109
+ .locator('body')
110
+ .innerText()
111
+ .catch(() => '(overlay present, text unreadable)')
112
+ : '';
113
+ /** The Vite overlay keeps its text in a shadow root. */
114
+ const viteOverlayText = await page.evaluate(() => {
115
+ const overlay = document.querySelector('vite-error-overlay');
116
+ if (!overlay) return '';
117
+ return overlay.shadowRoot?.textContent?.trim() || '(overlay present, text unreadable)';
118
+ });
119
+ const overlayText = webpackOverlayText || viteOverlayText;
120
+
121
+ await browser.close();
122
+
123
+ if (overlayText) {
124
+ console.error(`COMPILE ERROR on ${id}\n${trim(overlayText)}`);
125
+ process.exit(1);
126
+ }
127
+
128
+ if (!rendered) {
129
+ console.error(`EMPTY on ${id} - #storybook-root never got a child.`);
130
+ if (consoleErrors.length > 0) console.error(trim(consoleErrors.join('\n')));
131
+ process.exit(1);
132
+ }
133
+
134
+ if (consoleErrors.length > 0) {
135
+ console.error(`RENDERED WITH ERRORS on ${id}\n${trim(consoleErrors.join('\n'))}`);
136
+ process.exit(1);
137
+ }
138
+
139
+ console.log(`ok ${id}`);
@@ -0,0 +1,15 @@
1
+ # Design exploration: screenshots
2
+
3
+ **Off by default.** The user has the call open and sends you a picture when something looks
4
+ wrong. Take one only when the code cannot tell you whether two variants really differ, and
5
+ never to put in front of the user. Copy `shoot-template.mjs` from this skill folder to the repository
6
+ root.
7
+
8
+ ```bash
9
+ node shoot.mjs <story-id> 1100 760 out.png
10
+ ```
11
+
12
+ - `waitUntil: 'networkidle'` never settles on an iframe that holds a live dev server
13
+ connection. Use `'domcontentloaded'`.
14
+ - `:hover`, `:focus-visible` and `:active` need a CDP session and `CSS.forcePseudoState`.
15
+ Several hold open at once, so one image shows them all. The template does this.