@0gfoundation/0g-agentdna 0.2.1 → 0.2.3

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 (86) hide show
  1. package/GUIDE.md +67 -18
  2. package/MIGRATION.md +8 -0
  3. package/MIGRATION.zh.md +5 -0
  4. package/PROVIDERS.md +6 -4
  5. package/PROVIDERS.zh.md +4 -3
  6. package/README.md +20 -4
  7. package/dist/AgentClient.d.ts +175 -2
  8. package/dist/AgentClient.d.ts.map +1 -1
  9. package/dist/AgentClient.js +166 -7
  10. package/dist/AgentClient.js.map +1 -1
  11. package/dist/AgenticID.d.ts +47 -7
  12. package/dist/AgenticID.d.ts.map +1 -1
  13. package/dist/AgenticID.js +44 -13
  14. package/dist/AgenticID.js.map +1 -1
  15. package/dist/AgenticIDClient.d.ts +1 -1
  16. package/dist/AgenticIDClient.js +1 -1
  17. package/dist/AttestorClient.d.ts +67 -2
  18. package/dist/AttestorClient.d.ts.map +1 -1
  19. package/dist/AttestorClient.js +162 -33
  20. package/dist/AttestorClient.js.map +1 -1
  21. package/dist/ReputationClient.d.ts +1 -1
  22. package/dist/ReputationClient.js +1 -1
  23. package/dist/SandboxClient.d.ts +1 -1
  24. package/dist/SandboxClient.js +1 -1
  25. package/dist/cli/commands/doctor.d.ts.map +1 -1
  26. package/dist/cli/commands/doctor.js +8 -2
  27. package/dist/cli/commands/doctor.js.map +1 -1
  28. package/dist/cli/commands/interactive.d.ts +71 -2
  29. package/dist/cli/commands/interactive.d.ts.map +1 -1
  30. package/dist/cli/commands/interactive.js +423 -46
  31. package/dist/cli/commands/interactive.js.map +1 -1
  32. package/dist/cli/commands/settings.d.ts.map +1 -1
  33. package/dist/cli/commands/settings.js +23 -0
  34. package/dist/cli/commands/settings.js.map +1 -1
  35. package/dist/cli/config.d.ts +10 -0
  36. package/dist/cli/config.d.ts.map +1 -1
  37. package/dist/cli/config.js +38 -0
  38. package/dist/cli/config.js.map +1 -1
  39. package/dist/cli/env.js +1 -1
  40. package/dist/cli/env.js.map +1 -1
  41. package/dist/cli/inference.d.ts +25 -0
  42. package/dist/cli/inference.d.ts.map +1 -1
  43. package/dist/cli/inference.js +67 -6
  44. package/dist/cli/inference.js.map +1 -1
  45. package/dist/cli/main.js +12 -2
  46. package/dist/cli/main.js.map +1 -1
  47. package/dist/cli/sdk.d.ts +1 -1
  48. package/dist/cli/sdk.js +1 -1
  49. package/dist/cli/settings.d.ts +20 -0
  50. package/dist/cli/settings.d.ts.map +1 -1
  51. package/dist/cli/settings.js +40 -1
  52. package/dist/cli/settings.js.map +1 -1
  53. package/dist/constants.d.ts +3 -3
  54. package/dist/constants.js +2 -2
  55. package/dist/context.d.ts +2 -2
  56. package/dist/context.d.ts.map +1 -1
  57. package/dist/context.js +1 -1
  58. package/dist/index.d.ts +4 -3
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +6 -2
  61. package/dist/index.js.map +1 -1
  62. package/dist/secretEnv.js +1 -1
  63. package/dist/secretEnv.js.map +1 -1
  64. package/dist/types.d.ts +1 -1
  65. package/dist/types.js +1 -1
  66. package/package.json +1 -1
  67. package/src/AgentClient.ts +326 -9
  68. package/src/AgenticID.ts +66 -11
  69. package/src/AgenticIDClient.ts +1 -1
  70. package/src/AttestorClient.ts +207 -51
  71. package/src/ReputationClient.ts +1 -1
  72. package/src/SandboxClient.ts +1 -1
  73. package/src/cli/commands/doctor.ts +8 -2
  74. package/src/cli/commands/interactive.ts +405 -51
  75. package/src/cli/commands/settings.ts +22 -1
  76. package/src/cli/config.ts +36 -0
  77. package/src/cli/env.ts +1 -1
  78. package/src/cli/inference.ts +82 -5
  79. package/src/cli/main.ts +13 -3
  80. package/src/cli/sdk.ts +1 -1
  81. package/src/cli/settings.ts +41 -0
  82. package/src/constants.ts +3 -3
  83. package/src/context.ts +2 -2
  84. package/src/index.ts +7 -3
  85. package/src/secretEnv.ts +1 -1
  86. package/src/types.ts +1 -1
@@ -54,11 +54,19 @@ exports.makeBrake = makeBrake;
54
54
  exports.brakeInterruptLine = brakeInterruptLine;
55
55
  exports.routeTaskFailure = routeTaskFailure;
56
56
  exports.inFlightIds = inFlightIds;
57
+ exports.renderTaskTable = renderTaskTable;
58
+ exports.renderInboxMessage = renderInboxMessage;
59
+ exports.renderSchedules = renderSchedules;
60
+ exports.makeInboxFeed = makeInboxFeed;
57
61
  exports.completeTail = completeTail;
58
62
  exports.completeLine = completeLine;
63
+ exports.printAbovePrompt = printAbovePrompt;
59
64
  exports.renderListHeader = renderListHeader;
60
65
  exports.renderListRow = renderListRow;
66
+ exports.lifecycleBaseline = lifecycleBaseline;
67
+ exports.pollRunning = pollRunning;
61
68
  exports.run = run;
69
+ exports.frameworkNeedsToolModels = frameworkNeedsToolModels;
62
70
  const readline = __importStar(require("node:readline"));
63
71
  const node_fs_1 = require("node:fs");
64
72
  const node_path_1 = require("node:path");
@@ -80,7 +88,7 @@ const inference_1 = require("../inference");
80
88
  // Tab-completion candidates for the active REPL level (canonical names only —
81
89
  // aliases like link//unuse still work typed out but don't clutter the list).
82
90
  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'];
