fix: hc send text after --, history reads send args by name

Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
FactorandOvis Fast committed 2026-11-19 12:08:13 +01:00
1 parent 2fd0234831
commit 3b7b4618a3
3 files changed
+71 -3

No files matched your search

+33 -1
View File
@@ -144,6 +144,38 @@ export function gateAfter(status, seenWorking) {
return status === "idle" || status === "done";
}
/**
* The arguments of `hc send`.
*
* The text goes after `--`: a message that starts with a dash ("- fix bug",
* "--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.
*
* @param {string} terminal
* @param {string} text
* @returns {string[]}
*/
export function sendArgs(terminal, text) {
return ["send", "--json", terminal, "--", text];
}
/**
* The fields of the arguments `sendArgs` built - so a caller that watches
* the calls (the history) reads them by name, not by position.
*
* @param {unknown} args
* @returns {{terminal:string, text:string, force:boolean}|null} null when this is not a send
*/
export function parseSendArgs(args) {
if (!Array.isArray(args) || args[0] !== "send") return null;
const dashes = args.indexOf("--");
if (dashes < 0 || args.length !== dashes + 2) return null;
const terminal = args.slice(1, dashes).find((arg) => typeof arg === "string" && !arg.startsWith("-"));
if (typeof terminal !== "string" || typeof args[dashes + 1] !== "string") return null;
return { terminal, text: args[dashes + 1], force: args.slice(1, dashes).includes("--force") };
}
/**
* Paste the text into the terminal and press Enter.
*
@@ -156,7 +188,7 @@ export function gateAfter(status, seenWorking) {
* @returns {Promise<Result>}
*/
export async function sendNow(ctx, text) {
const res = await callHc(ctx, ["send", ctx.terminal, text, "--json"]);
const res = await callHc(ctx, sendArgs(ctx.terminal, text));
if (res.failure) {
// The runner itself failed - there is no exit code to report.