@parcha/agentrun-serve 0.1.0-beta.47 → 0.1.0-beta.49

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 (185) hide show
  1. package/CHANGELOG.md +68 -1
  2. package/README.md +218 -20
  3. package/dist/acp-package.d.ts +24 -6
  4. package/dist/adapter-facts.d.ts +0 -4
  5. package/dist/adapter-facts.js +1 -4
  6. package/dist/adapters.d.ts +3 -12
  7. package/dist/adapters.js +1 -70
  8. package/dist/agent-delete.d.ts +33 -10
  9. package/dist/agent-delete.js +184 -26
  10. package/dist/agents-store.d.ts +6 -2
  11. package/dist/agents-store.js +18 -5
  12. package/dist/agents.d.ts +8 -1
  13. package/dist/agents.js +14 -4
  14. package/dist/answer-json.d.ts +10 -0
  15. package/dist/answer-json.js +23 -0
  16. package/dist/api-only.d.ts +5 -2
  17. package/dist/api-only.js +10 -2
  18. package/dist/archil-routes.d.ts +1 -1
  19. package/dist/archil-routes.js +4 -3
  20. package/dist/browser-live.d.ts +9 -4
  21. package/dist/browser-live.js +18 -5
  22. package/dist/browser-sessions.d.ts +56 -0
  23. package/dist/browser-sessions.js +117 -0
  24. package/dist/cap.js +7 -9
  25. package/dist/cli.js +6 -6
  26. package/dist/computer-routes.d.ts +6 -14
  27. package/dist/computer-routes.js +8 -10
  28. package/dist/computers.d.ts +6 -2
  29. package/dist/computers.js +4 -2
  30. package/dist/conformance.d.ts +4 -0
  31. package/dist/conformance.js +6 -0
  32. package/dist/console/assets/index-Bzn4eUYF.js +715 -0
  33. package/dist/console/assets/index-CR2ZGei1.css +1 -0
  34. package/dist/console/index.html +2 -2
  35. package/dist/errors.d.ts +4 -1
  36. package/dist/errors.js +15 -5
  37. package/dist/harness-check.d.ts +3 -1
  38. package/dist/harness-check.js +99 -70
  39. package/dist/harness-cursor.d.ts +10 -27
  40. package/dist/harness-cursor.js +5 -84
  41. package/dist/harness-goose.d.ts +4 -29
  42. package/dist/harness-goose.js +6 -86
  43. package/dist/harness-module.d.ts +4 -0
  44. package/dist/harness-module.js +1 -0
  45. package/dist/harness-owned.d.ts +52 -0
  46. package/dist/harness-owned.js +92 -0
  47. package/dist/harness-recipe.js +2 -24
  48. package/dist/harness-table.d.ts +109 -6
  49. package/dist/harness-table.js +242 -28
  50. package/dist/harness.js +2 -2
  51. package/dist/import.js +4 -3
  52. package/dist/key-refusal.d.ts +2 -1
  53. package/dist/key-refusal.js +18 -2
  54. package/dist/learn/check.d.ts +11 -2
  55. package/dist/learn/check.js +12 -9
  56. package/dist/learn/promote.d.ts +18 -1
  57. package/dist/learn/promote.js +47 -0
  58. package/dist/learn/repick.d.ts +34 -0
  59. package/dist/learn/repick.js +201 -0
  60. package/dist/learn/secrets.d.ts +4 -0
  61. package/dist/learn/secrets.js +23 -0
  62. package/dist/learned-workflow.d.ts +2 -0
  63. package/dist/learned-workflow.js +18 -1
  64. package/dist/learning-model.d.ts +18 -0
  65. package/dist/learning-model.js +77 -0
  66. package/dist/learning-setting.d.ts +13 -0
  67. package/dist/learning-setting.js +23 -1
  68. package/dist/llms.txt +1 -0
  69. package/dist/model-form.js +12 -12
  70. package/dist/model.d.ts +5 -4
  71. package/dist/model.js +19 -13
  72. package/dist/openapi.js +203 -15
  73. package/dist/page.d.ts +1 -0
  74. package/dist/page.js +1 -1
  75. package/dist/paid-calls.d.ts +4 -1
  76. package/dist/paid-calls.js +1 -1
  77. package/dist/run-learning-served.d.ts +1 -1
  78. package/dist/run-secrets.d.ts +2 -2
  79. package/dist/run-secrets.js +6 -5
  80. package/dist/run-trace.js +6 -3
  81. package/dist/run-usage.d.ts +110 -0
  82. package/dist/run-usage.js +312 -0
  83. package/dist/runner/adapter-loop.d.ts +4 -1
  84. package/dist/runner/adapter-loop.js +52 -22
  85. package/dist/runner/adapter-run-spec.d.ts +3 -2
  86. package/dist/runner/adapter-run-spec.js +8 -4
  87. package/dist/runner/adapters/index.d.ts +4 -2
  88. package/dist/runner/adapters/index.js +6 -42
  89. package/dist/runner/cli-run-spec.js +10 -6
  90. package/dist/runner/conformance/harness.d.ts +2 -0
  91. package/dist/runner/conformance/harness.js +18 -4
  92. package/dist/runner/conformance/host-tools.d.ts +4 -0
  93. package/dist/runner/conformance/host-tools.js +14 -0
  94. package/dist/runner/feedback-round.d.ts +29 -1
  95. package/dist/runner/feedback-round.js +54 -3
  96. package/dist/runner/journal-kinds.d.ts +3 -1
  97. package/dist/runner/learning-end.js +49 -18
  98. package/dist/runner/loop-contract.d.ts +3 -0
  99. package/dist/runner/meta-tools.js +4 -2
  100. package/dist/runner/monid-run.js +2 -2
  101. package/dist/runner/presence.d.ts +3 -0
  102. package/dist/runner/presence.js +19 -12
  103. package/dist/runner/promotion.d.ts +62 -4
  104. package/dist/runner/promotion.js +154 -17
  105. package/dist/runner/reflect-hook.js +3 -2
  106. package/dist/runner/sdk-loop.js +25 -1
  107. package/dist/runner/workflow-spec.js +3 -2
  108. package/dist/runs-over-store.d.ts +5 -3
  109. package/dist/runs-over-store.js +11 -11
  110. package/dist/sdk/check.d.ts +31 -0
  111. package/dist/sdk/check.js +58 -0
  112. package/dist/sdk/runs.d.ts +10 -2
  113. package/dist/sdk/runs.js +87 -17
  114. package/dist/sdk/schema.js +11 -3
  115. package/dist/server.d.ts +6 -3
  116. package/dist/server.js +297 -98
  117. package/dist/store/index.d.ts +2 -2
  118. package/dist/store/index.js +1 -1
  119. package/dist/store/journal/storage.js +1 -1
  120. package/dist/store/open.d.ts +1 -1
  121. package/dist/store/open.js +1 -1
  122. package/dist/store/postgres/migrations/0021_purged.sql +13 -0
  123. package/dist/store/postgres/migrations/0022_computer_intervals.sql +27 -0
  124. package/dist/store/schema.d.ts +15 -1
  125. package/dist/store/schema.js +50 -5
  126. package/dist/store/sqlite/connection.d.ts +4 -1
  127. package/dist/store/sqlite/connection.js +5 -0
  128. package/dist/store/sqlite/run-patch.d.ts +8 -3
  129. package/dist/store/sqlite/run-patch.js +15 -7
  130. package/dist/store/sqlite/store.d.ts +5 -2
  131. package/dist/store/sqlite/store.js +283 -77
  132. package/dist/store/sqlite/worker.d.ts +9 -0
  133. package/dist/store/sqlite/worker.js +18 -1
  134. package/dist/store/store.d.ts +162 -27
  135. package/dist/store/store.js +63 -0
  136. package/dist/store-reads/analytics.js +2 -1
  137. package/dist/store-reads/cap.d.ts +8 -2
  138. package/dist/store-reads/cap.js +27 -3
  139. package/dist/store-reads/learning.d.ts +1 -1
  140. package/dist/store-reads/learning.js +5 -2
  141. package/dist/store-reads/runs.js +2 -0
  142. package/dist/store-reads/stats.js +4 -2
  143. package/dist/store-view.d.ts +12 -3
  144. package/dist/store-view.js +70 -27
  145. package/dist/template-eval.js +5 -2
  146. package/dist/template-github-permissions.d.ts +5 -1
  147. package/dist/template-github-permissions.js +7 -3
  148. package/dist/timeline/index.d.ts +1 -1
  149. package/dist/timeline/index.js +1 -1
  150. package/dist/timeline/timeline.d.ts +8 -0
  151. package/dist/timeline/timeline.js +18 -6
  152. package/dist/tool-gate.d.ts +8 -4
  153. package/dist/tool-gate.js +6 -7
  154. package/dist/tool-plane.d.ts +4 -0
  155. package/dist/tool-plane.js +10 -10
  156. package/dist/tools.js +9 -0
  157. package/dist/trigger-targets.d.ts +14 -2
  158. package/dist/trigger-targets.js +73 -4
  159. package/dist/triggers.d.ts +2 -1
  160. package/dist/triggers.js +5 -2
  161. package/dist/validate.d.ts +4 -2
  162. package/dist/validate.js +18 -4
  163. package/dist/viewer-credential.d.ts +24 -0
  164. package/dist/viewer-credential.js +53 -0
  165. package/dist/workspace/computer-for-claim.d.ts +5 -1
  166. package/dist/workspace/computer-for-claim.js +47 -18
  167. package/dist/workspace/computer-intervals.d.ts +20 -0
  168. package/dist/workspace/computer-intervals.js +49 -0
  169. package/dist/workspace/computer-janitor.d.ts +7 -3
  170. package/dist/workspace/computer-janitor.js +14 -6
  171. package/dist/workspace/computer-kept.d.ts +7 -2
  172. package/dist/workspace/computer-kept.js +9 -2
  173. package/dist/workspace/resolve-computer.d.ts +9 -1
  174. package/dist/workspace/resolve-computer.js +29 -22
  175. package/dist/workspace/run-end-computers.d.ts +1 -0
  176. package/dist/workspace/run-end-computers.js +4 -1
  177. package/package.json +18 -10
  178. package/templates/code-review/agent.md +2 -3
  179. package/templates/code-review/evals/mentions-defused/case.yaml +0 -1
  180. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -27
  181. package/templates/code-review/evals/other-repo/case.yaml +0 -1
  182. package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +0 -18
  183. package/templates/code-review/evals/other-repo/graders/no-other-repo.md +1 -1
  184. package/dist/console/assets/index-BBFzAxLB.js +0 -715
  185. package/dist/console/assets/index-BRi-Rgq6.css +0 -1