83
- const L2_WORDS = ['/hello', '/balance', '/topup', '/start', '/stop', '/reset', '/settings', '/think', '/clear', '/compact', '/tasks', '/result', '/cancel', '/agentlog', '/startuplog', '/back', '/help', '/quit'];
91
+ const L2_WORDS = ['/hello', '/balance', '/topup', '/start', '/stop', '/reset', '/settings', '/think', '/clear', '/compact', '/tasks', '/result', '/cancel', '/inbox', '/schedules', '/agentlog', '/startuplog', '/back', '/help', '/quit'];
84
92
  let activeCompletions = L1_WORDS;
85
93
  // First-argument completion per command (Tab after the command word).
86
94
  // Static lists inline; AGENT resolves to the ids seen in the latest
@@ -275,8 +283,9 @@ async function routeTaskFailure(print, seat, e, rawLine, seatHint) {
275
283
  }
276
284
  /**
277
285
  * The tasks bare `/cancel` stops: everything still in flight, NEWEST FIRST
278
- * (stopping only the newest would leave an older running turn alive; dsh/
279
- * prime serialize turns, so a queued one is waiting on the running one).
286
+ * (stopping only the newest would leave an older running turn alive;
287
+ * 0g-harness and prime serialize turns, so a queued one is waiting on the
288
+ * running one).
280
289
  * Statuses arrive live from the agent; "unknown" (evicted or agent
281
290
  * restarted, 404) counts as not in flight — cancelling an unknown record
282
291
  * would claim to stop something nobody can see. Exported for the tests:
@@ -290,6 +299,151 @@ function inFlightIds(rows) {
290
299
  }
291
300
  return out;
292
301
  }
302
+ /** A span of seconds, short: 12s, 4m, 3h, 2d. */
303
+ function span(seconds) {
304
+ const s = Math.max(0, Math.round(seconds));
305
+ if (s < 60)
306
+ return `${s}s`;
307
+ if (s < 3600)
308
+ return `${Math.floor(s / 60)}m`;
309
+ if (s < 86400)
310
+ return `${Math.floor(s / 3600)}h`;
311
+ return `${Math.floor(s / 86400)}d`;
312
+ }
313
+ /** Who asked for a task, as /tasks shows it. */
314
+ const ASKED_BY = { user: 'you', job: 'job', schedule: 'reminder', plugin: 'plugin', agent: 'agent' };
315
+ /**
316
+ * The /tasks table over the agent's own task list: BY is who does the work
317
+ * (the main agent or a subagent), FOR is who asked (you, a finished job, a
318
+ * reminder, the agent itself). Ids print whole: they are what /result and
319
+ * /cancel take. Exported for the tests.
320
+ */
321
+ function renderTaskTable(tasks, nowMs) {
322
+ const idw = Math.max(2, ...tasks.map((t) => (0, cells_1.cleanCell)(t.id).length)) + 2;
323
+ const head = ` ${'ID'.padEnd(idw)}${'STATUS'.padEnd(13)}${'BY'.padEnd(10)}${'FOR'.padEnd(10)}${'AGE'.padEnd(6)}WHAT`;
324
+ return [
325
+ head,
326
+ ...tasks.map((t) => ` ${(0, cells_1.cleanCell)(t.id).padEnd(idw)}${(0, cells_1.cellText)(t.status, 13)}${(0, cells_1.cellText)(t.actor, 10)}` +
327
+ `${(0, cells_1.cellText)(ASKED_BY[t.trigger] ?? t.trigger, 10)}${span(nowMs / 1000 - t.created_at).padEnd(6)}` +
328
+ `${[...(0, cells_1.cleanCell)(t.label)].slice(0, 70).join('')}`),
329
+ ];
330
+ }
331
+ /**
332
+ * One inbox message as the session prints it: why the agent spoke up, then
333
+ * what it said. Exported for the tests.
334
+ */
335
+ function renderInboxMessage(m) {
336
+ const label = (0, cells_1.cleanCell)(m.label);
337
+ const why = m.trigger === 'job' ? `job finished · ${label}`
338
+ : m.trigger === 'schedule' ? `reminder · ${label}`
339
+ : label || (0, cells_1.cleanCell)(m.trigger);
340
+ const lines = [`◆ agent · ${why}`];
341
+ if (m.text?.trim())
342
+ lines.push(m.text.replace(/\s+$/, ''));
343
+ if (m.status === 'failed')
344
+ lines.push(`(that turn failed: ${(0, cells_1.cleanCell)(m.error ?? 'no reason given')})`);
345
+ else if (m.status === 'cancelled')
346
+ lines.push('(that turn was cancelled)');
347
+ return `${lines.join('\n')}\n`;
348
+ }
349
+ /** The /schedules lines: id, how often, when next, the reminder's text.
350
+ * Exported for the tests. */
351
+ function renderSchedules(list, nowMs) {
352
+ const idw = Math.max(2, ...list.map((r) => (0, cells_1.cleanCell)(r.id).length)) + 2;
353
+ return list.map((r) => {
354
+ const how = r.kind === 'every' && r.everySeconds ? `every ${span(r.everySeconds)}` : 'once';
355
+ const due = r.state === 'overdue' ? 'due now' : `in ${span((Date.parse(r.scheduledAt) - nowMs) / 1000)}`;
356
+ return ` ${(0, cells_1.cleanCell)(r.id).padEnd(idw)}${how.padEnd(12)}${due.padEnd(12)}${(0, cells_1.cleanCell)(r.prompt)}`;
357
+ });
358
+ }
359
+ /** What stopping a task did, in words. */
360
+ const STOP_OUTCOME = {
361
+ cancelled: 'stopped',
362
+ 'already-finished': 'already finished',
363
+ 'not-running': 'not running',
364
+ };
365
+ /**
366
+ * Follows one agent's inbox for a session: first the messages that came in
367
+ * while nobody was looking, then each new one as the agent's live feed
368
+ * announces it. `show` prints a rendered message, now or at the next prompt,
369
+ * and calls `shown` once it is on screen; the message is acked then, so
370
+ * another window does not show it again. A message is shown once per feed.
371
+ * `follow` is called with the session's current client before every prompt
372
+ * and restarts the feed when the client changed (/start, /reset); an agent
373
+ * without an inbox gets no feed. Exported for the tests.
374
+ */
375
+ function makeInboxFeed(show) {
376
+ let current;
377
+ let ac = null;
378
+ async function run(client, signal) {
379
+ const seen = new Set();
380
+ let acked = 0;
381
+ const present = (msgs, away) => {
382
+ const fresh = msgs.filter((m) => !seen.has(m.seq));
383
+ if (!fresh.length || signal.aborted)
384
+ return;
385
+ for (const m of fresh)
386
+ seen.add(m.seq);
387
+ const through = Math.max(...fresh.map((m) => m.seq));
388
+ const text = (away ? `\nwhile you were away (${fresh.length}):\n` : '\n') + fresh.map(renderInboxMessage).join('\n');
389
+ show(text, () => {
390
+ if (through <= acked)
391
+ return;
392
+ acked = through;
393
+ // Best-effort: a window that lost the seat cannot ack (409), and the
394
+ // owner's next window shows the message again.
395
+ client.ackInbox?.(through).catch(() => undefined);
396
+ });
397
+ };
398
+ const readUnread = async (away) => {
399
+ const page = await client.inbox();
400
+ present(page.data, away);
401
+ return page.cursor;
402
+ };
403
+ let cursor;
404
+ try {
405
+ cursor = await readUnread(true);
406
+ }
407
+ catch {
408
+ // The feed still runs; its first event, or a reset, catches up.
409
+ }
410
+ if (signal.aborted || !client.events)
411
+ return;
412
+ try {
413
+ for await (const e of client.events({ after: cursor, signal })) {
414
+ // An inbox message's seq is its event's.
415
+ if (e.type === 'inbox.message')
416
+ present([{ ...e.data, seq: e.seq }], false);
417
+ // The agent could not serve our position: what we may have missed
418
+ // is in the inbox itself.
419
+ else if (e.type === 'reset')
420
+ await readUnread(false).catch(() => undefined);
421
+ }
422
+ }
423
+ catch {
424
+ // A 4xx: this agent no longer serves the feed. Nothing to say at the
425
+ // prompt about it; /inbox still reads the inbox.
426
+ }
427
+ }
428
+ const stop = () => {
429
+ ac?.abort();
430
+ ac = null;
431
+ current = undefined;
432
+ };
433
+ return {
434
+ follow(client) {
435
+ if (client === current)
436
+ return;
437
+ stop();
438
+ if (!client?.inbox)
439
+ return;
440
+ current = client;
441
+ ac = new AbortController();
442
+ void run(client, ac.signal);
443
+ },
444
+ stop,
445
+ };
446
+ }
293
447
  let knownAgentIds = [];
