@0gfoundation/0g-agentdna 0.2.0 → 0.2.2

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.
Files changed (56) hide show
  1. package/GUIDE.md +64 -15
  2. package/PROVIDERS.md +6 -4
  3. package/PROVIDERS.zh.md +4 -3
  4. package/README.md +19 -3
  5. package/dist/AgentClient.d.ts +175 -2
  6. package/dist/AgentClient.d.ts.map +1 -1
  7. package/dist/AgentClient.js +166 -7
  8. package/dist/AgentClient.js.map +1 -1
  9. package/dist/AgenticID.d.ts +45 -6
  10. package/dist/AgenticID.d.ts.map +1 -1
  11. package/dist/AgenticID.js +40 -10
  12. package/dist/AgenticID.js.map +1 -1
  13. package/dist/AttestorClient.d.ts +66 -1
  14. package/dist/AttestorClient.d.ts.map +1 -1
  15. package/dist/AttestorClient.js +161 -32
  16. package/dist/AttestorClient.js.map +1 -1
  17. package/dist/cli/commands/cells.d.ts +29 -1
  18. package/dist/cli/commands/cells.d.ts.map +1 -1
  19. package/dist/cli/commands/cells.js +48 -1
  20. package/dist/cli/commands/cells.js.map +1 -1
  21. package/dist/cli/commands/interactive.d.ts +84 -7
  22. package/dist/cli/commands/interactive.d.ts.map +1 -1
  23. package/dist/cli/commands/interactive.js +453 -58
  24. package/dist/cli/commands/interactive.js.map +1 -1
  25. package/dist/cli/commands/list.d.ts.map +1 -1
  26. package/dist/cli/commands/list.js +7 -31
  27. package/dist/cli/commands/list.js.map +1 -1
  28. package/dist/cli/commands/settings.d.ts.map +1 -1
  29. package/dist/cli/commands/settings.js +23 -0
  30. package/dist/cli/commands/settings.js.map +1 -1
  31. package/dist/cli/inference.d.ts +25 -0
  32. package/dist/cli/inference.d.ts.map +1 -1
  33. package/dist/cli/inference.js +67 -6
  34. package/dist/cli/inference.js.map +1 -1
  35. package/dist/cli/settings.d.ts +20 -0
  36. package/dist/cli/settings.d.ts.map +1 -1
  37. package/dist/cli/settings.js +40 -1
  38. package/dist/cli/settings.js.map +1 -1
  39. package/dist/constants.d.ts +1 -1
  40. package/dist/constants.js +1 -1
  41. package/dist/index.d.ts +4 -3
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +6 -2
  44. package/dist/index.js.map +1 -1
  45. package/package.json +1 -1
  46. package/src/AgentClient.ts +326 -9
  47. package/src/AgenticID.ts +62 -8
  48. package/src/AttestorClient.ts +206 -50
  49. package/src/cli/commands/cells.ts +47 -1
  50. package/src/cli/commands/interactive.ts +441 -64
  51. package/src/cli/commands/list.ts +7 -29
  52. package/src/cli/commands/settings.ts +22 -1
  53. package/src/cli/inference.ts +82 -5
  54. package/src/cli/settings.ts +41 -0
  55. package/src/constants.ts +1 -1
  56. package/src/index.ts +7 -3
@@ -19,7 +19,7 @@ import { join } from 'node:path';
19
19
  import { SDK_VERSION } from '../../constants';
20
20
  import { parseEther, keccak256, isAddress, ContractFunctionRevertedError, type Address } from 'viem';
21
21
  import type { AgenticID } from '../../AgenticID';
22
- import type { AgentClient, ChatMessage } from '../../AgentClient';
22
+ import type { AgentClient, AgentInboxMessage, AgentSchedule, AgentTaskInfo, AgentTaskStop, ChatMessage } from '../../AgentClient';
23
23
  import type { ServeProof, TaskReveal } from '../../types';
24
24
  import { taskHashOf, requestUriCandidates } from '../../taskHash';
25
25
  import { buildClient } from '../sdk';
@@ -28,17 +28,17 @@ import { CliError } from '../errors';
28
28
  import { requireAttestorUrl } from '../env';
29
29
  import { loadKey, saveKey, normalizeKey, saveApiKey, loadConfig, saveConfig, configPaths } from '../config';
30
30
  import { parseAgentRef, refMatchesSeal, type AgentRef } from '../ref';
31
- import { applyAssignments, assertModelPresent, parseAssignments, renderSettings } from '../settings';
31
+ import { applyAssignments, assertModelPresent, assertOthersFitFramework, isHarnessFramework, parseAssignments, renderSettings } from '../settings';
32
32
  import { SettingsConflictError, THINKING_LEVELS, type SettingsDoc, type ThinkingLevel } from '../../Settings';
33
33
  import { splitHead, tokenize } from '../tokenize';
34
34
  import { pandaLines, svgPixelLines } from '../logo';
35
35
  import { listInferenceProviders, type InferenceProvider, changesProvider } from '../../Providers';
36
- import { configuredInferenceKey, requireConfiguredInferenceKey, agentInferenceProvider, requiresProviderReset, deployWithInference } from '../inference';
36
+ import { configuredInferenceKey, requireConfiguredInferenceKey, resetInferencePlan, applyResetInference, readDeploymentFacts, requiresProviderReset, deployWithInference } from '../inference';
37
37
 
38
38
  // Tab-completion candidates for the active REPL level (canonical names only —
39
39
  // aliases like link//unuse still work typed out but don't clutter the list).
40
40
  const L1_WORDS = ['list', 'use ', 'hello ', 'call ', 'rate ', 'deploy', 'start ', 'stop ', 'reset ', 'retry ', 'settings ', 'clone ', 'transfer ', 'authorizer ', 'grant ', 'revoke ', 'balance', 'deposit', 'withdraw', 'ack', 'login', 'whoami', 'help', 'quit'];
41
- const L2_WORDS = ['/hello', '/balance', '/topup', '/start', '/stop', '/reset', '/settings', '/think', '/clear', '/compact', '/tasks', '/result', '/cancel', '/agentlog', '/startuplog', '/back', '/help', '/quit'];
41
+ const L2_WORDS = ['/hello', '/balance', '/topup', '/start', '/stop', '/reset', '/settings', '/think', '/clear', '/compact', '/tasks', '/result', '/cancel', '/inbox', '/schedules', '/agentlog', '/startuplog', '/back', '/help', '/quit'];
42
42
  let activeCompletions: string[] = L1_WORDS;
43
43
  // First-argument completion per command (Tab after the command word).
44
44
  // Static lists inline; AGENT resolves to the ids seen in the latest
