refactor: centralize sandbox runtime label
This commit is contained in:
@@ -74,6 +74,25 @@ describe("buildStatusMessage", () => {
|
|||||||
expect(normalized).toContain("Queue: collect");
|
expect(normalized).toContain("Queue: collect");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("uses per-agent sandbox config when config and session key are provided", () => {
|
||||||
|
const text = buildStatusMessage({
|
||||||
|
config: {
|
||||||
|
agents: {
|
||||||
|
list: [
|
||||||
|
{ id: "main", default: true },
|
||||||
|
{ id: "discord", sandbox: { mode: "all" } },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
} as ClawdbotConfig,
|
||||||
|
agent: {},
|
||||||
|
sessionKey: "agent:discord:discord:channel:1456350065223270435",
|
||||||
|
sessionScope: "per-sender",
|
||||||
|
queue: { mode: "collect", depth: 0 },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(normalizeTestText(text)).toContain("Runtime: docker/all");
|
||||||
|
});
|
||||||
|
|
||||||
it("shows verbose/elevated labels only when enabled", () => {
|
it("shows verbose/elevated labels only when enabled", () => {
|
||||||
const text = buildStatusMessage({
|
const text = buildStatusMessage({
|
||||||
agent: { model: "anthropic/claude-opus-4-5" },
|
agent: { model: "anthropic/claude-opus-4-5" },
|
||||||
|
|||||||
@@ -59,6 +59,42 @@ type StatusArgs = {
|
|||||||
now?: number;
|
now?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function resolveRuntimeLabel(
|
||||||
|
args: Pick<StatusArgs, "config" | "agent" | "sessionKey" | "sessionScope">,
|
||||||
|
): string {
|
||||||
|
const sessionKey = args.sessionKey?.trim();
|
||||||
|
if (args.config && sessionKey) {
|
||||||
|
const runtimeStatus = resolveSandboxRuntimeStatus({
|
||||||
|
cfg: args.config,
|
||||||
|
sessionKey,
|
||||||
|
});
|
||||||
|
const sandboxMode = runtimeStatus.mode ?? "off";
|
||||||
|
if (sandboxMode === "off") return "direct";
|
||||||
|
const runtime = runtimeStatus.sandboxed ? "docker" : sessionKey ? "direct" : "unknown";
|
||||||
|
return `${runtime}/${sandboxMode}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const sandboxMode = args.agent?.sandbox?.mode ?? "off";
|
||||||
|
if (sandboxMode === "off") return "direct";
|
||||||
|
const sandboxed = (() => {
|
||||||
|
if (!sessionKey) return false;
|
||||||
|
if (sandboxMode === "all") return true;
|
||||||
|
if (args.config) {
|
||||||
|
return resolveSandboxRuntimeStatus({
|
||||||
|
cfg: args.config,
|
||||||
|
sessionKey,
|
||||||
|
}).sandboxed;
|
||||||
|
}
|
||||||
|
const sessionScope = args.sessionScope ?? "per-sender";
|
||||||
|
const mainKey = resolveMainSessionKey({
|
||||||
|
session: { scope: sessionScope },
|
||||||
|
});
|
||||||
|
return sessionKey !== mainKey.trim();
|
||||||
|
})();
|
||||||
|
const runtime = sandboxed ? "docker" : sessionKey ? "direct" : "unknown";
|
||||||
|
return `${runtime}/${sandboxMode}`;
|
||||||
|
}
|
||||||
|
|
||||||
const formatTokens = (total: number | null | undefined, contextTokens: number | null) => {
|
const formatTokens = (total: number | null | undefined, contextTokens: number | null) => {
|
||||||
const ctx = contextTokens ?? null;
|
const ctx = contextTokens ?? null;
|
||||||
if (total == null) {
|
if (total == null) {
|
||||||
@@ -258,41 +294,7 @@ export function buildStatusMessage(args: StatusArgs): string {
|
|||||||
args.agent?.elevatedDefault ??
|
args.agent?.elevatedDefault ??
|
||||||
"on";
|
"on";
|
||||||
|
|
||||||
const runtime = (() => {
|
const runtime = { label: resolveRuntimeLabel(args) };
|
||||||
const sessionKey = args.sessionKey?.trim();
|
|
||||||
if (args.config && sessionKey) {
|
|
||||||
const runtimeStatus = resolveSandboxRuntimeStatus({
|
|
||||||
cfg: args.config,
|
|
||||||
sessionKey,
|
|
||||||
});
|
|
||||||
const sandboxMode = runtimeStatus.mode ?? "off";
|
|
||||||
if (sandboxMode === "off") return { label: "direct" };
|
|
||||||
const runtime = runtimeStatus.sandboxed ? "docker" : sessionKey ? "direct" : "unknown";
|
|
||||||
return { label: `${runtime}/${sandboxMode}` };
|
|
||||||
}
|
|
||||||
|
|
||||||
const sandboxMode = args.agent?.sandbox?.mode ?? "off";
|
|
||||||
if (sandboxMode === "off") return { label: "direct" };
|
|
||||||
const sandboxed = (() => {
|
|
||||||
if (!sessionKey) return false;
|
|
||||||
if (sandboxMode === "all") return true;
|
|
||||||
if (args.config) {
|
|
||||||
return resolveSandboxRuntimeStatus({
|
|
||||||
cfg: args.config,
|
|
||||||
sessionKey,
|
|
||||||
}).sandboxed;
|
|
||||||
}
|
|
||||||
const sessionScope = args.sessionScope ?? "per-sender";
|
|
||||||
const mainKey = resolveMainSessionKey({
|
|
||||||
session: { scope: sessionScope },
|
|
||||||
});
|
|
||||||
return sessionKey !== mainKey.trim();
|
|
||||||
})();
|
|
||||||
const runtime = sandboxed ? "docker" : sessionKey ? "direct" : "unknown";
|
|
||||||
return {
|
|
||||||
label: `${runtime}/${sandboxMode}`,
|
|
||||||
};
|
|
||||||
})();
|
|
||||||
|
|
||||||
const updatedAt = entry?.updatedAt;
|
const updatedAt = entry?.updatedAt;
|
||||||
const sessionLine = [
|
const sessionLine = [
|
||||||
|
|||||||
Reference in New Issue
Block a user