@koush/chatsh 1.0.12 → 1.0.13

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 (3) hide show
  1. package/README.md +16 -35
  2. package/dist/main.js +30 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -2,34 +2,23 @@
2
2
 
3
3
  A terminal-based shell assistant that connects your shell session to an LLM for context-aware help.
4
4
 
5
- ## What it does
5
+ ## Quick Start
6
6
 
7
- Chatsh wraps your shell session and maintains a transcript of all terminal activity. Use the `help` command to query an LLM with context about what you're doing.
8
-
9
- ```
10
- $ help how do I find large files?
11
- ```
12
-
13
- The LLM receives your entire shell transcript and can provide context-aware assistance.
14
-
15
- ## Features
7
+ ```bash
8
+ $ npx @koush/chatsh
9
+ $ ls /nonexistent
10
+ ls: /nonexistent: No such file or directory
16
11
 
17
- - **Shell wrapper** - Wraps zsh/bash/fish in a PTY session
18
- - **LLM integration** - Multiple provider support (OpenAI, Anthropic, Google, OpenAI-compatible)
19
- - **Transcript tracking** - Maintains full terminal history
20
- - **Smart clear detection** - Resets transcript on terminal clear
12
+ $ help why did this command fail
21
13
 
22
- ## Installation
14
+ The command failed because the directory /nonexistent does not exist.
15
+ The ls command lists directory contents, but it cannot find a path
16
+ that doesn't exist on your filesystem. Try ls without arguments to
17
+ see your current directory, or use ls / to list the root directory.
23
18
 
24
- ```bash
25
- npm install -g @koush/chatsh
26
19
  ```
27
20
 
28
- Or run directly with:
29
-
30
- ```bash
31
- npx @koush/chatsh
32
- ```
21
+ The LLM sees your entire terminal transcript and provides context-aware assistance.
33
22
 
34
23
  ## Configuration
35
24
 
@@ -75,20 +64,12 @@ Create `~/.chatsh/chatsh.jsonc`:
75
64
  }
76
65
  ```
77
66
 
78
- ## Usage
79
-
80
- Start chatsh:
81
-
82
- ```bash
83
- chatsh
84
- ```
85
-
86
- Use your shell normally. When you need help:
67
+ ## Features
87
68
 
88
- ```bash
89
- $ help what does this error mean?
90
- $ help how do I grep recursively?
91
- ```
69
+ - Wraps zsh/bash/fish in a PTY session
70
+ - Multiple LLM providers (OpenAI, Anthropic, Google, OpenAI-compatible)
71
+ - Maintains full terminal history
72
+ - Resets transcript on terminal clear
92
73
 
93
74
  ## How it works
94
75
 
package/dist/main.js CHANGED
@@ -4,12 +4,14 @@ import { once } from 'node:events';
4
4
  import { readFileSync, existsSync } from 'node:fs';
5
5
  import { homedir } from 'node:os';
6
6
  import { join } from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
7
8
  import * as jsonc from 'jsonc-parser';
8
9
  import { createOpenAI } from '@ai-sdk/openai';
9
10
  import { createAnthropic } from '@ai-sdk/anthropic';
10
11
  import { createGoogleGenerativeAI } from '@ai-sdk/google';
11
12
  import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
12
13
  import { streamText } from 'ai';
14
+ const __filename = fileURLToPath(import.meta.url);
13
15
  const CONFIG_PATH = join(homedir(), '.chatsh', 'chatsh.jsonc');
14
16
  function loadConfig() {
15
17
  if (!existsSync(CONFIG_PATH)) {
@@ -180,7 +182,13 @@ async function main() {
180
182
  cols: process.stdout.columns || 80,
181
183
  rows: process.stdout.rows || 24,
182
184
  cwd: process.cwd(),
183
- env: { ...process.env, CHATSH_PORT: String(port) }
185
+ env: {
186
+ ...process.env,
187
+ CHATSH_PORT: String(port),
188
+ CHATSH_NODE: process.execPath,
189
+ CHATSH_SCRIPT: __filename,
190
+ CHATSH_TS: __filename.endsWith('.ts') ? '--experimental-strip-types' : ''
191
+ }
184
192
  });
185
193
  process.stdin.setRawMode(true);
186
194
  process.stdin.resume();
@@ -200,7 +208,7 @@ async function main() {
200
208
  }
201
209
  process.stdout.write(data);
202
210
  });
203
- ptyProcess.write('help() { curl -s -X POST -d "$*" http://localhost:$CHATSH_PORT }\n');
211
+ ptyProcess.write('help() { "$CHATSH_NODE" --no-warnings $CHATSH_TS "$CHATSH_SCRIPT" --help "$*"; }\n');
204
212
  if (shell.includes('zsh')) {
205
213
  ptyProcess.write('bindkey "^R" history-incremental-search-backward\n');
206
214
  }
@@ -214,4 +222,23 @@ async function main() {
214
222
  ptyProcess.resize(process.stdout.columns || 80, process.stdout.rows || 24);
215
223
  });
216
224
  }
217
- main();
225
+ // Handle --help flag for shell help command
226
+ if (process.argv[2] === '--help') {
227
+ const query = process.argv.slice(3).join(' ');
228
+ const port = process.env.CHATSH_PORT;
229
+ if (!port) {
230
+ console.error('CHATSH_PORT not set');
231
+ process.exit(1);
232
+ }
233
+ const response = await fetch(`http://localhost:${port}`, {
234
+ method: 'POST',
235
+ body: query
236
+ });
237
+ for await (const chunk of response.body) {
238
+ process.stdout.write(chunk);
239
+ }
240
+ process.exit(0);
241
+ }
242
+ else {
243
+ main();
244
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koush/chatsh",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "type": "module",
5
5
  "main": "dist/main.js",
6
6
  "bin": {