@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
package/dist/types.d.ts CHANGED
@@ -36,6 +36,14 @@ export declare const HOST_RESULT_MAX_CHARS = 120000;
36
36
  * answer again. A host reads a run's end by it (agentrun-serve's `moderated`).
37
37
  */
38
38
  export declare const CONTENT_FILTERED = "content_filter: the model provider stopped this answer";
39
+ /**
40
+ * What a run on a person's ChatGPT plan ends with once the plan's limit is reached (its 429): the plan's own limit, never
41
+ * the run's spend cap, so nothing here can raise it and nothing tries again. A harness's model proxy answers its client
42
+ * these words (`ProviderPolicy.finalError`) and the harness halts the turn with them; a host shows them as they are.
43
+ */
44
+ export declare const PLAN_LIMIT_WORDS = "Your ChatGPT plan's limit is reached. Manage usage in your ChatGPT settings, then run it again.";
45
+ /** The code the proxy's answer carries beside PLAN_LIMIT_WORDS. */
46
+ export declare const PLAN_LIMIT_CODE = "plan_limit_reached";
39
47
  /** A tool the host gives a session. */
40
48
  export interface HostTool {
41
49
  name: string;
@@ -56,7 +64,8 @@ export interface HostTool {
56
64
  sessionDir?: (key: string) => string; /** The kernel's attempt at this call: 0 the first time; above 0 when a crash cut an earlier attempt of a replay-safe tool and this one runs it again, so the earlier one may have been sent. */
57
65
  attempt?: number;
58
66
  model?: unknown;
59
- output?(chunk: string): void;
67
+ output?(chunk: string): void; /** The session's other tools, called as calls of their own nested in this one (NestedCalls): given to a tool that `nests`, where the harness has a way to. */
68
+ nested?: NestedCalls;
60
69
  }): Promise<{
61
70
  text: string;
62
71
  isError?: boolean;
@@ -64,6 +73,43 @@ export interface HostTool {
64
73
  structured?: JsonValue;
65
74
  parked?: true;
66
75
  }>;
76
+ /** The tool only calls the session's other tools (tools_call, codemode), each as a call of its own nested in this one
77
+ * (`context.nested`): each nested call passes the gate as itself and is recorded under its own id, so this call writes
78
+ * no intent or outcome of its own. A harness runs it again after a crash, its recorded nested calls answered from their
79
+ * records, never run twice. */
80
+ nests?: true;
81
+ /** Registered and callable (by the gate, and by a nested call: tools_call, a script), but not listed to the model: a
82
+ * catalog tool of a run whose catalog is deferred (tool-deferral.ts), which the model finds with tools_search. */
83
+ deferred?: true;
84
+ }
85
+ /**
86
+ * A tool's calls of the session's other tools, each a call of its own nested in the calling one: asked about at the gate
87
+ * as itself (GateCall `nested`), its intent and outcome recorded under `<callId>/<key>` before and after it runs, as a
88
+ * call the model made is. A call the record finished answers from the record, never runs again.
89
+ */
90
+ export interface NestedCalls {
91
+ /** Call tool `name` (a session tool, by its host name) with `args`, under `key`: stable for the same call in a rerun
92
+ * of the calling one. A deny answers `refused` with the gate's words; a park holds until the session lets go, then
93
+ * rejects. Given `signal`, the call runs on it as well as on the calling one's: a caller that cuts one part of its work
94
+ * (a learned workflow's node whose sibling failed) cuts that part's call. */
95
+ call(name: string, args: Record<string, unknown>, key: string, signal?: AbortSignal): Promise<NestedResult>;
96
+ /** `value` the first time `key` is asked in this call, and that first value again in every rerun of the call. Given a
97
+ * function, it is called only the first time: a rerun reads the recorded value and never calls it, so work it does (a
98
+ * model's request, a paid decision) is done and paid for once. */
99
+ memo<T extends JsonValue>(key: string, value: T | (() => T | Promise<T>)): Promise<T>;
100
+ }
101
+ /** A nested call's answer. */
102
+ export interface NestedResult {
103
+ text: string;
104
+ isError?: boolean;
105
+ images?: readonly ToolImage[];
106
+ structured?: JsonValue;
107
+ /** The gate refused it: `text` is the gate's words, and nothing of it ran. */
108
+ refused?: true;
109
+ /** Its intent was recorded and its outcome lost (a crash cut it): it may or may not have taken effect. */
110
+ interrupted?: true;
111
+ /** It was asked and run (or refused) now, in this attempt of the calling call; false when its answer came from the record. */
112
+ fresh: boolean;
67
113
  }
