prompt-language-shell 0.2.4 → 0.2.8

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/ui/Main.js CHANGED
@@ -1,66 +1,157 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import React from 'react';
3
+ import { FeedbackType } from '../types/components.js';
3
4
  import { Column } from './Column.js';
4
- export const Main = ({ app, command, service, isReady, onConfigured, }) => {
5
+ function exit(code) {
6
+ setTimeout(() => globalThis.process.exit(code), 100);
7
+ }
8
+ function markAsDone(component) {
9
+ return { ...component, state: { ...component.state, done: true } };
10
+ }
11
+ function createWelcomeDefinition(app) {
12
+ return {
13
+ name: 'welcome',
14
+ props: { app },
15
+ };
16
+ }
17
+ function createConfigSteps() {
18
+ return [
19
+ { description: 'Anthropic API key', key: 'key', value: null },
20
+ {
21
+ description: 'Model',
22
+ key: 'model',
23
+ value: 'claude-haiku-4-5-20251001',
24
+ },
25
+ ];
26
+ }
27
+ function createConfigDefinition(onFinished, onAborted) {
28
+ return {
29
+ name: 'config',
30
+ state: { done: false },
31
+ props: {
32
+ steps: createConfigSteps(),
33
+ onFinished,
34
+ onAborted,
35
+ },
36
+ };
37
+ }
38
+ function createCommandDefinition(command, service, onError, onComplete) {
39
+ return {
40
+ name: 'command',
41
+ state: {
42
+ done: false,
43
+ isLoading: true,
44
+ },
45
+ props: {
46
+ command,
47
+ service,
48
+ onError,
49
+ onComplete,
50
+ },
51
+ };
52
+ }
53
+ export const Main = ({ app, command, service: initialService, isReady, onConfigured, }) => {
5
54
  const [history, setHistory] = React.useState([]);
6
55
  const [current, setCurrent] = React.useState(null);
7
- React.useEffect(() => {
8
- // Initialize history and current component based on props
9
- if (!isReady) {
10
- // Not configured - show welcome in history, config as current
11
- setHistory([
12
- {
13
- name: 'welcome',
14
- props: {
15
- app,
56
+ const [service, setService] = React.useState(initialService);
57
+ const handleConfigFinished = React.useCallback((config) => {
58
+ const service = onConfigured?.(config);
59
+ if (service) {
60
+ setService(service);
61
+ }
62
+ // Move config to history with done state and add success feedback
63
+ setCurrent((previous) => {
64
+ if (previous && previous.name === 'config') {
65
+ setHistory((history) => [
66
+ ...history,
67
+ markAsDone(previous),
68
+ {
69
+ name: 'feedback',
70
+ props: {
71
+ type: FeedbackType.Succeeded,
72
+ message: 'Configuration complete',
73
+ },
74
+ },
75
+ ]);
76
+ }
77
+ return null;
78
+ });
79
+ }, [onConfigured]);
80
+ const handleConfigAborted = React.useCallback(() => {
81
+ // Move config to history with done state and add aborted feedback
82
+ setCurrent((previous) => {
83
+ if (previous && previous.name === 'config') {
84
+ setHistory((history) => [
85
+ ...history,
86
+ markAsDone(previous),
87
+ {
88
+ name: 'feedback',
89
+ props: {
90
+ type: FeedbackType.Aborted,
91
+ message: 'Configuration aborted by user',
92
+ },
16
93
  },
17
- },
18
- ]);
19
- const configSteps = [
20
- { description: 'Anthropic API key', key: 'key', value: null },
21
- {
22
- description: 'Model',
23
- key: 'model',
24
- value: 'claude-haiku-4-5-20251001',
25
- },
26
- ];
27
- setCurrent({
28
- name: 'config',
29
- state: {
30
- done: false,
31
- },
32
- props: {
33
- steps: configSteps,
34
- onFinished: (config) => {
35
- if (onConfigured) {
36
- onConfigured(config);
37
- }
94
+ ]);
95
+ // Exit after showing abort message
96
+ exit(0);
97
+ }
98
+ return null;
99
+ });
100
+ }, []);
101
+ const handleCommandError = React.useCallback((error) => {
102
+ // Move command to history with done state and add error feedback
103
+ setCurrent((previous) => {
104
+ if (previous && previous.name === 'command') {
105
+ setHistory((history) => [
106
+ ...history,
107
+ markAsDone(previous),
108
+ {
109
+ name: 'feedback',
110
+ props: {
111
+ type: FeedbackType.Failed,
112
+ message: `Unexpected error occurred:\n\n ${error}`,
113
+ },
38
114
  },
39
- },
40
- });
115
+ ]);
116
+ // Exit after showing error
117
+ exit(1);
118
+ }
119
+ return null;
120
+ });
121
+ }, []);
122
+ const addToHistory = React.useCallback((...items) => {
123
+ setHistory((history) => [...history, ...items]);
124
+ }, []);
125
+ const handleCommandComplete = React.useCallback(() => {
126
+ // Move command to history with done state
127
+ setCurrent((previous) => {
128
+ if (previous && previous.name === 'command') {
129
+ addToHistory(markAsDone(previous));
130
+ // Exit after showing plan
131
+ exit(0);
132
+ }
133
+ return null;
134
+ });
135
+ }, [addToHistory]);
136
+ // Initialize configuration flow when not ready
137
+ React.useEffect(() => {
138
+ if (!isReady) {
139
+ setHistory(command ? [] : [createWelcomeDefinition(app)]);
140
+ setCurrent(createConfigDefinition(handleConfigFinished, handleConfigAborted));
41
141
  }
42
- else if (command && service) {
43
- setCurrent({
44
- name: 'command',
45
- state: {
46
- done: false,
47
- isLoading: true,
48
- },
49
- props: {
50
- command,
51
- service,
52
- },
53
- });
142
+ }, [isReady, app, command, handleConfigFinished, handleConfigAborted]);
143
+ // Execute command when service and command are available
144
+ React.useEffect(() => {
145
+ if (command && service) {
146
+ setCurrent(createCommandDefinition(command, service, handleCommandError, handleCommandComplete));
54
147
  }
55
- else {
56
- setCurrent({
57
- name: 'welcome',
58
- props: {
59
- app,
60
- },
61
- });
148
+ }, [command, service, handleCommandError, handleCommandComplete]);
149
+ // Show welcome screen when ready but no command
150
+ React.useEffect(() => {
151
+ if (isReady && !command) {
152
+ setCurrent(createWelcomeDefinition(app));
62
153
  }
63
- }, [isReady, command, service, app, onConfigured]);
154
+ }, [isReady, command, app]);
64
155
  const items = [...history, ...(current ? [current] : [])];
65
156
  return _jsx(Column, { items: items });
66
157
  };
@@ -18,5 +18,5 @@ function Usage() {
18
18
  return (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { color: "brightWhite", bold: true, children: "Usage:" }), _jsxs(Box, { gap: 1, children: [_jsx(Text, { color: "whiteBright", dimColor: true, children: ">" }), _jsxs(Box, { gap: 1, children: [_jsx(Text, { color: "greenBright", bold: true, children: "pls" }), _jsx(Text, { color: "yellow", bold: true, children: "[describe your request]" })] })] })] }));
19
19
  }
20
20
  export function Welcome({ app }) {
21
- return (_jsx(Box, { alignSelf: "flex-start", marginBottom: 1, children: _jsxs(Panel, { children: [_jsx(Header, { app: app }), _jsx(Description, { description: app.description }), _jsx(Usage, {})] }) }));
21
+ return (_jsx(Box, { alignSelf: "flex-start", children: _jsxs(Panel, { children: [_jsx(Header, { app: app }), _jsx(Description, { description: app.description }), _jsx(Usage, {})] }) }));
22
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prompt-language-shell",
3
- "version": "0.2.4",
3
+ "version": "0.2.8",
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",