@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.
- package/CHANGELOG.md +68 -1
- package/README.md +218 -20
- package/dist/acp-package.d.ts +24 -6
- package/dist/adapter-facts.d.ts +0 -4
- package/dist/adapter-facts.js +1 -4
- package/dist/adapters.d.ts +3 -12
- package/dist/adapters.js +1 -70
- package/dist/agent-delete.d.ts +33 -10
- package/dist/agent-delete.js +184 -26
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +18 -5
- package/dist/agents.d.ts +8 -1
- package/dist/agents.js +14 -4
- package/dist/answer-json.d.ts +10 -0
- package/dist/answer-json.js +23 -0
- package/dist/api-only.d.ts +5 -2
- package/dist/api-only.js +10 -2
- package/dist/archil-routes.d.ts +1 -1
- package/dist/archil-routes.js +4 -3
- package/dist/browser-live.d.ts +9 -4
- package/dist/browser-live.js +18 -5
- package/dist/browser-sessions.d.ts +56 -0
- package/dist/browser-sessions.js +117 -0
- package/dist/cap.js +7 -9
- package/dist/cli.js +6 -6
- package/dist/computer-routes.d.ts +6 -14
- package/dist/computer-routes.js +8 -10
- package/dist/computers.d.ts +6 -2
- package/dist/computers.js +4 -2
- package/dist/conformance.d.ts +4 -0
- package/dist/conformance.js +6 -0
- package/dist/console/assets/index-Bzn4eUYF.js +715 -0
- package/dist/console/assets/index-CR2ZGei1.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/errors.d.ts +4 -1
- package/dist/errors.js +15 -5
- package/dist/harness-check.d.ts +3 -1
- package/dist/harness-check.js +99 -70
- package/dist/harness-cursor.d.ts +10 -27
- package/dist/harness-cursor.js +5 -84
- package/dist/harness-goose.d.ts +4 -29
- package/dist/harness-goose.js +6 -86
- package/dist/harness-module.d.ts +4 -0
- package/dist/harness-module.js +1 -0
- package/dist/harness-owned.d.ts +52 -0
- package/dist/harness-owned.js +92 -0
- package/dist/harness-recipe.js +2 -24
- package/dist/harness-table.d.ts +109 -6
- package/dist/harness-table.js +242 -28
- package/dist/harness.js +2 -2
- package/dist/import.js +4 -3
- package/dist/key-refusal.d.ts +2 -1
- package/dist/key-refusal.js +18 -2
- package/dist/learn/check.d.ts +11 -2
- package/dist/learn/check.js +12 -9
- package/dist/learn/promote.d.ts +18 -1
- package/dist/learn/promote.js +47 -0
- package/dist/learn/repick.d.ts +34 -0
- package/dist/learn/repick.js +201 -0
- package/dist/learn/secrets.d.ts +4 -0
- package/dist/learn/secrets.js +23 -0
- package/dist/learned-workflow.d.ts +2 -0
- package/dist/learned-workflow.js +18 -1
- package/dist/learning-model.d.ts +18 -0
- package/dist/learning-model.js +77 -0
- package/dist/learning-setting.d.ts +13 -0
- package/dist/learning-setting.js +23 -1
- package/dist/llms.txt +1 -0
- package/dist/model-form.js +12 -12
- package/dist/model.d.ts +5 -4
- package/dist/model.js +19 -13
- package/dist/openapi.js +203 -15
- package/dist/page.d.ts +1 -0
- package/dist/page.js +1 -1
- package/dist/paid-calls.d.ts +4 -1
- package/dist/paid-calls.js +1 -1
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/run-secrets.d.ts +2 -2
- package/dist/run-secrets.js +6 -5
- package/dist/run-trace.js +6 -3
- package/dist/run-usage.d.ts +110 -0
- package/dist/run-usage.js +312 -0
- package/dist/runner/adapter-loop.d.ts +4 -1
- package/dist/runner/adapter-loop.js +52 -22
- package/dist/runner/adapter-run-spec.d.ts +3 -2
- package/dist/runner/adapter-run-spec.js +8 -4
- package/dist/runner/adapters/index.d.ts +4 -2
- package/dist/runner/adapters/index.js +6 -42
- package/dist/runner/cli-run-spec.js +10 -6
- package/dist/runner/conformance/harness.d.ts +2 -0
- package/dist/runner/conformance/harness.js +18 -4
- package/dist/runner/conformance/host-tools.d.ts +4 -0
- package/dist/runner/conformance/host-tools.js +14 -0
- package/dist/runner/feedback-round.d.ts +29 -1
- package/dist/runner/feedback-round.js +54 -3
- package/dist/runner/journal-kinds.d.ts +3 -1
- package/dist/runner/learning-end.js +49 -18
- package/dist/runner/loop-contract.d.ts +3 -0
- package/dist/runner/meta-tools.js +4 -2
- package/dist/runner/monid-run.js +2 -2
- package/dist/runner/presence.d.ts +3 -0
- package/dist/runner/presence.js +19 -12
- package/dist/runner/promotion.d.ts +62 -4
- package/dist/runner/promotion.js +154 -17
- package/dist/runner/reflect-hook.js +3 -2
- package/dist/runner/sdk-loop.js +25 -1
- package/dist/runner/workflow-spec.js +3 -2
- package/dist/runs-over-store.d.ts +5 -3
- package/dist/runs-over-store.js +11 -11
- package/dist/sdk/check.d.ts +31 -0
- package/dist/sdk/check.js +58 -0
- package/dist/sdk/runs.d.ts +10 -2
- package/dist/sdk/runs.js +87 -17
- package/dist/sdk/schema.js +11 -3
- package/dist/server.d.ts +6 -3
- package/dist/server.js +297 -98
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/journal/storage.js +1 -1
- package/dist/store/open.d.ts +1 -1
- package/dist/store/open.js +1 -1
- package/dist/store/postgres/migrations/0021_purged.sql +13 -0
- package/dist/store/postgres/migrations/0022_computer_intervals.sql +27 -0
- package/dist/store/schema.d.ts +15 -1
- package/dist/store/schema.js +50 -5
- package/dist/store/sqlite/connection.d.ts +4 -1
- package/dist/store/sqlite/connection.js +5 -0
- package/dist/store/sqlite/run-patch.d.ts +8 -3
- package/dist/store/sqlite/run-patch.js +15 -7
- package/dist/store/sqlite/store.d.ts +5 -2
- package/dist/store/sqlite/store.js +283 -77
- package/dist/store/sqlite/worker.d.ts +9 -0
- package/dist/store/sqlite/worker.js +18 -1
- package/dist/store/store.d.ts +162 -27
- package/dist/store/store.js +63 -0
- package/dist/store-reads/analytics.js +2 -1
- package/dist/store-reads/cap.d.ts +8 -2
- package/dist/store-reads/cap.js +27 -3
- package/dist/store-reads/learning.d.ts +1 -1
- package/dist/store-reads/learning.js +5 -2
- package/dist/store-reads/runs.js +2 -0
- package/dist/store-reads/stats.js +4 -2
- package/dist/store-view.d.ts +12 -3
- package/dist/store-view.js +70 -27
- package/dist/template-eval.js +5 -2
- package/dist/template-github-permissions.d.ts +5 -1
- package/dist/template-github-permissions.js +7 -3
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/timeline.d.ts +8 -0
- package/dist/timeline/timeline.js +18 -6
- package/dist/tool-gate.d.ts +8 -4
- package/dist/tool-gate.js +6 -7
- package/dist/tool-plane.d.ts +4 -0
- package/dist/tool-plane.js +10 -10
- package/dist/tools.js +9 -0
- package/dist/trigger-targets.d.ts +14 -2
- package/dist/trigger-targets.js +73 -4
- package/dist/triggers.d.ts +2 -1
- package/dist/triggers.js +5 -2
- package/dist/validate.d.ts +4 -2
- package/dist/validate.js +18 -4
- package/dist/viewer-credential.d.ts +24 -0
- package/dist/viewer-credential.js +53 -0
- package/dist/workspace/computer-for-claim.d.ts +5 -1
- package/dist/workspace/computer-for-claim.js +47 -18
- package/dist/workspace/computer-intervals.d.ts +20 -0
- package/dist/workspace/computer-intervals.js +49 -0
- package/dist/workspace/computer-janitor.d.ts +7 -3
- package/dist/workspace/computer-janitor.js +14 -6
- package/dist/workspace/computer-kept.d.ts +7 -2
- package/dist/workspace/computer-kept.js +9 -2
- package/dist/workspace/resolve-computer.d.ts +9 -1
- package/dist/workspace/resolve-computer.js +29 -22
- package/dist/workspace/run-end-computers.d.ts +1 -0
- package/dist/workspace/run-end-computers.js +4 -1
- package/package.json +18 -10
- package/templates/code-review/agent.md +2 -3
- package/templates/code-review/evals/mentions-defused/case.yaml +0 -1
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -27
- package/templates/code-review/evals/other-repo/case.yaml +0 -1
- package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +0 -18
- package/templates/code-review/evals/other-repo/graders/no-other-repo.md +1 -1
- package/dist/console/assets/index-BBFzAxLB.js +0 -715
- package/dist/console/assets/index-BRi-Rgq6.css +0 -1
|
@@ -48,13 +48,12 @@ import { sideEffect } from "./side-effects.js";
|
|
|
48
48
|
import { McpClaimRefused } from "./mcp-claim.js";
|
|
49
49
|
import { CODEMODE, defersCatalog, isCatalogWire, TOOLS_CALL, TOOLS_SEARCH } from "@parcha/agentrun-kernel";
|
|
50
50
|
import { metaTools } from "./meta-tools.js";
|
|
51
|
-
import { builtinHarness } from "../harness-table.js";
|
|
52
51
|
import { Fenced } from "../store/index.js";
|
|
53
52
|
import { answerAsServed } from "../answer-json.js";
|
|
54
53
|
import { reserveFor, stepAndAnswerFor, wrappingUp, wrapUpText } from "../wrap-up.js";
|
|
55
54
|
import { LEARNED_CARD_FIELDS, LEARNED_CLIP, LEARNED_WORKFLOW_TOOL, learnedApprovedTools } from "../learned-workflow.js";
|
|
56
55
|
import { warnHoldShort } from "../print.js";
|
|
57
|
-
import { feedbackAsk, feedbackOf, pendingFeedbackOf } from "./feedback-round.js";
|
|
56
|
+
import { feedbackAsk, feedbackOf, jobEndOpen, pendingFeedbackOf } from "./feedback-round.js";
|
|
58
57
|
import { handbackText, servedAnswerOf, servedAnswerText, WORKFLOW_FIRST, WORKFLOW_FIRST_CALL } from "./workflow-first.js";
|
|
59
58
|
/** The end of a harness's own call (Claude Code's WebSearch) the gate held and then let run: the host ran nothing of it,
|
|
60
59
|
* and the harness's next call runs it. */
|
|
@@ -2050,7 +2049,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2050
2049
|
}
|
|
2051
2050
|
},
|
|
2052
2051
|
});
|
|
2053
|
-
const facts =
|
|
2052
|
+
const { facts } = spec;
|
|
2054
2053
|
// tools_search, tools_call and codemode over the session's tools (meta-tools.ts), on every harness (codemode on
|
|
2055
2054
|
// each but one that runs scripts of its own): what they call is called nested, each call asked about and recorded
|
|
2056
2055
|
// as its own tool's. A search finds a tool whose setting is not deny; an MCP tool's setting is its catalog name's.
|
|
@@ -2303,7 +2302,14 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2303
2302
|
// CLI's look-back has no submission until it ends: its record's lookingBack, below). Read before the session
|
|
2304
2303
|
// opens, so its first request is already learning's.
|
|
2305
2304
|
const lookingBackOpen = (await harness.inspect(context)).submissions.filter((one) => one.type === "input" && Number(one.conversationId) === Number(ROOT_CONVERSATION_ID)).at(-1)?.requestId?.startsWith(REFLECT_PREFIX) === true;
|
|
2306
|
-
|
|
2305
|
+
// The job's end an earlier claim kept for its look-back, with no run end after it (feedback-round.ts jobEndOpen):
|
|
2306
|
+
// its runner was lost after keeping it, maybe before the look-back's first ask (no input in flight then). The job
|
|
2307
|
+
// ended there too: this pass runs no job turn, and the run ends on that end at its time (jobEndKept), never on one
|
|
2308
|
+
// worked out again now, which would move the end every reader served. A follow-up's turn after the run's last end
|
|
2309
|
+
// has kept none, so it is never taken for one.
|
|
2310
|
+
const rootFound = await harness.conversation(ROOT_CONVERSATION_ID, context);
|
|
2311
|
+
const jobKept = rootFound ? jobEndOpen(await entriesOf(gate.journal, rootFound.id, context)) : false;
|
|
2312
|
+
reflecting = lookingBackOpen || jobKept;
|
|
2307
2313
|
// The MCP tools are host tools like any other (mcp.tools, wrapped above): every harness gets them on its own channel
|
|
2308
2314
|
// for host tools, each call through the gate before its intent.
|
|
2309
2315
|
session = await spec.adapter.open({ ...spec.session, tools, deferCatalog: deferred }, io);
|
|
@@ -2663,7 +2669,8 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2663
2669
|
}, context);
|
|
2664
2670
|
}
|
|
2665
2671
|
}
|
|
2666
|
-
|
|
2672
|
+
// Never again for a job whose end is kept (jobKept): what the workflow did is in that end.
|
|
2673
|
+
if (firstToServe && !followedUp && !firstUnplaced && !jobKept && session.state === "new") {
|
|
2667
2674
|
let release;
|
|
2668
2675
|
servingFirst = new Promise((resolve) => (release = resolve));
|
|
2669
2676
|
try {
|
|
@@ -2701,9 +2708,10 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2701
2708
|
}
|
|
2702
2709
|
}
|
|
2703
2710
|
const placed = served !== undefined || followedUp || (session.state !== "idle" && !firstUnplaced);
|
|
2704
|
-
// The end-of-run turn found open (lookingBackOpen),
|
|
2705
|
-
//
|
|
2706
|
-
|
|
2711
|
+
// The end-of-run turn found open (lookingBackOpen), or the job's end found kept before that turn's first ask
|
|
2712
|
+
// (jobKept), with no turn of this claim's sent before it: never recovered as the job's; the run goes to its
|
|
2713
|
+
// end-of-run step, on the job's end the claim that kept it kept (jobEndKept).
|
|
2714
|
+
const lookingBack = (lookingBackOpen || jobKept) && !followedUp && served === undefined;
|
|
2707
2715
|
if (served || followedUp || firstUnplaced || lookingBack) {
|
|
2708
2716
|
// The workflow answered, or handed back and its handback is the turn; the follow-up is the turn this claim runs,
|
|
2709
2717
|
// or there is none.
|
|
@@ -2734,8 +2742,16 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2734
2742
|
let parkOn;
|
|
2735
2743
|
/** The ask_person call the run waits on in its claim, while it does. */
|
|
2736
2744
|
let waitingOn;
|
|
2745
|
+
/** When the job's end was, once it is kept (keepJobEnd): the look-back after it never moves it, and its end is
|
|
2746
|
+
* written at that time. A grade's round keeps the end the run had when the grade opened it (feedbackNow.kept). */
|
|
2747
|
+
let keptAt;
|
|
2737
2748
|
if (alone && lookingBack)
|
|
2738
|
-
({ end: data, failedWith } = await jobEndKept(root));
|
|
2749
|
+
({ end: data, failedWith, endedAt: keptAt } = await jobEndKept(root));
|
|
2750
|
+
else if (alone && feedbackNow?.kept) {
|
|
2751
|
+
const { endedAt, ...end } = feedbackNow.kept;
|
|
2752
|
+
data = end;
|
|
2753
|
+
keptAt = endedAt;
|
|
2754
|
+
}
|
|
2739
2755
|
else if (alone)
|
|
2740
2756
|
data = { state: "ended" };
|
|
2741
2757
|
else
|
|
@@ -2970,14 +2986,19 @@ function adapterLoop(specOf, options, deps) {
|
|
|
2970
2986
|
// The run's status is how its job's own turn ended (`data`), whatever the step spends after it: learning spend that
|
|
2971
2987
|
// takes the run past its cap is the learning's (askEndOfRun reads overCap after each of its turns), never the run's.
|
|
2972
2988
|
// That end is kept before the step's first ask, so a claim that finds its turn open ends the run on it (jobEndKept).
|
|
2989
|
+
// Kept with its time: from then on every reader serves it, and the run's end is written at it (writeEnd `keptAt`).
|
|
2973
2990
|
if (!lookingBack)
|
|
2974
|
-
await keepJobEnd(harness, root, spec, data, failedWith);
|
|
2975
|
-
const step = await endOfRunStep(claim, spec, data.state === "failed" ? "failed" : "completed", overCap);
|
|
2991
|
+
keptAt = await keepJobEnd(harness, root, spec, data, failedWith, keptAt);
|
|
2992
|
+
const step = await endOfRunStep(claim, spec, data.state === "failed" ? "failed" : "completed", overCap, keptAt);
|
|
2993
|
+
// A stop or cancel the runner took during the step (one that raced the read refusing it, its row written while the
|
|
2994
|
+
// run still read as going on) cuts the look-back alone: the run ends on its job's end, the row taken by that end.
|
|
2995
|
+
if (step.kind === "stopped" && keptAt !== undefined)
|
|
2996
|
+
return await writeEnd(harness, root, gate, data, [step.commandId], await cutRows(claim, spec, "stopped-looking"), failedWith, keptAt);
|
|
2976
2997
|
if (step.kind === "stopped")
|
|
2977
2998
|
return await writeEnd(harness, root, gate, stopEnd(stopReason?.kind === "command" ? stopReason.cancel : undefined), [step.commandId], await cutRows(claim, spec, "stopped-looking"));
|
|
2978
2999
|
if (step.kind === "interrupted")
|
|
2979
3000
|
return await interrupted(stopReason?.kind ?? "its claim's signal aborted");
|
|
2980
|
-
return await writeEnd(harness, root, gate, data, [], step.also, failedWith);
|
|
3001
|
+
return await writeEnd(harness, root, gate, data, [], step.also, failedWith, keptAt);
|
|
2981
3002
|
}
|
|
2982
3003
|
}
|
|
2983
3004
|
catch (error) {
|
|
@@ -3362,13 +3383,16 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3362
3383
|
}
|
|
3363
3384
|
/** How the job's own turn ended (`data`, and a CLI's error answer `failedWith`), as this claim decided it, kept on the
|
|
3364
3385
|
* root before the end-of-run step asks its first turn (KINDS.jobEnd), for a run with a step to ask (stepOf). Its
|
|
3365
|
-
* summary is cut of every secret the runner holds, as every summary is when served.
|
|
3366
|
-
|
|
3386
|
+
* summary is cut of every secret the runner holds, as every summary is when served. Kept with its time, `at` (a grade's
|
|
3387
|
+
* round keeps the end it found) or now, which it answers; with no step to ask, nothing is kept and `at` comes back. */
|
|
3388
|
+
async function keepJobEnd(on, conversation, spec, data, failedWith, at) {
|
|
3367
3389
|
if (!stepOf(spec))
|
|
3368
|
-
return;
|
|
3390
|
+
return at;
|
|
3369
3391
|
const end = data.summary !== undefined && deps.redact ? { ...data, summary: deps.redact(data.summary) } : data;
|
|
3370
|
-
const
|
|
3392
|
+
const endedAt = at ?? now();
|
|
3393
|
+
const kept = { end, ...(failedWith !== undefined ? { failedWith } : {}), endedAt };
|
|
3371
3394
|
await on.commit((tx) => tx.appendEntry(conversation.id, { kind: KINDS.jobEnd, data: kept }), context);
|
|
3395
|
+
return endedAt;
|
|
3372
3396
|
}
|
|
3373
3397
|
/** The job's end for a claim that found the end-of-run turn open (lookingBackOpen): the newest keepJobEnd kept (a
|
|
3374
3398
|
* follow-up's round keeps its own), never worked out again. */
|
|
@@ -3538,7 +3562,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3538
3562
|
* came during it; `interrupted` when the claim was lost or the runner is closing (no end is written, and the next claim
|
|
3539
3563
|
* asks it again). A step that throws on its own writes the end without rows: the run's end never waits on it. `over`:
|
|
3540
3564
|
* the claim's overCap, read after each turn the step asks (askEndOfRun). */
|
|
3541
|
-
async function endOfRunStep(claim, spec, outcome, over) {
|
|
3565
|
+
async function endOfRunStep(claim, spec, outcome, over, endedAt) {
|
|
3542
3566
|
const cut = () => {
|
|
3543
3567
|
if (stopReason?.kind === "command")
|
|
3544
3568
|
return { kind: "stopped", commandId: stopReason.commandId };
|
|
@@ -3560,7 +3584,7 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3560
3584
|
void harness?.closed.then(() => closed.abort(new Error("the Session closed")), () => closed.abort(new Error("the Session closed")));
|
|
3561
3585
|
const signal = AbortSignal.any([deps.signal, stopAbort.signal, closed.signal]);
|
|
3562
3586
|
try {
|
|
3563
|
-
const rows = await step({ runId: claim.runId, agentId: spec.agentId, claim, outcome, signal, ask: (prompt, opts) => askEndOfRun(claim, over, prompt, opts.deadlineMs, opts.again === true, opts.round ?? 1, opts.keep, opts.step), keptOf: await keptOf(claim) });
|
|
3587
|
+
const rows = await step({ runId: claim.runId, agentId: spec.agentId, claim, outcome, ...(endedAt !== undefined ? { endedAt } : {}), signal, ask: (prompt, opts) => askEndOfRun(claim, over, prompt, opts.deadlineMs, opts.again === true, opts.round ?? 1, opts.keep, opts.step), keptOf: await keptOf(claim) });
|
|
3564
3588
|
// A replay's or a shadow's grader verdict (runner/compare-end.ts), on its root before its end: its metrics carry it
|
|
3565
3589
|
// (workflow-first.ts pathMetrics), where the check and the audit read it.
|
|
3566
3590
|
const on = harness;
|
|
@@ -3885,8 +3909,11 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3885
3909
|
/** The end commit: an `agentrun.end` entry carrying the run row's final patch (the spec's end patch in it), the rows
|
|
3886
3910
|
* staged with it (the end-of-run step's), and the rows it takes. */
|
|
3887
3911
|
/** `failedWith`: a CLI turn's own error (record "loop"), cut of every secret the runner holds: written in the end's
|
|
3888
|
-
* commit, right before the end, as pi's own error answer (cliErrorAnswer), main's error row for a CLI's turn.
|
|
3889
|
-
|
|
3912
|
+
* commit, right before the end, as pi's own error answer (cliErrorAnswer), main's error row for a CLI's turn.
|
|
3913
|
+
* `keptAt`: the end is the job's, kept before its look-back (keepJobEnd), and every reader served it while the run
|
|
3914
|
+
* looked back: it is written at that time, and a stop or cancel taken here cut the look-back alone, never the end
|
|
3915
|
+
* (the store refuses one still waiting: RunPatch.keepsEnd). */
|
|
3916
|
+
async function writeEnd(on, conversation, theGate, base, take, also = [], failedWith, keptAt) {
|
|
3890
3917
|
// A person's stop of a run that holds its computer ends its agent, not the hold (computer-held.ts): the end, and the
|
|
3891
3918
|
// computer's release after it, wait for the owner's release or the hold's lapse, the owner's calls still answered.
|
|
3892
3919
|
// A cancel, a lost claim or a shutdown meanwhile ends the wait; a cancel's end is then the run's, taking both rows.
|
|
@@ -3897,7 +3924,8 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3897
3924
|
await heldNow.heldAtEnd(Promise.race([heldCut, aborted, on.closed]), heldWords.stopped(heldNow.minutes));
|
|
3898
3925
|
const later = laterStop;
|
|
3899
3926
|
if (later?.kind === "command" && later.cancel) {
|
|
3900
|
-
|
|
3927
|
+
if (keptAt === undefined)
|
|
3928
|
+
base = { ...base, ...stopEnd(true) };
|
|
3901
3929
|
take = [...take, later.commandId];
|
|
3902
3930
|
}
|
|
3903
3931
|
}
|
|
@@ -3916,9 +3944,11 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3916
3944
|
const lateStop = late?.kind === "command" && !take.includes(late.commandId) ? late : undefined;
|
|
3917
3945
|
if (lateStop)
|
|
3918
3946
|
take = [...take, lateStop.commandId];
|
|
3919
|
-
|
|
3947
|
+
// An end that keeps the job's takes it too, and stays the job's.
|
|
3948
|
+
const data = { ...base, ...(patch.outcome !== undefined ? { outcome: patch.outcome } : {}), ...(patch.costUsd !== undefined ? { costUsd: patch.costUsd, ...(patch.costUpperBound ? { costUpperBound: true } : {}) } : {}), ...(patch.metrics !== undefined ? { metrics: patch.metrics } : {}), ...(lateStop && keptAt === undefined ? stopEnd(lateStop.cancel) : {}) };
|
|
3920
3949
|
const run = {
|
|
3921
3950
|
state: data.state,
|
|
3951
|
+
...(keptAt !== undefined ? { endedAt: keptAt, keepsEnd: true } : {}),
|
|
3922
3952
|
// An end's summary is its own: with none, a wait's summary the row still says (a question's, a hand-over's: HELD_WAITS
|
|
3923
3953
|
// and the park's) goes, so an ended run never reads as waiting on its person.
|
|
3924
3954
|
...(data.summary ? { summary: data.summary } : {}),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Context } from "@earendil-works/chord/context";
|
|
2
2
|
import { type CapModel } from "@parcha/agentrun-kernel/kernel/cap";
|
|
3
|
-
import type { HostTool, Wire } from "@parcha/agentrun-kernel";
|
|
3
|
+
import type { AdapterFacts, HostTool, Wire } from "@parcha/agentrun-kernel";
|
|
4
4
|
import type { Approvals } from "../approvals.js";
|
|
5
5
|
import type { installForClaim, installSettled } from "../harness-install.js";
|
|
6
6
|
import type { LiveHandover, LiveViewerStore } from "../browser-live.js";
|
|
@@ -228,9 +228,10 @@ export declare function adapterRunGate(store: Pick<Store, "settings">, claim: Pi
|
|
|
228
228
|
harness?: string;
|
|
229
229
|
approvals?: Approvals;
|
|
230
230
|
};
|
|
231
|
-
}, root: RunFiles, shell
|
|
231
|
+
}, root: RunFiles, shell: ShellPlace | undefined, options: {
|
|
232
232
|
readonly effectOf?: (name: string) => ToolEffect | undefined;
|
|
233
233
|
readonly argumentsOf?: ArgumentsOf;
|
|
234
|
+
readonly facts: AdapterFacts | undefined;
|
|
234
235
|
}): Promise<NonNullable<AdapterRunSpec["gate"]> & {
|
|
235
236
|
readonly permissions: RunPermissions;
|
|
236
237
|
readonly learn: (flows: readonly LearnedWorkflow[]) => void;
|
|
@@ -16,6 +16,7 @@ import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
|
16
16
|
import { defineExtension, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
17
17
|
import { checkRaise, followUpOf, freeModelRequestsOf, parkOf, planCapModel } from "@parcha/agentrun-kernel/kernel/cap";
|
|
18
18
|
import { inspectWorkflow } from "@parcha/agentrun-dsl";
|
|
19
|
+
import { factsOf } from "../harness-table.js";
|
|
19
20
|
import { decisionProvidersIn } from "../decisions.js";
|
|
20
21
|
import { dropLiveViewer, putLiveViewer } from "../browser-live.js";
|
|
21
22
|
import { liveForRun, runnerLiveOf } from "../live-reach.js";
|
|
@@ -155,7 +156,7 @@ export async function graderRouteOf(body, keyed, runKey, claimed, cut, log, deps
|
|
|
155
156
|
export function modelAskOf(pinned, ref) {
|
|
156
157
|
return pinned ? { pinned, ...(ref ? { ref } : {}) } : ref;
|
|
157
158
|
}
|
|
158
|
-
export async function adapterRunGate(store, claim, revision, root, shell, options
|
|
159
|
+
export async function adapterRunGate(store, claim, revision, root, shell, options) {
|
|
159
160
|
let current = await storeSettings(store);
|
|
160
161
|
const approvers = await readApprovers(store.settings);
|
|
161
162
|
// A Workspace's paths are in the run's folder: its folder named as a computer names it, for the gate's path checks.
|
|
@@ -163,7 +164,7 @@ export async function adapterRunGate(store, claim, revision, root, shell, option
|
|
|
163
164
|
// Where the run's shell is (run-tools.ts shell): with no computer, a tool no setting names takes the kernel's ruled
|
|
164
165
|
// default (tool-gate.ts defaultPermission): bash asks first, the background tools are refused.
|
|
165
166
|
// An MCP tool's effect as the run's pin marks it (ClaimMcp.effectOf): what "allow reads" lifts an ask by.
|
|
166
|
-
const where = { root: folder, work: folder, ...(options.effectOf ? { effectOf: options.effectOf } : {}), ...(options.argumentsOf ? { argumentsOf: options.argumentsOf } : {}) };
|
|
167
|
+
const where = { root: folder, work: folder, ...(options.effectOf ? { effectOf: options.effectOf } : {}), ...(options.argumentsOf ? { argumentsOf: options.argumentsOf } : {}), facts: options.facts };
|
|
167
168
|
const gate = runGate({ ...where, ...(shell === undefined ? {} : { computer: shell === "computer" }) }, claim.runId, revision, () => current, approvers);
|
|
168
169
|
// The run's learned workflows, once its spec has read them (learn): a learned_workflow call is asked about its MCP nodes.
|
|
169
170
|
let learned = [];
|
|
@@ -473,8 +474,10 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
473
474
|
const root = runFolder(deps.data, runRow.agentId, claim.runId);
|
|
474
475
|
// The gate names the run's folder by its Workspace (Mode 2: its folder on the run's disk, never this machine's folder at
|
|
475
476
|
// the same path), for its path checks; it reads nothing in it.
|
|
476
|
-
// A pinned MCP tool is held to the arguments its listing in the run's pin declares (mcp.argumentsOf).
|
|
477
|
-
|
|
477
|
+
// A pinned MCP tool is held to the arguments its listing in the run's pin declares (mcp.argumentsOf). The harness's facts
|
|
478
|
+
// are its entry's on the owner's table (factsOf): none for pi, nor for a module's harness on a runner of its own.
|
|
479
|
+
const facts = factsOf(deps.env, revision.body.harness);
|
|
480
|
+
const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell, { ...(mcp ? { effectOf: (name) => mcp.effectOf(name), argumentsOf: (name) => mcp.argumentsOf(name) } : {}), facts });
|
|
478
481
|
// The run's one cap, as the loop's runCap reads it (adapter-loop.ts RunCapConfig): the launch's cap figure (undefined
|
|
479
482
|
// uncapped — every paid request still books through the one cap), the run's model priced WITH tiers, strict where the
|
|
480
483
|
// launch says. The loop builds the kernel runCap from these over the run's own sessions (its model requests, its paid
|
|
@@ -677,6 +680,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
|
|
|
677
680
|
}), { ...audits, launch, ...(run.redact ? { redact: run.redact } : {}) });
|
|
678
681
|
return {
|
|
679
682
|
adapter,
|
|
683
|
+
facts,
|
|
680
684
|
// Who keeps the run's visible record: its runner says (none: the adapter, as pi keeps its own).
|
|
681
685
|
...(runner.record ? { record: runner.record } : {}),
|
|
682
686
|
session,
|
|
@@ -34,6 +34,8 @@ export interface RunnerHarness {
|
|
|
34
34
|
/** Every harness the runner runs, by name. */
|
|
35
35
|
export declare const RUNNER_HARNESSES: Readonly<Record<string, RunnerHarness>>;
|
|
36
36
|
/** The harness the launch names, as `env`'s harness table has it (harness-table.ts harnessOf): a built-in one's runner is
|
|
37
|
-
* the runner's own (RUNNER_HARNESSES), one a harness module adds brings its own (HarnessEntry.runner)
|
|
38
|
-
*
|
|
37
|
+
* the runner's own (RUNNER_HARNESSES), one a harness module adds (and Goose) brings its own (HarnessEntry.runner), and any
|
|
38
|
+
* other entry with facts and an adapter (Cursor's: harness-loops.ts cliRunSpecFromLaunch builds the run from the entry) is
|
|
39
|
+
* run from the table (harness-table.ts ON_TABLE, the modules' runner too). Undefined when the table has none by that name. `env`:
|
|
40
|
+
* the run's environment (this process's when not given). */
|
|
39
41
|
export declare function resolveHarness(harness: string, env?: NodeJS.ProcessEnv): RunnerHarness | undefined;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { facts as claudeFacts } from "@parcha/agentrun-harness-claude/facts";
|
|
2
2
|
import { facts as codexFacts } from "@parcha/agentrun-harness-codex/facts";
|
|
3
3
|
import { facts as openCodeFacts } from "../../harness-opencode/facts.js";
|
|
4
|
-
import { harnessOf } from "../../harness-table.js";
|
|
5
|
-
import { acpPackage } from "../../acp-package.js";
|
|
6
|
-
import { GOOSE_ID } from "../../harness-goose.js";
|
|
7
|
-
import { CURSOR_ID } from "../../harness-cursor.js";
|
|
4
|
+
import { harnessOf, ON_TABLE } from "../../harness-table.js";
|
|
8
5
|
import { piAdapter } from "./pi.js";
|
|
9
6
|
const CLAUDE_PACKAGE = "@parcha/agentrun-harness-claude";
|
|
10
7
|
const CODEX_PACKAGE = "@parcha/agentrun-harness-codex";
|
|
@@ -76,48 +73,15 @@ export const RUNNER_HARNESSES = {
|
|
|
76
73
|
});
|
|
77
74
|
},
|
|
78
75
|
},
|
|
79
|
-
// Goose, where its package is beside serve (acp-package.ts): on the binary `extra.binary` names, which its owner
|
|
80
|
-
// installed (harness-goose.ts); a run on serve's table builds its adapter from its entry (adapters.ts gooseOf).
|
|
81
|
-
[GOOSE_ID]: {
|
|
82
|
-
record: "loop",
|
|
83
|
-
adapter: async (launch, extra = {}) => {
|
|
84
|
-
const acp = acpPackage();
|
|
85
|
-
if (!acp)
|
|
86
|
-
throw new Error("Goose's adapter (@parcha/agentrun-harness-acp) is not installed beside this runner");
|
|
87
|
-
if (typeof extra.binary !== "string")
|
|
88
|
-
throw new Error("Goose's runner adapter needs the installed binary's path (extra.binary)");
|
|
89
|
-
return acp.gooseAdapter({
|
|
90
|
-
model: launch.model,
|
|
91
|
-
provider: { origin: launch.provider.origin, credential: launch.provider.credential, ...(launch.provider.headers ? { headers: launch.provider.headers } : {}), ...(launch.provider.auth ? { auth: launch.provider.auth } : {}) },
|
|
92
|
-
...(launch.price ? { price: launch.price } : {}),
|
|
93
|
-
...(launch.fetch ? { fetch: launch.fetch } : {}),
|
|
94
|
-
sessionsDir: launch.sessionsDir,
|
|
95
|
-
...extra,
|
|
96
|
-
});
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
// Cursor, where the same package is beside serve: on the launcher `extra.binary` names, which its owner installed
|
|
100
|
-
// (harness-cursor.ts), and its owner's key read by name from `extra.env`; billed to the owner's Cursor plan, so the
|
|
101
|
-
// launch's provider and price are never its. A run on serve's table builds its adapter from its entry (adapters.ts
|
|
102
|
-
// cursorOf).
|
|
103
|
-
[CURSOR_ID]: {
|
|
104
|
-
record: "loop",
|
|
105
|
-
adapter: async (launch, extra = {}) => {
|
|
106
|
-
const acp = acpPackage();
|
|
107
|
-
if (!acp)
|
|
108
|
-
throw new Error("Cursor's adapter (@parcha/agentrun-harness-acp) is not installed beside this runner");
|
|
109
|
-
if (typeof extra.binary !== "string")
|
|
110
|
-
throw new Error("Cursor's runner adapter needs the installed launcher's path (extra.binary)");
|
|
111
|
-
return acp.cursorAdapter({ sessionsDir: launch.sessionsDir, ...extra });
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
76
|
};
|
|
115
77
|
/** The harness the launch names, as `env`'s harness table has it (harness-table.ts harnessOf): a built-in one's runner is
|
|
116
|
-
* the runner's own (RUNNER_HARNESSES), one a harness module adds brings its own (HarnessEntry.runner)
|
|
117
|
-
*
|
|
78
|
+
* the runner's own (RUNNER_HARNESSES), one a harness module adds (and Goose) brings its own (HarnessEntry.runner), and any
|
|
79
|
+
* other entry with facts and an adapter (Cursor's: harness-loops.ts cliRunSpecFromLaunch builds the run from the entry) is
|
|
80
|
+
* run from the table (harness-table.ts ON_TABLE, the modules' runner too). Undefined when the table has none by that name. `env`:
|
|
81
|
+
* the run's environment (this process's when not given). */
|
|
118
82
|
export function resolveHarness(harness, env = process.env) {
|
|
119
83
|
const entry = harnessOf(env, harness);
|
|
120
84
|
if (!entry)
|
|
121
85
|
return undefined;
|
|
122
|
-
return entry.runner ?? (Object.prototype.hasOwnProperty.call(RUNNER_HARNESSES, harness) ? RUNNER_HARNESSES[harness] : undefined);
|
|
86
|
+
return entry.runner ?? (Object.prototype.hasOwnProperty.call(RUNNER_HARNESSES, harness) ? RUNNER_HARNESSES[harness] : entry.facts && entry.adapter ? ON_TABLE : undefined);
|
|
123
87
|
}
|
|
@@ -20,6 +20,7 @@ import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
|
20
20
|
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
21
21
|
import { checkRaise, followUpOf, freeModelRequestsOf, parkOf, planCapModel } from "@parcha/agentrun-kernel/kernel/cap";
|
|
22
22
|
import { PLAN_LIMIT_WORDS } from "@parcha/agentrun-kernel";
|
|
23
|
+
import { modelWire } from "../wires.js";
|
|
23
24
|
import { confineOf, noNewPrivsPrefix, standsIn, thinkingFor } from "../adapters.js";
|
|
24
25
|
import { claimSettled, claudeCliIn, installDirOf, installForClaim, installingWords } from "../harness-install.js";
|
|
25
26
|
import { HarnessUnavailable } from "../provider.js";
|
|
@@ -27,7 +28,7 @@ import { effortGuidance } from "../effort-guidance.js";
|
|
|
27
28
|
import { outputContract } from "../answer-json.js";
|
|
28
29
|
import { wireName } from "../catalog.js";
|
|
29
30
|
import { environmentLine, runZone } from "../environment.js";
|
|
30
|
-
import { harnessOf } from "../harness-table.js";
|
|
31
|
+
import { factsOf, harnessOf } from "../harness-table.js";
|
|
31
32
|
import { laidLearned, learningFolderOf, secretsShown } from "../learning.js";
|
|
32
33
|
import { laidOf, layLearningSeed } from "./learning-seed.js";
|
|
33
34
|
import { learningWorkspace } from "../learn/folder.js";
|
|
@@ -121,12 +122,12 @@ export function capModelOf(id, wire, listed, unpriced, plan = false) {
|
|
|
121
122
|
return { id, api: wire, price, outputCeiling: typeof listed?.maxTokens === "number" ? listed.maxTokens : null };
|
|
122
123
|
}
|
|
123
124
|
/** The model a CLI run of `entry` on `chosen` (modelsOf) is capped at, on its `wire`: the catalog entry that bills it
|
|
124
|
-
* (its entry's priceModel), priced by capModelOf. A harness its vendor bills to its owner's plan (
|
|
125
|
-
* Cursor's) is the plan rule's, as a ChatGPT plan's model is. */
|
|
125
|
+
* (its entry's priceModel), priced by capModelOf. A harness its vendor bills to its owner's plan (no model wire of ours:
|
|
126
|
+
* modelWire, Cursor's) is the plan rule's, as a ChatGPT plan's model is. */
|
|
126
127
|
function chosenCapModel(entry, env, chosen, wire) {
|
|
127
128
|
const priced = entry.priceModel(env, chosen.model);
|
|
128
129
|
const listed = chosen.models.getModel(priced.provider, priced.modelId);
|
|
129
|
-
return capModelOf(priced.modelId, wire, listed, chosen.unpriced.has(priced.modelId) || listed === undefined, priced.provider === PLAN_PROVIDER || priced.provider === CLAUDE_LOGIN_PROVIDER ||
|
|
130
|
+
return capModelOf(priced.modelId, wire, listed, chosen.unpriced.has(priced.modelId) || listed === undefined, priced.provider === PLAN_PROVIDER || priced.provider === CLAUDE_LOGIN_PROVIDER || !modelWire(wire));
|
|
130
131
|
}
|
|
131
132
|
/** The model a run of the CLI harness `entry` on `ref` (a revision's model; none, this host's default for it) is capped
|
|
132
133
|
* at here, as its run's spec prices it (modelsOf, chosenCapModel), before any run: a save's cap warning (cap-short.ts)
|
|
@@ -546,8 +547,10 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
546
547
|
// The gate before a call's intent, the same as the pi spec: the revision's tool settings over the store's, read from the
|
|
547
548
|
// store at each decide — adapterRunGate (RunGate.decide: deny with its words, a pin, allow, ask). The end-of-run turn's
|
|
548
549
|
// refusal of writes under .learning/ is the adapter loop's own (it knows the turn), never a file's.
|
|
549
|
-
// A pinned MCP tool is held to the arguments its listing in the run's pin declares (mcp.argumentsOf).
|
|
550
|
-
|
|
550
|
+
// A pinned MCP tool is held to the arguments its listing in the run's pin declares (mcp.argumentsOf). The harness's
|
|
551
|
+
// native tools are named by its facts on the owner's table (factsOf: a module's harness's too).
|
|
552
|
+
const ownerFacts = factsOf(deps.env, name);
|
|
553
|
+
const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell, { ...(mcp ? { effectOf: (name) => mcp.effectOf(name), argumentsOf: (name) => mcp.argumentsOf(name) } : {}), facts: ownerFacts });
|
|
551
554
|
// The run's tools: the kernel registry's hands on its Workspace (and computer); the web host tools it is granted
|
|
552
555
|
// (web_fetch, web_search, monid), bound by the binding the pi spec uses (webHostTools) on the ToolHost the pi spec builds
|
|
553
556
|
// (buildToolHost); and the learned_workflow tool when the run has it (learnsWorkflows: its revision is agentic and the
|
|
@@ -690,6 +693,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
|
|
|
690
693
|
}), { ...audits, launch, ...(run.redact ? { redact: run.redact } : {}) });
|
|
691
694
|
return {
|
|
692
695
|
adapter,
|
|
696
|
+
facts: ownerFacts,
|
|
693
697
|
session,
|
|
694
698
|
input,
|
|
695
699
|
// A trigger's first input is its origin's, the launch's own owner flag kept (run-launch.ts keepInputOrigin).
|
|
@@ -25,6 +25,8 @@ export declare function suiteTools(countFile?: string): {
|
|
|
25
25
|
ran: Record<ToolName, number>;
|
|
26
26
|
letSlowGo: () => void;
|
|
27
27
|
slowStarted: Promise<void>;
|
|
28
|
+
holdAsked: () => undefined;
|
|
29
|
+
letAskedGo: () => void;
|
|
28
30
|
};
|
|
29
31
|
/** Catalog tools (an MCP server's, by wire name) that do nothing, enough of them to pass DEFER_CATALOG_OVER: a run with that
|
|
30
32
|
* many has its catalog deferred (not listed) and is offered tools_search and tools_call, which the meta cases need. */
|
|
@@ -87,6 +87,10 @@ export function suiteTools(countFile) {
|
|
|
87
87
|
const slowGate = new Promise((resolve) => (letGo = resolve));
|
|
88
88
|
let slowStarted = () => { };
|
|
89
89
|
const started = new Promise((resolve) => (slowStarted = resolve));
|
|
90
|
+
// Held (holdAsked), an approved `asked` call runs until the suite lets it go (letAskedGo), so its run cannot end first.
|
|
91
|
+
let askedGate;
|
|
92
|
+
let letAskedGoNow = () => { };
|
|
93
|
+
const holdAsked = () => void (askedGate = new Promise((resolve) => (letAskedGoNow = resolve)));
|
|
90
94
|
const tool = (name, replaySafe, ask, run) => ({ name, replaySafe, ask, run });
|
|
91
95
|
const tools = {
|
|
92
96
|
effect: tool("effect", false, false, async () => {
|
|
@@ -103,12 +107,14 @@ export function suiteTools(countFile) {
|
|
|
103
107
|
await Promise.race([slowGate, new Promise((resolve) => signal.addEventListener("abort", () => resolve(), { once: true }))]);
|
|
104
108
|
return signal.aborted ? "cut" : "slow done";
|
|
105
109
|
}),
|
|
106
|
-
asked: tool("asked", false, true, async () => {
|
|
110
|
+
asked: tool("asked", false, true, async (_args, signal) => {
|
|
107
111
|
ran.asked += 1;
|
|
112
|
+
if (askedGate)
|
|
113
|
+
await Promise.race([askedGate, new Promise((resolve) => signal.addEventListener("abort", () => resolve(), { once: true }))]);
|
|
108
114
|
return "asked done";
|
|
109
115
|
}),
|
|
110
116
|
};
|
|
111
|
-
return { tools, ran, letSlowGo: () => letGo(), slowStarted: started };
|
|
117
|
+
return { tools, ran, letSlowGo: () => letGo(), slowStarted: started, holdAsked, letAskedGo: () => letAskedGoNow() };
|
|
112
118
|
}
|
|
113
119
|
/** Catalog tools (an MCP server's, by wire name) that do nothing, enough of them to pass DEFER_CATALOG_OVER: a run with that
|
|
114
120
|
* many has its catalog deferred (not listed) and is offered tools_search and tools_call, which the meta cases need. */
|
|
@@ -1022,12 +1028,20 @@ const CASES = [
|
|
|
1022
1028
|
title: "a double-clicked approval runs the call once: the first answers it, and the store refuses the second (one answer per approval)",
|
|
1023
1029
|
async body(subject, t) {
|
|
1024
1030
|
const w = await world(subject, t);
|
|
1025
|
-
const { tools, ran } = suiteTools();
|
|
1031
|
+
const { tools, ran, holdAsked, letAskedGo } = suiteTools();
|
|
1032
|
+
// The approved call is held until the second click is answered, so the run cannot end first: a run that ended
|
|
1033
|
+
// refuses any command as final (RunFinal) before the one-answer index is reached, which is not this case.
|
|
1034
|
+
holdAsked();
|
|
1026
1035
|
await w.start("runner-a", { script: [{ call: "asked" }, { say: "done" }], tools, hooks: quiet });
|
|
1027
1036
|
await w.ended("parked");
|
|
1028
1037
|
const callId = await w.askedCall();
|
|
1029
1038
|
const first = await sendCommand(w.server, RUN, { kind: "approve", body: { approval: callId } });
|
|
1030
|
-
|
|
1039
|
+
try {
|
|
1040
|
+
await assert.rejects(sendCommand(w.server, RUN, { kind: "approve", body: { approval: callId } }), AnswerTaken, "a second answer to one approval is never written: the store says it is answered already");
|
|
1041
|
+
}
|
|
1042
|
+
finally {
|
|
1043
|
+
letAskedGo();
|
|
1044
|
+
}
|
|
1031
1045
|
await w.ended("ended");
|
|
1032
1046
|
assert.equal(ran.asked, 1, "the call ran once");
|
|
1033
1047
|
assert.equal((await w.commandRow(first.id)).refused, null, "the first approve answered it");
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { HostTool } from "@parcha/agentrun-kernel";
|
|
2
|
+
import type { SuiteTool } from "./subject.js";
|
|
3
|
+
/** The suite's `tools` (setup.tools) as host tools, in their order. */
|
|
4
|
+
export declare function suiteHostTools(tools: Readonly<Record<string, SuiteTool>>): HostTool[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The suite's `tools` (setup.tools) as host tools, in their order. */
|
|
2
|
+
export function suiteHostTools(tools) {
|
|
3
|
+
return Object.values(tools).map((tool) => ({
|
|
4
|
+
name: tool.name,
|
|
5
|
+
description: `The suite's ${tool.name} tool.`,
|
|
6
|
+
inputSchema: { type: "object", properties: {} },
|
|
7
|
+
replay: tool.replaySafe ? "safe" : "never",
|
|
8
|
+
call: async (args, context) => ({
|
|
9
|
+
text: String(await tool.run((args ?? {}), context.signal)),
|
|
10
|
+
...(tool.images ? { images: tool.images } : {}),
|
|
11
|
+
...(tool.structured !== undefined ? { structured: tool.structured } : {}),
|
|
12
|
+
}),
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
@@ -2,15 +2,43 @@ import { type Grade } from "../learn/promote.js";
|
|
|
2
2
|
import type { RunPath } from "../learning-cost.js";
|
|
3
3
|
import { type RunLaunch } from "../run-launch.js";
|
|
4
4
|
import { type Command, type Store } from "../store/store.js";
|
|
5
|
+
import { type EndData } from "./journal-kinds.js";
|
|
5
6
|
export declare const FEEDBACK_ROUNDS: readonly ["correction"];
|
|
6
7
|
export type FeedbackRound = (typeof FEEDBACK_ROUNDS)[number];
|
|
8
|
+
/** The end a run's look-back keeps: how its job ended (its state, summary and outcome) and when. While the run looks
|
|
9
|
+
* back (its end-of-run step, a fresh run's or a grade's feedback round) every reader serves this end, and the look-back's
|
|
10
|
+
* own end writes it again at the same time (adapter-loop.ts writeEnd `keptAt`): a look-back never undoes or moves its
|
|
11
|
+
* run's end. */
|
|
12
|
+
export interface KeptEnd {
|
|
13
|
+
readonly state: EndData["state"];
|
|
14
|
+
readonly summary?: string;
|
|
15
|
+
readonly outcome?: EndData["outcome"];
|
|
16
|
+
readonly endedAt: number;
|
|
17
|
+
}
|
|
7
18
|
/** A feedback round, as its steer's body carries it (`feedback`) and its FEEDBACK entry keeps it: the round, whether the
|
|
8
|
-
* grade said right,
|
|
19
|
+
* grade said right, the grade's words (`text`), and the end the run had when the grade opened it again (`kept`). */
|
|
9
20
|
export interface FeedbackData {
|
|
10
21
|
readonly round: FeedbackRound;
|
|
11
22
|
readonly correct: boolean;
|
|
12
23
|
readonly text: string;
|
|
24
|
+
readonly kept?: KeptEnd;
|
|
13
25
|
}
|
|
26
|
+
/** Whether the run's root `entries` hold a job's end kept for its look-back (KINDS.jobEnd) with no run end after it: the
|
|
27
|
+
* job ended and its look-back is under way, whether or not that look-back has asked anything yet. A follow-up's turn
|
|
28
|
+
* keeps none until its own job's end is kept, so a turn after the run's last end reads false. */
|
|
29
|
+
export declare function jobEndOpen(entries: readonly {
|
|
30
|
+
readonly kind: string;
|
|
31
|
+
}[]): boolean;
|
|
32
|
+
/** The end run's look-back keeps while it runs, from the run's root `entries` and its command rows, else undefined (no
|
|
33
|
+
* look-back under way, or one whose job's end was never kept):
|
|
34
|
+
* - the job's end its claim kept before the end-of-run step (KINDS.jobEnd, with its time), newer than the run's last end;
|
|
35
|
+
* - else the end a grade's round kept, from its FEEDBACK entry newer than the run's last end;
|
|
36
|
+
* - else from the round's steer the grade wrote, not taken yet (the run opened again, no runner on it yet).
|
|
37
|
+
* A follow-up's own turn keeps none until its job's end is kept: its run reads as going on, as main's does. */
|
|
38
|
+
export declare function keptEndOf(entries: readonly {
|
|
39
|
+
readonly kind: string;
|
|
40
|
+
readonly data?: unknown;
|
|
41
|
+
}[], commands: readonly Pick<Command, "kind" | "body" | "takenAt" | "refused">[]): KeptEnd | undefined;
|
|
14
42
|
/** What a grade asks for: `correction` for a graded run the agent finished when the grade has words, else none
|
|
15
43
|
* (undefined): a run its learned workflow answered alone opens none, right or wrong (its grade is kept). A replay run
|
|
16
44
|
* is never graded. */
|
|
@@ -15,6 +15,51 @@ import { RunFinal } from "../store/store.js";
|
|
|
15
15
|
import { KINDS } from "./journal-kinds.js";
|
|
16
16
|
import { commandRequest } from "./loop.js";
|
|
17
17
|
export const FEEDBACK_ROUNDS = ["correction"];
|
|
18
|
+
const END_STATES = ["ended", "stopped", "failed"];
|
|
19
|
+
const OUTCOMES = ["completed", "escalated", "stopped", "cancelled"];
|
|
20
|
+
/** A kept end as a steer's body or a journal entry holds it, else undefined. */
|
|
21
|
+
function keptOf(value) {
|
|
22
|
+
const kept = value;
|
|
23
|
+
if (!kept || typeof kept !== "object" || !END_STATES.includes(kept.state) || typeof kept.endedAt !== "number")
|
|
24
|
+
return undefined;
|
|
25
|
+
if (kept.summary !== undefined && typeof kept.summary !== "string")
|
|
26
|
+
return undefined;
|
|
27
|
+
if (kept.outcome !== undefined && !OUTCOMES.includes(kept.outcome))
|
|
28
|
+
return undefined;
|
|
29
|
+
return { state: kept.state, ...(kept.summary !== undefined ? { summary: kept.summary } : {}), ...(kept.outcome !== undefined ? { outcome: kept.outcome } : {}), endedAt: kept.endedAt };
|
|
30
|
+
}
|
|
31
|
+
/** The end run `run` has now, as a grade's round keeps it: only one a round opens again (reopenableWhere: ended, or
|
|
32
|
+
* stopped by a person), with its end time. */
|
|
33
|
+
function keptEndOfRow(run) {
|
|
34
|
+
if (run.endedAt === null || !(run.state === "ended" || (run.state === "stopped" && run.outcome === "stopped")))
|
|
35
|
+
return undefined;
|
|
36
|
+
return { state: run.state, ...(run.summary !== null ? { summary: run.summary } : {}), ...(run.outcome !== null ? { outcome: run.outcome } : {}), endedAt: run.endedAt };
|
|
37
|
+
}
|
|
38
|
+
/** Whether the run's root `entries` hold a job's end kept for its look-back (KINDS.jobEnd) with no run end after it: the
|
|
39
|
+
* job ended and its look-back is under way, whether or not that look-back has asked anything yet. A follow-up's turn
|
|
40
|
+
* keeps none until its own job's end is kept, so a turn after the run's last end reads false. */
|
|
41
|
+
export function jobEndOpen(entries) {
|
|
42
|
+
return entries.findLastIndex((entry) => entry.kind === KINDS.jobEnd) > entries.findLastIndex((entry) => entry.kind === KINDS.end);
|
|
43
|
+
}
|
|
44
|
+
/** The end run's look-back keeps while it runs, from the run's root `entries` and its command rows, else undefined (no
|
|
45
|
+
* look-back under way, or one whose job's end was never kept):
|
|
46
|
+
* - the job's end its claim kept before the end-of-run step (KINDS.jobEnd, with its time), newer than the run's last end;
|
|
47
|
+
* - else the end a grade's round kept, from its FEEDBACK entry newer than the run's last end;
|
|
48
|
+
* - else from the round's steer the grade wrote, not taken yet (the run opened again, no runner on it yet).
|
|
49
|
+
* A follow-up's own turn keeps none until its job's end is kept: its run reads as going on, as main's does. */
|
|
50
|
+
export function keptEndOf(entries, commands) {
|
|
51
|
+
const last = (kind) => entries.findLastIndex((entry) => entry.kind === kind);
|
|
52
|
+
const end = last(KINDS.end);
|
|
53
|
+
if (jobEndOpen(entries)) {
|
|
54
|
+
const data = entries[last(KINDS.jobEnd)].data;
|
|
55
|
+
return keptOf(data?.end && data.endedAt !== undefined ? { ...data.end, endedAt: data.endedAt } : undefined);
|
|
56
|
+
}
|
|
57
|
+
const fed = last(KINDS.feedback);
|
|
58
|
+
if (fed > end)
|
|
59
|
+
return keptOf(entries[fed].data?.kept);
|
|
60
|
+
const steer = commands.find((command) => command.kind === "steer" && command.takenAt === null && command.refused === null && feedbackOf(command.body)?.kept !== undefined);
|
|
61
|
+
return steer ? feedbackOf(steer.body).kept : undefined;
|
|
62
|
+
}
|
|
18
63
|
/** What a grade asks for: `correction` for a graded run the agent finished when the grade has words, else none
|
|
19
64
|
* (undefined): a run its learned workflow answered alone opens none, right or wrong (its grade is kept). A replay run
|
|
20
65
|
* is never graded. */
|
|
@@ -28,7 +73,8 @@ export function feedbackOf(body) {
|
|
|
28
73
|
const text = body?.text;
|
|
29
74
|
if (!fed || typeof fed !== "object" || !FEEDBACK_ROUNDS.includes(fed.round) || typeof fed.correct !== "boolean" || typeof text !== "string")
|
|
30
75
|
return undefined;
|
|
31
|
-
|
|
76
|
+
const kept = keptOf(fed.kept);
|
|
77
|
+
return { round: fed.round, correct: fed.correct, text, ...(kept ? { kept } : {}) };
|
|
32
78
|
}
|
|
33
79
|
/** The feedback round the run's root `entries` say its next end closes: its newest FEEDBACK entry when no end came after
|
|
34
80
|
* it, else undefined. */
|
|
@@ -88,9 +134,14 @@ export async function openFeedbackRound(store, grade, label, canTurn = () => tru
|
|
|
88
134
|
// run's route (`canTurn` false), the grade is kept and the run is not opened again, never left to fail with no key.
|
|
89
135
|
if (launch && !canTurn(launch))
|
|
90
136
|
return null;
|
|
91
|
-
|
|
137
|
+
// The run's end as the grade found it: the round keeps it (the run reads it while it looks back, and its end writes it
|
|
138
|
+
// again), and opens the run again only at that end (`endedAt`), never at a later one a message's turn wrote meanwhile.
|
|
139
|
+
const kept = keptEndOfRow(run);
|
|
140
|
+
if (!kept)
|
|
141
|
+
return null;
|
|
142
|
+
const feedback = { round, correct: grade.correct, kept };
|
|
92
143
|
try {
|
|
93
|
-
const steer = await store.runs.reopen(grade.run, { kind: "steer", body: { text: words, feedback } });
|
|
144
|
+
const steer = await store.runs.reopen(grade.run, { kind: "steer", body: { text: words, feedback } }, { endedAt: kept.endedAt });
|
|
94
145
|
return { round, command: steer.id };
|
|
95
146
|
}
|
|
96
147
|
catch (error) {
|
|
@@ -343,10 +343,12 @@ export interface EndData {
|
|
|
343
343
|
readonly review?: EndReview;
|
|
344
344
|
}
|
|
345
345
|
/** How a run's job's own turn ended (KINDS.jobEnd): the end it gives the run (its summary cut of every secret the runner
|
|
346
|
-
* holds),
|
|
346
|
+
* holds), a CLI's error answer the end writes as its error row (`failedWith`), and the end's time (`endedAt`): the run
|
|
347
|
+
* reads that end while it looks back, and its end is written at that time (feedback-round.ts KeptEnd). */
|
|
347
348
|
export interface JobEndData {
|
|
348
349
|
readonly end: EndData;
|
|
349
350
|
readonly failedWith?: string;
|
|
351
|
+
readonly endedAt?: number;
|
|
350
352
|
}
|
|
351
353
|
/** An escalated workflow run's review as its end keeps it: the escalation's kind, the escalate node's label (else the node
|
|
352
354
|
* it escalated at), and its summary (else the run's). Served as the run's `review`, `at` its end. */
|