@coda-console/codex 2.0.1 → 2.1.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
@@ -4,6 +4,10 @@ Codex Agent:Codex 插件提供的入口运行 codex-acp,报告子 Agent、
4
4
 
5
5
  实时的上下文压缩(自动或手动)作为 Coda 的「整理上下文」记录显示:开始报 `compaction_update` in_progress、完成报 completed,Coda 据此知道会话压缩过;回合失败或中断、压缩未完成时补报 failed,不再出「Compact conversation」工具卡。恢复会话时,历史里的压缩仍显示为「Compact conversation」工具卡,不上报,免得 Coda 把它当成新的压缩。
6
6
 
7
+ **Coda 自己的 MCP 服务器**(名为 `coda`、经后端的 mcp-shim 接入的那一个)在交给 Codex 时多带两项按服务器的设置:`default_tools_approval_mode = "approve"`(工具请求都交到 Coda 自己的权限边界)与 `tool_timeout_sec = 900`。Codex 对单次 MCP 工具调用默认只等 300 秒,到点就报 `timed out awaiting tools/call` 并取消;Coda 的工具里有远程执行,命令最长跑 10 分钟,所以给 Coda 的服务器 15 分钟。用户自己配的其他 MCP 服务器、以及 Codex 配置里本来就有的同名 `coda` 服务器不受影响,沿用它们自己的设置(没设就是 Codex 的 300 秒)。
8
+
9
+ **会话临时目录可写**:Coda 给会话一个临时目录时(环境变量 `CODA_SESSION_TMP`,绝对路径,`<状态根>/session-tmp/<会话ID>`),它加进 Codex workspace-write 沙箱的可写根,和 Coda 经 ACP 交来的附加目录同样处理(每一轮的沙箱策略与会话配置的 `sandbox_workspace_write.writable_roots`),从别的机器拉下来的文件可以原地改再推回去。只加这个会话自己的目录,不加 `session-tmp/`(别的会话的目录在它下面);完全放开模式本来就能写,只读的沙箱策略不加;没有这个变量(旧的后端)或不是绝对路径时和以前一样。Codex 的 `TMPDIR` 不改。
10
+
7
11
  ## 资源页:Codex 的登录与额度
8
12
 
9
13
  资源页上的资源类型「Codex」:这台机器上 Codex 自己的登录(本机登录)和它的额度。打开「多账号」时它输出为空,「Codex」里是多账号管理的账号(类型 `accounts`,见下)。
@@ -44,3 +48,4 @@ Codex Agent:Codex 插件提供的入口运行 codex-acp,报告子 Agent、
44
48
  交令牌(`chatgptAuthTokens`)是 app-server 的实验接口:升级 codex-acp 或 Codex 时复核登录、`account/read` 的身份核对、续期请求与轮次边界。
45
49
 
46
50
  「模型服务」设置、异步消息与提问见仓库根 README 的「模型服务」「Codex 异步消息与提问」。
51
+ 异步提问被宿主当场拒绝(`decline` 带非空 `_meta.coda.reason`)时,交给 Codex 的是这段文字原文;不带 reason 的 `decline` 与 `cancel` 仍是「用户没有回答「<问题>」」。同步提问(`item/tool/requestUserInput`)由 codex-acp 回 `{ answers: {} }`,拿不到 reason。
package/agent/entry.mjs CHANGED
@@ -4,7 +4,7 @@
4
4
  // and a steer that finds no turn going is answered `promptRequired` (steering.mjs); Codex's async messages are shown and its
5
5
  // async questions asked as cards whose answers it is given within the same turn (questions.mjs); its context compactions told as
6
6
  // `compaction_update` (compaction.mjs); what of Codex is not adapted
7
- // is told to Coda (unrecognized.mjs); the models of the model service chosen in Coda join Codex's own (providers.mjs). What Coda wants of Codex beyond ACP is set here: the mode a session starts in, and
7
+ // is told to Coda (unrecognized.mjs); the models of the model service chosen in Coda join Codex's own (providers.mjs). the session's own temporary directory is writable in its sandbox (session-tmp.mjs). What Coda wants of Codex beyond ACP is set here: the mode a session starts in, and
8
8
  // which Codex program runs, through the account bridge when「多账号」chooses the account (accounts.mjs).
9
9
  import { createRequire, registerHooks } from 'node:module';
10
10
  import { spawnSync } from 'node:child_process';
@@ -30,6 +30,7 @@ import { reportedCodexSleeps } from './sleep.mjs';
30
30
  import { reportedCodexCompactions } from './compaction.mjs';
31
31
  import { codexDisplayNames } from './display.mjs';
32
32
  import { trustedCodaMcpRequests } from './mcp-policy.mjs';
33
+ import { writableCodexSessionTmp } from './session-tmp.mjs';
33
34
  import { CodexQuestions, shownCodexAsyncMessages } from './questions.mjs';
34
35
  import { CodexUnrecognized, listenUnrecognized, reportedCodexUnrecognized } from './unrecognized.mjs';
35
36
 
@@ -90,6 +91,6 @@ registerHooks({ load(url, context, nextLoad) {
90
91
  const loaded = nextLoad(url, context);
91
92
  if (url !== adapter.href) return loaded;
92
93
  return { ...loaded, source: reportedCodexUnrecognized(shownCodexAsyncMessages(reportedCodexCompactions(reportedCodexSleeps(reportedCodexFailures(codexOptionsAsShown(relayedCodexStreams(orderedCodexTitles(followCodexProcessExit(continuedCodexSubagents(
93
- promptRequiredCodexSteering(instructedCodexThreads(servedCodexModels(networkedCodexDevelopment(trustedCodaMcpRequests(Buffer.from(loaded.source).toString('utf8')))))))))))))))) };
94
+ promptRequiredCodexSteering(instructedCodexThreads(servedCodexModels(networkedCodexDevelopment(writableCodexSessionTmp(trustedCodaMcpRequests(Buffer.from(loaded.source).toString('utf8'))))))))))))))))) };
94
95
  } });
