-
Notifications
You must be signed in to change notification settings - Fork 0
fix(codebuddy): stage system prompts in a private file instead of process argv #479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
06ec553
116c2ac
07b48da
bcdf559
b0900e5
3970601
bba6322
3d53e5f
eda8754
f9e3515
6f71931
9a60256
9e9b1d3
947bae9
f7f890f
544ebee
d24ff57
9a27e86
62849df
2f3f736
5a9cd6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| import type { AdapterEvent, OcxParsedRequest, OcxProviderConfig } from "../../types"; | ||
| import { mkdtemp, rm, writeFile } from "node:fs/promises"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import type { AdapterRequest, ProviderAdapter } from "../base"; | ||
| import { mapReasoningEffort } from "../../reasoning-effort"; | ||
| import { buildSystemPrompt } from "../coding-agent/protocol"; | ||
|
|
@@ -34,7 +37,12 @@ export function buildChildEnv(profile: CodeBuddyProfile, apiKey: string): Record | |
| * would require authorization is blocked. The turn is a single text/reasoning pass over stream-json; | ||
| * Codex's tool catalog is not advertised in v1 (the control-protocol tool bridge is a fast-follow). | ||
| */ | ||
| export function buildArgs(profile: CodeBuddyProfile, parsed: OcxParsedRequest, provider: OcxProviderConfig): string[] { | ||
| export function buildArgs( | ||
| profile: CodeBuddyProfile, | ||
| parsed: OcxParsedRequest, | ||
| provider: OcxProviderConfig, | ||
| systemPromptFile?: string, | ||
| ): string[] { | ||
| const args: string[] = [ | ||
| "-p", | ||
| "--output-format", "stream-json", | ||
|
|
@@ -49,8 +57,7 @@ export function buildArgs(profile: CodeBuddyProfile, parsed: OcxParsedRequest, p | |
| ]; | ||
| const effort = mapReasoningEffort(provider, parsed.modelId, parsed.options.reasoning); | ||
| if (effort) args.push("--effort", effort); | ||
| const system = buildSystemPrompt(parsed); | ||
| if (system) args.push("--append-system-prompt", system); | ||
| if (systemPromptFile) args.push("--system-prompt-file", systemPromptFile); | ||
| // profile is retained for symmetry with the region-isolated design and future per-region flags. | ||
| void profile; | ||
| return args; | ||
|
|
@@ -70,16 +77,42 @@ export function createCodeBuddyAdapter(provider: OcxProviderConfig, deps: CodeBu | |
| }, | ||
|
|
||
| async runTurn(parsed, incoming, emit): Promise<void> { | ||
| await runCodingAgentTurn({ | ||
| profiles: CODEBUDDY_PROFILES, | ||
| provider, | ||
| parsed, | ||
| incoming, | ||
| emit, | ||
| buildArgs: (resolved, req, prov) => buildArgs(resolved as CodeBuddyProfile, req, prov), | ||
| buildEnv: (resolved, apiKey) => buildChildEnv(resolved as CodeBuddyProfile, apiKey), | ||
| deps, | ||
| }); | ||
| const system = buildSystemPrompt(parsed); | ||
| let promptDir: string | undefined; | ||
| let promptFile: string | undefined; | ||
| if (system) { | ||
| try { | ||
| promptDir = await mkdtemp(join(tmpdir(), "ocx-codebuddy-prompt-")); | ||
| promptFile = join(promptDir, "system-prompt.txt"); | ||
| await writeFile(promptFile, system, { encoding: "utf8", mode: 0o600, flag: "wx" }); | ||
|
Comment on lines
+83
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the temporary directory is unavailable or unwritable, a request with a system prompt now emits AGENTS.md reference: src/AGENTS.md:L19-L19 Useful? React with 👍 / 👎. |
||
| } catch { | ||
| if (promptDir) await rm(promptDir, { recursive: true, force: true }).catch(() => {}); | ||
| emit({ | ||
| type: "error", | ||
| message: "CodeBuddy system prompt could not be staged securely.", | ||
| status: 500, | ||
| errorType: "upstream_error", | ||
| code: "system_prompt_staging_failed", | ||
| retryable: false, | ||
| }); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| try { | ||
| await runCodingAgentTurn({ | ||
| profiles: CODEBUDDY_PROFILES, | ||
| provider, | ||
| parsed, | ||
| incoming, | ||
| emit, | ||
| buildArgs: (resolved, req, prov) => buildArgs(resolved as CodeBuddyProfile, req, prov, promptFile), | ||
| buildEnv: (resolved, apiKey) => buildChildEnv(resolved as CodeBuddyProfile, apiKey), | ||
| deps, | ||
| }); | ||
| } finally { | ||
| if (promptDir) await rm(promptDir, { recursive: true, force: true }).catch(() => {}); | ||
|
Comment on lines
+113
to
+114
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If recursive removal encounters a transient AGENTS.md reference: src/AGENTS.md:L17-L17 Useful? React with 👍 / 👎. |
||
| } | ||
| }, | ||
| }; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For every turn containing a system or developer prompt, this changes the previous append behavior into replacement behavior: the Claude-compatible CLI distinguishes
--system-prompt-file, which replaces its default system prompt, from--append-system-prompt-file, which appends file contents (CLI flag reference). Replacing the vendor prompt can remove the CLI's baseline behavioral and protocol instructions, so pass the staged file through the append-file variant instead.Useful? React with 👍 / 👎.