u-foo 4.0.1 → 4.0.2

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 CHANGED
@@ -332,9 +332,11 @@ select each layout directly. The one-child layout selects the most recently
332
332
  activated live internal agent, or the first agent when none has been activated.
333
333
  With no children, split modes remain selected while showing only the full-width
334
334
  main pane; new children appear automatically when they become available.
335
- In either split layout, `Esc` and `Ctrl+C` first leave the footer if it has focus,
336
- then return child focus to the main agent, then close the split. Drafts and
337
- running tasks are preserved while moving through these layers. Both keys also
335
+ When the input has focus and contains text, `Ctrl+C` first clears the selected
336
+ agent's draft without cancelling work or switching focus. `Esc` preserves the
337
+ draft. In either split layout, both keys first leave the footer if it has focus,
338
+ then return child focus to the main agent, then close the split. Running tasks
339
+ are preserved while moving through these layers. Both keys also
338
340
  dismiss command completion and follow the main input's cancellation and project
339
341
  return layers. At the main-only root, `Esc` keeps the application open and only
340
342
  `Ctrl+C` exits. `Ctrl+Q` or `/window main` closes either split directly.
package/bin/ucode.js CHANGED
@@ -16,6 +16,10 @@ const { resolveUcodeLaunch } = require("../src/code/launcher/ucode");
16
16
  const { prepareUcodeBootstrap } = require("../src/code/launcher/ucodeBootstrap");
17
17
  const { prepareUcodeRuntimeConfig } = require("../src/code/launcher/ucodeRuntimeConfig");
18
18
 
