fix(adapter): combine instructions file and path directive into single temp file
Claude CLI forbids using both --append-system-prompt-file and --append-system-prompt simultaneously. Write a merged temp file instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -291,6 +291,18 @@ export async function execute(ctx: AdapterExecutionContext): Promise<AdapterExec
|
|||||||
const billingType = resolveClaudeBillingType(env);
|
const billingType = resolveClaudeBillingType(env);
|
||||||
const skillsDir = await buildSkillsDir();
|
const skillsDir = await buildSkillsDir();
|
||||||
|
|
||||||
|
// When instructionsFilePath is configured, create a combined temp file that
|
||||||
|
// includes both the file content and the path directive, so we only need
|
||||||
|
// --append-system-prompt-file (Claude CLI forbids using both flags together).
|
||||||
|
let effectiveInstructionsFilePath = instructionsFilePath;
|
||||||
|
if (instructionsFilePath) {
|
||||||
|
const instructionsContent = await fs.readFile(instructionsFilePath, "utf-8");
|
||||||
|
const pathDirective = `\nThe above agent instructions were loaded from ${instructionsFilePath}. Resolve any relative file references from ${instructionsFileDir}.`;
|
||||||
|
const combinedPath = path.join(skillsDir, "agent-instructions.md");
|
||||||
|
await fs.writeFile(combinedPath, instructionsContent + pathDirective, "utf-8");
|
||||||
|
effectiveInstructionsFilePath = combinedPath;
|
||||||
|
}
|
||||||
|
|
||||||
const runtimeSessionParams = parseObject(runtime.sessionParams);
|
const runtimeSessionParams = parseObject(runtime.sessionParams);
|
||||||
const runtimeSessionId = asString(runtimeSessionParams.sessionId, runtime.sessionId ?? "");
|
const runtimeSessionId = asString(runtimeSessionParams.sessionId, runtime.sessionId ?? "");
|
||||||
const runtimeSessionCwd = asString(runtimeSessionParams.cwd, "");
|
const runtimeSessionCwd = asString(runtimeSessionParams.cwd, "");
|
||||||
@@ -323,12 +335,8 @@ export async function execute(ctx: AdapterExecutionContext): Promise<AdapterExec
|
|||||||
if (model) args.push("--model", model);
|
if (model) args.push("--model", model);
|
||||||
if (effort) args.push("--effort", effort);
|
if (effort) args.push("--effort", effort);
|
||||||
if (maxTurns > 0) args.push("--max-turns", String(maxTurns));
|
if (maxTurns > 0) args.push("--max-turns", String(maxTurns));
|
||||||
if (instructionsFilePath) {
|
if (effectiveInstructionsFilePath) {
|
||||||
args.push("--append-system-prompt-file", instructionsFilePath);
|
args.push("--append-system-prompt-file", effectiveInstructionsFilePath);
|
||||||
args.push(
|
|
||||||
"--append-system-prompt",
|
|
||||||
`The above agent instructions were loaded from ${instructionsFilePath}. Resolve any relative file references from ${instructionsFileDir}.`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
args.push("--add-dir", skillsDir);
|
args.push("--add-dir", skillsDir);
|
||||||
if (extraArgs.length > 0) args.push(...extraArgs);
|
if (extraArgs.length > 0) args.push(...extraArgs);
|
||||||
|
|||||||
Reference in New Issue
Block a user