prompt-language-shell 0.5.2 → 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/dist/config/ANSWER.md +4 -0
- 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 +26 -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 +1 -1
- 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
|
@@ -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
|
-
});
|