19
+ // CLI-wrapper startup text belongs to the parent agent. Native ucode loads
20
+ // its own system prompt; do not inject or pass the parent's text to its tools.
21
+ delete process.env.UFOO_STARTUP_BOOTSTRAP_TEXT;
22
+
19
23
  function stripAppendSystemPromptArgs(args = [], targetFile = "") {
20
24
  const normalizedTarget = String(targetFile || "").trim();
21
25
  if (!Array.isArray(args) || args.length === 0) return { args: [], removed: false };
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": "4.0.1",
3
+ "version": "4.0.2",
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",
@@ -26,26 +26,13 @@ const {
26
26
  } = require("../../runtime/terminal/adapters/hostAdapter");
27
27
  const PtyWrapper = require("./ptyWrapper");
28
28
  const ReadyDetector = require("./readyDetector");
29
+ const { setLauncherReady, isLauncherReady } = require("./launcherReadiness");
30
+ const STARTUP_WAIT_DIAGNOSTIC_MS = 10 * 60 * 1000;
29
31
  const {
30
32
  extractResumeConversationId,
31
33
  persistConversationId,
32
34
  } = require("./agyConversation");
33
35
 
34
- function setLauncherReady(projectRoot, subscriber, ready) {
35
- try {
36
- const file = getUfooPaths(projectRoot).agentsFile;
37
- if (!fs.existsSync(file)) return false;
38
- return updateAgentsData(file, (data) => {
39
- const meta = data.agents && data.agents[subscriber];
40
- if (!meta || meta.status === "inactive") return false;
41
- meta.launcher_ready = ready;
42
- return true;
43
- });
44
- } catch {
45
- return false;
46
- }
47
- }
48
-
49
36
  function connectSocket(sockPath) {
50
37
  return new Promise((resolve, reject) => {
51
38
  const client = net.createConnection(sockPath, () => resolve(client));
@@ -752,7 +739,7 @@ class AgentLauncher {
752
739
  const sessionId = result.sessionId || (subscriberId.split(":")[1] || "");
753
740
  const finalNickname = result.nickname || nickname || "";
754
741
 
755
- if (["codex", "claude-code"].includes(this.agentType)) {
742
+ if (["codex", "claude-code", "ucode"].includes(this.agentType)) {
756
743
  setLauncherReady(this.cwd, subscriberId, false);
757
744
  }
758
745
 
@@ -804,7 +791,11 @@ class AgentLauncher {
804
791
  }
805
792
 
806
793
  // 7. 启动命令(PTY wrapper或直接spawn)
807
- const startupBootstrapText = String(process.env.UFOO_STARTUP_BOOTSTRAP_TEXT || "").trim();
794
+ // Native ucode loads its bootstrap through the system-prompt file. A
795
+ // parent's wrapper bootstrap must never become user input in its TUI.
796
+ const startupBootstrapText = this.agentType === "ucode"
797
+ ? ""
798
+ : String(process.env.UFOO_STARTUP_BOOTSTRAP_TEXT || "").trim();
808
799
 
809
800
  // 7.1 PTY启用条件(显式开关 + 自动检测)
810
801
  let shouldUsePty = false;
@@ -869,8 +860,17 @@ class AgentLauncher {
869
860
  });
870
861
  // Heal daemon inject-stamp desync (disk working, detector idle).
871
862
  const agentsFilePath = getUfooPaths(this.cwd).agentsFile;
863
+ // Native ucode confirms readiness after the Rust client's authenticated
864
+ // handshake. Its bordered prompt is not a plain-text CLI ready marker.
865
+ const reconcileNativeReadiness = () => {
866
+ if (this.agentType === "ucode" && !readyDetector.ready
867
+ && isLauncherReady(this.cwd, subscriberId)) {
868
+ readyDetector.confirmNativeReady();
869
+ }
870
+ };
872
871
  const activityReconcileTimer = setInterval(() => {
873
872
  try {
873
+ reconcileNativeReadiness();
874
874
  reconcileDetectorOwnedActivity({
875
875
  detector: launcherActivityDetector,
876
876
  publisher: launcherPublisher,
@@ -948,15 +948,24 @@ class AgentLauncher {
948
948
 
949
949
  // Elapsed time cannot prove that a host can accept input. Preserve
950
950
  // queued work and report a slow startup instead of injecting blindly.
951
- const forceReadyTimer = setTimeout(() => {
952
- if (!readyDetector.ready) console.error(`[ufoo] Waiting for ${this.command} to become ready; queued work is retained.`);
953
- }, 10000);
951
+ const startupWaitingTimer = setTimeout(() => {
952
+ reconcileNativeReadiness();
953
+ if (!readyDetector.ready) {
954
+ // The child TUI owns this terminal. Parent stderr would be written
955
+ // at its input cursor, so keep asynchronous diagnostics in IO logs.
956
+ wrapper.writeLogEntry({
957
+ ts: Date.now(), dir: "diagnostic", source: "launcher",
958
+ event: "startup.waiting", agent_type: this.agentType,
959
+ text: `Waiting for ${this.agentType} to become ready; queued work is retained.`,
960
+ });
961
+ }
962
+ }, STARTUP_WAIT_DIAGNOSTIC_MS);
954
963
 
955
964
  // 设置退出回调(复用清理逻辑)
956
965
  wrapper.onExit = async ({ exitCode, signal }) => {
957
966
  await nativeMessages?.close();
958
967
  // 清理 timers
959
- clearTimeout(forceReadyTimer);
968
+ clearTimeout(startupWaitingTimer);
960
969
  clearInterval(activityReconcileTimer);
961
970
  launcherActivityDetector.destroy();
962
971
 
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ const fs = require("fs");
4
+ const { readJSON } = require("../../coordination/bus/utils");
5
+ const { getUfooPaths } = require("../../coordination/state/paths");
6
+ const { updateAgentsData } = require("../../coordination/state/agentsStore");
7
+
8
+ function setLauncherReady(projectRoot, subscriber, ready) {
9
+ if (!subscriber) return false;
10
+ try {
11
+ const file = getUfooPaths(projectRoot).agentsFile;
12
+ if (!fs.existsSync(file)) return false;
13
+ return updateAgentsData(file, (data) => {
14
+ const meta = data.agents && data.agents[subscriber];
15
+ if (!meta || meta.status === "inactive") return false;
16
+ meta.launcher_ready = ready;
17
+ return true;
18
+ });
19
+ } catch {
20
+ return false;
21
+ }
22
+ }
23
+
24
+ function isLauncherReady(projectRoot, subscriber) {
25
+ if (!subscriber) return false;
26
+ try {
27
+ const data = readJSON(getUfooPaths(projectRoot).agentsFile, null);
28
+ const meta = data && data.agents && data.agents[subscriber];
29
+ return Boolean(meta && meta.status !== "inactive" && meta.launcher_ready === true);
30
+ } catch {
31
+ return false;
32
+ }
33
+ }
34
+
35
+ module.exports = { setLauncherReady, isLauncherReady };
@@ -179,11 +179,14 @@ class PtyWrapper {
179
179
 
180
180
  // 进程退出
181
181
  this._ptyExitHandler = ({ exitCode, signal }) => {
182
+ // cleanup clears callbacks along with streams. Preserve the launcher's
183
+ // exit handler so natural child exits still clean up the wrapper host.
184
+ const onExit = this.onExit;
182
185
  this.cleanup();
183
186
 
184
187
  // 回调给launcher处理退出(不直接process.exit)
185
- if (this.onExit) {
186
- this.onExit({ exitCode, signal });
188
+ if (onExit) {
189
+ onExit({ exitCode, signal });
187
190
  }
188
191
  };
189
192
  this.pty.onExit(this._ptyExitHandler);
@@ -10,9 +10,16 @@ const { systemBlocksToAnthropicPayload } = require("./transports/systemBlocks");
10
10
  const { buildResponsesPayload, isResponsesKeepalive, responseEventDelta, parseResponsesEvents, parseResponsesSsePayload } = require("./transports/responsesProtocol");
11
11
 
12
12
  const DEFAULT_NATIVE_TIMEOUT_MS = 43200000;
13
+ const DEFAULT_NATIVE_CONNECT_TIMEOUT_MS = 10 * 60 * 1000;
13
14
  const DEFAULT_OPENAI_MAX_TOKENS = 32768;
14
15
  const DEFAULT_ANTHROPIC_MAX_TOKENS = 32768;
15
- const NATIVE_SSE_DISPATCHER_OPTIONS = Object.freeze({ headersTimeout: 0, bodyTimeout: 0 });
16
+ // Undici otherwise imposes its own 10-second connection deadline, regardless
17
+ // of the model task budget. Explicit cancellation/task deadlines still apply.
18
+ const NATIVE_SSE_DISPATCHER_OPTIONS = Object.freeze({
19
+ connectTimeout: DEFAULT_NATIVE_CONNECT_TIMEOUT_MS,
20
+ headersTimeout: 0,
21
+ bodyTimeout: 0,
22
+ });
16
23
  const ANTHROPIC_CACHE_CONTROL = Object.freeze({ type: "ephemeral" });
17
24
 
18
25
  function nowMs() {
package/src/code/repl.js CHANGED
@@ -26,6 +26,7 @@ const { summarizeSessionUsage, formatSessionUsageStatus } = require("./usageStor
26
26
  const { listUcodeCommandsForHelp } = require("./commands");
27
27
  const { applyUcodeModelCommand, suggestUcodeModels } = require("./modelCommand");
28
28
  const { applyUcodePlanCommand } = require("./context/planMode");
29
+ const { setLauncherReady } = require("../agents/launch/launcherReadiness");
29
30
 
30
31
  function printPrompt(stdout = process.stdout) {
31
32
  stdout.write("> ");
@@ -358,6 +359,7 @@ async function runUcodeCoreAgent({
358
359
  return runUcodeTui({
359
360
  stdin,
360
361
  stdout,
362
+ onReady: () => setLauncherReady(workspaceRoot, process.env.UFOO_SUBSCRIBER_ID || "", true),
361
363
  runSingleCommand,
362
364
  runNaturalLanguageTask,
363
365
  runUbusCommand,
@@ -159,6 +159,8 @@ class GlobalMcpHttpServer {
159
159
  this.activeRequests = new Map();
160
160
  this.httpRequestCount = 0;
161
161
  this.server = null;
162
+ this.startPromise = null;
163
+ this.stopPromise = null;
162
164
  this.startedAt = "";
163
165
  this.stopping = false;
164
166
  }
@@ -358,33 +360,46 @@ class GlobalMcpHttpServer {
358
360
  }
359
361
 
360
362
  async start() {
363
+ if (this.stopPromise) await this.stopPromise;
361
364
  if (this.server && this.server.listening) return this.getStatus();
365
+ if (this.startPromise) return this.startPromise;
366
+ const starting = this.startListener();
367
+ this.startPromise = starting;
368
+ try {
369
+ return await starting;
370
+ } finally {
371
+ this.startPromise = null;
372
+ }
373
+ }
374
+
375
+ async startListener() {
362
376
  if (this.host !== "127.0.0.1" && this.host !== "::1") {
363
377
  const err = new Error(`MCP HTTP host must be loopback, got: ${this.host}`);
364
378
  err.code = "UFOO_MCP_NON_LOOPBACK_HOST";
365
379
  throw err;
366
380
  }
367
381
  this.token = this.token || loadOrCreateMcpToken(this.tokenPath);
368
- this.server = http.createServer((req, res) => {
382
+ const server = http.createServer((req, res) => {
369
383
  void this.handleHttpRequest(req, res);
370
384
  });
371
- this.server.on("clientError", (_err, socket) => {
385
+ this.server = server;
386
+ server.on("clientError", (_err, socket) => {
372
387
  if (socket.writable) socket.end("HTTP/1.1 400 Bad Request\r\n\r\n");
373
388
  });
374
389
  await new Promise((resolve, reject) => {
375
390
  const onError = (err) => {
376
- this.server.off("listening", onListening);
391
+ server.off("listening", onListening);
377
392
  reject(err);
378
393
  };
379
394
  const onListening = () => {
380
- this.server.off("error", onError);
395
+ server.off("error", onError);
381
396
  resolve();
382
397
  };
383
- this.server.once("error", onError);
384
- this.server.once("listening", onListening);
385
- this.server.listen(this.port, this.host);
398
+ server.once("error", onError);
399
+ server.once("listening", onListening);
400
+ server.listen(this.port, this.host);
386
401
  });
387
- const address = this.server.address();
402
+ const address = server.address();
388
403
  if (address && typeof address === "object") this.port = address.port;
389
404
  this.startedAt = new Date().toISOString();
390
405
  this.writeEndpointFile();
@@ -393,8 +408,23 @@ class GlobalMcpHttpServer {
393
408
  }
394
409
 
395
410
  async stop() {
396
- if (this.stopping) return;
411
+ if (this.stopPromise) return this.stopPromise;
397
412
  this.stopping = true;
413
+ const stopping = this.stopListener();
414
+ this.stopPromise = stopping;
415
+ try {
416
+ await stopping;
417
+ } finally {
418
+ this.stopPromise = null;
419
+ this.stopping = false;
420
+ }
421
+ }
422
+
423
+ async stopListener() {
424
+ // Shutdown must wait for the listener and endpoint publication to settle.
425
+ // Otherwise a delayed listening event can access a cleared server or leave
426
+ // a live listener and stale endpoint after shutdown has already completed.
427
+ if (this.startPromise) await this.startPromise.catch(() => {});
398
428
  const sessions = Array.from(this.sessions.values());
399
429
  this.sessions.clear();
400
430
  await Promise.allSettled(sessions.map(async ({ transport, protocolServer }) => {
@@ -419,7 +449,6 @@ class GlobalMcpHttpServer {
419
449
  } catch {
420
450
  // Best effort; a PID mismatch is still visible in status diagnostics.
421
451
  }
422
- this.stopping = false;
423
452
  }
424
453
  }
425
454
 
@@ -208,6 +208,7 @@ async function runUcodeRust(props = {}) {
208
208
  const backgroundTasks = new Map();
209
209
  let backgroundSeq = 0;
210
210
  let requestExit = false;
211
+ let clientReady = false;
211
212
  const MARKDOWN_LOG_KINDS = new Set(["assistant", "error"]);
212
213
  const surface = createAgentSurface({ maxEntries: 4000 });
213
214
  const controller = createUcodeController({
@@ -761,6 +762,10 @@ async function runUcodeRust(props = {}) {
761
762
  socket.write(encodeMessage(snap));
762
763
  publishPendingInteraction();
763
764
  publishPlan();
765
+ if (!clientReady) {
766
+ clientReady = true;
767
+ if (typeof props.onReady === "function") props.onReady();
768
+ }
764
769
  },
765
770
  async onCommand(cmd) {
766
771
  const name = String(cmd.name || "");