@coda-console/claude 1.17.1 → 1.18.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.
- package/README.md +2 -0
- package/agent/session.mjs +10 -1
- package/agent/usage.mjs +21 -7
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Claude SDK Agent:Coda 基于 Claude Agent SDK 写的 ACP 入口,一个进程一个 SDK 会话;资源页的「Claude」显示会话报告的额度,可从 Coda 登录。
|
|
4
4
|
|
|
5
|
+
**审批模式**:清单最低 `engines.coda: 21`,按 API Level 21 的四级模式登记:人工审批档 `default`、自动审批档 `auto`、完全放开档 `bypassPermissions`,安全模式 `plan`、`dontAsk`;未选档时默认等效 `manual`。其余模式(如 `acceptEdits`)未登记,按 `auto` 归档。
|
|
6
|
+
|
|
5
7
|
## MCP 配置不进命令行
|
|
6
8
|
|
|
7
9
|
Coda 交来的 MCP 服务(含 `coda` 服务 `env` 里的令牌 `CODA_TOKEN`)若交给 SDK 的 `mcpServers`,会被写成 `--mcp-config '<JSON>'` 放进 Claude 进程的命令行参数,同一台机器上别的用户看得见。
|
package/agent/session.mjs
CHANGED
|
@@ -94,6 +94,10 @@ export class ClaudeSession {
|
|
|
94
94
|
// The messages sent into the prompt's turn not yet taken (steer), the prompt whose own turn ended before they were, how
|
|
95
95
|
// the prompt ends once it is ending before they are taken (dropRest), and whether a native turn is going.
|
|
96
96
|
this.steering = new Set(); this.held = null; this.ending = null; this.turning = false;
|
|
97
|
+
// The model chosen that the turn going runs as (system init): what its usage says it asked for on Claude's own models.
|
|
98
|
+
this.turnAsked = null;
|
|
99
|
+
// The models the turn's main thread said it ran on (its init, its own messages; never a subagent's), for that usage.
|
|
100
|
+
this.turnModels = new Set();
|
|
97
101
|
// The model services chosen in Coda (providers.mjs), and the service's model the query runs on: null on Claude's own.
|
|
98
102
|
this.services = chosenServices(env); this.serviceModel = null;
|
|
99
103
|
this.models = []; this.commands = []; this.terminal = null; this.current = { mode: 'default', model: undefined, effort: null, ultracode: null };
|
|
@@ -515,6 +519,9 @@ export class ClaudeSession {
|
|
|
515
519
|
// Its effort is the one applied, the model's own included: what was chosen stays what it was. A query on the
|
|
516
520
|
// service's model reports it by that service's name for it.
|
|
517
521
|
this.current = { ...this.current, model: this.serviceModel ?? reportedModel(this.models, this.current.model, m.model), mode: m.permissionMode ?? this.current.mode };
|
|
522
|
+
// The model this turn runs as chosen: a model chosen while it goes is the next turn's.
|
|
523
|
+
this.turnAsked = this.current.model;
|
|
524
|
+
this.turnModels = new Set([m.model]);
|
|
518
525
|
if (!this.title) {
|
|
519
526
|
const sessionId = this.sessionId;
|
|
520
527
|
this.title = new SessionTitle({ sdk: this.sdk, query: this.query, cwd: this.cwd, sessionId, alive: () => ['starting', 'running'].includes(this.phase),
|
|
@@ -632,6 +639,7 @@ export class ClaudeSession {
|
|
|
632
639
|
if (!parent) {
|
|
633
640
|
this.turnError = m.error ? { error: m.error, message: text(m.message?.content) } : null;
|
|
634
641
|
if (m.error) return;
|
|
642
|
+
this.turnModels.add(m.message?.model);
|
|
635
643
|
// One not streamed was a request too.
|
|
636
644
|
if (!blocks) this.cacheUse.requested();
|
|
637
645
|
this.cacheUse.used(m.message?.usage);
|
|
@@ -671,7 +679,8 @@ export class ClaudeSession {
|
|
|
671
679
|
}
|
|
672
680
|
result(m) {
|
|
673
681
|
// What this turn used; the base moves with every result, whose turn it is told as (below) or not.
|
|
674
|
-
const spent = this.usage.measure(m);
|
|
682
|
+
const spent = this.usage.measure(m, this.turnAsked ?? this.current.model, [...this.turnModels]);
|
|
683
|
+
this.turnModels = new Set();
|
|
675
684
|
const windows = Object.values(m.modelUsage ?? {});
|
|
676
685
|
const ids = takenIn(m);
|
|
677
686
|
// The compaction Coda asked for (compact) is the turn that names its input. Any other is the session's own, whose cache runs
|
package/agent/usage.mjs
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
// the uncached input (the cached reads and writes not in it), the cache reads and writes beside it, and `breakdown` by model
|
|
3
3
|
// where the models are known (when it is there, it is the whole of what Coda counts; the top level is its sum). A model is told as
|
|
4
4
|
// `served` when the SDK names the one that ran (`canonicalModel`) and else by the SDK's own name as the unlayered `model` label; on a
|
|
5
|
-
// model service (providers.mjs) the usage says its `service` and `asked` instead (Coda's docs/plugins.md「Coda 的用量记录」).
|
|
5
|
+
// model service (providers.mjs) the usage says its `service` and `asked` instead (Coda's docs/plugins.md「Coda 的用量记录」). On
|
|
6
|
+
// Claude's own models the row of the model the turn asked for (the session's chosen one) also says `asked`, so that its turns and
|
|
7
|
+
// tokens are one record; a subagent's model is never told as asked, nor is a model told by `model` (that label stands alone). That
|
|
8
|
+
// row is the one named as asked (by its key or canonical name) or one the turn's main thread said it ran on (`confirmed`: the
|
|
9
|
+
// models of its init and of its own messages): a lone model that is neither, a subagent's say, is never taken for the main one.
|
|
6
10
|
//
|
|
7
11
|
// The SDK's result carries `modelUsage`, per model and cumulative over the query() call: main loop, Task subagents and all. This
|
|
8
12
|
// keeps what the last result said (`base`) and answers each result with the difference, so that a turn says what it used.
|
|
@@ -78,8 +82,9 @@ export class PromptUsage {
|
|
|
78
82
|
// A query begins: a new session's from nothing, a resumed one's with its history (its first result says it). `requested`: the
|
|
79
83
|
// `{ service, asked }` of the model service it runs on (`{}` for a service whose address gives no reference), null on Claude's own models.
|
|
80
84
|
restarted(resumed, requested = null) { this.base = resumed ? null : new Map(); this.held = new Spent(); this.requested = requested; }
|
|
81
|
-
// What this result's turn used (never throws: the result is handled whatever this makes of it).
|
|
82
|
-
|
|
85
|
+
// What this result's turn used (never throws: the result is handled whatever this makes of it). `asked`: the model the turn ran as
|
|
86
|
+
// chosen, on Claude's own models; `confirmed`: the models its main thread said it ran on (never a subagent's).
|
|
87
|
+
measure(m, asked = null, confirmed = []) {
|
|
83
88
|
const spent = new Spent();
|
|
84
89
|
try {
|
|
85
90
|
const entries = Object.entries(m.modelUsage ?? {}).map(([key, usage]) => ({ key, usage, counts: fromModelUsage(usage) })).filter(entry => entry.counts);
|
|
@@ -90,11 +95,20 @@ export class PromptUsage {
|
|
|
90
95
|
if (counts) spent.addLoose(counts);
|
|
91
96
|
return spent;
|
|
92
97
|
}
|
|
93
|
-
|
|
98
|
+
const named = entry => !this.requested && typeof entry.usage.canonicalModel === 'string' && entry.usage.canonicalModel;
|
|
99
|
+
// What each model used this turn (the results hold the whole query's totals, those of models idle now included).
|
|
100
|
+
const turn = entries.map(entry => ({ ...entry, used: increase(entry.counts, this.base.get(entry.key)) }));
|
|
101
|
+
for (const { key, counts } of turn) this.base.set(key, counts);
|
|
102
|
+
const active = turn.filter(entry => !none(entry.used));
|
|
103
|
+
// The main model's row is the one asked for, or else the one its main thread said ran, whatever name the SDK gives it.
|
|
104
|
+
const bare = name => typeof name === 'string' ? name.replace(/\[[^\]]+\]$/, '') : name;
|
|
105
|
+
const is = names => entry => named(entry) && [entry.key, named(entry)].some(name => names.map(bare).includes(bare(name)));
|
|
106
|
+
const main = !this.requested && typeof asked === 'string' && asked ? active.find(is([asked])) ?? active.find(is([...confirmed])) : undefined;
|
|
107
|
+
for (const entry of active) {
|
|
108
|
+
const { key, used } = entry, canonical = named(entry);
|
|
94
109
|
// A service's model is told by the name the SDK has it asked as, which is no model that ran; Claude's own by the canonical one.
|
|
95
|
-
const
|
|
96
|
-
spent.addModel(
|
|
97
|
-
this.base.set(key, counts);
|
|
110
|
+
const label = !canonical ? { model: key } : main && canonical === named(main) ? { asked, served: canonical } : { served: canonical };
|
|
111
|
+
spent.addModel(label, used);
|
|
98
112
|
}
|
|
99
113
|
} catch {}
|
|
100
114
|
return spent;
|
package/package.json
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
"id": "claude",
|
|
4
4
|
"displayName": "Claude",
|
|
5
5
|
"description": "用 Claude Agent SDK 跑会话",
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.18.1",
|
|
7
7
|
"engines": {
|
|
8
|
-
"coda":
|
|
8
|
+
"coda": 21
|
|
9
9
|
},
|
|
10
10
|
"categories": [
|
|
11
11
|
"Agent"
|
|
@@ -27,8 +27,11 @@
|
|
|
27
27
|
"title": "审批模式",
|
|
28
28
|
"unset": "Agent 默认",
|
|
29
29
|
"note": "未选择时从人工审批开始;Claude 自己切换的模式保持不变。",
|
|
30
|
+
"manual": "default",
|
|
30
31
|
"auto": "auto",
|
|
31
|
-
"full": "bypassPermissions"
|
|
32
|
+
"full": "bypassPermissions",
|
|
33
|
+
"safe": ["plan", "dontAsk"],
|
|
34
|
+
"default": "manual"
|
|
32
35
|
},
|
|
33
36
|
"skillsDir": ".claude/skills",
|
|
34
37
|
"configFiles": [
|