95
96
  await import(adapter.href);
@@ -1,5 +1,9 @@
1
1
  import { isAbsolute, sep } from 'node:path';
2
2
 
3
+ // Codex gives up on a single MCP tool call after 300 seconds unless the server sets `tool_timeout_sec`. Coda's own tools include
4
+ // remote execution, whose commands may run for 10 minutes (the call's deadline is a little longer), so Coda's server gets 15 minutes.
5
+ export const CODA_TOOL_TIMEOUT_SEC = 900;
6
+
3
7
  // ACP is the trusted host boundary: Coda reserves the server name `coda` and supplies this stdio shim itself
4
8
  // (backend/src/components/session-config/service.mjs). Do not infer trust from a Codex config entry of the same name.
5
9
  // The shape check limits the exception to the current Coda transport, not arbitrary HTTP or plugin MCP servers.
@@ -12,7 +16,8 @@ export function codaMcpPolicy(server, config) {
12
16
  args[3] !== '--socket' || typeof args[4] !== 'string' || !isAbsolute(args[4])) return config;
13
17
  // All tools of Coda's own server, including workflow_run/approve-command, must reach Coda's permission boundary.
14
18
  // This approves the MCP request, not the command or human decision it asks Coda to handle.
15
- return { ...config, default_tools_approval_mode: 'approve' };
19
+ // Long tools of Coda's server (remote execution runs up to 10 minutes) must not be cut by Codex's 300-second default.
20
+ return { ...config, default_tools_approval_mode: 'approve', tool_timeout_sec: CODA_TOOL_TIMEOUT_SEC };
16
21
  }
17
22
 
18
23
  const before = ' "mcp_servers": Object.fromEntries(serversToConfigure.map((mcp) => [mcp.name, this.createMcpSeverConfig(mcp.server)]))';
@@ -51,8 +51,11 @@ export function questionForm(sessionId, questions) {
51
51
  return { sessionId, mode: 'form', message: 'Codex 需要你的回答', requestedSchema: { type: 'object', properties, required: questions.map((_, i) => `q${i}`) } };
52
52
  }
53
53
 
54
- // What the user said to a card, as the message Codex is told, a line a question.
54
+ // What the user said to a card, as the message Codex is told, a line a question. A decline with the host's reason
55
+ // (coda-protocol「宿主当场拒绝表单」) is told as that text, once, as it is.
55
56
  export function answerText(questions, response) {
57
+ const reason = response?.action === 'decline' ? response._meta?.coda?.reason : null;
58
+ if (typeof reason === 'string' && reason.trim()) return reason;
56
59
  const content = response?.action === 'accept' && record(response.content) ? response.content : null;
57
60
  return questions.map((q, i) => {
58
61
  if (!content) return `用户没有回答「${q.title}」`;
@@ -0,0 +1,26 @@
1
+ import { isAbsolute } from 'node:path';
2
+
3
+ // Coda gives each session's Agent process its own temporary directory (`CODA_SESSION_TMP`, `<state>/session-tmp/<session>`), where
4
+ // files the session pulls from other machines land, to be edited in place and pushed back. codex-acp's workspace-write sandbox
5
+ // allows only the working directory, `$TMPDIR`, `/tmp` and the ACP additional directories, so the session's own directory joins
6
+ // those roots, the same way the additional directories do: in each turn's sandbox policy and in the session config. It is that
7
+ // one directory, never `session-tmp/` itself (sessions would write each other's). A read-only or full-access policy is left as it
8
+ // is: codex-acp widens only workspace-write policies. Without an absolute `CODA_SESSION_TMP` nothing changes.
9
+ export function withSessionTmp(directories, env = process.env) {
10
+ const own = env.CODA_SESSION_TMP;
11
+ return typeof own === 'string' && isAbsolute(own) && !directories.includes(own) ? [...directories, own] : directories;
12
+ }
13
+
14
+ const patches = [
15
+ [' const configWithWorkspaceRoots = mergeSandboxWorkspaceWriteRoots(mergedConfig, additionalDirectories);',
16
+ ' const configWithWorkspaceRoots = mergeSandboxWorkspaceWriteRoots(mergedConfig, withSessionTmp(additionalDirectories));'],
17
+ [' sandboxPolicy: addAdditionalDirectoriesToSandboxPolicy(agentMode.sandboxPolicy, additionalDirectories),',
18
+ ' sandboxPolicy: addAdditionalDirectoriesToSandboxPolicy(agentMode.sandboxPolicy, withSessionTmp(additionalDirectories)),'],
19
+ ];
20
+ export function writableCodexSessionTmp(source) {
21
+ for (const [before, after] of patches) {
22
+ if (source.split(before).length !== 2) throw new Error('codex-acp session temporary directory patch no longer matches the locked adapter');
23
+ source = source.replace(before, after);
24
+ }
25
+ return `import { withSessionTmp } from ${JSON.stringify(import.meta.url)};\n${source.replace(/^#![^\n]*\n/, '')}`;
26
+ }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "id": "codex",
4
4
  "displayName": "Codex",
5
5
  "description": "用 OpenAI Codex 跑会话",
6
- "version": "2.0.1",
6
+ "version": "2.1.2",
7
7
  "engines": {
8
8
  "coda": 6
9
9
  },