@parcha/agentrun-kernel 0.1.0-beta.37 → 0.1.0-beta.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/CHANGELOG.md +136 -0
  2. package/NOTICE +2 -0
  3. package/dist/booking.d.ts +25 -6
  4. package/dist/booking.js +15 -4
  5. package/dist/host/index.d.ts +4 -5
  6. package/dist/host/index.js +3 -3
  7. package/dist/host/o200k.d.ts +11 -0
  8. package/dist/host/o200k.js +185 -0
  9. package/dist/host/overhead.d.ts +105 -3
  10. package/dist/host/overhead.js +276 -20
  11. package/dist/host/proxy.d.ts +97 -16
  12. package/dist/host/proxy.js +420 -108
  13. package/dist/index.d.ts +6 -5
  14. package/dist/index.js +4 -3
  15. package/dist/kernel/cap/admit.d.ts +5 -8
  16. package/dist/kernel/cap/admit.js +13 -19
  17. package/dist/kernel/cap/free.d.ts +43 -0
  18. package/dist/kernel/cap/free.js +71 -0
  19. package/dist/kernel/cap/index.d.ts +7 -6
  20. package/dist/kernel/cap/index.js +6 -5
  21. package/dist/kernel/cap/marks.d.ts +2 -3
  22. package/dist/kernel/cap/park.d.ts +3 -4
  23. package/dist/kernel/cap/park.js +4 -5
  24. package/dist/kernel/cap/port.d.ts +11 -5
  25. package/dist/kernel/cap/port.js +26 -24
  26. package/dist/kernel/cap/price.d.ts +10 -30
  27. package/dist/kernel/cap/price.js +15 -48
  28. package/dist/kernel/cap/recover.d.ts +1 -2
  29. package/dist/kernel/cap/recover.js +2 -4
  30. package/dist/kernel/cap/rule.d.ts +11 -17
  31. package/dist/kernel/cap/rule.js +37 -19
  32. package/dist/kernel/cap/run-cap.d.ts +25 -10
  33. package/dist/kernel/cap/run-cap.js +78 -35
  34. package/dist/kernel/cap/types.d.ts +11 -27
  35. package/dist/kernel/cap/words.d.ts +13 -8
  36. package/dist/kernel/cap/words.js +23 -14
  37. package/dist/kernel/cap/wrap-up.d.ts +4 -0
  38. package/dist/kernel/cap/wrap-up.js +5 -1
  39. package/dist/kernel/registry/computer-surface.generated.d.ts +1 -1
  40. package/dist/kernel/registry/computer-surface.generated.js +18 -27
  41. package/dist/kernel/registry/computer.d.ts +14 -7
  42. package/dist/kernel/registry/computer.js +64 -16
  43. package/dist/kernel/registry/gate.d.ts +2 -2
  44. package/dist/kernel/registry/gate.js +4 -7
  45. package/dist/kernel/registry/hands.d.ts +4 -5
  46. package/dist/kernel/registry/index.d.ts +1 -1
  47. package/dist/kernel/registry/index.js +1 -1
  48. package/dist/kernel/registry/registry.js +6 -9
  49. package/dist/kernel/types.d.ts +8 -1
  50. package/dist/process/recovery.d.ts +4 -1
  51. package/dist/process/recovery.js +15 -3
  52. package/dist/process/resume.d.ts +5 -2
  53. package/dist/process/resume.js +15 -3
  54. package/dist/process/tools.d.ts +28 -1
  55. package/dist/process/tools.js +102 -5
  56. package/dist/run-booking.d.ts +21 -2
  57. package/dist/run-booking.js +215 -18
  58. package/dist/runner.d.ts +82 -21
  59. package/dist/runner.js +271 -56
  60. package/dist/testing.d.ts +10 -4
  61. package/dist/testing.js +7 -5
  62. package/dist/tool-deferral.d.ts +12 -0
  63. package/dist/tool-deferral.js +17 -0
  64. package/dist/types.d.ts +133 -48
  65. package/dist/types.js +8 -0
  66. package/package.json +5 -3
  67. package/vendor/o200k/LICENSE +61 -0
  68. package/vendor/o200k/o200k_base.tiktoken +199998 -0
  69. package/dist/host/mcp-route.d.ts +0 -14
  70. package/dist/host/mcp-route.js +0 -125
@@ -19,24 +19,16 @@ export interface ModelPrice extends PriceRates {
19
19
  readonly tiers?: readonly PriceTier[];
20
20
  }
21
21
  /** A model as the cap prices it: its API (what its provider adds server-side, and whether its thinking takes a budget),
22
- * its price (null: none known), and its output ceiling (null: none). */
22
+ * its price (null: none known), and its output ceiling (null: none). `plan`: billed to a person's subscription plan (a
23
+ * ChatGPT plan's model), never by the token: a request on it costs the run no dollars, so the cap holds it at $0 and
24
+ * never limits its output, whatever its price says. */
23
25
  export interface CapModel {
24
26
  readonly id: string;
25
27
  readonly api: string;
26
28
  readonly price: ModelPrice | null;
27
29
  readonly outputCeiling: number | null;
28
30
  readonly reasoning?: boolean;
29
- }
30
- /** The previous request of the conversation, as its usage reported it: what of its input was read from or written to
31
- * the cache, the rest, its input bound (the unit this request's is in) and when it ended (ms), on which model. */
32
- export interface Previous {
33
- readonly model: string;
34
- readonly cachedTokens: number;
35
- readonly inputTokens: number;
36
- readonly boundTokens: number;
37
- /** Its bound was its provider's count, not its bytes: used only for a next request bounded the same way. */
38
- readonly counted?: boolean;
39
- readonly endedAt: number;
31
+ readonly plan?: boolean;
40
32
  }
41
33
  /** A model request about to be sent, from any harness (pi in process, a CLI's through the model proxy). */
