prompt-language-shell 0.5.2 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/config/ANSWER.md +4 -0
  2. package/dist/config/CONFIG.md +4 -2
  3. package/dist/config/PLAN.md +23 -0
  4. package/dist/config/VALIDATE.md +12 -11
  5. package/dist/services/anthropic.js +49 -4
  6. package/dist/services/components.js +56 -66
  7. package/dist/services/configuration.js +169 -13
  8. package/dist/services/messages.js +22 -0
  9. package/dist/services/queue.js +2 -2
  10. package/dist/services/refinement.js +37 -0
  11. package/dist/services/task-router.js +141 -0
  12. package/dist/types/types.js +0 -1
  13. package/dist/ui/Answer.js +18 -27
  14. package/dist/ui/Command.js +44 -27
  15. package/dist/ui/Component.js +23 -50
  16. package/dist/ui/Config.js +77 -55
  17. package/dist/ui/Confirm.js +17 -11
  18. package/dist/ui/Execute.js +66 -45
  19. package/dist/ui/Feedback.js +1 -1
  20. package/dist/ui/Introspect.js +26 -23
  21. package/dist/ui/Main.js +71 -100
  22. package/dist/ui/Message.js +1 -1
  23. package/dist/ui/Plan.js +54 -32
  24. package/dist/ui/Refinement.js +6 -7
  25. package/dist/ui/Report.js +1 -1
  26. package/dist/ui/UserQuery.js +6 -0
  27. package/dist/ui/Validate.js +49 -19
  28. package/dist/ui/Welcome.js +1 -1
  29. package/dist/ui/Workflow.js +132 -0
  30. package/package.json +1 -1
  31. package/dist/handlers/answer.js +0 -21
  32. package/dist/handlers/command.js +0 -34
  33. package/dist/handlers/config.js +0 -88
  34. package/dist/handlers/execute.js +0 -46
  35. package/dist/handlers/execution.js +0 -140
  36. package/dist/handlers/introspect.js +0 -21
  37. package/dist/handlers/plan.js +0 -79
  38. package/dist/types/handlers.js +0 -1
  39. package/dist/ui/AnswerDisplay.js +0 -8
  40. package/dist/ui/Column.js +0 -7
@@ -0,0 +1,132 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useEffect, useMemo, useRef, 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
+ // Ref to track active component for synchronous access
14
+ const activeRef = useRef(null);
15
+ // Keep ref in sync with active state
16
+ useEffect(() => {
17
+ activeRef.current = active;
18
+ }, [active]);
19
+ // Function to move active component to timeline with optional additional items
20
+ const moveActiveToTimeline = useCallback((...items) => {
21
+ const curr = activeRef.current;
22
+ if (!curr) {
23
+ // No active component, just add items if provided
24
+ if (items.length > 0) {
25
+ setTimeline((prev) => [...prev, ...items]);
26
+ }
27
+ return;
28
+ }
29
+ const doneComponent = markAsDone(curr);
30
+ // Atomic update: add active component and any additional items
31
+ setTimeline((prev) => items.length > 0
32
+ ? [...prev, doneComponent, ...items]
33
+ : [...prev, doneComponent]);
34
+ setActive(null);
35
+ }, []);
36
+ // Global handlers for all stateful components
37
+ const handlers = useMemo(() => ({
38
+ onAborted: (operation) => {
39
+ moveActiveToTimeline();
40
+ // Add feedback to queue and exit
41
+ const message = getCancellationMessage(operation);
42
+ setQueue((queue) => [
43
+ ...queue,
44
+ createFeedback(FeedbackType.Aborted, message),
45
+ ]);
46
+ },
47
+ onError: (error) => {
48
+ moveActiveToTimeline();
49
+ // Add feedback to queue and exit with error code
50
+ setQueue((queue) => [
51
+ ...queue,
52
+ createFeedback(FeedbackType.Failed, error),
53
+ ]);
54
+ },
55
+ addToQueue: (...items) => {
56
+ setQueue((queue) => [...queue, ...items]);
57
+ },
58
+ addToTimeline: (...items) => {
59
+ setTimeline((prev) => [...prev, ...items]);
60
+ },
61
+ completeActive: (...items) => {
62
+ moveActiveToTimeline(...items);
63
+ },
64
+ updateState: (newState) => {
65
+ setActive((curr) => {
66
+ if (!curr || !('state' in curr))
67
+ return curr;
68
+ const stateful = curr;
69
+ const updated = {
70
+ ...stateful,
71
+ state: {
72
+ ...stateful.state,
73
+ ...newState,
74
+ },
75
+ };
76
+ // Update ref synchronously so moveActiveToTimeline sees the latest state
77
+ activeRef.current = updated;
78
+ return updated;
79
+ });
80
+ },
81
+ }), [moveActiveToTimeline]);
82
+ // Global Esc handler removed - components handle their own Esc individually
83
+ // Move next item from queue to active
84
+ useEffect(() => {
85
+ if (queue.length > 0 && active === null) {
86
+ const [first, ...rest] = queue;
87
+ setQueue(rest);
88
+ setActive(first);
89
+ }
90
+ }, [queue, active]);
91
+ // Process active component - stateless components auto-move to timeline
92
+ useEffect(() => {
93
+ if (!active)
94
+ return;
95
+ if (isStateless(active)) {
96
+ const doneComponent = markAsDone(active);
97
+ setTimeline((prev) => [...prev, doneComponent]);
98
+ setActive(null);
99
+ }
100
+ // Stateful components stay in active until handlers move them to timeline
101
+ }, [active]);
102
+ // Exit when all done
103
+ useEffect(() => {
104
+ if (active === null && queue.length === 0 && timeline.length > 0) {
105
+ // Check if last item in timeline is a failed feedback
106
+ const lastItem = timeline[timeline.length - 1];
107
+ const isFailed = lastItem.name === ComponentName.Feedback &&
108
+ lastItem.props.type === FeedbackType.Failed;
109
+ exitApp(isFailed ? 1 : 0);
110
+ }
111
+ }, [active, queue, timeline]);
112
+ // Inject global handlers into active component
113
+ const activeComponent = useMemo(() => {
114
+ if (!active)
115
+ return null;
116
+ // For stateless components, render as-is with isActive=true
117
+ if (isStateless(active)) {
118
+ return (_jsx(Component, { def: active, isActive: true, debug: debug }, active.id));
119
+ }
120
+ // For stateful components, inject global handlers
121
+ const statefulActive = active;
122
+ const wrappedDef = {
123
+ ...statefulActive,
124
+ props: {
125
+ ...statefulActive.props,
126
+ handlers,
127
+ },
128
+ };
129
+ return (_jsx(Component, { def: wrappedDef, isActive: true, debug: debug }, active.id));
130
+ }, [active, debug, handlers]);
131
+ 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 })] }));
132
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prompt-language-shell",
3
- "version": "0.5.2",
3
+ "version": "0.6.2",
4
4
  "description": "Your personal command-line concierge. Ask politely, and it gets things done.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -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
- }
@@ -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
- }
@@ -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
- }
@@ -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
- }
@@ -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
- }
@@ -1 +0,0 @@
1
- export {};
@@ -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
- });