@@ -232,8 +232,9 @@ export async function routeTaskFailure(
232
232
 
233
233
  /**
234
234
  * The tasks bare `/cancel` stops: everything still in flight, NEWEST FIRST
235
- * (stopping only the newest would leave an older running turn alive; dsh/
236
- * prime serialize turns, so a queued one is waiting on the running one).
235
+ * (stopping only the newest would leave an older running turn alive;
236
+ * 0g-harness and prime serialize turns, so a queued one is waiting on the
237
+ * running one).
237
238
  * Statuses arrive live from the agent; "unknown" (evicted or agent
238
239
  * restarted, 404) counts as not in flight — cancelling an unknown record
239
240
  * would claim to stop something nobody can see. Exported for the tests:
@@ -247,6 +248,148 @@ export function inFlightIds(rows: Array<{ id: string; status: string }>): string
247
248
  return out;
248
249
  }
249
250
 
251
+ /** A span of seconds, short: 12s, 4m, 3h, 2d. */
252
+ function span(seconds: number): string {
253
+ const s = Math.max(0, Math.round(seconds));
254
+ if (s < 60) return `${s}s`;
255
+ if (s < 3600) return `${Math.floor(s / 60)}m`;
256
+ if (s < 86400) return `${Math.floor(s / 3600)}h`;
257
+ return `${Math.floor(s / 86400)}d`;
258
+ }
259
+
260
+ /** Who asked for a task, as /tasks shows it. */
261
+ const ASKED_BY: Record<string, string> = { user: 'you', job: 'job', schedule: 'reminder', plugin: 'plugin', agent: 'agent' };
262
+
263
+ /**
264
+ * The /tasks table over the agent's own task list: BY is who does the work
265
+ * (the main agent or a subagent), FOR is who asked (you, a finished job, a
266
+ * reminder, the agent itself). Ids print whole: they are what /result and
267
+ * /cancel take. Exported for the tests.
268
+ */
269
+ export function renderTaskTable(tasks: AgentTaskInfo[], nowMs: number): string[] {
270
+ const idw = Math.max(2, ...tasks.map((t) => cleanCell(t.id).length)) + 2;
271
+ const head = ` ${'ID'.padEnd(idw)}${'STATUS'.padEnd(13)}${'BY'.padEnd(10)}${'FOR'.padEnd(10)}${'AGE'.padEnd(6)}WHAT`;
272
+ return [
273
+ head,
274
+ ...tasks.map((t) =>
275
+ ` ${cleanCell(t.id).padEnd(idw)}${cellText(t.status, 13)}${cellText(t.actor, 10)}` +
276
+ `${cellText(ASKED_BY[t.trigger] ?? t.trigger, 10)}${span(nowMs / 1000 - t.created_at).padEnd(6)}` +
277
+ `${[...cleanCell(t.label)].slice(0, 70).join('')}`),
278
+ ];
279
+ }
280
+
281
+ /**
282
+ * One inbox message as the session prints it: why the agent spoke up, then
283
+ * what it said. Exported for the tests.
284
+ */
285
+ export function renderInboxMessage(m: AgentInboxMessage): string {
286
+ const label = cleanCell(m.label);
287
+ const why = m.trigger === 'job' ? `job finished · ${label}`
288
+ : m.trigger === 'schedule' ? `reminder · ${label}`
289
+ : label || cleanCell(m.trigger);
290
+ const lines = [`◆ agent · ${why}`];
291
+ if (m.text?.trim()) lines.push(m.text.replace(/\s+$/, ''));
292
+ if (m.status === 'failed') lines.push(`(that turn failed: ${cleanCell(m.error ?? 'no reason given')})`);
293
+ else if (m.status === 'cancelled') lines.push('(that turn was cancelled)');
294
+ return `${lines.join('\n')}\n`;
295
+ }
296
+
297
+ /** The /schedules lines: id, how often, when next, the reminder's text.
298
+ * Exported for the tests. */
299
+ export function renderSchedules(list: AgentSchedule[], nowMs: number): string[] {
300
+ const idw = Math.max(2, ...list.map((r) => cleanCell(r.id).length)) + 2;
301
+ return list.map((r) => {
302
+ const how = r.kind === 'every' && r.everySeconds ? `every ${span(r.everySeconds)}` : 'once';
303
+ const due = r.state === 'overdue' ? 'due now' : `in ${span((Date.parse(r.scheduledAt) - nowMs) / 1000)}`;
304
+ return ` ${cleanCell(r.id).padEnd(idw)}${how.padEnd(12)}${due.padEnd(12)}${cleanCell(r.prompt)}`;
305
+ });
306
+ }
307
+
308
+ /** What stopping a task did, in words. */
309
+ const STOP_OUTCOME: Record<AgentTaskStop['outcome'], string> = {
310
+ cancelled: 'stopped',
311
+ 'already-finished': 'already finished',
312
+ 'not-running': 'not running',
313
+ };
314
+
315
+ /**
316
+ * Follows one agent's inbox for a session: first the messages that came in
317
+ * while nobody was looking, then each new one as the agent's live feed
318
+ * announces it. `show` prints a rendered message, now or at the next prompt,
319
+ * and calls `shown` once it is on screen; the message is acked then, so
320
+ * another window does not show it again. A message is shown once per feed.
321
+ * `follow` is called with the session's current client before every prompt
322
+ * and restarts the feed when the client changed (/start, /reset); an agent
323
+ * without an inbox gets no feed. Exported for the tests.
324
+ */
325
+ export function makeInboxFeed(show: (text: string, shown: () => void) => void): {
326
+ follow(client: AgentClient | undefined): void;
327
+ stop(): void;
328
+ } {
329
+ let current: AgentClient | undefined;
330
+ let ac: AbortController | null = null;
331
+
332
+ async function run(client: AgentClient, signal: AbortSignal): Promise<void> {
333
+ const seen = new Set<number>();
334
+ let acked = 0;
335
+ const present = (msgs: AgentInboxMessage[], away: boolean): void => {
336
+ const fresh = msgs.filter((m) => !seen.has(m.seq));
337
+ if (!fresh.length || signal.aborted) return;
338
+ for (const m of fresh) seen.add(m.seq);
339
+ const through = Math.max(...fresh.map((m) => m.seq));
340
+ const text = (away ? `\nwhile you were away (${fresh.length}):\n` : '\n') + fresh.map(renderInboxMessage).join('\n');
341
+ show(text, () => {
342
+ if (through <= acked) return;
343
+ acked = through;
344
+ // Best-effort: a window that lost the seat cannot ack (409), and the
345
+ // owner's next window shows the message again.
346
+ client.ackInbox?.(through).catch(() => undefined);
347
+ });
348
+ };
349
+ const readUnread = async (away: boolean): Promise<number | undefined> => {
350
+ const page = await client.inbox!();
351
+ present(page.data, away);
352
+ return page.cursor;
353
+ };
354
+ let cursor: number | undefined;
355
+ try {
356
+ cursor = await readUnread(true);
357
+ } catch {
358
+ // The feed still runs; its first event, or a reset, catches up.
359
+ }
360
+ if (signal.aborted || !client.events) return;
361
+ try {
362
+ for await (const e of client.events({ after: cursor, signal })) {
363
+ // An inbox message's seq is its event's.
364
+ if (e.type === 'inbox.message') present([{ ...(e.data as unknown as AgentInboxMessage), seq: e.seq }], false);
365
+ // The agent could not serve our position: what we may have missed
366
+ // is in the inbox itself.
367
+ else if (e.type === 'reset') await readUnread(false).catch(() => undefined);
368
+ }
369
+ } catch {
370
+ // A 4xx: this agent no longer serves the feed. Nothing to say at the
371
+ // prompt about it; /inbox still reads the inbox.
372
+ }
373
+ }
374
+
375
+ const stop = (): void => {
376
+ ac?.abort();
377
+ ac = null;
378
+ current = undefined;
379
+ };
380
+ return {
381
+ follow(client) {
382
+ if (client === current) return;
383
+ stop();
384
+ if (!client?.inbox) return;
385
+ current = client;
386
+ ac = new AbortController();
387
+ void run(client, ac.signal);
388
+ },
389
+ stop,
390
+ };
391
+ }
392
+
250
393
  let knownAgentIds: string[] = [];
251
394
  const rememberAgentIds = (rows: Array<{ agentId?: unknown }>): void => {
252
395
  const ids = rows.map((r) => String(r.agentId ?? '')).filter((x) => x && x !== 'undefined');
@@ -285,6 +428,8 @@ const L1_ARGS: Record<string, string[] | (() => string[])> = {
285
428
  const L2_ARGS: Record<string, string[] | (() => string[])> = {
286
429
  '/think': ['low', 'high', 'max'],
287
430
  '/reset': ['pick'],
431
+ '/cancel': ['all'],
432
+ '/inbox': ['all'],
288
433
  '/settings': ['provider=', 'model=', 'thinking=', 'others='],
289
434
  };
290
435
  let activeArgs: Record<string, string[] | (() => string[])> = L1_ARGS;
@@ -356,23 +501,72 @@ export function completeLine(
356
501
  // The live readline interface — askSecret scrubs submitted secrets out of
357
502
  // its history (display masking alone leaves the plaintext one ↑ away).
358
503
  let activeRl: readline.Interface | null = null;
504
+
505
+ /**
506
+ * Print a block above the live prompt, keeping what the user has typed. The
507
+ * prompt and its input are erased from their first row down, the block is
508
+ * written, and readline redraws the prompt below it. Its redraw first moves
509
+ * up as many rows as the cursor sat below the prompt's first row (the
510
+ * prompt's own leading newline counts), so that many blank rows are left for
511
+ * it to land on. Without a terminal there is no prompt to keep: the block is
512
+ * just written. `rl`/`output` are the session's; exported for the tests,
513
+ * which pass a readline over a captured stream.
514
+ */
515
+ export function printAbovePrompt(
516
+ text: string,
517
+ rl: readline.Interface | null = activeRl,
518
+ output: NodeJS.WritableStream = process.stdout,
519
+ ): void {
520
+ if (!rl || !rl.terminal) {
521
+ output.write(text.startsWith('\n') ? text : `\n${text}`);
522
+ return;
523
+ }
524
+ const { rows } = rl.getCursorPos();
525
+ readline.moveCursor(output, 0, -rows);
526
+ readline.cursorTo(output, 0);
527
+ readline.clearScreenDown(output);
528
+ output.write(text.endsWith('\n') ? text : `${text}\n`);
529
+ output.write('\n'.repeat(rows));
530
+ rl.prompt(true);
531
+ }
359
532
  import type { CommandContext } from '../types';
360
- import { cleanCell } from './cells';
533
+ import { cellText, cleanCell, ownerCellText, sealToAgentMap, shortAddr, trustedCell } from './cells';
534
+
535
+ /** Column widths of the REPL listing; its header and every row share them. */
536
+ const LIST_COLS = { id: 6, phase: 11, framework: 12, seal: 13, agentSeal: 13, owner: 24 } as const;
537
+
538
+ /** The REPL listing's header line, aligned with {@link renderListRow}. */
539
+ export function renderListHeader(): string {
540
+ const c = LIST_COLS;
541
+ return ` ${'ID'.padEnd(c.id)} ${'PHASE'.padEnd(c.phase)}${'FRAMEWORK'.padEnd(c.framework)}` +
542
+ `${'SEAL'.padEnd(c.seal)}${'AGENTSEAL'.padEnd(c.agentSeal)}${'OWNER'.padEnd(c.owner)}NAME\n`;
543
+ }
361
544
 
362
545
  /**
363
546
  * One row of the REPL's agent listing. Exported for the tests: this IS the
364
- * renderer the interactive loop prints — NAME goes through cleanCell (./cells),
365
- * so a name cannot forge rows in this listing either, same as `list`.
366
- * Everyone gets the seal PREFIX short form — commands accept a unique prefix,
367
- * so unminted rows stay referenceable without a 66-char column blowout (F12).
547
+ * renderer the interactive loop prints. Its cells go through ./cells, shared
548
+ * with `list`: a name cannot forge rows in this listing either, and an
549
+ * agent-owned agent reads the same way — its OWNER is another row's
550
+ * AGENTSEAL, annotated `⇄ #<agentId>` (`sealToAgent`, from the full listing).
551
+ * SEAL is the sealId PREFIX (`0x` + 10 hex), the form commands accept as a
552
+ * reference, so unminted rows stay referenceable without a 66-char column
553
+ * blowout (F12).
554
+ * AGENTSEAL is the agent's on-chain signing address.
368
555
  */
369
556
  export function renderListRow(
370
- r: { agentId: bigint | number | null; phase?: string | null; sealId: string; name?: string | null },
557
+ r: {
558
+ agentId: bigint | number | null; phase?: string | null; sealId: string; name?: string | null;
559
+ framework?: string | null; agentSeal?: string | null;
560
+ },
371
561
  owner: string | null | undefined,
372
562
  owned = ' ',
563
+ sealToAgent: ReadonlyMap<string, string> = new Map(),
373
564
  ): string {
374
- const seal = `${r.sealId.slice(0, 12)}…${r.sealId.slice(-6)}`;
375
- return `${owned} ${String(r.agentId ?? '?').padEnd(6)} ${String(r.phase ?? '?').padEnd(10)} ${seal.padEnd(21)} ${(owner ?? '').padEnd(13)} ${cleanCell(r.name)}\n`;
565
+ const c = LIST_COLS;
566
+ const seal = `0x${r.sealId.slice(2, 12)}`;
567
+ return `${owned} ${String(r.agentId ?? '?').padEnd(c.id)} ${cellText(r.phase ?? '?', c.phase)}` +
568
+ `${cellText(r.framework, c.framework)}${cellText(seal, c.seal)}${cellText(shortAddr(r.agentSeal), c.agentSeal)}` +
569
+ `${trustedCell(ownerCellText(owner, sealToAgent), c.owner)}${cleanCell(r.name)}\n`;
376
570
  }
377
571
 
378
572
  const sbid = (url: string): string | undefined => url.match(/8080-([^.]+)\./)?.[1];
@@ -491,19 +685,63 @@ async function refreshSession(s: Session, quiet = false): Promise<void> {
491
685
  if (reason) out(` last error: ${reason}\n`);
492
686
  }
493
687
 
688
+ /** An agent's container state just before a lifecycle request was sent. */
689
+ export interface LifecycleBaseline {
690
+ /** The container stage's `at`, in ms (server clock); undefined when it has none. */
691
+ at?: number;
692
+ state?: string;
693
+ sandboxId?: string;
694
+ }
695
+
696
+ /**
697
+ * Read the row a lifecycle request is about to change. The attestor answers
698
+ * `/reset` and `/start` with 202 before its worker touches the row, so the
699
+ * wait compares against this. undefined when the row cannot be read; the wait
700
+ * then takes the row as it finds it.
701
+ */
702
+ export async function lifecycleBaseline(attestorUrl: string, sealId: `0x${string}`): Promise<LifecycleBaseline | undefined> {
703
+ try {
704
+ const d = (await (await fetch(`${attestorUrl}/deployment/${sealId}`, { signal: AbortSignal.timeout(10_000) })).json()) as {
705
+ sandbox_id?: string; container_stage?: { state?: string; at?: string };
706
+ };
707
+ const at = Date.parse(d.container_stage?.at ?? '');
708
+ return { at: Number.isFinite(at) ? at : undefined, state: d.container_stage?.state, sandboxId: d.sandbox_id };
709
+ } catch {
710
+ return undefined;
711
+ }
712
+ }
713
+
494
714
  /**
495
715
  * Wait for a deployment to reach `running` by polling the attestor's public
496
716
  * /deployment/:sealId — and FAIL LOUD instead of hanging: a `failed`/`offline`
497
717
  * phase (or a failed container_stage) surfaces its recorded reason
498
718
  * immediately, and the timeout produces an error naming the last phase seen.
719
+ *
720
+ * With a `baseline` (the row read before a reset or start was sent), the row
721
+ * as it was then is not this request's outcome: until the worker moves the
722
+ * container on (a new start or create, a new sandbox, a stage written after
723
+ * the baseline), the wait shows `queued` and neither a still-running old
724
+ * container nor an earlier failure ends it.
499
725
  */
500
726
  class WaitCancelled extends Error { constructor() { super('wait cancelled'); } }
501
727
 
502
- async function pollRunning(attestorUrl: string, sealId: `0x${string}`, agentId: string, timeoutMs = 360000, signal?: AbortSignal): Promise<{ url: string }> {
728
+ export async function pollRunning(
729
+ attestorUrl: string,
730
+ sealId: `0x${string}`,
731
+ agentId: string,
732
+ timeoutMs = 360000,
733
+ signal?: AbortSignal,
734
+ opts: { baseline?: LifecycleBaseline; intervalMs?: number } = {},
735
+ ): Promise<{ url: string }> {
736
+ const { baseline, intervalMs = 4000 } = opts;
503
737
  const deadline = Date.now() + timeoutMs;
504
738
  const t0 = Date.now();
505
739
  let lastPhase = 'contacting attestor';
506
740
  let lastShown = '';
741
+ // Whether the request has visibly started: a fresh `submitted` stage, a new
742
+ // sandbox, or a stage written after the baseline other than the old
743
+ // container's own running reports.
744
+ let progressed = !baseline;
507
745
  // Transient progress line between phase changes — a deploy sits minutes in
508
746
  // one phase with zero output otherwise. Repainted each second; phase-change
509
747
  // lines and the final result overwrite it. TTY only.
@@ -529,15 +767,22 @@ async function pollRunning(attestorUrl: string, sealId: `0x${string}`, agentId:
529
767
  const d = (await (await fetch(`${attestorUrl}/deployment/${sealId}`)).json()) as {
530
768
  phase?: string; url?: string; sandbox_id?: string;
531
769
  agent_card?: { url?: string };
532
- container_stage?: { state?: string; reason?: string };
770
+ container_stage?: { state?: string; reason?: string; at?: string };
533
771
  };
534
- lastPhase = d.phase ?? lastPhase;
772
+ if (!progressed && baseline) {
773
+ const at = Date.parse(d.container_stage?.at ?? '');
774
+ const fresh = Number.isFinite(at) && (baseline.at === undefined || at > baseline.at);
775
+ const state = d.container_stage?.state;
776
+ progressed = (fresh && !(state === 'confirmed' && baseline.state === 'confirmed'))
777
+ || (d.sandbox_id !== undefined && d.sandbox_id !== baseline.sandboxId);
778
+ }
779
+ lastPhase = progressed ? (d.phase ?? lastPhase) : 'queued';
535
780
  if (lastPhase !== lastShown) { clearSpinner(); out(` … ${lastPhase}\n`); lastShown = lastPhase; }
536
781
  const cardBase = d.agent_card?.url?.replace(/\/hello$/, '');
537
782
  const url = d.url ?? cardBase ?? (d.sandbox_id && cfg.sandbox_proxy_addr ? containerUrl(d.sandbox_id, cfg.sandbox_proxy_addr) : undefined);
538
- if (d.phase === 'running' && url) return { url };
783
+ if (progressed && d.phase === 'running' && url) return { url };
539
784
  const reason = d.container_stage?.state === 'failed' ? d.container_stage?.reason : undefined;
540
- if (d.phase === 'failed' || reason) {
785
+ if (progressed && (d.phase === 'failed' || reason)) {
541
786
  throw new CliError('UNKNOWN', `agent ${agentId} did not start: ${reason ?? `phase=${d.phase}`}`, {
542
787
  remedy: `run \`reset ${agentId}\` to recreate the container once the cause is fixed`,
543
788
  });
@@ -547,12 +792,17 @@ async function pollRunning(attestorUrl: string, sealId: `0x${string}`, agentId:
547
792
  // transient fetch error — keep polling until the deadline
548
793
  }
549
794
  if (Date.now() > deadline) {
795
+ if (!progressed) {
796
+ throw new CliError('UNKNOWN', `agent ${agentId} did not come online: the attestor had not started this request after ${Math.round(timeoutMs / 1000)}s`, {
797
+ remedy: 'a request that waits too long in the attestor\'s queue expires and leaves the agent as it was — run the command again',
798
+ });
799
+ }
550
800
  throw new CliError('UNKNOWN', `timed out after ${Math.round(timeoutMs / 1000)}s waiting for agent ${agentId} (last phase: ${lastPhase})`, {
551
801
  remedy: 'check `status` — provisioning can lag; retry the command when the phase moves',
552
802
  });
553
803
  }
554
804
  if (signal?.aborted) throw new WaitCancelled();
555
- await new Promise((r) => setTimeout(r, 4000));
805
+ await new Promise((r) => setTimeout(r, intervalMs));
556
806
  if (signal?.aborted) throw new WaitCancelled();
557
807
  }
558
808
  } finally {
@@ -563,11 +813,11 @@ async function pollRunning(attestorUrl: string, sealId: `0x${string}`, agentId:
563
813
 
564
814
  /** pollRunning wired to the Esc/Ctrl-C interrupt: cancelling abandons the
565
815
  * WAIT only — the lifecycle operation keeps going server-side. */
566
- async function waitRunningInterruptible(irq: Interrupt, attestorUrl: string, sealId: `0x${string}`, agentId: string): Promise<{ url: string } | null> {
816
+ async function waitRunningInterruptible(irq: Interrupt, attestorUrl: string, sealId: `0x${string}`, agentId: string, baseline?: LifecycleBaseline): Promise<{ url: string } | null> {
567
817
  const ac = new AbortController();
568
818
  irq.streaming = ac;
569
819
  try {
570
- return await pollRunning(attestorUrl, sealId, agentId, 360000, ac.signal);
820
+ return await pollRunning(attestorUrl, sealId, agentId, 360000, ac.signal, { baseline });
571
821
  } catch (e) {
572
822
  if (e instanceof WaitCancelled || ac.signal.aborted) {
573
823
  out('\n(wait cancelled — the operation continues server-side; check with `list` or re-enter with `use`)\n');
@@ -1050,12 +1300,14 @@ async function managerRepl(ctx: CommandContext, ask: (q: string) => Promise<stri
1050
1300
  }
1051
1301
  const shown = mineOnly ? rows.filter((r) => mine?.has(r.sealId)) : rows;
1052
1302
  if (!shown.length) { out(mineOnly ? 'no agents owned by this wallet here\n' : 'no agents on this attestor\n'); continue; }
1053
- const shortAddr = (a?: string | null): string => (a ? `${a.slice(0, 6)}…${a.slice(-4)}` : '');
1054
- out(` ${'ID'.padEnd(6)} ${'PHASE'.padEnd(10)} ${'SEAL'.padEnd(21)} ${'OWNER'.padEnd(13)} NAME\n`);
1303
+ // From the full public listing, as in `list`: a --mine view must not
1304
+ // strip the annotation off a child whose parent it hides.
1305
+ const sealToAgent = sealToAgentMap(rows);
1306
+ out(renderListHeader());
1055
1307
  for (const r of shown) {
1056
- const owned = mine?.has(r.sealId) ? '*' : ' ';
1057
- const owner = shortAddr(mine?.get(r.sealId)?.owner ?? r.owner);
1058
- out(renderListRow(r, owner, owned));
1308
+ const own = mine?.get(r.sealId);
1309
+ // The owner tier carries owner and agentSeal for UNMINTED rows too.
1310
+ out(renderListRow({ ...r, agentSeal: own?.agentSeal ?? r.agentSeal }, own?.owner ?? r.owner, own ? '*' : ' ', sealToAgent));
1059
1311
  }
1060
1312
  if (mine && !mineOnly) out('(* = owned by your wallet · `list --mine` filters to them)\n');
1061
1313
  if (shown.some((r) => r.agentId == null)) out("('?' rows have no agentId yet — reference them by sealId prefix, e.g. retry 0x" + shown.find((r) => r.agentId == null)!.sealId.slice(2, 12) + ')\n');
@@ -1079,8 +1331,9 @@ async function managerRepl(ctx: CommandContext, ask: (q: string) => Promise<stri
1079
1331
  if (row.phase !== 'stopped' || !row.sandboxId) { out(`agent ${row.agentId} is ${row.phase} — a plain start cannot revive it; run: reset ${row.agentId}\n`); continue; }
1080
1332
  if (!(await ensureOwnerReady(ag, ask))) { out('start cancelled — prepaid balance too low\n'); continue; }
1081
1333
  out(`starting agent ${row.agentId}… (Esc cancels the wait)\n`);
1334
+ const baseline = await lifecycleBaseline(attestorUrl, row.sealId);
1082
1335
  await ag.agent.start(row.sealId, row.sandboxId);
1083
- const r = await waitRunningInterruptible(irq, attestorUrl, row.sealId, row.agentId);
1336
+ const r = await waitRunningInterruptible(irq, attestorUrl, row.sealId, row.agentId, baseline);
1084
1337
  if (r) out(`running at ${r.url} — enter with: use ${row.agentId}\n`);
1085
1338
  continue;
1086
1339
  }
@@ -1094,13 +1347,16 @@ async function managerRepl(ctx: CommandContext, ask: (q: string) => Promise<stri
1094
1347
  } else {
1095
1348
  framework = await pickFramework(attestorUrl, ask, row.framework ?? undefined);
1096
1349
  }
1097
- const provider = await agentInferenceProvider(ag, row.sealId);
1350
+ const plan = await resetInferencePlan(ag, row.sealId, await readDeploymentFacts(attestorUrl, row.sealId));
1351
+ const provider = plan.provider;
1098
1352
  await ag.agent.assertProviderSupported(provider, { sealId: row.sealId, framework });
1099
1353
  const apiKey = await inferenceKey(ctx, ask, provider);
1100
1354
  if (!(await ensureOwnerReady(ag, ask))) { out('reset cancelled — prepaid balance too low\n'); continue; }
1355
+ await applyResetInference(ag, row.sealId, plan, out);
1101
1356
  out(`resetting agent ${row.agentId} as ${framework}… (Esc cancels the wait)\n`);
1357
+ const baseline = await lifecycleBaseline(attestorUrl, row.sealId);
1102
1358
  await ag.agent.reset(row.sealId, { provider, framework, apiKey });
1103
- const r = await waitRunningInterruptible(irq, attestorUrl, row.sealId, row.agentId);
1359
+ const r = await waitRunningInterruptible(irq, attestorUrl, row.sealId, row.agentId, baseline);
1104
1360
  if (r) out(`running at ${r.url} — enter with: use ${row.agentId}\n`);
1105
1361
  continue;
1106
1362
  }
@@ -1135,7 +1391,7 @@ async function managerRepl(ctx: CommandContext, ask: (q: string) => Promise<stri
1135
1391
  const ag = await withWallet(ctx);
1136
1392
  const row = await findAgentRow(ag, args[0]);
1137
1393
  if (!row) { out(`no agent matching ${args[0]} on this attestor\n`); continue; }
1138
- await settingsOp(ag, row.sealId, args.slice(1), row.phase === 'running' && row.url ? row.url : undefined);
1394
+ await settingsOp(ag, row.sealId, args.slice(1), row.phase === 'running' && row.url ? row.url : undefined, row.framework);
1139
1395
  continue;
1140
1396
  }
1141
1397
 
@@ -1457,8 +1713,9 @@ let cachedClient: { key: string; ag: AgenticID } | null = null;
1457
1713
  * Returns the document now in force (unchanged on a bare show), so a caller
1458
1714
  * like /think can report the level that actually landed.
1459
1715
  */
1460
- async function settingsOp(ag: AgenticID, sealId: `0x${string}`, args: string[], serveBase?: string): Promise<SettingsDoc | null> {
1716
+ async function settingsOp(ag: AgenticID, sealId: `0x${string}`, args: string[], serveBase?: string, framework?: string | null): Promise<SettingsDoc | null> {
1461
1717
  const assignments = parseAssignments(args); // throws CliError on a bad key/level
1718
+ assertOthersFitFramework(assignments, framework);
1462
1719
  const { settings: current, version } = await ag.agent.getSettings(sealId);
1463
1720
  if (!assignments.length) {
1464
1721
  for (const l of renderSettings(current)) out(` ${l}\n`);
@@ -1843,6 +2100,15 @@ async function ensureOwnerReady(ag: AgenticID, ask: (q: string) => Promise<strin
1843
2100
  return true;
1844
2101
  }
1845
2102
 
2103
+ /**
2104
+ * Whether the deploy wizard offers `framework` only models with tool use: the
2105
+ * tool-driven frameworks, the harness under either of its names (`dsh` on a
2106
+ * network still on AgentDNA 1.3, see `isHarnessFramework`).
2107
+ */
2108
+ export function frameworkNeedsToolModels(framework: string): boolean {
2109
+ return framework === 'openclaw' || framework === 'prime-agent' || isHarnessFramework(framework);
2110
+ }
2111
+
1846
2112
  async function deployWizard(ag: AgenticID, attestorUrl: string, ask: (q: string) => Promise<string>, ctx: CommandContext, irq: Interrupt): Promise<Session | null> {
1847
2113
  const cfg = (await fetch(`${attestorUrl}/config`, { signal: AbortSignal.timeout(10_000) })
1848
2114
  .then((r) => r.json())
@@ -1866,10 +2132,9 @@ async function deployWizard(ag: AgenticID, attestorUrl: string, ask: (q: string)
1866
2132
  const provider = await pickInferenceProvider(ask, loadConfig().inferenceProvider ?? '0g-compute');
1867
2133
  const definition = knownProviders.find((entry) => entry.id === provider)!;
1868
2134
  await ag.agent.assertProviderSupported(provider, { framework });
1869
- const NEEDS_TOOLS = new Set(['openclaw', 'dsh', 'prime-agent']);
1870
2135
  const caps = await ag.agent.listModelCaps({ provider });
1871
2136
  const models = caps.filter((model) => model.chat)
1872
- .filter((model) => !NEEDS_TOOLS.has(framework) || model.tools)
2137
+ .filter((model) => !frameworkNeedsToolModels(framework) || model.tools)
1873
2138
  .filter((model) => framework !== 'hermes' || definition.native || model.formats.includes('openai') || (!model.formats.length && !model.id.startsWith('claude')))
1874
2139
  .map((model) => model.id);
1875
2140
  let model: string;
@@ -2013,7 +2278,7 @@ async function pickFramework(attestorUrl: string, ask: (q: string) => Promise<st
2013
2278
  // ── L2: session REPL ─────────────────────────────────────────────────────────
2014
2279
 
2015
2280
  const L2_HELP =
2016
- 'chat, or: /hello /balance /topup /stop /start /reset /settings /think /clear /compact /tasks /result /cancel /agentlog /startuplog /back /quit — Esc interrupts a turn (help: /help)';
2281
+ 'chat, or: /hello /balance /topup /stop /start /reset /settings /think /clear /compact /tasks /result /cancel /inbox /schedules /agentlog /startuplog /back /quit — Esc interrupts a turn (help: /help)';
2017
2282
 
2018
2283
  const L2_HELP_FULL = `session commands
2019
2284
  <anything else> chat with the agent — Esc or Ctrl-C interrupts the
@@ -2044,24 +2309,40 @@ const L2_HELP_FULL = `session commands
2044
2309
  is untouched; that is the difference from /reset
2045
2310
  /compact compact the agent's conversation in place — older
2046
2311
  history becomes a summary, the newest part stays
2047
- as it is (openclaw ~20K tokens, dsh its newest
2048
- item), and the conversation goes on (unlike
2312
+ as it is (openclaw ~20K tokens, 0g-harness its
2313
+ newest item), and the conversation goes on (unlike
2049
2314
  /clear). One or more model calls; can take
2050
- minutes. dsh, and openclaw 2026.7.1 or later
2051
- /tasks this session's long tasks with live status — on
2052
- agents with the responses transport a chat turn
2053
- survives dropped connections and keeps running
2315
+ minutes. 0g-harness, and openclaw 2026.7.1 or later
2316
+ /tasks on 0g-harness: everything that runs or ran on the
2317
+ agent — your turns, the turns it opened itself,
2318
+ background commands and subagents — with who did
2319
+ each (BY) and who asked (FOR). Elsewhere: this
2320
+ session's long tasks with live status — on agents
2321
+ with the responses transport a chat turn survives
2322
+ dropped connections and keeps running
2054
2323
  /result [id] re-attach to a task (default: latest): prints a
2055
- finished one, follows a running one live
2056
- /cancel [id] stop tasks — the brake for orphaned turns: Esc only
2057
- cancels a turn THIS connection started (on dsh/prime
2058
- it interrupts the bridge-wide current turn), so after
2059
- a dropped stream /cancel is the way to stop what
2060
- survived. Bare form stops everything this session
2061
- knows to be in flight (newest first); with an id,
2062
- just that one — /result <id> adopts an id into the
2063
- session first. Session memory starts empty after a
2064
- CLI restart or /back + use
2324
+ finished one, follows a running one live; on
2325
+ 0g-harness also a subagent's answer or a command's
2326
+ status
2327
+ /cancel [id|all] stop tasks — the brake for orphaned turns: Esc only
2328
+ cancels a turn THIS connection started (on
2329
+ 0g-harness and prime it interrupts the agent-wide
2330
+ current turn), so after a dropped stream /cancel
2331
+ is the way to stop what survived. Bare form stops
2332
+ everything this session knows to be in flight
2333
+ (newest first); with an id, just that one —
2334
+ /result <id> adopts an id into the session first.
2335
+ Session memory starts empty after a CLI restart or
2336
+ /back + use. On 0g-harness an id can be any task
2337
+ /tasks lists, and /cancel all stops everything
2338
+ running on the agent
2339
+ /inbox [all] what the agent said on its own (0g-harness): a
2340
+ background job finished, a reminder came due. It
2341
+ prints above the prompt as it arrives, and what
2342
+ came while you were away prints when you enter.
2343
+ Bare: unread messages; all: the read ones too
2344
+ /schedules the reminders the agent set for itself
2345
+ (0g-harness)
2065
2346
  /agentlog [n] agent process log, last n lines (owner-only)
2066
2347
  /startuplog [n] sealed runtime startup log, last n lines
2067
2348
  /back (or /unuse) return to the manager
@@ -2122,6 +2403,20 @@ async function sessionRepl(s: Session, ask: (q: string) => Promise<string>, irq:
2122
2403
  };
2123
2404
 
2124
2405
  irq.brake = makeBrake(() => s.client, out, displacedSeat, () => seatPromptPending);
2406
+ // What the agent says on its own (a background job finished, a reminder
2407
+ // came due) arrives at any time. At the session prompt it prints above the
2408
+ // prompt; during a command, a chat turn or any other question it waits for
2409
+ // the next session prompt, so it never lands inside a reply.
2410
+ let atPrompt = false;
2411
+ const held: Array<{ text: string; shown: () => void }> = [];
2412
+ const inbox = makeInboxFeed((text, shown) => {
2413
+ if (atPrompt) {
2414
+ printAbovePrompt(text);
2415
+ shown();
2416
+ } else {
2417
+ held.push({ text, shown });
2418
+ }
2419
+ });
2125
2420
  // A friendly message that hides WHICH failure happened costs a whole
2126
2421
  // debugging round trip: "no headers ever arrived" and "the stream was cut
2127
2422
  // mid-way" have different causes and used to print identically. Append the
@@ -2142,7 +2437,18 @@ async function sessionRepl(s: Session, ask: (q: string) => Promise<string>, irq:
2142
2437
  // connecting the moment it reaches running). Once connected, skip: no
2143
2438
  // per-chat-line attestor round-trip; bare Enter stays the manual refresh.
2144
2439
  if (!s.client) { try { await refreshSession(s, true); } catch { /* prompt anyway */ } }
2145
- const line = (await ask(`\nagent ${s.agentId} › `)).trim();
2440
+ inbox.follow(s.client);
2441
+ for (const h of held.splice(0)) {
2442
+ out(h.text);
2443
+ h.shown();
2444
+ }
2445
+ atPrompt = true;
2446
+ let line: string;
2447
+ try {
2448
+ line = (await ask(`\nagent ${s.agentId} › `)).trim();
2449
+ } finally {
2450
+ atPrompt = false;
2451
+ }
2146
2452
  if (!line) {
2147
2453
  // Bare Enter = live status refresh (phase moves on its own during
2148
2454
  // deploying/provisioning; the entry card only showed the initial one).
@@ -2221,8 +2527,10 @@ async function sessionRepl(s: Session, ask: (q: string) => Promise<string>, irq:
2221
2527
  if (s.phase === 'running') { out('already running\n'); continue; }
2222
2528
  if (s.phase !== 'stopped' || !s.sandboxId) { out(`agent is ${s.phase} — a plain start cannot revive it; use /reset\n`); continue; }
2223
2529
  if (!(await ensureOwnerReady(s.ag, ask))) { out('start cancelled — prepaid balance too low\n'); continue; }
2224
- out('starting… (Esc cancels the wait)\n'); await s.ag.agent.start(s.sealId, s.sandboxId);
2225
- const r = await waitRunningInterruptible(irq, s.attestorUrl, s.sealId, s.agentId);
2530
+ out('starting… (Esc cancels the wait)\n');
2531
+ const baseline = await lifecycleBaseline(s.attestorUrl, s.sealId);
2532
+ await s.ag.agent.start(s.sealId, s.sandboxId);
2533
+ const r = await waitRunningInterruptible(irq, s.attestorUrl, s.sealId, s.agentId, baseline);
2226
2534
  if (!r) continue;
2227
2535
  await connectSession(s, r.url);
2228
2536
  out(`running at ${s.url}\n`); continue;
@@ -2237,13 +2545,16 @@ async function sessionRepl(s: Session, ask: (q: string) => Promise<string>, irq:
2237
2545
  } else {
2238
2546
  s.framework = await pickFramework(s.attestorUrl, ask, s.framework);
2239
2547
  }
2240
- const provider = await agentInferenceProvider(s.ag, s.sealId);
2548
+ const plan = await resetInferencePlan(s.ag, s.sealId, await readDeploymentFacts(s.attestorUrl, s.sealId));
2549
+ const provider = plan.provider;
2241
2550
  await s.ag.agent.assertProviderSupported(provider, { sealId: s.sealId, framework: s.framework });
2242
2551
  const apiKey = await inferenceKey(ctx, ask, provider);
2243
2552
  if (!(await ensureOwnerReady(s.ag, ask))) { out('reset cancelled — prepaid balance too low\n'); continue; }
2553
+ await applyResetInference(s.ag, s.sealId, plan, out);
2244
2554
  out(`resetting as ${s.framework}… (Esc cancels the wait)\n`);
2555
+ const baseline = await lifecycleBaseline(s.attestorUrl, s.sealId);
2245
2556
  await s.ag.agent.reset(s.sealId, { provider, framework: s.framework, apiKey });
2246
- const r = await waitRunningInterruptible(irq, s.attestorUrl, s.sealId, s.agentId);
2557
+ const r = await waitRunningInterruptible(irq, s.attestorUrl, s.sealId, s.agentId, baseline);
2247
2558
  if (!r) continue;
2248
2559
  await connectSession(s, r.url);
2249
2560
  messages.length = 0; out(`back up at ${s.url}\n`); continue;
@@ -2329,7 +2640,7 @@ async function sessionRepl(s: Session, ask: (q: string) => Promise<string>, irq:
2329
2640
  // with, and how hard. Bare shows it; key=value writes it (merged).
2330
2641
  // Owner-signed in both directions, so it needs the wallet client and
2331
2642
  // not the session's (possibly keyless) one.
2332
- await settingsOp(await withWallet(ctx), s.sealId, tokenize(line).slice(1), s.client && s.url ? s.url : undefined);
2643
+ await settingsOp(await withWallet(ctx), s.sealId, tokenize(line).slice(1), s.client && s.url ? s.url : undefined, s.framework);
2333
2644
  continue;
2334
2645
  }
2335
2646
  if (line === '/think' || line.startsWith('/think ')) {
@@ -2360,6 +2671,16 @@ async function sessionRepl(s: Session, ask: (q: string) => Promise<string>, irq:
2360
2671
  continue;
2361
2672
  }
2362
2673
  if (line === '/tasks') {
2674
+ // An agent with its own task list (0g-harness) answers for everything that
2675
+ // runs on it: every turn, yours and the ones it opened itself, and
2676
+ // every background command and subagent, with who did each.
2677
+ if (s.client?.tasks) {
2678
+ const list = await s.client.tasks({ limit: 30 });
2679
+ if (!list.length) { out('nothing has run on this agent yet\n'); continue; }
2680
+ for (const l of renderTaskTable(list, Date.now())) out(`${l}\n`);
2681
+ out('/result <id> shows one · /cancel <id> stops one · /cancel all stops everything running\n');
2682
+ continue;
2683
+ }
2363
2684
  // Long-task surface (responses transport). The list is this session's
2364
2685
  // memory of submitted ids; status is fetched live from the agent.
2365
2686
  if (!s.client?.task) { out('(this agent has no task surface — chat turns are connection-bound here)\n'); continue; }
@@ -2384,8 +2705,21 @@ async function sessionRepl(s: Session, ask: (q: string) => Promise<string>, irq:
2384
2705
  continue;
2385
2706
  }
2386
2707
  if (line === '/result' || line.startsWith('/result ')) {
2708
+ // A background command or a subagent is not a turn: its record is
2709
+ // the task list's, and it has no stream to follow.
2710
+ const named = line.split(/\s+/)[1];
2711
+ if (named && s.client?.taskInfo) {
2712
+ const t = await s.client.taskInfo(named).catch(() => null);
2713
+ if (t && t.type !== 'turn') {
2714
+ out(`${cleanCell(t.id)} — ${t.status} · by ${t.actor} · ${cleanCell(t.label)}\n`);
2715
+ if (t.output_text) out(`${t.output_text}\n`);
2716
+ else if (t.type === 'command') out('(a command\'s output goes to the agent, which reports on it when the command finishes — /inbox)\n');
2717
+ if (t.error) out(`error: ${cleanCell(t.error)}\n`);
2718
+ continue;
2719
+ }
2720
+ }
2387
2721
  if (!s.client?.task || !s.client.followTask) { out('(this agent has no task surface)\n'); continue; }
2388
- const id = line.split(/\s+/)[1] ?? s.tasks?.[s.tasks.length - 1]?.id;
2722
+ const id = named ?? s.tasks?.[s.tasks.length - 1]?.id;
2389
2723
  if (!id) { out('no task to show — /result <id>, or start one by chatting\n'); continue; }
2390
2724
  // Adopt an explicitly-named id into this session's task memory: the
2391
2725
  // id may come from another window, a /tasks listing before a restart,
@@ -2434,6 +2768,27 @@ async function sessionRepl(s: Session, ask: (q: string) => Promise<string>, irq:
2434
2768
  // survival is the feature). /cancel is the explicit brake: by id, or
2435
2769
  // everything in flight this session knows.
2436
2770
  let id = line.split(/\s+/)[1];
2771
+ // An agent with its own task list (0g-harness) stops any of its tasks by id
2772
+ // (a turn, a background command, a subagent), and all of them at once.
2773
+ if (id && s.client.stopTask && s.client.stopAllTasks) {
2774
+ for (;;) {
2775
+ try {
2776
+ const stopped = id === 'all' ? await s.client.stopAllTasks() : [await s.client.stopTask(id)];
2777
+ if (!stopped.length) out('nothing running\n');
2778
+ for (const x of stopped) out(`⏹ ${cleanCell(x.id)} — ${STOP_OUTCOME[x.outcome] ?? x.outcome}\n`);
2779
+ break;
2780
+ } catch (e) {
2781
+ const d = await routeTaskFailure(out, displacedSeat, e, `(cancel failed: ${(e as Error).message})\n`, `retry /cancel ${id}`);
2782
+ if (d === 'reclaimed') continue; // seat is back — retry
2783
+ break;
2784
+ }
2785
+ }
2786
+ continue;
2787
+ }
2788
+ if (id === 'all') {
2789
+ out('(this agent has no task list: bare /cancel stops what this session started, /stop stops the whole container)\n');
2790
+ continue;
2791
+ }
2437
2792
  if (!id && s.client?.task) {
2438
2793
  if (!s.tasks?.length) { out('no task id given and none started from this session — /cancel <id>, or /tasks to list (after a CLI restart or /back+use, this session starts empty)\n'); continue; }
2439
2794
  // Fetch live statuses; a fetch FAILURE is not "not in flight" —
@@ -2461,8 +2816,8 @@ async function sessionRepl(s: Session, ask: (q: string) => Promise<string>, irq:
2461
2816
  continue;
2462
2817
  }
2463
2818
  // A brake stops everything in flight, newest first — stopping only
2464
- // the newest would leave an older running turn alive (dsh/prime
2465
- // serialize turns, so a queued one is waiting on the running one).
2819
+ // the newest would leave an older running turn alive (0g-harness and
2820
+ // prime serialize turns, so a queued one is waiting on the running one).
2466
2821
  const inFlight = inFlightIds(rows);
2467
2822
  if (!inFlight.length) { out('nothing in flight from this session — /tasks to list; a finished task cannot be cancelled\n'); continue; }
2468
2823
  if (s.client?.cancelTask) {
@@ -2505,7 +2860,7 @@ async function sessionRepl(s: Session, ask: (q: string) => Promise<string>, irq:
2505
2860
  if (id && !s.client?.cancelTask) {
2506
2861
  // An id was asked for but this image has no task-level cancel: do
2507
2862
  // NOT silently interrupt "whatever is running" instead — but on
2508
- // dsh/prime the bridge-wide interrupt DOES stop the running turn,
2863
+ // 0g-harness and prime the agent-wide interrupt DOES stop the running turn,
2509
2864
  // so point there instead of claiming nothing can be done.
2510
2865
  out(s.client?.interrupt
2511
2866
  ? '(this agent image has no per-task cancel — the bridge interrupt stops the current running turn; try /cancel with no id)\n'
@@ -2523,6 +2878,27 @@ async function sessionRepl(s: Session, ask: (q: string) => Promise<string>, irq:
2523
2878
  if (r) out(r.aborted ? '⏹ stopped the running turn\n' : `(nothing to stop, or: ${r.note ?? 'not supported'})\n`);
2524
2879
  continue;
2525
2880
  }
2881
+ if (line === '/inbox' || line === '/inbox all') {
2882
+ if (!s.client) { out(`agent is ${s.phase} — /start or /reset first\n`); continue; }
2883
+ if (!s.client.inbox) { out('(no inbox on this agent: its framework does not run work in the background)\n'); continue; }
2884
+ const all = line === '/inbox all';
2885
+ const page = await s.client.inbox(all ? { after: 0 } : {});
2886
+ if (!page.data.length) { out(all ? 'the inbox is empty\n' : 'no new messages — /inbox all shows the ones already read\n'); continue; }
2887
+ out(page.data.map(renderInboxMessage).join('\n'));
2888
+ const through = Math.max(...page.data.map((m) => m.seq));
2889
+ if (through > page.read_through) await s.client.ackInbox?.(through).catch(() => undefined);
2890
+ continue;
2891
+ }
2892
+ if (line === '/schedules') {
2893
+ if (!s.client) { out(`agent is ${s.phase} — /start or /reset first\n`); continue; }
2894
+ if (!s.client.schedules) { out('(no reminders on this agent: its framework does not support them)\n'); continue; }
2895
+ const r = await s.client.schedules();
2896
+ if (!r.enabled) { out('reminders are off on this agent (the "schedule" switch in /settings others)\n'); continue; }
2897
+ if (!r.data.length) { out('no reminders set — the agent sets one when you ask it to remind you of something\n'); continue; }
2898
+ for (const l of renderSchedules(r.data, Date.now())) out(`${l}\n`);
2899
+ out('to remove one, ask the agent to\n');
2900
+ continue;
2901
+ }
2526
2902
  if (line.startsWith('/')) { out(`unknown command ${line}\n${L2_HELP}\n`); continue; }
2527
2903
  } catch (e) {
2528
2904
  // Show the remedy too: an error whose whole point is "do this instead"
@@ -2536,7 +2912,7 @@ async function sessionRepl(s: Session, ask: (q: string) => Promise<string>, irq:
2536
2912
  if (!s.client.chatStream) { out('(chat unavailable on this agent)\n'); continue; }
2537
2913
  messages.push({ role: 'user', content: line });
2538
2914
  // `model` is a per-framework selector some gateways require (openclaw
2539
- // does; the dsh/prime bridges ignore it). Send it when known, omit it
2915
+ // does; 0g-harness and the prime bridge ignore it). Send it when known, omit it
2540
2916
  // otherwise — and only if the framework rejects that, ask once and retry.
2541
2917
  let retriedWithPick = false;
2542
2918
  for (;;) {
@@ -2576,7 +2952,7 @@ async function sessionRepl(s: Session, ask: (q: string) => Promise<string>, irq:
2576
2952
  const onActivity = process.stdout.isTTY
2577
2953
  ? (label: string): void => {
2578
2954
  // "did work this turn" detector, across bridges' label dialects:
2579
- // dsh "tool/call bash", prime "tool_execution_start — bash" /
2955
+ // 0g-harness "tool/call bash", prime "tool_execution_start — bash" /
2580
2956
  // "bash_command_start", hermes "tool/call web_search". Thinking
2581
2957
  // alone doesn't count — a think-only turn with no output is still
2582
2958
  // a failure worth reporting.
@@ -2681,7 +3057,7 @@ async function sessionRepl(s: Session, ask: (q: string) => Promise<string>, irq:
2681
3057
  continue; // retry the same user message once with the selector
2682
3058
  }
2683
3059
  // A turn that ran tools but produced no text is WORK, not failure —
2684
- // dsh agents legitimately end tool-only turns silently. Say what
3060
+ // 0g-harness agents legitimately end tool-only turns silently. Say what
2685
3061
  // happened instead of crying wolf (the true-failure path — no deltas,
2686
3062
  // no activity — still reports as an error).
2687
3063
  // Displaced by another window (occupancy.go): WeChat semantics — this
@@ -2711,5 +3087,6 @@ async function sessionRepl(s: Session, ask: (q: string) => Promise<string>, irq:
2711
3087
  }
2712
3088
  } finally {
2713
3089
  irq.brake = null; // leaving the session: idle-Esc no longer targets this agent
3090
+ inbox.stop();
2714
3091
  }
2715
3092
  }