style: biome format
This commit is contained in:
@@ -197,9 +197,13 @@ export function createBashTool(
|
|||||||
const runtime = defaults?.sandbox ? "sandboxed" : "direct";
|
const runtime = defaults?.sandbox ? "sandboxed" : "direct";
|
||||||
const gates: string[] = [];
|
const gates: string[] = [];
|
||||||
if (!elevatedDefaults?.enabled) {
|
if (!elevatedDefaults?.enabled) {
|
||||||
gates.push("enabled (tools.elevated.enabled / agents.list[].tools.elevated.enabled)");
|
gates.push(
|
||||||
|
"enabled (tools.elevated.enabled / agents.list[].tools.elevated.enabled)",
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
gates.push("allowFrom (tools.elevated.allowFrom.<provider> / agents.list[].tools.elevated.allowFrom.<provider>)");
|
gates.push(
|
||||||
|
"allowFrom (tools.elevated.allowFrom.<provider> / agents.list[].tools.elevated.allowFrom.<provider>)",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
throw new Error(
|
throw new Error(
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -6,14 +6,13 @@ import type {
|
|||||||
AgentToolResult,
|
AgentToolResult,
|
||||||
} from "@mariozechner/pi-agent-core";
|
} from "@mariozechner/pi-agent-core";
|
||||||
import type { AssistantMessage } from "@mariozechner/pi-ai";
|
import type { AssistantMessage } from "@mariozechner/pi-ai";
|
||||||
import type { ClawdbotConfig } from "../config/config.js";
|
|
||||||
import {
|
import {
|
||||||
normalizeThinkLevel,
|
normalizeThinkLevel,
|
||||||
type ThinkLevel,
|
type ThinkLevel,
|
||||||
} from "../auto-reply/thinking.js";
|
} from "../auto-reply/thinking.js";
|
||||||
|
import type { ClawdbotConfig } from "../config/config.js";
|
||||||
import { sanitizeContentBlocksImages } from "./tool-images.js";
|
|
||||||
import { formatSandboxToolPolicyBlockedMessage } from "./sandbox.js";
|
import { formatSandboxToolPolicyBlockedMessage } from "./sandbox.js";
|
||||||
|
import { sanitizeContentBlocksImages } from "./tool-images.js";
|
||||||
import type { WorkspaceBootstrapFile } from "./workspace.js";
|
import type { WorkspaceBootstrapFile } from "./workspace.js";
|
||||||
|
|
||||||
export type EmbeddedContextFile = { path: string; content: string };
|
export type EmbeddedContextFile = { path: string; content: string };
|
||||||
|
|||||||
@@ -64,4 +64,3 @@ describe("sandbox explain helpers", () => {
|
|||||||
expect(msg).toContain("Use main session key (direct): agent:main:main");
|
expect(msg).toContain("Use main session key (direct): agent:main:main");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -219,7 +219,11 @@ function resolveElevatedPermissions(params: {
|
|||||||
agentId: string;
|
agentId: string;
|
||||||
ctx: MsgContext;
|
ctx: MsgContext;
|
||||||
provider: string;
|
provider: string;
|
||||||
}): { enabled: boolean; allowed: boolean; failures: Array<{ gate: string; key: string }> } {
|
}): {
|
||||||
|
enabled: boolean;
|
||||||
|
allowed: boolean;
|
||||||
|
failures: Array<{ gate: string; key: string }>;
|
||||||
|
} {
|
||||||
const globalConfig = params.cfg.tools?.elevated;
|
const globalConfig = params.cfg.tools?.elevated;
|
||||||
const agentConfig = resolveAgentConfig(params.cfg, params.agentId)?.tools
|
const agentConfig = resolveAgentConfig(params.cfg, params.agentId)?.tools
|
||||||
?.elevated;
|
?.elevated;
|
||||||
@@ -227,9 +231,13 @@ function resolveElevatedPermissions(params: {
|
|||||||
const agentEnabled = agentConfig?.enabled !== false;
|
const agentEnabled = agentConfig?.enabled !== false;
|
||||||
const enabled = globalEnabled && agentEnabled;
|
const enabled = globalEnabled && agentEnabled;
|
||||||
const failures: Array<{ gate: string; key: string }> = [];
|
const failures: Array<{ gate: string; key: string }> = [];
|
||||||
if (!globalEnabled) failures.push({ gate: "enabled", key: "tools.elevated.enabled" });
|
if (!globalEnabled)
|
||||||
|
failures.push({ gate: "enabled", key: "tools.elevated.enabled" });
|
||||||
if (!agentEnabled)
|
if (!agentEnabled)
|
||||||
failures.push({ gate: "enabled", key: "agents.list[].tools.elevated.enabled" });
|
failures.push({
|
||||||
|
gate: "enabled",
|
||||||
|
key: "agents.list[].tools.elevated.enabled",
|
||||||
|
});
|
||||||
if (!enabled) return { enabled, allowed: false, failures };
|
if (!enabled) return { enabled, allowed: false, failures };
|
||||||
if (!params.provider) {
|
if (!params.provider) {
|
||||||
failures.push({ gate: "provider", key: "ctx.Provider" });
|
failures.push({ gate: "provider", key: "ctx.Provider" });
|
||||||
|
|||||||
@@ -31,10 +31,7 @@ import {
|
|||||||
} from "../../agents/model-selection.js";
|
} from "../../agents/model-selection.js";
|
||||||
import { resolveSandboxRuntimeStatus } from "../../agents/sandbox.js";
|
import { resolveSandboxRuntimeStatus } from "../../agents/sandbox.js";
|
||||||
import type { ClawdbotConfig } from "../../config/config.js";
|
import type { ClawdbotConfig } from "../../config/config.js";
|
||||||
import {
|
import { type SessionEntry, saveSessionStore } from "../../config/sessions.js";
|
||||||
type SessionEntry,
|
|
||||||
saveSessionStore,
|
|
||||||
} from "../../config/sessions.js";
|
|
||||||
import { enqueueSystemEvent } from "../../infra/system-events.js";
|
import { enqueueSystemEvent } from "../../infra/system-events.js";
|
||||||
import { applyVerboseOverride } from "../../sessions/level-overrides.js";
|
import { applyVerboseOverride } from "../../sessions/level-overrides.js";
|
||||||
import { shortenHomePath } from "../../utils.js";
|
import { shortenHomePath } from "../../utils.js";
|
||||||
|
|||||||
@@ -144,7 +144,10 @@ export function registerSandboxCli(program: Command) {
|
|||||||
sandbox
|
sandbox
|
||||||
.command("explain")
|
.command("explain")
|
||||||
.description("Explain effective sandbox/tool policy for a session/agent")
|
.description("Explain effective sandbox/tool policy for a session/agent")
|
||||||
.option("--session <key>", "Session key to inspect (defaults to agent main)")
|
.option(
|
||||||
|
"--session <key>",
|
||||||
|
"Session key to inspect (defaults to agent main)",
|
||||||
|
)
|
||||||
.option("--agent <id>", "Agent id to inspect (defaults to derived agent)")
|
.option("--agent <id>", "Agent id to inspect (defaults to derived agent)")
|
||||||
.option("--json", "Output result as JSON", false)
|
.option("--json", "Output result as JSON", false)
|
||||||
.addHelpText("after", EXAMPLES.explain)
|
.addHelpText("after", EXAMPLES.explain)
|
||||||
|
|||||||
@@ -28,14 +28,11 @@ describe("sandbox explain command", () => {
|
|||||||
const { sandboxExplainCommand } = await import("./sandbox-explain.js");
|
const { sandboxExplainCommand } = await import("./sandbox-explain.js");
|
||||||
|
|
||||||
const logs: string[] = [];
|
const logs: string[] = [];
|
||||||
await sandboxExplainCommand(
|
await sandboxExplainCommand({ json: true, session: "agent:main:main" }, {
|
||||||
{ json: true, session: "agent:main:main" },
|
log: (msg: string) => logs.push(msg),
|
||||||
{
|
error: (msg: string) => logs.push(msg),
|
||||||
log: (msg: string) => logs.push(msg),
|
exit: (_code: number) => {},
|
||||||
error: (msg: string) => logs.push(msg),
|
} as unknown as Parameters<typeof sandboxExplainCommand>[1]);
|
||||||
exit: (_code: number) => {},
|
|
||||||
} as unknown as Parameters<typeof sandboxExplainCommand>[1],
|
|
||||||
);
|
|
||||||
|
|
||||||
const out = logs.join("");
|
const out = logs.join("");
|
||||||
const parsed = JSON.parse(out);
|
const parsed = JSON.parse(out);
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
import { resolveAgentConfig } from "../agents/agent-scope.js";
|
||||||
|
import {
|
||||||
|
resolveSandboxConfigForAgent,
|
||||||
|
resolveSandboxToolPolicyForAgent,
|
||||||
|
} from "../agents/sandbox.js";
|
||||||
import type { ClawdbotConfig } from "../config/config.js";
|
import type { ClawdbotConfig } from "../config/config.js";
|
||||||
import { loadConfig } from "../config/config.js";
|
import { loadConfig } from "../config/config.js";
|
||||||
import {
|
import {
|
||||||
@@ -14,11 +19,6 @@ import {
|
|||||||
resolveAgentIdFromSessionKey,
|
resolveAgentIdFromSessionKey,
|
||||||
} from "../routing/session-key.js";
|
} from "../routing/session-key.js";
|
||||||
import type { RuntimeEnv } from "../runtime.js";
|
import type { RuntimeEnv } from "../runtime.js";
|
||||||
import { resolveAgentConfig } from "../agents/agent-scope.js";
|
|
||||||
import {
|
|
||||||
resolveSandboxConfigForAgent,
|
|
||||||
resolveSandboxToolPolicyForAgent,
|
|
||||||
} from "../agents/sandbox.js";
|
|
||||||
|
|
||||||
type SandboxExplainOptions = {
|
type SandboxExplainOptions = {
|
||||||
session?: string;
|
session?: string;
|
||||||
@@ -71,7 +71,9 @@ function inferProviderFromSessionKey(params: {
|
|||||||
const configuredMainKey = normalizeMainKey(params.cfg.session?.mainKey);
|
const configuredMainKey = normalizeMainKey(params.cfg.session?.mainKey);
|
||||||
if (parts[0] === configuredMainKey) return undefined;
|
if (parts[0] === configuredMainKey) return undefined;
|
||||||
const candidate = parts[0]?.trim().toLowerCase();
|
const candidate = parts[0]?.trim().toLowerCase();
|
||||||
return candidate && KNOWN_PROVIDER_KEYS.has(candidate) ? candidate : undefined;
|
return candidate && KNOWN_PROVIDER_KEYS.has(candidate)
|
||||||
|
? candidate
|
||||||
|
: undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveActiveProvider(params: {
|
function resolveActiveProvider(params: {
|
||||||
@@ -135,7 +137,9 @@ export async function sandboxExplainCommand(
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const cfg = loadConfig();
|
const cfg = loadConfig();
|
||||||
|
|
||||||
const defaultAgentId = resolveAgentIdFromSessionKey(resolveMainSessionKey(cfg));
|
const defaultAgentId = resolveAgentIdFromSessionKey(
|
||||||
|
resolveMainSessionKey(cfg),
|
||||||
|
);
|
||||||
const resolvedAgentId = normalizeAgentId(
|
const resolvedAgentId = normalizeAgentId(
|
||||||
opts.agent?.trim()
|
opts.agent?.trim()
|
||||||
? opts.agent
|
? opts.agent
|
||||||
@@ -277,7 +281,8 @@ export async function sandboxExplainCommand(
|
|||||||
alwaysAllowedByConfig: elevatedAlwaysAllowedByConfig,
|
alwaysAllowedByConfig: elevatedAlwaysAllowedByConfig,
|
||||||
allowFrom: {
|
allowFrom: {
|
||||||
global: provider ? globalAllowTokens : undefined,
|
global: provider ? globalAllowTokens : undefined,
|
||||||
agent: elevatedAgent?.allowFrom && provider ? agentAllowTokens : undefined,
|
agent:
|
||||||
|
elevatedAgent?.allowFrom && provider ? agentAllowTokens : undefined,
|
||||||
},
|
},
|
||||||
failures: elevatedFailures,
|
failures: elevatedFailures,
|
||||||
},
|
},
|
||||||
@@ -323,7 +328,10 @@ export async function sandboxExplainCommand(
|
|||||||
.join(", ")}`,
|
.join(", ")}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (payload.sandbox.mode === "non-main" && payload.sandbox.sessionIsSandboxed) {
|
if (
|
||||||
|
payload.sandbox.mode === "non-main" &&
|
||||||
|
payload.sandbox.sessionIsSandboxed
|
||||||
|
) {
|
||||||
lines.push("");
|
lines.push("");
|
||||||
lines.push(
|
lines.push(
|
||||||
`Hint: sandbox mode is non-main; use main session key to run direct: ${payload.mainSessionKey}`,
|
`Hint: sandbox mode is non-main; use main session key to run direct: ${payload.mainSessionKey}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user