68
114
  /** A tool of a remote MCP server, as the server listed it when its owner saved it (the run's pinned copy). */
69
115
  export interface McpTool {
@@ -73,29 +119,13 @@ export interface McpTool {
73
119
  inputSchema: Record<string, unknown>;
74
120
  annotations?: Record<string, unknown>;
75
121
  }
76
- /** What an MCP tool call answers the model: its text, and whether the tool said it failed. */
122
+ /** What an MCP tool call answers: its text, and whether the tool said it failed. */
77
123
  export interface McpCallResult {
78
124
  content: {
79
125
  type: "text";
80
126
  text: string;
81
127
  }[];
82
128
  isError?: boolean;
83
- /** The host parked the call for a person's approval: it did not run, and the text says it waits. The harness's own
84
- * client never sees this flag (the door sends `content` and `isError`). */
85
- parked?: true;
86
- }
87
- /** A session's remote MCP servers: each one's granted tools, and the call that reaches them through the host, which holds
88
- * their credentials. A harness with its own MCP client points it at the session's model proxy (`/mcp/<server>`). */
89
- export interface SessionMcp {
90
- servers: readonly {
91
- name: string;
92
- tools: readonly McpTool[];
93
- }[];
94
- /** Never throws: a failure is an `isError` result the model reads. `callId` is the harness's id for the call. */
95
- call(server: string, tool: string, args: Record<string, unknown>, context: {
96
- signal: AbortSignal;
97
- callId?: string;
98
- }): Promise<McpCallResult>;
99
129
  }
100
130
  /** One durable record of a session, in the order it was appended. */
101
131
  export interface SessionRecord {
@@ -115,6 +145,12 @@ export interface SessionStore {
115
145
  /** The one holder that may write a session. */
116
146
  export interface SessionWriter {
117
147
  readonly key: string;
148
+ /** The session's identity across the claims of one holder (a runner's name and a run's id beside the key), for a store
149
+ * whose claims a holder can lose and take again. A booking of the session whose cost write is refused (its claim lost
150
+ * as its request answered) hands that booking to the next booking of the same scope in this process, which writes it
151
+ * before it books any request cut (ModelBooking.bookCut). Absent: nothing is handed on, and such a request is booked
152
+ * cut. Never shared by two holders: another runner, as one that died, takes nothing of it. */
153
+ readonly scope?: string;
118
154
  read(): Promise<SessionRecord[]>;
119
155
  /** Resolves once the records are durable, in order. Rejects with `SessionFenced`, writing none of them, once a newer
120
156
  * `open` of the key has resolved. */
@@ -131,11 +167,13 @@ export interface SessionSpec {
131
167
  label: string;
132
168
  executionPath?: string;
133
169
  system: string[];
134
- /** Exactly these tools; the harness's own stay off. */
170
+ /** Exactly these tools (a run's remote MCP tools among them, as host tools); the harness's own stay off. */
135
171
  tools: HostTool[];
136
- /** The remote MCP servers it may call, for a harness that has its own MCP client. */
137
- mcp?: SessionMcp;
138
172
  context: "fresh" | "fork";
173
+ /** The host's one verdict on whether the run's catalog tools are deferred (tool-deferral.ts defersCatalog, and both
174
+ * tools_search and tools_call allowed). A harness with a tool search of its own (`ownToolSearch`) turns it on exactly
175
+ * when this is true; absent, it decides by the names alone. */
176
+ deferCatalog?: boolean;
139
177
  tier?: NodeRequest["tier"];
140
178
  effort?: NodeRequest["effort"];
141
179
  thinking?: NodeRequest["thinking"];
@@ -146,8 +184,6 @@ export interface ModelRequest {
146
184
  /** The most input tokens the request can be billed for (the model proxy's `inputTokensMaxOf`: the body's UTF-8 bytes
147
185
  * plus what the provider adds), undefined when it was not measured. */
148
186
  inputTokensMax?: number;
149
- /** Its `inputTokensMax` is its provider's count, not its bytes (ProxyRequest.inputTokensCounted). */
150
- inputTokensCounted?: true;
151
187
  /** The most output tokens the request asks for, when its body says (the proxy's policy reads it). */
152
188
  outputTokensAsked?: number;
153
189
  /** The least output it may be limited to and still answer: its answer's 1,024 tokens, plus the least thinking its
@@ -164,7 +200,11 @@ export interface ModelRequest {
164
200
  * release, the time a person used): held at `feeUsd` and booked, never asked of the cap's rule, so a run past its cap
165
201
  * or of unknown spend still counts it (main keeps it so: keepHold). `hold`: a hold-only step: money reserved, not
166
202
  * spent; given back on a lost claim, never booked as cut (its holder's charges book the money, each its own step).
167
- * `ref`: the one booking it names (a browser charge's session and time): a second admit of the same ref is not booked. */
203
+ * `ref`: the one booking it names (a browser charge's session and time): a second admit of the same ref is not booked.
204
+ * `under`: the key of the model session whose tool call it runs in (the CLI's session): a request of that session
205
+ * still in flight may be the one that asked for the call, unbooked until the call returns (Claude Code books its
206
+ * cost after its calls, Codex starts a call with its response open), so the call never waits on it (runBooking).
207
+ * Not written on its record. */
168
208
  paid?: {
169
209
  name: string;
170
210
  basis: string;
@@ -175,14 +215,16 @@ export interface ModelRequest {
175
215
  owed?: true;
176
216
  hold?: true;
177
217
  ref?: string;
218
+ under?: string;
178
219
  };
179
220
  /** A side call, never its turn's own: on another model than the session's (a client's title, a summary), or the
180
221
  * host's own request beside the harness's (`host`). */
181
222
  side?: true;
182
223
  /** On the session's model but no answer of the turn (a title, a summary, a child's request): booked as any request, but
183
- * never the session's previous request for the cap's expected pricing, read or replaced. */
224
+ * no answer the host keeps its wrap-up's reserve back for. */
184
225
  unanswered?: true;
185
- /** It carries the host's note (ModelPort.note) in its body: the note is delivered once this request is admitted.
226
+ /** It carries the host's note (ModelPort.note) in its body: admitted, it holds the note until it ends, and the note is
227
+ * told once it is answered (its afterRequest's `ended`), else the host gives it to a later request.
186
228
  * `inputTokensMaxWithoutNote`: its input measured as its client sent it, before the note was placed. */
187
229
  noted?: true;
188
230
  inputTokensMaxWithoutNote?: number;
@@ -194,6 +236,13 @@ export interface ModelRequest {
194
236
  * the session's, for a model of another tier): the host prices it by its model and this route, so one model id two
195
237
  * routes price apart is held at the price its route books it at. Absent: the session's own route. */
196
238
  route?: string;
239
+ /** The reasoning effort its body asks its model at, as its provider names it (the proxy's policy reads it:
240
+ * ProviderPolicy.effortOf), when the body names one. What its least output was read at, so words that name its
241
+ * figures can name it too. */
242
+ effort?: string;
243
+ /** Aborted when the request's client goes (a stop, a cancel, a lost claim): a request still waiting for room under the
244
+ * run's cap (runBooking) leaves its line then, admitted for nothing and holding nothing. */
245
+ signal?: AbortSignal;
197
246
  }
198
247
  /** What a paid request cost, once it completed. */
199
248
  export interface ModelUsage {
@@ -206,13 +255,20 @@ export interface ModelUsage {
206
255
  estimated?: boolean;
207
256
  /** Beside the provider's own figure, what the host's price table makes of the same usage: kept to audit the table. */
208
257
  tableUsd?: number | null;
258
+ /** `plan`: billed to a person's subscription plan (a ChatGPT plan's token), not by the token: `usd` is null. */
259
+ billing?: "plan";
209
260
  /** A request a crash cut off: it left, and no answer came back to this run. Its tokens are unknown (0 here) and its
210
261
  * price is null; the provider may have billed it. */
211
262
  cut?: boolean;
263
+ /** A cut request its host held a figure for: booked at that hold (runner.ts CUT_AT_HOLD), the most it can have cost. */
264
+ atMostUsd?: number;
212
265
  /** A paid step's hold given back unused (a workflow call node's, its effect never sent the paid request it held for):
213
266
  * nothing was sent and nothing charged, at usd 0. Its record says so, so no reader takes it for a $0 charge or an
214
267
  * unpriced one. */
215
268
  givenBack?: true;
269
+ /** On a free model (its known price $0 for every token): booked a known $0 however it ended, `usd` 0, set by the
270
+ * runner's booking (Admitted.free) on what it tells of the request's end, for a reader to say why it cost nothing. */
271
+ free?: true;
216
272
  /** The ids the provider's response gave the request, by header name (the provider's `request-id`, a gateway's call
217
273
  * id such as LiteLLM's `x-litellm-call-id`): what joins this booking to the provider's own log. A cut request has
218
274
  * them only if its response had begun. */
@@ -241,14 +297,15 @@ export interface ModelPort {
241
297
  responded?(ids: Record<string, string>, ticket?: ModelTicket): Promise<void>;
242
298
  /** A note its host has for the session's next main-model request (the spend cap's wrap-up), taken by this call; the
243
299
  * session's model proxy adds it to that request's body (ModelProxyHooks.note). `request`: that request as its client
244
- * sent it, measured before the note is placed (NoteRequest), so the host can price it as its admission will. */
300
+ * sent it, measured before the note is placed (NoteRequest), so the host prices it as its admission will. */
245
301
  note?(model: string, request?: NoteRequest): string | undefined;
246
302
  /** The note `note` gave back: the request that took it left before its admission (its client gone, a refusal or an
247
303
  * error before `beforeRequest`), so it was never sent, and the host may give it to the next request at once. */
248
304
  noteReturned?(note: string): void;
249
305
  }
250
- /** A request about to take its host's note, as its client sent it: its input bound and the output it asks for and needs
251
- * at least, as the model proxy reads them (ModelRequest's figures, without the note). */
306
+ /** A request about to take its host's note, as its client sent it: its input bound (the provider's count or the local
307
+ * count where the proxy took one, else its bytes) and the output it asks for and needs at least, as the model proxy reads
308
+ * them: ModelRequest's figures without the note (its `inputTokensMaxWithoutNote`), the same ones the cap admits it by. */
252
309
  export type NoteRequest = {
253
310
  inputTokensMax?: number;
254
311
  outputTokensAsked?: number;
@@ -294,6 +351,24 @@ export interface SessionIO {
294
351
  * a side effect, the host's hooks on the result). An adapter hands every tool it adds through it. Absent: the host
295
352
  * keeps no record of calls, and the tool runs as it is. */
296
353
  hostTool?(tool: HostTool): HostTool;
354
+ /** The host's record of a call of the harness's own that runs host tools inside it (Codex's code-mode `exec`): its row,
355
+ * and each host tool call it makes nested under it, as a host tool that `nests` (codemode) has its calls on every other
356
+ * harness. Absent: the host keeps no record of calls. */
357
+ ownCalls?: OwnCalls;
358
+ }
359
+ /** The record of a call of the harness's own that host tool calls nest in (SessionIO.ownCalls). Each is said from what the
360
+ * harness's own stream holds (the call's id, its input, its output), never a made-up id. */
361
+ export interface OwnCalls {
362
+ /** The call started, `input` what it was given (once per call id: a second says nothing). */
363
+ opened(callId: string, name: string, input: unknown): Promise<void>;
364
+ /** The host tool call `callId` runs inside the harness's call `parent`: said before the call reaches the gate, so its
365
+ * row (a refused or parked one's too) names its parent. */
366
+ nestedIn(callId: string, parent: string): void;
367
+ /** The call ended with `output`, `failed` when the harness's stream says it did not do its work (Codex's "Script failed"),
368
+ * so its row reads failed as a failed call's does (once: a call already ended says nothing). A crash leaves an opened call
369
+ * open on the host's record: the harness ends it after the resume, from its CLI's answer to it (Codex's recovered exec
370
+ * output), so its end comes after the rows of the calls it made. */
371
+ ended(callId: string, output: string, failed: boolean): Promise<void>;
297
372
  }
298
373
  /** `tool`, a tool the adapter adds of its own, made the host's (SessionIO.hostTool). */
299
374
  export declare const hostedTool: (io: Pick<SessionIO, "hostTool">, tool: HostTool) => HostTool;
@@ -305,6 +380,9 @@ export interface GateCall {
305
380
  /** The call runs again after an earlier attempt whose start the log holds (a replay-safe call a crash cut): that
306
381
  * attempt may have been sent, so a refusal never says nothing was. */
307
382
  readonly replayed?: true;
383
+ /** A call a running tool made (NestedCalls: a script's, tools_call's), part of a call already let through: the cap's
384
+ * wrap-up never refuses one, so a call in flight is never cut short, as pi's nested call is not. */
385
+ readonly nested?: true;
308
386
  }
309
387
  /** The host's answer before a call's intent: run it, refuse it in these words, or park the run on it. */
310
388
  export type GateAnswer = "allow" | {
@@ -445,8 +523,6 @@ export interface AdapterFacts {
445
523
  readonly recoversCutAnswers?: number;
446
524
  /** What one run of it holds in memory, in MiB: the host admits runs by it. */
447
525
  readonly runMib: number;
448
- /** Whether it binds a session's remote MCP servers (its own MCP client, at the session's gateway). */
449
- readonly mcp: boolean;
450
526
  /** The thinking levels it takes, lowest first: a run's level above its highest runs at that highest. */
451
527
  readonly thinking: readonly ("low" | "medium" | "high" | "xhigh" | "max")[];
452
528
  /** Its own web search, when the provider runs it: `native`, the provider's search through the session's proxy (its
@@ -455,6 +531,12 @@ export interface AdapterFacts {
455
531
  readonly webSearch?: "native" | "live";
456
532
  /** Its model is its own, chosen on its own wire's settings, never the host's default for the other harnesses. */
457
533
  readonly ownModel: boolean;
534
+ /** It runs the model's scripts itself (Codex's code mode, its nested calls the host's tools): the host offers no
535
+ * `codemode` of its own beside it. Absent: the host's codemode is offered. */
536
+ readonly ownCodemode?: true;
537
+ /** It defers a run's MCP tools behind a tool search of its own (Claude Code's ToolSearch), so the host offers no
538
+ * `tools_search` or `tools_call` beside it. Absent: the host's are offered when a run's catalog tools are deferred. */
539
+ readonly ownToolSearch?: true;
458
540
  /** The model as the harness names it (Anthropic's id has no dot). */
459
541
  normalizeModel(model: {
460
542
  provider: string;
@@ -473,15 +555,23 @@ export interface AdapterFacts {
473
555
  pins: string;
474
556
  };
475
557
  };
476
- /** The problems its own MCP client has with a tool's input schema (`tool` as it names it, `mcp__<server>__<tool>`):
477
- * shapes it drops or retypes, measured on its pinned build, so a grant of that tool would offer the model another
478
- * tool than the one granted. None: its client takes any schema the kernel's check does. */
558
+ /** The problems it has with a host tool's input schema (`tool` by its name, a run's MCP tool's `mcp__<server>__<tool>`):
559
+ * shapes it drops or retypes, measured on its pinned build, so a grant of an MCP tool would offer the model another
560
+ * tool than the one granted. None: it takes any schema the kernel's check does. */
479
561
  schemaProblems?(tool: string, schema: Record<string, unknown>): string[];
480
- /** A name its client calls a session's MCP tool by beside `mcp__<server>__<tool>` (OpenCode's `<server>_<tool>`). */
481
- readonly toolAlias?: RegExp;
562
+ /** The host's name for a host tool the model names its own way on this harness's tool channel (Claude's
563
+ * `mcp__hands__<name>`, OpenCode's `hands_<name>`, Codex's `mcp_<server>__<tool>`). Absent: the model's name is the
564
+ * host's (pi's). A name already the host's comes back as it is. */
565
+ readonly hostName?: (given: string) => string;
482
566
  /** Its CLI's own tools, by the name a call reaches the host by, each with the host's table tool it is (Claude's
483
567
  * `Bash` is `bash`): a host holds such a call to that tool's setting. None: its CLI calls only the host's tools. */
484
568
  readonly nativeTools?: Readonly<Record<string, string>>;
569
+ /** The input tokens its first model request carries before the agent's own prompt and the person's message: its own
570
+ * system prompt and tool definitions, as measured on its pinned build (the constant beside its pin says how). A host
571
+ * prices a cap's least step on it before any run (a save's warning that a cap is below one step and an answer). A
572
+ * count of what was measured, with o200k_base or from billing (the constant says which). Absent: not measured, read
573
+ * as 0 (a floor). */
574
+ readonly baseInputTokens?: number;
485
575
  /** The policy its model proxy applies, for a host that serves the same route itself (a test's faux harness). */
486
576
  policy(options: {
487
577
  model: string;
@@ -503,20 +593,15 @@ export interface SessionPort {
503
593
  /** The API the proxy serves: Anthropic's Messages (claude-agent) or OpenAI's Responses (codex, opencode). */
504
594
  api: "anthropic-messages" | "openai-responses";
505
595
  }
506
- export interface AdapterCapabilities {
507
- /** Its harness's own MCP client, when it has one: it calls `spec.mcp`'s servers at the session proxy's `/mcp/<server>`,
508
- * which the kernel's model proxy mounts from the session's MCP and this fact (ModelProxyOptions.mcp). */
509
- mcpClient?: McpClient;
510
- }
511
- /** A harness's own MCP client, as its adapter declares it: the `_meta` key of a `tools/call` that carries the harness's
512
- * own id for the call (Claude Code's `claudecode/toolUseId`, Codex's `callId`), the id its timeline and gate know the
513
- * call by. The route reads that key and no other. */
514
- export interface McpClient {
515
- callIdMeta: string;
516
- }
517
596
  export interface AgentAdapter {
518
597
  readonly id: string;
519
- capabilities(): AdapterCapabilities;
598
+ /** Tools the harness runs itself beside the session's host tools (pi's subagent tool, its browser's): offered to the
599
+ * model as the host tools are, so the host's tools_search lists them and a nested call reaches one by its name. */
600
+ readonly ownTools?: readonly {
601
+ readonly name: string;
602
+ readonly description: string;
603
+ readonly inputSchema: Record<string, unknown>;
604
+ }[];
520
605
  /** Problems with a session before anything is spent; an empty list opens it. */
521
606
  check(spec: SessionSpec): string[];
522
607
  /** Opens the session, restoring it from `io.writer` when its key has records. */
package/dist/types.js CHANGED
@@ -15,5 +15,13 @@ export const HOST_RESULT_MAX_CHARS = 120_000;
15
15
  * answer again. A host reads a run's end by it (agentrun-serve's `moderated`).
16
16
  */
17
17
  export const CONTENT_FILTERED = "content_filter: the model provider stopped this answer";
18
+ /**
19
+ * What a run on a person's ChatGPT plan ends with once the plan's limit is reached (its 429): the plan's own limit, never
20
+ * the run's spend cap, so nothing here can raise it and nothing tries again. A harness's model proxy answers its client
21
+ * these words (`ProviderPolicy.finalError`) and the harness halts the turn with them; a host shows them as they are.
22
+ */
23
+ export const PLAN_LIMIT_WORDS = "Your ChatGPT plan's limit is reached. Manage usage in your ChatGPT settings, then run it again.";
24
+ /** The code the proxy's answer carries beside PLAN_LIMIT_WORDS. */
25
+ export const PLAN_LIMIT_CODE = "plan_limit_reached";
18
26
  /** `tool`, a tool the adapter adds of its own, made the host's (SessionIO.hostTool). */
19
27
  export const hostedTool = (io, tool) => (io.hostTool ? io.hostTool(tool) : tool);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-kernel",
3
- "version": "0.1.0-beta.37",
3
+ "version": "0.1.0-beta.39",
4
4
  "description": "Agent harnesses other than Pi, starting with Codex, behind one seam: a DSL node's runNode and an AgentRun run on a harness adapter, durable in AgentRun's own store.",
5
5
  "keywords": [
6
6
  "agentrun",
@@ -50,7 +50,9 @@
50
50
  "CHANGELOG.md",
51
51
  "LICENSE",
52
52
  "NOTICE",
53
- "vendor/durable-harness/UPSTREAM.json"
53
+ "vendor/durable-harness/UPSTREAM.json",
54
+ "vendor/o200k/o200k_base.tiktoken",
55
+ "vendor/o200k/LICENSE"
54
56
  ],
55
57
  "sideEffects": false,
56
58
  "scripts": {
@@ -60,7 +62,7 @@
60
62
  "test": "node --test --test-concurrency=8 'test/*.test.mjs'"
61
63
  },
62
64
  "dependencies": {
63
- "@parcha/agentrun-dsl": "0.1.0-beta.37",
65
+ "@parcha/agentrun-dsl": "0.1.0-beta.39",
64
66
  "ajv": "8.18.0",
65
67
  "typebox": "1.3.27"
66
68
  },
@@ -0,0 +1,61 @@
1
+ The o200k_base tokenizer in src/host/o200k.ts (dist/host/o200k.js) is built from two MIT-licensed sources.
2
+
3
+ o200k_base.tiktoken, beside this file, is OpenAI's o200k_base vocabulary, unchanged: the file tiktoken loads, from
4
+ https://openaipublic.blob.core.windows.net/encodings/o200k_base.tiktoken, sha256
5
+ 446a9538cb6c348e3516120d7c08b09f57c36495e2acfffe59a5bf8b0cfb1a2d, as pinned in tiktoken at commit
6
+ 79dc2c0533685b893616c78160b5d9e40876e724 (https://github.com/openai/tiktoken).
7
+
8
+ The split pattern is tiktoken's o200k_base pattern as gpt-tokenizer spells it for JavaScript, at commit
9
+ 785c2695acbda31ae31ef8ab6343bcd7f1dde72f, release 4.1.2 (https://github.com/niieani/gpt-tokenizer).
10
+
11
+ ---
12
+
13
+ tiktoken
14
+
15
+ MIT License
16
+
17
+ Copyright (c) 2022 OpenAI, Shantanu Jain
18
+
19
+ Permission is hereby granted, free of charge, to any person obtaining a copy
20
+ of this software and associated documentation files (the "Software"), to deal
21
+ in the Software without restriction, including without limitation the rights
22
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23
+ copies of the Software, and to permit persons to whom the Software is
24
+ furnished to do so, subject to the following conditions:
25
+
26
+ The above copyright notice and this permission notice shall be included in all
27
+ copies or substantial portions of the Software.
28
+
29
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35
+ SOFTWARE.
36
+
37
+ ---
38
+
39
+ gpt-tokenizer
40
+
41
+ MIT License
42
+
43
+ Copyright (c) 2023-2024 Bazyli Brzoska
44
+
45
+ Permission is hereby granted, free of charge, to any person obtaining a copy
46
+ of this software and associated documentation files (the "Software"), to deal
47
+ in the Software without restriction, including without limitation the rights
48
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
49
+ copies of the Software, and to permit persons to whom the Software is
50
+ furnished to do so, subject to the following conditions:
51
+
52
+ The above copyright notice and this permission notice shall be included in all
53
+ copies or substantial portions of the Software.
54
+
55
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
56
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
57
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
58
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
59
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
60
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
61
+ SOFTWARE.