42
34
  export interface ModelCapRequest {
@@ -59,7 +51,6 @@ export interface ModelCapRequest {
59
51
  readonly outputTokensLeast?: number;
60
52
  /** Its thinking budget, on an API whose thinking takes one beside the answer's output. */
61
53
  readonly thinkingBudget?: number;
62
- readonly previous?: Previous;
63
54
  /** A side call (a title, a summary), never its turn's own. */
64
55
  readonly side?: boolean;
65
56
  /** It carries the cap's wrap-up note (Cap.note) in its body, its bytes in `inputTokens`: told once it is answered. */
@@ -67,7 +58,7 @@ export interface ModelCapRequest {
67
58
  }
68
59
  /** A workflow decision about to be judged, held as main holds it (serve decision-cap.ts holdOf): its model at its
69
60
  * catalog's price (`outputCeiling`: the catalog's most completion tokens), "unreadable" when the catalog could not be
70
- * read for one. Its output is DECISION_OUTPUT_TOKENS a question (expected), or its model's most (strict); its input its
61
+ * read for one. Its output is its model's most (no answer can take more); its input its
71
62
  * state and questions' bytes plus DECISION_IMAGE_TOKENS an image; its fees the catalog's per request and per image. With
72
63
  * no cap it is not priced at all. */
73
64
  export interface DecisionCapRequest {
@@ -76,8 +67,6 @@ export interface DecisionCapRequest {
76
67
  readonly model: CapModel | "unreadable";
77
68
  /** The UTF-8 bytes of its state and questions as JSON, one token a byte. */
78
69
  readonly inputTokens: number;
79
- /** How many questions it asks. */
80
- readonly questions: number;
81
70
  /** How many images it sends. */
82
71
  readonly images?: number;
83
72
  /** The catalog's price per request and per image, in USD. */
@@ -94,25 +83,23 @@ export interface ToolCapRequest {
94
83
  readonly basis: string;
95
84
  }
96
85
  export type CapRequest = ModelCapRequest | ToolCapRequest | DecisionCapRequest;
97
- /** A step the cap let go: what it is held at until it settles (a model request's expected cost at the output it may be
98
- * sent with, its worst case under strict), the most a cache miss can add (`boundUsd`), its worst case, and for a model
99
- * request the output it is limited to and what it counts at if stopped having streamed that many tokens. */
86
+ /** A step the cap let go: what it is held at until it settles (a model request's worst case at the output it may be sent
87
+ * with: its whole input bound uncached), and for a model request the output it is limited to and what it counts at if
88
+ * stopped having streamed that many tokens. */
100
89
  export interface Admission {
101
90
  readonly id: string;
102
91
  readonly heldUsd: number;
103
- readonly boundUsd: number;
104
- readonly worstUsd: number;
105
92
  readonly outputTokensMax?: number;
106
93
  readonly thinkingBudget?: number;
107
94
  stoppedUsd(streamedTokens: number): number;
108
95
  }
109
- /** A refusal for room's figures, beside its words: what the cap counted as taken, the least the step needs, and the least
110
- * cap that sends it (the figure its words name). */
96
+ /** A refusal for room's figures, beside its words: what the run had spent (never a hold), what its steps in flight held,
97
+ * the least the step needs, and the least cap that sends it (the figure its words name). */
111
98
  export interface RefusalFigures {
112
99
  readonly spentUsd: number;
100
+ readonly heldUsd?: number;
113
101
  readonly needsUsd: number;
114
102
  readonly leastCapUsd: number;
115
- readonly boundUsd?: number;
116
103
  /** A paid call's refusal: the call (its name, hold and basis), so a pause that lands after the refusal can say it again
117
104
  * with the run's spend as it is then (paidRefusal). */
118
105
  readonly step?: {
@@ -129,7 +116,6 @@ export type Settled = Ended | {
129
116
  export interface CapOptions {
130
117
  /** The run's cap, read before every paid check, so a raise holds from the next one. Undefined: no cap. */
131
118
  capUsd(): number | undefined;
132
- mode?: CapMode;
133
119
  /** What the run has spent when the cap opens (null: unknown). openCap reads it from `marks`. */
134
120
  spentUsd?: number | null;
135
121
  now?: () => number;
@@ -138,8 +124,6 @@ export interface CapOptions {
138
124
  /** How long settle waits for a step's end mark before it fails loudly. Default 10 s. */
139
125
  endMarkWaitMs?: number;
140
126
  }
141
- /** How the cap prices a request's input: "expected" from the previous request's cache; "strict" every token uncached. */
142
- export type CapMode = "expected" | "strict";
143
127
  export interface Cap {
144
128
  admit(request: CapRequest): Promise<Admission>;
145
129
  /** Books a step that ended, its hold let go: a model request by how it ended, a paid call at its charge (its hold when
@@ -21,23 +21,28 @@ export declare const suggestedRaise: (cap: number, spentUsd: number, needsUsd: n
21
21
  * say the run spent nothing. */
22
22
  export declare const spentMoney: (usd: number) => string;
23
23
  /** A model request what is left cannot buy the least of. */
24
- export declare function roomRefusal(cap: number, spent: number, held: number, least: number, boundUsd?: number): {
24
+ export declare function roomRefusal(cap: number, spent: number, held: number, least: number): {
25
25
  text: string;
26
26
  figures: RefusalFigures;
27
27
  };
28
+ /** A step that does not fit even once the steps in flight settle, so no wait sends it (`figures`, the refusal's as if none
29
+ * were in flight, with what they hold, `heldUsd`): what the run has spent, what it is holding for steps still running
30
+ * (never called spent: they settle at what they cost), and what the step needs, more than the cap leaves beside what is
31
+ * spent. A model request's least; a paid call's hold, by name (figures.step). Raise to `leastCapUsd`, the least cap that
32
+ * sends it once they settle. */
33
+ export declare function aloneRefusal(cap: number, figures: RefusalFigures): string;
28
34
  /** A paid call what is left cannot hold. */
29
35
  export declare function paidRefusal(cap: number, spent: number, held: number, name: string, holdUsd: number, basis: string): {
30
36
  text: string;
31
37
  figures: RefusalFigures;
32
38
  };
33
- /** The over-cap row's words, after the usage row whose booked cost `spentUsd` passed `capUsd`: by how much; when it passed
34
- * by no more than `boundUsd` (the bound of the requests since the cost last fit), a cache miss did it, and the most it
35
- * could have. None at or under the cap, with no cap, or with no known cost. */
36
- export declare function overCapWords(spentUsd: number | null, capUsd: number | undefined, boundUsd?: number): string | undefined;
39
+ /** The over-cap row's words, after the usage row whose booked cost `spentUsd` passed `capUsd`: by how much. A request is
40
+ * held at its worst case, so only a cost its admission never priced passes the cap (an owed charge, a provider that bills
41
+ * past its list price). None at or under the cap, with no cap, or with no known cost. */
42
+ export declare function overCapWords(spentUsd: number | null, capUsd: number | undefined): string | undefined;
37
43
  /** How a run ends whose booked cost `spentUsd` passed `capUsd`: failed, in these words (main's run end), the answer that
38
- * crossed it booked. None at or under the cap, with no cap, with no known cost, or when it passed by no more than
39
- * `boundUsd` (a cache miss within the bound it was admitted at: the run pauses at its next request instead). */
40
- export declare function overCapEnd(spentUsd: number | null, capUsd: number | undefined, boundUsd?: number): string | undefined;
44
+ * crossed it booked. None at or under the cap, with no cap, or with no known cost. */
45
+ export declare function overCapEnd(spentUsd: number | null, capUsd: number | undefined): string | undefined;
41
46
  /** How overCapEnd's words begin, and only theirs: a reader of a run's summary serves one that does as the error
42
47
  * spend_cap_reached, its message the words after `spend_cap_reached: ` (overCapMessage). */
43
48
  export declare const OVER_CAP_END = "spend_cap_reached: The run cost ";
@@ -43,41 +43,50 @@ const spentOf = (spent, held, cap) => {
43
43
  return holds !== "$0" ? `spent ${spentMoney(spent)} and holds ${holds} for steps still running, of its ${money(cap)} cap` : `spent ${spentMoney(spent)} of its ${money(cap)} cap`;
44
44
  };
45
45
  /** A model request what is left cannot buy the least of. */
46
- export function roomRefusal(cap, spent, held, least, boundUsd) {
46
+ export function roomRefusal(cap, spent, held, least) {
47
47
  const leastCapUsd = raiseFigure(cap, spent + held + least);
48
- const figures = { spentUsd: spent + held, needsUsd: least, leastCapUsd, ...(boundUsd && boundUsd > 0 ? { boundUsd } : {}) };
48
+ const figures = { spentUsd: spent, heldUsd: held, needsUsd: least, leastCapUsd };
49
49
  const [need, raise] = [leastMoney(least), `$${leastCapUsd.toFixed(2)}`];
50
50
  if (spent === 0 && held === 0)
51
51
  return { text: `${CAP_REFUSAL_CODE}Not sent: the next step needs at least ${need}, and this run's cap is ${money(cap)}. Raise the cap to at least ${raise} to continue.`, figures };
52
52
  return { text: `${CAP_REFUSAL_CODE}Not sent: this run has ${spentOf(spent, held, cap)}, and the next step needs at least ${need}. Raise the cap to at least ${raise} to continue.`, figures };
53
53
  }
54
+ /** A step that does not fit even once the steps in flight settle, so no wait sends it (`figures`, the refusal's as if none
55
+ * were in flight, with what they hold, `heldUsd`): what the run has spent, what it is holding for steps still running
56
+ * (never called spent: they settle at what they cost), and what the step needs, more than the cap leaves beside what is
57
+ * spent. A model request's least; a paid call's hold, by name (figures.step). Raise to `leastCapUsd`, the least cap that
58
+ * sends it once they settle. */
59
+ export function aloneRefusal(cap, figures) {
60
+ const holds = centsMoney(figures.heldUsd ?? 0);
61
+ const holding = holds !== "$0" ? ` and is holding ${holds} for steps still running` : "";
62
+ const [code, needs] = figures.step
63
+ ? [`${SPEND_CAP_REACHED}: `, `the next step, ${figures.step.name}, could cost up to ${money(figures.step.holdUsd)} (${figures.step.basis})`]
64
+ : [CAP_REFUSAL_CODE, `the next step needs at least ${leastMoney(figures.needsUsd)}`];
65
+ return `${code}Not sent: this run has spent ${spentMoney(figures.spentUsd)} of its ${money(cap)} cap${holding}; ${needs}, more than the cap leaves even once the steps still running settle. Raise the cap to at least $${figures.leastCapUsd.toFixed(2)} to continue.`;
66
+ }
54
67
  /** A paid call what is left cannot hold. */
55
68
  export function paidRefusal(cap, spent, held, name, holdUsd, basis) {
56
69
  const leastCapUsd = raiseFigure(cap, spent + held + holdUsd);
57
70
  return {
58
71
  text: `${SPEND_CAP_REACHED}: Not sent: this run has ${spentOf(spent, held, cap)}, and the next step, ${name}, could cost up to ${money(holdUsd)} (${basis}). Raise the cap to at least $${leastCapUsd.toFixed(2)} to continue.`,
59
- figures: { spentUsd: spent + held, needsUsd: holdUsd, leastCapUsd, step: { name, holdUsd, basis } },
72
+ figures: { spentUsd: spent, heldUsd: held, needsUsd: holdUsd, leastCapUsd, step: { name, holdUsd, basis } },
60
73
  };
61
74
  }
62
75
  /** An amount rounded up to the cent, so "at most" holds. */
63
76
  const centsUp = (usd) => money(Math.ceil(usd * 100 - 1e-9) / 100);
64
- /** The over-cap row's words, after the usage row whose booked cost `spentUsd` passed `capUsd`: by how much; when it passed
65
- * by no more than `boundUsd` (the bound of the requests since the cost last fit), a cache miss did it, and the most it
66
- * could have. None at or under the cap, with no cap, or with no known cost. */
67
- export function overCapWords(spentUsd, capUsd, boundUsd = 0) {
77
+ /** The over-cap row's words, after the usage row whose booked cost `spentUsd` passed `capUsd`: by how much. A request is
78
+ * held at its worst case, so only a cost its admission never priced passes the cap (an owed charge, a provider that bills
79
+ * past its list price). None at or under the cap, with no cap, or with no known cost. */
80
+ export function overCapWords(spentUsd, capUsd) {
68
81
  if (capUsd === undefined || typeof spentUsd !== "number" || spentUsd <= capUsd + FIT_TOLERANCE)
69
82
  return undefined;
70
- const byMiss = boundUsd > 0 && spentUsd - capUsd <= boundUsd + FIT_TOLERANCE;
71
- return byMiss ? `Went ${centsUp(spentUsd - capUsd)} over its cap on a cache miss (at most ${centsUp(boundUsd)}).` : `Spent ${centsMoney(spentUsd)}, ${centsUp(spentUsd - capUsd)} over the run's cap of ${centsMoney(capUsd)}`;
83
+ return `Spent ${centsMoney(spentUsd)}, ${centsUp(spentUsd - capUsd)} over the run's cap of ${centsMoney(capUsd)}`;
72
84
  }
73
85
  /** How a run ends whose booked cost `spentUsd` passed `capUsd`: failed, in these words (main's run end), the answer that
74
- * crossed it booked. None at or under the cap, with no cap, with no known cost, or when it passed by no more than
75
- * `boundUsd` (a cache miss within the bound it was admitted at: the run pauses at its next request instead). */
76
- export function overCapEnd(spentUsd, capUsd, boundUsd = 0) {
86
+ * crossed it booked. None at or under the cap, with no cap, or with no known cost. */
87
+ export function overCapEnd(spentUsd, capUsd) {
77
88
  if (capUsd === undefined || typeof spentUsd !== "number" || spentUsd <= capUsd + FIT_TOLERANCE)
78
89
  return undefined;
79
- if (boundUsd > 0 && spentUsd - capUsd <= boundUsd + FIT_TOLERANCE)
80
- return undefined;
81
90
  return `${OVER_CAP_END}${centsMoney(spentUsd)}, ${centsUp(spentUsd - capUsd)} over its cap of ${centsMoney(capUsd)}.`;
82
91
  }
83
92
  /** How overCapEnd's words begin, and only theirs: a reader of a run's summary serves one that does as the error
@@ -13,5 +13,9 @@ export declare function typicalCost(costs: readonly unknown[], nextExpected: num
13
13
  export declare function wrapUpDue(cap: number, spent: number, held: number, typical: number, leastUsd?: number): {
14
14
  leftUsd: number;
15
15
  } | undefined;
16
+ /** What every note the run's model is told by the server begins with (this wrap-up, and serve's note that its computer
17
+ * was replaced), so the model names it as the server's, never as an error of its own conversation. The server's row
18
+ * for such a note (serve's timeline, "AgentRun: …") is labelled already, and says the words after it. */
19
+ export declare const SERVER_NOTE_LABEL = "AgentRun server note: ";
16
20
  /** The note's words, what is left to the cent; before any priced request, the budget and a short answer. */
17
21
  export declare const wrapUpWords: (leftUsd: number, nonePriced?: boolean) => string;
@@ -30,8 +30,12 @@ export function wrapUpDue(cap, spent, held, typical, leastUsd) {
30
30
  const byLeast = leastUsd !== undefined && Number.isFinite(leastUsd) && leftUsd < WRAP_UP_LEAST_FACTOR * leastUsd;
31
31
  return byTypical || byLeast ? { leftUsd } : undefined;
32
32
  }
33
+ /** What every note the run's model is told by the server begins with (this wrap-up, and serve's note that its computer
34
+ * was replaced), so the model names it as the server's, never as an error of its own conversation. The server's row
35
+ * for such a note (serve's timeline, "AgentRun: …") is labelled already, and says the words after it. */
36
+ export const SERVER_NOTE_LABEL = "AgentRun server note: ";
33
37
  /** The note's words, what is left to the cent; before any priced request, the budget and a short answer. */
34
38
  export const wrapUpWords = (leftUsd, nonePriced = false) => {
35
39
  const left = centsMoney(Math.max(0, leftUsd));
36
- return nonePriced ? `This run's budget is about ${left}, enough for little work: answer as soon as you can.` : `About ${left} left of this run's budget: finish now with your answer.`;
40
+ return `${SERVER_NOTE_LABEL}${nonePriced ? `This run's budget is about ${left}, enough for little work: answer as soon as you can.` : `About ${left} left of this run's budget: finish now with your answer.`}`;
37
41
  };
@@ -1,6 +1,6 @@
1
1
  /** Each per-step tool's parameters, as JSON Schema. */
2
2
  export declare const COMPUTER_TOOL_SCHEMAS: {
3
- readonly [tool in "computer_observe" | "computer_act" | "computer_screenshot" | "computer_script"]: object;
3
+ readonly [tool in "computer_observe" | "computer_act" | "computer_screenshot"]: object;
4
4
  };
5
5
  /** computer_act's steps as TypeScript, for its description: its schema types them, with no words. */
6
6
  export declare const ACT_STEPS = "type UiStep = { press: UiRef; } | { set: UiRef; value: string; } | { perform: UiRef; action: string; } | { click: UiRef | Point; button?: \"left\" | \"right\"; count?: 1 | 2 | 3; } | { type: string; into?: UiRef; } | { key: string; } | { nav: \"back\" | \"home\" | \"app_switch\"; } | { scroll: UiRef | Point; dx?: number; dy?: number; } | { drag: Point[]; ms?: number; }; type UiRef = string; type Point = [ x: number, y: number ];";
@@ -6,7 +6,7 @@ export const COMPUTER_TOOL_SCHEMAS = {
6
6
  "type": "object",
7
7
  "properties": {
8
8
  "app": {
9
- "description": "Default: the app in front.",
9
+ "description": "Default: the app in front. With no ui group, opened or brought in front first.",
10
10
  "type": "string"
11
11
  },
12
12
  "image": {
@@ -24,7 +24,7 @@ export const COMPUTER_TOOL_SCHEMAS = {
24
24
  "type": "object",
25
25
  "properties": {
26
26
  "app": {
27
- "description": "Default: the state's app, else the app in front.",
27
+ "description": "Default: the state's app, else the app in front. With no ui group, opened or brought in front first.",
28
28
  "type": "string"
29
29
  },
30
30
  "state": {
@@ -308,27 +308,6 @@ export const COMPUTER_TOOL_SCHEMAS = {
308
308
  }
309
309
  },
310
310
  "additionalProperties": false
311
- },
312
- "computer_script": {
313
- "type": "object",
314
- "properties": {
315
- "code": {
316
- "description": "An async function's body; `return` what you need.",
317
- "type": "string"
318
- },
319
- "title": {
320
- "description": "For the run's timeline.",
321
- "type": "string"
322
- },
323
- "timeoutMs": {
324
- "description": "Default 120000, at most 600000.",
325
- "type": "number"
326
- }
327
- },
328
- "additionalProperties": false,
329
- "required": [
330
- "code"
331
- ]
332
311
  }
333
312
  };
334
313
  /** computer_act's steps as TypeScript, for its description: its schema types them, with no words. */
@@ -416,13 +395,18 @@ const TYPES = [
416
395
  },
417
396
  {
418
397
  "name": "UiStep",
419
- "uses": [],
420
- "text": "type UiStep = object; // computer_act's steps"
398
+ "uses": [
399
+ "UiRef",
400
+ "Point"
401
+ ],
402
+ "text": "type UiStep = { press: UiRef; } | { set: UiRef; value: string; } | { perform: UiRef; action: string; } | { click: UiRef | Point; button?: \"left\" | \"right\"; count?: 1 | 2 | 3; } | { type: string; into?: UiRef; } | { key: string; } | { nav: \"back\" | \"home\" | \"app_switch\"; } | { scroll: UiRef | Point; dx?: number; dy?: number; } | { drag: Point[]; ms?: number; };"
421
403
  },
422
404
  {
423
405
  "name": "UiExpect",
424
- "uses": [],
425
- "text": "type UiExpect = object; // computer_act's expect"
406
+ "uses": [
407
+ "UiRef"
408
+ ],
409
+ "text": "interface UiExpect { text?: string; ref?: UiRef; window?: { title?: string; role?: string; }; gone?: boolean; timeoutMs?: number; }"
426
410
  },
427
411
  {
428
412
  "name": "Image",
@@ -577,6 +561,13 @@ const MEMBERS = [
577
561
  ],
578
562
  "text": "readonly shell: { run(command: string | string[], options?: { cwd?: string; timeoutMs?: number; env?: Record<string, string>; }): Promise<RunResult>; };"
579
563
  },
564
+ {
565
+ "groups": [
566
+ "processes"
567
+ ],
568
+ "uses": [],
569
+ "text": "readonly processes: { start(command: string | string[], options?: { cwd?: string; env?: Record<string, string>; }): Promise<{ pid: number; }>; };"
570
+ },
580
571
  {
581
572
  "groups": [
582
573
  "files"
@@ -1,14 +1,21 @@
1
1
  import type { ToolDef } from "./defs.js";
2
2
  import { type CapabilityKind, type Executor } from "./hands.js";
3
+ /** The tool a script's `computer` runs every op through that no step tool runs. */
4
+ export declare const COMPUTER_OP_TOOL = "computer_op";
3
5
  /** The computer's tools, in the order a run lists them (the hand-over last). */
4
- export declare const COMPUTER_TOOLS: readonly ["computer_observe", "computer_act", "computer_screenshot", "computer_script", "computer_request_handoff"];
5
- /** The tool a host runs itself: a script runs in the host's isolate, over the same port. */
6
- export declare const SCRIPT_TOOL = "computer_script";
6
+ export declare const COMPUTER_TOOLS: readonly ["computer_observe", "computer_act", "computer_screenshot", "computer_op", "computer_request_handoff"];
7
+ /** The ops computer_op runs, each with the groups that offer it (one of them): the surface's ops (SURFACE_OPS) but the
8
+ * three the step tools run. */
9
+ export declare const COMPUTER_OPS: Readonly<Record<string, readonly string[]>>;
10
+ /** The op of each step tool, as a script's `computer` names it. */
11
+ export declare const STEP_TOOL_OPS: Readonly<Record<string, string>>;
12
+ /** The ops computer_op runs on a computer with `groups`. */
13
+ export declare function computerOpsFor(groups: readonly string[]): readonly string[];
7
14
  /** The tools a computer with `groups` offers: observe and act with the ui group, or a screen (observe) and input (act)
8
- * without it; the screenshot with a screen; the script with any of them. */
15
+ * without it; the screenshot with a screen; computer_op with any op past those (computerOpsFor). */
9
16
  export declare function computerToolsFor(groups: readonly string[]): readonly string[];
10
- /** The computer's tools in `kind`, under its settings key, for a computer with `groups` (the script's declarations
11
- * hold only what they offer). A script and an act change the computer: never replayed. */
17
+ /** The computer's tools in `kind`, under its settings key, for a computer with `groups`. An act or an op changes the
18
+ * computer: never replayed. */
12
19
  export declare function computerToolDefs(kind: CapabilityKind, groups: readonly string[]): readonly ToolDef[];
13
- /** The kernel's own executors of the computer's tools in `kind`: all but the script, which the host runs. */
20
+ /** The kernel's own executors of the computer's tools in `kind`. */
14
21
  export declare const computerExecutors: (kind: CapabilityKind) => Readonly<Record<string, Executor>>;
@@ -1,43 +1,79 @@
1
- import { ACT_STEPS, COMPUTER_TOOL_SCHEMAS, computerDeclarations } from "./computer-surface.generated.js";
1
+ import { ACT_STEPS, COMPUTER_TOOL_SCHEMAS } from "./computer-surface.generated.js";
2
2
  import { answerOf, needsKindWords } from "./hands.js";
3
3
  import { HANDOFF_TOOL, handoffDef, handoffExecutor } from "./handoff.js";
4
+ /** The tool a script's `computer` runs every op through that no step tool runs. */
5
+ export const COMPUTER_OP_TOOL = "computer_op";
4
6
  /** 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";
7
+ export const COMPUTER_TOOLS = ["computer_observe", "computer_act", "computer_screenshot", COMPUTER_OP_TOOL, HANDOFF_TOOL];
8
+ /** The ops computer_op runs, each with the groups that offer it (one of them): the surface's ops (SURFACE_OPS) but the
9
+ * three the step tools run. */
10
+ export const COMPUTER_OPS = Object.freeze({
11
+ "input.act": ["input.pointer", "input.touch", "input.keys"],
12
+ "apps.list": ["apps"],
13
+ "apps.open": ["apps"],
14
+ "shell.run": ["exec"],
15
+ "processes.start": ["processes"],
16
+ "files.read": ["files"],
17
+ "files.write": ["files"],
18
+ "files.list": ["files"],
19
+ "files.stat": ["files"],
20
+ });
21
+ /** The op of each step tool, as a script's `computer` names it. */
22
+ export const STEP_TOOL_OPS = Object.freeze({ observe: "computer_observe", act: "computer_act", screenshot: "computer_screenshot" });
8
23
  // The words are short on purpose: every request of a run with a computer carries them. The kind skill (desktop-computer,
9
24
  // phone-computer) teaches how to work; a description says only what its tool does.
10
25
  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
26
  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
27
  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\`\`\``;
28
+ const OP = `One of the computer's ops no other tool runs, as a script's \`computer\` calls it: input.act {actions}, apps.list, apps.open {id, url?, background?}, shell.run {command, cwd?, env?, timeoutMs?}, processes.start {command, cwd?, env?}, files.read {path, encoding?}, files.write {path, data, encoding?}, files.list {path}, files.stat {path}. An op this computer does not offer is refused.`;
29
+ /** The ops computer_op runs on a computer with `groups`. */
30
+ export function computerOpsFor(groups) {
31
+ return Object.keys(COMPUTER_OPS).filter((op) => COMPUTER_OPS[op].some((group) => groups.includes(group)));
32
+ }
15
33
  /** 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. */
34
+ * without it; the screenshot with a screen; computer_op with any op past those (computerOpsFor). */
17
35
  export function computerToolsFor(groups) {
18
36
  const has = (group) => groups.includes(group);
19
37
  const input = has("input.pointer") || has("input.touch") || has("input.keys");
20
38
  const observe = has("ui") || has("screen");
21
39
  const act = has("ui") || input;
22
- return [...(observe ? ["computer_observe"] : []), ...(act ? ["computer_act"] : []), ...(has("screen") ? ["computer_screenshot"] : []), ...(observe || act ? [SCRIPT_TOOL] : []), HANDOFF_TOOL];
40
+ return [...(observe ? ["computer_observe"] : []), ...(act ? ["computer_act"] : []), ...(has("screen") ? ["computer_screenshot"] : []), ...(computerOpsFor(groups).length > 0 ? [COMPUTER_OP_TOOL] : []), HANDOFF_TOOL];
23
41
  }
24
- const def = (kind, name, description, replaySafe) => ({
42
+ /** computer_act's parameters on a computer with no ui group: no expect, which only the ui group checks, so neither the
43
+ * expect nor the wait on one (an empty act with an expect) is offered there. */
44
+ const ACT_WITHOUT_UI = (() => {
45
+ const schema = COMPUTER_TOOL_SCHEMAS.computer_act;
46
+ const { expect: _, ...properties } = schema.properties;
47
+ return { ...schema, properties: { ...properties, steps: { ...properties.steps, description: "Run in order." } } };
48
+ })();
49
+ const def = (kind, name, description, replaySafe, parameters = COMPUTER_TOOL_SCHEMAS[name]) => ({
25
50
  name,
26
51
  source: "host",
27
52
  gateName: `host:${kind}/${name}`,
28
53
  settingsKey: kind,
29
54
  description,
30
- parameters: COMPUTER_TOOL_SCHEMAS[name],
55
+ parameters,
31
56
  replaySafe,
32
57
  });
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. */
58
+ /** computer_op's parameters: the op, and its arguments as a script's `computer` gives them. */
59
+ const OP_PARAMETERS = {
60
+ type: "object",
61
+ properties: {
62
+ op: { type: "string", enum: Object.keys(COMPUTER_OPS) },
63
+ args: { type: "object", description: "The op's arguments." },
64
+ },
65
+ required: ["op"],
66
+ additionalProperties: false,
67
+ };
68
+ /** The computer's tools in `kind`, under its settings key, for a computer with `groups`. An act or an op changes the
69
+ * computer: never replayed. */
35
70
  export function computerToolDefs(kind, groups) {
36
71
  return Object.freeze([
37
- def(kind, "computer_observe", OBSERVE, true),
38
- def(kind, "computer_act", ACT, false),
72
+ // With apps and no ui group, an observe that names an app opens it first: it changes the screen, so it never runs again.
73
+ def(kind, "computer_observe", OBSERVE, groups.includes("ui") || !groups.includes("apps")),
74
+ def(kind, "computer_act", ACT, false, groups.includes("ui") ? undefined : ACT_WITHOUT_UI),
39
75
  def(kind, "computer_screenshot", SCREENSHOT, true),
40
- def(kind, "computer_script", scriptWords(groups), false),
76
+ def(kind, COMPUTER_OP_TOOL, OP, false, OP_PARAMETERS),
41
77
  handoffDef(kind),
42
78
  ]);
43
79
  }
@@ -58,10 +94,22 @@ const surfaceExecutor = (kind, tool, op) => (args, call) => answerOf(call, async
58
94
  const answer = await port.call(op, args ?? {}, call.signal);
59
95
  return { text: answer.text, ...(answer.images.length > 0 ? { images: answer.images } : {}), structured: (withoutImageData(answer.value) ?? null) };
60
96
  });
61
- /** The kernel's own executors of the computer's tools in `kind`: all but the script, which the host runs. */
97
+ /** computer_op's run: `op` with `args` on the hands' computer port. An op a step tool runs is sent to that tool, so each
98
+ * is held and recorded as that tool's call; any other the port refuses where the computer does not offer it. */
99
+ const opExecutor = (kind) => (args, call) => {
100
+ const { op, args: given } = (args ?? {});
101
+ const tool = typeof op === "string" ? STEP_TOOL_OPS[op] : undefined;
102
+ if (tool)
103
+ return answerOf(call, async () => { throw new Error(`${COMPUTER_OP_TOOL} does not run ${op}: call ${tool}, which does`); });
104
+ if (typeof op !== "string" || !Object.hasOwn(COMPUTER_OPS, op))
105
+ return answerOf(call, async () => { throw new Error(`${COMPUTER_OP_TOOL} runs one of ${Object.keys(COMPUTER_OPS).join(", ")}: not ${JSON.stringify(op)}`); });
106
+ return surfaceExecutor(kind, COMPUTER_OP_TOOL, op)(given !== null && typeof given === "object" && !Array.isArray(given) ? given : {}, call);
107
+ };
108
+ /** The kernel's own executors of the computer's tools in `kind`. */
62
109
  export const computerExecutors = (kind) => ({
63
110
  computer_observe: surfaceExecutor(kind, "computer_observe", "observe"),
64
111
  computer_act: surfaceExecutor(kind, "computer_act", "act"),
65
112
  computer_screenshot: surfaceExecutor(kind, "computer_screenshot", "screenshot"),
113
+ [COMPUTER_OP_TOOL]: opExecutor(kind),
66
114
  [HANDOFF_TOOL]: handoffExecutor(kind),
67
115
  });
@@ -9,8 +9,8 @@ export declare const SHELL_FAMILY: Readonly<Record<string, string>>;
9
9
  export declare const SHELL_WATCHERS: ReadonlySet<string>;
10
10
  /** Shell tool `name`'s permission, given bash's: a watcher's ask is allow; any other keeps bash's. */
11
11
  export declare const shellPermission: (name: string, bash: Permission) => Permission;
12
- /** The shell tool a call named `name` is, under claude-agent's host-tool name too (`mcp__hands__bash_background`), when
13
- * it is one held to another's setting: its own name, which its request, its refusal and its approved call keep. */
12
+ /** The shell tool a call named `name` is, when it is one held to another's setting: its own name, which its request, its
13
+ * refusal and its approved call keep. */
14
14
  export declare const shellToolOf: (name: string) => string | undefined;
15
15
  /** A host tool's permission when no setting names it, by where the run's shell is. On a computer every host tool is
16
16
  * allowed, as main's defaults are. With no computer, bash runs in the run's own folder on this machine, so it is asked
@@ -1,4 +1,4 @@
1
- // The tool gate's shell family, moved from serve's tool-gate.ts unchanged, and the host tools' default permissions by
1
+ // The tool gate's shell family (serve's tool-gate.ts reads it from here), and the host tools' default permissions by
2
2
  // where the run's shell is (the cutover's ruled change: with no computer, bash runs in the run's folder and is asked
3
3
  // first, and the background tools are refused).
4
4
  import { BACKGROUND_TOOLS, SHELL_TOOLS } from "./limits.js";
@@ -12,12 +12,9 @@ export const SHELL_FAMILY = Object.freeze(Object.fromEntries(SHELL_TOOLS.map((na
12
12
  export const SHELL_WATCHERS = new Set(["bash_output", "bash_list", "bash_signal"]);
13
13
  /** Shell tool `name`'s permission, given bash's: a watcher's ask is allow; any other keeps bash's. */
14
14
  export const shellPermission = (name, bash) => (bash === "ask" && SHELL_WATCHERS.has(name) ? "allow" : bash);
15
- /** The shell tool a call named `name` is, under claude-agent's host-tool name too (`mcp__hands__bash_background`), when
16
- * it is one held to another's setting: its own name, which its request, its refusal and its approved call keep. */
17
- export const shellToolOf = (name) => {
18
- const own = name.replace(/^mcp__hands__/, "");
19
- return Object.hasOwn(SHELL_FAMILY, own) && SHELL_FAMILY[own] !== own ? own : undefined;
20
- };
15
+ /** The shell tool a call named `name` is, when it is one held to another's setting: its own name, which its request, its
16
+ * refusal and its approved call keep. */
17
+ export const shellToolOf = (name) => (Object.hasOwn(SHELL_FAMILY, name) && SHELL_FAMILY[name] !== name ? name : undefined);
21
18
  /** A host tool's permission when no setting names it, by where the run's shell is. On a computer every host tool is
22
19
  * allowed, as main's defaults are. With no computer, bash runs in the run's own folder on this machine, so it is asked
23
20
  * first, and the background tools, which need a computer, are refused. */
@@ -71,7 +71,7 @@ export type ComputerAnswer = {
71
71
  readonly images: readonly ToolImage[];
72
72
  };
73
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
74
+ * input.act, apps.list, apps.open, shell.run, processes.start, files.read, files.write, files.list, files.stat), which
75
75
  * @parcha/agentrun-computer's surface answers the same for a per-step tool, a script and the claim's MCP endpoint. A
76
76
  * refusal throws an error with a `kind` (stale, unsupported, ...) and the computer's words; an abort throws. */
77
77
  export type ComputerPort = {
@@ -127,7 +127,7 @@ export type Hands = {
127
127
  }, signal?: AbortSignal): Promise<ExecResult>;
128
128
  /** The attached computer's processes; absent with no computer, where the background tools are refused. */
129
129
  readonly processes?: Processes;
130
- /** A desktop's or a phone's surface (computer_observe, computer_act, computer_screenshot, computer_script); absent
130
+ /** A desktop's or a phone's surface (computer_observe, computer_act, computer_screenshot); absent
131
131
  * where the computer is neither, and those tools are refused in words. */
132
132
  readonly computer?: ComputerPort;
133
133
  /** A desktop's or a phone's hand-over to the person (the run's hold); absent where there is none. */
@@ -163,6 +163,5 @@ export type ToolCall = {
163
163
  export declare function answerOf(call: ToolCall, run: () => Promise<ToolAnswer>): Promise<ToolAnswer>;
164
164
  /** A host tool's run. */
165
165
  export type Executor = (args: unknown, call: ToolCall) => Promise<ToolAnswer>;
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>>>;
166
+ /** What the host gives the registry, by tool name: read, write and edit, and bash's own run, which the registry bounds. */
167
+ export type HostExecutors = Readonly<Partial<Record<"read" | "write" | "edit" | "bash", Executor>>>;
@@ -2,7 +2,7 @@ export { BACKGROUND_EXECUTORS, endBackground, NEEDS_A_COMPUTER, NO_SHELL } from
2
2
  export { boundedBash } from "./bash.js";
3
3
  export { bashTimeoutWords, CAPABILITY_KINDS, hostToolDefs } from "./defs.js";
4
4
  export type { ShellPlace, ToolDef } from "./defs.js";
5
- export { COMPUTER_TOOLS, computerExecutors, computerToolDefs, computerToolsFor, SCRIPT_TOOL } from "./computer.js";
5
+ export { COMPUTER_OP_TOOL, COMPUTER_OPS, COMPUTER_TOOLS, computerExecutors, computerOpsFor, computerToolDefs, computerToolsFor, STEP_TOOL_OPS } from "./computer.js";
6
6
  export { COMPUTER_TOOL_SCHEMAS, computerDeclarations } from "./computer-surface.generated.js";
7
7
  export { defaultPermissionOf, SHELL_FAMILY, SHELL_WATCHERS, shellPermission, shellToolOf } from "./gate.js";
8
8
  export type { Permission } from "./gate.js";
@@ -5,7 +5,7 @@
5
5
  export { BACKGROUND_EXECUTORS, endBackground, NEEDS_A_COMPUTER, NO_SHELL } from "./background.js";
6
6
  export { boundedBash } from "./bash.js";
7
7
  export { bashTimeoutWords, CAPABILITY_KINDS, hostToolDefs } from "./defs.js";
8
- export { COMPUTER_TOOLS, computerExecutors, computerToolDefs, computerToolsFor, SCRIPT_TOOL } from "./computer.js";
8
+ export { COMPUTER_OP_TOOL, COMPUTER_OPS, COMPUTER_TOOLS, computerExecutors, computerOpsFor, computerToolDefs, computerToolsFor, STEP_TOOL_OPS } from "./computer.js";
9
9
  export { COMPUTER_TOOL_SCHEMAS, computerDeclarations } from "./computer-surface.generated.js";
10
10
  export { defaultPermissionOf, SHELL_FAMILY, SHELL_WATCHERS, shellPermission, shellToolOf } from "./gate.js";
11
11
  export { answerOf, exitCodeOf, needsKindWords } from "./hands.js";
@@ -1,14 +1,15 @@
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
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,
4
+ // tools after them (computer.ts), as its groups offer them, under its kind's settings key: observe, act, screenshot,
5
+ // computer_op (a codemode script's every other op) and the hand-over run on the kernel's own executors over the hands'
6
+ // computer port. A registry missing an executor for a
7
+ // tool the model sees is refused when it is built,
7
8
  // 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
9
  // the setting.
9
10
  import { BACKGROUND_EXECUTORS, NEEDS_A_COMPUTER, NO_SHELL } from "./background.js";
10
11
  import { boundedBash } from "./bash.js";
11
- import { COMPUTER_TOOLS, computerExecutors, computerToolDefs, computerToolsFor, SCRIPT_TOOL } from "./computer.js";
12
+ import { COMPUTER_TOOLS, computerExecutors, computerToolDefs, computerToolsFor } from "./computer.js";
12
13
  import { CAPABILITY_KINDS, hostToolDefs } from "./defs.js";
13
14
  import { answerOf, needsKindWords } from "./hands.js";
14
15
  import { BACKGROUND_TOOLS } from "./limits.js";
@@ -36,11 +37,7 @@ export function createRegistry(options) {
36
37
  for (const def of computerToolDefs(kind, groups)) {
37
38
  if (!offered.includes(def.name))
38
39
  continue;
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.
41
- if (!run)
42
- continue;
43
- runs.set(def.name, run);
40
+ runs.set(def.name, kernel[def.name]);
44
41
  defs.push(def);
45
42
  }
46
43
  }