ghcralph 0.1.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.
- package/LICENSE +21 -0
- package/README.md +327 -0
- package/bin/ghcralph.js +2 -0
- package/dist/cli.d.ts +12 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +92 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/config.d.ts +8 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +118 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/index.d.ts +11 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +11 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/init.d.ts +15 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +116 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/rollback.d.ts +8 -0
- package/dist/commands/rollback.d.ts.map +1 -0
- package/dist/commands/rollback.js +238 -0
- package/dist/commands/rollback.js.map +1 -0
- package/dist/commands/run.d.ts +28 -0
- package/dist/commands/run.d.ts.map +1 -0
- package/dist/commands/run.js +407 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/commands/status.d.ts +8 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +399 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/core/action-executor.d.ts +96 -0
- package/dist/core/action-executor.d.ts.map +1 -0
- package/dist/core/action-executor.js +289 -0
- package/dist/core/action-executor.js.map +1 -0
- package/dist/core/checkpoint-manager.d.ts +94 -0
- package/dist/core/checkpoint-manager.d.ts.map +1 -0
- package/dist/core/checkpoint-manager.js +236 -0
- package/dist/core/checkpoint-manager.js.map +1 -0
- package/dist/core/config-manager.d.ts +62 -0
- package/dist/core/config-manager.d.ts.map +1 -0
- package/dist/core/config-manager.js +184 -0
- package/dist/core/config-manager.js.map +1 -0
- package/dist/core/config-schema.d.ts +74 -0
- package/dist/core/config-schema.d.ts.map +1 -0
- package/dist/core/config-schema.js +84 -0
- package/dist/core/config-schema.js.map +1 -0
- package/dist/core/context-builder.d.ts +116 -0
- package/dist/core/context-builder.d.ts.map +1 -0
- package/dist/core/context-builder.js +388 -0
- package/dist/core/context-builder.js.map +1 -0
- package/dist/core/feedback-builder.d.ts +94 -0
- package/dist/core/feedback-builder.d.ts.map +1 -0
- package/dist/core/feedback-builder.js +226 -0
- package/dist/core/feedback-builder.js.map +1 -0
- package/dist/core/file-safeguard.d.ts +109 -0
- package/dist/core/file-safeguard.d.ts.map +1 -0
- package/dist/core/file-safeguard.js +200 -0
- package/dist/core/file-safeguard.js.map +1 -0
- package/dist/core/git-branch-manager.d.ts +122 -0
- package/dist/core/git-branch-manager.d.ts.map +1 -0
- package/dist/core/git-branch-manager.js +302 -0
- package/dist/core/git-branch-manager.js.map +1 -0
- package/dist/core/github-plan.d.ts +86 -0
- package/dist/core/github-plan.d.ts.map +1 -0
- package/dist/core/github-plan.js +333 -0
- package/dist/core/github-plan.js.map +1 -0
- package/dist/core/index.d.ts +43 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +26 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/local-markdown-plan.d.ts +65 -0
- package/dist/core/local-markdown-plan.d.ts.map +1 -0
- package/dist/core/local-markdown-plan.js +154 -0
- package/dist/core/local-markdown-plan.js.map +1 -0
- package/dist/core/loop-engine.d.ts +133 -0
- package/dist/core/loop-engine.d.ts.map +1 -0
- package/dist/core/loop-engine.js +420 -0
- package/dist/core/loop-engine.js.map +1 -0
- package/dist/core/loop-events.d.ts +48 -0
- package/dist/core/loop-events.d.ts.map +1 -0
- package/dist/core/loop-events.js +24 -0
- package/dist/core/loop-events.js.map +1 -0
- package/dist/core/loop-state.d.ts +51 -0
- package/dist/core/loop-state.d.ts.map +1 -0
- package/dist/core/loop-state.js +48 -0
- package/dist/core/loop-state.js.map +1 -0
- package/dist/core/markdown-parser.d.ts +51 -0
- package/dist/core/markdown-parser.d.ts.map +1 -0
- package/dist/core/markdown-parser.js +122 -0
- package/dist/core/markdown-parser.js.map +1 -0
- package/dist/core/plan-manager.d.ts +61 -0
- package/dist/core/plan-manager.d.ts.map +1 -0
- package/dist/core/plan-manager.js +7 -0
- package/dist/core/plan-manager.js.map +1 -0
- package/dist/core/progress-tracker.d.ts +74 -0
- package/dist/core/progress-tracker.d.ts.map +1 -0
- package/dist/core/progress-tracker.js +198 -0
- package/dist/core/progress-tracker.js.map +1 -0
- package/dist/core/prompt-examples.d.ts +52 -0
- package/dist/core/prompt-examples.d.ts.map +1 -0
- package/dist/core/prompt-examples.js +194 -0
- package/dist/core/prompt-examples.js.map +1 -0
- package/dist/core/response-parser.d.ts +90 -0
- package/dist/core/response-parser.d.ts.map +1 -0
- package/dist/core/response-parser.js +209 -0
- package/dist/core/response-parser.js.map +1 -0
- package/dist/core/verification-hooks.d.ts +103 -0
- package/dist/core/verification-hooks.d.ts.map +1 -0
- package/dist/core/verification-hooks.js +268 -0
- package/dist/core/verification-hooks.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/auth.d.ts +28 -0
- package/dist/integrations/auth.d.ts.map +1 -0
- package/dist/integrations/auth.js +76 -0
- package/dist/integrations/auth.js.map +1 -0
- package/dist/integrations/copilot-agent.d.ts +104 -0
- package/dist/integrations/copilot-agent.d.ts.map +1 -0
- package/dist/integrations/copilot-agent.js +235 -0
- package/dist/integrations/copilot-agent.js.map +1 -0
- package/dist/integrations/index.d.ts +18 -0
- package/dist/integrations/index.d.ts.map +1 -0
- package/dist/integrations/index.js +14 -0
- package/dist/integrations/index.js.map +1 -0
- package/dist/integrations/mcp-tools.d.ts +129 -0
- package/dist/integrations/mcp-tools.d.ts.map +1 -0
- package/dist/integrations/mcp-tools.js +272 -0
- package/dist/integrations/mcp-tools.js.map +1 -0
- package/dist/integrations/tokens.d.ts +45 -0
- package/dist/integrations/tokens.d.ts.map +1 -0
- package/dist/integrations/tokens.js +50 -0
- package/dist/integrations/tokens.js.map +1 -0
- package/dist/types/index.d.ts +53 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +7 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.d.ts +23 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +37 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/output.d.ts +59 -0
- package/dist/utils/output.d.ts.map +1 -0
- package/dist/utils/output.js +96 -0
- package/dist/utils/output.js.map +1 -0
- package/dist/utils/paths.d.ts +34 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +67 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/shell.d.ts +26 -0
- package/dist/utils/shell.d.ts.map +1 -0
- package/dist/utils/shell.js +65 -0
- package/dist/utils/shell.js.map +1 -0
- package/dist/utils/validation.d.ts +27 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +43 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +86 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt Examples
|
|
3
|
+
*
|
|
4
|
+
* Provides concrete examples of ACTION blocks for weaker models.
|
|
5
|
+
* The original Ralph pattern was designed for Claude's strong instruction-following.
|
|
6
|
+
* For weaker models (like gpt-4.1), explicit examples help ensure correct output format.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Example of ACTION:CREATE block
|
|
10
|
+
*/
|
|
11
|
+
export declare const CREATE_EXAMPLE = "[ACTION:CREATE]\npath: src/calculator.sh\n```bash\n#!/bin/bash\n# Simple calculator\n\nnum1=$1\nop=$2\nnum2=$3\n\ncase $op in\n \"+\") echo $((num1 + num2)) ;;\n \"-\") echo $((num1 - num2)) ;;\n \"*\") echo $((num1 * num2)) ;;\n \"/\") echo $((num1 / num2)) ;;\nesac\n```";
|
|
12
|
+
/**
|
|
13
|
+
* Example of ACTION:EDIT block
|
|
14
|
+
*/
|
|
15
|
+
export declare const EDIT_EXAMPLE = "[ACTION:EDIT]\npath: src/calculator.sh\n[OLD]\ncase $op in\n \"+\") echo $((num1 + num2)) ;;\nesac\n[NEW]\ncase $op in\n \"+\") echo $((num1 + num2)) ;;\n \"-\") echo $((num1 - num2)) ;;\nesac";
|
|
16
|
+
/**
|
|
17
|
+
* Example of ACTION:DELETE block
|
|
18
|
+
*/
|
|
19
|
+
export declare const DELETE_EXAMPLE = "[ACTION:DELETE]\npath: src/old-file.ts";
|
|
20
|
+
/**
|
|
21
|
+
* Example of ACTION:EXECUTE block
|
|
22
|
+
*/
|
|
23
|
+
export declare const EXECUTE_EXAMPLE = "[ACTION:EXECUTE]\ncommand: npm test";
|
|
24
|
+
/**
|
|
25
|
+
* Example of ACTION:COMPLETE block
|
|
26
|
+
*/
|
|
27
|
+
export declare const COMPLETE_EXAMPLE = "[ACTION:COMPLETE]\nreason: All tests pass. Calculator implements addition, subtraction, multiplication, and division.";
|
|
28
|
+
/**
|
|
29
|
+
* All examples combined for inclusion in prompts
|
|
30
|
+
*/
|
|
31
|
+
export declare const ALL_EXAMPLES = "\n### Example: Create a new file\n[ACTION:CREATE]\npath: src/calculator.sh\n```bash\n#!/bin/bash\n# Simple calculator\n\nnum1=$1\nop=$2\nnum2=$3\n\ncase $op in\n \"+\") echo $((num1 + num2)) ;;\n \"-\") echo $((num1 - num2)) ;;\n \"*\") echo $((num1 * num2)) ;;\n \"/\") echo $((num1 / num2)) ;;\nesac\n```\n\n### Example: Edit an existing file\n[ACTION:EDIT]\npath: src/calculator.sh\n[OLD]\ncase $op in\n \"+\") echo $((num1 + num2)) ;;\nesac\n[NEW]\ncase $op in\n \"+\") echo $((num1 + num2)) ;;\n \"-\") echo $((num1 - num2)) ;;\nesac\n\n### Example: Run a command to test\n[ACTION:EXECUTE]\ncommand: npm test\n\n### Example: Mark task complete\n[ACTION:COMPLETE]\nreason: All tests pass. Calculator implements addition, subtraction, multiplication, and division.\n";
|
|
32
|
+
/**
|
|
33
|
+
* Minimal examples (for context-constrained situations)
|
|
34
|
+
*/
|
|
35
|
+
export declare const MINIMAL_EXAMPLES = "\nExample CREATE:\n[ACTION:CREATE]\npath: file.sh\n```bash\n#!/bin/bash\necho \"Hello\"\n```\n\nExample EDIT:\n[ACTION:EDIT]\npath: file.sh\n[OLD]\necho \"Hello\"\n[NEW]\necho \"Hello World\"\n\nExample EXECUTE:\n[ACTION:EXECUTE]\ncommand: ./file.sh\n\nExample COMPLETE:\n[ACTION:COMPLETE]\nreason: Task done, tests pass\n";
|
|
36
|
+
/**
|
|
37
|
+
* Format instructions for ACTION blocks
|
|
38
|
+
*/
|
|
39
|
+
export declare const FORMAT_INSTRUCTIONS = "## Output Format\n\nYou MUST respond using ONLY structured ACTION blocks. DO NOT write prose explanations.\n\nAvailable actions:\n\n**[ACTION:CREATE]** - Create a new file\n```\n[ACTION:CREATE]\npath: <relative file path>\n```<language>\n<file content>\n```\n```\n\n**[ACTION:EDIT]** - Modify an existing file \n```\n[ACTION:EDIT]\npath: <relative file path>\n[OLD]\n<exact text to find>\n[NEW]\n<replacement text>\n```\n\n**[ACTION:EXECUTE]** - Run a shell command\n```\n[ACTION:EXECUTE]\ncommand: <shell command>\n```\n\n**[ACTION:COMPLETE]** - Mark task as done (only when tests pass!)\n```\n[ACTION:COMPLETE]\nreason: <brief explanation of why task is complete>\n```\n\n## Important Rules\n1. Use EXACT text for [OLD] blocks - must match file contents precisely\n2. Use [ACTION:EXECUTE] to run tests before marking complete\n3. Only use [ACTION:COMPLETE] when verification passes\n4. One action per block - you can include multiple blocks\n";
|
|
40
|
+
/**
|
|
41
|
+
* Get prompt examples based on model strength
|
|
42
|
+
*/
|
|
43
|
+
export declare function getPromptExamples(modelStrength: 'strong' | 'medium' | 'weak'): string;
|
|
44
|
+
/**
|
|
45
|
+
* Map model names to strength levels
|
|
46
|
+
*/
|
|
47
|
+
export declare function getModelStrength(model: string): 'strong' | 'medium' | 'weak';
|
|
48
|
+
/**
|
|
49
|
+
* Get appropriate examples for a specific model
|
|
50
|
+
*/
|
|
51
|
+
export declare function getExamplesForModel(model: string): string;
|
|
52
|
+
//# sourceMappingURL=prompt-examples.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-examples.d.ts","sourceRoot":"","sources":["../../src/core/prompt-examples.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,eAAO,MAAM,cAAc,iSAgBpB,CAAC;AAER;;GAEG;AACH,eAAO,MAAM,YAAY,8MAUpB,CAAC;AAEN;;GAEG;AACH,eAAO,MAAM,cAAc,2CACL,CAAC;AAEvB;;GAEG;AACH,eAAO,MAAM,eAAe,wCACV,CAAC;AAEnB;;GAEG;AACH,eAAO,MAAM,gBAAgB,0HACsE,CAAC;AAEpG;;GAEG;AACH,eAAO,MAAM,YAAY,2xBAYxB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,uUAwB5B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,s7BA0C/B,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,aAAa,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAcrF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAyB5E;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGzD"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt Examples
|
|
3
|
+
*
|
|
4
|
+
* Provides concrete examples of ACTION blocks for weaker models.
|
|
5
|
+
* The original Ralph pattern was designed for Claude's strong instruction-following.
|
|
6
|
+
* For weaker models (like gpt-4.1), explicit examples help ensure correct output format.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Example of ACTION:CREATE block
|
|
10
|
+
*/
|
|
11
|
+
export const CREATE_EXAMPLE = `[ACTION:CREATE]
|
|
12
|
+
path: src/calculator.sh
|
|
13
|
+
\`\`\`bash
|
|
14
|
+
#!/bin/bash
|
|
15
|
+
# Simple calculator
|
|
16
|
+
|
|
17
|
+
num1=$1
|
|
18
|
+
op=$2
|
|
19
|
+
num2=$3
|
|
20
|
+
|
|
21
|
+
case $op in
|
|
22
|
+
"+") echo $((num1 + num2)) ;;
|
|
23
|
+
"-") echo $((num1 - num2)) ;;
|
|
24
|
+
"*") echo $((num1 * num2)) ;;
|
|
25
|
+
"/") echo $((num1 / num2)) ;;
|
|
26
|
+
esac
|
|
27
|
+
\`\`\``;
|
|
28
|
+
/**
|
|
29
|
+
* Example of ACTION:EDIT block
|
|
30
|
+
*/
|
|
31
|
+
export const EDIT_EXAMPLE = `[ACTION:EDIT]
|
|
32
|
+
path: src/calculator.sh
|
|
33
|
+
[OLD]
|
|
34
|
+
case $op in
|
|
35
|
+
"+") echo $((num1 + num2)) ;;
|
|
36
|
+
esac
|
|
37
|
+
[NEW]
|
|
38
|
+
case $op in
|
|
39
|
+
"+") echo $((num1 + num2)) ;;
|
|
40
|
+
"-") echo $((num1 - num2)) ;;
|
|
41
|
+
esac`;
|
|
42
|
+
/**
|
|
43
|
+
* Example of ACTION:DELETE block
|
|
44
|
+
*/
|
|
45
|
+
export const DELETE_EXAMPLE = `[ACTION:DELETE]
|
|
46
|
+
path: src/old-file.ts`;
|
|
47
|
+
/**
|
|
48
|
+
* Example of ACTION:EXECUTE block
|
|
49
|
+
*/
|
|
50
|
+
export const EXECUTE_EXAMPLE = `[ACTION:EXECUTE]
|
|
51
|
+
command: npm test`;
|
|
52
|
+
/**
|
|
53
|
+
* Example of ACTION:COMPLETE block
|
|
54
|
+
*/
|
|
55
|
+
export const COMPLETE_EXAMPLE = `[ACTION:COMPLETE]
|
|
56
|
+
reason: All tests pass. Calculator implements addition, subtraction, multiplication, and division.`;
|
|
57
|
+
/**
|
|
58
|
+
* All examples combined for inclusion in prompts
|
|
59
|
+
*/
|
|
60
|
+
export const ALL_EXAMPLES = `
|
|
61
|
+
### Example: Create a new file
|
|
62
|
+
${CREATE_EXAMPLE}
|
|
63
|
+
|
|
64
|
+
### Example: Edit an existing file
|
|
65
|
+
${EDIT_EXAMPLE}
|
|
66
|
+
|
|
67
|
+
### Example: Run a command to test
|
|
68
|
+
${EXECUTE_EXAMPLE}
|
|
69
|
+
|
|
70
|
+
### Example: Mark task complete
|
|
71
|
+
${COMPLETE_EXAMPLE}
|
|
72
|
+
`;
|
|
73
|
+
/**
|
|
74
|
+
* Minimal examples (for context-constrained situations)
|
|
75
|
+
*/
|
|
76
|
+
export const MINIMAL_EXAMPLES = `
|
|
77
|
+
Example CREATE:
|
|
78
|
+
[ACTION:CREATE]
|
|
79
|
+
path: file.sh
|
|
80
|
+
\`\`\`bash
|
|
81
|
+
#!/bin/bash
|
|
82
|
+
echo "Hello"
|
|
83
|
+
\`\`\`
|
|
84
|
+
|
|
85
|
+
Example EDIT:
|
|
86
|
+
[ACTION:EDIT]
|
|
87
|
+
path: file.sh
|
|
88
|
+
[OLD]
|
|
89
|
+
echo "Hello"
|
|
90
|
+
[NEW]
|
|
91
|
+
echo "Hello World"
|
|
92
|
+
|
|
93
|
+
Example EXECUTE:
|
|
94
|
+
[ACTION:EXECUTE]
|
|
95
|
+
command: ./file.sh
|
|
96
|
+
|
|
97
|
+
Example COMPLETE:
|
|
98
|
+
[ACTION:COMPLETE]
|
|
99
|
+
reason: Task done, tests pass
|
|
100
|
+
`;
|
|
101
|
+
/**
|
|
102
|
+
* Format instructions for ACTION blocks
|
|
103
|
+
*/
|
|
104
|
+
export const FORMAT_INSTRUCTIONS = `## Output Format
|
|
105
|
+
|
|
106
|
+
You MUST respond using ONLY structured ACTION blocks. DO NOT write prose explanations.
|
|
107
|
+
|
|
108
|
+
Available actions:
|
|
109
|
+
|
|
110
|
+
**[ACTION:CREATE]** - Create a new file
|
|
111
|
+
\`\`\`
|
|
112
|
+
[ACTION:CREATE]
|
|
113
|
+
path: <relative file path>
|
|
114
|
+
\`\`\`<language>
|
|
115
|
+
<file content>
|
|
116
|
+
\`\`\`
|
|
117
|
+
\`\`\`
|
|
118
|
+
|
|
119
|
+
**[ACTION:EDIT]** - Modify an existing file
|
|
120
|
+
\`\`\`
|
|
121
|
+
[ACTION:EDIT]
|
|
122
|
+
path: <relative file path>
|
|
123
|
+
[OLD]
|
|
124
|
+
<exact text to find>
|
|
125
|
+
[NEW]
|
|
126
|
+
<replacement text>
|
|
127
|
+
\`\`\`
|
|
128
|
+
|
|
129
|
+
**[ACTION:EXECUTE]** - Run a shell command
|
|
130
|
+
\`\`\`
|
|
131
|
+
[ACTION:EXECUTE]
|
|
132
|
+
command: <shell command>
|
|
133
|
+
\`\`\`
|
|
134
|
+
|
|
135
|
+
**[ACTION:COMPLETE]** - Mark task as done (only when tests pass!)
|
|
136
|
+
\`\`\`
|
|
137
|
+
[ACTION:COMPLETE]
|
|
138
|
+
reason: <brief explanation of why task is complete>
|
|
139
|
+
\`\`\`
|
|
140
|
+
|
|
141
|
+
## Important Rules
|
|
142
|
+
1. Use EXACT text for [OLD] blocks - must match file contents precisely
|
|
143
|
+
2. Use [ACTION:EXECUTE] to run tests before marking complete
|
|
144
|
+
3. Only use [ACTION:COMPLETE] when verification passes
|
|
145
|
+
4. One action per block - you can include multiple blocks
|
|
146
|
+
`;
|
|
147
|
+
/**
|
|
148
|
+
* Get prompt examples based on model strength
|
|
149
|
+
*/
|
|
150
|
+
export function getPromptExamples(modelStrength) {
|
|
151
|
+
switch (modelStrength) {
|
|
152
|
+
case 'strong':
|
|
153
|
+
// Strong models (Claude, GPT-4o) need minimal examples
|
|
154
|
+
return FORMAT_INSTRUCTIONS;
|
|
155
|
+
case 'medium':
|
|
156
|
+
// Medium models need format + minimal examples
|
|
157
|
+
return FORMAT_INSTRUCTIONS + '\n\n## Examples\n' + MINIMAL_EXAMPLES;
|
|
158
|
+
case 'weak':
|
|
159
|
+
// Weak models (gpt-4.1, smaller models) need full examples
|
|
160
|
+
return FORMAT_INSTRUCTIONS + '\n\n## Detailed Examples\n' + ALL_EXAMPLES;
|
|
161
|
+
default:
|
|
162
|
+
return FORMAT_INSTRUCTIONS;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Map model names to strength levels
|
|
167
|
+
*/
|
|
168
|
+
export function getModelStrength(model) {
|
|
169
|
+
const normalized = model.toLowerCase();
|
|
170
|
+
// Strong models - excellent instruction following
|
|
171
|
+
if (normalized.includes('claude') ||
|
|
172
|
+
normalized.includes('gpt-4o') ||
|
|
173
|
+
normalized.includes('gpt-5') ||
|
|
174
|
+
normalized.includes('sonnet') ||
|
|
175
|
+
normalized.includes('opus')) {
|
|
176
|
+
return 'strong';
|
|
177
|
+
}
|
|
178
|
+
// Medium models - good but benefit from examples
|
|
179
|
+
if (normalized.includes('gpt-4-turbo') ||
|
|
180
|
+
normalized.includes('gemini')) {
|
|
181
|
+
return 'medium';
|
|
182
|
+
}
|
|
183
|
+
// Weak models - need explicit examples
|
|
184
|
+
// Includes gpt-4.1 (default due to 0x cost), gpt-3.5, smaller models
|
|
185
|
+
return 'weak';
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Get appropriate examples for a specific model
|
|
189
|
+
*/
|
|
190
|
+
export function getExamplesForModel(model) {
|
|
191
|
+
const strength = getModelStrength(model);
|
|
192
|
+
return getPromptExamples(strength);
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=prompt-examples.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-examples.js","sourceRoot":"","sources":["../../src/core/prompt-examples.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;OAgBvB,CAAC;A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U,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAC7B,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,EAC3B,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,iDAAiD;IACjD,IACE,UAAU,CAAC,QAAQ,CAAC,aAAa,CAAC;QAClC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAC7B,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,uCAAuC;IACvC,qEAAqE;IACrE,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC/C,MAAM,QAAQ,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACzC,OAAO,iBAAiB,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response Parser
|
|
3
|
+
*
|
|
4
|
+
* Parses AI responses to extract structured actions.
|
|
5
|
+
* This is a core component of the Ralph pattern - the AI outputs
|
|
6
|
+
* structured actions that we parse and execute.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Action types that the AI can request
|
|
10
|
+
*/
|
|
11
|
+
export type ActionType = 'CREATE' | 'EDIT' | 'DELETE' | 'EXECUTE' | 'COMPLETE';
|
|
12
|
+
/**
|
|
13
|
+
* Base action interface
|
|
14
|
+
*/
|
|
15
|
+
export interface BaseAction {
|
|
16
|
+
type: ActionType;
|
|
17
|
+
raw: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Create a new file
|
|
21
|
+
*/
|
|
22
|
+
export interface CreateAction extends BaseAction {
|
|
23
|
+
type: 'CREATE';
|
|
24
|
+
path: string;
|
|
25
|
+
content: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Edit an existing file
|
|
29
|
+
*/
|
|
30
|
+
export interface EditAction extends BaseAction {
|
|
31
|
+
type: 'EDIT';
|
|
32
|
+
path: string;
|
|
33
|
+
oldContent: string;
|
|
34
|
+
newContent: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Delete a file
|
|
38
|
+
*/
|
|
39
|
+
export interface DeleteAction extends BaseAction {
|
|
40
|
+
type: 'DELETE';
|
|
41
|
+
path: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Execute a shell command
|
|
45
|
+
*/
|
|
46
|
+
export interface ExecuteAction extends BaseAction {
|
|
47
|
+
type: 'EXECUTE';
|
|
48
|
+
command: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Mark task as complete
|
|
52
|
+
*/
|
|
53
|
+
export interface CompleteAction extends BaseAction {
|
|
54
|
+
type: 'COMPLETE';
|
|
55
|
+
reason: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Union type of all actions
|
|
59
|
+
*/
|
|
60
|
+
export type Action = CreateAction | EditAction | DeleteAction | ExecuteAction | CompleteAction;
|
|
61
|
+
/**
|
|
62
|
+
* Result of parsing a response
|
|
63
|
+
*/
|
|
64
|
+
export interface ParseResult {
|
|
65
|
+
/** Successfully parsed actions */
|
|
66
|
+
actions: Action[];
|
|
67
|
+
/** Any parsing errors or warnings */
|
|
68
|
+
errors: string[];
|
|
69
|
+
/** Whether response contained any valid action blocks */
|
|
70
|
+
hasActions: boolean;
|
|
71
|
+
/** Raw text outside of action blocks (for logging/debugging) */
|
|
72
|
+
freeText: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Parse an AI response to extract structured actions
|
|
76
|
+
*/
|
|
77
|
+
export declare function parseResponse(response: string): ParseResult;
|
|
78
|
+
/**
|
|
79
|
+
* Check if a response contains a COMPLETE action
|
|
80
|
+
*/
|
|
81
|
+
export declare function hasCompleteAction(result: ParseResult): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Get the COMPLETE action if present
|
|
84
|
+
*/
|
|
85
|
+
export declare function getCompleteAction(result: ParseResult): CompleteAction | null;
|
|
86
|
+
/**
|
|
87
|
+
* Filter actions by type
|
|
88
|
+
*/
|
|
89
|
+
export declare function getActionsByType<T extends Action>(result: ParseResult, type: T['type']): T[];
|
|
90
|
+
//# sourceMappingURL=response-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-parser.d.ts","sourceRoot":"","sources":["../../src/core/response-parser.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,UAAU,CAAC;AAE/E;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,UAAU,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,YAAa,SAAQ,UAAU;IAC9C,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,UAAW,SAAQ,UAAU;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,YAAa,SAAQ,UAAU;IAC9C,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,aAAc,SAAQ,UAAU;IAC/C,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,UAAU;IAChD,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG,YAAY,GAAG,UAAU,GAAG,YAAY,GAAG,aAAa,GAAG,cAAc,CAAC;AAE/F;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,kCAAkC;IAClC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,qCAAqC;IACrC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,yDAAyD;IACzD,UAAU,EAAE,OAAO,CAAC;IACpB,gEAAgE;IAChE,QAAQ,EAAE,MAAM,CAAC;CAClB;AAOD;;GAEG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,CA8C3D;AAqJD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAE9D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,GAAG,cAAc,GAAG,IAAI,CAG5E;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAC/C,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,GACd,CAAC,EAAE,CAEL"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response Parser
|
|
3
|
+
*
|
|
4
|
+
* Parses AI responses to extract structured actions.
|
|
5
|
+
* This is a core component of the Ralph pattern - the AI outputs
|
|
6
|
+
* structured actions that we parse and execute.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Action block pattern - matches [ACTION:TYPE] blocks
|
|
10
|
+
*/
|
|
11
|
+
const ACTION_BLOCK_PATTERN = /\[ACTION:(CREATE|EDIT|DELETE|EXECUTE|COMPLETE)\]([\s\S]*?)(?=\[ACTION:|$)/gi;
|
|
12
|
+
/**
|
|
13
|
+
* Parse an AI response to extract structured actions
|
|
14
|
+
*/
|
|
15
|
+
export function parseResponse(response) {
|
|
16
|
+
const actions = [];
|
|
17
|
+
const errors = [];
|
|
18
|
+
let freeText = response;
|
|
19
|
+
// Find all action blocks
|
|
20
|
+
const matches = [...response.matchAll(ACTION_BLOCK_PATTERN)];
|
|
21
|
+
if (matches.length === 0) {
|
|
22
|
+
return {
|
|
23
|
+
actions: [],
|
|
24
|
+
errors: ['No action blocks found in response'],
|
|
25
|
+
hasActions: false,
|
|
26
|
+
freeText: response.trim(),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
for (const match of matches) {
|
|
30
|
+
const actionTypeStr = match[1];
|
|
31
|
+
const actionBodyStr = match[2];
|
|
32
|
+
if (!actionTypeStr || !actionBodyStr)
|
|
33
|
+
continue;
|
|
34
|
+
const actionType = actionTypeStr.toUpperCase();
|
|
35
|
+
const actionBody = actionBodyStr.trim();
|
|
36
|
+
const raw = match[0];
|
|
37
|
+
// Remove this block from freeText
|
|
38
|
+
freeText = freeText.replace(raw, '');
|
|
39
|
+
try {
|
|
40
|
+
const action = parseActionBody(actionType, actionBody, raw);
|
|
41
|
+
if (action) {
|
|
42
|
+
actions.push(action);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
47
|
+
errors.push(`Failed to parse ${actionType} action: ${errorMsg}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
actions,
|
|
52
|
+
errors,
|
|
53
|
+
hasActions: actions.length > 0,
|
|
54
|
+
freeText: freeText.trim(),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Parse the body of an action block based on its type
|
|
59
|
+
*/
|
|
60
|
+
function parseActionBody(type, body, raw) {
|
|
61
|
+
switch (type) {
|
|
62
|
+
case 'CREATE':
|
|
63
|
+
return parseCreateAction(body, raw);
|
|
64
|
+
case 'EDIT':
|
|
65
|
+
return parseEditAction(body, raw);
|
|
66
|
+
case 'DELETE':
|
|
67
|
+
return parseDeleteAction(body, raw);
|
|
68
|
+
case 'EXECUTE':
|
|
69
|
+
return parseExecuteAction(body, raw);
|
|
70
|
+
case 'COMPLETE':
|
|
71
|
+
return parseCompleteAction(body, raw);
|
|
72
|
+
default:
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Parse a CREATE action
|
|
78
|
+
* Expected format:
|
|
79
|
+
* path: relative/path/to/file
|
|
80
|
+
* ```
|
|
81
|
+
* file content
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
function parseCreateAction(body, raw) {
|
|
85
|
+
// Extract path
|
|
86
|
+
const pathMatch = body.match(/^path:\s*(.+)$/m);
|
|
87
|
+
if (!pathMatch?.[1]) {
|
|
88
|
+
throw new Error('Missing path field');
|
|
89
|
+
}
|
|
90
|
+
const filePath = pathMatch[1].trim();
|
|
91
|
+
// Extract content from code block
|
|
92
|
+
const contentMatch = body.match(/```(?:\w*\n)?([\s\S]*?)```/);
|
|
93
|
+
if (!contentMatch?.[1]) {
|
|
94
|
+
throw new Error('Missing content code block');
|
|
95
|
+
}
|
|
96
|
+
const content = contentMatch[1];
|
|
97
|
+
return {
|
|
98
|
+
type: 'CREATE',
|
|
99
|
+
path: filePath,
|
|
100
|
+
content,
|
|
101
|
+
raw,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Parse an EDIT action
|
|
106
|
+
* Expected format:
|
|
107
|
+
* path: relative/path/to/file
|
|
108
|
+
* [OLD]
|
|
109
|
+
* old content
|
|
110
|
+
* [NEW]
|
|
111
|
+
* new content
|
|
112
|
+
*/
|
|
113
|
+
function parseEditAction(body, raw) {
|
|
114
|
+
// Extract path
|
|
115
|
+
const pathMatch = body.match(/^path:\s*(.+)$/m);
|
|
116
|
+
if (!pathMatch?.[1]) {
|
|
117
|
+
throw new Error('Missing path field');
|
|
118
|
+
}
|
|
119
|
+
const filePath = pathMatch[1].trim();
|
|
120
|
+
// Extract old and new content
|
|
121
|
+
const oldMatch = body.match(/\[OLD\]\s*([\s\S]*?)\[NEW\]/);
|
|
122
|
+
if (!oldMatch?.[1]) {
|
|
123
|
+
throw new Error('Missing [OLD]...[NEW] markers');
|
|
124
|
+
}
|
|
125
|
+
const oldContent = oldMatch[1].trim();
|
|
126
|
+
const newMatch = body.match(/\[NEW\]\s*([\s\S]*)$/);
|
|
127
|
+
if (!newMatch?.[1]) {
|
|
128
|
+
throw new Error('Missing content after [NEW] marker');
|
|
129
|
+
}
|
|
130
|
+
const newContent = newMatch[1].trim();
|
|
131
|
+
return {
|
|
132
|
+
type: 'EDIT',
|
|
133
|
+
path: filePath,
|
|
134
|
+
oldContent,
|
|
135
|
+
newContent,
|
|
136
|
+
raw,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Parse a DELETE action
|
|
141
|
+
* Expected format:
|
|
142
|
+
* path: relative/path/to/file
|
|
143
|
+
*/
|
|
144
|
+
function parseDeleteAction(body, raw) {
|
|
145
|
+
const pathMatch = body.match(/^path:\s*(.+)$/m);
|
|
146
|
+
if (!pathMatch?.[1]) {
|
|
147
|
+
throw new Error('Missing path field');
|
|
148
|
+
}
|
|
149
|
+
const filePath = pathMatch[1].trim();
|
|
150
|
+
return {
|
|
151
|
+
type: 'DELETE',
|
|
152
|
+
path: filePath,
|
|
153
|
+
raw,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Parse an EXECUTE action
|
|
158
|
+
* Expected format:
|
|
159
|
+
* command: shell command here
|
|
160
|
+
*/
|
|
161
|
+
function parseExecuteAction(body, raw) {
|
|
162
|
+
const commandMatch = body.match(/^command:\s*(.+)$/m);
|
|
163
|
+
if (!commandMatch?.[1]) {
|
|
164
|
+
throw new Error('Missing command field');
|
|
165
|
+
}
|
|
166
|
+
const command = commandMatch[1].trim();
|
|
167
|
+
return {
|
|
168
|
+
type: 'EXECUTE',
|
|
169
|
+
command,
|
|
170
|
+
raw,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Parse a COMPLETE action
|
|
175
|
+
* Expected format:
|
|
176
|
+
* reason: explanation
|
|
177
|
+
*/
|
|
178
|
+
function parseCompleteAction(body, raw) {
|
|
179
|
+
const reasonMatch = body.match(/^reason:\s*(.+)$/m);
|
|
180
|
+
if (!reasonMatch?.[1]) {
|
|
181
|
+
throw new Error('Missing reason field');
|
|
182
|
+
}
|
|
183
|
+
const reason = reasonMatch[1].trim();
|
|
184
|
+
return {
|
|
185
|
+
type: 'COMPLETE',
|
|
186
|
+
reason,
|
|
187
|
+
raw,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Check if a response contains a COMPLETE action
|
|
192
|
+
*/
|
|
193
|
+
export function hasCompleteAction(result) {
|
|
194
|
+
return result.actions.some((a) => a.type === 'COMPLETE');
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Get the COMPLETE action if present
|
|
198
|
+
*/
|
|
199
|
+
export function getCompleteAction(result) {
|
|
200
|
+
const action = result.actions.find((a) => a.type === 'COMPLETE');
|
|
201
|
+
return action?.type === 'COMPLETE' ? action : null;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Filter actions by type
|
|
205
|
+
*/
|
|
206
|
+
export function getActionsByType(result, type) {
|
|
207
|
+
return result.actions.filter((a) => a.type === type);
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=response-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-parser.js","sourceRoot":"","sources":["../../src/core/response-parser.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA6EH;;GAEG;AACH,MAAM,oBAAoB,GAAG,6EAA6E,CAAC;AAE3G;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,QAAgB;IAC5C,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,QAAQ,GAAG,QAAQ,CAAC;IAExB,yBAAyB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AC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;AAC3D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAmB;IACnD,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;IACjE,OAAO,MAAM,EAAE,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AACrD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAAmB,EACnB,IAAe;IAEf,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAQ,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verification Hooks
|
|
3
|
+
*
|
|
4
|
+
* Implements objective exit criteria for the Ralph loop.
|
|
5
|
+
* The original Ralph pattern requires external, objective verification
|
|
6
|
+
* (tests pass, build succeeds) rather than trusting the AI to say "I'm done".
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Result of running a verification hook
|
|
10
|
+
*/
|
|
11
|
+
export interface VerificationResult {
|
|
12
|
+
/** Whether verification passed */
|
|
13
|
+
passed: boolean;
|
|
14
|
+
/** The hook that was run */
|
|
15
|
+
hookType: VerificationHookType;
|
|
16
|
+
/** Human-readable message */
|
|
17
|
+
message: string;
|
|
18
|
+
/** Command output (stdout + stderr) */
|
|
19
|
+
output?: string;
|
|
20
|
+
/** Duration in milliseconds */
|
|
21
|
+
durationMs: number;
|
|
22
|
+
/** Error if verification failed to run */
|
|
23
|
+
error?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Types of verification hooks
|
|
27
|
+
*/
|
|
28
|
+
export type VerificationHookType = 'test' | 'build' | 'lint' | 'custom';
|
|
29
|
+
/**
|
|
30
|
+
* Configuration for a verification hook
|
|
31
|
+
*/
|
|
32
|
+
export interface VerificationHook {
|
|
33
|
+
/** Type of hook */
|
|
34
|
+
type: VerificationHookType;
|
|
35
|
+
/** Command to run */
|
|
36
|
+
command: string;
|
|
37
|
+
/** Optional name for display */
|
|
38
|
+
name?: string;
|
|
39
|
+
/** Whether this hook is required to pass */
|
|
40
|
+
required: boolean;
|
|
41
|
+
/** Timeout in milliseconds */
|
|
42
|
+
timeoutMs: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Verification manager configuration
|
|
46
|
+
*/
|
|
47
|
+
export interface VerificationConfig {
|
|
48
|
+
/** Working directory */
|
|
49
|
+
cwd: string;
|
|
50
|
+
/** Hooks to run */
|
|
51
|
+
hooks: VerificationHook[];
|
|
52
|
+
/** Whether to stop on first failure */
|
|
53
|
+
stopOnFirstFailure: boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Default hooks based on common project patterns
|
|
57
|
+
*/
|
|
58
|
+
export declare function detectDefaultHooks(_cwd: string): VerificationHook[];
|
|
59
|
+
/**
|
|
60
|
+
* Verification Manager
|
|
61
|
+
*
|
|
62
|
+
* Runs objective verification hooks after each iteration to determine
|
|
63
|
+
* if the task is actually complete (not just AI-declared complete).
|
|
64
|
+
*/
|
|
65
|
+
export declare class VerificationManager {
|
|
66
|
+
private config;
|
|
67
|
+
private detectedHooks;
|
|
68
|
+
private initialized;
|
|
69
|
+
constructor(config?: Partial<VerificationConfig>);
|
|
70
|
+
/**
|
|
71
|
+
* Initialize by detecting available verification hooks
|
|
72
|
+
*/
|
|
73
|
+
initialize(): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Get all configured hooks (explicit + detected)
|
|
76
|
+
*/
|
|
77
|
+
getHooks(): VerificationHook[];
|
|
78
|
+
/**
|
|
79
|
+
* Add a custom hook
|
|
80
|
+
*/
|
|
81
|
+
addHook(hook: VerificationHook): void;
|
|
82
|
+
/**
|
|
83
|
+
* Run a single verification hook
|
|
84
|
+
*/
|
|
85
|
+
runHook(hook: VerificationHook): Promise<VerificationResult>;
|
|
86
|
+
/**
|
|
87
|
+
* Run all verification hooks
|
|
88
|
+
*/
|
|
89
|
+
runAll(): Promise<VerificationResult[]>;
|
|
90
|
+
/**
|
|
91
|
+
* Check if all required hooks passed
|
|
92
|
+
*/
|
|
93
|
+
allRequiredPassed(results: VerificationResult[]): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Get a summary of verification results
|
|
96
|
+
*/
|
|
97
|
+
getSummary(results: VerificationResult[]): string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Create a verification manager with custom configuration
|
|
101
|
+
*/
|
|
102
|
+
export declare function createVerificationManager(config?: Partial<VerificationConfig>): VerificationManager;
|
|
103
|
+
//# sourceMappingURL=verification-hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verification-hooks.d.ts","sourceRoot":"","sources":["../../src/core/verification-hooks.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,kCAAkC;IAClC,MAAM,EAAE,OAAO,CAAC;IAChB,4BAA4B;IAC5B,QAAQ,EAAE,oBAAoB,CAAC;IAC/B,6BAA6B;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+BAA+B;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;AAExE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mBAAmB;IACnB,IAAI,EAAE,oBAA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