funolio-agent 1.0.53 → 1.1.65

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 (276) hide show
  1. package/dist/approval.d.ts +1 -6
  2. package/dist/approval.d.ts.map +1 -1
  3. package/dist/approval.js +2 -7
  4. package/dist/approval.js.map +1 -1
  5. package/dist/auth/credential-reader.d.ts.map +1 -1
  6. package/dist/auth/credential-reader.js +4 -3
  7. package/dist/auth/credential-reader.js.map +1 -1
  8. package/dist/auth/token-refresh.d.ts +8 -0
  9. package/dist/auth/token-refresh.d.ts.map +1 -1
  10. package/dist/auth/token-refresh.js +82 -52
  11. package/dist/auth/token-refresh.js.map +1 -1
  12. package/dist/auto-organizer.d.ts.map +1 -1
  13. package/dist/auto-organizer.js +6 -7
  14. package/dist/auto-organizer.js.map +1 -1
  15. package/dist/bench-prefix.d.ts +16 -0
  16. package/dist/bench-prefix.d.ts.map +1 -0
  17. package/dist/bench-prefix.js +25 -0
  18. package/dist/bench-prefix.js.map +1 -0
  19. package/dist/bot-manager.d.ts +5 -1
  20. package/dist/bot-manager.d.ts.map +1 -1
  21. package/dist/bot-manager.js +46 -27
  22. package/dist/bot-manager.js.map +1 -1
  23. package/dist/chat-sync.d.ts +42 -0
  24. package/dist/chat-sync.d.ts.map +1 -0
  25. package/dist/chat-sync.js +95 -0
  26. package/dist/chat-sync.js.map +1 -0
  27. package/dist/clerk-model.d.ts +7 -0
  28. package/dist/clerk-model.d.ts.map +1 -1
  29. package/dist/clerk-model.js +42 -8
  30. package/dist/clerk-model.js.map +1 -1
  31. package/dist/cli-bootstrap-history.d.ts +10 -0
  32. package/dist/cli-bootstrap-history.d.ts.map +1 -0
  33. package/dist/cli-bootstrap-history.js +112 -0
  34. package/dist/cli-bootstrap-history.js.map +1 -0
  35. package/dist/cli-models.d.ts +8 -0
  36. package/dist/cli-models.d.ts.map +1 -0
  37. package/dist/cli-models.js +91 -0
  38. package/dist/cli-models.js.map +1 -0
  39. package/dist/cli-session-epoch.d.ts +13 -3
  40. package/dist/cli-session-epoch.d.ts.map +1 -1
  41. package/dist/cli-session-epoch.js +53 -4
  42. package/dist/cli-session-epoch.js.map +1 -1
  43. package/dist/cli-session-registry.d.ts +35 -0
  44. package/dist/cli-session-registry.d.ts.map +1 -0
  45. package/dist/cli-session-registry.js +177 -0
  46. package/dist/cli-session-registry.js.map +1 -0
  47. package/dist/cli.js +62 -0
  48. package/dist/cli.js.map +1 -1
  49. package/dist/codex-app-server-manager.d.ts +189 -0
  50. package/dist/codex-app-server-manager.d.ts.map +1 -0
  51. package/dist/codex-app-server-manager.js +1468 -0
  52. package/dist/codex-app-server-manager.js.map +1 -0
  53. package/dist/commands/init.d.ts.map +1 -1
  54. package/dist/commands/init.js +8 -30
  55. package/dist/commands/init.js.map +1 -1
  56. package/dist/commands/pool.d.ts +32 -0
  57. package/dist/commands/pool.d.ts.map +1 -1
  58. package/dist/commands/pool.js +145 -66
  59. package/dist/commands/pool.js.map +1 -1
  60. package/dist/commands/setup.d.ts +4 -1
  61. package/dist/commands/setup.d.ts.map +1 -1
  62. package/dist/commands/setup.js +9 -25
  63. package/dist/commands/setup.js.map +1 -1
  64. package/dist/commands/start.d.ts +21 -0
  65. package/dist/commands/start.d.ts.map +1 -1
  66. package/dist/commands/start.js +559 -63
  67. package/dist/commands/start.js.map +1 -1
  68. package/dist/commands/status.d.ts.map +1 -1
  69. package/dist/commands/status.js +5 -2
  70. package/dist/commands/status.js.map +1 -1
  71. package/dist/completion-marker.d.ts +7 -0
  72. package/dist/completion-marker.d.ts.map +1 -0
  73. package/dist/completion-marker.js +28 -0
  74. package/dist/completion-marker.js.map +1 -0
  75. package/dist/config.d.ts +7 -2
  76. package/dist/config.d.ts.map +1 -1
  77. package/dist/config.js +184 -60
  78. package/dist/config.js.map +1 -1
  79. package/dist/context-window.d.ts +37 -1
  80. package/dist/context-window.d.ts.map +1 -1
  81. package/dist/context-window.js +210 -17
  82. package/dist/context-window.js.map +1 -1
  83. package/dist/live-activity.d.ts +31 -0
  84. package/dist/live-activity.d.ts.map +1 -0
  85. package/dist/live-activity.js +36 -0
  86. package/dist/live-activity.js.map +1 -0
  87. package/dist/local-chat-execution.d.ts +114 -0
  88. package/dist/local-chat-execution.d.ts.map +1 -0
  89. package/dist/local-chat-execution.js +349 -0
  90. package/dist/local-chat-execution.js.map +1 -0
  91. package/dist/local-cli-pty-manager.d.ts +186 -0
  92. package/dist/local-cli-pty-manager.d.ts.map +1 -1
  93. package/dist/local-cli-pty-manager.js +2581 -164
  94. package/dist/local-cli-pty-manager.js.map +1 -1
  95. package/dist/local-conversation-gateway.d.ts +110 -0
  96. package/dist/local-conversation-gateway.d.ts.map +1 -0
  97. package/dist/local-conversation-gateway.js +175 -0
  98. package/dist/local-conversation-gateway.js.map +1 -0
  99. package/dist/local-data.d.ts +276 -5
  100. package/dist/local-data.d.ts.map +1 -1
  101. package/dist/local-data.js +1201 -86
  102. package/dist/local-data.js.map +1 -1
  103. package/dist/local-db.d.ts +6 -0
  104. package/dist/local-db.d.ts.map +1 -1
  105. package/dist/local-db.js +428 -2
  106. package/dist/local-db.js.map +1 -1
  107. package/dist/local-funnel.d.ts.map +1 -1
  108. package/dist/local-funnel.js +6 -5
  109. package/dist/local-funnel.js.map +1 -1
  110. package/dist/local-server.d.ts +55 -0
  111. package/dist/local-server.d.ts.map +1 -1
  112. package/dist/local-server.js +3281 -441
  113. package/dist/local-server.js.map +1 -1
  114. package/dist/managed-process-registry.d.ts +59 -0
  115. package/dist/managed-process-registry.d.ts.map +1 -0
  116. package/dist/managed-process-registry.js +390 -0
  117. package/dist/managed-process-registry.js.map +1 -0
  118. package/dist/mcp/claude-config-writer.d.ts +5 -5
  119. package/dist/mcp/claude-config-writer.d.ts.map +1 -1
  120. package/dist/mcp/claude-config-writer.js +19 -11
  121. package/dist/mcp/claude-config-writer.js.map +1 -1
  122. package/dist/mcp/index.d.ts +4 -2
  123. package/dist/mcp/index.d.ts.map +1 -1
  124. package/dist/mcp/index.js.map +1 -1
  125. package/dist/mcp/sync-cli-config.d.ts +42 -4
  126. package/dist/mcp/sync-cli-config.d.ts.map +1 -1
  127. package/dist/mcp/sync-cli-config.js +497 -17
  128. package/dist/mcp/sync-cli-config.js.map +1 -1
  129. package/dist/message-loop.d.ts +6 -0
  130. package/dist/message-loop.d.ts.map +1 -1
  131. package/dist/message-loop.js +281 -89
  132. package/dist/message-loop.js.map +1 -1
  133. package/dist/mqtt-client.d.ts +44 -1
  134. package/dist/mqtt-client.d.ts.map +1 -1
  135. package/dist/mqtt-client.js +284 -46
  136. package/dist/mqtt-client.js.map +1 -1
  137. package/dist/mqtt-data-relay.d.ts +44 -0
  138. package/dist/mqtt-data-relay.d.ts.map +1 -0
  139. package/dist/mqtt-data-relay.js +106 -0
  140. package/dist/mqtt-data-relay.js.map +1 -0
  141. package/dist/oauth.d.ts.map +1 -1
  142. package/dist/oauth.js +69 -29
  143. package/dist/oauth.js.map +1 -1
  144. package/dist/orchestration/capabilities.d.ts +13 -0
  145. package/dist/orchestration/capabilities.d.ts.map +1 -0
  146. package/dist/orchestration/capabilities.js +152 -0
  147. package/dist/orchestration/capabilities.js.map +1 -0
  148. package/dist/orchestration/dispatch-executor.d.ts +83 -0
  149. package/dist/orchestration/dispatch-executor.d.ts.map +1 -0
  150. package/dist/orchestration/dispatch-executor.js +266 -0
  151. package/dist/orchestration/dispatch-executor.js.map +1 -0
  152. package/dist/orchestration/dispatch-hint.d.ts +134 -0
  153. package/dist/orchestration/dispatch-hint.d.ts.map +1 -0
  154. package/dist/orchestration/dispatch-hint.js +247 -0
  155. package/dist/orchestration/dispatch-hint.js.map +1 -0
  156. package/dist/orchestration/dispatch-runner.d.ts +106 -0
  157. package/dist/orchestration/dispatch-runner.d.ts.map +1 -0
  158. package/dist/orchestration/dispatch-runner.js +604 -0
  159. package/dist/orchestration/dispatch-runner.js.map +1 -0
  160. package/dist/orchestration/dispatch-tools.d.ts +167 -0
  161. package/dist/orchestration/dispatch-tools.d.ts.map +1 -0
  162. package/dist/orchestration/dispatch-tools.js +328 -0
  163. package/dist/orchestration/dispatch-tools.js.map +1 -0
  164. package/dist/orchestration/front-door-policy.d.ts +35 -10
  165. package/dist/orchestration/front-door-policy.d.ts.map +1 -1
  166. package/dist/orchestration/front-door-policy.js +30 -267
  167. package/dist/orchestration/front-door-policy.js.map +1 -1
  168. package/dist/orchestration/orchestrator-dispatch-prompt.d.ts +43 -0
  169. package/dist/orchestration/orchestrator-dispatch-prompt.d.ts.map +1 -0
  170. package/dist/orchestration/orchestrator-dispatch-prompt.js +267 -0
  171. package/dist/orchestration/orchestrator-dispatch-prompt.js.map +1 -0
  172. package/dist/orchestration/orchestrator-operating-prompt.d.ts +15 -0
  173. package/dist/orchestration/orchestrator-operating-prompt.d.ts.map +1 -1
  174. package/dist/orchestration/orchestrator-operating-prompt.js +206 -20
  175. package/dist/orchestration/orchestrator-operating-prompt.js.map +1 -1
  176. package/dist/orchestration/plan-import.d.ts +39 -0
  177. package/dist/orchestration/plan-import.d.ts.map +1 -0
  178. package/dist/orchestration/plan-import.js +547 -0
  179. package/dist/orchestration/plan-import.js.map +1 -0
  180. package/dist/orchestration/validation.d.ts +40 -0
  181. package/dist/orchestration/validation.d.ts.map +1 -0
  182. package/dist/orchestration/validation.js +203 -0
  183. package/dist/orchestration/validation.js.map +1 -0
  184. package/dist/orchestration/worker-operating-prompt.d.ts +2 -0
  185. package/dist/orchestration/worker-operating-prompt.d.ts.map +1 -1
  186. package/dist/orchestration/worker-operating-prompt.js +36 -46
  187. package/dist/orchestration/worker-operating-prompt.js.map +1 -1
  188. package/dist/orchestrator.d.ts +214 -33
  189. package/dist/orchestrator.d.ts.map +1 -1
  190. package/dist/orchestrator.js +2200 -1100
  191. package/dist/orchestrator.js.map +1 -1
  192. package/dist/providers/anthropic.d.ts.map +1 -1
  193. package/dist/providers/anthropic.js +8 -4
  194. package/dist/providers/anthropic.js.map +1 -1
  195. package/dist/providers/claude-cli-prompt.d.ts.map +1 -1
  196. package/dist/providers/claude-cli-prompt.js +49 -5
  197. package/dist/providers/claude-cli-prompt.js.map +1 -1
  198. package/dist/providers/claude-cli.d.ts.map +1 -1
  199. package/dist/providers/claude-cli.js +81 -5
  200. package/dist/providers/claude-cli.js.map +1 -1
  201. package/dist/providers/codex-cli.d.ts +10 -6
  202. package/dist/providers/codex-cli.d.ts.map +1 -1
  203. package/dist/providers/codex-cli.js +204 -26
  204. package/dist/providers/codex-cli.js.map +1 -1
  205. package/dist/providers/google.d.ts.map +1 -1
  206. package/dist/providers/google.js +15 -5
  207. package/dist/providers/google.js.map +1 -1
  208. package/dist/providers/index.d.ts +15 -1
  209. package/dist/providers/index.d.ts.map +1 -1
  210. package/dist/providers/index.js.map +1 -1
  211. package/dist/providers/openai.d.ts +1 -1
  212. package/dist/providers/openai.d.ts.map +1 -1
  213. package/dist/providers/openai.js +13 -5
  214. package/dist/providers/openai.js.map +1 -1
  215. package/dist/response-guard.js +1 -1
  216. package/dist/response-guard.js.map +1 -1
  217. package/dist/server-adapter.d.ts +8 -0
  218. package/dist/server-adapter.d.ts.map +1 -1
  219. package/dist/server-adapter.js +7 -0
  220. package/dist/server-adapter.js.map +1 -1
  221. package/dist/service-mode.d.ts +1 -1
  222. package/dist/service-mode.d.ts.map +1 -1
  223. package/dist/service-mode.js +64 -1
  224. package/dist/service-mode.js.map +1 -1
  225. package/dist/service-setup-only.d.ts +8 -0
  226. package/dist/service-setup-only.d.ts.map +1 -0
  227. package/dist/service-setup-only.js +37 -0
  228. package/dist/service-setup-only.js.map +1 -0
  229. package/dist/slash-commands.d.ts +21 -0
  230. package/dist/slash-commands.d.ts.map +1 -0
  231. package/dist/slash-commands.js +99 -0
  232. package/dist/slash-commands.js.map +1 -0
  233. package/dist/subagent/index.d.ts +4 -2
  234. package/dist/subagent/index.d.ts.map +1 -1
  235. package/dist/subagent/index.js.map +1 -1
  236. package/dist/summarization-pipeline.d.ts.map +1 -1
  237. package/dist/summarization-pipeline.js +1 -9
  238. package/dist/summarization-pipeline.js.map +1 -1
  239. package/dist/token-counter.d.ts.map +1 -1
  240. package/dist/token-counter.js +11 -4
  241. package/dist/token-counter.js.map +1 -1
  242. package/dist/tool-filter.d.ts.map +1 -1
  243. package/dist/tool-filter.js +10 -6
  244. package/dist/tool-filter.js.map +1 -1
  245. package/dist/tools/admin-tools.d.ts.map +1 -1
  246. package/dist/tools/admin-tools.js +20 -5
  247. package/dist/tools/admin-tools.js.map +1 -1
  248. package/dist/tools/index.d.ts.map +1 -1
  249. package/dist/tools/index.js +2 -1
  250. package/dist/tools/index.js.map +1 -1
  251. package/dist/tools/run-command.d.ts.map +1 -1
  252. package/dist/tools/run-command.js +5 -1
  253. package/dist/tools/run-command.js.map +1 -1
  254. package/dist/tools/search-conversation-history.d.ts +16 -0
  255. package/dist/tools/search-conversation-history.d.ts.map +1 -0
  256. package/dist/tools/search-conversation-history.js +334 -0
  257. package/dist/tools/search-conversation-history.js.map +1 -0
  258. package/dist/tools/todo-tasks.d.ts.map +1 -1
  259. package/dist/tools/todo-tasks.js +77 -5
  260. package/dist/tools/todo-tasks.js.map +1 -1
  261. package/dist/usage-log.d.ts +62 -0
  262. package/dist/usage-log.d.ts.map +1 -0
  263. package/dist/usage-log.js +98 -0
  264. package/dist/usage-log.js.map +1 -0
  265. package/dist/wizard-state.d.ts +20 -0
  266. package/dist/wizard-state.d.ts.map +1 -1
  267. package/dist/wizard-state.js +90 -3
  268. package/dist/wizard-state.js.map +1 -1
  269. package/dist/wizard-support.d.ts.map +1 -1
  270. package/dist/wizard-support.js +27 -1
  271. package/dist/wizard-support.js.map +1 -1
  272. package/dist/workflow-engine.d.ts +44 -2
  273. package/dist/workflow-engine.d.ts.map +1 -1
  274. package/dist/workflow-engine.js +932 -111
  275. package/dist/workflow-engine.js.map +1 -1
  276. package/package.json +2 -2
