fix: an answer to a blocked agent goes ahead of the queue
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
1 parent
f3250e594e
commit
e6afb3ebf9
3 files changed
+50
-5
No files matched your search
@@ -48,7 +48,6 @@ import {
|
||||
decide,
|
||||
shouldDrain,
|
||||
shouldStartCountdown,
|
||||
queueBlocksDirectSend,
|
||||
parseSendArgs,
|
||||
sendNow as sendToTerminal,
|
||||
} from "./delivery.js";
|
||||
@@ -94,6 +93,7 @@ import {
|
||||
queueLabel,
|
||||
shortPath,
|
||||
stillSameAgent,
|
||||
directSendBlocked,
|
||||
statusText,
|
||||
targetAgent,
|
||||
} from "./view.js";
|
||||
@@ -1066,9 +1066,14 @@ export default class Composer extends View {
|
||||
const allowed = mode === "now" || canAutoSend(this.draftReady, key);
|
||||
// A message that is on the wire, waits in the queue or counts down goes first: the
|
||||
// new one waits behind it in the queue instead of vanishing or jumping
|
||||
// the line (Ctrl+Enter is the person's own order and does jump).
|
||||
const busy =
|
||||
this.draining.has(key) || (mode !== "now" && queueBlocksDirectSend(this.state.queue[key]));
|
||||
// the line. Ctrl+Enter is the person's own order and does jump, and so is
|
||||
// an answer to a blocked agent (see `directSendBlocked`).
|
||||
const busy = directSendBlocked({
|
||||
draining: this.draining.has(key),
|
||||
mode,
|
||||
status: this.statusOf(agent),
|
||||
queue: this.state.queue[key],
|
||||
});
|
||||
if (decision.kind === "send" && allowed && !busy) {
|
||||
// The person's own Enter answers an agent that waits for them: it goes
|
||||
// through even though the agent is blocked (`hc send --force`). Never
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
// belongs to an agent (the draft, the queue, the attachments) is keyed by the
|
||||
// agent's address, so two Claude Code agents never share a draft.
|
||||
|
||||
import { drain, gateAfter } from "./delivery.js";
|
||||
import { drain, gateAfter, queueBlocksDirectSend } from "./delivery.js";
|
||||
import { LIMITS } from "./attachments.js";
|
||||
|
||||
/**
|
||||
@@ -495,3 +495,24 @@ export function canAutoSend(ready, key) {
|
||||
export function stillSameAgent({ before, after, target }) {
|
||||
return before !== "" && before === after && before === target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Must a message that could go out now wait behind what is already in flight
|
||||
* or in the queue?
|
||||
*
|
||||
* - a message on the wire always goes first (`draining`);
|
||||
* - Ctrl+Enter (`mode "now"`) is the person's own order and does not wait;
|
||||
* - an answer to an agent that is `blocked` does not wait either: the queue
|
||||
* does not start while the agent waits for the person, so queueing the
|
||||
* answer would leave the agent waiting for ever - it goes ahead (with
|
||||
* `--force`) and the queue stays as it is;
|
||||
* - otherwise it waits when a message is queued or counting down.
|
||||
*
|
||||
* @param {{draining:boolean, mode:string, status:string, queue:object[]|undefined}} input
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function directSendBlocked({ draining, mode, status, queue }) {
|
||||
if (draining) return true;
|
||||
if (mode === "now" || status === "blocked") return false;
|
||||
return queueBlocksDirectSend(queue);
|
||||
}
|
||||
@@ -81,3 +81,22 @@ test("stillSameAgent: only when the field and the focus are on one agent", () =>
|
||||
assert.equal(stillSameAgent({ before: "", after: "", target: "" }), false);
|
||||
assert.equal(stillSameAgent({ before: "", after: "t2", target: "t2" }), false);
|
||||
});
|
||||
|
||||
import { directSendBlocked } from "../mod/ovis-composer/view.js";
|
||||
|
||||
test("directSendBlocked: who must wait behind the queue", () => {
|
||||
const queue = [{ state: "queued" }];
|
||||
// an answer to a blocked agent goes ahead of the queue
|
||||
assert.equal(directSendBlocked({ draining: false, mode: "auto", status: "blocked", queue }), false);
|
||||
// an idle agent with a queue: the new message waits at the end
|
||||
assert.equal(directSendBlocked({ draining: false, mode: "auto", status: "idle", queue }), true);
|
||||
assert.equal(directSendBlocked({ draining: false, mode: "auto", status: "done", queue }), true);
|
||||
// Ctrl+Enter is the person's own order
|
||||
assert.equal(directSendBlocked({ draining: false, mode: "now", status: "idle", queue }), false);
|
||||
// a message on the wire always goes first
|
||||
assert.equal(directSendBlocked({ draining: true, mode: "now", status: "blocked", queue: [] }), true);
|
||||
assert.equal(directSendBlocked({ draining: true, mode: "auto", status: "idle", queue }), true);
|
||||
// nothing waits
|
||||
assert.equal(directSendBlocked({ draining: false, mode: "auto", status: "idle", queue: [] }), false);
|
||||
assert.equal(directSendBlocked({ draining: false, mode: "auto", status: "idle", queue: [{ state: "held" }] }), false);
|
||||
});
|
||||
Reference in new issue
Block a user