fix: hc send text after --, history reads send args by name
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
1 parent
2fd0234831
commit
3b7b4618a3
3 files changed
+71
-3
No files matched your search
@@ -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.
|
||||
|
||||
@@ -39,7 +39,7 @@ import * as fs from "fs/promises";
|
||||
|
||||
import { createState, reduce } from "./state.js";
|
||||
import { keyIntent } from "./keys.js";
|
||||
import { decide, shouldDrain, shouldStartCountdown, sendNow as sendToTerminal } from "./delivery.js";
|
||||
import { decide, shouldDrain, shouldStartCountdown, parseSendArgs, sendNow as sendToTerminal } from "./delivery.js";
|
||||
import { detect as detectTrigger, rank, merge, startsLine } from "./suggest.js";
|
||||
import * as catalog from "./catalog.js";
|
||||
import { LIMITS, validate, mention, removeMention, kindOf, formatBytes } from "./attachments.js";
|
||||
@@ -1896,7 +1896,8 @@ export default class Composer extends View {
|
||||
*/
|
||||
async runSend(args) {
|
||||
const res = await hc(args);
|
||||
if (args[0] === "send" && hcOk(res)) this.recordSent(String(args[1]), String(args[2] ?? ""));
|
||||
const sent = parseSendArgs(args);
|
||||
if (sent && hcOk(res)) this.recordSent(sent.terminal, sent.text);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user