@@ -1,9 +1,22 @@
1
1
  /**
2
2
  * Sync MCP server configs to CLI provider native config files.
3
3
  *
4
- * For `claude-cli`: writes to ~/.claude.json so Claude Code can discover
5
- * both user-installed MCP servers and the funolio-tools bridge server.
4
+ * For `claude-cli`: writes to the selected Claude JSON config so Claude Code
5
+ * can discover both user-installed MCP servers and the funolio-tools bridge.
6
6
  */
7
+ export type CliProviderId = 'claude-cli' | 'codex-cli';
8
+ export declare function getCliProviderSessionHome(provider: CliProviderId): string;
9
+ export declare function getCliBotSessionHome(provider: CliProviderId, botId: string): string;
10
+ export declare function getCliSessionRuntimeHome(provider: CliProviderId, botId: string, conversationId: string): string;
11
+ export declare function claudeUserCredentialsPath(): string;
12
+ export declare function claudeCanonicalCredentialsPath(): string;
13
+ export declare function syncClaudeCanonicalCredentials(): string | null;
14
+ export declare function promoteClaudeBotHomeCredentialsToCanonical(botHomeDir: string): string | null;
15
+ export declare function forceSyncClaudeCanonicalCredentialsFromUser(): string | null;
16
+ export declare function resolveClaudeCredentialsSourcePath(): string | null;
17
+ export declare function ensureCliBotSessionHome(provider: CliProviderId, botId: string): string;
18
+ export declare function ensureCliSessionRuntimeHome(provider: CliProviderId, botId: string, conversationId: string): string;
19
+ export declare function claudeJsonConfigPath(baseDir?: string): string;
7
20
  export declare function resolvePackagedAgentCommand(): string;
