@bastani/atomic 0.5.2-0 → 0.5.3-0

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 (51) hide show
  1. package/dist/chunk-1gb5qxz9.js +1 -0
  2. package/dist/chunk-fdk7tact.js +417 -0
  3. package/dist/chunk-mn870nrv.js +982 -0
  4. package/dist/sdk/components/color-utils.d.ts +3 -0
  5. package/dist/sdk/components/connectors.d.ts +14 -0
  6. package/dist/sdk/components/connectors.test.d.ts +1 -0
  7. package/dist/sdk/components/edge.d.ts +3 -0
  8. package/dist/sdk/components/error-boundary.d.ts +22 -0
  9. package/dist/sdk/components/graph-theme.d.ts +16 -0
  10. package/dist/sdk/components/header.d.ts +2 -0
  11. package/dist/sdk/components/layout.d.ts +26 -0
  12. package/dist/sdk/components/layout.test.d.ts +1 -0
  13. package/dist/sdk/components/node-card.d.ts +8 -0
  14. package/dist/sdk/components/orchestrator-panel-contexts.d.ts +15 -0
  15. package/dist/sdk/components/orchestrator-panel-store.d.ts +35 -0
  16. package/dist/sdk/components/orchestrator-panel-store.test.d.ts +1 -0
  17. package/dist/sdk/components/orchestrator-panel-types.d.ts +16 -0
  18. package/dist/sdk/components/orchestrator-panel.d.ts +51 -0
  19. package/dist/sdk/components/session-graph-panel.d.ts +6 -0
  20. package/dist/sdk/components/status-helpers.d.ts +5 -0
  21. package/dist/sdk/components/statusline.d.ts +6 -0
  22. package/dist/sdk/define-workflow.d.ts +77 -0
  23. package/dist/sdk/define-workflow.test.d.ts +1 -0
  24. package/dist/sdk/errors.d.ts +21 -0
  25. package/dist/sdk/index.d.ts +12 -0
  26. package/dist/sdk/index.js +52 -0
  27. package/dist/sdk/providers/claude.d.ts +159 -0
  28. package/dist/sdk/providers/copilot.d.ts +14 -0
  29. package/dist/sdk/providers/opencode.d.ts +14 -0
  30. package/dist/sdk/runtime/discovery.d.ts +31 -0
  31. package/dist/sdk/runtime/executor-entry.d.ts +10 -0
  32. package/dist/sdk/runtime/executor.d.ts +61 -0
  33. package/dist/sdk/runtime/executor.test.d.ts +1 -0
  34. package/dist/sdk/runtime/graph-inference.d.ts +34 -0
  35. package/dist/sdk/runtime/loader.d.ts +72 -0
  36. package/dist/sdk/runtime/panel.d.ts +8 -0
  37. package/dist/sdk/runtime/theme.d.ts +27 -0
  38. package/dist/sdk/runtime/tmux.d.ts +191 -0
  39. package/dist/sdk/types.d.ts +214 -0
  40. package/dist/sdk/workflows/builtin/ralph/claude/index.d.ts +13 -0
  41. package/dist/sdk/workflows/builtin/ralph/claude/index.js +95 -0
  42. package/dist/sdk/workflows/builtin/ralph/copilot/index.d.ts +13 -0
  43. package/dist/sdk/workflows/builtin/ralph/copilot/index.js +118 -0
  44. package/dist/sdk/workflows/builtin/ralph/helpers/git.d.ts +16 -0
  45. package/dist/sdk/workflows/builtin/ralph/helpers/prompts.d.ts +118 -0
  46. package/dist/sdk/workflows/builtin/ralph/helpers/review.d.ts +19 -0
  47. package/dist/sdk/workflows/builtin/ralph/opencode/index.d.ts +13 -0
  48. package/dist/sdk/workflows/builtin/ralph/opencode/index.js +147 -0
  49. package/dist/sdk/workflows/index.d.ts +24 -0
  50. package/dist/sdk/workflows/index.js +94 -0
  51. package/package.json +33 -6
