@parcha/agentrun-kernel 0.1.0-beta.60 → 0.1.0-beta.62
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 +11 -0
- package/dist/host/parent-watch.js +4 -1
- package/dist/kernel/registry/computer-surface.generated.d.ts +3 -2
- package/dist/kernel/registry/computer-surface.generated.js +95 -28
- package/dist/kernel/registry/computer.d.ts +9 -0
- package/dist/kernel/registry/computer.js +27 -4
- package/dist/kernel/registry/index.d.ts +1 -1
- package/dist/kernel/registry/index.js +1 -1
- package/dist/process/tools.js +6 -2
- package/dist/testing.d.ts +10 -1
- package/dist/testing.js +27 -12
- package/dist/types.d.ts +5 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## 0.1.0-beta.62 (2026-11-26)
|
|
6
|
+
|
|
7
|
+
**Breaking:**
|
|
8
|
+
|
|
9
|
+
- A script's file ops on a desktop or a phone need their tool among the agent's tools: `computer.files.read`, `files.list` and `files.stat` need `read`, and `files.write` needs `write`, as before. Naming a desktop no longer grants them: an agent that read files through `computer` without `read` in its `tools` is now refused in words (`computer_op files.read needs read among this agent's tools…`), whatever `read`'s setting says, on every desktop, mounted or not. Add `read` to the agent's `tools` to keep them. `computer_op`'s op list and a script's `computer` declarations offer only the ops the gate would let through: not one whose tool the agent is not given, nor one held to a tool set to deny, nor one held to a tool set to ask where no one can approve, nor one `bash`'s policy refuses whatever its command (`bash` set to deny drops `shell.run` and `processes.start`; the read-only policy drops `processes.start`). Both say that input ops on a computer with a terminal app or a GUI file manager, and `apps.open` with a `file://` URL, can do what a shell or the file ops do, whatever `bash`'s, `read`'s or `write`'s setting. `shell.run` and `processes.start` still follow `bash`'s setting, not a grant, so leaving `read` out keeps no file from an agent that has the shell, paired machines included: on a desktop with exec on, `computer.shell.run` reads and writes any file under `bash`'s setting, which allows by default. `computerDeclarations` takes the ops to leave out, and the kernel exports `withoutOps` for computer_op's definition and `GUI_REACH` for the words. <!-- changes/desktop-file-ops-need-grants.md -->
|
|
10
|
+
|
|
11
|
+
**Changes:**
|
|
12
|
+
|
|
13
|
+
- The parent-watch shim (`parentWatched`'s `shim` watch, used where `setpriv --pdeathsig` is not) takes TERM, INT and HUP before it starts its child. Before, a TERM that reached it in the moment after the child started ended the shim alone and left the child running with nothing watching it: a Claude sign-in stopped as it opened kept its CLI. <!-- changes/kernel-shim-signals-first.md -->
|
|
14
|
+
- A learned workflow call in a run's `workflow_calls` whose rerun was refused now reads `refused` only while every attempt the gate let go was closed by a refusal. One with an attempt left open (a crash cut it before it kept a record, or its record says it ran) reads `failed`, even when a sibling call ran beside it, so its model nodes' spend can't be told for its own: its `usd` is null there, and null for an attempt cut after the refused record. Before, it read `refused` at $0. A CLI's own side request on another model (its title or summary helper) inside a refused call's window no longer flips the call to `failed`. A tool that nests calls, issued again after an earlier attempt fixed a value or nested a call, is now asked at the gate as `replayed`. <!-- changes/workflow-calls-window.md -->
|
|
15
|
+
|
|
5
16
|
## 0.1.0-beta.59 (2026-11-25)
|
|
6
17
|
|
|
7
18
|
**Breaking:**
|
|
@@ -26,7 +26,9 @@ if (!Number.isSafeInteger(parent) || parent < 1 || (graceAsked && termGraceMs ==
|
|
|
26
26
|
// Started after the host was already gone: nothing to run for.
|
|
27
27
|
if (process.ppid !== parent)
|
|
28
28
|
process.exit(1);
|
|
29
|
-
|
|
29
|
+
// The signals are taken before the child is started: a handler runs on a later turn of the loop, once spawn has
|
|
30
|
+
// returned, so a TERM that lands as the child starts is passed on to it. Taken after, such a TERM would end this process
|
|
31
|
+
// alone, with its child left running and nothing watching it.
|
|
30
32
|
const passed = ["SIGTERM", "SIGINT", "SIGHUP"];
|
|
31
33
|
let grace;
|
|
32
34
|
for (const signal of passed) {
|
|
@@ -36,6 +38,7 @@ for (const signal of passed) {
|
|
|
36
38
|
grace ??= setTimeout(() => child.kill("SIGKILL"), termGraceMs);
|
|
37
39
|
});
|
|
38
40
|
}
|
|
41
|
+
const child = spawn(command, args, { stdio: "inherit" });
|
|
39
42
|
child.on("error", (error) => {
|
|
40
43
|
process.stderr.write(`parent-watch: ${error.message}\n`);
|
|
41
44
|
process.exit(127);
|
|
@@ -5,5 +5,6 @@ export declare const COMPUTER_TOOL_SCHEMAS: {
|
|
|
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 ];";
|
|
7
7
|
/** The declarations a script on a computer with these groups reads: the types its members reach, Computer with only
|
|
8
|
-
* the members its groups offer,
|
|
9
|
-
|
|
8
|
+
* the members its groups offer, less each op in `without` (a member left with none goes), and
|
|
9
|
+
* `declare const computer`, one line each. */
|
|
10
|
+
export declare function computerDeclarations(groups: readonly string[], without?: readonly string[]): string;
|
|
@@ -504,7 +504,8 @@ const TYPES = [
|
|
|
504
504
|
"text": "interface FileInfo { path: string; type: FileType; size: number; mtimeMs: number; }"
|
|
505
505
|
}
|
|
506
506
|
];
|
|
507
|
-
/** Computer's members, each with the groups it needs one of
|
|
507
|
+
/** Computer's members, each with the groups it needs one of: one that is an object of methods as its ops, put back
|
|
508
|
+
* together after `open` (its text up to the object's `{`); any other with the types it names and its text. */
|
|
508
509
|
const MEMBERS = [
|
|
509
510
|
{
|
|
510
511
|
"uses": [
|
|
@@ -516,10 +517,21 @@ const MEMBERS = [
|
|
|
516
517
|
"groups": [
|
|
517
518
|
"apps"
|
|
518
519
|
],
|
|
519
|
-
"
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
520
|
+
"open": "readonly apps: {",
|
|
521
|
+
"ops": [
|
|
522
|
+
{
|
|
523
|
+
"op": "apps.list",
|
|
524
|
+
"uses": [
|
|
525
|
+
"AppInfo"
|
|
526
|
+
],
|
|
527
|
+
"text": "list(): Promise<{ apps: AppInfo[]; foreground: string | null; }>;"
|
|
528
|
+
},
|
|
529
|
+
{
|
|
530
|
+
"op": "apps.open",
|
|
531
|
+
"uses": [],
|
|
532
|
+
"text": "open(id: string, options?: { url?: string; background?: boolean; }): Promise<void>;"
|
|
533
|
+
}
|
|
534
|
+
]
|
|
523
535
|
},
|
|
524
536
|
{
|
|
525
537
|
"groups": [
|
|
@@ -534,11 +546,17 @@ const MEMBERS = [
|
|
|
534
546
|
"groups": [
|
|
535
547
|
"screen"
|
|
536
548
|
],
|
|
537
|
-
"
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
549
|
+
"open": "readonly screen: {",
|
|
550
|
+
"ops": [
|
|
551
|
+
{
|
|
552
|
+
"op": "screen.shot",
|
|
553
|
+
"uses": [
|
|
554
|
+
"Rect",
|
|
555
|
+
"Image"
|
|
556
|
+
],
|
|
557
|
+
"text": "shot(options?: { region?: Rect; }): Promise<Image>;"
|
|
558
|
+
}
|
|
559
|
+
]
|
|
542
560
|
},
|
|
543
561
|
{
|
|
544
562
|
"groups": [
|
|
@@ -546,42 +564,91 @@ const MEMBERS = [
|
|
|
546
564
|
"input.touch",
|
|
547
565
|
"input.keys"
|
|
548
566
|
],
|
|
549
|
-
"
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
567
|
+
"open": "readonly input: {",
|
|
568
|
+
"ops": [
|
|
569
|
+
{
|
|
570
|
+
"op": "input.act",
|
|
571
|
+
"uses": [
|
|
572
|
+
"InputAction",
|
|
573
|
+
"InputResult"
|
|
574
|
+
],
|
|
575
|
+
"text": "act(actions: InputAction[]): Promise<InputResult>;"
|
|
576
|
+
}
|
|
577
|
+
]
|
|
554
578
|
},
|
|
555
579
|
{
|
|
556
580
|
"groups": [
|
|
557
581
|
"exec"
|
|
558
582
|
],
|
|
559
|
-
"
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
583
|
+
"open": "readonly shell: {",
|
|
584
|
+
"ops": [
|
|
585
|
+
{
|
|
586
|
+
"op": "shell.run",
|
|
587
|
+
"uses": [
|
|
588
|
+
"RunResult"
|
|
589
|
+
],
|
|
590
|
+
"text": "run(command: string | string[], options?: { cwd?: string; timeoutMs?: number; env?: Record<string, string>; }): Promise<RunResult>;"
|
|
591
|
+
}
|
|
592
|
+
]
|
|
563
593
|
},
|
|
564
594
|
{
|
|
565
595
|
"groups": [
|
|
566
596
|
"processes"
|
|
567
597
|
],
|
|
568
|
-
"
|
|
569
|
-
"
|
|
598
|
+
"open": "readonly processes: {",
|
|
599
|
+
"ops": [
|
|
600
|
+
{
|
|
601
|
+
"op": "processes.start",
|
|
602
|
+
"uses": [],
|
|
603
|
+
"text": "start(command: string | string[], options?: { cwd?: string; env?: Record<string, string>; }): Promise<{ pid: number; }>;"
|
|
604
|
+
}
|
|
605
|
+
]
|
|
570
606
|
},
|
|
571
607
|
{
|
|
572
608
|
"groups": [
|
|
573
609
|
"files"
|
|
574
610
|
],
|
|
575
|
-
"
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
611
|
+
"open": "readonly files: {",
|
|
612
|
+
"ops": [
|
|
613
|
+
{
|
|
614
|
+
"op": "files.read",
|
|
615
|
+
"uses": [],
|
|
616
|
+
"text": "read(path: string, options?: { encoding?: \"utf8\" | \"base64\"; }): Promise<string>;"
|
|
617
|
+
},
|
|
618
|
+
{
|
|
619
|
+
"op": "files.write",
|
|
620
|
+
"uses": [],
|
|
621
|
+
"text": "write(path: string, data: string, options?: { encoding?: \"utf8\" | \"base64\"; }): Promise<void>;"
|
|
622
|
+
},
|
|
623
|
+
{
|
|
624
|
+
"op": "files.list",
|
|
625
|
+
"uses": [
|
|
626
|
+
"FileInfo"
|
|
627
|
+
],
|
|
628
|
+
"text": "list(path: string): Promise<FileInfo[]>;"
|
|
629
|
+
},
|
|
630
|
+
{
|
|
631
|
+
"op": "files.stat",
|
|
632
|
+
"uses": [
|
|
633
|
+
"FileInfo"
|
|
634
|
+
],
|
|
635
|
+
"text": "stat(path: string): Promise<FileInfo>;"
|
|
636
|
+
}
|
|
637
|
+
]
|
|
579
638
|
}
|
|
580
639
|
];
|
|
581
640
|
/** The declarations a script on a computer with these groups reads: the types its members reach, Computer with only
|
|
582
|
-
* the members its groups offer,
|
|
583
|
-
|
|
584
|
-
|
|
641
|
+
* the members its groups offer, less each op in `without` (a member left with none goes), and
|
|
642
|
+
* `declare const computer`, one line each. */
|
|
643
|
+
export function computerDeclarations(groups, without = []) {
|
|
644
|
+
const members = MEMBERS.flatMap((member) => {
|
|
645
|
+
if (member.groups !== undefined && !member.groups.some((group) => groups.includes(group)))
|
|
646
|
+
return [];
|
|
647
|
+
if (!("ops" in member))
|
|
648
|
+
return [member];
|
|
649
|
+
const kept = member.ops.filter((one) => !without.includes(one.op));
|
|
650
|
+
return kept.length === 0 ? [] : [{ uses: kept.flatMap((one) => one.uses), text: `${member.open} ${kept.map((one) => one.text).join(" ")} };` }];
|
|
651
|
+
});
|
|
585
652
|
const uses = new Map(TYPES.map((type) => [type.name, type.uses]));
|
|
586
653
|
const reached = new Set();
|
|
587
654
|
const visit = (name) => {
|
|
@@ -15,11 +15,20 @@ export declare const unsavedScreenshot: <T extends {
|
|
|
15
15
|
readonly description: string;
|
|
16
16
|
readonly parameters: object;
|
|
17
17
|
}>(def: T) => T;
|
|
18
|
+
/** What every offer of a computer's ops says of its screen: leaving bash, read or write out does not keep a script from
|
|
19
|
+
* a terminal app, a file manager, or an app opened on a file:// URL. */
|
|
20
|
+
export declare const GUI_REACH = "Input ops on a computer with a terminal app or a GUI file manager, and apps.open with a file:// URL, can do what a shell or the file ops do, whatever bash's, read's or write's setting.";
|
|
18
21
|
/** The ops computer_op runs on a computer with `groups`. */
|
|
19
22
|
export declare function computerOpsFor(groups: readonly string[]): readonly string[];
|
|
20
23
|
/** The tools a computer with `groups` offers: observe and act with the ui group, or a screen (observe) and input (act)
|
|
21
24
|
* without it; the screenshot with a screen; computer_op with any op past those (computerOpsFor). */
|
|
22
25
|
export declare function computerToolsFor(groups: readonly string[]): readonly string[];
|
|
26
|
+
/** computer_op's definition `def` for a run whose gate refuses the ops `without` (its agent is not given their tool):
|
|
27
|
+
* its words and its op list name only the others. */
|
|
28
|
+
export declare const withoutOps: <T extends {
|
|
29
|
+
readonly description: string;
|
|
30
|
+
readonly parameters: object;
|
|
31
|
+
}>(def: T, without: readonly string[]) => T;
|
|
23
32
|
/** The computer's tools in `kind`, under its settings key, for a computer with `groups`. An act or an op changes the
|
|
24
33
|
* computer: never replayed. */
|
|
25
34
|
export declare function computerToolDefs(kind: CapabilityKind, groups: readonly string[]): readonly ToolDef[];
|
|
@@ -61,7 +61,23 @@ function savePathOf(given) {
|
|
|
61
61
|
throw new Error(`save_as names a .png file: not ${JSON.stringify(given)}`);
|
|
62
62
|
return path;
|
|
63
63
|
}
|
|
64
|
-
|
|
64
|
+
/** Each op's arguments, as computer_op's words give them (none: it takes none). */
|
|
65
|
+
const OP_ARGS = Object.freeze({
|
|
66
|
+
"input.act": "{actions}",
|
|
67
|
+
"apps.open": "{id, url?, background?}",
|
|
68
|
+
"shell.run": "{command, cwd?, env?, timeoutMs?}",
|
|
69
|
+
"processes.start": "{command, cwd?, env?}",
|
|
70
|
+
"files.read": "{path, encoding?}",
|
|
71
|
+
"files.write": "{path, data, encoding?}",
|
|
72
|
+
"files.list": "{path}",
|
|
73
|
+
"files.stat": "{path}",
|
|
74
|
+
});
|
|
75
|
+
/** What every offer of a computer's ops says of its screen: leaving bash, read or write out does not keep a script from
|
|
76
|
+
* a terminal app, a file manager, or an app opened on a file:// URL. */
|
|
77
|
+
export const GUI_REACH = "Input ops on a computer with a terminal app or a GUI file manager, and apps.open with a file:// URL, can do what a shell or the file ops do, whatever bash's, read's or write's setting.";
|
|
78
|
+
/** computer_op's words for the ops it offers. */
|
|
79
|
+
const opWords = (ops) => `One of the computer's ops no other tool runs, as a script's \`computer\` calls it: ${ops.map((op) => (OP_ARGS[op] ? `${op} ${OP_ARGS[op]}` : op)).join(", ")}. An op this computer does not offer is refused. ${GUI_REACH}`;
|
|
80
|
+
const OP = opWords(Object.keys(COMPUTER_OPS));
|
|
65
81
|
/** The ops computer_op runs on a computer with `groups`. */
|
|
66
82
|
export function computerOpsFor(groups) {
|
|
67
83
|
return Object.keys(COMPUTER_OPS).filter((op) => COMPUTER_OPS[op].some((group) => groups.includes(group)));
|
|
@@ -91,15 +107,22 @@ const def = (kind, name, description, replaySafe, parameters = COMPUTER_TOOL_SCH
|
|
|
91
107
|
parameters,
|
|
92
108
|
replaySafe,
|
|
93
109
|
});
|
|
94
|
-
/** computer_op's parameters
|
|
95
|
-
const
|
|
110
|
+
/** computer_op's parameters over `ops`: the op, and its arguments as a script's `computer` gives them. */
|
|
111
|
+
const opParameters = (ops) => ({
|
|
96
112
|
type: "object",
|
|
97
113
|
properties: {
|
|
98
|
-
op: { type: "string", enum:
|
|
114
|
+
op: { type: "string", enum: [...ops] },
|
|
99
115
|
args: { type: "object", description: "The op's arguments." },
|
|
100
116
|
},
|
|
101
117
|
required: ["op"],
|
|
102
118
|
additionalProperties: false,
|
|
119
|
+
});
|
|
120
|
+
const OP_PARAMETERS = opParameters(Object.keys(COMPUTER_OPS));
|
|
121
|
+
/** computer_op's definition `def` for a run whose gate refuses the ops `without` (its agent is not given their tool):
|
|
122
|
+
* its words and its op list name only the others. */
|
|
123
|
+
export const withoutOps = (def, without) => {
|
|
124
|
+
const ops = Object.keys(COMPUTER_OPS).filter((op) => !without.includes(op));
|
|
125
|
+
return { ...def, description: opWords(ops), parameters: opParameters(ops) };
|
|
103
126
|
};
|
|
104
127
|
/** The computer's tools in `kind`, under its settings key, for a computer with `groups`. An act or an op changes the
|
|
105
128
|
* computer: never replayed. */
|
|
@@ -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_OP_TOOL, COMPUTER_OPS, COMPUTER_TOOLS, computerExecutors, computerOpsFor, computerToolDefs, computerToolsFor, STEP_TOOL_OPS, unsavedScreenshot } from "./computer.js";
|
|
5
|
+
export { COMPUTER_OP_TOOL, COMPUTER_OPS, COMPUTER_TOOLS, computerExecutors, computerOpsFor, computerToolDefs, computerToolsFor, GUI_REACH, STEP_TOOL_OPS, unsavedScreenshot, withoutOps } 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_OP_TOOL, COMPUTER_OPS, COMPUTER_TOOLS, computerExecutors, computerOpsFor, computerToolDefs, computerToolsFor, STEP_TOOL_OPS, unsavedScreenshot } from "./computer.js";
|
|
8
|
+
export { COMPUTER_OP_TOOL, COMPUTER_OPS, COMPUTER_TOOLS, computerExecutors, computerOpsFor, computerToolDefs, computerToolsFor, GUI_REACH, STEP_TOOL_OPS, unsavedScreenshot, withoutOps } 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";
|
package/dist/process/tools.js
CHANGED
|
@@ -124,11 +124,15 @@ export function toolBridge(ctx, tools, options = {}) {
|
|
|
124
124
|
};
|
|
125
125
|
/** A tool that `nests`: asked at the gate as itself, then run with the session's tools as its nested calls, no effect
|
|
126
126
|
* of its own written. Its error result is its answer; a throw while the drive or the call is aborted (a nested call
|
|
127
|
-
* parked, the session let go) halts the drive, as an effect's does, so the harness is never handed a result.
|
|
127
|
+
* parked, the session let go) halts the drive, as an effect's does, so the harness is never handed a result. Asked
|
|
128
|
+
* as `replayed` when the log holds an effect of an earlier attempt's (a value it fixed, a call nested in it), as a
|
|
129
|
+
* call whose own start is in the log is: that attempt was let go and may have spent. */
|
|
128
130
|
const runNesting = async (args, callId, signal, nested) => {
|
|
129
131
|
const aborted = signal ? AbortSignal.any([signal, ctx.signal]) : ctx.signal;
|
|
130
132
|
if (options.gate) {
|
|
131
|
-
const
|
|
133
|
+
const under = [`nested:${callId}/`, `${toolKey(callId)}/`];
|
|
134
|
+
const replayed = [...ctx.state().effects.keys()].some((key) => under.some((prefix) => key.startsWith(prefix)));
|
|
135
|
+
const refused = await askGate(options.gate, { callId, tool: tool.name, args: (args ?? {}), ...(replayed ? { replayed: true } : {}), ...(nested ? { nested } : {}) }, aborted);
|
|
132
136
|
if (refused)
|
|
133
137
|
return { text: refused.deny, isError: true, refused: true };
|
|
134
138
|
}
|
package/dist/testing.d.ts
CHANGED
|
@@ -57,10 +57,19 @@ export type FauxRequest = {
|
|
|
57
57
|
export type FauxAction = ({
|
|
58
58
|
say: string;
|
|
59
59
|
usd?: number | null;
|
|
60
|
-
} & FauxRequest)
|
|
60
|
+
} & FauxRequest)
|
|
61
|
+
/** One call. `again`: a crash that cuts it off mid-call (its intent recorded, no outcome) leaves it for the recovered
|
|
62
|
+
* turn to issue again, under its id, asking the gate first as the tool bridge does (process/tools.ts: `replayed`,
|
|
63
|
+
* unless the tool `nests`), as a CLI that sends its transcript's unanswered call again through its bridge; without
|
|
64
|
+
* it, the cut call is answered interrupted. `dies`: the process stops once the call's gate has answered, before its
|
|
65
|
+
* intent or outcome is written (a refusal's too), so a recovered turn issues it again as a call left unstarted; only
|
|
66
|
+
* the first time, never when a recovered turn issues it again. */
|
|
67
|
+
| ({
|
|
61
68
|
call: string;
|
|
62
69
|
args?: unknown;
|
|
63
70
|
usd?: number | null;
|
|
71
|
+
again?: true;
|
|
72
|
+
dies?: true;
|
|
64
73
|
} & FauxRequest)
|
|
65
74
|
/** One answer that asks for several tools, run one after another, as Claude Code and Codex run a response's calls.
|
|
66
75
|
* `bookAfter`: the calls run before the answer's cost is booked, as with Claude Code, whose cost comes in after its
|
package/dist/testing.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Test kit: a session store in memory, and a scripted harness with no model and no network. The faux harness keeps its
|
|
2
2
|
// own records in the store as a real adapter does (the requests it made, each tool call's intent and outcome, its turns),
|
|
3
3
|
// so a later process resumes from them: a request already made is not made again, and a call a crash cut off is
|
|
4
|
-
// answered interrupted, never run again
|
|
4
|
+
// answered interrupted, never run again (unless its action says `again`: then it is issued again, asked as the bridge
|
|
5
|
+
// asks it). Each call asks the host's gate first, as a real harness's tool bridge does
|
|
5
6
|
// (process/tools.ts askGate): a deny is the call's answer, and a park holds the turn; a recovered turn runs the calls its
|
|
6
7
|
// last request asked for that never started (a parked one), under their own ids, as a real CLI's resume does.
|
|
7
8
|
import { SessionFenced } from "./errors.js";
|
|
@@ -80,11 +81,21 @@ export function fauxAdapter(options) {
|
|
|
80
81
|
const turnsEnded = records.filter((r) => r.kind === FAUX_RECORDS.turnEnd).length;
|
|
81
82
|
let state = turnsStarted === 0 ? "new" : turnsStarted > turnsEnded ? "open_turn" : "idle";
|
|
82
83
|
stats.opened.push({ key: spec.key, state });
|
|
83
|
-
// A call whose intent is recorded and whose outcome is not: a crash cut it off. It is answered interrupted, once
|
|
84
|
+
// A call whose intent is recorded and whose outcome is not: a crash cut it off. It is answered interrupted, once; one
|
|
85
|
+
// its action marks `again`, in a turn still open, is issued again by the recovered turn instead, its gate asked as the
|
|
86
|
+
// tool bridge asks it (process/tools.ts): `replayed` for a tool that runs as one effect, nothing more for one that
|
|
87
|
+
// `nests` (runNesting), which writes nothing of its own and so has no earlier attempt in the kernel's log to see.
|
|
84
88
|
const results = new Set(records.filter((r) => r.kind === FAUX_RECORDS.result).map((r) => r.data.callId));
|
|
89
|
+
const again = new Map();
|
|
85
90
|
for (const r of records.filter((r) => r.kind === FAUX_RECORDS.call)) {
|
|
86
91
|
const { callId } = r.data;
|
|
87
|
-
if (
|
|
92
|
+
if (results.has(callId) || again.has(callId))
|
|
93
|
+
continue;
|
|
94
|
+
const action = script[Number(callId.slice(spec.key.length + 1))];
|
|
95
|
+
const nests = action && "call" in action ? spec.tools.find((tool) => tool.name === action.call)?.nests === true : false;
|
|
96
|
+
if (state === "open_turn" && action && "call" in action && action.again)
|
|
97
|
+
again.set(callId, { name: action.call, args: action.args ?? {}, callId, ...(nests ? {} : { replayed: true }) });
|
|
98
|
+
else
|
|
88
99
|
await append(FAUX_RECORDS.result, { callId, interrupted: true });
|
|
89
100
|
}
|
|
90
101
|
const tools = new Map(spec.tools.map((tool) => [tool.name, tool]));
|
|
@@ -102,9 +113,10 @@ export function fauxAdapter(options) {
|
|
|
102
113
|
// Each keeps its own text (`say`) unless it was said already (FAUX_RECORDS.said: the call that parked said its text
|
|
103
114
|
// before its gate).
|
|
104
115
|
const saidAlready = new Set(records.filter((r) => r.kind === FAUX_RECORDS.said).map((r) => r.data.callId));
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
116
|
+
// The cut calls issued again (`again`, above) come first: they were asked for before any left unstarted.
|
|
117
|
+
let dangling = [...again.values(), ...(state === "open_turn" && answered.has(cursor - 1)
|
|
118
|
+
? callsOf(script[cursor - 1], cursor - 1).filter((call) => !begun.has(call.callId)).map(({ say, ...call }) => ({ ...call, ...(say && !saidAlready.has(call.callId) ? { say } : {}) }))
|
|
119
|
+
: [])];
|
|
108
120
|
/** What the session has been sent, as a model would be prompted with it. */
|
|
109
121
|
const prompt = records.filter((r) => r.kind === FAUX_RECORDS.user).map((r) => r.data.text);
|
|
110
122
|
let ending;
|
|
@@ -137,10 +149,13 @@ export function fauxAdapter(options) {
|
|
|
137
149
|
});
|
|
138
150
|
/** One call of the model's: the host's gate first, before anything of it is written (a deny is its answer, in the
|
|
139
151
|
* gate's words, recorded so it is never asked again; a park holds the turn until it is stopped), then its intent,
|
|
140
|
-
* the tool, and its outcome.
|
|
141
|
-
|
|
152
|
+
* the tool, and its outcome. `replayed`: a cut call issued again, its gate told an earlier attempt may have run.
|
|
153
|
+
* `dies`: the process stops once the gate has answered, before anything of the call is written. */
|
|
154
|
+
const runCall = async (name, args, callId, signal, replayed, dies) => {
|
|
142
155
|
const tool = tools.get(name);
|
|
143
|
-
const refused = tool && io.gate ? await askGate((call) => io.gate(call), { callId, tool: name, args: (args ?? {}) }, signal) : undefined;
|
|
156
|
+
const refused = tool && io.gate ? await askGate((call) => io.gate(call), { callId, tool: name, args: (args ?? {}), ...(replayed ? { replayed } : {}) }, signal) : undefined;
|
|
157
|
+
if (dies)
|
|
158
|
+
await hang(signal);
|
|
144
159
|
if (refused)
|
|
145
160
|
return void (await append(FAUX_RECORDS.result, { callId, isError: true, refused: true }));
|
|
146
161
|
await append(FAUX_RECORDS.call, { callId, name });
|
|
@@ -161,10 +176,10 @@ export function fauxAdapter(options) {
|
|
|
161
176
|
const signal = AbortSignal.any([io.signal, (turnSignal = new AbortController()).signal]);
|
|
162
177
|
try {
|
|
163
178
|
// A recovered turn: the calls its last request left dangling run first, then the model goes on.
|
|
164
|
-
for (const { name, args, callId, say } of dangling.splice(0)) {
|
|
179
|
+
for (const { name, args, callId, say, replayed } of dangling.splice(0)) {
|
|
165
180
|
if (say)
|
|
166
181
|
await saying(callId, say);
|
|
167
|
-
await runCall(name, args, callId, signal);
|
|
182
|
+
await runCall(name, args, callId, signal, replayed);
|
|
168
183
|
}
|
|
169
184
|
for (;;) {
|
|
170
185
|
const action = script[cursor];
|
|
@@ -275,7 +290,7 @@ export function fauxAdapter(options) {
|
|
|
275
290
|
const side = await io.models.beforeRequest({ model: "faux-small", side: true, inputTokensMax: 100 });
|
|
276
291
|
await io.models.afterRequest({ input: 10, output: 5, usd: action.sideDuring.usd }, side || undefined);
|
|
277
292
|
}
|
|
278
|
-
await runCall(name, args, callId, signal);
|
|
293
|
+
await runCall(name, args, callId, signal, undefined, "call" in action && action.dies ? true : undefined);
|
|
279
294
|
}
|
|
280
295
|
if (bookAfter)
|
|
281
296
|
await book();
|
package/dist/types.d.ts
CHANGED
|
@@ -579,6 +579,11 @@ export interface AdapterFacts {
|
|
|
579
579
|
/** It defers a run's MCP tools behind a tool search of its own (Claude Code's ToolSearch), so the host offers no
|
|
580
580
|
* `tools_search` or `tools_call` beside it. Absent: the host's are offered when a run's catalog tools are deferred. */
|
|
581
581
|
readonly ownToolSearch?: true;
|
|
582
|
+
/** Its tool list is the one its thread was started with: a resume takes no new one (Codex's app-server takes
|
|
583
|
+
* `dynamicTools` on thread/start alone; thread/resume and its settings updates take none). So the host never leaves a
|
|
584
|
+
* tool out at a claim for a reason a later claim of the same run may lift (a per_run MCP server's credential, handed
|
|
585
|
+
* with a message): that tool would never come back. Absent: it takes the host's tools again at every claim. */
|
|
586
|
+
readonly toolsFixedAtStart?: true;
|
|
582
587
|
/** Its model proxy forwards with the fetch its launch hands it (ModuleLaunch.fetch, a provider's `fetch`), so a model
|
|
583
588
|
* only that fetch reaches (one the host's route translates onto its wire: an Ollama model on Messages or Responses) is
|
|
584
589
|
* its to run. Absent: the host offers it no such model, names none as its default, and refuses one a run names. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcha/agentrun-kernel",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.62",
|
|
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",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"test": "node --test --test-concurrency=8 'test/*.test.mjs'"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@parcha/agentrun-dsl": "0.1.0-beta.
|
|
65
|
+
"@parcha/agentrun-dsl": "0.1.0-beta.62",
|
|
66
66
|
"ajv": "8.18.0",
|
|
67
67
|
"typebox": "1.3.27"
|
|
68
68
|
},
|