@parcha/agentrun-serve 0.1.0-beta.41 → 0.1.0-beta.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- package/NOTICE +2 -0
- package/README.md +77 -12
- package/dist/agent-rows.d.ts +1 -1
- package/dist/agents-store.js +3 -1
- package/dist/calendar/address.d.ts +49 -0
- package/dist/calendar/address.js +153 -0
- package/dist/calendar/fetch.d.ts +24 -0
- package/dist/calendar/fetch.js +146 -0
- package/dist/calendar/ics-faux.d.ts +39 -0
- package/dist/calendar/ics-faux.js +236 -0
- package/dist/calendar/labels.d.ts +3 -0
- package/dist/calendar/labels.js +61 -0
- package/dist/calendar/names.d.ts +52 -0
- package/dist/calendar/names.js +54 -0
- package/dist/calendar/parse.d.ts +108 -0
- package/dist/calendar/parse.js +625 -0
- package/dist/calendar/routes.d.ts +17 -0
- package/dist/calendar/routes.js +81 -0
- package/dist/calendar/tools.d.ts +23 -0
- package/dist/calendar/tools.js +124 -0
- package/dist/cli.js +3 -1
- package/dist/computer-record.d.ts +55 -0
- package/dist/computer-record.js +315 -0
- package/dist/computer-setting.d.ts +1 -0
- package/dist/computer-setting.js +15 -2
- package/dist/computers.js +2 -14
- package/dist/console/assets/index-DYJ_wj27.js +711 -0
- package/dist/console/index.html +1 -1
- package/dist/eval-feed.d.ts +2 -2
- package/dist/eval-feed.js +9 -5
- package/dist/feed/parse.d.ts +3 -2
- package/dist/feed/parse.js +9 -18
- package/dist/feed/pointer.d.ts +2 -0
- package/dist/feed/pointer.js +17 -0
- package/dist/file-types.js +1 -0
- package/dist/host-command.d.ts +3 -0
- package/dist/host-command.js +18 -0
- package/dist/host.d.ts +3 -0
- package/dist/host.js +3 -0
- package/dist/learn/check.d.ts +14 -0
- package/dist/learn/check.js +194 -14
- package/dist/learn/compile.d.ts +48 -27
- package/dist/learn/compile.js +134 -101
- package/dist/learn/promote.d.ts +61 -5
- package/dist/learn/promote.js +12 -2
- package/dist/learning-setting.d.ts +23 -0
- package/dist/learning-setting.js +51 -0
- package/dist/learning-words.d.ts +3 -0
- package/dist/learning-words.js +3 -0
- package/dist/learning.d.ts +3 -2
- package/dist/learning.js +5 -3
- package/dist/mcp-oauth.d.ts +8 -0
- package/dist/mcp-oauth.js +7 -0
- package/dist/mcp-private-hosts.d.ts +13 -0
- package/dist/mcp-private-hosts.js +16 -0
- package/dist/openapi.d.ts +1 -0
- package/dist/openapi.js +105 -9
- package/dist/run-files.d.ts +6 -2
- package/dist/run-files.js +29 -7
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/run-reads-over-store.d.ts +5 -1
- package/dist/run-reads-over-store.js +8 -4
- package/dist/run-recordings.d.ts +20 -0
- package/dist/run-recordings.js +133 -0
- package/dist/runner/adapter-loop.d.ts +1 -1
- package/dist/runner/adapter-loop.js +3 -6
- package/dist/runner/adapter-run-spec.d.ts +16 -1
- package/dist/runner/adapter-run-spec.js +20 -6
- package/dist/runner/beside.js +1 -1
- package/dist/runner/cli-run-spec.js +10 -7
- package/dist/runner/feedback-round.d.ts +9 -25
- package/dist/runner/feedback-round.js +22 -40
- package/dist/runner/learning-end.d.ts +17 -7
- package/dist/runner/learning-end.js +79 -53
- package/dist/runner/main.d.ts +11 -0
- package/dist/runner/main.js +29 -2
- package/dist/runner/mcp-run.d.ts +2 -2
- package/dist/runner/promotion.d.ts +36 -4
- package/dist/runner/promotion.js +280 -20
- package/dist/runner/reflect-hook.d.ts +5 -0
- package/dist/runner/reflect-hook.js +22 -14
- package/dist/runner/store-secrets.js +3 -1
- package/dist/runner/workflow-first.d.ts +0 -6
- package/dist/runner/workflow-first.js +7 -13
- package/dist/runs-over-store.d.ts +1 -1
- package/dist/sdk/runs.js +2 -1
- package/dist/secrets.js +2 -2
- package/dist/server.d.ts +4 -3
- package/dist/server.js +72 -11
- package/dist/store/agent-body.d.ts +5 -3
- package/dist/store/agent-body.js +14 -10
- package/dist/store-reads/learning.d.ts +1 -1
- package/dist/store-reads/loop.d.ts +1 -0
- package/dist/store-reads/loop.js +14 -4
- package/dist/store-view.d.ts +5 -0
- package/dist/store-view.js +4 -0
- package/dist/template-eval.d.ts +7 -0
- package/dist/template-eval.js +54 -6
- package/dist/templates.d.ts +3 -1
- package/dist/templates.js +14 -1
- package/dist/timeline/computer.js +2 -1
- package/dist/tool-list.js +1 -0
- package/dist/tools.d.ts +7 -0
- package/dist/tools.js +11 -0
- package/dist/trigger-feed.js +67 -18
- package/dist/validate.js +7 -2
- package/dist/workspace/computer-for-claim.d.ts +7 -0
- package/dist/workspace/computer-for-claim.js +12 -2
- package/dist/workspace/paths.d.ts +4 -0
- package/dist/workspace/paths.js +9 -0
- package/dist/workspace/resolve-computer.d.ts +3 -1
- package/launcher/agentrun-serve +31 -24
- package/package.json +10 -9
- package/templates/README.md +11 -2
- package/dist/console/assets/index-COGhx_2Z.js +0 -711
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
// - whether it looks back (learning-run.ts reflectSkip): its cap and its spend so far, read as its view reads them;
|
|
6
6
|
// - its prompt's facts: how many notes its seed held (launch seedNotes);
|
|
7
7
|
// - the compile turn's facts (compileAskOf, learn/compile.ts): whether the job is due to be compiled (its notes, its
|
|
8
|
-
// completed runs, no learned workflow yet), or a workflow
|
|
9
|
-
//
|
|
10
|
-
//
|
|
8
|
+
// completed runs, no learned workflow yet), or a workflow its promotion holds wants a revision (once per hold); its
|
|
9
|
+
// notes whole, its last runs' traces, the tools a workflow may name (draftTools) and the DSL's own language for
|
|
10
|
+
// writing one;
|
|
11
|
+
// - whether it looks back at all (ownerSaid): a run of a job that compiles workflows is asked its look-back only when
|
|
12
|
+
// its owner gave feedback (a grade's words, or a message after its first); its compile turn, when due, is asked alone;
|
|
11
13
|
// - what the person said in the run and a trigger's input (heard.ts Hearing over its entries, the end-of-run turn's
|
|
12
14
|
// own left out), as learning-run.ts turnOf reads them;
|
|
13
15
|
// - whether the job gave nothing new to look back on (onlyLearnedWorkflows over its timeline): a run whose only tool
|
|
@@ -29,7 +31,8 @@ import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
|
29
31
|
import { isMessageRow } from "../timeline/index.js";
|
|
30
32
|
import { Hearing } from "../heard.js";
|
|
31
33
|
import { readLearning, readSnapshot } from "../learn/folder.js";
|
|
32
|
-
import { compileDue, compilePrompt, compileReference,
|
|
34
|
+
import { completedRun, lastOwnRuns, compileDue, compilePrompt, compileReference, COMPILE_QUIET_RUNS, COMPILE_TRACES, heldNamesOf } from "../learn/compile.js";
|
|
35
|
+
import { loopOf } from "../learning-setting.js";
|
|
33
36
|
import { promotionOf, promotionsOf, scoreOf } from "../learn/promote.js";
|
|
34
37
|
import { draftDecisionProviders } from "../learn/skills.js";
|
|
35
38
|
import { DECISION_PROVIDER_KEYS } from "../tool-plane.js";
|
|
@@ -48,7 +51,7 @@ import { readApprovers } from "../server-approvers.js";
|
|
|
48
51
|
import { runEntries, runReflect, runTimeline, withFeedback, withoutFeedbackRounds } from "../store-reads/journal.js";
|
|
49
52
|
import { capNowOf } from "./journal-kinds.js";
|
|
50
53
|
import { bookedCapSpend, bookedSpend } from "./metrics.js";
|
|
51
|
-
import { fits,
|
|
54
|
+
import { fits, workflowDigest } from "./workflow-first.js";
|
|
52
55
|
import { pendingFeedbackOf } from "./feedback-round.js";
|
|
53
56
|
import { createReflectHook } from "./reflect-hook.js";
|
|
54
57
|
import { sdkDraftTools } from "../sdk/workflows.js";
|
|
@@ -99,8 +102,15 @@ export function learningEndOfRun(launch, deps) {
|
|
|
99
102
|
// new"), whatever the job did: said here, never left to the words' row counting as a message of the job's.
|
|
100
103
|
nothingNew: async (runId) => !pendingFeedbackOf(await runEntries(deps.store, runId, BACKGROUND_CONTEXT)) && onlyLearnedWorkflows(await runTimeline(deps.store, runId, BACKGROUND_CONTEXT, { settled: false })),
|
|
101
104
|
promptFacts: async () => ({ active: start.seedNotes ?? start.given.length }),
|
|
102
|
-
// A notes run (`learning: "notes"`) compiles nothing.
|
|
103
|
-
|
|
105
|
+
// A notes run (`learning: "notes"`) compiles nothing, and looks back on every run. A run of a job that compiles
|
|
106
|
+
// workflows looks back only on its owner's feedback (ownerSaid).
|
|
107
|
+
...(start.notesOnly ? {} : {
|
|
108
|
+
compileFacts: (input) => compileAskOf(deps, { ...input, input: launch.input, seedWorkflows: start.workflows?.length ?? 0 }),
|
|
109
|
+
ownerSaid: async (runId) => {
|
|
110
|
+
const [entries, rows] = await Promise.all([runEntries(deps.store, runId, BACKGROUND_CONTEXT), runTimeline(deps.store, runId, BACKGROUND_CONTEXT, { settled: false })]);
|
|
111
|
+
return ownerSaid(entries, rows);
|
|
112
|
+
},
|
|
113
|
+
}),
|
|
104
114
|
asked: async (runId) => {
|
|
105
115
|
const [entries, reflect] = await Promise.all([runEntries(deps.store, runId, BACKGROUND_CONTEXT), runReflect(deps.store, runId, BACKGROUND_CONTEXT)]);
|
|
106
116
|
const hearing = new Hearing();
|
|
@@ -244,6 +254,17 @@ export function onlyLearnedWorkflows(rows) {
|
|
|
244
254
|
const answered = new Set(results.filter(models).map((row) => row.tool_use_id));
|
|
245
255
|
return calls.every((row) => answered.has(row.tool_use_id));
|
|
246
256
|
}
|
|
257
|
+
/** Whether a run carries its owner's feedback, the only thing a run of a job that compiles workflows is looked back on
|
|
258
|
+
* for: a grade's words its end closes (a feedback round, feedback-round.ts pendingFeedbackOf over its root `entries`),
|
|
259
|
+
* or a person's message after its first in its timeline `rows` (a follow-up, or a word while it ran: traceFrom's
|
|
260
|
+
* feedback), the end-of-run turn's own, a grade's round's and a subagent's (a child conversation's rows carry its
|
|
261
|
+
* spawning call, parent_tool_use_id: its task prompt is the job's, not the owner's) rows left out. */
|
|
262
|
+
export function ownerSaid(entries, rows) {
|
|
263
|
+
if (pendingFeedbackOf(entries))
|
|
264
|
+
return true;
|
|
265
|
+
const messages = withoutFeedbackRounds(rows).filter((row) => row.agent_label !== LEARNING_LABEL && !row.parent_tool_use_id && isMessageRow(row));
|
|
266
|
+
return messages.slice(1).some((row) => row.kind === "user_message");
|
|
267
|
+
}
|
|
247
268
|
/** The path a run took (learning-cost.ts RunPath), by its timeline `rows` as runTimeline labels them (its end-of-run
|
|
248
269
|
* turn's rows, LEARNING_LABEL, are the learning's and left out): `workflow` when its job did only what
|
|
249
270
|
* onlyLearnedWorkflows asks of a run with nothing new to look back on, `handed_back` when it called a learned workflow
|
|
@@ -336,8 +357,17 @@ async function describedOf(tools, store) {
|
|
|
336
357
|
}
|
|
337
358
|
/** The most of an agent's kept learning, newest first, read for a held workflow's ask since its hold (compileAskOf). */
|
|
338
359
|
const HELD_ASKED_READ = 200;
|
|
339
|
-
/**
|
|
340
|
-
|
|
360
|
+
/** The loop's numbers (learning-setting.ts loopOf) of the revision run `runId` runs: its definition's `learning`. */
|
|
361
|
+
async function loopOfRun(store, runId) {
|
|
362
|
+
try {
|
|
363
|
+
const run = await store.runs.get(runId);
|
|
364
|
+
const revision = run ? await store.agents.revision(run.revisionId) : undefined;
|
|
365
|
+
return loopOf(revision?.body?.learning);
|
|
366
|
+
}
|
|
367
|
+
catch {
|
|
368
|
+
return loopOf(undefined);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
341
371
|
/** The most tool calls of one run a trace keeps, and the most of a call's input or a message it holds, in characters. */
|
|
342
372
|
const TRACE_CALLS = 20;
|
|
343
373
|
const TRACE_TEXT = 600;
|
|
@@ -363,36 +393,38 @@ export function traceFrom(timeline, refuse) {
|
|
|
363
393
|
return { input: first ? cut(first.text ?? first.summary) : "", calls, answer: cut(answer), feedback: messages.slice(1).filter((row) => row.kind === "user_message").map((row) => cut(row.text ?? row.summary)) };
|
|
364
394
|
}
|
|
365
395
|
/** The compile turn's facts for run `runId` of agent `agentId` (learn/compile.ts): a revision of the learned workflow
|
|
366
|
-
* that
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
* agent
|
|
370
|
-
*
|
|
371
|
-
* of its last COMPILE_QUIET_RUNS runs compiled, and it
|
|
396
|
+
* that fits the run's input and whose promotion holds it at main's digest (runner/promotion.ts: its replay on the
|
|
397
|
+
* agent's graded inputs, or its graded served runs, fell under the bar; its champion served the run, or the agent did by
|
|
398
|
+
* hand), its text as main holds it, with the hold's numbers, once per hold (none when any run since the hold compiled
|
|
399
|
+
* it, read from the agent's kept learning; a check's hold with the inputs it disagreed on, a stopped check's none);
|
|
400
|
+
* else, when the job is due (compileDue: the run completed, the agent has no learned workflow active or waiting, none
|
|
401
|
+
* of its last COMPILE_QUIET_RUNS runs compiled, and it has its definition's compile_after completed agent runs), a new
|
|
402
|
+
* one. Nothing else asks one: a hand-back, a wrong grade of a served answer and the money rule's
|
|
403
|
+
* stop are single runs, which the hold reads among many. Either way the
|
|
372
404
|
* agent's active notes whole, the traces of its last COMPILE_TRACES completed runs before this one, the tools a call node
|
|
373
405
|
* may run (draftTools) with what each takes and gives, its decision providers, the run's input (`input`, its fields for
|
|
374
406
|
* the workflow's input schema), the agent's output schema when it has one (its final output's shape) and the DSL's
|
|
375
407
|
* language with this host's addendum. Undefined when it compiles nothing, or
|
|
376
408
|
* when the folder can't be read. */
|
|
377
409
|
export async function compileAskOf(deps, input) {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
// A wrong grade of the answer its workflow gave alone (a `revise` feedback round this end closes): that workflow.
|
|
382
|
-
const fed = pendingFeedbackOf(entries);
|
|
383
|
-
const gradedOf = fed?.round === "revise" && fed.workflow ? fed.workflow : undefined;
|
|
384
|
-
let revising = served?.outcome === "handed_back" ? served.workflow : (stopped?.workflow ?? gradedOf);
|
|
410
|
+
// A revision is asked only of a workflow its promotion holds, once per hold. One run is one sample: a hand-back, a wrong
|
|
411
|
+
// grade of a served answer or the money rule's stop asks for none (with a 10-15% base error rate on both sides, one
|
|
412
|
+
// wrong answer says nothing about the workflow); the hold, read over many runs, does.
|
|
385
413
|
// The workflows whose newest revision other than their champion (learn/promote.ts championOf: it serves while that one
|
|
386
414
|
// is held) is held: the run's own may be one (its champion served it, or it went by hand).
|
|
387
|
-
const records =
|
|
415
|
+
const records = await promotionsOf(deps.store.settings, input.agentId).catch(() => []);
|
|
388
416
|
const heldNames = heldNamesOf(records);
|
|
417
|
+
// The loop's numbers on the agent's definition (the revision this run runs): the first compile waits for compile_after
|
|
418
|
+
// completed agent runs, the ending one counted.
|
|
419
|
+
const { compile_after: compileAfter } = await loopOfRun(deps.store, input.runId);
|
|
389
420
|
// The agent's latest runs, newest first: those after the ending one in the list started before it.
|
|
390
|
-
const listed = await deps.store.runs.list({ agentId: input.agentId, limit: 200 });
|
|
421
|
+
const listed = await deps.store.runs.list({ agentId: input.agentId, limit: Math.max(200, 2 * compileAfter + COMPILE_QUIET_RUNS) });
|
|
391
422
|
const at = listed.findIndex((run) => run.id === input.runId);
|
|
392
423
|
const earlier = (at < 0 ? listed : listed.slice(at + 1)).filter((run) => run.agentId === input.agentId);
|
|
393
424
|
const done = earlier.filter(completedRun);
|
|
425
|
+
const byHand = (await lastOwnRuns(deps.store, input.agentId, compileAfter, input.runId)).length;
|
|
394
426
|
let compiledLately = false;
|
|
395
|
-
const dueWith = (
|
|
427
|
+
const dueWith = (workflows) => compileDue({ completed: input.outcome === "completed", runs: byHand + (input.outcome === "completed" ? 1 : 0), workflows, compiledLately, compileAfter });
|
|
396
428
|
const compiledOf = (kept) => kept?.proposal?.compiled;
|
|
397
429
|
// Every learning round a run kept: its newest, and each before it (a follow-up opened the run again after it).
|
|
398
430
|
const roundsOf = async (runId) => {
|
|
@@ -401,16 +433,14 @@ export async function compileAskOf(deps, input) {
|
|
|
401
433
|
return [];
|
|
402
434
|
return [newest, ...(await Promise.all(Array.from({ length: Math.max(0, newest.round - 1) }, (_, i) => deps.store.learning.proposal(runId, i + 1).catch(() => undefined))))];
|
|
403
435
|
};
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
return undefined;
|
|
413
|
-
}
|
|
436
|
+
// A compile in any learning round of the agent's last runs (a draft still waiting for its grade, or one that failed)
|
|
437
|
+
// asks no new one now: a follow-up's round keeps no compile of its own, so a run's earlier rounds are read too.
|
|
438
|
+
const lately = (await Promise.all(earlier.slice(0, COMPILE_QUIET_RUNS).map((run) => roundsOf(run.id)))).flat();
|
|
439
|
+
compiledLately = lately.some((kept) => compiledOf(kept) !== undefined);
|
|
440
|
+
// First by what the run started from (its seed's notes and the workflows it was offered): a run not due by them
|
|
441
|
+
// opens no folder, unless one of its workflows is held. Main is read below for the turn itself, and decides again.
|
|
442
|
+
if (!heldNames.size && !dueWith(input.seedWorkflows ?? 0))
|
|
443
|
+
return undefined;
|
|
414
444
|
const dsl = await import("@parcha/agentrun-dsl");
|
|
415
445
|
// Every text the turn is told passes the check a run's start makes (learning.ts holdsSecret, as chooseWorkflows reads a
|
|
416
446
|
// learned workflow) over what the run must never learn (`refuse`): one that holds a secret is left out whole, never sent
|
|
@@ -432,13 +462,13 @@ export async function compileAskOf(deps, input) {
|
|
|
432
462
|
leftOut.workflows.add(shown.name(name));
|
|
433
463
|
return undefined;
|
|
434
464
|
};
|
|
435
|
-
let current
|
|
465
|
+
let current;
|
|
436
466
|
let held;
|
|
437
|
-
if (
|
|
467
|
+
if (heldNames.size) {
|
|
438
468
|
// The one active workflow that fits the run's input (the one workflow-first would serve), held at main's digest.
|
|
439
469
|
const active = [];
|
|
440
470
|
for (const one of workflows)
|
|
441
|
-
if (one.status === "active") {
|
|
471
|
+
if (one.status === "active" && heldNames.has(one.name)) {
|
|
442
472
|
const text = await textOf(one.name);
|
|
443
473
|
if (text !== undefined)
|
|
444
474
|
active.push({ name: one.name, workflow: text });
|
|
@@ -449,7 +479,7 @@ export async function compileAskOf(deps, input) {
|
|
|
449
479
|
[held, current] = [record, fitting[0].workflow];
|
|
450
480
|
}
|
|
451
481
|
// An agent with a learned workflow compiles nothing new: its notes' text is not read.
|
|
452
|
-
if (!
|
|
482
|
+
if (!held && workflows.length)
|
|
453
483
|
return { notes: [], workflows: workflows.length };
|
|
454
484
|
const notes = [];
|
|
455
485
|
for (const note of snapshot?.notes ?? []) {
|
|
@@ -476,9 +506,6 @@ export async function compileAskOf(deps, input) {
|
|
|
476
506
|
if (parts.length)
|
|
477
507
|
deps.log?.(`learning: run ${input.runId}: the compile turn left out what holds a secret: ${parts.join(", ")}`);
|
|
478
508
|
};
|
|
479
|
-
// A revision of a workflow main no longer holds (a person retired it), or whose text holds a secret, asks for none.
|
|
480
|
-
if (revising && read.current === undefined)
|
|
481
|
-
return sayLeftOut(), undefined;
|
|
482
509
|
let held;
|
|
483
510
|
if (read.held) {
|
|
484
511
|
// Once per hold: a run since it that compiled this workflow asked already, whatever came of it (its revision is on its
|
|
@@ -488,11 +515,13 @@ export async function compileAskOf(deps, input) {
|
|
|
488
515
|
const kept = await deps.store.learning.proposals(input.agentId, { limit: HELD_ASKED_READ }).catch(() => undefined);
|
|
489
516
|
if (!kept || kept.some((one) => !(one.createdAt < since) && compiledOf(one)?.workflow === read.held.workflow))
|
|
490
517
|
return sayLeftOut(), undefined;
|
|
491
|
-
const { workflow, digest, source, reason, replay } = read.held;
|
|
492
|
-
|
|
493
|
-
|
|
518
|
+
const { workflow, digest, source, reason, replay, check } = read.held;
|
|
519
|
+
// A check's disagreements are the agent's own inputs and answers: cut of the run's secrets as a trace is (traceFrom).
|
|
520
|
+
const cut = (text) => redactSecrets(text, input.refuse, Number.POSITIVE_INFINITY);
|
|
521
|
+
const checked = check ? { ...check, ...(check.disagreements ? { disagreements: check.disagreements.map((one) => ({ ...one, input: cut(one.input), agent: one.agent === null ? null : cut(one.agent), ...(one.draft !== undefined ? { draft: cut(one.draft) } : {}), ...(one.escalated !== undefined ? { escalated: cut(one.escalated) } : {}) })) } : {}) } : undefined;
|
|
522
|
+
held = { workflow, digest, source, reason, ...(replay ? { replay: scoreOf(replay) } : {}), ...(checked ? { check: checked } : {}) };
|
|
494
523
|
}
|
|
495
|
-
if (!
|
|
524
|
+
if (!held && !dueWith(read.workflows))
|
|
496
525
|
return sayLeftOut(), undefined;
|
|
497
526
|
// An earlier run's trace is cut of each value it held (traceFrom); one that still holds a secret (a value in a call's
|
|
498
527
|
// input spelled in JSON escapes, a shape the cut does not take) is left out whole.
|
|
@@ -507,19 +536,16 @@ export async function compileAskOf(deps, input) {
|
|
|
507
536
|
const { tools, decisions, outputSchema, workflowAdapters, described: sdkCatalog } = await draftTools(deps, input.runId);
|
|
508
537
|
const allowed = draftDecisionProviders(decisions);
|
|
509
538
|
const judges = workflowAdapters !== undefined ? workflowAdapters.includes("runJudge") : allowed.length > 0;
|
|
510
|
-
// Jev by default: a
|
|
511
|
-
|
|
539
|
+
// No Jev by default: a draft's steps are asked for no Jev guard, whether or not the run can call Jev (per-step Jev guards
|
|
540
|
+
// gave no judgment that moved a served answer; a check in code does that job).
|
|
512
541
|
const described = sdkCatalog ?? await describedOf(tools, deps.store);
|
|
513
542
|
const object = input.input !== null && typeof input.input === "object" && !Array.isArray(input.input);
|
|
514
543
|
leftOut.input = object && holds(input.input);
|
|
515
544
|
const fields = object && !leftOut.input ? { input: input.input } : {};
|
|
516
545
|
const bridge = workflowAdapters !== undefined ? { workflowAdapters } : {};
|
|
517
|
-
const base = { ...bridge, reference: compileReference(dsl, { tools, judges,
|
|
518
|
-
// A wrong grade of the answer its workflow gave alone: that answer and the grade's words, cut of the runner's secrets.
|
|
519
|
-
const cut = (text) => redactSecrets(text, input.refuse, Number.POSITIVE_INFINITY);
|
|
520
|
-
const graded = revising && gradedOf && fed ? { answer: cut(servedAnswerOf(entries)?.answer ?? ""), words: cut(fed.text) } : undefined;
|
|
546
|
+
const base = { ...bridge, reference: compileReference(dsl, { tools, judges, ...bridge }), notes: read.notes, traces, tools, described, judges, ...fields, ...(outputSchema !== undefined ? { outputSchema } : {}) };
|
|
521
547
|
// A revision is of main's text as read here, whatever the run started from: that commit is its conflict base (`base`).
|
|
522
|
-
const ask = !
|
|
548
|
+
const ask = !held ? { mode: "new", ...base } : { mode: "revise", workflow: held.workflow, current: read.current, ...(read.main ? { base: read.main } : {}), held, ...base };
|
|
523
549
|
sayLeftOut();
|
|
524
550
|
// Last, the prompt itself, whatever it is told now or later (a tool's description, the agent's output schema): one that
|
|
525
551
|
// still holds a secret asks nothing.
|
package/dist/runner/main.d.ts
CHANGED
|
@@ -84,6 +84,17 @@ export declare function besideRunEnv(env: NodeJS.ProcessEnv, switches: NodeJS.Pr
|
|
|
84
84
|
* journal, the seal key and the model route. `booted`: the seal key startRunnerProcess booted against the store (else
|
|
85
85
|
* this process's, as it was handed or booted). Refused in words with no seal key. */
|
|
86
86
|
export declare function runnerLoop(store: Store, dataDir: string, env?: NodeJS.ProcessEnv, booted?: Buffer): RunnerParts;
|
|
87
|
+
/** What a runner in its own process may reach on loopback, from its own environment alone, as a server takes its opt-in
|
|
88
|
+
* (cli.ts mcpLoopback): with AGENTRUN_MCP_ALLOW_LOOPBACK=1, an MCP server on this machine's loopback (the machine this
|
|
89
|
+
* process runs on, its container's in a container), never at `own`: the port a server listens on unless --port says
|
|
90
|
+
* otherwise (DEFAULT_PORT) and, when this environment names one on loopback, the port of its public address
|
|
91
|
+
* (AGENTRUN_PUBLIC_URL); runnerLoop adds, at each claim, the addresses the server kept in the store at its last start
|
|
92
|
+
* (serverOwn), so a run never reaches a server beside this runner through an MCP server's address, whatever its port.
|
|
93
|
+
* Undefined without it. The opt-in is never read from the store or the data directory: a runner never inherits
|
|
94
|
+
* another process's. */
|
|
95
|
+
export declare function runnerLoopback(env: NodeJS.ProcessEnv): {
|
|
96
|
+
readonly own: readonly string[];
|
|
97
|
+
} | undefined;
|
|
87
98
|
/** A runner's loop factory with the run's computers it composed and the runs' environment: what the janitor sweeps with. */
|
|
88
99
|
export type RunnerParts = {
|
|
89
100
|
readonly createLoop: LoopFactory;
|
package/dist/runner/main.js
CHANGED
|
@@ -20,7 +20,7 @@ import { hostCommandRefusals } from "../computers.js";
|
|
|
20
20
|
import { hostAddressesOnce } from "../docker-host-addresses.js";
|
|
21
21
|
import { claimInstallsStopped } from "../harness-install.js";
|
|
22
22
|
import { HARNESS_TABLE_ENV } from "../harness-table.js";
|
|
23
|
-
import { maxRunsOf } from "../host.js";
|
|
23
|
+
import { DEFAULT_PORT, maxRunsOf } from "../host.js";
|
|
24
24
|
import { FAUX_ENV, FAUX_PREFIX, withoutFaux } from "../model.js";
|
|
25
25
|
import { durationMs, runLine } from "../print.js";
|
|
26
26
|
import { bootSealKey } from "../seal-key.js";
|
|
@@ -29,7 +29,10 @@ import { migrationsIn, openStore, SchemaVersionUnknown, storePlace, storeTarget
|
|
|
29
29
|
import { SCHEMA_VERSION } from "../store/schema.js";
|
|
30
30
|
import { SEAL_KEY_ENV, sealKeyOf } from "../tool-keys.js";
|
|
31
31
|
import { claimViewOpener } from "../computer-live.js";
|
|
32
|
-
import { runnerLiveOf } from "../live-reach.js";
|
|
32
|
+
import { LOOPBACK as LIVE_LOOPBACK, runnerLiveOf } from "../live-reach.js";
|
|
33
|
+
import { LOOPBACK } from "../mcp-oauth.js";
|
|
34
|
+
import { serverOwn } from "../mcp-private-hosts.js";
|
|
35
|
+
import { MCP_ALLOW_LOOPBACK_ENV } from "../mcp-servers-store.js";
|
|
33
36
|
import { envValue } from "../key-meta.js";
|
|
34
37
|
import { fauxComputers } from "../faux-computers.js";
|
|
35
38
|
import { computerDepsFrom } from "../workspace/computer-deps.js";
|
|
@@ -126,15 +129,39 @@ export function runnerLoop(store, dataDir, env = process.env, booted) {
|
|
|
126
129
|
// mounts by where this process's Docker has the data directory (box-paths.ts), read once; a desktop's or a phone's live
|
|
127
130
|
// view opened with it.
|
|
128
131
|
const computers = runnerComputers(store, runs, sealKey, { dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs), hostWhy: hostCommandRefusals(PROVIDERS, process.env.PATH) });
|
|
132
|
+
const loopback = runnerLoopback(env);
|
|
133
|
+
if (loopback)
|
|
134
|
+
process.stderr.write(`agentrun-serve runner: ${MCP_ALLOW_LOOPBACK_ENV}=1: this runner's runs may reach an MCP server on this machine's loopback, never at ${loopback.own.join(" or ")} nor where its server listens\n`);
|
|
129
135
|
const deps = {
|
|
130
136
|
env: runs, data: dataDir, journal: (claim) => store.journal(claim), store, sealKey, routeOf,
|
|
131
137
|
computerForClaim: computers.computerForClaim, computerDeps: computers.computerDeps,
|
|
132
138
|
// A run's log lines (a learning run's skipped generality check, a sweep that failed) on the runner's stderr, as its
|
|
133
139
|
// warnings are.
|
|
134
140
|
log: (line) => void process.stderr.write(`agentrun-serve runner: ${line}\n`),
|
|
141
|
+
// An MCP server on loopback: reached only when this process's own operator set AGENTRUN_MCP_ALLOW_LOOPBACK=1
|
|
142
|
+
// (runnerLoopback), never at a server's own port on it.
|
|
143
|
+
// The server's own addresses, as it kept them in the store at its last start, are read at each claim beside these.
|
|
144
|
+
...(loopback ? { mcpLoopback: true, mcpOwn: loopback.own, mcpOwnOf: () => serverOwn(store) } : {}),
|
|
135
145
|
};
|
|
136
146
|
return { createLoop: createDispatchLoop({ launchOf: (runId) => store.runs.launch(runId), resolve: resolveRunnerLoop(deps) }), computers: computers.computerDeps, env: runs };
|
|
137
147
|
}
|
|
148
|
+
/** What a runner in its own process may reach on loopback, from its own environment alone, as a server takes its opt-in
|
|
149
|
+
* (cli.ts mcpLoopback): with AGENTRUN_MCP_ALLOW_LOOPBACK=1, an MCP server on this machine's loopback (the machine this
|
|
150
|
+
* process runs on, its container's in a container), never at `own`: the port a server listens on unless --port says
|
|
151
|
+
* otherwise (DEFAULT_PORT) and, when this environment names one on loopback, the port of its public address
|
|
152
|
+
* (AGENTRUN_PUBLIC_URL); runnerLoop adds, at each claim, the addresses the server kept in the store at its last start
|
|
153
|
+
* (serverOwn), so a run never reaches a server beside this runner through an MCP server's address, whatever its port.
|
|
154
|
+
* Undefined without it. The opt-in is never read from the store or the data directory: a runner never inherits
|
|
155
|
+
* another process's. */
|
|
156
|
+
export function runnerLoopback(env) {
|
|
157
|
+
if (env[MCP_ALLOW_LOOPBACK_ENV] !== "1")
|
|
158
|
+
return undefined;
|
|
159
|
+
const own = [`http://${LIVE_LOOPBACK}:${DEFAULT_PORT}`];
|
|
160
|
+
const pub = URL.parse(env.AGENTRUN_PUBLIC_URL ?? "");
|
|
161
|
+
if (pub && LOOPBACK.test(pub.hostname))
|
|
162
|
+
own.push(pub.origin);
|
|
163
|
+
return { own };
|
|
164
|
+
}
|
|
138
165
|
/** Where runner `name` writes its heartbeat in `dataDir`. */
|
|
139
166
|
export const heartbeatFile = (dataDir, name) => join(dataDir, `runner-${name.replace(/[^A-Za-z0-9._:-]/g, "_")}.alive`);
|
|
140
167
|
/** The runner's heartbeat writer: its file's time set to now, at most every half renew interval. */
|
package/dist/runner/mcp-run.d.ts
CHANGED
|
@@ -35,8 +35,8 @@ export interface McpForClaimOptions {
|
|
|
35
35
|
/** A test's fake GitHub MCP origin, handed to the claim step (mcpClaim's githubMcpOrigin): for tests only: no environment variable, flag or setting maps onto it; absent, GitHub's hosted MCP
|
|
36
36
|
* (github.ts GITHUB_MCP_ORIGIN). */
|
|
37
37
|
readonly githubMcpOrigin?: string;
|
|
38
|
-
/** Whether this runner may reach an MCP server whose URL is on loopback (AdapterSpecDeps.mcpLoopback):
|
|
39
|
-
* beside a local-install server
|
|
38
|
+
/** Whether this runner may reach an MCP server whose URL is on loopback (AdapterSpecDeps.mcpLoopback): the runner
|
|
39
|
+
* beside a local-install server, or a runner in its own process whose own environment opts in. Absent, never. */
|
|
40
40
|
readonly loopback?: boolean;
|
|
41
41
|
/** The own addresses of the local-install server beside this runner (AdapterSpecDeps.mcpOwn, Serve.own): a loopback
|
|
42
42
|
* URL on one of their ports is refused, as the server refuses it, so a run never reaches that server through an MCP
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { Context } from "@earendil-works/chord/context";
|
|
2
2
|
import type { LearnedWorkflow } from "../learning.js";
|
|
3
|
+
import type { GuardRow } from "../learned-nodes.js";
|
|
3
4
|
import { type RunLaunch } from "../run-launch.js";
|
|
4
5
|
import { type Store } from "../store/store.js";
|
|
5
|
-
import { type ReplayCalls } from "../learn/replay-calls.js";
|
|
6
|
+
import { type ReplayCalls, type Skipped } from "../learn/replay-calls.js";
|
|
6
7
|
import { type Json } from "../validate.js";
|
|
7
|
-
import { type ReplayOutcomes, type ReplayScore } from "../learn/promote.js";
|
|
8
|
-
import { type FirstChoice, type Promoted } from "./workflow-first.js";
|
|
8
|
+
import { type CheckBar, type PromotionRecord, type ReplayOutcomes, type ReplayScore } from "../learn/promote.js";
|
|
9
|
+
import { type FirstChoice, type Promoted, type ReplayOutcome } from "./workflow-first.js";
|
|
9
10
|
import type { LearningFolder } from "../learn/folder.js";
|
|
10
11
|
import type { Shown } from "../learning.js";
|
|
11
12
|
/** A replay run still not ended this long after its replay started counts as failed (no evidence), and is cancelled once
|
|
@@ -49,6 +50,9 @@ export interface PromotionDeps {
|
|
|
49
50
|
* (startReplay). Absent: a replay run is handed none (a per_run server's calls are refused unsent, the input failed). */
|
|
50
51
|
readonly sealKey?: Buffer;
|
|
51
52
|
readonly now?: () => number;
|
|
53
|
+
/** The host's secrets as a reader cuts them (learning.ts secretsShown): a check's texts are cut of them whole, before
|
|
54
|
+
* they are shortened (decideCheck). */
|
|
55
|
+
readonly shown: () => Promise<Shown>;
|
|
52
56
|
}
|
|
53
57
|
/** The claim's promotion ports: `folder`, the agent's learning folder where the run's place keeps it, a refit's revision
|
|
54
58
|
* written on it as a merge from the claim's seed (a workflow.json changed on main since is a conflict, never written over),
|
|
@@ -56,7 +60,6 @@ export interface PromotionDeps {
|
|
|
56
60
|
* the workflow an earlier claim of this run served (`kept`, from its journal: none on a first claim). */
|
|
57
61
|
export declare function claimPromotion(deps: Omit<PromotionDeps, "commit" | "champion" | "kept"> & {
|
|
58
62
|
readonly folder: () => LearningFolder;
|
|
59
|
-
readonly shown: () => Promise<Shown>;
|
|
60
63
|
}): PromotionDeps;
|
|
61
64
|
/** A replay run's claim (launch.replay) of run `runId`, once its first choice is made: refused (ClaimRefused: the run ends
|
|
62
65
|
* failed, no agent turn, nothing sent) unless its revision's record still says replaying and names it among its runs (it
|
|
@@ -85,6 +88,35 @@ export declare function toolFlowsFor(deps: Pick<PromotionDeps, "store" | "agentI
|
|
|
85
88
|
* (championOf), the laid text when it is the champion, its own text read from its record's commit when not; undefined
|
|
86
89
|
* when none serves (the agent takes the run). A digest's own record never says it serves. */
|
|
87
90
|
export declare const promotionGate: (deps: PromotionDeps) => Promoted;
|
|
91
|
+
/** The words a stopped check's record starts with when it had nothing to check its draft on. */
|
|
92
|
+
export declare const NOTHING_TO_CHECK = "nothing to check it on";
|
|
93
|
+
/** One input a check ran its draft on: the agent's run (`of`) and its input, the agent's recorded answer, and what the
|
|
94
|
+
* draft did: its answer when it answered alone, why it handed the input back, or failed (or skipped a write). A
|
|
95
|
+
* reserved input whose replay run was never created, or never ended, by the check's deadline failed (`unstarted` for
|
|
96
|
+
* the first). */
|
|
97
|
+
type CheckRow = {
|
|
98
|
+
readonly of: string;
|
|
99
|
+
readonly input: string;
|
|
100
|
+
readonly agent: string | null;
|
|
101
|
+
readonly outcome: ReplayOutcome;
|
|
102
|
+
readonly answer: string | null;
|
|
103
|
+
readonly guards: readonly GuardRow[];
|
|
104
|
+
readonly escalated?: string;
|
|
105
|
+
readonly skipped?: Skipped;
|
|
106
|
+
readonly unstarted?: true;
|
|
107
|
+
};
|
|
108
|
+
/** Decides a check on its rows: each input it ran on (a skipped write is none) agreed when the draft answered it alone
|
|
109
|
+
* with the agent's recorded answer (learn/promote.ts sameAnswer), alone when it answered it with no escalate, no failed
|
|
110
|
+
* step, and no guard or recorded escalate that hands it back at the workflow's serving `thresholds` (handsBackAt). Promoted (source check) when it clears the bar (checkPasses); else held with the inputs it did not
|
|
111
|
+
* agree on, which the agent's next run's compile turn reads as data (its one recompile); a recompile's check that holds
|
|
112
|
+
* it too stops: nothing compiles again. No grade, refit, queue or second replay. Kept only while `still` holds of the
|
|
113
|
+
* digest's record (the one write: of two claims at once, one decides). */
|
|
114
|
+
export declare function decideCheck(deps: PromotionDeps, name: string, digest: string, bar: CheckBar, read: {
|
|
115
|
+
rows: readonly CheckRow[];
|
|
116
|
+
cost: number | null;
|
|
117
|
+
outcomes: ReplayOutcomes;
|
|
118
|
+
unstarted: number;
|
|
119
|
+
}, thresholds: ReadonlyMap<string, number>, still: (was: PromotionRecord | undefined) => boolean, extra: Partial<PromotionRecord>): Promise<import("../learn/promote.js").Recorded>;
|
|
88
120
|
/** Why a replay a person asked for (askReplay) or read (replayView) was refused: `missing`, no such workflow, revision or
|
|
89
121
|
* replay of the agent (404); `conflict`, the revision cannot replay now (409), in words that say why. */
|
|
90
122
|
export declare class ReplayRefused extends Error {
|