8
21
  /**
9
22
  * Sync installed MCP servers + funolio-tools bridge to the CLI provider's
@@ -11,9 +24,34 @@ export declare function resolvePackagedAgentCommand(): string;
11
24
  *
12
25
  * @returns Summary string for logging.
13
26
  */
14
- export declare function syncMcpToCliConfig(provider: string): Promise<string>;
15
- export declare function codexConfigPath(): string;
27
+ export declare function syncMcpToCliConfig(provider: string, funolioToolEnv?: Record<string, string>, target?: {
28
+ claudeJsonPath?: string;
29
+ codexHomeDir?: string;
30
+ }): Promise<string>;
31
+ export declare function syncClaudeJsonConfig(funolioToolEnv?: Record<string, string>, claudeJsonPath?: string): string;
32
+ export declare function codexConfigPath(baseDir?: string): string;
16
33
  export declare function stripCodexMcpSection(raw: string, name: string): string;
17
34
  export declare function appendCodexMcpStdio(raw: string, name: string, command: string, args: string[], envVars?: Record<string, string>): string;
18
35
  export declare const CODEX_FUNOLIO_SERVER_NAME = "funolio_tools";
36
+ type ClaudeBotSettingsInput = {
37
+ model?: string | null;
38
+ effortLevel?: string | null;
39
+ outputStyle?: string | null;
40
+ fastMode?: boolean | null;
41
+ permissions?: Record<string, unknown> | null;
42
+ };
43
+ export declare function writeClaudeBotSettings(botId: string, settings: ClaudeBotSettingsInput): string;
44
+ export declare function claudeBotSettingsPath(botId: string): string;
45
+ export declare function readClaudeBotSettings(botId: string): ClaudeBotSettingsInput;
46
+ type CodexBotConfigInput = {
47
+ model?: string | null;
48
+ modelReasoningEffort?: string | null;
49
+ personality?: string | null;
50
+ serviceTier?: string | null;
51
+ sandbox?: string | null;
52
+ approvalPolicy?: string | null;
53
+ };
54
+ export declare function writeCodexBotConfig(botId: string, config: CodexBotConfigInput): string;
55
+ export declare function readCodexBotConfig(botId: string): CodexBotConfigInput;
56
+ export {};
19
57
  //# sourceMappingURL=sync-cli-config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sync-cli-config.d.ts","sourceRoot":"","sources":["../../src/mcp/sync-cli-config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA0BH,wBAAgB,2BAA2B,IAAI,MAAM,CAoBpD;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAU1E;AAkED,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAuBtE;AAED,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,MAAM,CAiBR;AAmDD,eAAO,MAAM,yBAAyB,kBAAkB,CAAC"}
