claude: prefix prompt with Clawd identity
parent
a331bd5ea1
commit
0adc0ed7a6
|
|
@ -3,6 +3,8 @@ import { z } from "zod";
|
|||
|
||||
// Preferred binary name for Claude CLI invocations.
|
||||
export const CLAUDE_BIN = "claude";
|
||||
export const CLAUDE_IDENTITY_PREFIX =
|
||||
"You are Clawd (Claude) running on the user's Mac via warelay. Be concise (<=1000 chars).";
|
||||
|
||||
function extractClaudeText(payload: unknown): string | undefined {
|
||||
// Best-effort walker to find the primary text field in Claude JSON outputs.
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import crypto from "node:crypto";
|
|||
import path from "node:path";
|
||||
|
||||
import type { MessageInstance } from "twilio/lib/rest/api/v2010/account/message.js";
|
||||
import { CLAUDE_BIN, parseClaudeJson } from "./claude.js";
|
||||
import { CLAUDE_BIN, CLAUDE_IDENTITY_PREFIX, parseClaudeJson } from "./claude.js";
|
||||
import {
|
||||
applyTemplate,
|
||||
type MsgContext,
|
||||
|
|
@ -270,9 +270,17 @@ const mediaNote =
|
|||
];
|
||||
}
|
||||
}
|
||||
const finalArgv = argv;
|
||||
let finalArgv = argv;
|
||||
const isClaudeInvocation =
|
||||
finalArgv.length > 0 && path.basename(finalArgv[0]) === CLAUDE_BIN;
|
||||
if (isClaudeInvocation && finalArgv.length > 0) {
|
||||
const bodyIdx = finalArgv.length - 1;
|
||||
const existingBody = finalArgv[bodyIdx] ?? "";
|
||||
finalArgv = [
|
||||
...finalArgv.slice(0, bodyIdx),
|
||||
[CLAUDE_IDENTITY_PREFIX, existingBody].filter(Boolean).join("\n\n"),
|
||||
];
|
||||
}
|
||||
logVerbose(`Running command auto-reply: ${finalArgv.join(" ")}`);
|
||||
const started = Date.now();
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -389,7 +389,8 @@ describe("config and templating", () => {
|
|||
|
||||
const argv = runSpy.mock.calls[0][0];
|
||||
expect(argv[0]).toBe("claude");
|
||||
expect(argv.at(-1)).toBe("hi");
|
||||
expect(argv.at(-1)).toContain("You are Clawd (Claude)");
|
||||
expect(argv.at(-1)).toMatch(/hi$/);
|
||||
// The helper should auto-add print and output format flags without disturbing the prompt position.
|
||||
expect(argv.includes("-p") || argv.includes("--print")).toBe(true);
|
||||
const outputIdx = argv.findIndex(
|
||||
|
|
@ -454,7 +455,9 @@ describe("config and templating", () => {
|
|||
);
|
||||
|
||||
expect(result?.text).toBe("Sure! What's up?");
|
||||
});
|
||||
const argv = runSpy.mock.calls[0][0];
|
||||
expect(argv.at(-1)).toContain("You are Clawd (Claude)");
|
||||
});
|
||||
|
||||
it("serializes command auto-replies via the queue", async () => {
|
||||
let active = 0;
|
||||
|
|
|
|||
Loading…
Reference in New Issue