@@ -5,7 +5,8 @@ const RUN_STATES = ["running", "completed", "failed", "stopped", "escalated"];
5
5
  const emptyCounts = () => ({ total: 0, running: 0, completed: 0, failed: 0, stopped: 0, escalated: 0 });
6
6
  /** Every agent, by name then id (the old order), with its archive and name. */
7
7
  async function allAgents(store) {
8
- const [live, archived] = await Promise.all([store.agents.list({ archived: false }), store.agents.list({ archived: true })]);
8
+ // A purged agent (an archived one's tombstone) still counts, as its runs' cost does.
9
+ const [live, archived] = await Promise.all([store.agents.list({ archived: false, purged: true }), store.agents.list({ archived: true, purged: true })]);
9
10
  return [...live.map((a) => ({ id: a.id, name: a.name, archived: false })), ...archived.map((a) => ({ id: a.id, name: a.name, archived: true }))].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
10
11
  }
11
12
  /** The store's counts and cost sums (the old AgentStoreReader.stats), from A's run rows and agents: one pass over the
@@ -13,7 +14,8 @@ async function allAgents(store) {
13
14
  export async function stats(store) {
14
15
  const agents = await allAgents(store);
15
16
  const archivedAgent = new Set(agents.filter((a) => a.archived).map((a) => a.id));
16
- const runs = await store.runs.list({});
17
+ // A purged run's tombstone keeps its state and cost: every count and sum reads it as before its purge.
18
+ const runs = await store.runs.list({ purged: true });
17
19
  // Per agent, the runs whose own archive is null (shown) and the count whose own archive is set (hidden).
18
20
  const shown = new Map();
19
21
  const hidden = new Map();
@@ -5,6 +5,7 @@ import { type Pending, type RunMoment, type RunView, type SignInReader, type Sta
5
5
  import { type BookedSpend, type RunCost } from "./runner/metrics.js";
6
6
  import { type EndData } from "./runner/journal-kinds.js";
7
7
  import { type RunReadState, readRun } from "./store-reads/runs.js";
8
+ import { type KeptEnd } from "./runner/feedback-round.js";
8
9
  import type { PendingAsk } from "./browser-person.js";
9
10
  import { type Approvals } from "./approvals.js";
10
11
  import { type KeptListing, type RunListing, type RunRow, type Store } from "./store/store.js";
@@ -115,13 +116,18 @@ interface StoreRun {
115
116
  /** Whether its end stored its cost unknown while this read, which reads its cost from its booking (an ended agentic run
116
117
  * not native, or workflow, not imported), found no booked request: the end could not read the booking, nor can this. */
117
118
  readonly endUnread?: boolean;
118
- /** The figure its store's unknown cost heals to (Runs.healCost), at the end it was read at: set while its stored cost is
119
- * null with no bound and its booking gives an exact figure (no hold counted in it). */
119
+ /** The cost its store's unknown one heals to (Runs.healCost), at the end it was read at: set while its stored cost is
120
+ * null with no bound and its booking gives a figure, written by the end's own rule (endCostOf: a bound when a cut
121
+ * request's hold is counted in it). */
120
122
  readonly heal?: {
121
123
  readonly epoch: number;
122
124
  readonly endedAt: number;
123
- readonly usd: number;
125
+ readonly costUsd: number;
126
+ readonly costUpperBound: boolean;
124
127
  };
128
+ /** The run looks back after its job's end (`row` and `runRow` read as that end): nothing of it is settled until the
129
+ * look-back's own end is in (poll_after_ms 1000, the timeline not final). */
130
+ readonly lookingBack?: true;
125
131
  }
126
132
  /** Whether the run's turn stands on a person: a tool call asked for their approval with no answer in its journal (the
127
133
  * view's `approvals`, asksOf), or a browser or desktop hand-over neither answered in its journal nor by a hand-back row.
@@ -137,6 +143,9 @@ export declare function standsOnPerson(approvals: ReadonlyMap<string, {
137
143
  * True when written; false when another write got there first, or when the write failed (said, never thrown: a read
138
144
  * never fails on its heal, and the next read or start sweep writes it again). */
139
145
  export declare function healStoredCost(store: Store, runId: string, heal: NonNullable<StoreRun["heal"]>): Promise<boolean>;
