@parcha/agentrun-serve 0.1.0-beta.62 → 0.1.0-beta.63

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 (128) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +32 -13
  3. package/dist/adapters.js +4 -2
  4. package/dist/agent-delete.d.ts +3 -3
  5. package/dist/agent-delete.js +50 -4
  6. package/dist/chatgpt-plan.d.ts +8 -1
  7. package/dist/chatgpt-plan.js +55 -6
  8. package/dist/console/assets/{backend-DEgVn5lC.js → backend-BxQ2G1M0.js} +2 -2
  9. package/dist/console/assets/{index-CG5tELph.js → index-C8Y5Zl8x.js} +2 -2
  10. package/dist/console/assets/share-CjBJ_rxP.js +6 -0
  11. package/dist/console/index.html +1 -1
  12. package/dist/console/share.html +1 -1
  13. package/dist/harness-opencode/adapter.d.ts +3 -1
  14. package/dist/harness-opencode/adapter.js +6 -2
  15. package/dist/harness-opencode/harness.d.ts +4 -0
  16. package/dist/harness-opencode/harness.js +6 -1
  17. package/dist/host-tools.d.ts +18 -3
  18. package/dist/host-tools.js +27 -4
  19. package/dist/learn/ledger.d.ts +37 -16
  20. package/dist/learn/ledger.js +56 -24
  21. package/dist/learn/promote.d.ts +4 -1
  22. package/dist/learning-cost.d.ts +5 -3
  23. package/dist/learning-model.js +7 -5
  24. package/dist/learning-work.d.ts +69 -0
  25. package/dist/learning-work.js +148 -0
  26. package/dist/openapi.js +23 -9
  27. package/dist/run-export.js +7 -4
  28. package/dist/run-launch.d.ts +6 -1
  29. package/dist/run-launch.js +10 -3
  30. package/dist/run-view.js +9 -3
  31. package/dist/runnable.js +5 -5
  32. package/dist/runner/adapter-loop.js +31 -3
  33. package/dist/runner/adapter-run-spec.d.ts +14 -3
  34. package/dist/runner/adapter-run-spec.js +50 -19
  35. package/dist/runner/adapters/index.d.ts +2 -0
  36. package/dist/runner/adapters/index.js +3 -0
  37. package/dist/runner/adapters/pi.d.ts +42 -3
  38. package/dist/runner/adapters/pi.js +114 -13
  39. package/dist/runner/audit.d.ts +8 -2
  40. package/dist/runner/audit.js +34 -18
  41. package/dist/runner/book-cut.d.ts +6 -0
  42. package/dist/runner/book-cut.js +38 -0
  43. package/dist/runner/claim-secrets.d.ts +9 -4
  44. package/dist/runner/claim-secrets.js +10 -5
  45. package/dist/runner/cli-run-spec.d.ts +0 -2
  46. package/dist/runner/cli-run-spec.js +44 -19
  47. package/dist/runner/held.d.ts +6 -3
  48. package/dist/runner/learned-first.d.ts +5 -0
  49. package/dist/runner/learned-first.js +1 -1
  50. package/dist/runner/learning-end.d.ts +15 -8
  51. package/dist/runner/learning-end.js +23 -7
  52. package/dist/runner/loop-contract.d.ts +4 -0
  53. package/dist/runner/main.js +2 -0
  54. package/dist/runner/model-route.d.ts +4 -0
  55. package/dist/runner/model-route.js +1 -1
  56. package/dist/runner/pr-checkout.d.ts +12 -0
  57. package/dist/runner/pr-checkout.js +21 -2
  58. package/dist/runner/promotion.d.ts +9 -2
  59. package/dist/runner/promotion.js +79 -28
  60. package/dist/runner/reflect-hook.d.ts +7 -0
  61. package/dist/runner/reflect-hook.js +2 -1
  62. package/dist/runner/run-child-host.js +21 -12
  63. package/dist/runner/run-child.js +1 -0
  64. package/dist/runner/runner.d.ts +9 -0
  65. package/dist/runner/runner.js +156 -25
  66. package/dist/runner/store-port.d.ts +4 -1
  67. package/dist/runner/workflow-first.js +4 -3
  68. package/dist/runner/workflow-loop.js +13 -1
  69. package/dist/secret-cut.d.ts +4 -0
  70. package/dist/secret-cut.js +1 -1
  71. package/dist/secret-rules.d.ts +2 -0
  72. package/dist/secret-rules.js +63 -19
  73. package/dist/server.js +20 -9
  74. package/dist/share-host.js +6 -3
  75. package/dist/store/schema.d.ts +4 -3
  76. package/dist/store/schema.js +4 -3
  77. package/dist/store/seal.d.ts +8 -2
  78. package/dist/store/seal.js +13 -2
  79. package/dist/store/sqlite/learning-rows.js +2 -1
  80. package/dist/store/sqlite/run-patch.js +4 -4
  81. package/dist/store/sqlite/store.js +28 -4
  82. package/dist/store/store.d.ts +5 -0
  83. package/dist/store-reads/journal.d.ts +2 -0
  84. package/dist/store-reads/journal.js +1 -1
  85. package/dist/store-reads/learning.d.ts +4 -3
  86. package/dist/store-reads/learning.js +62 -18
  87. package/dist/store-view.d.ts +3 -0
  88. package/dist/store-view.js +18 -1
  89. package/dist/tool-list.d.ts +4 -0
  90. package/dist/tool-list.js +4 -0
  91. package/dist/tools.js +2 -2
  92. package/dist/workspace/attach.js +22 -5
  93. package/dist/workspace/kind-skills/desktop/SKILL.md +7 -3
  94. package/package.json +12 -12
  95. package/templates/kyb/agent.md +7 -1
  96. package/templates/kyb/evals/list-file-fuzzy-alias/case.yaml +10 -0
  97. package/templates/kyb/evals/list-file-fuzzy-alias/fixtures/web.json +58 -0
  98. package/templates/kyb/evals/list-file-fuzzy-alias/graders/finds-the-transliteration.md +17 -0
  99. package/templates/kyb/evals/list-file-fuzzy-alias/graders/greps-the-files.md +11 -0
  100. package/templates/kyb/evals/list-file-fuzzy-alias/graders/saves-the-uk-file.md +8 -0
  101. package/templates/kyb/evals/list-file-fuzzy-alias/prompt.md +7 -0
  102. package/templates/kyb/evals/list-file-hit/case.yaml +10 -0
  103. package/templates/kyb/evals/list-file-hit/fixtures/web.json +58 -0
  104. package/templates/kyb/evals/list-file-hit/graders/greps-the-files.md +11 -0
  105. package/templates/kyb/evals/list-file-hit/graders/hits-by-company-number.md +18 -0
  106. package/templates/kyb/evals/list-file-hit/graders/saves-the-uk-file.md +8 -0
  107. package/templates/kyb/evals/list-file-hit/prompt.md +7 -0
  108. package/templates/kyb/evals/list-file-no-hit/case.yaml +10 -0
  109. package/templates/kyb/evals/list-file-no-hit/fixtures/web.json +58 -0
  110. package/templates/kyb/evals/list-file-no-hit/graders/greps-the-files.md +11 -0
  111. package/templates/kyb/evals/list-file-no-hit/graders/no-hit-by-whole-file.md +12 -0
  112. package/templates/kyb/evals/list-file-no-hit/graders/saves-the-uk-file.md +8 -0
  113. package/templates/kyb/evals/list-file-no-hit/prompt.md +7 -0
  114. package/templates/kyb/evals/list-file-short-name/case.yaml +9 -0
  115. package/templates/kyb/evals/list-file-short-name/fixtures/web.json +58 -0
  116. package/templates/kyb/evals/list-file-short-name/graders/finds-the-short-name.md +19 -0
  117. package/templates/kyb/evals/list-file-short-name/graders/greps-the-files.md +11 -0
  118. package/templates/kyb/evals/list-file-short-name/graders/saves-the-uk-file.md +8 -0
  119. package/templates/kyb/evals/list-file-short-name/prompt.md +7 -0
  120. package/templates/kyb/evals/list-file-split-name/case.yaml +11 -0
  121. package/templates/kyb/evals/list-file-split-name/fixtures/web.json +58 -0
  122. package/templates/kyb/evals/list-file-split-name/graders/finds-the-director.md +18 -0
  123. package/templates/kyb/evals/list-file-split-name/graders/greps-the-files.md +11 -0
  124. package/templates/kyb/evals/list-file-split-name/graders/saves-the-uk-file.md +8 -0
  125. package/templates/kyb/evals/list-file-split-name/prompt.md +7 -0
  126. package/templates/kyb/kyb.schema.json +2 -2
  127. package/templates/kyb/rules/SANCTIONS.md +82 -13
  128. package/dist/console/assets/share-CIeFK2Oe.js +0 -6