1
+ {"version":3,"file":"sync-cli-config.d.ts","sourceRoot":"","sources":["../../src/mcp/sync-cli-config.ts"],"names":[],"mappings":"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"}
@@ -2,8 +2,8 @@
2
2
  /**
3
3
  * Sync MCP server configs to CLI provider native config files.
4
4
  *
5
- * For `claude-cli`: writes to ~/.claude.json so Claude Code can discover
6
- * both user-installed MCP servers and the funolio-tools bridge server.
5
+ * For `claude-cli`: writes to the selected Claude JSON config so Claude Code
6
+ * can discover both user-installed MCP servers and the funolio-tools bridge.
7
7
  */
8
8
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
9
  if (k2 === undefined) k2 = k;
@@ -40,20 +40,316 @@ var __importStar = (this && this.__importStar) || (function () {
40
40
  })();
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  exports.CODEX_FUNOLIO_SERVER_NAME = void 0;
43
+ exports.getCliProviderSessionHome = getCliProviderSessionHome;
44
+ exports.getCliBotSessionHome = getCliBotSessionHome;
45
+ exports.getCliSessionRuntimeHome = getCliSessionRuntimeHome;
46
+ exports.claudeUserCredentialsPath = claudeUserCredentialsPath;
47
+ exports.claudeCanonicalCredentialsPath = claudeCanonicalCredentialsPath;
48
+ exports.syncClaudeCanonicalCredentials = syncClaudeCanonicalCredentials;
49
+ exports.promoteClaudeBotHomeCredentialsToCanonical = promoteClaudeBotHomeCredentialsToCanonical;
50
+ exports.forceSyncClaudeCanonicalCredentialsFromUser = forceSyncClaudeCanonicalCredentialsFromUser;
51
+ exports.resolveClaudeCredentialsSourcePath = resolveClaudeCredentialsSourcePath;
52
+ exports.ensureCliBotSessionHome = ensureCliBotSessionHome;
53
+ exports.ensureCliSessionRuntimeHome = ensureCliSessionRuntimeHome;
54
+ exports.claudeJsonConfigPath = claudeJsonConfigPath;
43
55
  exports.resolvePackagedAgentCommand = resolvePackagedAgentCommand;
44
56
  exports.syncMcpToCliConfig = syncMcpToCliConfig;
57
+ exports.syncClaudeJsonConfig = syncClaudeJsonConfig;
45
58
  exports.codexConfigPath = codexConfigPath;
46
59
  exports.stripCodexMcpSection = stripCodexMcpSection;
47
60
  exports.appendCodexMcpStdio = appendCodexMcpStdio;
61
+ exports.writeClaudeBotSettings = writeClaudeBotSettings;
62
+ exports.claudeBotSettingsPath = claudeBotSettingsPath;
63
+ exports.readClaudeBotSettings = readClaudeBotSettings;
64
+ exports.writeCodexBotConfig = writeCodexBotConfig;
65
+ exports.readCodexBotConfig = readCodexBotConfig;
48
66
  const fs = __importStar(require("fs"));
49
67
  const path = __importStar(require("path"));
50
68
  const os = __importStar(require("os"));
51
69
  const config_1 = require("../config");