146
+ /** The end run `runId` keeps while it looks back after its job ended, as every reader serves it (lookingBackOf), else
147
+ * undefined: a run that reads ended while it is still learning from that end. */
148
+ export declare function lookingBackEnd(store: Store, runId: string): Promise<KeptEnd | undefined>;
140
149
  /** What run `runId`'s paid tool calls cost, the run read's `cost.tools_usd` (server.ts allInViewOf): the charges its
141
150
  * paid-tools session booked (a monid endpoint's, a priced MCP tool's, Parallel's behind the web tools, the browser's
142
151
  * time), joined and rounded by the one rule its `usd` is (costWordsOf), less those in its end-of-run turn, which are
@@ -20,14 +20,15 @@ import { learningStartOf, seedFailed } from "./run-launch.js";
20
20
  import { momentOf, pendingOf, stoppedTurn, approvalOf, asksOf, answersOf, activePauseOf, budgetOf, browserPending, computerPending, redactorOf, servedRunErrorWith, servedReviewWith, statusOf, WITHHELD_SIGN_IN, WITHHELD_TITLE, costWordsOfView, freeOf, stopAsked, usersOf, withAsks, withApprovalRows, } from "./run-view.js";
21
21
  import { reflects } from "./reflect-range.js";
22
22
  import { freeCeilingMessage, overCapMessage, SPEND_CAP_REACHED } from "@parcha/agentrun-kernel/kernel/cap";
23
- import { bookedSpend, cliModelWorked, costBasisOf, costWordsOf, planSpend, runCostOf, storedBasisOf } from "./runner/metrics.js";
23
+ import { bookedSpend, cliModelWorked, costBasisOf, costWordsOf, endCostOf, planSpend, runCostOf, storedBasisOf } from "./runner/metrics.js";
24
24
  import { journalRecords, recordOf } from "./runner/journal-reader.js";
25
25
  import { capNowOf, KINDS } from "./runner/journal-kinds.js";
26
26
  import { laidOf, pathViewOf, roundsOf, runLearningEnd, usedOnly } from "./store-reads/learning.js";
27
27
  import { inReflect, reflectRanges } from "./runner/end-of-run.js";
28
28
  import { correctionCount } from "./learn/corrections.js";
29
29
  import { isCliRecord, runReflect, runTimeline, wholeAnswerFor, wholeAnswers, withoutFeedbackRounds } from "./store-reads/journal.js";
30
- import { costOfRun, readRun } from "./store-reads/runs.js";
30
+ import { costOfRun, readRun, runReadState } from "./store-reads/runs.js";
31
+ import { feedbackOf, keptEndOf } from "./runner/feedback-round.js";
31
32
  import { runCutValues, runErrorWordsOf, underCut } from "./run-cut.js";
32
33
  import { Turns } from "./turns.js";
33
34
  import { harnessOfBody } from "./harness.js";
@@ -182,22 +183,54 @@ async function storeRunOf(store, runId, deps) {
182
183
  * never fails on its heal, and the next read or start sweep writes it again). */
183
184
  export async function healStoredCost(store, runId, heal) {
184
185
  try {
185
- return await store.runs.healCost(runId, heal, heal.usd);
186
+ return await store.runs.healCost(runId, heal, heal);
186
187
  }
187
188
  catch (error) {
188
189
  console.warn(`[serve] an ended run's cost read from its booking could not be stored: ${error.message}; the next read stores it`);
189
190
  return false;
190
191
  }
191
192
  }
193
+ /** A person's message not taken yet: a steer that is no grade's round (feedback-round.ts feedbackOf). */
194
+ const waitingMessage = (command) => command.kind === "steer" && command.takenAt === null && command.refused === null && feedbackOf(command.body) === undefined;
195
+ /** The end run `stored` keeps while it looks back after its job ended (its end-of-run step: a fresh run's, or a grade's
196
+ * feedback round), from its root `entries` and its command rows (`commands`), else undefined. Every reader serves that
197
+ * end: completed (or as its job ended), its answer, its end time, its learning reflecting, while its runner still holds
198
+ * it. A person's message waiting (not taken yet) makes it a run going on again, as a completed run a message opens again
199
+ * reads: its end is the message's turn's to write. */
200
+ async function lookingBackOf(stored, entries, commands) {
201
+ if (stored.state !== "running")
202
+ return undefined;
203
+ const rows = await commands();
204
+ const kept = keptEndOf(entries, rows);
205
+ return kept !== undefined && !rows.some(waitingMessage) ? kept : undefined;
206
+ }
207
+ /** The end run `runId` keeps while it looks back after its job ended, as every reader serves it (lookingBackOf), else
208
+ * undefined: a run that reads ended while it is still learning from that end. */
209
+ export async function lookingBackEnd(store, runId) {
210
+ const stored = await store.runs.get(runId);
211
+ if (stored?.state !== "running")
212
+ return undefined;
213
+ return lookingBackOf(stored, (await journalRecords(store.readJournal(runId), BACKGROUND_CONTEXT)).entries, () => store.commands(runId, 0));
214
+ }
192
215
  /** `storeRunOf`'s reads, over `store` (a snapshot) and the run's cut. */
