claude: prefix prompt with Clawd identity
This commit is contained in:
@@ -3,6 +3,8 @@ import { z } from "zod";
|
|||||||
|
|
||||||
// Preferred binary name for Claude CLI invocations.
|
// Preferred binary name for Claude CLI invocations.
|
||||||
export const CLAUDE_BIN = "claude";
|
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 {
|
function extractClaudeText(payload: unknown): string | undefined {
|
||||||
// Best-effort walker to find the primary text field in Claude JSON outputs.
|
// 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 path from "node:path";
|
||||||
|
|
||||||
import type { MessageInstance } from "twilio/lib/rest/api/v2010/account/message.js";
|
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 {
|
import {
|
||||||
applyTemplate,
|
applyTemplate,
|
||||||
type MsgContext,
|
type MsgContext,
|
||||||
@@ -270,9 +270,17 @@ const mediaNote =
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const finalArgv = argv;
|
let finalArgv = argv;
|
||||||
const isClaudeInvocation =
|
const isClaudeInvocation =
|
||||||
finalArgv.length > 0 && path.basename(finalArgv[0]) === CLAUDE_BIN;
|
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(" ")}`);
|
logVerbose(`Running command auto-reply: ${finalArgv.join(" ")}`);
|
||||||
const started = Date.now();
|
const started = Date.now();
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -389,7 +389,8 @@ describe("config and templating", () => {
|
|||||||
|
|
||||||
const argv = runSpy.mock.calls[0][0];
|
const argv = runSpy.mock.calls[0][0];
|
||||||
expect(argv[0]).toBe("claude");
|
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.
|
// The helper should auto-add print and output format flags without disturbing the prompt position.
|
||||||
expect(argv.includes("-p") || argv.includes("--print")).toBe(true);
|
expect(argv.includes("-p") || argv.includes("--print")).toBe(true);
|
||||||
const outputIdx = argv.findIndex(
|
const outputIdx = argv.findIndex(
|
||||||
@@ -454,7 +455,9 @@ describe("config and templating", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(result?.text).toBe("Sure! What's up?");
|
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 () => {
|
it("serializes command auto-replies via the queue", async () => {
|
||||||
let active = 0;
|
let active = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user