@hanzo/build 0.2.121 → 0.2.123
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/lib/api/cli.d.ts +59 -0
- package/lib/api/cli.js +133 -0
- package/lib/api/sessions.d.ts +13 -0
- package/lib/api/sessions.js +23 -2
- package/lib/api/talk.d.ts +44 -0
- package/lib/api/talk.js +71 -0
- package/lib/api/turn.d.ts +29 -3
- package/lib/api/turn.js +121 -5
- package/lib/builder.js +2 -2
- package/lib/data.d.ts +4 -2
- package/lib/data.js +43 -10
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -1
- package/lib/landing.js +15 -14
- package/lib/mind.d.ts +2 -0
- package/lib/mind.js +28 -1
- package/lib/project.js +4 -1
- package/lib/run.d.ts +1 -0
- package/lib/run.js +30 -5
- package/lib/section.d.ts +5 -0
- package/lib/section.js +7 -1
- package/lib/shelf.js +5 -4
- package/lib/talk.d.ts +5 -0
- package/lib/talk.js +104 -0
- package/lib/transcript.d.ts +5 -1
- package/lib/transcript.js +15 -4
- package/package.json +1 -1
package/lib/api/cli.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** One action a command performs, as the agent parses it (exec's `command_actions`). */
|
|
2
|
+
export type Action = {
|
|
3
|
+
type: 'read';
|
|
4
|
+
command: string;
|
|
5
|
+
name: string;
|
|
6
|
+
path: string;
|
|
7
|
+
} | {
|
|
8
|
+
type: 'listFiles';
|
|
9
|
+
command: string;
|
|
10
|
+
path: string | null;
|
|
11
|
+
} | {
|
|
12
|
+
type: 'search';
|
|
13
|
+
command: string;
|
|
14
|
+
query: string | null;
|
|
15
|
+
path: string | null;
|
|
16
|
+
} | {
|
|
17
|
+
type: 'unknown';
|
|
18
|
+
command: string;
|
|
19
|
+
};
|
|
20
|
+
/** One call in an Explored block: what it did, and how it exited (null while it runs). */
|
|
21
|
+
export interface Explore {
|
|
22
|
+
actions: Action[];
|
|
23
|
+
exit: number | null;
|
|
24
|
+
}
|
|
25
|
+
/** One line of an Explored block: the CLI's verb, and what it names. */
|
|
26
|
+
export interface Line {
|
|
27
|
+
title: string;
|
|
28
|
+
text: string;
|
|
29
|
+
}
|
|
30
|
+
/** One file of a patch, with the lines it adds and removes — null from a `dev` too old to count them. */
|
|
31
|
+
export interface Changed {
|
|
32
|
+
path: string;
|
|
33
|
+
kind: 'add' | 'delete' | 'update';
|
|
34
|
+
added: number | null;
|
|
35
|
+
removed: number | null;
|
|
36
|
+
}
|
|
37
|
+
/** A file's line counts as the CLI writes them, "(+a -r)", or nothing when they were not counted. */
|
|
38
|
+
export declare const counted: (f: Pick<Changed, 'added' | 'removed'>) => string;
|
|
39
|
+
/** A command's actions as exec's stream states them; anything it does not name is not one. */
|
|
40
|
+
export declare function actions(raw: unknown): Action[];
|
|
41
|
+
/** Whether a call is exploration: it read, listed or searched, and did nothing else. */
|
|
42
|
+
export declare const explores: (a: Action[]) => boolean;
|
|
43
|
+
/**
|
|
44
|
+
* An Explored block's lines, as the CLI writes them: a call that only read, and the
|
|
45
|
+
* reads that follow it, are one "Read" line naming each file once; any other call
|
|
46
|
+
* says each action on a line of its own. A call that exited non-zero says so on its
|
|
47
|
+
* last line — "(command exit N)" for a compound command.
|
|
48
|
+
*/
|
|
49
|
+
export declare function explored(calls: Explore[]): Line[];
|
|
50
|
+
/**
|
|
51
|
+
* A command as the CLI shows it: a shell's own wrapper (`bash -lc '…'`) taken off,
|
|
52
|
+
* the script it ran left. exec's stream joins the argv as a shell would (shlex), so
|
|
53
|
+
* the script is the wrapper's last word, unquoted.
|
|
54
|
+
*/
|
|
55
|
+
export declare function shown(command: string): string;
|
|
56
|
+
/** A patch's header, as the CLI writes it: one file named with its verb, or the count of files. */
|
|
57
|
+
export declare function edited(files: Changed[]): string;
|
|
58
|
+
/** An MCP call as the CLI names it: server.tool(arguments), the arguments as compact JSON. */
|
|
59
|
+
export declare const called: (server: string, tool: string, args: unknown) => string;
|
package/lib/api/cli.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A run's tool calls as `dev` prints them in its terminal (hanzoai/dev, the TUI's
|
|
3
|
+
* exec, patch and MCP cells): the run IS `dev exec`, so its transcript reads in
|
|
4
|
+
* the CLI's own words and groups —
|
|
5
|
+
*
|
|
6
|
+
* • Explored reads, listings and searches, consecutive ones in one block
|
|
7
|
+
* └ Search widget in src one line an action
|
|
8
|
+
* Read lib.rs, main.rs consecutive reads, one line, each name once
|
|
9
|
+
* • Ran cargo test any other command, the shell's own wrapper taken off
|
|
10
|
+
* └ ok
|
|
11
|
+
* • Edited lib.rs (+2 -1) a patch: Added / Deleted / Edited, or "Edited N files (+a -r)"
|
|
12
|
+
* • Called hanzo.search({"q":1}) an MCP tool, server.tool(arguments)
|
|
13
|
+
*
|
|
14
|
+
* What a command does is the agent's own parse of it (`command_actions` in exec's
|
|
15
|
+
* stream), and the lines a patch adds and removes are its own count (`added`,
|
|
16
|
+
* `removed`): nothing here parses a command or a diff. Running, a block says
|
|
17
|
+
* Exploring, Running or Calling, as the CLI does.
|
|
18
|
+
*/
|
|
19
|
+
import { phrase } from '@hanzo/i18n';
|
|
20
|
+
/** A file's line counts as the CLI writes them, "(+a -r)", or nothing when they were not counted. */
|
|
21
|
+
export const counted = (f) => (f.added === null || f.removed === null ? '' : `(+${f.added} -${f.removed})`);
|
|
22
|
+
const str = (v) => (typeof v === 'string' ? v : '');
|
|
23
|
+
const nullable = (v) => (typeof v === 'string' ? v : null);
|
|
24
|
+
/** A command's actions as exec's stream states them; anything it does not name is not one. */
|
|
25
|
+
export function actions(raw) {
|
|
26
|
+
if (!Array.isArray(raw))
|
|
27
|
+
return [];
|
|
28
|
+
return raw.flatMap((a) => {
|
|
29
|
+
const o = a && typeof a === 'object' ? a : {};
|
|
30
|
+
switch (o.type) {
|
|
31
|
+
case 'read':
|
|
32
|
+
return [{ type: 'read', command: str(o.command), name: str(o.name), path: str(o.path) }];
|
|
33
|
+
case 'listFiles':
|
|
34
|
+
return [{ type: 'listFiles', command: str(o.command), path: nullable(o.path) }];
|
|
35
|
+
case 'search':
|
|
36
|
+
return [{ type: 'search', command: str(o.command), query: nullable(o.query), path: nullable(o.path) }];
|
|
37
|
+
case 'unknown':
|
|
38
|
+
return [{ type: 'unknown', command: str(o.command) }];
|
|
39
|
+
}
|
|
40
|
+
return [];
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/** Whether a call is exploration: it read, listed or searched, and did nothing else. */
|
|
44
|
+
export const explores = (a) => a.length > 0 && a.every((x) => x.type !== 'unknown');
|
|
45
|
+
/**
|
|
46
|
+
* An Explored block's lines, as the CLI writes them: a call that only read, and the
|
|
47
|
+
* reads that follow it, are one "Read" line naming each file once; any other call
|
|
48
|
+
* says each action on a line of its own. A call that exited non-zero says so on its
|
|
49
|
+
* last line — "(command exit N)" for a compound command.
|
|
50
|
+
*/
|
|
51
|
+
export function explored(calls) {
|
|
52
|
+
const out = [];
|
|
53
|
+
const failed = (c) => c.exit !== null && c.exit !== 0;
|
|
54
|
+
const reads = (c) => c.actions.every((a) => a.type === 'read');
|
|
55
|
+
for (let i = 0; i < calls.length;) {
|
|
56
|
+
const call = calls[i];
|
|
57
|
+
let n = 1;
|
|
58
|
+
if (reads(call) && !failed(call))
|
|
59
|
+
while (i + n < calls.length && !failed(calls[i + n]) && reads(calls[i + n]))
|
|
60
|
+
n++;
|
|
61
|
+
const group = calls.slice(i, i + n);
|
|
62
|
+
i += n;
|
|
63
|
+
const lines = reads(call)
|
|
64
|
+
? [{ title: phrase('Read'), text: [...new Set(group.flatMap((c) => c.actions.map((a) => (a.type === 'read' ? a.name : ''))))].join(', ') }]
|
|
65
|
+
: call.actions.map((a) => {
|
|
66
|
+
switch (a.type) {
|
|
67
|
+
case 'read':
|
|
68
|
+
return { title: phrase('Read'), text: a.name };
|
|
69
|
+
case 'listFiles':
|
|
70
|
+
return { title: phrase('List'), text: a.path ?? a.command };
|
|
71
|
+
case 'search':
|
|
72
|
+
return { title: phrase('Search'), text: a.query !== null && a.path !== null ? `${a.query} in ${a.path}` : (a.query ?? a.command) };
|
|
73
|
+
default:
|
|
74
|
+
return { title: phrase('Run'), text: a.command };
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
if (failed(call)) {
|
|
78
|
+
const last = lines[lines.length - 1];
|
|
79
|
+
last.text += call.actions.length > 1 ? ` (command exit ${call.exit})` : ` (exit ${call.exit})`;
|
|
80
|
+
}
|
|
81
|
+
out.push(...lines);
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* A command as the CLI shows it: a shell's own wrapper (`bash -lc '…'`) taken off,
|
|
87
|
+
* the script it ran left. exec's stream joins the argv as a shell would (shlex), so
|
|
88
|
+
* the script is the wrapper's last word, unquoted.
|
|
89
|
+
*/
|
|
90
|
+
export function shown(command) {
|
|
91
|
+
const m = /^(?:\S*\/)?(?:bash|zsh|sh)\s+-l?c\s+(.+)$/s.exec(command.trim());
|
|
92
|
+
return m ? unquote(m[1]) : command;
|
|
93
|
+
}
|
|
94
|
+
/** One shell word, its quoting taken off: single quotes, double quotes and backslashes. */
|
|
95
|
+
function unquote(word) {
|
|
96
|
+
let out = '';
|
|
97
|
+
for (let i = 0; i < word.length; i++) {
|
|
98
|
+
const c = word[i];
|
|
99
|
+
if (c === "'") {
|
|
100
|
+
const end = word.indexOf("'", i + 1);
|
|
101
|
+
if (end < 0)
|
|
102
|
+
return word;
|
|
103
|
+
out += word.slice(i + 1, end);
|
|
104
|
+
i = end;
|
|
105
|
+
}
|
|
106
|
+
else if (c === '"') {
|
|
107
|
+
let j = i + 1;
|
|
108
|
+
for (; j < word.length && word[j] !== '"'; j++)
|
|
109
|
+
out += word[j] === '\\' && j + 1 < word.length ? word[++j] : word[j];
|
|
110
|
+
i = j;
|
|
111
|
+
}
|
|
112
|
+
else if (c === '\\' && i + 1 < word.length)
|
|
113
|
+
out += word[++i];
|
|
114
|
+
else if (/\s/.test(c))
|
|
115
|
+
return word; // more than one word: not one script
|
|
116
|
+
else
|
|
117
|
+
out += c;
|
|
118
|
+
}
|
|
119
|
+
return out;
|
|
120
|
+
}
|
|
121
|
+
/** A patch's header, as the CLI writes it: one file named with its verb, or the count of files. */
|
|
122
|
+
export function edited(files) {
|
|
123
|
+
if (files.length === 1) {
|
|
124
|
+
const [f] = files;
|
|
125
|
+
const verb = f.kind === 'add' ? 'Added' : f.kind === 'delete' ? 'Deleted' : 'Edited';
|
|
126
|
+
return `${verb} ${f.path} ${counted(f)}`.trim();
|
|
127
|
+
}
|
|
128
|
+
const known = files.every((f) => f.added !== null && f.removed !== null);
|
|
129
|
+
const total = known ? { added: files.reduce((n, f) => n + f.added, 0), removed: files.reduce((n, f) => n + f.removed, 0) } : { added: null, removed: null };
|
|
130
|
+
return `Edited ${files.length} ${files.length === 1 ? 'file' : 'files'} ${counted(total)}`.trim();
|
|
131
|
+
}
|
|
132
|
+
/** An MCP call as the CLI names it: server.tool(arguments), the arguments as compact JSON. */
|
|
133
|
+
export const called = (server, tool, args) => `${server}.${tool}(${args === undefined || args === null ? '' : JSON.stringify(args)})`;
|
package/lib/api/sessions.d.ts
CHANGED
|
@@ -27,6 +27,12 @@ export interface Session {
|
|
|
27
27
|
org: string;
|
|
28
28
|
/** Whether its story is open to the public build route. Only a run that names a project can be. */
|
|
29
29
|
published: boolean;
|
|
30
|
+
/** Where it was started: 'app' for a conversation in Dev (talk.ts), '' for a run on its own. */
|
|
31
|
+
channel: string;
|
|
32
|
+
/** The session it belongs to — a conversation, for the coding runs it started — or ''. */
|
|
33
|
+
parent: string;
|
|
34
|
+
/** The top of its tree: its own id for a session of its own. A stream is followed by it. */
|
|
35
|
+
root: string;
|
|
30
36
|
events: number;
|
|
31
37
|
createdAt: string;
|
|
32
38
|
updatedAt: string;
|
|
@@ -53,6 +59,8 @@ export declare function event(raw: unknown): Event;
|
|
|
53
59
|
export declare function took(runs: Session[], mode: string): [number, number] | null;
|
|
54
60
|
export interface ListQuery {
|
|
55
61
|
kind?: string;
|
|
62
|
+
/** The sessions started on one channel: 'app' for Dev's conversations. */
|
|
63
|
+
channel?: string;
|
|
56
64
|
project?: string;
|
|
57
65
|
/** running, paused, done or error: the four the platform filters on. */
|
|
58
66
|
status?: string;
|
|
@@ -68,6 +76,11 @@ export interface Page {
|
|
|
68
76
|
export declare function page(t: Target, q?: ListQuery): Promise<Page>;
|
|
69
77
|
export declare function list(t: Target, q?: ListQuery): Promise<Session[]>;
|
|
70
78
|
export declare function get(t: Target, id: string): Promise<Detail>;
|
|
79
|
+
/**
|
|
80
|
+
* A session's whole log, oldest first, read a page at a time — what a conversation
|
|
81
|
+
* draws from its first word, where the detail carries only the latest fifty.
|
|
82
|
+
*/
|
|
83
|
+
export declare function log(t: Target, id: string): Promise<Event[]>;
|
|
71
84
|
export declare function message(t: Target, id: string, text: string): Promise<void>;
|
|
72
85
|
export declare function stop(t: Target, id: string, why?: string): Promise<void>;
|
|
73
86
|
export declare function pause(t: Target, id: string): Promise<void>;
|
package/lib/api/sessions.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Runs, as the platform records them: one session per run
|
|
2
|
+
* Runs, as the platform records them: one session per run — and Dev's
|
|
3
|
+
* conversations (talk.ts), one session for every turn.
|
|
3
4
|
*
|
|
4
|
-
* GET /v1/agent/sessions?kind=&project=&status=&limit=&after= newest first, {sessions, next}
|
|
5
|
+
* GET /v1/agent/sessions?kind=&channel=&project=&status=&limit=&after= newest first, {sessions, next}
|
|
5
6
|
* GET /v1/agent/sessions/{id} + the 50 most recent events
|
|
7
|
+
* GET /v1/agent/sessions/{id}/events?after=&limit= its whole log, a page at a time, {events, next}
|
|
6
8
|
* PATCH /v1/agent/sessions/{id} {title}|{published} rename it; open its story to the public build route
|
|
7
9
|
* POST /v1/agent/sessions/{id}/message {message} steer a running run
|
|
8
10
|
* POST /v1/agent/sessions/{id}/pause pause it; a sandbox run keeps its work on its branch
|
|
@@ -41,6 +43,9 @@ export function session(raw) {
|
|
|
41
43
|
sandbox: str(s.sandbox),
|
|
42
44
|
org: str(s.org),
|
|
43
45
|
published: s.published === true,
|
|
46
|
+
channel: str(s.channel),
|
|
47
|
+
parent: str(s.parentSessionId),
|
|
48
|
+
root: str(s.rootSessionId),
|
|
44
49
|
events: num(s.events),
|
|
45
50
|
createdAt: str(s.createdAt),
|
|
46
51
|
updatedAt: str(s.updatedAt),
|
|
@@ -106,6 +111,22 @@ export async function get(t, id) {
|
|
|
106
111
|
recent,
|
|
107
112
|
};
|
|
108
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* A session's whole log, oldest first, read a page at a time — what a conversation
|
|
116
|
+
* draws from its first word, where the detail carries only the latest fifty.
|
|
117
|
+
*/
|
|
118
|
+
export async function log(t, id) {
|
|
119
|
+
const out = [];
|
|
120
|
+
let after = 0;
|
|
121
|
+
for (;;) {
|
|
122
|
+
const raw = obj(await call(t, 'GET', `/v1/agent/sessions/${seg(id)}/events${query({ after: after || undefined, limit: 1000 })}`));
|
|
123
|
+
out.push(...(Array.isArray(raw.events) ? raw.events : []).map(event));
|
|
124
|
+
const next = num(raw.next);
|
|
125
|
+
if (next <= after)
|
|
126
|
+
return out;
|
|
127
|
+
after = next;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
109
130
|
export async function message(t, id, text) {
|
|
110
131
|
const m = text.trim();
|
|
111
132
|
if (!m)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Target } from './call.ts';
|
|
2
|
+
import type { Event, Session } from './sessions.ts';
|
|
3
|
+
/** The channel a conversation's session is on. */
|
|
4
|
+
export declare const TALK = "app";
|
|
5
|
+
/**
|
|
6
|
+
* Whether a session is a conversation, rather than one run. A conversation's runs
|
|
7
|
+
* are on its channel too — born in its tree, its person's alone — and are told
|
|
8
|
+
* from it by having a parent: the conversation is the root.
|
|
9
|
+
*/
|
|
10
|
+
export declare const talks: (s: Pick<Session, 'channel' | 'parent'> | null | undefined) => boolean;
|
|
11
|
+
export interface Say {
|
|
12
|
+
/** The conversation to continue. Absent starts one. */
|
|
13
|
+
session?: string;
|
|
14
|
+
/** What the person said. */
|
|
15
|
+
input: string;
|
|
16
|
+
/** The model, by the id GET /v1/models lists. */
|
|
17
|
+
model?: string;
|
|
18
|
+
/** The repository: its name in the org, or owner/name on GitHub. */
|
|
19
|
+
repo?: string;
|
|
20
|
+
/** The branch a coding run starts from. */
|
|
21
|
+
base?: string;
|
|
22
|
+
/** One of the org's machines. Absent is the sandbox. */
|
|
23
|
+
target?: string;
|
|
24
|
+
/** How the conversation's coding runs go: on their own, asked for first, or plans only. */
|
|
25
|
+
mode?: 'auto' | 'manual' | 'plan';
|
|
26
|
+
/** How hard a coding run thinks: low, medium or high. */
|
|
27
|
+
effort?: string;
|
|
28
|
+
/** The issue on `repo` a coding run resolves. */
|
|
29
|
+
issue?: number;
|
|
30
|
+
}
|
|
31
|
+
export interface Said {
|
|
32
|
+
/** The conversation: the same id on every turn. */
|
|
33
|
+
session: string;
|
|
34
|
+
/** This turn's run within it. */
|
|
35
|
+
run: string;
|
|
36
|
+
}
|
|
37
|
+
/** The request body: only what was said, with no empty values sent. */
|
|
38
|
+
export declare function body(s: Say): Record<string, string | number | boolean>;
|
|
39
|
+
/** Say one thing in a conversation: a new one without `session`, that one with it. */
|
|
40
|
+
export declare function say(t: Target, s: Say): Promise<Said>;
|
|
41
|
+
/** What a conversation's turn is doing now: its latest progress line, or ''. */
|
|
42
|
+
export declare function now(events: Pick<Event, 'kind' | 'payload' | 'seq'>[]): string;
|
|
43
|
+
/** Answer a question a session's run asked: an option pressed, or the person's own words. */
|
|
44
|
+
export declare function answer(t: Target, session: string, question: string, text: string, chosen: boolean): Promise<void>;
|
package/lib/api/talk.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dev's conversation, as the platform keeps it (apps/agents talk.go): one
|
|
3
|
+
* session, every turn.
|
|
4
|
+
*
|
|
5
|
+
* POST /v1/agent/turns {session?, input, model?, effort?, repo?, base?, target?, mode?, issue?}
|
|
6
|
+
* → {sessionId, runId}
|
|
7
|
+
* POST /v1/agent/sessions/{id}/answer {question, text, chosen} answer what a turn asked
|
|
8
|
+
*
|
|
9
|
+
* The first thing said opens the conversation; everything said after continues
|
|
10
|
+
* the SAME session under a new run, once its last turn has answered — what is said
|
|
11
|
+
* while a turn still works is that turn's next input (sessions.ts `message`). The
|
|
12
|
+
* agent answers, and decides for itself when a turn needs a sandbox (leased on its
|
|
13
|
+
* first use, kept for the conversation) or a coding run (which carries on the
|
|
14
|
+
* conversation's last, in its sandbox and on its branch). A turn that only talks
|
|
15
|
+
* uses neither, and a turn ends when its answer does: a build it started is
|
|
16
|
+
* followed after, and its outcome is said into the conversation when it ends.
|
|
17
|
+
*
|
|
18
|
+
* The repository, branch, machine and mode are kept on the conversation from the
|
|
19
|
+
* first message: every coding run its turns start works on them, auto starts it,
|
|
20
|
+
* manual asks first (a question answered here), plan only reads and plans. The
|
|
21
|
+
* model and effort ride each turn. Between turns the session rests `paused`.
|
|
22
|
+
*/
|
|
23
|
+
import { phrase } from '@hanzo/i18n';
|
|
24
|
+
import { call, Refusal, seg } from './call.js';
|
|
25
|
+
import { decode } from './turn.js';
|
|
26
|
+
/** The channel a conversation's session is on. */
|
|
27
|
+
export const TALK = 'app';
|
|
28
|
+
/**
|
|
29
|
+
* Whether a session is a conversation, rather than one run. A conversation's runs
|
|
30
|
+
* are on its channel too — born in its tree, its person's alone — and are told
|
|
31
|
+
* from it by having a parent: the conversation is the root.
|
|
32
|
+
*/
|
|
33
|
+
export const talks = (s) => s?.channel === TALK && !s.parent;
|
|
34
|
+
/** The request body: only what was said, with no empty values sent. */
|
|
35
|
+
export function body(s) {
|
|
36
|
+
const out = { input: s.input.trim() };
|
|
37
|
+
for (const k of ['session', 'model', 'effort', 'repo', 'base', 'target', 'mode']) {
|
|
38
|
+
const v = s[k]?.trim();
|
|
39
|
+
if (v)
|
|
40
|
+
out[k] = v;
|
|
41
|
+
}
|
|
42
|
+
if (s.issue && Number.isInteger(s.issue) && s.issue > 0)
|
|
43
|
+
out.issue = s.issue;
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
/** Say one thing in a conversation: a new one without `session`, that one with it. */
|
|
47
|
+
export async function say(t, s) {
|
|
48
|
+
if (!s.input.trim())
|
|
49
|
+
throw new Refusal(400, phrase('Say something'));
|
|
50
|
+
const r = await call(t, 'POST', '/v1/agent/turns', body(s));
|
|
51
|
+
const session = typeof r?.sessionId === 'string' ? r.sessionId : '';
|
|
52
|
+
if (!session)
|
|
53
|
+
throw new Refusal(502, phrase('The conversation answered with no session'));
|
|
54
|
+
return { session, run: typeof r?.runId === 'string' ? r.runId : '' };
|
|
55
|
+
}
|
|
56
|
+
/** What a conversation's turn is doing now: its latest progress line, or ''. */
|
|
57
|
+
export function now(events) {
|
|
58
|
+
let doing = '';
|
|
59
|
+
for (const e of [...events].sort((a, b) => a.seq - b.seq)) {
|
|
60
|
+
const b = decode(e.payload);
|
|
61
|
+
if (e.kind === 'progress' && b && typeof b !== 'string' && typeof b.activity === 'string')
|
|
62
|
+
doing = b.activity;
|
|
63
|
+
}
|
|
64
|
+
return doing;
|
|
65
|
+
}
|
|
66
|
+
/** Answer a question a session's run asked: an option pressed, or the person's own words. */
|
|
67
|
+
export async function answer(t, session, question, text, chosen) {
|
|
68
|
+
if (!text.trim())
|
|
69
|
+
throw new Refusal(400, phrase('Say an answer'));
|
|
70
|
+
await call(t, 'POST', `/v1/agent/sessions/${seg(session)}/answer`, { question, text: text.trim(), chosen });
|
|
71
|
+
}
|
package/lib/api/turn.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Say } from '@hanzo/i18n/react';
|
|
2
|
+
import { type Changed, type Explore } from './cli.ts';
|
|
2
3
|
import type { Event } from './sessions.ts';
|
|
3
4
|
/** The payload as an object. A live frame may carry it as a JSON string. */
|
|
4
5
|
export declare function decode(payload: unknown): Record<string, unknown> | string | null;
|
|
@@ -91,12 +92,15 @@ export type Ran = 'running' | 'done' | 'error' | 'cancelled';
|
|
|
91
92
|
*
|
|
92
93
|
* said prose: the agent's messages (markdown), or a person's steering words
|
|
93
94
|
* think the agent's reasoning, folded until opened
|
|
94
|
-
* shell a command the agent ran, and what it printed
|
|
95
|
-
*
|
|
95
|
+
* shell a command the agent ran, and what it printed: the CLI's "Ran"
|
|
96
|
+
* explore reads, listings and searches, consecutive ones together: the CLI's "Explored"
|
|
97
|
+
* edit files the agent changed, with the lines each adds and removes; the diff is the run's Git tab
|
|
96
98
|
* step a step of the run itself (lease, clone, install, push), or a tool the agent called
|
|
97
99
|
* todo the agent's plan, as a checklist it ticks
|
|
98
100
|
* note a lifecycle line: started, pushed, stopped
|
|
99
101
|
* plan a plan run's answer, which can be approved into a build
|
|
102
|
+
* run a coding run a conversation's turn started (talk.ts), opened on its own page
|
|
103
|
+
* ask a question the run asked its person, with its options, and the answer once given
|
|
100
104
|
*/
|
|
101
105
|
export type Card = {
|
|
102
106
|
kind: 'said';
|
|
@@ -113,10 +117,15 @@ export type Card = {
|
|
|
113
117
|
command: string;
|
|
114
118
|
output: string;
|
|
115
119
|
ran: Ran;
|
|
120
|
+
} | {
|
|
121
|
+
kind: 'explore';
|
|
122
|
+
key: string;
|
|
123
|
+
calls: Explore[];
|
|
124
|
+
ran: Ran;
|
|
116
125
|
} | {
|
|
117
126
|
kind: 'edit';
|
|
118
127
|
key: string;
|
|
119
|
-
files:
|
|
128
|
+
files: Changed[];
|
|
120
129
|
ran: Ran;
|
|
121
130
|
} | {
|
|
122
131
|
kind: 'step';
|
|
@@ -140,6 +149,17 @@ export type Card = {
|
|
|
140
149
|
kind: 'plan';
|
|
141
150
|
key: string;
|
|
142
151
|
text: string;
|
|
152
|
+
} | {
|
|
153
|
+
kind: 'run';
|
|
154
|
+
key: string;
|
|
155
|
+
session: string;
|
|
156
|
+
} | {
|
|
157
|
+
kind: 'ask';
|
|
158
|
+
key: string;
|
|
159
|
+
question: string;
|
|
160
|
+
text: string;
|
|
161
|
+
options: string[];
|
|
162
|
+
answer: string;
|
|
143
163
|
};
|
|
144
164
|
/**
|
|
145
165
|
* A run's events, as the cards its transcript draws. `mode` is the run's, from
|
|
@@ -155,6 +175,12 @@ export type Card = {
|
|
|
155
175
|
* answer, drawn once. `log` is never drawn here.
|
|
156
176
|
*/
|
|
157
177
|
export declare function cards(events: Pick<Event, 'kind' | 'payload' | 'seq'>[], mode?: string, t?: Say): Card[];
|
|
178
|
+
/**
|
|
179
|
+
* Cards as the CLI prints them, line for line: what a run's transcript reads as in
|
|
180
|
+
* `dev`'s terminal. The transcript draws the same words (transcript.tsx); this is
|
|
181
|
+
* them as text, which the parity tests hold to the CLI's own.
|
|
182
|
+
*/
|
|
183
|
+
export declare function printed(cards: Card[], live?: boolean): string;
|
|
158
184
|
/** The plan a plan run answered with, from its final status, or ''. */
|
|
159
185
|
export declare function answer(events: Pick<Event, 'kind' | 'payload' | 'seq'>[]): string;
|
|
160
186
|
export interface Settled {
|
package/lib/api/turn.js
CHANGED
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
*/
|
|
30
30
|
import { phrase } from '@hanzo/i18n';
|
|
31
31
|
import { english } from '../say.js';
|
|
32
|
+
import { actions, called, counted, edited, explored, explores, shown } from './cli.js';
|
|
32
33
|
const str = (v) => (typeof v === 'string' ? v : '');
|
|
33
34
|
const obj = (v) => (v && typeof v === 'object' ? v : {});
|
|
34
35
|
/** The payload as an object. A live frame may carry it as a JSON string. */
|
|
@@ -339,14 +340,37 @@ function item(it, key) {
|
|
|
339
340
|
return str(it.text) ? { kind: 'said', key, who: 'agent', text: str(it.text) } : null;
|
|
340
341
|
case 'reasoning':
|
|
341
342
|
return str(it.text) ? { kind: 'think', key, text: str(it.text) } : null;
|
|
342
|
-
case 'command_execution':
|
|
343
|
-
|
|
343
|
+
case 'command_execution': {
|
|
344
|
+
// What the command did is the agent's own parse of it (cli.ts): exploration, or a command it ran.
|
|
345
|
+
const did = actions(it.command_actions);
|
|
346
|
+
if (explores(did))
|
|
347
|
+
return { kind: 'explore', key, calls: [{ actions: did, exit: typeof it.exit_code === 'number' ? it.exit_code : null }], ran: itemRan(it) };
|
|
348
|
+
return { kind: 'shell', key, command: shown(str(it.command)), output: str(it.aggregated_output), ran: itemRan(it) };
|
|
349
|
+
}
|
|
344
350
|
case 'file_change': {
|
|
345
351
|
const changes = Array.isArray(it.changes) ? it.changes : [];
|
|
346
|
-
|
|
352
|
+
const files = changes
|
|
353
|
+
.map((c) => {
|
|
354
|
+
const o = obj(c);
|
|
355
|
+
const kind = o.kind === 'add' || o.kind === 'delete' ? o.kind : 'update';
|
|
356
|
+
const n = (v) => (typeof v === 'number' ? v : null);
|
|
357
|
+
return { path: rel(str(o.path)), kind, added: n(o.added), removed: n(o.removed) };
|
|
358
|
+
})
|
|
359
|
+
.filter((f) => f.path);
|
|
360
|
+
return { kind: 'edit', key, files, ran: itemRan(it) };
|
|
361
|
+
}
|
|
362
|
+
case 'mcp_tool_call': {
|
|
363
|
+
const ran = itemRan(it);
|
|
364
|
+
const said = Array.isArray(obj(it.result).content) ? obj(it.result).content.map((c) => str(obj(c).text)).filter(Boolean).join('\n') : '';
|
|
365
|
+
return {
|
|
366
|
+
kind: 'step',
|
|
367
|
+
key,
|
|
368
|
+
name: ran === 'running' ? phrase('Calling') : phrase('Called'),
|
|
369
|
+
detail: called(str(it.server), str(it.tool), it.arguments),
|
|
370
|
+
output: str(obj(it.error).message) || said,
|
|
371
|
+
ran,
|
|
372
|
+
};
|
|
347
373
|
}
|
|
348
|
-
case 'mcp_tool_call':
|
|
349
|
-
return { kind: 'step', key, name: str(it.tool) || phrase('Tool'), detail: str(it.server), output: '', ran: itemRan(it) };
|
|
350
374
|
case 'web_search':
|
|
351
375
|
return { kind: 'step', key, name: phrase('Search'), detail: str(it.query), output: '', ran: 'done' };
|
|
352
376
|
case 'todo_list': {
|
|
@@ -386,6 +410,8 @@ export function cards(events, mode = '', t = english) {
|
|
|
386
410
|
return c;
|
|
387
411
|
};
|
|
388
412
|
const failures = new Set();
|
|
413
|
+
const spawned = new Set();
|
|
414
|
+
const asked = new Map();
|
|
389
415
|
const failed = (message) => {
|
|
390
416
|
if (failures.has(message))
|
|
391
417
|
return;
|
|
@@ -461,6 +487,20 @@ export function cards(events, mode = '', t = english) {
|
|
|
461
487
|
phase = null;
|
|
462
488
|
if (!b)
|
|
463
489
|
break;
|
|
490
|
+
// A question the run asked its person (apps/agents ask.go), and its answer, drawn on the question.
|
|
491
|
+
if (str(b.status) === 'asked') {
|
|
492
|
+
const options = (Array.isArray(b.options) ? b.options : []).map((o) => str(obj(o).label)).filter(Boolean);
|
|
493
|
+
asked.set(str(b.question), out.length);
|
|
494
|
+
out.push({ kind: 'ask', key: mint(), question: str(b.question), text: str(b.text), options, answer: '' });
|
|
495
|
+
break;
|
|
496
|
+
}
|
|
497
|
+
if (str(b.status) === 'answered') {
|
|
498
|
+
const at = asked.get(str(b.question));
|
|
499
|
+
const card = at === undefined ? undefined : out[at];
|
|
500
|
+
if (card?.kind === 'ask')
|
|
501
|
+
out[at] = { ...card, answer: str(b.answer) };
|
|
502
|
+
break;
|
|
503
|
+
}
|
|
464
504
|
const done = str(b.status) === 'done';
|
|
465
505
|
const text = str(b.plan) || str(b.answer);
|
|
466
506
|
if (done && (mode === 'plan' || mode === 'setup') && text) {
|
|
@@ -507,6 +547,21 @@ export function cards(events, mode = '', t = english) {
|
|
|
507
547
|
out.push({ kind: 'said', key: mint(), who: 'agent', text });
|
|
508
548
|
break;
|
|
509
549
|
}
|
|
550
|
+
case 'spawn': {
|
|
551
|
+
// A conversation's turn started a coding run, or follows the one that carried it on.
|
|
552
|
+
const session = str(b?.session);
|
|
553
|
+
if (!session || spawned.has(session))
|
|
554
|
+
break;
|
|
555
|
+
spawned.add(session);
|
|
556
|
+
out.push({ kind: 'run', key: mint(), session });
|
|
557
|
+
break;
|
|
558
|
+
}
|
|
559
|
+
case 'log': {
|
|
560
|
+
// A conversation's turn that failed says why on its record of the run.
|
|
561
|
+
if (b && str(b.runId) && str(b.status) === 'error')
|
|
562
|
+
failed(str(b.error));
|
|
563
|
+
break;
|
|
564
|
+
}
|
|
510
565
|
}
|
|
511
566
|
}
|
|
512
567
|
// The answer a status carries is also the agent's last message: each is drawn once, as the answer.
|
|
@@ -523,8 +578,69 @@ export function cards(events, mode = '', t = english) {
|
|
|
523
578
|
const ask = out.findIndex((c) => c.kind === 'said' && c.who === 'person' && !steered.has(c));
|
|
524
579
|
if (ask > 0)
|
|
525
580
|
out.unshift(...out.splice(ask, 1));
|
|
581
|
+
return gather(out);
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Consecutive exploration as the CLI keeps it: one Explored block, open across the
|
|
585
|
+
* reads, listings and searches that follow each other — the agent's reasoning
|
|
586
|
+
* between them included, which stays where it was said, after the block.
|
|
587
|
+
*/
|
|
588
|
+
function gather(cards) {
|
|
589
|
+
const out = [];
|
|
590
|
+
let open = null;
|
|
591
|
+
for (const c of cards) {
|
|
592
|
+
if (c.kind === 'explore') {
|
|
593
|
+
if (open) {
|
|
594
|
+
open.calls = [...open.calls, ...c.calls];
|
|
595
|
+
if (c.ran === 'running')
|
|
596
|
+
open.ran = 'running';
|
|
597
|
+
continue;
|
|
598
|
+
}
|
|
599
|
+
open = { ...c, calls: [...c.calls] };
|
|
600
|
+
out.push(open);
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
if (c.kind !== 'think')
|
|
604
|
+
open = null;
|
|
605
|
+
out.push(c);
|
|
606
|
+
}
|
|
526
607
|
return out;
|
|
527
608
|
}
|
|
609
|
+
/**
|
|
610
|
+
* Cards as the CLI prints them, line for line: what a run's transcript reads as in
|
|
611
|
+
* `dev`'s terminal. The transcript draws the same words (transcript.tsx); this is
|
|
612
|
+
* them as text, which the parity tests hold to the CLI's own.
|
|
613
|
+
*/
|
|
614
|
+
export function printed(cards, live = false) {
|
|
615
|
+
const lines = [];
|
|
616
|
+
const under = (first, rest = ' ') => first.map((l, i) => `${i === 0 ? ' └ ' : rest}${l}`);
|
|
617
|
+
for (const c of cards) {
|
|
618
|
+
switch (c.kind) {
|
|
619
|
+
case 'explore':
|
|
620
|
+
lines.push(`• ${c.ran === 'running' && live ? 'Exploring' : 'Explored'}`, ...under(explored(c.calls).map((l) => `${l.title} ${l.text}`)));
|
|
621
|
+
break;
|
|
622
|
+
case 'shell': {
|
|
623
|
+
const output = c.output.replace(/\n+$/, '');
|
|
624
|
+
lines.push(`• ${c.ran === 'running' && live ? 'Running' : 'Ran'} ${c.command}`, ...under(output ? output.split('\n') : ['(no output)']));
|
|
625
|
+
break;
|
|
626
|
+
}
|
|
627
|
+
case 'edit':
|
|
628
|
+
lines.push(`• ${edited(c.files)}`);
|
|
629
|
+
if (c.files.length > 1)
|
|
630
|
+
lines.push(...c.files.map((f) => ` └ ${f.path} ${counted(f)}`.trimEnd()));
|
|
631
|
+
break;
|
|
632
|
+
case 'step':
|
|
633
|
+
if (c.name === 'Called' || c.name === 'Calling')
|
|
634
|
+
lines.push(`• ${c.name} ${c.detail}`);
|
|
635
|
+
break;
|
|
636
|
+
case 'said':
|
|
637
|
+
if (c.who === 'agent')
|
|
638
|
+
lines.push(`• ${c.text}`);
|
|
639
|
+
break;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
return lines.join('\n');
|
|
643
|
+
}
|
|
528
644
|
/** The plan a plan run answered with, from its final status, or ''. */
|
|
529
645
|
export function answer(events) {
|
|
530
646
|
let out = '';
|
package/lib/builder.js
CHANGED
|
@@ -48,7 +48,7 @@ import { Project } from './project.js';
|
|
|
48
48
|
import { Plans } from './plans.js';
|
|
49
49
|
import { path, route } from './route.js';
|
|
50
50
|
import { Run } from './run.js';
|
|
51
|
-
import {
|
|
51
|
+
import { dot } from './section.js';
|
|
52
52
|
import { Library } from './library.js';
|
|
53
53
|
import { Templates } from './shelf.js';
|
|
54
54
|
import { Find } from './find.js';
|
|
@@ -71,7 +71,7 @@ function Shell() {
|
|
|
71
71
|
host.go(p);
|
|
72
72
|
};
|
|
73
73
|
const rows = useMemo(() => {
|
|
74
|
-
const list = recents.value.map((s) => ({ id: s.id, title: s.title || say('Untitled run'), status:
|
|
74
|
+
const list = recents.value.map((s) => ({ id: s.id, title: s.title || say('Untitled run'), status: dot(s) }));
|
|
75
75
|
if (order === 'running')
|
|
76
76
|
list.sort((a, b) => Number(b.status === 'running') - Number(a.status === 'running'));
|
|
77
77
|
return list;
|
package/lib/data.d.ts
CHANGED
|
@@ -24,8 +24,10 @@ export declare class Slow extends Error {
|
|
|
24
24
|
*/
|
|
25
25
|
export declare function useCached<T>(key: string | null, load: (signal: AbortSignal) => Promise<T>, initial: T, wait?: number): Read<T>;
|
|
26
26
|
/**
|
|
27
|
-
* The org's coding runs, newest first, kept current by the
|
|
28
|
-
* stream: a status that moves moves its dot, and
|
|
27
|
+
* The org's conversations and coding runs, newest first, kept current by the
|
|
28
|
+
* org's own session stream: a status that moves moves its dot, and one started
|
|
29
|
+
* anywhere appears. A conversation's own coding runs are in its tree, not here:
|
|
30
|
+
* the platform lists roots.
|
|
29
31
|
*/
|
|
30
32
|
export declare function useRecents(t: Target, signed: boolean): Read<Session[]>;
|
|
31
33
|
export declare function usePlaces(t: Target, signed: boolean): Read<Place[]>;
|