@coda-console/claude 1.10.0 → 1.10.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.
Files changed (2) hide show
  1. package/agent/session.mjs +30 -20
  2. package/package.json +1 -1
package/agent/session.mjs CHANGED
@@ -102,16 +102,7 @@ export class ClaudeSession {
102
102
  .onRequest('session/set_mode', async ({ params }) => { await this.configure('mode', params.modeId); return {}; })
103
103
  .onRequest('session/prompt', ({ params }) => this.prompt(params))
104
104
  .onRequest('_session/steering', params => params ?? {}, ({ params }) => this.steer(params))
105
- .onNotification('session/cancel', ({ params }) => {
106
- if (params.sessionId !== this.sessionId) return;
107
- // While the session moves to another query there is none to interrupt: the turn waiting on the move is stopped there.
108
- if (this.rerouting) this.cancelling = true;
109
- // Messages sent into the turn and not taken yet (steer) are stopped with it: else Claude Code would run them after.
110
- if (this.steering.size) this.dropRest({ stopReason: 'cancelled' });
111
- // Prompts waiting behind a compaction Coda asked for have not begun: they are dropped with it, else they would run after.
112
- else if (this.compacting && this.prompts.size) this.dropQueued();
113
- else void this.query?.interrupt().catch(() => {});
114
- })
105
+ .onNotification('session/cancel', ({ params }) => this.cancel(params))
115
106
  .onRequest('_coda/wait/stop', params => params, ({ params }) => this.stopWait(params))
116
107
  .onRequest('_coda/session/compact', params => params ?? {}, ({ params }) => this.compact(params))
117
108
  .connect(stream);
@@ -311,13 +302,29 @@ export class ClaudeSession {
311
302
  this.heard(content);
312
303
  return { outcome: 'injected' };
313
304
  }
305
+ // Coda stops what the session runs (session/cancel).
306
+ cancel({ sessionId }) {
307
+ if (sessionId !== this.sessionId) return;
308
+ // While the session moves to another query there is none to interrupt: the turn waiting on the move is stopped there.
309
+ if (this.rerouting) this.cancelling = true;
310
+ // Messages sent into the turn and not taken yet (steer) are stopped with it: else Claude Code would run them after.
311
+ if (this.steering.size) this.dropRest({ stopReason: 'cancelled' });
312
+ // Prompts waiting behind a compaction Coda asked for have not begun: they are dropped with it, else they would run after.
313
+ else if (this.compacting && this.prompts.size) this.dropQueued();
314
+ else void this.query?.interrupt().catch(() => {});
315
+ }
314
316
  // What was said into the prompt and is not taken yet is not to run after it ends, stopped or failed: Claude Code drops it
315
317
  // (cancelQueued), and the prompt ends as `outcome` once nothing of it goes on — at the drop's receipt when no native turn
316
- // is going (one held, whose own turn ended), else as the turn going ends (result).
318
+ // is going (one held, whose own turn ended), else as the turn going ends (result). A prompt dropped before any turn took it
319
+ // ends stopped then.
317
320
  dropRest(outcome) {
318
321
  this.ending = outcome;
319
322
  void this.query?.interrupt({ cancelQueued: true }).then(receipt => {
320
- for (const id of receipt?.cancelled ?? []) this.steering.delete(id);
323
+ for (const id of receipt?.cancelled ?? []) {
324
+ this.steering.delete(id);
325
+ const prompt = this.prompts.get(id);
326
+ if (prompt) { this.prompts.delete(id); this.ending = null; prompt.resolve({ stopReason: 'cancelled' }); }
327
+ }
321
328
  this.dropped(receipt?.cancelled);
322
329
  if (this.held && !this.turning) this.settle(this.held, this.ending);
323
330
  }, () => {});
@@ -622,23 +629,26 @@ export class ClaudeSession {
622
629
  }
623
630
  // A message sent into the prompt's turn (steer) is the prompt's, and so is the turn Claude Code runs it in when the prompt's
624
631
  // own ended before taking it: the prompt is answered once none is left to take. Stopped or failed with some not taken
625
- // yet, it ends once those are dropped (dropRest); one ending already ends as it was to.
632
+ // yet, it ends once those are dropped (dropRest); one ending already ends as it was to. One held whose messages were all
633
+ // dropped while another turn went ends as that turn ends.
626
634
  const steered = ids.filter(id => this.steering.delete(id)).length > 0;
627
- const id = ids.find(id => this.prompts.has(id)) ?? (steered ? this.held : undefined);
635
+ const id = ids.find(id => this.prompts.has(id)) ?? (steered || !this.steering.size ? this.held : undefined);
628
636
  const cancelled = interrupted(m), failed = !cancelled && (m.is_error || m.subtype !== 'success');
629
637
  const error = failed ? claudeFailure(m.errors?.length || m.result ? errorText(m) : this.turnError?.message || errorText(m),
630
638
  { error: this.turnError?.error, limits: this.turnLimits, window: this.window }) : null;
631
639
  this.turnError = null; this.turnLimits = null;
640
+ // A turn of Claude's own has no RPC reply to fail. End its own activity as failed with the reason, rather than
641
+ // saying the error as an answer and marking the work complete. The task that woke it retains its own outcome.
642
+ // It ends before a prompt it took in is answered: Coda opens a turn of Claude's own for what still handles then.
643
+ const own = this.waits.handling || this.waits.unclaimed;
644
+ if (own) this.waits.finished(error ? { error: error.message, title: error.data?._meta?.coda?.failure?.kind === 'quota_exhausted' ? '额度不足' : undefined } : {});
632
645
  if (id) {
633
646
  const outcome = this.ending ?? (failed ? { failure: error } : { stopReason: cancelled ? 'cancelled' : 'end_turn' });
634
647
  if (this.ending || !this.steering.size) this.settle(id, outcome);
635
648
  else { this.held = id; if (cancelled || failed) this.dropRest(outcome); }
636
- } else if (this.waits.handling || this.waits.unclaimed) {
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
- // A failure of the session itself names no input: none of those given can be said to have run.
649
+ } else if (!own && failed && this.prompts.size && !(m.queued_turn_count > 0)) {
650
+ // A failure of the session itself names no input: none of those given can be said to have run. Those still queued
651
+ // (queued_turn_count) run after it, each to a result of its own.
642
652
  for (const prompt of this.prompts.values()) prompt.reject(error);
643
653
  this.prompts.clear();
644
654
  }
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.10.0",
6
+ "version": "1.10.2",
7
7
  "categories": [
8
8
  "Agent"
9
9
  ],