fix: a new message goes behind queued entries, not ahead of them
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
1 parent
cb7f7b58f5
commit
2dbb3fe23e
3 files changed
+32
-4
No files matched your search
@@ -130,6 +130,17 @@ export function shouldStartCountdown({ status, queue, gateOpen, stopped }) {
|
|||||||
return queue.some((item) => item.state === "queued");
|
return queue.some((item) => item.state === "queued");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does a message wait in the queue (`queued`, or counting down)? Then a new
|
||||||
|
* message does not go out ahead of it - it takes its place at the end.
|
||||||
|
*
|
||||||
|
* @param {QueueItem[]|undefined} queue
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
export function queueBlocksDirectSend(queue) {
|
||||||
|
return (Array.isArray(queue) ? queue : []).some((item) => item.state === "queued" || item.state === "countdown");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The turn gate: the next message goes out only after a whole turn was seen -
|
* The turn gate: the next message goes out only after a whole turn was seen -
|
||||||
* the agent was working and then came back to idle/done. Without that
|
* the agent was working and then came back to idle/done. Without that
|
||||||
|
|||||||
@@ -39,7 +39,14 @@ import * as fs from "fs/promises";
|
|||||||
|
|
||||||
import { createState, reduce } from "./state.js";
|
import { createState, reduce } from "./state.js";
|
||||||
import { keyIntent } from "./keys.js";
|
import { keyIntent } from "./keys.js";
|
||||||
import { decide, shouldDrain, shouldStartCountdown, parseSendArgs, sendNow as sendToTerminal } from "./delivery.js";
|
import {
|
||||||
|
decide,
|
||||||
|
shouldDrain,
|
||||||
|
shouldStartCountdown,
|
||||||
|
queueBlocksDirectSend,
|
||||||
|
parseSendArgs,
|
||||||
|
sendNow as sendToTerminal,
|
||||||
|
} from "./delivery.js";
|
||||||
import { detect as detectTrigger, rank, merge, startsLine } from "./suggest.js";
|
import { detect as detectTrigger, rank, merge, startsLine } from "./suggest.js";
|
||||||
import * as catalog from "./catalog.js";
|
import * as catalog from "./catalog.js";
|
||||||
import { LIMITS, validate, mention, removeMention, kindOf, formatBytes, relativeTo } from "./attachments.js";
|
import { LIMITS, validate, mention, removeMention, kindOf, formatBytes, relativeTo } from "./attachments.js";
|
||||||
@@ -1055,12 +1062,11 @@ export default class Composer extends View {
|
|||||||
// Not before the draft and the identity of the agent were checked - the
|
// Not before the draft and the identity of the agent were checked - the
|
||||||
// person's own "send now" (Ctrl+Enter) is the exception.
|
// person's own "send now" (Ctrl+Enter) is the exception.
|
||||||
const allowed = mode === "now" || canAutoSend(this.draftReady, key);
|
const allowed = mode === "now" || canAutoSend(this.draftReady, key);
|
||||||
// A message that is on the wire, or one that counts down, goes first: the
|
// 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
|
// 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).
|
// the line (Ctrl+Enter is the person's own order and does jump).
|
||||||
const busy =
|
const busy =
|
||||||
this.draining.has(key) ||
|
this.draining.has(key) || (mode !== "now" && queueBlocksDirectSend(this.state.queue[key]));
|
||||||
(mode !== "now" && (this.state.queue[key] ?? []).some((entry) => entry.state === "countdown"));
|
|
||||||
if (decision.kind === "send" && allowed && !busy) {
|
if (decision.kind === "send" && allowed && !busy) {
|
||||||
// The person's own Enter answers an agent that waits for them: it goes
|
// 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
|
// through even though the agent is blocked (`hc send --force`). Never
|
||||||
|
|||||||
@@ -105,3 +105,14 @@ test("shouldStartCountdown: stopped or closed gate blocks", () => {
|
|||||||
test("shouldStartCountdown tolerates a non-array queue", () => {
|
test("shouldStartCountdown tolerates a non-array queue", () => {
|
||||||
assert.equal(shouldStartCountdown(sc({ queue: null })), false);
|
assert.equal(shouldStartCountdown(sc({ queue: null })), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
import { queueBlocksDirectSend } from "../mod/ovis-composer/delivery.js";
|
||||||
|
|
||||||
|
test("queueBlocksDirectSend: a message that waits (queued or counting down) goes first", () => {
|
||||||
|
assert.equal(queueBlocksDirectSend([{ state: "queued" }]), true);
|
||||||
|
assert.equal(queueBlocksDirectSend([{ state: "countdown" }]), true);
|
||||||
|
assert.equal(queueBlocksDirectSend([{ state: "held" }, { state: "uncertain" }]), false);
|
||||||
|
assert.equal(queueBlocksDirectSend([{ state: "sending" }]), false);
|
||||||
|
assert.equal(queueBlocksDirectSend([]), false);
|
||||||
|
assert.equal(queueBlocksDirectSend(undefined), false);
|
||||||
|
});
|
||||||
Reference in new issue
Block a user