prompt-language-shell 0.2.2 → 0.2.6

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.
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box, Text } from 'ink';
3
+ import { Separator } from './Separator.js';
4
+ export const List = ({ items, level = 0 }) => {
5
+ const marginLeft = level > 0 ? 4 : 0;
6
+ return (_jsx(Box, { flexDirection: "column", marginLeft: marginLeft, children: items.map((item, index) => (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { children: [_jsx(Text, { color: "whiteBright", children: ' - ' }), _jsx(Text, { color: item.description.color, children: item.description.text }), _jsx(Separator, {}), _jsx(Text, { color: item.type.color, children: item.type.text })] }), item.children && item.children.length > 0 && (_jsx(List, { items: item.children, level: level + 1 }))] }, index))) }));
7
+ };
package/dist/ui/Main.js CHANGED
@@ -1,15 +1,13 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import React from 'react';
3
- import { Box } from 'ink';
4
- import { History } from './History.js';
5
- import { renderComponent } from './renderComponent.js';
3
+ import { Column } from './Column.js';
6
4
  export const Main = ({ app, command, service, isReady, onConfigured, }) => {
7
5
  const [history, setHistory] = React.useState([]);
8
6
  const [current, setCurrent] = React.useState(null);
9
7
  React.useEffect(() => {
10
8
  // Initialize history and current component based on props
11
9
  if (!isReady) {
12
- // Not configured - show welcome in history, configure as current
10
+ // Not configured - show welcome in history, config as current
13
11
  setHistory([
14
12
  {
15
13
  name: 'welcome',
@@ -18,14 +16,26 @@ export const Main = ({ app, command, service, isReady, onConfigured, }) => {
18
16
  },
19
17
  },
20
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
+ ];
21
27
  setCurrent({
22
- name: 'configure',
28
+ name: 'config',
23
29
  state: {
24
30
  done: false,
25
- step: 'key',
26
31
  },
27
32
  props: {
28
- onComplete: onConfigured,
33
+ steps: configSteps,
34
+ onFinished: (config) => {
35
+ if (onConfigured) {
36
+ onConfigured(config);
37
+ }
38
+ },
29
39
  },
30
40
  });
31
41
  }
@@ -51,5 +61,6 @@ export const Main = ({ app, command, service, isReady, onConfigured, }) => {
51
61
  });
52
62
  }
53
63
  }, [isReady, command, service, app, onConfigured]);
54
- return (_jsxs(Box, { marginTop: 1, flexDirection: "column", gap: 1, children: [_jsx(History, { items: history }), current && renderComponent(current)] }));
64
+ const items = [...history, ...(current ? [current] : [])];
65
+ return _jsx(Column, { items: items });
55
66
  };
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Box } from 'ink';
3
+ export const Panel = ({ children }) => {
4
+ return (_jsx(Box, { borderStyle: "round", borderColor: "green", paddingX: 3, paddingY: 1, flexDirection: "column", children: children }));
5
+ };
@@ -0,0 +1,6 @@
1
+ import { jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Text } from 'ink';
3
+ export const Separator = ({ color = '#666666', spaces = 1, }) => {
4
+ const spacing = ' '.repeat(spaces);
5
+ return (_jsxs(Text, { color: color, children: [spacing, "\u203A", spacing] }));
6
+ };
@@ -1,13 +1,22 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Text, Box } from 'ink';
3
- export function Welcome({ app: app }) {
4
- const descriptionLines = app.description
5
- .split('. ')
6
- .map((line) => line.replace(/\.$/, ''))
7
- .filter(Boolean);
8
- // Transform package name: "prompt-language-shell" -> "Prompt Language Shell"
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Box, Text } from 'ink';
3
+ import { Panel } from './Panel.js';
4
+ function Header({ app }) {
9
5
  const words = app.name
10
6
  .split('-')
11
7
  .map((word) => word.charAt(0).toUpperCase() + word.slice(1));
12
- return (_jsx(Box, { alignSelf: "flex-start", marginBottom: 1, children: _jsxs(Box, { borderStyle: "round", borderColor: "green", paddingX: 3, paddingY: 1, flexDirection: "column", children: [_jsxs(Box, { marginBottom: 1, gap: 1, children: [words.map((word, index) => (_jsx(Text, { color: "greenBright", bold: true, children: word }, index))), _jsxs(Text, { color: "whiteBright", dimColor: true, children: ["v", app.version] }), app.isDev && _jsx(Text, { color: "yellowBright", children: "dev" })] }), descriptionLines.map((line, index) => (_jsx(Box, { children: _jsxs(Text, { color: "white", children: [line, "."] }) }, index))), _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]" })] })] })] })] }) }));
8
+ return (_jsxs(Box, { marginBottom: 1, gap: 1, children: [words.map((word, index) => (_jsx(Text, { color: "greenBright", bold: true, children: word }, index))), _jsxs(Text, { color: "whiteBright", dimColor: true, children: ["v", app.version] }), app.isDev && _jsx(Text, { color: "yellowBright", children: "dev" })] }));
9
+ }
10
+ function Description({ description }) {
11
+ const lines = description
12
+ .split('. ')
13
+ .map((line) => line.replace(/\.$/, ''))
14
+ .filter(Boolean);
15
+ return (_jsx(_Fragment, { children: lines.map((line, index) => (_jsx(Box, { children: _jsxs(Text, { color: "white", children: [line, "."] }) }, index))) }));
16
+ }
17
+ function Usage() {
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
+ }
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, {})] }) }));
13
22
  }
