@omercnet/paseo-omp 5.7.0-next.524.1 → 5.7.0-next.526.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -35,7 +35,7 @@ Open the **OMP** sidebar to review the provider-profile contract, choose which c
35
35
 
36
36
  Open the **Accounts** tab of the **OMP** sidebar to see the logins in OMP's own credential store with their usage and banked resets, add a login through OMP's own sign-in, sign one out, spend a banked reset, and steer OMP's balancing: prefer a login, keep part of its quota in reserve, and set what OMP does at a limit. Each login shows plan and organization badges from its usage report, such as **Business**, **Pro Lite**, **Personal** or an organization name, and the label drops OMP's parenthesized organization once a badge shows it. Steering is written to OMP's own config. See [OMP accounts](docs/configuration.md#omp-accounts).
37
37
 
38
- The quota popover groups recorded limits by provider and OMP account, showing an available recorded email or, when absent, the Copilot account ID (GitHub username) across that account's windows. Duplicate and unnamed accounts receive numbers in opaque account-key order, so changing usage does not swap their numbers; accounts are still displayed by highest usage. Duplicate-name suffixes stay visible when long emails truncate, and a lone unnamed account needs no heading. Copilot accounts also show **GitHub** or **GHE · host**, using the enterprise URL in OMP's recorded account key; unrecognized keys show neither. Badges beside each account name show the plan (such as **Business** or **Pro Lite**) and organization name from OMP's cached usage report for that account; an Anthropic organization named after the account's email shows as **Personal**, and accounts without a cached plan or organization show no badge. Only a server-side SHA-256 hash of the account key reaches the client. **CURRENT PROVIDER** identifies the session's provider, not its active account. Provider summary percentages show the highest recorded usage across that provider's accounts. Reset countdowns a day or more away show days and hours, such as **resets 14d 21h**.
38
+ The quota popover groups recorded limits by provider and OMP account, showing an available recorded email or, when absent, the Copilot account ID (GitHub username) across that account's windows. Duplicate and unnamed accounts receive numbers in opaque account-key order, so changing usage does not swap their numbers; accounts are still displayed by highest usage. Duplicate-name suffixes stay visible when long emails truncate, and a lone unnamed account needs no heading. Copilot accounts also show **GitHub** or **GHE · host**, using the enterprise URL in OMP's recorded account key; unrecognized keys show neither. Badges beside each account name show the plan (such as **Business** or **Pro Lite**) and organization name from OMP's cached usage report for that account; an Anthropic organization named after the account's email shows as **Personal**, and accounts without a cached plan or organization show no badge. Only a server-side SHA-256 hash of the account key reaches the client. **CURRENT PROVIDER** identifies the session's provider, not its active account. Paseo sees an OMP Plugin agent's model only as an opaque id, so the pill and popover ask the agent's live OMP session which provider that model belongs to; a closed OMP Plugin agent shows every provider until its session runs again. Provider summary percentages show the highest recorded usage across that provider's accounts. Reset countdowns a day or more away show days and hours, such as **resets 14d 21h**.
39
39
 
