@ethlete/agent-rules 0.1.0-next.6 → 0.1.0-next.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +28 -0
- package/CHANGELOG.md +847 -0
- package/CLAUDE.md +1 -0
- package/README.md +244 -36
- package/THIRD-PARTY-LICENSES.md +35 -0
- package/content/defaults.json +1 -1
- package/content/hooks/away-mode.py +413 -0
- package/content/hooks/background-commands.py +177 -0
- package/content/hooks/builder-idle-check.py +562 -0
- package/content/hooks/context-warning.py +666 -134
- package/content/hooks/git-safety.py +213 -0
- package/content/hooks/human-wait-check.py +167 -0
- package/content/hooks/subagent-model-policy.py +261 -0
- package/content/mods/.claude-plugin/marketplace.json +26 -0
- package/content/mods/plugins/codex-runs/.claude-plugin/plugin.json +6 -0
- package/content/mods/plugins/codex-runs/hooks/agent-runs.ts +310 -0
- package/content/mods/plugins/codex-runs/hooks/hooks.json +1 -0
- package/content/mods/plugins/codex-runs/hooks/progress.ts +130 -0
- package/content/mods/plugins/codex-runs/hooks/register.tsx +283 -0
- package/content/mods/plugins/codex-runs/tests/pane.test.ts +21 -0
- package/content/mods/plugins/codex-runs/tsconfig.json +4 -0
- package/content/mods/plugins/codex-runs/types/index.d.ts +37 -0
- package/content/mods/plugins/e2e-progress/.claude-plugin/plugin.json +6 -0
- package/content/mods/plugins/e2e-progress/hooks/hooks.json +1 -0
- package/content/mods/plugins/e2e-progress/hooks/progress.ts +205 -0
- package/content/mods/plugins/e2e-progress/hooks/register.tsx +498 -0
- package/content/mods/plugins/e2e-progress/tsconfig.json +3 -0
- package/content/mods/plugins/e2e-progress/types/index.d.ts +27 -0
- package/content/mods/plugins/status-line/.claude-plugin/plugin.json +6 -0
- package/content/mods/plugins/status-line/hooks/hooks.json +1 -0
- package/content/mods/plugins/status-line/hooks/line.ts +74 -0
- package/content/mods/plugins/status-line/hooks/register.tsx +141 -0
- package/content/mods/plugins/status-line/types/index.d.ts +5 -0
- package/content/mods/plugins/usage-line/.claude-plugin/plugin.json +6 -0
- package/content/mods/plugins/usage-line/hooks/codex.ts +52 -0
- package/content/mods/plugins/usage-line/hooks/format.ts +24 -0
- package/content/mods/plugins/usage-line/hooks/hooks.json +1 -0
- package/content/mods/plugins/usage-line/hooks/rate-limits.ts +23 -0
- package/content/mods/plugins/usage-line/hooks/register.tsx +83 -0
- package/content/mods/plugins/usage-line/tsconfig.json +4 -0
- package/content/mods/plugins/usage-line/types/index.d.ts +5 -0
- package/content/output-styles/ste-clarity.md +131 -0
- package/content/rules/agent-sessions-wake-up.md +11 -0
- package/content/rules/app-styling.md +66 -0
- package/content/rules/comments.md +4 -1
- package/content/rules/lint-and-format.md +7 -5
- package/content/rules/nx-layout.md +53 -0
- package/content/rules/reactive-state.md +1 -1
- package/content/rules/styling.md +19 -10
- package/content/rules/subagent-models.md +42 -0
- package/content/rules/waiting-on-the-human.md +17 -0
- package/content/skills/agent-sessions/SKILL.md +101 -0
- package/content/skills/agent-sessions/agent-sessions.mjs +1462 -0
- package/content/skills/angular-patterns/SKILL.md +31 -7
- package/content/skills/api-source/SKILL.md +156 -0
- package/content/skills/app-testing/SKILL.md +141 -0
- package/content/skills/codex-subagent/SKILL.md +102 -0
- package/content/skills/codex-subagent/codex-agent.mjs +260 -0
- package/content/skills/codex-subagent/codex-limit.mjs +106 -0
- package/content/skills/design-exploration/SKILL.md +121 -0
- package/content/skills/design-exploration/check-story.mjs +139 -0
- package/content/skills/design-exploration/reference-shots.md +15 -0
- package/content/skills/design-exploration/shoot-template.mjs +61 -0
- package/content/skills/domain-modeling/CONTEXT-FORMAT.md +60 -0
- package/content/skills/domain-modeling/SKILL.md +71 -0
- package/content/skills/e2e-triage/SKILL.md +80 -0
- package/content/skills/figma-export/SKILL.md +16 -18
- package/content/skills/git-commit/SKILL.md +21 -7
- package/content/skills/git-flow/SKILL.md +9 -5
- package/content/skills/grill-with-docs/SKILL.md +13 -0
- package/content/skills/grilling/SKILL.md +52 -0
- package/content/skills/handoff/SKILL.md +30 -72
- package/content/skills/handoff/save.md +189 -0
- package/content/skills/query/SKILL.md +165 -74
- package/content/skills/report/SKILL.md +26 -0
- package/content/skills/rxjs-signals/SKILL.md +33 -4
- package/content/skills/sdk-docs/SKILL.md +50 -14
- package/content/skills/sdk-local-build/SKILL.md +26 -8
- package/content/skills/sdk-local-build/sdk-local-baseline.mjs +64 -0
- package/content/skills/sdk-source/SKILL.md +37 -34
- package/content/skills/sdk-update/SKILL.md +103 -0
- package/content/skills/story-styling/SKILL.md +12 -10
- package/content/skills/styleguide/SKILL.md +13 -8
- package/content/skills/styleguide/assets.md +54 -0
- package/content/skills/styleguide/changesets.md +17 -0
- package/content/skills/styleguide/file-structure.md +73 -0
- package/content/skills/styleguide/lint-rule-lookup.md +52 -0
- package/content/skills/styleguide/storybook-structure.md +25 -0
- package/content/skills/theming/SKILL.md +76 -49
- package/content/skills/verify-in-app/SKILL.md +107 -0
- package/content/skills/verify-in-storybook/SKILL.md +1 -1
- package/content/skills/verify-on-apple-devices/SKILL.md +100 -0
- package/content/skills/verify-on-apple-devices/apple-remote.sh +421 -0
- package/content/skills/verify-on-apple-devices/sim-edge-back.m +159 -0
- package/migrations/list-state-query-form.md +20 -0
- package/migrations/nx-layout.md +29 -0
- package/migrations/sdk-components-over-hand-built-ui.md +27 -0
- package/migrations/search-query-field.md +52 -0
- package/migrations/studio-claude-plugin.md +27 -0
- package/migrations.json +47 -0
- package/package.json +8 -3
- package/src/index.js +84 -28
- package/src/index.js.map +1 -1
- package/src/lib/cli-args.d.ts +9 -0
- package/src/lib/cli-args.js +48 -0
- package/src/lib/cli-args.js.map +1 -0
- package/src/lib/commitlint.d.ts +10 -0
- package/src/lib/commitlint.js +51 -0
- package/src/lib/commitlint.js.map +1 -0
- package/src/lib/config.d.ts +53 -22
- package/src/lib/config.js +128 -12
- package/src/lib/config.js.map +1 -1
- package/src/lib/filter.d.ts +3 -0
- package/src/lib/filter.js +7 -5
- package/src/lib/filter.js.map +1 -1
- package/src/lib/frontmatter.d.ts +2 -0
- package/src/lib/frontmatter.js +33 -5
- package/src/lib/frontmatter.js.map +1 -1
- package/src/lib/git-flow/config.js +1 -1
- package/src/lib/git-flow/config.js.map +1 -1
- package/src/lib/git-flow/index.d.ts +1 -0
- package/src/lib/git-flow/index.js +20 -6
- package/src/lib/git-flow/index.js.map +1 -1
- package/src/lib/git-flow/parse.js +38 -12
- package/src/lib/git-flow/parse.js.map +1 -1
- package/src/lib/git-flow/rename.d.ts +24 -0
- package/src/lib/git-flow/rename.js +70 -0
- package/src/lib/git-flow/rename.js.map +1 -0
- package/src/lib/git-flow/start.d.ts +27 -0
- package/src/lib/git-flow/start.js +34 -1
- package/src/lib/git-flow/start.js.map +1 -1
- package/src/lib/git-flow-command.js +10 -2
- package/src/lib/git-flow-command.js.map +1 -1
- package/src/lib/git-flow-repair.d.ts +1 -1
- package/src/lib/git-flow-repair.js +30 -15
- package/src/lib/git-flow-repair.js.map +1 -1
- package/src/lib/git-flow-start.d.ts +1 -1
- package/src/lib/git-flow-start.js +25 -32
- package/src/lib/git-flow-start.js.map +1 -1
- package/src/lib/git.d.ts +37 -0
- package/src/lib/git.js +85 -3
- package/src/lib/git.js.map +1 -1
- package/src/lib/gitlab.js +24 -6
- package/src/lib/gitlab.js.map +1 -1
- package/src/lib/index.d.ts +2 -0
- package/src/lib/index.js +26 -11
- package/src/lib/index.js.map +1 -1
- package/src/lib/migrate.js +8 -2
- package/src/lib/migrate.js.map +1 -1
- package/src/lib/output-style-command.d.ts +3 -0
- package/src/lib/output-style-command.js +69 -0
- package/src/lib/output-style-command.js.map +1 -0
- package/src/lib/output-style.d.ts +38 -0
- package/src/lib/output-style.js +134 -0
- package/src/lib/output-style.js.map +1 -0
- package/src/lib/owned-paths.js +8 -2
- package/src/lib/owned-paths.js.map +1 -1
- package/src/lib/package-runner.d.ts +4 -0
- package/src/lib/package-runner.js +86 -0
- package/src/lib/package-runner.js.map +1 -0
- package/src/lib/plain-text.d.ts +9 -0
- package/src/lib/plain-text.js +22 -0
- package/src/lib/plain-text.js.map +1 -0
- package/src/lib/plan.d.ts +6 -6
- package/src/lib/plan.js +153 -40
- package/src/lib/plan.js.map +1 -1
- package/src/lib/prettier.d.ts +21 -0
- package/src/lib/prettier.js +51 -0
- package/src/lib/prettier.js.map +1 -0
- package/src/lib/prompt.js +10 -2
- package/src/lib/prompt.js.map +1 -1
- package/src/lib/render.d.ts +14 -1
- package/src/lib/render.js +23 -5
- package/src/lib/render.js.map +1 -1
- package/src/lib/report-command.d.ts +34 -0
- package/src/lib/report-command.js +322 -0
- package/src/lib/report-command.js.map +1 -0
- package/src/lib/sessions-command.d.ts +4 -0
- package/src/lib/sessions-command.js +16 -0
- package/src/lib/sessions-command.js.map +1 -0
- package/src/lib/sync.d.ts +1 -2
- package/src/lib/sync.js +37 -17
- package/src/lib/sync.js.map +1 -1
- package/src/lib/targets/agents-skills.js +1 -1
- package/src/lib/targets/agents-skills.js.map +1 -1
- package/src/lib/targets/claude-hooks.d.ts +5 -0
- package/src/lib/targets/claude-hooks.js +27 -4
- package/src/lib/targets/claude-hooks.js.map +1 -1
- package/src/lib/targets/claude-mods.d.ts +20 -0
- package/src/lib/targets/claude-mods.js +47 -0
- package/src/lib/targets/claude-mods.js.map +1 -0
- package/src/lib/targets/claude.js +2 -3
- package/src/lib/targets/claude.js.map +1 -1
- package/src/lib/targets/codex-hooks.js +4 -2
- package/src/lib/targets/codex-hooks.js.map +1 -1
- package/src/lib/targets/codex.js +4 -4
- package/src/lib/targets/codex.js.map +1 -1
- package/src/lib/targets/copilot.js +4 -4
- package/src/lib/targets/copilot.js.map +1 -1
- package/src/lib/targets/cursor.js +3 -3
- package/src/lib/targets/cursor.js.map +1 -1
- package/src/lib/targets/git-hooks.d.ts +1 -1
- package/src/lib/targets/git-hooks.js +6 -5
- package/src/lib/targets/git-hooks.js.map +1 -1
- package/src/lib/targets/hooks-shared.d.ts +34 -5
- package/src/lib/targets/hooks-shared.js +132 -36
- package/src/lib/targets/hooks-shared.js.map +1 -1
- package/src/lib/targets/mcp.d.ts +25 -0
- package/src/lib/targets/mcp.js +114 -0
- package/src/lib/targets/mcp.js.map +1 -0
- package/src/lib/targets/shared.d.ts +1 -9
- package/src/lib/targets/shared.js +4 -8
- package/src/lib/targets/shared.js.map +1 -1
- package/src/lib/timetrack.d.ts +16 -0
- package/src/lib/timetrack.js +149 -0
- package/src/lib/timetrack.js.map +1 -0
- package/content/skills/styleguide/STYLEGUIDE.md +0 -520
- package/src/lib/jira.d.ts +0 -28
- package/src/lib/jira.js +0 -83
- package/src/lib/jira.js.map +0 -1
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
export type TraceLine = { kind: 'command' | 'files' | 'message' | 'error'; text: string };
|
|
2
|
+
|
|
3
|
+
export type Trace = {
|
|
4
|
+
thread: string;
|
|
5
|
+
commands: number;
|
|
6
|
+
lastCommand: string;
|
|
7
|
+
files: string[];
|
|
8
|
+
lastMessage: string;
|
|
9
|
+
lines: TraceLine[];
|
|
10
|
+
errors: string[];
|
|
11
|
+
outputTokens: number | null;
|
|
12
|
+
isCompleted: boolean;
|
|
13
|
+
isFailed: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type TraceReader = { trace: Trace; rest: string };
|
|
17
|
+
|
|
18
|
+
export type RunIndex = {
|
|
19
|
+
pid: number;
|
|
20
|
+
session: string;
|
|
21
|
+
cwd: string;
|
|
22
|
+
model: string;
|
|
23
|
+
effort: string;
|
|
24
|
+
sandbox: string;
|
|
25
|
+
prompt: string;
|
|
26
|
+
startedAt: number;
|
|
27
|
+
log: string;
|
|
28
|
+
endedAt?: number;
|
|
29
|
+
exitCode?: number | null;
|
|
30
|
+
failed?: boolean;
|
|
31
|
+
error?: string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type AgentRunState = 'running' | 'done' | 'failed';
|
|
35
|
+
|
|
36
|
+
export type AgentRun = {
|
|
37
|
+
id: string;
|
|
38
|
+
log: string;
|
|
39
|
+
session: string;
|
|
40
|
+
cwd: string;
|
|
41
|
+
label: string;
|
|
42
|
+
prompt: string;
|
|
43
|
+
startedAt: number;
|
|
44
|
+
endedAt: number | null;
|
|
45
|
+
state: AgentRunState;
|
|
46
|
+
error: string;
|
|
47
|
+
progress: string;
|
|
48
|
+
trace: TraceLine[];
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const KEEP_LINES = 40;
|
|
52
|
+
const SHELL_WRAPPER = /^\S*\/(?:ba|z)?sh -l?c (["'])([\s\S]*)\1$/;
|
|
53
|
+
|
|
54
|
+
const clip = (text: string, max: number) => {
|
|
55
|
+
const line = text.replace(/\s+/g, ' ').trim();
|
|
56
|
+
return line.length > max ? `${line.slice(0, max - 1)}…` : line;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const commandOf = (command: string) => {
|
|
60
|
+
const inner = SHELL_WRAPPER.exec(command.trim())?.[2] ?? command;
|
|
61
|
+
return clip(inner.replace(/\\"/g, '"'), 160);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const emptyTrace = (): Trace => ({
|
|
65
|
+
thread: '',
|
|
66
|
+
commands: 0,
|
|
67
|
+
lastCommand: '',
|
|
68
|
+
files: [],
|
|
69
|
+
lastMessage: '',
|
|
70
|
+
lines: [],
|
|
71
|
+
errors: [],
|
|
72
|
+
outputTokens: null,
|
|
73
|
+
isCompleted: false,
|
|
74
|
+
isFailed: false,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
type Item = { type?: string; command?: string; text?: string; message?: string; changes?: unknown };
|
|
78
|
+
type TraceEvent = {
|
|
79
|
+
type?: string;
|
|
80
|
+
thread_id?: string;
|
|
81
|
+
item?: Item;
|
|
82
|
+
usage?: { output_tokens?: number };
|
|
83
|
+
error?: { message?: string };
|
|
84
|
+
message?: string;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
function addLine(trace: Trace, line: TraceLine): Trace {
|
|
88
|
+
return { ...trace, lines: [...trace.lines, line].slice(-KEEP_LINES) };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function applyItem(trace: Trace, item: Item, isStarted: boolean): Trace {
|
|
92
|
+
if (item.type === 'command_execution') {
|
|
93
|
+
const command = commandOf(String(item.command ?? ''));
|
|
94
|
+
if (isStarted) return { ...trace, lastCommand: command };
|
|
95
|
+
return addLine(
|
|
96
|
+
{ ...trace, commands: trace.commands + 1, lastCommand: command },
|
|
97
|
+
{ kind: 'command', text: command },
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
if (isStarted) return trace;
|
|
101
|
+
if (item.type === 'agent_message' && item.text) {
|
|
102
|
+
return addLine({ ...trace, lastMessage: clip(item.text, 400) }, { kind: 'message', text: clip(item.text, 400) });
|
|
103
|
+
}
|
|
104
|
+
if (item.type === 'file_change' && Array.isArray(item.changes)) {
|
|
105
|
+
const paths = item.changes.map((change: { path?: string }) => String(change?.path ?? '')).filter(Boolean);
|
|
106
|
+
const files = [...trace.files.filter((file) => !paths.includes(file)), ...paths];
|
|
107
|
+
return addLine({ ...trace, files }, { kind: 'files', text: paths.join(', ') });
|
|
108
|
+
}
|
|
109
|
+
if (item.type === 'error') {
|
|
110
|
+
const message = clip(item.message ?? 'unknown error', 300);
|
|
111
|
+
return addLine({ ...trace, errors: [...trace.errors, message] }, { kind: 'error', text: message });
|
|
112
|
+
}
|
|
113
|
+
return trace;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function applyEvent(trace: Trace, event: TraceEvent): Trace {
|
|
117
|
+
switch (event.type) {
|
|
118
|
+
case 'thread.started':
|
|
119
|
+
return { ...trace, thread: event.thread_id ?? '' };
|
|
120
|
+
case 'item.started':
|
|
121
|
+
return event.item ? applyItem(trace, event.item, true) : trace;
|
|
122
|
+
case 'item.completed':
|
|
123
|
+
return event.item ? applyItem(trace, event.item, false) : trace;
|
|
124
|
+
case 'turn.completed':
|
|
125
|
+
return { ...trace, isCompleted: true, outputTokens: event.usage?.output_tokens ?? null };
|
|
126
|
+
case 'turn.failed': {
|
|
127
|
+
const message = clip(event.error?.message ?? 'the turn failed', 300);
|
|
128
|
+
return addLine(
|
|
129
|
+
{ ...trace, isFailed: true, errors: [...trace.errors, message] },
|
|
130
|
+
{ kind: 'error', text: message },
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
case 'error':
|
|
134
|
+
return addLine(trace, { kind: 'error', text: clip(event.message ?? 'unknown error', 300) });
|
|
135
|
+
default:
|
|
136
|
+
return trace;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function feedTrace(reader: TraceReader, chunk: string): TraceReader {
|
|
141
|
+
const lines = `${reader.rest}${chunk}`.split('\n');
|
|
142
|
+
const rest = lines.pop() ?? '';
|
|
143
|
+
let trace = reader.trace;
|
|
144
|
+
for (const line of lines) {
|
|
145
|
+
if (!line.trim()) continue;
|
|
146
|
+
try {
|
|
147
|
+
trace = applyEvent(trace, JSON.parse(line) as TraceEvent);
|
|
148
|
+
} catch {
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return { trace, rest };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export const parseTrace = (text: string) => feedTrace({ trace: emptyTrace(), rest: '' }, `${text}\n`).trace;
|
|
156
|
+
|
|
157
|
+
export function parseRunIndex(text: string): RunIndex | null {
|
|
158
|
+
try {
|
|
159
|
+
const value = JSON.parse(text) as Partial<RunIndex>;
|
|
160
|
+
if (typeof value.startedAt !== 'number' || typeof value.log !== 'string') return null;
|
|
161
|
+
return {
|
|
162
|
+
pid: Number(value.pid) || 0,
|
|
163
|
+
session: String(value.session ?? ''),
|
|
164
|
+
cwd: String(value.cwd ?? ''),
|
|
165
|
+
model: String(value.model ?? ''),
|
|
166
|
+
effort: String(value.effort ?? ''),
|
|
167
|
+
sandbox: String(value.sandbox ?? ''),
|
|
168
|
+
prompt: String(value.prompt ?? ''),
|
|
169
|
+
startedAt: value.startedAt,
|
|
170
|
+
log: value.log,
|
|
171
|
+
endedAt: typeof value.endedAt === 'number' ? value.endedAt : undefined,
|
|
172
|
+
exitCode: value.exitCode ?? null,
|
|
173
|
+
failed: value.failed === true,
|
|
174
|
+
error: String(value.error ?? ''),
|
|
175
|
+
};
|
|
176
|
+
} catch {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function stampTime(stamp: string) {
|
|
182
|
+
const match = /^(\d{4}-\d{2}-\d{2})T(\d{2})-(\d{2})-(\d{2})-(\d{3})Z$/.exec(stamp);
|
|
183
|
+
return match ? Date.parse(`${match[1]}T${match[2]}:${match[3]}:${match[4]}.${match[5]}Z`) : NaN;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function progressOf(trace: Trace) {
|
|
187
|
+
const parts = [`${trace.commands} cmd`];
|
|
188
|
+
if (trace.files.length > 0) parts.push(`${trace.files.length} files changed`);
|
|
189
|
+
const latest = trace.lines[trace.lines.length - 1];
|
|
190
|
+
if (latest?.kind === 'message') parts.push(`“${clip(latest.text, 100)}”`);
|
|
191
|
+
else if (trace.lastCommand) parts.push(`$ ${clip(trace.lastCommand, 100)}`);
|
|
192
|
+
return parts.join(' · ');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** `isAlive` is `null` when the wrapper's liveness is unknown. */
|
|
196
|
+
export function agentRunOf({
|
|
197
|
+
id,
|
|
198
|
+
log,
|
|
199
|
+
index,
|
|
200
|
+
trace,
|
|
201
|
+
logChangedAt,
|
|
202
|
+
isAlive,
|
|
203
|
+
now,
|
|
204
|
+
}: {
|
|
205
|
+
id: string;
|
|
206
|
+
log: string;
|
|
207
|
+
index: RunIndex | null;
|
|
208
|
+
trace: Trace;
|
|
209
|
+
logChangedAt: number;
|
|
210
|
+
isAlive: boolean | null;
|
|
211
|
+
now: number;
|
|
212
|
+
}): AgentRun {
|
|
213
|
+
const ended = index?.endedAt ?? null;
|
|
214
|
+
const lost = ended === null && (index ? isAlive === false : now - logChangedAt > 10 * 60_000);
|
|
215
|
+
const state: AgentRunState =
|
|
216
|
+
ended !== null
|
|
217
|
+
? index?.failed || trace.isFailed
|
|
218
|
+
? 'failed'
|
|
219
|
+
: 'done'
|
|
220
|
+
: trace.isFailed || lost
|
|
221
|
+
? 'failed'
|
|
222
|
+
: !index && trace.isCompleted
|
|
223
|
+
? 'done'
|
|
224
|
+
: 'running';
|
|
225
|
+
const error =
|
|
226
|
+
state !== 'failed'
|
|
227
|
+
? ''
|
|
228
|
+
: index?.error ||
|
|
229
|
+
trace.errors[trace.errors.length - 1] ||
|
|
230
|
+
(lost ? 'the wrapper stopped without an end mark' : 'failed');
|
|
231
|
+
const label = index
|
|
232
|
+
? [index.model, index.effort, index.sandbox === 'workspace-write' ? 'write' : ''].filter(Boolean).join(' ')
|
|
233
|
+
: 'codex';
|
|
234
|
+
return {
|
|
235
|
+
id,
|
|
236
|
+
log,
|
|
237
|
+
session: index?.session ?? '',
|
|
238
|
+
cwd: index?.cwd ?? '',
|
|
239
|
+
label,
|
|
240
|
+
prompt: index?.prompt ?? '',
|
|
241
|
+
startedAt: index?.startedAt ?? stampTime(id),
|
|
242
|
+
endedAt: ended ?? (state === 'running' ? null : logChangedAt),
|
|
243
|
+
state,
|
|
244
|
+
error,
|
|
245
|
+
progress: progressOf(trace),
|
|
246
|
+
trace: trace.lines,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export function shortIdOf(id: string) {
|
|
251
|
+
const at = stampTime(id);
|
|
252
|
+
if (Number.isNaN(at)) return id.slice(11, 19).replace(/-/g, ':');
|
|
253
|
+
const date = new Date(at);
|
|
254
|
+
return [date.getHours(), date.getMinutes(), date.getSeconds()].map((part) => String(part).padStart(2, '0')).join(':');
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export const isRunNamed = (run: { id: string }, name: string) =>
|
|
258
|
+
run.id === name || shortIdOf(run.id) === name.replace(/-/g, ':');
|
|
259
|
+
|
|
260
|
+
export function durationOf(run: { startedAt: number; endedAt: number | null }, now: number) {
|
|
261
|
+
const seconds = Math.max(0, Math.floor(((run.endedAt ?? now) - run.startedAt) / 1000));
|
|
262
|
+
const minutes = Math.floor(seconds / 60);
|
|
263
|
+
return minutes ? `${minutes}m${String(seconds % 60).padStart(2, '0')}s` : `${seconds}s`;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export function statusOf(runs: AgentRun[], session: string, now: number) {
|
|
267
|
+
const running = runs.filter((run) => run.state === 'running' && run.session === session);
|
|
268
|
+
if (running.length === 0) return undefined;
|
|
269
|
+
const oldest = Math.min(...running.map((run) => run.startedAt));
|
|
270
|
+
return `Codex: ${running.length} running, ${Math.max(0, Math.floor((now - oldest) / 60_000))}m`;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export function finishNotices(previous: AgentRun[], next: AgentRun[], session: string, now: number) {
|
|
274
|
+
const wasRunning = new Set(previous.filter((run) => run.state === 'running').map((run) => run.id));
|
|
275
|
+
return next
|
|
276
|
+
.filter((run) => run.state !== 'running' && wasRunning.has(run.id) && run.session === session)
|
|
277
|
+
.map((run) =>
|
|
278
|
+
run.state === 'failed'
|
|
279
|
+
? `Codex run failed after ${durationOf(run, now)}: ${clip(run.error, 120)}`
|
|
280
|
+
: `Codex run done in ${durationOf(run, now)}: ${clip(run.prompt || run.progress, 80)}`,
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export const isCodexAgentCommand = (command: unknown) =>
|
|
285
|
+
typeof command === 'string' && /codex-agent\.mjs\b/.test(command) && !/(?:^|\s)(?:-h|--help)\b/.test(command);
|
|
286
|
+
|
|
287
|
+
export function claimRuns(
|
|
288
|
+
waiting: { toolUseId: string; at: number }[],
|
|
289
|
+
claimed: Record<string, string>,
|
|
290
|
+
runs: AgentRun[],
|
|
291
|
+
session: string,
|
|
292
|
+
) {
|
|
293
|
+
const taken = new Set(Object.values(claimed));
|
|
294
|
+
const next = { ...claimed };
|
|
295
|
+
const free = runs
|
|
296
|
+
.filter((run) => run.session === session && !taken.has(run.id))
|
|
297
|
+
.sort((a, b) => a.startedAt - b.startedAt);
|
|
298
|
+
const still: typeof waiting = [];
|
|
299
|
+
for (const call of [...waiting].sort((a, b) => a.at - b.at)) {
|
|
300
|
+
const index = free.findIndex((run) => run.startedAt >= call.at - 5_000 && run.startedAt <= call.at + 120_000);
|
|
301
|
+
const run = free[index];
|
|
302
|
+
if (!run) {
|
|
303
|
+
still.push(call);
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
next[call.toolUseId] = run.id;
|
|
307
|
+
free.splice(index, 1);
|
|
308
|
+
}
|
|
309
|
+
return { claimed: next, waiting: still };
|
|
310
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "modules": ["./register.tsx"] }
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
const SEPARATOR = '\t';
|
|
2
|
+
const PANE_FORMAT = [
|
|
3
|
+
'session_id',
|
|
4
|
+
'session_name',
|
|
5
|
+
'session_created',
|
|
6
|
+
'session_path',
|
|
7
|
+
'pane_id',
|
|
8
|
+
'pane_dead',
|
|
9
|
+
'pane_dead_time',
|
|
10
|
+
'pane_current_command',
|
|
11
|
+
'ETHLETE_CODEX_OWNER',
|
|
12
|
+
]
|
|
13
|
+
.map((field) => `#{${field}}`)
|
|
14
|
+
.join(SEPARATOR);
|
|
15
|
+
|
|
16
|
+
const KEEP_ENDED_MS = 60 * 60_000;
|
|
17
|
+
const TAIL_LINES = 12;
|
|
18
|
+
const CODEX_NAME = /^codex(?:-|@|$)/;
|
|
19
|
+
const INPUT_HINT = /\b(?:to submit (?:answer|all)|to confirm|to approve|to select)\b/i;
|
|
20
|
+
const WORKING_HINT = /\([^)]*\b(?:esc|ctrl\+c) to interrupt\)/i;
|
|
21
|
+
const PROMPT = /^\s*›(?:\s|$)/;
|
|
22
|
+
|
|
23
|
+
type TmuxResult = { stdout: string; stderr: string; exitCode: number | null };
|
|
24
|
+
type Tmux = (args: string[]) => Promise<TmuxResult>;
|
|
25
|
+
type Scope = { sessionId: string; root: string };
|
|
26
|
+
type Pane = {
|
|
27
|
+
id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
paneId: string;
|
|
30
|
+
cwd: string;
|
|
31
|
+
owner: string;
|
|
32
|
+
startedAt: number;
|
|
33
|
+
dead: boolean;
|
|
34
|
+
endedAt: number | null;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type CodexRun = Omit<Pane, 'dead' | 'paneId'> & {
|
|
38
|
+
state: 'running' | 'waiting for input' | 'ended';
|
|
39
|
+
tail: string[];
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const visibleTo = ({ owner, cwd }: { owner: string; cwd: string }, { sessionId, root }: Scope) =>
|
|
43
|
+
owner !== '' ? owner === sessionId : cwd === root || cwd.startsWith(`${root.replace(/\/$/, '')}/`);
|
|
44
|
+
|
|
45
|
+
function codexPanes(stdout: string): Pane[] {
|
|
46
|
+
const panes = new Map<string, { pane: Pane; rank: number }>();
|
|
47
|
+
for (const line of stdout.split('\n')) {
|
|
48
|
+
const [session, name, created, cwd, paneId, dead, ended, command, owner = ''] = line.split(SEPARATOR);
|
|
49
|
+
const startedAt = Number(created) * 1000;
|
|
50
|
+
if (!session || !name || !cwd || !paneId || !startedAt || !Number.isFinite(startedAt)) continue;
|
|
51
|
+
if (command !== 'codex' && !CODEX_NAME.test(name) && owner === '') continue;
|
|
52
|
+
const id = `${session}:${created}`;
|
|
53
|
+
const rank = dead === '1' ? 0 : command === 'codex' ? 2 : 1;
|
|
54
|
+
if ((panes.get(id)?.rank ?? -1) >= rank) continue;
|
|
55
|
+
panes.set(id, {
|
|
56
|
+
rank,
|
|
57
|
+
pane: {
|
|
58
|
+
id,
|
|
59
|
+
name,
|
|
60
|
+
paneId,
|
|
61
|
+
cwd,
|
|
62
|
+
owner,
|
|
63
|
+
startedAt,
|
|
64
|
+
dead: dead === '1',
|
|
65
|
+
endedAt: ended ? Number(ended) * 1000 || null : null,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return [...panes.values()].map(({ pane }) => pane);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function stateOf(lines: string[]): CodexRun['state'] {
|
|
73
|
+
const footer = lines.slice(-8);
|
|
74
|
+
if (footer.some((line) => !PROMPT.test(line) && INPUT_HINT.test(line))) return 'waiting for input';
|
|
75
|
+
if (footer.some((line) => !PROMPT.test(line) && WORKING_HINT.test(line))) return 'running';
|
|
76
|
+
return footer.some((line) => PROMPT.test(line)) ? 'waiting for input' : 'running';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export async function discoverRuns({
|
|
80
|
+
tmux,
|
|
81
|
+
scope,
|
|
82
|
+
previous,
|
|
83
|
+
now,
|
|
84
|
+
}: {
|
|
85
|
+
tmux: Tmux;
|
|
86
|
+
scope: Scope;
|
|
87
|
+
previous: CodexRun[];
|
|
88
|
+
now: number;
|
|
89
|
+
}): Promise<CodexRun[]> {
|
|
90
|
+
const result = await tmux(['list-panes', '-a', '-F', PANE_FORMAT]);
|
|
91
|
+
const oldRuns = previous.filter(
|
|
92
|
+
(run) => visibleTo(run, scope) && (run.endedAt === null || now - run.endedAt < KEEP_ENDED_MS),
|
|
93
|
+
);
|
|
94
|
+
if (result.exitCode !== 0 && !/no server running|no such file or directory/i.test(result.stderr)) return oldRuns;
|
|
95
|
+
|
|
96
|
+
const panes = codexPanes(result.stdout);
|
|
97
|
+
const present = new Set(panes.map((pane) => pane.id));
|
|
98
|
+
const oldById = new Map(oldRuns.map((run) => [run.id, run]));
|
|
99
|
+
const current = await Promise.all(
|
|
100
|
+
panes
|
|
101
|
+
.filter((pane) => visibleTo(pane, scope))
|
|
102
|
+
.map(async ({ paneId, dead, ...pane }): Promise<CodexRun> => {
|
|
103
|
+
const capture = await tmux(['capture-pane', '-p', '-t', paneId, '-S', '-20']);
|
|
104
|
+
const old = oldById.get(pane.id);
|
|
105
|
+
const lines = capture.stdout
|
|
106
|
+
.trimEnd()
|
|
107
|
+
.split('\n')
|
|
108
|
+
.filter((line) => line.trim() !== '');
|
|
109
|
+
return {
|
|
110
|
+
...pane,
|
|
111
|
+
endedAt: dead ? (pane.endedAt ?? old?.endedAt ?? now) : null,
|
|
112
|
+
state: dead ? 'ended' : stateOf(capture.exitCode === 0 ? lines : (old?.tail ?? [])),
|
|
113
|
+
tail: capture.exitCode === 0 ? lines.slice(-TAIL_LINES) : (old?.tail ?? []),
|
|
114
|
+
};
|
|
115
|
+
}),
|
|
116
|
+
);
|
|
117
|
+
const ended = oldRuns
|
|
118
|
+
.filter((run) => !present.has(run.id))
|
|
119
|
+
.map((run): CodexRun => ({ ...run, state: 'ended', endedAt: run.endedAt ?? now }));
|
|
120
|
+
return [...current, ...ended]
|
|
121
|
+
.filter((run) => run.endedAt === null || now - run.endedAt < KEEP_ENDED_MS)
|
|
122
|
+
.sort((a, b) => b.startedAt - a.startedAt || a.name.localeCompare(b.name));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function durationOf(run: CodexRun, now: number): string {
|
|
126
|
+
const seconds = Math.max(0, Math.floor(((run.endedAt ?? now) - run.startedAt) / 1000));
|
|
127
|
+
const hours = Math.floor(seconds / 3600);
|
|
128
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
129
|
+
return hours ? `${hours}h ${minutes}m` : minutes ? `${minutes}m ${seconds % 60}s` : `${seconds}s`;
|
|
130
|
+
}
|