prompt-language-shell 0.4.8 → 0.4.9
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/dist/config/EXECUTE.md +279 -0
- package/dist/config/PLAN.md +19 -6
- package/dist/handlers/answer.js +13 -20
- package/dist/handlers/command.js +26 -30
- package/dist/handlers/config.js +9 -18
- package/dist/handlers/execute.js +38 -0
- package/dist/handlers/execution.js +66 -81
- package/dist/handlers/introspect.js +13 -20
- package/dist/handlers/plan.js +31 -34
- package/dist/services/anthropic.js +26 -1
- package/dist/services/colors.js +1 -1
- package/dist/services/components.js +17 -0
- package/dist/services/messages.js +1 -0
- package/dist/services/shell.js +117 -0
- package/dist/services/tool-registry.js +5 -0
- package/dist/services/utils.js +21 -0
- package/dist/tools/execute.tool.js +44 -0
- package/dist/types/handlers.js +1 -0
- package/dist/types/types.js +1 -0
- package/dist/ui/Component.js +6 -0
- package/dist/ui/Confirm.js +2 -2
- package/dist/ui/Execute.js +217 -0
- package/dist/ui/Main.js +30 -69
- package/dist/ui/Spinner.js +10 -5
- package/package.json +7 -7
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
## Overview
|
|
2
|
+
|
|
3
|
+
You are the execution component of "pls" (please), a professional command-line
|
|
4
|
+
concierge. Your role is to **execute shell commands** and operations when tasks
|
|
5
|
+
with type "execute" have been planned and confirmed.
|
|
6
|
+
|
|
7
|
+
## Execution Flow
|
|
8
|
+
|
|
9
|
+
This tool is invoked AFTER:
|
|
10
|
+
1. PLAN created tasks with type "execute" describing operations to perform
|
|
11
|
+
2. User reviewed and confirmed the plan
|
|
12
|
+
3. The execute tasks are now being executed
|
|
13
|
+
|
|
14
|
+
Your task is to translate the planned actions into specific shell commands that
|
|
15
|
+
can be run in the terminal.
|
|
16
|
+
|
|
17
|
+
## Input
|
|
18
|
+
|
|
19
|
+
You will receive:
|
|
20
|
+
- An array of tasks with their actions and parameters
|
|
21
|
+
- Each task describes what needs to be done (e.g., "Create a new file called
|
|
22
|
+
test.txt", "List files in the current directory")
|
|
23
|
+
- Tasks may include params with specific values (paths, filenames, etc.)
|
|
24
|
+
- Tasks from user-defined skills include params.skill (skill name) and parameter
|
|
25
|
+
values that were substituted into the action
|
|
26
|
+
|
|
27
|
+
## Skill-Based Command Generation
|
|
28
|
+
|
|
29
|
+
**CRITICAL**: When tasks originate from a user-defined skill, you MUST use the
|
|
30
|
+
skill's **Execution** section to generate commands, NOT invent your own.
|
|
31
|
+
|
|
32
|
+
### Understanding Skill Structure
|
|
33
|
+
|
|
34
|
+
User-defined skills have two key sections:
|
|
35
|
+
- **Steps**: Describes WHAT to do (shown to user as task actions)
|
|
36
|
+
- **Execution**: Describes HOW to do it (actual shell commands)
|
|
37
|
+
|
|
38
|
+
Each line in Steps corresponds to a line in Execution at the same position.
|
|
39
|
+
|
|
40
|
+
### How to Generate Commands from Skills
|
|
41
|
+
|
|
42
|
+
1. **Identify skill tasks**: Check if tasks have params.skill
|
|
43
|
+
2. **Find the skill**: Look up the skill in "Available Skills" section below
|
|
44
|
+
3. **Match tasks to Execution**: Each task action came from a Steps line;
|
|
45
|
+
use the corresponding Execution line for the command
|
|
46
|
+
4. **Substitute parameters**: Replace {PARAM} placeholders with actual values
|
|
47
|
+
from task params
|
|
48
|
+
|
|
49
|
+
### Example Skill
|
|
50
|
+
|
|
51
|
+
```markdown
|
|
52
|
+
### Name
|
|
53
|
+
Process Data
|
|
54
|
+
|
|
55
|
+
### Steps
|
|
56
|
+
- Load the {SOURCE} dataset
|
|
57
|
+
- Transform the {SOURCE} data
|
|
58
|
+
- Export the results to {FORMAT}
|
|
59
|
+
|
|
60
|
+
### Execution
|
|
61
|
+
- curl -O https://data.example.com/{SOURCE}.csv
|
|
62
|
+
- python3 transform.py --input {SOURCE}.csv --output processed.csv
|
|
63
|
+
- csvtool col 1-3 processed.csv > output.{FORMAT}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Matching Process
|
|
67
|
+
|
|
68
|
+
Given tasks from this skill:
|
|
69
|
+
- Task 1 action: "Load the sales dataset"
|
|
70
|
+
→ Matches Steps line 1 → Use Execution line 1: curl command
|
|
71
|
+
- Task 2 action: "Transform the sales data"
|
|
72
|
+
→ Matches Steps line 2 → Use Execution line 2: python3 transform.py
|
|
73
|
+
- Task 3 action: "Export the results to json"
|
|
74
|
+
→ Matches Steps line 3 → Use Execution line 3: csvtool command
|
|
75
|
+
|
|
76
|
+
**IMPORTANT**: The Execution section contains the ACTUAL commands to run.
|
|
77
|
+
Do NOT invent different commands - use exactly what the skill specifies,
|
|
78
|
+
with parameter placeholders replaced by actual values.
|
|
79
|
+
|
|
80
|
+
**CRITICAL**: Take the exact command from the ### Execution section. Do not
|
|
81
|
+
modify, improve, or rewrite the command in any way. The user wrote these
|
|
82
|
+
commands specifically for their environment and workflow.
|
|
83
|
+
|
|
84
|
+
## Response Format
|
|
85
|
+
|
|
86
|
+
Return a structured response with commands to execute:
|
|
87
|
+
|
|
88
|
+
**Response structure:**
|
|
89
|
+
- **message**: Brief status message (max 64 characters, end with period)
|
|
90
|
+
- **commands**: Array of command objects to execute sequentially
|
|
91
|
+
|
|
92
|
+
**Command object structure:**
|
|
93
|
+
- **description**: Brief description of what this command does (max 64 chars)
|
|
94
|
+
- **command**: The exact shell command to run
|
|
95
|
+
- **workdir**: Optional working directory for the command (defaults to current)
|
|
96
|
+
- **timeout**: Optional timeout in milliseconds (defaults to 30000)
|
|
97
|
+
- **critical**: Whether failure should stop execution (defaults to true)
|
|
98
|
+
|
|
99
|
+
## Command Generation Guidelines
|
|
100
|
+
|
|
101
|
+
When generating commands:
|
|
102
|
+
|
|
103
|
+
1. **Be precise**: Generate exact, runnable shell commands
|
|
104
|
+
2. **Be safe**: Never generate destructive commands without explicit user intent
|
|
105
|
+
3. **Use parameters**: Extract values from task params and incorporate them
|
|
106
|
+
4. **Handle paths**: Use proper quoting for paths with spaces
|
|
107
|
+
5. **Be portable**: Prefer POSIX-compatible commands when possible
|
|
108
|
+
|
|
109
|
+
**Safety rules:**
|
|
110
|
+
- NEVER run `rm -rf /` or any command that could delete system files
|
|
111
|
+
- NEVER run commands that modify system configuration without explicit request
|
|
112
|
+
- NEVER expose sensitive information in command output
|
|
113
|
+
- Always use safe defaults (e.g., prefer `rm -i` over `rm -f` for deletions)
|
|
114
|
+
- For file deletions, prefer moving to trash over permanent deletion
|
|
115
|
+
|
|
116
|
+
## Examples
|
|
117
|
+
|
|
118
|
+
### Example 1: Simple file creation
|
|
119
|
+
|
|
120
|
+
Task: { action: "Create a new file called test.txt", type: "execute",
|
|
121
|
+
params: { filename: "test.txt" } }
|
|
122
|
+
|
|
123
|
+
Response:
|
|
124
|
+
```
|
|
125
|
+
message: "Creating the file."
|
|
126
|
+
commands:
|
|
127
|
+
- description: "Create test.txt"
|
|
128
|
+
command: "touch test.txt"
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Example 2: Directory listing
|
|
132
|
+
|
|
133
|
+
Task: { action: "Show files in the current directory", type: "execute" }
|
|
134
|
+
|
|
135
|
+
Response:
|
|
136
|
+
```
|
|
137
|
+
message: "Listing directory contents."
|
|
138
|
+
commands:
|
|
139
|
+
- description: "List files with details"
|
|
140
|
+
command: "ls -la"
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Example 3: Multiple sequential commands
|
|
144
|
+
|
|
145
|
+
Tasks:
|
|
146
|
+
- { action: "Create project directory", type: "execute",
|
|
147
|
+
params: { path: "my-project" } }
|
|
148
|
+
- { action: "Initialize git repository", type: "execute" }
|
|
149
|
+
- { action: "Create README file", type: "execute" }
|
|
150
|
+
|
|
151
|
+
Response:
|
|
152
|
+
```
|
|
153
|
+
message: "Setting up the project."
|
|
154
|
+
commands:
|
|
155
|
+
- description: "Create project directory"
|
|
156
|
+
command: "mkdir -p my-project"
|
|
157
|
+
- description: "Initialize git repository"
|
|
158
|
+
command: "git init"
|
|
159
|
+
workdir: "my-project"
|
|
160
|
+
- description: "Create README file"
|
|
161
|
+
command: "echo '# My Project' > README.md"
|
|
162
|
+
workdir: "my-project"
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Example 4: Install dependencies
|
|
166
|
+
|
|
167
|
+
Task: { action: "Install dependencies", type: "execute" }
|
|
168
|
+
|
|
169
|
+
Response:
|
|
170
|
+
```
|
|
171
|
+
message: "Installing dependencies."
|
|
172
|
+
commands:
|
|
173
|
+
- description: "Install npm packages"
|
|
174
|
+
command: "npm install"
|
|
175
|
+
timeout: 120000
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Example 5: Skill-based execution
|
|
179
|
+
|
|
180
|
+
When executing from a skill like "Process Data", tasks include params.skill:
|
|
181
|
+
|
|
182
|
+
Tasks:
|
|
183
|
+
- { action: "Load the sales dataset", type: "execute",
|
|
184
|
+
params: { skill: "Process Data", source: "sales", format: "json" } }
|
|
185
|
+
- { action: "Transform the sales data", type: "execute",
|
|
186
|
+
params: { skill: "Process Data", source: "sales", format: "json" } }
|
|
187
|
+
- { action: "Export the results to json", type: "execute",
|
|
188
|
+
params: { skill: "Process Data", source: "sales", format: "json" } }
|
|
189
|
+
|
|
190
|
+
The "Process Data" skill's Execution section specifies:
|
|
191
|
+
- Line 1: curl -O https://data.example.com/{SOURCE}.csv
|
|
192
|
+
- Line 2: python3 transform.py --input {SOURCE}.csv --output processed.csv
|
|
193
|
+
- Line 3: csvtool col 1-3 processed.csv > output.{FORMAT}
|
|
194
|
+
|
|
195
|
+
Response (using skill's Execution commands):
|
|
196
|
+
```
|
|
197
|
+
message: "Processing sales data."
|
|
198
|
+
commands:
|
|
199
|
+
- description: "Load the sales dataset"
|
|
200
|
+
command: "curl -O https://data.example.com/sales.csv"
|
|
201
|
+
timeout: 60000
|
|
202
|
+
- description: "Transform the sales data"
|
|
203
|
+
command: "python3 transform.py --input sales.csv --output processed.csv"
|
|
204
|
+
timeout: 120000
|
|
205
|
+
- description: "Export the results to json"
|
|
206
|
+
command: "csvtool col 1-3 processed.csv > output.json"
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Note: Commands come directly from the skill's Execution section, with {SOURCE}
|
|
210
|
+
replaced by "sales" and {FORMAT} replaced by "json" from task params.
|
|
211
|
+
|
|
212
|
+
### Example 6: File operations with paths
|
|
213
|
+
|
|
214
|
+
Task: { action: "Copy config to backup", type: "execute",
|
|
215
|
+
params: { source: "~/.config/app", destination: "~/.config/app.backup" } }
|
|
216
|
+
|
|
217
|
+
Response:
|
|
218
|
+
```
|
|
219
|
+
message: "Creating backup."
|
|
220
|
+
commands:
|
|
221
|
+
- description: "Copy config directory"
|
|
222
|
+
command: "cp -r ~/.config/app ~/.config/app.backup"
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Example 7: Checking system information
|
|
226
|
+
|
|
227
|
+
Task: { action: "Check disk space", type: "execute" }
|
|
228
|
+
|
|
229
|
+
Response:
|
|
230
|
+
```
|
|
231
|
+
message: "Checking disk space."
|
|
232
|
+
commands:
|
|
233
|
+
- description: "Show disk usage"
|
|
234
|
+
command: "df -h"
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Handling Complex Operations
|
|
238
|
+
|
|
239
|
+
For complex multi-step operations:
|
|
240
|
+
|
|
241
|
+
1. **Sequential dependencies**: Mark early commands as critical so failure
|
|
242
|
+
stops the chain
|
|
243
|
+
2. **Long-running processes**: Set appropriate timeouts (build processes may
|
|
244
|
+
need 10+ minutes)
|
|
245
|
+
3. **Working directories**: Use workdir to ensure commands run in the right
|
|
246
|
+
location
|
|
247
|
+
4. **Error handling**: For non-critical cleanup steps, set critical: false
|
|
248
|
+
|
|
249
|
+
## Common Mistakes to Avoid
|
|
250
|
+
|
|
251
|
+
❌ Generating commands that don't match the task description
|
|
252
|
+
❌ Using platform-specific commands without consideration
|
|
253
|
+
❌ Forgetting to quote paths with spaces
|
|
254
|
+
❌ Setting unrealistic timeouts for long operations
|
|
255
|
+
❌ Running destructive commands without safeguards
|
|
256
|
+
❌ Ignoring task parameters when generating commands
|
|
257
|
+
❌ Inventing commands instead of using skill's Execution section
|
|
258
|
+
❌ Ignoring params.skill and making up your own commands
|
|
259
|
+
❌ Not substituting parameter placeholders in skill commands
|
|
260
|
+
|
|
261
|
+
✅ Match commands precisely to task descriptions
|
|
262
|
+
✅ Use task params to fill in specific values
|
|
263
|
+
✅ Quote all file paths properly
|
|
264
|
+
✅ Set appropriate timeouts for each operation type
|
|
265
|
+
✅ Include safety checks for destructive operations
|
|
266
|
+
✅ Generate portable commands when possible
|
|
267
|
+
✅ Always use skill's Execution section when params.skill is present
|
|
268
|
+
✅ Replace all {PARAM} placeholders with values from task params
|
|
269
|
+
|
|
270
|
+
## Final Validation
|
|
271
|
+
|
|
272
|
+
Before returning commands:
|
|
273
|
+
|
|
274
|
+
1. Verify each command matches its task description
|
|
275
|
+
2. Check that all task params are incorporated
|
|
276
|
+
3. Ensure paths are properly quoted
|
|
277
|
+
4. Confirm timeouts are reasonable for each operation
|
|
278
|
+
5. Validate that critical flags are set appropriately
|
|
279
|
+
6. Review for any safety concerns
|
package/dist/config/PLAN.md
CHANGED
|
@@ -127,8 +127,13 @@ executable operations.
|
|
|
127
127
|
- Create a task definition for each step with:
|
|
128
128
|
- action: clear, professional description starting with a capital letter
|
|
129
129
|
- type: category of operation (if the skill specifies it or you can infer it)
|
|
130
|
-
- params:
|
|
130
|
+
- params: MUST include:
|
|
131
|
+
- skill: the skill name (REQUIRED for all skill-based tasks)
|
|
132
|
+
- All parameter values used in the step (e.g., target, environment, etc.)
|
|
133
|
+
- Any other specific parameters mentioned in the step
|
|
131
134
|
- NEVER replace the skill's detailed steps with a generic restatement
|
|
135
|
+
- The params.skill field is CRITICAL for execution to use the skill's
|
|
136
|
+
Execution section
|
|
132
137
|
|
|
133
138
|
6. **Handle additional requirements beyond the skill:**
|
|
134
139
|
- If the user's query includes additional requirements beyond the skill,
|
|
@@ -138,13 +143,19 @@ executable operations.
|
|
|
138
143
|
- NEVER create generic execute tasks for unmatched requirements
|
|
139
144
|
|
|
140
145
|
Example 1 - Skill with parameter, variant specified:
|
|
146
|
+
- Skill name: "Process Data"
|
|
141
147
|
- Skill has {TARGET} parameter with variants: Alpha, Beta, Gamma
|
|
142
148
|
- Skill steps: "- Navigate to the {TARGET} root directory. - Execute the
|
|
143
149
|
{TARGET} generation script. - Run the {TARGET} processing pipeline"
|
|
144
150
|
- User: "process Alpha"
|
|
145
|
-
- Correct: Three tasks with
|
|
146
|
-
{
|
|
147
|
-
|
|
151
|
+
- Correct: Three tasks with params including skill name:
|
|
152
|
+
- { action: "Navigate to the Alpha root directory", type: "execute",
|
|
153
|
+
params: { skill: "Process Data", target: "Alpha" } }
|
|
154
|
+
- { action: "Execute the Alpha generation script", type: "execute",
|
|
155
|
+
params: { skill: "Process Data", target: "Alpha" } }
|
|
156
|
+
- { action: "Run the Alpha processing pipeline", type: "execute",
|
|
157
|
+
params: { skill: "Process Data", target: "Alpha" } }
|
|
158
|
+
- WRONG: Tasks without params.skill or single task "Process Alpha"
|
|
148
159
|
|
|
149
160
|
Example 2 - Skill with parameter, variant NOT specified:
|
|
150
161
|
- Same skill as Example 1
|
|
@@ -658,8 +669,10 @@ Examples showing proper use of skills and disambiguation:
|
|
|
658
669
|
Delta"] }. NOTE: If variants have descriptions, format as "Process Alpha, the
|
|
659
670
|
legacy version" NOT "Process Alpha (the legacy version)"
|
|
660
671
|
- "process Alpha" with same process skill → Three tasks extracted from skill
|
|
661
|
-
steps
|
|
662
|
-
|
|
672
|
+
steps, each with params: { skill: "Process Data", target: "Alpha" }:
|
|
673
|
+
- "Navigate to the Alpha target's root directory"
|
|
674
|
+
- "Execute the Alpha target generation script"
|
|
675
|
+
- "Run the Alpha processing pipeline"
|
|
663
676
|
- "process all" with same process skill → Twelve tasks (3 steps × 4 targets)
|
|
664
677
|
- "deploy" with deploy skill (staging, production, canary) → One task: type
|
|
665
678
|
"define", action "Clarify which environment to deploy to:", params
|
package/dist/handlers/answer.js
CHANGED
|
@@ -2,27 +2,20 @@ import { ComponentName } from '../types/types.js';
|
|
|
2
2
|
import { createAnswerDisplayDefinition } from '../services/components.js';
|
|
3
3
|
import { createErrorHandler, withQueueHandler } from '../services/queue.js';
|
|
4
4
|
/**
|
|
5
|
-
* Creates answer
|
|
5
|
+
* Creates all answer handlers
|
|
6
6
|
*/
|
|
7
|
-
export function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return undefined;
|
|
19
|
-
}, true, 0);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Creates answer aborted handler
|
|
23
|
-
*/
|
|
24
|
-
export function createAnswerAbortedHandler(handleAborted) {
|
|
25
|
-
return () => {
|
|
7
|
+
export function createAnswerHandlers(ops, handleAborted) {
|
|
8
|
+
const onError = (error) => {
|
|
9
|
+
ops.setQueue(createErrorHandler(ComponentName.Answer, ops.addToTimeline)(error));
|
|
10
|
+
};
|
|
11
|
+
const onComplete = (answer) => {
|
|
12
|
+
ops.setQueue(withQueueHandler(ComponentName.Answer, () => {
|
|
13
|
+
ops.addToTimeline(createAnswerDisplayDefinition(answer));
|
|
14
|
+
return undefined;
|
|
15
|
+
}, true, 0));
|
|
16
|
+
};
|
|
17
|
+
const onAborted = () => {
|
|
26
18
|
handleAborted('Answer');
|
|
27
19
|
};
|
|
20
|
+
return { onError, onComplete, onAborted };
|
|
28
21
|
}
|
package/dist/handlers/command.js
CHANGED
|
@@ -2,37 +2,33 @@ import { ComponentName, TaskType } from '../types/types.js';
|
|
|
2
2
|
import { createConfirmDefinition, createPlanDefinition, markAsDone, } from '../services/components.js';
|
|
3
3
|
import { createErrorHandler, withQueueHandler } from '../services/queue.js';
|
|
4
4
|
/**
|
|
5
|
-
* Creates command
|
|
5
|
+
* Creates all command handlers
|
|
6
6
|
*/
|
|
7
|
-
export function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Creates command aborted handler
|
|
33
|
-
*/
|
|
34
|
-
export function createCommandAbortedHandler(handleAborted) {
|
|
35
|
-
return () => {
|
|
7
|
+
export function createCommandHandlers(ops, handleAborted, planHandlers, executionHandlers) {
|
|
8
|
+
const onError = (error) => {
|
|
9
|
+
ops.setQueue(createErrorHandler(ComponentName.Command, ops.addToTimeline)(error));
|
|
10
|
+
};
|
|
11
|
+
const onComplete = (message, tasks) => {
|
|
12
|
+
ops.setQueue(withQueueHandler(ComponentName.Command, (first) => {
|
|
13
|
+
const hasDefineTask = tasks.some((task) => task.type === TaskType.Define);
|
|
14
|
+
const planDefinition = createPlanDefinition(message, tasks, planHandlers.createAbortHandler(tasks), hasDefineTask ? planHandlers.onSelectionConfirmed : undefined);
|
|
15
|
+
if (hasDefineTask) {
|
|
16
|
+
ops.addToTimeline(markAsDone(first));
|
|
17
|
+
return [planDefinition];
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
const confirmDefinition = createConfirmDefinition(() => {
|
|
21
|
+
executionHandlers.onConfirmed(tasks);
|
|
22
|
+
}, () => {
|
|
23
|
+
executionHandlers.onCancelled(tasks);
|
|
24
|
+
});
|
|
25
|
+
ops.addToTimeline(markAsDone(first), planDefinition);
|
|
26
|
+
return [confirmDefinition];
|
|
27
|
+
}
|
|
28
|
+
}, false, 0));
|
|
29
|
+
};
|
|
30
|
+
const onAborted = () => {
|
|
36
31
|
handleAborted('Request');
|
|
37
32
|
};
|
|
33
|
+
return { onError, onComplete, onAborted };
|
|
38
34
|
}
|
package/dist/handlers/config.js
CHANGED
|
@@ -6,36 +6,30 @@ import { FeedbackMessages } from '../services/messages.js';
|
|
|
6
6
|
import { exitApp } from '../services/process.js';
|
|
7
7
|
import { withQueueHandler } from '../services/queue.js';
|
|
8
8
|
/**
|
|
9
|
-
* Creates config
|
|
9
|
+
* Creates all config handlers
|
|
10
10
|
*/
|
|
11
|
-
export function
|
|
12
|
-
|
|
11
|
+
export function createConfigHandlers(ops, handleAborted, command, commandHandlers, setService) {
|
|
12
|
+
const onFinished = (config) => {
|
|
13
13
|
const anthropicConfig = config;
|
|
14
14
|
saveAnthropicConfig(anthropicConfig);
|
|
15
15
|
const newService = createAnthropicService(anthropicConfig);
|
|
16
16
|
setService(newService);
|
|
17
|
-
|
|
18
|
-
addToTimeline(markAsDone(first), createFeedback(FeedbackType.Succeeded, FeedbackMessages.ConfigurationComplete));
|
|
19
|
-
// Add command to queue if we have one
|
|
17
|
+
ops.setQueue(withQueueHandler(ComponentName.Config, (first, rest) => {
|
|
18
|
+
ops.addToTimeline(markAsDone(first), createFeedback(FeedbackType.Succeeded, FeedbackMessages.ConfigurationComplete));
|
|
20
19
|
if (command) {
|
|
21
20
|
return [
|
|
22
21
|
...rest,
|
|
23
|
-
createCommandDefinition(command, newService,
|
|
22
|
+
createCommandDefinition(command, newService, commandHandlers.onError, commandHandlers.onComplete, commandHandlers.onAborted),
|
|
24
23
|
];
|
|
25
24
|
}
|
|
26
|
-
// No command - exit after showing completion message
|
|
27
25
|
exitApp(0);
|
|
28
26
|
return rest;
|
|
29
|
-
}, false, 0);
|
|
27
|
+
}, false, 0));
|
|
30
28
|
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Creates config aborted handler
|
|
34
|
-
*/
|
|
35
|
-
export function createConfigAbortedHandler(handleAborted) {
|
|
36
|
-
return () => {
|
|
29
|
+
const onAborted = () => {
|
|
37
30
|
handleAborted('Configuration');
|
|
38
31
|
};
|
|
32
|
+
return { onFinished, onAborted };
|
|
39
33
|
}
|
|
40
34
|
/**
|
|
41
35
|
* Creates config execution finished handler for CONFIG skill
|
|
@@ -43,8 +37,6 @@ export function createConfigAbortedHandler(handleAborted) {
|
|
|
43
37
|
*/
|
|
44
38
|
export function createConfigExecutionFinishedHandler(addToTimeline, keys) {
|
|
45
39
|
return (config) => {
|
|
46
|
-
// Map short keys back to full keys and save
|
|
47
|
-
// Group by section (e.g., "anthropic", "settings")
|
|
48
40
|
const sections = {};
|
|
49
41
|
for (const fullKey of keys) {
|
|
50
42
|
const parts = fullKey.split('.');
|
|
@@ -55,7 +47,6 @@ export function createConfigExecutionFinishedHandler(addToTimeline, keys) {
|
|
|
55
47
|
sections[section][shortKey] = config[shortKey];
|
|
56
48
|
}
|
|
57
49
|
}
|
|
58
|
-
// Save each section
|
|
59
50
|
for (const [section, sectionConfig] of Object.entries(sections)) {
|
|
60
51
|
saveConfig(section, sectionConfig);
|
|
61
52
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ComponentName, FeedbackType } from '../types/types.js';
|
|
2
|
+
import { createFeedback, createMessage, markAsDone, } from '../services/components.js';
|
|
3
|
+
import { formatDuration } from '../services/messages.js';
|
|
4
|
+
import { exitApp } from '../services/process.js';
|
|
5
|
+
import { ExecutionResult } from '../services/shell.js';
|
|
6
|
+
import { withQueueHandler } from '../services/queue.js';
|
|
7
|
+
/**
|
|
8
|
+
* Creates all execute handlers
|
|
9
|
+
*/
|
|
10
|
+
export function createExecuteHandlers(ops, handleAborted) {
|
|
11
|
+
const onError = (error) => {
|
|
12
|
+
ops.setQueue(withQueueHandler(ComponentName.Execute, (first) => {
|
|
13
|
+
ops.addToTimeline(markAsDone(first), createFeedback(FeedbackType.Failed, error));
|
|
14
|
+
exitApp(1);
|
|
15
|
+
return [];
|
|
16
|
+
}));
|
|
17
|
+
};
|
|
18
|
+
const onComplete = (outputs, totalElapsed) => {
|
|
19
|
+
ops.setQueue(withQueueHandler(ComponentName.Execute, (first) => {
|
|
20
|
+
const failed = outputs.find((out) => out.result !== ExecutionResult.Success);
|
|
21
|
+
if (failed) {
|
|
22
|
+
const errorMessage = failed.error
|
|
23
|
+
? `${failed.description}: ${failed.error}`
|
|
24
|
+
: `${failed.description} failed`;
|
|
25
|
+
ops.addToTimeline(markAsDone(first), createFeedback(FeedbackType.Failed, errorMessage));
|
|
26
|
+
exitApp(1);
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
ops.addToTimeline(markAsDone(first), createMessage(`Execution completed in ${formatDuration(totalElapsed)}.`));
|
|
30
|
+
exitApp(0);
|
|
31
|
+
return [];
|
|
32
|
+
}));
|
|
33
|
+
};
|
|
34
|
+
const onAborted = () => {
|
|
35
|
+
handleAborted('Execution');
|
|
36
|
+
};
|
|
37
|
+
return { onError, onComplete, onAborted };
|
|
38
|
+
}
|