@parcha/agentrun-kernel 0.1.0-beta.35 → 0.1.0-beta.37
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/CHANGELOG.md +45 -0
- package/README.md +0 -7
- package/dist/host/box.d.ts +0 -14
- package/dist/host/index.d.ts +1 -1
- package/dist/host/proxy.d.ts +20 -4
- package/dist/host/proxy.js +67 -5
- package/dist/index.d.ts +1 -3
- package/dist/index.js +0 -1
- package/dist/kernel/cap/index.d.ts +3 -3
- package/dist/kernel/cap/index.js +3 -3
- package/dist/kernel/cap/port.js +6 -3
- package/dist/kernel/cap/price.d.ts +6 -0
- package/dist/kernel/cap/price.js +14 -0
- package/dist/kernel/cap/rule.d.ts +8 -0
- package/dist/kernel/cap/rule.js +9 -0
- package/dist/kernel/cap/types.d.ts +2 -0
- package/dist/kernel/cap/words.d.ts +3 -0
- package/dist/kernel/cap/words.js +4 -1
- package/dist/kernel/index.d.ts +0 -2
- package/dist/kernel/index.js +0 -1
- package/dist/kernel/registry/computer-surface.generated.d.ts +9 -0
- package/dist/kernel/registry/computer-surface.generated.js +611 -0
- package/dist/kernel/registry/computer.d.ts +14 -0
- package/dist/kernel/registry/computer.js +67 -0
- package/dist/kernel/registry/defs.d.ts +1 -4
- package/dist/kernel/registry/defs.js +1 -13
- package/dist/kernel/registry/handoff.js +4 -4
- package/dist/kernel/registry/hands.d.ts +22 -115
- package/dist/kernel/registry/hands.js +0 -2
- package/dist/kernel/registry/index.d.ts +5 -5
- package/dist/kernel/registry/index.js +6 -6
- package/dist/kernel/registry/limits.d.ts +0 -1
- package/dist/kernel/registry/limits.js +0 -1
- package/dist/kernel/registry/registry.d.ts +4 -5
- package/dist/kernel/registry/registry.js +27 -29
- package/dist/kernel/types.d.ts +2 -1
- package/dist/process/records.d.ts +0 -16
- package/dist/process/records.js +0 -41
- package/dist/process/settle.d.ts +1 -1
- package/dist/process/settle.js +2 -2
- package/dist/process/tools.d.ts +3 -1
- package/dist/process/tools.js +3 -3
- package/dist/process/zod.d.ts +0 -2
- package/dist/process/zod.js +0 -4
- package/dist/run-booking.d.ts +3 -0
- package/dist/run-booking.js +7 -0
- package/dist/runner.d.ts +21 -2
- package/dist/runner.js +27 -10
- package/dist/testing.d.ts +9 -4
- package/dist/testing.js +22 -16
- package/dist/types.d.ts +18 -4
- package/package.json +2 -2
- package/dist/delegate.d.ts +0 -87
- package/dist/delegate.js +0 -143
- package/dist/kernel/follow-up.d.ts +0 -67
- package/dist/kernel/follow-up.js +0 -146
- package/dist/kernel/registry/desktop.d.ts +0 -11
- package/dist/kernel/registry/desktop.js +0 -90
- package/dist/kernel/registry/phone.d.ts +0 -15
- package/dist/kernel/registry/phone.js +0 -135
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ACT_STEPS, COMPUTER_TOOL_SCHEMAS, computerDeclarations } from "./computer-surface.generated.js";
|
|
2
|
+
import { answerOf, needsKindWords } from "./hands.js";
|
|
3
|
+
import { HANDOFF_TOOL, handoffDef, handoffExecutor } from "./handoff.js";
|
|
4
|
+
/** The computer's tools, in the order a run lists them (the hand-over last). */
|
|
5
|
+
export const COMPUTER_TOOLS = ["computer_observe", "computer_act", "computer_screenshot", "computer_script", HANDOFF_TOOL];
|
|
6
|
+
/** The tool a host runs itself: a script runs in the host's isolate, over the same port. */
|
|
7
|
+
export const SCRIPT_TOOL = "computer_script";
|
|
8
|
+
// The words are short on purpose: every request of a run with a computer carries them. The kind skill (desktop-computer,
|
|
9
|
+
// phone-computer) teaches how to work; a description says only what its tool does.
|
|
10
|
+
const OBSERVE = `An app's window as its elements, one line each (@e12 button "Save"), under a head line naming the state (s7). With no ui group: a screenshot.`;
|
|
11
|
+
const ACT = `Run steps on an app, each on an element's ref or at a point in the window (refused as stale once the window changed under it). The answer says how each step ran and whether the window changed. The first refused step stops the rest. steps: UiStep[]\n\`\`\`ts\n${ACT_STEPS}\n\`\`\``;
|
|
12
|
+
const SCREENSHOT = "The whole screen as an image, or a region of it.";
|
|
13
|
+
/** computer_script's words: what a script is, and the `computer` object's declarations for these groups. */
|
|
14
|
+
const scriptWords = (groups) => `Run JavaScript with \`computer\` bound: many steps in one call. Return only what you need; text() and image() show words and pictures. A refused step throws.\n\`\`\`ts\n${computerDeclarations(groups)}\n\`\`\``;
|
|
15
|
+
/** The tools a computer with `groups` offers: observe and act with the ui group, or a screen (observe) and input (act)
|
|
16
|
+
* without it; the screenshot with a screen; the script with any of them. */
|
|
17
|
+
export function computerToolsFor(groups) {
|
|
18
|
+
const has = (group) => groups.includes(group);
|
|
19
|
+
const input = has("input.pointer") || has("input.touch") || has("input.keys");
|
|
20
|
+
const observe = has("ui") || has("screen");
|
|
21
|
+
const act = has("ui") || input;
|
|
22
|
+
return [...(observe ? ["computer_observe"] : []), ...(act ? ["computer_act"] : []), ...(has("screen") ? ["computer_screenshot"] : []), ...(observe || act ? [SCRIPT_TOOL] : []), HANDOFF_TOOL];
|
|
23
|
+
}
|
|
24
|
+
const def = (kind, name, description, replaySafe) => ({
|
|
25
|
+
name,
|
|
26
|
+
source: "host",
|
|
27
|
+
gateName: `host:${kind}/${name}`,
|
|
28
|
+
settingsKey: kind,
|
|
29
|
+
description,
|
|
30
|
+
parameters: COMPUTER_TOOL_SCHEMAS[name],
|
|
31
|
+
replaySafe,
|
|
32
|
+
});
|
|
33
|
+
/** The computer's tools in `kind`, under its settings key, for a computer with `groups` (the script's declarations
|
|
34
|
+
* hold only what they offer). A script and an act change the computer: never replayed. */
|
|
35
|
+
export function computerToolDefs(kind, groups) {
|
|
36
|
+
return Object.freeze([
|
|
37
|
+
def(kind, "computer_observe", OBSERVE, true),
|
|
38
|
+
def(kind, "computer_act", ACT, false),
|
|
39
|
+
def(kind, "computer_screenshot", SCREENSHOT, true),
|
|
40
|
+
def(kind, "computer_script", scriptWords(groups), false),
|
|
41
|
+
handoffDef(kind),
|
|
42
|
+
]);
|
|
43
|
+
}
|
|
44
|
+
/** A value with its images' data left out: they travel in the answer's images. */
|
|
45
|
+
const withoutImageData = (value) => {
|
|
46
|
+
if (Array.isArray(value))
|
|
47
|
+
return value.map(withoutImageData);
|
|
48
|
+
if (value === null || typeof value !== "object")
|
|
49
|
+
return value;
|
|
50
|
+
const record = value;
|
|
51
|
+
return Object.fromEntries(Object.entries(record).filter(([key]) => !(key === "data" && record.type === "image")).map(([key, entry]) => [key, withoutImageData(entry)]));
|
|
52
|
+
};
|
|
53
|
+
/** A tool's run on the hands' computer port: the surface's op, answered as its text, its images and its value. */
|
|
54
|
+
const surfaceExecutor = (kind, tool, op) => (args, call) => answerOf(call, async () => {
|
|
55
|
+
const port = call.hands.computer;
|
|
56
|
+
if (!port)
|
|
57
|
+
throw new Error(needsKindWords(tool, kind));
|
|
58
|
+
const answer = await port.call(op, args ?? {}, call.signal);
|
|
59
|
+
return { text: answer.text, ...(answer.images.length > 0 ? { images: answer.images } : {}), structured: (withoutImageData(answer.value) ?? null) };
|
|
60
|
+
});
|
|
61
|
+
/** The kernel's own executors of the computer's tools in `kind`: all but the script, which the host runs. */
|
|
62
|
+
export const computerExecutors = (kind) => ({
|
|
63
|
+
computer_observe: surfaceExecutor(kind, "computer_observe", "observe"),
|
|
64
|
+
computer_act: surfaceExecutor(kind, "computer_act", "act"),
|
|
65
|
+
computer_screenshot: surfaceExecutor(kind, "computer_screenshot", "screenshot"),
|
|
66
|
+
[HANDOFF_TOOL]: handoffExecutor(kind),
|
|
67
|
+
});
|
|
@@ -32,8 +32,5 @@ export declare function hostToolDefs(options: {
|
|
|
32
32
|
maxExecS: number;
|
|
33
33
|
shell: ShellPlace;
|
|
34
34
|
}): readonly ToolDef[];
|
|
35
|
-
/** The kinds
|
|
35
|
+
/** The kinds whose computer brings the computer's tools, each under its own settings key. */
|
|
36
36
|
export declare const CAPABILITY_KINDS: readonly CapabilityKind[];
|
|
37
|
-
/** A computer kind's own tools, which a run of that kind sees after its host tools: the desktop's (desktop.ts) or the
|
|
38
|
-
* phone's (phone.ts). */
|
|
39
|
-
export declare function capabilityToolDefs(kind: CapabilityKind): readonly ToolDef[];
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
// Every model-visible host tool's definition: its name, words, schema and replay, as main shows them today. read, write,
|
|
2
|
-
// edit and bash are pi's (pi 1.5.0's coding tools, MIT), with serve's additions: bash's timeout words and read's image
|
|
3
|
-
// sentence on a computer. The five background tools are serve's (background.ts). A test holds every one of them, in
|
|
4
|
-
// order, to serve's own on main. A computer of a kind past files and a shell adds its own tools after them
|
|
5
|
-
// (capabilityToolDefs): the desktop's, the phone's.
|
|
6
|
-
import { DESKTOP_TOOL_DEFS } from "./desktop.js";
|
|
7
|
-
import { PHONE_TOOL_DEFS } from "./phone.js";
|
|
8
1
|
import { BACKGROUND_INPUT_BYTES, BACKGROUND_LIST_MAX, BACKGROUND_LOG_BYTES, BACKGROUND_MAX, BACKGROUND_PAGE_BYTES, BACKGROUND_SIGNALS, BASH_DEFAULT_TIMEOUT_S } from "./limits.js";
|
|
9
2
|
const READ_WORDS = "Read the contents of a file. Supports text files and images (jpg, png, gif, webp). Images are sent as attachments. For text files, output is truncated to 2000 lines or 50KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.";
|
|
10
3
|
/** read's sentence on a computer: it opens an image anywhere in the computer. */
|
|
@@ -139,10 +132,5 @@ export function hostToolDefs(options) {
|
|
|
139
132
|
defs.push(host(tool.name, "shell", tool.description, tool.parameters, tool.replaySafe, tool.name === "bash_output" || tool.name === "bash_list" || tool.name === "bash_signal"));
|
|
140
133
|
return defs;
|
|
141
134
|
}
|
|
142
|
-
/** The kinds
|
|
135
|
+
/** The kinds whose computer brings the computer's tools, each under its own settings key. */
|
|
143
136
|
export const CAPABILITY_KINDS = Object.freeze(["desktop", "phone"]);
|
|
144
|
-
/** A computer kind's own tools, which a run of that kind sees after its host tools: the desktop's (desktop.ts) or the
|
|
145
|
-
* phone's (phone.ts). */
|
|
146
|
-
export function capabilityToolDefs(kind) {
|
|
147
|
-
return kind === "desktop" ? DESKTOP_TOOL_DEFS : PHONE_TOOL_DEFS;
|
|
148
|
-
}
|
|
@@ -4,14 +4,14 @@ export const HANDOFF_TOOL = "computer_request_handoff";
|
|
|
4
4
|
export const HANDOFF_DEFAULT_S = 600;
|
|
5
5
|
export const HANDOFF_MIN_S = 30;
|
|
6
6
|
export const HANDOFF_MAX_S = 3600;
|
|
7
|
-
const DESCRIPTION = `Hand the computer to the person for a step
|
|
7
|
+
const DESCRIPTION = `Hand the computer to the person for a step only they should do (their password, a captcha, a payment, their choice), and wait until they answer or the ask expires. The screen may have changed after.`;
|
|
8
8
|
const PARAMETERS = {
|
|
9
9
|
type: "object",
|
|
10
10
|
additionalProperties: false,
|
|
11
11
|
properties: {
|
|
12
|
-
instruction: { type: "string", minLength: 1, description: "What the person should do
|
|
13
|
-
completion_condition: { type: "string", minLength: 1, description: "
|
|
14
|
-
expires_in_s: { type: "integer", minimum: HANDOFF_MIN_S, maximum: HANDOFF_MAX_S, description: `
|
|
12
|
+
instruction: { type: "string", minLength: 1, description: "What the person should do." },
|
|
13
|
+
completion_condition: { type: "string", minLength: 1, description: "What the screen shows once it is done." },
|
|
14
|
+
expires_in_s: { type: "integer", minimum: HANDOFF_MIN_S, maximum: HANDOFF_MAX_S, description: `Default ${HANDOFF_DEFAULT_S}.` },
|
|
15
15
|
},
|
|
16
16
|
required: ["instruction", "completion_condition"],
|
|
17
17
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ToolImage } from "../../types.js";
|
|
1
|
+
import type { JsonValue, ToolImage } from "../../types.js";
|
|
2
2
|
/** How one exec ended: its exit code, or the signal that ended it (exitCode null), and whether its timeout did. */
|
|
3
3
|
export type ExecResult = {
|
|
4
4
|
readonly exitCode: number | null;
|
|
@@ -60,118 +60,23 @@ export type Processes = {
|
|
|
60
60
|
}>;
|
|
61
61
|
list(): Promise<readonly ProcessInfo[]>;
|
|
62
62
|
};
|
|
63
|
-
/** A computer's kind past files and a shell: each adds
|
|
63
|
+
/** A computer's kind past files and a shell: each adds the computer's tools to the run's (computer.ts COMPUTER_TOOLS). */
|
|
64
64
|
export type CapabilityKind = "desktop" | "phone";
|
|
65
65
|
/** A kind's tool refused in a run whose computer is not of that kind (or lacks the port): the words name the setting. */
|
|
66
66
|
export declare const needsKindWords: (tool: string, kind: CapabilityKind) => string;
|
|
67
|
-
/**
|
|
68
|
-
export
|
|
69
|
-
|
|
70
|
-
export type ScreenPoint = readonly [x: number, y: number];
|
|
71
|
-
/** A screenshot: its PNG's bytes, and its size in pixels (the coordinates input takes). */
|
|
72
|
-
export type Shot = {
|
|
73
|
-
readonly png: Uint8Array;
|
|
74
|
-
readonly width: number;
|
|
75
|
-
readonly height: number;
|
|
76
|
-
};
|
|
77
|
-
/** A desktop's screen (computerd's screen.shot): the whole screen, or a region of it in the whole screen's pixels. */
|
|
78
|
-
export type Screen = {
|
|
79
|
-
shot(options?: {
|
|
80
|
-
readonly region?: {
|
|
81
|
-
readonly x: number;
|
|
82
|
-
readonly y: number;
|
|
83
|
-
readonly w: number;
|
|
84
|
-
readonly h: number;
|
|
85
|
-
};
|
|
86
|
-
}): Promise<Shot>;
|
|
87
|
-
};
|
|
88
|
-
/** One action of a desktop's input, as computerd's input.actions takes it: the pointer's and the keyboard's, and
|
|
89
|
-
* nothing more. A key is a name of computerd's key table or one printable ASCII character. */
|
|
90
|
-
export type InputAction = {
|
|
91
|
-
readonly type: "move";
|
|
92
|
-
readonly at: ScreenPoint;
|
|
93
|
-
} | {
|
|
94
|
-
readonly type: "click";
|
|
95
|
-
readonly at?: ScreenPoint;
|
|
96
|
-
readonly button?: "left" | "right" | "middle";
|
|
97
|
-
readonly count?: 1 | 2 | 3;
|
|
98
|
-
} | {
|
|
99
|
-
readonly type: "drag";
|
|
100
|
-
readonly path: readonly ScreenPoint[];
|
|
101
|
-
readonly button?: "left" | "right" | "middle";
|
|
102
|
-
} | {
|
|
103
|
-
readonly type: "scroll";
|
|
104
|
-
readonly at?: ScreenPoint;
|
|
105
|
-
readonly dx?: number;
|
|
106
|
-
readonly dy?: number;
|
|
107
|
-
readonly unit: "clicks" | "px";
|
|
108
|
-
} | {
|
|
109
|
-
readonly type: "type";
|
|
67
|
+
/** One answer of the run's computer: the value a script gets, the text a model reads, and the images beside it. */
|
|
68
|
+
export type ComputerAnswer = {
|
|
69
|
+
readonly value: unknown;
|
|
110
70
|
readonly text: string;
|
|
111
|
-
|
|
112
|
-
readonly type: "key";
|
|
113
|
-
readonly keys: readonly string[];
|
|
114
|
-
};
|
|
115
|
-
/** A desktop's input (computerd's input.actions): the batch runs in order; a refusal throws its code and words. */
|
|
116
|
-
export type Input = {
|
|
117
|
-
actions(list: readonly InputAction[]): Promise<void>;
|
|
71
|
+
readonly images: readonly ToolImage[];
|
|
118
72
|
};
|
|
119
|
-
/**
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
export type PhoneNode = {
|
|
127
|
-
readonly role: string;
|
|
128
|
-
readonly id?: string;
|
|
129
|
-
readonly text?: string;
|
|
130
|
-
readonly label?: string;
|
|
131
|
-
readonly bounds: {
|
|
132
|
-
readonly x: number;
|
|
133
|
-
readonly y: number;
|
|
134
|
-
readonly w: number;
|
|
135
|
-
readonly h: number;
|
|
136
|
-
};
|
|
137
|
-
readonly clickable: boolean;
|
|
138
|
-
readonly editable: boolean;
|
|
139
|
-
readonly focused?: boolean;
|
|
140
|
-
/** A node with no text or label of its own, named by its first inner text (else label): an Android list row, a
|
|
141
|
-
* clickable layout whose title sits on a child that is not clickable. */
|
|
142
|
-
readonly inner?: string;
|
|
143
|
-
};
|
|
144
|
-
/** A key a phone presses: its back and home buttons, and enter. */
|
|
145
|
-
export type PhoneKey = "back" | "home" | "enter";
|
|
146
|
-
/** A phone: its screen and the screen's structure, a tap, a swipe, typing into the field in focus, its keys, and its apps. */
|
|
147
|
-
export type Phone = {
|
|
148
|
-
shot(): Promise<Shot>;
|
|
149
|
-
/** The screen's structure, flattened (`total` the nodes the phone gave, `truncated` when it gave only part); absent on a
|
|
150
|
-
* phone that does not offer it. */
|
|
151
|
-
tree?(): Promise<{
|
|
152
|
-
readonly nodes: readonly PhoneNode[];
|
|
153
|
-
readonly total: number;
|
|
154
|
-
readonly truncated: boolean;
|
|
155
|
-
}>;
|
|
156
|
-
tap(at: PhonePoint): Promise<void>;
|
|
157
|
-
swipe(spec: {
|
|
158
|
-
readonly from: PhonePoint;
|
|
159
|
-
readonly to: PhonePoint;
|
|
160
|
-
readonly durationMs: number;
|
|
161
|
-
}): Promise<void>;
|
|
162
|
-
type(text: string): Promise<void>;
|
|
163
|
-
/** Absent on a phone that does not offer its keys. */
|
|
164
|
-
key?(name: PhoneKey): Promise<void>;
|
|
165
|
-
readonly apps: {
|
|
166
|
-
list(): Promise<{
|
|
167
|
-
readonly apps: readonly {
|
|
168
|
-
readonly id: string;
|
|
169
|
-
readonly name?: string;
|
|
170
|
-
}[];
|
|
171
|
-
readonly foreground: string | null;
|
|
172
|
-
}>;
|
|
173
|
-
open(id: string): Promise<void>;
|
|
174
|
-
};
|
|
73
|
+
/** The run's computer as its tools reach it: its groups (its hello's), and one call per op (observe, act, screenshot,
|
|
74
|
+
* input.act, apps.list, apps.open, shell.run, files.read, files.write, files.list, files.stat), which
|
|
75
|
+
* @parcha/agentrun-computer's surface answers the same for a per-step tool, a script and the claim's MCP endpoint. A
|
|
76
|
+
* refusal throws an error with a `kind` (stale, unsupported, ...) and the computer's words; an abort throws. */
|
|
77
|
+
export type ComputerPort = {
|
|
78
|
+
readonly groups: readonly string[];
|
|
79
|
+
call(op: string, args: unknown, signal?: AbortSignal): Promise<ComputerAnswer>;
|
|
175
80
|
};
|
|
176
81
|
/** The agent's hand-over of a desktop or a phone to the person, through the run's hold: ask opens it (what the person is
|
|
177
82
|
* to do, how both will know it is done, when it expires, ISO time) and resolves with its first answer, or expired. An
|
|
@@ -222,11 +127,9 @@ export type Hands = {
|
|
|
222
127
|
}, signal?: AbortSignal): Promise<ExecResult>;
|
|
223
128
|
/** The attached computer's processes; absent with no computer, where the background tools are refused. */
|
|
224
129
|
readonly processes?: Processes;
|
|
225
|
-
/** A desktop's
|
|
226
|
-
|
|
227
|
-
readonly
|
|
228
|
-
/** A phone's screen, touch, typing and apps; absent where the computer is no phone. */
|
|
229
|
-
readonly phone?: Phone;
|
|
130
|
+
/** A desktop's or a phone's surface (computer_observe, computer_act, computer_screenshot, computer_script); absent
|
|
131
|
+
* where the computer is neither, and those tools are refused in words. */
|
|
132
|
+
readonly computer?: ComputerPort;
|
|
230
133
|
/** A desktop's or a phone's hand-over to the person (the run's hold); absent where there is none. */
|
|
231
134
|
readonly handoff?: Handoff;
|
|
232
135
|
};
|
|
@@ -237,6 +140,9 @@ export type ToolAnswer = {
|
|
|
237
140
|
readonly text: string;
|
|
238
141
|
readonly error?: string;
|
|
239
142
|
readonly images?: readonly ToolImage[];
|
|
143
|
+
/** The answer as a value, for a script that called the tool (Codex's code mode, an MCP client's structuredContent):
|
|
144
|
+
* the computer's tools give the surface's value, its images' data left out (they travel in `images`). */
|
|
145
|
+
readonly structured?: JsonValue;
|
|
240
146
|
readonly details?: unknown;
|
|
241
147
|
readonly isError?: boolean;
|
|
242
148
|
readonly diagnostics?: readonly {
|
|
@@ -257,5 +163,6 @@ export type ToolCall = {
|
|
|
257
163
|
export declare function answerOf(call: ToolCall, run: () => Promise<ToolAnswer>): Promise<ToolAnswer>;
|
|
258
164
|
/** A host tool's run. */
|
|
259
165
|
export type Executor = (args: unknown, call: ToolCall) => Promise<ToolAnswer>;
|
|
260
|
-
/** What the host gives the registry, by tool name: read, write and edit,
|
|
261
|
-
|
|
166
|
+
/** What the host gives the registry, by tool name: read, write and edit, bash's own run, which the registry bounds, and
|
|
167
|
+
* computer_script's run in the host's isolate (listed only where the host gives it). */
|
|
168
|
+
export type HostExecutors = Readonly<Partial<Record<"read" | "write" | "edit" | "bash" | "computer_script", Executor>>>;
|
|
@@ -13,8 +13,6 @@ export function exitCodeOf(result) {
|
|
|
13
13
|
}
|
|
14
14
|
/** A kind's tool refused in a run whose computer is not of that kind (or lacks the port): the words name the setting. */
|
|
15
15
|
export const needsKindWords = (tool, kind) => `${tool} needs a ${kind} computer: set this agent's computer to ${kind} (Settings → Computers).`;
|
|
16
|
-
/** A screenshot as a tool's answer: the words, and the PNG in the answer's images. */
|
|
17
|
-
export const shotAnswer = (text, shot) => ({ text, images: [{ mimeType: "image/png", data: Buffer.from(shot.png.buffer, shot.png.byteOffset, shot.png.byteLength).toString("base64") }] });
|
|
18
16
|
/** An executor's failure as an answer: an abort (the call's signal aborted) throws; any other error is its words. */
|
|
19
17
|
export async function answerOf(call, run) {
|
|
20
18
|
try {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export { BACKGROUND_EXECUTORS, endBackground, NEEDS_A_COMPUTER, NO_SHELL } from "./background.js";
|
|
2
2
|
export { boundedBash } from "./bash.js";
|
|
3
|
-
export { bashTimeoutWords, CAPABILITY_KINDS,
|
|
3
|
+
export { bashTimeoutWords, CAPABILITY_KINDS, hostToolDefs } from "./defs.js";
|
|
4
4
|
export type { ShellPlace, ToolDef } from "./defs.js";
|
|
5
|
-
export {
|
|
5
|
+
export { COMPUTER_TOOLS, computerExecutors, computerToolDefs, computerToolsFor, SCRIPT_TOOL } from "./computer.js";
|
|
6
|
+
export { COMPUTER_TOOL_SCHEMAS, computerDeclarations } from "./computer-surface.generated.js";
|
|
6
7
|
export { defaultPermissionOf, SHELL_FAMILY, SHELL_WATCHERS, shellPermission, shellToolOf } from "./gate.js";
|
|
7
8
|
export type { Permission } from "./gate.js";
|
|
8
9
|
export { answerOf, exitCodeOf, needsKindWords } from "./hands.js";
|
|
9
|
-
export type { CapabilityKind, ExecResult, Executor, Hands, HostExecutors,
|
|
10
|
-
export { PHONE_EXECUTORS, PHONE_KEYS, PHONE_SWIPE_MAX_MS, PHONE_SWIPE_MS, PHONE_TOOL_DEFS, PHONE_TREE_MAX_CHARS, PHONE_TREE_MAX_NODES } from "./phone.js";
|
|
10
|
+
export type { CapabilityKind, ComputerAnswer, ComputerPort, ExecResult, Executor, Hands, HostExecutors, ProcessInfo, Processes, ToolAnswer, ToolCall } from "./hands.js";
|
|
11
11
|
export { HANDOFF_DEFAULT_S, HANDOFF_MAX_S, HANDOFF_MIN_S, HANDOFF_TOOL } from "./handoff.js";
|
|
12
12
|
export type { Handoff } from "./hands.js";
|
|
13
|
-
export { BACKGROUND_DIR, BACKGROUND_INPUT_BYTES, BACKGROUND_LIST_MAX, BACKGROUND_LOG_BYTES, BACKGROUND_MAX, BACKGROUND_PAGE_BYTES, BACKGROUND_SIGNALS, BACKGROUND_TOOLS, BASH_DEFAULT_TIMEOUT_S,
|
|
13
|
+
export { BACKGROUND_DIR, BACKGROUND_INPUT_BYTES, BACKGROUND_LIST_MAX, BACKGROUND_LOG_BYTES, BACKGROUND_MAX, BACKGROUND_PAGE_BYTES, BACKGROUND_SIGNALS, BACKGROUND_TOOLS, BASH_DEFAULT_TIMEOUT_S, READ_IMAGE_MAX_BYTES, SHELL_TOOLS, } from "./limits.js";
|
|
14
14
|
export { createRegistry } from "./registry.js";
|
|
15
15
|
export type { Registry } from "./registry.js";
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// The kernel's one tool registry: the host tools' definitions, words and limits, the gate's shell family, the run's
|
|
2
|
-
// hands, and the executors the kernel owns; a
|
|
3
|
-
//
|
|
2
|
+
// hands, and the executors the kernel owns; a desktop's or a phone's computer tools and the one port they run on. A
|
|
3
|
+
// browser computer's tools are the host's browser tool's (serve's tools.ts, pi-browser's durable extension), not
|
|
4
4
|
// the registry's.
|
|
5
5
|
export { BACKGROUND_EXECUTORS, endBackground, NEEDS_A_COMPUTER, NO_SHELL } from "./background.js";
|
|
6
6
|
export { boundedBash } from "./bash.js";
|
|
7
|
-
export { bashTimeoutWords, CAPABILITY_KINDS,
|
|
8
|
-
export {
|
|
7
|
+
export { bashTimeoutWords, CAPABILITY_KINDS, hostToolDefs } from "./defs.js";
|
|
8
|
+
export { COMPUTER_TOOLS, computerExecutors, computerToolDefs, computerToolsFor, SCRIPT_TOOL } from "./computer.js";
|
|
9
|
+
export { COMPUTER_TOOL_SCHEMAS, computerDeclarations } from "./computer-surface.generated.js";
|
|
9
10
|
export { defaultPermissionOf, SHELL_FAMILY, SHELL_WATCHERS, shellPermission, shellToolOf } from "./gate.js";
|
|
10
11
|
export { answerOf, exitCodeOf, needsKindWords } from "./hands.js";
|
|
11
|
-
export { PHONE_EXECUTORS, PHONE_KEYS, PHONE_SWIPE_MAX_MS, PHONE_SWIPE_MS, PHONE_TOOL_DEFS, PHONE_TREE_MAX_CHARS, PHONE_TREE_MAX_NODES } from "./phone.js";
|
|
12
12
|
export { HANDOFF_DEFAULT_S, HANDOFF_MAX_S, HANDOFF_MIN_S, HANDOFF_TOOL } from "./handoff.js";
|
|
13
|
-
export { BACKGROUND_DIR, BACKGROUND_INPUT_BYTES, BACKGROUND_LIST_MAX, BACKGROUND_LOG_BYTES, BACKGROUND_MAX, BACKGROUND_PAGE_BYTES, BACKGROUND_SIGNALS, BACKGROUND_TOOLS, BASH_DEFAULT_TIMEOUT_S,
|
|
13
|
+
export { BACKGROUND_DIR, BACKGROUND_INPUT_BYTES, BACKGROUND_LIST_MAX, BACKGROUND_LOG_BYTES, BACKGROUND_MAX, BACKGROUND_PAGE_BYTES, BACKGROUND_SIGNALS, BACKGROUND_TOOLS, BASH_DEFAULT_TIMEOUT_S, READ_IMAGE_MAX_BYTES, SHELL_TOOLS, } from "./limits.js";
|
|
14
14
|
export { createRegistry } from "./registry.js";
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* (Claude Code's own 120 s and 600 s). A command that needs longer is a background process (bash_background). The
|
|
3
3
|
* ceiling a run gets is its hands' `maxExecS`: 600 s locally and on a computer, less where the hands' exec is bounded. */
|
|
4
4
|
export declare const BASH_DEFAULT_TIMEOUT_S = 120;
|
|
5
|
-
export declare const BASH_MAX_TIMEOUT_S = 600;
|
|
6
5
|
/** The largest image read hands the model, in bytes: 3.75 MiB, whose base64 is the 5 MiB the strictest platform a
|
|
7
6
|
* harness sends images to takes (the claude-agent adapter's CLAUDE_AGENT_MAX_IMAGE_BYTES, Amazon Bedrock's). */
|
|
8
7
|
export declare const READ_IMAGE_MAX_BYTES = 3932160;
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* (Claude Code's own 120 s and 600 s). A command that needs longer is a background process (bash_background). The
|
|
5
5
|
* ceiling a run gets is its hands' `maxExecS`: 600 s locally and on a computer, less where the hands' exec is bounded. */
|
|
6
6
|
export const BASH_DEFAULT_TIMEOUT_S = 120;
|
|
7
|
-
export const BASH_MAX_TIMEOUT_S = 600;
|
|
8
7
|
/** The largest image read hands the model, in bytes: 3.75 MiB, whose base64 is the 5 MiB the strictest platform a
|
|
9
8
|
* harness sends images to takes (the claude-agent adapter's CLAUDE_AGENT_MAX_IMAGE_BYTES, Amazon Bedrock's). */
|
|
10
9
|
export const READ_IMAGE_MAX_BYTES = 3_932_160;
|
|
@@ -6,14 +6,13 @@ export type Registry = {
|
|
|
6
6
|
get(name: string): ToolDef | undefined;
|
|
7
7
|
invoke(name: string, args: unknown, call: ToolCall): Promise<ToolAnswer>;
|
|
8
8
|
};
|
|
9
|
-
/** The registry of a run's host tools, by where its shell is, and its computer's
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* the model; one called anyway runs, and its port's absence answers in words. */
|
|
9
|
+
/** The registry of a run's host tools, by where its shell is, and its computer's kind (`kinds`: none, or the desktop or
|
|
10
|
+
* the phone it is) with its groups (`groups`, its hello's: which of the computer's tools it offers), with the host's
|
|
11
|
+
* executors. */
|
|
13
12
|
export declare function createRegistry(options: {
|
|
14
13
|
maxExecS: number;
|
|
15
14
|
shell: ShellPlace;
|
|
16
15
|
kinds?: readonly CapabilityKind[];
|
|
16
|
+
groups?: readonly string[];
|
|
17
17
|
executors: HostExecutors;
|
|
18
|
-
without?: readonly string[];
|
|
19
18
|
}): Registry;
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
// The kernel's one registry of host tools: the model-visible definitions (defs.ts), each with its executor. read,
|
|
2
2
|
// write and edit, and bash's own run, are the host's (pi's tools over the run's hands, until their semantics move
|
|
3
|
-
// here); the kernel bounds bash and runs the five background tools itself. A
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
3
|
+
// here); the kernel bounds bash and runs the five background tools itself. A desktop or a phone adds the computer's
|
|
4
|
+
// tools after them (computer.ts), as its groups offer them, under its kind's settings key: observe, act and screenshot
|
|
5
|
+
// run on the kernel's own executors over the hands' computer port; computer_script runs in the host's isolate, listed
|
|
6
|
+
// only where the host gives it. A registry missing an executor for a tool the model sees is refused when it is built,
|
|
7
|
+
// so a run never offers a tool it cannot run. A computer's tool the run does not have is refused in words that name
|
|
8
|
+
// the setting.
|
|
8
9
|
import { BACKGROUND_EXECUTORS, NEEDS_A_COMPUTER, NO_SHELL } from "./background.js";
|
|
9
10
|
import { boundedBash } from "./bash.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
11
|
+
import { COMPUTER_TOOLS, computerExecutors, computerToolDefs, computerToolsFor, SCRIPT_TOOL } from "./computer.js";
|
|
12
|
+
import { CAPABILITY_KINDS, hostToolDefs } from "./defs.js";
|
|
12
13
|
import { answerOf, needsKindWords } from "./hands.js";
|
|
13
14
|
import { BACKGROUND_TOOLS } from "./limits.js";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*
|
|
17
|
-
* tools this run's computer does not offer (its capabilities lack them: an iPhone's tree and keys, say), not listed to
|
|
18
|
-
* the model; one called anyway runs, and its port's absence answers in words. */
|
|
15
|
+
/** The registry of a run's host tools, by where its shell is, and its computer's kind (`kinds`: none, or the desktop or
|
|
16
|
+
* the phone it is) with its groups (`groups`, its hello's: which of the computer's tools it offers), with the host's
|
|
17
|
+
* executors. */
|
|
19
18
|
export function createRegistry(options) {
|
|
20
19
|
const { shell, executors } = options;
|
|
21
|
-
const
|
|
20
|
+
const kind = CAPABILITY_KINDS.find((each) => options.kinds?.includes(each));
|
|
22
21
|
const own = hostToolDefs({ maxExecS: options.maxExecS, shell });
|
|
23
22
|
const runs = new Map();
|
|
24
23
|
for (const def of own) {
|
|
@@ -30,24 +29,21 @@ export function createRegistry(options) {
|
|
|
30
29
|
runs.set(def.name, run);
|
|
31
30
|
}
|
|
32
31
|
const defs = [...own];
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
if (kind) {
|
|
33
|
+
const groups = options.groups ?? [];
|
|
34
|
+
const offered = computerToolsFor(groups);
|
|
35
|
+
const kernel = computerExecutors(kind);
|
|
36
|
+
for (const def of computerToolDefs(kind, groups)) {
|
|
37
|
+
if (!offered.includes(def.name))
|
|
37
38
|
continue;
|
|
38
|
-
const run =
|
|
39
|
+
const run = def.name === SCRIPT_TOOL ? executors.computer_script : kernel[def.name];
|
|
40
|
+
// The script is the host's to run (its isolate): a host that gives none lists none.
|
|
39
41
|
if (!run)
|
|
40
|
-
|
|
42
|
+
continue;
|
|
41
43
|
runs.set(def.name, run);
|
|
42
|
-
|
|
43
|
-
defs.push(def);
|
|
44
|
+
defs.push(def);
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
|
-
// Every kind's tool by name, the run's or not, for the refusal of one it does not have.
|
|
47
|
-
const kindOf = new Map([
|
|
48
|
-
...DESKTOP_TOOL_DEFS.map((def) => [def.name, "desktop"]),
|
|
49
|
-
...PHONE_TOOL_DEFS.map((def) => [def.name, "phone"]),
|
|
50
|
-
]);
|
|
51
47
|
const byName = new Map(defs.map((def) => [def.name, def]));
|
|
52
48
|
return {
|
|
53
49
|
list: () => defs,
|
|
@@ -63,9 +59,11 @@ export function createRegistry(options) {
|
|
|
63
59
|
// No shell at all: bash is not listed, and a call of it anyway says how to get one.
|
|
64
60
|
if (shell === "none" && name === "bash")
|
|
65
61
|
throw new Error(NO_SHELL);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
if (COMPUTER_TOOLS.includes(name)) {
|
|
63
|
+
if (kind)
|
|
64
|
+
throw new Error(`${name} is not offered by this ${kind} computer: it offers ${(options.groups ?? []).join(", ") || "no groups"}`);
|
|
65
|
+
throw new Error(`${needsKindWords(name, "desktop")} A phone computer has it too.`);
|
|
66
|
+
}
|
|
69
67
|
throw new Error(`there is no host tool ${name} in this run`);
|
|
70
68
|
});
|
|
71
69
|
},
|
package/dist/kernel/types.d.ts
CHANGED
|
@@ -108,10 +108,11 @@ export interface HostTool<Input = any> {
|
|
|
108
108
|
* from the record answers with the same images. */
|
|
109
109
|
execute(input: Input, io: HostToolIO): Promise<string | ToolOutput>;
|
|
110
110
|
}
|
|
111
|
-
/** A tool's answer with images. */
|
|
111
|
+
/** A tool's answer with images, and its value where it gives one (a computer tool's: what a script reads). */
|
|
112
112
|
export interface ToolOutput {
|
|
113
113
|
text: string;
|
|
114
114
|
images?: readonly ToolImage[];
|
|
115
|
+
structured?: JsonValue;
|
|
115
116
|
}
|
|
116
117
|
export interface HostToolIO {
|
|
117
118
|
signal: AbortSignal;
|
|
@@ -109,22 +109,6 @@ export declare function journalBatches(state: SessionState): BatchRef[];
|
|
|
109
109
|
export declare function journalRecords<T = unknown>(state: SessionState, stream?: string): JournalRecord<T>[];
|
|
110
110
|
/** The normalized transcript, in log order. */
|
|
111
111
|
export declare function transcriptOf(state: SessionState): JournalRecord<TranscriptEntry>[];
|
|
112
|
-
/**
|
|
113
|
-
* Where the last turn ended: the `effectOrder` index of the batch holding
|
|
114
|
-
* the last `turn` entry, or of the last `unavailable` fact (a turn the
|
|
115
|
-
* harness could not run: it is over, with an error, and nothing in it is
|
|
116
|
-
* recovered), or -1 if no turn has ended yet. Everything after it belongs to
|
|
117
|
-
* the current (or an interrupted) turn.
|
|
118
|
-
*/
|
|
119
|
-
export declare function lastTurnEnd(state: SessionState): number;
|
|
120
|
-
/**
|
|
121
|
-
* A batch input for UIs: the transcript entries as they are, every other
|
|
122
|
-
* stream as a count (native records can be large, and a page polling a
|
|
123
|
-
* session should not carry them).
|
|
124
|
-
*/
|
|
125
|
-
export declare function summarizeBatch(input: unknown): unknown;
|
|
126
|
-
/** The transcript entries of one batch input (inline only; transcript entries are never offloaded). */
|
|
127
|
-
export declare function batchTranscript(input: unknown): TranscriptEntry[];
|
|
128
112
|
export interface OpenTurn {
|
|
129
113
|
/** `effectOrder` index of the batch that ended the previous turn (-1: none ended yet). */
|
|
130
114
|
since: number;
|
package/dist/process/records.js
CHANGED
|
@@ -80,47 +80,6 @@ function lastUnavailable(state) {
|
|
|
80
80
|
return i;
|
|
81
81
|
return -1;
|
|
82
82
|
}
|
|
83
|
-
/**
|
|
84
|
-
* Where the last turn ended: the `effectOrder` index of the batch holding
|
|
85
|
-
* the last `turn` entry, or of the last `unavailable` fact (a turn the
|
|
86
|
-
* harness could not run: it is over, with an error, and nothing in it is
|
|
87
|
-
* recovered), or -1 if no turn has ended yet. Everything after it belongs to
|
|
88
|
-
* the current (or an interrupted) turn.
|
|
89
|
-
*/
|
|
90
|
-
export function lastTurnEnd(state) {
|
|
91
|
-
let at = -1;
|
|
92
|
-
for (const r of transcriptOf(state))
|
|
93
|
-
if (r.data?.type === 'turn')
|
|
94
|
-
at = r.at;
|
|
95
|
-
return Math.max(at, lastUnavailable(state));
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* A batch input for UIs: the transcript entries as they are, every other
|
|
99
|
-
* stream as a count (native records can be large, and a page polling a
|
|
100
|
-
* session should not carry them).
|
|
101
|
-
*/
|
|
102
|
-
export function summarizeBatch(input) {
|
|
103
|
-
const batch = input;
|
|
104
|
-
if (!batch || typeof batch !== 'object' || !batch.streams)
|
|
105
|
-
return input;
|
|
106
|
-
const streams = {};
|
|
107
|
-
for (const [name, part] of Object.entries(batch.streams)) {
|
|
108
|
-
streams[name] =
|
|
109
|
-
name === TRANSCRIPT
|
|
110
|
-
? part
|
|
111
|
-
: {
|
|
112
|
-
from: part.from,
|
|
113
|
-
count: part.entries.length,
|
|
114
|
-
blobs: part.entries.filter((e) => e.blob).length,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
return { v: batch.v, n: batch.n, streams };
|
|
118
|
-
}
|
|
119
|
-
/** The transcript entries of one batch input (inline only; transcript entries are never offloaded). */
|
|
120
|
-
export function batchTranscript(input) {
|
|
121
|
-
const part = input?.streams?.[TRANSCRIPT];
|
|
122
|
-
return (part?.entries ?? []).map((e) => e.data).filter(Boolean);
|
|
123
|
-
}
|
|
124
83
|
/**
|
|
125
84
|
* The turn that has not ended: everything after the last `turn` entry of
|
|
126
85
|
* the transcript. `undefined` when the last turn ended and nothing happened
|
package/dist/process/settle.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export interface SettleOptions {
|
|
|
4
4
|
/** Placed prompts and follow-ups the harness's CLI never recorded (its own record, as the session keeps it): carried,
|
|
5
5
|
* as a pending one is. */
|
|
6
6
|
readonly unsent?: readonly string[];
|
|
7
|
-
/** The submission of a host's own prompt (
|
|
7
|
+
/** The submission of a host's own prompt (`AdapterSession.settleOpenTurn`'s `opening`): withdrawn
|
|
8
8
|
* while pending, never carried, and the only one withdrawn. */
|
|
9
9
|
readonly host?: string;
|
|
10
10
|
}
|
package/dist/process/settle.js
CHANGED
|
@@ -22,8 +22,8 @@ export async function settleTurn(drive, options = {}) {
|
|
|
22
22
|
continue;
|
|
23
23
|
await drive.submit({ id: `withdraw:${id}`, kind: "withdraw", target: id, carry: true, unsent: true });
|
|
24
24
|
}
|
|
25
|
-
// A
|
|
26
|
-
// as it is
|
|
25
|
+
// A host's settle of its own prompt names it (`host`): that one is withdrawn and never carried, and the rest is left
|
|
26
|
+
// as it is. A person's stop withdraws every prompt pending.
|
|
27
27
|
const pending = pendingSubmissions(drive.state()).filter((s) => options.host === undefined || s.id === options.host);
|
|
28
28
|
for (const submission of pending) {
|
|
29
29
|
// A prompt or follow-up the person stopped stays in the conversation: its text is carried into the next one
|
package/dist/process/tools.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type DriveContext, type EffectError, type HostTool, type ReplayPolicy } from '../kernel/index.js';
|
|
2
|
-
import { type GateAnswer, type GateCall, type ToolImage } from '../types.js';
|
|
2
|
+
import { type GateAnswer, type GateCall, type JsonValue, type ToolImage } from '../types.js';
|
|
3
3
|
/**
|
|
4
4
|
* The tool bridge: `HostTool`s as a harness-neutral list a port maps onto its
|
|
5
5
|
* harness's own tool mechanism (Codex's dynamic tools).
|
|
@@ -26,6 +26,8 @@ export interface ToolResult {
|
|
|
26
26
|
interrupted?: boolean;
|
|
27
27
|
/** Images the tool answered with, as it gave them (recorded with its outcome). */
|
|
28
28
|
images?: readonly ToolImage[];
|
|
29
|
+
/** The answer as a value, where the tool gives one (recorded with its outcome): what a script's nested call reads. */
|
|
30
|
+
structured?: JsonValue;
|
|
29
31
|
/** The text was cut at HOST_RESULT_MAX_CHARS (`boundResult`); it says so in its last line. */
|
|
30
32
|
truncated?: true;
|
|
31
33
|
}
|