@coda-console/claude 1.10.1 → 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.
- package/agent/session.mjs +25 -16
- 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 ?? [])
|
|
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,9 +629,10 @@ 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;
|
|
@@ -638,8 +646,9 @@ export class ClaudeSession {
|
|
|
638
646
|
const outcome = this.ending ?? (failed ? { failure: error } : { stopReason: cancelled ? 'cancelled' : 'end_turn' });
|
|
639
647
|
if (this.ending || !this.steering.size) this.settle(id, outcome);
|
|
640
648
|
else { this.held = id; if (cancelled || failed) this.dropRest(outcome); }
|
|
641
|
-
} else if (!own && failed && this.prompts.size) {
|
|
642
|
-
// 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.
|
|
643
652
|
for (const prompt of this.prompts.values()) prompt.reject(error);
|
|
644
653
|
this.prompts.clear();
|
|
645
654
|
}
|