40
40
  Open the **MCPs** tab of the **OMP** sidebar to list the MCP servers OMP connects to, add one by URL or command, test, enable, disable or remove it, and sign a remote server in through your browser, like **Accounts** does for logins. See [OMP MCP servers](docs/configuration.md#omp-mcp-servers).
41
41
 
@@ -4,9 +4,10 @@ import { useQuery } from "@tanstack/react-query";
4
4
  import { useMemo } from "react";
5
5
  import { Text, View } from "react-native";
6
6
  import { storeForProvider, storeLabel } from "../shared/omp-store";
7
- import { listOmpQuotas } from "../shared/quota";
7
+ import { getOmpSessionModelProvider, listOmpQuotas } from "../shared/quota";
8
8
  import { ompStoreKey } from "./omp-store-state";
9
9
  import {
10
+ needsSessionModelProvider,
10
11
  type QuotaProviderGroup,
11
12
  quotaDetailLabel,
12
13
  quotaProviderFromSession,
@@ -21,8 +22,35 @@ const QUOTA_POLL_MS = 30_000;
21
22
  export function QuotaPopover(props: PluginButtonContentProps) {
22
23
  const { theme, layout } = props;
23
24
  const agentId = props.context === "agent" ? props.agentId : "";
24
- const session = useAgent(agentId, (agent) => ({ model: agent.model, provider: agent.provider }));
25
- const currentProvider = quotaProviderFromSession(session?.provider ?? "", session?.model ?? null);
25
+ const session = useAgent(agentId, (agent) => ({
26
+ model: agent.model,
27
+ provider: agent.provider,
28
+ status: agent.status,
29
+ }));
30
+ const loadSessionModelProvider = useRpc(getOmpSessionModelProvider);
31
+ const sessionModelProvider = useQuery({
32
+ // The answer comes from the live session, so a closed or resumed session asks again.
33
+ queryKey: [
34
+ "paseo-omp",
35
+ "session-model-provider",
36
+ agentId,
37
+ session?.model ?? null,
38
+ session?.status ?? null,
39
+ ],
40
+ queryFn: () => loadSessionModelProvider({ agentId }),
41
+ // A closed agent has no live session to ask, as in the pill.
42
+ enabled: Boolean(
43
+ agentId &&
44
+ session &&
45
+ session.status !== "closed" &&
46
+ needsSessionModelProvider(session.provider, session.model),
47
+ ),
48
+ retry: false,
49
+ });
50
+ const currentProvider =
51
+ quotaProviderFromSession(session?.provider ?? "", session?.model ?? null) ??
52
+ sessionModelProvider.data?.provider ??
53
+ null;
26
54
  const store = storeForProvider(session?.provider);
27
55
  const loadQuotas = useRpc(listOmpQuotas);
28
56
  const quotas = useQuery({
@@ -44,6 +44,15 @@ export function quotaProviderFromSession(
44
44
  return model?.includes("/") ? model.split("/")[0] : null;
45
45
  }
46
46
 
47
+ /** An OMP Plugin agent's model reaches Paseo as an opaque id; its live session names the provider. */
48
+ export function needsSessionModelProvider(provider: string, model: string | null): boolean {
49
+ return (
50
+ isOmpProvider(provider.split("/")[0]) &&
51
+ Boolean(model) &&
52
+ quotaProviderFromSession(provider, model) === null
53
+ );
54
+ }
55
+
47
56
  export function quotaProviderLabel(provider: string | null): string {
48
57
  return provider
49
58
  ? (PROVIDER_LABELS[provider] ?? `${provider.slice(0, 1).toUpperCase()}${provider.slice(1)}`)
package/index.client.tsx CHANGED
@@ -28,6 +28,7 @@ import { quotaProviderIcon } from "./client/provider-icon";
28
28
  import { OmpImageTimeline } from "./client/provider-image";
29
29
  import { QuotaPopover } from "./client/quota-popover";
30
30
  import {
31
+ needsSessionModelProvider,
31
32
  type QuotaSeverity,
32
33
  quotaProviderFromSession,
33
34
  quotaSeverityForProvider,
@@ -61,7 +62,7 @@ import {
61
62
  import { OMP_MCP_AUTH_TIMELINE_KIND, ompMcpAuthorizationTimelineSchema } from "./shared/mcp";
62
63
  import { type OmpStore, storeForProvider } from "./shared/omp-store";
63
64
  import { ompImageTimelineSchema, transformOmpImageToolItem } from "./shared/provider-image";
64
- import { listOmpQuotas } from "./shared/quota";
65
+ import { getOmpSessionModelProvider, listOmpQuotas } from "./shared/quota";
65
66
  import { OMP_RULE_NOTICE_KIND, ompRuleNoticeSchema } from "./shared/rule-notices";
66
67
  import { OMP_SUBAGENT_STRIP_KIND, ompSubagentStripSchema } from "./shared/subagents";
67
68
 
@@ -71,6 +72,7 @@ const STATUS_POLL_MS = 4_000;
71
72
  const QUOTA_POLL_MS = 30_000;
72
73
  const RECONCILE_DEBOUNCE_MS = 250;
73
74
  const SETTINGS_POLL_MS = 15_000;
75
+ const SESSION_PROVIDER_RETRY_MS = 60_000;
74
76
  const composerPillSettingsRpc = settingsRpc(composerPillSettings.id);
75
77
 
76
78
  type AgentEntry = PaseoAgentListResult["entries"][number];
@@ -382,15 +384,52 @@ export default function contribute(client: PluginClientContext) {
382
384
  }
383
385
  }
384
386
 
387
+ // Agent id to its session's provider, asked again only when the agent's model or status changes.
388
+ // A failed lookup is kept too, but only until `retryAt`, so a server without the RPC is not asked
389
+ // on every reconcile and a transient failure still recovers.
390
+ const sessionModelProviders = new Map<
391
+ string,
392
+ { key: string; provider: string | null; retryAt?: number }
393
+ >();
394
+
395
+ async function sessionModelProvider(agent: AgentEntry["agent"]): Promise<string | null> {
396
+ if (agent.status === "closed" || !needsSessionModelProvider(agent.provider, agent.model)) {
397
+ return null;
398
+ }
399
+ const key = `${agent.model}|${agent.status}`;
400
+ const cached = sessionModelProviders.get(agent.id);
401
+ if (cached?.key === key && (cached.retryAt === undefined || Date.now() < cached.retryAt)) {
402
+ return cached.provider;
403
+ }
404
+ try {
405
+ const { provider } = await client.rpc(getOmpSessionModelProvider, { agentId: agent.id });
406
+ sessionModelProviders.set(agent.id, { key, provider });
407
+ return provider;
408
+ } catch {
409
+ sessionModelProviders.set(agent.id, {
410
+ key,
411
+ provider: null,
412
+ retryAt: Date.now() + SESSION_PROVIDER_RETRY_MS,
413
+ });
414
+ return null;
415
+ }
416
+ }
417
+
385
418
  async function reconcileOnce(): Promise<void> {
386
419
  if (!preferences) return;
387
- const agents = await loadAgents(client.paseo);
420
+ const listed = (await loadAgents(client.paseo)).filter(
421
+ ({ agent }) => !agent.archivedAt && agent.workspaceId && agent.cwd,
422
+ );
423
+ const sessionProviders = await Promise.all(
424
+ listed.map(({ agent }) => sessionModelProvider(agent)),
425
+ );
388
426
  if (disposed || !preferences) return;
389
427
  const activeIds = new Set<string>();
390
- for (const { agent } of agents) {
391
- if (agent.archivedAt || !agent.workspaceId || !agent.cwd) continue;
428
+ for (const [index, { agent }] of listed.entries()) {
429
+ if (!agent.workspaceId || !agent.cwd) continue;
392
430
  activeIds.add(agent.id);
393
- const quotaProvider = quotaProviderFromSession(agent.provider, agent.model);
431
+ const quotaProvider =
432
+ quotaProviderFromSession(agent.provider, agent.model) ?? sessionProviders[index];
394
433
  const store = storeForProvider(agent.provider);
395
434
  let entry = pills.get(agent.id);
396
435
  if (
@@ -419,6 +458,9 @@ export default function contribute(client: PluginClientContext) {
419
458
  removePills(entry);
420
459
  pills.delete(agentId);
421
460
  }
461
+ for (const agentId of sessionModelProviders.keys()) {
462
+ if (!activeIds.has(agentId)) sessionModelProviders.delete(agentId);
463
+ }
422
464
  await Promise.all([refreshHubStatus(), refreshQuotaStatus()]);
423
465
  }
424
466
 
package/index.server.ts CHANGED
@@ -57,6 +57,7 @@ import { ompRuleNoticeRow } from "./server/rule-notices";
57
57
  import {
58
58
  OmpSubagentControlRegistry,
59
59
  resolveCancelOmpSubagent,
60
+ resolveGetOmpSessionModelProvider,
60
61
  resolveSteerOmpSubagent,
61
62
  } from "./server/subagents";
62
63
  import { resolveGetOmpSupportReport } from "./server/support-diagnostics";
@@ -116,7 +117,7 @@ import { getOmpUpdateStatus, installOmpUpdate } from "./shared/omp-update";
116
117
  import { getOmpProviderHealth } from "./shared/provider-diagnostics";
117
118
  import { getOmpImage } from "./shared/provider-image";
118
119
  import { providerLaunchSettings } from "./shared/provider-launch-settings";
119
- import { listOmpQuotas } from "./shared/quota";
120
+ import { getOmpSessionModelProvider, listOmpQuotas } from "./shared/quota";
120
121
  import { cancelOmpSubagent, steerOmpSubagent } from "./shared/subagents";
121
122
  import { getOmpSupportReport } from "./shared/support-diagnostics";
122
123
 
@@ -283,6 +284,9 @@ export default function contribute(server: PluginServerContext) {
283
284
  server.handle(steerOmpSubagent, (input) =>
284
285
  resolveSteerOmpSubagent(input, subagentControlRegistry),
285
286
  );
287
+ server.handle(getOmpSessionModelProvider, (input) =>
288
+ resolveGetOmpSessionModelProvider(input, subagentControlRegistry),
289
+ );
286
290
  const removeTurnRows = registerOmpTurnRows(server, [ompRuleNoticeRow, ompScreenshotRow]);
287
291
  const removeSessionOpenHook = server.before("agent.session_open", ({ request }) => {
288
292
  if (request.provider !== "omp-plugin" && !request.provider.startsWith("omp-plugin-")) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omercnet/paseo-omp",
3
- "version": "5.7.0-next.524.1",
3
+ "version": "5.7.0-next.526.1",
4
4
  "type": "module",
5
5
  "description": "Paseo integration for OMP, including its direct provider and workspace tooling.",
6
6
  "license": "MIT",
package/server/hub.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  import type { Dirent } from "node:fs";
2
- import { readdir, readFile, realpath } from "node:fs/promises";
2
+ import { access, open, readdir, readFile, realpath } from "node:fs/promises";
3
3
  import { homedir } from "node:os";
4
4
  import { join, resolve } from "node:path";
5
+ import { DatabaseSync } from "node:sqlite";
5
6
  import type { RpcInput } from "@getpaseo/plugin";
6
7
  import { z } from "zod";
7
8
  import type { HubProcess, listHubProcesses, tailHubLog } from "../shared/hub";
9
+ import { ompDaemonDir } from "./paths";
8
10
  import { waitMs } from "./provider/omp-rpc-process";
9
11
 
10
12
  const MAX_LOG_BYTES = 64 * 1024;
@@ -48,6 +50,15 @@ function ompRunDir(): string {
48
50
  return process.env.PASEO_OMP_RUN_DIR ?? join(homedir(), ".omp", "run", "daemons");
49
51
  }
50
52
 
53
+ /**
54
+ * omp 19's per-user daemon directory; see {@link ompDaemonDir}. `PASEO_OMP_DAEMON_DIR` is a
55
+ * test-only override: set in production it makes the Hub read a different store than the one
56
+ * omp's own `ps stop` acts on.
57
+ */
58
+ function ompDaemonRunDir(): string {
59
+ return process.env.PASEO_OMP_DAEMON_DIR || ompDaemonDir();
60
+ }
61
+
51
62
  type Read<T> = { value: T } | { missing: true } | { unreadable: true };
52
63
 
53
64
  export function readFailure(error: unknown): { missing: true } | { unreadable: true } {
@@ -138,8 +149,16 @@ function toHubProcess(name: string, value: unknown, specFile: unknown): HubProce
138
149
  };
139
150
  }
140
151
 
152
+ export interface ScannedHubProcess extends HubProcess {
153
+ /**
154
+ * omp 19's unit id. `omp ps stop` resolves a bare name machine-wide (exact id first, then any
155
+ * single unit with that key in any project), so a daemon service is stopped by its id.
156
+ */
157
+ unitId?: string;
158
+ }
159
+
141
160
  export interface HubProcessScan {
142
- processes: HubProcess[];
161
+ processes: ScannedHubProcess[];
143
162
  /** Records that exist but could not be read or parsed: their state is unknown. */
144
163
  unreadable: string[];
145
164
  /**
@@ -149,9 +168,16 @@ export interface HubProcessScan {
149
168
  strays: string[];
150
169
  /** False when a directory that could hold this project's records could not be read. */
151
170
  complete: boolean;
171
+ /**
172
+ * Every key and label in omp 19's daemon store, across all projects and scopes: `undefined`
173
+ * when there is no store, `null` when it exists but could not be read. A 19 `omp ps stop
174
+ * <name>` matches any of them, so an 18.x broker service is only stopped by name when its
175
+ * name is provably absent here.
176
+ */
177
+ daemonUnitNames?: ReadonlySet<string> | null;
152
178
  }
153
179
 
154
- export async function scanHubProcessesFrom(root: string, cwd: string): Promise<HubProcessScan> {
180
+ async function scanBrokerProcessesFrom(root: string, cwd: string): Promise<HubProcessScan> {
155
181
  const found = await findProjectDaemonRoots(root, cwd);
156
182
  const scan: HubProcessScan = {
157
183
  processes: [],
@@ -187,18 +213,212 @@ export async function scanHubProcessesFrom(root: string, cwd: string): Promise<H
187
213
  );
188
214
  }),
189
215
  );
216
+ return scan;
217
+ }
218
+
219
+ /*
220
+ * omp 19 replaced the per-project brokers with one per-user daemon. It keeps every unit in a
221
+ * sqlite store, `<daemonDir>/daemon.db` (table `units`, one JSON `snapshot` per unit), and a
222
+ * unit's output in `<daemonDir>/units/<id>/output.log`. A named service is a `proc` unit in its
223
+ * session's project scope (`scope_key` `project:<canonical dir>`), keyed by the service name.
224
+ * Like the broker layout above this is unversioned, so every read degrades instead of throwing.
225
+ */
226
+ const DAEMON_SERVICE_KIND = "proc";
227
+ // A service runs as omp re-entering itself with this selector, its shell command last
228
+ // (pi-utils `SHELL_PROCESS_SELECTOR`); `omp ps` shows such a launch as just that command.
229
+ const SHELL_PROCESS_SELECTOR = "__omp_worker_shell_process";
230
+ const DaemonRowSchema = z.object({
231
+ id: z.string(),
232
+ key: z.string(),
233
+ snapshot: z.string(),
234
+ proc: z.string().nullable(),
235
+ });
236
+ const DaemonUnitSchema = z.object({
237
+ state: z.string(),
238
+ pids: z.array(z.number()).optional(),
239
+ owner: z.string().optional(),
240
+ restartCount: z.number().optional(),
241
+ policy: z.object({ hold: z.string().optional() }).optional(),
242
+ createdAt: z.number().optional(),
243
+ startedAt: z.number().optional(),
244
+ readyAt: z.number().optional(),
245
+ exitedAt: z.number().optional(),
246
+ exitCode: z.number().optional(),
247
+ command: z.string().optional(),
248
+ cwd: z.string().optional(),
249
+ });
250
+
251
+ interface DaemonService {
252
+ process: ScannedHubProcess;
253
+ log: string;
254
+ }
255
+
256
+ interface DaemonServiceScan {
257
+ services: DaemonService[];
258
+ unreadable: string[];
259
+ complete: boolean;
260
+ /** See {@link HubProcessScan.daemonUnitNames}. */
261
+ unitNames?: ReadonlySet<string> | null;
262
+ }
263
+
264
+ // omp names units with `crypto.randomUUID()`. A row id that is not a plain basename must never
265
+ // reach a log path or a CLI argument; the leading alphanumeric also rules out `.`, `..` and flags.
266
+ const UNIT_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u;
267
+
268
+ function processAlive(pid: number): boolean {
269
+ try {
270
+ process.kill(pid, 0);
271
+ return true;
272
+ } catch (error) {
273
+ // EPERM: the process exists but belongs to someone else.
274
+ return (error as NodeJS.ErrnoException | undefined)?.code === "EPERM";
275
+ }
276
+ }
277
+
278
+ function launchCommand(
279
+ spec: z.infer<typeof SpecSchema> | undefined,
280
+ command: string | undefined,
281
+ ): { application: string; args: string[] } {
282
+ if (!spec) return { application: command ?? "", args: [] };
283
+ const args = spec.args ?? [];
284
+ if (args.includes(SHELL_PROCESS_SELECTOR)) return { application: args.at(-1) ?? "", args: [] };
285
+ return { application: spec.application, args };
286
+ }
287
+
288
+ function toDaemonService(
289
+ daemonDir: string,
290
+ row: z.infer<typeof DaemonRowSchema>,
291
+ ): DaemonService | undefined {
292
+ let snapshot: unknown;
293
+ let proc: unknown;
294
+ try {
295
+ snapshot = JSON.parse(row.snapshot);
296
+ proc = row.proc === null ? undefined : JSON.parse(row.proc);
297
+ } catch {
298
+ return undefined;
299
+ }
300
+ const parsed = DaemonUnitSchema.safeParse(snapshot);
301
+ if (!parsed.success) return undefined;
302
+ const unit = parsed.data;
303
+ const spec = SpecSchema.safeParse(proc).data;
304
+ // The store keeps a unit's last persisted state, and a daemon that died took its services down
305
+ // with it (omp's own offline `ps` reports them exited), so a running state whose main process
306
+ // is gone is stale. Transitional states are left alone: a live daemon may be restarting the
307
+ // service or still ending its tree.
308
+ const mainPid = unit.pids?.[0];
309
+ const stale =
310
+ (unit.state === "running" || unit.state === "ready") &&
311
+ mainPid !== undefined &&
312
+ // kill(0)/kill(-n) would probe a process group, not this service.
313
+ mainPid > 0 &&
314
+ !processAlive(mainPid);
315
+ return {
316
+ log: join(daemonDir, "units", row.id, "output.log"),
317
+ process: {
318
+ name: row.key,
319
+ ...launchCommand(spec, unit.command),
320
+ cwd: spec?.cwd ?? unit.cwd ?? "",
321
+ state: stale ? "exited" : unit.state,
322
+ owner: unit.owner ?? null,
323
+ restartCount: unit.restartCount ?? 0,
324
+ persist: unit.policy?.hold === "persist",
325
+ detached: unit.policy?.hold === "detached",
326
+ createdAt: unit.createdAt ?? null,
327
+ startedAt: unit.startedAt ?? null,
328
+ readyAt: unit.readyAt ?? null,
329
+ exitedAt: unit.exitedAt ?? null,
330
+ exitCode: unit.exitCode ?? null,
331
+ unitId: row.id,
332
+ },
333
+ };
334
+ }
335
+
336
+ async function scanDaemonServicesFrom(daemonDir: string, cwd: string): Promise<DaemonServiceScan> {
337
+ const scan: DaemonServiceScan = { services: [], unreadable: [], complete: true };
338
+ const path = join(daemonDir, "daemon.db");
339
+ try {
340
+ await access(path);
341
+ } catch (error) {
342
+ // No store: omp 19 never ran here (or omp is older), so it owns no services.
343
+ if ("missing" in readFailure(error)) return scan;
344
+ return { ...scan, complete: false, unitNames: null };
345
+ }
346
+ // omp keys the scope by the same canonical directory (`daemon/paths.ts` canonicalProjectDir).
347
+ const projectDir = await canonicalProjectDir(cwd);
348
+ let rows: unknown[];
349
+ let names: unknown[];
350
+ try {
351
+ const database = new DatabaseSync(path, { readOnly: true, timeout: 500 });
352
+ try {
353
+ rows = database
354
+ .prepare("SELECT id, key, snapshot, proc FROM units WHERE kind = ? AND scope_key = ?")
355
+ .all(DAEMON_SERVICE_KIND, `project:${projectDir}`);
356
+ names = database.prepare("SELECT key, label FROM units").all();
357
+ } finally {
358
+ database.close();
359
+ }
360
+ } catch {
361
+ return { ...scan, complete: false, unitNames: null };
362
+ }
363
+ scan.unitNames = new Set(
364
+ names.flatMap((value) => {
365
+ const row = value as { key?: unknown; label?: unknown };
366
+ return [row.key, row.label].filter((name): name is string => typeof name === "string");
367
+ }),
368
+ );
369
+ for (const value of rows) {
370
+ const row = DaemonRowSchema.safeParse(value);
371
+ if (!row.success) {
372
+ scan.complete = false;
373
+ continue;
374
+ }
375
+ const service = UNIT_ID.test(row.data.id) ? toDaemonService(daemonDir, row.data) : undefined;
376
+ if (service) scan.services.push(service);
377
+ else scan.unreadable.push(row.data.key);
378
+ }
379
+ return scan;
380
+ }
381
+
382
+ /**
383
+ * Every hub process of `cwd`'s project: the 18.x per-project brokers under `root` and, when
384
+ * `daemonDir` is given, omp 19's per-user daemon. Both can hold services at once on a machine
385
+ * that upgraded, since omp 19 does not adopt the brokers' services.
386
+ */
387
+ export async function scanHubProcessesFrom(
388
+ root: string,
389
+ cwd: string,
390
+ daemonDir?: string,
391
+ ): Promise<HubProcessScan> {
392
+ const [brokers, daemon] = await Promise.all([
393
+ scanBrokerProcessesFrom(root, cwd),
394
+ daemonDir === undefined ? undefined : scanDaemonServicesFrom(daemonDir, cwd),
395
+ ]);
396
+ const scan: HubProcessScan = daemon
397
+ ? {
398
+ processes: [...brokers.processes, ...daemon.services.map((service) => service.process)],
399
+ unreadable: [...brokers.unreadable, ...daemon.unreadable],
400
+ strays: brokers.strays,
401
+ complete: brokers.complete && daemon.complete,
402
+ daemonUnitNames: daemon.unitNames,
403
+ }
404
+ : brokers;
190
405
  scan.processes.sort((a, b) => (b.startedAt ?? 0) - (a.startedAt ?? 0));
191
406
  return scan;
192
407
  }
193
408
 
194
- export async function listHubProcessesFrom(root: string, cwd: string): Promise<HubProcess[]> {
195
- return (await scanHubProcessesFrom(root, cwd)).processes;
409
+ export async function listHubProcessesFrom(
410
+ root: string,
411
+ cwd: string,
412
+ daemonDir?: string,
413
+ ): Promise<HubProcess[]> {
414
+ const { processes } = await scanHubProcessesFrom(root, cwd, daemonDir);
415
+ return processes.map(({ unitId: _unitId, ...process }) => process);
196
416
  }
197
417
 
198
418
  export async function resolveListHubProcesses({
199
419
  cwd,
200
420
  }: RpcInput<typeof listHubProcesses>): Promise<{ processes: HubProcess[] }> {
201
- return { processes: await listHubProcessesFrom(ompRunDir(), cwd) };
421
+ return { processes: await listHubProcessesFrom(ompRunDir(), cwd, ompDaemonRunDir()) };
202
422
  }
203
423
 
204
424
  // omp 18.18.9 made launch services persistent in RPC mode (`launch.persist` is forced on for
@@ -233,10 +453,10 @@ export interface OwnedHubCleanupDependencies {
233
453
  /** A timer that fires after `ms`; scans that outlive it count as incomplete. */
234
454
  expire(ms: number): { fired: Promise<void>; cancel(): void };
235
455
  /**
236
- * Asks omp's broker to stop one service within `timeoutMs`; resolves true only when the
237
- * command succeeded.
456
+ * Asks omp to stop one service, named by its omp 19 unit id or its 18.x broker name, within
457
+ * `timeoutMs`; resolves true only when the command succeeded.
238
458
  */
239
- stop(name: string, cwd: string, timeoutMs: number): Promise<boolean>;
459
+ stop(target: string, cwd: string, timeoutMs: number): Promise<boolean>;
240
460
  sleep(ms: number): Promise<void>;
241
461
  now(): number;
242
462
  }
@@ -264,21 +484,24 @@ function startedWhileOwned(process: HubProcess, ownedUntil: number | undefined):
264
484
  }
265
485
 
266
486
  function ownedPersistentServices(
267
- processes: readonly HubProcess[],
487
+ processes: readonly ScannedHubProcess[],
268
488
  owners: HubServiceOwners,
269
489
  states: Readonly<Record<string, true>>,
270
- ): string[] {
271
- return processes
272
- .filter(
273
- (process) =>
274
- HUB_SERVICE_NAME.test(process.name) &&
275
- process.owner !== null &&
276
- startedWhileOwned(process, owners.get(process.owner)) &&
277
- process.persist &&
278
- !process.detached &&
279
- states[process.state] === true,
280
- )
281
- .map((process) => process.name);
490
+ ): ScannedHubProcess[] {
491
+ return processes.filter(
492
+ (process) =>
493
+ HUB_SERVICE_NAME.test(process.name) &&
494
+ process.owner !== null &&
495
+ startedWhileOwned(process, owners.get(process.owner)) &&
496
+ process.persist &&
497
+ !process.detached &&
498
+ states[process.state] === true,
499
+ );
500
+ }
501
+
502
+ /** What `omp ps stop` is given: an omp 19 unit by its id, an 18.x broker service by its name. */
503
+ function stopTarget(process: ScannedHubProcess): string {
504
+ return process.unitId ?? process.name;
282
505
  }
283
506
 
284
507
  async function boundedScan(
@@ -312,15 +535,25 @@ export async function stopOwnedHubProcesses(
312
535
  // A record that cannot be read may be one of ours, so the lookup is not complete.
313
536
  const complete = initial.complete && initial.unreadable.length === 0;
314
537
  if (owned.length === 0) return { stopped: [], failed: [], complete };
315
- const failed = new Set<string>();
538
+ const failed = new Set<ScannedHubProcess>();
316
539
  const queue = [...owned];
317
540
  const stopDeadline = deadline - HUB_CLEANUP_VERIFY_RESERVE_MS;
541
+ // On a machine that has run omp 19, `omp` may now be the 19 CLI, which resolves a bare name
542
+ // against every unit in every project. An 18.x broker service is stopped by name only when no
543
+ // daemon unit anywhere could answer to it; otherwise it is left running and reported failed.
544
+ const daemonNames = initial.daemonUnitNames;
545
+ const stoppableByName = (service: ScannedHubProcess): boolean =>
546
+ service.unitId !== undefined ||
547
+ daemonNames === undefined ||
548
+ (daemonNames !== null && !daemonNames.has(service.name));
318
549
  const stopNext = async (): Promise<void> => {
319
- for (let name = queue.shift(); name !== undefined; name = queue.shift()) {
550
+ for (let service = queue.shift(); service !== undefined; service = queue.shift()) {
320
551
  const remaining = stopDeadline - dependencies.now();
321
552
  const stopped =
322
- remaining > 0 && (await dependencies.stop(name, cwd, remaining).catch(() => false));
323
- if (!stopped) failed.add(name);
553
+ remaining > 0 &&
554
+ stoppableByName(service) &&
555
+ (await dependencies.stop(stopTarget(service), cwd, remaining).catch(() => false));
556
+ if (!stopped) failed.add(service);
324
557
  }
325
558
  };
326
559
  await Promise.all(
@@ -328,27 +561,29 @@ export async function stopOwnedHubProcesses(
328
561
  );
329
562
  // Report success only for services omp's own state confirms have settled. A record that cannot
330
563
  // be read is unknown, not stopped.
331
- let unsettled: ReadonlySet<string>;
564
+ let unsettled: ScannedHubProcess[];
332
565
  while (true) {
333
566
  const current = await boundedScan(dependencies, cwd, deadline - dependencies.now());
334
- unsettled = new Set(
335
- current?.complete
336
- ? [
337
- ...ownedPersistentServices(current.processes, owners, UNSETTLED_HUB_STATES),
338
- ...current.unreadable,
339
- ...current.strays,
340
- ].filter((name) => owned.includes(name))
341
- : owned,
342
- );
343
- if (unsettled.size === 0 || dependencies.now() >= deadline) break;
567
+ if (current?.complete) {
568
+ const live = new Set(
569
+ ownedPersistentServices(current.processes, owners, UNSETTLED_HUB_STATES).map(stopTarget),
570
+ );
571
+ const unknown = new Set([...current.unreadable, ...current.strays]);
572
+ unsettled = owned.filter(
573
+ (service) => live.has(stopTarget(service)) || unknown.has(service.name),
574
+ );
575
+ } else {
576
+ unsettled = owned;
577
+ }
578
+ if (unsettled.length === 0 || dependencies.now() >= deadline) break;
344
579
  await dependencies.sleep(HUB_CLEANUP_POLL_MS);
345
580
  // Keep the last observation rather than scan with no time left.
346
581
  if (dependencies.now() >= deadline) break;
347
582
  }
348
- for (const name of unsettled) failed.add(name);
583
+ for (const service of unsettled) failed.add(service);
349
584
  return {
350
- stopped: owned.filter((name) => !failed.has(name)),
351
- failed: owned.filter((name) => failed.has(name)),
585
+ stopped: owned.filter((service) => !failed.has(service)).map((service) => service.name),
586
+ failed: owned.filter((service) => failed.has(service)).map((service) => service.name),
352
587
  complete,
353
588
  };
354
589
  }
@@ -356,32 +591,57 @@ export async function stopOwnedHubProcesses(
356
591
  export function ownedHubCleanupDependencies(
357
592
  runOmp: (args: readonly string[], timeoutMs: number) => Promise<boolean>,
358
593
  root = ompRunDir(),
594
+ daemonDir = ompDaemonRunDir(),
359
595
  ): OwnedHubCleanupDependencies {
360
596
  return {
361
- scan: (cwd) => scanHubProcessesFrom(root, cwd),
597
+ scan: (cwd) => scanHubProcessesFrom(root, cwd, daemonDir),
362
598
  expire: (ms) => {
363
599
  const fired = Promise.withResolvers<void>();
364
600
  const timer = setTimeout(fired.resolve, ms);
365
601
  return { fired: fired.promise, cancel: () => clearTimeout(timer) };
366
602
  },
367
- stop: (name, cwd, timeoutMs) => runOmp(["ps", "stop", "--dir", cwd, "--", name], timeoutMs),
603
+ stop: (target, cwd, timeoutMs) => runOmp(["ps", "stop", "--dir", cwd, "--", target], timeoutMs),
368
604
  sleep: waitMs,
369
605
  now: () => Date.now(),
370
606
  };
371
607
  }
372
608
 
609
+ // omp 19 lets a unit's log grow to 25 MiB before rotating it, so read only the tail.
610
+ async function readLogTail(path: string): Promise<{ content: string; truncated: boolean }> {
611
+ const file = await open(path, "r");
612
+ try {
613
+ const { size } = await file.stat();
614
+ const truncated = size > MAX_LOG_BYTES;
615
+ const length = Math.min(size, MAX_LOG_BYTES);
616
+ const buffer = Buffer.alloc(length);
617
+ const { bytesRead } = await file.read(buffer, 0, length, size - length);
618
+ return { content: buffer.subarray(0, bytesRead).toString("utf8"), truncated };
619
+ } finally {
620
+ await file.close();
621
+ }
622
+ }
623
+
373
624
  export async function tailHubLogFrom(
374
625
  root: string,
375
626
  cwd: string,
376
627
  name: string,
628
+ daemonDir?: string,
377
629
  ): Promise<{ content: string; truncated: boolean }> {
630
+ if (daemonDir !== undefined) {
631
+ // omp 19's daemon runs every current service, so its newest record of the name wins.
632
+ const { services } = await scanDaemonServicesFrom(daemonDir, cwd);
633
+ const newest = services
634
+ .filter((service) => service.process.name === name)
635
+ .sort((a, b) => (b.process.startedAt ?? 0) - (a.process.startedAt ?? 0))[0];
636
+ if (newest) {
637
+ // A unit that has not written output yet (or whose log was pruned) has no log to show.
638
+ return readLogTail(newest.log).catch(() => ({ content: "", truncated: false }));
639
+ }
640
+ }
378
641
  const { roots } = await findProjectDaemonRoots(root, cwd);
379
642
  for (const projectRoot of roots) {
380
643
  try {
381
- const buffer = await readFile(join(projectRoot, "daemons", name, "output.log"));
382
- const truncated = buffer.byteLength > MAX_LOG_BYTES;
383
- const slice = truncated ? buffer.subarray(buffer.byteLength - MAX_LOG_BYTES) : buffer;
384
- return { content: slice.toString("utf8"), truncated };
644
+ return await readLogTail(join(projectRoot, "daemons", name, "output.log"));
385
645
  } catch {
386
646
  // This root doesn't have that process (or its log vanished); try the next match.
387
647
  }
@@ -393,5 +653,5 @@ export async function resolveTailHubLog({
393
653
  cwd,
394
654
  name,
395
655
  }: RpcInput<typeof tailHubLog>): Promise<{ content: string; truncated: boolean }> {
396
- return tailHubLogFrom(ompRunDir(), cwd, name);
656
+ return tailHubLogFrom(ompRunDir(), cwd, name, ompDaemonRunDir());
397
657
  }
@@ -1,2 +1,2 @@
1
1
  /** Release Please keeps this bundle-safe constant aligned with package.json. */
2
- export const PASEO_OMP_PACKAGE_VERSION = "5.7.0-next.524.1"; // x-release-please-version
2
+ export const PASEO_OMP_PACKAGE_VERSION = "5.7.0-next.526.1"; // x-release-please-version
package/server/paths.ts CHANGED
@@ -183,6 +183,27 @@ export function ompHubRunDir(
183
183
  return join(root, "run", "daemons");
184
184
  }
185
185
 
186
+ /**
187
+ * The run directory of omp 19's single per-user daemon, which owns every service a session
188
+ * starts. Unlike the 18.x brokers it ignores the profile and any agent-dir override, so every
189
+ * omp process on the machine agrees on it (pi-utils `getDaemonDir`, `OMP_DAEMON_DIR` first).
190
+ */
191
+ export function ompDaemonDir(
192
+ environment: NodeJS.ProcessEnv = currentOmpEnvironment(),
193
+ platform: NodeJS.Platform = process.platform,
194
+ ): string {
195
+ if (environment.OMP_DAEMON_DIR) return environment.OMP_DAEMON_DIR;
196
+ const xdgHome = environment.XDG_STATE_HOME;
197
+ if (xdgHome && (platform === "linux" || platform === "darwin")) {
198
+ const xdgRoot = join(xdgHome, "omp");
199
+ if (existsSync(xdgRoot)) return join(xdgRoot, "run", "daemon");
200
+ }
201
+ // OMP uses `os.homedir()`, evaluated in its own environment: libuv reads USERPROFILE first on
202
+ // Windows (a Git Bash HOME there does not count) and HOME first elsewhere.
203
+ const home = (platform === "win32" ? environment.USERPROFILE : environment.HOME) || homedir();
204
+ return join(home, environment.PI_CONFIG_DIR || ".omp", "run", "daemon");
205
+ }
206
+
186
207
  function configuredSessionDir(agentDir: string): string | undefined {
187
208
  for (const settingsPath of [
188
209
  join(agentDir, "settings.json"),
@@ -7,7 +7,7 @@ import {
7
7
  ownedHubCleanupDependencies,
8
8
  stopOwnedHubProcesses,
9
9
  } from "../hub";
10
- import { ompDataDir, ompHubRunDir } from "../paths";
10
+ import { ompDaemonDir, ompDataDir, ompHubRunDir } from "../paths";
11
11
  import { defaultSpawn, runBounded } from "../provider-diagnostics";
12
12
  import {
13
13
  buildOmpSpawnRequest,
@@ -189,6 +189,8 @@ export interface OmpRpcRuntimeOptions {
189
189
  timeoutMs: number,
190
190
  ) => Promise<boolean>;
191
191
  hubRunDir?: string;
192
+ /** omp 19's per-user daemon directory; defaults to the one the session's environment selects (`PASEO_OMP_DAEMON_DIR` is test-only). */
193
+ hubDaemonDir?: string;
192
194
  }
193
195
 
194
196
  const OMP_COMMAND_TIMEOUT_MS = 15_000;
@@ -710,6 +712,7 @@ export class OmpRpcRuntime implements OmpRuntime {
710
712
  (args, timeoutMs) =>
711
713
  run(request.command, [...prefix, ...args], env, request.cwd, timeoutMs),
712
714
  this.options.hubRunDir ?? process.env.PASEO_OMP_RUN_DIR ?? ompHubRunDir(env),
715
+ this.options.hubDaemonDir ?? (process.env.PASEO_OMP_DAEMON_DIR || ompDaemonDir(env)),
713
716
  ),
714
717
  );
715
718
  }
@@ -482,6 +482,15 @@ export class OmpProviderSession implements OmpOpenedSession, OmpSubagentControls
482
482
  await target.runtime.steerSubagent(target.nativeId, message);
483
483
  }
484
484
 
485
+ /** Paseo publishes the model as an opaque id; only the session can map it back to OMP's model. */
486
+ modelProvider(): string | null {
487
+ if (this.closed || this.runtimeDead) return null;
488
+ const model = this.configState.model
489
+ ? this.nativeModelsByPublicId.get(this.configState.model)
490
+ : undefined;
491
+ return model?.provider ?? null;
492
+ }
493
+
485
494
  /**
486
495
  * The native ID and runtime of a subagent this session's current runtime lists as running, or
487
496
  * `null`. OMP repeats the check; this scopes the request to this session and answers exactly.
@@ -1,4 +1,5 @@
1
1
  import type { RpcInput, RpcOutput } from "@getpaseo/plugin";
2
+ import type { getOmpSessionModelProvider } from "../shared/quota";
2
3
  import type { cancelOmpSubagent, steerOmpSubagent } from "../shared/subagents";
3
4
  import { OmpRpcRequestRejectedError } from "./provider/omp-rpc-transport";
4
5
  import { isOmpPublicError, OmpPublicError } from "./provider/security";
@@ -8,6 +9,8 @@ export interface OmpSubagentControls {
8
9
  /** Resolves `false` when the subagent is no longer running. */
9
10
  cancelSubagent(handle: string): Promise<boolean>;
10
11
  steerSubagent(handle: string, message: string): Promise<void>;
12
+ /** The OMP provider of the session's current model, or null once the session has ended. */
13
+ modelProvider(): string | null;
11
14
  }
12
15
 
13
16
  export class OmpSubagentNotRunningError extends OmpPublicError {
@@ -95,3 +98,11 @@ export async function resolveSteerOmpSubagent(
95
98
  await withPublicFailure("steer", () => controls.steerSubagent(input.subagentId, input.message));
96
99
  return { accepted: true };
97
100
  }
101
+
102
+ /** No live session (closed, history-only or another daemon's) answers null rather than failing. */
103
+ export function resolveGetOmpSessionModelProvider(
104
+ input: RpcInput<typeof getOmpSessionModelProvider>,
105
+ registry: OmpSubagentControlRegistry,
106
+ ): RpcOutput<typeof getOmpSessionModelProvider> {
107
+ return { provider: registry.get(input.agentId)?.modelProvider() ?? null };
108
+ }
package/shared/hub.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { defineRpc } from "@getpaseo/plugin";
2
2
  import { z } from "zod";
3
3
 
4
- // Mirrors the on-disk shape omp's hub writes under
5
- // ~/.omp/run/daemons/<projectHash>/daemons/<name>/meta.json. That layout is an internal,
6
- // unversioned implementation detail of the omp harness, not a published API, so every field
7
- // here is optional-safe on the server side and this schema is intentionally permissive
8
- // (state is a free-form string, not a fixed enum) to avoid rejecting shapes we have not seen.
4
+ // Mirrors the on-disk shape omp's hub writes: omp 18's per-project brokers under
5
+ // ~/.omp/run/daemons/<projectHash>/daemons/<name>/meta.json, and omp 19's per-user daemon store
6
+ // (~/.omp/run/daemon/daemon.db). Both are internal, unversioned implementation details of the omp
7
+ // harness, not a published API, so every field here is optional-safe on the server side and this
8
+ // schema is intentionally permissive (state is a free-form string, not a fixed enum) to avoid
9
+ // rejecting shapes we have not seen.
9
10
  export const HubProcessSchema = z.object({
10
11
  name: z.string(),
11
12
  application: z.string(),
package/shared/quota.ts CHANGED
@@ -34,3 +34,13 @@ export const listOmpQuotas = defineRpc({
34
34
  input: z.object({ store: OmpStoreSchema.optional() }),
35
35
  output: z.object({ quotas: z.array(OmpQuotaSchema) }),
36
36
  });
37
+
38
+ /**
39
+ * The OMP provider (such as `anthropic`) of the model an OMP Plugin agent's live session uses.
40
+ * Paseo only sees that model as an opaque id, so the provider is null without a live session.
41
+ */
42
+ export const getOmpSessionModelProvider = defineRpc({
43
+ name: "paseo-omp.session-model-provider",
44
+ input: z.object({ agentId: z.string().min(1).max(256) }),
45
+ output: z.object({ provider: z.string().nullable() }),
46
+ });