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

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 +742 -0
  3. package/CLAUDE.md +1 -0
  4. package/README.md +430 -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 +388 -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 +152 -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 +100 -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 +68 -43
  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 +64 -5
  113. package/src/lib/config.js +140 -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 +160 -38
  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 +2 -0
  206. package/src/lib/targets/claude-hooks.js +8 -3
  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,229 @@
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, rmSync } 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 run = async () => {
122
+ const options = parseArgs(process.argv.slice(2));
123
+
124
+ if (options.help) {
125
+ process.stdout.write(`${USAGE}\n`);
126
+ return 0;
127
+ }
128
+
129
+ if (!options.prompt.trim() && !process.stdin.isTTY) options.prompt = await readStdin();
130
+
131
+ if (!options.prompt.trim()) {
132
+ process.stderr.write(`${USAGE}\n`);
133
+ return 2;
134
+ }
135
+
136
+ const logDir = join(tmpdir(), 'codex-agent');
137
+ mkdirSync(logDir, { recursive: true });
138
+
139
+ const stamp = new Date().toISOString().replace(/[:.]/g, '-');
140
+ const logFile = join(logDir, `${stamp}.jsonl`);
141
+ const lastMessageFile = join(logDir, `${stamp}.last.md`);
142
+ const log = createWriteStream(logFile);
143
+ const started = Date.now();
144
+
145
+ const child = spawn('codex', buildArgs(options, lastMessageFile), {
146
+ stdio: ['pipe', 'pipe', 'pipe'],
147
+ env: process.env,
148
+ });
149
+
150
+ child.stdin.end(options.prompt);
151
+
152
+ const state = { thread: '', usage: null, errors: [], trace: [], failed: false };
153
+
154
+ createInterface({ input: child.stdout }).on('line', (line) => {
155
+ log.write(`${line}\n`);
156
+
157
+ let event;
158
+
159
+ try {
160
+ event = JSON.parse(line);
161
+ } catch {
162
+ return;
163
+ }
164
+
165
+ if (event.type === 'thread.started') state.thread = event.thread_id ?? '';
166
+ else if (event.type === 'turn.completed') state.usage = event.usage ?? null;
167
+ else if (event.type === 'turn.failed') {
168
+ state.failed = true;
169
+ state.errors.push(event.error?.message ?? 'the turn failed');
170
+ } else if (event.type === 'item.completed') {
171
+ const description = describeItem(event.item ?? {});
172
+ if (description) state.trace.push(description);
173
+ if (event.item?.type === 'error') state.errors.push(event.item.message ?? 'unknown error');
174
+ }
175
+ });
176
+
177
+ let stderrText = '';
178
+ child.stderr.setEncoding('utf8');
179
+ child.stderr.on('data', (chunk) => (stderrText += chunk));
180
+
181
+ const timer = setTimeout(() => child.kill('SIGKILL'), Math.max(1, options.timeout) * 1000);
182
+ const code = await new Promise((resolve) => child.on('close', resolve));
183
+
184
+ clearTimeout(timer);
185
+ log.end();
186
+
187
+ let finalMessage;
188
+
189
+ try {
190
+ finalMessage = readFileSync(lastMessageFile, 'utf8').trim();
191
+ rmSync(lastMessageFile, { force: true });
192
+ } catch {
193
+ finalMessage = '';
194
+ }
195
+
196
+ const failed = code !== 0 || state.failed || (!finalMessage && state.errors.length > 0);
197
+
198
+ if (options.trace && state.trace.length > 0) process.stdout.write(`${state.trace.join('\n')}\n\n`);
199
+ if (finalMessage) process.stdout.write(`${finalMessage}\n`);
200
+
201
+ if (failed) {
202
+ const reason = state.errors.join('\n') || stderrText.trim() || `codex exited with code ${code}`;
203
+ process.stdout.write(`\ncodex agent FAILED: ${reason}\n`);
204
+ }
205
+
206
+ const parts = [
207
+ `codex ${options.model}`,
208
+ options.write ? 'workspace-write' : 'read-only',
209
+ duration(Date.now() - started),
210
+ ];
211
+
212
+ if (state.usage) parts.push(`${state.usage.output_tokens ?? 0} out tok`);
213
+
214
+ process.stdout.write(`\n--- ${parts.join(' · ')}\n`);
215
+
216
+ if (state.thread) process.stdout.write(`resume: --resume ${state.thread}\n`);
217
+
218
+ process.stdout.write(`log: ${logFile}\n`);
219
+
220
+ return failed ? 1 : 0;
221
+ };
222
+
223
+ run().then(
224
+ (code) => process.exit(code),
225
+ (error) => {
226
+ process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
227
+ process.exit(2);
228
+ },
229
+ );
@@ -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 0 when Codex can start a task, 1 when a window is exhausted, 2 without data.
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 EXHAUSTED_AT = 100;
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 expired = resetsAt <= now;
38
+ const usedPercent = expired ? 0 : window.used_percent;
39
+ return { leftPercent: Math.max(0, 100 - usedPercent), resetsAt, exhausted: usedPercent >= EXHAUSTED_AT };
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,203 @@
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: `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.
59
+
60
+ If a second defect appears, add it to the open list and give it one line. Do not draw it.
61
+
62
+ ## Where the variants are drawn
63
+
64
+ The exploration's plan file names the tool. Two shapes exist.
65
+
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.
74
+
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
147
+
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.
151
+
152
+ With `et design`, run the checker from the checkout it draws:
153
+
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.
161
+
162
+ With a Storybook, copy {%resource:check-story.mjs%} to the **repository root** first:
163
+
164
+ ```bash
165
+ node check-story.mjs --lint <changed files> --tsconfig apps/<app>/.storybook/tsconfig.json
166
+ ```
167
+
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:
170
+
171
+ ```bash
172
+ et design check --call <slug> # every variant of the call
173
+ et design check --call <slug> --variant b # one of them
174
+ node check-story.mjs --tsconfig <path> --story <story-id>
175
+ ```
176
+
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.
181
+
182
+ ## Delegating a sketch
183
+
184
+ Every brief names `model: opus`, and every prompt names the exact model id the sub-agent runs on,
185
+ for example "Your model id is `claude-opus-5-5`; pass `--by claude-opus-5-5` to every write
186
+ command." You know the id because you chose the model; the sub-agent does not, and must not guess.
187
+
188
+ 1. **One agent per sketch.** It draws all the variants of the sketch. Give it the sketch folder, the
189
+ fixture it must not change, and the claim of each variant. Do not spawn one agent per
190
+ variant: each would re-read the skill, the call, the fixture and the example, about 45-57k
191
+ tokens each, so the cost is several times higher. Calls are independent, so several calls
192
+ can run at once, one agent each.
193
+ 2. **One check-and-fix agent, after the drawing agents return.** Give it the changed files
194
+ and the call slug. It runs the check above, fixes what it reports, and repeats until the
195
+ 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
197
+ user's own words and the plan file. It records what won, what lost and why, it sets each
198
+ 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
+ the next call.
200
+
201
+ ## Writing it down
202
+
203
+ 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}`);