self-evolve-framework 1.5.0 → 1.6.1

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 (154) hide show
  1. package/README.md +33 -23
  2. package/bin/cli.js +24 -67
  3. package/package.json +1 -1
  4. package/template/rules/knowledge/README.md +56 -0
  5. package/template/rules/knowledge/ant-design-vue.mdc +54 -0
  6. package/template/rules/knowledge/general.mdc +56 -0
  7. package/template/rules/knowledge/rust.mdc +55 -0
  8. package/template/rules/knowledge/shadcn-svelte.mdc +64 -0
  9. package/template/rules/knowledge/svelte.mdc +135 -0
  10. package/template/rules/knowledge/tailwind.mdc +66 -0
  11. package/template/rules/knowledge/tauri.mdc +65 -0
  12. package/template/rules/knowledge/typescript.mdc +41 -0
  13. package/template/rules/knowledge/vue.mdc +48 -0
  14. package/template/rules/ponytail.mdc +23 -98
  15. package/template/rules/self-evolve.mdc +24 -0
  16. package/template/skills/impeccable/SKILL.md +47 -174
  17. package/template/skills/skillopt-sleep/SKILL.md +34 -48
  18. package/template/skills/impeccable/agents/impeccable_asset_producer.toml +0 -92
  19. package/template/skills/impeccable/agents/impeccable_manual_edit_applier.toml +0 -95
  20. package/template/skills/impeccable/agents/openai.yaml +0 -4
  21. package/template/skills/impeccable/reference/adapt.md +0 -311
  22. package/template/skills/impeccable/reference/animate.md +0 -201
  23. package/template/skills/impeccable/reference/audit.md +0 -133
  24. package/template/skills/impeccable/reference/bolder.md +0 -113
  25. package/template/skills/impeccable/reference/brand.md +0 -108
  26. package/template/skills/impeccable/reference/clarify.md +0 -288
  27. package/template/skills/impeccable/reference/codex.md +0 -105
  28. package/template/skills/impeccable/reference/colorize.md +0 -257
  29. package/template/skills/impeccable/reference/craft.md +0 -123
  30. package/template/skills/impeccable/reference/critique.md +0 -790
  31. package/template/skills/impeccable/reference/delight.md +0 -302
  32. package/template/skills/impeccable/reference/distill.md +0 -111
  33. package/template/skills/impeccable/reference/document.md +0 -429
  34. package/template/skills/impeccable/reference/extract.md +0 -69
  35. package/template/skills/impeccable/reference/harden.md +0 -347
  36. package/template/skills/impeccable/reference/hooks.md +0 -90
  37. package/template/skills/impeccable/reference/init.md +0 -172
  38. package/template/skills/impeccable/reference/interaction-design.md +0 -189
  39. package/template/skills/impeccable/reference/layout.md +0 -161
  40. package/template/skills/impeccable/reference/live.md +0 -720
  41. package/template/skills/impeccable/reference/onboard.md +0 -234
  42. package/template/skills/impeccable/reference/optimize.md +0 -258
  43. package/template/skills/impeccable/reference/overdrive.md +0 -130
  44. package/template/skills/impeccable/reference/polish.md +0 -241
  45. package/template/skills/impeccable/reference/product.md +0 -60
  46. package/template/skills/impeccable/reference/quieter.md +0 -99
  47. package/template/skills/impeccable/reference/shape.md +0 -165
  48. package/template/skills/impeccable/reference/typeset.md +0 -279
  49. package/template/skills/impeccable/scripts/command-metadata.json +0 -94
  50. package/template/skills/impeccable/scripts/context-signals.mjs +0 -225
  51. package/template/skills/impeccable/scripts/context.mjs +0 -961
  52. package/template/skills/impeccable/scripts/critique-storage.mjs +0 -242
  53. package/template/skills/impeccable/scripts/detect-csp.mjs +0 -198
  54. package/template/skills/impeccable/scripts/detect.mjs +0 -21
  55. package/template/skills/impeccable/scripts/detector/browser/injected/index.mjs +0 -1937
  56. package/template/skills/impeccable/scripts/detector/cli/main.mjs +0 -290
  57. package/template/skills/impeccable/scripts/detector/design-system.mjs +0 -750
  58. package/template/skills/impeccable/scripts/detector/detect-antipatterns-browser.js +0 -5138
  59. package/template/skills/impeccable/scripts/detector/detect-antipatterns.mjs +0 -50
  60. package/template/skills/impeccable/scripts/detector/engines/browser/detect-url.mjs +0 -277
  61. package/template/skills/impeccable/scripts/detector/engines/regex/detect-text.mjs +0 -568
  62. package/template/skills/impeccable/scripts/detector/engines/static-html/css-cascade.mjs +0 -1015
  63. package/template/skills/impeccable/scripts/detector/engines/static-html/detect-html.mjs +0 -234
  64. package/template/skills/impeccable/scripts/detector/engines/visual/screenshot-contrast.mjs +0 -189
  65. package/template/skills/impeccable/scripts/detector/findings.mjs +0 -12
  66. package/template/skills/impeccable/scripts/detector/node/file-system.mjs +0 -198
  67. package/template/skills/impeccable/scripts/detector/profile/profiler.mjs +0 -166
  68. package/template/skills/impeccable/scripts/detector/registry/antipatterns.mjs +0 -448
  69. package/template/skills/impeccable/scripts/detector/rules/checks.mjs +0 -2671
  70. package/template/skills/impeccable/scripts/detector/shared/color.mjs +0 -124
  71. package/template/skills/impeccable/scripts/detector/shared/constants.mjs +0 -101
  72. package/template/skills/impeccable/scripts/detector/shared/inline-ignores.mjs +0 -148
  73. package/template/skills/impeccable/scripts/detector/shared/page.mjs +0 -7
  74. package/template/skills/impeccable/scripts/hook-admin.mjs +0 -661
  75. package/template/skills/impeccable/scripts/hook-before-edit.mjs +0 -476
  76. package/template/skills/impeccable/scripts/hook-lib.mjs +0 -1632
  77. package/template/skills/impeccable/scripts/hook.mjs +0 -61
  78. package/template/skills/impeccable/scripts/lib/design-parser.mjs +0 -842
  79. package/template/skills/impeccable/scripts/lib/impeccable-config.mjs +0 -638
  80. package/template/skills/impeccable/scripts/lib/impeccable-paths.mjs +0 -128
  81. package/template/skills/impeccable/scripts/lib/is-generated.mjs +0 -69
  82. package/template/skills/impeccable/scripts/lib/target-args.mjs +0 -42
  83. package/template/skills/impeccable/scripts/live/browser-script-parts.mjs +0 -49
  84. package/template/skills/impeccable/scripts/live/completion.mjs +0 -19
  85. package/template/skills/impeccable/scripts/live/event-validation.mjs +0 -137
  86. package/template/skills/impeccable/scripts/live/insert-ui.mjs +0 -458
  87. package/template/skills/impeccable/scripts/live/manual-apply.mjs +0 -939
  88. package/template/skills/impeccable/scripts/live/manual-edit-routes.mjs +0 -357
  89. package/template/skills/impeccable/scripts/live/manual-edits-buffer.mjs +0 -152
  90. package/template/skills/impeccable/scripts/live/session-store.mjs +0 -289
  91. package/template/skills/impeccable/scripts/live/svelte-component.mjs +0 -826
  92. package/template/skills/impeccable/scripts/live/sveltekit-adapter.mjs +0 -274
  93. package/template/skills/impeccable/scripts/live/ui-core.mjs +0 -180
  94. package/template/skills/impeccable/scripts/live/vocabulary.mjs +0 -36
  95. package/template/skills/impeccable/scripts/live-accept.mjs +0 -812
  96. package/template/skills/impeccable/scripts/live-browser-dom.js +0 -146
  97. package/template/skills/impeccable/scripts/live-browser-session.js +0 -123
  98. package/template/skills/impeccable/scripts/live-browser.js +0 -11173
  99. package/template/skills/impeccable/scripts/live-commit-manual-edits.mjs +0 -1241
  100. package/template/skills/impeccable/scripts/live-complete.mjs +0 -75
  101. package/template/skills/impeccable/scripts/live-copy-edit-agent.mjs +0 -683
  102. package/template/skills/impeccable/scripts/live-discard-manual-edits.mjs +0 -51
  103. package/template/skills/impeccable/scripts/live-inject.mjs +0 -583
  104. package/template/skills/impeccable/scripts/live-insert.mjs +0 -272
  105. package/template/skills/impeccable/scripts/live-manual-edit-evidence.mjs +0 -363
  106. package/template/skills/impeccable/scripts/live-poll.mjs +0 -384
  107. package/template/skills/impeccable/scripts/live-resume.mjs +0 -94
  108. package/template/skills/impeccable/scripts/live-server.mjs +0 -1135
  109. package/template/skills/impeccable/scripts/live-status.mjs +0 -61
  110. package/template/skills/impeccable/scripts/live-target.mjs +0 -30
  111. package/template/skills/impeccable/scripts/live-wrap.mjs +0 -894
  112. package/template/skills/impeccable/scripts/live.mjs +0 -297
  113. package/template/skills/impeccable/scripts/modern-screenshot.umd.js +0 -14
  114. package/template/skills/impeccable/scripts/palette.mjs +0 -633
  115. package/template/skills/impeccable/scripts/pin.mjs +0 -214
  116. package/template/skills/skillopt-sleep/scripts/python/__init__.py +0 -20
  117. package/template/skills/skillopt-sleep/scripts/python/__main__.py +0 -343
  118. package/template/skills/skillopt-sleep/scripts/python/backend.py +0 -1371
  119. package/template/skills/skillopt-sleep/scripts/python/budget.py +0 -75
  120. package/template/skills/skillopt-sleep/scripts/python/config.py +0 -162
  121. package/template/skills/skillopt-sleep/scripts/python/consolidate.py +0 -238
  122. package/template/skills/skillopt-sleep/scripts/python/cycle.py +0 -291
  123. package/template/skills/skillopt-sleep/scripts/python/dream.py +0 -138
  124. package/template/skills/skillopt-sleep/scripts/python/experiments/__init__.py +0 -1
  125. package/template/skills/skillopt-sleep/scripts/python/experiments/gbrain_bench.py +0 -119
  126. package/template/skills/skillopt-sleep/scripts/python/experiments/personas.py +0 -86
  127. package/template/skills/skillopt-sleep/scripts/python/experiments/report.py +0 -132
  128. package/template/skills/skillopt-sleep/scripts/python/experiments/run_experiment.py +0 -178
  129. package/template/skills/skillopt-sleep/scripts/python/experiments/run_gbrain.py +0 -209
  130. package/template/skills/skillopt-sleep/scripts/python/experiments/run_transfer.py +0 -155
  131. package/template/skills/skillopt-sleep/scripts/python/experiments/sweep.py +0 -164
  132. package/template/skills/skillopt-sleep/scripts/python/gate.py +0 -50
  133. package/template/skills/skillopt-sleep/scripts/python/harvest.py +0 -304
  134. package/template/skills/skillopt-sleep/scripts/python/harvest_codex.py +0 -253
  135. package/template/skills/skillopt-sleep/scripts/python/harvest_sources.py +0 -41
  136. package/template/skills/skillopt-sleep/scripts/python/judges.py +0 -84
  137. package/template/skills/skillopt-sleep/scripts/python/llm_miner.py +0 -134
  138. package/template/skills/skillopt-sleep/scripts/python/memory.py +0 -129
  139. package/template/skills/skillopt-sleep/scripts/python/mine.py +0 -312
  140. package/template/skills/skillopt-sleep/scripts/python/replay.py +0 -146
  141. package/template/skills/skillopt-sleep/scripts/python/rollout.py +0 -153
  142. package/template/skills/skillopt-sleep/scripts/python/scheduler.py +0 -138
  143. package/template/skills/skillopt-sleep/scripts/python/slow_update.py +0 -142
  144. package/template/skills/skillopt-sleep/scripts/python/staging.py +0 -103
  145. package/template/skills/skillopt-sleep/scripts/python/state.py +0 -96
  146. package/template/skills/skillopt-sleep/scripts/python/tasks_file.py +0 -81
  147. package/template/skills/skillopt-sleep/scripts/python/types.py +0 -146
  148. package/template/skills/skillopt-sleep/scripts/shell/__init__.py +0 -0
  149. package/template/skills/skillopt-sleep/scripts/shell/eval_only.py +0 -466
  150. package/template/skills/skillopt-sleep/scripts/shell/materialize_searchqa.py +0 -148
  151. package/template/skills/skillopt-sleep/scripts/shell/run_alfworld.sh +0 -60
  152. package/template/skills/skillopt-sleep/scripts/shell/run_searchqa.sh +0 -40
  153. package/template/skills/skillopt-sleep/scripts/shell/run_spreadsheetbench.sh +0 -39
  154. package/template/skills/skillopt-sleep/scripts/shell/train.py +0 -556
