@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
package/dist/harness-table.js
CHANGED
|
@@ -13,13 +13,14 @@ import { facts as claudeFacts } from "@parcha/agentrun-harness-claude/facts";
|
|
|
13
13
|
import { facts as codexFacts } from "@parcha/agentrun-harness-codex/facts";
|
|
14
14
|
import { facts as openCodeFacts } from "./harness-opencode/facts.js";
|
|
15
15
|
import { CURSOR_FACTS, GOOSE_FACTS } from "./adapter-facts.js";
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
16
|
+
import { ACP_PACKAGE, acpPackage } from "./acp-package.js";
|
|
17
|
+
import { gooseHidden, gooseMissing } from "./harness-goose.js";
|
|
18
|
+
import { CURSOR_DEFAULT_MODEL, CURSOR_KEY, cursorCardOf, cursorHidden, cursorLimitsOf, cursorMissing } from "./harness-cursor.js";
|
|
18
19
|
import { DEFAULT_HARNESS, HARNESS_ID_PATTERN, PLAN_HARNESSES, RESERVED_HARNESS_IDS } from "./harness.js";
|
|
19
20
|
import { HARNESS_INSTALLS } from "./harness-install.js";
|
|
20
21
|
import { chooseModel } from "./model.js";
|
|
21
22
|
import { HarnessUnavailable, modelOn, openRouterOnly, priceModelFor, providerFor } from "./provider.js";
|
|
22
|
-
import { modelWire, WIRES } from "./wires.js";
|
|
23
|
+
import { modelWire, wireOf, WIRES } from "./wires.js";
|
|
23
24
|
import { PLAN_PROVIDER, signedIn } from "./chatgpt-plan.js";
|
|
24
25
|
/** A module of entries a test merges over the built-in ones (HarnessTableModule), by absolute path. */
|
|
25
26
|
export const HARNESS_TABLE_ENV = "AGENTRUN_HARNESS_TABLE";
|
|
@@ -65,7 +66,7 @@ const onOpenRouter = (id, vendor) => new RegExp(`^openrouter/${vendor}/[^/]+$`).
|
|
|
65
66
|
/** An adapter harness's entry, from its facts and the factory that builds its adapter. */
|
|
66
67
|
function adapterEntry(facts, make, extra = {}) {
|
|
67
68
|
const { wire, id } = facts;
|
|
68
|
-
// A harness billed to its own plan
|
|
69
|
+
// A harness billed to its own plan is acpEntryOf's plan-billed entry (Cursor's): this one is for a model wire of ours.
|
|
69
70
|
if (!modelWire(wire))
|
|
70
71
|
throw new Error(`${id} is billed to its own plan, so its table entry is its own, never adapterEntry's`);
|
|
71
72
|
const { vendor, gateway } = WIRES[wire];
|
|
@@ -117,43 +118,163 @@ function adapterEntry(facts, make, extra = {}) {
|
|
|
117
118
|
};
|
|
118
119
|
return Object.freeze(entry);
|
|
119
120
|
}
|
|
120
|
-
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
121
|
+
/** An adapter harness's adapter for one run, from `facts` and its builder: the launch serve chooses for the run's model
|
|
122
|
+
* on this server's keys (providerFor, priceOf). A module's, and the built-in Goose's. An error `missing` or the builder
|
|
123
|
+
* throws is a HarnessUnavailable with the fix its code names in the facts (fixOf: install, pins). */
|
|
124
|
+
function moduleAdapter(facts, build, { missing }, host = {}) {
|
|
125
|
+
return async (env, needs) => {
|
|
126
|
+
const { fixOf, harnessLog, priceOf } = await import("./adapters.js");
|
|
127
|
+
const unavailable = (error) => (error instanceof HarnessUnavailable ? error : new HarnessUnavailable(error.message, fixOf(facts, error)));
|
|
128
|
+
// What no key fixes is said first (a binary): a refusal for it names no key.
|
|
129
|
+
let lacks;
|
|
130
|
+
try {
|
|
131
|
+
lacks = await missing?.(env);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
throw unavailable(error);
|
|
135
|
+
}
|
|
136
|
+
if (lacks)
|
|
137
|
+
throw new HarnessUnavailable(lacks);
|
|
138
|
+
const provider = providerFor(facts.wire, env, needs.model, facts.id);
|
|
139
|
+
// A person's Claude Code login is its CLI's alone (claude-login.ts): no request of this harness goes on it; a key of
|
|
140
|
+
// its wire's vendor's, or OpenRouter's, runs it.
|
|
141
|
+
if (provider.login)
|
|
142
|
+
throw new HarnessUnavailable(`${facts.label} runs on a model key: Claude Code's login on this machine is its CLI's alone.`, undefined, [wireOf(facts.wire).key, "OPENROUTER_API_KEY"]);
|
|
143
|
+
try {
|
|
144
|
+
return await build({
|
|
145
|
+
model: provider.modelId,
|
|
146
|
+
provider: { origin: provider.origin, credential: provider.credential, ...(provider.auth ? { auth: provider.auth } : {}) },
|
|
147
|
+
price: priceOf({ ...needs, model: provider.priceModel }),
|
|
148
|
+
log: host.log ?? harnessLog(facts.id, env),
|
|
149
|
+
...(needs.confine ? { confine: needs.confine } : {}),
|
|
150
|
+
...(needs.skills?.length ? { skills: needs.skills } : {}),
|
|
151
|
+
env,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
throw unavailable(error);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/** `recipe`, once its `keys` name no key this server holds for something else (harness-recipe.ts serverKey, the
|
|
160
|
+
* loader's rule 1) but its own built-in harness's (builtinOwns: Cursor's CURSOR_API_KEY). Its keys are read from the
|
|
161
|
+
* launch's environment, where a server key is readable by name, and a module's or a check's recipe is not the loader's:
|
|
162
|
+
* checked as each launch's recipe is made, before its agent starts, so the harness's offer at start says it. */
|
|
163
|
+
async function ownKeysOnly(facts, recipe) {
|
|
164
|
+
const { RECIPE_CODES, serverKey } = await import("./harness-recipe.js");
|
|
165
|
+
const named = (recipe.keys ?? []).filter((name) => serverKey(name) && !builtinOwns(facts.id, name));
|
|
166
|
+
if (named.length)
|
|
167
|
+
throw new HarnessUnavailable(`${RECIPE_CODES.keys}: ${facts.label}'s recipe names ${named.join(", ")} in keys, a key this server holds for something else; a recipe names only keys saved for its own harness.`);
|
|
168
|
+
return recipe;
|
|
169
|
+
}
|
|
170
|
+
/** The runner of an entry run on serve's table (its facts' adapter, cli-run-spec.ts), never by a runner's adapter of its
|
|
171
|
+
* own: a module's, and Goose's and Cursor's (resolveHarness). Its adapter says so if it is ever asked. The loop keeps the
|
|
172
|
+
* run's record, as for every CLI harness. */
|
|
173
|
+
export const ON_TABLE = Object.freeze({
|
|
174
|
+
record: "loop",
|
|
175
|
+
adapter: async () => {
|
|
176
|
+
throw new Error("this harness runs from its table entry (facts and adapter), not a runner adapter");
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
/** What an ACP harness promises by default: a resume by the agent's session/load, tool calls through its permission asks,
|
|
180
|
+
* its model through the session's proxy (Goose's). */
|
|
181
|
+
const ACP_PROMISES = Object.freeze({ resume: "load", tool_gate: "permission", billing: "proxy" });
|
|
182
|
+
/** As ACP_PROMISES, with a resume by a new session given the conversation so far: a module's ACP agent's, unless it
|
|
183
|
+
* says "load" (AcpEntryOptions.resume). */
|
|
184
|
+
const ACP_RESTART_PROMISES = Object.freeze({ ...ACP_PROMISES, resume: "restart" });
|
|
185
|
+
/** The code a module's ACP entry is refused by at its first launch when it promises resume "load" and its recipe
|
|
186
|
+
* declares no session/load (AcpEntryOptions.resume). */
|
|
187
|
+
export const HARNESS_RESUME_UNDECLARED = "HARNESS_RESUME_UNDECLARED";
|
|
188
|
+
/** An adapter harness's whole entry over the builder of its adapter for one run (moduleAdapter), run from the table
|
|
189
|
+
* (ON_TABLE): a module's (HarnessModuleKit.adapterEntry, which takes no `hidden`) and the built-in Goose's. */
|
|
190
|
+
const moduleEntryOf = (facts, adapter, { missing, ...extra } = {}, host = {}) => Object.freeze({ ...adapterEntry(facts, moduleAdapter(facts, adapter, missing ? { missing } : {}, host), extra), runner: ON_TABLE });
|
|
191
|
+
/** A proxy-billed ACP agent's whole entry, moduleEntryOf over serve's own ACP adapter: a module's (HarnessModuleKit.acpEntry,
|
|
192
|
+
* `host` none) and a proxy-billed recipe's under harness-check (AcpEntryHost). Its agent's allowlist and keys are read
|
|
193
|
+
* from the launch's environment, never this process's, and its recipe names no server key (ownKeysOnly). */
|
|
194
|
+
function acpProxyEntryOf(options, host = {}) {
|
|
195
|
+
const { facts, resume = "restart" } = options;
|
|
196
|
+
return moduleEntryOf(facts, async (launch) => {
|
|
197
|
+
const acp = acpPackage();
|
|
198
|
+
if (!acp)
|
|
199
|
+
throw new HarnessUnavailable(`${facts.label} needs the ACP adapter (${ACP_PACKAGE}) beside this server`);
|
|
200
|
+
const recipe = await ownKeysOnly(facts, options.recipe(launch));
|
|
201
|
+
// Promising less than the recipe declares is allowed; promising a session/load the agent is never asked for is not.
|
|
202
|
+
if (resume === "load" && !recipe.declares.load)
|
|
203
|
+
throw new HarnessUnavailable(`${HARNESS_RESUME_UNDECLARED}: ${facts.label} (${facts.id}) promises resume "load", but its recipe's declares.load is false, so its run would restart instead: declare session/load in the recipe, or leave resume at "restart".`);
|
|
204
|
+
return acp.acpAdapter({
|
|
205
|
+
recipe,
|
|
206
|
+
proxy: options.proxy(launch),
|
|
207
|
+
...(options.beforeStart ? { beforeStart: options.beforeStart } : {}),
|
|
208
|
+
...(launch.confine ? { confine: launch.confine } : {}),
|
|
209
|
+
env: launch.env,
|
|
210
|
+
log: launch.log,
|
|
211
|
+
});
|
|
212
|
+
}, { promises: resume === "load" ? ACP_PROMISES : ACP_RESTART_PROMISES, ...(options.missing ? { missing: options.missing } : {}) }, host);
|
|
213
|
+
}
|
|
214
|
+
/** What a plan-billed ACP harness promises: as ACP_PROMISES, billed to its owner's plan. */
|
|
215
|
+
const ACP_PLAN_PROMISES = Object.freeze({ resume: "load", tool_gate: "permission", billing: "plan" });
|
|
216
|
+
/** The model id of a plan-billed agent's own default (`<id>/default`). */
|
|
217
|
+
const PLAN_DEFAULT_MODEL = "default";
|
|
218
|
+
/** A plan-billed ACP agent's whole entry: its models are the ones its vendor lists for its owner, named `<id>/<model-id>`
|
|
219
|
+
* (`<id>/default`: the vendor's own default), checked against that list when its session opens (ACP_MODEL_UNLISTED);
|
|
220
|
+
* no model key, route, proxy, catalog or price of ours is its, and it has no runner adapter of a module's (ON_TABLE). */
|
|
221
|
+
function acpPlanEntryOf(options, host = {}) {
|
|
222
|
+
const { facts } = options;
|
|
223
|
+
const { id, label } = facts;
|
|
224
|
+
if (modelWire(facts.wire))
|
|
225
|
+
throw new Error(`${id} runs on a model wire of ours, so its ACP entry is the proxy-billed one`);
|
|
226
|
+
const prefix = `${id}/`;
|
|
227
|
+
const make = async (env, needs) => {
|
|
228
|
+
const { fixOf, harnessLog } = await import("./adapters.js");
|
|
229
|
+
// What no key fixes is said first, as for the built-in harnesses' binaries.
|
|
230
|
+
const lacks = await options.missing?.(env);
|
|
231
|
+
if (lacks)
|
|
232
|
+
throw new HarnessUnavailable(lacks);
|
|
233
|
+
const acp = acpPackage();
|
|
234
|
+
if (!acp)
|
|
235
|
+
throw new HarnessUnavailable(`${label} needs the ACP adapter (${ACP_PACKAGE}) beside this server`);
|
|
236
|
+
if (needs.model.provider !== id)
|
|
237
|
+
throw new HarnessUnavailable(`${label} runs ${label}'s models, named ${prefix}<model-id>; the run's model is ${needs.model.provider}/${needs.model.modelId}.`);
|
|
238
|
+
const log = host.log ?? harnessLog(id, env);
|
|
239
|
+
try {
|
|
240
|
+
const recipe = await ownKeysOnly(facts, await options.recipe({ model: needs.model.modelId, log, ...(needs.confine ? { confine: needs.confine } : {}), env }));
|
|
241
|
+
// Its keys (recipe.keys) are read from the run's environment, which holds its own (ownKeys: run-secrets.ts keysFor).
|
|
242
|
+
return acp.acpAdapter({ recipe, ...(options.beforeStart ? { beforeStart: options.beforeStart } : {}), ...(needs.confine ? { confine: needs.confine } : {}), env, log });
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
if (error instanceof HarnessUnavailable)
|
|
246
|
+
throw error;
|
|
247
|
+
throw new HarnessUnavailable(error.message, fixOf(facts, error));
|
|
248
|
+
}
|
|
249
|
+
};
|
|
128
250
|
const entry = {
|
|
129
251
|
id,
|
|
130
|
-
label
|
|
252
|
+
label,
|
|
131
253
|
steer: facts.steer,
|
|
132
254
|
runMib: facts.runMib,
|
|
133
255
|
oneAlwaysFits: false,
|
|
134
256
|
facts,
|
|
135
|
-
promises:
|
|
136
|
-
ownKeys: Object.freeze([
|
|
137
|
-
hidden:
|
|
138
|
-
card:
|
|
257
|
+
promises: ACP_PLAN_PROMISES,
|
|
258
|
+
...(options.ownKeys ? { ownKeys: Object.freeze([...options.ownKeys]) } : {}),
|
|
259
|
+
...(options.hidden ? { hidden: options.hidden } : {}),
|
|
260
|
+
...(options.card ? { card: options.card } : {}),
|
|
139
261
|
runs: (_env, model) => model.startsWith(prefix),
|
|
140
262
|
onWire: () => true,
|
|
141
263
|
model: async (_env, ref, available) => {
|
|
142
264
|
if (!available)
|
|
143
265
|
return undefined;
|
|
144
|
-
const named = ref ?? `${prefix}${
|
|
266
|
+
const named = ref ?? `${prefix}${PLAN_DEFAULT_MODEL}`;
|
|
145
267
|
const modelId = named.startsWith(prefix) ? named.slice(prefix.length) : "";
|
|
146
|
-
const { acpPackage } = await import("./acp-package.js");
|
|
147
268
|
if (!modelId || !acpPackage()?.MODEL_ID.test(modelId))
|
|
148
|
-
return { why: `${
|
|
149
|
-
return { model: { provider:
|
|
269
|
+
return { why: `${label} runs a model ${label} lists for your ${label} API key, named ${prefix}<model-id> (${prefix}${PLAN_DEFAULT_MODEL} for ${label}'s own default); ${named} is not one.`, host: false, needs: "model" };
|
|
270
|
+
return { model: { provider: id, modelId } };
|
|
150
271
|
},
|
|
151
272
|
priceModel: (_env, model) => model,
|
|
152
|
-
adapter:
|
|
273
|
+
adapter: make,
|
|
153
274
|
refusal: async (env, given, { atStart }) => {
|
|
154
|
-
const {
|
|
275
|
+
const { startReason } = await import("./adapters.js");
|
|
155
276
|
try {
|
|
156
|
-
const adapter = await
|
|
277
|
+
const adapter = await make(env, given ?? { model: { provider: id, modelId: PLAN_DEFAULT_MODEL }, models: { getModel: () => undefined } });
|
|
157
278
|
const problems = adapter.check({ key: "capabilities", label: "capabilities", system: [], tools: [], context: "fresh" });
|
|
158
279
|
return problems.length ? { reason: problems.join(" ") } : undefined;
|
|
159
280
|
}
|
|
@@ -164,6 +285,77 @@ function cursorEntry(facts) {
|
|
|
164
285
|
};
|
|
165
286
|
return Object.freeze(entry);
|
|
166
287
|
}
|
|
288
|
+
export function acpEntryOf(options, host = {}) {
|
|
289
|
+
return modelWire(options.facts.wire) ? acpProxyEntryOf(options, host) : acpPlanEntryOf(options, host);
|
|
290
|
+
}
|
|
291
|
+
/** The kit a harness module is handed (HarnessModuleKit): never a host's log (AcpEntryHost), so its launches log as
|
|
292
|
+
* their harness. */
|
|
293
|
+
const MODULE_KIT = Object.freeze({
|
|
294
|
+
adapterEntry: (facts, adapter, extra) => moduleEntryOf(facts, adapter, extra),
|
|
295
|
+
acpEntry: (options) => acpProxyEntryOf(options),
|
|
296
|
+
});
|
|
297
|
+
/** Why Goose cannot run here (harness-owned.ts `missing`: not installed, or not the pinned binary) as an error of its
|
|
298
|
+
* code, so moduleAdapter refuses it with the install fix its facts name. */
|
|
299
|
+
const gooseRefused = (missing) => Object.assign(new Error(missing.message), { code: missing.code });
|
|
300
|
+
/** Goose's adapter for one run (moduleAdapter's builder, after its `missing`): its package's gooseAdapter on the binary
|
|
301
|
+
* its owner installed into the data's harnesses directory (`agentrun harness install goose`) and from nowhere else,
|
|
302
|
+
* looked up and verified again (its sha256 is kept per file identity, so only the first look reads it). Its model goes
|
|
303
|
+
* where claude-agent's does, the host's Anthropic Messages provider, through a model proxy of its own. */
|
|
304
|
+
async function gooseLaunch(launch) {
|
|
305
|
+
const found = await gooseMissing(launch.env);
|
|
306
|
+
if ("missing" in found)
|
|
307
|
+
throw gooseRefused(found.missing);
|
|
308
|
+
return acpPackage().gooseAdapter({
|
|
309
|
+
binary: found.binary, sha256: found.sha256, model: launch.model, provider: launch.provider, price: launch.price, log: launch.log,
|
|
310
|
+
...(launch.confine ? { confine: launch.confine } : {}),
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
/** What Cursor gives acpEntryOf for its plan-billed entry: billed to its owner's Cursor plan on the owner's Cursor API key
|
|
314
|
+
* (`ownKeys`), its model one Cursor lists for that key (`cursor/<model-id>`, `cursor/default` for Cursor's own). Listed
|
|
315
|
+
* only once its owner has installed it (`agentrun harness install cursor`): `missing` is its release, looked up and
|
|
316
|
+
* verified (harness-cursor.ts cursorMissing), and `beforeStart` checks its launcher and every file beside it again
|
|
317
|
+
* before each process starts. Stopped by its owner's turn and tool-call limits (cursorLimitsOf), which its card says. */
|
|
318
|
+
function cursorOptions(facts) {
|
|
319
|
+
/** Cursor's launcher, or the HarnessUnavailable that says why it is not here, with the fix (install, pins) it names. */
|
|
320
|
+
const launcher = async (env) => {
|
|
321
|
+
const found = await cursorMissing(env);
|
|
322
|
+
if (!("missing" in found))
|
|
323
|
+
return found.binary;
|
|
324
|
+
const { fixOf } = await import("./adapters.js");
|
|
325
|
+
throw new HarnessUnavailable(found.missing.message, fixOf(facts, found.missing));
|
|
326
|
+
};
|
|
327
|
+
return {
|
|
328
|
+
facts,
|
|
329
|
+
ownKeys: [CURSOR_KEY],
|
|
330
|
+
hidden: cursorHidden,
|
|
331
|
+
card: cursorCardOf,
|
|
332
|
+
missing: async (env) => void (await launcher(env)),
|
|
333
|
+
recipe: async (launch) => {
|
|
334
|
+
if (!launch.env[CURSOR_KEY])
|
|
335
|
+
throw new HarnessUnavailable(`${facts.label} runs on your Cursor API key, and ${CURSOR_KEY} is not set where AgentRun starts: set it there (it is handed to Cursor's runs alone), then restart AgentRun.`);
|
|
336
|
+
const acp = acpPackage();
|
|
337
|
+
let limits;
|
|
338
|
+
try {
|
|
339
|
+
limits = cursorLimitsOf(acp, launch.env);
|
|
340
|
+
}
|
|
341
|
+
catch (error) {
|
|
342
|
+
throw new HarnessUnavailable(error.message);
|
|
343
|
+
}
|
|
344
|
+
const model = launch.model === CURSOR_DEFAULT_MODEL ? undefined : launch.model;
|
|
345
|
+
return acp.cursorRecipe({ command: await launcher(launch.env), limits, ...(model ? { model } : {}) });
|
|
346
|
+
},
|
|
347
|
+
beforeStart: async (command) => {
|
|
348
|
+
const acp = acpPackage();
|
|
349
|
+
const release = acp.pinnedRelease(acp.CURSOR_PIN, acp.acpPlatform(), true);
|
|
350
|
+
const root = release && acp.cursorRootOf(command, release.cmd);
|
|
351
|
+
// The launcher is the one cursorMissing found at its pinned path: a release or folder lost since is refused.
|
|
352
|
+
if (!release?.treeSha256 || !root)
|
|
353
|
+
throw new Error(`ACP_BINARY_MISMATCH: the Cursor launcher at ${command} is not at its pinned path inside its folder`);
|
|
354
|
+
// The tree's digest covers every file it runs, the launcher among them (as cursorAdapter's check does).
|
|
355
|
+
await acp.verifyPinnedTree(root, release.treeSha256);
|
|
356
|
+
},
|
|
357
|
+
};
|
|
358
|
+
}
|
|
167
359
|
/** The secrets the built-in harnesses own (each entry's ownKeys), whether or not its package is beside serve here: a
|
|
168
360
|
* server without Cursor's adapter still never hands CURSOR_API_KEY to another harness's run (run-secrets.ts keysFor). */
|
|
169
361
|
export const BUILTIN_OWN_KEYS = Object.freeze([CURSOR_KEY]);
|
|
@@ -189,18 +381,32 @@ const BUILTIN = Object.freeze({
|
|
|
189
381
|
// Goose, over ACP, where its package is beside serve (acp-package.ts): its owner installs its pinned binary
|
|
190
382
|
// (`agentrun harness install goose`, harness-goose.ts), never a run; listed only once it is installed and verified.
|
|
191
383
|
...(GOOSE_FACTS ? {
|
|
192
|
-
[GOOSE_FACTS.id]:
|
|
193
|
-
|
|
384
|
+
[GOOSE_FACTS.id]: moduleEntryOf(GOOSE_FACTS, gooseLaunch, {
|
|
385
|
+
missing: async (env) => {
|
|
386
|
+
const found = await gooseMissing(env);
|
|
387
|
+
if ("missing" in found)
|
|
388
|
+
throw gooseRefused(found.missing);
|
|
389
|
+
return undefined;
|
|
390
|
+
},
|
|
391
|
+
promises: ACP_PROMISES,
|
|
194
392
|
hidden: gooseHidden,
|
|
195
393
|
}),
|
|
196
394
|
} : {}),
|
|
197
395
|
// Cursor, over ACP, where the same package is beside serve: its owner installs its pinned release (`agentrun harness
|
|
198
396
|
// install cursor`, harness-cursor.ts) and sets CURSOR_API_KEY; listed only once it is installed and verified.
|
|
199
|
-
...(CURSOR_FACTS ? { [CURSOR_FACTS.id]:
|
|
397
|
+
...(CURSOR_FACTS ? { [CURSOR_FACTS.id]: acpEntryOf(cursorOptions(CURSOR_FACTS)) } : {}),
|
|
200
398
|
});
|
|
201
399
|
/** The ids of the harnesses this server has built in (Goose and Cursor where their package is beside it, as a recipe
|
|
202
400
|
* needs it too): a recipe or module never takes one (harness-recipe.ts). */
|
|
203
401
|
export const BUILTIN_HARNESS_IDS = Object.freeze(Object.keys(BUILTIN));
|
|
402
|
+
/** Whether built-in harness `id` owns secret `key`: its own built-in entry names it in ownKeys. By the pair, so a key one
|
|
403
|
+
* built-in owns never crosses to another built-in, a module's entry or a test's; and none is owned where its harness's
|
|
404
|
+
* package is not beside serve (run-secrets.ts keysFor). */
|
|
405
|
+
export function builtinOwns(id, key) {
|
|
406
|
+
return Object.hasOwn(BUILTIN, id) && BUILTIN[id].ownKeys?.includes(key) === true;
|
|
407
|
+
}
|
|
408
|
+
/** The code a harness module's entry is refused by when its ownKeys names a key a built-in harness owns (BUILTIN_OWN_KEYS). */
|
|
409
|
+
export const HARNESS_KEY_OWNED = "HARNESS_KEY_OWNED";
|
|
204
410
|
const loaded = new Map();
|
|
205
411
|
const requireHere = createRequire(import.meta.url);
|
|
206
412
|
/** The members a harness module's new entry gives: what the table's readers ask of every entry. */
|
|
@@ -210,7 +416,7 @@ function entriesOf(path, named) {
|
|
|
210
416
|
const module = requireHere(resolve(path));
|
|
211
417
|
if (typeof module.entries !== "function")
|
|
212
418
|
throw new Error(`${named} names ${path}, which exports no entries(builtins)`);
|
|
213
|
-
return module.entries(BUILTIN);
|
|
419
|
+
return module.entries(BUILTIN, MODULE_KIT);
|
|
214
420
|
}
|
|
215
421
|
/** The harness modules `env` names (HARNESS_MODULES_ENV): none when it names none. */
|
|
216
422
|
function modulesOf(env) {
|
|
@@ -256,6 +462,9 @@ export function harnessTable(env) {
|
|
|
256
462
|
const missing = WHOLE.filter((member) => entry[member] === undefined);
|
|
257
463
|
if (missing.length)
|
|
258
464
|
throw new Error(`harness module ${module}: its entry ${id} lacks ${missing.join(", ")}`);
|
|
465
|
+
const owned = (entry.ownKeys ?? []).filter((key) => BUILTIN_OWN_KEYS.includes(key));
|
|
466
|
+
if (owned.length)
|
|
467
|
+
throw Object.assign(new Error(`${HARNESS_KEY_OWNED}: harness module ${module}: its entry ${id} names ${owned.join(", ")} in ownKeys, a key a built-in harness owns and is handed alone: a module's harness takes none of ${BUILTIN_OWN_KEYS.join(", ")}`), { code: HARNESS_KEY_OWNED });
|
|
259
468
|
built[id] = Object.freeze({ ...entry, id });
|
|
260
469
|
}
|
|
261
470
|
}
|
|
@@ -308,6 +517,11 @@ export const ownerHarness = (env, id) => {
|
|
|
308
517
|
const key = id ?? DEFAULT_HARNESS;
|
|
309
518
|
return Object.hasOwn(table, key) ? table[key] : undefined;
|
|
310
519
|
};
|
|
520
|
+
/** The facts of harness `id`'s adapter on the owner's table (ownerTable: the built-in harnesses and those `env`'s modules
|
|
521
|
+
* add, never a test table's, so a stand-in keeps the facts of the harness it stands in for). Every reader of a harness's
|
|
522
|
+
* facts by id asks here: its models (model-form.ts), its key rows (model.ts), its search and tool names (tool-plane.ts,
|
|
523
|
+
* tool-gate.ts). Undefined for pi, for a module's harness that gives none, and for an id the table has none of. */
|
|
524
|
+
export const factsOf = (env, id) => ownerHarness(env, id)?.facts;
|
|
311
525
|
/** The entry of harness `id` (none: the default, pi) on `env`'s table; undefined for an id this server has none of. */
|
|
312
526
|
export const harnessOf = (env, id) => harnessTable(env)[id ?? DEFAULT_HARNESS];
|
|
313
527
|
/** Whether `id` runs on an adapter (every harness but pi): a session of its own, beside the run's process. */
|
package/dist/harness.js
CHANGED
|
@@ -86,9 +86,9 @@ export function harnessOffers(env) {
|
|
|
86
86
|
// lacks only a key is (a save warns of that, never refuses).
|
|
87
87
|
const { MODEL_REF } = await import("./validate.js");
|
|
88
88
|
const { providerFor, HarnessUnavailable } = await import("./provider.js");
|
|
89
|
-
const { adapterFactsOf } = await import("./adapter-facts.js");
|
|
90
89
|
const { FAUX_ENV } = await import("./model.js");
|
|
91
|
-
const
|
|
90
|
+
const { factsOf } = await import("./harness-table.js");
|
|
91
|
+
const facts = factsOf(env, offer.id);
|
|
92
92
|
for (const id of new Set([...pickerCandidates(env, offer.id), ...free.map((m) => m.id)])) {
|
|
93
93
|
if (!MODEL_REF.test(id))
|
|
94
94
|
continue;
|
package/dist/import.js
CHANGED
|
@@ -378,14 +378,15 @@ async function findKeys(plan, add, cut, held, signal, onProgress) {
|
|
|
378
378
|
/** A project's own text for secretlint: its path, its instructions, and its skills' paths and text. */
|
|
379
379
|
const projectText = (cwd, files) => [cwd, ...Object.values(files.instructions), ...Object.entries(files.skills).flat()].join("\n");
|
|
380
380
|
export const agentIdOf = (cwd) => `imp-${hash(`dir:${cwd}`).slice(0, 32)}`;
|
|
381
|
-
/** The sessions the store holds already, as `source:session`, to their run's id
|
|
382
|
-
|
|
381
|
+
/** The sessions the store holds already, as `source:session`, to their run's id: a purged run's too, so a session its
|
|
382
|
+
* owner purged is never imported again. */
|
|
383
|
+
const importedIn = async (store) => new Map((await store.runs.list({ purged: true })).flatMap((run) => (run.importedFrom ? [[`${run.importedFrom.source}:${run.importedFrom.session}`, run.id]] : [])));
|
|
383
384
|
const sameFile = (seen, stats) => seen !== undefined && seen.size === stats.size && seen.mtime_ms === stats.mtimeMs;
|
|
384
385
|
/** The session files the store's imports read whole, by their path's sha256, with their run: the file stamp an import kept
|
|
385
386
|
* on the run's `imported_from`, so an unchanged file is not parsed again. */
|
|
386
387
|
async function filesIn(store) {
|
|
387
388
|
const out = new Map();
|
|
388
|
-
for (const run of await store.runs.list({})) {
|
|
389
|
+
for (const run of await store.runs.list({ purged: true })) {
|
|
389
390
|
const seen = run.importedFrom?.file;
|
|
390
391
|
if (seen)
|
|
391
392
|
out.set(seen.path_sha256, { path_sha256: seen.path_sha256, size: seen.size, mtime_ms: seen.mtime_ms, run: run.id });
|
package/dist/key-refusal.d.ts
CHANGED
|
@@ -27,7 +27,8 @@ export declare const answerPasses: {
|
|
|
27
27
|
/** `text`, a run's answer as serve serves it (its final answer, or a string in its workflow output), with no held secret
|
|
28
28
|
* in it, and NEVER cut: an answer is shown whole. The same rule as redacted() (redactSecrets over `secrets`), over the
|
|
29
29
|
* whole text, read in pieces of about ANSWER_PIECE characters cut at whitespace. No form of a held value redactSecrets
|
|
30
|
-
* finds as it stands (as written, JSON-escaped, base64, hex) holds whitespace, so a cut there splits none
|
|
30
|
+
* finds as it stands (as written, JSON-escaped, base64, hex) holds whitespace, so a cut there splits none; the one shape
|
|
31
|
+
* read across whitespace, a Bearer scheme and its token, is never cut between the two (endsInScheme). A run of more
|
|
31
32
|
* than ANSWER_PIECE characters with no whitespace is no person's text and is shown as "[redacted]", unread. A value split
|
|
32
33
|
* by whitespace across a cut, or a form only found across pieces, still shows to one valueMatcher pass over the joined
|
|
33
34
|
* output, and then the whole answer is "[redacted]", as redactSecrets does with a text that still holds a value. */
|
package/dist/key-refusal.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// count, a file name, a duration, another service's status) is no refused key, and the error is left as it is.
|
|
5
5
|
import { DEFAULT_HARNESS } from "./harness.js";
|
|
6
6
|
import { harnessOf } from "./harness-table.js";
|
|
7
|
-
import { redactSecrets, valueMatcher } from "./learn/secrets.js";
|
|
7
|
+
import { endsInScheme, redactSecrets, valueMatcher } from "./learn/secrets.js";
|
|
8
8
|
import { hostModel, MODEL_KEYS } from "./model.js";
|
|
9
9
|
import { modelWire, openRouterOnly, WIRES } from "./provider.js";
|
|
10
10
|
import { savedGatewayIn } from "./model-gateway.js";
|
|
@@ -82,7 +82,8 @@ export const answerPasses = { count: 0 };
|
|
|
82
82
|
/** `text`, a run's answer as serve serves it (its final answer, or a string in its workflow output), with no held secret
|
|
83
83
|
* in it, and NEVER cut: an answer is shown whole. The same rule as redacted() (redactSecrets over `secrets`), over the
|
|
84
84
|
* whole text, read in pieces of about ANSWER_PIECE characters cut at whitespace. No form of a held value redactSecrets
|
|
85
|
-
* finds as it stands (as written, JSON-escaped, base64, hex) holds whitespace, so a cut there splits none
|
|
85
|
+
* finds as it stands (as written, JSON-escaped, base64, hex) holds whitespace, so a cut there splits none; the one shape
|
|
86
|
+
* read across whitespace, a Bearer scheme and its token, is never cut between the two (endsInScheme). A run of more
|
|
86
87
|
* than ANSWER_PIECE characters with no whitespace is no person's text and is shown as "[redacted]", unread. A value split
|
|
87
88
|
* by whitespace across a cut, or a form only found across pieces, still shows to one valueMatcher pass over the joined
|
|
88
89
|
* output, and then the whole answer is "[redacted]", as redactSecrets does with a text that still holds a value. */
|
|
@@ -104,6 +105,21 @@ export function redactedAnswer(text, secrets) {
|
|
|
104
105
|
continue;
|
|
105
106
|
}
|
|
106
107
|
to = from + space + 1;
|
|
108
|
+
// A cut after a Bearer scheme would leave its token at the head of the next piece, where no shape reads it (the
|
|
109
|
+
// shape is the scheme, then the token). The cut moves back to the whitespace before the scheme; with none in this
|
|
110
|
+
// piece, the scheme and its token are read as one run, to the next whitespace, as a run with no whitespace is.
|
|
111
|
+
if (endsInScheme(text.slice(from, to))) {
|
|
112
|
+
const before = text.slice(from, to).trimEnd().search(/\s[^\s]*$/);
|
|
113
|
+
if (before > 0)
|
|
114
|
+
to = from + before + 1;
|
|
115
|
+
else {
|
|
116
|
+
const next = text.slice(to).search(/\s/);
|
|
117
|
+
to = next < 0 ? text.length : to + next;
|
|
118
|
+
parts.push(to - from > ANSWER_PIECE ? "[redacted]" : redactSecrets(text.slice(from, to), secrets, Buffer.byteLength(text.slice(from, to))));
|
|
119
|
+
from = to;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
107
123
|
}
|
|
108
124
|
const piece = text.slice(from, to);
|
|
109
125
|
parts.push(redactSecrets(piece, secrets, Buffer.byteLength(piece)));
|
package/dist/learn/check.d.ts
CHANGED
|
@@ -37,6 +37,10 @@ export type DraftCheckInput = {
|
|
|
37
37
|
readonly deniedBy?: Readonly<Record<string, "agent" | "server" | "default">>;
|
|
38
38
|
/** Explicit host adapter capabilities; absent keeps the managed runner defaults. */
|
|
39
39
|
readonly workflowAdapters?: readonly ("runNode" | "runJudge")[];
|
|
40
|
+
/** The agent's learning.repick (learning-setting.ts): true, a re-pick loop whose body is the pass marker the host derives
|
|
41
|
+
* from its pass 1 (learn/repick.ts repickPassOne) is read as that pass 1 by the compact state rule, so its clone's page
|
|
42
|
+
* read passes; any other page read on the agent's model is refused as ever. */
|
|
43
|
+
readonly repick?: boolean;
|
|
40
44
|
/** The workflow DSL a draft is read with. */
|
|
41
45
|
readonly dsl: DraftReader;
|
|
42
46
|
/** The decision providers a draft's decision nodes may ask, and the gate's setting of each (workflow-draft.ts
|
|
@@ -75,8 +79,13 @@ export declare function answerTierProblems(doc: unknown): string[];
|
|
|
75
79
|
* child sees an input key as a page when its value reads one. Pages reach a step on the agent's model only through a fast-tier step's
|
|
76
80
|
* output: chain14b's drafts fed whole pages to the answering step (4.1 requests a run at ~70k cached tokens each,
|
|
77
81
|
* $0.364 a served run), where the research shape (a fast extract's compact facts to the answering step) booked ~$0.08.
|
|
78
|
-
* One line each, in words the compile retry acts on.
|
|
79
|
-
|
|
82
|
+
* One line each, in words the compile retry acts on. With `repick` (the agent's learning.repick), a top-level re-pick
|
|
83
|
+
* loop of the draft whose body is the host's pass marker is read as its pass 1 (learn/repick.ts repickMarked): the
|
|
84
|
+
* clone its pass 2 runs reads the pages by the owner's setting, the one page read on the agent's model a draft may
|
|
85
|
+
* hold, and only that exact clone at that place. */
|
|
86
|
+
export declare function compactStateProblems(doc: unknown, { repick }?: {
|
|
87
|
+
readonly repick?: boolean;
|
|
88
|
+
}): string[];
|
|
80
89
|
/** Why a draft's quote check is not code: its answer carries quotes (a `quote` or `quotes` property in its output schema)
|
|
81
90
|
* and it fetches pages (a call step), yet some place in the answer holding quotes has no escalate on quote_missing
|
|
82
91
|
* reading it after the answer is written (quoteRule), or that escalate reads as a page a key holding no page as fetched
|
package/dist/learn/check.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// host's secrets and of text shaped like one, and a field over PRINT_MAX is redacted whole.
|
|
5
5
|
import { placeholdersOf, placeholderValue } from "@parcha/agentrun-dsl";
|
|
6
6
|
import { hiddenCharacter } from "./invisible.js";
|
|
7
|
+
import { REPICK_PASSES, repickCheckOf, repickMarked } from "./repick.js";
|
|
7
8
|
import { learnedSecretShapes, redactLearned, valueMatcher } from "./secrets.js";
|
|
8
9
|
import { childNodes, draftProblems, decodedStrings, DECODED_DEPTH, DRY_RUN_FAILED, frontKeys, frontValues, LEARNED_KEYS, learnedPlace, readmeProblems, WORKFLOW_NAME, WORKFLOWS_DIR } from "./workflow-draft.js";
|
|
9
10
|
/** Byte caps (UTF-8). Over a cap is refused, never cut. */
|
|
@@ -182,9 +183,14 @@ function pagesRead(value, state, out = new Set(), depth = 0) {
|
|
|
182
183
|
* child sees an input key as a page when its value reads one. Pages reach a step on the agent's model only through a fast-tier step's
|
|
183
184
|
* output: chain14b's drafts fed whole pages to the answering step (4.1 requests a run at ~70k cached tokens each,
|
|
184
185
|
* $0.364 a served run), where the research shape (a fast extract's compact facts to the answering step) booked ~$0.08.
|
|
185
|
-
* One line each, in words the compile retry acts on.
|
|
186
|
-
|
|
186
|
+
* One line each, in words the compile retry acts on. With `repick` (the agent's learning.repick), a top-level re-pick
|
|
187
|
+
* loop of the draft whose body is the host's pass marker is read as its pass 1 (learn/repick.ts repickMarked): the
|
|
188
|
+
* clone its pass 2 runs reads the pages by the owner's setting, the one page read on the agent's model a draft may
|
|
189
|
+
* hold, and only that exact clone at that place. */
|
|
190
|
+
export function compactStateProblems(doc, { repick = false } = {}) {
|
|
187
191
|
const problems = new Set();
|
|
192
|
+
// The draft's own top-level marked loops alone (repickMarked): a marker in a composed child is read as written.
|
|
193
|
+
const marked = new Map(repick ? repickMarked(doc).map(({ loop, step }) => [loop, step]) : []);
|
|
188
194
|
const walk = (node, pages, depth) => {
|
|
189
195
|
const after = new Set(pages);
|
|
190
196
|
if (!isNode(node) || depth > 32)
|
|
@@ -233,14 +239,15 @@ export function compactStateProblems(doc) {
|
|
|
233
239
|
// until the marks stop changing. The set read grows on each further pass, so it stops within one pass a key the
|
|
234
240
|
// workflow names, and never past maxIters; each pass's way out holds the ones before it.
|
|
235
241
|
const passes = typeof node.maxIters === "number" && node.maxIters >= 1 ? Math.floor(node.maxIters) : Number.POSITIVE_INFINITY;
|
|
242
|
+
const body = marked.get(node) ?? node.body;
|
|
236
243
|
let read = after;
|
|
237
|
-
let out = walk(
|
|
244
|
+
let out = walk(body, read, depth + 1);
|
|
238
245
|
for (let pass = 2; pass <= passes; pass++) {
|
|
239
246
|
const next = new Set([...read, ...out]);
|
|
240
247
|
if (next.size === read.size)
|
|
241
248
|
break;
|
|
242
249
|
read = next;
|
|
243
|
-
out = walk(
|
|
250
|
+
out = walk(body, read, depth + 1);
|
|
244
251
|
}
|
|
245
252
|
return out;
|
|
246
253
|
}
|
|
@@ -493,11 +500,7 @@ export function quoteCheckProblems(doc) {
|
|
|
493
500
|
return isObject(doc) ? quoteRule(doc, {}).problems : [];
|
|
494
501
|
}
|
|
495
502
|
const siteKey = (site) => site.keys.join("\u0000");
|
|
496
|
-
/** The passes of a checked answer's re-pick loop: the draft, then one re-pick. */
|
|
497
|
-
const REPICK_PASSES = 2;
|
|
498
503
|
const quoteMissingText = ({ path, field, pages }) => `{"predicate": "quote_missing", "path": ${JSON.stringify(path)}${field ? `, "field": ${JSON.stringify(field)}` : ""}, "pages": ${JSON.stringify(pages)}}`;
|
|
499
|
-
/** The quote_missing a re-pick loop waits on: `step`'s, when it is a loop of REPICK_PASSES until `not` of a quote_missing. */
|
|
500
|
-
const repickCheckOf = (step) => isNode(step) && step.node === "loop" && step.maxIters === REPICK_PASSES && isObject(step.until) && step.until.predicate === "not" && isObject(step.until.of) && step.until.of.predicate === "quote_missing" ? step.until.of : undefined;
|
|
501
504
|
/** Whether `step` is the re-pick of an answer `check` reads: a loop of REPICK_PASSES until that check's quote_missing (its
|
|
502
505
|
* path, field and pages) no longer holds. */
|
|
503
506
|
const repickOn = (step, check) => {
|
|
@@ -677,7 +680,7 @@ function learnedChecked(change, place, refused, input, add) {
|
|
|
677
680
|
// (the SDK bridge's runNode picks every model itself: it names no tier), and its quote check to code.
|
|
678
681
|
if (!problems.length) {
|
|
679
682
|
const doc = JSON.parse(text);
|
|
680
|
-
const compact = input.workflowAdapters === undefined ? compactStateProblems(doc) : [];
|
|
683
|
+
const compact = input.workflowAdapters === undefined ? compactStateProblems(doc, { repick: input.repick === true }) : [];
|
|
681
684
|
problems.push(...[...answerTierProblems(doc), ...compact, ...quoteCheckProblems(doc)].map((detail) => ({ rule: "workflow", detail })));
|
|
682
685
|
}
|
|
683
686
|
for (const { rule, detail } of problems)
|
package/dist/learn/promote.d.ts
CHANGED
|
@@ -80,6 +80,10 @@ export interface PromotionRecord {
|
|
|
80
80
|
/** The learning commit whose workflows/<workflow>/workflow.json is this digest's text: the seed of the claim that
|
|
81
81
|
* recorded it. What the digest serves from as the champion (championOf) once a newer revision is on the folder's main. */
|
|
82
82
|
readonly commit?: string;
|
|
83
|
+
/** `sdk`: a connected (SDK) agent's check (runner/promotion.ts reserveSdkCheck), on its reservation and the record that
|
|
84
|
+
* decides it. Its one run (`runs`) is the agent's own native turn, not a replay run; a replaying one with no `runs`
|
|
85
|
+
* waits for the next native turn the draft takes. Absent: a server replay's. */
|
|
86
|
+
readonly via?: "sdk";
|
|
83
87
|
}
|
|
84
88
|
/** One audit row a hold was decided on that disagreed: the served run (`served`) and its input, the run whose answer is
|
|
85
89
|
* the agent's (`run`: the shadow run, else the served run for a grade), the agent's answer (`agent`: the shadow's, null
|
|
@@ -142,6 +146,13 @@ export type CheckRecord = CheckBar & {
|
|
|
142
146
|
readonly skipped_tools?: readonly SkippedTool[];
|
|
143
147
|
readonly disagreements?: readonly CheckDisagreement[];
|
|
144
148
|
readonly stopped?: true;
|
|
149
|
+
/** A connected agent's check: how many of its reserved native turns gave no answer to check the draft against (a
|
|
150
|
+
* cancelled or refused turn, a subagent, redacted evidence, no shadow report) and were given back to wait for the
|
|
151
|
+
* next one (runner/promotion.ts SDK_CHECK_RELEASES stops it). Absent: none. */
|
|
152
|
+
readonly released?: number;
|
|
153
|
+
/** A connected agent's check: how many fresh read-only calls its shadow made where the native turn's recording had
|
|
154
|
+
* no result (the client's opt-in shadowReadFallback). Absent: none, every call was answered from the recording. */
|
|
155
|
+
readonly fresh_reads?: number;
|
|
145
156
|
/** How it compared with no agree_on: the fast model that read the answers (its name), when it was asked on any input.
|
|
146
157
|
* With agree_on, the paths compared (CheckBar.agree_on); with neither, the whole answer. */
|
|
147
158
|
readonly grader?: string;
|
|
@@ -189,6 +200,12 @@ export declare const promotionsKey: (agentId: string) => string;
|
|
|
189
200
|
export declare const gradesOf: (settings: Pick<Settings, "get">, agentId: string) => Promise<Grade[]>;
|
|
190
201
|
/** Keeps `grade`, in place of any earlier grade of the same run, the newest GRADES_KEPT kept, at the next `seq`. */
|
|
191
202
|
export declare const putGrade: (settings: Pick<Settings, "get" | "putIfAbsent" | "replaceIf">, agentId: string, grade: Grade) => Promise<Grade>;
|
|
203
|
+
/** Every kept grade of run `runId` dropped (the run's delete, agent-delete.ts); no write when the agent keeps no grades. */
|
|
204
|
+
export declare const dropGrades: (settings: Pick<Settings, "get" | "putIfAbsent" | "replaceIf">, agentId: string, runId: string) => Promise<void>;
|
|
205
|
+
/** What agent `agentId`'s learning copied from run `runId`, gone (the run's purge, agent-delete.ts): its kept grades
|
|
206
|
+
* dropped (dropGrades), and its promotion records' disagreements naming it blanked (forgetRunIn), each record's decision,
|
|
207
|
+
* numbers and run ids kept. No write when nothing names it. */
|
|
208
|
+
export declare const forgetRunCopies: (settings: Pick<Settings, "get" | "putIfAbsent" | "replaceIf">, agentId: string, runId: string) => Promise<void>;
|
|
192
209
|
/** Marks the kept grade `grade` (its run, given at its `at`, kept at its `seq`) with the feedback round it opened and
|
|
193
210
|
* that round's steer, in place: its `seq` stays. A newer grade of the run is left as it is, one given in the same
|
|
194
211
|
* millisecond too (its `seq` is another). The grade, marked. */
|
|
@@ -342,7 +359,7 @@ export declare function comparedOf(value: unknown): Compared | undefined;
|
|
|
342
359
|
export declare const gradeView: (grade: Grade) => {
|
|
343
360
|
source: "feedback" | "eval";
|
|
344
361
|
graded_at: string;
|
|
345
|
-
path: "agent" | "workflow" | "replay" | "
|
|
362
|
+
path: "agent" | "workflow" | "replay" | "audit" | "handed_back";
|
|
346
363
|
workflow: string | null;
|
|
347
364
|
workflow_digest: string | null;
|
|
348
365
|
feedback: "correction" | null;
|