feat: Enter answers a blocked agent with hc send --force (never from the queue)
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
1 parent
3b7b4618a3
commit
d852c406dd
3 files changed
+46
-7
No files matched your search
@@ -151,12 +151,17 @@ export function gateAfter(status, seenWorking) {
|
|||||||
* "--help") would otherwise be read by hc as an option and fail with a usage
|
* "--help") would otherwise be read by hc as an option and fail with a usage
|
||||||
* error. Everything after `--` is the text, whatever it looks like.
|
* error. Everything after `--` is the text, whatever it looks like.
|
||||||
*
|
*
|
||||||
|
* `force` is `--force`: "type even if the program is blocked" (hc 0.1.21).
|
||||||
|
* Only the person's own Enter, answering an agent that waits for them, asks
|
||||||
|
* for it - the queue never does.
|
||||||
|
*
|
||||||
* @param {string} terminal
|
* @param {string} terminal
|
||||||
* @param {string} text
|
* @param {string} text
|
||||||
|
* @param {{force?:boolean}} [options]
|
||||||
* @returns {string[]}
|
* @returns {string[]}
|
||||||
*/
|
*/
|
||||||
export function sendArgs(terminal, text) {
|
export function sendArgs(terminal, text, { force = false } = {}) {
|
||||||
return ["send", "--json", terminal, "--", text];
|
return ["send", "--json", ...(force ? ["--force"] : []), terminal, "--", text];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -185,10 +190,11 @@ export function parseSendArgs(args) {
|
|||||||
*
|
*
|
||||||
* @param {Ctx} ctx
|
* @param {Ctx} ctx
|
||||||
* @param {string} text
|
* @param {string} text
|
||||||
|
* @param {{force?:boolean}} [options] - `force`: type even if the agent is blocked
|
||||||
* @returns {Promise<Result>}
|
* @returns {Promise<Result>}
|
||||||
*/
|
*/
|
||||||
export async function sendNow(ctx, text) {
|
export async function sendNow(ctx, text, options = {}) {
|
||||||
const res = await callHc(ctx, sendArgs(ctx.terminal, text));
|
const res = await callHc(ctx, sendArgs(ctx.terminal, text, options));
|
||||||
|
|
||||||
if (res.failure) {
|
if (res.failure) {
|
||||||
// The runner itself failed - there is no exit code to report.
|
// The runner itself failed - there is no exit code to report.
|
||||||
|
|||||||
@@ -1021,7 +1021,10 @@ export default class Composer extends View {
|
|||||||
this.draining.has(key) ||
|
this.draining.has(key) ||
|
||||||
(mode !== "now" && (this.state.queue[key] ?? []).some((entry) => entry.state === "countdown"));
|
(mode !== "now" && (this.state.queue[key] ?? []).some((entry) => entry.state === "countdown"));
|
||||||
if (decision.kind === "send" && allowed && !busy) {
|
if (decision.kind === "send" && allowed && !busy) {
|
||||||
this.sendNow(agent, message, cx);
|
// 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
|
||||||
|
// from the queue.
|
||||||
|
this.sendNow(agent, message, cx, { force: this.statusOf(agent) === "blocked" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1061,7 +1064,7 @@ export default class Composer extends View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** The message goes to the terminal now. */
|
/** The message goes to the terminal now. */
|
||||||
async sendNow(agent, message, cx) {
|
async sendNow(agent, message, cx, options = {}) {
|
||||||
const key = agentKey(agent);
|
const key = agentKey(agent);
|
||||||
if (this.draining.has(key)) {
|
if (this.draining.has(key)) {
|
||||||
this.notice("Ta wiadomość jest już w locie.", "error", cx);
|
this.notice("Ta wiadomość jest już w locie.", "error", cx);
|
||||||
@@ -1086,7 +1089,9 @@ export default class Composer extends View {
|
|||||||
this.persistQueue(key);
|
this.persistQueue(key);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await sendToTerminal({ terminal: agent.address, hc: this.sendHc }, message);
|
const result = await sendToTerminal({ terminal: agent.address, hc: this.sendHc }, message, {
|
||||||
|
force: options.force === true,
|
||||||
|
});
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
this.state = reduce(this.state, { type: "settle", agent: key, id, outcome: "sent" });
|
this.state = reduce(this.state, { type: "settle", agent: key, id, outcome: "sent" });
|
||||||
this.persistQueue(key);
|
this.persistQueue(key);
|
||||||
|
|||||||
@@ -33,3 +33,31 @@ test("parseSendArgs: not a send, or a send of another shape, is nothing", () =>
|
|||||||
assert.equal(parseSendArgs(null), null);
|
assert.equal(parseSendArgs(null), null);
|
||||||
assert.equal(parseSendArgs([]), null);
|
assert.equal(parseSendArgs([]), null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("--force is only there when asked for, and before the `--`", async () => {
|
||||||
|
assert.deepEqual(sendArgs("t2", "yes", { force: true }), ["send", "--json", "--force", "t2", "--", "yes"]);
|
||||||
|
assert.deepEqual(sendArgs("t2", "yes", { force: false }), sendArgs("t2", "yes"));
|
||||||
|
assert.deepEqual(parseSendArgs(sendArgs("t2", "--force x", { force: true })), { terminal: "t2", text: "--force x", force: true });
|
||||||
|
assert.equal(parseSendArgs(sendArgs("t2", "--force")).force, false);
|
||||||
|
|
||||||
|
const calls = [];
|
||||||
|
const ctx = { terminal: "t2", hc: async (args) => (calls.push(args), ok) };
|
||||||
|
await sendNow(ctx, "yes", { force: true });
|
||||||
|
await sendNow(ctx, "yes");
|
||||||
|
assert.equal(calls[0].includes("--force"), true);
|
||||||
|
assert.equal(calls[1].includes("--force"), false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("the queue never forces: drain sends without --force", async () => {
|
||||||
|
const { createState, reduce } = await import("../mod/ovis-composer/state.js");
|
||||||
|
const { drain } = await import("../mod/ovis-composer/delivery.js");
|
||||||
|
const state = reduce(createState(), { type: "queue", agent: "t2", item: { id: "1", text: "q", createdAt: 1 } });
|
||||||
|
const calls = [];
|
||||||
|
const result = await drain(
|
||||||
|
{ agent: "t2", terminal: "t2", status: () => "idle", gate: () => true, hc: async (args) => (calls.push(args), ok) },
|
||||||
|
state,
|
||||||
|
);
|
||||||
|
assert.equal(result.sent, true);
|
||||||
|
assert.equal(calls.length, 1);
|
||||||
|
assert.equal(calls[0].includes("--force"), false);
|
||||||
|
});
|
||||||
Reference in new issue
Block a user