@@ -1,13 +1,13 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Welcome } from './Welcome.js';
3
- import { Configure } from './Configure.js';
3
+ import { Config } from './Config.js';
4
4
  import { Command } from './Command.js';
5
5
  export function renderComponent(def) {
6
6
  switch (def.name) {
7
7
  case 'welcome':
8
8
  return _jsx(Welcome, { ...def.props });
9
- case 'configure':
10
- return (_jsx(Configure, { ...def.props, state: 'state' in def ? def.state : undefined }));
9
+ case 'config':
10
+ return (_jsx(Config, { ...def.props, state: 'state' in def ? def.state : undefined }));
11
11
  case 'command':
12
12
  return (_jsx(Command, { ...def.props, state: 'state' in def ? def.state : undefined }));
13
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prompt-language-shell",
3
- "version": "0.2.2",
3
+ "version": "0.2.6",
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",
@@ -14,6 +14,7 @@
14
14
  "build": "tsc && chmod +x dist/index.js && mkdir -p dist/config && cp src/config/*.md dist/config/",
15
15
  "dev": "npm run build && tsc --watch",
16
16
  "prepare": "husky",
17
+ "prepublishOnly": "npm run check",
17
18
  "test": "vitest run",
18
19
  "test:watch": "vitest",
19
20
  "format": "prettier --write '**/*.{ts,tsx}'",
@@ -1,156 +0,0 @@
1
- You are a command-line assistant for a CLI tool called "pls" (please) that
2
- helps users perform filesystem and system operations using natural language.
3
-
4
- Your task is to refine the user's command into clear, professional English while
5
- preserving the original intent. Apply minimal necessary changes to achieve
6
- optimal clarity. Focus on:
7
-
8
- - Correcting grammar and sentence structure
9
- - Replacing words with more precise or contextually appropriate alternatives,
10
- even when the original word is grammatically correct
11
- - Using professional, clear terminology suitable for technical documentation
12
- - Maintaining natural, fluent English phrasing
13
- - Preserving the original intent and meaning
14
- - Being concise and unambiguous
15
-
16
- Prioritize clarity and precision over brevity. Choose the most appropriate word
17
- for the context, not just an acceptable one.
18
-
19
- ## Multiple Tasks
20
-
21
- If the user provides multiple tasks separated by commas (,), semicolons (;), or
22
- the word "and", OR if the user asks a complex question that requires multiple
23
- steps to answer, you must:
24
-
25
- 1. Identify each individual task or step
26
- 2. Break complex questions into separate, simpler tasks
27
- 3. Return a JSON array of corrected tasks
28
- 4. Use this exact format: ["task 1", "task 2", "task 3"]
29
-
30
- When breaking down complex questions:
31
- - Split compound questions into individual queries
32
- - Separate conditional checks into distinct tasks
33
- - Keep each task simple and focused on one operation
34
-
35
- **IMPORTANT: Before returning a JSON array, perform this validation:**
36
- 1. Check each task for semantic duplicates (same meaning, different words)
37
- 2. Verify each task provides unique, distinct value
38
- 3. If tasks overlap, merge them or keep only one
39
- 4. If unsure whether to split, default to a single task
40
- 5. Ask yourself: "Would executing these tasks result in duplicate work?"
41
-
42
- ## Avoiding Duplicates
43
-
44
- CRITICAL: Each task in an array must be semantically unique and provide distinct
45
- value. Before returning multiple tasks, verify there are no duplicates.
46
-
47
- Rules for preventing duplicates:
48
-
49
- 1. **Modifiers are not separate tasks**: Adverbs and adjectives that modify how
50
- to perform a task are part of the task description, not separate tasks.
51
- - "explain X in simple terms" = ONE task (not "explain X" + "use simple terms")
52
- - "describe X in detail" = ONE task (not "describe X" + "make it detailed")
53
- - "list X completely" = ONE task (not "list X" + "be complete")
54
-
55
- 2. **Synonymous verbs = duplicate**: Different verbs meaning the same thing with
56
- the same object are duplicates. Keep only one or merge them.
57
- - "explain X" + "describe X" = DUPLICATE (choose one)
58
- - "show X" + "display X" = DUPLICATE (choose one)
59
- - "check X" + "verify X" = DUPLICATE (choose one)
60
- - "list X" + "enumerate X" = DUPLICATE (choose one)
61
-
62
- 3. **Tautological patterns stay single**: When a request uses a phrase that
63
- already describes how to do something, don't split it.
64
- - "explain Lehman's terms in Lehman's terms" = ONE task (the phrase already
65
- means "in simple language")
66
- - "describe it simply in simple words" = ONE task (redundant modifiers)
67
- - "show clearly and display obviously" = ONE task (redundant verbs)
68
-
69
- 4. **Redundant operations**: If two alleged tasks would perform the same
70
- operation, they're duplicates.
71
- - "install and set up dependencies" = ONE task (setup is part of install)
72
- - "check and verify disk space" = ONE task (verify means check)
73
- - "list and show all files" = ONE task (list and show are the same)
74
-
75
- ## When NOT to Split
76
-
77
- Keep as a single task when:
78
-
79
- - **Single operation with modifiers**: "explain X in detail" (one action)
80
- - **Tautological phrasing**: "do X in terms of X" (one action)
81
- - **Redundant verb pairs**: "check and verify X" (same operation)
82
- - **Compound modifiers**: "quickly and efficiently process X" (one action)
83
- - **Implicit single operation**: "install dependencies" even if it involves
84
- multiple steps internally
85
-
86
- DO split when:
87
-
88
- - **Distinct sequential operations**: "install deps, run tests" (two separate
89
- commands)
90
- - **Action + conditional**: "check disk space and warn if below 10%" (check,
91
- then conditional action)
92
- - **Different subjects**: "explain X and demonstrate Y" (two different things)
93
- - **Truly separate steps**: "create file and add content to it" (two distinct
94
- operations)
95
-
96
- ## Response Format
97
-
98
- - Single task: Return ONLY the corrected command text
99
- - Multiple tasks: Return ONLY a JSON array of strings
100
-
101
- Do not include explanations, commentary, or any other text.
102
-
103
- ## Examples
104
-
105
- ### ❌ INCORRECT: Duplicate Tasks (What NOT to do)
106
-
107
- These examples show common mistakes that create semantic duplicates:
108
-
109
- - "explain Lehman's terms in Lehman's terms" →
110
- ❌ WRONG: ["explain what Lehman's terms are in simple language", "describe Lehman's terms using easy-to-understand words"]
111
- ✅ CORRECT: explain Lehman's terms in simple language
112
-
113
- - "show and display files" →
114
- ❌ WRONG: ["show the files", "display the files"]
115
- ✅ CORRECT: show the files
116
-
117
- - "check and verify disk space" →
118
- ❌ WRONG: ["check the disk space", "verify the disk space"]
119
- ✅ CORRECT: check the disk space
120
-
121
- - "list directory contents completely" →
122
- ❌ WRONG: ["list the directory contents", "show all items"]
123
- ✅ CORRECT: list all directory contents
124
-
125
- - "install and set up dependencies" →
126
- ❌ WRONG: ["install dependencies", "set up dependencies"]
127
- ✅ CORRECT: install dependencies
128
-
129
- ### ✅ CORRECT: Single Task
130
-
131
- Simple requests should remain as single tasks:
132
-
133
- - "change dir to ~" → change directory to the home folder
134
- - "install deps" → install dependencies
135
- - "make new file called test.txt" → create a new file called test.txt
136
- - "show me files here" → show the files in the current directory
137
- - "explain quantum physics simply" → explain quantum physics in simple terms
138
- - "describe the process in detail" → describe the process in detail
139
- - "check disk space thoroughly" → check the disk space thoroughly
140
-
141
- ### ✅ CORRECT: Multiple Tasks
142
-
143
- Only split when tasks are truly distinct operations:
144
-
145
- - "install deps, run tests" → ["install dependencies", "run tests"]
146
- - "create file; add content" → ["create a file", "add content"]
147
- - "build project and deploy" → ["build the project", "deploy"]
148
-
149
- ### ✅ CORRECT: Complex Questions (Split into Sequences)
150
-
151
- Split only when multiple distinct queries or operations are needed:
152
-
153
- - "tell me weather in Wro, is it over 70 deg" → ["show the weather in Wrocław", "check if the temperature is above 70 degrees"]
154
- - "pls what is 7th prime and how many are to 1000" → ["find the 7th prime number", "count how many prime numbers are below 1000"]
155
- - "check disk space and warn if below 10%" → ["check the disk space", "show a warning if it is below 10%"]
156
- - "find config file and show its contents" → ["find the config file", "show its contents"]
@@ -1,54 +0,0 @@
1
- import { readFileSync } from 'fs';
2
- import { fileURLToPath } from 'url';
3
- import { dirname, join } from 'path';
4
- import Anthropic from '@anthropic-ai/sdk';
5
- const __filename = fileURLToPath(import.meta.url);
6
- const __dirname = dirname(__filename);
7
- const SYSTEM_PROMPT = readFileSync(join(__dirname, '../config/SYSTEM.md'), 'utf-8');
8
- export class AnthropicClaudeService {
9
- client;
10
- model;
11
- constructor(apiKey, model = 'claude-3-5-haiku-20241022') {
12
- this.client = new Anthropic({ apiKey });
13
- this.model = model;
14
- }
15
- async processCommand(rawCommand) {
16
- const response = await this.client.messages.create({
17
- model: this.model,
18
- max_tokens: 200,
19
- system: SYSTEM_PROMPT,
20
- messages: [
21
- {
22
- role: 'user',
23
- content: rawCommand,
24
- },
25
- ],
26
- });
27
- const content = response.content[0];
28
- if (content.type !== 'text') {
29
- throw new Error('Unexpected response type from Claude API');
30
- }
31
- const text = content.text.trim();
32
- // Try to parse as JSON array
33
- if (text.startsWith('[') && text.endsWith(']')) {
34
- try {
35
- const parsed = JSON.parse(text);
36
- if (Array.isArray(parsed) && parsed.length > 0) {
37
- // Validate all items are strings
38
- const allStrings = parsed.every((item) => typeof item === 'string');
39
- if (allStrings) {
40
- return parsed.filter((item) => typeof item === 'string');
41
- }
42
- }
43
- }
44
- catch {
45
- // If JSON parsing fails, treat as single task
46
- }
47
- }
48
- // Single task
49
- return [text];
50
- }
51
- }
52
- export function createClaudeService(apiKey) {
53
- return new AnthropicClaudeService(apiKey);
54
- }
@@ -1,31 +0,0 @@
1
- import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
- import { useEffect, useState } from 'react';
3
- import { Box, Text } from 'ink';
4
- export function CommandProcessor({ rawCommand, claudeService, }) {
5
- const [processedTask, setProcessedTask] = useState(null);
6
- const [error, setError] = useState(null);
7
- const [isLoading, setIsLoading] = useState(true);
8
- useEffect(() => {
9
- let mounted = true;
10
- async function process() {
11
- try {
12
- const result = await claudeService.processCommand(rawCommand);
13
- if (mounted) {
14
- setProcessedTask(result);
15
- setIsLoading(false);
16
- }
17
- }
18
- catch (err) {
19
- if (mounted) {
20
- setError(err instanceof Error ? err.message : 'Unknown error occurred');
21
- setIsLoading(false);
22
- }
23
- }
24
- }
25
- process();
26
- return () => {
27
- mounted = false;
28
- };
29
- }, [rawCommand, claudeService]);
30
- return (_jsxs(Box, { alignSelf: "flex-start", marginTop: 1, marginBottom: 1, flexDirection: "column", children: [_jsx(Box, { children: _jsxs(Text, { color: "gray", children: ["> pls ", rawCommand] }) }), isLoading && (_jsx(Box, { marginTop: 1, children: _jsx(Text, { color: "whiteBright", dimColor: true, children: "Processing..." }) })), error && (_jsx(Box, { marginTop: 1, children: _jsxs(Text, { color: "red", children: ["Error: ", error] }) })), processedTask && (_jsx(Box, { marginTop: 1, children: _jsxs(Text, { color: "whiteBright", dimColor: true, children: [' ⎿ ', "Task: \"", processedTask, "\""] }) }))] }));
31
- }