@coda-console/claude 1.12.2 → 1.12.3
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 +6 -0
- package/agent/session.mjs +17 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Claude SDK Agent:Coda 基于 Claude Agent SDK 写的 ACP 入口,一个进程一个 SDK 会话;资源页的「Claude」显示会话报告的额度,可从 Coda 登录。
|
|
4
4
|
|
|
5
|
+
## MCP 配置不进命令行
|
|
6
|
+
|
|
7
|
+
Coda 交来的 MCP 服务(含 `coda` 服务 `env` 里的令牌 `CODA_TOKEN`)若交给 SDK 的 `mcpServers`,会被写成 `--mcp-config '<JSON>'` 放进 Claude 进程的命令行参数,同一台机器上别的用户看得见。
|
|
8
|
+
入口改为:会话打开时在系统临时目录下 `mkdtemp` 建目录(0700),把 `{ mcpServers }` 写进里面的 `mcp.json`(0600),用 `extraArgs` 交 `--mcp-config <路径>`。
|
|
9
|
+
入口这一侧,令牌不再进命令行,只写进这个文件;会话结束(进程被关、查询自己结束)时连目录一起删。进程崩溃留下的目录不另外清理:令牌随托管记录作废,系统临时目录也会自己回收。没有 MCP 服务的会话不建目录。
|
|
10
|
+
|
|
5
11
|
## 认不出的东西
|
|
6
12
|
|
|
7
13
|
Claude Code 会自己长出新东西:SDK 升级带来新的消息类型,服务端让模型返回新的内容块,模型多了新的原生工具。
|
package/agent/session.mjs
CHANGED
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
// that is to go on later is compacted before its cache expires, as the plugin's lifecycle process asks (compaction.mjs).
|
|
8
8
|
// What the SDK sends that is not registered, and native tools not known, are told to Coda (registry.mjs).
|
|
9
9
|
import { randomUUID } from 'node:crypto';
|
|
10
|
-
import { readFileSync } from 'node:fs';
|
|
10
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
11
11
|
import { realpath, stat } from 'node:fs/promises';
|
|
12
|
+
import { tmpdir } from 'node:os';
|
|
12
13
|
import { join } from 'node:path';
|
|
13
14
|
import { agent, PROTOCOL_VERSION, RequestError } from '@agentclientprotocol/sdk';
|
|
14
15
|
import { ClaudeSessionLimits, accountHash } from './limits.mjs';
|
|
@@ -163,7 +164,7 @@ export class ClaudeSession {
|
|
|
163
164
|
// message would start a turn Coda cannot attribute. Continuing a native subagent is in-process and unaffected.
|
|
164
165
|
settings: { crossSessionInbound: 'refuse' },
|
|
165
166
|
includePartialMessages: true, forwardSubagentText: true, cwd: dir,
|
|
166
|
-
...(Object.keys(servers).length ? { mcpServers: servers } : {}), ...(additionalDirectories.length ? { additionalDirectories } : {}),
|
|
167
|
+
...(Object.keys(servers).length ? { extraArgs: { 'mcp-config': this.mcpConfig({ mcpServers: servers }) } } : {}), ...(additionalDirectories.length ? { additionalDirectories } : {}),
|
|
167
168
|
// Identify Coda even when a parent supplied an SDK label (anthropics/claude-code#97074).
|
|
168
169
|
// Claude Code reports running and idle only when asked: idle is what ends a task's wait.
|
|
169
170
|
env: { ...environment, CLAUDE_CODE_ENTRYPOINT: 'coda', CLAUDE_CODE_EMIT_SESSION_STATE_EVENTS: '1' },
|
|
@@ -196,6 +197,18 @@ export class ClaudeSession {
|
|
|
196
197
|
throw error instanceof RequestError ? error : failure(error?.message || 'Claude 会话启动失败');
|
|
197
198
|
}
|
|
198
199
|
}
|
|
200
|
+
// The SDK would put `mcpServers` in Claude's command line, where the servers' environment (Coda's token) shows to every user of
|
|
201
|
+
// the machine. They go in a file only this user reads, by path, which stays until the session ends (`dropMcpConfig`).
|
|
202
|
+
mcpConfig(config) {
|
|
203
|
+
this.mcpDir = mkdtempSync(join(tmpdir(), 'coda-claude-mcp-'));
|
|
204
|
+
const file = join(this.mcpDir, 'mcp.json');
|
|
205
|
+
writeFileSync(file, JSON.stringify(config), { mode: 0o600 });
|
|
206
|
+
return file;
|
|
207
|
+
}
|
|
208
|
+
dropMcpConfig() {
|
|
209
|
+
if (this.mcpDir) rmSync(this.mcpDir, { recursive: true, force: true });
|
|
210
|
+
this.mcpDir = null;
|
|
211
|
+
}
|
|
199
212
|
// A query of the session, reading a prompt stream of its own: on Claude's own models, or on `model` of a chosen
|
|
200
213
|
// service, which it runs with that service as its API and that model for every role. One started after the session
|
|
201
214
|
// opened goes on with the model, mode and effort chosen.
|
|
@@ -436,6 +449,7 @@ export class ClaudeSession {
|
|
|
436
449
|
for (const { reject } of this.prompts.values()) reject(failure(error?.message ?? 'Claude 会话已结束'));
|
|
437
450
|
this.prompts.clear();
|
|
438
451
|
try { query?.close(); } catch {}
|
|
452
|
+
this.dropMcpConfig();
|
|
439
453
|
if (!intended) this.onEnded(error);
|
|
440
454
|
}
|
|
441
455
|
receive(m) {
|
|
@@ -683,5 +697,6 @@ export class ClaudeSession {
|
|
|
683
697
|
for (const withdrawn of this.withdrawals) withdrawn.abort();
|
|
684
698
|
try { this.query?.close(); } catch {}
|
|
685
699
|
if (this.pump) await this.pump; else this.phase = 'ended';
|
|
700
|
+
this.dropMcpConfig();
|
|
686
701
|
}
|
|
687
702
|
}
|