Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/api/web-settings/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function PUT(req: Request) {
if (!isRecord(body)) {
return NextResponse.json({ error: "Request body must be a settings object", code: "invalid_settings" }, { status: 400 });
}
const payload = body as { autoResumeSessions?: unknown; agentEnv?: unknown };
const payload = body as { autoResumeSessions?: unknown; agentToolsEnabled?: unknown; agentEnv?: unknown };
const patch: Partial<WebServerSettings> = {};

// Both keys are optional so a caller can update one without reading the other;
Expand All @@ -41,6 +41,13 @@ export async function PUT(req: Request) {
resumeProvided = true;
}

if (payload.agentToolsEnabled !== undefined) {
if (typeof payload.agentToolsEnabled !== "boolean") {
return NextResponse.json({ error: "agentToolsEnabled must be a boolean", code: "invalid_settings" }, { status: 400 });
}
patch.agentToolsEnabled = payload.agentToolsEnabled;
}

if (payload.agentEnv !== undefined) {
// Either raw KEY=VALUE text (what the settings textarea holds) or a record.
let parsed: AgentEnvParseResult;
Expand Down
38 changes: 38 additions & 0 deletions components/SettingsConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ const SETTING_INDEX: SettingIndexEntry[] = [
{ id: "model-breakdown", tab: "usage", sectionKey: "settingsTabs.usage.label", labelKey: "usageConfig.breakdown", descKey: "usageConfig.model", fallbackSection: "Usage", fallbackLabel: "Model Breakdown", fallbackDesc: "Historical token usage and cost per model, day, and project", scope: "UI" },
// Windows Background Service & System Tray
{ id: "auto-resume-sessions", tab: "system", sectionKey: "settingsConfig.systemUpdates", labelKey: "settingsConfig.autoResumeSessions", descKey: "settingsConfig.autoResumeSessionsDesc", fallbackSection: "System & Updates", fallbackLabel: "Resume running sessions after a restart", fallbackDesc: "When omp-web restarts while agents are working, restart those sessions and tell each agent: \"Session interrupted and resumed. Continue as you would have done without the interruption.\" Work in progress at the moment of the restart, such as a running command, is lost." },
{ id: "agent-tools-cross-session", tab: "system", sectionKey: "settingsConfig.systemUpdates", labelKey: "settingsConfig.agentTools", descKey: "settingsConfig.agentToolsDesc", fallbackSection: "System & Updates", fallbackLabel: "Agent tools (cross-session)", fallbackDesc: "Allow agents to call list_sessions, new_session and send_to_session to reach other omp-web sessions, even with no browser tab open. Delivered messages are prefixed with the sending session's ID." },
{ id: "agent-env", tab: "system", sectionKey: "settingsConfig.systemUpdates", labelKey: "settingsConfig.agentEnv", descKey: "settingsConfig.agentEnvDesc", fallbackSection: "System & Updates", fallbackLabel: "Agent environment variables", fallbackDesc: "Extra environment variables passed to the omp process, one KEY=VALUE per line. Applied to sessions started after saving.", scope: "UI" },
{ id: "windows-service-autostart", tab: "system", sectionKey: "settingsConfig.windowsServiceTitle", labelKey: "settingsConfig.windowsServiceAutostart", descKey: "settingsConfig.windowsServiceAutostartDesc", fallbackSection: "Windows Background Service & System Tray", fallbackLabel: "Start with Windows", fallbackDesc: "Launch background service quietly in system tray when logging into Windows.", scope: "UI" },
{ id: "windows-service-shortcuts", tab: "system", sectionKey: "settingsConfig.windowsServiceTitle", labelKey: "settingsConfig.windowsServiceInstallBtn", descKey: "settingsConfig.windowsServiceDesc", fallbackSection: "Windows Background Service & System Tray", fallbackLabel: "Install Service & Shortcuts", fallbackDesc: "Manage background service execution, system tray monitor, Windows logon autostart, and Desktop shortcuts.", scope: "UI" },
Expand Down Expand Up @@ -382,6 +383,41 @@ function AutoResumeSessionsSetting() {
);
}

/** Server-side omp-web setting (issue #275): cross-session agent tools.
* Off by default; mirrors AutoResumeSessionsSetting above. */
function AgentToolsSetting() {
const { t } = useI18n();
const [enabled, setEnabled] = useState<boolean | null>(null);
useEffect(() => {
let alive = true;
fetch("/api/web-settings")
.then((res) => (res.ok ? res.json() : null))
.then((data: { agentToolsEnabled?: boolean } | null) => { if (alive) setEnabled(data?.agentToolsEnabled === true); })
.catch(() => { if (alive) setEnabled(false); });
return () => { alive = false; };
}, []);
const change = async (next: boolean) => {
const previous = enabled;
setEnabled(next);
try {
const res = await fetch("/api/web-settings", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ agentToolsEnabled: next }),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
} catch (error) {
setEnabled(previous);
toast.error(t("settingsConfig.agentToolsSaveFailed"), error instanceof Error ? error.message : String(error));
}
};
return (
<NativeSetting searchId="agent-tools-cross-session" label={t("settingsConfig.agentTools")} description={t("settingsConfig.agentToolsDesc")}>
<ToggleSwitch checked={enabled === true} disabled={enabled === null} onChange={(next) => void change(next)} />
</NativeSetting>
);
}

/** Server-side omp-web setting (issue #104): KEY=VALUE text injected into the
* `omp` child process. Parsing/validation lives in lib/omp/agent-env.ts; this only
* feeds it localized messages and renders the result. */
Expand Down Expand Up @@ -1759,6 +1795,8 @@ export function SettingsConfig({ activeTab, toolCallsDefaultCollapsed, onToolCal

<AutoResumeSessionsSetting />

<AgentToolsSetting />

<AgentEnvSetting />

{/* ompweb app update card */}
Expand Down
187 changes: 187 additions & 0 deletions lib/agent-tools.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
import assert from "node:assert/strict";
import test from "node:test";
import { createJiti } from "jiti";

const jiti = createJiti(import.meta.url);
const {
AGENT_TOOL_DEFINITIONS,
AGENT_TOOL_NAMES,
AgentToolGuard,
executeAgentTool,
formatAttributedMessage,
} = await jiti.import("./agent-tools.ts");

function fakeOps(overrides = {}) {
const calls = { list: 0, create: [], deliver: [] };
return {
calls,
async listSessions() {
calls.list += 1;
return [{ id: "target-1", name: "Release", cwd: "/tmp/release", running: false }];
},
async createSession(input) {
calls.create.push(input);
return { sessionId: "new-1" };
},
async deliver(input) {
calls.deliver.push(input);
return { accepted: true, targetSessionId: input.sessionId, delivery: input.delivery, waited: false, responseText: null };
},
...overrides,
};
}

const ctx = (overrides = {}) => ({
sourceSessionId: "source-1",
sourceCwd: "/tmp/source",
enabled: true,
guard: new AgentToolGuard(),
...overrides,
});

test("agent tool definitions cover the three cross-session tools (#275)", () => {
assert.deepEqual([...AGENT_TOOL_NAMES].sort(), ["list_sessions", "new_session", "send_to_session"]);
assert.deepEqual(AGENT_TOOL_DEFINITIONS.map((t) => t.name).sort(), ["list_sessions", "new_session", "send_to_session"]);
const send = AGENT_TOOL_DEFINITIONS.find((t) => t.name === "send_to_session");
assert.deepEqual(send.parameters.required, ["sessionId", "message"]);
assert.deepEqual(send.parameters.properties.delivery.enum, ["prompt", "steer", "followUp"]);
});

test("agent tools refuse every call while the Settings gate is off (#275)", async () => {
const off = ctx({ enabled: false });
await assert.rejects(() => executeAgentTool("list_sessions", {}, fakeOps(), off), /disabled/);
await assert.rejects(
() => executeAgentTool("send_to_session", { sessionId: "t", message: "hi" }, fakeOps(), off),
/disabled/,
);
});

test("list_sessions returns the sessions the ops layer reports (#275)", async () => {
const ops = fakeOps();
const result = await executeAgentTool("list_sessions", {}, ops, ctx());
assert.deepEqual(result, { sessions: [{ id: "target-1", name: "Release", cwd: "/tmp/release", running: false }] });
assert.equal(ops.calls.list, 1);
});

test("new_session defaults cwd, attributes the prompt, and splits provider/model (#275)", async () => {
const ops = fakeOps();
const result = await executeAgentTool(
"new_session",
{ prompt: "Do the release checklist", model: "anthropic/claude-sonnet-4-5", name: "Release worker" },
ops,
ctx(),
);
assert.deepEqual(result, { sessionId: "new-1" });
assert.equal(ops.calls.create.length, 1);
const input = ops.calls.create[0];
assert.equal(input.cwd, "/tmp/source");
assert.equal(input.prompt, "[From session source-1 via omp-web agent tools]: Do the release checklist");
assert.equal(input.provider, "anthropic");
assert.equal(input.modelId, "claude-sonnet-4-5");
assert.equal(input.name, "Release worker");
});

test("new_session without a prompt creates an idle session, and bad models are rejected (#275)", async () => {
const ops = fakeOps();
await executeAgentTool("new_session", { cwd: "/tmp/other" }, ops, ctx());
assert.equal(ops.calls.create[0].prompt, null);
assert.equal(ops.calls.create[0].cwd, "/tmp/other");
await assert.rejects(() => executeAgentTool("new_session", { model: "no-slash" }, fakeOps(), ctx()), /provider\/modelId/);
await assert.rejects(
() => executeAgentTool("new_session", { provider: "anthropic" }, fakeOps(), ctx()),
/together/,
);
await assert.rejects(() => executeAgentTool("new_session", {}, fakeOps(), ctx({ sourceCwd: "" })), /cwd/);
});

test("send_to_session attributes, defaults to prompt, and passes wait through (#275)", async () => {
const ops = fakeOps();
const result = await executeAgentTool(
"send_to_session",
{ sessionId: "target-1", message: "The build passed", wait: true, waitTimeoutMs: 5000 },
ops,
ctx(),
);
assert.equal(ops.calls.deliver.length, 1);
const input = ops.calls.deliver[0];
assert.equal(input.message, "[From session source-1 via omp-web agent tools]: The build passed");
assert.equal(input.delivery, "prompt");
assert.equal(input.wait, true);
assert.equal(input.waitTimeoutMs, 5000);
assert.equal(result.targetSessionId, "target-1");
});

test("send_to_session rejects self-targets, bad deliveries, and bad waits (#275)", async () => {
const base = ctx();
await assert.rejects(
() => executeAgentTool("send_to_session", { sessionId: "source-1", message: "hi" }, fakeOps(), base),
/itself/,
);
await assert.rejects(
() => executeAgentTool("send_to_session", { sessionId: "t", message: "hi", delivery: "shout" }, fakeOps(), ctx()),
/delivery/,
);
await assert.rejects(
() => executeAgentTool("send_to_session", { sessionId: "t", message: "hi", wait: "yes" }, fakeOps(), ctx()),
/wait/,
);
await assert.rejects(
() => executeAgentTool("send_to_session", { sessionId: "t" }, fakeOps(), ctx()),
/message/,
);
});

test("send_to_session wait timeout defaults and caps (#275)", async () => {
const ops = fakeOps();
await executeAgentTool("send_to_session", { sessionId: "t", message: "hi" }, ops, ctx());
assert.equal(ops.calls.deliver[0].wait, false);
assert.equal(ops.calls.deliver[0].waitTimeoutMs, 120000);
const capped = fakeOps();
await executeAgentTool("send_to_session", { sessionId: "t", message: "hi", waitTimeoutMs: 9999999 }, capped, ctx());
assert.equal(capped.calls.deliver[0].waitTimeoutMs, 300000);
});

test("attribution format keeps the full source ID for sidebar lookup (#275)", () => {
assert.equal(
formatAttributedMessage("019c625b-b900-7000-8000-000000000277", "hello"),
"[From session 019c625b-b900-7000-8000-000000000277 via omp-web agent tools]: hello",
);
});

test("chain depth stops a loop and a failed delivery does not advance it (#275)", async () => {
const guard = new AgentToolGuard();
guard.setDepth("source-1", 5);
await assert.rejects(
() => executeAgentTool("send_to_session", { sessionId: "t", message: "hi" }, fakeOps(), ctx({ guard })),
/chain depth/,
);

const failing = fakeOps({
async deliver() {
throw new Error("target vanished");
},
});
const guard2 = new AgentToolGuard();
await assert.rejects(
() => executeAgentTool("send_to_session", { sessionId: "t", message: "hi" }, failing, ctx({ guard: guard2 })),
/target vanished/,
);
assert.equal(guard2.depthFor("t"), 0);

const ok = fakeOps();
await executeAgentTool("send_to_session", { sessionId: "t", message: "hi" }, ok, ctx({ guard: guard2 }));
assert.equal(guard2.depthFor("t"), 1);
});

test("rate limit caps a source at 20 agent tool calls per minute (#275)", async () => {
const guard = new AgentToolGuard();
const ops = fakeOps();
for (let i = 0; i < 20; i++) {
await executeAgentTool("list_sessions", {}, ops, ctx({ guard }));
}
await assert.rejects(() => executeAgentTool("list_sessions", {}, ops, ctx({ guard })), /rate limit/);
});

test("unknown agent tools are rejected (#275)", async () => {
await assert.rejects(() => executeAgentTool("delete_everything", {}, fakeOps(), ctx()), /Unknown agent tool/);
});
Loading
Loading