@songsid/agend 2.1.0-beta.4 → 2.1.0-beta.40
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 +1 -0
- package/README.zh-TW.md +2 -1
- package/dist/access-path.js +3 -3
- package/dist/access-path.js.map +1 -1
- package/dist/agent-cli.js +1 -1
- package/dist/agent-cli.js.map +1 -1
- package/dist/agent-endpoint.d.ts +8 -0
- package/dist/agent-endpoint.js +36 -8
- package/dist/agent-endpoint.js.map +1 -1
- package/dist/backend/antigravity.d.ts +2 -0
- package/dist/backend/antigravity.js +30 -3
- package/dist/backend/antigravity.js.map +1 -1
- package/dist/backend/claude-code.d.ts +2 -0
- package/dist/backend/claude-code.js +16 -4
- package/dist/backend/claude-code.js.map +1 -1
- package/dist/backend/factory.js +4 -1
- package/dist/backend/factory.js.map +1 -1
- package/dist/backend/grok.d.ts +53 -0
- package/dist/backend/grok.js +302 -0
- package/dist/backend/grok.js.map +1 -0
- package/dist/backend/kiro.d.ts +2 -0
- package/dist/backend/kiro.js +32 -3
- package/dist/backend/kiro.js.map +1 -1
- package/dist/backend/types.d.ts +36 -3
- package/dist/backend/types.js +1 -0
- package/dist/backend/types.js.map +1 -1
- package/dist/channel/adapters/discord.d.ts +20 -0
- package/dist/channel/adapters/discord.js +89 -11
- package/dist/channel/adapters/discord.js.map +1 -1
- package/dist/channel/adapters/telegram.js +4 -1
- package/dist/channel/adapters/telegram.js.map +1 -1
- package/dist/channel/mcp-tools.js +18 -2
- package/dist/channel/mcp-tools.js.map +1 -1
- package/dist/chat-export.js +5 -2
- package/dist/chat-export.js.map +1 -1
- package/dist/classic-channel-manager.d.ts +16 -1
- package/dist/classic-channel-manager.js +76 -4
- package/dist/classic-channel-manager.js.map +1 -1
- package/dist/cli.js +116 -19
- package/dist/cli.js.map +1 -1
- package/dist/config-validator.js +70 -1
- package/dist/config-validator.js.map +1 -1
- package/dist/config.d.ts +3 -1
- package/dist/config.js +14 -1
- package/dist/config.js.map +1 -1
- package/dist/context-guardian.d.ts +2 -0
- package/dist/context-guardian.js +10 -2
- package/dist/context-guardian.js.map +1 -1
- package/dist/daemon-entry.js +2 -1
- package/dist/daemon-entry.js.map +1 -1
- package/dist/daemon.d.ts +91 -6
- package/dist/daemon.js +602 -186
- package/dist/daemon.js.map +1 -1
- package/dist/daily-summary.js +7 -2
- package/dist/daily-summary.js.map +1 -1
- package/dist/fleet-context.d.ts +6 -0
- package/dist/fleet-manager.d.ts +113 -8
- package/dist/fleet-manager.js +972 -142
- package/dist/fleet-manager.js.map +1 -1
- package/dist/fleet-system-prompt.js +1 -1
- package/dist/general-knowledge/skills/fleet-config/SKILL.md +19 -13
- package/dist/general-knowledge/skills/fleet-health/SKILL.md +30 -51
- package/dist/general-knowledge/skills/fleet-restart/SKILL.md +1 -1
- package/dist/general-knowledge/skills/instance-lifecycle/SKILL.md +19 -13
- package/dist/general-knowledge/skills/model-discovery/SKILL.md +1 -5
- package/dist/general-knowledge/skills/scheduling/SKILL.md +41 -0
- package/dist/general-knowledge/skills/session-management/SKILL.md +29 -116
- package/dist/instance-lifecycle.d.ts +15 -1
- package/dist/instance-lifecycle.js +71 -22
- package/dist/instance-lifecycle.js.map +1 -1
- package/dist/locale.js +28 -2
- package/dist/locale.js.map +1 -1
- package/dist/logger.d.ts +6 -0
- package/dist/logger.js +28 -9
- package/dist/logger.js.map +1 -1
- package/dist/outbound-handlers.d.ts +3 -0
- package/dist/outbound-handlers.js +224 -11
- package/dist/outbound-handlers.js.map +1 -1
- package/dist/outbound-schemas.d.ts +44 -2
- package/dist/outbound-schemas.js +50 -3
- package/dist/outbound-schemas.js.map +1 -1
- package/dist/pause-marker.d.ts +5 -0
- package/dist/pause-marker.js +36 -0
- package/dist/pause-marker.js.map +1 -0
- package/dist/scheduler/db.d.ts +8 -0
- package/dist/scheduler/db.js +74 -5
- package/dist/scheduler/db.js.map +1 -1
- package/dist/scheduler/db.test.js +50 -0
- package/dist/scheduler/db.test.js.map +1 -1
- package/dist/scheduler/scheduler.d.ts +6 -0
- package/dist/scheduler/scheduler.js +99 -16
- package/dist/scheduler/scheduler.js.map +1 -1
- package/dist/scheduler/scheduler.test.js +131 -1
- package/dist/scheduler/scheduler.test.js.map +1 -1
- package/dist/scheduler/types.d.ts +9 -3
- package/dist/scheduler/types.js.map +1 -1
- package/dist/settings-api.d.ts +20 -2
- package/dist/settings-api.js +213 -9
- package/dist/settings-api.js.map +1 -1
- package/dist/setup-wizard.js +8 -0
- package/dist/setup-wizard.js.map +1 -1
- package/dist/statusline-watcher.d.ts +1 -1
- package/dist/statusline-watcher.js +3 -2
- package/dist/statusline-watcher.js.map +1 -1
- package/dist/tmux-control.d.ts +7 -0
- package/dist/tmux-control.js +22 -1
- package/dist/tmux-control.js.map +1 -1
- package/dist/tmux-manager.d.ts +1 -1
- package/dist/tmux-manager.js.map +1 -1
- package/dist/topic-commands.d.ts +19 -1
- package/dist/topic-commands.js +148 -23
- package/dist/topic-commands.js.map +1 -1
- package/dist/transcript-monitor.js +2 -0
- package/dist/transcript-monitor.js.map +1 -1
- package/dist/types.d.ts +29 -1
- package/dist/tz-utils.d.ts +26 -0
- package/dist/tz-utils.js +46 -0
- package/dist/tz-utils.js.map +1 -0
- package/dist/ui/dashboard.html +3 -3
- package/dist/ui/settings.html +453 -74
- package/dist/web-api.d.ts +1 -0
- package/dist/web-api.js +24 -15
- package/dist/web-api.js.map +1 -1
- package/dist/workflow-templates/default.md +0 -4
- package/package.json +2 -1
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
import { existsSync, readFileSync, readdirSync, statSync, writeFileSync, chmodSync } from "node:fs";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
import { isModelCompatible, resolveBinary, validateModel } from "./types.js";
|
|
7
|
+
import { appendWithMarker, removeMarker } from "./marker-utils.js";
|
|
8
|
+
/** Session ids are UUIDs (e.g. "019f82d4-…"); guard before shell interpolation. */
|
|
9
|
+
const SESSION_ID_RE = /^[A-Za-z0-9-]+$/;
|
|
10
|
+
/**
|
|
11
|
+
* Grok Build (xAI) — https://docs.x.ai/build/cli
|
|
12
|
+
*
|
|
13
|
+
* IMPORTANT — why the interactive TUI, not `grok agent stdio`:
|
|
14
|
+
* Grok Build exposes three surfaces: the interactive TUI (`grok`), headless
|
|
15
|
+
* (`grok -p "<prompt>"`), and an ACP agent (`grok agent stdio`) that speaks
|
|
16
|
+
* JSON-RPC over stdin/stdout. AgEnD drives a backend through a tmux PTY — it
|
|
17
|
+
* scans human-readable pane text for ready/error patterns and injects
|
|
18
|
+
* keystrokes (cancel key, slash commands). An ACP JSON-RPC agent has no
|
|
19
|
+
* human-readable prompt, ready banner, or slash commands, so the CliBackend
|
|
20
|
+
* interface does not map onto it. The interactive TUI is the correct surface,
|
|
21
|
+
* the same choice made for codex/opencode/kiro.
|
|
22
|
+
*
|
|
23
|
+
* Phase 2: ready pattern, cancel/quit keys, /compact, context format, and the
|
|
24
|
+
* device-flow login dialog were confirmed against a live grok session. Error
|
|
25
|
+
* strings beyond the cancellation notice are still best-effort and may need
|
|
26
|
+
* tuning.
|
|
27
|
+
*/
|
|
28
|
+
export class GrokBackend {
|
|
29
|
+
instanceDir;
|
|
30
|
+
binaryName = "grok";
|
|
31
|
+
binaryPath;
|
|
32
|
+
// Cached from buildCommand/writeConfig so getSessionId() (which takes no args)
|
|
33
|
+
// can scope to grok's per-cwd session directory.
|
|
34
|
+
workingDirectory;
|
|
35
|
+
constructor(instanceDir) {
|
|
36
|
+
this.instanceDir = instanceDir;
|
|
37
|
+
this.binaryPath = resolveBinary("grok");
|
|
38
|
+
}
|
|
39
|
+
buildCommand(config) {
|
|
40
|
+
this.workingDirectory = config.workingDirectory;
|
|
41
|
+
// Flags: -m/--model, --always-approve, -r/--resume <ID>, -p/--single, --no-auto-update.
|
|
42
|
+
// --no-auto-update: an auto-update prompt on launch would corrupt ready detection.
|
|
43
|
+
let cmd = `${this.binaryPath} --no-auto-update`;
|
|
44
|
+
// --always-approve auto-approves tool executions (documented flag). If a grok
|
|
45
|
+
// build ignores it, getRuntimeDialogs() auto-approves the prompt as a net.
|
|
46
|
+
if (config.skipPermissions !== false)
|
|
47
|
+
cmd += " --always-approve";
|
|
48
|
+
// Resume by explicit session id (verified: grok prints
|
|
49
|
+
// "Resume this session with: grok --resume <uuid>" on exit — there is no
|
|
50
|
+
// bare --continue that reliably resumes). The id is persisted by the daemon
|
|
51
|
+
// from getSessionId(); skip on crash recovery (skipResume) for a clean start.
|
|
52
|
+
if (!config.skipResume) {
|
|
53
|
+
const sid = this.storedSessionId();
|
|
54
|
+
if (sid)
|
|
55
|
+
cmd += ` --resume ${sid}`;
|
|
56
|
+
}
|
|
57
|
+
if (config.model) {
|
|
58
|
+
if (isModelCompatible("grok", config.model)) {
|
|
59
|
+
cmd += ` --model ${validateModel(config.model)}`;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
console.warn(`[agend] model "${config.model}" is not compatible with grok — skipping --model, using the CLI's default`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return cmd;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Build an ASCII-only, per-instance MCP server key. Grok Build's MCP client has
|
|
69
|
+
* a bug where a non-ASCII (e.g. CJK) server name connects but drops ALL tools
|
|
70
|
+
* (tool_count=0, misreported as "connection failed"). Instance names can be CJK
|
|
71
|
+
* (persona ClassicBot channels), so sanitize: pure-ASCII names pass through
|
|
72
|
+
* unchanged (readable + already unique); names with non-ASCII are stripped to an
|
|
73
|
+
* ASCII slug plus a short hash of the ORIGINAL name, so two distinct CJK names
|
|
74
|
+
* sharing a working directory can't collide to the same key.
|
|
75
|
+
*/
|
|
76
|
+
mcpKey(mcpName, instanceName) {
|
|
77
|
+
const ascii = instanceName.replace(/[^\x20-\x7E]/g, "");
|
|
78
|
+
if (ascii === instanceName)
|
|
79
|
+
return `${mcpName}-${instanceName}`;
|
|
80
|
+
const slug = ascii.replace(/[^A-Za-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
81
|
+
const hash = createHash("md5").update(instanceName).digest("hex").slice(0, 8);
|
|
82
|
+
return slug ? `${mcpName}-${slug}-${hash}` : `${mcpName}-${hash}`;
|
|
83
|
+
}
|
|
84
|
+
/** The daemon's persisted session id (written from getSessionId()), for --resume. */
|
|
85
|
+
storedSessionId() {
|
|
86
|
+
try {
|
|
87
|
+
const sid = readFileSync(join(this.instanceDir, "session-id"), "utf-8").trim();
|
|
88
|
+
return SESSION_ID_RE.test(sid) ? sid : null;
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
writeConfig(config) {
|
|
95
|
+
this.workingDirectory = config.workingDirectory;
|
|
96
|
+
// Grok Build merges MCP servers from a project-level .mcp.json (loaded below
|
|
97
|
+
// ~/.grok/config.toml in priority). Using the project file means we never
|
|
98
|
+
// clobber the user's global config. Standard mcpServers format: { command, args, env }.
|
|
99
|
+
const mcpPath = join(config.workingDirectory, ".mcp.json");
|
|
100
|
+
let root = {};
|
|
101
|
+
try {
|
|
102
|
+
root = JSON.parse(readFileSync(mcpPath, "utf-8"));
|
|
103
|
+
}
|
|
104
|
+
catch { /* new file */ }
|
|
105
|
+
const servers = (root.mcpServers ?? {});
|
|
106
|
+
// Drop stale agend entries whose wrapper script no longer exists, plus any
|
|
107
|
+
// legacy non-ASCII key (grok drops all tools on a CJK key — we now always
|
|
108
|
+
// write ASCII keys, so a lingering CJK entry is dead weight to remove).
|
|
109
|
+
for (const [key, val] of Object.entries(servers)) {
|
|
110
|
+
if (key.startsWith("agend-")) {
|
|
111
|
+
const cmd = val?.command;
|
|
112
|
+
if ((typeof cmd === "string" && !existsSync(cmd)) || /[^\x20-\x7E]/.test(key)) {
|
|
113
|
+
delete servers[key];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// Namespace each server by instance so multiple instances can share a working
|
|
118
|
+
// dir. Key is ASCII-sanitized (grok's MCP client drops tools on a CJK key).
|
|
119
|
+
for (const [name, entry] of Object.entries(config.mcpServers)) {
|
|
120
|
+
const instanceKey = this.mcpKey(name, config.instanceName);
|
|
121
|
+
const allEnv = { ...entry.env, AGEND_INSTANCE_NAME: config.instanceName };
|
|
122
|
+
// WORKAROUND (same as kiro-cli): grok does not reliably pass the mcp.json
|
|
123
|
+
// "env" block to the MCP server subprocess — the process would inherit grok's
|
|
124
|
+
// env, which has NO AGEND_SOCKET_PATH (the daemon keeps it out of process.env),
|
|
125
|
+
// so the server can't connect and every MCP tool (reply/react/…) fails. Emit a
|
|
126
|
+
// wrapper that exports the env explicitly, waits for the IPC socket, then execs
|
|
127
|
+
// the real server. This is env-delivery-independent and works either way.
|
|
128
|
+
const wrapperPath = join(this.instanceDir, `mcp-wrapper-${name}.sh`);
|
|
129
|
+
const envExports = Object.entries(allEnv)
|
|
130
|
+
.map(([k, v]) => `export ${k}='${String(v).replace(/'/g, "'\\''")}'`)
|
|
131
|
+
.join("\n");
|
|
132
|
+
// 0o700: wrapper inlines sensitive env (tokens, socket paths) — owner-only.
|
|
133
|
+
writeFileSync(wrapperPath, `#!/bin/bash\n${envExports}\n# Wait for IPC socket to be ready (up to 10s)\nfor i in $(seq 1 20); do [ -S "$AGEND_SOCKET_PATH" ] && break; sleep 0.5; done\nexec ${entry.command} ${entry.args.map((a) => JSON.stringify(a)).join(" ")}\n`, { mode: 0o700 });
|
|
134
|
+
chmodSync(wrapperPath, 0o700);
|
|
135
|
+
servers[instanceKey] = { command: wrapperPath, args: [] };
|
|
136
|
+
}
|
|
137
|
+
// Clean up any legacy non-namespaced key.
|
|
138
|
+
delete servers["agend"];
|
|
139
|
+
root.mcpServers = servers;
|
|
140
|
+
writeFileSync(mcpPath, JSON.stringify(root, null, 2));
|
|
141
|
+
// Fleet instructions → AGENTS.md marker block (Grok reads AGENTS.md project docs,
|
|
142
|
+
// same convention as Codex). Additive + idempotent via the AGEND marker.
|
|
143
|
+
if (config.instructions) {
|
|
144
|
+
try {
|
|
145
|
+
appendWithMarker(join(config.workingDirectory, "AGENTS.md"), config.instanceName, config.instructions);
|
|
146
|
+
}
|
|
147
|
+
catch { /* best effort */ }
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
getReadyPattern() {
|
|
151
|
+
// Verified: `❯` is the idle input prompt inside the TUI box; the Grok Build
|
|
152
|
+
// header ("Grok Build" / "Grok <n>") also identifies the ready screen.
|
|
153
|
+
return /❯|Grok \d|Grok Build/m;
|
|
154
|
+
}
|
|
155
|
+
getErrorPatterns() {
|
|
156
|
+
// NOTE: "Turn cancelled by user" is NORMAL behaviour (user interrupt), not an
|
|
157
|
+
// error — none of the patterns below match it, and none should be added that do.
|
|
158
|
+
// Error strings below are best-effort generic API shapes; tune once observed live.
|
|
159
|
+
return [
|
|
160
|
+
{ pattern: /rate.?limit|too many requests|\b429\b/i, type: "rate_limit", action: "failover", message: "Grok rate limit reached" },
|
|
161
|
+
{ pattern: /unauthorized|authentication (failed|error)|\b401\b/i, type: "auth_error", action: "pause", message: "Grok authentication error" },
|
|
162
|
+
{ pattern: /quota|insufficient credits|out of credits/i, type: "quota", action: "notify", message: "Grok quota/credits exhausted" },
|
|
163
|
+
];
|
|
164
|
+
}
|
|
165
|
+
getStartupDialogs() {
|
|
166
|
+
return [
|
|
167
|
+
// Workspace trust confirmation ("Do you trust the contents of this directory?")
|
|
168
|
+
// appears BEFORE the login screen — auto-approve with the 'y' hotkey.
|
|
169
|
+
{ pattern: /Do you trust the contents|trust.*directory/i, keys: ["y"], description: "Grok workspace trust — auto-approve" },
|
|
170
|
+
// Device-flow login is BLOCKING and cannot be auto-dismissed — the user must
|
|
171
|
+
// approve externally. Empty keys => the daemon sends nothing but treats the
|
|
172
|
+
// screen as "not ready yet" and keeps polling, so the login screen is never
|
|
173
|
+
// mistaken for the idle prompt. (The "[Click here to Upgrade]" banner is
|
|
174
|
+
// non-blocking and is intentionally NOT listed — nothing to dismiss.)
|
|
175
|
+
{ pattern: /Waiting for approval|Log in to continue|device.*approval/i, keys: [], description: "Grok device-flow login — wait for user authorization (no auto-dismiss)" },
|
|
176
|
+
];
|
|
177
|
+
}
|
|
178
|
+
getContextUsage() {
|
|
179
|
+
// Grok shows context as "12K / 500K" (used / total) in the TUI, not in a file.
|
|
180
|
+
// getContextUsage() has no pane access, so parsing lives in the pane scanners
|
|
181
|
+
// (parseContextPercent in topic-commands.ts + defaultParser in cli.ts), which
|
|
182
|
+
// is what /ctx and `agend ls` use. Nothing file-based to report here.
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
getSessionId() {
|
|
186
|
+
// grok stores sessions per working directory (verified):
|
|
187
|
+
// ~/.grok/sessions/<encodeURIComponent(cwd)>/<session-uuid>/{events.jsonl,…}
|
|
188
|
+
// Scoping by cwd means multiple concurrent grok instances (distinct cwds)
|
|
189
|
+
// never pick up each other's session. Return the UUID of the most-recently
|
|
190
|
+
// ACTIVE session in this instance's cwd for the daemon to persist (--resume).
|
|
191
|
+
if (!this.workingDirectory)
|
|
192
|
+
return null;
|
|
193
|
+
try {
|
|
194
|
+
const base = join(homedir(), ".grok", "sessions", encodeURIComponent(this.workingDirectory));
|
|
195
|
+
let newestId = null;
|
|
196
|
+
let newestMtime = -1;
|
|
197
|
+
for (const name of readdirSync(base)) {
|
|
198
|
+
// Session dirs are named by UUID; skip prompt_history.jsonl etc.
|
|
199
|
+
if (!SESSION_ID_RE.test(name) || name.length < 8)
|
|
200
|
+
continue;
|
|
201
|
+
const sessionDir = join(base, name);
|
|
202
|
+
let st;
|
|
203
|
+
try {
|
|
204
|
+
st = statSync(sessionDir);
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
if (!st.isDirectory())
|
|
210
|
+
continue;
|
|
211
|
+
// Activity = latest INNER-file mtime. The dir's own mtime doesn't move on
|
|
212
|
+
// append AND is misleadingly recent for a just-created dir, so it must NOT
|
|
213
|
+
// outweigh a resumed older session whose logs were just appended. Only fall
|
|
214
|
+
// back to dir mtime when the session has no inner files yet.
|
|
215
|
+
let activity = -1;
|
|
216
|
+
try {
|
|
217
|
+
for (const f of readdirSync(sessionDir)) {
|
|
218
|
+
try {
|
|
219
|
+
const m = statSync(join(sessionDir, f)).mtimeMs;
|
|
220
|
+
if (m > activity)
|
|
221
|
+
activity = m;
|
|
222
|
+
}
|
|
223
|
+
catch { /* skip */ }
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
catch { /* unreadable dir */ }
|
|
227
|
+
if (activity < 0)
|
|
228
|
+
activity = st.mtimeMs;
|
|
229
|
+
if (activity > newestMtime) {
|
|
230
|
+
newestMtime = activity;
|
|
231
|
+
newestId = name;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return newestId;
|
|
235
|
+
}
|
|
236
|
+
catch {
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
getRuntimeDialogs() {
|
|
241
|
+
return [
|
|
242
|
+
// Mid-task tool-approval prompt ("1. Yes, always 2. Yes 3. No"). Select
|
|
243
|
+
// option 1 so the fleet runs unattended. Primary mechanism is
|
|
244
|
+
// --always-approve at launch; this is the net if that flag is absent/ignored.
|
|
245
|
+
// ⚠️ key needs live confirmation — assumes a numeric hotkey (types "1"+Enter);
|
|
246
|
+
// if grok uses an arrow-select cursor instead, switch to ["Enter"] or nav keys.
|
|
247
|
+
{ pattern: /1\.\s*Yes,?\s*always|Yes,?\s*always[\s\S]{0,40}\bNo\b/i, keys: ["1"], description: "Grok tool-approval prompt — select 'Yes, always'" },
|
|
248
|
+
];
|
|
249
|
+
}
|
|
250
|
+
// grok has no slash quit command — it quits via the Ctrl+Q key chord (getQuitKey).
|
|
251
|
+
getQuitCommand() { return null; }
|
|
252
|
+
getQuitKey() { return "C-q"; }
|
|
253
|
+
// Trailing space commits the exact slash command before Grok's autocomplete
|
|
254
|
+
// can expand the partial token to `/compact-mode`.
|
|
255
|
+
getCompactCommand() { return "/compact "; }
|
|
256
|
+
// Verified: grok interrupts generation on Ctrl+C.
|
|
257
|
+
getCancelKey() { return "C-c"; }
|
|
258
|
+
// grok's in-session model switch is a picker → restart to apply reliably.
|
|
259
|
+
getModelSwitchStrategy() { return "restart"; }
|
|
260
|
+
async listModels() {
|
|
261
|
+
// ⚠️ UNVERIFIED `grok models` format — best-effort; falls back to documented ids.
|
|
262
|
+
try {
|
|
263
|
+
const out = execFileSync(this.binaryPath, ["models"], { encoding: "utf-8", timeout: 5000, stdio: ["ignore", "pipe", "ignore"] });
|
|
264
|
+
const ids = [...new Set(out.split("\n")
|
|
265
|
+
.map(l => l.trim().split(/\s+/)[0])
|
|
266
|
+
.filter(id => /^grok[\w.-]*$/i.test(id)))];
|
|
267
|
+
if (ids.length)
|
|
268
|
+
return ids.map(id => ({ id, label: id }));
|
|
269
|
+
}
|
|
270
|
+
catch { /* fall back to documented set */ }
|
|
271
|
+
return [
|
|
272
|
+
{ id: "grok-4.5", label: "grok-4.5" },
|
|
273
|
+
{ id: "grok-4.3", label: "grok-4.3" },
|
|
274
|
+
{ id: "grok-code", label: "grok-code" },
|
|
275
|
+
];
|
|
276
|
+
}
|
|
277
|
+
cleanup(config) {
|
|
278
|
+
// Remove only this instance's namespaced MCP entries — a non-namespaced key
|
|
279
|
+
// may belong to another instance sharing the working directory.
|
|
280
|
+
try {
|
|
281
|
+
const mcpPath = join(config.workingDirectory, ".mcp.json");
|
|
282
|
+
if (existsSync(mcpPath)) {
|
|
283
|
+
const root = JSON.parse(readFileSync(mcpPath, "utf-8"));
|
|
284
|
+
if (root.mcpServers) {
|
|
285
|
+
for (const name of Object.keys(config.mcpServers)) {
|
|
286
|
+
delete root.mcpServers[this.mcpKey(name, config.instanceName)];
|
|
287
|
+
// Also drop any legacy raw (pre-sanitize) key for this instance.
|
|
288
|
+
delete root.mcpServers[`${name}-${config.instanceName}`];
|
|
289
|
+
}
|
|
290
|
+
writeFileSync(mcpPath, JSON.stringify(root, null, 2));
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
catch { /* best effort */ }
|
|
295
|
+
// Remove fleet instructions marker block from AGENTS.md.
|
|
296
|
+
try {
|
|
297
|
+
removeMarker(join(config.workingDirectory, "AGENTS.md"), config.instanceName);
|
|
298
|
+
}
|
|
299
|
+
catch { /* best effort */ }
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
//# sourceMappingURL=grok.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grok.js","sourceRoot":"","sources":["../../src/backend/grok.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpG,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAqG,iBAAiB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChL,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEnE,mFAAmF;AACnF,MAAM,aAAa,GAAG,iBAAiB,CAAC;AAExC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,WAAW;IAOF;IANX,UAAU,GAAG,MAAM,CAAC;IACrB,UAAU,CAAS;IAC3B,+EAA+E;IAC/E,iDAAiD;IACzC,gBAAgB,CAAU;IAElC,YAAoB,WAAmB;QAAnB,gBAAW,GAAX,WAAW,CAAQ;QACrC,IAAI,CAAC,UAAU,GAAG,aAAa,CAAC,M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/dist/backend/kiro.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export declare class KiroBackend implements CliBackend {
|
|
|
14
14
|
getSessionId(): string | null;
|
|
15
15
|
getQuitCommand(): string;
|
|
16
16
|
getCompactCommand(): string;
|
|
17
|
+
getModelSwitchStrategy(): "runtime" | "restart";
|
|
18
|
+
listModels(): Promise<import("./types.js").ModelOption[]>;
|
|
17
19
|
getCancelKey(): string;
|
|
18
20
|
cleanup(config: CliBackendConfig): void;
|
|
19
21
|
}
|
package/dist/backend/kiro.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
2
3
|
import { existsSync, mkdirSync, readFileSync, writeFileSync, chmodSync, unlinkSync } from "node:fs";
|
|
3
4
|
import { isModelCompatible, resolveBinary, validateModel } from "./types.js";
|
|
4
5
|
export class KiroBackend {
|
|
@@ -10,7 +11,12 @@ export class KiroBackend {
|
|
|
10
11
|
this.binaryPath = resolveBinary("kiro-cli");
|
|
11
12
|
}
|
|
12
13
|
buildCommand(config) {
|
|
13
|
-
|
|
14
|
+
const ui = config.kiroUi ?? "legacy";
|
|
15
|
+
let cmd = `${this.binaryPath} chat`;
|
|
16
|
+
if (ui === "legacy")
|
|
17
|
+
cmd += " --legacy-ui";
|
|
18
|
+
else if (ui === "v3")
|
|
19
|
+
cmd += " --v3";
|
|
14
20
|
if (config.skipPermissions !== false)
|
|
15
21
|
cmd += " --trust-all-tools";
|
|
16
22
|
// --resume is boolean: Kiro auto-resumes latest conversation for this working directory
|
|
@@ -89,13 +95,15 @@ export class KiroBackend {
|
|
|
89
95
|
}
|
|
90
96
|
}
|
|
91
97
|
getReadyPattern() {
|
|
92
|
-
// Startup: trust/banner text. Daily prompt: "22% !>" / "8% ❯"
|
|
98
|
+
// Startup: trust/banner text. Daily prompt: "22% !>" / "8% ❯";
|
|
99
|
+
// Kiro may insert mode glyphs between them, e.g. "20% λ !>".
|
|
93
100
|
// TUI statusline: "◔ 22%" context indicator shown while waiting for input.
|
|
94
|
-
return /All tools are now trusted|Trust All Tools active|Credits:.*Time:|ask a question or describe a task|\d
|
|
101
|
+
return /All tools are now trusted|Trust All Tools active|Credits:.*Time:|ask a question or describe a task|\d+%.*[!❯>]|◔\s*\d+%/m;
|
|
95
102
|
}
|
|
96
103
|
getErrorPatterns() {
|
|
97
104
|
return [
|
|
98
105
|
{ pattern: /having trouble responding/i, type: "rate_limit", action: "notify", message: "Rate limit (having trouble responding)" },
|
|
106
|
+
{ pattern: /model.*not available|Please use '\/model'/i, type: "model_error", action: "notify", message: "Model unavailable — use /model to switch" },
|
|
99
107
|
{ pattern: /Response timed out/i, type: "timeout", action: "notify", message: "Kiro response timed out (generation too long) — please try again", skipCooldown: true, skipRecoveryWait: true },
|
|
100
108
|
];
|
|
101
109
|
}
|
|
@@ -130,6 +138,27 @@ export class KiroBackend {
|
|
|
130
138
|
}
|
|
131
139
|
getQuitCommand() { return "/quit"; }
|
|
132
140
|
getCompactCommand() { return "/compact"; }
|
|
141
|
+
// kiro's in-session `/model` opens an interactive picker (not a one-shot
|
|
142
|
+
// command), so a runtime paste can't select a specific model — use restart.
|
|
143
|
+
getModelSwitchStrategy() { return "restart"; }
|
|
144
|
+
async listModels() {
|
|
145
|
+
// ⚠️ UNVERIFIED subcommand/format — best-effort, never throws; [] ⇒ free-text.
|
|
146
|
+
try {
|
|
147
|
+
const out = execFileSync(this.binaryPath, ["chat", "--list-models", "--format", "json"], { encoding: "utf-8", timeout: 5000, stdio: ["ignore", "pipe", "ignore"] });
|
|
148
|
+
const arr = JSON.parse(out);
|
|
149
|
+
if (Array.isArray(arr)) {
|
|
150
|
+
return arr.map((m) => {
|
|
151
|
+
if (typeof m === "string")
|
|
152
|
+
return { id: m, label: m };
|
|
153
|
+
const o = m;
|
|
154
|
+
const id = String(o.id ?? o.name ?? o.model ?? "");
|
|
155
|
+
return { id, label: String(o.label ?? o.name ?? id) };
|
|
156
|
+
}).filter(o => o.id);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch { /* unknown flag/format — fall back to free-text */ }
|
|
160
|
+
return [];
|
|
161
|
+
}
|
|
133
162
|
// kiro-cli interrupts generation on Ctrl+C (others use Escape).
|
|
134
163
|
getCancelKey() { return "C-c"; }
|
|
135
164
|
cleanup(config) {
|
package/dist/backend/kiro.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kiro.js","sourceRoot":"","sources":["../../src/backend/kiro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACpG,OAAO,EAAqG,iBAAiB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhL,MAAM,OAAO,WAAW;IAIF;IAHX,UAAU,GAAG,UAAU,CAAC;IACzB,UAAU,CAAS;IAE3B,YAAoB,WAAmB;QAAnB,gBAAW,GAAX,WAAW,CAAQ;QACrC,IAAI,CAAC,UAAU,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;IAC9C,CAAC;IAED,YAAY,CAAC,MAAwB;QACnC,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC,UAAU,
|
|
1
|
+
{"version":3,"file":"kiro.js","sourceRoot":"","sources":["../../src/backend/kiro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACpG,OAAO,EAAqG,iBAAiB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhL,MAAM,OAAO,W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issions?: boolean;
|
|
24
24
|
model?: string;
|
|
25
|
+
/** Kiro-only UI/agent profile. Defaults to "legacy". */
|
|
26
|
+
kiroUi?: "legacy" | "tui" | "v3";
|
|
25
27
|
/** When true, backend should not resume a previous session (crash recovery). */
|
|
26
28
|
skipResume?: boolean;
|
|
27
29
|
/** Fleet instructions content to inject into the CLI's additive system prompt mechanism. */
|
|
@@ -34,7 +36,7 @@ export interface CliBackendConfig {
|
|
|
34
36
|
/** Action to take when an error pattern is detected in PTY output. */
|
|
35
37
|
export type ErrorActionType = "notify" | "failover" | "restart" | "pause";
|
|
36
38
|
/** Categorizes detected errors for logging and response. */
|
|
37
|
-
export type ErrorType = "rate_limit" | "auth_error" | "crash" | "network" | "quota" | "timeout";
|
|
39
|
+
export type ErrorType = "rate_limit" | "auth_error" | "crash" | "network" | "quota" | "timeout" | "model_error";
|
|
38
40
|
export interface ErrorPattern {
|
|
39
41
|
pattern: RegExp;
|
|
40
42
|
type: ErrorType;
|
|
@@ -50,6 +52,12 @@ export interface ErrorPattern {
|
|
|
50
52
|
* so waiting would block ALL future error detection forever. */
|
|
51
53
|
skipRecoveryWait?: boolean;
|
|
52
54
|
}
|
|
55
|
+
/** A selectable model, surfaced by `/model` (id is what gets applied). */
|
|
56
|
+
export interface ModelOption {
|
|
57
|
+
id: string;
|
|
58
|
+
label: string;
|
|
59
|
+
description?: string;
|
|
60
|
+
}
|
|
53
61
|
/** A dialog that may appear at runtime and needs auto-dismissal via key sequences. */
|
|
54
62
|
export interface RuntimeDialog {
|
|
55
63
|
/** Pattern to detect the dialog in PTY output. */
|
|
@@ -92,8 +100,18 @@ export interface CliBackend {
|
|
|
92
100
|
preTrust?(workingDirectory: string): void;
|
|
93
101
|
/** Resolve working directory (e.g. create symlink to avoid hidden paths). Returns resolved path. */
|
|
94
102
|
resolveWorkingDirectory?(workingDirectory: string, instanceName?: string): string;
|
|
95
|
-
/**
|
|
96
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Slash/text command to gracefully quit the CLI (e.g. "/exit", "/quit"),
|
|
105
|
+
* typed then followed by Enter. Return null when the CLI has no quit command
|
|
106
|
+
* and quits via a key chord instead — implement getQuitKey() in that case.
|
|
107
|
+
*/
|
|
108
|
+
getQuitCommand(): string | null;
|
|
109
|
+
/**
|
|
110
|
+
* The tmux key chord that quits the CLI, for backends whose quit is a keypress
|
|
111
|
+
* rather than a typed command (e.g. grok Ctrl+Q). Consulted only when
|
|
112
|
+
* getQuitCommand() returns null. Values are tmux send-keys names (e.g. "C-q").
|
|
113
|
+
*/
|
|
114
|
+
getQuitKey?(): string;
|
|
97
115
|
/**
|
|
98
116
|
* In-session command to compact/reset the conversation context. Most CLIs use
|
|
99
117
|
* "/compact"; some (e.g. Codex) use "/compact" too, OpenCode uses "/compact".
|
|
@@ -108,6 +126,21 @@ export interface CliBackend {
|
|
|
108
126
|
getCancelKey(): string;
|
|
109
127
|
/** Clean up config files on shutdown. */
|
|
110
128
|
cleanup?(config: CliBackendConfig): void;
|
|
129
|
+
/**
|
|
130
|
+
* List selectable models for `/model`. Best-effort — may exec the CLI's own
|
|
131
|
+
* model-listing subcommand (formats vary and are UNVERIFIED for some CLIs) or
|
|
132
|
+
* return a static alias set. Return [] when unknown; callers fall back to
|
|
133
|
+
* free-text `/model <name>`. Must never throw.
|
|
134
|
+
*/
|
|
135
|
+
listModels?(config: CliBackendConfig): Promise<ModelOption[]>;
|
|
136
|
+
/**
|
|
137
|
+
* How a model switch takes effect for this backend:
|
|
138
|
+
* "runtime" — paste the CLI's in-session `/model <name>` (only clean for CLIs
|
|
139
|
+
* with a one-shot command, e.g. claude-code); "restart" — persist + respawn
|
|
140
|
+
* (universal; use for picker-style CLIs like kiro/opencode/antigravity).
|
|
141
|
+
* Absent ⇒ treated as "restart".
|
|
142
|
+
*/
|
|
143
|
+
getModelSwitchStrategy?(model: string): "runtime" | "restart";
|
|
111
144
|
}
|
|
112
145
|
/**
|
|
113
146
|
* Resolve the full path to a CLI binary.
|
package/dist/backend/types.js
CHANGED
|
@@ -34,6 +34,7 @@ const BACKEND_MODEL_PATTERNS = {
|
|
|
34
34
|
"gemini-cli": /^gemini/i,
|
|
35
35
|
"opencode": /./, // opencode accepts anything (provider-dependent)
|
|
36
36
|
"antigravity": / /, // agy models always contain spaces (display names like "Gemini 3.5 Flash (High)")
|
|
37
|
+
"grok": /^grok/i, // grok-4.5, grok-4.3, grok-code, grok-build-0.1
|
|
37
38
|
};
|
|
38
39
|
/** Check if a model name is compatible with the given backend. */
|
|
39
40
|
export function isModelCompatible(backendName, model) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/backend/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/backend/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AA+KlD;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,IAAI,CAAC;QACH,OAAO,YAAY,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACrE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC,CAAC,wBAAwB;IACvC,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,aAAa,GAAG,qBAAqB,CAAC;AAC5C,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,iBAAiB,aAAa,EAAE,CAAC,CAAC;IAChG,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,0GAA0G;AAC1G,MAAM,sBAAsB,GAA2B;IACrD,aAAa,EAAE,4CAA4C;IAC3D,UAAU,EAAE,8BAA8B;IAC1C,OAAO,EAAE,wBAAwB;IACjC,YAAY,EAAE,UAAU;IACxB,UAAU,EAAE,GAAG,EAAG,iDAAiD;IACnE,aAAa,EAAE,GAAG,EAAG,kFAAkF;IACvG,MAAM,EAAE,QAAQ,EAAG,gDAAgD;CACpE,CAAC;AAEF,kEAAkE;AAClE,MAAM,UAAU,iBAAiB,CAAC,WAAmB,EAAE,KAAa;IAClE,MAAM,OAAO,GAAG,sBAAsB,CAAC,WAAW,CAAC,CAAC;IACpD,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC,CAAC,iCAAiC;IAC5D,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,WAAmB,EAAE,KAAa;IACpE,IAAI,CAAC,iBAAiB,CAAC,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC;QAC3C,OAAO,CAAC,IAAI,CAAC,kBAAkB,KAAK,uCAAuC,WAAW,0BAA0B,CAAC,CAAC;IACpH,CAAC;AACH,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,UAAU,CAAC,CAAS;IAClC,OAAO,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC;AACzC,CAAC"}
|
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
import { EventEmitter } from "node:events";
|
|
2
2
|
import type { ChannelAdapter, ApprovalHandle, SendOpts, SentMessage, PermissionPrompt, Choice, AlertData } from "../types.js";
|
|
3
3
|
import type { AccessManager } from "../access-manager.js";
|
|
4
|
+
/** Curated ClassicBot backends for Discord's native slash-option dropdown. */
|
|
5
|
+
export declare const DISCORD_START_BACKEND_CHOICES: readonly [{
|
|
6
|
+
readonly name: "Claude Code";
|
|
7
|
+
readonly value: "claude-code";
|
|
8
|
+
}, {
|
|
9
|
+
readonly name: "Kiro CLI";
|
|
10
|
+
readonly value: "kiro-cli";
|
|
11
|
+
}, {
|
|
12
|
+
readonly name: "Codex";
|
|
13
|
+
readonly value: "codex";
|
|
14
|
+
}, {
|
|
15
|
+
readonly name: "OpenCode";
|
|
16
|
+
readonly value: "opencode";
|
|
17
|
+
}, {
|
|
18
|
+
readonly name: "Antigravity";
|
|
19
|
+
readonly value: "antigravity";
|
|
20
|
+
}, {
|
|
21
|
+
readonly name: "Grok Build";
|
|
22
|
+
readonly value: "grok";
|
|
23
|
+
}];
|
|
4
24
|
export interface DiscordAdapterOptions {
|
|
5
25
|
id: string;
|
|
6
26
|
botToken: string;
|