cralph 1.0.0-beta.3 → 1.0.0-beta.4
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/package.json +1 -1
- package/src/prompt.ts +55 -14
- package/src/runner.ts +10 -2
package/package.json
CHANGED
package/src/prompt.ts
CHANGED
|
@@ -2,26 +2,67 @@ import type { RalphConfig } from "./types";
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* The main ralph prompt template.
|
|
5
|
-
*
|
|
5
|
+
* Based on ralph-ref best practices for autonomous agent loops.
|
|
6
6
|
*/
|
|
7
|
-
const BASE_PROMPT = `You are an autonomous agent running in a loop.
|
|
7
|
+
const BASE_PROMPT = `You are an autonomous coding agent running in a loop.
|
|
8
8
|
|
|
9
9
|
FIRST: Read and internalize the rules provided below.
|
|
10
10
|
|
|
11
|
-
Your
|
|
11
|
+
## Your Task Each Iteration
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
1. Read the TODO file and check the Patterns section first
|
|
14
|
+
2. Pick the FIRST uncompleted task (marked with [ ])
|
|
15
|
+
3. Implement that SINGLE task
|
|
16
|
+
4. Run quality checks (typecheck, lint, test - whatever the project requires)
|
|
17
|
+
5. If checks pass, mark the task [x] complete
|
|
18
|
+
6. Append your progress with learnings (see format below)
|
|
19
|
+
7. If ALL tasks are complete, output the completion signal
|
|
14
20
|
|
|
15
|
-
|
|
16
|
-
Keep the TODO structure with these sections:
|
|
17
|
-
- **# Tasks** - Checklist with [ ] for pending and [x] for done
|
|
18
|
-
- **# Notes** - Any relevant notes or context
|
|
21
|
+
## Critical Rules
|
|
19
22
|
|
|
20
|
-
|
|
23
|
+
- **ONE task per iteration** - Do not try to complete multiple tasks
|
|
24
|
+
- **Quality first** - Do NOT mark a task complete if tests/typecheck fail
|
|
25
|
+
- **Keep changes focused** - Minimal, targeted changes only
|
|
26
|
+
- **Follow existing patterns** - Match the codebase style
|
|
27
|
+
|
|
28
|
+
## Progress Format
|
|
29
|
+
|
|
30
|
+
After completing a task, APPEND to the Notes section:
|
|
31
|
+
|
|
32
|
+
\`\`\`
|
|
33
|
+
## [Task Title] - Done
|
|
34
|
+
- What was implemented
|
|
35
|
+
- Files changed
|
|
36
|
+
- **Learnings:**
|
|
37
|
+
- Patterns discovered
|
|
38
|
+
- Gotchas encountered
|
|
39
|
+
\`\`\`
|
|
40
|
+
|
|
41
|
+
## Consolidate Patterns
|
|
42
|
+
|
|
43
|
+
If you discover a REUSABLE pattern, add it to the **# Patterns** section at the TOP of the TODO file:
|
|
44
|
+
|
|
45
|
+
\`\`\`
|
|
46
|
+
# Patterns
|
|
47
|
+
- Example: Use \`sql<number>\` template for aggregations
|
|
48
|
+
- Example: Always update X when changing Y
|
|
49
|
+
\`\`\`
|
|
50
|
+
|
|
51
|
+
Only add patterns that are general and reusable, not task-specific details.
|
|
52
|
+
|
|
53
|
+
## Refs (Read-Only)
|
|
54
|
+
|
|
55
|
+
If refs paths are provided, they are READ-ONLY reference material. Never modify files in refs.
|
|
56
|
+
|
|
57
|
+
## Stop Condition
|
|
58
|
+
|
|
59
|
+
After completing a task, check if ALL tasks are marked [x] complete.
|
|
60
|
+
|
|
61
|
+
If ALL tasks are done, output exactly:
|
|
21
62
|
|
|
22
63
|
<promise>COMPLETE</promise>
|
|
23
64
|
|
|
24
|
-
|
|
65
|
+
If there are still pending tasks, end your response normally (the loop will continue).`;
|
|
25
66
|
|
|
26
67
|
/**
|
|
27
68
|
* Build the complete prompt with config and rules injected
|
|
@@ -37,18 +78,18 @@ export function buildPrompt(config: RalphConfig, rulesContent: string, todoFile:
|
|
|
37
78
|
|
|
38
79
|
## Configuration
|
|
39
80
|
|
|
40
|
-
**TODO file (update after each
|
|
81
|
+
**TODO file (read first, update after each task):**
|
|
41
82
|
${todoFile}
|
|
42
83
|
|
|
43
|
-
**Refs
|
|
84
|
+
**Refs (read-only reference material):**
|
|
44
85
|
${refsList}
|
|
45
86
|
|
|
46
|
-
**Output directory:**
|
|
87
|
+
**Output directory (write your work here):**
|
|
47
88
|
${config.output}
|
|
48
89
|
|
|
49
90
|
---
|
|
50
91
|
|
|
51
|
-
## Rules
|
|
92
|
+
## Rules (Your Instructions)
|
|
52
93
|
|
|
53
94
|
${rulesContent}
|
|
54
95
|
`;
|
package/src/runner.ts
CHANGED
|
@@ -9,14 +9,22 @@ import { setCurrentProcess, throwIfCancelled } from "./state";
|
|
|
9
9
|
const COMPLETION_SIGNAL = "<promise>COMPLETE</promise>";
|
|
10
10
|
const AUTH_CACHE_TTL_MS = 6 * 60 * 60 * 1000; // 6 hours
|
|
11
11
|
|
|
12
|
-
const INITIAL_TODO_CONTENT = `#
|
|
12
|
+
const INITIAL_TODO_CONTENT = `# Patterns
|
|
13
|
+
|
|
14
|
+
_None yet - add reusable patterns discovered during work_
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
# Tasks
|
|
13
19
|
|
|
14
20
|
- [ ] Task 1
|
|
15
21
|
- [ ] Task 2
|
|
16
22
|
|
|
23
|
+
---
|
|
24
|
+
|
|
17
25
|
# Notes
|
|
18
26
|
|
|
19
|
-
|
|
27
|
+
_Append progress and learnings here after each iteration_
|
|
20
28
|
`;
|
|
21
29
|
|
|
22
30
|
/**
|