u-foo 3.0.29 → 3.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +13 -8
  2. package/bin/ufoo.js +7 -2
  3. package/bin/ugrok.js +68 -0
  4. package/dist/tui/darwin-arm64/ufoo-tui +0 -0
  5. package/dist/tui/darwin-x64/ufoo-tui +0 -0
  6. package/dist/tui/linux-arm64/ufoo-tui +0 -0
  7. package/dist/tui/linux-x64/ufoo-tui +0 -0
  8. package/package.json +2 -1
  9. package/src/agents/activity/activityDetector.js +95 -0
  10. package/src/agents/controller/ufooAgent.js +3 -3
  11. package/src/agents/launch/launcher.js +17 -11
  12. package/src/agents/launch/ptyRunner.js +34 -12
  13. package/src/agents/launch/readyDetector.js +27 -0
  14. package/src/agents/prompts/defaultBootstrap.js +126 -1
  15. package/src/agents/providers/directAuthStatus.js +79 -0
  16. package/src/agents/providers/upstreamTransport.js +234 -85
  17. package/src/app/chat/commandExecutor.js +18 -10
  18. package/src/app/chat/commands.js +4 -2
  19. package/src/app/cli/run.js +7 -5
  20. package/src/code/UcodeController.js +201 -40
  21. package/src/code/agent.js +9 -2
  22. package/src/code/commands.js +13 -0
  23. package/src/code/dispatch.js +9 -1
  24. package/src/code/index.js +9 -2
  25. package/src/code/nativeRunner.js +398 -16
  26. package/src/code/providers/index.js +1 -0
  27. package/src/code/providers/modelsCatalog.js +21 -6
  28. package/src/code/providers/openaiResponsesTransport.js +119 -0
  29. package/src/code/providers/responsesProtocol.js +499 -0
  30. package/src/code/providers/transportContract.js +5 -1
  31. package/src/code/repl.js +95 -2
  32. package/src/code/tools/bash.js +159 -6
  33. package/src/code/ucodeSlashDispatch.js +13 -0
  34. package/src/config.js +6 -0
  35. package/src/coordination/bus/inject.js +2 -2
  36. package/src/coordination/bus/utils.js +4 -1
  37. package/src/orchestration/controller/gateRouter.js +2 -2
  38. package/src/orchestration/controller/launchRouting.js +2 -1
  39. package/src/orchestration/groups/validateTemplate.js +1 -1
  40. package/src/orchestration/solo/commands.js +1 -0
  41. package/src/runtime/daemon/index.js +12 -4
  42. package/src/runtime/daemon/nicknameScope.js +4 -1
  43. package/src/runtime/daemon/ops.js +8 -2
  44. package/src/ui/rustUcodeHost.js +86 -10
package/README.md CHANGED
@@ -3,9 +3,9 @@
3
3
  [中文](README.zh-CN.md)
4
4
 
5
5
  ufoo is a project-scoped multi-agent workspace runtime. It wraps Claude Code,
6
- OpenAI Codex, Antigravity, and ufoo's native `ucode` agent with a shared chat
7
- dashboard, daemon, event bus, memory, reports, group orchestration, and terminal
8
- launch modes.
6
+ OpenAI Codex, Antigravity, Grok Build, Kimi Code, and ufoo's native `ucode`
7
+ agent with a shared chat dashboard, daemon, event bus, memory, reports, group
8
+ orchestration, and terminal launch modes.
9
9
 