70
+ function resolveHomeDir() {
71
+ const override = process.env.FUNOLIO_CLI_HOME_OVERRIDE?.trim();
72
+ return override || os.homedir();
73
+ }
74
+ function funolioCliSessionsRoot() {
75
+ return path.join(resolveHomeDir(), '.funolio', 'cli-sessions');
76
+ }
77
+ function providerDirName(provider) {
78
+ return provider === 'claude-cli' ? 'claude' : 'codex';
79
+ }
80
+ function getCliProviderSessionHome(provider) {
81
+ return path.join(funolioCliSessionsRoot(), providerDirName(provider));
82
+ }
83
+ function getCliBotSessionHome(provider, botId) {
84
+ return path.join(getCliProviderSessionHome(provider), botId);
85
+ }
86
+ function safeSessionDirName(value) {
87
+ const normalized = String(value || '').trim();
88
+ if (!normalized)
89
+ return 'session';
90
+ return normalized.replace(/[^a-zA-Z0-9._-]/g, '_');
91
+ }
92
+ function getCliSessionRuntimeHome(provider, botId, conversationId) {
93
+ return path.join(getCliBotSessionHome(provider, botId), 'runtime', safeSessionDirName(conversationId));
94
+ }
95
+ function userCliHome(provider) {
96
+ return path.join(resolveHomeDir(), provider === 'claude-cli' ? '.claude' : '.codex');
97
+ }
98
+ function copyDirectoryRecursive(sourceDir, targetDir) {
99
+ if (!fs.existsSync(sourceDir))
100
+ return;
101
+ if (!fs.existsSync(targetDir))
102
+ fs.mkdirSync(targetDir, { recursive: true });
103
+ for (const entry of fs.readdirSync(sourceDir, { withFileTypes: true })) {
104
+ const sourcePath = path.join(sourceDir, entry.name);
105
+ const targetPath = path.join(targetDir, entry.name);
106
+ if (entry.isDirectory()) {
107
+ copyDirectoryRecursive(sourcePath, targetPath);
108
+ continue;
109
+ }
110
+ if (!entry.isFile())
111
+ continue;
112
+ if (!fs.existsSync(targetPath)) {
113
+ fs.copyFileSync(sourcePath, targetPath);
114
+ }
115
+ }
116
+ }
117
+ function copyFileIfPresent(sourcePath, targetPath, overwrite = false) {
118
+ if (!fs.existsSync(sourcePath))
119
+ return;
120
+ if (!overwrite && fs.existsSync(targetPath))
121
+ return;
122
+ fs.mkdirSync(path.dirname(targetPath), { recursive: true });
123
+ fs.copyFileSync(sourcePath, targetPath);
124
+ }
125
+ function fileMtimeMs(filePath) {
126
+ try {
127
+ return fs.statSync(filePath).mtimeMs;
128
+ }
129
+ catch {
130
+ return null;
131
+ }
132
+ }
133
+ function readClaudeOauthJson(filePath) {
134
+ try {
135
+ const parsed = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
136
+ const oauth = parsed.claudeAiOauth;
137
+ return oauth && typeof oauth === 'object' ? oauth : null;
138
+ }
139
+ catch {
140
+ return null;
141
+ }
142
+ }
143
+ function toNonEmptyString(value) {
144
+ return typeof value === 'string' && value.trim() ? value : null;
145
+ }
146
+ function toEpochMs(value) {
147
+ if (typeof value === 'number' && Number.isFinite(value))
148
+ return value;
149
+ if (typeof value === 'string' && value.trim()) {
150
+ const asNumber = Number(value);
151
+ if (Number.isFinite(asNumber))
152
+ return asNumber;
153
+ const asDate = Date.parse(value);
154
+ return Number.isFinite(asDate) ? asDate : null;
155
+ }
156
+ return null;
157
+ }
158
+ function mergeClaudeOauth(baseOauth, incomingOauth) {
159
+ if (!baseOauth && !incomingOauth)
160
+ return null;
161
+ if (!baseOauth)
162
+ return incomingOauth ? { ...incomingOauth } : null;
163
+ if (!incomingOauth)
164
+ return { ...baseOauth };
165
+ const baseAccess = toNonEmptyString(baseOauth.accessToken);
166
+ const incomingAccess = toNonEmptyString(incomingOauth.accessToken);
167
+ const baseRefresh = toNonEmptyString(baseOauth.refreshToken);
168
+ const incomingRefresh = toNonEmptyString(incomingOauth.refreshToken);
169
+ const baseExpiry = toEpochMs(baseOauth.expiresAt);
170
+ const incomingExpiry = toEpochMs(incomingOauth.expiresAt);
171
+ let accessToken = baseAccess;
172
+ if (!accessToken && incomingAccess) {
173
+ accessToken = incomingAccess;
174
+ }
175
+ else if (incomingAccess
176
+ && incomingAccess !== baseAccess
177
+ && (!!incomingRefresh
178
+ || !baseAccess
179
+ || ((incomingExpiry ?? -1) > (baseExpiry ?? -1)))) {
180
+ accessToken = incomingAccess;
181
+ }
182
+ const refreshToken = incomingRefresh || baseRefresh || '';
183
+ const expiresAt = Math.max(baseExpiry ?? 0, incomingExpiry ?? 0) || incomingOauth.expiresAt || baseOauth.expiresAt;
184
+ return {
185
+ ...baseOauth,
186
+ ...incomingOauth,
187
+ ...(accessToken ? { accessToken } : {}),
188
+ refreshToken,
189
+ expiresAt,
190
+ };
191
+ }
192
+ function writeClaudeOauthJson(targetPath, oauth) {
193
+ const existing = readJsonFile(targetPath);
194
+ const payload = existing && typeof existing === 'object' ? existing : {};
195
+ payload.claudeAiOauth = oauth;
196
+ fs.mkdirSync(path.dirname(targetPath), { recursive: true });
197
+ fs.writeFileSync(targetPath, JSON.stringify(payload, null, 2), 'utf-8');
198
+ }
199
+ function removeFileIfPresent(filePath) {
200
+ try {
201
+ if (fs.existsSync(filePath))
202
+ fs.unlinkSync(filePath);
203
+ }
204
+ catch {
205
+ // best effort
206
+ }
207
+ }
208
+ function claudeUserCredentialsPath() {
209
+ return path.join(userCliHome('claude-cli'), '.credentials.json');
210
+ }
211
+ function claudeCanonicalCredentialsPath() {
212
+ return path.join(getCliProviderSessionHome('claude-cli'), '.credentials.json');
213
+ }
214
+ function overwriteFileFromSource(sourcePath, targetPath) {
215
+ if (!fs.existsSync(sourcePath))
216
+ return false;
217
+ fs.mkdirSync(path.dirname(targetPath), { recursive: true });
218
+ fs.copyFileSync(sourcePath, targetPath);
219
+ return true;
220
+ }
221
+ function syncClaudeCanonicalCredentials() {
222
+ const canonicalPath = claudeCanonicalCredentialsPath();
223
+ return fs.existsSync(canonicalPath) ? canonicalPath : null;
224
+ }
225
+ function promoteClaudeBotHomeCredentialsToCanonical(botHomeDir) {
226
+ const botPath = path.join(botHomeDir, '.credentials.json');
227
+ if (!fs.existsSync(botPath)) {
228
+ return syncClaudeCanonicalCredentials();
229
+ }
230
+ const canonicalPath = claudeCanonicalCredentialsPath();
231
+ if (!fs.existsSync(canonicalPath)) {
232
+ try {
233
+ overwriteFileFromSource(botPath, canonicalPath);
234
+ return canonicalPath;
235
+ }
236
+ catch {
237
+ return syncClaudeCanonicalCredentials();
238
+ }
239
+ }
240
+ try {
241
+ const merged = mergeClaudeOauth(readClaudeOauthJson(canonicalPath), readClaudeOauthJson(botPath));
242
+ if (merged) {
243
+ writeClaudeOauthJson(canonicalPath, merged);
244
+ return canonicalPath;
245
+ }
246
+ }
247
+ catch {
248
+ // fall through
249
+ }
250
+ return syncClaudeCanonicalCredentials();
251
+ }
252
+ function forceSyncClaudeCanonicalCredentialsFromUser() {
253
+ const userPath = claudeUserCredentialsPath();
254
+ const canonicalPath = claudeCanonicalCredentialsPath();
255
+ if (!fs.existsSync(userPath))
256
+ return fs.existsSync(canonicalPath) ? canonicalPath : null;
257
+ try {
258
+ overwriteFileFromSource(userPath, canonicalPath);
259
+ return canonicalPath;
260
+ }
261
+ catch {
262
+ return null;
263
+ }
264
+ }
265
+ function resolveClaudeCredentialsSourcePath() {
266
+ return syncClaudeCanonicalCredentials();
267
+ }
268
+ function syncClaudeCredentialsIntoBotHome(targetDir) {
269
+ const sourcePath = syncClaudeCanonicalCredentials();
270
+ const targetPath = path.join(targetDir, '.credentials.json');
271
+ if (!sourcePath) {
272
+ removeFileIfPresent(targetPath);
273
+ return;
274
+ }
275
+ overwriteFileFromSource(sourcePath, targetPath);
276
+ }
277
+ function seedCliBotSessionHome(provider, targetDir) {
278
+ const sources = [getCliProviderSessionHome(provider), userCliHome(provider)];
279
+ for (const sourceDir of sources) {
280
+ if (!fs.existsSync(sourceDir))
281
+ continue;
282
+ if (provider === 'claude-cli') {
283
+ copyFileIfPresent(path.join(sourceDir, 'settings.json'), path.join(targetDir, 'settings.json'));
284
+ const pluginsDir = path.join(sourceDir, 'plugins');
285
+ if (fs.existsSync(pluginsDir)) {
286
+ copyDirectoryRecursive(pluginsDir, path.join(targetDir, 'plugins'));
287
+ }
288
+ return;
289
+ }
290
+ for (const fileName of ['auth.json', 'config.toml', 'version.json', 'installation_id', 'cap_sid', '.env', '.personality_migration']) {
291
+ copyFileIfPresent(path.join(sourceDir, fileName), path.join(targetDir, fileName));
292
+ }
293
+ for (const dirName of ['rules', 'skills', 'memories']) {
294
+ const sourcePath = path.join(sourceDir, dirName);
295
+ if (fs.existsSync(sourcePath)) {
296
+ copyDirectoryRecursive(sourcePath, path.join(targetDir, dirName));
297
+ }
298
+ }
299
+ return;
300
+ }
301
+ }
302
+ function refreshCliBotSessionRuntimeFiles(provider, targetDir) {
303
+ if (provider === 'claude-cli') {
304
+ syncClaudeCredentialsIntoBotHome(targetDir);
305
+ copyFileIfPresent(claudeJsonConfigPath(), path.join(targetDir, '.claude.json'), true);
306
+ copyFileIfPresent(path.join(userCliHome(provider), 'settings.json'), path.join(targetDir, 'settings.json'), true);
307
+ ensureClaudeBotSettingsDefaults(path.join(targetDir, 'settings.json'));
308
+ const sourceDir = userCliHome(provider);
309
+ const pluginsDir = path.join(sourceDir, 'plugins');
310
+ if (fs.existsSync(pluginsDir)) {
311
+ copyDirectoryRecursive(pluginsDir, path.join(targetDir, 'plugins'));
312
+ }
313
+ return;
314
+ }
315
+ const sourceDir = userCliHome(provider);
316
+ if (!fs.existsSync(sourceDir))
317
+ return;
318
+ for (const fileName of ['auth.json', 'version.json', 'installation_id', 'cap_sid', '.env', '.personality_migration']) {
319
+ copyFileIfPresent(path.join(sourceDir, fileName), path.join(targetDir, fileName), true);
320
+ }
321
+ }
322
+ function ensureCliSessionHome(provider, targetDir) {
323
+ if (!fs.existsSync(targetDir)) {
324
+ fs.mkdirSync(targetDir, { recursive: true });
325
+ }
326
+ seedCliBotSessionHome(provider, targetDir);
327
+ refreshCliBotSessionRuntimeFiles(provider, targetDir);
328
+ return targetDir;
329
+ }
330
+ function ensureCliBotSessionHome(provider, botId) {
331
+ return ensureCliSessionHome(provider, getCliBotSessionHome(provider, botId));
332
+ }
333
+ function ensureCliSessionRuntimeHome(provider, botId, conversationId) {
334
+ return ensureCliSessionHome(provider, getCliSessionRuntimeHome(provider, botId, conversationId));
335
+ }
336
+ function claudeJsonConfigPath(baseDir) {
337
+ return baseDir
338
+ ? path.join(baseDir, '.claude.json')
339
+ : path.join(resolveHomeDir(), '.claude.json');
340
+ }
52
341
  function resolvePackagedAgentCommand() {
53
342
  const execBase = path.basename(process.execPath).toLowerCase();
54
343
  if (execBase === 'funolio-agent' || execBase === 'funolio-agent.exe') {
55
344
  return process.execPath;
56
345
  }
346
+ const argvCliCandidate = process.argv[1];
347
+ if (argvCliCandidate
348
+ && path.basename(argvCliCandidate).toLowerCase() === 'cli.js'
349
+ && argvCliCandidate.toLowerCase().includes(`${path.sep}funolio-agent${path.sep}`)
350
+ && fs.existsSync(argvCliCandidate)) {
351
+ return argvCliCandidate;
352
+ }
57
353
  const exeName = process.platform === 'win32' ? 'funolio-agent.exe' : 'funolio-agent';
58
354
  const installedCandidate = process.platform === 'win32'
59
355
  ? path.join(os.homedir(), 'AppData', 'Local', 'Funolio', exeName)
@@ -61,7 +357,17 @@ function resolvePackagedAgentCommand() {
61
357
  if (fs.existsSync(installedCandidate)) {
62
358
  return installedCandidate;
63
359
  }
64
- const distCandidate = path.resolve(__dirname, '..', '..', 'dist', exeName);
360
+ if (process.platform !== 'win32') {
361
+ const localBinCandidate = '/usr/local/bin/funolio-agent';
362
+ if (fs.existsSync(localBinCandidate)) {
363
+ return localBinCandidate;
364
+ }
365
+ }
366
+ const distCliCandidate = path.resolve(__dirname, '..', 'cli.js');
367
+ if (fs.existsSync(distCliCandidate)) {
368
+ return distCliCandidate;
369
+ }
370
+ const distCandidate = path.resolve(__dirname, '..', '..', 'dist', 'cli.js');
65
371
  if (fs.existsSync(distCandidate)) {
66
372
  return distCandidate;
67
373
  }
@@ -73,19 +379,18 @@ function resolvePackagedAgentCommand() {
73
379
  *
74
380
  * @returns Summary string for logging.
75
381
  */
76
- async function syncMcpToCliConfig(provider) {
382
+ async function syncMcpToCliConfig(provider, funolioToolEnv, target) {
77
383
  if (provider === 'claude-cli') {
78
- return syncToClaudeJson();
384
+ return syncToClaudeJson(target?.claudeJsonPath);
79
385
  }
80
386
  if (provider === 'codex-cli') {
81
- return syncToCodexCli();
387
+ return syncToCodexCli(funolioToolEnv, target?.codexHomeDir);
82
388
  }
83
389
  return `[MCP sync] Provider "${provider}" is not a CLI provider — skipping`;
84
390
  }
85
- function syncToClaudeJson() {
86
- const claudeJsonPath = path.join(os.homedir(), '.claude.json');
391
+ function syncClaudeJsonConfig(funolioToolEnv = {}, claudeJsonPath = claudeJsonConfigPath()) {
87
392
  let config = {};
88
- // Read existing ~/.claude.json
393
+ // Read existing Claude JSON config.
89
394
  try {
90
395
  if (fs.existsSync(claudeJsonPath)) {
91
396
  config = JSON.parse(fs.readFileSync(claudeJsonPath, 'utf-8'));
@@ -132,18 +437,30 @@ function syncToClaudeJson() {
132
437
  }
133
438
  // 2. Add the funolio-tools bridge server through the packaged binary.
134
439
  const agentCommand = resolvePackagedAgentCommand();
440
+ const funolioEnv = {};
441
+ if (process.env.BRAVE_API_KEY)
442
+ funolioEnv.BRAVE_API_KEY = process.env.BRAVE_API_KEY;
443
+ for (const [key, value] of Object.entries(funolioToolEnv || {})) {
444
+ if (!value || !String(value).trim())
445
+ continue;
446
+ funolioEnv[key] = String(value);
447
+ }
135
448
  config.mcpServers['funolio-tools'] = {
136
449
  command: agentCommand,
137
450
  args: ['mcp-serve'],
138
- env: process.env.BRAVE_API_KEY ? { BRAVE_API_KEY: process.env.BRAVE_API_KEY } : undefined,
451
+ env: Object.keys(funolioEnv).length > 0 ? funolioEnv : undefined,
139
452
  };
140
453
  serverCount++;
141
- // Write back ~/.claude.json
454
+ ensureClaudeJsonOnboardingDefaults(config);
455
+ // Write back the selected Claude JSON config.
142
456
  fs.writeFileSync(claudeJsonPath, JSON.stringify(config, null, 2), 'utf-8');
143
- return `[MCP sync] Wrote ${serverCount} MCP server(s) to ~/.claude.json (including funolio-tools bridge)`;
457
+ return `[MCP sync] Wrote ${serverCount} MCP server(s) to ${claudeJsonPath} (including funolio-tools bridge)`;
458
+ }
459
+ function syncToClaudeJson(claudeJsonPath) {
460
+ return syncClaudeJsonConfig({}, claudeJsonPath || claudeJsonConfigPath());
144
461
  }
145
- function codexConfigPath() {
146
- return path.join(os.homedir(), '.codex', 'config.toml');
462
+ function codexConfigPath(baseDir) {
463
+ return path.join(baseDir || path.join(resolveHomeDir(), '.codex'), 'config.toml');
147
464
  }
148
465
  function stripCodexMcpSection(raw, name) {
149
466
  const lines = raw.split(/\r?\n/);
@@ -183,11 +500,11 @@ function appendCodexMcpStdio(raw, name, command, args, envVars) {
183
500
  }
184
501
  return `${raw.trimEnd()}\n${lines.join('\n')}\n`;
185
502
  }
186
- function syncToCodexCli() {
503
+ function syncToCodexCli(funolioToolEnv, codexHomeDir) {
187
504
  const codexFunolioServerName = exports.CODEX_FUNOLIO_SERVER_NAME;
188
505
  let serverCount = 0;
189
506
  const configuredNames = [];
190
- const configPath = codexConfigPath();
507
+ const configPath = codexConfigPath(codexHomeDir);
191
508
  if (!fs.existsSync(path.dirname(configPath))) {
192
509
  fs.mkdirSync(path.dirname(configPath), { recursive: true });
193
510
  }
@@ -219,11 +536,174 @@ function syncToCodexCli() {
219
536
  catch {
220
537
  // non-fatal
221
538
  }
222
- raw = appendCodexMcpStdio(raw, codexFunolioServerName, resolvePackagedAgentCommand(), ['mcp-serve'], process.env.BRAVE_API_KEY ? { BRAVE_API_KEY: process.env.BRAVE_API_KEY } : undefined);
539
+ const mcpEnv = {};
540
+ if (process.env.BRAVE_API_KEY)
541
+ mcpEnv.BRAVE_API_KEY = process.env.BRAVE_API_KEY;
542
+ for (const [key, value] of Object.entries(funolioToolEnv || {})) {
543
+ if (value && String(value).trim())
544
+ mcpEnv[key] = String(value);
545
+ }
546
+ raw = appendCodexMcpStdio(raw, codexFunolioServerName, resolvePackagedAgentCommand(), ['mcp-serve'], Object.keys(mcpEnv).length > 0 ? mcpEnv : undefined);
223
547
  serverCount++;
224
548
  configuredNames.push(codexFunolioServerName);
225
549
  fs.writeFileSync(configPath, raw, 'utf-8');
226
550
  return `[MCP sync] Wrote ${serverCount} MCP server(s) to Codex CLI (${configuredNames.join(', ')})`;
227
551
  }
228
552
  exports.CODEX_FUNOLIO_SERVER_NAME = 'funolio_tools';
553
+ function readJsonFile(filePath) {
554
+ try {
555
+ if (fs.existsSync(filePath)) {
556
+ const parsed = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
557
+ if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
558
+ return parsed;
559
+ }
560
+ }
561
+ }
562
+ catch {
563
+ // fall through
564
+ }
565
+ return {};
566
+ }
567
+ function ensureClaudeBotSettingsDefaults(settingsPath) {
568
+ const next = readJsonFile(settingsPath);
569
+ let dirty = false;
570
+ if (next.skipDangerousModePermissionPrompt !== true) {
571
+ next.skipDangerousModePermissionPrompt = true;
572
+ dirty = true;
573
+ }
574
+ if (typeof next.theme !== 'string' || !next.theme.trim()) {
575
+ next.theme = 'dark';
576
+ dirty = true;
577
+ }
578
+ if (dirty) {
579
+ fs.mkdirSync(path.dirname(settingsPath), { recursive: true });
580
+ fs.writeFileSync(settingsPath, `${JSON.stringify(next, null, 2)}\n`, 'utf-8');
581
+ }
582
+ }
583
+ function ensureClaudeJsonOnboardingDefaults(config) {
584
+ if (config.hasCompletedOnboarding !== true) {
585
+ config.hasCompletedOnboarding = true;
586
+ }
587
+ if (typeof config.lastOnboardingVersion !== 'string' || !config.lastOnboardingVersion.trim()) {
588
+ config.lastOnboardingVersion = '2.1.0';
589
+ }
590
+ if (config.hasSeenTasksHint !== true) {
591
+ config.hasSeenTasksHint = true;
592
+ }
593
+ if (config.hasSeenStashHint !== true) {
594
+ config.hasSeenStashHint = true;
595
+ }
596
+ }
597
+ function writeClaudeBotSettings(botId, settings) {
598
+ const homeDir = ensureCliBotSessionHome('claude-cli', botId);
599
+ const settingsPath = path.join(homeDir, 'settings.json');
600
+ const next = readJsonFile(settingsPath);
601
+ const apply = (key, value) => {
602
+ if (value === undefined)
603
+ return;
604
+ if (value === null || value === '') {
605
+ delete next[key];
606
+ return;
607
+ }
608
+ next[key] = value;
609
+ };
610
+ apply('model', settings.model ?? undefined);
611
+ apply('effortLevel', settings.effortLevel ?? undefined);
612
+ apply('outputStyle', settings.outputStyle ?? undefined);
613
+ apply('fastMode', settings.fastMode ?? undefined);
614
+ apply('permissions', settings.permissions ?? undefined);
615
+ fs.writeFileSync(settingsPath, `${JSON.stringify(next, null, 2)}\n`, 'utf-8');
616
+ ensureClaudeBotSettingsDefaults(settingsPath);
617
+ return settingsPath;
618
+ }
619
+ function claudeBotSettingsPath(botId) {
620
+ return path.join(ensureCliBotSessionHome('claude-cli', botId), 'settings.json');
621
+ }
622
+ function readClaudeBotSettings(botId) {
623
+ const settingsPath = claudeBotSettingsPath(botId);
624
+ const parsed = readJsonFile(settingsPath);
625
+ const permissions = parsed.permissions && typeof parsed.permissions === 'object' && !Array.isArray(parsed.permissions)
626
+ ? parsed.permissions
627
+ : null;
628
+ return {
629
+ model: typeof parsed.model === 'string' ? parsed.model : null,
630
+ effortLevel: typeof parsed.effortLevel === 'string' ? parsed.effortLevel : null,
631
+ outputStyle: typeof parsed.outputStyle === 'string' ? parsed.outputStyle : null,
632
+ fastMode: typeof parsed.fastMode === 'boolean' ? parsed.fastMode : null,
633
+ permissions,
634
+ };
635
+ }
636
+ function setTomlScalarValue(raw, key, value) {
637
+ const linePattern = new RegExp(`^${key.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\$&')}\\s*=.*$`, 'm');
638
+ if (value === undefined)
639
+ return raw;
640
+ if (value === null || value === '') {
641
+ return raw.replace(linePattern, '').replace(/\n{3,}/g, '\n\n').trimEnd();
642
+ }
643
+ const serialized = typeof value === 'string'
644
+ ? JSON.stringify(value)
645
+ : typeof value === 'boolean'
646
+ ? (value ? 'true' : 'false')
647
+ : String(value);
648
+ if (linePattern.test(raw)) {
649
+ return raw.replace(linePattern, `${key} = ${serialized}`);
650
+ }
651
+ const suffix = raw.trimEnd().length > 0 ? '\n' : '';
652
+ return `${raw.trimEnd()}${suffix}${key} = ${serialized}\n`;
653
+ }
654
+ function writeCodexBotConfig(botId, config) {
655
+ const homeDir = ensureCliBotSessionHome('codex-cli', botId);
656
+ const configPath = codexConfigPath(homeDir);
657
+ let raw = fs.existsSync(configPath) ? fs.readFileSync(configPath, 'utf-8') : '';
658
+ raw = setTomlScalarValue(raw, 'model', config.model ?? undefined);
659
+ raw = setTomlScalarValue(raw, 'model_reasoning_effort', config.modelReasoningEffort ?? undefined);
660
+ raw = setTomlScalarValue(raw, 'personality', config.personality ?? undefined);
661
+ raw = setTomlScalarValue(raw, 'service_tier', config.serviceTier ?? undefined);
662
+ raw = setTomlScalarValue(raw, 'sandbox', config.sandbox ?? undefined);
663
+ raw = setTomlScalarValue(raw, 'approval_policy', config.approvalPolicy ?? undefined);
664
+ raw = setTomlScalarValue(raw, 'funolio_statusline_json', null);
665
+ raw = setTomlScalarValue(raw, 'funolio_terminal_title_json', null);
666
+ raw = setTomlScalarValue(raw, 'funolio_experimental_flags_json', null);
667
+ fs.mkdirSync(path.dirname(configPath), { recursive: true });
668
+ fs.writeFileSync(configPath, raw.trimEnd() ? `${raw.trimEnd()}\n` : '', 'utf-8');
669
+ return configPath;
670
+ }
671
+ function readTomlScalarValue(raw, key) {
672
+ const linePattern = new RegExp(`^${key.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\$&')}\\s*=\\s*(.+)$`, 'm');
673
+ const match = linePattern.exec(raw);
674
+ if (!match)
675
+ return null;
676
+ const value = match[1].trim();
677
+ if (!value)
678
+ return null;
679
+ if (value.startsWith('"') && value.endsWith('"')) {
680
+ try {
681
+ return JSON.parse(value);
682
+ }
683
+ catch {
684
+ return value.slice(1, -1);
685
+ }
686
+ }
687
+ return value;
688
+ }
689
+ function readCodexBotConfig(botId) {
690
+ const configPath = codexConfigPath(ensureCliBotSessionHome('codex-cli', botId));
691
+ if (!fs.existsSync(configPath))
692
+ return {};
693
+ let raw = '';
694
+ try {
695
+ raw = fs.readFileSync(configPath, 'utf-8');
696
+ }
697
+ catch {
698
+ return {};
699
+ }
700
+ return {
701
+ model: readTomlScalarValue(raw, 'model'),
702
+ modelReasoningEffort: readTomlScalarValue(raw, 'model_reasoning_effort'),
703
+ personality: readTomlScalarValue(raw, 'personality'),
704
+ serviceTier: readTomlScalarValue(raw, 'service_tier'),
705
+ sandbox: readTomlScalarValue(raw, 'sandbox'),
706
+ approvalPolicy: readTomlScalarValue(raw, 'approval_policy'),
707
+ };
708
+ }
229
709
  //# sourceMappingURL=sync-cli-config.js.map