@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.
- package/GUIDE.md +64 -15
- package/PROVIDERS.md +6 -4
- package/PROVIDERS.zh.md +4 -3
- package/README.md +19 -3
- package/dist/AgentClient.d.ts +175 -2
- package/dist/AgentClient.d.ts.map +1 -1
- package/dist/AgentClient.js +166 -7
- package/dist/AgentClient.js.map +1 -1
- package/dist/AgenticID.d.ts +45 -6
- package/dist/AgenticID.d.ts.map +1 -1
- package/dist/AgenticID.js +40 -10
- package/dist/AgenticID.js.map +1 -1
- package/dist/AttestorClient.d.ts +66 -1
- package/dist/AttestorClient.d.ts.map +1 -1
- package/dist/AttestorClient.js +161 -32
- package/dist/AttestorClient.js.map +1 -1
- package/dist/cli/commands/cells.d.ts +29 -1
- package/dist/cli/commands/cells.d.ts.map +1 -1
- package/dist/cli/commands/cells.js +48 -1
- package/dist/cli/commands/cells.js.map +1 -1
- package/dist/cli/commands/interactive.d.ts +84 -7
- package/dist/cli/commands/interactive.d.ts.map +1 -1
- package/dist/cli/commands/interactive.js +453 -58
- package/dist/cli/commands/interactive.js.map +1 -1
- package/dist/cli/commands/list.d.ts.map +1 -1
- package/dist/cli/commands/list.js +7 -31
- package/dist/cli/commands/list.js.map +1 -1
- package/dist/cli/commands/settings.d.ts.map +1 -1
- package/dist/cli/commands/settings.js +23 -0
- package/dist/cli/commands/settings.js.map +1 -1
- package/dist/cli/inference.d.ts +25 -0
- package/dist/cli/inference.d.ts.map +1 -1
- package/dist/cli/inference.js +67 -6
- package/dist/cli/inference.js.map +1 -1
- package/dist/cli/settings.d.ts +20 -0
- package/dist/cli/settings.d.ts.map +1 -1
- package/dist/cli/settings.js +40 -1
- package/dist/cli/settings.js.map +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/AgentClient.ts +326 -9
- package/src/AgenticID.ts +62 -8
- package/src/AttestorClient.ts +206 -50
- package/src/cli/commands/cells.ts +47 -1
- package/src/cli/commands/interactive.ts +441 -64
- package/src/cli/commands/list.ts +7 -29
- package/src/cli/commands/settings.ts +22 -1
- package/src/cli/inference.ts +82 -5
- package/src/cli/settings.ts +41 -0
- package/src/constants.ts +1 -1
- package/src/index.ts +7 -3
|
@@ -54,10 +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;
|
|
64
|
+
exports.renderListHeader = renderListHeader;
|
|
59
65
|
exports.renderListRow = renderListRow;
|
|
66
|
+
exports.lifecycleBaseline = lifecycleBaseline;
|
|
67
|
+
exports.pollRunning = pollRunning;
|
|
60
68
|
exports.run = run;
|
|
69
|
+
exports.frameworkNeedsToolModels = frameworkNeedsToolModels;
|
|
61
70
|
const readline = __importStar(require("node:readline"));
|
|
62
71
|
const node_fs_1 = require("node:fs");
|
|
63
72
|
const node_path_1 = require("node:path");
|
|
@@ -79,7 +88,7 @@ const inference_1 = require("../inference");
|
|
|
79
88
|
// Tab-completion candidates for the active REPL level (canonical names only —
|
|
80
89
|
// aliases like link//unuse still work typed out but don't clutter the list).
|
|
81
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'];
|
|
82
|
-
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'];
|
|
83
92
|
let activeCompletions = L1_WORDS;
|
|
84
93
|
// First-argument completion per command (Tab after the command word).
|
|
85
94
|
// Static lists inline; AGENT resolves to the ids seen in the latest
|
|
@@ -274,8 +283,9 @@ async function routeTaskFailure(print, seat, e, rawLine, seatHint) {
|
|
|
274
283
|
}
|
|
275
284
|
/**
|
|
276
285
|
* The tasks bare `/cancel` stops: everything still in flight, NEWEST FIRST
|
|
277
|
-
* (stopping only the newest would leave an older running turn alive;
|
|
278
|
-
* prime serialize turns, so a queued one is waiting on the
|
|
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).
|
|
279
289
|
* Statuses arrive live from the agent; "unknown" (evicted or agent
|
|
280
290
|
* restarted, 404) counts as not in flight — cancelling an unknown record
|
|
281
291
|
* would claim to stop something nobody can see. Exported for the tests:
|
|
@@ -289,6 +299,151 @@ function inFlightIds(rows) {
|
|
|
289
299
|
}
|
|
290
300
|
return out;
|
|
291
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
|
+
}
|
|
292
447
|
let knownAgentIds = [];
|
|
293
448
|
const rememberAgentIds = (rows) => {
|
|
294
449
|
const ids = rows.map((r) => String(r.agentId ?? '')).filter((x) => x && x !== 'undefined');
|
|
@@ -328,6 +483,8 @@ const L1_ARGS = {
|
|
|
328
483
|
const L2_ARGS = {
|
|
329
484
|
'/think': ['low', 'high', 'max'],
|
|
330
485
|
'/reset': ['pick'],
|
|
486
|
+
'/cancel': ['all'],
|
|
487
|
+
'/inbox': ['all'],
|
|
331
488
|
'/settings': ['provider=', 'model=', 'thinking=', 'others='],
|
|
332
489
|
};
|
|
333
490
|
let activeArgs = L1_ARGS;
|
|
@@ -393,17 +550,55 @@ function completeLine(line, state) {
|
|
|
393
550
|
// The live readline interface — askSecret scrubs submitted secrets out of
|
|
394
551
|
// its history (display masking alone leaves the plaintext one ↑ away).
|
|
395
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
|
+
}
|
|
396
576
|
const cells_1 = require("./cells");
|
|
577
|
+
/** Column widths of the REPL listing; its header and every row share them. */
|
|
578
|
+
const LIST_COLS = { id: 6, phase: 11, framework: 12, seal: 13, agentSeal: 13, owner: 24 };
|
|
579
|
+
/** The REPL listing's header line, aligned with {@link renderListRow}. */
|
|
580
|
+
function renderListHeader() {
|
|
581
|
+
const c = LIST_COLS;
|
|
582
|
+
return ` ${'ID'.padEnd(c.id)} ${'PHASE'.padEnd(c.phase)}${'FRAMEWORK'.padEnd(c.framework)}` +
|
|
583
|
+
`${'SEAL'.padEnd(c.seal)}${'AGENTSEAL'.padEnd(c.agentSeal)}${'OWNER'.padEnd(c.owner)}NAME\n`;
|
|
584
|
+
}
|
|
397
585
|
/**
|
|
398
586
|
* One row of the REPL's agent listing. Exported for the tests: this IS the
|
|
399
|
-
* renderer the interactive loop prints
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
587
|
+
* renderer the interactive loop prints. Its cells go through ./cells, shared
|
|
588
|
+
* with `list`: a name cannot forge rows in this listing either, and an
|
|
589
|
+
* agent-owned agent reads the same way — its OWNER is another row's
|
|
590
|
+
* AGENTSEAL, annotated `⇄ #<agentId>` (`sealToAgent`, from the full listing).
|
|
591
|
+
* SEAL is the sealId PREFIX (`0x` + 10 hex), the form commands accept as a
|
|
592
|
+
* reference, so unminted rows stay referenceable without a 66-char column
|
|
593
|
+
* blowout (F12).
|
|
594
|
+
* AGENTSEAL is the agent's on-chain signing address.
|
|
403
595
|
*/
|
|
404
|
-
function renderListRow(r, owner, owned = ' ') {
|
|
405
|
-
const
|
|
406
|
-
|
|
596
|
+
function renderListRow(r, owner, owned = ' ', sealToAgent = new Map()) {
|
|
597
|
+
const c = LIST_COLS;
|
|
598
|
+
const seal = `0x${r.sealId.slice(2, 12)}`;
|
|
599
|
+
return `${owned} ${String(r.agentId ?? '?').padEnd(c.id)} ${(0, cells_1.cellText)(r.phase ?? '?', c.phase)}` +
|
|
600
|
+
`${(0, cells_1.cellText)(r.framework, c.framework)}${(0, cells_1.cellText)(seal, c.seal)}${(0, cells_1.cellText)((0, cells_1.shortAddr)(r.agentSeal), c.agentSeal)}` +
|
|
601
|
+
`${(0, cells_1.trustedCell)((0, cells_1.ownerCellText)(owner, sealToAgent), c.owner)}${(0, cells_1.cleanCell)(r.name)}\n`;
|
|
407
602
|
}
|
|
408
603
|
const sbid = (url) => url.match(/8080-([^.]+)\./)?.[1];
|
|
409
604
|
/** Build a container URL from a sandbox id + proxy host, matching the
|
|
@@ -491,20 +686,47 @@ async function refreshSession(s, quiet = false) {
|
|
|
491
686
|
if (reason)
|
|
492
687
|
out(` last error: ${reason}\n`);
|
|
493
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
|
+
}
|
|
494
705
|
/**
|
|
495
706
|
* Wait for a deployment to reach `running` by polling the attestor's public
|
|
496
707
|
* /deployment/:sealId — and FAIL LOUD instead of hanging: a `failed`/`offline`
|
|
497
708
|
* phase (or a failed container_stage) surfaces its recorded reason
|
|
498
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.
|
|
499
716
|
*/
|
|
500
717
|
class WaitCancelled extends Error {
|
|
501
718
|
constructor() { super('wait cancelled'); }
|
|
502
719
|
}
|
|
503
|
-
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;
|
|
504
722
|
const deadline = Date.now() + timeoutMs;
|
|
505
723
|
const t0 = Date.now();
|
|
506
724
|
let lastPhase = 'contacting attestor';
|
|
507
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;
|
|
508
730
|
// Transient progress line between phase changes — a deploy sits minutes in
|
|
509
731
|
// one phase with zero output otherwise. Repainted each second; phase-change
|
|
510
732
|
// lines and the final result overwrite it. TTY only.
|
|
@@ -532,7 +754,14 @@ async function pollRunning(attestorUrl, sealId, agentId, timeoutMs = 360000, sig
|
|
|
532
754
|
for (;;) {
|
|
533
755
|
try {
|
|
534
756
|
const d = (await (await fetch(`${attestorUrl}/deployment/${sealId}`)).json());
|
|
535
|
-
|
|
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';
|
|
536
765
|
if (lastPhase !== lastShown) {
|
|
537
766
|
clearSpinner();
|
|
538
767
|
out(` … ${lastPhase}\n`);
|
|
@@ -540,10 +769,10 @@ async function pollRunning(attestorUrl, sealId, agentId, timeoutMs = 360000, sig
|
|
|
540
769
|
}
|
|
541
770
|
const cardBase = d.agent_card?.url?.replace(/\/hello$/, '');
|
|
542
771
|
const url = d.url ?? cardBase ?? (d.sandbox_id && cfg.sandbox_proxy_addr ? containerUrl(d.sandbox_id, cfg.sandbox_proxy_addr) : undefined);
|
|
543
|
-
if (d.phase === 'running' && url)
|
|
772
|
+
if (progressed && d.phase === 'running' && url)
|
|
544
773
|
return { url };
|
|
545
774
|
const reason = d.container_stage?.state === 'failed' ? d.container_stage?.reason : undefined;
|
|
546
|
-
if (d.phase === 'failed' || reason) {
|
|
775
|
+
if (progressed && (d.phase === 'failed' || reason)) {
|
|
547
776
|
throw new errors_1.CliError('UNKNOWN', `agent ${agentId} did not start: ${reason ?? `phase=${d.phase}`}`, {
|
|
548
777
|
remedy: `run \`reset ${agentId}\` to recreate the container once the cause is fixed`,
|
|
549
778
|
});
|
|
@@ -555,13 +784,18 @@ async function pollRunning(attestorUrl, sealId, agentId, timeoutMs = 360000, sig
|
|
|
555
784
|
// transient fetch error — keep polling until the deadline
|
|
556
785
|
}
|
|
557
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
|
+
}
|
|
558
792
|
throw new errors_1.CliError('UNKNOWN', `timed out after ${Math.round(timeoutMs / 1000)}s waiting for agent ${agentId} (last phase: ${lastPhase})`, {
|
|
559
793
|
remedy: 'check `status` — provisioning can lag; retry the command when the phase moves',
|
|
560
794
|
});
|
|
561
795
|
}
|
|
562
796
|
if (signal?.aborted)
|
|
563
797
|
throw new WaitCancelled();
|
|
564
|
-
await new Promise((r) => setTimeout(r,
|
|
798
|
+
await new Promise((r) => setTimeout(r, intervalMs));
|
|
565
799
|
if (signal?.aborted)
|
|
566
800
|
throw new WaitCancelled();
|
|
567
801
|
}
|
|
@@ -574,11 +808,11 @@ async function pollRunning(attestorUrl, sealId, agentId, timeoutMs = 360000, sig
|
|
|
574
808
|
}
|
|
575
809
|
/** pollRunning wired to the Esc/Ctrl-C interrupt: cancelling abandons the
|
|
576
810
|
* WAIT only — the lifecycle operation keeps going server-side. */
|
|
577
|
-
async function waitRunningInterruptible(irq, attestorUrl, sealId, agentId) {
|
|
811
|
+
async function waitRunningInterruptible(irq, attestorUrl, sealId, agentId, baseline) {
|
|
578
812
|
const ac = new AbortController();
|
|
579
813
|
irq.streaming = ac;
|
|
580
814
|
try {
|
|
581
|
-
return await pollRunning(attestorUrl, sealId, agentId, 360000, ac.signal);
|
|
815
|
+
return await pollRunning(attestorUrl, sealId, agentId, 360000, ac.signal, { baseline });
|
|
582
816
|
}
|
|
583
817
|
catch (e) {
|
|
584
818
|
if (e instanceof WaitCancelled || ac.signal.aborted) {
|
|
@@ -1093,12 +1327,14 @@ async function managerRepl(ctx, ask, irq) {
|
|
|
1093
1327
|
out(mineOnly ? 'no agents owned by this wallet here\n' : 'no agents on this attestor\n');
|
|
1094
1328
|
continue;
|
|
1095
1329
|
}
|
|
1096
|
-
|
|
1097
|
-
|
|
1330
|
+
// From the full public listing, as in `list`: a --mine view must not
|
|
1331
|
+
// strip the annotation off a child whose parent it hides.
|
|
1332
|
+
const sealToAgent = (0, cells_1.sealToAgentMap)(rows);
|
|
1333
|
+
out(renderListHeader());
|
|
1098
1334
|
for (const r of shown) {
|
|
1099
|
-
const
|
|
1100
|
-
|
|
1101
|
-
out(renderListRow(r, owner,
|
|
1335
|
+
const own = mine?.get(r.sealId);
|
|
1336
|
+
// The owner tier carries owner and agentSeal for UNMINTED rows too.
|
|
1337
|
+
out(renderListRow({ ...r, agentSeal: own?.agentSeal ?? r.agentSeal }, own?.owner ?? r.owner, own ? '*' : ' ', sealToAgent));
|
|
1102
1338
|
}
|
|
1103
1339
|
if (mine && !mineOnly)
|
|
1104
1340
|
out('(* = owned by your wallet · `list --mine` filters to them)\n');
|
|
@@ -1138,8 +1374,9 @@ async function managerRepl(ctx, ask, irq) {
|
|
|
1138
1374
|
continue;
|
|
1139
1375
|
}
|
|
1140
1376
|
out(`starting agent ${row.agentId}… (Esc cancels the wait)\n`);
|
|
1377
|
+
const baseline = await lifecycleBaseline(attestorUrl, row.sealId);
|
|
1141
1378
|
await ag.agent.start(row.sealId, row.sandboxId);
|
|
1142
|
-
const r = await waitRunningInterruptible(irq, attestorUrl, row.sealId, row.agentId);
|
|
1379
|
+
const r = await waitRunningInterruptible(irq, attestorUrl, row.sealId, row.agentId, baseline);
|
|
1143
1380
|
if (r)
|
|
1144
1381
|
out(`running at ${r.url} — enter with: use ${row.agentId}\n`);
|
|
1145
1382
|
continue;
|
|
@@ -1155,16 +1392,19 @@ async function managerRepl(ctx, ask, irq) {
|
|
|
1155
1392
|
else {
|
|
1156
1393
|
framework = await pickFramework(attestorUrl, ask, row.framework ?? undefined);
|
|
1157
1394
|
}
|
|
1158
|
-
const
|
|
1395
|
+
const plan = await (0, inference_1.resetInferencePlan)(ag, row.sealId, await (0, inference_1.readDeploymentFacts)(attestorUrl, row.sealId));
|
|
1396
|
+
const provider = plan.provider;
|
|
1159
1397
|
await ag.agent.assertProviderSupported(provider, { sealId: row.sealId, framework });
|
|
1160
1398
|
const apiKey = await inferenceKey(ctx, ask, provider);
|
|
1161
1399
|
if (!(await ensureOwnerReady(ag, ask))) {
|
|
1162
1400
|
out('reset cancelled — prepaid balance too low\n');
|
|
1163
1401
|
continue;
|
|
1164
1402
|
}
|
|
1403
|
+
await (0, inference_1.applyResetInference)(ag, row.sealId, plan, out);
|
|
1165
1404
|
out(`resetting agent ${row.agentId} as ${framework}… (Esc cancels the wait)\n`);
|
|
1405
|
+
const baseline = await lifecycleBaseline(attestorUrl, row.sealId);
|
|
1166
1406
|
await ag.agent.reset(row.sealId, { provider, framework, apiKey });
|
|
1167
|
-
const r = await waitRunningInterruptible(irq, attestorUrl, row.sealId, row.agentId);
|
|
1407
|
+
const r = await waitRunningInterruptible(irq, attestorUrl, row.sealId, row.agentId, baseline);
|
|
1168
1408
|
if (r)
|
|
1169
1409
|
out(`running at ${r.url} — enter with: use ${row.agentId}\n`);
|
|
1170
1410
|
continue;
|
|
@@ -1214,7 +1454,7 @@ async function managerRepl(ctx, ask, irq) {
|
|
|
1214
1454
|
out(`no agent matching ${args[0]} on this attestor\n`);
|
|
1215
1455
|
continue;
|
|
1216
1456
|
}
|
|
1217
|
-
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);
|
|
1218
1458
|
continue;
|
|
1219
1459
|
}
|
|
1220
1460
|
if (cmd === 'authorizer') {
|
|
@@ -1612,8 +1852,9 @@ let cachedClient = null;
|
|
|
1612
1852
|
* Returns the document now in force (unchanged on a bare show), so a caller
|
|
1613
1853
|
* like /think can report the level that actually landed.
|
|
1614
1854
|
*/
|
|
1615
|
-
async function settingsOp(ag, sealId, args, serveBase) {
|
|
1855
|
+
async function settingsOp(ag, sealId, args, serveBase, framework) {
|
|
1616
1856
|
const assignments = (0, settings_1.parseAssignments)(args); // throws CliError on a bad key/level
|
|
1857
|
+
(0, settings_1.assertOthersFitFramework)(assignments, framework);
|
|
1617
1858
|
const { settings: current, version } = await ag.agent.getSettings(sealId);
|
|
1618
1859
|
if (!assignments.length) {
|
|
1619
1860
|
for (const l of (0, settings_1.renderSettings)(current))
|
|
@@ -1995,6 +2236,14 @@ async function ensureOwnerReady(ag, ask) {
|
|
|
1995
2236
|
}
|
|
1996
2237
|
return true;
|
|
1997
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
|
+
}
|
|
1998
2247
|
async function deployWizard(ag, attestorUrl, ask, ctx, irq) {
|
|
1999
2248
|
const cfg = (await fetch(`${attestorUrl}/config`, { signal: AbortSignal.timeout(10000) })
|
|
2000
2249
|
.then((r) => r.json())
|
|
@@ -2017,10 +2266,9 @@ async function deployWizard(ag, attestorUrl, ask, ctx, irq) {
|
|
|
2017
2266
|
const provider = await pickInferenceProvider(ask, (0, config_1.loadConfig)().inferenceProvider ?? '0g-compute');
|
|
2018
2267
|
const definition = knownProviders.find((entry) => entry.id === provider);
|
|
2019
2268
|
await ag.agent.assertProviderSupported(provider, { framework });
|
|
2020
|
-
const NEEDS_TOOLS = new Set(['openclaw', 'dsh', 'prime-agent']);
|
|
2021
2269
|
const caps = await ag.agent.listModelCaps({ provider });
|
|
2022
2270
|
const models = caps.filter((model) => model.chat)
|
|
2023
|
-
.filter((model) => !
|
|
2271
|
+
.filter((model) => !frameworkNeedsToolModels(framework) || model.tools)
|
|
2024
2272
|
.filter((model) => framework !== 'hermes' || definition.native || model.formats.includes('openai') || (!model.formats.length && !model.id.startsWith('claude')))
|
|
2025
2273
|
.map((model) => model.id);
|
|
2026
2274
|
let model;
|
|
@@ -2166,7 +2414,7 @@ async function pickFramework(attestorUrl, ask, current) {
|
|
|
2166
2414
|
return !raw ? fws[di] : Number.isInteger(i) && fws[i] ? fws[i] : fws.includes(raw) ? raw : fws[di];
|
|
2167
2415
|
}
|
|
2168
2416
|
// ── L2: session REPL ─────────────────────────────────────────────────────────
|
|
2169
|
-
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)';
|
|
2170
2418
|
const L2_HELP_FULL = `session commands
|
|
2171
2419
|
<anything else> chat with the agent — Esc or Ctrl-C interrupts the
|
|
2172
2420
|
turn in flight (the runtime cancels server-side)
|
|
@@ -2196,24 +2444,40 @@ const L2_HELP_FULL = `session commands
|
|
|
2196
2444
|
is untouched; that is the difference from /reset
|
|
2197
2445
|
/compact compact the agent's conversation in place — older
|
|
2198
2446
|
history becomes a summary, the newest part stays
|
|
2199
|
-
as it is (openclaw ~20K tokens,
|
|
2200
|
-
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
|
|
2201
2449
|
/clear). One or more model calls; can take
|
|
2202
|
-
minutes.
|
|
2203
|
-
/tasks
|
|
2204
|
-
|
|
2205
|
-
|
|
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
|
|
2206
2458
|
/result [id] re-attach to a task (default: latest): prints a
|
|
2207
|
-
finished one, follows a running one live
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
a
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
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)
|
|
2217
2481
|
/agentlog [n] agent process log, last n lines (owner-only)
|
|
2218
2482
|
/startuplog [n] sealed runtime startup log, last n lines
|
|
2219
2483
|
/back (or /unuse) return to the manager
|
|
@@ -2275,6 +2539,21 @@ async function sessionRepl(s, ask, irq, ctx) {
|
|
|
2275
2539
|
}
|
|
2276
2540
|
};
|
|
2277
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
|
+
});
|
|
2278
2557
|
// A friendly message that hides WHICH failure happened costs a whole
|
|
2279
2558
|
// debugging round trip: "no headers ever arrived" and "the stream was cut
|
|
2280
2559
|
// mid-way" have different causes and used to print identically. Append the
|
|
@@ -2300,7 +2579,19 @@ async function sessionRepl(s, ask, irq, ctx) {
|
|
|
2300
2579
|
}
|
|
2301
2580
|
catch { /* prompt anyway */ }
|
|
2302
2581
|
}
|
|
2303
|
-
|
|
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
|
+
}
|
|
2304
2595
|
if (!line) {
|
|
2305
2596
|
// Bare Enter = live status refresh (phase moves on its own during
|
|
2306
2597
|
// deploying/provisioning; the entry card only showed the initial one).
|
|
@@ -2416,8 +2707,9 @@ async function sessionRepl(s, ask, irq, ctx) {
|
|
|
2416
2707
|
continue;
|
|
2417
2708
|
}
|
|
2418
2709
|
out('starting… (Esc cancels the wait)\n');
|
|
2710
|
+
const baseline = await lifecycleBaseline(s.attestorUrl, s.sealId);
|
|
2419
2711
|
await s.ag.agent.start(s.sealId, s.sandboxId);
|
|
2420
|
-
const r = await waitRunningInterruptible(irq, s.attestorUrl, s.sealId, s.agentId);
|
|
2712
|
+
const r = await waitRunningInterruptible(irq, s.attestorUrl, s.sealId, s.agentId, baseline);
|
|
2421
2713
|
if (!r)
|
|
2422
2714
|
continue;
|
|
2423
2715
|
await connectSession(s, r.url);
|
|
@@ -2435,16 +2727,19 @@ async function sessionRepl(s, ask, irq, ctx) {
|
|
|
2435
2727
|
else {
|
|
2436
2728
|
s.framework = await pickFramework(s.attestorUrl, ask, s.framework);
|
|
2437
2729
|
}
|
|
2438
|
-
const
|
|
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;
|
|
2439
2732
|
await s.ag.agent.assertProviderSupported(provider, { sealId: s.sealId, framework: s.framework });
|
|
2440
2733
|
const apiKey = await inferenceKey(ctx, ask, provider);
|
|
2441
2734
|
if (!(await ensureOwnerReady(s.ag, ask))) {
|
|
2442
2735
|
out('reset cancelled — prepaid balance too low\n');
|
|
2443
2736
|
continue;
|
|
2444
2737
|
}
|
|
2738
|
+
await (0, inference_1.applyResetInference)(s.ag, s.sealId, plan, out);
|
|
2445
2739
|
out(`resetting as ${s.framework}… (Esc cancels the wait)\n`);
|
|
2740
|
+
const baseline = await lifecycleBaseline(s.attestorUrl, s.sealId);
|
|
2446
2741
|
await s.ag.agent.reset(s.sealId, { provider, framework: s.framework, apiKey });
|
|
2447
|
-
const r = await waitRunningInterruptible(irq, s.attestorUrl, s.sealId, s.agentId);
|
|
2742
|
+
const r = await waitRunningInterruptible(irq, s.attestorUrl, s.sealId, s.agentId, baseline);
|
|
2448
2743
|
if (!r)
|
|
2449
2744
|
continue;
|
|
2450
2745
|
await connectSession(s, r.url);
|
|
@@ -2565,7 +2860,7 @@ async function sessionRepl(s, ask, irq, ctx) {
|
|
|
2565
2860
|
// with, and how hard. Bare shows it; key=value writes it (merged).
|
|
2566
2861
|
// Owner-signed in both directions, so it needs the wallet client and
|
|
2567
2862
|
// not the session's (possibly keyless) one.
|
|
2568
|
-
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);
|
|
2569
2864
|
continue;
|
|
2570
2865
|
}
|
|
2571
2866
|
if (line === '/think' || line.startsWith('/think ')) {
|
|
@@ -2600,6 +2895,20 @@ async function sessionRepl(s, ask, irq, ctx) {
|
|
|
2600
2895
|
continue;
|
|
2601
2896
|
}
|
|
2602
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
|
+
}
|
|
2603
2912
|
// Long-task surface (responses transport). The list is this session's
|
|
2604
2913
|
// memory of submitted ids; status is fetched live from the agent.
|
|
2605
2914
|
if (!s.client?.task) {
|
|
@@ -2632,11 +2941,27 @@ async function sessionRepl(s, ask, irq, ctx) {
|
|
|
2632
2941
|
continue;
|
|
2633
2942
|
}
|
|
2634
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
|
+
}
|
|
2635
2960
|
if (!s.client?.task || !s.client.followTask) {
|
|
2636
2961
|
out('(this agent has no task surface)\n');
|
|
2637
2962
|
continue;
|
|
2638
2963
|
}
|
|
2639
|
-
const id =
|
|
2964
|
+
const id = named ?? s.tasks?.[s.tasks.length - 1]?.id;
|
|
2640
2965
|
if (!id) {
|
|
2641
2966
|
out('no task to show — /result <id>, or start one by chatting\n');
|
|
2642
2967
|
continue;
|
|
@@ -2698,6 +3023,31 @@ async function sessionRepl(s, ask, irq, ctx) {
|
|
|
2698
3023
|
// survival is the feature). /cancel is the explicit brake: by id, or
|
|
2699
3024
|
// everything in flight this session knows.
|
|
2700
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
|
+
}
|
|
2701
3051
|
if (!id && s.client?.task) {
|
|
2702
3052
|
if (!s.tasks?.length) {
|
|
2703
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');
|
|
@@ -2735,8 +3085,8 @@ async function sessionRepl(s, ask, irq, ctx) {
|
|
|
2735
3085
|
continue;
|
|
2736
3086
|
}
|
|
2737
3087
|
// A brake stops everything in flight, newest first — stopping only
|
|
2738
|
-
// the newest would leave an older running turn alive (
|
|
2739
|
-
// 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).
|
|
2740
3090
|
const inFlight = inFlightIds(rows);
|
|
2741
3091
|
if (!inFlight.length) {
|
|
2742
3092
|
out('nothing in flight from this session — /tasks to list; a finished task cannot be cancelled\n');
|
|
@@ -2790,7 +3140,7 @@ async function sessionRepl(s, ask, irq, ctx) {
|
|
|
2790
3140
|
if (id && !s.client?.cancelTask) {
|
|
2791
3141
|
// An id was asked for but this image has no task-level cancel: do
|
|
2792
3142
|
// NOT silently interrupt "whatever is running" instead — but on
|
|
2793
|
-
//
|
|
3143
|
+
// 0g-harness and prime the agent-wide interrupt DOES stop the running turn,
|
|
2794
3144
|
// so point there instead of claiming nothing can be done.
|
|
2795
3145
|
out(s.client?.interrupt
|
|
2796
3146
|
? '(this agent image has no per-task cancel — the bridge interrupt stops the current running turn; try /cancel with no id)\n'
|
|
@@ -2813,6 +3163,50 @@ async function sessionRepl(s, ask, irq, ctx) {
|
|
|
2813
3163
|
out(r.aborted ? '⏹ stopped the running turn\n' : `(nothing to stop, or: ${r.note ?? 'not supported'})\n`);
|
|
2814
3164
|
continue;
|
|
2815
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
|
+
}
|
|
2816
3210
|
if (line.startsWith('/')) {
|
|
2817
3211
|
out(`unknown command ${line}\n${L2_HELP}\n`);
|
|
2818
3212
|
continue;
|
|
@@ -2836,7 +3230,7 @@ async function sessionRepl(s, ask, irq, ctx) {
|
|
|
2836
3230
|
}
|
|
2837
3231
|
messages.push({ role: 'user', content: line });
|
|
2838
3232
|
// `model` is a per-framework selector some gateways require (openclaw
|
|
2839
|
-
// does; the
|
|
3233
|
+
// does; 0g-harness and the prime bridge ignore it). Send it when known, omit it
|
|
2840
3234
|
// otherwise — and only if the framework rejects that, ask once and retry.
|
|
2841
3235
|
let retriedWithPick = false;
|
|
2842
3236
|
for (;;) {
|
|
@@ -2881,7 +3275,7 @@ async function sessionRepl(s, ask, irq, ctx) {
|
|
|
2881
3275
|
const onActivity = process.stdout.isTTY
|
|
2882
3276
|
? (label) => {
|
|
2883
3277
|
// "did work this turn" detector, across bridges' label dialects:
|
|
2884
|
-
//
|
|
3278
|
+
// 0g-harness "tool/call bash", prime "tool_execution_start — bash" /
|
|
2885
3279
|
// "bash_command_start", hermes "tool/call web_search". Thinking
|
|
2886
3280
|
// alone doesn't count — a think-only turn with no output is still
|
|
2887
3281
|
// a failure worth reporting.
|
|
@@ -2995,7 +3389,7 @@ async function sessionRepl(s, ask, irq, ctx) {
|
|
|
2995
3389
|
continue; // retry the same user message once with the selector
|
|
2996
3390
|
}
|
|
2997
3391
|
// A turn that ran tools but produced no text is WORK, not failure —
|
|
2998
|
-
//
|
|
3392
|
+
// 0g-harness agents legitimately end tool-only turns silently. Say what
|
|
2999
3393
|
// happened instead of crying wolf (the true-failure path — no deltas,
|
|
3000
3394
|
// no activity — still reports as an error).
|
|
3001
3395
|
// Displaced by another window (occupancy.go): WeChat semantics — this
|
|
@@ -3029,6 +3423,7 @@ async function sessionRepl(s, ask, irq, ctx) {
|
|
|
3029
3423
|
}
|
|
3030
3424
|
finally {
|
|
3031
3425
|
irq.brake = null; // leaving the session: idle-Esc no longer targets this agent
|
|
3426
|
+
inbox.stop();
|
|
3032
3427
|
}
|
|
3033
3428
|
}
|
|
3034
3429
|
//# sourceMappingURL=interactive.js.map
|