@hncode/hncode 0.8.6 → 1.0.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 +30 -0
- package/README_CN.md +27 -0
- package/package.json +1 -1
- package/src/agent.js +172 -43
- package/src/bootstrap.js +63 -56
- package/src/ci.js +247 -247
- package/src/colors.js +5 -1
- package/src/commands.js +121 -0
- package/src/composer.js +31 -1
- package/src/config.js +177 -45
- package/src/context.js +29 -0
- package/src/files.js +32 -0
- package/src/fx.js +19 -2
- package/src/i18n.js +180 -131
- package/src/index.js +558 -77
- package/src/permission-gate.js +103 -0
- package/src/plugin.js +221 -2
- package/src/prompt-presets.js +36 -0
- package/src/protocol.js +184 -0
- package/src/registry-browser.js +14 -3
- package/src/remote.js +117 -5
- package/src/schedule.js +148 -11
- package/src/serve.js +613 -0
- package/src/session-client.js +148 -0
- package/src/session-host.js +52 -0
- package/src/session.js +26 -3
- package/src/settings-schema.js +2 -2
- package/src/status-line.js +48 -0
- package/src/toml.js +18 -4
- package/src/tool-status.js +45 -0
- package/src/tools/bash.js +43 -24
- package/src/tools/edit.js +10 -5
- package/src/tools/web-search.js +8 -5
- package/src/tools/write.js +28 -3
- package/src/tui.js +448 -1380
- package/src/ws.js +248 -0
- package/src/session-hub.js +0 -445
- package/src/web-auth.js +0 -98
- package/src/web-daemon-cli.js +0 -63
- package/src/web-daemon-client.js +0 -203
- package/src/web-daemon.js +0 -894
- package/src/web-live.js +0 -250
- package/src/web-public/app.css +0 -1524
- package/src/web-public/app.js +0 -2969
- package/src/web-public/complete.js +0 -154
- package/src/web-public/fonts/JetBrainsMono-Bold.woff2 +0 -0
- package/src/web-public/fonts/JetBrainsMono-Regular.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-100-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-101-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-102-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-103-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-104-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-105-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-106-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-107-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-108-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-109-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-110-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-111-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-112-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-113-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-114-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-115-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-116-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-117-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-118-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-119-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-21-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-22-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-23-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-24-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-25-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-26-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-27-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-28-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-29-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-30-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-31-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-32-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-33-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-34-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-35-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-36-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-37-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-38-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-39-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-4-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-40-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-41-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-42-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-43-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-44-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-45-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-46-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-47-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-48-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-49-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-5-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-50-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-51-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-52-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-53-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-54-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-55-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-56-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-57-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-58-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-59-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-6-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-60-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-61-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-62-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-63-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-64-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-65-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-66-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-67-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-68-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-69-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-70-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-71-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-72-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-73-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-74-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-75-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-76-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-77-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-78-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-79-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-80-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-81-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-82-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-83-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-84-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-85-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-86-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-87-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-88-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-89-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-90-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-91-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-97-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-98-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc-99-400-normal.woff2 +0 -0
- package/src/web-public/fonts/noto-sans-sc.css +0 -775
- package/src/web-public/fonts.css +0 -31
- package/src/web-public/home.css +0 -222
- package/src/web-public/home.html +0 -33
- package/src/web-public/home.js +0 -160
- package/src/web-public/i18n.js +0 -983
- package/src/web-public/index.html +0 -196
- package/src/web-public/login.css +0 -123
- package/src/web-public/login.html +0 -25
- package/src/web-public/login.js +0 -46
- package/src/web-public/settings.js +0 -290
- package/src/web-ws.js +0 -226
- package/src/web.js +0 -430
package/src/ci.js
CHANGED
|
@@ -1,247 +1,247 @@
|
|
|
1
|
-
// CI / scripting integration — turning a headless run into something a pipeline
|
|
2
|
-
// can act on.
|
|
3
|
-
//
|
|
4
|
-
// `hncode -p "…"` already prints the reply. What a CI job additionally needs is:
|
|
5
|
-
// * a machine-readable final result (did it succeed? what changed?),
|
|
6
|
-
// * an exit code that reflects the OUTCOME, not just "the process started",
|
|
7
|
-
// * a stable JSON envelope it can parse without scraping prose.
|
|
8
|
-
//
|
|
9
|
-
// The formats (chosen to match what CI systems and Claude-Code-style tools
|
|
10
|
-
// already understand):
|
|
11
|
-
// text — the assistant's reply, as before (default)
|
|
12
|
-
// json — ONE object at the end: { ok, reply, toolCalls, files, error }
|
|
13
|
-
// stream-json — one JSON event per line as the run progresses (existing), now
|
|
14
|
-
// terminated by a final `result` event so a reader can stop.
|
|
15
|
-
//
|
|
16
|
-
// Exit codes (see EXIT):
|
|
17
|
-
// 0 the run completed and produced an answer
|
|
18
|
-
// 1 generic failure (LLM error, bad config)
|
|
19
|
-
// 2 configuration problem (no API key)
|
|
20
|
-
// 3 the model stopped without an answer / reported a blocker
|
|
21
|
-
// 4 interrupted
|
|
22
|
-
//
|
|
23
|
-
// Nothing here writes to stdout directly except through the helpers, so the
|
|
24
|
-
// caller stays in control of framing.
|
|
25
|
-
|
|
26
|
-
import net from 'node:net';
|
|
27
|
-
import fs from 'node:fs';
|
|
28
|
-
import os from 'node:os';
|
|
29
|
-
import path from 'node:path';
|
|
30
|
-
|
|
31
|
-
export const EXIT = {
|
|
32
|
-
OK: 0,
|
|
33
|
-
FAILURE: 1,
|
|
34
|
-
CONFIG: 2,
|
|
35
|
-
NO_ANSWER: 3,
|
|
36
|
-
INTERRUPTED: 4,
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const FORMATS = ['text', 'json', 'stream-json'];
|
|
40
|
-
|
|
41
|
-
export function isValidFormat(f) {
|
|
42
|
-
return f == null || FORMATS.includes(f);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Build the structured result for a finished run.
|
|
46
|
-
// ok — completed with a usable answer
|
|
47
|
-
// reply — the assistant's final text
|
|
48
|
-
// toolCalls — names of tools invoked, in order
|
|
49
|
-
// files — files the run wrote/edited (from tool ARGS, best-effort)
|
|
50
|
-
// error — a fatal error message, when the run failed outright
|
|
51
|
-
// stopped — the turn was interrupted
|
|
52
|
-
export function buildResult({ reply, toolCalls, files, error, stopped, durationMs, model, sessionId, timedOut }) {
|
|
53
|
-
const hasReply = typeof reply === 'string' && reply.trim().length > 0;
|
|
54
|
-
const ok = !error && !stopped && hasReply;
|
|
55
|
-
const result = {
|
|
56
|
-
ok,
|
|
57
|
-
reply: reply || '',
|
|
58
|
-
toolCalls: toolCalls || [],
|
|
59
|
-
files: files || [],
|
|
60
|
-
durationMs: durationMs || 0,
|
|
61
|
-
model: model || '',
|
|
62
|
-
sessionId: sessionId || '',
|
|
63
|
-
};
|
|
64
|
-
if (error) result.error = String(error);
|
|
65
|
-
if (stopped) result.stopped = true;
|
|
66
|
-
// `--timeout <seconds>` tripped: distinct from a user interrupt so a caller can
|
|
67
|
-
// tell "the model was too slow" from "someone pressed Esc" (both set stopped).
|
|
68
|
-
if (timedOut) result.timedOut = true;
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Map a result to a process exit code.
|
|
73
|
-
export function exitCodeFor(result, hadConfigError) {
|
|
74
|
-
if (hadConfigError) return EXIT.CONFIG;
|
|
75
|
-
if (!result) return EXIT.FAILURE;
|
|
76
|
-
if (result.stopped) return EXIT.INTERRUPTED;
|
|
77
|
-
if (result.error) return EXIT.FAILURE;
|
|
78
|
-
if (!result.ok) return EXIT.NO_ANSWER;
|
|
79
|
-
return EXIT.OK;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// The JSON envelope printed at the end in `json` mode. Single line so a shell
|
|
83
|
-
// can capture it with `tail -1` or `jq`.
|
|
84
|
-
export function resultLine(result) {
|
|
85
|
-
return JSON.stringify({ type: 'result', ...result });
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Collect tool activity from an agent event stream. `onEvent` is called per
|
|
89
|
-
// event; this returns the mutable accumulators the caller reads at the end.
|
|
90
|
-
export function createRunTracker() {
|
|
91
|
-
return { toolCalls: [], files: [], errors: [], text: '' };
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Files a tool call will write, taken from its arguments. Only the mutating
|
|
95
|
-
// tools are considered: a Read of a file is not "changed by this run".
|
|
96
|
-
const WRITE_TOOLS = new Set(['Write', 'Edit']);
|
|
97
|
-
|
|
98
|
-
export function trackEvent(tracker, e) {
|
|
99
|
-
if (!tracker || !e) return tracker;
|
|
100
|
-
if (e.type === 'data' && e.text) tracker.text += e.text;
|
|
101
|
-
if (e.type === 'tool_use' && e.name) {
|
|
102
|
-
tracker.toolCalls.push(e.name);
|
|
103
|
-
if (WRITE_TOOLS.has(e.name) && e.args && typeof e.args.path === 'string') {
|
|
104
|
-
if (!tracker.files.includes(e.args.path)) tracker.files.push(e.args.path);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (e.type === 'error') tracker.errors.push((e.error && e.error.message) || String(e.error));
|
|
108
|
-
return tracker;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// The final assistant text for the run. Prefers the LAST assistant message that
|
|
112
|
-
// has text (the handoff), falling back to the streamed aggregate. Mirrors the
|
|
113
|
-
// rule subagents use, so both report the same thing.
|
|
114
|
-
export function finalReply(messages, streamedText) {
|
|
115
|
-
const msgs = Array.isArray(messages) ? messages : [];
|
|
116
|
-
for (let i = msgs.length - 1; i >= 0; i--) {
|
|
117
|
-
const m = msgs[i];
|
|
118
|
-
if (m && m.role === 'assistant' && typeof m.content === 'string' && m.content.trim()) {
|
|
119
|
-
return m.content.trim();
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return String(streamedText || '').trim();
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// --- remote control ----------------------------------------------------------
|
|
126
|
-
// A running hncode TUI can expose a small control surface (a unix socket /
|
|
127
|
-
// named pipe) so another process can queue a prompt or query status. This is
|
|
128
|
-
// what "remote control" means here: not a network server by default, a local
|
|
129
|
-
// endpoint the user opts into.
|
|
130
|
-
//
|
|
131
|
-
// The protocol is newline-delimited JSON, one request per line, one response
|
|
132
|
-
// per line: {"op":"prompt","text":"…"} -> {"ok":true}
|
|
133
|
-
// {"op":"status"} -> {"ok":true,"busy":false,"session":"…"}
|
|
134
|
-
|
|
135
|
-
export function defaultControlPath() {
|
|
136
|
-
if (process.env.HNCODE_CONTROL_SOCKET) return process.env.HNCODE_CONTROL_SOCKET;
|
|
137
|
-
if (process.platform === 'win32') {
|
|
138
|
-
// Windows has no unix sockets at a filesystem path: Node exposes named pipes
|
|
139
|
-
// under \\.\pipe\. Using a normal temp path there fails with EACCES, which is
|
|
140
|
-
// exactly what happened before this branch existed.
|
|
141
|
-
return `\\\\.\\pipe\\hncode-control-${process.pid}`;
|
|
142
|
-
}
|
|
143
|
-
return path.join(os.homedir(), '.hncode', 'control.sock');
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Start a control server. `handlers` is { prompt(text), status(), interrupt() }.
|
|
147
|
-
// Returns { server, path, close() }. A stale socket file is replaced; a live one
|
|
148
|
-
// makes the call fail so two TUIs cannot fight over it.
|
|
149
|
-
export function startControlServer(handlers, opts = {}) {
|
|
150
|
-
const sockPath = opts.path || defaultControlPath();
|
|
151
|
-
const isPipe = process.platform === 'win32' && sockPath.startsWith('\\\\');
|
|
152
|
-
if (!isPipe) {
|
|
153
|
-
try { fs.mkdirSync(path.dirname(sockPath), { recursive: true }); } catch { /* exists */ }
|
|
154
|
-
// Remove a stale socket (a crash leaves one behind). Windows named pipes
|
|
155
|
-
// disappear with the process and cannot be stat()ed, hence the guard above.
|
|
156
|
-
try {
|
|
157
|
-
const st = fs.statSync(sockPath);
|
|
158
|
-
if (st.isSocket() || st.isFIFO()) fs.unlinkSync(sockPath);
|
|
159
|
-
} catch { /* nothing to clean */ }
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const server = net.createServer((conn) => {
|
|
163
|
-
let buf = '';
|
|
164
|
-
conn.on('data', (d) => {
|
|
165
|
-
buf += d.toString('utf8');
|
|
166
|
-
let i;
|
|
167
|
-
while ((i = buf.indexOf('\n')) >= 0) {
|
|
168
|
-
const line = buf.slice(0, i).trim();
|
|
169
|
-
buf = buf.slice(i + 1);
|
|
170
|
-
if (!line) continue;
|
|
171
|
-
handleControlLine(line, handlers).then((res) => {
|
|
172
|
-
try { conn.write(JSON.stringify(res) + '\n'); } catch { /* peer gone */ }
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
conn.on('error', () => { /* client hung up */ });
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
return new Promise((resolve) => {
|
|
180
|
-
server.on('error', (e) => resolve({ server: null, path: sockPath, error: e.message, close() {} }));
|
|
181
|
-
server.listen(sockPath, () => {
|
|
182
|
-
resolve({
|
|
183
|
-
server,
|
|
184
|
-
path: sockPath,
|
|
185
|
-
error: null,
|
|
186
|
-
close() {
|
|
187
|
-
try { server.close(); } catch { /* already closed */ }
|
|
188
|
-
if (!isPipe) { try { fs.unlinkSync(sockPath); } catch { /* already gone */ } }
|
|
189
|
-
},
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
async function handleControlLine(line, handlers) {
|
|
196
|
-
let req;
|
|
197
|
-
try { req = JSON.parse(line); } catch { return { ok: false, error: 'invalid JSON' }; }
|
|
198
|
-
try {
|
|
199
|
-
if (req.op === 'status') return { ok: true, ...(await handlers.status()) };
|
|
200
|
-
if (req.op === 'prompt') {
|
|
201
|
-
if (typeof req.text !== 'string' || !req.text.trim()) return { ok: false, error: 'text required' };
|
|
202
|
-
await handlers.prompt(req.text);
|
|
203
|
-
return { ok: true };
|
|
204
|
-
}
|
|
205
|
-
if (req.op === 'interrupt') {
|
|
206
|
-
await handlers.interrupt();
|
|
207
|
-
return { ok: true };
|
|
208
|
-
}
|
|
209
|
-
return { ok: false, error: `unknown op: ${req.op}` };
|
|
210
|
-
} catch (e) {
|
|
211
|
-
return { ok: false, error: e.message };
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// Client side: send one request to a running control server. Returns the parsed
|
|
216
|
-
// response or { ok:false, error }. Never throws.
|
|
217
|
-
export async function sendControl(req, opts = {}) {
|
|
218
|
-
const sockPath = opts.path || defaultControlPath();
|
|
219
|
-
const timeoutMs = opts.timeoutMs || 10_000;
|
|
220
|
-
return new Promise((resolve) => {
|
|
221
|
-
let done = false;
|
|
222
|
-
let sock = null;
|
|
223
|
-
const finish = (r) => {
|
|
224
|
-
if (done) return;
|
|
225
|
-
done = true;
|
|
226
|
-
try { if (sock) sock.destroy(); } catch { /* already gone */ }
|
|
227
|
-
resolve(r);
|
|
228
|
-
};
|
|
229
|
-
try { sock = net.connect(sockPath); }
|
|
230
|
-
catch (e) { resolve({ ok: false, error: e.message }); return; }
|
|
231
|
-
const timer = setTimeout(() => finish({ ok: false, error: 'timeout' }), timeoutMs);
|
|
232
|
-
sock.on('connect', () => {
|
|
233
|
-
try { sock.write(JSON.stringify(req) + '\n'); }
|
|
234
|
-
catch (e) { clearTimeout(timer); finish({ ok: false, error: e.message }); }
|
|
235
|
-
});
|
|
236
|
-
let buf = '';
|
|
237
|
-
sock.on('data', (d) => {
|
|
238
|
-
buf += d.toString('utf8');
|
|
239
|
-
const i = buf.indexOf('\n');
|
|
240
|
-
if (i >= 0) {
|
|
241
|
-
clearTimeout(timer);
|
|
242
|
-
try { finish(JSON.parse(buf.slice(0, i))); } catch { finish({ ok: false, error: 'bad response' }); }
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
sock.on('error', (e) => { clearTimeout(timer); finish({ ok: false, error: e.message }); });
|
|
246
|
-
});
|
|
247
|
-
}
|
|
1
|
+
// CI / scripting integration — turning a headless run into something a pipeline
|
|
2
|
+
// can act on.
|
|
3
|
+
//
|
|
4
|
+
// `hncode -p "…"` already prints the reply. What a CI job additionally needs is:
|
|
5
|
+
// * a machine-readable final result (did it succeed? what changed?),
|
|
6
|
+
// * an exit code that reflects the OUTCOME, not just "the process started",
|
|
7
|
+
// * a stable JSON envelope it can parse without scraping prose.
|
|
8
|
+
//
|
|
9
|
+
// The formats (chosen to match what CI systems and Claude-Code-style tools
|
|
10
|
+
// already understand):
|
|
11
|
+
// text — the assistant's reply, as before (default)
|
|
12
|
+
// json — ONE object at the end: { ok, reply, toolCalls, files, error }
|
|
13
|
+
// stream-json — one JSON event per line as the run progresses (existing), now
|
|
14
|
+
// terminated by a final `result` event so a reader can stop.
|
|
15
|
+
//
|
|
16
|
+
// Exit codes (see EXIT):
|
|
17
|
+
// 0 the run completed and produced an answer
|
|
18
|
+
// 1 generic failure (LLM error, bad config)
|
|
19
|
+
// 2 configuration problem (no API key)
|
|
20
|
+
// 3 the model stopped without an answer / reported a blocker
|
|
21
|
+
// 4 interrupted
|
|
22
|
+
//
|
|
23
|
+
// Nothing here writes to stdout directly except through the helpers, so the
|
|
24
|
+
// caller stays in control of framing.
|
|
25
|
+
|
|
26
|
+
import net from 'node:net';
|
|
27
|
+
import fs from 'node:fs';
|
|
28
|
+
import os from 'node:os';
|
|
29
|
+
import path from 'node:path';
|
|
30
|
+
|
|
31
|
+
export const EXIT = {
|
|
32
|
+
OK: 0,
|
|
33
|
+
FAILURE: 1,
|
|
34
|
+
CONFIG: 2,
|
|
35
|
+
NO_ANSWER: 3,
|
|
36
|
+
INTERRUPTED: 4,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const FORMATS = ['text', 'json', 'stream-json'];
|
|
40
|
+
|
|
41
|
+
export function isValidFormat(f) {
|
|
42
|
+
return f == null || FORMATS.includes(f);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Build the structured result for a finished run.
|
|
46
|
+
// ok — completed with a usable answer
|
|
47
|
+
// reply — the assistant's final text
|
|
48
|
+
// toolCalls — names of tools invoked, in order
|
|
49
|
+
// files — files the run wrote/edited (from tool ARGS, best-effort)
|
|
50
|
+
// error — a fatal error message, when the run failed outright
|
|
51
|
+
// stopped — the turn was interrupted
|
|
52
|
+
export function buildResult({ reply, toolCalls, files, error, stopped, durationMs, model, sessionId, timedOut }) {
|
|
53
|
+
const hasReply = typeof reply === 'string' && reply.trim().length > 0;
|
|
54
|
+
const ok = !error && !stopped && hasReply;
|
|
55
|
+
const result = {
|
|
56
|
+
ok,
|
|
57
|
+
reply: reply || '',
|
|
58
|
+
toolCalls: toolCalls || [],
|
|
59
|
+
files: files || [],
|
|
60
|
+
durationMs: durationMs || 0,
|
|
61
|
+
model: model || '',
|
|
62
|
+
sessionId: sessionId || '',
|
|
63
|
+
};
|
|
64
|
+
if (error) result.error = String(error);
|
|
65
|
+
if (stopped) result.stopped = true;
|
|
66
|
+
// `--timeout <seconds>` tripped: distinct from a user interrupt so a caller can
|
|
67
|
+
// tell "the model was too slow" from "someone pressed Esc" (both set stopped).
|
|
68
|
+
if (timedOut) result.timedOut = true;
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Map a result to a process exit code.
|
|
73
|
+
export function exitCodeFor(result, hadConfigError) {
|
|
74
|
+
if (hadConfigError) return EXIT.CONFIG;
|
|
75
|
+
if (!result) return EXIT.FAILURE;
|
|
76
|
+
if (result.stopped) return EXIT.INTERRUPTED;
|
|
77
|
+
if (result.error) return EXIT.FAILURE;
|
|
78
|
+
if (!result.ok) return EXIT.NO_ANSWER;
|
|
79
|
+
return EXIT.OK;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// The JSON envelope printed at the end in `json` mode. Single line so a shell
|
|
83
|
+
// can capture it with `tail -1` or `jq`.
|
|
84
|
+
export function resultLine(result) {
|
|
85
|
+
return JSON.stringify({ type: 'result', ...result });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Collect tool activity from an agent event stream. `onEvent` is called per
|
|
89
|
+
// event; this returns the mutable accumulators the caller reads at the end.
|
|
90
|
+
export function createRunTracker() {
|
|
91
|
+
return { toolCalls: [], files: [], errors: [], text: '' };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Files a tool call will write, taken from its arguments. Only the mutating
|
|
95
|
+
// tools are considered: a Read of a file is not "changed by this run".
|
|
96
|
+
const WRITE_TOOLS = new Set(['Write', 'Edit']);
|
|
97
|
+
|
|
98
|
+
export function trackEvent(tracker, e) {
|
|
99
|
+
if (!tracker || !e) return tracker;
|
|
100
|
+
if (e.type === 'data' && e.text) tracker.text += e.text;
|
|
101
|
+
if (e.type === 'tool_use' && e.name) {
|
|
102
|
+
tracker.toolCalls.push(e.name);
|
|
103
|
+
if (WRITE_TOOLS.has(e.name) && e.args && typeof e.args.path === 'string') {
|
|
104
|
+
if (!tracker.files.includes(e.args.path)) tracker.files.push(e.args.path);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (e.type === 'error') tracker.errors.push((e.error && e.error.message) || String(e.error));
|
|
108
|
+
return tracker;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// The final assistant text for the run. Prefers the LAST assistant message that
|
|
112
|
+
// has text (the handoff), falling back to the streamed aggregate. Mirrors the
|
|
113
|
+
// rule subagents use, so both report the same thing.
|
|
114
|
+
export function finalReply(messages, streamedText) {
|
|
115
|
+
const msgs = Array.isArray(messages) ? messages : [];
|
|
116
|
+
for (let i = msgs.length - 1; i >= 0; i--) {
|
|
117
|
+
const m = msgs[i];
|
|
118
|
+
if (m && m.role === 'assistant' && typeof m.content === 'string' && m.content.trim()) {
|
|
119
|
+
return m.content.trim();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return String(streamedText || '').trim();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// --- remote control ----------------------------------------------------------
|
|
126
|
+
// A running hncode TUI can expose a small control surface (a unix socket /
|
|
127
|
+
// named pipe) so another process can queue a prompt or query status. This is
|
|
128
|
+
// what "remote control" means here: not a network server by default, a local
|
|
129
|
+
// endpoint the user opts into.
|
|
130
|
+
//
|
|
131
|
+
// The protocol is newline-delimited JSON, one request per line, one response
|
|
132
|
+
// per line: {"op":"prompt","text":"…"} -> {"ok":true}
|
|
133
|
+
// {"op":"status"} -> {"ok":true,"busy":false,"session":"…"}
|
|
134
|
+
|
|
135
|
+
export function defaultControlPath() {
|
|
136
|
+
if (process.env.HNCODE_CONTROL_SOCKET) return process.env.HNCODE_CONTROL_SOCKET;
|
|
137
|
+
if (process.platform === 'win32') {
|
|
138
|
+
// Windows has no unix sockets at a filesystem path: Node exposes named pipes
|
|
139
|
+
// under \\.\pipe\. Using a normal temp path there fails with EACCES, which is
|
|
140
|
+
// exactly what happened before this branch existed.
|
|
141
|
+
return `\\\\.\\pipe\\hncode-control-${process.pid}`;
|
|
142
|
+
}
|
|
143
|
+
return path.join(os.homedir(), '.hncode', 'control.sock');
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Start a control server. `handlers` is { prompt(text), status(), interrupt() }.
|
|
147
|
+
// Returns { server, path, close() }. A stale socket file is replaced; a live one
|
|
148
|
+
// makes the call fail so two TUIs cannot fight over it.
|
|
149
|
+
export function startControlServer(handlers, opts = {}) {
|
|
150
|
+
const sockPath = opts.path || defaultControlPath();
|
|
151
|
+
const isPipe = process.platform === 'win32' && sockPath.startsWith('\\\\');
|
|
152
|
+
if (!isPipe) {
|
|
153
|
+
try { fs.mkdirSync(path.dirname(sockPath), { recursive: true }); } catch { /* exists */ }
|
|
154
|
+
// Remove a stale socket (a crash leaves one behind). Windows named pipes
|
|
155
|
+
// disappear with the process and cannot be stat()ed, hence the guard above.
|
|
156
|
+
try {
|
|
157
|
+
const st = fs.statSync(sockPath);
|
|
158
|
+
if (st.isSocket() || st.isFIFO()) fs.unlinkSync(sockPath);
|
|
159
|
+
} catch { /* nothing to clean */ }
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const server = net.createServer((conn) => {
|
|
163
|
+
let buf = '';
|
|
164
|
+
conn.on('data', (d) => {
|
|
165
|
+
buf += d.toString('utf8');
|
|
166
|
+
let i;
|
|
167
|
+
while ((i = buf.indexOf('\n')) >= 0) {
|
|
168
|
+
const line = buf.slice(0, i).trim();
|
|
169
|
+
buf = buf.slice(i + 1);
|
|
170
|
+
if (!line) continue;
|
|
171
|
+
handleControlLine(line, handlers).then((res) => {
|
|
172
|
+
try { conn.write(JSON.stringify(res) + '\n'); } catch { /* peer gone */ }
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
conn.on('error', () => { /* client hung up */ });
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
return new Promise((resolve) => {
|
|
180
|
+
server.on('error', (e) => resolve({ server: null, path: sockPath, error: e.message, close() {} }));
|
|
181
|
+
server.listen(sockPath, () => {
|
|
182
|
+
resolve({
|
|
183
|
+
server,
|
|
184
|
+
path: sockPath,
|
|
185
|
+
error: null,
|
|
186
|
+
close() {
|
|
187
|
+
try { server.close(); } catch { /* already closed */ }
|
|
188
|
+
if (!isPipe) { try { fs.unlinkSync(sockPath); } catch { /* already gone */ } }
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async function handleControlLine(line, handlers) {
|
|
196
|
+
let req;
|
|
197
|
+
try { req = JSON.parse(line); } catch { return { ok: false, error: 'invalid JSON' }; }
|
|
198
|
+
try {
|
|
199
|
+
if (req.op === 'status') return { ok: true, ...(await handlers.status()) };
|
|
200
|
+
if (req.op === 'prompt') {
|
|
201
|
+
if (typeof req.text !== 'string' || !req.text.trim()) return { ok: false, error: 'text required' };
|
|
202
|
+
await handlers.prompt(req.text);
|
|
203
|
+
return { ok: true };
|
|
204
|
+
}
|
|
205
|
+
if (req.op === 'interrupt') {
|
|
206
|
+
await handlers.interrupt();
|
|
207
|
+
return { ok: true };
|
|
208
|
+
}
|
|
209
|
+
return { ok: false, error: `unknown op: ${req.op}` };
|
|
210
|
+
} catch (e) {
|
|
211
|
+
return { ok: false, error: e.message };
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Client side: send one request to a running control server. Returns the parsed
|
|
216
|
+
// response or { ok:false, error }. Never throws.
|
|
217
|
+
export async function sendControl(req, opts = {}) {
|
|
218
|
+
const sockPath = opts.path || defaultControlPath();
|
|
219
|
+
const timeoutMs = opts.timeoutMs || 10_000;
|
|
220
|
+
return new Promise((resolve) => {
|
|
221
|
+
let done = false;
|
|
222
|
+
let sock = null;
|
|
223
|
+
const finish = (r) => {
|
|
224
|
+
if (done) return;
|
|
225
|
+
done = true;
|
|
226
|
+
try { if (sock) sock.destroy(); } catch { /* already gone */ }
|
|
227
|
+
resolve(r);
|
|
228
|
+
};
|
|
229
|
+
try { sock = net.connect(sockPath); }
|
|
230
|
+
catch (e) { resolve({ ok: false, error: e.message }); return; }
|
|
231
|
+
const timer = setTimeout(() => finish({ ok: false, error: 'timeout' }), timeoutMs);
|
|
232
|
+
sock.on('connect', () => {
|
|
233
|
+
try { sock.write(JSON.stringify(req) + '\n'); }
|
|
234
|
+
catch (e) { clearTimeout(timer); finish({ ok: false, error: e.message }); }
|
|
235
|
+
});
|
|
236
|
+
let buf = '';
|
|
237
|
+
sock.on('data', (d) => {
|
|
238
|
+
buf += d.toString('utf8');
|
|
239
|
+
const i = buf.indexOf('\n');
|
|
240
|
+
if (i >= 0) {
|
|
241
|
+
clearTimeout(timer);
|
|
242
|
+
try { finish(JSON.parse(buf.slice(0, i))); } catch { finish({ ok: false, error: 'bad response' }); }
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
sock.on('error', (e) => { clearTimeout(timer); finish({ ok: false, error: e.message }); });
|
|
246
|
+
});
|
|
247
|
+
}
|
package/src/colors.js
CHANGED
|
@@ -5,7 +5,11 @@ function colorDepth() {
|
|
|
5
5
|
try { return process.stdout.getColorDepth?.() || 0; } catch { return 0; }
|
|
6
6
|
}
|
|
7
7
|
const DEPTH = colorDepth();
|
|
8
|
-
|
|
8
|
+
// THE RENDERER IMPORTS THIS FILE TOO (format.js -> text.js -> here), and a browser has no
|
|
9
|
+
// `process`. One guard at the top of the module is cheaper than a second copy of the colour
|
|
10
|
+
// rules, which is exactly the drift this migration exists to remove.
|
|
11
|
+
const HAS_PROCESS = typeof process !== 'undefined' && !!process.env;
|
|
12
|
+
export const TRUECOLOR = DEPTH >= 24 || (HAS_PROCESS && (process.env.COLORTERM === 'truecolor' || /^xterm.*-256color$|.*-truecolor$/.test(process.env.TERM || '')));
|
|
9
13
|
|
|
10
14
|
function rgb(r, g, b) { return TRUECOLOR ? `\x1b[38;2;${r};${g};${b}m` : `\x1b[38;5;${ansi256(r, g, b)}m`; }
|
|
11
15
|
function brgb(r, g, b) { return TRUECOLOR ? `\x1b[48;2;${r};${g};${b}m` : `\x1b[48;5;${ansi256(r, g, b)}m`; }
|
package/src/commands.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// The slash-command table.
|
|
2
|
+
//
|
|
3
|
+
// It lives apart from tui.js because TWO front ends need it and only one of them has a
|
|
4
|
+
// terminal: a GUI shows the same list, and `hncode commands --json` prints it. Importing
|
|
5
|
+
// tui.js for the array pulled the whole renderer into both.
|
|
6
|
+
import { THEME_NAMES } from './colors.js';
|
|
7
|
+
|
|
8
|
+
export const TUI_ONLY_COMMANDS = new Set([
|
|
9
|
+
'vim', 'theme', 'keybindings', 'reduced-motion', 'shimmer-edge', 'statusline',
|
|
10
|
+
'output-style', 'raw', 'copy', 'reload', 'web', 'exit',
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
/** Commands a GUI can offer. */
|
|
14
|
+
export function commandsForSurface(surface) {
|
|
15
|
+
if (surface !== 'gui') return COMMANDS;
|
|
16
|
+
return COMMANDS.filter((c) => !TUI_ONLY_COMMANDS.has(c.name));
|
|
17
|
+
}
|
|
18
|
+
export const COMMANDS = [
|
|
19
|
+
{ name: 'yolo', aliases: ['yes'], desc: 'Yolo mode: anything inside the workspace (edits, writes, commands) runs automatically; paths outside it, destructive commands, questions and plans still ask.', priority: 101 },
|
|
20
|
+
{ name: 'permission', desc: 'Select permission mode', priority: 100 },
|
|
21
|
+
{ name: 'settings', aliases: ['config'], desc: 'Browse and change every setting, grouped by area', priority: 100, argumentHint: '[tab|filter]' },
|
|
22
|
+
{ name: 'set', desc: 'Set one config value by key, or list what differs from the default', priority: 100, argumentHint: '[<key> [value]]' },
|
|
23
|
+
{ name: 'sampling', desc: 'Show or set temperature, top_p and presence_penalty', priority: 100, argumentHint: '[on|off|temperature <n>|top_p <n>|presence_penalty <n>]' },
|
|
24
|
+
{ name: 'plan', desc: 'Toggle plan mode', priority: 100, argumentHint: '[on|off|clear]' },
|
|
25
|
+
{ name: 'websearch-api', desc: 'Edit the WebSearch API keys (one per line, tried in order)', priority: 96 },
|
|
26
|
+
{ name: 'focus', desc: 'Toggle Focus mode (minimal tools first, full tools after)', priority: 98, argumentHint: '[on|off]' },
|
|
27
|
+
{ name: 'auto', desc: 'Auto mode: never interrupts you; everything runs and is decided automatically.', priority: 99 },
|
|
28
|
+
{ name: 'ask', aliases: ['manual'], desc: 'Ask mode: read-only runs automatically; every other action asks first.', priority: 99 },
|
|
29
|
+
{ name: 'model', desc: 'Switch LLM model', priority: 100 },
|
|
30
|
+
// The argument hint is a PLACEHOLDER, not the level list: the real levels come
|
|
31
|
+
// from the current model (models.dev), so they are completed live by
|
|
32
|
+
// setArgCompletionProvider rather than hardcoded here.
|
|
33
|
+
{ name: 'effort', aliases: ['thinking'], desc: 'Switch thinking effort', priority: 95, argumentHint: '[level]' },
|
|
34
|
+
{ name: 'provider', aliases: ['providers'], desc: 'Manage AI providers (add / delete)', priority: 95 },
|
|
35
|
+
{ name: 'help', aliases: ['h', '?'], desc: 'Show available commands and shortcuts', priority: 80 },
|
|
36
|
+
{ name: 'new', aliases: ['clear'], desc: 'Start a fresh session in the current workspace', priority: 80 },
|
|
37
|
+
{ name: 'sessions', aliases: ['resume'], desc: 'Browse and resume sessions', priority: 80 },
|
|
38
|
+
{ name: 'all-sessions', desc: 'Browse sessions from EVERY workspace', priority: 79 },
|
|
39
|
+
{ name: 'tasks', aliases: ['task'], desc: 'Browse background tasks (full-screen panel)', priority: 80 },
|
|
40
|
+
{ name: 'swarm', desc: 'Toggle swarm mode: decompose work across parallel subagents', priority: 80, argumentHint: '[on|off]' },
|
|
41
|
+
{ name: 'subagent-model', aliases: ['swarm-sub-agent'], desc: 'Which model subagents run on, for both Agent and AgentSwarm (default = this session\u2019s model)', priority: 60, argumentHint: '[<model> | default]' },
|
|
42
|
+
{ name: 'compact', desc: 'Compact the conversation context (AI summary + keep last 20%)', priority: 80, argumentHint: '[ratio]' },
|
|
43
|
+
{ name: 'goal', aliases: ['objective'], desc: 'Start or manage an autonomous goal', priority: 80, argumentHint: '[status|pause|resume|cancel|clear|replace <text>] | <objective>' },
|
|
44
|
+
{ name: 'init', desc: 'Generate or update AGENTS.md from the codebase', priority: 70, argumentHint: '[instructions]' },
|
|
45
|
+
{ name: 'fork', desc: 'Fork the current session into a copy without switching to it', priority: 80 },
|
|
46
|
+
// `/rewind` is the name this is usually looked for by; the behaviour is the same picker either way.
|
|
47
|
+
{ name: 'undo', aliases: ['rewind'], desc: 'Rewind to an earlier prompt: the transcript truncates and the files those turns changed are restored', priority: 80, argumentHint: '[count]' },
|
|
48
|
+
{ name: 'trim', desc: 'Trim old tool results now, down to the keep ratio (manual)', priority: 40, argumentHint: '[keep-ratio]' },
|
|
49
|
+
{ name: 'auto-trim', aliases: ['autotrim'], desc: 'Auto tool-result trimming: the threshold is a share of the WINDOW, `keep` a share of the tool-result TEXT', priority: 40, argumentHint: '[on|off | threshold <n> | keep <n>]' },
|
|
50
|
+
{ name: 'title', aliases: ['rename'], desc: 'Set or show session title (also sets window title)', priority: 60, argumentHint: '<title>' },
|
|
51
|
+
{ name: 'auto-title', desc: 'Let the model name the session from its first message (persisted)', priority: 60, argumentHint: '[on|off]' },
|
|
52
|
+
{ name: 'ptc', desc: 'PTC mode: every tool call goes through the programmatic sandbox, no direct tools', priority: 55, argumentHint: '[on|off]' },
|
|
53
|
+
{ name: 'status', desc: 'Show current session and runtime status', priority: 60 },
|
|
54
|
+
{ name: 'doctor', desc: 'Diagnose the environment: config, store, MCP, hooks, disk, git, terminal', priority: 60, argumentHint: '[--all] [--probe]' },
|
|
55
|
+
{ name: 'memory-profile', aliases: ['memprof'], desc: 'Where this session’s memory goes: text vs tool results vs tool arguments', priority: 60, argumentHint: '[--verbose]' },
|
|
56
|
+
{ name: 'usage', desc: 'Show real token totals (provider-reported) + context window', priority: 60 },
|
|
57
|
+
{ name: 'stats', aliases: ['summary'], desc: 'What this session has done: turns, tools, files touched, time and tokens', priority: 59 },
|
|
58
|
+
{ name: 'cost', desc: 'Show what this session has spent, in USD or CNY', priority: 60, argumentHint: '[usd|cny]' },
|
|
59
|
+
{ name: 'context', aliases: ['ctx'], desc: 'Break down what fills the context window', priority: 60 },
|
|
60
|
+
{ name: 'raw', desc: 'Show assistant replies verbatim: no Markdown, no wrapping', priority:50, argumentHint: '[on|off]' },
|
|
61
|
+
{ name: 'reduced-motion', desc: 'Replace all animation with a slow-breathing indicator', priority: 50, argumentHint: '[on|off]' },
|
|
62
|
+
{ name: 'shimmer-edge', desc: 'Sweep edge: cosine (soft both sides) or linear (hard leading edge)', priority: 40, argumentHint: '[cosine|linear]' },
|
|
63
|
+
{ name: 'output-style', aliases: ['style'], desc: 'Apply an output style loaded from ~/.hncode/output-styles/*.md', priority: 50, argumentHint: '[name | off | new <name> | edit]' },
|
|
64
|
+
{ name: 'experiments', desc: 'List or toggle unfinished features', priority: 50, argumentHint: '[name on|off]' },
|
|
65
|
+
{ name: 'btw', aliases: ['aside'], desc: 'Ask a question in a side thread that does not enter the conversation', priority: 55, argumentHint: '[question]' },
|
|
66
|
+
{ name: 'recap', desc: 'Say where this session got to, without changing it', priority: 55 },
|
|
67
|
+
{ name: 'secondary-model', aliases: ['small-model'], desc: 'Pick the model used for side questions and recaps', priority: 45, argumentHint: '[model | off]' },
|
|
68
|
+
{ name: 'replay', aliases: ['rollout'], desc: 'Step back through this session: what the model saw at each step', priority: 45, argumentHint: '[step | next | prev | last]' },
|
|
69
|
+
{ name: 'schedule', desc: 'Recurring prompts queued on a running session', priority: 45, argumentHint: '[list | run <id>]' },
|
|
70
|
+
{ name: 'teleport', desc: 'Export or import this session for another machine or checkout', priority: 45, argumentHint: '[export [path] | import <file>]' },
|
|
71
|
+
{ name: 'search', aliases: ['grep'], desc: 'Search the project and insert the hit into the composer', priority: 60, argumentHint: '[query]' },
|
|
72
|
+
{ name: 'mcp', desc: 'Show MCP server status', priority: 60, argumentHint: '[tools]' },
|
|
73
|
+
{ name: 'mcp-config', desc: 'Manage MCP servers (interactive, or list / add / remove)', priority: 60, argumentHint: '[list] | add <name> <command|url> [args…] | remove <name>' },
|
|
74
|
+
{ name: 'statusline', desc: 'Configure which items appear in the status line', priority: 60 },
|
|
75
|
+
{ name: 'theme', desc: 'Switch the colour theme', priority: 60, argumentHint: `[${THEME_NAMES.join('|')}]` },
|
|
76
|
+
{ name: 'keybindings', aliases: ['keys'], desc: 'Remap a key to another key or to a slash command', priority: 55, argumentHint: '[list | add <key> <key|/command> | remove <key> | edit]' },
|
|
77
|
+
{ name: 'agents', aliases: ['subagents'], desc: 'List running subagents, and message, interrupt or close them', priority: 55, argumentHint: '[list | message <id> <text> | interrupt [id|all] | close <id>]' },
|
|
78
|
+
{ name: 'team', desc: 'Lead a team: watch and message the members, add them, and open a team from an earlier session', priority: 100, argumentHint: '[panel | create <name> | add <name> [model] | msg <name> <text> | list | delete]' },
|
|
79
|
+
{ name: 'files', aliases: ['tree'], desc: 'Browse the workspace as a tree; Enter inserts the path', priority: 60, argumentHint: '[path-filter]' },
|
|
80
|
+
{ name: 'checkpoints', aliases: ['cp'], desc: 'List per-file checkpoints and restore one file on its own', priority: 55, argumentHint: '[list | restore <n> | diff <n>]' },
|
|
81
|
+
{ name: 'save-history', desc: 'Keep the display-only transcript (notices, warnings, compaction, plan cards, reasoning) in the saved session', priority: 60, argumentHint: '[on|off|thinking|nothinking]' },
|
|
82
|
+
{ name: 'export-md', aliases: ['export'], desc: 'Export current session as a Markdown file', priority: 40, argumentHint: '[output-path]' },
|
|
83
|
+
{ name: 'import-session', aliases: ['import'], desc: 'Attach a Markdown file to the prompt so the AI reads it without a tool call', priority: 40, argumentHint: '<file.md>' },
|
|
84
|
+
{ name: 'copy', desc: 'Copy the last assistant message to the clipboard', priority: 40 },
|
|
85
|
+
{ name: 'set-system-prompt', aliases: ['system-prompt'], desc: 'Edit the system prompt, or load one of the model-family presets', priority: 60 },
|
|
86
|
+
{ name: 'personal', aliases: ['preferences'], desc: 'Edit personal preferences injected into every prompt (global or per-project)', priority: 60, argumentHint: '[global|project]' },
|
|
87
|
+
{ name: 'permissions', aliases: ['rules'], desc: 'Show or edit standing allow/ask/deny rules for tools', priority: 60, argumentHint: '[edit]' },
|
|
88
|
+
{ name: 'external', aliases: ['allow-external'], desc: 'Toggle access to paths outside the workspace (persisted)', priority: 60, argumentHint: '[on|off]' },
|
|
89
|
+
{ name: 'web', desc: 'Serve this session to a browser (token-protected; loopback by default)', priority: 60, argumentHint: '[bindIp] [port] | off' },
|
|
90
|
+
{ name: 'calm-mode', desc: 'Terse replies: stop the model narrating what it will do and why unless asked', priority: 60, argumentHint: '[on|off]' },
|
|
91
|
+
{ name: 'add-dir', desc: 'Add or list an additional workspace directory', priority: 60, argumentHint: '[list] | <path>' },
|
|
92
|
+
{ name: 'move', aliases: ['cd'], desc: 'Move current session to another directory (must exist)', priority: 60, argumentHint: '<path>' },
|
|
93
|
+
{ name: 'vim', aliases: ['nvim'], desc: 'Edit the composer in $EDITOR (vim by default); on save it comes back into the composer', priority: 60 },
|
|
94
|
+
{ name: 'reload', desc: 'Reload config and plugins without restart', priority: 60 },
|
|
95
|
+
{ name: 'reload-config', desc: 'Reload config.toml settings only', priority: 60 },
|
|
96
|
+
{ name: 'plugins', desc: 'Open the plugin manager (installed + available in the repo)', priority: 60, argumentHint: '[install <name> | remove <name> | reload]' },
|
|
97
|
+
{ name: 'skills', desc: 'Open the skill manager (installed + available in the repo)', priority: 60, argumentHint: '[install <name> | remove <name>]' },
|
|
98
|
+
{ name: 'import-skill', desc: 'Add a skill from a Markdown file, or install every skill in a GitHub repository (owner/repo)', cooldown: false },
|
|
99
|
+
{ name: 'hooks', desc: 'Show configured shell hooks, or test one', priority: 60, argumentHint: '[list | test <event>]' },
|
|
100
|
+
{ name: 'git', desc: 'Show repository status (branch, changes, remote)', priority: 62 },
|
|
101
|
+
{ name: 'commit', desc: 'Stage and commit with a message (or let the agent draft one)', priority: 62, argumentHint: '[message]' },
|
|
102
|
+
{ name: 'branch', desc: 'List, create, or switch git branches', priority: 62, argumentHint: '[list | <name> | -c <name>]' },
|
|
103
|
+
{ name: 'worktree', desc: 'List, create, or remove git worktrees for parallel work', priority: 60, argumentHint: '[list | new [name] [--branch] | add <dir> [branch] | remove <dir>]' },
|
|
104
|
+
{ name: 'pr', desc: 'Show the URL to open a pull request for the current branch', priority: 60, argumentHint: '[base]' },
|
|
105
|
+
{ name: 'add', aliases: ['stage'], desc: 'Stage changes (all by default, or given paths)', priority: 62, argumentHint: '[<path> ...]' },
|
|
106
|
+
{ name: 'diff', desc: 'Show uncommitted changes', priority: 62, argumentHint: '[--staged|--cached] [<path>]' },
|
|
107
|
+
{ name: 'review', desc: 'Have the agent review the uncommitted changes and report real problems', priority: 62, argumentHint: '[--staged|--cached] [<path>]' },
|
|
108
|
+
{ name: 'log', desc: 'Show recent commits', priority: 62, argumentHint: '[count] [<path>]' },
|
|
109
|
+
{ name: 'push', desc: 'Push the current branch (asks first)', priority: 62, argumentHint: '[branch] [-f]' },
|
|
110
|
+
{ name: 'stash', desc: 'Stash changes: list / push / pop', priority: 60, argumentHint: '[list | push [msg] | pop]' },
|
|
111
|
+
{ name: 'rebase', desc: 'Rebase the current branch onto another (asks first)', priority: 60, argumentHint: '<branch>' },
|
|
112
|
+
{ name: 'cache', desc: 'Toggle prompt caching for long stable prefixes (saves input tokens)', priority: 58, argumentHint: '[on|off]' },
|
|
113
|
+
{ name: 'logout', aliases: ['disconnect'], desc: 'Log out of a configured provider', priority: 40 },
|
|
114
|
+
{ name: 'feedback', aliases: ['bug'], desc: 'Open a prefilled GitHub issue (title + body)', priority: 60, argumentHint: '<title> | <body>' },
|
|
115
|
+
{ name: 'update', desc: 'Check for and install a newer version', priority: 40, argumentHint: '[-y]' },
|
|
116
|
+
{ name: 'auto-update', desc: 'Toggle automatic background updates (check at startup + every 30 min)', priority: 40, argumentHint: '[on|off]' },
|
|
117
|
+
{ name: 'auto-compact', aliases: ['autocompact'], desc: 'Auto context compaction: toggle, or set the trigger/keep ratios', priority: 40, argumentHint: '[on|off | threshold <n> | keep <n>]' },
|
|
118
|
+
{ name: 'lang', desc: 'Switch the interface language (zh / en)', priority: 60, argumentHint: '[zh|en]' },
|
|
119
|
+
{ name: 'version', desc: 'Show version information', priority: 20 },
|
|
120
|
+
{ name: 'exit', aliases: ['quit', 'q'], desc: 'Exit the application', priority: 20 },
|
|
121
|
+
].sort((a, b) => (b.priority || 0) - (a.priority || 0) || a.name.localeCompare(b.name));
|