u-foo 4.0.0 → 4.0.1

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 (154) hide show
  1. package/OBSERVABILITY.md +65 -0
  2. package/README.md +88 -30
  3. package/README.zh-CN.md +76 -26
  4. package/SKILLS/ufoo/SKILL.md +25 -1
  5. package/SKILLS/ufoo-bus/SKILL.md +25 -2
  6. package/bin/ufoo.js +3 -3
  7. package/dist/tui/darwin-arm64/ufoo-tui +0 -0
  8. package/dist/tui/darwin-x64/ufoo-tui +0 -0
  9. package/dist/tui/linux-arm64/ufoo-tui +0 -0
  10. package/dist/tui/linux-x64/ufoo-tui +0 -0
  11. package/package.json +6 -6
  12. package/src/agents/activity/activityDetector.js +1 -1
  13. package/src/agents/capabilities/agentManagement/service.js +40 -13
  14. package/src/agents/capabilities/coordination/index.js +1 -1
  15. package/src/agents/capabilities/taskReports/index.js +1 -1
  16. package/src/agents/controller/controllerToolExecutor.js +36 -20
  17. package/src/agents/controller/index.js +1 -6
  18. package/src/agents/internal/internalRunner.js +90 -56
  19. package/src/agents/launch/index.js +0 -1
  20. package/src/agents/launch/launcher.js +8 -8
  21. package/src/agents/launch/notifier.js +2 -2
  22. package/src/agents/launch/readyDetector.js +2 -2
  23. package/src/agents/profiles/main.js +1 -1
  24. package/src/agents/prompts/cooperation.js +14 -0
  25. package/src/agents/prompts/defaultBootstrap.js +1 -1
  26. package/src/agents/prompts/groupBootstrap.js +23 -7
  27. package/src/agents/prompts/mainAgent.js +11 -2
  28. package/src/agents/prompts/native/system.js +4 -1
  29. package/src/agents/prompts/native/ufoo.js +11 -3
  30. package/src/agents/prompts/promptProfiles.js +2 -0
  31. package/src/agents/prompts/reporting.js +16 -0
  32. package/src/agents/providers/claudeEventTranslator.js +3 -0
  33. package/src/agents/providers/claudeThreadProvider.js +3 -2
  34. package/src/agents/providers/clientIdentity.js +75 -0
  35. package/src/agents/providers/codexEventTranslator.js +23 -2
  36. package/src/agents/providers/codexThreadProvider.js +15 -6
  37. package/src/agents/providers/credentials/index.js +2 -0
  38. package/src/agents/providers/directAuthStatus.js +1 -1
  39. package/src/agents/providers/index.js +1 -1
  40. package/src/agents/providers/modelSettings.js +34 -0
  41. package/src/agents/providers/modelsCatalog.js +379 -0
  42. package/src/agents/providers/nativeTransport.js +50 -39
  43. package/src/agents/providers/runtimeConfig.js +10 -8
  44. package/src/agents/providers/thinkingLevels.js +10 -36
  45. package/src/agents/providers/transports/responsesProtocol.js +11 -6
  46. package/src/agents/providers/upstreamRuntime.js +135 -0
  47. package/src/agents/runtime/context/checkpointStore.js +38 -0
  48. package/src/agents/runtime/context/compaction.js +151 -0
  49. package/src/agents/runtime/context/contextBudget.js +93 -0
  50. package/src/agents/runtime/context/replayHistory.js +28 -0
  51. package/src/agents/runtime/context/runtimeStore.js +2 -1
  52. package/src/agents/runtime/core/agentLoop.js +99 -18
  53. package/src/agents/runtime/core/executionBudget.js +36 -0
  54. package/src/agents/runtime/createAgentRuntime.js +16 -4
  55. package/src/agents/runtime/prompts/responseLanguage.js +12 -0
  56. package/src/agents/runtime/protocol/runObservation.js +24 -0
  57. package/src/agents/runtime/protocol/traceContext.js +9 -0
  58. package/src/app/chat/ChatController.js +26 -53
  59. package/src/app/chat/agentDirectory.js +1 -16
  60. package/src/app/chat/bootstrap.js +1 -2
  61. package/src/app/chat/commandExecutor.js +93 -285
  62. package/src/app/chat/commands.js +32 -45
  63. package/src/app/chat/daemonMessageRouter.js +0 -45
  64. package/src/app/chat/historyStore.js +12 -48
  65. package/src/app/chat/inputSubmitHandler.js +7 -33
  66. package/src/app/chat/internalAgentLogHistory.js +19 -60
  67. package/src/app/chat/multiWindow/paneManager.js +10 -3
  68. package/src/app/chat/streamState.js +0 -4
  69. package/src/app/cli/features/init.js +5 -5
  70. package/src/app/cli/metricsCommands.js +68 -0
  71. package/src/app/cli/run.js +42 -3
  72. package/src/app/cli/traceCommands.js +36 -0
  73. package/src/code/agent.js +18 -13
  74. package/src/code/busConsumer.js +1 -3
  75. package/src/code/commands.js +1 -1
  76. package/src/code/context/assembler.js +7 -8
  77. package/src/code/context/stateCommit.js +2 -1
  78. package/src/code/internalThread.js +10 -3
  79. package/src/code/launcher/ucode.js +1 -1
  80. package/src/code/launcher/ucodeBootstrap.js +1 -1
  81. package/src/code/modelCommand.js +11 -35
  82. package/src/code/nativeRunner.js +55 -17
  83. package/src/code/providers/modelsCatalog.js +1 -317
  84. package/src/code/repl.js +2 -11
  85. package/src/code/sessionStore.js +3 -3
  86. package/src/code/taskDecomposer.js +18 -0
  87. package/src/code/toolBudget.js +1 -17
  88. package/src/config.js +22 -72
  89. package/src/coordination/bus/index.js +12 -3
  90. package/src/coordination/bus/inject.js +2 -2
  91. package/src/coordination/bus/message.js +15 -1
  92. package/src/coordination/bus/nickname.js +1 -1
  93. package/src/coordination/bus/subscriber.js +3 -2
  94. package/src/coordination/bus/utils.js +1 -1
  95. package/src/coordination/history/agentPerformance.js +279 -0
  96. package/src/coordination/history/agentTrace.js +249 -0
  97. package/src/coordination/state/workspaceAccess.js +1 -1
  98. package/src/orchestration/controller/index.js +1 -8
  99. package/src/orchestration/controller/launchRouting.js +1 -1
  100. package/src/orchestration/solo/commands.js +3 -1
  101. package/src/runtime/contracts/agentMode.js +11 -2
  102. package/src/runtime/contracts/uiProtocol.js +18 -19
  103. package/src/runtime/daemon/agentHost.js +57 -25
  104. package/src/runtime/daemon/agentRecoveryGroups.js +70 -0
  105. package/src/runtime/daemon/busBridge.js +1 -1
  106. package/src/runtime/daemon/controlPlaneService.js +1 -1
  107. package/src/runtime/daemon/groupOrchestrator.js +20 -5
  108. package/src/runtime/daemon/groupStatus.js +20 -0
  109. package/src/runtime/daemon/index.js +19 -44
  110. package/src/runtime/daemon/mcpServer.js +1 -1
  111. package/src/runtime/daemon/nicknameScope.js +1 -1
  112. package/src/runtime/daemon/ops.js +46 -23
  113. package/src/runtime/daemon/projectRuntimeGateway.js +2 -0
  114. package/src/runtime/daemon/promptRequest.js +92 -589
  115. package/src/runtime/daemon/status.js +5 -6
  116. package/src/tools/controllerSchemas.js +6 -2
  117. package/src/tools/handlers/tier2.js +4 -2
  118. package/src/tools/registry.js +4 -0
  119. package/src/tools/schemaFixtures.js +26 -2
  120. package/src/tools/tier0/readAgentMetrics.js +14 -0
  121. package/src/tools/tier0/readAgentTrace.js +12 -0
  122. package/src/ui/agentSettingsController.js +107 -0
  123. package/src/ui/agentSurface.js +1 -1
  124. package/src/ui/dashboardBridge.js +1 -1
  125. package/src/ui/format/banner.js +1 -4
  126. package/src/ui/format/index.js +14 -10
  127. package/src/ui/format/loopSummary.js +50 -0
  128. package/src/ui/format/markdownRenderer.js +3 -4
  129. package/src/ui/rustChatHost.js +191 -206
  130. package/src/ui/rustMultiSession.js +77 -36
  131. package/src/ui/rustUcodeHost.js +1 -1
  132. package/src/ui/settingsBridge.js +33 -16
  133. package/src/ui/toolMergeBridge.js +0 -4
  134. package/src/ui/uiHostServer.js +5 -8
  135. package/src/agents/controller/loopObservability.js +0 -200
  136. package/src/agents/controller/loopRuntime.js +0 -336
  137. package/src/agents/controller/ufooAgent.js +0 -830
  138. package/src/agents/launch/ptyRunner.js +0 -1135
  139. package/src/agents/providers/controllerJsonTransport.js +0 -28
  140. package/src/agents/providers/upstreamTransport.js +0 -698
  141. package/src/app/chat/agentBar.js +0 -135
  142. package/src/app/chat/agentSockets.js +0 -225
  143. package/src/app/chat/dashboardView.js +0 -405
  144. package/src/app/chat/rawKeyMap.js +0 -42
  145. package/src/app/chat/settingsController.js +0 -111
  146. package/src/coordination/history/controllerSummary.js +0 -23
  147. package/src/orchestration/controller/flags.js +0 -167
  148. package/src/orchestration/controller/gateRouter.js +0 -211
  149. package/src/orchestration/controller/routerFastPath.js +0 -22
  150. package/src/orchestration/controller/routerFinalize.js +0 -222
  151. package/src/orchestration/controller/shadowGuard.js +0 -280
  152. package/src/runtime/daemon/executionPaths.js +0 -30
  153. package/src/runtime/daemon/promptLoop.js +0 -136
  154. package/src/runtime/privacy/shadowDiff.js +0 -174
