diff --git a/CHANGELOG.md b/CHANGELOG.md index cff9e4537..6e0333eb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f ### Fixes & Improvements +- **Goal mode is available to native clients.** `goal` RPC commands (`create`, `get`, `pause`, `resume`, `drop`) are forwarded to omp unchanged, and `get_state` carries omp's `goal` snapshot (an absent field stays absent on older omp). Native apps can now start, show and control a running goal; `goal_updated` frames already streamed. - **In-app updates work when ompweb runs as a systemd service.** The update worker ran inside the service's cgroup, so stopping the server killed the worker too: nothing was installed, the service could stay down (`Restart=on-failure` does not restart a clean SIGTERM exit), and every page load reopened the update dialog at "Stop ompweb-managed sessions". The worker now runs in its own transient scope (`systemd-run --scope`) and stops, updates and starts the unit through `systemctl`, starting it again if the install fails. - **An update whose worker died is reported as failed.** A running update whose worker process is gone, or whose lease has expired, now becomes a failed attempt the dialog can show and clean up, instead of waiting forever. - **The Provider Usage header stays put while its list scrolls.** Scrolling a long provider list in the sidebar also scrolled the section header (title, window toggle, refresh) out of view, on desktop and mobile. Only the list scrolls now. diff --git a/lib/pi-types.ts b/lib/pi-types.ts index f3a7dca25..20d91609c 100644 --- a/lib/pi-types.ts +++ b/lib/pi-types.ts @@ -16,6 +16,26 @@ export type UsageLimitState = export type SlowModeScope = "session" | "global"; +/** omp's goal record (`goal` command reply, `goal_updated`, `get_state.goal.goal`). */ +export interface GoalInfo { + id: string; + objective: string; + /** `active` / `paused`; completed and dropped goals answer `null` instead. */ + status: string; + tokenBudget?: number; + tokensUsed: number; + timeUsedSeconds: number; + createdAt: number; + updatedAt: number; +} + +/** Mirror of omp's GoalModeState: the `goal` reply and the `goal` field of `get_state`. */ +export interface GoalModeState { + enabled: boolean; + mode: string; + goal: GoalInfo | null; +} + export interface ModelLike { id: string; provider: string; @@ -102,6 +122,8 @@ export interface RpcSessionState { tokensPerSecond?: number | null; /** Structured skill resolution diagnostics; absent on older OMP builds. */ skillDiagnostics?: SkillDiagnosticsSnapshot; + /** omp goal mode; absent on older OMP builds (never invented here). */ + goal?: GoalModeState | null; } /** @@ -140,6 +162,8 @@ export interface WebSessionState { /** Parsed public diagnostics DTO; absent means unsupported or malformed. */ skillDiagnostics?: SkillDiagnosticsSnapshot; todoPhases: TodoPhase[]; + /** omp goal mode snapshot; omitted when the child predates the `goal` field. */ + goal?: GoalModeState | null; extensionStatuses: Array<{ key: string; text: string }>; extensionWidgets: Array<{ key: string; lines: string[]; placement: "aboveEditor" | "belowEditor" }>; } diff --git a/lib/rpc-manager.test.mjs b/lib/rpc-manager.test.mjs index a153e829d..7e34060f8 100644 --- a/lib/rpc-manager.test.mjs +++ b/lib/rpc-manager.test.mjs @@ -193,6 +193,73 @@ test("commands with no omp equivalent fail with a clear unsupported error", asyn } }); +test("goal commands reach omp verbatim and answer its goal payload", async () => { + const { AgentSessionWrapper } = await runtimeJiti.import("./rpc-manager.ts"); + const goal = { + id: "goal-1", objective: "ship the export", status: "active", tokenBudget: 2000, + tokensUsed: 0, timeUsedSeconds: 0, createdAt: 1, updatedAt: 1, + }; + const reply = { goal, state: { enabled: true, mode: "active", goal } }; + const sent = []; + const fakeProc = { + isAlive: true, + onFrame: () => () => {}, + sendCommand: async (command, timeoutMs) => { + sent.push({ command, timeoutMs }); + return reply; + }, + sendFrame: () => {}, + dispose: async () => {}, + }; + const wrapper = new AgentSessionWrapper(fakeProc, process.cwd()); + wrapper.start(); + try { + const command = { type: "goal", op: "create", objective: "ship the export", token_budget: 2000 }; + const result = await wrapper.send(command); + assert.deepEqual(sent.map(({ command: forwarded }) => forwarded), [command]); + assert.equal(sent[0].timeoutMs, undefined, "goal keeps the passthrough's unbounded wait"); + assert.deepEqual(result, reply, "native clients need omp's {goal, state} shape"); + } finally { + await wrapper.destroyAndWait(); + } +}); + +test("get_state forwards omp's goal snapshot and omits an absent field", async () => { + const { AgentSessionWrapper } = await runtimeJiti.import("./rpc-manager.ts"); + const goal = { + id: "goal-2", objective: "keep going", status: "paused", tokensUsed: 3, + timeUsedSeconds: 7, createdAt: 2, updatedAt: 3, + }; + let rawState = { + sessionId: "goal-state", + sessionFile: "/tmp/goal-state.jsonl", + isStreaming: false, + isCompacting: false, + goal: { enabled: true, mode: "active", goal }, + }; + const fakeProc = { + isAlive: true, + onFrame: () => () => {}, + sendCommand: async (command) => command.type === "get_state" ? rawState : {}, + sendFrame: () => {}, + dispose: async () => {}, + }; + const wrapper = new AgentSessionWrapper(fakeProc, process.cwd()); + wrapper.start(); + try { + const state = await wrapper.send({ type: "get_state" }); + assert.deepEqual(state.goal, rawState.goal); + // An older omp has no `goal` field: the server must not invent `null`, + // which native clients read as "omp explicitly has no goal". + rawState = { ...rawState }; + delete rawState.goal; + const legacy = await wrapper.send({ type: "get_state" }); + assert.equal(Object.hasOwn(legacy, "goal"), false); + } finally { + await wrapper.destroyAndWait(); + } +}); + test("terminal completion retains response evidence without retaining the unpersisted message", async (t) => { const { wrapper, emit } = snapshotSession(t, async () => ({ sessionId: "observed-response", isStreaming: false, isCompacting: false, diff --git a/lib/rpc-manager.ts b/lib/rpc-manager.ts index f8e23cee8..e3d71e9b4 100644 --- a/lib/rpc-manager.ts +++ b/lib/rpc-manager.ts @@ -169,6 +169,9 @@ const PASSTHROUGH_COMMANDS = new Set([ "btw", "btw_cancel", "get_btw_history", + // Goal mode (`{type:"goal", op}`) has the same shape as omp's RPC frame and + // is the only way native clients reach it; every op answers `{goal, state}`. + "goal", ]); // Outlasts omp's cold prediction-daemon start (up to 3 × 30s start rounds plus a @@ -1577,6 +1580,9 @@ export class AgentSessionWrapper { usageLimit: state.usageLimit, ...(skillDiagnostics ? { skillDiagnostics } : {}), todoPhases: state.todoPhases ?? [], + // Clients distinguish "no goal" (explicit null) from "omp does not know + // goals" (field absent), so an absent field stays absent. + ...(state.goal !== undefined ? { goal: state.goal } : {}), extensionStatuses: Array.from(this.extensionStatuses, ([key, text]) => ({ key, text })), extensionWidgets: Array.from(this.extensionWidgets.values()), };