prompt-language-shell 0.5.0 → 0.6.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/README.md +114 -10
- package/dist/config/ANSWER.md +4 -0
- package/dist/config/INTROSPECT.md +4 -3
- package/dist/config/PLAN.md +23 -0
- package/dist/config/VALIDATE.md +12 -11
- package/dist/services/components.js +54 -64
- package/dist/services/configuration.js +84 -0
- package/dist/services/messages.js +22 -0
- package/dist/services/queue.js +2 -2
- package/dist/services/refinement.js +36 -0
- package/dist/services/task-router.js +135 -0
- package/dist/types/types.js +0 -1
- package/dist/ui/Answer.js +18 -27
- package/dist/ui/Command.js +45 -27
- package/dist/ui/Component.js +23 -50
- package/dist/ui/Config.js +49 -24
- package/dist/ui/Confirm.js +17 -11
- package/dist/ui/Execute.js +66 -45
- package/dist/ui/Feedback.js +1 -1
- package/dist/ui/Introspect.js +27 -23
- package/dist/ui/Main.js +71 -100
- package/dist/ui/Message.js +1 -1
- package/dist/ui/Plan.js +54 -32
- package/dist/ui/Refinement.js +6 -7
- package/dist/ui/Report.js +1 -1
- package/dist/ui/UserQuery.js +6 -0
- package/dist/ui/Validate.js +49 -19
- package/dist/ui/Welcome.js +12 -5
- package/dist/ui/Workflow.js +119 -0
- package/package.json +1 -1
- package/dist/handlers/answer.js +0 -21
- package/dist/handlers/command.js +0 -34
- package/dist/handlers/config.js +0 -88
- package/dist/handlers/execute.js +0 -46
- package/dist/handlers/execution.js +0 -140
- package/dist/handlers/introspect.js +0 -21
- package/dist/handlers/plan.js +0 -79
- package/dist/types/handlers.js +0 -1
- package/dist/ui/AnswerDisplay.js +0 -8
- package/dist/ui/Column.js +0 -7
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { Box, Static } from 'ink';
|
|
4
|
+
import { ComponentName, FeedbackType } from '../types/types.js';
|
|
5
|
+
import { createFeedback, isStateless, markAsDone, } from '../services/components.js';
|
|
6
|
+
import { exitApp } from '../services/process.js';
|
|
7
|
+
import { getCancellationMessage } from '../services/messages.js';
|
|
8
|
+
import { Component } from './Component.js';
|
|
9
|
+
export const Workflow = ({ initialQueue, debug }) => {
|
|
10
|
+
const [timeline, setTimeline] = useState([]);
|
|
11
|
+
const [active, setActive] = useState(null);
|
|
12
|
+
const [queue, setQueue] = useState(initialQueue);
|
|
13
|
+
// Function to move active component to timeline
|
|
14
|
+
const moveActiveToTimeline = useCallback(() => {
|
|
15
|
+
setActive((curr) => {
|
|
16
|
+
if (!curr)
|
|
17
|
+
return null;
|
|
18
|
+
const doneComponent = markAsDone(curr);
|
|
19
|
+
setTimeline((prev) => [...prev, doneComponent]);
|
|
20
|
+
return null;
|
|
21
|
+
});
|
|
22
|
+
}, []);
|
|
23
|
+
// Global handlers for all stateful components
|
|
24
|
+
const handlers = useMemo(() => ({
|
|
25
|
+
onComplete: () => {
|
|
26
|
+
moveActiveToTimeline();
|
|
27
|
+
},
|
|
28
|
+
onAborted: (operation) => {
|
|
29
|
+
moveActiveToTimeline();
|
|
30
|
+
// Add feedback to queue and exit
|
|
31
|
+
const message = getCancellationMessage(operation);
|
|
32
|
+
setQueue((queue) => [
|
|
33
|
+
...queue,
|
|
34
|
+
createFeedback(FeedbackType.Aborted, message),
|
|
35
|
+
]);
|
|
36
|
+
},
|
|
37
|
+
onError: (error) => {
|
|
38
|
+
moveActiveToTimeline();
|
|
39
|
+
// Add feedback to queue and exit with error code
|
|
40
|
+
setQueue((queue) => [
|
|
41
|
+
...queue,
|
|
42
|
+
createFeedback(FeedbackType.Failed, error),
|
|
43
|
+
]);
|
|
44
|
+
},
|
|
45
|
+
addToQueue: (...items) => {
|
|
46
|
+
setQueue((queue) => [...queue, ...items]);
|
|
47
|
+
},
|
|
48
|
+
addToTimeline: (...items) => {
|
|
49
|
+
setTimeline((prev) => [...prev, ...items]);
|
|
50
|
+
},
|
|
51
|
+
completeActive: () => {
|
|
52
|
+
moveActiveToTimeline();
|
|
53
|
+
},
|
|
54
|
+
updateState: (newState) => {
|
|
55
|
+
setActive((curr) => {
|
|
56
|
+
if (!curr || !('state' in curr))
|
|
57
|
+
return curr;
|
|
58
|
+
const stateful = curr;
|
|
59
|
+
return {
|
|
60
|
+
...stateful,
|
|
61
|
+
state: {
|
|
62
|
+
...stateful.state,
|
|
63
|
+
...newState,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
}), [moveActiveToTimeline]);
|
|
69
|
+
// Global Esc handler removed - components handle their own Esc individually
|
|
70
|
+
// Move next item from queue to active
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (queue.length > 0 && active === null) {
|
|
73
|
+
const [first, ...rest] = queue;
|
|
74
|
+
setQueue(rest);
|
|
75
|
+
setActive(first);
|
|
76
|
+
}
|
|
77
|
+
}, [queue, active]);
|
|
78
|
+
// Process active component - stateless components auto-move to timeline
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (!active)
|
|
81
|
+
return;
|
|
82
|
+
if (isStateless(active)) {
|
|
83
|
+
const doneComponent = markAsDone(active);
|
|
84
|
+
setTimeline((prev) => [...prev, doneComponent]);
|
|
85
|
+
setActive(null);
|
|
86
|
+
}
|
|
87
|
+
// Stateful components stay in active until handlers move them to timeline
|
|
88
|
+
}, [active]);
|
|
89
|
+
// Exit when all done
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
if (active === null && queue.length === 0 && timeline.length > 0) {
|
|
92
|
+
// Check if last item in timeline is a failed feedback
|
|
93
|
+
const lastItem = timeline[timeline.length - 1];
|
|
94
|
+
const isFailed = lastItem.name === ComponentName.Feedback &&
|
|
95
|
+
lastItem.props.type === FeedbackType.Failed;
|
|
96
|
+
exitApp(isFailed ? 1 : 0);
|
|
97
|
+
}
|
|
98
|
+
}, [active, queue, timeline]);
|
|
99
|
+
// Inject global handlers into active component
|
|
100
|
+
const activeComponent = useMemo(() => {
|
|
101
|
+
if (!active)
|
|
102
|
+
return null;
|
|
103
|
+
// For stateless components, render as-is with isActive=true
|
|
104
|
+
if (isStateless(active)) {
|
|
105
|
+
return (_jsx(Component, { def: active, isActive: true, debug: debug }, active.id));
|
|
106
|
+
}
|
|
107
|
+
// For stateful components, inject global handlers
|
|
108
|
+
const statefulActive = active;
|
|
109
|
+
const wrappedDef = {
|
|
110
|
+
...statefulActive,
|
|
111
|
+
props: {
|
|
112
|
+
...statefulActive.props,
|
|
113
|
+
handlers,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
return (_jsx(Component, { def: wrappedDef, isActive: true, debug: debug }, active.id));
|
|
117
|
+
}, [active, debug, handlers]);
|
|
118
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Static, { items: timeline, children: (item) => (_jsx(Box, { marginTop: 1, children: _jsx(Component, { def: item, isActive: false, debug: debug }) }, item.id)) }, "timeline"), _jsx(Box, { marginTop: 1, children: activeComponent })] }));
|
|
119
|
+
};
|
package/package.json
CHANGED
package/dist/handlers/answer.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ComponentName } from '../types/types.js';
|
|
2
|
-
import { createAnswerDisplayDefinition } from '../services/components.js';
|
|
3
|
-
import { createErrorHandler, withQueueHandler } from '../services/queue.js';
|
|
4
|
-
/**
|
|
5
|
-
* Creates all answer handlers
|
|
6
|
-
*/
|
|
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 = () => {
|
|
18
|
-
handleAborted('Answer');
|
|
19
|
-
};
|
|
20
|
-
return { onError, onComplete, onAborted };
|
|
21
|
-
}
|
package/dist/handlers/command.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { ComponentName, TaskType } from '../types/types.js';
|
|
2
|
-
import { createConfirmDefinition, createPlanDefinition, markAsDone, } from '../services/components.js';
|
|
3
|
-
import { createErrorHandler, withQueueHandler } from '../services/queue.js';
|
|
4
|
-
/**
|
|
5
|
-
* Creates all command handlers
|
|
6
|
-
*/
|
|
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 = () => {
|
|
31
|
-
handleAborted('Request');
|
|
32
|
-
};
|
|
33
|
-
return { onError, onComplete, onAborted };
|
|
34
|
-
}
|
package/dist/handlers/config.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { ComponentName, FeedbackType } from '../types/types.js';
|
|
2
|
-
import { createAnthropicService, } from '../services/anthropic.js';
|
|
3
|
-
import { createCommandDefinition, createExecuteDefinition, createFeedback, markAsDone, } from '../services/components.js';
|
|
4
|
-
import { saveAnthropicConfig, saveConfig } from '../services/configuration.js';
|
|
5
|
-
import { FeedbackMessages } from '../services/messages.js';
|
|
6
|
-
import { exitApp } from '../services/process.js';
|
|
7
|
-
import { withQueueHandler } from '../services/queue.js';
|
|
8
|
-
/**
|
|
9
|
-
* Creates all config handlers
|
|
10
|
-
*/
|
|
11
|
-
export function createConfigHandlers(ops, handleAborted, command, commandHandlers, setService) {
|
|
12
|
-
const onFinished = (config) => {
|
|
13
|
-
const anthropicConfig = config;
|
|
14
|
-
saveAnthropicConfig(anthropicConfig);
|
|
15
|
-
const newService = createAnthropicService(anthropicConfig);
|
|
16
|
-
setService(newService);
|
|
17
|
-
ops.setQueue(withQueueHandler(ComponentName.Config, (first, rest) => {
|
|
18
|
-
ops.addToTimeline(markAsDone(first), createFeedback(FeedbackType.Succeeded, FeedbackMessages.ConfigurationComplete));
|
|
19
|
-
if (command) {
|
|
20
|
-
return [
|
|
21
|
-
...rest,
|
|
22
|
-
createCommandDefinition(command, newService, commandHandlers.onError, commandHandlers.onComplete, commandHandlers.onAborted),
|
|
23
|
-
];
|
|
24
|
-
}
|
|
25
|
-
exitApp(0);
|
|
26
|
-
return rest;
|
|
27
|
-
}, false, 0));
|
|
28
|
-
};
|
|
29
|
-
const onAborted = () => {
|
|
30
|
-
handleAborted('Configuration');
|
|
31
|
-
};
|
|
32
|
-
return { onFinished, onAborted };
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Creates config execution finished handler for CONFIG skill
|
|
36
|
-
* Saves arbitrary config keys and optionally continues with execution
|
|
37
|
-
*/
|
|
38
|
-
export function createConfigExecutionFinishedHandler(addToTimeline, keys, tasks, service, executeHandlers) {
|
|
39
|
-
return (config) => {
|
|
40
|
-
// Group by top-level section
|
|
41
|
-
const sections = {};
|
|
42
|
-
for (const fullKey of keys) {
|
|
43
|
-
const parts = fullKey.split('.');
|
|
44
|
-
const shortKey = parts[parts.length - 1];
|
|
45
|
-
const topSection = parts[0];
|
|
46
|
-
// Initialize section if needed
|
|
47
|
-
sections[topSection] = sections[topSection] ?? {};
|
|
48
|
-
if (shortKey in config) {
|
|
49
|
-
const value = config[shortKey];
|
|
50
|
-
// Build nested structure recursively
|
|
51
|
-
let current = sections[topSection];
|
|
52
|
-
for (let i = 1; i < parts.length - 1; i++) {
|
|
53
|
-
current[parts[i]] = current[parts[i]] ?? {};
|
|
54
|
-
current = current[parts[i]];
|
|
55
|
-
}
|
|
56
|
-
current[parts[parts.length - 1]] = value;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
for (const [section, sectionConfig] of Object.entries(sections)) {
|
|
60
|
-
saveConfig(section, sectionConfig);
|
|
61
|
-
}
|
|
62
|
-
return withQueueHandler(ComponentName.Config, (first, rest) => {
|
|
63
|
-
addToTimeline(markAsDone(first), createFeedback(FeedbackType.Succeeded, FeedbackMessages.ConfigurationComplete));
|
|
64
|
-
// If tasks are provided, continue with execution
|
|
65
|
-
if (tasks && service && executeHandlers) {
|
|
66
|
-
return [
|
|
67
|
-
...rest,
|
|
68
|
-
createExecuteDefinition(tasks, service, executeHandlers.onError, executeHandlers.onComplete, executeHandlers.onAborted),
|
|
69
|
-
];
|
|
70
|
-
}
|
|
71
|
-
// Otherwise, exit (legacy behavior for initial setup)
|
|
72
|
-
exitApp(0);
|
|
73
|
-
return rest;
|
|
74
|
-
}, false, 0);
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Creates config execution aborted handler for CONFIG skill
|
|
79
|
-
*/
|
|
80
|
-
export function createConfigExecutionAbortedHandler(addToTimeline) {
|
|
81
|
-
return () => {
|
|
82
|
-
return withQueueHandler(ComponentName.Config, (first, rest) => {
|
|
83
|
-
addToTimeline(markAsDone(first), createFeedback(FeedbackType.Aborted, 'Configuration cancelled.'));
|
|
84
|
-
exitApp(0);
|
|
85
|
-
return rest;
|
|
86
|
-
}, false, 0);
|
|
87
|
-
};
|
|
88
|
-
}
|
package/dist/handlers/execute.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
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
|
-
void handleAborted;
|
|
12
|
-
const onError = (error) => {
|
|
13
|
-
ops.setQueue(withQueueHandler(ComponentName.Execute, (first) => {
|
|
14
|
-
ops.addToTimeline(markAsDone(first), createFeedback(FeedbackType.Failed, error));
|
|
15
|
-
exitApp(1);
|
|
16
|
-
return [];
|
|
17
|
-
}));
|
|
18
|
-
};
|
|
19
|
-
const onComplete = (outputs, totalElapsed) => {
|
|
20
|
-
ops.setQueue(withQueueHandler(ComponentName.Execute, (first) => {
|
|
21
|
-
const failed = outputs.find((out) => out.result !== ExecutionResult.Success);
|
|
22
|
-
if (failed) {
|
|
23
|
-
const errorMessage = failed.error
|
|
24
|
-
? `${failed.description}: ${failed.error}`
|
|
25
|
-
: `${failed.description} failed`;
|
|
26
|
-
ops.addToTimeline(markAsDone(first), createFeedback(FeedbackType.Failed, errorMessage));
|
|
27
|
-
exitApp(1);
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
ops.addToTimeline(markAsDone(first), createMessage(`Execution completed in ${formatDuration(totalElapsed)}.`));
|
|
31
|
-
exitApp(0);
|
|
32
|
-
return [];
|
|
33
|
-
}));
|
|
34
|
-
};
|
|
35
|
-
const onAborted = (elapsedTime) => {
|
|
36
|
-
ops.setQueue(withQueueHandler(ComponentName.Execute, (first) => {
|
|
37
|
-
const message = elapsedTime > 0
|
|
38
|
-
? `The execution was cancelled after ${formatDuration(elapsedTime)}.`
|
|
39
|
-
: 'The execution was cancelled.';
|
|
40
|
-
ops.addToTimeline(markAsDone(first), createFeedback(FeedbackType.Aborted, message));
|
|
41
|
-
exitApp(0);
|
|
42
|
-
return [];
|
|
43
|
-
}));
|
|
44
|
-
};
|
|
45
|
-
return { onError, onComplete, onAborted };
|
|
46
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { ComponentName, FeedbackType, TaskType } from '../types/types.js';
|
|
2
|
-
import { createAnswerDefinition, createConfigDefinitionWithKeys, createExecuteDefinition, createFeedback, createIntrospectDefinition, createValidateDefinition, markAsDone, } from '../services/components.js';
|
|
3
|
-
import { StepType } from '../ui/Config.js';
|
|
4
|
-
import { getCancellationMessage } from '../services/messages.js';
|
|
5
|
-
import { exitApp } from '../services/process.js';
|
|
6
|
-
import { withQueueHandler } from '../services/queue.js';
|
|
7
|
-
import { createConfigExecutionAbortedHandler, createConfigExecutionFinishedHandler, } from './config.js';
|
|
8
|
-
import { validateExecuteTasks } from '../services/execution-validator.js';
|
|
9
|
-
/**
|
|
10
|
-
* Creates all execution handlers
|
|
11
|
-
*/
|
|
12
|
-
export function createExecutionHandlers(ops, taskHandlers) {
|
|
13
|
-
const onConfirmed = (tasks) => {
|
|
14
|
-
ops.setQueue(withQueueHandler(ComponentName.Confirm, (first) => {
|
|
15
|
-
const allIntrospect = tasks.every((task) => task.type === TaskType.Introspect);
|
|
16
|
-
const allAnswer = tasks.every((task) => task.type === TaskType.Answer);
|
|
17
|
-
const allConfig = tasks.every((task) => task.type === TaskType.Config);
|
|
18
|
-
const allExecute = tasks.every((task) => task.type === TaskType.Execute);
|
|
19
|
-
const service = ops.service;
|
|
20
|
-
if (!service) {
|
|
21
|
-
ops.addToTimeline(markAsDone(first), createFeedback(FeedbackType.Failed, 'Service not available'));
|
|
22
|
-
exitApp(1);
|
|
23
|
-
return [];
|
|
24
|
-
}
|
|
25
|
-
if (allIntrospect && tasks.length > 0) {
|
|
26
|
-
ops.addToTimeline(markAsDone(first));
|
|
27
|
-
return [
|
|
28
|
-
createIntrospectDefinition(tasks, service, taskHandlers.introspect.onError, taskHandlers.introspect.onComplete, taskHandlers.introspect.onAborted),
|
|
29
|
-
];
|
|
30
|
-
}
|
|
31
|
-
else if (allAnswer && tasks.length > 0) {
|
|
32
|
-
const question = tasks[0].action;
|
|
33
|
-
ops.addToTimeline(markAsDone(first));
|
|
34
|
-
return [
|
|
35
|
-
createAnswerDefinition(question, service, taskHandlers.answer.onError, taskHandlers.answer.onComplete, taskHandlers.answer.onAborted),
|
|
36
|
-
];
|
|
37
|
-
}
|
|
38
|
-
else if (allConfig && tasks.length > 0) {
|
|
39
|
-
const keys = tasks
|
|
40
|
-
.map((task) => task.params?.key)
|
|
41
|
-
.filter((key) => typeof key === 'string');
|
|
42
|
-
ops.addToTimeline(markAsDone(first));
|
|
43
|
-
const handleConfigFinished = (config) => {
|
|
44
|
-
ops.setQueue(createConfigExecutionFinishedHandler(ops.addToTimeline, keys)(config));
|
|
45
|
-
};
|
|
46
|
-
const handleConfigAborted = () => {
|
|
47
|
-
ops.setQueue(createConfigExecutionAbortedHandler(ops.addToTimeline)());
|
|
48
|
-
};
|
|
49
|
-
return [
|
|
50
|
-
createConfigDefinitionWithKeys(keys, handleConfigFinished, handleConfigAborted),
|
|
51
|
-
];
|
|
52
|
-
}
|
|
53
|
-
else if (allExecute && tasks.length > 0) {
|
|
54
|
-
// Validate config requirements before execution
|
|
55
|
-
const missingConfig = validateExecuteTasks(tasks);
|
|
56
|
-
if (missingConfig.length > 0) {
|
|
57
|
-
// Config is missing - call VALIDATE tool to get contextual descriptions
|
|
58
|
-
const keys = missingConfig.map((req) => req.path);
|
|
59
|
-
const userRequest = tasks.map((t) => t.action).join(', ');
|
|
60
|
-
ops.addToTimeline(markAsDone(first));
|
|
61
|
-
// Create handlers for Validate completion
|
|
62
|
-
const handleValidateComplete = (configWithDescriptions) => {
|
|
63
|
-
ops.setQueue(withQueueHandler(ComponentName.Validate, (first) => {
|
|
64
|
-
// Create CONFIG component with descriptions from VALIDATE
|
|
65
|
-
const handleConfigFinished = (config) => {
|
|
66
|
-
ops.setQueue(createConfigExecutionFinishedHandler(ops.addToTimeline, keys, tasks, service, taskHandlers.execute)(config));
|
|
67
|
-
};
|
|
68
|
-
const handleConfigAborted = () => {
|
|
69
|
-
ops.setQueue(createConfigExecutionAbortedHandler(ops.addToTimeline)());
|
|
70
|
-
};
|
|
71
|
-
// Create config steps from validated descriptions
|
|
72
|
-
const steps = configWithDescriptions.map((req) => {
|
|
73
|
-
const keyParts = req.path.split('.');
|
|
74
|
-
const shortKey = keyParts[keyParts.length - 1];
|
|
75
|
-
// Extract description without the {path} suffix
|
|
76
|
-
// Format from VALIDATE: "Description {path}"
|
|
77
|
-
let description = req.description || req.path;
|
|
78
|
-
const pathPattern = /\s*\{[^}]+\}\s*$/;
|
|
79
|
-
description = description.replace(pathPattern, '').trim();
|
|
80
|
-
const step = {
|
|
81
|
-
description,
|
|
82
|
-
key: shortKey,
|
|
83
|
-
path: req.path,
|
|
84
|
-
type: StepType.Text,
|
|
85
|
-
value: null,
|
|
86
|
-
validate: () => true,
|
|
87
|
-
};
|
|
88
|
-
return step;
|
|
89
|
-
});
|
|
90
|
-
// Mark Validate as done and move to timeline
|
|
91
|
-
ops.addToTimeline(markAsDone(first));
|
|
92
|
-
return [
|
|
93
|
-
{
|
|
94
|
-
id: crypto.randomUUID(),
|
|
95
|
-
name: ComponentName.Config,
|
|
96
|
-
state: { done: false },
|
|
97
|
-
props: {
|
|
98
|
-
steps,
|
|
99
|
-
onFinished: handleConfigFinished,
|
|
100
|
-
onAborted: handleConfigAborted,
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
];
|
|
104
|
-
}));
|
|
105
|
-
};
|
|
106
|
-
const handleValidateError = (error) => {
|
|
107
|
-
ops.addToTimeline(createFeedback(FeedbackType.Failed, error));
|
|
108
|
-
exitApp(1);
|
|
109
|
-
};
|
|
110
|
-
const handleValidateAborted = () => {
|
|
111
|
-
ops.addToTimeline(createFeedback(FeedbackType.Aborted, 'Configuration validation cancelled'));
|
|
112
|
-
exitApp(0);
|
|
113
|
-
};
|
|
114
|
-
return [
|
|
115
|
-
createValidateDefinition(missingConfig, userRequest, service, handleValidateError, handleValidateComplete, handleValidateAborted),
|
|
116
|
-
];
|
|
117
|
-
}
|
|
118
|
-
// No missing config - execute directly
|
|
119
|
-
ops.addToTimeline(markAsDone(first));
|
|
120
|
-
return [
|
|
121
|
-
createExecuteDefinition(tasks, service, taskHandlers.execute.onError, taskHandlers.execute.onComplete, taskHandlers.execute.onAborted),
|
|
122
|
-
];
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
ops.addToTimeline(markAsDone(first), createFeedback(FeedbackType.Failed, 'I can only process one type of task at a time for now.'));
|
|
126
|
-
exitApp(0);
|
|
127
|
-
return [];
|
|
128
|
-
}
|
|
129
|
-
}));
|
|
130
|
-
};
|
|
131
|
-
const onCancelled = (tasks) => {
|
|
132
|
-
ops.setQueue(withQueueHandler(ComponentName.Confirm, (first) => {
|
|
133
|
-
const allIntrospect = tasks.every((task) => task.type === TaskType.Introspect);
|
|
134
|
-
const operation = allIntrospect ? 'introspection' : 'execution';
|
|
135
|
-
ops.addToTimeline(markAsDone(first), createFeedback(FeedbackType.Aborted, getCancellationMessage(operation)));
|
|
136
|
-
return undefined;
|
|
137
|
-
}, true, 0));
|
|
138
|
-
};
|
|
139
|
-
return { onConfirmed, onCancelled };
|
|
140
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ComponentName } from '../types/types.js';
|
|
2
|
-
import { createReportDefinition } from '../services/components.js';
|
|
3
|
-
import { createErrorHandler, withQueueHandler } from '../services/queue.js';
|
|
4
|
-
/**
|
|
5
|
-
* Creates all introspect handlers
|
|
6
|
-
*/
|
|
7
|
-
export function createIntrospectHandlers(ops, handleAborted) {
|
|
8
|
-
const onError = (error) => {
|
|
9
|
-
ops.setQueue(createErrorHandler(ComponentName.Introspect, ops.addToTimeline)(error));
|
|
10
|
-
};
|
|
11
|
-
const onComplete = (message, capabilities) => {
|
|
12
|
-
ops.setQueue(withQueueHandler(ComponentName.Introspect, () => {
|
|
13
|
-
ops.addToTimeline(createReportDefinition(message, capabilities));
|
|
14
|
-
return undefined;
|
|
15
|
-
}, true, 0));
|
|
16
|
-
};
|
|
17
|
-
const onAborted = () => {
|
|
18
|
-
handleAborted('Introspection');
|
|
19
|
-
};
|
|
20
|
-
return { onError, onComplete, onAborted };
|
|
21
|
-
}
|
package/dist/handlers/plan.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { ComponentName, FeedbackType, TaskType } from '../types/types.js';
|
|
2
|
-
import { createConfirmDefinition, createFeedback, createPlanDefinition, markAsDone, createRefinement, } from '../services/components.js';
|
|
3
|
-
import { FeedbackMessages, formatErrorMessage, getRefiningMessage, } from '../services/messages.js';
|
|
4
|
-
import { exitApp } from '../services/process.js';
|
|
5
|
-
/**
|
|
6
|
-
* Creates all plan handlers
|
|
7
|
-
*/
|
|
8
|
-
export function createPlanHandlers(ops, handleAborted, executionHandlers) {
|
|
9
|
-
const onAborted = () => {
|
|
10
|
-
handleAborted('Task selection');
|
|
11
|
-
};
|
|
12
|
-
const createAbortHandler = (tasks) => {
|
|
13
|
-
const allIntrospect = tasks.every((task) => task.type === TaskType.Introspect);
|
|
14
|
-
if (allIntrospect) {
|
|
15
|
-
return () => {
|
|
16
|
-
handleAborted('Introspection');
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
return onAborted;
|
|
20
|
-
};
|
|
21
|
-
const onSelectionConfirmed = async (selectedTasks) => {
|
|
22
|
-
const refinementDef = createRefinement(getRefiningMessage(), () => {
|
|
23
|
-
handleAborted('Plan refinement');
|
|
24
|
-
});
|
|
25
|
-
ops.setQueue((currentQueue) => {
|
|
26
|
-
if (currentQueue.length === 0)
|
|
27
|
-
return currentQueue;
|
|
28
|
-
const [first] = currentQueue;
|
|
29
|
-
if (first.name === ComponentName.Plan) {
|
|
30
|
-
ops.addToTimeline(markAsDone(first));
|
|
31
|
-
}
|
|
32
|
-
return [refinementDef];
|
|
33
|
-
});
|
|
34
|
-
try {
|
|
35
|
-
const service = ops.service;
|
|
36
|
-
if (!service) {
|
|
37
|
-
ops.addToTimeline(createFeedback(FeedbackType.Failed, FeedbackMessages.UnexpectedError, 'Service not available'));
|
|
38
|
-
exitApp(1);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const refinedCommand = selectedTasks
|
|
42
|
-
.map((task) => {
|
|
43
|
-
const action = task.action.toLowerCase().replace(/,/g, ' -');
|
|
44
|
-
const type = task.type;
|
|
45
|
-
return `${action} (type: ${type})`;
|
|
46
|
-
})
|
|
47
|
-
.join(', ');
|
|
48
|
-
const result = await service.processWithTool(refinedCommand, 'plan');
|
|
49
|
-
ops.setQueue((currentQueue) => {
|
|
50
|
-
if (currentQueue.length > 0 &&
|
|
51
|
-
currentQueue[0].id === refinementDef.id) {
|
|
52
|
-
ops.addToTimeline(markAsDone(currentQueue[0]));
|
|
53
|
-
}
|
|
54
|
-
return [];
|
|
55
|
-
});
|
|
56
|
-
const planDefinition = createPlanDefinition(result.message, result.tasks, createAbortHandler(result.tasks), undefined);
|
|
57
|
-
const confirmDefinition = createConfirmDefinition(() => {
|
|
58
|
-
executionHandlers.onConfirmed(result.tasks);
|
|
59
|
-
}, () => {
|
|
60
|
-
executionHandlers.onCancelled(result.tasks);
|
|
61
|
-
});
|
|
62
|
-
ops.addToTimeline(planDefinition);
|
|
63
|
-
ops.setQueue([confirmDefinition]);
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
const errorMessage = formatErrorMessage(error);
|
|
67
|
-
ops.setQueue((currentQueue) => {
|
|
68
|
-
if (currentQueue.length > 0 &&
|
|
69
|
-
currentQueue[0].id === refinementDef.id) {
|
|
70
|
-
ops.addToTimeline(markAsDone(currentQueue[0]));
|
|
71
|
-
}
|
|
72
|
-
return [];
|
|
73
|
-
});
|
|
74
|
-
ops.addToTimeline(createFeedback(FeedbackType.Failed, FeedbackMessages.UnexpectedError, errorMessage));
|
|
75
|
-
exitApp(1);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
return { onAborted, createAbortHandler, onSelectionConfirmed };
|
|
79
|
-
}
|
package/dist/types/handlers.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/ui/AnswerDisplay.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Box, Text } from 'ink';
|
|
3
|
-
import { Colors } from '../services/colors.js';
|
|
4
|
-
export function AnswerDisplay({ answer }) {
|
|
5
|
-
// Split answer into lines and display with indentation
|
|
6
|
-
const lines = answer.split('\n');
|
|
7
|
-
return (_jsx(Box, { flexDirection: "column", paddingLeft: 2, children: lines.map((line, index) => (_jsx(Text, { color: Colors.Text.Active, children: line }, index))) }));
|
|
8
|
-
}
|
package/dist/ui/Column.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { Box } from 'ink';
|
|
4
|
-
import { Component } from './Component.js';
|
|
5
|
-
export const Column = React.memo(({ items, debug }) => {
|
|
6
|
-
return (_jsx(Box, { marginTop: 1, marginBottom: 1, marginLeft: 1, flexDirection: "column", gap: 1, children: items.map((item) => (_jsx(Box, { children: _jsx(Component, { def: item, debug: debug }) }, item.id))) }));
|
|
7
|
-
});
|