@@ -1,4 +1,4 @@
1
- const { defaultResolveTerminalApp, collectHostLaunchRequestContext, collectTerminalLaunchRequestContext, collectTmuxLaunchRequestContext } = require("./launchRequestContext");
1
+ const { normalizeInternalAgentType } = require("../../runtime/contracts/agentMode");
2
2
  const path = require("path");
3
3
  const EventBus = require("../../coordination/bus");
4
4
  const { IPC_REQUEST_TYPES } = require("../../runtime/contracts/eventContract");
@@ -9,20 +9,18 @@ const {
9
9
  saveConfig: saveProjectConfig,
10
10
  loadGlobalUcodeConfig,
11
11
  saveGlobalUcodeConfig,
12
- normalizeControllerMode,
13
- normalizeLaunchMode,
14
12
  SETTINGS_MODEL_DEFAULTS,
15
13
  defaultAgentModelForProvider,
16
- defaultRouterModelForProvider,
17
14
  } = require("../../config");
15
+ const { DEFAULT_THINKING_LEVEL } = require("../../agents/providers/thinkingLevels");
18
16
 
19
- const LAUNCH_MODE_OPTIONS = Object.freeze(["auto", "host", "terminal", "tmux", "internal"]);
20
17
  const AGENT_PROVIDER_OPTIONS = Object.freeze([
21
18
  { label: "codex", value: "codex-cli" },
22
19
  { label: "claude", value: "claude-cli" },
23
20
  { label: "agy", value: "agy-cli" },
24
21
  { label: "kimi", value: "kimi-cli" },
25
22
  { label: "grok", value: "grok-cli" },
23
+ { label: "custom", value: "custom" },
26
24
  ]);