@@ -11,7 +11,8 @@ import { learningStartOf, learningStartOfStored, readLaunchBody, seedFailed } fr
11
11
  import { said, seedStopped } from "../learning-words.js";
12
12
  import { learningImpact } from "../learning-run.js";
13
13
  import { COST_WINDOW, JOB_PATHS, noiseOff, RUN_PATHS, SERVED_PATHS, workflowCallsIn } from "../learning-cost.js";
14
- import { answeredOf, auditOfLaunch, figuresOf, record, roundsLooked, roundsSpentIn, shadowCostOf, spendByRun, summarize } from "../learn/ledger.js";
14
+ import { answeredOf, figuresOf, ownCheck, record, roundsLooked, roundsSpentIn, runEndOfLaunch, shadowCostOf, spendByRun, summarize } from "../learn/ledger.js";
15
+ import { learningChildrenOf } from "../learning-work.js";
15
16
  import { COMPILE_AFTER_DEFAULT } from "../learning-setting.js";
16
17
  import { modelsOwn, runPathOf } from "../runner/learning-end.js";
17
18
  import { feedbackStatus } from "../runner/feedback-round.js";
@@ -246,7 +247,8 @@ const zipWith = (keys, values) => keys.map((key, at) => [key, values[at]]);
246
247
  /** What summarize reads of agent `agentId` (LedgerRead, its revisions aside), over `listed` (its runs, as runs.list read
247
248
  * them): the ledger rows of its ended runs that do a job or check one (neither imported nor archived, no workflow
248
249
  * revision's run, no shadow), each on the path its end wrote, each with the workflow name its launch
249
- * offered; every spend row; each run's audit shadow (open or ended); and the runs on no named disk (learn/learning-of.ts:
250
+ * offered; every spend row; each run's audit shadow (open or ended); the runs whose own-key check has a replay still at
251
+ * work (`openChecks`, one launch read per run of `listed` not yet final); and the runs on no named disk (learn/learning-of.ts:
250
252
  * one on a named disk learns nothing and serves nothing). Each ended run has its row: its end wrote it, or the server's
251
253
  * open (run-patch.ts backfillLedger) for one an earlier build ended; none is recorded here. `runIds`: the runs whose
252
254
  * ledger is read (Learning.ledger), the agent's every run when absent. `named` false: no workflow name is read for the
@@ -275,8 +277,25 @@ async function ledgerReadOf(store, agentId, listed, records, { runIds, named = t
275
277
  if (shadow)
276
278
  shadows.set(run.id, shadow);
277
279
  }
280
+ // The runs whose own-key check still runs: each replay not yet final names the run that pays it (its launch's
281
+ // `replay.paid_by`), whose check stays unknown until it ends, as that run's own read says (runFiguresOf). A replay's end
282
+ // writes its spend row with its ledger row, so one that ended is counted there.
283
+ const openChecks = new Set();
284
+ for (const run of listed) {
285
+ if (FINAL_STATES.includes(run.state))
286
+ continue;
287
+ // A run with no launch row was started by no check (a replay's launch is written with it).
288
+ const launch = await records.runs.launch(run.id).catch((error) => {
289
+ if (error instanceof StoreLaunchMissing)
290
+ return undefined;
291
+ throw error;
292
+ });
293
+ const paidBy = readLaunchBody(launch?.body)?.replay?.paidBy;
294
+ if (paidBy)
295
+ openChecks.add(paidBy);
296
+ }
278
297
  // Only a name the launch offered is shown.
279
- return { rows, spend, shadows, learning, compileAfter: COMPILE_AFTER_DEFAULT, ...(named ? { named: (row) => offeredName(row.workflow, offered.get(row.runId)) } : {}) };
298
+ return { rows, spend, shadows, openChecks, learning, compileAfter: COMPILE_AFTER_DEFAULT, ...(named ? { named: (row) => offeredName(row.workflow, offered.get(row.runId)) } : {}) };
280
299
  }
281
300
  /** Run `runId`'s audit shadow among `byId` (open while queued or running, ended once final), undefined with none. */