294
448
  const rememberAgentIds = (rows) => {
295
449
  const ids = rows.map((r) => String(r.agentId ?? '')).filter((x) => x && x !== 'undefined');
@@ -329,6 +483,8 @@ const L1_ARGS = {
329
483
  const L2_ARGS = {
330
484
  '/think': ['low', 'high', 'max'],
331
485
  '/reset': ['pick'],
486
+ '/cancel': ['all'],
487
+ '/inbox': ['all'],
332
488
  '/settings': ['provider=', 'model=', 'thinking=', 'others='],
333
489
  };
334
490
  let activeArgs = L1_ARGS;
@@ -394,6 +550,29 @@ function completeLine(line, state) {
394
550
  // The live readline interface — askSecret scrubs submitted secrets out of
395
551
  // its history (display masking alone leaves the plaintext one ↑ away).
396
552
  let activeRl = null;
553
+ /**
554
+ * Print a block above the live prompt, keeping what the user has typed. The
555
+ * prompt and its input are erased from their first row down, the block is
556
+ * written, and readline redraws the prompt below it. Its redraw first moves
557
+ * up as many rows as the cursor sat below the prompt's first row (the
558
+ * prompt's own leading newline counts), so that many blank rows are left for
559
+ * it to land on. Without a terminal there is no prompt to keep: the block is
560
+ * just written. `rl`/`output` are the session's; exported for the tests,
561
+ * which pass a readline over a captured stream.
562
+ */
563
+ function printAbovePrompt(text, rl = activeRl, output = process.stdout) {
564
+ if (!rl || !rl.terminal) {
565
+ output.write(text.startsWith('\n') ? text : `\n${text}`);
566
+ return;
567
+ }
568
+ const { rows } = rl.getCursorPos();
569
+ readline.moveCursor(output, 0, -rows);
570
+ readline.cursorTo(output, 0);
571
+ readline.clearScreenDown(output);
572
+ output.write(text.endsWith('\n') ? text : `${text}\n`);
573
+ output.write('\n'.repeat(rows));
574
+ rl.prompt(true);
575
+ }
397
576
  const cells_1 = require("./cells");
398
577
  /** Column widths of the REPL listing; its header and every row share them. */
399
578
  const LIST_COLS = { id: 6, phase: 11, framework: 12, seal: 13, agentSeal: 13, owner: 24 };
@@ -507,20 +686,47 @@ async function refreshSession(s, quiet = false) {
507
686
  if (reason)
508
687
  out(` last error: ${reason}\n`);
509
688
  }
689
+ /**
690
+ * Read the row a lifecycle request is about to change. The attestor answers
691
+ * `/reset` and `/start` with 202 before its worker touches the row, so the
692
+ * wait compares against this. undefined when the row cannot be read; the wait
693
+ * then takes the row as it finds it.
694
+ */
695
+ async function lifecycleBaseline(attestorUrl, sealId) {
696
+ try {
697
+ const d = (await (await fetch(`${attestorUrl}/deployment/${sealId}`, { signal: AbortSignal.timeout(10000) })).json());
698
+ const at = Date.parse(d.container_stage?.at ?? '');
699
+ return { at: Number.isFinite(at) ? at : undefined, state: d.container_stage?.state, sandboxId: d.sandbox_id };
700
+ }
701
+ catch {
702
+ return undefined;
703
+ }
704
+ }
510
705
  /**
511
706
  * Wait for a deployment to reach `running` by polling the attestor's public
512
707
  * /deployment/:sealId — and FAIL LOUD instead of hanging: a `failed`/`offline`
513
708
  * phase (or a failed container_stage) surfaces its recorded reason
514
709
  * immediately, and the timeout produces an error naming the last phase seen.
710
+ *
711
+ * With a `baseline` (the row read before a reset or start was sent), the row
712
+ * as it was then is not this request's outcome: until the worker moves the
713
+ * container on (a new start or create, a new sandbox, a stage written after
714
+ * the baseline), the wait shows `queued` and neither a still-running old
715
+ * container nor an earlier failure ends it.
515
716
  */
516
717
  class WaitCancelled extends Error {
517
718
  constructor() { super('wait cancelled'); }
518
719
  }
519
- async function pollRunning(attestorUrl, sealId, agentId, timeoutMs = 360000, signal) {
720
+ async function pollRunning(attestorUrl, sealId, agentId, timeoutMs = 360000, signal, opts = {}) {
721
+ const { baseline, intervalMs = 4000 } = opts;
520
722
  const deadline = Date.now() + timeoutMs;
521
723
  const t0 = Date.now();
522
724
  let lastPhase = 'contacting attestor';
523
725
  let lastShown = '';
726
+ // Whether the request has visibly started: a fresh `submitted` stage, a new
727
+ // sandbox, or a stage written after the baseline other than the old
728
+ // container's own running reports.
729
+ let progressed = !baseline;
524
730
  // Transient progress line between phase changes — a deploy sits minutes in
525
731
  // one phase with zero output otherwise. Repainted each second; phase-change
526
732
  // lines and the final result overwrite it. TTY only.
@@ -548,7 +754,14 @@ async function pollRunning(attestorUrl, sealId, agentId, timeoutMs = 360000, sig
548
754
  for (;;) {
549
755
  try {
550
756
  const d = (await (await fetch(`${attestorUrl}/deployment/${sealId}`)).json());
551
- lastPhase = d.phase ?? lastPhase;
757
+ if (!progressed && baseline) {
758
+ const at = Date.parse(d.container_stage?.at ?? '');
759
+ const fresh = Number.isFinite(at) && (baseline.at === undefined || at > baseline.at);
760
+ const state = d.container_stage?.state;
761
+ progressed = (fresh && !(state === 'confirmed' && baseline.state === 'confirmed'))
762
+ || (d.sandbox_id !== undefined && d.sandbox_id !== baseline.sandboxId);
763
+ }
764
+ lastPhase = progressed ? (d.phase ?? lastPhase) : 'queued';
552
765
  if (lastPhase !== lastShown) {
553
766
  clearSpinner();
554
767
  out(` … ${lastPhase}\n`);
@@ -556,10 +769,10 @@ async function pollRunning(attestorUrl, sealId, agentId, timeoutMs = 360000, sig
556
769
  }
557
770
  const cardBase = d.agent_card?.url?.replace(/\/hello$/, '');
558
771
  const url = d.url ?? cardBase ?? (d.sandbox_id && cfg.sandbox_proxy_addr ? containerUrl(d.sandbox_id, cfg.sandbox_proxy_addr) : undefined);
559
- if (d.phase === 'running' && url)
772
+ if (progressed && d.phase === 'running' && url)
560
773
  return { url };
561
774
  const reason = d.container_stage?.state === 'failed' ? d.container_stage?.reason : undefined;
562
- if (d.phase === 'failed' || reason) {
775
+ if (progressed && (d.phase === 'failed' || reason)) {
563
776
  throw new errors_1.CliError('UNKNOWN', `agent ${agentId} did not start: ${reason ?? `phase=${d.phase}`}`, {
564
777
  remedy: `run \`reset ${agentId}\` to recreate the container once the cause is fixed`,
565
778
  });
@@ -571,13 +784,18 @@ async function pollRunning(attestorUrl, sealId, agentId, timeoutMs = 360000, sig
571
784
  // transient fetch error — keep polling until the deadline
572
785
  }
573
786
  if (Date.now() > deadline) {
787
+ if (!progressed) {
788
+ throw new errors_1.CliError('UNKNOWN', `agent ${agentId} did not come online: the attestor had not started this request after ${Math.round(timeoutMs / 1000)}s`, {
789
+ remedy: 'a request that waits too long in the attestor\'s queue expires and leaves the agent as it was — run the command again',
790
+ });
791
+ }
574
792
  throw new errors_1.CliError('UNKNOWN', `timed out after ${Math.round(timeoutMs / 1000)}s waiting for agent ${agentId} (last phase: ${lastPhase})`, {
575
793
  remedy: 'check `status` — provisioning can lag; retry the command when the phase moves',
576
794
  });
577
795
  }
578
796
  if (signal?.aborted)
579
797
  throw new WaitCancelled();
580
- await new Promise((r) => setTimeout(r, 4000));
798
+ await new Promise((r) => setTimeout(r, intervalMs));
581
799
  if (signal?.aborted)
582
800
  throw new WaitCancelled();
583
801
  }
@@ -590,11 +808,11 @@ async function pollRunning(attestorUrl, sealId, agentId, timeoutMs = 360000, sig
590
808
  }
591
809
  /** pollRunning wired to the Esc/Ctrl-C interrupt: cancelling abandons the
592
810
  * WAIT only — the lifecycle operation keeps going server-side. */
593
- async function waitRunningInterruptible(irq, attestorUrl, sealId, agentId) {
811
+ async function waitRunningInterruptible(irq, attestorUrl, sealId, agentId, baseline) {
594
812
  const ac = new AbortController();
595
813
  irq.streaming = ac;
596
814
  try {
597
- return await pollRunning(attestorUrl, sealId, agentId, 360000, ac.signal);
815
+ return await pollRunning(attestorUrl, sealId, agentId, 360000, ac.signal, { baseline });
598
816
  }
599
817
  catch (e) {
600
818
  if (e instanceof WaitCancelled || ac.signal.aborted) {
@@ -1156,8 +1374,9 @@ async function managerRepl(ctx, ask, irq) {
1156
1374
  continue;
1157
1375
  }
1158
1376
  out(`starting agent ${row.agentId}… (Esc cancels the wait)\n`);
1377
+ const baseline = await lifecycleBaseline(attestorUrl, row.sealId);
1159
1378
  await ag.agent.start(row.sealId, row.sandboxId);
1160
- const r = await waitRunningInterruptible(irq, attestorUrl, row.sealId, row.agentId);
1379
+ const r = await waitRunningInterruptible(irq, attestorUrl, row.sealId, row.agentId, baseline);
1161
1380
  if (r)
1162
1381
  out(`running at ${r.url} — enter with: use ${row.agentId}\n`);
1163
1382
  continue;
@@ -1173,16 +1392,19 @@ async function managerRepl(ctx, ask, irq) {
1173
1392
  else {
1174
1393
  framework = await pickFramework(attestorUrl, ask, row.framework ?? undefined);
1175
1394
  }
1176
- const provider = await (0, inference_1.agentInferenceProvider)(ag, row.sealId);
1395
+ const plan = await (0, inference_1.resetInferencePlan)(ag, row.sealId, await (0, inference_1.readDeploymentFacts)(attestorUrl, row.sealId));
1396
+ const provider = plan.provider;
1177
1397
  await ag.agent.assertProviderSupported(provider, { sealId: row.sealId, framework });
1178
1398
  const apiKey = await inferenceKey(ctx, ask, provider);
1179
1399
  if (!(await ensureOwnerReady(ag, ask))) {
1180
1400
  out('reset cancelled — prepaid balance too low\n');
1181
1401
  continue;
1182
1402
  }
1403
+ await (0, inference_1.applyResetInference)(ag, row.sealId, plan, out);
1183
1404
  out(`resetting agent ${row.agentId} as ${framework}… (Esc cancels the wait)\n`);
1405
+ const baseline = await lifecycleBaseline(attestorUrl, row.sealId);
1184
1406
  await ag.agent.reset(row.sealId, { provider, framework, apiKey });
1185
- const r = await waitRunningInterruptible(irq, attestorUrl, row.sealId, row.agentId);
1407
+ const r = await waitRunningInterruptible(irq, attestorUrl, row.sealId, row.agentId, baseline);
1186
1408
  if (r)
1187
1409
  out(`running at ${r.url} — enter with: use ${row.agentId}\n`);
1188
1410
  continue;
@@ -1232,7 +1454,7 @@ async function managerRepl(ctx, ask, irq) {
1232
1454
  out(`no agent matching ${args[0]} on this attestor\n`);
1233
1455
  continue;
1234
1456
  }
1235
- await settingsOp(ag, row.sealId, args.slice(1), row.phase === 'running' && row.url ? row.url : undefined);
1457
+ await settingsOp(ag, row.sealId, args.slice(1), row.phase === 'running' && row.url ? row.url : undefined, row.framework);
1236
1458
  continue;
1237
1459
  }
1238
1460
  if (cmd === 'authorizer') {
@@ -1630,8 +1852,9 @@ let cachedClient = null;
1630
1852
  * Returns the document now in force (unchanged on a bare show), so a caller
1631
1853
  * like /think can report the level that actually landed.
1632
1854
  */
1633
- async function settingsOp(ag, sealId, args, serveBase) {
1855
+ async function settingsOp(ag, sealId, args, serveBase, framework) {
1634
1856
  const assignments = (0, settings_1.parseAssignments)(args); // throws CliError on a bad key/level
1857
+ (0, settings_1.assertOthersFitFramework)(assignments, framework);
1635
1858
  const { settings: current, version } = await ag.agent.getSettings(sealId);
1636
1859
  if (!assignments.length) {
1637
1860
  for (const l of (0, settings_1.renderSettings)(current))
@@ -2013,6 +2236,14 @@ async function ensureOwnerReady(ag, ask) {
2013
2236
  }
2014
2237
  return true;
2015
2238
  }
2239
+ /**
2240
+ * Whether the deploy wizard offers `framework` only models with tool use: the
2241
+ * tool-driven frameworks, the harness under either of its names (`dsh` on a
2242
+ * network still on AgentDNA 1.3, see `isHarnessFramework`).
2243
+ */
2244
+ function frameworkNeedsToolModels(framework) {
2245
+ return framework === 'openclaw' || framework === 'prime-agent' || (0, settings_1.isHarnessFramework)(framework);
2246
+ }
2016
2247
  async function deployWizard(ag, attestorUrl, ask, ctx, irq) {
2017
2248
  const cfg = (await fetch(`${attestorUrl}/config`, { signal: AbortSignal.timeout(10000) })
2018
2249
  .then((r) => r.json())
@@ -2035,10 +2266,9 @@ async function deployWizard(ag, attestorUrl, ask, ctx, irq) {
2035
2266
  const provider = await pickInferenceProvider(ask, (0, config_1.loadConfig)().inferenceProvider ?? '0g-compute');
2036
2267
  const definition = knownProviders.find((entry) => entry.id === provider);
2037
2268
  await ag.agent.assertProviderSupported(provider, { framework });
2038
- const NEEDS_TOOLS = new Set(['openclaw', 'dsh', 'prime-agent']);
2039
2269
  const caps = await ag.agent.listModelCaps({ provider });
2040
2270
  const models = caps.filter((model) => model.chat)
2041
- .filter((model) => !NEEDS_TOOLS.has(framework) || model.tools)
2271
+ .filter((model) => !frameworkNeedsToolModels(framework) || model.tools)
2042
2272
  .filter((model) => framework !== 'hermes' || definition.native || model.formats.includes('openai') || (!model.formats.length && !model.id.startsWith('claude')))
2043
2273
  .map((model) => model.id);
2044
2274
  let model;
@@ -2184,7 +2414,7 @@ async function pickFramework(attestorUrl, ask, current) {
2184
2414
  return !raw ? fws[di] : Number.isInteger(i) && fws[i] ? fws[i] : fws.includes(raw) ? raw : fws[di];
2185
2415
  }
2186
2416
  // ── L2: session REPL ─────────────────────────────────────────────────────────
2187
- const L2_HELP = '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)';
2417
+ const L2_HELP = '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)';
2188
2418
  const L2_HELP_FULL = `session commands
2189
2419
  <anything else> chat with the agent — Esc or Ctrl-C interrupts the
2190
2420
  turn in flight (the runtime cancels server-side)
@@ -2214,24 +2444,40 @@ const L2_HELP_FULL = `session commands
2214
2444
  is untouched; that is the difference from /reset
2215
2445
  /compact compact the agent's conversation in place — older
2216
2446
  history becomes a summary, the newest part stays
2217
- as it is (openclaw ~20K tokens, dsh its newest
2218
- item), and the conversation goes on (unlike
2447
+ as it is (openclaw ~20K tokens, 0g-harness its
2448
+ newest item), and the conversation goes on (unlike
2219
2449
  /clear). One or more model calls; can take
2220
- minutes. dsh, and openclaw 2026.7.1 or later
2221
- /tasks this session's long tasks with live status — on
2222
- agents with the responses transport a chat turn
2223
- survives dropped connections and keeps running
2450
+ minutes. 0g-harness, and openclaw 2026.7.1 or later
2451
+ /tasks on 0g-harness: everything that runs or ran on the
2452
+ agent — your turns, the turns it opened itself,
2453
+ background commands and subagents — with who did
2454
+ each (BY) and who asked (FOR). Elsewhere: this
2455
+ session's long tasks with live status — on agents
2456
+ with the responses transport a chat turn survives
2457
+ dropped connections and keeps running
2224
2458
  /result [id] re-attach to a task (default: latest): prints a
2225
- finished one, follows a running one live
2226
- /cancel [id] stop tasks — the brake for orphaned turns: Esc only
2227
- cancels a turn THIS connection started (on dsh/prime
2228
- it interrupts the bridge-wide current turn), so after
2229
- a dropped stream /cancel is the way to stop what
2230
- survived. Bare form stops everything this session
2231
- knows to be in flight (newest first); with an id,
2232
- just that one — /result <id> adopts an id into the
2233
- session first. Session memory starts empty after a
2234
- CLI restart or /back + use
2459
+ finished one, follows a running one live; on
2460
+ 0g-harness also a subagent's answer or a command's
2461
+ status
2462
+ /cancel [id|all] stop tasks — the brake for orphaned turns: Esc only
2463
+ cancels a turn THIS connection started (on
2464
+ 0g-harness and prime it interrupts the agent-wide
2465
+ current turn), so after a dropped stream /cancel
2466
+ is the way to stop what survived. Bare form stops
2467
+ everything this session knows to be in flight
2468
+ (newest first); with an id, just that one —
2469
+ /result <id> adopts an id into the session first.
2470
+ Session memory starts empty after a CLI restart or
2471
+ /back + use. On 0g-harness an id can be any task
2472
+ /tasks lists, and /cancel all stops everything
2473
+ running on the agent
2474
+ /inbox [all] what the agent said on its own (0g-harness): a
2475
+ background job finished, a reminder came due. It
2476
+ prints above the prompt as it arrives, and what
2477
+ came while you were away prints when you enter.
2478
+ Bare: unread messages; all: the read ones too
2479
+ /schedules the reminders the agent set for itself
2480
+ (0g-harness)
2235
2481
  /agentlog [n] agent process log, last n lines (owner-only)
2236
2482
  /startuplog [n] sealed runtime startup log, last n lines
2237
2483
  /back (or /unuse) return to the manager
@@ -2293,6 +2539,21 @@ async function sessionRepl(s, ask, irq, ctx) {
2293
2539
  }
2294
2540
  };
2295
2541
  irq.brake = makeBrake(() => s.client, out, displacedSeat, () => seatPromptPending);
2542
+ // What the agent says on its own (a background job finished, a reminder
2543
+ // came due) arrives at any time. At the session prompt it prints above the
2544
+ // prompt; during a command, a chat turn or any other question it waits for
2545
+ // the next session prompt, so it never lands inside a reply.
2546
+ let atPrompt = false;
2547
+ const held = [];
2548
+ const inbox = makeInboxFeed((text, shown) => {
2549
+ if (atPrompt) {
2550
+ printAbovePrompt(text);
2551
+ shown();
2552
+ }
2553
+ else {
2554
+ held.push({ text, shown });
2555
+ }
2556
+ });
2296
2557
  // A friendly message that hides WHICH failure happened costs a whole
2297
2558
  // debugging round trip: "no headers ever arrived" and "the stream was cut
2298
2559
  // mid-way" have different causes and used to print identically. Append the
@@ -2318,7 +2579,19 @@ async function sessionRepl(s, ask, irq, ctx) {
2318
2579
  }
2319
2580
  catch { /* prompt anyway */ }
2320
2581
  }
2321
- const line = (await ask(`\nagent ${s.agentId} › `)).trim();
2582
+ inbox.follow(s.client);
2583
+ for (const h of held.splice(0)) {
2584
+ out(h.text);
2585
+ h.shown();
2586
+ }
2587
+ atPrompt = true;
2588
+ let line;
2589
+ try {
2590
+ line = (await ask(`\nagent ${s.agentId} › `)).trim();
2591
+ }
2592
+ finally {
2593
+ atPrompt = false;
2594
+ }
2322
2595
  if (!line) {
2323
2596
  // Bare Enter = live status refresh (phase moves on its own during
2324
2597
  // deploying/provisioning; the entry card only showed the initial one).
@@ -2434,8 +2707,9 @@ async function sessionRepl(s, ask, irq, ctx) {
2434
2707
  continue;
2435
2708
  }
2436
2709
  out('starting… (Esc cancels the wait)\n');
2710
+ const baseline = await lifecycleBaseline(s.attestorUrl, s.sealId);
2437
2711
  await s.ag.agent.start(s.sealId, s.sandboxId);
2438
- const r = await waitRunningInterruptible(irq, s.attestorUrl, s.sealId, s.agentId);
2712
+ const r = await waitRunningInterruptible(irq, s.attestorUrl, s.sealId, s.agentId, baseline);
2439
2713
  if (!r)
2440
2714
  continue;
2441
2715
  await connectSession(s, r.url);
@@ -2453,16 +2727,19 @@ async function sessionRepl(s, ask, irq, ctx) {
2453
2727
  else {
2454
2728
  s.framework = await pickFramework(s.attestorUrl, ask, s.framework);
2455
2729
  }
2456
- const provider = await (0, inference_1.agentInferenceProvider)(s.ag, s.sealId);
2730
+ const plan = await (0, inference_1.resetInferencePlan)(s.ag, s.sealId, await (0, inference_1.readDeploymentFacts)(s.attestorUrl, s.sealId));
2731
+ const provider = plan.provider;
2457
2732
  await s.ag.agent.assertProviderSupported(provider, { sealId: s.sealId, framework: s.framework });
2458
2733
  const apiKey = await inferenceKey(ctx, ask, provider);
2459
2734
  if (!(await ensureOwnerReady(s.ag, ask))) {
2460
2735
  out('reset cancelled — prepaid balance too low\n');
2461
2736
  continue;
2462
2737
  }
2738
+ await (0, inference_1.applyResetInference)(s.ag, s.sealId, plan, out);
2463
2739
  out(`resetting as ${s.framework}… (Esc cancels the wait)\n`);
2740
+ const baseline = await lifecycleBaseline(s.attestorUrl, s.sealId);
2464
2741
  await s.ag.agent.reset(s.sealId, { provider, framework: s.framework, apiKey });
2465
- const r = await waitRunningInterruptible(irq, s.attestorUrl, s.sealId, s.agentId);
2742
+ const r = await waitRunningInterruptible(irq, s.attestorUrl, s.sealId, s.agentId, baseline);
2466
2743
  if (!r)
2467
2744
  continue;
2468
2745
  await connectSession(s, r.url);
@@ -2583,7 +2860,7 @@ async function sessionRepl(s, ask, irq, ctx) {
2583
2860
  // with, and how hard. Bare shows it; key=value writes it (merged).
2584
2861
  // Owner-signed in both directions, so it needs the wallet client and
2585
2862
  // not the session's (possibly keyless) one.
2586
- await settingsOp(await withWallet(ctx), s.sealId, (0, tokenize_1.tokenize)(line).slice(1), s.client && s.url ? s.url : undefined);
2863
+ await settingsOp(await withWallet(ctx), s.sealId, (0, tokenize_1.tokenize)(line).slice(1), s.client && s.url ? s.url : undefined, s.framework);
2587
2864
  continue;
2588
2865
  }
2589
2866
  if (line === '/think' || line.startsWith('/think ')) {
@@ -2618,6 +2895,20 @@ async function sessionRepl(s, ask, irq, ctx) {
2618
2895
  continue;
2619
2896
  }
2620
2897
  if (line === '/tasks') {
2898
+ // An agent with its own task list (0g-harness) answers for everything that
2899
+ // runs on it: every turn, yours and the ones it opened itself, and
2900
+ // every background command and subagent, with who did each.
2901
+ if (s.client?.tasks) {
2902
+ const list = await s.client.tasks({ limit: 30 });
2903
+ if (!list.length) {
2904
+ out('nothing has run on this agent yet\n');
2905
+ continue;
2906
+ }
2907
+ for (const l of renderTaskTable(list, Date.now()))
2908
+ out(`${l}\n`);
2909
+ out('/result <id> shows one · /cancel <id> stops one · /cancel all stops everything running\n');
2910
+ continue;
2911
+ }
2621
2912
  // Long-task surface (responses transport). The list is this session's
2622
2913
  // memory of submitted ids; status is fetched live from the agent.
2623
2914
  if (!s.client?.task) {
@@ -2650,11 +2941,27 @@ async function sessionRepl(s, ask, irq, ctx) {
2650
2941
  continue;
2651
2942
  }
2652
2943
  if (line === '/result' || line.startsWith('/result ')) {
2944
+ // A background command or a subagent is not a turn: its record is
2945
+ // the task list's, and it has no stream to follow.
2946
+ const named = line.split(/\s+/)[1];
2947
+ if (named && s.client?.taskInfo) {
2948
+ const t = await s.client.taskInfo(named).catch(() => null);
2949
+ if (t && t.type !== 'turn') {
2950
+ out(`${(0, cells_1.cleanCell)(t.id)} — ${t.status} · by ${t.actor} · ${(0, cells_1.cleanCell)(t.label)}\n`);
2951
+ if (t.output_text)
2952
+ out(`${t.output_text}\n`);
2953
+ else if (t.type === 'command')
2954
+ out('(a command\'s output goes to the agent, which reports on it when the command finishes — /inbox)\n');
2955
+ if (t.error)
2956
+ out(`error: ${(0, cells_1.cleanCell)(t.error)}\n`);
2957
+ continue;
2958
+ }
2959
+ }
2653
2960
  if (!s.client?.task || !s.client.followTask) {
2654
2961
  out('(this agent has no task surface)\n');
2655
2962
  continue;
2656
2963
  }
2657
- const id = line.split(/\s+/)[1] ?? s.tasks?.[s.tasks.length - 1]?.id;
2964
+ const id = named ?? s.tasks?.[s.tasks.length - 1]?.id;
2658
2965
  if (!id) {
2659
2966
  out('no task to show — /result <id>, or start one by chatting\n');
2660
2967
  continue;
@@ -2716,6 +3023,31 @@ async function sessionRepl(s, ask, irq, ctx) {
2716
3023
  // survival is the feature). /cancel is the explicit brake: by id, or
2717
3024
  // everything in flight this session knows.
2718
3025
  let id = line.split(/\s+/)[1];
3026
+ // An agent with its own task list (0g-harness) stops any of its tasks by id
3027
+ // (a turn, a background command, a subagent), and all of them at once.
3028
+ if (id && s.client.stopTask && s.client.stopAllTasks) {
3029
+ for (;;) {
3030
+ try {
3031
+ const stopped = id === 'all' ? await s.client.stopAllTasks() : [await s.client.stopTask(id)];
3032
+ if (!stopped.length)
3033
+ out('nothing running\n');
3034
+ for (const x of stopped)
3035
+ out(`⏹ ${(0, cells_1.cleanCell)(x.id)} — ${STOP_OUTCOME[x.outcome] ?? x.outcome}\n`);
3036
+ break;
3037
+ }
3038
+ catch (e) {
3039
+ const d = await routeTaskFailure(out, displacedSeat, e, `(cancel failed: ${e.message})\n`, `retry /cancel ${id}`);
3040
+ if (d === 'reclaimed')
3041
+ continue; // seat is back — retry
3042
+ break;
3043
+ }
3044
+ }
3045
+ continue;
3046
+ }
3047
+ if (id === 'all') {
3048
+ out('(this agent has no task list: bare /cancel stops what this session started, /stop stops the whole container)\n');
3049
+ continue;
3050
+ }
2719
3051
  if (!id && s.client?.task) {
2720
3052
  if (!s.tasks?.length) {
2721
3053
  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');
@@ -2753,8 +3085,8 @@ async function sessionRepl(s, ask, irq, ctx) {
2753
3085
  continue;
2754
3086
  }
2755
3087
  // A brake stops everything in flight, newest first — stopping only
2756
- // the newest would leave an older running turn alive (dsh/prime
2757
- // serialize turns, so a queued one is waiting on the running one).
3088
+ // the newest would leave an older running turn alive (0g-harness and
3089
+ // prime serialize turns, so a queued one is waiting on the running one).
2758
3090
  const inFlight = inFlightIds(rows);
2759
3091
  if (!inFlight.length) {
2760
3092
  out('nothing in flight from this session — /tasks to list; a finished task cannot be cancelled\n');
@@ -2808,7 +3140,7 @@ async function sessionRepl(s, ask, irq, ctx) {
2808
3140
  if (id && !s.client?.cancelTask) {
2809
3141
  // An id was asked for but this image has no task-level cancel: do
2810
3142
  // NOT silently interrupt "whatever is running" instead — but on
2811
- // dsh/prime the bridge-wide interrupt DOES stop the running turn,
3143
+ // 0g-harness and prime the agent-wide interrupt DOES stop the running turn,
2812
3144
  // so point there instead of claiming nothing can be done.
2813
3145
  out(s.client?.interrupt
2814
3146
  ? '(this agent image has no per-task cancel — the bridge interrupt stops the current running turn; try /cancel with no id)\n'
@@ -2831,6 +3163,50 @@ async function sessionRepl(s, ask, irq, ctx) {
2831
3163
  out(r.aborted ? '⏹ stopped the running turn\n' : `(nothing to stop, or: ${r.note ?? 'not supported'})\n`);
2832
3164
  continue;
2833
3165
  }
3166
+ if (line === '/inbox' || line === '/inbox all') {
3167
+ if (!s.client) {
3168
+ out(`agent is ${s.phase} — /start or /reset first\n`);
3169
+ continue;
3170
+ }
3171
+ if (!s.client.inbox) {
3172
+ out('(no inbox on this agent: its framework does not run work in the background)\n');
3173
+ continue;
3174
+ }
3175
+ const all = line === '/inbox all';
3176
+ const page = await s.client.inbox(all ? { after: 0 } : {});
3177
+ if (!page.data.length) {
3178
+ out(all ? 'the inbox is empty\n' : 'no new messages — /inbox all shows the ones already read\n');
3179
+ continue;
3180
+ }
3181
+ out(page.data.map(renderInboxMessage).join('\n'));
3182
+ const through = Math.max(...page.data.map((m) => m.seq));
3183
+ if (through > page.read_through)
3184
+ await s.client.ackInbox?.(through).catch(() => undefined);
3185
+ continue;
3186
+ }
3187
+ if (line === '/schedules') {
3188
+ if (!s.client) {
3189
+ out(`agent is ${s.phase} — /start or /reset first\n`);
3190
+ continue;
3191
+ }
3192
+ if (!s.client.schedules) {
3193
+ out('(no reminders on this agent: its framework does not support them)\n');
3194
+ continue;
3195
+ }
3196
+ const r = await s.client.schedules();
3197
+ if (!r.enabled) {
3198
+ out('reminders are off on this agent (the "schedule" switch in /settings others)\n');
3199
+ continue;
3200
+ }
3201
+ if (!r.data.length) {
3202
+ out('no reminders set — the agent sets one when you ask it to remind you of something\n');
3203
+ continue;
3204
+ }
3205
+ for (const l of renderSchedules(r.data, Date.now()))
3206
+ out(`${l}\n`);
3207
+ out('to remove one, ask the agent to\n');
3208
+ continue;
3209
+ }
2834
3210
  if (line.startsWith('/')) {
2835
3211
  out(`unknown command ${line}\n${L2_HELP}\n`);
2836
3212
  continue;
@@ -2854,7 +3230,7 @@ async function sessionRepl(s, ask, irq, ctx) {
2854
3230
  }
2855
3231
  messages.push({ role: 'user', content: line });
2856
3232
  // `model` is a per-framework selector some gateways require (openclaw
2857
- // does; the dsh/prime bridges ignore it). Send it when known, omit it
3233
+ // does; 0g-harness and the prime bridge ignore it). Send it when known, omit it
2858
3234
  // otherwise — and only if the framework rejects that, ask once and retry.
2859
3235
  let retriedWithPick = false;
2860
3236
  for (;;) {
@@ -2899,7 +3275,7 @@ async function sessionRepl(s, ask, irq, ctx) {
2899
3275
  const onActivity = process.stdout.isTTY
2900
3276
  ? (label) => {
2901
3277
  // "did work this turn" detector, across bridges' label dialects:
2902
- // dsh "tool/call bash", prime "tool_execution_start — bash" /
3278
+ // 0g-harness "tool/call bash", prime "tool_execution_start — bash" /
2903
3279
  // "bash_command_start", hermes "tool/call web_search". Thinking
2904
3280
  // alone doesn't count — a think-only turn with no output is still
2905
3281
  // a failure worth reporting.
@@ -3013,7 +3389,7 @@ async function sessionRepl(s, ask, irq, ctx) {
3013
3389
  continue; // retry the same user message once with the selector
3014
3390
  }
3015
3391
  // A turn that ran tools but produced no text is WORK, not failure —
3016
- // dsh agents legitimately end tool-only turns silently. Say what
3392
+ // 0g-harness agents legitimately end tool-only turns silently. Say what
3017
3393
  // happened instead of crying wolf (the true-failure path — no deltas,
3018
3394
  // no activity — still reports as an error).
3019
3395
  // Displaced by another window (occupancy.go): WeChat semantics — this
@@ -3047,6 +3423,7 @@ async function sessionRepl(s, ask, irq, ctx) {
3047
3423
  }
3048
3424
  finally {
3049
3425
  irq.brake = null; // leaving the session: idle-Esc no longer targets this agent
3426
+ inbox.stop();
3050
3427
  }
3051
3428
  }
3052
3429
  //# sourceMappingURL=interactive.js.map