feat(FN-4639): complete Step 4 — add sandbox prompt override resolver
Fusion-Task-Id: FN-4639 Fusion-Task-Lineage: 40745d49-dd20-4c51-87e3-42062417f788
This commit is contained in:
34
packages/core/src/sandbox-prompt-override.ts
Normal file
34
packages/core/src/sandbox-prompt-override.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import type { SandboxBackendName, SandboxProjectSettings } from "./types.js";
|
||||
|
||||
/**
|
||||
* Sandbox backend override parsing for per-task PROMPT.md content (FN-4639; design from FN-4635).
|
||||
*
|
||||
* The engine can call these pure helpers to resolve the effective backend with precedence:
|
||||
* PROMPT override (`**Sandbox:** <backend>`) > project settings > default native backend.
|
||||
*/
|
||||
const SANDBOX_OVERRIDE_RE = /^\*\*Sandbox:\*\*\s*(native|sandbox-exec|bubblewrap|docker|podman|custom)\s*$/im;
|
||||
|
||||
export function parseSandboxPromptOverride(prompt: string | undefined): SandboxBackendName | undefined {
|
||||
if (!prompt) {
|
||||
return undefined;
|
||||
}
|
||||
const match = prompt.match(SANDBOX_OVERRIDE_RE);
|
||||
return match ? (match[1] as SandboxBackendName) : undefined;
|
||||
}
|
||||
|
||||
export function resolveSandboxBackend(
|
||||
settings: { sandbox?: SandboxProjectSettings } | undefined,
|
||||
prompt: string | undefined,
|
||||
): { backend: SandboxBackendName; source: "default" | "project" | "prompt" } {
|
||||
const promptOverride = parseSandboxPromptOverride(prompt);
|
||||
if (promptOverride) {
|
||||
return { backend: promptOverride, source: "prompt" };
|
||||
}
|
||||
|
||||
const projectBackend = settings?.sandbox?.backend;
|
||||
if (projectBackend) {
|
||||
return { backend: projectBackend, source: "project" };
|
||||
}
|
||||
|
||||
return { backend: "native", source: "default" };
|
||||
}
|
||||
Reference in New Issue
Block a user