10
10
  Package: [u-foo on npm](https://www.npmjs.com/package/u-foo)
11
11
 
@@ -34,8 +34,9 @@ Package: [u-foo on npm](https://www.npmjs.com/package/u-foo)
34
34
 
35
35
  - Node.js 18 or newer.
36
36
  - macOS for Terminal.app/iTerm2 integration.
37
- - Claude Code, Codex CLI, or Antigravity CLI installed when using the matching
38
- wrappers: `uclaude`, `ucodex`, or `uagy`.
37
+ - Claude Code, Codex CLI, Antigravity CLI, Grok Build, or Kimi Code installed
38
+ when using the matching wrappers: `uclaude`, `ucodex`, `uagy`, `ugrok`, or
39
+ `ukimi`.
39
40
 
40
41
  ## Installation
41
42
 
@@ -62,6 +63,7 @@ Installed binaries:
62
63
  | `uclaude` | Claude Code wrapper with ufoo bootstrap and bus identity. |
63
64
  | `ucodex` | Codex wrapper with ufoo bootstrap and bus identity. |
64
65
  | `uagy` | Antigravity wrapper with ufoo bootstrap and bus identity. |
66
+ | `ugrok` | Grok Build wrapper with ufoo bootstrap and bus identity. |
65
67
  | `ukimi` | Kimi Code wrapper with ufoo bootstrap and bus identity. |
66
68
  | `ucode` | Native ufoo coding-agent CLI/TUI. |
67
69
 
@@ -80,6 +82,7 @@ Launch agents from chat:
80
82
  ```text
81
83
  > /launch codex reviewer
82
84
  > /launch claude builder
85
+ > /launch grok explorer
83
86
  > /launch ucode fixer
84
87
  > @reviewer inspect the current diff and list release risks
85
88
  ```
@@ -90,6 +93,7 @@ Or launch wrappers directly inside a project:
90
93
  uclaude
91
94
  ucodex
92
95
  uagy
96
+ ugrok
93
97
  ukimi
94
98
  ucode
95
99
  ```
@@ -153,7 +157,7 @@ legacy per-project daemon rollback path.
153
157
  ufoo supports two Agent delivery modes, selected only from the host Agent's
154
158
  inherited `UFOO_SUBSCRIBER_ID` before any helper terminal is started:
155
159
 
156
- - Wrapper-managed Agents start through `ucodex`, `uclaude`, `uagy`, `ukimi`, or
160
+ - Wrapper-managed Agents start through `ucodex`, `uclaude`, `uagy`, `ugrok`, `ukimi`, or
157
161
  `ucode`. The wrapper provides `UFOO_SUBSCRIBER_ID`; ufoo monitors the shell
158
162
  activity and injection endpoint, so bus messages can be injected directly.
159
163
  These Agents reuse the environment identity and do not register through MCP
@@ -195,6 +199,7 @@ activate lazily.
195
199
  ```text
196
200
  /launch codex reviewer
197
201
  /launch claude builder
202
+ /launch grok explorer
198
203
  /launch ucode fixer
199
204
  @reviewer inspect the current diff and list release risks
200
205
 
@@ -207,8 +212,8 @@ activate lazily.
207
212
  /open /path/to/project
208
213
  ```
209
214
 
210
- Direct wrapper commands such as `uclaude`, `ucodex`, `uagy`, and `ucode` are
211
- still available, but the normal ufoo workflow is to work from chat.
215
+ Direct wrapper commands such as `uclaude`, `ucodex`, `uagy`, `ugrok`, `ukimi`, and
216
+ `ucode` are still available, but the normal ufoo workflow is to work from chat.
212
217
 
213
218
  ### Initialization And Maintenance
214
219
 
package/bin/ufoo.js CHANGED
@@ -82,7 +82,7 @@ async function main() {
82
82
  const target = argv[1];
83
83
  if (!target) {
84
84
  console.error("Error: resume requires an agent type or nickname");
85
- console.error("Usage: ufoo resume <ucode|uclaude|ucodex|nickname>");
85
+ console.error("Usage: ufoo resume <ucode|uclaude|ucodex|ugrok|nickname>");
86
86
  console.error("");
87
87
  console.error("Examples:");
88
88
  console.error(" ufoo resume ucode # Start new ucode agent");
@@ -157,6 +157,9 @@ async function main() {
157
157
  } else if (agentType === "codex") {
158
158
  scriptName = "ucodex.js";
159
159
  displayName = "ucodex";
160
+ } else if (agentType === "grok") {
161
+ scriptName = "ugrok.js";
162
+ displayName = "ugrok";
160
163
  } else if (agentType === "kimi") {
161
164
  scriptName = "ukimi.js";
162
165
  displayName = "ukimi";
@@ -199,13 +202,15 @@ async function main() {
199
202
  scriptName = "uclaude.js";
200
203
  } else if (targetLower === "ucodex" || targetLower === "codex" || targetLower === "openai") {
201
204
  scriptName = "ucodex.js";
205
+ } else if (targetLower === "ugrok" || targetLower === "grok" || targetLower === "grok-build" || targetLower === "xai") {
206
+ scriptName = "ugrok.js";
202
207
  } else if (targetLower === "ukimi" || targetLower === "kimi" || targetLower === "kimi-cli" || targetLower === "kimi-code") {
203
208
  scriptName = "ukimi.js";
204
209
  } else {
205
210
  // Not a valid agent type - might be an offline agent nickname
206
211
  console.error(`Error: Agent '${target}' is not online and is not a valid agent type`);
207
212
  console.error("");
208
- console.error("Valid agent types: ucode, uclaude, ucodex, ukimi");
213
+ console.error("Valid agent types: ucode, uclaude, ucodex, ugrok, ukimi");
209
214
  console.error("");
210
215
  console.error("To see online agents, run: ufoo bus status");
211
216
  process.exitCode = 1;
package/bin/ugrok.js ADDED
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * ugrok: Launch Grok Build CLI (grok) and auto-join the ufoo event bus.
4
+ *
5
+ * Usage: ugrok [grok args...]
6
+ *
7
+ * Grok Build accepts an initial positional prompt and a --rules system
8
+ * prompt extension, so ufoo bootstrap is prepared before launch instead of
9
+ * relying on post-launch PTY injection.
10
+ */
11
+
12
+ const AgentLauncher = require("../src/agents/launch/launcher");
13
+ const { resolveDefaultManualBootstrap } = require("../src/agents/prompts/defaultBootstrap");
14
+
15
+ function extractUfooParamsFromArgs(args = []) {
16
+ const nextArgs = [];
17
+ let nickname = "";
18
+ let role = "";
19
+ for (let i = 0; i < args.length; i += 1) {
20
+ const arg = String(args[i] || "");
21
+ if (arg === "--nickname") {
22
+ if (i + 1 < args.length) {
23
+ nickname = String(args[i + 1]).trim();
24
+ i += 1;
25
+ }
26
+ continue;
27
+ }
28
+ if (arg.startsWith("--nickname=")) {
29
+ nickname = arg.slice("--nickname=".length).trim();
30
+ continue;
31
+ }
32
+ if (arg === "--role") {
33
+ if (i + 1 < args.length) {
34
+ role = String(args[i + 1]).trim();
35
+ i += 1;
36
+ }
37
+ continue;
38
+ }
39
+ if (arg.startsWith("--role=")) {
40
+ role = arg.slice("--role=".length).trim();
41
+ continue;
42
+ }
43
+ nextArgs.push(args[i]);
44
+ }
45
+ return { args: nextArgs, nickname, role };
46
+ }
47
+
48
+ const { args: cleanArgs, nickname, role } = extractUfooParamsFromArgs(process.argv.slice(2));
49
+ if (nickname) {
50
+ process.env.UFOO_NICKNAME = nickname;
51
+ }
52
+ if (role) {
53
+ process.env.UFOO_PROMPT_PROFILE = role;
54
+ }
55
+
56
+ const launcher = new AgentLauncher("grok", "grok");
57
+ const resolved = resolveDefaultManualBootstrap({
58
+ projectRoot: process.cwd(),
59
+ agentType: "grok",
60
+ args: cleanArgs,
61
+ env: process.env,
62
+ });
63
+
64
+ for (const [key, value] of Object.entries(resolved.env || {})) {
65
+ process.env[key] = String(value);
66
+ }
67
+
68
+ launcher.launch(resolved.args);
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "u-foo",
3
- "version": "3.0.29",
3
+ "version": "3.0.31",
4
4
  "description": "Multi-Agent Workspace Protocol. Just add u. claude → uclaude, codex → ucodex.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "homepage": "https://ufoo.dev",
@@ -27,6 +27,7 @@
27
27
  "uclaude": "bin/uclaude.js",
28
28
  "ucodex": "bin/ucodex.js",
29
29
  "uagy": "bin/uagy.js",
30
+ "ugrok": "bin/ugrok.js",
30
31
  "ukimi": "bin/ukimi.js",
31
32
  "ucode": "bin/ucode.js"
32
33
  },
@@ -53,6 +53,25 @@ const INPUT_PATTERNS = {
53
53
  /Yes, and run (?:in|without) sandbox/i, // Terminal command approval (sandbox toggle)
54
54
  /\bn\b\s*-\s*Don't run/i, // y/n/edit confirmation
55
55
  ],
56
+ // grok (Grok Build CLI) parks blocking reverse-requests for permission,
57
+ // ask_user_question, and exit_plan_mode plan approval. Source references:
58
+ // xai-grok-shell/src/session/pending_interaction.rs
59
+ // xai-grok-pager/src/views/{permission_view,question_view,plan_approval_view}.rs
60
+ grok: [
61
+ /Waiting on plan approval/i, // Plan approval status line
62
+ /No plan written\s*[\u2014-]\s*approve or request changes/i, // Empty-plan approval status
63
+ /# No plan written yet[\s\S]*Request changes[\s\S]*Quit/i, // Empty-plan approval preview
64
+ /Approve plan[\s\S]{0,120}Reject plan/i, // Legacy/alternate plan approval labels
65
+ /\bApprove\b[\s\S]{0,160}\bRequest changes\b[\s\S]{0,160}\bQuit\b/i, // Plan preview actions
66
+ /Plan approval requested/i, // Shell notification hook detail
67
+ /User question requested/i, // ask_user_question notification hook detail
68
+ /Tool permission requested/i, // Permission notification hook detail
69
+ /\bAllow once\b[\s\S]{0,180}\bNo, reject \(type to add feedback\)/i, // Permission rows
70
+ /\bAlways allow:[\s\S]{0,180}\bNo, reject \(type to add feedback\)/i, // Scoped permission rows
71
+ /\bUse\s+\u2190\s+\u2192\s+to choose permission scope\b/i, // Permission scope selector
72
+ /\bChat about this\b[\s\S]{0,180}\bSkip interview\b/i, // Plan-mode question bottom panel
73
+ /\bz\s+(?:\(\u25cb\)|\[ \])\s+Type your answer here\b/i, // Default question freeform row
74
+ ],
56
75
  // kimi (Kimi Code CLI) ink-style approval menus (verified against 0.27.0).
57
76
  kimi: [
58
77
  /Run this command\?/, // Bash command approval question
@@ -74,8 +93,42 @@ const FATAL_PATTERNS = {
74
93
  /Account ineligible/, // Generic account-state failure
75
94
  /FAILED_PRECONDITION/, // gRPC backend precondition reject
76
95
  ],
96
+ grok: [
97
+ /Run [`'"]?grok login[`'"]? first/i,
98
+ /set XAI_API_KEY/i,
99
+ /not authenticated/i,
100
+ /reached your free Grok Build usage limit/i,
101
+ /subscription:free-usage-exhausted/i,
102
+ /SuperGrok subscription required/i,
103
+ ],
77
104
  };