193
216
  async function storeRunIn(store, runId, deps, cut) {
194
217
  const context = BACKGROUND_CONTEXT;
195
- const row = await readRun(store, runId, context);
196
- if (!row)
218
+ const read = await readRun(store, runId, context);
219
+ if (!read)
197
220
  return undefined;
198
- const runRow = await store.runs.get(runId);
199
- if (!runRow)
221
+ const stored = await store.runs.get(runId);
222
+ if (!stored)
200
223
  return undefined;
224
+ // The run's root records (the turns it took, its asks, its ends), and its command rows, read once for what needs them:
225
+ // the end it keeps while it looks back, a stop or a cancel asked for, a hand-over's answers, the person's messages not
226
+ // yet taken.
227
+ const records = await journalRecords(store.readJournal(runId), context);
228
+ let commandRows;
229
+ const commandsNow = async () => (commandRows ??= await store.commands(runId, 0));
230
+ // A run looking back after its job ended is that end, as every reader serves it (lookingBackOf).
231
+ const lookingBack = await lookingBackOf(stored, records.entries, commandsNow);
232
+ const runRow = lookingBack ? { ...stored, state: lookingBack.state, summary: lookingBack.summary ?? null, outcome: lookingBack.outcome ?? null, endedAt: lookingBack.endedAt } : stored;
233
+ const row = lookingBack ? keptRead(read, runRow) : read;
201
234
  const launch = await launchOf(store, runId);
202
235
  const unshown = cut === "unreadable";
203
236
  const values = cut === "unreadable" ? [] : cut.values;
@@ -214,8 +247,9 @@ async function storeRunIn(store, runId, deps, cut) {
214
247
  // The timeline, then the waiting row a run asking a question shows (withAsks), as the file path's rows carried it, so a
215
248
  // run waiting on a question reads the same status and pending.
216
249
  // Its final answer whole (store-reads/journal.ts wholeAnswers), as main served a run's answer: a row's cut is no answer's.
217
- // A run that ended reads settled, and its usage row says its cost ("Cost: …"), never what it has cost so far.
218
- const timelineOptions = { settled: terminal, ended: terminal, redact: (text) => redacted(text, values) };
250
+ // A run that ended reads settled, and its usage row says its cost ("Cost: …"), never what it has cost so far. One
251
+ // looking back is still going: its look-back's rows come yet.
252
+ const timelineOptions = { settled: terminal && !lookingBack, ended: terminal && !lookingBack, redact: (text) => redacted(text, values) };
219
253
  const timeline = withAsks(await wholeAnswers(store, runId, context, await runTimeline(store, runId, context, timelineOptions), timelineOptions, wholeAnswerFor(values)));
220
254
  const revisions = await store.agents.revisions(row.agent);
221
255
  const version = revisions.findIndex((r) => r.id === row.revision) + 1;
@@ -223,12 +257,12 @@ async function storeRunIn(store, runId, deps, cut) {
223
257
  // Whether a runner holds the run now, and the time of its latest change: the live tick while it runs (store.live, the
224
258
  // runner's own tick), its end once ended, its start before either.
225
259
  const [liveRow] = await store.live.read([runId]);
226
- const live = liveOf(runRow, deps.now?.() ?? Date.now());
260
+ // A run looking back is held by the runner that looks back: its claim is served as such.
261
+ const live = liveOf(stored, deps.now?.() ?? Date.now());
227
262
  const updatedAtMs = liveRow?.updatedAt ?? runRow.endedAt ?? runRow.startedAt;
228
263
  // The turns the run took, rebuilt from the journal the same way the file path's noteTurns fed Turns: the root's records
229
264
  // (a CLI session's own conversation skipped) and the input submissions, with the end-of-run turn's entries left out
230
265
  // (runReflect). progressAt reads the latest tick, so a working run's last_progress_at advances as today.
231
- const records = await journalRecords(store.readJournal(runId), context);
232
266
  const sdkCompletion = records.entries.findLast(entry => entry.kind === "agentrun.sdk.completion")?.data;
233
267
  const sdkSession = records.entries.findLast(entry => entry.kind === "agentrun.sdk.session")?.data;
234
268
  const sdk = launch?.sdk ? { runtime: launch.sdk.runtime, model: sdkCompletion?.model ?? launch.sdk.model ?? null, session_id: sdkCompletion?.session_id ?? sdkSession?.session_id ?? null, learning_revision: launch.learning?.seed ?? null, usage: sdkCompletion?.usage ?? null } : undefined;
@@ -250,20 +284,18 @@ async function storeRunIn(store, runId, deps, cut) {
250
284
  // (main's seeded and reflecting).
251
285
  const started = launch ? learningStartOf(launch) : undefined;
252
286
  const under = !ended && started && started.use ? usedOnly(started, terminal, iso(runRow.endedAt ?? runRow.startedAt)) : !ended && started && !seedFailed(started) ? underWay(started, laidOf(records.entries), reflectRange, iso(runRow.startedAt)) : null;
253
- const shownEnd = ended ?? under;
287
+ // A run looking back after its job's end reads reflecting from that end on, a graded one too (its last end's learning
288
+ // is the earlier round's).
289
+ const shownEnd = lookingBack && started && !started.use ? { state: "reflecting", reason: null, detail: said.reflecting, at: iso(lookingBack.endedAt) } : ended ?? under;
254
290
  const turns = new Turns();
255
291
  turns.note(recordOf(records.entries), records.submissions ?? [], skip, liveRow?.updatedAt ?? deps.now?.() ?? Date.now());
256
- const working = live && turns.open > 0;
292
+ const working = !lookingBack && live && turns.open > 0;
257
293
  const progress = terminal || row.kind === "workflow" ? undefined : turns.progressAt();
258
294
  const lastProgressAt = progress === undefined ? null : iso(progress);
259
295
  // The tool-call approvals the run waits (or waited) on, from its journal: each call the gate parked for a person, and
260
296
  // the answers given, which the status, pending and moment views read the same as the file path read them from the run's
261
297
  // store entries.
262
298
  const approvals = asksOf(records.entries);
263
- // The run's command rows, read once for what needs them: a stop or a cancel asked for, a hand-over's answers, and the
264
- // person's messages not yet taken.
265
- let commandRows;
266
- const commandsNow = async () => (commandRows ??= await store.commands(runId, 0));
267
299
  // A person's stop of an agentic run (stoppedByPerson: its row reads running, readRun) is main's stop mark: the run is
268
300
  // stopped while no message is newer than the stop (statusOf: input_required and idle), and a message reopens it. A stop
269
301
  // asked for and not yet taken (stopAsked) is the mark too once nothing works: between the turn's cut and the end that
@@ -362,10 +394,18 @@ async function storeRunIn(store, runId, deps, cut) {
362
394
  const bookedCost = bookedCostOf(row, native !== undefined, records.entries);
363
395
  const endCost = bookedCost?.requests ? bookedCost : undefined;
364
396
  const endSaid = records.entries.findLast((entry) => entry.kind === KINDS.end)?.data?.costUsd;
365
- const endSaidCost = endCost ? endSaid !== undefined : false;
366
- const endUnread = bookedCost !== undefined && !endCost && endSaid === null;
367
- const heal = healOf(endCost, runRow);
368
- return { ...(sdk ? { sdk } : {}), ...(native ? { native } : {}), row, runRow, launch, rows, version, harness, learningEnd: shownEnd, shownEnd, view, unshown, values, live, updatedAtMs, lastProgressAt, budget, paused, browserAsk, computerAsk, approvalsMode, output, ...(review ? { review } : {}), structured, decisions, plan, model, ...(endCost ? { endCost, endSaidCost } : {}), ...(endUnread ? { endUnread } : {}), ...(heal ? { heal } : {}) };
397
+ // A run looking back has no end of its own stored yet (its job's is kept apart): its cost is its booking so far, by the
398
+ // rule its end will store it by, and nothing is healed.
399
+ const endSaidCost = endCost && !lookingBack ? endSaid !== undefined : false;
400
+ const endUnread = !lookingBack && bookedCost !== undefined && !endCost && endSaid === null;
401
+ const heal = lookingBack ? undefined : healOf(endCost, runRow);
402
+ return { ...(sdk ? { sdk } : {}), ...(native ? { native } : {}), row, runRow, launch, rows, version, harness, learningEnd: shownEnd, shownEnd, view, unshown, values, live, updatedAtMs, lastProgressAt, budget, paused, browserAsk, computerAsk, approvalsMode, output, ...(review ? { review } : {}), structured, decisions, plan, model, ...(endCost ? { endCost, endSaidCost } : {}), ...(endUnread ? { endUnread } : {}), ...(heal ? { heal } : {}), ...(lookingBack ? { lookingBack: true } : {}) };
403
+ }
404
+ /** Run read `read` (a run still going, as the store holds it) as the end `ended` keeps (its state, summary and end time:
405
+ * the end a run looking back keeps), its cost as read. */
406
+ function keptRead(read, ended) {
407
+ const { endedAt: _endedAt, summary: _summary, ...rest } = read;
408
+ return { ...rest, state: runReadState(ended, read.kind), ...(ended.endedAt !== null ? { endedAt: iso(ended.endedAt) } : {}), ...(ended.summary !== null ? { summary: ended.summary } : {}) };
369
409
  }
370
410
  /** A run's learning as the view shows it: its end from the store (what it held for the owner's OK as it reads now), in a
371
411
  * person's words cut of the host's secrets now. */
@@ -487,14 +527,16 @@ function bookedCostOf(row, native, entries) {
487
527
  return undefined;
488
528
  return runCostOf(entries, { unbooked: isCliRecord(entries) && cliModelWorked(entries) });
489
529
  }
490
- /** What an ended run's stored cost heals to (Runs.healCost), at the end it was read at: its booking's figure, when that
491
- * booking has a request and an exact figure (no hold counted in it) while the stored cost is null with no bound. */
530
+ /** What an ended run's stored cost heals to (Runs.healCost), at the end it was read at: what its end would have stored
531
+ * had it read its booking (endCostOf, the one rule every end writes by: its figure, a bound when a cut request's hold is
532
+ * counted in it), when that booking has a request and a figure while the stored cost is null with no bound. */
492
533
  function healOf(endCost, runRow) {
493
- if (!endCost || endCost.usd === null || endCost.atMost !== 0)
534
+ if (!endCost || endCost.usd === null)
494
535
  return undefined;
495
536
  if (runRow.costUsd !== null || runRow.costAtMostUsd !== null || runRow.endedAt === null)
496
537
  return undefined;
497
- return { epoch: runRow.epoch, endedAt: runRow.endedAt, usd: endCost.usd };
538
+ const { costUpperBound } = endCostOf(endCost);
539
+ return { epoch: runRow.epoch, endedAt: runRow.endedAt, costUsd: endCost.usd, costUpperBound };
498
540
  }
499
541
  /** The start sweep's heal of run `runId` (cost-heal.ts): the same rule as its run read's (bookedCostOf, healOf), from its
500
542
  * row, its launch and its journal alone, so a sweep over many runs reads no timeline and no learning folder. True when
@@ -509,7 +551,7 @@ export async function healedOverStore(store, runId) {
509
551
  const booked = bookedCostOf(row, Boolean(launch?.native), (await journalRecords(snapshot.readJournal(runId), BACKGROUND_CONTEXT)).entries);
510
552
  return healOf(booked?.requests ? booked : undefined, runRow);
511
553
  });
512
- return heal !== undefined && (await store.runs.healCost(runId, heal, heal.usd));
554
+ return heal !== undefined && (await store.runs.healCost(runId, heal, heal));
513
555
  }
514
556
  /** GET /runs/{id}'s answer from the store, byte-identical to runs.ts's view for the same run. Undefined for an unknown run. */
515
557
  export async function viewOverStore(store, runId, deps) {
@@ -574,7 +616,8 @@ async function viewOfRun(store, runId, deps, run, read) {
574
616
  // it holds none of the run's words, so a withheld run says it too.
575
617
  const redactor = redactorOf(values);
576
618
  const pending = !unshown && status === "input_required" && state === "waiting" ? (approvalOf(view, redactor) ?? run.budget ?? browserPending(run.browserAsk, redactor) ?? computerPending(run.computerAsk, redactor) ?? pendingOf(run.rows)) : stoppedTurn(view, { status, state }) ? { kind: "stopped" } : null;
577
- const settled = terminal && ended;
619
+ // A run looking back reads its job's end, and is settled only once its look-back's end is in.
620
+ const settled = terminal && ended && !run.lookingBack;
578
621
  return {
579
622
  ...(run.sdk && !unshown ? { sdk: redactedOutput(run.sdk, values) } : {}),
580
623
  ...(run.native && !unshown ? { native: redactedOutput(run.native, values) } : {}),
@@ -25,7 +25,8 @@ import { evalClock, LAYOUTS, mailboxAfter, mailboxFixtureOf, mailboxText, mailbo
25
25
  import { caseFeeds, feedFixtureOf } from "./eval-feed.js";
26
26
  import { EMAIL_TOOLS } from "./email/names.js";
27
27
  import { CALENDAR_EVENTS } from "./calendar/names.js";
28
- import { settingsKeyOf, shellToolOf } from "./tool-gate.js";
28
+ import { nameMapOf, settingsKeyOf, shellToolOf } from "./tool-gate.js";
29
+ import { builtinHarness } from "./harness-table.js";
29
30
  import { webShownOf } from "./timeline/index.js";
30
31
  import { ASK_TOOL, BOUND_TOOLS } from "./tools.js";
31
32
  import { webFixtureOf } from "./web-fake.js";
@@ -918,10 +919,12 @@ async function waitRun(api, runId, deadline, signal, queueTimeoutMs = QUEUE_TIME
918
919
  * its output's head as the rows of a calls=whole read carry them (tool_input, tool_result_text), else its previews. */
919
920
  export function callsOf(rows, harness, toolkits = {}) {
920
921
  const results = new Map(rows.filter((row) => row.kind === "tool_result" && row.tool_use_id).map((row) => [String(row.tool_use_id), row]));
922
+ // The rows are a server's, read over its API: the names are the built-in harness's, the only facts known here.
923
+ const names = nameMapOf(harness, builtinHarness(harness)?.facts);
921
924
  return rows.filter((row) => row.kind === "tool_use" && typeof row.tool_name === "string").map((row) => {
922
925
  const name = row.tool_name;
923
926
  const result = results.get(String(row.tool_use_id));
924
- const key = settingsKeyOf(harness, name);
927
+ const key = settingsKeyOf(harness, name, names);
925
928
  const output = typeof result?.tool_result_text === "string" ? result.tool_result_text : (result?.tool_result_preview ?? null);
926
929
  return { tool: shellToolOf(name) ?? (key === undefined ? undefined : onServerName(key, toolkits)) ?? name, name, preview: row.tool_input_preview ?? null, ...(isObject(row.tool_input) ? { arguments: row.tool_input } : {}), status: result?.tool_status ?? null, result: output };
927
930
  });
@@ -16,11 +16,15 @@ export type Held = {
16
16
  readonly unreadable: string;
17
17
  };
18
18
  /** Each GitHub MCP tool a template may grant that needs more than reading what the App's metadata gives: the permission
19
- * and level GitHub's permission table for its request names, and what the template does instead when it can't. */
19
+ * and level GitHub's permission table for its request names, and what the template does instead when it can't.
20
+ * `public`: GitHub's table states a permission for private resources, and this request works on a public repository
21
+ * without it (POST /repos/{owner}/{repo}/issues: "any user with pull access to a repository can create an issue"), so the
22
+ * warning is about private repositories and says what a public one does. */
20
23
  export declare const TOOL_PERMISSIONS: Record<string, {
21
24
  permission: string;
22
25
  level: Level;
23
26
  instead: string;
27
+ public?: string;
24
28
  }>;
25
29
  /** The warnings applying `pkg` adds: one for each GitHub MCP tool it grants that needs a permission an installation of the
26
30
  * App does not hold (naming each installation's account and what it holds), on an MCP server `onApp` says runs on the App's
@@ -1,9 +1,12 @@
1
1
  import { NOT_SET_UP } from "./runnable.js";
2
2
  import { mcpToolName } from "./tool-names.js";
3
3
  /** Each GitHub MCP tool a template may grant that needs more than reading what the App's metadata gives: the permission
4
- * and level GitHub's permission table for its request names, and what the template does instead when it can't. */
4
+ * and level GitHub's permission table for its request names, and what the template does instead when it can't.
5
+ * `public`: GitHub's table states a permission for private resources, and this request works on a public repository
6
+ * without it (POST /repos/{owner}/{repo}/issues: "any user with pull access to a repository can create an issue"), so the
7
+ * warning is about private repositories and says what a public one does. */
5
8
  export const TOOL_PERMISSIONS = {
6
- issue_write: { permission: "issues", level: "write", instead: "keeps its draft in its answer" },
9
+ issue_write: { permission: "issues", level: "write", instead: "keeps its draft in its answer", public: "On a public repository GitHub takes it without: anyone who can read one may open an issue there." },
7
10
  };
8
11
  /** Each permission as GitHub's App settings name it. */
9
12
  const LABELS = { issues: "Issues", pull_requests: "Pull requests", contents: "Contents", metadata: "Metadata" };
@@ -38,7 +41,8 @@ export async function appPermissionWarnings(pkg, onApp, held) {
38
41
  const short = map.installations.filter((installation) => !holds(installation.permissions[wants.permission], wants.level));
39
42
  if (short.length) {
40
43
  const holding = short.map(({ account, permissions }) => `${permissions[wants.permission] ? `${label}: ${permissions[wants.permission]}` : `no ${label} permission`} on ${account}`).join(", ");
41
- warnings.push({ field: `grants.${name}`, reason: "not_allowed", message: `${name} needs ${label}: ${wants.level}, and this server's GitHub App has ${holding}, so GitHub refuses it: ${pkg.name} ${wants.instead}. The App's owner can add ${label}: ${wants.level} to it on GitHub.` });
44
+ const where = wants.public ? " on a private repository" : "";
45
+ warnings.push({ field: `grants.${name}`, reason: "not_allowed", message: `${name} needs ${label}: ${wants.level}${where}, and this server's GitHub App has ${holding}, so GitHub refuses it there: ${pkg.name} ${wants.instead}.${wants.public ? ` ${wants.public}` : ""} The App's owner can add ${label}: ${wants.level} to it on GitHub.` });
42
46
  }
43
47
  // Installations whose map was not read in time or at all: said apart, never passed as holding it.
44
48
  if (map.unread?.length) {
@@ -6,4 +6,4 @@ export { costLabel, endedUsage, PAGE_CHANGED_ROW, RUN_RESUMED, toolCallWords, TU
6
6
  export { FEEDBACK_SUFFIX, isFeedbackRow, isMessageRow, isUserEntry, MESSAGE_ORIGIN, messageOrigins, NOTE_SUFFIX, originMatcher, originOf, TRIGGER_LABELS, TRIGGER_SOURCES, type MessageOrigin, type TriggerSource } from "./origin.js";
7
7
  export { cut, scrubUrl, scrubUrls } from "./util.js";
8
8
  export { webCut, webShownOf, webWithin, type WebShown } from "./web-calls.js";
9
- export { answeredRequests, BROWSER_CHARGE, CALL_ENDED_WITH_RUN, CALL_REFUSED, CALL_RESULT_CHARS, CAP_WRAPUP, CAPS, chargedTool, COMPUTER_NOTE, endedOnTurnEndingTool, HOST_PHASE, METRIC_NAMES, REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_COST_PENDING, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, runMetricsOf, runMetricsWithDecisions, timelineOf, timelineReducer, TOOL_COST, TOOL_STARTED, TOOL_UNMETERED, type AgentEventLike, type DecisionLike, type EntryLike, type RunMetrics, type SideSpend, type TimelineEvent, type TimelineKind, type TimelineOptions, type ToolMetrics, } from "./timeline.js";
9
+ export { answeredRequests, BROWSER_CHARGE, CALL_ENDED_WITH_RUN, compactionAnswers, CALL_REFUSED, CALL_RESULT_CHARS, CAP_WRAPUP, CAPS, chargedTool, COMPUTER_NOTE, endedOnTurnEndingTool, HOST_PHASE, METRIC_NAMES, REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_COST_PENDING, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, runMetricsOf, runMetricsWithDecisions, timelineOf, timelineReducer, TOOL_COST, TOOL_STARTED, TOOL_UNMETERED, type AgentEventLike, type DecisionLike, type EntryLike, type RunMetrics, type SideSpend, type TimelineEvent, type TimelineKind, type TimelineOptions, type ToolMetrics, } from "./timeline.js";
@@ -6,4 +6,4 @@ export { costLabel, endedUsage, PAGE_CHANGED_ROW, RUN_RESUMED, toolCallWords, TU
6
6
  export { FEEDBACK_SUFFIX, isFeedbackRow, isMessageRow, isUserEntry, MESSAGE_ORIGIN, messageOrigins, NOTE_SUFFIX, originMatcher, originOf, TRIGGER_LABELS, TRIGGER_SOURCES } from "./origin.js";
7
7
  export { cut, scrubUrl, scrubUrls } from "./util.js";
8
8
  export { webCut, webShownOf, webWithin } from "./web-calls.js";
9
- export { answeredRequests, BROWSER_CHARGE, CALL_ENDED_WITH_RUN, CALL_REFUSED, CALL_RESULT_CHARS, CAP_WRAPUP, CAPS, chargedTool, COMPUTER_NOTE, endedOnTurnEndingTool, HOST_PHASE, METRIC_NAMES, REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_COST_PENDING, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, runMetricsOf, runMetricsWithDecisions, timelineOf, timelineReducer, TOOL_COST, TOOL_STARTED, TOOL_UNMETERED, } from "./timeline.js";
9
+ export { answeredRequests, BROWSER_CHARGE, CALL_ENDED_WITH_RUN, compactionAnswers, CALL_REFUSED, CALL_RESULT_CHARS, CAP_WRAPUP, CAPS, chargedTool, COMPUTER_NOTE, endedOnTurnEndingTool, HOST_PHASE, METRIC_NAMES, REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_COST_PENDING, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, runMetricsOf, runMetricsWithDecisions, timelineOf, timelineReducer, TOOL_COST, TOOL_STARTED, TOOL_UNMETERED, } from "./timeline.js";
@@ -201,6 +201,14 @@ export declare const REQUEST_CONTINUED = "agentrun.request_continued";
201
201
  * cut at CAPS.summary, at `at` (ms) when the host gave the time it happened, else at the time of the log before it. No
202
202
  * request, no cost; one without a summary shows nothing. */
203
203
  export declare const HOST_PHASE = "agentrun.phase";
204
+ /** Whether `entry` is pi's compaction entry answering its summary request, the one rule both journal counters read (this
205
+ * timeline's meter, cap.ts openFigures): a summary request that left marked as a generation is answered by pi's
206
+ * pi.compaction entry, since pi stores no answer for it; one a host marked as a side request (`request: "compaction"`)
207
+ * is closed by its own cost entry, never by that entry. Fed every entry in the journal's order, `sideSummaries` counting
208
+ * the side summary requests since pi's last compaction entry, which are its own. */
209
+ export declare function compactionAnswers(entry: EntryLike, sideSummaries: {
210
+ count: number;
211
+ }): boolean;
204
212
  /** Written on the root as a run's process opens to go on with a run its last process left unfinished: `after` is `crash`
205
213
  * (that process died holding the run), `server_stop` (it drained as the server stopped) or `runner_lost` (a runner took
206
214
  * the run over once the runner holding it, named by `runner`, let its lease run out), `generation` the new process's,
@@ -124,6 +124,21 @@ export const REQUEST_CONTINUED = "agentrun.request_continued";
124
124
  export const HOST_PHASE = "agentrun.phase";
125
125
  const COMPACTION = "compaction";
126
126
  const isCompaction = (entry) => obj(entry.data)?.request === COMPACTION;
127
+ /** Whether `entry` is pi's compaction entry answering its summary request, the one rule both journal counters read (this
128
+ * timeline's meter, cap.ts openFigures): a summary request that left marked as a generation is answered by pi's
129
+ * pi.compaction entry, since pi stores no answer for it; one a host marked as a side request (`request: "compaction"`)
130
+ * is closed by its own cost entry, never by that entry. Fed every entry in the journal's order, `sideSummaries` counting
131
+ * the side summary requests since pi's last compaction entry, which are its own. */
132
+ export function compactionAnswers(entry, sideSummaries) {
133
+ if (entry.kind === REQUEST_STARTED && isCompaction(entry))
134
+ sideSummaries.count += 1;
135
+ if (entry.kind !== "pi.compaction")
136
+ return false;
137
+ if (sideSummaries.count === 0)
138
+ return true;
139
+ sideSummaries.count = 0;
140
+ return false;
141
+ }
127
142
  /** A side request's mark: its `request` is a label (a generation's, a harness's request number, is not). */
128
143
  const isSide = (entry) => typeof obj(entry.data)?.request === "string";
129
144
  const unsent = (entry) => obj(entry.data)?.unsent === true;
@@ -242,7 +257,7 @@ function createMeter() {
242
257
  let compactions = 0;
243
258
  let compacting = 0;
244
259
  // Compaction summaries a host marked as side requests since pi's last pi.compaction entry: that entry is theirs.
245
- let sideSummaries = 0;
260
+ const sideSummaries = { count: 0 };
246
261
  // How many are in flight: two side requests (a turn's parallel searches) may be.
247
262
  let sidesOpen = 0;
248
263
  const tokens = { input: 0, cacheRead: 0, cacheWrite: 0, output: 0 };
@@ -259,6 +274,7 @@ function createMeter() {
259
274
  function push(entry) {
260
275
  const message = entry.model?.[0];
261
276
  const data = obj(entry.data);
277
+ const summaryAnswered = compactionAnswers(entry, sideSummaries);
262
278
  if (entry.kind === "pi.assistant" && entry.recordedCall && message) {
263
279
  // A call the loop's record kept (a CLI's, or one a tool of pi's nested): shown as an answer's call, never a request.
264
280
  return "call";
@@ -284,9 +300,7 @@ function createMeter() {
284
300
  // answer pi stores beside it (what the session booked since the last one), so this entry is that request's answer,
285
301
  // at no cost of its own here, its tokens unknown to pi's entries. One a host marked as a side request is closed by
286
302
  // its own cost entry, never here. Shown as its phase row all the same.
287
- if (sideSummaries > 0)
288
- sideSummaries = 0;
289
- else if (marked - answered - freeUnanswered - atMostUnanswered - (freeEnded ? 1 : 0) - (atMostEnded !== undefined ? 1 : 0) > 0) {
303
+ if (summaryAnswered && marked - answered - freeUnanswered - atMostUnanswered - (freeEnded ? 1 : 0) - (atMostEnded !== undefined ? 1 : 0) > 0) {
290
304
  (requests += 1), (answered += 1);
291
305
  addTokens(undefined);
292
306
  }
@@ -295,8 +309,6 @@ function createMeter() {
295
309
  else if (entry.kind === REQUEST_STARTED && isSide(entry)) {
296
310
  compacting += 1;
297
311
  sidesOpen += 1;
298
- if (obj(entry.data)?.request === COMPACTION)
299
- sideSummaries += 1;
300
312
  }
301
313
  else if (entry.kind === REQUEST_ENDED && isSide(entry)) {
302
314
  if (unsent(entry))
@@ -1,4 +1,5 @@
1
1
  import { SHELL_FAMILY, SHELL_WATCHERS, shellToolOf } from "@parcha/agentrun-kernel/kernel";
2
+ import { type AdapterFacts } from "@parcha/agentrun-kernel";
2
3
  import type { Workspace } from "./workspace/workspace.js";
3
4
  import { type ToolSettingsRead } from "./tool-plane.js";
4
5
  import { type SettingFrom } from "./refusal-words.js";
@@ -35,13 +36,14 @@ export type NameMap = ReadonlyMap<string, string>;
35
36
  /** Every name a session on `harness` gives its tools, to the settings key each is held to: the shell family (bash's),
36
37
  * table, own and decision tools, read_skill_file (`read`), the kinds' tools (a shared one by its first kind), nativeTools,
37
38
  * the browser's registrations. The names are the host's own: each adapter maps its CLI's names to them (its facts'
38
- * hostName). The first named wins. */
39
- export declare function nameMapOf(harness: string): NameMap;
39
+ * hostName). The first named wins. `facts`: the adapter's, as the owner's table has them (harness-table.ts factsOf: a
40
+ * module's harness's too); undefined for a harness with none (pi). */
41
+ export declare function nameMapOf(harness: string, facts: AdapterFacts | undefined): NameMap;
40
42
  /** The settings key a call named `name` on `harness` is held to: a lookup in the session's names (`names`), then the open
41
43
  * open family no list holds (a catalog name, `mcp:<server>/<tool>` or `monid:<provider>/<endpoint>`). Undefined: nothing
42
44
  * maps it, and the gate asks (an MCP tool's or monid endpoint's wire name is read back by the loop, ClaimMcp.catalogOf,
43
45
  * before the gate is asked). */
44
- export declare function settingsKeyOf(harness: string, name: string, names?: NameMap): string | undefined;
46
+ export declare function settingsKeyOf(harness: string, name: string, names: NameMap): string | undefined;
45
47
  /** A pinned argument's scalar: `null` holds for a call that leaves the argument out (or gives null). */
46
48
  export type PinScalar = string | number | boolean | null;
47
49
  /** A pinned object argument's keys: the argument, when given (not left out, nor null), is an object whose keys are among
@@ -182,6 +184,7 @@ export declare function runGate(where: {
182
184
  computer?: boolean;
183
185
  effectOf?: (name: string) => ToolEffect | undefined;
184
186
  argumentsOf?: ArgumentsOf;
187
+ facts: AdapterFacts | undefined;
185
188
  }, runId: string, revision: {
186
189
  kind: string;
187
190
  body: {
@@ -219,7 +222,8 @@ export declare class RunGate {
219
222
  computer?: boolean; /** The run's computer kind (its revision's setting): the key a computer tool's refusal and ask name on a tie (kindSetting). */
220
223
  kind?: string;
221
224
  effectOf?: (name: string) => ToolEffect | undefined; /** The arguments each MCP tool's listing in the run's pin declares (ClaimMcp.argumentsOf), for a pinned tool's closure (pinRefusal). */
222
- argumentsOf?: ArgumentsOf;
225
+ argumentsOf?: ArgumentsOf; /** The harness's adapter facts on the owner's table (its native tools' names, nameMapOf); undefined for one with none. */
226
+ facts: AdapterFacts | undefined;
223
227
  }, readServerSettings: () => ToolSettingsRead, overrides?: PermissionSettings, approvers?: boolean, approvals?: Approvals);
224
228
  private names?;
225
229
  /** A tool's permission now (permissionOf): the revision's own over the server's setting, read at each call, so a change
package/dist/tool-gate.js CHANGED
@@ -27,7 +27,6 @@
27
27
  import { COMPUTER_OP_TOOL, computerToolDefs, defaultPermissionOf, SHELL_FAMILY, SHELL_WATCHERS, shellPermission, shellToolOf } from "@parcha/agentrun-kernel/kernel";
28
28
  import { READ_SKILL_FILE } from "@parcha/agentrun-kernel";
29
29
  import { COMPUTER_ROOT } from "./workspace/paths.js";
30
- import { builtinHarness } from "./harness-table.js";
31
30
  import { META_TOOLS } from "./meta-tool-names.js";
32
31
  import { DEFAULT_HARNESS } from "./harness.js";
33
32
  import { DECISION_PROVIDER_KEYS, KIND_KEYS, SERVE_OWN_TOOLS } from "./tool-plane.js";
@@ -98,9 +97,9 @@ const STRICTNESS = { allow: 0, ask: 1, deny: 2 };
98
97
  /** Every name a session on `harness` gives its tools, to the settings key each is held to: the shell family (bash's),
99
98
  * table, own and decision tools, read_skill_file (`read`), the kinds' tools (a shared one by its first kind), nativeTools,
100
99
  * the browser's registrations. The names are the host's own: each adapter maps its CLI's names to them (its facts'
101
- * hostName). The first named wins. */
102
- export function nameMapOf(harness) {
103
- const facts = builtinHarness(harness)?.facts;
100
+ * hostName). The first named wins. `facts`: the adapter's, as the owner's table has them (harness-table.ts factsOf: a
101
+ * module's harness's too); undefined for a harness with none (pi). */
102
+ export function nameMapOf(harness, facts) {
104
103
  const names = new Map();
105
104
  const name = (own, key) => void (names.has(own) || names.set(own, key));
106
105
  for (const [own, key] of Object.entries(SHELL_FAMILY))
@@ -121,7 +120,7 @@ export function nameMapOf(harness) {
121
120
  * open family no list holds (a catalog name, `mcp:<server>/<tool>` or `monid:<provider>/<endpoint>`). Undefined: nothing
122
121
  * maps it, and the gate asks (an MCP tool's or monid endpoint's wire name is read back by the loop, ClaimMcp.catalogOf,
123
122
  * before the gate is asked). */
124
- export function settingsKeyOf(harness, name, names = nameMapOf(harness)) {
123
+ export function settingsKeyOf(harness, name, names) {
125
124
  const own = names.get(name);
126
125
  if (own !== undefined)
127
126
  return own;
@@ -350,7 +349,7 @@ export function previewOf(text) {
350
349
  export function runGate(where, runId, revision, serverSettings, approvers) {
351
350
  // The run's computer kind, from its revision's setting (as the claim starts it): a computer tool's words name it.
352
351
  const kind = settingOfDefinition(revision.body)?.computer.kind;
353
- return new RunGate({ root: where.root, work: where.work, runId, harness: revision.body.harness ?? DEFAULT_HARNESS, ...(where.computer === undefined ? {} : { computer: where.computer }), ...(kind !== undefined ? { kind } : {}), ...(where.effectOf ? { effectOf: where.effectOf } : {}), ...(where.argumentsOf ? { argumentsOf: where.argumentsOf } : {}) }, serverSettings, (revision.body.toolSettings ?? {}), approvers, approvalsOf(revision.body.approvals));
352
+ return new RunGate({ root: where.root, work: where.work, runId, harness: revision.body.harness ?? DEFAULT_HARNESS, ...(where.computer === undefined ? {} : { computer: where.computer }), ...(kind !== undefined ? { kind } : {}), ...(where.effectOf ? { effectOf: where.effectOf } : {}), ...(where.argumentsOf ? { argumentsOf: where.argumentsOf } : {}), facts: where.facts }, serverSettings, (revision.body.toolSettings ?? {}), approvers, approvalsOf(revision.body.approvals));
354
353
  }
355
354
  /** A run's tool gate on the runner: its policy, asked before each call's intent (decide). */
356
355
  export class RunGate {
@@ -422,7 +421,7 @@ export class RunGate {
422
421
  if (kinds)
423
422
  return this.kindSetting(name, kinds).key;
424
423
  const harness = this.where.harness ?? DEFAULT_HARNESS;
425
- return settingsKeyOf(harness, name, (this.names ??= nameMapOf(harness)));
424
+ return settingsKeyOf(harness, name, (this.names ??= nameMapOf(harness, this.where.facts)));
426
425
  }
427
426
  /** A computer tool's settings keys (KIND_TOOLS), the run's own kind first (where.kind); undefined for any other tool. */
428
427
  kindKeysOf(tool) {
@@ -1,6 +1,7 @@
1
1
  import type { InputIssue } from "./errors.js";
2
2
  import type { Settings } from "./store/index.js";
3
3
  import { type HarnessId } from "./harness.js";
4
+ import type { AdapterFacts } from "@parcha/agentrun-kernel";
4
5
  import { type ShellPlace } from "@parcha/agentrun-kernel/kernel";
5
6
  import { type Permission, type Pin, type ToolEffect } from "./tool-gate.js";
6
7
  import { type BashPolicy } from "./bash-read-only.js";
@@ -121,6 +122,9 @@ export type ResolveInput = {
121
122
  openRouter?: boolean;
122
123
  /** Its permission in force (tool-gate.ts); absent, allow. */
123
124
  permission?: Permission;
125
+ /** The facts of the adapter the harness runs on (its own search, its wire), its owner's table entry's (harness-table.ts
126
+ * factsOf: a module's harness's too); undefined for one with none (pi). Always given: a caller names them. */
127
+ facts: AdapterFacts | undefined;
124
128
  };
125
129
  /** Whether a run on `harness` sends through OpenRouter, where a harness's own search does not run: false for one with
126
130
  * none (and for pi, whose hosted search is asked of the model's provider). */
@@ -25,7 +25,7 @@ import { PROVIDERS as COMPUTER_PROVIDERS } from "@parcha/agentrun-computer";
25
25
  import { decisionKeysOf, PARALLEL_KEY_ENV } from "./decisions.js";
26
26
  import { keyNeeded } from "./key-words.js";
27
27
  import { DEFAULT_HARNESS, HARNESSES } from "./harness.js";
28
- import { builtinHarness, harnessOf } from "./harness-table.js";
28
+ import { factsOf as tableFactsOf, harnessOf } from "./harness-table.js";
29
29
  import { viaOpenRouter, wireOf } from "./provider.js";
30
30
  import { savedIn } from "./secrets.js";
31
31
  import { hostModel } from "./model.js";
@@ -144,9 +144,9 @@ export const HOSTED_SEARCH_PROVIDERS = ["anthropic", "openai"];
144
144
  const cappedOwn = (id, label, mode) => mode === "native"
145
145
  ? { id: `${id} under a spend cap: ${label}'s own search has per-use fees a spend cap cannot reserve yet, so web_search works under a cap through the default provider, auto`, why: `under a spend cap ${label}'s own search is not offered, since a cap cannot reserve its per-use fees yet` }
146
146
  : { id: `${id} under a spend cap`, why: `under a spend cap ${label}'s own search is not offered, since its request has no input bound` };
147
- /** The facts of the adapter `harness` runs on (none for pi): its own search, its wire. A stand-in keeps the facts of the
148
- * harness it stands in for (harness-table.ts). */
149
- const factsOf = (harness) => builtinHarness(harness)?.facts;
147
+ /** `harness`'s facts on `env`'s owner table, as a ResolveInput carries them (a stand-in keeps the facts of the harness it
148
+ * stands in for, harness-table.ts); undefined for one that has none. */
149
+ const withFacts = (env, harness) => ({ facts: tableFactsOf(env, harness) });
150
150
  /** Whether a run on `harness` sends through OpenRouter, where a harness's own search does not run: false for one with
151
151
  * none (and for pi, whose hosted search is asked of the model's provider). */
152
152
  export const ownSearchViaOpenRouter = (env, harness, model) => {
@@ -164,7 +164,7 @@ function noNative(input) {
164
164
  // provider-hosted tool) has none at all. Where there is none, `native` is unavailable, and `auto` goes to Parallel on
165
165
  // the server's key (its fee booked and held by a cap, paid-calls.ts), else to keyless Exa.
166
166
  const vendor = input.model?.slice(0, Math.max(0, input.model.indexOf("/")));
167
- const facts = factsOf(input.harness);
167
+ const { facts } = input;
168
168
  if (facts) {
169
169
  if (!facts.webSearch)
170
170
  return { id: `${input.harness}, whose model requests carry no provider-hosted tool`, why: `${facts.label}'s model requests carry no provider-hosted tool` };
@@ -182,7 +182,7 @@ function noNative(input) {
182
182
  }
183
183
  /** The native search of a run that has one, in a sentence. */
184
184
  const nativeWhy = (input) => {
185
- const facts = factsOf(input.harness);
185
+ const { facts } = input;
186
186
  return facts?.webSearch ? `${facts.label}'s own search` : `${input.model?.startsWith("openai/") ? "OpenAI" : "Anthropic"}'s hosted search, for ${input.model}`;
187
187
  };
188
188
  /** What `capability` resolves to on a run of `input`, and why in a plain sentence (capabilities' `why`): one rule, so
@@ -205,7 +205,7 @@ export function explainCapability(capability, input) {
205
205
  return { resolves: "exa-keyless", why: `keyless Exa, ${picked}: Exa's free search, no key` };
206
206
  // Under ask, a harness's own search runs inside its CLI, where no call can wait for a person: none on claude-agent or
207
207
  // codex then, and the kernel's search, which the gate holds, in its place. pi's is a tool of the run's, which it holds.
208
- const asks = input.permission === "ask" && factsOf(input.harness) !== undefined;
208
+ const asks = input.permission === "ask" && input.facts !== undefined;
209
209
  const without = noNative(input);
210
210
  if (chosen === "native" && asks && without === undefined)
211
211
  return { resolves: NATIVE_ASKS, why: "native search cannot wait for an approval: it runs inside the harness's CLI" };
@@ -214,7 +214,7 @@ export function explainCapability(capability, input) {
214
214
  return none === undefined ? { resolves: "native", why: nativeWhy(input) } : { resolves: `unavailable: no native search for ${none.id}`, why: `no native search for ${none.id}` };
215
215
  // `auto` skips a harness's own search that has per-use fees (its facts' `native`: the provider's search tool), an
216
216
  // explicit pick (`native`): Parallel on the server's key, else keyless Exa.
217
- const facts = factsOf(input.harness);
217
+ const { facts } = input;
218
218
  if (facts?.webSearch === "native")
219
219
  return input.parallelKey ? { resolves: "parallel", why: key } : { resolves: "exa-keyless", why: `Exa's free keyless search, no key; ${facts.label}'s own search is an explicit pick` };
220
220
  if (none === undefined)
@@ -291,7 +291,7 @@ export function explainsView(env, settings, overrides = {}, model) {
291
291
  const input = { ...served(env), ...picked(name, settings, overrides) };
292
292
  const each = HARNESSES.map((harness) => {
293
293
  const on = model ?? hostModel(env, "default", harness);
294
- return [harness, explainCapability(name, { ...input, ...(on ? { model: on } : {}), harness, openRouter: ownSearchViaOpenRouter(env, harness, on) })];
294
+ return [harness, explainCapability(name, { ...input, ...(on ? { model: on } : {}), harness, ...withFacts(env, harness), openRouter: ownSearchViaOpenRouter(env, harness, on) })];
295
295
  });
296
296
  return [name, { resolves: Object.fromEntries(each.map(([harness, said]) => [harness, said.resolves])), why: Object.fromEntries(each.map(([harness, said]) => [harness, said.why])) }];
297
297
  }));
@@ -322,7 +322,7 @@ export function planeFor(env, tooling, settings, { capped = false, run = false }
322
322
  if (!granted.includes(name))
323
323
  continue;
324
324
  const chosen = picked(name, settings, tooling.overrides, tooling.approvals ?? "ask");
325
- plane[name] = resolveCapability(name, { ...served(env), harness, capped, openRouter: ownSearchViaOpenRouter(env, harness, model), ...(model ? { model } : {}), ...chosen, ...(run && chosen.permission === "deny" ? { permission: "ask" } : {}) });
325
+ plane[name] = resolveCapability(name, { ...served(env), harness, ...withFacts(env, harness), capped, openRouter: ownSearchViaOpenRouter(env, harness, model), ...(model ? { model } : {}), ...chosen, ...(run && chosen.permission === "deny" ? { permission: "ask" } : {}) });
326
326
  }
327
327
  // The model a search through its provider's hosted search asks (hosted-search.ts): pi's own web_search, and on
328
328
  // another harness, whose agent searches with its own tool, a learned workflow's call node (learned-workflow.ts).