@parcha/agentrun-kernel 0.1.0-beta.59 → 0.1.0-beta.61

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/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. Each call asks the host's gate first, as a real harness's tool bridge does
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 (!results.has(callId))
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
- let dangling = state === "open_turn" && answered.has(cursor - 1)
106
- ? callsOf(script[cursor - 1], cursor - 1).filter((call) => !begun.has(call.callId)).map(({ say, ...call }) => ({ ...call, ...(say && !saidAlready.has(call.callId) ? { say } : {}) }))
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
- const runCall = async (name, args, callId, signal) => {
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.59",
3
+ "version": "0.1.0-beta.61",
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.59",
65
+ "@parcha/agentrun-dsl": "0.1.0-beta.61",
66
66
  "ajv": "8.18.0",
67
67
  "typebox": "1.3.27"
68
68
  },