78
105
 
106
+ // Grok Build continuously redraws its welcome screen/logo while it is waiting
107
+ // for a prompt. Those redraws are PTY output, but they do not represent model
108
+ // work. Keep the screen markers narrow enough that normal model output cannot
109
+ // accidentally acquire the idle-screen latch.
110
+ const GROK_IDLE_MENU_LABELS = [
111
+ /\bGrok Build\b/i,
112
+ /\bNew worktree\b/i,
113
+ /\bResume session\b/i,
114
+ /\bChangelog\b/i,
115
+ /\bQuit\b/i,
116
+ ];
117
+
118
+ const GROK_IDLE_FOOTER_PATTERN = /\bgrok-build\b[\s\S]{0,240}(?:Enter:run|Type:(?:custom command|change task))/i;
119
+
120
+ const GROK_DECORATIVE_CHARACTERS = /[\s\u00b7\u2500-\u259f\u2800-\u28ff\u2b00-\u2bff]/gu;
121
+
122
+ function stripGrokTerminalFragments(text = "") {
123
+ return String(text)
124
+ // PTY chunks can split CSI sequences, leaving fragments such as
125
+ // `20;20;20m` or `54;7H` after the normal ANSI pass.
126
+ .replace(/(?:\d{1,3};)*\d{1,3}[A-Za-z]/g, "")
127
+ .replace(/\?[0-9;]*[A-Za-z]/g, "")
128
+ // A lone final CSI byte can arrive in its own chunk.
129
+ .replace(/(^|[\s;])[A-Za-z](?=$|[\s;])/g, "$1");
130
+ }
131
+
79
132
  const COMMON_PATTERNS = [
80
133
  /Continue\?\s*$/m, // Line-ending "Continue?"
81
134
  /Proceed\?\s*$/m, // Line-ending "Proceed?"
@@ -138,6 +191,7 @@ class ActivityDetector {
138
191
  this.blockedTimer = null;
139
192
  this.quietTimer = null;
140
193
  this.quietToken = 0;
194
+ this.grokIdleScreenActive = false;
141
195
  }
142
196
 
143
197
  /**
@@ -187,6 +241,7 @@ class ActivityDetector {
187
241
  * - resets buffer by default when coming from non-WORKING states
188
242
  */
189
243
  markWorking(options = {}) {
244
+ this.grokIdleScreenActive = false;
190
245
  const hasResetFlag = Object.prototype.hasOwnProperty.call(options, "resetBuffer");
191
246
  const resetBuffer = hasResetFlag ? Boolean(options.resetBuffer) : this.state !== ACTIVITY_STATES.working;
192
247
  this._clearBlockedTimer();
@@ -221,6 +276,19 @@ class ActivityDetector {
221
276
  const normalized = this._normalizeOutput(text);
222
277
  if (!normalized) return;
223
278
  if (!this._hasMeaningfulOutput(normalized)) return;
279
+
280
+ // Once Grok's welcome screen has been identified, ignore its decorative
281
+ // logo redraws. A real prompt/output clears the latch; the scheduler's
282
+ // markWorking() also clears it immediately before a bus injection.
283
+ if (this.agentType === "grok" && this.grokIdleScreenActive) {
284
+ const candidate = `${this.buffer}\n${normalized}`;
285
+ if (this._isGrokIdleScreen(candidate) || this._isGrokDecorativeOutput(normalized)) {
286
+ this._clearQuietTimer();
287
+ return;
288
+ }
289
+ this.grokIdleScreenActive = false;
290
+ }
291
+
224
292
  if (this.state === ACTIVITY_STATES.starting) {
225
293
  if (!this.startOnOutput) return;
226
294
  this._setState(ACTIVITY_STATES.working, "output");
@@ -232,6 +300,14 @@ class ActivityDetector {
232
300
  this.buffer = this.buffer.slice(-this.bufferSize);
233
301
  }
234
302
 
303
+ if (this.agentType === "grok" && this._isGrokIdleScreen(this.buffer)) {
304
+ this._clearBlockedTimer();
305
+ this._clearQuietTimer();
306
+ this.grokIdleScreenActive = true;
307
+ this._setState(ACTIVITY_STATES.idle, "grok:idle-screen");
308
+ return;
309
+ }
310
+
235
311
  if (this.state !== ACTIVITY_STATES.working) {
236
312
  this._clearBlockedTimer();
237
313
  this._setState(ACTIVITY_STATES.working);
@@ -254,6 +330,25 @@ class ActivityDetector {
254
330
  return visible.length > 0;
255
331
  }
256
332
 
333
+ _isGrokIdleScreen(text) {
334
+ const value = String(text || "");
335
+ if (GROK_IDLE_FOOTER_PATTERN.test(value)) return true;
336
+
337
+ const menuMatches = GROK_IDLE_MENU_LABELS.reduce(
338
+ (count, pattern) => count + (pattern.test(value) ? 1 : 0),
339
+ 0
340
+ );
341
+ return menuMatches >= 3;
342
+ }
343
+
344
+ _isGrokDecorativeOutput(text) {
345
+ const residual = stripGrokTerminalFragments(text)
346
+ .replace(GROK_DECORATIVE_CHARACTERS, "")
347
+ .trim();
348
+ if (!residual) return true;
349
+ return !/[\p{L}\p{N}]/u.test(residual);
350
+ }
351
+
257
352
  _scheduleQuietClassification() {
258
353
  this.quietToken += 1;
259
354
  const quietToken = this.quietToken;
@@ -488,7 +488,7 @@ function buildSystemPrompt(context, options = {}) {
488
488
  ' "reply": "string",',
489
489
  ' "done": true,',
490
490
  ' "dispatch": [{"target":"broadcast|<agent-id>|<nickname>","message":"string","injection_mode":"immediate|queued (optional)","source":"optional"}],',
491
- ' "ops": [{"action":"launch|close|rename|role|cron","agent":"codex|claude|ucode","count":1,"agent_id":"id","nickname":"optional"}],',
491
+ ' "ops": [{"action":"launch|close|rename|role|cron","agent":"codex|claude|agy|grok|kimi|ucode","count":1,"agent_id":"id","nickname":"optional"}],',
492
492
  ` "tool_call": {"id":"optional","name":"${loopToolNameList}","arguments":{}}`,
493
493
  "}",
494
494
  `Available controller tools: ${loopToolNames.join(", ") || "dispatch_message, ack_bus, launch_agent"}.`,
@@ -516,7 +516,7 @@ function buildSystemPrompt(context, options = {}) {
516
516
  ' "reply": "string",',
517
517
  ];
518
518
  schemaLines.push(' "dispatch": [{"target":"broadcast|<agent-id>|<nickname>","message":"string","injection_mode":"immediate|queued (optional)","source":"optional"}],');
519
- schemaLines.push(' "ops": [{"action":"launch|close|rename|role|cron","agent":"codex|claude|ucode","count":1,"agent_id":"id","nickname":"optional","prompt_profile":"profile-id (for role)","operation":"start|list|stop","every":"30m","interval_ms":1800000,"at":"YYYY-MM-DD HH:mm","once_at_ms":1700000000000,"target":"agent-id|nickname|csv","targets":["agent-id"],"title":"optional short title","prompt":"message","id":"task-id|all"}],');
519
+ schemaLines.push(' "ops": [{"action":"launch|close|rename|role|cron","agent":"codex|claude|agy|grok|kimi|ucode","count":1,"agent_id":"id","nickname":"optional","prompt_profile":"profile-id (for role)","operation":"start|list|stop","every":"30m","interval_ms":1800000,"at":"YYYY-MM-DD HH:mm","once_at_ms":1700000000000,"target":"agent-id|nickname|csv","targets":["agent-id"],"title":"optional short title","prompt":"message","id":"task-id|all"}],');
520
520
  schemaLines.push(' "disambiguate": {"prompt":"string","candidates":[{"agent_id":"id","reason":"string"}]}');
521
521
  if (controllerMode === CONTROLLER_MODES.LOOP) {
522
522
  schemaLines.push(' "upgrade_to_loop_router": true');
@@ -630,7 +630,7 @@ function buildRouteAgentSystemPrompt(context, options = {}) {
630
630
 
631
631
  function shouldUseDirectProvider(value = "") {
632
632
  const provider = normalizeProvider(value);
633
- return provider === "ucode" || provider === "codex" || provider === "claude";
633
+ return provider === "ucode" || provider === "codex" || provider === "claude" || provider === "grok";
634
634
  }
635
635
 
636
636
  function stripMarkdownFence(text = "") {
@@ -230,10 +230,13 @@ function shouldShowLaunchBanner(agentType = "") {
230
230
  function computeInjectedSubmitDelayMs(agentType, text) {
231
231
  const normalizedAgent = String(agentType || "").trim().toLowerCase();
232
232
  const input = typeof text === "string" ? text : "";
233
- // Agy uses an ink-style TUI like claude-code, so it needs a similar grace
234
- // window before the input handler picks up injected text. Kimi Code is an
235
- // Ink TUI as well and gets the same treatment.
236
- const isInkStyle = normalizedAgent === "claude-code" || normalizedAgent === "agy" || normalizedAgent === "kimi";
233
+ // Agy, Grok Build, and Kimi Code use ink-style TUIs like claude-code, so
234
+ // they need a similar grace window before the input handler picks up
235
+ // injected text.
236
+ const isInkStyle = normalizedAgent === "claude-code"
237
+ || normalizedAgent === "agy"
238
+ || normalizedAgent === "grok"
239
+ || normalizedAgent === "kimi";
237
240
  let delayMs = isInkStyle ? 350 : 200;
238
241
  if (input.includes("\n")) {
239
242
  delayMs += isInkStyle ? 250 : 120;
@@ -267,10 +270,13 @@ async function injectPtyCommand(wrapper, agentType, commandText, source = "injec
267
270
  const normalizedAgentType = String(agentType || "").trim().toLowerCase();
268
271
  const submitDelayMs = computeInjectedSubmitDelayMs(agentType, text);
269
272
  wrapper.write(text);
270
- // claude-code, agy and kimi all run ink-style TUIs that accept a bare CR
273
+ // claude-code, agy, grok and kimi all run ink-style TUIs that accept a bare CR
271
274
  // to submit. codex needs the Esc-prefix trick to flush its multi-byte input
272
275
  // handler before the CR.
273
- const isInkStyle = normalizedAgentType === "claude-code" || normalizedAgentType === "agy" || normalizedAgentType === "kimi";
276
+ const isInkStyle = normalizedAgentType === "claude-code"
277
+ || normalizedAgentType === "agy"
278
+ || normalizedAgentType === "grok"
279
+ || normalizedAgentType === "kimi";
274
280
  if (isInkStyle) {
275
281
  await sleep(submitDelayMs);
276
282
  wrapper.write("\r");
@@ -838,18 +844,18 @@ class AgentLauncher {
838
844
  // Claude Code's Ink TUI renders ❯ prompt before the input handler
839
845
  // is fully mounted. Wait a short period for the TUI to be ready to
840
846
  // accept injected text, otherwise only the trailing CR is processed
841
- // and the injected slash command is lost. Agy uses the same ink-style TUI
842
- // so it gets the same grace window.
843
- if (this.agentType === "claude-code" || this.agentType === "agy") {
847
+ // and the injected slash command is lost. Agy and Grok use the
848
+ // same ink-style TUI pattern, so they get the same grace window.
849
+ if (this.agentType === "claude-code" || this.agentType === "agy" || this.agentType === "grok") {
844
850
  await new Promise((r) => setTimeout(r, 800));
845
851
  }
846
852
 
847
853
  // Inject /rename to set the session label (before AGENT_READY/bootstrap).
848
854
  // /rename is a slash command, completes instantly, doesn't hit the LLM.
849
855
  // Only when an explicit nickname was supplied (UFOO_NICKNAME from group
850
- // launch or user). Both claude-code and agy support /rename.
856
+ // launch or user). claude-code, agy, and grok support /rename.
851
857
  const explicitNickname = this._originalNickname || "";
852
- const supportsRenameSlash = this.agentType === "claude-code" || this.agentType === "agy";
858
+ const supportsRenameSlash = this.agentType === "claude-code" || this.agentType === "agy" || this.agentType === "grok";
853
859
  if (supportsRenameSlash && explicitNickname && wrapper.pty) {
854
860
  try {
855
861
  const safeNick = AgentLauncher._sanitizeNickname(explicitNickname);
@@ -125,9 +125,13 @@ function getOuterTerminalSize() {
125
125
  function computeInjectedSubmitDelayMs(agentType, text) {
126
126
  const normalizedAgent = String(agentType || "").trim().toLowerCase();
127
127
  const input = typeof text === "string" ? text : "";
128
- let delayMs = normalizedAgent === "claude-code" ? 350 : 200;
128
+ const directSubmit = normalizedAgent === "claude-code"
129
+ || normalizedAgent === "agy"
130
+ || normalizedAgent === "grok"
131
+ || normalizedAgent === "kimi";
132
+ let delayMs = directSubmit ? 350 : 200;
129
133
  if (input.includes("\n")) {
130
- delayMs += normalizedAgent === "claude-code" ? 250 : 120;
134
+ delayMs += directSubmit ? 250 : 120;
131
135
  }
132
136
  if (input.length > 512) {
133
137
  delayMs += Math.min(1200, Math.ceil(input.length / 512) * 90);
@@ -135,6 +139,14 @@ function computeInjectedSubmitDelayMs(agentType, text) {
135
139
  return delayMs;
136
140
  }
137
141
 
142
+ function isDirectSubmitAgent(agentType) {
143
+ const normalizedAgent = String(agentType || "").trim().toLowerCase();
144
+ return normalizedAgent === "claude-code"
145
+ || normalizedAgent === "agy"
146
+ || normalizedAgent === "grok"
147
+ || normalizedAgent === "kimi";
148
+ }
149
+
138
150
  function hasPromptArg(args = []) {
139
151
  if (!Array.isArray(args) || args.length === 0) return false;
140
152
  const lastIndex = args.length - 1;
@@ -159,11 +171,18 @@ function resolvePtyBootstrapArgs(agentType, extraArgs = [], {
159
171
  } = {}) {
160
172
  const normalizedAgent = String(agentType || "").trim().toLowerCase();
161
173
  const args = Array.isArray(extraArgs) ? extraArgs.slice() : [];
162
- if (normalizedAgent !== "codex" && normalizedAgent !== "claude" && normalizedAgent !== "claude-code") {
174
+ if (
175
+ normalizedAgent !== "codex"
176
+ && normalizedAgent !== "claude"
177
+ && normalizedAgent !== "claude-code"
178
+ && normalizedAgent !== "grok"
179
+ ) {
163
180
  return { args, env: {} };
164
181
  }
165
182
 
166
- const bootstrapAgentType = normalizedAgent === "codex" ? "codex" : "claude-code";
183
+ const bootstrapAgentType = normalizedAgent === "codex"
184
+ ? "codex"
185
+ : (normalizedAgent === "grok" ? "grok" : "claude-code");
167
186
  const resolved = resolveDefaultManualBootstrap({
168
187
  projectRoot,
169
188
  agentType: bootstrapAgentType,
@@ -195,6 +214,9 @@ function resolveCommand(agentType, extraArgs = [], options = {}) {
195
214
  if (normalizedAgent === "claude" || normalizedAgent === "claude-code") {
196
215
  return { command: "claude", args: [...extra], env: bootstrap.env };
197
216
  }
217
+ if (normalizedAgent === "grok") {
218
+ return { command: "grok", args: ["--no-alt-screen", ...extra], env: bootstrap.env };
219
+ }
198
220
  if (normalizedAgent === "ufoo" || normalizedAgent === "ucode" || normalizedAgent === "ufoo-code") {
199
221
  return { command: "ucode", args: [...extra], env: bootstrap.env };
200
222
  }
@@ -493,13 +515,13 @@ async function runPtyRunner({ projectRoot, agentType = "codex", extraArgs = [] }
493
515
  const req = JSON.parse(line);
494
516
  if (req.type === "inject" && req.command) {
495
517
  if (ptyProcess && ptyAlive) {
496
- const isClaude = agentType === "claude-code";
518
+ const directSubmit = isDirectSubmitAgent(agentType);
497
519
  const commandText = String(req.command);
498
520
  const submitDelayMs = computeInjectedSubmitDelayMs(agentType, commandText);
499
521
  ptyProcess.write(commandText);
500
- if (isClaude) {
501
- // Claude Code: send CR directly without ESC.
502
- // ESC before CR is interpreted as Alt+Enter (newline).
522
+ if (directSubmit) {
523
+ // Ink-style CLIs: send CR directly without ESC. ESC before
524
+ // CR can be interpreted as Alt+Enter or clear/reset.
503
525
  setTimeout(() => {
504
526
  if (ptyProcess && ptyAlive) {
505
527
  ptyProcess.write("\r");
@@ -1011,10 +1033,10 @@ async function runPtyRunner({ projectRoot, agentType = "codex", extraArgs = [] }
1011
1033
  if (ptyProcess && ptyAlive) {
1012
1034
  // Drop the local TUI input echo from any forwarded stream output.
1013
1035
  outputBuffer = "";
1014
- const isClaude = agentType === "claude-code";
1015
- if (isClaude) {
1016
- // Claude Code: send CR directly without ESC.
1017
- // ESC before CR is interpreted as Alt+Enter (newline).
1036
+ const directSubmit = isDirectSubmitAgent(agentType);
1037
+ if (directSubmit) {
1038
+ // Ink-style CLIs: send CR directly without ESC. ESC before CR
1039
+ // can be interpreted as Alt+Enter or clear/reset.
1018
1040
  ptyProcess.write("\r");
1019
1041
  } else {
1020
1042
  // Codex/others: ESC dismisses autocomplete, then CR submits.
@@ -109,6 +109,31 @@ class ReadyDetector {
109
109
  return false;
110
110
  }
111
111
 
112
+ /**
113
+ * Detect Grok Build CLI ready markers.
114
+ *
115
+ * grok renders an ink-style TUI whose mounted prompt footer includes
116
+ * `grok-build` plus key hints such as `Enter:run`, `Esc:reset`, and
117
+ * `Type:custom command`. Require the product marker to avoid treating
118
+ * generic chevrons or unrelated key-hint text as readiness.
119
+ */
120
+ _detectGrokReady(text) {
121
+ if (
122
+ text.includes("grok-build")
123
+ && (
124
+ text.includes("Enter:run")
125
+ || text.includes("Type:custom command")
126
+ || text.includes("Type:change task")
127
+ )
128
+ ) {
129
+ return true;
130
+ }
131
+ if (text.includes("grok-build") && /(?:^|\n)[ \t]*❯(?:[ \t]+[^\n]*)?[ \t]*$/m.test(text)) {
132
+ return true;
133
+ }
134
+ return false;
135
+ }
136
+
112
137
  /**
113
138
  * Detect kimi (Kimi Code CLI) ready markers.
114
139
  *
@@ -178,6 +203,8 @@ class ReadyDetector {
178
203
  isReady = this._detectCodexReady(this.buffer);
179
204
  } else if (this.agentType === "agy") {
180
205
  isReady = this._detectAgyReady(this.buffer);
206
+ } else if (this.agentType === "grok") {
207
+ isReady = this._detectGrokReady(this.buffer);
181
208
  } else if (this.agentType === "kimi") {
182
209
  isReady = this._detectKimiReady(this.buffer);
183
210
  } else if (this.agentType === "ufoo" || this.agentType === "ucode" || this.agentType === "ufoo-code") {