@@ -1,384 +0,0 @@
1
- /**
2
- * CLI client for the live variant mode poll/reply protocol.
3
- *
4
- * Usage:
5
- * node <scripts_path>/live-poll.mjs # Block until browser event, print JSON
6
- * node <scripts_path>/live-poll.mjs --stream # Experimental: keep polling; one JSON line per event
7
- * node <scripts_path>/live-poll.mjs --timeout=600000 # Custom timeout (ms); default is long-poll friendly
8
- * node <scripts_path>/live-poll.mjs --reply <id> done # Reply "done" to event <id>
9
- * node <scripts_path>/live-poll.mjs --reply <id> error "msg" # Reply with error
10
- */
11
-
12
- import { execFileSync } from 'node:child_process';
13
- import path from 'node:path';
14
- import { fileURLToPath } from 'node:url';
15
- import { completionAckForAcceptResult, completionTypeForAcceptResult } from './live/completion.mjs';
16
- import { readLiveServerInfo } from './lib/impeccable-paths.mjs';
17
-
18
- // Absolute path to a sibling script in this skill's scripts dir, so runtime
19
- // error hints print a directly-runnable command instead of a placeholder.
20
- const SELF_DIR = path.dirname(fileURLToPath(import.meta.url));
21
- const scriptCmd = (name) => `node "${path.join(SELF_DIR, name)}"`;
22
-
23
- // Node's built-in fetch (undici under the hood) enforces a 300s headers
24
- // timeout that can't be lowered per-request. We cap each request below
25
- // that ceiling and loop in `pollOnce` to synthesize a long poll without
26
- // depending on the standalone undici package.
27
- export const PER_REQUEST_TIMEOUT_MS = 270_000;
28
- export const DEFAULT_EVENT_LEASE_MS = 600_000;
29
-
30
- const EVENT_TYPES_NEEDING_AGENT_REPLY = new Set(['generate', 'steer', 'manual_edit_apply']);
31
-
32
- function readServerInfo() {
33
- const record = readLiveServerInfo(process.cwd());
34
- if (!record) {
35
- console.error(`No running live server found. Start one with: ${scriptCmd('live.mjs')}`);
36
- process.exit(1);
37
- }
38
- return record.info;
39
- }
40
-
41
- export function buildPollReplyPayload(token, { id, type, message, file, data }) {
42
- return { token, id, type, message, file, data };
43
- }
44
-
45
- export function manualApplyPollBanner(event = {}) {
46
- const id = event.id || 'EVENT_ID';
47
- return [
48
- `Manual Apply action required: edit source, then reply with \`live-poll.mjs --reply ${id} done --data '<json>'\`.`,
49
- 'The JSON data must include status, appliedEntryIds, failed, files, and notes; summary counters are only a recovery fallback.',
50
- 'Do not run live-commit-manual-edits.mjs for this leased event.',
51
- 'Do not poll again before replying.',
52
- ].join('\n') + '\n';
53
- }
54
-
55
- /**
56
- * Parse `--reply <id> <status> [--file path] [--data '<json>'] [message]` argv
57
- * into a reply object. Returns null when `--reply` is absent. Throws (code
58
- * INVALID_REPLY_ARGS) when the reply shape is missing its event id/status and
59
- * INVALID_DATA_JSON when `--data` is present but not valid JSON.
60
- */
61
- export function parseReplyArgs(args) {
62
- const replyIdx = args.indexOf('--reply');
63
- if (replyIdx === -1) return null;
64
- const id = args[replyIdx + 1];
65
- const status = args[replyIdx + 2];
66
- validateReplyArgs({ id, status });
67
- const fileIdx = args.indexOf('--file');
68
- const file = fileIdx !== -1 && fileIdx + 1 < args.length ? args[fileIdx + 1] : undefined;
69
- const dataIdx = args.indexOf('--data');
70
- let data;
71
- if (dataIdx !== -1 && dataIdx + 1 < args.length) {
72
- try {
73
- data = JSON.parse(args[dataIdx + 1]);
74
- } catch (err) {
75
- const wrapped = new Error('--data must be valid JSON: ' + err.message);
76
- wrapped.code = 'INVALID_DATA_JSON';
77
- throw wrapped;
78
- }
79
- }
80
- const message = args.find((a, i) =>
81
- i > replyIdx + 2
82
- && !a.startsWith('--')
83
- && i !== fileIdx + 1
84
- && i !== dataIdx + 1
85
- ) || undefined;
86
- return { id, type: status, message, file, data };
87
- }
88
-
89
- function validateReplyArgs({ id, status }) {
90
- const usage = `Usage: ${scriptCmd('live-poll.mjs')} --reply <id> <status> [--file path] [--data '<json>'] [message]`;
91
- if (!id || id.startsWith('--')) {
92
- const err = new Error(`${usage}\nMissing event id after --reply.`);
93
- err.code = 'INVALID_REPLY_ARGS';
94
- throw err;
95
- }
96
- if (['done', 'error', 'complete', 'discard', 'discarded'].includes(id)) {
97
- const err = new Error(`${usage}\nThe value after --reply must be the event id, not the status ${JSON.stringify(id)}. Use --reply EVENT_ID ${id}.`);
98
- err.code = 'INVALID_REPLY_ARGS';
99
- throw err;
100
- }
101
- if (!status || status.startsWith('--')) {
102
- const err = new Error(`${usage}\nMissing reply status after event id ${JSON.stringify(id)}.`);
103
- err.code = 'INVALID_REPLY_ARGS';
104
- throw err;
105
- }
106
- }
107
-
108
- export function requiresAgentReply(event) {
109
- return EVENT_TYPES_NEEDING_AGENT_REPLY.has(event?.type);
110
- }
111
-
112
- export async function postReply(base, token, reply) {
113
- const res = await fetch(`${base}/poll`, {
114
- method: 'POST',
115
- headers: { 'Content-Type': 'application/json' },
116
- body: JSON.stringify(buildPollReplyPayload(token, reply)),
117
- });
118
- if (!res.ok) {
119
- const body = await res.json().catch(() => ({}));
120
- const parts = [body.error || res.statusText, body.reason, body.hint].filter(Boolean);
121
- throw new Error(parts.join(': '));
122
- }
123
- }
124
-
125
- export async function fetchServerStatus(base, token) {
126
- const res = await fetch(`${base}/status?token=${token}`);
127
- if (res.status === 401) {
128
- const err = new Error('Authentication failed. The server token may have changed.');
129
- err.code = 'AUTH_FAILED';
130
- throw err;
131
- }
132
- if (!res.ok) {
133
- throw new Error(`Status failed: ${res.status} ${res.statusText}`);
134
- }
135
- return res.json();
136
- }
137
-
138
- export function isEventPending(status, eventId) {
139
- return (status.pendingEvents || []).some((entry) => entry.id === eventId);
140
- }
141
-
142
- export async function waitForEventAck(base, token, eventId, {
143
- pollIntervalMs = 400,
144
- maxWaitMs = 600_000,
145
- } = {}) {
146
- const deadline = Date.now() + maxWaitMs;
147
- while (Date.now() < deadline) {
148
- const status = await fetchServerStatus(base, token);
149
- if (!isEventPending(status, eventId)) return true;
150
- await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
151
- }
152
- return false;
153
- }
154
-
155
- export async function fetchNextEvent(base, token, { totalDeadline } = {}) {
156
- while (true) {
157
- if (totalDeadline && Date.now() >= totalDeadline) {
158
- return { type: 'timeout' };
159
- }
160
-
161
- const remaining = totalDeadline
162
- ? totalDeadline - Date.now()
163
- : PER_REQUEST_TIMEOUT_MS;
164
- const slice = Math.min(Math.max(remaining, 1000), PER_REQUEST_TIMEOUT_MS);
165
- const res = await fetch(`${base}/poll?token=${token}&timeout=${slice}&leaseMs=${DEFAULT_EVENT_LEASE_MS}`);
166
-
167
- if (res.status === 401) {
168
- const err = new Error('Authentication failed. The server token may have changed.');
169
- err.code = 'AUTH_FAILED';
170
- throw err;
171
- }
172
-
173
- if (!res.ok) {
174
- throw new Error(`Poll failed: ${res.status} ${res.statusText}`);
175
- }
176
-
177
- const next = await res.json();
178
- if (next?.type === 'timeout') {
179
- if (totalDeadline && Date.now() < totalDeadline) continue;
180
- if (!totalDeadline) continue;
181
- return next;
182
- }
183
- return next;
184
- }
185
- }
186
-
187
- export async function augmentEventWithAcceptHandling(event, base, token) {
188
- if (event.type !== 'accept' && event.type !== 'discard') return event;
189
-
190
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
191
- const acceptScript = path.join(__dirname, 'live-accept.mjs');
192
- const scriptArgs = buildAcceptScriptArgs(event);
193
-
194
- try {
195
- const out = execFileSync(
196
- 'node',
197
- [acceptScript, ...scriptArgs],
198
- { encoding: 'utf-8', cwd: process.cwd(), timeout: 30_000 },
199
- );
200
- event._acceptResult = JSON.parse(out.trim());
201
- } catch (err) {
202
- event._acceptResult = { handled: false, mode: 'error', error: err.message };
203
- }
204
-
205
- const completionType = completionTypeForAcceptResult(event.type, event._acceptResult);
206
- try {
207
- await postReply(base, token, {
208
- id: event.id,
209
- type: completionType,
210
- message: event._acceptResult?.error,
211
- file: event._acceptResult?.file,
212
- data: event._acceptResult?.carbonize === true ? { carbonize: true } : undefined,
213
- });
214
- } catch (err) {
215
- event._completionAck = { ok: false, error: err.message };
216
- }
217
- if (!event._completionAck) {
218
- event._completionAck = completionAckForAcceptResult(event.id, completionType, event._acceptResult);
219
- }
220
-
221
- return event;
222
- }
223
-
224
- export function buildAcceptScriptArgs(event) {
225
- const scriptArgs = event.type === 'discard'
226
- ? ['--id', String(event.id), '--discard']
227
- : ['--id', String(event.id), '--variant', String(event.variantId)];
228
- if (event.pageUrl) scriptArgs.push('--page-url', String(event.pageUrl));
229
- if (event.type === 'accept' && event.paramValues && Object.keys(event.paramValues).length > 0) {
230
- scriptArgs.push('--param-values', JSON.stringify(event.paramValues));
231
- }
232
- return scriptArgs;
233
- }
234
-
235
- export function writeCarbonizeBanner(event) {
236
- if (event.type === 'manual_edit_apply') {
237
- process.stderr.write('\n' + manualApplyPollBanner(event) + '\n');
238
- }
239
- if (event._acceptResult?.carbonize === true) {
240
- process.stderr.write('\n⚠ Carbonize cleanup REQUIRED before next poll. After cleanup, run live-complete.mjs --id ' + event.id + '. See reference/live.md "Required after accept".\n\n');
241
- }
242
- }
243
-
244
- export function printPollEvent(event) {
245
- console.log(JSON.stringify(event));
246
- }
247
-
248
- export async function runPollOnce(base, token, { totalTimeout = 600_000 } = {}) {
249
- const deadline = Date.now() + totalTimeout;
250
- const event = await fetchNextEvent(base, token, { totalDeadline: deadline });
251
- await augmentEventWithAcceptHandling(event, base, token);
252
- writeCarbonizeBanner(event);
253
- printPollEvent(event);
254
- return event;
255
- }
256
-
257
- export async function runPollStream(base, token, {
258
- ackTimeoutMs = 600_000,
259
- ackPollIntervalMs = 400,
260
- shouldContinue = () => true,
261
- } = {}) {
262
- process.stderr.write('[impeccable-poll] stream mode: one JSON object per line on stdout; use --reply while this process stays running\n');
263
-
264
- while (shouldContinue()) {
265
- const event = await fetchNextEvent(base, token);
266
- await augmentEventWithAcceptHandling(event, base, token);
267
- writeCarbonizeBanner(event);
268
- printPollEvent(event);
269
-
270
- if (event.type === 'exit') return event;
271
-
272
- if (requiresAgentReply(event)) {
273
- const acked = await waitForEventAck(base, token, event.id, {
274
- pollIntervalMs: ackPollIntervalMs,
275
- maxWaitMs: ackTimeoutMs,
276
- });
277
- if (!acked) {
278
- const err = new Error(`Timed out waiting for --reply on event ${event.id}`);
279
- err.code = 'ACK_TIMEOUT';
280
- throw err;
281
- }
282
- }
283
- }
284
-
285
- return null;
286
- }
287
-
288
- function handlePollError(err) {
289
- if (err.code === 'AUTH_FAILED') {
290
- console.error(err.message);
291
- console.error(`Try restarting: ${scriptCmd('live-server.mjs')} stop && ${scriptCmd('live.mjs')}`);
292
- process.exit(1);
293
- }
294
- if (err.cause?.code === 'ECONNREFUSED') {
295
- console.error(`Live server not running. Start one with: ${scriptCmd('live.mjs')}`);
296
- process.exit(1);
297
- }
298
- if (err.code === 'ACK_TIMEOUT') {
299
- console.error(err.message);
300
- process.exit(1);
301
- }
302
- console.error('Poll failed:', err.message);
303
- process.exit(1);
304
- }
305
-
306
- export async function pollCli() {
307
- const args = process.argv.slice(2);
308
-
309
- if (args.includes('--help') || args.includes('-h')) {
310
- console.log(`Usage: impeccable poll [options]
311
-
312
- Wait for a browser event from the live variant server, or reply to one.
313
-
314
- Modes:
315
- poll Block until a browser event arrives, print JSON, exit
316
- poll --stream Keep polling; print one JSON line per event (see live.md)
317
- poll --reply <id> done Reply "done" to event <id> (replace or insert generate)
318
- poll --reply <id> steer_done Reply after handling a steer event (unlocks Steer bar)
319
- poll --reply <id> error "msg" Reply with an error message
320
- poll --reply <id> done --data '<json>'
321
- Reply with a structured JSON result (manual_edit_apply)
322
-
323
- Options:
324
- --timeout=MS One-shot poll timeout in ms (default: 600000). Ignored in --stream mode
325
- --ack-timeout=MS Stream mode: max wait for --reply after generate/steer (default: 600000)
326
- --file PATH Attach a source file path to the reply (generate/steer flow)
327
- --data JSON Attach a JSON result object to the reply (manual_edit_apply flow). Must be valid JSON
328
- --help Show this help message
329
-
330
- Harness note:
331
- Default one-shot mode is the portable contract for Claude Code, Codex, and Cursor.
332
- --stream is experimental for harnesses with fast incremental stdout; do not use on Cursor.`);
333
- process.exit(0);
334
- }
335
-
336
- const info = readServerInfo();
337
- const base = `http://localhost:${info.port}`;
338
-
339
- // Reply mode: node <scripts_path>/live-poll.mjs --reply <id> <status> [--file path] [--data '<json>'] [message]
340
- if (args.includes('--reply')) {
341
- let reply;
342
- try {
343
- reply = parseReplyArgs(args);
344
- } catch (err) {
345
- console.error(err.message);
346
- process.exit(1);
347
- }
348
-
349
- try {
350
- await postReply(base, info.token, reply);
351
- } catch (err) {
352
- if (err.cause?.code === 'ECONNREFUSED') {
353
- console.error(`Live server not running. Start one with: ${scriptCmd('live.mjs')}`);
354
- } else {
355
- console.error('Reply failed:', err.message);
356
- }
357
- process.exit(1);
358
- }
359
- return;
360
- }
361
-
362
- const streamMode = args.includes('--stream');
363
- const ackTimeoutArg = args.find((a) => a.startsWith('--ack-timeout='));
364
- const ackTimeoutMs = ackTimeoutArg ? parseInt(ackTimeoutArg.split('=')[1], 10) : 600_000;
365
-
366
- try {
367
- if (streamMode) {
368
- await runPollStream(base, info.token, { ackTimeoutMs });
369
- return;
370
- }
371
-
372
- const timeoutArg = args.find((a) => a.startsWith('--timeout='));
373
- const totalTimeout = timeoutArg ? parseInt(timeoutArg.split('=')[1], 10) : 600_000;
374
- await runPollOnce(base, info.token, { totalTimeout });
375
- } catch (err) {
376
- handlePollError(err);
377
- }
378
- }
379
-
380
- // Auto-execute when run directly
381
- const _running = process.argv[1];
382
- if (_running?.endsWith('live-poll.mjs') || _running?.endsWith('live-poll.mjs/')) {
383
- pollCli();
384
- }
@@ -1,94 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Recover the next agent action from the durable live-session journal.
4
- */
5
-
6
- import { createLiveSessionStore } from './live/session-store.mjs';
7
-
8
- function manualApplyReplyCommand(eventOrId = 'EVENT_ID') {
9
- const id = typeof eventOrId === 'string' ? eventOrId : eventOrId?.id || 'EVENT_ID';
10
- return `live-poll.mjs --reply ${id} done --data '<json>'`;
11
- }
12
-
13
- export function manualApplyResumeHint(event = {}) {
14
- const summary = event.manualApplySummary || summarizeManualApplyEvent(event);
15
- const parts = [];
16
- if (summary.pageUrl) parts.push(`page ${summary.pageUrl}`);
17
- if (summary.chunk) parts.push(`chunk ${summary.chunk.index}/${summary.chunk.total}`);
18
- if (Number.isFinite(summary.opCount)) parts.push(`${summary.opCount} op(s)`);
19
- if (Number.isFinite(summary.entryCount)) parts.push(`${summary.entryCount} entr${summary.entryCount === 1 ? 'y' : 'ies'}`);
20
- if (summary.files?.length) parts.push(`likely files: ${summary.files.join(', ')}`);
21
- const scope = parts.length ? ` (${parts.join(', ')})` : '';
22
- return `Manual Apply pending${scope}. If you have not already leased it, run live-poll.mjs. Apply the source edits from the manual_edit_apply batch, then reply with ${manualApplyReplyCommand(event.id)}. Polling only leases this work item; it does not commit source edits. Do not run live-commit-manual-edits.mjs for this leased event. Do not poll again before replying.`;
23
- }
24
-
25
- function summarizeManualApplyEvent(event = {}) {
26
- const entries = Array.isArray(event.batch?.entries) ? event.batch.entries : [];
27
- const opCount = entries.reduce((sum, entry) => sum + (Array.isArray(entry.ops) ? entry.ops.length : 0), 0);
28
- return {
29
- pageUrl: event.pageUrl || null,
30
- chunk: event.chunk || null,
31
- entryCount: entries.length,
32
- opCount,
33
- files: collectManualApplyFiles(event.batch),
34
- };
35
- }
36
-
37
- function collectManualApplyFiles(batch) {
38
- const files = [];
39
- for (const entry of batch?.entries || []) {
40
- for (const op of entry.ops || []) files.push(op.sourceHint?.file);
41
- }
42
- for (const candidate of batch?.candidates || []) {
43
- files.push(candidate.sourceHint?.relativeFile, candidate.sourceHint?.file);
44
- for (const item of candidate.textMatches || []) files.push(item.file);
45
- for (const item of candidate.objectKeyMatches || []) files.push(item.file);
46
- for (const item of candidate.locatorMatches || []) files.push(item.file);
47
- for (const item of candidate.contextTextMatches || []) files.push(item.file);
48
- }
49
- return [...new Set(files.filter((file) => typeof file === 'string' && file.length > 0))].sort();
50
- }
51
-
52
- function parseArgs(argv) {
53
- const out = { id: null };
54
- for (let i = 0; i < argv.length; i++) {
55
- const arg = argv[i];
56
- if (arg === '--id') out.id = argv[++i];
57
- else if (arg.startsWith('--id=')) out.id = arg.slice('--id='.length);
58
- else if (arg === '--help' || arg === '-h') out.help = true;
59
- }
60
- return out;
61
- }
62
-
63
- export async function resumeCli() {
64
- const args = parseArgs(process.argv.slice(2));
65
- if (args.help) {
66
- console.log(`Usage: node live-resume.mjs [--id SESSION_ID]\n\nPrint the active durable session checkpoint and the next safe agent action.`);
67
- return;
68
- }
69
-
70
- const store = createLiveSessionStore({ cwd: process.cwd(), sessionId: args.id || undefined });
71
- const snapshot = args.id ? store.getSnapshot(args.id) : store.listActiveSessions()[0] || null;
72
- if (!snapshot) {
73
- console.log(JSON.stringify({ active: false, nextAction: 'No active durable live session found.' }, null, 2));
74
- return;
75
- }
76
-
77
- const pending = snapshot.pendingEvent || null;
78
- const nextAction = pending
79
- ? pending.type === 'manual_edit_apply'
80
- ? manualApplyResumeHint(pending)
81
- : `Run live-poll.mjs, handle ${pending.type} ${pending.id}, then acknowledge with live-poll.mjs --reply ${pending.id} done.`
82
- : snapshot.phase === 'carbonize_required'
83
- ? `Finish carbonize cleanup${snapshot.sourceFile ? ` in ${snapshot.sourceFile}` : ''}, then run live-complete.mjs --id ${snapshot.id}.`
84
- : snapshot.phase === 'accept_requested'
85
- ? `Run live-complete.mjs --id ${snapshot.id} after verifying the accepted variant is written.`
86
- : `Inspect ${snapshot.id}; no pending agent event is currently queued.`;
87
-
88
- console.log(JSON.stringify({ active: true, snapshot, pendingEvent: pending, nextAction }, null, 2));
89
- }
90
-
91
- const _running = process.argv[1];
92
- if (_running?.endsWith('live-resume.mjs') || _running?.endsWith('live-resume.mjs/')) {
93
- resumeCli();
94
- }