27
25
  const { resolveTransport } = require("../../code/nativeRunner");
28
26
  const { resolveDisplayNickname } = require("../../runtime/daemon/nicknameScope");
@@ -57,6 +55,7 @@ function defaultCreateSkills(projectRoot) {
57
55
 
58
56
  function normalizeSettingsProvider(value = "", fallback = "codex-cli") {
59
57
  const text = String(value || "").trim().toLowerCase();
58
+ if (text === "custom") return "custom";
60
59
  if (text === "claude" || text === "claude-cli" || text === "claude-code" || text === "anthropic") {
61
60
  return "claude-cli";
62
61
  }
@@ -81,13 +80,10 @@ function agentProviderKey(value = "") {
81
80
  if (provider === "agy-cli") return "agy";
82
81
  if (provider === "kimi-cli") return "kimi";
83
82
  if (provider === "grok-cli") return "grok";
83
+ if (provider === "custom") return "custom";
84
84
  return "codex";
85
85
  }
86
86
 
87
- function defaultGateModelForProvider(value = "") {
88
- return defaultRouterModelForProvider(value);
89
- }
90
-
91
87
  async function withCapturedConsole(capture, fn) {
92
88
  const originalLog = console.log;
93
89
  const originalError = console.error;
@@ -111,7 +107,6 @@ function createCommandExecutor(options = {}) {
111
107
  const hasRestartDaemon = typeof options.restartDaemon === "function";
112
108
  const {
113
109
  projectRoot,
114
- internalOnly = false,
115
110
  getActiveProjectRoot = () => projectRoot,
116
111
  parseCommand = () => null,
117
112
  escapeBlessed = (value) => String(value || ""),
@@ -150,12 +145,12 @@ function createCommandExecutor(options = {}) {
150
145
  listProjects = () => [],
151
146
  getCurrentProject = () => ({ projectRoot }),
152
147
  switchProject = async () => ({ ok: false, error: "project switching unavailable" }),
153
- resolveTerminalApp = defaultResolveTerminalApp,
154
148
  sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
155
149
  schedule = (fn, ms) => setTimeout(fn, ms),
156
150
  clearLog = null,
157
151
  fetchModelsImpl = null,
158
152
  applyChatSettings = null,
153
+ openResumeMenu = null,
159
154
  } = options;
160
155
 
161
156
  if (!projectRoot) {
@@ -597,22 +592,16 @@ function createCommandExecutor(options = {}) {
597
592
  if (args.length === 0) {
598
593
  logMessage(
599
594
  "error",
600
- "{white-fg}✗{/white-fg} Usage: /launch <claude|codex|agy|grok|kimi|ucode> [nickname=<name>] [profile=<id>] [count=<n>] [scope=inplace|window]"
595
+ "{white-fg}✗{/white-fg} Usage: /launch <claude|codex|ucode> [nickname=<name>] [profile=<id>] [count=<n>]"
601
596
  );
602
597
  return;
603
598
  }
604
599
 
605
- const agentTypeInput = String(args[0] || "").trim().toLowerCase();
606
- // Accept friendly aliases the same way `ufoo launch` does in cli.js.
607
- let agentType = agentTypeInput;
608
- if (agentTypeInput === "antigravity" || agentTypeInput === "uagy") agentType = "agy";
609
- if (agentTypeInput === "grok-build" || agentTypeInput === "ugrok" || agentTypeInput === "xai") agentType = "grok";
610
- if (agentTypeInput === "kimi-cli" || agentTypeInput === "kimi-code" || agentTypeInput === "ukimi") agentType = "kimi";
611
- if (agentType !== "claude" && agentType !== "codex" && agentType !== "agy" && agentType !== "grok" && agentType !== "kimi" && agentType !== "ucode") {
612
- logMessage("error", "{white-fg}✗{/white-fg} Unknown agent type. Use: claude, codex, agy, grok, kimi, or ucode");
600
+ const normalizedAgent = normalizeInternalAgentType(args[0]);
601
+ if (!normalizedAgent) {
602
+ logMessage("error", "Unknown internal agent type. Use: claude, codex or ucode");
613
603
  return;
614
604
  }
615
- const normalizedAgent = agentType === "ucode" ? "ufoo" : agentType;
616
605
 
617
606
  const parsedOptions = {};
618
607
  for (let i = 1; i < args.length; i += 1) {
@@ -623,51 +612,9 @@ function createCommandExecutor(options = {}) {
623
612
  }
624
613
  }
625
614
 
626
- function normalizeLaunchScopeOption(value, fallback = "inplace") {
627
- const raw = String(value || "").trim().toLowerCase();
628
- if (!raw) return fallback;
629
- if (raw === "inplace" || raw === "same" || raw === "current" || raw === "tab" || raw === "pane") {
630
- return "inplace";
631
- }
632
- if (
633
- raw === "window"
634
- || raw === "separate"
635
- || raw === "new"
636
- || raw === "new-window"
637
- || raw === "external"
638
- || raw === "1"
639
- || raw === "true"
640
- || raw === "yes"
641
- || raw === "y"
642
- || raw === "on"
643
- ) {
644
- return "window";
645
- }
646
- if (raw === "0" || raw === "false" || raw === "no" || raw === "n" || raw === "off") {
647
- return "inplace";
648
- }
649
- return "";
650
- }
651
-
652
615
  const nickname = parsedOptions.nickname || "";
653
616
  const promptProfile = parsedOptions.profile || parsedOptions.prompt_profile || "";
654
617
  const count = parseInt(parsedOptions.count || "1", 10);
655
- const scopeRaw = parsedOptions.scope || parsedOptions.launch_scope || parsedOptions.window || "";
656
- let launchScope = normalizeLaunchScopeOption(scopeRaw, "inplace");
657
- if (scopeRaw && !launchScope) {
658
- logMessage("error", "{white-fg}✗{/white-fg} scope must be inplace|window");
659
- return;
660
- }
661
- const rawFlags = args
662
- .slice(1)
663
- .filter((arg) => !String(arg || "").includes("="))
664
- .map((arg) => String(arg || "").trim().toLowerCase())
665
- .filter(Boolean);
666
- for (const flag of rawFlags) {
667
- const normalized = normalizeLaunchScopeOption(flag, "");
668
- if (normalized) launchScope = normalized;
669
- }
670
- if (!launchScope) launchScope = "inplace";
671
618
  if (nickname && count > 1) {
672
619
  logMessage("error", "{white-fg}✗{/white-fg} nickname requires count=1");
673
620
  return;
@@ -684,12 +631,7 @@ function createCommandExecutor(options = {}) {
684
631
  count: Number.isFinite(count) ? count : 1,
685
632
  nickname,
686
633
  prompt_profile: promptProfile,
687
- launch_scope: launchScope,
688
- ...(internalOnly ? { internal_only: true, launch_scope: "inplace" } : {
689
- ...collectHostLaunchRequestContext(),
690
- ...collectTerminalLaunchRequestContext(resolveTerminalApp),
691
- ...collectTmuxLaunchRequestContext(),
692
- }),
634
+ internal_only: true,
693
635
  };
694
636
  send(request);
695
637
  schedule(requestStatus, 1000);
@@ -787,7 +729,7 @@ function createCommandExecutor(options = {}) {
787
729
 
788
730
  const profile = String(args[1] || "").trim();
789
731
  if (!profile) {
790
- logMessage("error", "{white-fg}✗{/white-fg} Usage: /solo run <prompt-profile> [agent=codex|claude|agy|grok|ucode] [nickname=<name>] [scope=inplace|window]");
732
+ logMessage("error", "{white-fg}✗{/white-fg} Usage: /solo run <prompt-profile> [agent=codex|claude|ucode] [nickname=<name>]");
791
733
  return;
792
734
  }
793
735
 
@@ -800,39 +742,23 @@ function createCommandExecutor(options = {}) {
800
742
  }
801
743
  }
802
744
 
803
- function normalizeLaunchScopeOption(value, fallback = "inplace") {
804
- const raw = String(value || "").trim().toLowerCase();
805
- if (!raw) return fallback;
806
- if (raw === "inplace" || raw === "same" || raw === "current" || raw === "tab" || raw === "pane") {
807
- return "inplace";
808
- }
809
- if (raw === "window" || raw === "separate" || raw === "new" || raw === "new-window" || raw === "external") {
810
- return "window";
811
- }
812
- return "";
813
- }
814
-
815
745
  const config = loadConfig(projectRoot);
816
- const agent = resolveSoloAgentType(config, parsedOptions.agent || parsedOptions.type || "");
817
- const nickname = String(parsedOptions.nickname || "").trim();
818
- const scopeRaw = parsedOptions.scope || parsedOptions.launch_scope || "";
819
- const launchScope = normalizeLaunchScopeOption(scopeRaw, "inplace");
820
- if (scopeRaw && !launchScope) {
821
- logMessage("error", "{white-fg}✗{/white-fg} scope must be inplace|window");
746
+ const requested = parsedOptions.agent || parsedOptions.type || "";
747
+ const agent = normalizeInternalAgentType(resolveSoloAgentType(config, requested));
748
+ if (!agent) {
749
+ logMessage("error", "Unknown internal agent type. Use: claude, codex or ucode");
822
750
  return;
823
751
  }
752
+ const nickname = String(parsedOptions.nickname || "").trim();
824
753
 
825
754
  try {
826
755
  send({
827
756
  type: IPC_REQUEST_TYPES.LAUNCH_AGENT,
828
- agent: agent === "ucode" ? "ufoo" : agent,
757
+ agent,
829
758
  count: 1,
830
759
  nickname,
831
760
  prompt_profile: profile,
832
- launch_scope: launchScope,
833
- ...collectHostLaunchRequestContext(),
834
- ...collectTerminalLaunchRequestContext(resolveTerminalApp),
835
- ...collectTmuxLaunchRequestContext(),
761
+ internal_only: true,
836
762
  });
837
763
  schedule(requestStatus, 1000);
838
764
  } catch (err) {
@@ -841,20 +767,19 @@ function createCommandExecutor(options = {}) {
841
767
  }
842
768
 
843
769
  async function handleResumeCommand(args = []) {
844
- const action = String(args[0] || "").toLowerCase();
845
- if (action === "list" || action === "ls") {
846
- const target = args[1] || "";
847
- const label = target ? ` (${target})` : "";
848
- logMessage("system", `{white-fg}⚙{/white-fg} Listing recoverable agents${label}...`);
849
- send({ type: IPC_REQUEST_TYPES.LIST_RECOVERABLE_AGENTS, target });
850
- schedule(requestStatus, 1000);
770
+ if (args.length === 0) {
771
+ if (typeof openResumeMenu === "function") await openResumeMenu();
772
+ else logMessage("system", "Choose an agent or group from the /resume menu.");
773
+ return;
774
+ }
775
+ if (args.length !== 1 || ["list", "ls"].includes(args[0])) {
776
+ logMessage("error", "Use /resume to select an agent or group; /resume list has been removed.");
851
777
  return;
852
778
  }
853
-
854
779
  const target = args[0] || "";
855
780
  const label = target ? ` (${target})` : "";
856
781
  logMessage("system", `{white-fg}⚙{/white-fg} Resuming agents${label}...`);
857
- send({ type: IPC_REQUEST_TYPES.RESUME_AGENTS, target });
782
+ send({ type: IPC_REQUEST_TYPES.RESUME_AGENTS, target, internal_only: true });
858
783
  schedule(requestStatus, 1000);
859
784
  }
860
785
 
@@ -998,18 +923,6 @@ function createCommandExecutor(options = {}) {
998
923
  return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
999
924
  }
1000
925
 
1001
- function clearUfooAgentIdentity() {
1002
- try {
1003
- const { getUfooPaths } = require("../../coordination/state/paths");
1004
- const agentDir = getUfooPaths(projectRoot).agentDir;
1005
- const fsModule = require("fs");
1006
- fsModule.rmSync(path.join(agentDir, "ufoo-agent.json"), { force: true });
1007
- fsModule.rmSync(path.join(agentDir, "ufoo-agent.history.jsonl"), { force: true });
1008
- } catch {
1009
- // Ignore cleanup failures.
1010
- }
1011
- }
1012
-
1013
926
  async function notifyChatSettings(patch = {}) {
1014
927
  if (typeof applyChatSettings !== "function") return;
1015
928
  try {
@@ -1019,46 +932,9 @@ function createCommandExecutor(options = {}) {
1019
932
  }
1020
933
  }
1021
934
 
1022
- async function handleModeCommand(args = []) {
1023
- const action = String(args[0] || "").trim().toLowerCase();
1024
- if (internalOnly) {
1025
- logMessage(action && !["internal", "show", "status"].includes(action) ? "error" : "system",
1026
- "ufoo dashboard uses internal agents only.");
1027
- return;
1028
- }
1029
- const config = loadConfig(projectRoot) || {};
1030
- const current = normalizeLaunchMode(config.launchMode || "auto");
1031
-
1032
- if (!action || action === "show" || action === "status") {
1033
- logMessage("system", "{cyan-fg}launch mode:{/cyan-fg}");
1034
- logMessage("system", ` • current: ${current}`);
1035
- logMessage("system", ` • options: ${LAUNCH_MODE_OPTIONS.join(", ")}`);
1036
- logMessage("system", " • use: /mode <auto|host|terminal|tmux|internal>");
1037
- return;
1038
- }
1039
-
1040
- if (!LAUNCH_MODE_OPTIONS.includes(action)) {
1041
- logMessage(
1042
- "error",
1043
- `{white-fg}✗{/white-fg} Unknown mode: ${action}. Use: ${LAUNCH_MODE_OPTIONS.join("|")}`
1044
- );
1045
- return;
1046
- }
1047
-
1048
- const next = normalizeLaunchMode(action);
1049
- if (next === current) {
1050
- logMessage("system", `{cyan-fg}launch mode:{/cyan-fg} already ${next}`);
1051
- return;
1052
- }
1053
-
1054
- saveConfig(projectRoot, { launchMode: next });
1055
- logMessage("system", `{white-fg}✓{/white-fg} Launch mode: ${next}`);
1056
- await notifyChatSettings({ launchMode: next });
1057
- await restartDaemon(projectRoot);
1058
- }
1059
-
1060
935
  async function handleProviderCommand(args = []) {
1061
936
  const action = String(args[0] || "").trim().toLowerCase();
937
+ if (action === "custom" && options.openAgentSettings) return options.openAgentSettings("custom");
1062
938
  const config = loadConfig(projectRoot) || {};
1063
939
  const current = normalizeSettingsProvider(config.agentProvider);
1064
940
  const labels = AGENT_PROVIDER_OPTIONS.map((opt) => opt.label).join(", ");
@@ -1086,8 +962,12 @@ function createCommandExecutor(options = {}) {
1086
962
  return;
1087
963
  }
1088
964
 
965
+ if (options.applyAgentSettings) {
966
+ const result = await options.applyAgentSettings({ agentProvider: next });
967
+ if (!result.ok) logMessage("error", result.error);
968
+ return;
969
+ }
1089
970
  saveConfig(projectRoot, { agentProvider: next });
1090
- clearUfooAgentIdentity();
1091
971
  logMessage("system", `{white-fg}✓{/white-fg} ufoo-agent: ${agentProviderKey(next)}`);
1092
972
  await notifyChatSettings({ agentProvider: next });
1093
973
  await restartDaemon(projectRoot);
@@ -1337,11 +1217,7 @@ function createCommandExecutor(options = {}) {
1337
1217
  alias,
1338
1218
  instance,
1339
1219
  dry_run: dryRun,
1340
- ...(internalOnly ? { internal_only: true } : {
1341
- ...collectHostLaunchRequestContext(),
1342
- ...collectTerminalLaunchRequestContext(resolveTerminalApp),
1343
- ...collectTmuxLaunchRequestContext(),
1344
- }),
1220
+ internal_only: true,
1345
1221
  });
1346
1222
  schedule(requestStatus, 1000);
1347
1223
  return;
@@ -1428,12 +1304,6 @@ function createCommandExecutor(options = {}) {
1428
1304
  return;
1429
1305
  }
1430
1306
 
1431
- if (section === "router") {
1432
- const subArgs = args.slice(1);
1433
- await handleRouterSettingsCommand(subArgs);
1434
- return;
1435
- }
1436
-
1437
1307
  if (section === "ucode") {
1438
1308
  const subArgs = args.slice(1);
1439
1309
  if (subArgs.length === 0) {
@@ -1444,7 +1314,7 @@ function createCommandExecutor(options = {}) {
1444
1314
  return;
1445
1315
  }
1446
1316
 
1447
- logMessage("error", "{white-fg}✗{/white-fg} Unknown settings section. Use: show, agent, router, ucode");
1317
+ logMessage("error", "{white-fg}✗{/white-fg} Unknown settings section. Use: show, agent, ucode");
1448
1318
  }
1449
1319
 
1450
1320
  async function handleSettingsOverviewCommand() {
@@ -1452,22 +1322,35 @@ function createCommandExecutor(options = {}) {
1452
1322
  const agentProvider = normalizeSettingsProvider(config.agentProvider);
1453
1323
  const agentKey = agentProviderKey(agentProvider);
1454
1324
  const agentModel = String(config.agentModel || "").trim();
1455
- const routerMode = normalizeControllerMode(config.controllerMode);
1456
- const routerProvider = String(config.routerProvider || "").trim();
1457
- const routerModel = String(config.routerModel || "").trim();
1458
1325
  const ucodeConfig = loadUcodeConfig() || {};
1459
1326
  const ucodeProvider = String(ucodeConfig.ucodeProvider || "").trim();
1460
1327
  const ucodeModel = String(ucodeConfig.ucodeModel || "").trim();
1461
1328
 
1462
1329
  logMessage("system", "{cyan-fg}settings:{/cyan-fg}");
1463
1330
  logMessage("system", ` • agent: ${agentKey} · model ${agentModel || `(unset, recommended ${defaultAgentModelForProvider(agentProvider)})`}`);
1464
- logMessage("system", ` • router: mode ${routerMode} · provider ${routerProvider || "(unset)"} · model ${routerModel || "(unset)"}`);
1465
1331
  logMessage("system", ` • ucode: provider ${ucodeProvider || "(unset)"} · model ${ucodeModel || "(unset)"}`);
1466
- logMessage("system", " • use: /settings agent | /settings router | /settings ucode");
1332
+ logMessage("system", " • use: /settings agent | /settings ucode");
1467
1333
  }
1468
1334
 
1469
1335
  async function handleAgentSettingsCommand(args = []) {
1470
1336
  const first = String(args[0] || "").trim().toLowerCase();
1337
+ if (first === "custom" && options.openAgentSettings) return options.openAgentSettings("custom");
1338
+ if (first === "model") {
1339
+ if (args.length === 1 && options.openAgentSettings) return options.openAgentSettings("model");
1340
+ if (options.applyAgentModel) {
1341
+ const result = await options.applyAgentModel(args[1], args[2]);
1342
+ if (!result.ok) logMessage("error", result.error);
1343
+ return;
1344
+ }
1345
+ }
1346
+ if (first === "thinking") {
1347
+ if (args.length === 1 && options.openAgentSettings) return options.openAgentSettings("thinking");
1348
+ if (options.applyAgentSettings) {
1349
+ const result = await options.applyAgentSettings({ agent_thinking: args[1] });
1350
+ if (!result.ok) logMessage("error", result.error);
1351
+ return;
1352
+ }
1353
+ }
1471
1354
  const hasInlineKv = args.some((item) => String(item || "").includes("="));
1472
1355
  const action = !first ? "show" : (hasInlineKv ? "set" : first);
1473
1356
 
@@ -1480,7 +1363,12 @@ function createCommandExecutor(options = {}) {
1480
1363
  logMessage("system", ` • provider: ${key}`);
1481
1364
  logMessage("system", ` • model: ${model || `(unset, recommended ${defaultAgentModelForProvider(provider)})`}`);
1482
1365
  logMessage("system", ` • defaults: codex=${SETTINGS_MODEL_DEFAULTS.agent.codex}, claude=${SETTINGS_MODEL_DEFAULTS.agent.claude}`);
1483
- logMessage("system", " • use: /settings agent set provider=<codex|claude|agy> model=<id>");
1366
+ logMessage("system", ` • thinking: ${config.agentThinking || "medium"}`);
1367
+ if (provider === "custom") {
1368
+ logMessage("system", ` • url: ${config.agentBaseUrl || "(unset)"}`);
1369
+ logMessage("system", ` • key: ${config.agentApiKey ? "(configured)" : "(unset)"}`);
1370
+ }
1371
+ logMessage("system", " • use: /settings agent custom | model | thinking");
1484
1372
  return;
1485
1373
  }
1486
1374
 
@@ -1492,10 +1380,14 @@ function createCommandExecutor(options = {}) {
1492
1380
  ? "agy-cli"
1493
1381
  : (action === "kimi" ? "kimi-cli" : (action === "grok" ? "grok-cli" : "codex-cli")));
1494
1382
  const model = String(kv.model || defaultAgentModelForProvider(provider)).trim();
1495
- saveConfig(projectRoot, {
1496
- agentProvider: provider,
1497
- agentModel: model,
1498
- });
1383
+ const patch = { agentProvider: provider, agentModel: model,
1384
+ ...(action === "codex" ? { agentThinking: DEFAULT_THINKING_LEVEL } : {}) };
1385
+ if (options.applyAgentSettings) {
1386
+ const result = await options.applyAgentSettings(patch);
1387
+ if (!result.ok) logMessage("error", result.error);
1388
+ return;
1389
+ }
1390
+ saveConfig(projectRoot, patch);
1499
1391
  logMessage("system", "{white-fg}✓{/white-fg} ufoo-agent config updated");
1500
1392
  logMessage("system", ` • provider: ${agentProviderKey(provider)}`);
1501
1393
  logMessage("system", ` • model: ${model}`);
@@ -1528,6 +1420,12 @@ function createCommandExecutor(options = {}) {
1528
1420
  return;
1529
1421
  }
1530
1422
 
1423
+ if (options.applyAgentSettings) {
1424
+ const result = await options.applyAgentSettings(updates);
1425
+ if (!result.ok) logMessage("error", result.error);
1426
+ return;
1427
+ }
1428
+
1531
1429
  saveConfig(projectRoot, updates);
1532
1430
  logMessage("system", "{white-fg}✓{/white-fg} ufoo-agent config updated");
1533
1431
  if (Object.prototype.hasOwnProperty.call(updates, "agentProvider")) {
@@ -1551,110 +1449,18 @@ function createCommandExecutor(options = {}) {
1551
1449
  logMessage("error", "{white-fg}✗{/white-fg} Usage: /settings agent clear [provider|model|all]");
1552
1450
  return;
1553
1451
  }
1554
- saveConfig(projectRoot, updates);
1555
- logMessage("system", "{white-fg}✓{/white-fg} ufoo-agent config cleared");
1556
- await restartDaemon(projectRoot);
1557
- return;
1558
- }
1559
-
1560
- logMessage("error", "{white-fg}✗{/white-fg} Unknown settings agent action. Use: show, set, clear, codex, claude, agy, kimi, grok");
1561
- }
1562
-
1563
- async function handleRouterSettingsCommand(args = []) {
1564
- const first = String(args[0] || "").trim().toLowerCase();
1565
- const hasInlineKv = args.some((item) => String(item || "").includes("="));
1566
- const action = !first ? "show" : (hasInlineKv ? "set" : first);
1567
-
1568
- if (action === "show" || action === "status") {
1569
- const config = loadConfig(projectRoot) || {};
1570
- const mode = normalizeControllerMode(config.controllerMode);
1571
- logMessage("system", "{cyan-fg}gate router config:{/cyan-fg}");
1572
- logMessage("system", ` • controllerMode: ${mode}`);
1573
- logMessage("system", ` • provider: ${String(config.routerProvider || "").trim() || "(unset)"}`);
1574
- logMessage("system", ` • model: ${String(config.routerModel || "").trim() || "(unset)"}`);
1575
- logMessage("system", " • allowed modes: main | loop | legacy | shadow");
1576
- logMessage("system", ` • defaults: codex=${SETTINGS_MODEL_DEFAULTS.router.codex}, claude=${SETTINGS_MODEL_DEFAULTS.router.claude}`);
1577
- return;
1578
- }
1579
-
1580
- if (action === "codex" || action === "claude") {
1581
- const kv = parseKeyValueArgs(args.slice(1));
1582
- const provider = action;
1583
- const model = String(kv.model || defaultGateModelForProvider(provider)).trim();
1584
- saveConfig(projectRoot, {
1585
- routerProvider: provider,
1586
- routerModel: model,
1587
- });
1588
- logMessage("system", "{white-fg}✓{/white-fg} gate router config updated");
1589
- logMessage("system", ` • provider: ${provider}`);
1590
- logMessage("system", ` • model: ${model}`);
1591
- await restartDaemon(projectRoot);
1592
- return;
1593
- }
1594
-
1595
- if (action === "set") {
1596
- const kvArgs = hasInlineKv ? args : args.slice(1);
1597
- const kv = parseKeyValueArgs(kvArgs);
1598
- const updates = {};
1599
-
1600
- if (Object.prototype.hasOwnProperty.call(kv, "mode")) {
1601
- const nextMode = normalizeControllerMode(kv.mode);
1602
- if (!["main", "loop", "legacy", "shadow"].includes(nextMode) || nextMode !== String(kv.mode || "").trim().toLowerCase()) {
1603
- logMessage("error", "{white-fg}✗{/white-fg} Usage: /settings router set mode=<main|loop|legacy|shadow> provider=<id> model=<id>");
1604
- return;
1605
- }
1606
- updates.controllerMode = nextMode;
1607
- }
1608
- if (Object.prototype.hasOwnProperty.call(kv, "provider")) updates.routerProvider = String(kv.provider || "").trim();
1609
- if (Object.prototype.hasOwnProperty.call(kv, "model")) updates.routerModel = String(kv.model || "").trim();
1610
-
1611
- if (Object.keys(updates).length === 0) {
1612
- logMessage("error", "{white-fg}✗{/white-fg} Usage: /settings router set mode=<main|loop|legacy|shadow> provider=<id> model=<id>");
1613
- return;
1614
- }
1615
-
1616
- saveConfig(projectRoot, updates);
1617
- logMessage("system", "{white-fg}✓{/white-fg} gate router config updated");
1618
- if (Object.prototype.hasOwnProperty.call(updates, "controllerMode")) {
1619
- logMessage("system", ` • controllerMode: ${updates.controllerMode}`);
1620
- }
1621
- if (Object.prototype.hasOwnProperty.call(updates, "routerProvider")) {
1622
- logMessage("system", ` • provider: ${updates.routerProvider || "(unset)"}`);
1623
- }
1624
- if (Object.prototype.hasOwnProperty.call(updates, "routerModel")) {
1625
- logMessage("system", ` • model: ${updates.routerModel || "(unset)"}`);
1626
- }
1627
- await restartDaemon(projectRoot);
1628
- return;
1629
- }
1630
-
1631
- if (action === "clear") {
1632
- const fieldsRaw = args.slice(1).map((item) => String(item || "").trim().toLowerCase()).filter(Boolean);
1633
- const fields = fieldsRaw.length === 0 ? ["all"] : fieldsRaw;
1634
- const updates = {};
1635
- const clearAll = fields.includes("all");
1636
- if (clearAll || fields.includes("mode")) updates.controllerMode = "main";
1637
- if (clearAll || fields.includes("provider")) updates.routerProvider = "";
1638
- if (clearAll || fields.includes("model")) updates.routerModel = "";
1639
- if (Object.keys(updates).length === 0) {
1640
- logMessage("error", "{white-fg}✗{/white-fg} Usage: /settings router clear [mode|provider|model|all]");
1452
+ if (options.applyAgentSettings) {
1453
+ const result = await options.applyAgentSettings(updates);
1454
+ if (!result.ok) logMessage("error", result.error);
1641
1455
  return;
1642
1456
  }
1643
1457
  saveConfig(projectRoot, updates);
1644
- logMessage("system", "{white-fg}✓{/white-fg} gate router config cleared");
1458
+ logMessage("system", "{white-fg}✓{/white-fg} ufoo-agent config cleared");
1645
1459
  await restartDaemon(projectRoot);
1646
1460
  return;
1647
1461
  }
1648
1462
 
1649
- const nextMode = normalizeControllerMode(action);
1650
- if (nextMode !== action || !["main", "loop", "legacy", "shadow"].includes(nextMode)) {
1651
- logMessage("error", "{white-fg}✗{/white-fg} Usage: /settings router <main|loop|legacy|shadow>");
1652
- return;
1653
- }
1654
-
1655
- saveConfig(projectRoot, { controllerMode: nextMode });
1656
- logMessage("system", `{white-fg}✓{/white-fg} gate router mode set to ${nextMode}`);
1657
- await restartDaemon(projectRoot);
1463
+ logMessage("error", "{white-fg}✗{/white-fg} Unknown settings agent action. Use: show, set, clear, codex, claude, agy, kimi, grok");
1658
1464
  }
1659
1465
 
1660
1466
  function parseUcodeConfigKv(args = []) {
@@ -1760,7 +1566,13 @@ function createCommandExecutor(options = {}) {
1760
1566
  const kvArgs = hasInlineKv ? args : args.slice(1);
1761
1567
  const kv = parseUcodeConfigKv(kvArgs);
1762
1568
  const updates = {};
1763
- if (Object.prototype.hasOwnProperty.call(kv, "provider")) updates.ucodeProvider = String(kv.provider || "").trim();
1569
+ if (Object.prototype.hasOwnProperty.call(kv, "provider")) {
1570
+ updates.ucodeProvider = String(kv.provider || "").trim();
1571
+ if (["anthropic", "anthropic-messages"].includes(updates.ucodeProvider.toLowerCase())) {
1572
+ logMessage("error", "Custom APIs use OpenAI protocol. Use provider=openai; internal Claude retains its native connection.");
1573
+ return;
1574
+ }
1575
+ }
1764
1576
  if (Object.prototype.hasOwnProperty.call(kv, "model")) updates.ucodeModel = String(kv.model || "").trim();
1765
1577
  if (Object.prototype.hasOwnProperty.call(kv, "url")) updates.ucodeBaseUrl = String(kv.url || "").trim();
1766
1578
  if (Object.prototype.hasOwnProperty.call(kv, "baseurl")) updates.ucodeBaseUrl = String(kv.baseurl || "").trim();
@@ -1769,9 +1581,12 @@ function createCommandExecutor(options = {}) {
1769
1581
  if (Object.prototype.hasOwnProperty.call(kv, "apikey")) updates.ucodeApiKey = String(kv.apikey || "").trim();
1770
1582
  if (Object.prototype.hasOwnProperty.call(kv, "api_key")) updates.ucodeApiKey = String(kv.api_key || "").trim();
1771
1583
  if (Object.prototype.hasOwnProperty.call(kv, "token")) updates.ucodeApiKey = String(kv.token || "").trim();
1584
+ if ((updates.ucodeBaseUrl || updates.ucodeApiKey) && !updates.ucodeProvider && !(loadUcodeConfig() || {}).ucodeProvider) {
1585
+ updates.ucodeProvider = "openai";
1586
+ }
1772
1587
 
1773
1588
  if (Object.keys(updates).length === 0) {
1774
- logMessage("error", "{white-fg}✗{/white-fg} Usage: /settings ucode set provider=<openai|anthropic> model=<id> url=<baseUrl> key=<apiKey>");
1589
+ logMessage("error", "{white-fg}✗{/white-fg} Usage: /settings ucode set provider=openai model=<id> url=<baseUrl> key=<apiKey>");
1775
1590
  return;
1776
1591
  }
1777
1592
 
@@ -1927,11 +1742,11 @@ function createCommandExecutor(options = {}) {
1927
1742
  logMessage("error", "{white-fg}✗{/white-fg} /clear is not available in this view");
1928
1743
  }
1929
1744
  return true;
1930
- case "multi":
1931
- if (typeof options.toggleMultiWindow === "function") {
1932
- await (args.length ? options.toggleMultiWindow(args) : options.toggleMultiWindow());
1745
+ case "window":
1746
+ if (typeof options.setWindowLayout === "function") {
1747
+ await options.setWindowLayout(args);
1933
1748
  } else {
1934
- logMessage("error", "{white-fg}✗{/white-fg} Multi-window mode is not available");
1749
+ logMessage("error", "{white-fg}✗{/white-fg} Window layouts are not available");
1935
1750
  }
1936
1751
  return true;
1937
1752
  case "mcp":
@@ -1979,9 +1794,6 @@ function createCommandExecutor(options = {}) {
1979
1794
  case "cron":
1980
1795
  await handleCronCommand(args);
1981
1796
  return true;
1982
- case "mode":
1983
- await handleModeCommand(args);
1984
- return true;
1985
1797
  case "provider":
1986
1798
  await handleProviderCommand(args);
1987
1799
  return true;
@@ -2017,7 +1829,6 @@ function createCommandExecutor(options = {}) {
2017
1829
  handleRoleCommand,
2018
1830
  handleSoloCommand,
2019
1831
  handleCronCommand,
2020
- handleModeCommand,
2021
1832
  handleProviderCommand,
2022
1833
  handleGroupCommand,
2023
1834
  handleSettingsCommand,
@@ -2028,7 +1839,4 @@ function createCommandExecutor(options = {}) {
2028
1839
 
2029
1840
  module.exports = {
2030
1841
  createCommandExecutor,
2031
- collectHostLaunchRequestContext,
2032
- collectTerminalLaunchRequestContext,
2033
- collectTmuxLaunchRequestContext,
2034
1842
  };