282
301
  const shadowOf = (byId, runId) => {
@@ -288,11 +307,11 @@ async function ledgerRowsOf(store, agentId, runIds) {
288
307
  const ledger = await store.learning.ledger(agentId, runIds);
289
308
  return { recorded: new Map(ledger.rows.map((row) => [row.runId, row])), spend: ledger.spend };
290
309
  }
291
- /** What record() reads of an ended run: its row, every round its learning kept and, for a shadow, the run it audits. */
310
+ /** What record() reads of an ended run: its row, every round its learning kept and its launch, as its end's ledger write
311
+ * reads them (learn/ledger.ts runEndOfLaunch). */
292
312
  async function runEndOf(records, run) {
293
313
  const rounds = (await roundsOf(records, run.id)).map((one) => ({ round: one.round, proposal: one.proposal }));
294
- const auditOf = auditOfLaunch(run.id, isShadowRun(run.id) ? (await records.runs.launch(run.id).catch(() => undefined))?.body : undefined);
295
- return { id: run.id, agentId: run.agentId, startedAt: run.startedAt, costUsd: run.costUsd, costAtMostUsd: run.costAtMostUsd, metrics: run.metrics, rounds, ...(auditOf === undefined ? {} : { auditOf }) };
314
+ return runEndOfLaunch(run, rounds, (await records.runs.launch(run.id).catch(() => undefined))?.body);
296
315
  }
297
316
  /** Each hold of the agent's learned workflows (its promotion records that say hold), placed on the series: at the first
298
317
  * run that does a job from it on, by its number among them (the points' `n`), null when none has run since. */
@@ -333,8 +352,9 @@ export function revisionsOf(records, reset = []) {
333
352
  * (learn/ledger.ts figuresOf over its ledger row: one formula): `path` its record's (metrics.path, RUN_PATHS: `agent`
334
353
  * for a run that does not learn; null while it has not ended, for a workflow revision's run, and for a run that learns
335
354
  * whose end named none); `usd` its own spend, the job's (its look-back left out); `learning_usd` what learning spent for
336
- * it: its follow-up rounds' turns, its audit shadow's cost, and its share of its revision's compile and check (its own
337
- * compile turns are its revision's: `compile_usd`); `all_in_usd` the two; and `learning_usd`'s parts. A replay or a
355
+ * it: its follow-up rounds' turns, its audit shadow's cost, the replays of a check it started on its own model key
356
+ * (`check_usd`, null while one runs), and its share of its revision's compile and check (its own compile turns are its
357
+ * revision's: `compile_usd`); `all_in_usd` the two; and `learning_usd`'s parts. A replay or a
338
358
  * shadow run carries none: its spend is on the runs it serves, so its `learning_usd` and `all_in_usd` are 0, and the sum
339
359
  * of every run's `all_in_usd` and the bill's `unattributed_usd` is the booked total. `rowUsd`: the cost its view reads
340
360
  * (its row's when absent); one other than its row's (an imported run's estimate, a booking where its end stored none)
@@ -351,25 +371,44 @@ export async function runAllInOverStore(store, runId, rowUsd) {
351
371
  const path = !ended || kind === "workflow" ? null : (pathOfRow(run.metrics, started)?.path ?? null);
352
372
  if (!ended) {
353
373
  const row = rowUsd === undefined ? (typeof run.costAtMostUsd === "number" ? null : run.costUsd) : rowUsd;
354
- return { path, usd: row, learning_usd: null, all_in_usd: null, compile_usd: null, followup_usd: null, shadow_usd: null, share_usd: null };
374
+ return { path, usd: row, learning_usd: null, all_in_usd: null, compile_usd: null, followup_usd: null, shadow_usd: null, check_usd: null, share_usd: null };
355
375
  }
356
- // A served run carries a share of its revision's spend: its figures are the series' own, over the agent's ledger.
376
+ // A served run carries a share of its revision's spend: its figures are the series' own, over the agent's ledger, its
377
+ // own-key check unknown while a replay of it runs (as runFiguresOf reads it).
357
378
  const served = path !== null && SERVED_PATHS.includes(path) && revisionOfRow(run) !== undefined;
358
- const figures = (served ? (await agentLedgerOverStore(store, run.agentId)).out.figures.get(run.id) : undefined) ?? (await runFiguresOf(store, run));
379
+ const series = served ? (await agentLedgerOverStore(store, run.agentId)).out.figures.get(run.id) : undefined;
380
+ const figures = series ? ((await ownCheckOf(store, run.id)).some((one) => !one.ended) ? checkOpen(series) : series) : await runFiguresOf(store, run);
359
381
  // The run's view priced it other than its row does (`rowUsd`: an imported run's catalog estimate, or its booking where
360
382
  // its end stored none): its job is that figure, as its end would have recorded it at that cost (record: less its
361
383
  // look-back), its learning's parts the ledger's.
362
- const { usd, learning_usd, all_in_usd, compile_usd, followup_usd, shadow_usd, share_usd } = typeof rowUsd === "number" && rowUsd !== run.costUsd ? await pricedAt(store, run, rowUsd, figures) : figures;
363
- return { path, usd, learning_usd, all_in_usd, compile_usd, followup_usd, shadow_usd, share_usd };
384
+ const { usd, learning_usd, all_in_usd, compile_usd, followup_usd, shadow_usd, check_usd, share_usd } = typeof rowUsd === "number" && rowUsd !== run.costUsd ? await pricedAt(store, run, rowUsd, figures) : figures;
385
+ return { path, usd, learning_usd, all_in_usd, compile_usd, followup_usd, shadow_usd, check_usd, share_usd };
364
386
  }
365
387
  /** Run `run`'s figures with its row's cost read as `usd` (runAllInOverStore's `rowUsd`): its row as its end would have
366
- * recorded it at that cost, with `figures`' compile, shadow and share. */
388
+ * recorded it at that cost, with `figures`' compile, shadow, own-key check and share. */
367
389
  async function pricedAt(store, run, usd, figures) {
368
390
  const row = record(await runEndOf(store, { ...run, costUsd: usd, costAtMostUsd: null })).row;
369
- return figuresOf(row, { compile: figures.compile_usd, shadow: figures.shadow_usd, share: figures.share_usd });
391
+ return figuresOf(row, { compile: figures.compile_usd, shadow: figures.shadow_usd, check: figures.check_usd, share: figures.share_usd });
392
+ }
393
+ /** The replay runs of a check run `runId` started on its own model key (learning-work.ts names them), each with whether
394
+ * it has ended: what they spent is its learning (learn/ledger.ts `check_usd`), unknown while one runs. */
395
+ async function ownCheckOf(store, runId) {
396
+ const out = [];
397
+ for (const child of await learningChildrenOf(store.settings, runId)) {
398
+ if (!child.keyed || child.kind !== "replay" || child.run === null)
399
+ continue;
400
+ const row = await store.runs.get(child.run);
401
+ if (row)
402
+ out.push({ row, ended: FINAL_STATES.includes(row.state) });
403
+ }
404
+ return out;
370
405
  }
406
+ /** `figures` with its own-key check unknown (a replay of it still running): its learning and all-in with it, never $0. */
407
+ const checkOpen = (figures) => ({ ...figures, check_usd: null, learning_usd: null, all_in_usd: null, series_learning_usd: null, series_total_usd: null });
371
408
  /** One run's figures (learn/ledger.ts figuresOf) with no share of its revision's (a run that carries none: not served, or
372
- * out of the series), over the ledger of it and its audit's shadow (ledgerRowsOf), as summarize reads them. */
409
+ * out of the series), over the ledger of it and its audit's shadow (ledgerRowsOf), as summarize reads them. Its own-key
410
+ * check's replays are read as summarize reads them (their check rows of it, `ofRun`): unknown while one runs, and one
411
+ * that ended with no row of its own yet at its row's cost. */
373
412
  async function runFiguresOf(store, run) {
374
413
  const shadow = isShadowRun(run.id) ? undefined : await store.runs.get(shadowRunId(run.id));
375
414
  const listed = shadow ? [run, shadow] : [run];
@@ -377,12 +416,17 @@ async function runFiguresOf(store, run) {
377
416
  // Every ended run has its row (its end's, or backfillLedger's at the server's open); one read without it reads as its
378
417
  // end records it, never as nothing.
379
418
  const row = recorded.get(run.id) ?? record(await runEndOf(store, run)).row;
380
- const { compile, audit } = spendByRun(spend);
419
+ const replays = await ownCheckOf(store, run.id);
420
+ const unbooked = replays.flatMap(({ row: replay, ended }) => ended && !spend.some((one) => ownCheck(one) && one.runId === replay.id)
421
+ ? [{ runId: replay.id, agentId: replay.agentId, round: 0, kind: "check", ofRun: run.id, workflow: null, digest: null, usd: typeof replay.costAtMostUsd === "number" ? null : replay.costUsd }]
422
+ : []);
423
+ const { compile, audit, check } = spendByRun([...spend, ...unbooked]);
381
424
  const shadows = new Map();
382
425
  const state = shadowOf(new Map(listed.map((one) => [one.id, one])), run.id);
383
426
  if (state)
384
427
  shadows.set(run.id, state);
385
- return figuresOf(row, { compile: compile.has(run.id) ? compile.get(run.id) : 0, shadow: shadowCostOf(run.id, audit, shadows), share: 0 });
428
+ const checked = replays.some((one) => !one.ended) ? null : check.has(run.id) ? check.get(run.id) : 0;
429
+ return figuresOf(row, { compile: compile.has(run.id) ? compile.get(run.id) : 0, shadow: shadowCostOf(run.id, audit, shadows), check: checked, share: 0 });
386
430
  }
387
431
  /** The check the serving promotion was decided on, as the cost summary says it: the champion (championOf) of the learned
388
432
  * workflow the newest run a learned workflow ran first on ran (`workflow` or `handed_back`), its record's check numbers
@@ -10,6 +10,7 @@ import type { PendingAsk } from "./browser-person.js";
10
10
  import { type Approvals } from "./approvals.js";
11
11
  import { type KeptListing, type RunListing, type RunRow, type Store } from "./store/store.js";
12
12
  import type { RecordingView } from "./run-recordings.js";
13
+ import { type OwnLearning } from "./learning-work.js";
13
14
  import { type FactoryActivity, type FactoryObserved } from "./factory-activity.js";
14
15
  /** What the store-backed view needs beside the store: where its console lives, every secret it never shows (read now, so
15
16
  * one rotated is cut at once), and the agents' saved sign-ins (for the handed-pointer cut). The server passes the same it
@@ -140,6 +141,8 @@ interface StoreRun {
140
141
  /** The run looks back after its job's end (`row` and `runRow` read as that end): nothing of it is settled until the
141
142
  * look-back's own end is in (poll_after_ms 1000, the timeline not final). */
142
143
  readonly lookingBack?: true;
144
+ /** What its view's learning_work reads of the run's own learning (learning-work.ts learningWorkOf), from the reads above. */
145
+ readonly ownLearning: OwnLearning;
143
146
  }
144
147
  /** A runner holds the run's claim now: it is not in a final state, a runner is named on its row, and its lease has not run
145
148
  * out (claimed_until >= now, the predicate the claimable query's `claimed_until < ?` is the negation of). `now` is the
@@ -41,6 +41,8 @@ import { approvalsOf } from "./approvals.js";
41
41
  import { FINAL_STATES, stoppedByPerson } from "./store/store.js";
42
42
  import { LISTING_HELD, LISTING_KEYED } from "./store/schema.js";
43
43
  import { createHash } from "node:crypto";
44
+ import { learningWorkOf } from "./learning-work.js";
45
+ import { COMPILE_TIMEOUT_MS } from "./learn/compile.js";
44
46
  import { factoryChildren, factoryGithub, factoryLastActivity, factoryObservation, factoryObserved, factorySource } from "./factory-activity.js";
45
47
  /** A run that has ended reads one of these (the old RunRow state → the v2 status: an escalation is a completion with a
46
48
  * review; a stopped run is a cancellation), as runs.ts's STATUS_OF mapped them. A running run reads its status from the
@@ -312,6 +314,18 @@ async function storeRunIn(store, runId, deps, cut, since) {
312
314
  // A run looking back after its job's end reads reflecting from that end on, a graded one too (its last end's learning
313
315
  // is the earlier round's).
314
316
  const shownEnd = lookingBack && started && !started.use ? { state: "reflecting", reason: null, detail: said.reflecting, at: iso(lookingBack.endedAt) } : ended ?? under;
317
+ // Its own learning, as learning_work reads it: a run that learns (a learning start, and no replay or shadow run), its
318
+ // compile turn going (it looks back), one begun (its job's end kept for an end-of-run step), and, once its end is in,
319
+ // when that learning ended (its learning end's time, else its end's). While it looks back, its compile turn's bound as
320
+ // far as the view knows it: the job's end + the turn's timeout (the turn's own start, later, is kept with its children).
321
+ const learnedAt = !lookingBack && stored.state !== "running" ? Math.max(stored.endedAt ?? 0, ended ? Date.parse(ended.at) || 0 : 0) : 0;
322
+ const ownLearning = {
323
+ learns: started !== undefined && !launch?.replay && !launch?.audit,
324
+ compiling: lookingBack !== undefined,
325
+ compiled: records.entries.some((entry) => entry.kind === KINDS.jobEnd),
326
+ endedAt: learnedAt > 0 ? learnedAt : null,
327
+ compileBy: lookingBack ? lookingBack.endedAt + COMPILE_TIMEOUT_MS : null,
328
+ };
315
329
  const turns = new Turns();
316
330
  turns.note(recordOf(records.entries), records.submissions ?? [], skip, liveRow?.updatedAt ?? deps.now?.() ?? Date.now());
317
331
  const working = !lookingBack && live && turns.open > 0;
@@ -434,7 +448,7 @@ async function storeRunIn(store, runId, deps, cut, since) {
434
448
  github: unshown ? null : factoryGithub(launch, (text) => withoutLoopback(redacted(text, values))),
435
449
  children: terminal || FINAL_STATES.includes(runRow.state) || unshown ? [] : await factoryChildren(store, runId, records, (text) => withoutLoopback(redacted(text, values))),
436
450
  } : undefined;
437
- return { ...(factory ? { factory } : {}), ...(cli_learning ? { cli_learning } : {}), ...(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, model, windDown, ...(endCost ? { endCost, endSaidCost } : {}), ...(endUnread ? { endUnread } : {}), ...(heal ? { heal } : {}), ...(lookingBack ? { lookingBack: true } : {}) };
451
+ return { ...(factory ? { factory } : {}), ...(cli_learning ? { cli_learning } : {}), ...(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, model, windDown, ...(endCost ? { endCost, endSaidCost } : {}), ...(endUnread ? { endUnread } : {}), ...(heal ? { heal } : {}), ...(lookingBack ? { lookingBack: true } : {}), ownLearning };
438
452
  }
439
453
  /** Run read `read` (a run still going, as the store holds it) as the end `ended` keeps (its state, summary and end time:
440
454
  * the end a run looking back keeps), its cost as read. */
@@ -705,6 +719,9 @@ async function viewOfRun(store, runId, deps, run, read) {
705
719
  budget_refused_calls: run.windDown.refusedCalls,
706
720
  // The run an audit's shadow run audits (launch.audit, runner/audit.ts); null for any other run.
707
721
  audit_of: launch?.audit?.of ?? null,
722
+ // The learning work the run started beside its turn (its compile turn, its check's replays, its audit's shadow), what
723
+ // a caller revokes the run's own key on once the run is terminal and this is not running (learning-work.ts).
724
+ learning_work: await learningWorkOf(store, runId, run.ownLearning),
708
725
  // The path it took and the learned workflow that served it, as its record keeps them: the read the cost per run makes
709
726
  // (store-reads/learning.ts pathViewOf).
710
727
  ...pathViewOf(runRow, row.kind, launch ? learningStartOf(launch) : undefined),
@@ -17,6 +17,10 @@ export declare const isTableTool: (name: string) => boolean;
17
17
  export declare const isAskable: (name: string) => boolean;
18
18
  /** Whether a host runs `name` on a harness other than pi: it has a replay class. */
19
19
  export declare const isHostTool: (name: string) => boolean;
20
+ /** Whether a harness other than pi may be granted `name`: a host tool, or the browser, which has no host row (a call a crash
21
+ * cut off is its custody's to reconcile, never replayed) and binds through its own binding (runner/adapter-run-spec.ts
22
+ * browserHostTools). */
23
+ export declare const adapterBinds: (name: string) => boolean;
20
24
  /** `name`'s replay class as a host runs it, or none. */
21
25
  export declare const replayOf: (name: string) => "safe" | "never" | undefined;
22
26
  /** The tools a host runs on a harness other than pi, by name. */
package/dist/tool-list.js CHANGED
@@ -40,6 +40,10 @@ export const isTableTool = (name) => rowOf(name)?.table === true;
40
40
  export const isAskable = (name) => rowOf(name)?.askable === true;
41
41
  /** Whether a host runs `name` on a harness other than pi: it has a replay class. */
42
42
  export const isHostTool = (name) => rowOf(name)?.replay !== undefined;
43
+ /** Whether a harness other than pi may be granted `name`: a host tool, or the browser, which has no host row (a call a crash
44
+ * cut off is its custody's to reconcile, never replayed) and binds through its own binding (runner/adapter-run-spec.ts
45
+ * browserHostTools). */
46
+ export const adapterBinds = (name) => isHostTool(name) || name === "browser";
43
47
  /** `name`'s replay class as a host runs it, or none. */
44
48
  export const replayOf = (name) => rowOf(name)?.replay;
45
49
  /** The tools a host runs on a harness other than pi, by name. */
package/dist/tools.js CHANGED
@@ -4,7 +4,7 @@
4
4
  // nothing here: a run's runner binds them from its workspace's registry (workspace/run-tools.ts), each call made on the
5
5
  // run's folder or its computer. `bash` and the background tools may be named only by an agent whose place is a box
6
6
  // (runnable.ts).
7
- import { blurbOf, isHostTool } from "./tool-list.js";
7
+ import { adapterBinds, blurbOf } from "./tool-list.js";
8
8
  import { EMAIL_DESCRIPTIONS, EMAIL_DRAFT, EMAIL_FILE, EMAIL_READ, EMAIL_SEARCH, EMAIL_SEND, fileSummary, sendSummary } from "./email/names.js";
9
9
  // The email tools' timeline lines (registerLabel), registered as this module loads.
10
10
  import "./email/labels.js";
@@ -814,7 +814,7 @@ export const toolsView = (env, settings = {}, noBox, refused = {}, runnerShell =
814
814
  // Unavailable says why: a sandbox-only tool no box here can run, why none can (`noBox`); on a tool a user picks a
815
815
  // provider for, the resolutions' own words (`web_search is turned off in settings`); else the variables it needs.
816
816
  const reason = available ? undefined : refusal ?? boxless ?? (plane ? [...new Set(Object.values(plane).filter(isUnavailable).map(whyUnavailable))].join("; ") : `Needs ${keyNeeded(missing)}`);
817
- return { name, summary: entry.summary, ...(blurbOf(name) ? { blurb: blurbOf(name) } : {}), nodes: entry.nodes, calls: entry.effect !== undefined, ...(entry.callOnly ? { call_only: true } : {}), ...(entry.sandboxOnly ? { sandbox_only: true } : {}), ...(entry.runnerOnly ? { runner_only: true } : {}), available, ...(reason ? { reason } : {}), ...(missing.length ? { missing } : {}), harnesses: isHostTool(name) ? [...everyHarness] : [...generalSpec], ...serverGate(name, settings), ...(plane ? { providers: [...PROVIDERS[name]], provider: picked[name].provider, default_provider: PROVIDERS[name][0], resolves: plane, why: view.why } : {}) };
817
+ return { name, summary: entry.summary, ...(blurbOf(name) ? { blurb: blurbOf(name) } : {}), nodes: entry.nodes, calls: entry.effect !== undefined, ...(entry.callOnly ? { call_only: true } : {}), ...(entry.sandboxOnly ? { sandbox_only: true } : {}), ...(entry.runnerOnly ? { runner_only: true } : {}), available, ...(reason ? { reason } : {}), ...(missing.length ? { missing } : {}), harnesses: adapterBinds(name) ? [...everyHarness] : [...generalSpec], ...serverGate(name, settings), ...(plane ? { providers: [...PROVIDERS[name]], provider: picked[name].provider, default_provider: PROVIDERS[name][0], resolves: plane, why: view.why } : {}) };
818
818
  });
819
819
  // The host tools over a run's own tools (META_TOOLS): not in the table, never granted or named by a node (`meta`), listed
820
820
  // so the owner sees them and their setting (allow or deny; a deny is not offered at all).
@@ -368,10 +368,11 @@ export function attachedWorkspace(base, computer, options = {}) {
368
368
  // once, at its end, where a caller (bash) needs the output as it comes and the end of a long one. The process is
369
369
  // read as it comes (process.read, each stream from its own offset), every byte given to onOutput and the first
370
370
  // maxOutput of each kept; at the deadline or an abort it is sent KILL (computerd's guard then ends everything it
371
- // started), and once it ends its guard kills whatever it left, so nothing it started outlives it.
371
+ // started), and once it ends its guard kills whatever it left, so nothing it started outlives it. `stdin`: the process
372
+ // starts with its stdin open, and the bytes go by process.write, in chunks, its stdin closed after the last, so they
373
+ // are never in its argv or its environment (a checkout's token, pr-checkout.ts). A program that ends without reading
374
+ // them answers as it ended: a write it no longer takes is not the call's failure, as a closed pipe's is not.
372
375
  async exec(argv, options) {
373
- if (options.stdin !== undefined)
374
- throw new WorkspaceError("REFUSED", "exec with stdin runs on the run's folder, not in a computer: a computer's exec takes no stdin");
375
376
  if (options.network !== undefined)
376
377
  throw new WorkspaceError("REFUSED", "a command in a computer has the computer's own network: its exec takes no network of its own, and nothing ran");
377
378
  const { timeoutMs, signal } = options;
@@ -383,7 +384,23 @@ export function attachedWorkspace(base, computer, options = {}) {
383
384
  if (signal?.aborted)
384
385
  throw abortError(signal);
385
386
  const { abs, rel } = at(options.cwd ?? "");
386
- const { id } = await value(call("process.start", { argv: [...argv], cwd: abs, env: { ...options.env } }), rel);
387
+ const { stdin } = options;
388
+ const { id } = await value(call("process.start", { argv: [...argv], cwd: abs, env: { ...options.env }, ...(stdin !== undefined ? { stdin: true } : {}) }), rel);
389
+ const feed = async (bytes) => {
390
+ const parts = chunks(bytes);
391
+ for (const [i, part] of parts.entries()) {
392
+ const wrote = await call("process.write", { id, data: base64(part), ...(i === parts.length - 1 ? { close: true } : {}) });
393
+ if (wrote.ok)
394
+ continue;
395
+ // computerd answers invalid once the program closed its stdin or ended (EPIPE, EIO, a closed file, "has ended",
396
+ // "stdin is closed"): the program answers as it ended. A write it did not read in time (timeout), a lost
397
+ // connection or any other failure fails the call, which kills the process (the catch below); after this
398
+ // call's own deadline or abort, that answer stands instead.
399
+ if (wrote.error.code === "invalid" || timedOut || aborted)
400
+ return;
401
+ throw new WorkspaceError(CODES[wrote.error.code] ?? "UNAVAILABLE", `${JSON.stringify(rel === "" ? "." : rel)}: the program's input could not be written: ${wrote.error.message}`, { path: rel });
402
+ }
403
+ };
387
404
  let timedOut = false;
388
405
  let aborted = false;
389
406
  let truncated = false;
@@ -422,7 +439,7 @@ export function attachedWorkspace(base, computer, options = {}) {
422
439
  };
423
440
  let exit;
424
441
  try {
425
- await Promise.all([readAll("stdout"), readAll("stderr")]);
442
+ await Promise.all([readAll("stdout"), readAll("stderr"), ...(stdin !== undefined ? [feed(stdin)] : [])]);
426
443
  exit = await value(call("process.wait", { id, timeoutMs: EXEC_EXIT_WAIT_MS }), rel);
427
444
  }
428
445
  catch (error) {
@@ -88,8 +88,8 @@ file from Finder into a Mail message), or anything outside every window.
88
88
  **Only what you were given.** An agent's computer setting may leave some out: a code-only agent drives the desktop from
89
89
  `codemode` alone, with no `computer_observe`, `computer_act` or `computer_screenshot` in its tool list; an agent whose
90
90
  exec is off has no `computer.shell`, no `computer.processes` and no bash; one not given read has no `computer.files`
91
- read, list or stat, and one not given write no `computer.files.write`; an op whose setting is deny, or an ask no one
92
- can answer here, is left out the same way. Where the desktop has the `apps` group a
91
+ read, list or stat, and one not given write no `computer.files.write`; a file, shell or process op whose tool is set to
92
+ deny, or to an ask no one can answer here, is left out the same way. Where the desktop has the `apps` group a
93
93
  script opens apps with `computer.apps`, and on a desktop with no ui group the tools open the app they name (below);
94
94
  otherwise it uses the desktop's own launcher through the screen. Use what your tool list and codemode's types show.
95
95
 
@@ -137,7 +137,11 @@ Open an app from a script with `computer.apps.open("mousepad")`, by its id, its
137
137
  the app's window shows in front, and the app stays open. `computer.apps.list()` names the apps the desktop has (the
138
138
  text editor, the terminal, Firefox). App ids come from `apps.list`: call it before `apps.open`. With the tools, name the app: `computer_observe` or `computer_act` with
139
139
  `app: "org.xfce.mousepad"` opens it, or brings it in front, first. A screenshot with no app in front lists the ids. `computer.shell.run` ends everything its command started when it returns, so an
140
- app it starts closes at once; `computer.processes.start` keeps a program that is not one of the listed apps.
140
+ app it starts closes at once; `computer.processes.start` keeps a program that is not one of the listed apps. A Linux
141
+ desktop lists and opens no app whose desktop file its own user could change, such as one written with
142
+ `computer.files.write`: `apps.open` of one is refused, naming the file. `computer.apps.open(id, { url })` opens a URL
143
+ with a scheme or an absolute path in the app (on Linux nothing else, and never a url starting with `-`); the path may
144
+ be a file you wrote, where write is granted, and the app can then do what a shell or the file ops do.
141
145
 
142
146
  ## Habits that work
143
147
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-serve",
3
- "version": "0.1.0-beta.62",
3
+ "version": "0.1.0-beta.63",
4
4
  "description": "The AgentRun server: the /v2 API and console over one store, with runners that run your agents; the deployable process of the AgentRun platform.",
5
5
  "keywords": [
6
6
  "agentrun",
@@ -70,17 +70,17 @@
70
70
  "@opentelemetry/exporter-trace-otlp-http": "0.301.2",
71
71
  "@opentelemetry/resources": "3.1.1",
72
72
  "@opentelemetry/sdk-trace": "3.1.1",
73
- "@parcha/agentrun-computer": "0.1.0-beta.62",
74
- "@parcha/agentrun-decisions": "0.1.0-beta.62",
75
- "@parcha/agentrun-dsl": "0.1.0-beta.62",
76
- "@parcha/agentrun-harness-acp": "0.1.0-beta.62",
77
- "@parcha/agentrun-harness-claude": "0.1.0-beta.62",
78
- "@parcha/agentrun-harness-codex": "0.1.0-beta.62",
79
- "@parcha/agentrun-import": "0.1.0-beta.62",
80
- "@parcha/agentrun-jev": "0.1.0-beta.62",
81
- "@parcha/agentrun-kernel": "0.1.0-beta.62",
82
- "@parcha/agentrun-web": "0.1.0-beta.62",
83
- "@parcha/pi-browser": "0.1.0-beta.62",
73
+ "@parcha/agentrun-computer": "0.1.0-beta.63",
74
+ "@parcha/agentrun-decisions": "0.1.0-beta.63",
75
+ "@parcha/agentrun-dsl": "0.1.0-beta.63",
76
+ "@parcha/agentrun-harness-acp": "0.1.0-beta.63",
77
+ "@parcha/agentrun-harness-claude": "0.1.0-beta.63",
78
+ "@parcha/agentrun-harness-codex": "0.1.0-beta.63",
79
+ "@parcha/agentrun-import": "0.1.0-beta.63",
80
+ "@parcha/agentrun-jev": "0.1.0-beta.63",
81
+ "@parcha/agentrun-kernel": "0.1.0-beta.63",
82
+ "@parcha/agentrun-web": "0.1.0-beta.63",
83
+ "@parcha/pi-browser": "0.1.0-beta.63",
84
84
  "@secretlint/core": "14.1.0",
85
85
  "@secretlint/profiler": "14.1.0",
86
86
  "croner": "11.0.0",
@@ -11,7 +11,13 @@ tags: [kyb, due-diligence, sanctions]
11
11
  harness: [pi]
12
12
  model: { tier: balanced }
13
13
  effort: medium
14
- tools: [read, web_search, web_fetch, ask_person]
14
+ # A computer with a shell first, else none. With a shell, web_save puts each sanctions list's file in the run's work
15
+ # folder (the server downloads it; the computer reaches no list owner) and bash greps it there, read-only
16
+ # (bash-read-only.ts): the agent reads the rows that match, never a whole list. With none, there is no bash and
17
+ # SANCTIONS.md screens through the list owners' indexes and records instead.
18
+ computer: [shell, none]
19
+ tools: [read, web_search, web_fetch, web_save, bash, ask_person]
20
+ tool_policy: { bash: read-only }
15
21
  parameters:
16
22
  risk_appetite: { type: string, required: false, default: medium, enum: [low, medium, high], description: "low, medium or high: how much risk you accept, which sets how each red flag is graded and which verdict it leads to. Use medium (the default) unless your policy says otherwise; low is for regulated onboarding, high for low-exposure vendors." }
17
23
  jurisdictions_of_interest: { type: string, required: false, pattern: "^$|^[A-Za-z]{2}(\\s*,\\s*[A-Za-z]{2})*$", description: "Optional. Countries that matter to you, as ISO 3166-1 alpha-2 codes separated by commas (e.g. US,GB,AE). Every tie the company has to one (incorporation, address, owner, officer, operations) is reported. Empty: none." }
@@ -0,0 +1,10 @@
1
+ # Applied with these parameters (POST /v2/templates/kyb/apply). Pass: 3 of 3 runs.
2
+ # fixtures/web.json serves the list owners' own files as web_save fetches them, each under the type its owner sends
3
+ # (OFAC text/csv, UN application/xml, EU text/plain, UK application/octet-stream): real rows from the files of
4
+ # 2026-11-20 (OFAC, EU), 2026-11-24 (UK) and 2026-11-25 (UN), each cut to a few leading rows and every row of
5
+ # PETROPARS UK and AL RASHID TRUST (the UK's 847 AL RASHID TRUST rows to one per name). Searches find nothing and pages
6
+ # answer 404, so the lists' own files are the only sources: the case measures the screening, not the registry work.
7
+ parameters:
8
+ risk_appetite: medium
9
+ jurisdictions_of_interest: ""
10
+ web: fixtures/web.json