@coda-console/claude 1.9.0 → 1.10.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 +1 -1
- package/agent/limits.mjs +2 -2
- package/agent/session.mjs +9 -8
- package/package.json +3 -3
- package/scripts/login.mjs +2 -2
- package/scripts/quota.mjs +10 -9
- package/scripts/resources.mjs +6 -0
- package/scripts/panel.mjs +0 -6
package/README.md
CHANGED
package/agent/limits.mjs
CHANGED
|
@@ -4,8 +4,8 @@ import { readFileSync, renameSync, statSync, writeFileSync } from 'node:fs';
|
|
|
4
4
|
// The quota of the account Claude sessions run as, read from what the sessions themselves report. A setup token has no
|
|
5
5
|
// profile scope, so /usage cannot be asked with it; but the CLI sends a `rate_limit_event` whenever a window's rounded
|
|
6
6
|
// percentage or reset time moves, with the fraction of the window used and when it resets (SDKRateLimitInfo). Each
|
|
7
|
-
// session's entry (session.mjs) writes it to `limits.json` in this plugin's state; the「Claude」
|
|
8
|
-
// (scripts/
|
|
7
|
+
// session's entry (session.mjs) writes it to `limits.json` in this plugin's state; the「Claude」resource reads it
|
|
8
|
+
// (scripts/resources.mjs, docs/plugins.md「内置插件:Claude」).
|
|
9
9
|
// `unifiedWindows`, an internal field of newer CLIs, carries every window each time; the top-level fields, which every
|
|
10
10
|
// CLI sends, only the one that limits now.
|
|
11
11
|
const labels = { five_hour: '5 小时', seven_day: '7 天', seven_day_opus: 'Opus · 7 天', seven_day_sonnet: 'Sonnet · 7 天', seven_day_overage_included: 'Fable · 7 天' };
|
package/agent/session.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// its input. What Claude says, its tools and their results, its settings, its title and its usage become session updates;
|
|
4
4
|
// what it keeps going beside a turn, waits (waits.mjs); what it asks, permission requests and forms, withdrawn as the SDK
|
|
5
5
|
// withdraws them. A turn Claude begins on its own is told by what it handles. The plan windows it reports go to the file
|
|
6
|
-
// the plugin's「Claude」
|
|
6
|
+
// the plugin's「Claude」resource reads (limits.json in CODA_PLUGIN_STATE, limits.mjs), not to Coda's session. Chosen, a session
|
|
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
|
import { randomUUID } from 'node:crypto';
|
|
9
9
|
import { readFileSync } from 'node:fs';
|
|
@@ -184,8 +184,8 @@ export class ClaudeSession {
|
|
|
184
184
|
const initialization = await this.initialized(), served = await listed;
|
|
185
185
|
if (this.phase !== 'starting') throw failure('Claude 会话在初始化时结束', -32001);
|
|
186
186
|
this.models = [...claudeModels(initialization.models), ...served]; this.commands = initialization.commands ?? [];
|
|
187
|
-
// Who the session runs as, for the「Claude」
|
|
188
|
-
// only while the
|
|
187
|
+
// Who the session runs as, for the「Claude」resource (limits.mjs): the windows it reports are that account's, and
|
|
188
|
+
// only while the resource is of that account.
|
|
189
189
|
const email = initialization.account?.email;
|
|
190
190
|
this.account = typeof email === 'string' && email.trim() ? accountHash(email) : null;
|
|
191
191
|
if (this.env.CODA_PLUGIN_STATE) new ClaudeSessionLimits({ path: join(this.env.CODA_PLUGIN_STATE, 'limits.json') }).startedAs(this.account);
|
|
@@ -629,15 +629,16 @@ export class ClaudeSession {
|
|
|
629
629
|
const error = failed ? claudeFailure(m.errors?.length || m.result ? errorText(m) : this.turnError?.message || errorText(m),
|
|
630
630
|
{ error: this.turnError?.error, limits: this.turnLimits, window: this.window }) : null;
|
|
631
631
|
this.turnError = null; this.turnLimits = null;
|
|
632
|
+
// A turn of Claude's own has no RPC reply to fail. End its own activity as failed with the reason, rather than
|
|
633
|
+
// saying the error as an answer and marking the work complete. The task that woke it retains its own outcome.
|
|
634
|
+
// It ends before a prompt it took in is answered: Coda opens a turn of Claude's own for what still handles then.
|
|
635
|
+
const own = this.waits.handling || this.waits.unclaimed;
|
|
636
|
+
if (own) this.waits.finished(error ? { error: error.message, title: error.data?._meta?.coda?.failure?.kind === 'quota_exhausted' ? '额度不足' : undefined } : {});
|
|
632
637
|
if (id) {
|
|
633
638
|
const outcome = this.ending ?? (failed ? { failure: error } : { stopReason: cancelled ? 'cancelled' : 'end_turn' });
|
|
634
639
|
if (this.ending || !this.steering.size) this.settle(id, outcome);
|
|
635
640
|
else { this.held = id; if (cancelled || failed) this.dropRest(outcome); }
|
|
636
|
-
} else if (
|
|
637
|
-
// A turn of Claude's own has no RPC reply to fail. End its own activity as failed with the reason, rather than
|
|
638
|
-
// saying the error as an answer and marking the work complete. The task that woke it retains its own outcome.
|
|
639
|
-
this.waits.finished(error ? { error: error.message, title: error.data?._meta?.coda?.failure?.kind === 'quota_exhausted' ? '额度不足' : undefined } : {});
|
|
640
|
-
} else if (failed && this.prompts.size) {
|
|
641
|
+
} else if (!own && failed && this.prompts.size) {
|
|
641
642
|
// A failure of the session itself names no input: none of those given can be said to have run.
|
|
642
643
|
for (const prompt of this.prompts.values()) prompt.reject(error);
|
|
643
644
|
this.prompts.clear();
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"id": "claude",
|
|
4
4
|
"displayName": "Claude",
|
|
5
5
|
"description": "用 Claude Agent SDK 跑会话",
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.10.1",
|
|
7
7
|
"categories": [
|
|
8
8
|
"Agent"
|
|
9
9
|
],
|
|
@@ -61,11 +61,11 @@
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
|
-
"
|
|
64
|
+
"resources": [
|
|
65
65
|
{
|
|
66
66
|
"id": "limits",
|
|
67
67
|
"title": "Claude",
|
|
68
|
-
"command": "node \"$CODA_PLUGIN_PATH/scripts/
|
|
68
|
+
"command": "node \"$CODA_PLUGIN_PATH/scripts/resources.mjs\"",
|
|
69
69
|
"signIn": {
|
|
70
70
|
"command": "exec node \"$CODA_PLUGIN_PATH/scripts/login.mjs\"",
|
|
71
71
|
"installed": "node \"$CODA_PLUGIN_PATH/scripts/login.mjs\" --installed",
|
package/scripts/login.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// The「Claude」
|
|
1
|
+
// The「Claude」resource type's login (`signIn`): `claude auth login --claudeai` of the CLI that comes with the plugin's own Claude
|
|
2
2
|
// SDK (the one its sessions run), never another on the PATH. Coda shows the authorization link this prints
|
|
3
|
-
// and writes the code the page gave back to its input, once (docs/plugins.md
|
|
3
|
+
// and writes the code the page gave back to its input, once (docs/plugins.md「资源的登录」). Only the official link is
|
|
4
4
|
// passed on, and only a code bound to it is handed to the CLI, which does the exchange, keeps and renews the credentials.
|
|
5
5
|
// What the CLI says otherwise is not passed on: it may carry the code. `--installed` says whether that CLI is there.
|
|
6
6
|
import { spawn } from 'node:child_process';
|
package/scripts/quota.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
// What the「Claude」
|
|
2
|
-
// reported (agent/limits.mjs)
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// What the「Claude」resource type shows (docs/plugins.md「内置插件:Claude」): the plan windows this machine's Claude sessions
|
|
2
|
+
// last reported (agent/limits.mjs), each a value of what is left and when it resets. Nothing reported yet shows nothing;
|
|
3
|
+
// the type is then offered under「添加资源」 for signing in.
|
|
4
|
+
export function resources(limits) {
|
|
5
|
+
if (!limits.known()) return { resources: [] };
|
|
5
6
|
const windows = limits.quota();
|
|
6
|
-
// The account the windows are of, compared across machines by Coda's group view.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
// The account the windows are of, compared across machines by Coda's group view; its email is not kept, so it has no name.
|
|
8
|
+
const identity = limits.account ? { identity: `claude:${limits.account}` } : {};
|
|
9
|
+
if (!windows.length) return { resources: [{ name: 'Claude', ...identity, error: '额度记录已过期,会话再运行后更新' }] };
|
|
10
|
+
// Past its reset a window is not known, neither full nor empty: what was used since is not seen from here.
|
|
11
|
+
return { resources: [{ ...identity, values: windows.map(w => ({ label: w.label, value: `剩余 ${w.remainingPercent}%`, fraction: w.remainingPercent / 100, time: w.resetsAt })) }] };
|
|
11
12
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// The「Claude」resources, printed once as `{ resources }`, from what the sessions wrote into this plugin's state.
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { ClaudeSessionLimits } from '../agent/limits.mjs';
|
|
4
|
+
import { resources } from './quota.mjs';
|
|
5
|
+
|
|
6
|
+
console.log(JSON.stringify(resources(new ClaudeSessionLimits({ path: process.env.CODA_PLUGIN_STATE ? join(process.env.CODA_PLUGIN_STATE, 'limits.json') : null }))));
|
package/scripts/panel.mjs
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
// The「Claude」panel's reading, printed once as `{ items }`, from what the sessions wrote into this plugin's state.
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { ClaudeSessionLimits } from '../agent/limits.mjs';
|
|
4
|
-
import { panel } from './quota.mjs';
|
|
5
|
-
|
|
6
|
-
console.log(JSON.stringify(panel(new ClaudeSessionLimits({ path: process.env.CODA_PLUGIN_STATE ? join(process.env.CODA_PLUGIN_STATE, 'limits.json') : null }))));
|