@parcha/agentrun-serve 0.1.0-beta.41 → 0.1.0-beta.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- package/NOTICE +2 -0
- package/README.md +77 -12
- package/dist/agent-rows.d.ts +1 -1
- package/dist/agents-store.js +3 -1
- package/dist/calendar/address.d.ts +49 -0
- package/dist/calendar/address.js +153 -0
- package/dist/calendar/fetch.d.ts +24 -0
- package/dist/calendar/fetch.js +146 -0
- package/dist/calendar/ics-faux.d.ts +39 -0
- package/dist/calendar/ics-faux.js +236 -0
- package/dist/calendar/labels.d.ts +3 -0
- package/dist/calendar/labels.js +61 -0
- package/dist/calendar/names.d.ts +52 -0
- package/dist/calendar/names.js +54 -0
- package/dist/calendar/parse.d.ts +108 -0
- package/dist/calendar/parse.js +625 -0
- package/dist/calendar/routes.d.ts +17 -0
- package/dist/calendar/routes.js +81 -0
- package/dist/calendar/tools.d.ts +23 -0
- package/dist/calendar/tools.js +124 -0
- package/dist/cli.js +3 -1
- package/dist/computer-record.d.ts +55 -0
- package/dist/computer-record.js +315 -0
- package/dist/computer-setting.d.ts +1 -0
- package/dist/computer-setting.js +15 -2
- package/dist/computers.js +2 -14
- package/dist/console/assets/index-DYJ_wj27.js +711 -0
- package/dist/console/index.html +1 -1
- package/dist/eval-feed.d.ts +2 -2
- package/dist/eval-feed.js +9 -5
- package/dist/feed/parse.d.ts +3 -2
- package/dist/feed/parse.js +9 -18
- package/dist/feed/pointer.d.ts +2 -0
- package/dist/feed/pointer.js +17 -0
- package/dist/file-types.js +1 -0
- package/dist/host-command.d.ts +3 -0
- package/dist/host-command.js +18 -0
- package/dist/host.d.ts +3 -0
- package/dist/host.js +3 -0
- package/dist/learn/check.d.ts +14 -0
- package/dist/learn/check.js +194 -14
- package/dist/learn/compile.d.ts +48 -27
- package/dist/learn/compile.js +134 -101
- package/dist/learn/promote.d.ts +61 -5
- package/dist/learn/promote.js +12 -2
- package/dist/learning-setting.d.ts +23 -0
- package/dist/learning-setting.js +51 -0
- package/dist/learning-words.d.ts +3 -0
- package/dist/learning-words.js +3 -0
- package/dist/learning.d.ts +3 -2
- package/dist/learning.js +5 -3
- package/dist/mcp-oauth.d.ts +8 -0
- package/dist/mcp-oauth.js +7 -0
- package/dist/mcp-private-hosts.d.ts +13 -0
- package/dist/mcp-private-hosts.js +16 -0
- package/dist/openapi.d.ts +1 -0
- package/dist/openapi.js +105 -9
- package/dist/run-files.d.ts +6 -2
- package/dist/run-files.js +29 -7
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/run-reads-over-store.d.ts +5 -1
- package/dist/run-reads-over-store.js +8 -4
- package/dist/run-recordings.d.ts +20 -0
- package/dist/run-recordings.js +133 -0
- package/dist/runner/adapter-loop.d.ts +1 -1
- package/dist/runner/adapter-loop.js +3 -6
- package/dist/runner/adapter-run-spec.d.ts +16 -1
- package/dist/runner/adapter-run-spec.js +20 -6
- package/dist/runner/beside.js +1 -1
- package/dist/runner/cli-run-spec.js +10 -7
- package/dist/runner/feedback-round.d.ts +9 -25
- package/dist/runner/feedback-round.js +22 -40
- package/dist/runner/learning-end.d.ts +17 -7
- package/dist/runner/learning-end.js +79 -53
- package/dist/runner/main.d.ts +11 -0
- package/dist/runner/main.js +29 -2
- package/dist/runner/mcp-run.d.ts +2 -2
- package/dist/runner/promotion.d.ts +36 -4
- package/dist/runner/promotion.js +280 -20
- package/dist/runner/reflect-hook.d.ts +5 -0
- package/dist/runner/reflect-hook.js +22 -14
- package/dist/runner/store-secrets.js +3 -1
- package/dist/runner/workflow-first.d.ts +0 -6
- package/dist/runner/workflow-first.js +7 -13
- package/dist/runs-over-store.d.ts +1 -1
- package/dist/sdk/runs.js +2 -1
- package/dist/secrets.js +2 -2
- package/dist/server.d.ts +4 -3
- package/dist/server.js +72 -11
- package/dist/store/agent-body.d.ts +5 -3
- package/dist/store/agent-body.js +14 -10
- package/dist/store-reads/learning.d.ts +1 -1
- package/dist/store-reads/loop.d.ts +1 -0
- package/dist/store-reads/loop.js +14 -4
- package/dist/store-view.d.ts +5 -0
- package/dist/store-view.js +4 -0
- package/dist/template-eval.d.ts +7 -0
- package/dist/template-eval.js +54 -6
- package/dist/templates.d.ts +3 -1
- package/dist/templates.js +14 -1
- package/dist/timeline/computer.js +2 -1
- package/dist/tool-list.js +1 -0
- package/dist/tools.d.ts +7 -0
- package/dist/tools.js +11 -0
- package/dist/trigger-feed.js +67 -18
- package/dist/validate.js +7 -2
- package/dist/workspace/computer-for-claim.d.ts +7 -0
- package/dist/workspace/computer-for-claim.js +12 -2
- package/dist/workspace/paths.d.ts +4 -0
- package/dist/workspace/paths.js +9 -0
- package/dist/workspace/resolve-computer.d.ts +3 -1
- package/launcher/agentrun-serve +31 -24
- package/package.json +10 -9
- package/templates/README.md +11 -2
- package/dist/console/assets/index-COGhx_2Z.js +0 -711
package/dist/openapi.js
CHANGED
|
@@ -37,6 +37,9 @@ import "./mcp-secret-writes.js";
|
|
|
37
37
|
// The email account's routes (email/routes.ts), each marked x-agentrun-secret whole, registered with the one gate as it
|
|
38
38
|
// loads: the view among them, so the API token never reads the account.
|
|
39
39
|
import "./email/routes.js";
|
|
40
|
+
// The calendar's routes (calendar/routes.ts), each marked x-agentrun-secret whole, registered the same way: the view
|
|
41
|
+
// among them, so the API token never reads which calendar is saved.
|
|
42
|
+
import "./calendar/routes.js";
|
|
40
43
|
import { MCP_SETTINGS_PAGE } from "./mcp-oauth.js";
|
|
41
44
|
import { ATTEMPTS_KEPT, MESSAGE_TYPES, WEBHOOK_EVENTS } from "./webhooks.js";
|
|
42
45
|
import { DEFAULT_SCHEME, SCHEME_NAMES, SIGNATURE_SCHEMES } from "./trigger-signatures.js";
|
|
@@ -232,6 +235,20 @@ const EMAIL_ACCOUNT_BODY = {
|
|
|
232
235
|
};
|
|
233
236
|
/** One half of an email account test. */
|
|
234
237
|
const MAIL_CHECK = closed({ ok: { type: "boolean" }, message: { type: "string", description: "In plain words: \"Signed in to <host>.\", with INBOX's count for IMAP, or why not." } });
|
|
238
|
+
/** GET and PUT /settings/calendar's answer (calendar/address.ts calendarView): the calendar, never its address. */
|
|
239
|
+
const CALENDAR_VIEW = closed({
|
|
240
|
+
configured: { type: "boolean", description: "A calendar is saved and its address opens with this server's seal key: calendar_events reads it." },
|
|
241
|
+
host: { type: ["string", "null"], description: "The host its address reads from (calendar.google.com), never the address." },
|
|
242
|
+
name: { type: ["string", "null"], description: "The calendar's own name (its X-WR-CALNAME), as the save read it; null when that read failed or it has none." },
|
|
243
|
+
time_zone: { type: ["string", "null"], description: "The calendar's own time zone (its X-WR-TIMEZONE, else the server's), as the save read it; null when that read failed." },
|
|
244
|
+
}, "The server's one calendar, never its iCal address.");
|
|
245
|
+
/** PUT /settings/calendar's and POST /settings/calendar/test's body: the calendar's iCal address. */
|
|
246
|
+
const CALENDAR_BODY = {
|
|
247
|
+
type: "object", additionalProperties: false,
|
|
248
|
+
properties: {
|
|
249
|
+
url: { type: "string", minLength: 1, maxLength: 2048, "x-agentrun-secret": true, description: "The calendar's secret iCal address (https://… or webcal://…, read as https://): Google Calendar's \"Secret address in iCal format\", Outlook's ICS link, iCloud's public calendar link. Sealed, never answered or shown again." },
|
|
250
|
+
},
|
|
251
|
+
};
|
|
235
252
|
/** GET /settings/chatgpt's answer (chatgpt-plan.ts PlanView): the sign-in's state, never a token. */
|
|
236
253
|
const CHATGPT_SIGN_IN = {
|
|
237
254
|
type: "object", additionalProperties: false, required: ["state"],
|
|
@@ -1164,7 +1181,7 @@ const GRADE_FIELDS = {
|
|
|
1164
1181
|
path: { enum: [...RUN_PATHS], description: "The path the run took, read from its record when it was graded." },
|
|
1165
1182
|
workflow: { ...NULL_STRING, description: "The learned workflow that served it, when one did." },
|
|
1166
1183
|
workflow_digest: { ...NULL_STRING, description: "That workflow's digest (the first 16 hex of its workflow.json's sha256), when it was served first." },
|
|
1167
|
-
feedback: { enum: [...FEEDBACK_ROUNDS, null], description: "What the grade asked of the run's learning, a round the run opened again on (no turn of the job's: its end-of-run turn alone, learning spend): `
|
|
1184
|
+
feedback: { enum: [...FEEDBACK_ROUNDS, null], description: "What the grade asked of the run's learning, a round the run opened again on (no turn of the job's: its end-of-run turn alone, learning spend): `look_back`, a run the agent finished graded with a `label`, a look-back on it. null: nothing more (a grade of a run its learned workflow answered alone, right or wrong, is kept and costs $0: the workflow's graded hold reads it), or a run that does not learn or that can't be opened again. Kept with the grade once the round opened, so a later read still says it." },
|
|
1168
1185
|
};
|
|
1169
1186
|
const RUN_LEARNING = {
|
|
1170
1187
|
oneOf: [
|
|
@@ -1248,7 +1265,7 @@ const LEARNING_COST = closed({
|
|
|
1248
1265
|
workflows: { type: "array", items: closed({
|
|
1249
1266
|
workflow: { type: "string", description: "The learned workflow, by name." },
|
|
1250
1267
|
digest: { type: "string", description: "The version of it its newest run served first ran: the first 16 hex characters of its workflow.json's sha256. A new version starts its count from zero." },
|
|
1251
|
-
state: { enum: ["serving", "needs_revision"], description: `\`serving\`: it runs first on every run it fits. \`needs_revision\`: over its newest ${COST_WINDOW} priced runs served at this version, its mean all-in cost (\`served\`) is at or over the agent's cost by hand (\`by_hand\`), so it no longer runs first
|
|
1268
|
+
state: { enum: ["serving", "needs_revision"], description: `\`serving\`: it runs first on every run it fits. \`needs_revision\`: over its newest ${COST_WINDOW} priced runs served at this version, its mean all-in cost (\`served\`) is at or over the agent's cost by hand (\`by_hand\`), so it no longer runs first: the agent takes each run it would have served, and the stop asks for no new version. A new version (a new digest) runs first again.` },
|
|
1252
1269
|
served: COST_MEAN(`The mean all-in cost (\`total_usd\`: the run's own cost, the workflow's nodes and, after a handback, the agent's work, with every learning round booked for it) of its newest ${COST_WINDOW} runs served first at this version whose all-in cost is known (a window, never how many runs it served: \`runs\` stops at ${COST_WINDOW}); null when none is.`),
|
|
1253
1270
|
by_hand: COST_MEAN("The agent's cost by hand: the mean all-in cost (`total_usd`) of its runs on the `agent` path whose all-in cost is known or, with none, of its runs before the workflow first ran; null when there are none: the workflow then keeps serving."),
|
|
1254
1271
|
unknown_cost_runs: { ...COUNT, description: "How many runs `served` and `by_hand` would have read have no known all-in cost: left out of their means, never read as 0." },
|
|
@@ -1300,6 +1317,7 @@ const REPLAY_SCORE = {
|
|
|
1300
1317
|
handed_back: { ...COUNT, description: "How many of them it handed back; it answered `n` - `handed_back` alone. A revision that answered none alone is held: it would never serve." },
|
|
1301
1318
|
};
|
|
1302
1319
|
/** A replay's runs' outcomes, the one count of them: on its promotion record (`replay.outcomes`) and its read. */
|
|
1320
|
+
const SKIPPED_TOOLS = { type: "array", items: closed({ tool: { type: "string", description: "The tool's catalog name." }, inputs: { ...COUNT, description: "How many skipped inputs it stopped." }, no_read_only_hint: { type: "boolean", description: "An MCP tool its server lists with no `readOnlyHint` (and not `destructiveHint`): replay treats it as a write only because nothing says it reads. The hold's `reason` names these: if they only read, mark them read-only in the MCP server and the next replay runs them." } }), description: "The tools that stopped its skipped inputs, most inputs first." };
|
|
1303
1321
|
const REPLAY_OUTCOMES = closed({
|
|
1304
1322
|
answered: { ...COUNT, description: "Replay runs the workflow answered alone, as each run did (guards read record-only: one answered under a guard's threshold counts here, and the score hands it back)." },
|
|
1305
1323
|
handed_back: { ...COUNT, description: "Replay runs it handed back on." },
|
|
@@ -1311,10 +1329,26 @@ const PROMOTION = closedWith({
|
|
|
1311
1329
|
digest: { type: "string", description: "The revision the record decides: the first 16 hex of its workflow.json's sha256." },
|
|
1312
1330
|
at: DATE_TIME,
|
|
1313
1331
|
decided: { enum: ["promote", "hold", "replaying", "queued", "skipped"], description: "`promote`: it serves first on the runs it fits. `hold`: it does not; the champion (the revision promoted last) takes them, else the agent, until a new revision. `replaying`: its replay runs are at work; the champion serves meanwhile, else the agent. `queued`: it came while another revision replayed; one revision replays at a time and a running replay finishes, so it replays next, at the first run's claim once that replay is decided (the finished replay's verdict stands). `skipped`: a newer revision (`skipped_by`) came while it was queued; only the newest queued revision replays next, so it never replayed and never serves." },
|
|
1314
|
-
source: { enum: ["replay", "dry_run", "refit", "graded"], description: `\`replay\`: decided on a replay of it on the agent's last ${REPLAY_INPUTS} graded inputs it fits, or those its owner asked for (POST .../revisions/{digest}/replays). \`dry_run\`: fewer than ${REPLAY_MIN} graded inputs, promoted on its passing dry run. \`refit\`: a threshold refit wrote this revision, decided on the rows it was fit on. \`graded\`: the graded runs it served fell more than ${PROMOTE_BAR * 100} points under the agent's accuracy by hand.` },
|
|
1332
|
+
source: { enum: ["check", "replay", "dry_run", "refit", "graded"], description: `\`check\`: decided by its one check, a replay of it on the inputs of the agent's last \`compile_after\` completed runs scored against the agent's own recorded answers (\`check\` holds the numbers); a revision's first claim starts it. \`replay\`: decided on a replay of it on the agent's last ${REPLAY_INPUTS} graded inputs it fits, or those its owner asked for (POST .../revisions/{digest}/replays). \`dry_run\`: fewer than ${REPLAY_MIN} graded inputs, promoted on its passing dry run. \`refit\`: a threshold refit wrote this revision, decided on the rows it was fit on. \`graded\`: the graded runs it served fell more than ${PROMOTE_BAR * 100} points under the agent's accuracy by hand.` },
|
|
1315
1333
|
reason: { type: "string", description: "Why, in words, with the numbers." },
|
|
1316
1334
|
}, {
|
|
1317
|
-
|
|
1335
|
+
check: closedWith({
|
|
1336
|
+
compile_after: { type: "integer", minimum: 1, description: "The agent definition's `learning.compile_after` when the check began: how many of the agent's newest completed runs it read inputs from." },
|
|
1337
|
+
agree_min: { type: "number", minimum: 0, maximum: 1, description: "The bar on agreement: of the inputs it answered alone, the least share that must say what the agent's recorded answer said." },
|
|
1338
|
+
alone_min: { type: "number", minimum: 0, maximum: 1, description: "The bar on answering alone: the least share of the inputs it ran on that it must answer with no escalate and no failed step." },
|
|
1339
|
+
attempt: { enum: [1, 2], description: "1: the compile's first check. 2: the check of its one recompile, after the first held it; held again, it stops (`stopped`)." },
|
|
1340
|
+
}, {
|
|
1341
|
+
n: { ...COUNT, description: "The inputs it ran on (a replay stopped at a write is none; one never created, or not ended, by the check's deadline counts, as failed). 0 with nothing to run on: never promoted, it stops (`stopped`) and `reason` says why." },
|
|
1342
|
+
agreed: { ...COUNT, description: "How many of them it answered alone with the agent's recorded answer." },
|
|
1343
|
+
alone: { ...COUNT, description: "How many of them it answered alone. Promoted when `alone`/`n` >= `alone_min` and `agreed`/`alone` >= `agree_min`." },
|
|
1344
|
+
of: { type: "array", items: { type: "string" }, description: "The agent's runs whose inputs it ran on, newest first." },
|
|
1345
|
+
cost_usd: { type: ["number", "null"], minimum: 0, description: "What its replay runs cost together; null when one's cost is unknown." },
|
|
1346
|
+
outcomes: REPLAY_OUTCOMES,
|
|
1347
|
+
skipped_tools: SKIPPED_TOOLS,
|
|
1348
|
+
disagreements: { type: "array", items: closedWith({ run: { type: "string" }, input: { type: "string", description: "The run's input, as text or JSON, cut at 1200 characters." }, agent: NULL_STRING }, { draft: { type: "string", description: "What it answered instead." }, escalated: { type: "string", description: "Why it handed the input back." }, failed: { const: true, description: "A step failed on it, or its run was still at work past the check's deadline, or never created by then." } }), description: "On a hold: each input it did not agree on, which the agent's next run reads as data in its one recompile." },
|
|
1349
|
+
stopped: { const: true, description: "The recompile's check held it too, or there was nothing to check it on (no input of the agent's it takes, or every input skipped at a write: `n` 0, `reason` starting \"nothing to check it on\", which asks no recompile): nothing compiles again until a hold or its owner acts; the agent keeps the runs." },
|
|
1350
|
+
}),
|
|
1351
|
+
replay: { ...closedWith(REPLAY_SCORE, { of: { type: "array", items: { type: "string" }, description: "The graded runs replayed." }, cost_usd: { type: ["number", "null"], minimum: 0, description: "What its replay runs cost together; null when one's cost is unknown." }, skipped_tools: SKIPPED_TOOLS, outcomes: REPLAY_OUTCOMES }), description: "The numbers it was decided on. A replay runs each read live (through a cache seeded from the graded run's recorded calls) and answers each write from that recording, never sending one." },
|
|
1318
1352
|
runs: { type: "array", items: { type: "string" }, description: "Its replay runs (path `replay`)." },
|
|
1319
1353
|
inputs: { type: "array", items: { type: "string" }, description: "On a replaying record: the graded run each of `runs` replays, in the same order. Its runs are reserved before they are created; one not created a few minutes on is created by the next claim." },
|
|
1320
1354
|
replay_id: { type: "string", description: "The replay's id, on its replaying record and the one that decided it: GET .../revisions/{digest}/replays/{replay_id} reads it, whether a run's claim or its owner started it." },
|
|
@@ -1368,9 +1402,9 @@ const LEARNING_EXTENSIONS = {
|
|
|
1368
1402
|
"/runs/{run_id}/grade": {
|
|
1369
1403
|
put: {
|
|
1370
1404
|
operationId: "gradeRun", tags: ["runs"], summary: "Grade an ended run's answer: right or wrong, and the fields a right answer holds",
|
|
1371
|
-
description: `A person's feedback or an eval's label on a run that ended, kept for its agent (one grade a run: a later one replaces it; the newest ${GRADES_KEPT} are kept). Promotion by replay reads them: a learned workflow's new revision serves first only after a replay on the agent's last ${REPLAY_INPUTS} graded inputs it fits is within ${PROMOTE_BAR * 100} points of the agent's own answers on them; with fewer than ${REPLAY_MIN}, on its passing dry run. With \`expected\`, a replay's answer is right when its JSON holds each of those fields; else when it says what the graded answer said. A replay run is never graded. The run's path never changes on a grade: a
|
|
1405
|
+
description: `A person's feedback or an eval's label on a run that ended, kept for its agent (one grade a run: a later one replaces it; the newest ${GRADES_KEPT} are kept). Promotion by replay reads them: a learned workflow's new revision serves first only after a replay on the agent's last ${REPLAY_INPUTS} graded inputs it fits is within ${PROMOTE_BAR * 100} points of the agent's own answers on them; with fewer than ${REPLAY_MIN}, on its passing dry run. With \`expected\`, a replay's answer is right when its JSON holds each of those fields; else when it says what the graded answer said. A replay run is never graded. The run's path never changes on a grade: a grade of a run its learned workflow answered alone, right or wrong, is kept and nothing more ($0; the workflow's graded hold reads it, and only a hold asks for its revision); a run the agent finished, graded with a \`label\`, opens again on a look-back on it. That round asks the agent no turn of the job's, only its end-of-run turn, and its spend is the run's learning (\`feedback\`).`,
|
|
1372
1406
|
parameters: [ref("parameters/RunId")],
|
|
1373
|
-
requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, required: ["correct"], properties: { correct: { type: "boolean" }, expected: { type: "object", description: "The fields a right answer's JSON holds." }, source: { enum: [...GRADE_SOURCES], default: "feedback" }, label: { type: "string", maxLength: LABEL_MAX, description: "The grade's words (a teacher's label, a reviewer's note): what the run's look-back
|
|
1407
|
+
requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, required: ["correct"], properties: { correct: { type: "boolean" }, expected: { type: "object", description: "The fields a right answer's JSON holds." }, source: { enum: [...GRADE_SOURCES], default: "feedback" }, label: { type: "string", maxLength: LABEL_MAX, description: "The grade's words (a teacher's label, a reviewer's note): what the run's look-back reads." } } } } } },
|
|
1374
1408
|
responses: { "200": json(GRADE, "The run's grade."), ...errors(400, 401, 404, 429, 500) },
|
|
1375
1409
|
"x-agentrun-serve": "promotion/1",
|
|
1376
1410
|
},
|
|
@@ -1382,6 +1416,7 @@ const LEARNING_EXTENSIONS = {
|
|
|
1382
1416
|
parameters: [AGENT_ID],
|
|
1383
1417
|
responses: { "200": json(closed({
|
|
1384
1418
|
agent: { type: "string" },
|
|
1419
|
+
completed_runs: { ...COUNT, description: "The agent's completed runs of its own (never one a learned workflow answered alone, a replay, an imported or an archived run) toward its first compile, at most its definition's `learning.compile_after`." },
|
|
1385
1420
|
compiles: { type: "array", items: closed({
|
|
1386
1421
|
run_id: { type: "string", description: "The run whose end compiled it." },
|
|
1387
1422
|
round: { type: "integer", minimum: 1, description: "The run's round that compiled it: 1 its first end, more for an end after a follow-up opened it again." },
|
|
@@ -1391,7 +1426,7 @@ const LEARNING_EXTENSIONS = {
|
|
|
1391
1426
|
attempts: { type: "array", items: closed({ ok: { type: "boolean" }, errors: { type: "array", items: { type: "string" } } }), description: "Each attempt in order: whether its checks and dry run passed, and what they refused." },
|
|
1392
1427
|
digest: { ...NULL_STRING, description: "The kept draft's digest; null when none passed." },
|
|
1393
1428
|
promoted: { type: ["boolean", "null"], description: "Whether that revision was promoted, as its records say now: true promoted (or a refit of it was), false held or skipped, null queued, undecided or none passed. It may no longer serve: the promotions read's \`serving\` says which revision does." },
|
|
1394
|
-
draft_errors: { type: "array", items: { type: "string" }, description: "A draft that never passed: its last errors.
|
|
1429
|
+
draft_errors: { type: "array", items: { type: "string" }, description: "A draft that never passed: its last errors. A draft its check had nothing to run on (its promotion `check.stopped` with `n` 0): its record's reason, starting \"nothing to check it on\". Empty otherwise." },
|
|
1395
1430
|
withheld: { type: "boolean", description: "The run's handed values can't be read here: its error texts are left out (the counts stand)." },
|
|
1396
1431
|
}), description: "Newest first." },
|
|
1397
1432
|
guards: { type: "array", items: closed({
|
|
@@ -2142,6 +2177,44 @@ const EXTENSIONS = {
|
|
|
2142
2177
|
"x-agentrun-serve": "email/1",
|
|
2143
2178
|
},
|
|
2144
2179
|
},
|
|
2180
|
+
"/settings/calendar": {
|
|
2181
|
+
get: {
|
|
2182
|
+
operationId: "getCalendar", tags: ["local"], summary: "This server's calendar: its host, name and time zone, never its address",
|
|
2183
|
+
description: "The one calendar calendar_events reads. The owner's signed-in session alone (ownerSession), never the token, which is 403 forbidden in words.",
|
|
2184
|
+
"x-agentrun-secret": true,
|
|
2185
|
+
security: [{ ownerSession: [] }],
|
|
2186
|
+
responses: { "200": json(CALENDAR_VIEW, "The calendar."), ...errors(401, 403, 429, 500) },
|
|
2187
|
+
"x-agentrun-serve": "calendar/1",
|
|
2188
|
+
},
|
|
2189
|
+
put: {
|
|
2190
|
+
operationId: "saveCalendar", tags: ["local"], summary: "Save this server's calendar, its iCal address sealed",
|
|
2191
|
+
description: "Replaces the calendar. The address is https (webcal:// is read as https://; plain http, another scheme, or a user and password in it is refused in words), sealed under the server's seal key, and in no answer, event, log line or run input. The calendar is read once for its own name and time zone; a read that fails saves the address all the same (name and time_zone null): POST /settings/calendar/test says why. 422 by field for a body that does not read. A secret write: the owner's signed-in session alone (ownerSession), never the token, which is 403 forbidden in words.",
|
|
2192
|
+
"x-agentrun-secret": true,
|
|
2193
|
+
security: [{ ownerSession: [] }],
|
|
2194
|
+
requestBody: { required: true, content: { "application/json": { schema: { ...CALENDAR_BODY, required: ["url"] } } } },
|
|
2195
|
+
responses: { "200": json(CALENDAR_VIEW, "Saved."), ...errors(400, 401, 403, 415, 422, 429, 500, 503) },
|
|
2196
|
+
"x-agentrun-serve": "calendar/1",
|
|
2197
|
+
},
|
|
2198
|
+
delete: {
|
|
2199
|
+
operationId: "deleteCalendar", tags: ["local"], summary: "Forget this server's calendar",
|
|
2200
|
+
description: "Removes the calendar and its sealed address. calendar_events then answers that no calendar is saved. A secret write: the owner's signed-in session alone (ownerSession), never the token, which is 403 forbidden in words.",
|
|
2201
|
+
"x-agentrun-secret": true,
|
|
2202
|
+
security: [{ ownerSession: [] }],
|
|
2203
|
+
responses: { "204": { description: "Forgotten." }, ...errors(401, 403, 429, 500) },
|
|
2204
|
+
"x-agentrun-serve": "calendar/1",
|
|
2205
|
+
},
|
|
2206
|
+
},
|
|
2207
|
+
"/settings/calendar/test": {
|
|
2208
|
+
post: {
|
|
2209
|
+
operationId: "testCalendar", tags: ["local"], summary: "Read the calendar and say what it holds",
|
|
2210
|
+
description: "Reads the saved calendar with an empty body, or the address in the body (saved nowhere), as calendar_events reads it (https only; a private address refused unless its host is allowed in Settings → MCP servers; 10 MB, 20 s, 5 redirects), and answers in words: \"Work: 214 events, time zone America/New_York, next: Standup, Mon Nov 17 09:30\" (its name, its events and series, its time zone, and its next event in the next 62 days), or why it couldn't be read, never the address. 422 for a body that does not read, or an empty body with no calendar saved. A secret write: the owner's signed-in session alone (ownerSession), never the token, which is 403 forbidden in words.",
|
|
2211
|
+
"x-agentrun-secret": true,
|
|
2212
|
+
security: [{ ownerSession: [] }],
|
|
2213
|
+
requestBody: { required: false, content: { "application/json": { schema: CALENDAR_BODY } } },
|
|
2214
|
+
responses: { "200": json(closed({ ok: { type: "boolean", description: "The calendar was read." }, message: { type: "string", description: "In plain words: what it holds, or why it couldn't be read." } }), "The test's answer."), ...errors(400, 401, 403, 415, 422, 429, 500) },
|
|
2215
|
+
"x-agentrun-serve": "calendar/1",
|
|
2216
|
+
},
|
|
2217
|
+
},
|
|
2145
2218
|
"/settings/chatgpt": {
|
|
2146
2219
|
get: {
|
|
2147
2220
|
operationId: "getChatGPTSignIn", tags: ["local"], summary: "This server's ChatGPT sign-in: its state, who and which plan, never a token",
|
|
@@ -2886,6 +2959,18 @@ const FIELD_EXTENSIONS = {
|
|
|
2886
2959
|
description: "While a message the run took is still open (an agentic run, working or queued): when its turn last wrote anything, a request's start included; it holds still while a tool or a model request runs, and moves as the turn writes. Null once every message has had its turn, and on a workflow run.",
|
|
2887
2960
|
"x-agentrun-serve": "turnend/1",
|
|
2888
2961
|
},
|
|
2962
|
+
recordings: {
|
|
2963
|
+
type: "array",
|
|
2964
|
+
items: closed({
|
|
2965
|
+
path: { type: "string", description: "Where it is read: `GET /runs/{run_id}/files/{path}` with this path (`recordings/<computer>.mp4`), `video/mp4`, its byte ranges answered; `?download=1` for an attachment." },
|
|
2966
|
+
computer: { type: "string", description: "The computer it recorded: its id, as the file is named. A computer's later files (a resumed run's, a phone's frames that changed format) are `<computer>-2.mp4` and on." },
|
|
2967
|
+
seconds: { type: "number", minimum: 0, description: "How long it plays, to a tenth of a second, as far as it is written." },
|
|
2968
|
+
bytes: { type: "integer", minimum: 0, description: "Its size now." },
|
|
2969
|
+
finished: { type: "boolean", description: "false while it is still being written: it plays up to its last whole fragment. true once its recording stopped, and for every file once the run has ended and the file has stopped changing (a few seconds after the end)." },
|
|
2970
|
+
}, "One video of a computer's screen during the run (H.264 in fragmented MP4)."),
|
|
2971
|
+
description: "On the run read (and an archive's or unarchive's answer) alone, never in a list: the videos of the run's screen, where its agent's computer says `record: true` (a desktop or a phone), each computer's files in the order they were recorded; empty when nothing was recorded, and for a run whose words are withheld. Read from the files on the machine whose runner recorded them. The video shows everything on the screen: see the agent's `computer.record`.",
|
|
2972
|
+
"x-agentrun-serve": "runvideo/1",
|
|
2973
|
+
},
|
|
2889
2974
|
input: {
|
|
2890
2975
|
type: ["object", "null"],
|
|
2891
2976
|
additionalProperties: true,
|
|
@@ -3070,13 +3155,18 @@ const FIELD_EXTENSIONS = {
|
|
|
3070
3155
|
persistent: { type: "boolean", description: "Whether the agent keeps its own computer between runs: true makes one at its first run, detaches it (not deletes it) at each run's end, and attaches it again at the next, with what was on it; false or absent, a fresh computer for each run. Only where the provider keeps one for the kind and image (GET /computers: the provider's `persistent`), else 422 not_allowed; never one that mounts the run's folder. One run at a time: a run that finds the computer held by another run still going is refused at its start, naming that run. Archiving the agent, turning this off, or a setting on another provider or image deletes the computer (GET /agents/{agent_id}'s `own_computer` shows it)." },
|
|
3071
3156
|
surface: { enum: ["code", "tools"], description: "How the agent drives a desktop or a phone. `code`: by `codemode` scripts alone, whose `tools.computer_observe`, `tools.computer_act` and `tools.computer_screenshot` are each a gated, recorded call of its own; the model is offered `codemode` and the hand-over (`computer_request_handoff`), not the step tools (a harness with its own code mode, Codex, is still handed them). `tools`: the step tools and the hand-over, listed; a `codemode` script calls them too. Absent, as `tools`. Only a desktop or a phone takes it (422 not_allowed on another kind)." },
|
|
3072
3157
|
exec: { type: "boolean", description: "`false`: the agent gets no shell and starts no program on its desktop or phone. Its computer's `exec` and `processes` groups are taken out of what its tools and scripts see (no `computer.shell`, no `computer.processes`; a script that reaches for one is refused in words), no folder is mounted in the computer, and the run gets no `bash` or background tool, wherever its folder is. The run's own computer channel (`POST /runs/{run_id}/computer/call`, the owner's) keeps every group. `true` or absent: as the computer offers. Only a desktop or a phone takes it (422 not_allowed on another kind)." },
|
|
3158
|
+
record: { type: "boolean", description: "`true`: each run records a video of its desktop's or phone's screen (H.264, fragmented MP4, at most 10 frames a second and 1280 pixels on the long side, no audio) into its run folder's `recordings/`, beside `work/`, where the agent can neither read nor change it. The video shows everything on the screen, including whatever a person types while they take over and any secret that appears on screen; pixels can't be redacted the way the run's logs are. It records while the run holds the computer, with or without a viewer, pauses while the run is parked (a resumed run goes on in a new file) and stops at the computer's release, the run's end, or its cap (500 MB across the run's files, or 2 hours from its start or the run's resume), which the run's timeline says. A server without ffmpeg refuses it (422 not_allowed). `false` or absent: nothing is recorded. Only a desktop or a phone takes it (422 not_allowed on another kind)." },
|
|
3073
3159
|
},
|
|
3074
|
-
description: "The computer the revision's runs are given (Settings → Computers): its kind, the provider that serves it, the image it starts from, a sandbox's GPUs, whether the agent keeps it between runs, and, for a desktop or a phone, how the agent drives it
|
|
3160
|
+
description: "The computer the revision's runs are given (Settings → Computers): its kind, the provider that serves it, the image it starts from, a sandbox's GPUs, whether the agent keeps it between runs, and, for a desktop or a phone, how the agent drives it, whether it may run programs on it and whether its runs record its screen. `place` is its v2 view where it can say it: `{kind: none}` is `place {mode: runner}`, `{kind: sandbox, provider: X}` is `place {mode: sandbox, box: X}`; a desktop, phone or browser computer leaves the run's folder on the runner, so its place reads runner. Writing either sets both, and both given must agree (422). Absent on a create, the server's default (as `place`); an edit that names neither keeps the agent's.",
|
|
3075
3161
|
"x-agentrun-serve": "computer/1",
|
|
3076
3162
|
},
|
|
3077
3163
|
tool_settings: { ...AGENT_TOOL_SETTINGS, description: "The agent's own tool settings (web_search's, web_fetch's and browser's provider, any tool's permission, an MCP server's wildcard mcp:<server>/*, an MCP tool's pin, bash's policy), over the server's (GET /settings/tools), except a deny set on the server, which is absolute: the tool is refused on this server whatever this agent sets; absent, the server's. A pin is not over the server's: both hold. A grant in tools names the capability, never a provider.", "x-agentrun-serve": "providers/1" },
|
|
3078
3164
|
approvals: { enum: ["ask", "never"], default: "ask", description: "Whether the agent's runs ask a person or run unattended. `ask`, the default: a tool set to ask parks the run for an approval, as its tool settings say. `never`: the agent runs unattended, and each tool that would ask is allowed instead, decided by the tool gate at each call, so a tool granted later and an MCP tool (`mcp:<server>/<tool>`, which asks by default) are covered on every harness. It never lifts a deny, whether set on this server or in the agent's own tool_settings, nor a pin, nor anything else the gate refuses before it decides between running and asking. A workflow's call node on a tool set to ask runs under `never`. Absent on a request: ask. An edit that leaves it out asks, so no edit makes an agent unattended by saying nothing. Every answer names it.", "x-agentrun-serve": "unattended/1" },
|
|
3079
|
-
learning: { enum: [true, false, "notes"]
|
|
3165
|
+
learning: { oneOf: [{ enum: [true, false, "notes"] }, { type: "object", additionalProperties: false, properties: {
|
|
3166
|
+
compile_after: { type: "integer", minimum: 1, maximum: 200, default: 20, description: "The job compiles into a learned workflow once the agent has this many completed runs of its own." },
|
|
3167
|
+
agree_min: { type: "number", minimum: 0, maximum: 1, default: 0.8, description: "The draft's one check replays it on the inputs of those runs: promoted only when, of the inputs it answered alone, at least this share say what the agent's own recorded answer said." },
|
|
3168
|
+
alone_min: { type: "number", minimum: 0, maximum: 1, default: 0.7, description: "...and only when it answered at least this share of them alone (no escalate, no failed step). Under either bar it is recompiled once with the inputs it did not agree on, checked the same way, then promoted or stopped: nothing compiles again." },
|
|
3169
|
+
} }], default: false, description: "Whether an agentic revision's runs learn, and what: `true`, notes, skills and learned workflows; an object, the same with the loop's numbers set on it (`compile_after`, `agree_min`, `alone_min`, each optional: one left out is its default; `true` is every default); `\"notes\"`, notes and skills alone (a run is never given a learned workflow nor asked to draft one); `false`, nothing. A run that learns starts from what its agent has learned, its notes in its instructions under `# Learned` (each whole within the server's learning budget, else the index and the notes changed last, whole) and in `.learning/` in its working directory, and once it answers or fails is asked one more turn to add notes there, which are checked, graded and merged. Kept when a definition says so, true, false, `\"notes\"` or an object (its numbers in one order); a number out of range or an unknown key is a 422 `wrong_type`; absent, off, and an answer shows none. An edit that leaves it out keeps the agent's. A workflow revision keeps none. On a server whose learning is off (`capabilities.features.learning`), no run learns, whatever this says.", "x-agentrun-serve": "learning/1" },
|
|
3080
3170
|
checkout: { enum: ["pull_request", "none"], description: "What the server checks out in each run's folder before its first turn, an agentic definition's alone. `pull_request`: the pull request the run's GitHub event names (a GitHub trigger's firing: its repository, number, head and base), at its head, detached, in `repo/`, with its base and their merge base fetched beside it (refs `pr/head`, `pr/base`, `pr/merge-base`). The fetch is the server's own, one command on the run's folder, with an installation token of the server's GitHub App narrowed to that repository and `contents: read`, which the agent never holds: it is never in the folder, the checkout's git config, its remote's URL, the agent's environment or the log. With no App, or one not installed there, the fetch is anonymous, which a public repository answers. The run's system prompt says what was checked out, or why nothing was (no pull request named, the fetch failed), so it can read the change another way, such as the GitHub MCP. The checkout is removed when the run's claim ends. An edit that leaves it out keeps the agent's; `none` clears it. A template sets it from its manifest's `checkout`.", "x-agentrun-serve": "checkout/1" },
|
|
3081
3171
|
},
|
|
3082
3172
|
AgentCreate: {
|
|
@@ -3615,6 +3705,12 @@ export function openapiDocument(capabilityOf, adapters = TRIGGER_ADAPTERS) {
|
|
|
3615
3705
|
files["x-agentrun-serve-changed"] = { description: "signins/1", ...(added ? { responses: "signins/1" } : {}) };
|
|
3616
3706
|
changed.push(`GET ${path}`);
|
|
3617
3707
|
}
|
|
3708
|
+
// runvideo/1: a run's screen recordings are read under recordings/, as video/mp4, their byte ranges answered.
|
|
3709
|
+
const readFile = doc.paths["/runs/{run_id}/files/{path}"].get;
|
|
3710
|
+
readFile.description = `${String(readFile.description).trimEnd()}\nHere a path under \`recordings/\` is one of the run's screen recordings (the run read's \`recordings\`, made where its agent's computer says \`record: true\`), never a file the run made: \`video/mp4\`, inline unless \`?download=1\`, read-only, to whoever may read the run's other files. A folder the run made named \`recordings\` is neither listed nor served. A recording still being written is served as it stands: a fragmented MP4 plays up to its last whole fragment. \`Range\` is honoured for every file (\`features.files.range\`): one byte range, \`206\` with \`Content-Range\`, so a \`<video>\` can seek; one that starts past the end is \`416 range_not_satisfiable\`.\n`;
|
|
3711
|
+
for (const code of ["200", "206"])
|
|
3712
|
+
readFile.responses[code].content = { "video/mp4": { schema: { type: "string", contentMediaType: "video/mp4" } }, ...readFile.responses[code].content };
|
|
3713
|
+
readFile["x-agentrun-serve-changed"] = { ...readFile["x-agentrun-serve-changed"], responses: "runvideo/1" };
|
|
3618
3714
|
// An agentic run's cancel is its end at once: the 202 reads `cancelled`, and no later end of its turn moves it.
|
|
3619
3715
|
const cancel = doc.paths["/runs/{run_id}/cancel"].post;
|
|
3620
3716
|
cancel.description = `${String(cancel.description).trimEnd()}\nHere an agentic run reads \`cancelled\` from the 202 on, \`final\` once it has stopped: a run's first terminal status is its last, so nothing its cut turn writes later (an answer, a cost over its cap) moves it. A workflow run reads \`cancelled\` once its workflow has stopped.\n`;
|
package/dist/run-files.d.ts
CHANGED
|
@@ -26,6 +26,10 @@ export declare function listFiles(workspace: Workspace, cap: number, { owned: is
|
|
|
26
26
|
/** The listing entry at `rel`, a file's or a folder's, or undefined when there is none: not there, or a link (never
|
|
27
27
|
* listed). */
|
|
28
28
|
export declare function entryAt(workspace: Workspace, rel: string): Promise<Entry | undefined>;
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
29
|
+
/** The one byte range a Range header asks of a file of `size` bytes, first and last byte; undefined for the whole file (no
|
|
30
|
+
* Range, or one this server does not take: another unit, several ranges, or a last byte before the first);
|
|
31
|
+
* "unsatisfiable" when it starts past the file's end. */
|
|
32
|
+
export declare function rangeOf(header: string | undefined, size: number): [number, number] | "unsatisfiable" | undefined;
|
|
33
|
+
/** File `rel` of `workspace`, raw, in reads of SEND_CHUNK, whole or the one byte range its Range header asks (206): its
|
|
34
|
+
* length from the listing, so HEAD reads no byte. `who` names who makes a file private, in the words of a 403. */
|
|
31
35
|
export declare function sendFile(req: IncomingMessage, res: ServerResponse, url: URL, workspace: Workspace, rel: string, who: string): Promise<void>;
|
package/dist/run-files.js
CHANGED
|
@@ -73,8 +73,23 @@ const fileEntry = async (workspace, rel) => {
|
|
|
73
73
|
const entry = await entryAt(workspace, rel);
|
|
74
74
|
return entry?.kind === "file" ? entry : undefined;
|
|
75
75
|
};
|
|
76
|
-
/**
|
|
77
|
-
*
|
|
76
|
+
/** The one byte range a Range header asks of a file of `size` bytes, first and last byte; undefined for the whole file (no
|
|
77
|
+
* Range, or one this server does not take: another unit, several ranges, or a last byte before the first);
|
|
78
|
+
* "unsatisfiable" when it starts past the file's end. */
|
|
79
|
+
export function rangeOf(header, size) {
|
|
80
|
+
const asked = /^bytes=(\d*)-(\d*)$/.exec(header?.trim() ?? "");
|
|
81
|
+
if (!asked || (asked[1] === "" && asked[2] === ""))
|
|
82
|
+
return undefined;
|
|
83
|
+
if (asked[1] === "")
|
|
84
|
+
return Number(asked[2]) === 0 || size === 0 ? "unsatisfiable" : [Math.max(0, size - Number(asked[2])), size - 1];
|
|
85
|
+
const start = Number(asked[1]);
|
|
86
|
+
if (start >= size)
|
|
87
|
+
return "unsatisfiable";
|
|
88
|
+
const end = asked[2] === "" ? size - 1 : Math.min(Number(asked[2]), size - 1);
|
|
89
|
+
return end < start ? undefined : [start, end];
|
|
90
|
+
}
|
|
91
|
+
/** File `rel` of `workspace`, raw, in reads of SEND_CHUNK, whole or the one byte range its Range header asks (206): its
|
|
92
|
+
* length from the listing, so HEAD reads no byte. `who` names who makes a file private, in the words of a 403. */
|
|
78
93
|
export async function sendFile(req, res, url, workspace, rel, who) {
|
|
79
94
|
const unreadable = () => new ApiError("system_file_forbidden", `This file was created private by ${who}: this server cannot read it.`, { details: { reason: "unreadable" } });
|
|
80
95
|
const entry = await fileEntry(workspace, rel);
|
|
@@ -82,9 +97,14 @@ export async function sendFile(req, res, url, workspace, rel, who) {
|
|
|
82
97
|
throw new ApiError("not_found", "no such file");
|
|
83
98
|
if (entry.unreadable)
|
|
84
99
|
throw unreadable();
|
|
100
|
+
const range = rangeOf(req.headers?.range, entry.size);
|
|
101
|
+
if (range === "unsatisfiable")
|
|
102
|
+
throw new ApiError("range_not_satisfiable", `The range asked for starts past the file's end: it is ${entry.size} bytes.`, {}, { "content-range": `bytes */${entry.size}` });
|
|
103
|
+
const [start, last] = range ?? [0, entry.size - 1];
|
|
104
|
+
const length = last - start + 1;
|
|
85
105
|
// A GET reads its first chunk before the head: a file gone, or swapped for a link, since the listing is a 404, not a
|
|
86
106
|
// broken 200. A HEAD reads none.
|
|
87
|
-
const first = req.method === "HEAD" ? new Uint8Array(0) : await workspace.read(rel, { offset:
|
|
107
|
+
const first = req.method === "HEAD" ? new Uint8Array(0) : await workspace.read(rel, { offset: start, length: Math.min(SEND_CHUNK, length) }).catch((error) => {
|
|
88
108
|
if (isWorkspaceError(error, "REFUSED"))
|
|
89
109
|
throw unreadable();
|
|
90
110
|
if (skipped(error))
|
|
@@ -94,9 +114,11 @@ export async function sendFile(req, res, url, workspace, rel, who) {
|
|
|
94
114
|
const type = typeOf(rel) ?? "application/octet-stream";
|
|
95
115
|
const download = url.searchParams.get("download") === "1" || !INLINE_TYPES.has(type);
|
|
96
116
|
const name = rel.split("/").at(-1).replace(/[^\w.-]/g, "_");
|
|
97
|
-
res.writeHead(200, {
|
|
117
|
+
res.writeHead(range ? 206 : 200, {
|
|
98
118
|
"content-type": type,
|
|
99
|
-
"content-length":
|
|
119
|
+
"content-length": length,
|
|
120
|
+
"accept-ranges": "bytes",
|
|
121
|
+
...(range ? { "content-range": `bytes ${start}-${last}/${entry.size}` } : {}),
|
|
100
122
|
"x-content-type-options": "nosniff",
|
|
101
123
|
"cache-control": "no-store",
|
|
102
124
|
...(type.startsWith("text/html") ? { "content-security-policy": FILE_CSP } : {}),
|
|
@@ -107,13 +129,13 @@ export async function sendFile(req, res, url, workspace, rel, who) {
|
|
|
107
129
|
// The length said is the listing's: a file that changes while it is sent is cut there, or the answer ends short.
|
|
108
130
|
try {
|
|
109
131
|
let sent = 0;
|
|
110
|
-
for (let chunk = first;; chunk = await workspace.read(rel, { offset: sent, length: Math.min(SEND_CHUNK,
|
|
132
|
+
for (let chunk = first;; chunk = await workspace.read(rel, { offset: start + sent, length: Math.min(SEND_CHUNK, length - sent) })) {
|
|
111
133
|
if (chunk.length === 0 || res.destroyed)
|
|
112
134
|
break;
|
|
113
135
|
if (!res.write(chunk))
|
|
114
136
|
await new Promise((resolve) => { res.once("drain", resolve); res.once("close", resolve); });
|
|
115
137
|
sent += chunk.length;
|
|
116
|
-
if (sent >=
|
|
138
|
+
if (sent >= length)
|
|
117
139
|
break;
|
|
118
140
|
}
|
|
119
141
|
}
|
|
@@ -76,7 +76,7 @@ export declare function servedRunLearning(deps: {
|
|
|
76
76
|
graded_at: string;
|
|
77
77
|
path: "agent" | "workflow" | "handed_back" | "replay";
|
|
78
78
|
workflow_digest: string | null;
|
|
79
|
-
feedback: "
|
|
79
|
+
feedback: "look_back" | null;
|
|
80
80
|
run_id: string;
|
|
81
81
|
correct: boolean;
|
|
82
82
|
};
|
|
@@ -17,6 +17,9 @@ export interface RunReadsDeps {
|
|
|
17
17
|
/** The run's Workspace for a server-side read (not the runner's claim-time openRunWorkspace): null when it has no folder
|
|
18
18
|
* (an imported run never has one). */
|
|
19
19
|
runWorkspace(store: RunReadsStore, runId: string): Promise<Workspace | null>;
|
|
20
|
+
/** The run's recordings folder on this machine, read-only (run-recordings.ts recordingsWorkspace): null when it recorded
|
|
21
|
+
* nothing. */
|
|
22
|
+
recordings(store: RunReadsStore, runId: string): Promise<Workspace | null>;
|
|
20
23
|
/** The environment the plane re-check reads (tool-plane.ts recheckPlane): the server's keys as it holds them. */
|
|
21
24
|
readonly env: NodeJS.ProcessEnv;
|
|
22
25
|
/** The run's open live browser viewer, when its runner serves one (its link), or undefined. The runner publishes the
|
|
@@ -47,7 +50,8 @@ export declare function listRunFiles(store: RunReadsStore, runId: string, deps:
|
|
|
47
50
|
truncated: boolean;
|
|
48
51
|
}>;
|
|
49
52
|
/** One of a run's files, through its Workspace (readRunFile): streamed to `res` as the route streams it, with the route's
|
|
50
|
-
* path check and its 404 words; a withheld run refuses (403) before anything is streamed.
|
|
53
|
+
* path check and its 404 words; a withheld run refuses (403) before anything is streamed. A path under recordings/ is
|
|
54
|
+
* one of the run's recordings (its recordings folder, beside its Workspace's), never a file the run made. */
|
|
51
55
|
export declare function readRunFile(store: RunReadsStore, runId: string, rawPath: string, req: IncomingMessage, res: ServerResponse, url: URL, deps: RunReadsDeps): Promise<void>;
|
|
52
56
|
/** A run's browser state (getRunBrowser): `live` with its viewer's link when its runner serves one; else `off` with why
|
|
53
57
|
* when the run has no browser or its browser is unavailable here now (the kept plane re-checked, as a launch would); else
|
|
@@ -10,6 +10,7 @@ import { costIsBooked } from "./runner/metrics.js";
|
|
|
10
10
|
import { runEntries, runTimeline } from "./store-reads/journal.js";
|
|
11
11
|
import { StoreLaunchMissing } from "./store/index.js";
|
|
12
12
|
import { isUnavailable, recheckPlane, whyUnavailable } from "./tool-plane.js";
|
|
13
|
+
import { RECORDINGS } from "./workspace/paths.js";
|
|
13
14
|
/** The most files a list answers with (server.ts FILE_LIST_CAP). */
|
|
14
15
|
export const FILE_LIST_CAP = 2_000;
|
|
15
16
|
/** A run's files, through its Workspace (listRunFiles): every file, path-sorted, cut at the cap. A run with no folder lists
|
|
@@ -20,20 +21,23 @@ export async function listRunFiles(store, runId, deps) {
|
|
|
20
21
|
if (await deps.withheld(store, runId))
|
|
21
22
|
throw new ApiError("forbidden", WITHHELD_SIGN_IN);
|
|
22
23
|
const workspace = await deps.runWorkspace(store, runId);
|
|
23
|
-
|
|
24
|
+
// A folder the run made named recordings is not listed: the route's recordings/ is the run's recordings.
|
|
25
|
+
const { files, deep } = workspace ? await listFiles(workspace, FILE_LIST_CAP, { owned: (name) => name === RECORDINGS }) : { files: [], deep: false };
|
|
24
26
|
files.sort((a, b) => a.path.localeCompare(b.path));
|
|
25
27
|
return { run_id: runId, files: files.slice(0, FILE_LIST_CAP), complete: true, truncated: deep || files.length > FILE_LIST_CAP };
|
|
26
28
|
}
|
|
27
29
|
/** One of a run's files, through its Workspace (readRunFile): streamed to `res` as the route streams it, with the route's
|
|
28
|
-
* path check and its 404 words; a withheld run refuses (403) before anything is streamed.
|
|
30
|
+
* path check and its 404 words; a withheld run refuses (403) before anything is streamed. A path under recordings/ is
|
|
31
|
+
* one of the run's recordings (its recordings folder, beside its Workspace's), never a file the run made. */
|
|
29
32
|
export async function readRunFile(store, runId, rawPath, req, res, url, deps) {
|
|
30
33
|
if (await deps.withheld(store, runId))
|
|
31
34
|
throw new ApiError("forbidden", WITHHELD_SIGN_IN);
|
|
32
35
|
const rel = checkedPath(decodedPath(rawPath), "the run's own, not a file it wrote");
|
|
33
|
-
const
|
|
36
|
+
const recording = rel.startsWith(`${RECORDINGS}/`) ? rel.slice(RECORDINGS.length + 1) : undefined;
|
|
37
|
+
const workspace = await (recording === undefined ? deps.runWorkspace : deps.recordings)(store, runId);
|
|
34
38
|
if (!workspace)
|
|
35
39
|
throw new ApiError("not_found", "no such file");
|
|
36
|
-
return sendFile(req, res, url, workspace, rel, "a tool in the run's box");
|
|
40
|
+
return sendFile(req, res, url, workspace, recording ?? rel, "a tool in the run's box");
|
|
37
41
|
}
|
|
38
42
|
/** Whether the run's revision grants the browser tool: an agentic revision whose tools name it. */
|
|
39
43
|
async function grantsBrowser(store, revisionId) {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type Workspace } from "./workspace/index.js";
|
|
2
|
+
/** One recording as the run read lists it. `finished`: ffmpeg finished the file, or the run has ended and the file has
|
|
3
|
+
* stopped changing (an encoder cut short leaves a file that plays up to its last fragment). */
|
|
4
|
+
export type RecordingView = {
|
|
5
|
+
path: string;
|
|
6
|
+
computer: string;
|
|
7
|
+
seconds: number;
|
|
8
|
+
bytes: number;
|
|
9
|
+
finished: boolean;
|
|
10
|
+
};
|
|
11
|
+
/** The recordings `folder` holds as a read-only Workspace, or null when it holds none (the run recorded nothing). */
|
|
12
|
+
export declare function recordingsWorkspace(folder: string): Promise<Workspace | null>;
|
|
13
|
+
/** The recordings in `folder`, each computer's files in the order it recorded them: its path on the files route, its
|
|
14
|
+
* computer (its ref id, as its file is named: computer-record.ts names a computer's later files <computer>-2.mp4 and
|
|
15
|
+
* on), its length in seconds, its size, and whether it is finished: its trailer is there, or the run ended at `endedAt`
|
|
16
|
+
* and neither that end nor the file's last change is within twice the time the recorder gives ffmpeg to finish it
|
|
17
|
+
* (RECORDING_LIMITS.settleMs; the recorder stops at the computer's release, right after the run's end is saved, and a
|
|
18
|
+
* quiet screen's file may not have changed for a while before it). None when the folder isn't there. A file that can't
|
|
19
|
+
* be read is listed with 0 seconds. */
|
|
20
|
+
export declare function recordingsOf(folder: string, endedAt: number | null): Promise<RecordingView[]>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// A run's screen recordings as the API serves them: the files computer-record.ts writes into the run's recordings folder
|
|
2
|
+
// on this machine (workspace/paths.ts recordingsFolder), beside its work/ folder. The run view lists them (`recordings`),
|
|
3
|
+
// and the run files route serves them under recordings/, read-only, to the readers of the run's other files.
|
|
4
|
+
//
|
|
5
|
+
// A file's length is read from its own boxes, never by running a program: ffmpeg's fragmented MP4 says each fragment's
|
|
6
|
+
// start (tfdt) and each frame's duration (trun, else tfhd's or trex's default), at its track's timescale (mdhd). A
|
|
7
|
+
// finished file ends with ffmpeg's trailer (mfra); one still being written has none, and its last box may be cut short,
|
|
8
|
+
// so it is read up to its last whole box. A read goes on from where the one before it stopped, so a console that polls a
|
|
9
|
+
// recording being written reads only what was added.
|
|
10
|
+
import { lstat, open, readdir } from "node:fs/promises";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { RECORDING_LIMITS } from "./computer-record.js";
|
|
13
|
+
import { localWorkspace, readOnlyWorkspace } from "./workspace/index.js";
|
|
14
|
+
import { RECORDINGS } from "./workspace/paths.js";
|
|
15
|
+
/** The recordings `folder` holds as a read-only Workspace, or null when it holds none (the run recorded nothing). */
|
|
16
|
+
export async function recordingsWorkspace(folder) {
|
|
17
|
+
const there = await lstat(folder).catch(() => undefined);
|
|
18
|
+
return there?.isDirectory() ? readOnlyWorkspace(localWorkspace(folder)) : null;
|
|
19
|
+
}
|
|
20
|
+
/** The newest reads, by path: at most READS_KEPT. */
|
|
21
|
+
const reads = new Map();
|
|
22
|
+
const READS_KEPT = 256;
|
|
23
|
+
/** The boxes in `buf`, each its type and its body; a box cut short ends the walk. */
|
|
24
|
+
function* boxes(buf) {
|
|
25
|
+
for (let at = 0; at + 8 <= buf.length;) {
|
|
26
|
+
let length = buf.readUInt32BE(at);
|
|
27
|
+
let head = 8;
|
|
28
|
+
if (length === 1 && at + 16 <= buf.length)
|
|
29
|
+
[length, head] = [Number(buf.readBigUInt64BE(at + 8)), 16];
|
|
30
|
+
if (length < head || at + length > buf.length)
|
|
31
|
+
return;
|
|
32
|
+
yield [buf.toString("latin1", at + 4, at + 8), buf.subarray(at + head, at + length)];
|
|
33
|
+
at += length;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** What box `type` says into `read`: the timescale, the default frame duration, and a fragment's end. */
|
|
37
|
+
function take(read, type, body) {
|
|
38
|
+
if (type === "moov" || type === "trak" || type === "mdia" || type === "mvex" || type === "moof")
|
|
39
|
+
for (const [inner, part] of boxes(body))
|
|
40
|
+
take(read, inner, part);
|
|
41
|
+
else if (type === "mdhd")
|
|
42
|
+
read.timescale = body.readUInt32BE(body[0] === 1 ? 20 : 12);
|
|
43
|
+
else if (type === "trex")
|
|
44
|
+
read.dflt = body.readUInt32BE(12);
|
|
45
|
+
else if (type === "traf") {
|
|
46
|
+
let start = 0;
|
|
47
|
+
let dflt = read.dflt;
|
|
48
|
+
let length = 0;
|
|
49
|
+
for (const [inner, part] of boxes(body)) {
|
|
50
|
+
const flags = part.readUInt32BE(0) & 0xffffff;
|
|
51
|
+
if (inner === "tfhd" && flags & 0x8)
|
|
52
|
+
dflt = part.readUInt32BE(8 + (flags & 0x1 ? 8 : 0) + (flags & 0x2 ? 4 : 0));
|
|
53
|
+
else if (inner === "tfdt")
|
|
54
|
+
start = part[0] === 1 ? Number(part.readBigUInt64BE(4)) : part.readUInt32BE(4);
|
|
55
|
+
else if (inner === "trun") {
|
|
56
|
+
const count = part.readUInt32BE(4);
|
|
57
|
+
const stride = 4 * [0x100, 0x200, 0x400, 0x800].filter((bit) => flags & bit).length;
|
|
58
|
+
for (let i = 0, at = 8 + (flags & 0x1 ? 4 : 0) + (flags & 0x4 ? 4 : 0); i < count; i += 1, at += stride)
|
|
59
|
+
length += flags & 0x100 ? part.readUInt32BE(at) : dflt;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
read.end = Math.max(read.end, start + length);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** File `path`'s read, `size` bytes long and changed at `mtimeMs` now: the last read when the file is unchanged (it is not
|
|
66
|
+
* opened), on from it when the file only grew, else from its start. */
|
|
67
|
+
async function readOf(path, size, mtimeMs) {
|
|
68
|
+
const kept = reads.get(path);
|
|
69
|
+
if (kept && kept.size === size && kept.mtimeMs === mtimeMs)
|
|
70
|
+
return kept;
|
|
71
|
+
const read = kept && kept.size <= size ? { ...kept } : { at: 0, size: 0, mtimeMs: 0, timescale: 0, dflt: 0, end: 0, finished: false };
|
|
72
|
+
const file = await open(path, "r");
|
|
73
|
+
try {
|
|
74
|
+
const head = Buffer.alloc(16);
|
|
75
|
+
while (read.at + 8 <= size) {
|
|
76
|
+
await file.read(head, 0, 16, read.at);
|
|
77
|
+
let length = head.readUInt32BE(0);
|
|
78
|
+
let skip = 8;
|
|
79
|
+
if (length === 1)
|
|
80
|
+
[length, skip] = [Number(head.readBigUInt64BE(8)), 16];
|
|
81
|
+
if (length < skip || read.at + length > size)
|
|
82
|
+
break;
|
|
83
|
+
const type = head.toString("latin1", 4, 8);
|
|
84
|
+
if (type === "mfra")
|
|
85
|
+
read.finished = true;
|
|
86
|
+
if (type === "moov" || type === "moof") {
|
|
87
|
+
const body = Buffer.alloc(length - skip);
|
|
88
|
+
await file.read(body, 0, body.length, read.at + skip);
|
|
89
|
+
take(read, type, body);
|
|
90
|
+
}
|
|
91
|
+
read.at += length;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
await file.close();
|
|
96
|
+
}
|
|
97
|
+
read.size = size;
|
|
98
|
+
read.mtimeMs = mtimeMs;
|
|
99
|
+
reads.delete(path);
|
|
100
|
+
reads.set(path, read);
|
|
101
|
+
if (reads.size > READS_KEPT)
|
|
102
|
+
reads.delete(reads.keys().next().value);
|
|
103
|
+
return read;
|
|
104
|
+
}
|
|
105
|
+
/** The recordings in `folder`, each computer's files in the order it recorded them: its path on the files route, its
|
|
106
|
+
* computer (its ref id, as its file is named: computer-record.ts names a computer's later files <computer>-2.mp4 and
|
|
107
|
+
* on), its length in seconds, its size, and whether it is finished: its trailer is there, or the run ended at `endedAt`
|
|
108
|
+
* and neither that end nor the file's last change is within twice the time the recorder gives ffmpeg to finish it
|
|
109
|
+
* (RECORDING_LIMITS.settleMs; the recorder stops at the computer's release, right after the run's end is saved, and a
|
|
110
|
+
* quiet screen's file may not have changed for a while before it). None when the folder isn't there. A file that can't
|
|
111
|
+
* be read is listed with 0 seconds. */
|
|
112
|
+
export async function recordingsOf(folder, endedAt) {
|
|
113
|
+
const names = await readdir(folder).catch(() => []);
|
|
114
|
+
const files = new Set(names.filter((name) => name.endsWith(".mp4")));
|
|
115
|
+
const series = [...files].map((name) => {
|
|
116
|
+
const base = name.slice(0, -".mp4".length);
|
|
117
|
+
const later = /^(.+)-(\d+)$/.exec(base);
|
|
118
|
+
return later && Number(later[2]) >= 2 && files.has(`${later[1]}.mp4`) ? { name, computer: later[1], n: Number(later[2]) } : { name, computer: base, n: 1 };
|
|
119
|
+
});
|
|
120
|
+
series.sort((a, b) => (a.computer === b.computer ? a.n - b.n : a.computer < b.computer ? -1 : 1));
|
|
121
|
+
const listed = [];
|
|
122
|
+
for (const { name, computer } of series) {
|
|
123
|
+
const path = join(folder, name);
|
|
124
|
+
const file = await lstat(path).catch(() => undefined);
|
|
125
|
+
if (!file?.isFile())
|
|
126
|
+
continue;
|
|
127
|
+
const read = await readOf(path, file.size, file.mtimeMs).catch(() => undefined);
|
|
128
|
+
const seconds = read?.timescale ? Math.round((read.end / read.timescale) * 10) / 10 : 0;
|
|
129
|
+
const settled = endedAt !== null && Date.now() - Math.max(endedAt, file.mtimeMs) > 2 * RECORDING_LIMITS.settleMs;
|
|
130
|
+
listed.push({ path: `${RECORDINGS}/${name}`, computer, seconds, bytes: file.size, finished: read?.finished === true || settled });
|
|
131
|
+
}
|
|
132
|
+
return listed;
|
|
133
|
+
}
|
|
@@ -138,7 +138,7 @@ export interface AdapterRunSpec {
|
|
|
138
138
|
readonly workflowFirst?: WorkflowFirst;
|
|
139
139
|
/** The learned workflow that fits the run but that the money rule stopped from running first (workflow-first.ts
|
|
140
140
|
* costLineOf): the loop keeps why on the root (WORKFLOW_FIRST, outcome needs_revision, the two numbers) as the agent
|
|
141
|
-
* takes the run
|
|
141
|
+
* takes the run. The stop asks for no revision. */
|
|
142
142
|
readonly workflowRevise?: WorkflowRevise;
|
|
143
143
|
/** The run's end-of-run step, when its spec builds one (over the per-claim resources it holds, its Archil claim among
|
|
144
144
|
* them): it wins over LoopDeps.endOfRun and is asked where that one is, in the end turn while the claim is held, before
|
|
@@ -3580,14 +3580,11 @@ function adapterLoop(specOf, options, deps) {
|
|
|
3580
3580
|
const theSession = session;
|
|
3581
3581
|
const requestId = reflectRequestId(claim.runId, again, round, step);
|
|
3582
3582
|
const theRecord = cliRecord;
|
|
3583
|
-
// A grade's feedback round (feedbackNow): its first ask is told the grade first (feedback-round.ts feedbackAsk),
|
|
3584
|
-
//
|
|
3585
|
-
// workflow's answer before it, cut of every secret the runner holds, as a follow-up's are.
|
|
3583
|
+
// A grade's feedback round (feedbackNow): its first ask is told the grade first (feedback-round.ts feedbackAsk), cut
|
|
3584
|
+
// of every secret the runner holds. Only a run the agent finished opens one, so its session saw the job.
|
|
3586
3585
|
if (feedbackNow && !again && step === undefined) {
|
|
3587
3586
|
const cut = (text) => (deps.redact ? deps.redact(text) : text);
|
|
3588
|
-
|
|
3589
|
-
const seen = servedNow && specNow ? { job: specNow.input, served: { workflow: servedNow.workflow, answer: cut(servedNow.answer) } } : undefined;
|
|
3590
|
-
prompt = `${feedbackAsk({ ...feedbackNow, text: cut(feedbackNow.text) }, seen)}\n\n${prompt}`;
|
|
3587
|
+
prompt = `${feedbackAsk({ ...feedbackNow, text: cut(feedbackNow.text) })}\n\n${prompt}`;
|
|
3591
3588
|
}
|
|
3592
3589
|
let timer;
|
|
3593
3590
|
try {
|