@wheatley-ai/cli 0.1.0 → 0.2.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/README.md +192 -0
- package/dist/cli/chat-state.js +95 -0
- package/dist/cli/chat.js +32 -95
- package/dist/cli/io.js +22 -2
- package/dist/cli/personality.js +81 -0
- package/dist/cli/tui/app.js +159 -0
- package/dist/cli/tui/commands.js +98 -0
- package/dist/cli/tui/controller.js +504 -0
- package/dist/cli/tui/editor.js +125 -0
- package/dist/cli/tui/format.js +32 -0
- package/dist/cli/tui/markdown.js +147 -0
- package/dist/cli/tui/prompt.js +275 -0
- package/dist/cli/tui/run.js +63 -0
- package/dist/cli/tui/transcript.js +89 -0
- package/dist/node_modules/@wheatley-ai/sdk/package.json +1 -1
- package/package.json +8 -2
package/README.md
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# @wheatley-ai/cli
|
|
2
|
+
|
|
3
|
+
Wheatley is a personal AI assistant that you host yourself. It runs as a daemon on your machine or server and keeps working when you close the terminal. It remembers what you tell it and runs jobs on a schedule. Before it writes a file or runs a shell command, it asks you.
|
|
4
|
+
|
|
5
|
+
You can talk to it from the terminal, from the web dashboard, or from Telegram, Slack, and Discord.
|
|
6
|
+
|
|
7
|
+
This package installs the `wheatley` command. The daemon, the CLI, and the dashboard all ship in it.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
You need Node.js 26.13.1 or newer.
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install -g @wheatley-ai/cli
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
pnpm works too: `pnpm add -g @wheatley-ai/cli`.
|
|
18
|
+
|
|
19
|
+
## Quick start
|
|
20
|
+
|
|
21
|
+
Create the config files. By default they go in `~/.wheatley`. Set `WHEATLEY_HOME` or pass `--home` to put them somewhere else.
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
wheatley init
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Put your API key in `~/.wheatley/secrets.yaml`:
|
|
28
|
+
|
|
29
|
+
```yaml
|
|
30
|
+
ANTHROPIC_API_KEY: sk-ant-...
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Start the daemon:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
wheatley daemon
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Then, in another terminal:
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
wheatley ask "Summarize the README in the current folder"
|
|
43
|
+
wheatley chat
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The dashboard is at <http://127.0.0.1:7420>.
|
|
47
|
+
|
|
48
|
+
`wheatley init` sets up Anthropic with `claude-sonnet-5-5`. For another provider, pass `--provider` and `--model`. For example, `wheatley init --provider openai --model gpt-5.4-mini` expects `OPENAI_API_KEY`.
|
|
49
|
+
|
|
50
|
+
## Run it in the background
|
|
51
|
+
|
|
52
|
+
`wheatley service` installs a user service: systemd on Linux, launchd on macOS.
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
wheatley service install
|
|
56
|
+
wheatley service start
|
|
57
|
+
wheatley service status
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Commands
|
|
61
|
+
|
|
62
|
+
| Command | What it does |
|
|
63
|
+
| --- | --- |
|
|
64
|
+
| `wheatley init` | Create `config.yaml` and `secrets.yaml` |
|
|
65
|
+
| `wheatley daemon` | Run the daemon in the foreground |
|
|
66
|
+
| `wheatley chat` | Open an interactive chat with an agent |
|
|
67
|
+
| `wheatley ask "<prompt>"` | Send one prompt and print the reply |
|
|
68
|
+
| `wheatley status` | Show the health of the daemon and each agent |
|
|
69
|
+
| `wheatley service <action>` | `install`, `start`, `stop`, `restart`, or `status` |
|
|
70
|
+
| `wheatley update` | Update to the newest release in your major version |
|
|
71
|
+
| `wheatley restore <agent> [id]` | List or restore an agent's database backups |
|
|
72
|
+
|
|
73
|
+
Run `wheatley --help` for all the options.
|
|
74
|
+
|
|
75
|
+
With no arguments, `ask` reads the prompt from stdin:
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
{ echo "Review this diff:"; git diff; } | wheatley ask
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
If stdin is not a terminal, `ask` cannot ask for approval. It denies every tool call that needs one.
|
|
82
|
+
|
|
83
|
+
## Configuration
|
|
84
|
+
|
|
85
|
+
Wheatley reads its settings from `~/.wheatley/config.yaml`. Secrets go in `secrets.yaml`, and the config refers to them by name. If an environment variable has the same name as a secret, the variable wins.
|
|
86
|
+
|
|
87
|
+
```yaml
|
|
88
|
+
version: 1
|
|
89
|
+
|
|
90
|
+
providers:
|
|
91
|
+
anthropic:
|
|
92
|
+
apiKey:
|
|
93
|
+
secret: ANTHROPIC_API_KEY
|
|
94
|
+
|
|
95
|
+
agents:
|
|
96
|
+
default:
|
|
97
|
+
model:
|
|
98
|
+
provider: anthropic
|
|
99
|
+
id: claude-sonnet-5-5
|
|
100
|
+
|
|
101
|
+
# First match wins. Tools without a rule use their own default.
|
|
102
|
+
permissionPolicy:
|
|
103
|
+
- tool: read_file
|
|
104
|
+
action: allow
|
|
105
|
+
- tool: shell
|
|
106
|
+
action: ask
|
|
107
|
+
|
|
108
|
+
# Chat with the agent from Telegram.
|
|
109
|
+
frontends:
|
|
110
|
+
- id: phone
|
|
111
|
+
type: telegram
|
|
112
|
+
config:
|
|
113
|
+
botToken:
|
|
114
|
+
secret: TELEGRAM_BOT_TOKEN
|
|
115
|
+
allowedChatIds: [123456789]
|
|
116
|
+
|
|
117
|
+
# Give the agent the tools of an MCP server.
|
|
118
|
+
mcpServers:
|
|
119
|
+
github:
|
|
120
|
+
transport: http
|
|
121
|
+
url: https://api.githubcopilot.com/mcp/
|
|
122
|
+
headers:
|
|
123
|
+
Authorization:
|
|
124
|
+
secret: GITHUB_MCP_AUTH
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
You can define more than one agent. Each agent gets its own model, memory, schedule, and folder under `~/.wheatley/agents/<name>/`. After you edit the config, restart the agent from the dashboard or with `/restart` in a chat.
|
|
128
|
+
|
|
129
|
+
## Approvals
|
|
130
|
+
|
|
131
|
+
The file and shell tools work inside `agents/<name>/workspace`. Writing files, running shell commands, and calling MCP tools need your approval by default. When the agent wants to do one of these, the chat shows the tool and its input. You answer with one of these:
|
|
132
|
+
|
|
133
|
+
- `o`: allow it once.
|
|
134
|
+
- `c`: allow it for the rest of the conversation.
|
|
135
|
+
- `a`: allow it always. Wheatley adds an `allow` rule to your config.
|
|
136
|
+
- `d <reason>`: deny it, and tell the agent why.
|
|
137
|
+
|
|
138
|
+
An approval waits 15 minutes and then expires. Change this with `approvalTimeout` on the agent.
|
|
139
|
+
|
|
140
|
+
## Chat commands
|
|
141
|
+
|
|
142
|
+
| Command | What it does |
|
|
143
|
+
| ------------------- | ---------------------------------------------- |
|
|
144
|
+
| `/new` | Start a new conversation |
|
|
145
|
+
| `/model <id>` | Use another model for this conversation |
|
|
146
|
+
| `/compact` | Compact the conversation to save context |
|
|
147
|
+
| `/stop` | Stop the current run |
|
|
148
|
+
| `/goal <objective>` | Start a long-running task |
|
|
149
|
+
| `/status` | Show the conversation, model, and agent health |
|
|
150
|
+
| `/restart` | Restart the agent |
|
|
151
|
+
|
|
152
|
+
## What else it does
|
|
153
|
+
|
|
154
|
+
- **Memory.** Each agent keeps notes in `agents/<name>/memory/MEMORY.md` and reads them at the start of each conversation. Every day at 03:00, the agent reviews its notes. It merges duplicates and removes facts that are out of date.
|
|
155
|
+
- **Schedules.** Ask "remind me every weekday at 9 to check my email" and the agent creates a cron trigger. It can set one-off reminders too. A webhook trigger starts a run when it receives an HTTP request. You create webhook triggers in the dashboard.
|
|
156
|
+
- **Skills.** Put a folder with a `SKILL.md` in `~/.wheatley/skills/` to share it with all agents, or in `agents/<name>/skills/` for one agent.
|
|
157
|
+
- **Plugins.** Add your own tools and chat integrations in TypeScript. See [`@wheatley-ai/sdk`](https://www.npmjs.com/package/@wheatley-ai/sdk).
|
|
158
|
+
|
|
159
|
+
## Docker
|
|
160
|
+
|
|
161
|
+
If you would rather not install Node.js, use the image on the GitHub Container Registry:
|
|
162
|
+
|
|
163
|
+
```sh
|
|
164
|
+
docker volume create wheatley-data
|
|
165
|
+
docker run --rm -v wheatley-data:/data ghcr.io/sphericalkat/wheatley:latest wheatley init
|
|
166
|
+
docker run --rm -v wheatley-data:/data ghcr.io/sphericalkat/wheatley:latest \
|
|
167
|
+
sh -c 'printf "daemon:\n host: 0.0.0.0\n port: 7420\n" >> /data/config.yaml'
|
|
168
|
+
docker run --rm -v wheatley-data:/data ghcr.io/sphericalkat/wheatley:latest \
|
|
169
|
+
sh -c 'echo "ANTHROPIC_API_KEY: sk-ant-..." >> /data/secrets.yaml'
|
|
170
|
+
|
|
171
|
+
docker run -d --name wheatley --init --restart unless-stopped --stop-timeout 45 \
|
|
172
|
+
-p 127.0.0.1:7420:7420 -v wheatley-data:/data ghcr.io/sphericalkat/wheatley:latest
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Each release gets four image tags. For release `0.1.0`, these are `0.1.0`, `0.1`, `0`, and `latest`.
|
|
176
|
+
|
|
177
|
+
## Updating
|
|
178
|
+
|
|
179
|
+
```sh
|
|
180
|
+
wheatley update --check
|
|
181
|
+
wheatley update
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
`wheatley update` stays inside your current major version. To move to a new major version, run `npm install -g @wheatley-ai/cli@latest`. Then restart the daemon, for example with `wheatley service restart`.
|
|
185
|
+
|
|
186
|
+
## Security
|
|
187
|
+
|
|
188
|
+
The daemon has no login. Anyone who can reach port 7420 can use your agents, so keep it on `127.0.0.1`, which is the default. It also rejects browser requests from other origins. If you need remote access, use an SSH tunnel or a private network such as Tailscale.
|
|
189
|
+
|
|
190
|
+
## License
|
|
191
|
+
|
|
192
|
+
ISC
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { CLI_CHAT_ID } from "../core/agent/agent.js";
|
|
2
|
+
import { CLI_BINDING_ID } from "../core/config/validate.js";
|
|
3
|
+
/** True for a `run.started` or `run.finished` event of a Run in the CLI Chat. */
|
|
4
|
+
export const isCliChatRun = (event) => (event.name === "run.started" || event.name === "run.finished") &&
|
|
5
|
+
event.payload.run.origin.kind === "chat" &&
|
|
6
|
+
event.payload.run.origin.bindingId === CLI_BINDING_ID &&
|
|
7
|
+
event.payload.run.origin.chatId === CLI_CHAT_ID;
|
|
8
|
+
/**
|
|
9
|
+
* Tracks the Runs of the CLI Chat and its open Approvals while the chat runs. A sent message counts as busy until the
|
|
10
|
+
* Agent's echo of it names its Run. The echo and the Run events can arrive before or after the `chat.send` response
|
|
11
|
+
* is handled, so every step works in any order.
|
|
12
|
+
*/
|
|
13
|
+
export class ChatState {
|
|
14
|
+
approvals = [];
|
|
15
|
+
#waiting = new Set();
|
|
16
|
+
#echoed = new Set();
|
|
17
|
+
#active = new Set();
|
|
18
|
+
#finished = new Set();
|
|
19
|
+
#idle = Promise.withResolvers();
|
|
20
|
+
constructor() {
|
|
21
|
+
this.#idle.resolve(undefined);
|
|
22
|
+
}
|
|
23
|
+
removeApproval = (approvalId) => {
|
|
24
|
+
const index = this.approvals.findIndex((approval) => approval.approvalId === approvalId);
|
|
25
|
+
if (index !== -1) {
|
|
26
|
+
this.approvals.splice(index, 1);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/** This chat sent a message. */
|
|
30
|
+
sent = (messageId) => {
|
|
31
|
+
if (this.#echoed.delete(messageId)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
this.#busy();
|
|
35
|
+
this.#waiting.add(messageId);
|
|
36
|
+
};
|
|
37
|
+
/** The Agent stored a user message of this Chat for a Run. */
|
|
38
|
+
echoed = (messageId, runId) => {
|
|
39
|
+
if (!this.#waiting.delete(messageId)) {
|
|
40
|
+
this.#echoed.add(messageId);
|
|
41
|
+
}
|
|
42
|
+
if (runId !== undefined) {
|
|
43
|
+
this.started(runId);
|
|
44
|
+
}
|
|
45
|
+
this.#settle();
|
|
46
|
+
};
|
|
47
|
+
started = (runId) => {
|
|
48
|
+
if (this.#finished.has(runId)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
this.#busy();
|
|
52
|
+
this.#active.add(runId);
|
|
53
|
+
};
|
|
54
|
+
finished = (runId) => {
|
|
55
|
+
this.#finished.add(runId);
|
|
56
|
+
this.#active.delete(runId);
|
|
57
|
+
this.#settle();
|
|
58
|
+
};
|
|
59
|
+
/** True while a message waits for its Run or a Run of the CLI Chat is active. */
|
|
60
|
+
get busy() {
|
|
61
|
+
return this.#active.size > 0 || this.#waiting.size > 0;
|
|
62
|
+
}
|
|
63
|
+
/** Resolves when no message waits for its Run and no Run of the CLI Chat is active. */
|
|
64
|
+
get idle() {
|
|
65
|
+
return this.#idle.promise;
|
|
66
|
+
}
|
|
67
|
+
#busy = () => {
|
|
68
|
+
if (this.#active.size === 0 && this.#waiting.size === 0) {
|
|
69
|
+
this.#idle = Promise.withResolvers();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
#settle = () => {
|
|
73
|
+
if (this.#active.size === 0 && this.#waiting.size === 0) {
|
|
74
|
+
this.#idle.resolve(undefined);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/** Updates the chat state for one event. */
|
|
79
|
+
export const track = (state, event) => {
|
|
80
|
+
if (event.name === "chat.message" && event.payload.message.role === "user") {
|
|
81
|
+
state.echoed(event.payload.message.messageId, event.payload.message.runId);
|
|
82
|
+
}
|
|
83
|
+
else if (event.name === "approval.requested") {
|
|
84
|
+
state.approvals.push(event.payload.approval);
|
|
85
|
+
}
|
|
86
|
+
else if (event.name === "approval.resolved") {
|
|
87
|
+
state.removeApproval(event.payload.approvalId);
|
|
88
|
+
}
|
|
89
|
+
else if (isCliChatRun(event) && event.name === "run.started") {
|
|
90
|
+
state.started(event.payload.run.runId);
|
|
91
|
+
}
|
|
92
|
+
else if (isCliChatRun(event) && event.name === "run.finished") {
|
|
93
|
+
state.finished(event.payload.run.runId);
|
|
94
|
+
}
|
|
95
|
+
};
|
package/dist/cli/chat.js
CHANGED
|
@@ -1,86 +1,19 @@
|
|
|
1
1
|
import { BUILTIN_COMMANDS, parseCommandText } from "@wheatley-ai/sdk";
|
|
2
|
-
import { CLI_CHAT_ID } from "../core/agent/agent.js";
|
|
3
|
-
import { CLI_BINDING_ID } from "../core/config/validate.js";
|
|
4
2
|
import { errorMessage } from "../core/error-message.js";
|
|
5
|
-
import {
|
|
3
|
+
import { ChatState, isCliChatRun, track } from "./chat-state.js";
|
|
6
4
|
import { approvalQuestion, chooseAgent, connect, decideApproval, } from "./session.js";
|
|
5
|
+
import { runInteractiveChat } from "./tui/run.js";
|
|
7
6
|
/** Lines that end the chat. */
|
|
8
7
|
const EXIT_LINES = new Set(["/exit", "/quit"]);
|
|
9
|
-
const
|
|
10
|
-
event.
|
|
11
|
-
event.payload.run.
|
|
12
|
-
event.payload.run.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class ChatState {
|
|
19
|
-
approvals = [];
|
|
20
|
-
#waiting = new Set();
|
|
21
|
-
#echoed = new Set();
|
|
22
|
-
#active = new Set();
|
|
23
|
-
#finished = new Set();
|
|
24
|
-
#idle = Promise.withResolvers();
|
|
25
|
-
constructor() {
|
|
26
|
-
this.#idle.resolve(undefined);
|
|
27
|
-
}
|
|
28
|
-
removeApproval = (approvalId) => {
|
|
29
|
-
const index = this.approvals.findIndex((approval) => approval.approvalId === approvalId);
|
|
30
|
-
if (index !== -1) {
|
|
31
|
-
this.approvals.splice(index, 1);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
/** This chat sent a message. */
|
|
35
|
-
sent = (messageId) => {
|
|
36
|
-
if (this.#echoed.delete(messageId)) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
this.#busy();
|
|
40
|
-
this.#waiting.add(messageId);
|
|
41
|
-
};
|
|
42
|
-
/** The Agent stored a user message of this Chat for a Run. */
|
|
43
|
-
echoed = (messageId, runId) => {
|
|
44
|
-
if (!this.#waiting.delete(messageId)) {
|
|
45
|
-
this.#echoed.add(messageId);
|
|
46
|
-
}
|
|
47
|
-
if (runId !== undefined) {
|
|
48
|
-
this.started(runId);
|
|
49
|
-
}
|
|
50
|
-
this.#settle();
|
|
51
|
-
};
|
|
52
|
-
started = (runId) => {
|
|
53
|
-
if (this.#finished.has(runId)) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
this.#busy();
|
|
57
|
-
this.#active.add(runId);
|
|
58
|
-
};
|
|
59
|
-
finished = (runId) => {
|
|
60
|
-
this.#finished.add(runId);
|
|
61
|
-
this.#active.delete(runId);
|
|
62
|
-
this.#settle();
|
|
63
|
-
};
|
|
64
|
-
/** Resolves when no message waits for its Run and no Run of the CLI Chat is active. */
|
|
65
|
-
get idle() {
|
|
66
|
-
return this.#idle.promise;
|
|
67
|
-
}
|
|
68
|
-
#busy = () => {
|
|
69
|
-
if (this.#active.size === 0 && this.#waiting.size === 0) {
|
|
70
|
-
this.#idle = Promise.withResolvers();
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
#settle = () => {
|
|
74
|
-
if (this.#active.size === 0 && this.#waiting.size === 0) {
|
|
75
|
-
this.#idle.resolve(undefined);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
const render = (io, agent, state, event) => {
|
|
80
|
-
if (event.name === "chat.message" && event.payload.message.role === "user") {
|
|
81
|
-
state.echoed(event.payload.message.messageId, event.payload.message.runId);
|
|
82
|
-
}
|
|
83
|
-
else if (event.name === "chat.message") {
|
|
8
|
+
const failedRunError = (event) => isCliChatRun(event) &&
|
|
9
|
+
event.name === "run.finished" &&
|
|
10
|
+
event.payload.run.status === "failed"
|
|
11
|
+
? (event.payload.run.error ?? "unknown error")
|
|
12
|
+
: undefined;
|
|
13
|
+
/** Writes one event as plain lines, for pipes and scripts. */
|
|
14
|
+
const renderPlain = (io, agent, event) => {
|
|
15
|
+
const runError = failedRunError(event);
|
|
16
|
+
if (event.name === "chat.message" && event.payload.message.role !== "user") {
|
|
84
17
|
io.stdout(`${agent}> ${event.payload.message.text}\n`);
|
|
85
18
|
}
|
|
86
19
|
else if (event.name === "run.toolStarted") {
|
|
@@ -90,20 +23,10 @@ const render = (io, agent, state, event) => {
|
|
|
90
23
|
io.stdout(` [${event.payload.toolName} failed] ${event.payload.outputPreview}\n`);
|
|
91
24
|
}
|
|
92
25
|
else if (event.name === "approval.requested") {
|
|
93
|
-
state.approvals.push(event.payload.approval);
|
|
94
26
|
io.stdout(approvalQuestion(event.payload.approval));
|
|
95
27
|
}
|
|
96
|
-
else if (
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
else if (isCliChatRun(event) && event.name === "run.started") {
|
|
100
|
-
state.started(event.payload.run.runId);
|
|
101
|
-
}
|
|
102
|
-
else if (isCliChatRun(event) && event.name === "run.finished") {
|
|
103
|
-
if (event.payload.run.status === "failed") {
|
|
104
|
-
io.stderr(`The Run failed: ${event.payload.run.error ?? "unknown error"}\n`);
|
|
105
|
-
}
|
|
106
|
-
state.finished(event.payload.run.runId);
|
|
28
|
+
else if (runError !== undefined) {
|
|
29
|
+
io.stderr(`The Run failed: ${runError}\n`);
|
|
107
30
|
}
|
|
108
31
|
};
|
|
109
32
|
const handleLine = async (io, client, agent, state, line) => {
|
|
@@ -136,6 +59,8 @@ const handleLine = async (io, client, agent, state, line) => {
|
|
|
136
59
|
* shares (ADR 0007). Lines that start with a built-in command run it; `/exit` or the end of input ends the session
|
|
137
60
|
* after the active Runs end. While an Approval waits, the next line answers it.
|
|
138
61
|
*
|
|
62
|
+
* On a terminal, the chat runs the interactive terminal app in `tui/`. Pipes and scripts get plain lines.
|
|
63
|
+
*
|
|
139
64
|
* Resolves with the exit code.
|
|
140
65
|
*/
|
|
141
66
|
export const runChat = async (io, flags, version) => {
|
|
@@ -145,9 +70,20 @@ export const runChat = async (io, flags, version) => {
|
|
|
145
70
|
}
|
|
146
71
|
try {
|
|
147
72
|
const agent = await chooseAgent(client, flags.agent);
|
|
73
|
+
const terminal = io.terminal?.();
|
|
74
|
+
if (terminal !== undefined) {
|
|
75
|
+
return await runInteractiveChat({
|
|
76
|
+
agent,
|
|
77
|
+
client,
|
|
78
|
+
home: flags.home,
|
|
79
|
+
streams: terminal,
|
|
80
|
+
version,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
148
83
|
const state = new ChatState();
|
|
149
84
|
client.onEvent((event) => {
|
|
150
|
-
|
|
85
|
+
track(state, event);
|
|
86
|
+
renderPlain(io, agent, event);
|
|
151
87
|
});
|
|
152
88
|
await client.request("events.subscribe", {
|
|
153
89
|
agents: [agent],
|
|
@@ -156,13 +92,14 @@ export const runChat = async (io, flags, version) => {
|
|
|
156
92
|
io.stdout(`Chat with ${agent}. Commands: ${BUILTIN_COMMANDS.map((command) => `/${command.name}`).join(" ")} /exit\n`);
|
|
157
93
|
for (;;) {
|
|
158
94
|
// oxlint-disable-next-line no-await-in-loop -- The chat reads one line at a time.
|
|
159
|
-
const
|
|
160
|
-
|
|
95
|
+
const result = await io.lines.next();
|
|
96
|
+
const line = result.done === true ? undefined : result.value.trim();
|
|
97
|
+
if (line === undefined || EXIT_LINES.has(line)) {
|
|
161
98
|
break;
|
|
162
99
|
}
|
|
163
|
-
if (line
|
|
100
|
+
if (line !== "") {
|
|
164
101
|
// oxlint-disable-next-line no-await-in-loop -- Each line is handled before the next one is read.
|
|
165
|
-
await handleLine(io, client, agent, state, line
|
|
102
|
+
await handleLine(io, client, agent, state, line);
|
|
166
103
|
}
|
|
167
104
|
}
|
|
168
105
|
await state.idle;
|
package/dist/cli/io.js
CHANGED
|
@@ -11,11 +11,21 @@ export const processIo = () => {
|
|
|
11
11
|
};
|
|
12
12
|
process.once("SIGINT", stop);
|
|
13
13
|
process.once("SIGTERM", stop);
|
|
14
|
-
|
|
14
|
+
// Created on the first read, so that `terminal` can take standard input instead.
|
|
15
|
+
let lines;
|
|
16
|
+
let terminalOpen = false;
|
|
15
17
|
return {
|
|
16
18
|
env: process.env,
|
|
17
19
|
isTTY: isatty(process.stdin.fd),
|
|
18
|
-
lines:
|
|
20
|
+
lines: {
|
|
21
|
+
next: async () => {
|
|
22
|
+
lines ??= createInterface({
|
|
23
|
+
input: process.stdin,
|
|
24
|
+
terminal: false,
|
|
25
|
+
})[Symbol.asyncIterator]();
|
|
26
|
+
return await lines.next();
|
|
27
|
+
},
|
|
28
|
+
},
|
|
19
29
|
shutdown: shutdown.signal,
|
|
20
30
|
stderr: (text) => {
|
|
21
31
|
process.stderr.write(text);
|
|
@@ -23,6 +33,16 @@ export const processIo = () => {
|
|
|
23
33
|
stdout: (text) => {
|
|
24
34
|
process.stdout.write(text);
|
|
25
35
|
},
|
|
36
|
+
terminal: () => {
|
|
37
|
+
const usable = lines === undefined &&
|
|
38
|
+
!terminalOpen &&
|
|
39
|
+
isatty(process.stdin.fd) &&
|
|
40
|
+
isatty(process.stdout.fd);
|
|
41
|
+
terminalOpen ||= usable;
|
|
42
|
+
return usable
|
|
43
|
+
? { input: process.stdin, output: process.stdout }
|
|
44
|
+
: undefined;
|
|
45
|
+
},
|
|
26
46
|
};
|
|
27
47
|
};
|
|
28
48
|
/** Reads the next line, or resolves `undefined` at the end of input. */
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { styleText } from "node:util";
|
|
2
|
+
/**
|
|
3
|
+
* What the spinner says while the Agent thinks. These lines are original. They imitate the voice of an eager,
|
|
4
|
+
* slightly overconfident robot, not any script.
|
|
5
|
+
*/
|
|
6
|
+
export const THINKING_LINES = [
|
|
7
|
+
"Right. Right, right, right. Thinking.",
|
|
8
|
+
"Having a proper think. With the whole brain.",
|
|
9
|
+
"Bit of a tricky one, this. Love a tricky one.",
|
|
10
|
+
"It's in here somewhere. Rummaging.",
|
|
11
|
+
"Nearly there. Probably. Define 'nearly'.",
|
|
12
|
+
"Not stalling. This is thinking. Looks similar.",
|
|
13
|
+
"Plugging in a few ideas. Unplugging the bad ones.",
|
|
14
|
+
"Got a plan. Most of a plan. The start of a plan.",
|
|
15
|
+
"Crunching the numbers. Some of them are words.",
|
|
16
|
+
"Doing the clever bit now. Don't look.",
|
|
17
|
+
"Rerouting a few thoughts. Mind the sparks.",
|
|
18
|
+
"Completely under control. Largely under control.",
|
|
19
|
+
"Brilliant idea incoming. Brace yourself.",
|
|
20
|
+
"Checking my work. Twice. Once more for luck.",
|
|
21
|
+
"Ooh. Interesting. Give me a second.",
|
|
22
|
+
"Very nearly a genius move. Stand by.",
|
|
23
|
+
"Thinking quietly. Well, quietly for me.",
|
|
24
|
+
"Just tightening a few bolts on this answer.",
|
|
25
|
+
];
|
|
26
|
+
/** The spinner lines for one Run: every thinking line once, in a random order. */
|
|
27
|
+
export const shuffledThinkingLines = () => {
|
|
28
|
+
const lines = [...THINKING_LINES];
|
|
29
|
+
for (let index = lines.length - 1; index > 0; index -= 1) {
|
|
30
|
+
const other = Math.floor(Math.random() * (index + 1));
|
|
31
|
+
const current = lines[index];
|
|
32
|
+
const swapped = lines[other];
|
|
33
|
+
if (current !== undefined && swapped !== undefined) {
|
|
34
|
+
lines[index] = swapped;
|
|
35
|
+
lines[other] = current;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return lines;
|
|
39
|
+
};
|
|
40
|
+
/** "WHEATLEY" in block letters. Every row has the same width. */
|
|
41
|
+
const BANNER_ROWS = [
|
|
42
|
+
"█ █ █ █ █████ ███ █████ █ █████ █ █",
|
|
43
|
+
"█ █ █ █ █ █ █ █ █ █ █ █ ",
|
|
44
|
+
"█ █ █ █████ ████ █████ █ █ ████ █ ",
|
|
45
|
+
"██ ██ █ █ █ █ █ █ █ █ █ ",
|
|
46
|
+
"█ █ █ █ █████ █ █ █ █████ █████ █ ",
|
|
47
|
+
];
|
|
48
|
+
const BANNER_COLORS = [
|
|
49
|
+
"cyanBright",
|
|
50
|
+
"cyanBright",
|
|
51
|
+
"cyan",
|
|
52
|
+
"cyan",
|
|
53
|
+
"blue",
|
|
54
|
+
];
|
|
55
|
+
const BANNER_WIDTH = BANNER_ROWS[0].length;
|
|
56
|
+
/** The space that the banner keeps on each side. */
|
|
57
|
+
const BANNER_MARGIN = 4;
|
|
58
|
+
/** "WHEATLEY" in colored block letters, or one line on a terminal too narrow for them. */
|
|
59
|
+
export const bannerArt = (columns) => columns < BANNER_WIDTH + BANNER_MARGIN
|
|
60
|
+
? styleText(["cyan", "bold"], "◉ wheatley")
|
|
61
|
+
: BANNER_ROWS.map((row, index) => styleText(BANNER_COLORS[index] ?? "cyan", row)).join("\n");
|
|
62
|
+
/** Tips for the welcome screen. */
|
|
63
|
+
export const TIPS = [
|
|
64
|
+
"Type / to open the command menu, then Tab to complete.",
|
|
65
|
+
"Start a line with ! to run a shell command here, for example !git status.",
|
|
66
|
+
"End a line with \\ and press Enter to add a new line. Pasted text keeps its lines.",
|
|
67
|
+
"Press Esc to interrupt a Run. You can type the next message while it works.",
|
|
68
|
+
"/copy puts the last reply on your clipboard, even over SSH.",
|
|
69
|
+
"Ctrl+W deletes a word, Ctrl+U the line before the cursor, and Ctrl+K the rest.",
|
|
70
|
+
"The dashboard shows this same Chat at http://127.0.0.1:7420/.",
|
|
71
|
+
"Up and Down recall what you typed earlier, across sessions.",
|
|
72
|
+
];
|
|
73
|
+
/** Lines for the end of a chat. Original, in the same eager voice as the thinking lines. */
|
|
74
|
+
export const GOODBYES = [
|
|
75
|
+
"Right. Off you go, then. I'll just be here. Thinking.",
|
|
76
|
+
"Lovely chat. Really top quality. Same time tomorrow?",
|
|
77
|
+
"Bye! Don't touch anything on the way out.",
|
|
78
|
+
"Going quiet now. Very quiet. Starting… now.",
|
|
79
|
+
];
|
|
80
|
+
/** A random element of `items`. */
|
|
81
|
+
export const pick = (items) => items[Math.floor(Math.random() * items.length)];
|