@parcha/agentrun-serve 0.1.0-beta.55 → 0.1.0-beta.56
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 +32 -0
- package/README.md +44 -10
- package/dist/adapters.d.ts +3 -2
- package/dist/adapters.js +6 -3
- package/dist/answer-json.d.ts +6 -2
- package/dist/answer-json.js +22 -4
- package/dist/api-only.js +2 -0
- package/dist/calendar/tools.js +3 -2
- package/dist/chatgpt-plan.d.ts +16 -1
- package/dist/chatgpt-plan.js +116 -12
- package/dist/claude-login.d.ts +34 -5
- package/dist/claude-login.js +31 -7
- package/dist/claude-sign-in.d.ts +35 -0
- package/dist/claude-sign-in.js +90 -0
- package/dist/console/assets/{backend-D5EmB4N3.js → backend-Boh7tC4i.js} +1 -1
- package/dist/console/assets/{index-DUYLaqiR.js → index-CQ3cJRzI.js} +130 -130
- package/dist/console/assets/index-DKkaS3a0.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/host-check.d.ts +4 -0
- package/dist/host-check.js +4 -0
- package/dist/key-refusal.d.ts +21 -5
- package/dist/key-refusal.js +231 -37
- package/dist/learn/secrets.d.ts +20 -10
- package/dist/learn/secrets.js +44 -184
- package/dist/llms.txt +1 -1
- package/dist/openapi.d.ts +3 -3
- package/dist/openapi.js +70 -18
- package/dist/place-offers.d.ts +14 -6
- package/dist/place-offers.js +26 -13
- package/dist/redact/match.d.ts +74 -0
- package/dist/redact/match.js +771 -0
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-timeline-served.js +4 -4
- package/dist/runner/adapter-loop.d.ts +3 -0
- package/dist/runner/adapter-loop.js +1 -1
- package/dist/runner/adapter-run-spec.js +4 -1
- package/dist/runner/beside.js +7 -3
- package/dist/runner/cli-run-spec.js +3 -1
- package/dist/runner/loop-contract.d.ts +4 -0
- package/dist/runner/main.js +8 -4
- package/dist/runner/presence.d.ts +4 -3
- package/dist/runner/presence.js +4 -2
- package/dist/runner/run-child-host.d.ts +2 -0
- package/dist/runner/run-child-host.js +2 -2
- package/dist/runner/runner.d.ts +4 -0
- package/dist/runner/runner.js +33 -3
- package/dist/server.d.ts +5 -2
- package/dist/server.js +41 -10
- package/dist/store/dialect.d.ts +3 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.js +1 -1
- package/dist/store/postgres/dialect.js +3 -0
- package/dist/store/sqlite/store.js +43 -13
- package/dist/store/store.d.ts +10 -1
- package/dist/store/store.js +7 -0
- package/dist/store-view.js +1 -1
- package/dist/template-eval.d.ts +2 -2
- package/dist/template-eval.js +9 -8
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/timeline.d.ts +12 -7
- package/dist/timeline/timeline.js +14 -6
- package/dist/tool-gate.js +3 -1
- package/dist/validate.js +1 -1
- package/dist/workspace/computer-deps.d.ts +2 -1
- package/dist/workspace/computer-deps.js +5 -4
- package/dist/workspace/computer-for-claim.d.ts +8 -2
- package/dist/workspace/computer-for-claim.js +28 -9
- package/dist/workspace/computer-janitor.d.ts +15 -7
- package/dist/workspace/computer-janitor.js +33 -8
- package/dist/workspace/computer-kept.d.ts +52 -4
- package/dist/workspace/computer-kept.js +118 -6
- package/dist/workspace/run-end-computers.d.ts +5 -1
- package/dist/workspace/run-end-computers.js +27 -1
- package/dist/wrapped.d.ts +57 -0
- package/dist/wrapped.js +51 -0
- package/package.json +11 -11
- package/templates/README.md +8 -7
- package/dist/console/assets/index-DYhU4adm.css +0 -1
|
@@ -13,7 +13,7 @@ import { claimFence, storeNow } from "../fence.js";
|
|
|
13
13
|
import { JOURNAL_FIRST_ID, RunStorage } from "../journal/storage.js";
|
|
14
14
|
import { RUNNER_RECORDS } from "@parcha/agentrun-kernel";
|
|
15
15
|
import { COMMANDS_ONE_ANSWER, COMPUTER_INTERVALS, COMPUTER_INTERVALS_ADDED, COMPUTER_INTERVALS_RUN, DDL, diskUpgrade, HAND_BACKS, HAND_BACKS_AT, HAND_BACKS_KEPT_MS, HAND_BACKS_RUN, IMPORTED_TEMPLATES, listingUpgrade, MINTED_TOKENS, purgeUpgrade, relayUpgrade, NATIVE_COMMANDS_INDEX, PI_TABLE, PI_TABLES, REVISIONS_MCP_PIN, REVISIONS_MONID_PIN, RUN_ATTEMPTS, RUNNERS, RUNNERS_ADDED, RUNS_COST_UPPER_BOUND, RUNS_LABELS, SCHEMA_VERSION, SETTLED_LIST_STATUS, TRIGGERS_TEMPLATE_ID } from "../schema.js";
|
|
16
|
-
import { ActiveRuns, AgentArchived, AgentDeleting, AgentPurged, CommandTaken, ExternalBodyConflict, Fenced, RunFinal, RunPurged, RunsMadeFromLeft, SchemaVersionUnknown, STORE_WRITE_DEADLINE_MS, StoreAwaitsServer, StoreBusy, StoreConstraint, StoreFromEarlierVersion, TriggerFull, TriggersLeft, UPLOAD_PREFIX, FINAL_STATES, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, SignInHandedTo, SignInMissing, RUN_CHANGES_PAGE, RUNNER_ROWS_KEPT_MS, tombstoneMetrics, } from "../store.js";
|
|
16
|
+
import { ActiveRuns, AgentArchived, AgentDeleting, AgentPurged, CommandTaken, ExternalBodyConflict, Fenced, RunFinal, RunPurged, RunsMadeFromLeft, SchemaVersionUnknown, STORE_WRITE_DEADLINE_MS, StoreAwaitsServer, StoreBusy, StoreConstraint, StoreFromEarlierVersion, TriggerFull, TriggersLeft, UPLOAD_PREFIX, FINAL_STATES, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, SignInHandedTo, SignInMissing, RUN_CHANGES_PAGE, KEPT_PREFIX, RUNNER_ROWS_KEPT_MS, RUNNER_STALE_MS, tombstoneMetrics, } from "../store.js";
|
|
17
17
|
/** The run a launch body is made from (Runs.madeFrom): the run whose input it replays (`replay.of`) or audits (`audit.of`). */
|
|
18
18
|
const madeOf = (body) => {
|
|
19
19
|
for (const link of ["replay", "audit"]) {
|
|
@@ -132,17 +132,44 @@ const lockCommandsOf = (tx, runId) => tx.dialect.lockKey(tx, `commands:${runId}`
|
|
|
132
132
|
* its claim run out, once its backoff (an interrupted run's) has passed; parked, once no claim holds it (a run parks
|
|
133
133
|
* under its claim and is released a few seconds later), with its wake_at passed, an untaken stop or cancel, or an untaken command
|
|
134
134
|
* that can answer it once its backoff (a failed resume's) has passed. A row marked `answers: false` (a trigger's
|
|
135
|
-
* follow-up message) answers no park: it waits, untaken, and its loop gets it after the person's answer wakes the run.
|
|
136
|
-
|
|
137
|
-
|
|
135
|
+
* follow-up message) answers no park: it waits, untaken, and its loop gets it after the person's answer wakes the run.
|
|
136
|
+
* With `claimer` (a claim's runner), a parked run whose computer is pinned to another runner (keptElsewhere) is left
|
|
137
|
+
* out while only its wake or an answering command makes it claimable; without it (a count of what waits) it is in.
|
|
138
|
+
* An untaken stop or cancel row is its own branch, outside the pin: a person's stop never waits on a pin, and any
|
|
139
|
+
* runner claims the run at once to end it (runner.ts claimMore ends it without a loop, never taking the kept machine).
|
|
140
|
+
* The SQL tells the branches apart by place: the stop/cancel EXISTS is OR'ed beside a parenthesis holding the wake and
|
|
141
|
+
* the answer, and only that parenthesis carries `AND NOT keptElsewhere`. */
|
|
142
|
+
const claimableIn = (d, n, claimer) => {
|
|
143
|
+
const pin = claimer === undefined ? undefined : keptElsewhere(d, n, claimer);
|
|
144
|
+
return {
|
|
145
|
+
sql: `(state = 'queued'
|
|
138
146
|
OR (state = 'running' AND (runner IS NULL OR claimed_until < ${n.sql}) AND (backoff_until IS NULL OR backoff_until <= ${n.sql}))
|
|
139
147
|
OR (state = 'parked' AND (runner IS NULL OR claimed_until < ${n.sql}) AND (
|
|
140
|
-
(
|
|
141
|
-
OR
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
148
|
+
EXISTS (SELECT 1 FROM commands WHERE commands.run_id = runs.id AND commands.taken_at IS NULL AND commands.kind IN ('stop', 'cancel'))
|
|
149
|
+
OR (((wake_at IS NOT NULL AND wake_at <= ${n.sql})
|
|
150
|
+
OR ((backoff_until IS NULL OR backoff_until <= ${n.sql}) AND EXISTS (SELECT 1 FROM commands WHERE commands.run_id = runs.id AND commands.taken_at IS NULL
|
|
151
|
+
AND ${d.jsonNotFalse(readableJson(d, "commands.body"), ["answers"])})))${pin ? `
|
|
152
|
+
AND NOT ${pin.sql}` : ""}))))`,
|
|
153
|
+
params: [...n.params, ...n.params, ...n.params, ...n.params, ...n.params, ...(pin?.params ?? [])],
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
/** The run's computer is kept at its park (its KEPT_PREFIX row) pinned to a runner other than `claimer` that is still
|
|
157
|
+
* there under the incarnation the row names, at the deadlines' clock `n`: its runners row seen within RUNNER_STALE_MS,
|
|
158
|
+
* claiming (refused NULL); the keep neither ending nor ended, and its `until` ahead. That runner's Docker engine or
|
|
159
|
+
* attach hub holds the machine, so only it can take it back (workspace/computer-kept.ts pinnedOf); once any of these
|
|
160
|
+
* stops holding, any runner claims the run. Read in the claim's own statement, so no check-then-act gap. A row with no
|
|
161
|
+
* runner (a computer any runner reaches: an exec vendor's, a phone; or one an earlier build kept) pins nothing. */
|
|
162
|
+
const keptElsewhere = (d, n, claimer) => {
|
|
163
|
+
const value = readableJson(d, "kept.value");
|
|
164
|
+
const field = (name) => d.jsonText(value, [name]);
|
|
165
|
+
return {
|
|
166
|
+
sql: `EXISTS (SELECT 1 FROM settings kept JOIN runners pin ON pin.runner = ${field("runner")}
|
|
167
|
+
WHERE kept.key = '${KEPT_PREFIX}' || runs.id AND pin.runner <> ? AND pin.incarnation = ${field("incarnation")} AND pin.refused IS NULL
|
|
168
|
+
AND pin.seen_at >= ${n.sql} - ${d.bigintParam} AND ${field("ending")} IS NULL AND ${field("ended")} IS NULL
|
|
169
|
+
AND ${d.jsonNumber(value, ["until"])} > ${n.sql})`,
|
|
170
|
+
params: [claimer, ...n.params, RUNNER_STALE_MS, ...n.params],
|
|
171
|
+
};
|
|
172
|
+
};
|
|
146
173
|
/** What a claim sets: the next epoch, the runner and its lease (from `n`, the deadlines' clock, plus a lease in ms), running,
|
|
147
174
|
* no backoff. Binds the runner, `n`'s parameters, then the lease. */
|
|
148
175
|
const claimSet = (n) => `epoch = epoch + 1, runner = ?, claimed_until = ${n.sql} + ?, state = 'running', backoff_until = NULL`;
|
|
@@ -1532,8 +1559,9 @@ class SqliteStore {
|
|
|
1532
1559
|
const [result] = await db.write([{ sql: `UPDATE runs SET wake_at = ${n.sql} WHERE id = ? AND state = 'parked' RETURNING id`, params: [...n.params, runId] }]);
|
|
1533
1560
|
return (result?.rows.length ?? 0) > 0;
|
|
1534
1561
|
},
|
|
1535
|
-
claimable: async ({ limit } = {}) => {
|
|
1536
|
-
|
|
1562
|
+
claimable: async ({ limit, runner } = {}) => {
|
|
1563
|
+
// The claimer's name, where it is a claimer's read (a runner's memory path): a run pinned to another runner is not its.
|
|
1564
|
+
const claimable = claimableIn(d, clock(), runner);
|
|
1537
1565
|
const bounded = typeof limit === "number" && Number.isSafeInteger(limit) && limit >= 0;
|
|
1538
1566
|
const rows = await db.all(`SELECT id FROM runs WHERE ${claimable.sql} ORDER BY started_at, id${bounded ? " LIMIT ?" : ""}`, ...claimable.params, ...(bounded ? [limit] : []));
|
|
1539
1567
|
return rows.map((row) => row.id);
|
|
@@ -2473,7 +2501,9 @@ class SqliteStore {
|
|
|
2473
2501
|
// The clock is read once the transaction holds the writer lock: a claim that waited for another writer runs its
|
|
2474
2502
|
// lease from now, never comes back already run out. The deadlines' clock (the database's on Postgres) both judges what
|
|
2475
2503
|
// is claimable and stamps the lease, which comes back from the row.
|
|
2476
|
-
|
|
2504
|
+
// A run whose computer is kept for another runner still there is never picked: no claim, no epoch moved, nothing
|
|
2505
|
+
// given back (keptElsewhere).
|
|
2506
|
+
const claimable = claimableIn(this.#db.dialect, this.#clock(), runner);
|
|
2477
2507
|
// With many claimers (Postgres), the rows picked are locked as they are read. A poll over many (claimMany) skips a
|
|
2478
2508
|
// row another claimer holds (Dialect.claimLock): two claims never pick one run, and neither waits for the other. A
|
|
2479
2509
|
// claim of one named run waits for a write in flight on its row (Dialect.claimOneLock), then reads it as it is: a
|
package/dist/store/store.d.ts
CHANGED
|
@@ -1247,9 +1247,11 @@ export interface Runs {
|
|
|
1247
1247
|
failUnclaimed(summary: string): Promise<string[]>;
|
|
1248
1248
|
/** The runs a runner may claim, oldest first: queued; parked with an untaken command or its wake_at passed; running with
|
|
1249
1249
|
* no runner (released at a runner's shutdown: it stays running, a run that started keeps that fact) or its claim run
|
|
1250
|
-
* out.
|
|
1250
|
+
* out. A parked run whose computer is kept for another runner that is still there (its pin, KEPT_PREFIX) is that
|
|
1251
|
+
* runner's alone: with `runner`, the claimer, such a run is left out; without it every run is counted. */
|
|
1251
1252
|
claimable(options?: {
|
|
1252
1253
|
limit?: number;
|
|
1254
|
+
runner?: string;
|
|
1253
1255
|
}): Promise<string[]>;
|
|
1254
1256
|
/** The epoch a runner's claim holds run `runId` at now, judged by the store's own clock (the one claims are stamped
|
|
1255
1257
|
* and fenced by), never a reader's; undefined when no claim holds it (none, released, or run out) or there is no
|
|
@@ -1782,6 +1784,13 @@ export interface RunCapacity {
|
|
|
1782
1784
|
/** How long a runner's row is kept once it stopped saying it is there (a runner that died without its close): its next
|
|
1783
1785
|
* put removes every row older than this. */
|
|
1784
1786
|
export declare const RUNNER_ROWS_KEPT_MS: number;
|
|
1787
|
+
/** How old a runner's row can be and still count as there, on the store's clock (runner/presence.ts PRESENCE_STALE_MS:
|
|
1788
|
+
* three renewals missed). The claim rule reads it for a kept computer's pin. */
|
|
1789
|
+
export declare const RUNNER_STALE_MS = 30000;
|
|
1790
|
+
/** The settings key prefix of the computers kept at a run's park, one row per run (workspace/computer-kept.ts). A row
|
|
1791
|
+
* whose computer is pinned to the runner that kept it (its `runner` and `incarnation`) holds the run for that runner in
|
|
1792
|
+
* the claim rule, while that runner is there under that incarnation and the keep lasts. */
|
|
1793
|
+
export declare const KEPT_PREFIX = "computer_kept:";
|
|
1785
1794
|
/** Every runner's word that it is there (runner/presence.ts). */
|
|
1786
1795
|
export interface Runners {
|
|
1787
1796
|
/** Keeps `row` for its runner, replacing any earlier incarnation's, seen now; rows no runner renewed for
|
package/dist/store/store.js
CHANGED
|
@@ -119,6 +119,13 @@ export const MCP_REFRESH_LEASE_MS = MCP_REFRESH_CALL_MS + STORE_WRITE_DEADLINE_M
|
|
|
119
119
|
/** How long a runner's row is kept once it stopped saying it is there (a runner that died without its close): its next
|
|
120
120
|
* put removes every row older than this. */
|
|
121
121
|
export const RUNNER_ROWS_KEPT_MS = 24 * 60 * 60_000;
|
|
122
|
+
/** How old a runner's row can be and still count as there, on the store's clock (runner/presence.ts PRESENCE_STALE_MS:
|
|
123
|
+
* three renewals missed). The claim rule reads it for a kept computer's pin. */
|
|
124
|
+
export const RUNNER_STALE_MS = 30_000;
|
|
125
|
+
/** The settings key prefix of the computers kept at a run's park, one row per run (workspace/computer-kept.ts). A row
|
|
126
|
+
* whose computer is pinned to the runner that kept it (its `runner` and `incarnation`) holds the run for that runner in
|
|
127
|
+
* the claim rule, while that runner is there under that incarnation and the keep lasts. */
|
|
128
|
+
export const KEPT_PREFIX = "computer_kept:";
|
|
122
129
|
/** The id prefix of a package uploaded whole (POST /v2/templates/import {files}): `upload:<name>`. */
|
|
123
130
|
export const UPLOAD_PREFIX = "upload:";
|
|
124
131
|
/** A write under a claim whose epoch is no longer the run's: refused, and nothing written. */
|
package/dist/store-view.js
CHANGED
|
@@ -601,7 +601,7 @@ async function viewOfRun(store, runId, deps, run, read) {
|
|
|
601
601
|
const servedAnswer = (text) => (text ? servedOnce(store, runId, text, values, run.since) : text);
|
|
602
602
|
const finalAnswer = row.kind === "workflow" || unshown ? null : answerOf(run.rows) ?? row.summary ?? null;
|
|
603
603
|
// A workflow run's output, as its end kept it; an agentic run's, its final answer's structured part when its agent has
|
|
604
|
-
// an output schema and the answer's
|
|
604
|
+
// an output schema and the answer's json block (answer-json.ts jsonBlockOf) meets it (storeRunOf's `structured`), else none. Served as
|
|
605
605
|
// runs.ts serves it (servedOutput): each string in it cut of the values the run holds, its shape kept; none while the
|
|
606
606
|
// run's sign-in can't be read back.
|
|
607
607
|
const ownOutput = row.kind === "workflow" ? output : status === "completed" && structured && "value" in structured ? structured.value : null;
|
package/dist/template-eval.d.ts
CHANGED
|
@@ -231,7 +231,7 @@ export declare function fitCalls(lines: readonly {
|
|
|
231
231
|
* is cut first); else every text left out. A file with no text (media, a binary, one past what was read) is named with
|
|
232
232
|
* its size on a last line, cut to the room when even that passes it. */
|
|
233
233
|
export declare function fitFiles(files: readonly FinalFile[], room: number): string;
|
|
234
|
-
/** A grader run's answer read as its verdict:
|
|
234
|
+
/** A grader run's answer read as its verdict: its json block's (jsonBlockOf), else the last flat JSON object's, {pass, reason}. */
|
|
235
235
|
export declare function verdictOf(answer: string): {
|
|
236
236
|
pass: boolean;
|
|
237
237
|
reason: string;
|
|
@@ -266,7 +266,7 @@ export declare const CLAIM_READ_TIMEOUT_MS = 10000;
|
|
|
266
266
|
* shell tool held to bash's setting (bash_background, bash_output, ...) keeps its own name, so its grader sees it. A
|
|
267
267
|
* call on a saved server `toolkits` names ({<saved server>: <the package's toolkit>}, a need an owner's server filled
|
|
268
268
|
* under another name) is named on the package's toolkit, as the package's graders name it. Each with its arguments and
|
|
269
|
-
* its output
|
|
269
|
+
* its output as the rows of a calls=whole read carry them (tool_input, tool_result_text), else its previews. */
|
|
270
270
|
export declare function callsOf(rows: readonly Json[], harness: string, toolkits?: Readonly<Record<string, string>>): ToolCall[];
|
|
271
271
|
/** A file of a run's work folder as its listing names it: its size, its type (null for an extension the server does not
|
|
272
272
|
* type) and whether the server could read it. */
|
package/dist/template-eval.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// saved under its name with no credential and recording every call; the package applied with the case's parameters and
|
|
6
6
|
// grants, a fresh agent per run, its learning seeded from the case's corrections; one run per `runs` with the prompt's body as
|
|
7
7
|
// its input and the case's cap, on the case's clock when it sets one (`now`), waited for; then its answer, its tool calls (its timeline read with calls=whole, each
|
|
8
|
-
// call's arguments and its output
|
|
8
|
+
// call's arguments and its output whole, to CALL_RESULT_CHARS, through the run's redaction, and the fakes' own logs) and its files, graded, and held to the package's output schema when it declares one (outputVerdict,
|
|
9
9
|
// the server's own verdict). Every grader is deterministic but `llm`, which is itself a run on the same
|
|
10
10
|
// server: a grader agent with no tools that sees the rubric, the run's input, its answer and its calls, never another
|
|
11
11
|
// grader or an expected answer, and answers {pass, reason}. readCases checks a package's cases without running one.
|
|
@@ -15,7 +15,7 @@ import { chmodSync, cpSync, lstatSync, mkdtempSync, readdirSync, readFileSync, r
|
|
|
15
15
|
import { tmpdir } from "node:os";
|
|
16
16
|
import { join } from "node:path";
|
|
17
17
|
import { parseDocument } from "yaml";
|
|
18
|
-
import { answerJson,
|
|
18
|
+
import { answerJson, jsonBlockOf } from "./answer-json.js";
|
|
19
19
|
import { correctionsProblems } from "./learn/index.js";
|
|
20
20
|
import { linkCheck } from "./link-check.js";
|
|
21
21
|
import { frontMatter } from "./manifest.js";
|
|
@@ -29,7 +29,7 @@ import { EMAIL_TOOLS } from "./email/names.js";
|
|
|
29
29
|
import { CALENDAR_EVENTS } from "./calendar/names.js";
|
|
30
30
|
import { nameMapOf, settingsKeyOf, shellToolOf } from "./tool-gate.js";
|
|
31
31
|
import { builtinHarness } from "./harness-table.js";
|
|
32
|
-
import { webShownOf } from "./timeline/index.js";
|
|
32
|
+
import { CALLS_PAGE_ROWS, webShownOf } from "./timeline/index.js";
|
|
33
33
|
import { ASK_TOOL, BOUND_TOOLS } from "./tools.js";
|
|
34
34
|
import { webFixtureOf } from "./web-fake.js";
|
|
35
35
|
import { WEB_FETCH_TOOL } from "./web-fetch.js";
|
|
@@ -858,9 +858,9 @@ export function fitFiles(files, room) {
|
|
|
858
858
|
const list = [saidCut("every file's text is left out"), `By path and size in bytes: ${files.map((file) => `${file.path} (${file.bytes})`).join(", ")}`].join("\n");
|
|
859
859
|
return list.length <= room ? list : room < 4 ? "" : `${list.slice(0, room - 4)} ...`;
|
|
860
860
|
}
|
|
861
|
-
/** A grader run's answer read as its verdict:
|
|
861
|
+
/** A grader run's answer read as its verdict: its json block's (jsonBlockOf), else the last flat JSON object's, {pass, reason}. */
|
|
862
862
|
export function verdictOf(answer) {
|
|
863
|
-
const candidates = [
|
|
863
|
+
const candidates = [jsonBlockOf(answer), ...[...answer.matchAll(/\{[^{}]*"pass"[^{}]*\}/g)].map((m) => m[0]).reverse()];
|
|
864
864
|
for (const text of candidates) {
|
|
865
865
|
if (text === undefined)
|
|
866
866
|
continue;
|
|
@@ -998,8 +998,9 @@ async function waitRun(api, runId, deadline, signal, queueTimeoutMs = QUEUE_TIME
|
|
|
998
998
|
await api("POST", `/runs/${runId}/cancel`, {}).catch(() => undefined);
|
|
999
999
|
signal.throwIfAborted();
|
|
1000
1000
|
}
|
|
1001
|
-
// calls=whole: each call's arguments and its output
|
|
1002
|
-
|
|
1001
|
+
// calls=whole: each call's arguments and its output, whole to CALL_RESULT_CHARS (tool_input, tool_result_text), which its graders read.
|
|
1002
|
+
// CALLS_PAGE_ROWS rows a page, the most a calls=whole page holds (an older server's default is 500).
|
|
1003
|
+
const page = expectOk(`reading run ${runId}'s timeline`, await api("GET", `/runs/${runId}/timeline?after=${after}&wait_ms=5000&calls=whole&limit=${CALLS_PAGE_ROWS}`));
|
|
1003
1004
|
if (page.reset)
|
|
1004
1005
|
view.clear();
|
|
1005
1006
|
for (const id of page.drop ?? [])
|
|
@@ -1036,7 +1037,7 @@ async function waitRun(api, runId, deadline, signal, queueTimeoutMs = QUEUE_TIME
|
|
|
1036
1037
|
* shell tool held to bash's setting (bash_background, bash_output, ...) keeps its own name, so its grader sees it. A
|
|
1037
1038
|
* call on a saved server `toolkits` names ({<saved server>: <the package's toolkit>}, a need an owner's server filled
|
|
1038
1039
|
* under another name) is named on the package's toolkit, as the package's graders name it. Each with its arguments and
|
|
1039
|
-
* its output
|
|
1040
|
+
* its output as the rows of a calls=whole read carry them (tool_input, tool_result_text), else its previews. */
|
|
1040
1041
|
export function callsOf(rows, harness, toolkits = {}) {
|
|
1041
1042
|
const results = new Map(rows.filter((row) => row.kind === "tool_result" && row.tool_use_id).map((row) => [String(row.tool_use_id), row]));
|
|
1042
1043
|
// The rows are a server's, read over its API: the names are the built-in harness's, the only facts known here.
|
package/dist/timeline/index.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export { costLabel, endedUsage, PAGE_CHANGED_ROW, RUN_RESUMED, toolCallWords, TU
|
|
|
6
6
|
export { FEEDBACK_SUFFIX, isFeedbackRow, isMessageRow, isUserEntry, MESSAGE_ORIGIN, messageOrigins, NOTE_SUFFIX, originMatcher, originOf, TRIGGER_LABELS, TRIGGER_SOURCES, type MessageOrigin, type TriggerSource } from "./origin.js";
|
|
7
7
|
export { cut, scrubUrl, scrubUrls } from "./util.js";
|
|
8
8
|
export { webCut, webShownOf, webWithin, type WebShown } from "./web-calls.js";
|
|
9
|
-
export { answeredRequests, BROWSER_CHARGE, CALL_ENDED_WITH_RUN, compactionAnswers, CALL_REFUSED, CALL_RESULT_CHARS, CAP_REFUSED, CAP_WRAPUP, CAPS, chargedTool, COMPUTER_NOTE, endedOnTurnEndingTool, HOST_PHASE, METRIC_NAMES, REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_COST_PENDING, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, runMetricsOf, runMetricsWithDecisions, timelineOf, timelineReducer, TOOL_COST, TOOL_STARTED, TOOL_UNMETERED, type AgentEventLike, type DecisionLike, type EntryLike, type RunMetrics, type SideSpend, type TimelineEvent, type TimelineKind, type TimelineOptions, type ToolMetrics, } from "./timeline.js";
|
|
9
|
+
export { answeredRequests, BROWSER_CHARGE, CALL_ENDED_WITH_RUN, compactionAnswers, CALL_REFUSED, CALL_RESULT_CHARS, CALLS_PAGE_ROWS, CAP_REFUSED, CAP_WRAPUP, CAPS, chargedTool, COMPUTER_NOTE, endedOnTurnEndingTool, HOST_PHASE, METRIC_NAMES, REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_COST_PENDING, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, runMetricsOf, runMetricsWithDecisions, timelineOf, timelineReducer, TOOL_COST, TOOL_STARTED, TOOL_UNMETERED, type AgentEventLike, type DecisionLike, type EntryLike, type RunMetrics, type SideSpend, type TimelineEvent, type TimelineKind, type TimelineOptions, type ToolMetrics, } from "./timeline.js";
|
package/dist/timeline/index.js
CHANGED
|
@@ -6,4 +6,4 @@ export { costLabel, endedUsage, PAGE_CHANGED_ROW, RUN_RESUMED, toolCallWords, TU
|
|
|
6
6
|
export { FEEDBACK_SUFFIX, isFeedbackRow, isMessageRow, isUserEntry, MESSAGE_ORIGIN, messageOrigins, NOTE_SUFFIX, originMatcher, originOf, TRIGGER_LABELS, TRIGGER_SOURCES } from "./origin.js";
|
|
7
7
|
export { cut, scrubUrl, scrubUrls } from "./util.js";
|
|
8
8
|
export { webCut, webShownOf, webWithin } from "./web-calls.js";
|
|
9
|
-
export { answeredRequests, BROWSER_CHARGE, CALL_ENDED_WITH_RUN, compactionAnswers, CALL_REFUSED, CALL_RESULT_CHARS, CAP_REFUSED, CAP_WRAPUP, CAPS, chargedTool, COMPUTER_NOTE, endedOnTurnEndingTool, HOST_PHASE, METRIC_NAMES, REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_COST_PENDING, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, runMetricsOf, runMetricsWithDecisions, timelineOf, timelineReducer, TOOL_COST, TOOL_STARTED, TOOL_UNMETERED, } from "./timeline.js";
|
|
9
|
+
export { answeredRequests, BROWSER_CHARGE, CALL_ENDED_WITH_RUN, compactionAnswers, CALL_REFUSED, CALL_RESULT_CHARS, CALLS_PAGE_ROWS, CAP_REFUSED, CAP_WRAPUP, CAPS, chargedTool, COMPUTER_NOTE, endedOnTurnEndingTool, HOST_PHASE, METRIC_NAMES, REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_COST_PENDING, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, runMetricsOf, runMetricsWithDecisions, timelineOf, timelineReducer, TOOL_COST, TOOL_STARTED, TOOL_UNMETERED, } from "./timeline.js";
|
|
@@ -95,9 +95,9 @@ export type TimelineEvent = {
|
|
|
95
95
|
/** On a `tool_use` row of a timeline read with `calls` (TimelineOptions): the call's arguments, each string as `redact`
|
|
96
96
|
* makes it where the call is first seen, cut at CAPS.text. */
|
|
97
97
|
tool_input?: Obj;
|
|
98
|
-
/** On a `tool_result` row of a timeline read with `calls`: the
|
|
99
|
-
* as `calls.redact` makes it, its URLs' query values elided as the preview's are; a web call's every
|
|
100
|
-
* texts cut to fit (CALL_RESULT_CHARS). */
|
|
98
|
+
/** On a `tool_result` row of a timeline read with `calls`: the call's output whole to `calls.result` characters (its
|
|
99
|
+
* head past that), as `calls.redact` makes it, its URLs' query values elided as the preview's are; a web call's every
|
|
100
|
+
* url, its long texts cut to fit (CALL_RESULT_CHARS). */
|
|
101
101
|
tool_result_text?: string | null;
|
|
102
102
|
};
|
|
103
103
|
/** A pi conversation entry as stored: `pi.assistant`, `pi.tool-result`, a host's own kind. */
|
|
@@ -125,11 +125,16 @@ export declare const CAPS: {
|
|
|
125
125
|
text: number;
|
|
126
126
|
thinking: number;
|
|
127
127
|
};
|
|
128
|
-
/** The most of a call's output a read for a grader shows (`calls`, tool_result_text): a
|
|
129
|
-
*
|
|
128
|
+
/** The most of a call's output a read for a grader shows (`calls`, tool_result_text): as much as a grader's whole prompt
|
|
129
|
+
* takes (template-eval.ts GRADER_PROMPT_MAX), so a grader judges what the run read, not a head of it; the grader's own
|
|
130
|
+
* fit (fitCalls) shares that room among the calls. The run's redaction reads it in pieces of an answer's size
|
|
131
|
+
* (key-refusal.ts redactedCall), so a long head costs no more a pass than a short one. Past it, a tool's output's head; a
|
|
132
|
+
* web call's is not its head: a
|
|
130
133
|
* web_search's every result keeps its url, title and published date, and a web_fetch its url and title, their snippets
|
|
131
|
-
* and page text cut to fit (web-calls.ts), past this only when its urls alone pass it
|
|
132
|
-
export declare const CALL_RESULT_CHARS =
|
|
134
|
+
* and page text cut to fit (web-calls.ts), past this only when its urls alone pass it. */
|
|
135
|
+
export declare const CALL_RESULT_CHARS = 120000;
|
|
136
|
+
/** The most rows a `calls=whole` timeline page holds, and its default: each row's result may be CALL_RESULT_CHARS long. */
|
|
137
|
+
export declare const CALLS_PAGE_ROWS = 100;
|
|
133
138
|
/** A host's marks of a model request: as it leaves (written before it does), and as its stream ends aborted. A request
|
|
134
139
|
* that answered or failed has a `pi.assistant` entry; one aborted before its first content has none; a start with no
|
|
135
140
|
* end and no entry is in flight when it is the latest, unless the run is settled, and was cut by a crash when a later
|
|
@@ -10,11 +10,16 @@ export const nestingCallOf = (callId) => {
|
|
|
10
10
|
};
|
|
11
11
|
/** The base caps, so a row is the same on both sides. `thinking` cuts the first sentence of a thinking summary. */
|
|
12
12
|
export const CAPS = { summary: 500, preview: 500, text: 2000, thinking: 100 };
|
|
13
|
-
/** The most of a call's output a read for a grader shows (`calls`, tool_result_text): a
|
|
14
|
-
*
|
|
13
|
+
/** The most of a call's output a read for a grader shows (`calls`, tool_result_text): as much as a grader's whole prompt
|
|
14
|
+
* takes (template-eval.ts GRADER_PROMPT_MAX), so a grader judges what the run read, not a head of it; the grader's own
|
|
15
|
+
* fit (fitCalls) shares that room among the calls. The run's redaction reads it in pieces of an answer's size
|
|
16
|
+
* (key-refusal.ts redactedCall), so a long head costs no more a pass than a short one. Past it, a tool's output's head; a
|
|
17
|
+
* web call's is not its head: a
|
|
15
18
|
* web_search's every result keeps its url, title and published date, and a web_fetch its url and title, their snippets
|
|
16
|
-
* and page text cut to fit (web-calls.ts), past this only when its urls alone pass it
|
|
17
|
-
export const CALL_RESULT_CHARS =
|
|
19
|
+
* and page text cut to fit (web-calls.ts), past this only when its urls alone pass it. */
|
|
20
|
+
export const CALL_RESULT_CHARS = 120_000;
|
|
21
|
+
/** The most rows a `calls=whole` timeline page holds, and its default: each row's result may be CALL_RESULT_CHARS long. */
|
|
22
|
+
export const CALLS_PAGE_ROWS = 100;
|
|
18
23
|
/** A host's marks of a model request: as it leaves (written before it does), and as its stream ends aborted. A request
|
|
19
24
|
* that answered or failed has a `pi.assistant` entry; one aborted before its first content has none; a start with no
|
|
20
25
|
* end and no entry is in flight when it is the latest, unless the run is settled, and was cut by a crash when a later
|
|
@@ -696,8 +701,11 @@ function createProjector(options) {
|
|
|
696
701
|
const shown = options.calls ? obj(inputShown(args, caps.text, options.redact, options.calls.held)) : undefined;
|
|
697
702
|
return shown ? { tool_input: shown } : {};
|
|
698
703
|
};
|
|
699
|
-
/** A call's output as a `calls` read shows it (tool_result_text): redacted by its redactor, else the rows' own, its
|
|
700
|
-
* URLs' query values elided, cut at `calls.result`; a web call's every url whole, only its long texts cut
|
|
704
|
+
/** A call's output as a `calls` read shows it (tool_result_text): redacted by its redactor, else the rows' own, then its
|
|
705
|
+
* URLs' query values elided, cut at `calls.result`; a web call's every url whole, only its long texts cut
|
|
706
|
+
* (web-calls.ts). Every secret check reads the text as it came, never as shown: elided, a URL's query and userinfo are
|
|
707
|
+
* cut apart, and a held value in one no longer reads as itself. The served redactor (redactedCall) elides each piece it
|
|
708
|
+
* read after redacting it, so what it returns is already as shown and the elision here changes nothing in it. */
|
|
701
709
|
const wholeRedact = options.calls?.redact ?? options.redact;
|
|
702
710
|
const callShown = (text) => scrubUrls(wholeRedact ? wholeRedact(text) : text);
|
|
703
711
|
const resultText = (tool, text) => {
|
package/dist/tool-gate.js
CHANGED
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
//
|
|
19
19
|
// An ask has one way to wait, every tool's alike (the owner's ruling of 11-04): it PARKS. The runner's loop holds the
|
|
20
20
|
// call and the run goes needs_input with the pending approval. On an answer the loop runs the approved call once, through
|
|
21
|
-
// the journal, and the session goes on with its result.
|
|
21
|
+
// the journal, and the session goes on with its result. A read the runner lost mid-call (its claim lapsed before the
|
|
22
|
+
// call's end was recorded) may run again on its next claim; a call with a side effect never does: that claim answers it
|
|
23
|
+
// interrupted (test/adapter-approved-call-lapse.test.mjs). One call waits at a time: another asked meanwhile is refused.
|
|
22
24
|
//
|
|
23
25
|
// The answer: POST /v2/runs/{id}/approvals/{approval_id} { decision: "allow" | "deny", note? } -> 204. The first answer
|
|
24
26
|
// wins; the same answer again is 204, a conflicting one 409. Only the owner's password session answers (server.ts), never
|
package/dist/validate.js
CHANGED
|
@@ -128,7 +128,7 @@ export function definitionIssues(definition, { at = "definition", creating = tru
|
|
|
128
128
|
out.push(issue(`${at}.learning`, "wrong_type", wrong));
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
-
// An agentic revision's structured answer: the JSON Schema its final answer's
|
|
131
|
+
// An agentic revision's structured answer: the JSON Schema its final answer's json block (jsonBlockOf) meets, read into a
|
|
132
132
|
// completed run's result.output (answer-json.ts structuredAnswer). A workflow's output is its workflow's own.
|
|
133
133
|
if (d.output_schema !== undefined) {
|
|
134
134
|
if (d.workflow !== undefined)
|
|
@@ -110,7 +110,8 @@ export declare const computerStartingWords: ({ provider, kind }: Pick<ComputerSa
|
|
|
110
110
|
* replaced an earlier claim's (`replaced`) says it is a new one, never why the old one went (a lost runner, a crash, a
|
|
111
111
|
* server's stop, a park: the words fit each), and, where the run's folder is on Archil and mounted in it
|
|
112
112
|
* (`folderKept`), that the folder is kept. The one kept through the run's park (`kept`) says it is the same; a new one
|
|
113
|
-
* after a kept one's time passed (`replaced.lapsed`) says why first
|
|
113
|
+
* after a kept one's time passed (`replaced.lapsed`) says why first, as does one after a kept one pinned to a runner
|
|
114
|
+
* that was gone by the resume (`replaced.lost`, computerLostWords). */
|
|
114
115
|
export declare const computerReadyWords: ({ provider, kind, hello, replaced, kept }: ComputerSaid) => string;
|
|
115
116
|
/** The run's timeline phase as its run parks with its computer kept (ClaimComputer.keeps), such as "The desktop is kept
|
|
116
117
|
* for 10 minutes while you decide." */
|
|
@@ -29,7 +29,7 @@ import { BOX_CPUS_ENV, BOX_MEMORY_ENV, BOX_PIDS_ENV } from "../start-switches.js
|
|
|
29
29
|
import { readLaunchBody } from "../run-launch.js";
|
|
30
30
|
import { SERVER_NOTE_LABEL } from "@parcha/agentrun-kernel/kernel/cap";
|
|
31
31
|
import { computerForClaim } from "./computer-for-claim.js";
|
|
32
|
-
import { computerLapsedWords, KEEP_WORDS } from "./computer-kept.js";
|
|
32
|
+
import { computerLapsedWords, computerLostWords, KEEP_WORDS } from "./computer-kept.js";
|
|
33
33
|
import { storeLedger } from "./computer-ledger.js";
|
|
34
34
|
import { computerProviderFactories, computerProviderMakers } from "./computer-providers.js";
|
|
35
35
|
import { aLabel, needsNetwork, noNetworkRefusal, vendorNetworkOnly } from "./resolve-computer.js";
|
|
@@ -205,15 +205,16 @@ export const computerStartingWords = ({ provider, kind }) => `Starting a ${kind}
|
|
|
205
205
|
* replaced an earlier claim's (`replaced`) says it is a new one, never why the old one went (a lost runner, a crash, a
|
|
206
206
|
* server's stop, a park: the words fit each), and, where the run's folder is on Archil and mounted in it
|
|
207
207
|
* (`folderKept`), that the folder is kept. The one kept through the run's park (`kept`) says it is the same; a new one
|
|
208
|
-
* after a kept one's time passed (`replaced.lapsed`) says why first
|
|
208
|
+
* after a kept one's time passed (`replaced.lapsed`) says why first, as does one after a kept one pinned to a runner
|
|
209
|
+
* that was gone by the resume (`replaced.lost`, computerLostWords). */
|
|
209
210
|
export const computerReadyWords = ({ provider, kind, hello, replaced, kept }) => {
|
|
210
211
|
const ready = `The ${kind} is ready: ${[OS_NAMES[hello.os] ?? hello.os, hello.osVersion].filter(Boolean).join(" ")} (${hello.arch}), from ${provider}.`;
|
|
211
212
|
if (kept)
|
|
212
213
|
return `${ready} It's the same ${kind}, as the wait left it.`;
|
|
213
214
|
if (!replaced)
|
|
214
215
|
return ready;
|
|
215
|
-
const
|
|
216
|
-
return `${ready}${
|
|
216
|
+
const why = replaced.lost ? ` ${computerLostWords(kind)}` : replaced.lapsed ? ` ${computerLapsedWords(kind)}` : "";
|
|
217
|
+
return `${ready}${why} It's a new ${kind}: the one before is gone, with what was on it.${replaced.folderKept ? " The run folder is kept." : ""}`;
|
|
217
218
|
};
|
|
218
219
|
/** The run's timeline phase as its run parks with its computer kept (ClaimComputer.keeps), such as "The desktop is kept
|
|
219
220
|
* for 10 minutes while you decide." */
|
|
@@ -7,7 +7,7 @@ import type { MountCheck } from "./attach.js";
|
|
|
7
7
|
import { type AttachedComputers } from "./attached-computers.js";
|
|
8
8
|
import { type HeldComputer } from "./computer-hold.js";
|
|
9
9
|
import { type ComputeLedger, type ComputeMeterOptions } from "../compute-cost.js";
|
|
10
|
-
import { type Kept, type ParkCause, type ParkedEnd } from "./computer-kept.js";
|
|
10
|
+
import { type Kept, type KeptHolder, type ParkCause, type ParkedEnd } from "./computer-kept.js";
|
|
11
11
|
import { type ProviderLedger } from "./computer-ledger.js";
|
|
12
12
|
import { type ClaimBrowser, type ClaimSide, type ComputerSetting, type ComputerSettingKind, type KindRegistry, type ProviderEntry } from "./resolve-computer.js";
|
|
13
13
|
import type { RunComputer, RunHold } from "./run-tools.js";
|
|
@@ -29,6 +29,10 @@ export interface ClaimLaunch {
|
|
|
29
29
|
readonly boxAllow?: readonly string[] | "none";
|
|
30
30
|
/** The operator set that (run-launch.ts boxAllowSet), not the default. */
|
|
31
31
|
readonly boxAllowSet?: true;
|
|
32
|
+
/** The runner this claim runs in: its name and its process's presence incarnation (runner/presence.ts). A park that
|
|
33
|
+
* keeps a computer only this runner can reach again (computer-kept.ts pinnedOf) names both on its row, so the claim
|
|
34
|
+
* rule gives the run back to this runner while it is there. Absent: nothing kept is pinned. */
|
|
35
|
+
readonly holder?: KeptHolder;
|
|
32
36
|
}
|
|
33
37
|
/** What of the run a computer's spec is made from, besides its kind and provider: what it may reach, and whether the
|
|
34
38
|
* operator set that; and what the provider declares it makes (its capabilities()): its networks and its longest
|
|
@@ -224,11 +228,13 @@ export type MadeKind = "desktop" | "sandbox" | "phone";
|
|
|
224
228
|
export type KeptKind = Kept["kind"];
|
|
225
229
|
/** A computer the claim made fresh in place of an earlier claim's: its kind, and `folderKept`, the run's folder is on
|
|
226
230
|
* Archil (Mode 2) and mounted in it, so the folder is kept. `lapsed`: the earlier one was kept at a park, and its time
|
|
227
|
-
* (KEEP_MS) passed before this claim.
|
|
231
|
+
* (KEEP_MS) passed before this claim. `lost`: the earlier one was kept at a park pinned to another runner (or another
|
|
232
|
+
* process of this runner's name), that runner was gone by this claim, and this claim could not reach it. */
|
|
228
233
|
export type Replaced = {
|
|
229
234
|
readonly kind: MadeKind;
|
|
230
235
|
readonly folderKept: boolean;
|
|
231
236
|
readonly lapsed?: true;
|
|
237
|
+
readonly lost?: true;
|
|
232
238
|
};
|
|
233
239
|
/** The agent's computer setting: the launch's, else its revision's (computer, else place), else the launch's place. The
|
|
234
240
|
* run's end reads it the same way (run-end-computers.ts). */
|
|
@@ -15,7 +15,11 @@
|
|
|
15
15
|
// to be replaced. The claim that makes one says its kind (`made`), which the adapter loop records in the run's
|
|
16
16
|
// journal. When a later claim's replaces an earlier claim's (`replaced`: one this claim let go of, or one the run's
|
|
17
17
|
// journal says an earlier claim made, hadComputer), the ready line says so (and that the kept one's time had passed,
|
|
18
|
-
// `lapsed`), and the run's tools and model are told (run-tools.ts, the adapter loop's computer note).
|
|
18
|
+
// `lapsed`), and the run's tools and model are told (run-tools.ts, the adapter loop's computer note). A kept one only
|
|
19
|
+
// the runner that kept it can reach again (a Docker container, a machine that dials that runner: computer-kept.ts
|
|
20
|
+
// pinnedOf) names that runner and its incarnation on its row (`ClaimLaunch.holder`), and the store's claim rule lets no
|
|
21
|
+
// other runner claim the run while that runner is live and the keep lasts; one taken after it is gone and not reached
|
|
22
|
+
// here is said to be lost with it (`lost`).
|
|
19
23
|
//
|
|
20
24
|
// A sandbox the claim made can be lost mid-run (its vendor deleted it, or no longer has it): the call that finds it lost
|
|
21
25
|
// fails, saying so and that it was not run again (code gone, computer-lost.ts lostInCallWords), and is never sent to the
|
|
@@ -51,7 +55,7 @@ import { pairedProvider, withPaired } from "./attached-computers.js";
|
|
|
51
55
|
import { computerHold, heldHands } from "./computer-hold.js";
|
|
52
56
|
import { endingDeletes, figuresOf, intervalWrites } from "./computer-intervals.js";
|
|
53
57
|
import { computeMeter } from "../compute-cost.js";
|
|
54
|
-
import { deleteKept, endKept, KEEP_MS, readKept, takeKept, writeKept } from "./computer-kept.js";
|
|
58
|
+
import { deleteKept, endKept, KEEP_MS, keptBy, pinnedOf, readKept, takeKept, writeKept } from "./computer-kept.js";
|
|
55
59
|
import { storeLedger } from "./computer-ledger.js";
|
|
56
60
|
import { providerKeys, registryHere, resolveComputer } from "./resolve-computer.js";
|
|
57
61
|
import { claimHolds, fencedStore, holdSynced, storedFolder } from "./synced-folder.js";
|
|
@@ -650,9 +654,16 @@ store, deps) {
|
|
|
650
654
|
let kept = store.settings && launch.epoch > 1 ? await readKept(store.settings, launch.runId).catch(() => undefined) : undefined;
|
|
651
655
|
/** The kept computer's time passed before this claim: the new one says so (Replaced.lapsed). */
|
|
652
656
|
let lapsed = false;
|
|
657
|
+
/** The kept computer was pinned to another runner, gone by this claim, and this claim could not reach it: the new one
|
|
658
|
+
* says so (Replaced.lost). */
|
|
659
|
+
let lost = false;
|
|
653
660
|
/** What a park of this claim keeps (ClaimComputer.park): a desktop, a phone or a sandbox it made through its provider, or took
|
|
654
|
-
* back, with its provider, its connection's close and the claim epoch its labels carry
|
|
661
|
+
* back, with its provider, its connection's close and the claim epoch its labels carry; `pinned`: only this runner can
|
|
662
|
+
* reach it again (computer-kept.ts pinnedOf), so the park names this claim's holder on its row. */
|
|
655
663
|
let keepable;
|
|
664
|
+
/** Whether a computer of `entry` made with `configuration` is reachable again only by this runner: its options as
|
|
665
|
+
* vendorProvider makes it (the settings' options under the configuration's). */
|
|
666
|
+
const pinnedHere = (entry, configuration) => pinnedOf(entry, { ...settingOptions(entry.id, deps.settings ?? {}, table), ...configuration.options });
|
|
656
667
|
/** A vendor's provider (or a local one's), made with the keys and the configuration the setting selected: that
|
|
657
668
|
* configuration is built by its own create() options (Orgo's Windows: { os: "windows" }), beside the keys'. */
|
|
658
669
|
const vendorProvider = async (entry, keys, configuration) => {
|
|
@@ -770,6 +781,10 @@ store, deps) {
|
|
|
770
781
|
return undefined;
|
|
771
782
|
if (persistent || paired.some((row) => row.id === entry.id) || (deps.launch && (deps.launches?.(entry.id) ?? true)) || record.provider !== entry.id || record.kind !== kind || record.folder !== folder)
|
|
772
783
|
return undefined;
|
|
784
|
+
// Kept pinned to another runner (or another process of this runner's name): the claim rule let this claim have the
|
|
785
|
+
// run only once that runner was gone. Taken off its row, it is tried here all the same (a runner on the same host,
|
|
786
|
+
// sharing its Docker engine, finds it); one this claim cannot reach is lost with that runner, said so.
|
|
787
|
+
const elsewhere = record.runner !== undefined && !keptBy(record, launch.holder);
|
|
773
788
|
try {
|
|
774
789
|
// Its time over, or its end took it first (ending or ended): a new one, said so.
|
|
775
790
|
if (record.ending || record.ended || now() >= record.until || !(await takeKept(store.settings, launch.runId, record))) {
|
|
@@ -778,8 +793,10 @@ store, deps) {
|
|
|
778
793
|
}
|
|
779
794
|
const provider = await vendorProvider(entry, keys, configuration);
|
|
780
795
|
const taken = await keptLaunch(provider, record, signal, () => writes.ended(entry.id, record.id));
|
|
781
|
-
if (!taken)
|
|
796
|
+
if (!taken) {
|
|
797
|
+
lost = elsewhere;
|
|
782
798
|
return undefined;
|
|
799
|
+
}
|
|
783
800
|
// Metered again from here, with what its interval says it was made with: the time it was kept is no claim's.
|
|
784
801
|
const row = meter ? (await store.computerIntervals?.forRun(launch.runId).catch(() => undefined))?.find((one) => one.provider === entry.id && one.providerId === record.id) : undefined;
|
|
785
802
|
if (row)
|
|
@@ -788,7 +805,7 @@ store, deps) {
|
|
|
788
805
|
// A sandbox taken back is started again when it is lost as one this claim made (lostAware): the new one is this
|
|
789
806
|
// claim's, made from this claim's spec, its folder mounted.
|
|
790
807
|
const again = record.kind === "sandbox" ? lostAware(taken, renewalOf(provider, entry, () => specOf(entry, provider, kind, configuration, deps.signal, gpu), folder)) : taken;
|
|
791
|
-
keepable = { provider, entry: entry.id, kind: record.kind, computer: again, epoch: record.epoch };
|
|
808
|
+
keepable = { provider, entry: entry.id, kind: record.kind, computer: again, pinned: pinnedHere(entry, configuration), epoch: record.epoch };
|
|
792
809
|
ownKind = record.kind;
|
|
793
810
|
const screen = record.kind === "sandbox" ? undefined : record.kind;
|
|
794
811
|
made = { id: again.id, machine: again.machine, ...(again.watch && screen ? { watch: again.watch, gone: goneOf(provider, again.id, runLabels(launch.runId, record.epoch), screen) } : {}) };
|
|
@@ -798,6 +815,8 @@ store, deps) {
|
|
|
798
815
|
return { ...again, epoch: record.epoch };
|
|
799
816
|
}
|
|
800
817
|
catch {
|
|
818
|
+
// Taken off its row (or not), and not reached here: lost with its runner where it was pinned to another.
|
|
819
|
+
lost = elsewhere && !lapsed;
|
|
801
820
|
return undefined;
|
|
802
821
|
}
|
|
803
822
|
},
|
|
@@ -861,9 +880,9 @@ store, deps) {
|
|
|
861
880
|
if (!pairedRow)
|
|
862
881
|
ownKind = kind;
|
|
863
882
|
if (!pairedRow && (kind === "desktop" || kind === "phone" || kind === "sandbox"))
|
|
864
|
-
keepable = { provider, entry: entry.id, kind, computer: held, epoch: launch.epoch };
|
|
865
|
-
if (!pairedRow && (releasedOlder || journalSays))
|
|
866
|
-
replaced = { kind: kind, folderKept: deps.mode === 2 && mount !== undefined, ...(lapsed ? { lapsed: true } : {}) };
|
|
883
|
+
keepable = { provider, entry: entry.id, kind, computer: held, pinned: pinnedHere(entry, configuration), epoch: launch.epoch };
|
|
884
|
+
if (!pairedRow && (releasedOlder || journalSays || lost))
|
|
885
|
+
replaced = { kind: kind, folderKept: deps.mode === 2 && mount !== undefined, ...(lost ? { lost: true } : lapsed ? { lapsed: true } : {}) };
|
|
867
886
|
}
|
|
868
887
|
made = { id: launched.id, machine: launched.machine, ...(launched.watch ? { watch: launched.watch, ...(kind === "desktop" || kind === "phone" ? { gone: goneOf(provider, launched.id, listedUnder, kind) } : {}) } : {}) };
|
|
869
888
|
madeBy = entry;
|
|
@@ -1026,7 +1045,7 @@ store, deps) {
|
|
|
1026
1045
|
}
|
|
1027
1046
|
let row;
|
|
1028
1047
|
try {
|
|
1029
|
-
row = await writeKept(settings, launch.runId, { provider: keeps.entry, kind: keeps.kind, id: ref.id, name: ref.name, epoch: keeps.epoch, until: now() + KEEP_MS, ...(resolved.folder ? { folder: resolved.folder } : {}) });
|
|
1048
|
+
row = await writeKept(settings, launch.runId, { provider: keeps.entry, kind: keeps.kind, id: ref.id, name: ref.name, epoch: keeps.epoch, until: now() + KEEP_MS, ...(resolved.folder ? { folder: resolved.folder } : {}), ...(keeps.pinned && launch.holder ? { runner: launch.holder.runner, incarnation: launch.holder.incarnation } : {}) });
|
|
1030
1049
|
}
|
|
1031
1050
|
catch {
|
|
1032
1051
|
// No row, nothing to find it by: it goes as at the run's end.
|
|
@@ -2,7 +2,7 @@ import { type Result, type Swept } from "@parcha/agentrun-computer";
|
|
|
2
2
|
import { type KeyTable, type ProviderSettings } from "../computer-keys.js";
|
|
3
3
|
import { type Store } from "../store/index.js";
|
|
4
4
|
import type { ComputerDeps } from "./computer-deps.js";
|
|
5
|
-
import { type KeptSweep } from "./computer-kept.js";
|
|
5
|
+
import { type KeptHolder, type KeptSweep } from "./computer-kept.js";
|
|
6
6
|
/** How often the janitor sweeps after its first sweep at the runner's start. */
|
|
7
7
|
export declare const JANITOR_EVERY_MS: number;
|
|
8
8
|
/** The longest close() waits for a sweep it cut: a vendor call that ignores the cut is left to finish on its own. */
|
|
@@ -13,7 +13,11 @@ export declare const JANITOR_PROVIDER_MS: number;
|
|
|
13
13
|
export interface JanitorDeps {
|
|
14
14
|
/** The store: whose runs a computer's run label names, and the phone provider's ledger; with `settings` and `agents`,
|
|
15
15
|
* this server's id and its agents, whose own computers it then sweeps by their owner. */
|
|
16
|
-
readonly store: Pick<Store, "runs" | "computerLedger"> & Partial<Pick<Store, "settings" | "agents" | "computerIntervals">>;
|
|
16
|
+
readonly store: Pick<Store, "runs" | "computerLedger"> & Partial<Pick<Store, "settings" | "agents" | "computerIntervals" | "runners">>;
|
|
17
|
+
/** The runner this janitor sweeps for (its name and presence incarnation): a computer kept at a park pinned to another
|
|
18
|
+
* runner still there is that runner's to end, never this one's: its row (computer-kept.ts sweepKept) and its machine
|
|
19
|
+
* in a provider's list (sparedKept). Absent: every pinned row whose runner is there is left. */
|
|
20
|
+
readonly self?: KeptHolder;
|
|
17
21
|
/** The run's computers as the runner composed them (computer-deps.ts computerDepsFrom): the registry, the provider
|
|
18
22
|
* makers and the key reader. */
|
|
19
23
|
readonly computers: Pick<ComputerDeps, "kinds" | "providers" | "keyOf"> & {
|
|
@@ -38,15 +42,19 @@ export type ProviderSweep = {
|
|
|
38
42
|
readonly swept: Result<Swept>;
|
|
39
43
|
};
|
|
40
44
|
/** One sweep of every provider this server can list: each provider whose keys it has and whose computers the janitor
|
|
41
|
-
* ends, its computers past their deadline that are this server's and unheld ended. A
|
|
42
|
-
*
|
|
43
|
-
|
|
45
|
+
* ends, its computers past their deadline that are this server's and unheld ended. A computer kept at a park pinned to
|
|
46
|
+
* another runner still there is left out of every list (computer-kept.ts sparedKept, by the kept pass's own rule): a
|
|
47
|
+
* provider both runners list (a dial vendor's account, a shared Docker engine) would otherwise end, once its run is
|
|
48
|
+
* over, a machine the kept pass left to its runner. Where the kept rows can't be read, each provider is answered as not
|
|
49
|
+
* swept this pass. A provider that fails is answered in its words; nothing throws. */
|
|
50
|
+
export declare function sweepServerComputers(deps: Pick<JanitorDeps, "store" | "computers" | "now" | "providerMs" | "self"> & {
|
|
44
51
|
readonly log?: (line: string) => void;
|
|
45
52
|
}, signal?: AbortSignal): Promise<ProviderSweep[]>;
|
|
46
53
|
/** The pass over the desktops and phones kept at a run's park (computer-kept.ts sweepKept): one past its time, or whose
|
|
47
54
|
* run ended, is ended through its provider, made with this server's keys, whatever its lifetime (a vendor's own end is
|
|
48
|
-
* hours away)
|
|
49
|
-
|
|
55
|
+
* hours away); one pinned to another runner still there (the store's runners) is left to that runner. Undefined without
|
|
56
|
+
* the store's settings, where none is kept. Never throws. */
|
|
57
|
+
export declare function sweepKeptComputers(deps: Pick<JanitorDeps, "store" | "computers" | "now" | "self"> & {
|
|
50
58
|
readonly log?: (line: string) => void;
|
|
51
59
|
}): Promise<KeptSweep | undefined>;
|
|
52
60
|
/** The janitor: one sweep now, then one every `everyMs`, never two at once, and a kept pass at the earliest time a kept
|