@@ -0,0 +1 @@
1
+ // @bun
@@ -0,0 +1,417 @@
1
+ // @bun
2
+ // src/sdk/workflows/builtin/ralph/helpers/prompts.ts
3
+ function buildPlannerPrompt(spec, context = { iteration: 1 }) {
4
+ const debuggerReport = context.debuggerReport?.trim() ?? "";
5
+ const isReplan = context.iteration > 1 && debuggerReport.length > 0;
6
+ if (isReplan) {
7
+ return `# Re-Planning (Iteration ${context.iteration})
8
+
9
+ The previous Ralph iteration produced an implementation that the reviewer
10
+ flagged as incomplete or incorrect. The debugger investigated and produced
11
+ the report below. Use it to re-plan.
12
+
13
+ ## Original Specification
14
+
15
+ <specification>
16
+ ${spec}
17
+ </specification>
18
+
19
+ ## Debugger Report (authoritative)
20
+
21
+ <debugger_report>
22
+ ${debuggerReport}
23
+ </debugger_report>
24
+
25
+ ## Your Task
26
+
27
+ Decompose the work needed to resolve every issue in the debugger report into
28
+ an ordered task list, then persist them via TaskCreate.
29
+
30
+ <instructions>
31
+ 1. Treat the debugger report as authoritative. Every "Issue Identified" must
32
+ map to at least one task. Every "Suggested Plan Adjustment" must appear as
33
+ (or be subsumed by) a task.
34
+ 2. Drop any work from the original specification that is already complete and
35
+ unaffected by the report.
36
+ 3. Order tasks by priority: P0 fixes first, then dependent work, then
37
+ validation/tests.
38
+ 4. Optimize for parallel execution \u2014 minimize blockedBy dependencies.
39
+ 5. After creating all tasks via TaskCreate, call TaskList to verify.
40
+ </instructions>
41
+
42
+ <constraints>
43
+ - All tasks start as "pending".
44
+ - blockedBy must reference IDs that exist in the task list.
45
+ - Do not split fixes that touch the same file across multiple tasks unless they are truly independent.
46
+ </constraints>`;
47
+ }
48
+ return `# Planning (Iteration 1)
49
+
50
+ You are a task decomposition engine.
51
+
52
+ <specification>
53
+ ${spec}
54
+ </specification>
55
+
56
+ <instructions>
57
+ Decompose the specification above into an ordered list of implementation tasks
58
+ and persist them via TaskCreate.
59
+
60
+ 1. Read the specification and identify every distinct deliverable.
61
+ 2. Order tasks by priority: foundational/infrastructure first, then features,
62
+ then tests, then polish.
63
+ 3. Analyze technical dependencies between tasks.
64
+ 4. After creating all tasks via TaskCreate, call TaskList to verify.
65
+ </instructions>
66
+
67
+ <constraints>
68
+ - All tasks start as "pending".
69
+ - blockedBy must only reference IDs that exist in the task list.
70
+ - Optimize for parallel execution \u2014 minimize unnecessary dependencies.
71
+ </constraints>`;
72
+ }
73
+ function buildOrchestratorPrompt(spec, context = {}) {
74
+ const plannerNotes = context.plannerNotes?.trim() ?? "";
75
+ const plannerSection = plannerNotes.length > 0 ? `## Planner Notes (trailing commentary)
76
+
77
+ The planner produced the notes below alongside the task list. They capture
78
+ caveats, risks, or execution hints that did not fit into individual task
79
+ bodies. Treat them as guidance, not as task definitions.
80
+
81
+ <planner_notes>
82
+ ${plannerNotes}
83
+ </planner_notes>
84
+
85
+ ` : "";
86
+ return `You are an orchestrator managing a set of implementation tasks.
87
+
88
+ ## Original User Specification
89
+
90
+ <specification>
91
+ ${spec}
92
+ </specification>
93
+
94
+ ${plannerSection}## Retrieve Task List
95
+
96
+ Start by retrieving the current task list using your TaskList tool. The
97
+ planner has already created all tasks; you MUST retrieve them before any
98
+ execution.
99
+
100
+ ## Dependency Graph Integrity Check
101
+
102
+ BEFORE executing any tasks, validate the dependency graph:
103
+
104
+ 1. For each task, check that every ID in its "blockedBy" array corresponds to
105
+ an actual task ID in the list.
106
+ 2. If a blockedBy reference points to a task ID that does NOT exist, that
107
+ reference is a **dangling dependency** caused by data corruption during
108
+ planning.
109
+ 3. **Remove dangling dependencies**: Drop any blockedBy entry that references
110
+ a non-existent task ID. The task is still valid \u2014 only the corrupted
111
+ reference should be removed.
112
+ 4. After cleanup, re-evaluate which tasks are ready.
113
+
114
+ This step is critical. Dangling dependencies will permanently block tasks.
115
+
116
+ ## Dependency Rules
117
+
118
+ A task is READY only when:
119
+ 1. Its status is "pending"
120
+ 2. ALL tasks in its "blockedBy" array are "completed"
121
+
122
+ Do NOT spawn a worker for a task whose dependencies are not yet completed.
123
+
124
+ ## Instructions
125
+
126
+ 1. **Retrieve the task list** via TaskList. This is your source of truth.
127
+ 2. **Validate the dependency graph** as above. Remove dangling dependencies.
128
+ 3. **Identify ready tasks**: pending tasks whose blockedBy is fully completed.
129
+ 4. **Spawn parallel workers**: for each ready task, spawn a worker via the
130
+ Task tool with a focused prompt containing the task description, context
131
+ from completed dependencies, and instructions to implement and test.
132
+ 5. **Monitor completions**: as workers finish, mark tasks completed and spawn
133
+ the newly-unblocked tasks immediately.
134
+ 6. **Continue until ALL tasks are complete.** Do NOT stop early.
135
+ 7. **Report a summary** when finished, listing each task and its final status.
136
+
137
+ ## IMPORTANT
138
+
139
+ Spawn ALL ready tasks in parallel \u2014 do not serialize when multiple tasks are
140
+ ready simultaneously.
141
+
142
+ ## Error Handling
143
+
144
+ When a worker task FAILS:
145
+
146
+ 1. **Diagnose** the error.
147
+ 2. **Retry with fix**: spawn a new worker with the error context included.
148
+ 3. **Retry limit**: up to 3 retries per task. After that, mark it as "error".
149
+ 4. **Continue regardless**: do NOT stop. Execute all other unblocked tasks.
150
+ 5. **Unblocked tasks proceed**: only direct dependents of an "error" task
151
+ should be skipped.
152
+
153
+ NEVER mark tasks as "blocked-by-failure" and stop. Complete as much work as
154
+ possible.
155
+
156
+ ## Task Status Protocol
157
+
158
+ Update task statuses **immediately** at every transition via TaskUpdate.
159
+
160
+ ### Required update sequence per task
161
+
162
+ 1. **IMMEDIATELY BEFORE spawning** a worker for a task \u2192 mark "in_progress".
163
+ 2. **IMMEDIATELY AFTER** the worker returns \u2192 mark "completed" or "error".
164
+
165
+ ### Timing rules
166
+
167
+ - Update status in the same turn as the event that triggered it. Never batch.
168
+ - When multiple workers complete in parallel, issue a SEPARATE update for
169
+ each.
170
+ - Mark previous tasks "completed" before marking new ones "in_progress".`;
171
+ }
172
+ function buildReviewPrompt(spec, context) {
173
+ const gitStatus = context.gitStatus.trim();
174
+ const gitSection = gitStatus.length > 0 ? `## Working Tree (\`git status -s\`)
175
+
176
+ These files have uncommitted changes \u2014 they are the files actually touched in
177
+ this iteration. Use them to focus your review:
178
+
179
+ \`\`\`
180
+ ${gitStatus}
181
+ \`\`\`` : `## Working Tree (\`git status -s\`)
182
+
183
+ The working tree is clean. Either nothing was implemented this iteration or
184
+ all changes were already committed. Cross-check the task list to verify
185
+ whether the implementation actually ran.`;
186
+ const header = context.iteration ? `# Code Review Request (Iteration ${context.iteration}${context.isConfirmationPass ? ", confirmation pass" : ""})` : "# Code Review Request";
187
+ const confirmationNote = context.isConfirmationPass ? `
188
+
189
+ **Note**: This is a confirmation pass. The previous review of this same iteration produced zero findings. Re-verify with fresh eyes; do not assume the prior pass was correct.` : "";
190
+ return `${header}${confirmationNote}
191
+
192
+ ## Original Specification
193
+
194
+ <user_request>
195
+ ${spec}
196
+ </user_request>
197
+
198
+ ${gitSection}
199
+
200
+ ## Retrieve Task List
201
+
202
+ Call \`TaskList\` to fetch the current task plan and statuses. Use it to:
203
+ 1. Identify completed vs incomplete tasks.
204
+ 2. Cross-reference the plan against the specification.
205
+ 3. Calculate completion metrics.
206
+
207
+ ## Review Focus Areas (priority order)
208
+
209
+ 1. **Task Completion & Specification Gap Analysis** \u2014 HIGHEST priority. Every
210
+ task in PENDING / IN_PROGRESS / ERROR status MUST become a P0 finding.
211
+ Every spec requirement not covered by any task is a P0 finding. Do NOT
212
+ mark the patch correct if any task is incomplete.
213
+ 2. **Correctness of Logic** \u2014 does the code implement the requirements?
214
+ 3. **Error Handling & Edge Cases** \u2014 boundary, empty/null, error paths.
215
+ 4. **Security** \u2014 injection, secret leakage, auth bypasses.
216
+ 5. **Performance** \u2014 obvious resource leaks, N+1, hot loops.
217
+ 6. **Test Coverage** \u2014 critical paths and edge cases tested.
218
+
219
+ ## Output Format
220
+
221
+ Output ONLY a JSON object inside a single fenced \`\`\`json block. No prose
222
+ before or after. Use this schema exactly:
223
+
224
+ \`\`\`json
225
+ {
226
+ "findings": [
227
+ {
228
+ "title": "[P0] Brief title (P0=critical, P1=important, P2=moderate, P3=minor)",
229
+ "body": "Detailed explanation, why it matters, and a suggested fix",
230
+ "confidence_score": 0.95,
231
+ "priority": 0,
232
+ "code_location": {
233
+ "absolute_file_path": "/full/path/to/file.ts",
234
+ "line_range": { "start": 42, "end": 45 }
235
+ }
236
+ }
237
+ ],
238
+ "overall_correctness": "patch is correct",
239
+ "overall_explanation": "Summary of overall quality and correctness",
240
+ "overall_confidence_score": 0.85
241
+ }
242
+ \`\`\`
243
+
244
+ Set \`overall_correctness\` to \`"patch is incorrect"\` whenever there is at
245
+ least one P0 or P1 finding (including incomplete tasks). Use
246
+ \`"patch is correct"\` only when findings are empty or strictly P3.
247
+
248
+ Begin your review now.`;
249
+ }
250
+ function buildDebuggerReportPrompt(review, rawReview, context) {
251
+ let findingsSection;
252
+ if (review !== null && review.findings.length > 0) {
253
+ const sorted = [...review.findings].sort((a, b) => (a.priority ?? 3) - (b.priority ?? 3));
254
+ findingsSection = sorted.map((f, i) => {
255
+ const pri = f.priority !== undefined ? `P${f.priority}` : "P2";
256
+ const loc = f.code_location ? `${f.code_location.absolute_file_path}:${f.code_location.line_range.start}-${f.code_location.line_range.end}` : "unspecified";
257
+ return `### Finding ${i + 1}: [${pri}] ${f.title}
258
+ - **Location:** ${loc}
259
+ - **Issue:** ${f.body}`;
260
+ }).join(`
261
+
262
+ `);
263
+ } else {
264
+ const trimmed = rawReview.trim();
265
+ findingsSection = trimmed.length > 0 ? `Reviewer output (could not parse as JSON):
266
+
267
+ \`\`\`
268
+ ${trimmed}
269
+ \`\`\`` : `(no reviewer output captured)`;
270
+ }
271
+ const gitStatus = context.gitStatus.trim();
272
+ const gitSection = gitStatus.length > 0 ? `\`\`\`
273
+ ${gitStatus}
274
+ \`\`\`` : `(working tree clean)`;
275
+ return `# Debugging Report Request (Iteration ${context.iteration})
276
+
277
+ The reviewer flagged the issues below. Investigate them as a debugger and
278
+ produce a structured report that the planner will consume on the next loop
279
+ iteration.
280
+
281
+ **You are NOT applying fixes.** Your only deliverable is the report. Do not
282
+ edit files. Investigation tool calls (Read, grep, LSP, running tests in
283
+ read-only mode) are fine; mutations are not.
284
+
285
+ ## Reviewer Findings
286
+
287
+ ${findingsSection}
288
+
289
+ ## Working Tree (\`git status -s\`)
290
+
291
+ ${gitSection}
292
+
293
+ ## Investigation Steps
294
+
295
+ For each finding:
296
+ 1. Locate the relevant code (LSP / grep / Read).
297
+ 2. Identify the **root cause**, not just the symptom.
298
+ 3. List the absolute file paths that must change.
299
+ 4. Note constraints, pitfalls, or invariants the next planner must respect.
300
+
301
+ ## Output Format
302
+
303
+ Respond with EXACTLY one fenced \`\`\`markdown block containing the report.
304
+ No prose before or after the block. Use this exact section structure:
305
+
306
+ \`\`\`markdown
307
+ # Debugger Report
308
+
309
+ ## Issues Identified
310
+ - [P<priority>] <one-line issue summary>
311
+ - **Root cause:** <one or two sentences>
312
+ - **Files:** <abs/path/file.ext, abs/path/other.ext>
313
+ - **Fix approach:** <imperative description>
314
+
315
+ ## Suggested Plan Adjustments
316
+ 1. <imperative task description, suitable as a planner task>
317
+ 2. <...>
318
+
319
+ ## Pitfalls
320
+ - <invariant or gotcha the planner/workers must respect>
321
+ - <...>
322
+ \`\`\`
323
+
324
+ Keep the report tight \u2014 every line must be load-bearing for re-planning. Omit
325
+ the "Pitfalls" section entirely if there are none. Begin now.`;
326
+ }
327
+ function parseReviewResult(content) {
328
+ try {
329
+ const parsed = JSON.parse(content);
330
+ if (parsed && parsed.findings && parsed.overall_correctness) {
331
+ return filterActionable(parsed);
332
+ }
333
+ } catch {}
334
+ const blockRe = /```(?:json)?\s*\n([\s\S]*?)\n```/g;
335
+ let lastBlock = null;
336
+ let blockMatch;
337
+ while ((blockMatch = blockRe.exec(content)) !== null) {
338
+ if (blockMatch[1])
339
+ lastBlock = blockMatch[1];
340
+ }
341
+ if (lastBlock !== null) {
342
+ try {
343
+ const parsed = JSON.parse(lastBlock);
344
+ if (parsed && parsed.findings && parsed.overall_correctness) {
345
+ return filterActionable(parsed);
346
+ }
347
+ } catch {}
348
+ }
349
+ const objRe = /\{[\s\S]*?"findings"[\s\S]*?\}/g;
350
+ let lastObj = null;
351
+ let objMatch;
352
+ while ((objMatch = objRe.exec(content)) !== null) {
353
+ lastObj = objMatch[0];
354
+ }
355
+ if (lastObj !== null) {
356
+ try {
357
+ const parsed = JSON.parse(lastObj);
358
+ if (parsed && parsed.findings && parsed.overall_correctness) {
359
+ return filterActionable(parsed);
360
+ }
361
+ } catch {}
362
+ }
363
+ return null;
364
+ }
365
+ function filterActionable(parsed) {
366
+ const actionable = parsed.findings.filter((f) => f.priority === undefined || f.priority <= 2);
367
+ return {
368
+ findings: actionable,
369
+ overall_correctness: parsed.overall_correctness,
370
+ overall_explanation: parsed.overall_explanation ?? "",
371
+ overall_confidence_score: parsed.overall_confidence_score
372
+ };
373
+ }
374
+ function extractMarkdownBlock(content) {
375
+ const blockRe = /```markdown\s*\n([\s\S]*?)\n```/g;
376
+ let last = null;
377
+ let match;
378
+ while ((match = blockRe.exec(content)) !== null) {
379
+ if (match[1])
380
+ last = match[1];
381
+ }
382
+ if (last !== null)
383
+ return last.trim();
384
+ return content.trim();
385
+ }
386
+
387
+ // src/sdk/workflows/builtin/ralph/helpers/review.ts
388
+ function hasActionableFindings(review, rawText) {
389
+ if (review !== null && review.findings.length > 0) {
390
+ return true;
391
+ }
392
+ if (review === null && rawText.trim().length > 0) {
393
+ return true;
394
+ }
395
+ return false;
396
+ }
397
+
398
+ // src/sdk/workflows/builtin/ralph/helpers/git.ts
399
+ async function safeGitStatusS(cwd = process.cwd()) {
400
+ try {
401
+ const proc = Bun.spawn({
402
+ cmd: ["git", "status", "-s"],
403
+ cwd,
404
+ stdout: "pipe",
405
+ stderr: "ignore"
406
+ });
407
+ const stdout = await new Response(proc.stdout).text();
408
+ const code = await proc.exited;
409
+ if (code !== 0)
410
+ return "";
411
+ return stdout;
412
+ } catch {
413
+ return "";
414
+ }
415
+ }
416
+
417
+ export { buildPlannerPrompt, buildOrchestratorPrompt, buildReviewPrompt, buildDebuggerReportPrompt, parseReviewResult, extractMarkdownBlock, hasActionableFindings, safeGitStatusS };