@parcha/agentrun-serve 0.1.0-beta.57 → 0.1.0-beta.58
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 +52 -0
- package/README.md +64 -33
- package/dist/api-only.d.ts +2 -4
- package/dist/api-only.js +2 -4
- package/dist/box-paths.d.ts +4 -3
- package/dist/box-paths.js +7 -4
- package/dist/claude-login-token.d.ts +117 -0
- package/dist/claude-login-token.js +737 -0
- package/dist/claude-login.d.ts +52 -12
- package/dist/claude-login.js +164 -39
- package/dist/cli.js +7 -41
- package/dist/computer-attach.d.ts +35 -17
- package/dist/computer-attach.js +301 -49
- package/dist/computers.d.ts +10 -10
- package/dist/computers.js +5 -5
- package/dist/console/assets/{backend-DVhHzJX2.js → backend-CSAWUqtZ.js} +1 -1
- package/dist/console/assets/index-DPh29cyz.js +747 -0
- package/dist/console/index.html +1 -1
- package/dist/dial-relay.d.ts +25 -4
- package/dist/dial-relay.js +129 -1
- package/dist/env-switch.d.ts +1 -3
- package/dist/env-switch.js +1 -3
- package/dist/fal-price.d.ts +1 -3
- package/dist/fal-price.js +77 -26
- package/dist/learn/ledger.d.ts +170 -0
- package/dist/learn/ledger.js +218 -0
- package/dist/learn/promote.d.ts +3 -3
- package/dist/learn/promote.js +1 -1
- package/dist/learning-cost.d.ts +22 -20
- package/dist/learning-cost.js +15 -21
- package/dist/live-reach.d.ts +2 -0
- package/dist/live-reach.js +2 -0
- package/dist/mcp-api-only-origins.d.ts +8 -3
- package/dist/mcp-api-only-origins.js +17 -17
- package/dist/micro.d.ts +2 -0
- package/dist/micro.js +2 -0
- package/dist/model.d.ts +5 -4
- package/dist/model.js +7 -6
- package/dist/monid.d.ts +14 -1
- package/dist/monid.js +103 -26
- package/dist/openapi.js +34 -12
- package/dist/place-offers.d.ts +4 -0
- package/dist/place-offers.js +7 -4
- package/dist/provider.d.ts +2 -2
- package/dist/provider.js +9 -5
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-view.d.ts +1 -2
- package/dist/run-view.js +2 -1
- package/dist/runner/adapter-loop.js +3 -16
- package/dist/runner/adapter-run-spec.d.ts +20 -13
- package/dist/runner/adapter-run-spec.js +57 -48
- package/dist/runner/beside.d.ts +9 -2
- package/dist/runner/beside.js +24 -7
- package/dist/runner/claim-secrets.d.ts +17 -15
- package/dist/runner/claim-secrets.js +32 -34
- package/dist/runner/cli-run-spec.js +21 -9
- package/dist/runner/held.d.ts +16 -4
- package/dist/runner/main.d.ts +11 -6
- package/dist/runner/main.js +12 -7
- package/dist/runner/mcp-claim.js +3 -2
- package/dist/runner/mcp-run.d.ts +3 -6
- package/dist/runner/mcp-run.js +3 -4
- package/dist/runner/presence.d.ts +11 -1
- package/dist/runner/presence.js +7 -0
- package/dist/runner/reflect-hook.js +1 -1
- package/dist/runner/run-child-host.d.ts +19 -8
- package/dist/runner/run-child-host.js +80 -34
- package/dist/runner/runner.d.ts +3 -0
- package/dist/runner/runner.js +1 -1
- package/dist/runner/save-slots.js +2 -1
- package/dist/runner/subagent.d.ts +11 -0
- package/dist/runner/subagent.js +17 -3
- package/dist/runner/workflow-first.d.ts +27 -14
- package/dist/runner/workflow-first.js +29 -22
- package/dist/runner/workflow-spec.js +1 -1
- package/dist/server.d.ts +18 -7
- package/dist/server.js +150 -64
- package/dist/slots.d.ts +9 -0
- package/dist/slots.js +45 -0
- package/dist/store/postgres/migrations/0028_learning_ledger.sql +44 -0
- package/dist/store/schema.d.ts +17 -0
- package/dist/store/schema.js +47 -1
- package/dist/store/sqlite/run-patch.d.ts +11 -1
- package/dist/store/sqlite/run-patch.js +29 -1
- package/dist/store/sqlite/store.js +72 -9
- package/dist/store/store.d.ts +14 -0
- package/dist/store-reads/learning.d.ts +81 -124
- package/dist/store-reads/learning.js +207 -286
- package/dist/template-eval.d.ts +19 -0
- package/dist/template-eval.js +92 -43
- package/dist/template-import.d.ts +0 -10
- package/dist/template-import.js +5 -10
- package/dist/timeline/web-calls.d.ts +12 -14
- package/dist/timeline/web-calls.js +14 -30
- package/dist/web-save.d.ts +4 -9
- package/dist/web-save.js +4 -43
- package/dist/workspace/attached-computers.d.ts +32 -9
- package/dist/workspace/attached-computers.js +77 -13
- package/dist/workspace/computer-deps.d.ts +6 -1
- package/dist/workspace/computer-deps.js +1 -1
- package/dist/workspace/computer-for-claim.js +6 -3
- package/dist/workspace/paired-route.d.ts +91 -0
- package/dist/workspace/paired-route.js +153 -0
- package/dist/wrapped.d.ts +8 -2
- package/dist/wrapped.js +21 -6
- package/package.json +12 -12
- package/templates/README.md +3 -3
- package/dist/console/assets/index-okP-y8PK.js +0 -747
package/dist/server.js
CHANGED
|
@@ -27,7 +27,7 @@ import { isNativeRuntime, NATIVE_RUNTIME_FACTS } from "./native/runtimes.js";
|
|
|
27
27
|
import { connectNative, launchNative, updateNative, verifyConnection } from "./native/connection.js";
|
|
28
28
|
// The /v2 API over the agent store in a data directory: the contract agentrun.v2/0, served on loopback with a bearer
|
|
29
29
|
// token.
|
|
30
|
-
import { createHash, createHmac, randomBytes } from "node:crypto";
|
|
30
|
+
import { createHash, createHmac, randomBytes, randomUUID } from "node:crypto";
|
|
31
31
|
import { chmod, lstat, mkdir, readFile, realpath, rename, stat, writeFile } from "node:fs/promises";
|
|
32
32
|
import { createServer } from "node:http";
|
|
33
33
|
import proxyaddr from "proxy-addr";
|
|
@@ -51,14 +51,14 @@ import { agentRevision, agentRevisions, agentView, commitAgent, createAgent, def
|
|
|
51
51
|
import { WORKFLOW_ADAPTERS } from "./runner/workflow-adapters.js";
|
|
52
52
|
import { DECISION_ADAPTER, decisionsOf, FAUX_JEV_ENV, FAUX_OPENROUTER_ENV, FAUX_PARALLEL_ENV, fauxFetch } from "./decisions.js";
|
|
53
53
|
import { FAUX_EXA_ENV, FAUX_FIRECRAWL_ENV, FAUX_WEB_ENV } from "./web-run.js";
|
|
54
|
-
import { FAUX_MONID_ENV, MONID_KEY_ENV, pinMonid, PRICED_BY_USAGE } from "./monid.js";
|
|
54
|
+
import { FAUX_MONID_ENV, MONID_KEY_ENV, monidReads, pinMonid, PRICED_BY_USAGE } from "./monid.js";
|
|
55
55
|
import { FAUX_BROWSER_ENV, NODE_TOOLS, shellTools, toolingOf, toolOf, toolsView } from "./tools.js";
|
|
56
56
|
import { ApiError, invalid, sentence, unsupported } from "./errors.js";
|
|
57
57
|
import { deref, explain } from "./explain.js";
|
|
58
58
|
import { HOME_HOST_OWNED } from "./files.js";
|
|
59
59
|
import { DATA_ENV, syncDir, TOKEN_FILE, writeDurable } from "./server-fs.js";
|
|
60
60
|
import { homePath, hostOwnedOf } from "./home-path.js";
|
|
61
|
-
import { asksOllama, chooseModel, EFFORTS, FAUX_ENV, MODEL_NODES, modelSource, THINKING_LEVELS, unpricedModels, withoutFaux } from "./model.js";
|
|
61
|
+
import { asksOllama, chooseModel, EFFORTS, FAUX_ENV, hostModel, MODEL_NODES, modelSource, THINKING_LEVELS, unpricedModels, withoutFaux } from "./model.js";
|
|
62
62
|
import { DEFAULT_HARNESS, HARNESSES, harnessOfBody, harnessOffers } from "./harness.js";
|
|
63
63
|
import { HARNESS_MODULES_ENV, HARNESS_MODULES_SETTING, HARNESS_RECIPES_ENV, HARNESS_RECIPES_SETTING, HARNESS_TABLE_ENV, harnessIds, harnessModulesEnv, harnessOf, harnessRecipesEnv, planRecipesOf, recipeHarness, tableIds } from "./harness-table.js";
|
|
64
64
|
import { claudeCliIn, HarnessInstall, installDirOf, NPM_STOP_GRACE_MS, npmInstall } from "./harness-install.js";
|
|
@@ -144,15 +144,16 @@ import { hostSecrets, SECRET_NAMES, secret, withSecrets } from "./secrets.js";
|
|
|
144
144
|
import { isSecretWriteOperation, secretPageFor, secretsWritableFields, secretWriteRefusal, secretWriterFacts, writesSecretFor, writesSecretsAllowed } from "./secret-writes.js";
|
|
145
145
|
import { ChatGPTPlan, planOf, PlanSignInRefused, SIGN_OUT_UNCONFIRMED, withPlan } from "./chatgpt-plan.js";
|
|
146
146
|
import { modelGatewayRoute, readSavedGateway, withSavedGateway } from "./model-gateway.js";
|
|
147
|
-
import { CLAUDE_LOGIN_ROUTES, LOGIN_REFUSES_API_KEYS, oneOwnerDeps, ClaudeLoginRefused, claudeLoginOf, claudeLoginRouteOff, claudeLoginSwitchedOff, claudeLoginSetting, claudeLoginView, dropRefusedLogin, envAtPlace, LOGIN_HARNESS, loginOf, loopback, startLoginHere, turnOffClaudeLogin, turnOnClaudeLogin, withClaudeLogin } from "./claude-login.js";
|
|
147
|
+
import { CLAUDE_LOGIN_ROUTES, LOGIN_REFUSES_API_KEYS, oneOwnerDeps, ClaudeLoginRefused, claudeLoginOf, claudeLoginRouteOff, claudeLoginSwitchedOff, claudeLoginSetting, claudeLoginView, dropRefusedLogin, envAtPlace, homeOf, LOGIN_HARNESS, loginOf, loginOnRunnerOnly, loopback, startLoginHere, turnOffClaudeLogin, turnOnClaudeLogin, withClaudeLogin } from "./claude-login.js";
|
|
148
148
|
import { ClaudeSignIns } from "./claude-sign-in.js";
|
|
149
149
|
import { bootSealKey, parametersDigest, withSealKey } from "./seal-key.js";
|
|
150
150
|
import { ServerLockHeldError, takeServerLock } from "./server-lock.js";
|
|
151
151
|
import { recordDataRoot } from "./runner/disk-free.js";
|
|
152
152
|
import { recordRunEnv, runFacingNames } from "./runner/runner-check.js";
|
|
153
153
|
import { DRAIN_TIMEOUT } from "./runner/beside.js";
|
|
154
|
+
import { runnerName } from "./runner/runner.js";
|
|
154
155
|
import { analyticsFilter, analyticsView, statsView } from "./stats.js";
|
|
155
|
-
import {
|
|
156
|
+
import { loggedReads, within, WRAPPED_WAIT_MS, wrappedView } from "./wrapped.js";
|
|
156
157
|
import { joinedBasis } from "./runner/metrics.js";
|
|
157
158
|
import { unifiedUsage } from "./unified-usage.js";
|
|
158
159
|
import { agentLoopOverStore } from "./store-reads/loop.js";
|
|
@@ -215,8 +216,10 @@ import { COMPUTER_ROUTES, computerHoldOf, computerRoute, runComputerKind } from
|
|
|
215
216
|
import { runOver } from "./computer-commands.js";
|
|
216
217
|
import { mintViewerCredential, VIEWER_PARAM, viewerCookie, viewerCredentialFor, viewerCredentialKey, viewerCredentialOf } from "./viewer-credential.js";
|
|
217
218
|
import { ATTACH_PATH, AttachHub, PROVIDERS as COMPUTER_PROVIDERS, SETTING_KINDS, servingRefusals } from "@parcha/agentrun-computer";
|
|
219
|
+
import { dockerDaemonOf } from "@parcha/agentrun-computer/docker";
|
|
218
220
|
import { createAttachRoutes, liveRelays, pairedView } from "./computer-attach.js";
|
|
219
221
|
import { pairedRefusal, withPaired } from "./workspace/attached-computers.js";
|
|
222
|
+
import { PAIRED_ROUTE_MS, readRoute } from "./workspace/paired-route.js";
|
|
220
223
|
import { COMPUTER_TOOLS, hostToolDefs } from "@parcha/agentrun-kernel/kernel";
|
|
221
224
|
import { freeModelRequestsOf } from "@parcha/agentrun-kernel/kernel/cap";
|
|
222
225
|
import { archilRoute, createArchilRoutes, liveRunsOnDisk } from "./archil-routes.js";
|
|
@@ -653,7 +656,7 @@ const GATEWAY_VARS = ["AGENT_MODEL_BASE_URL", "AGENT_MODEL_GATEWAY_IDS", "AGENT_
|
|
|
653
656
|
* saved key is one of those; the rest of the environment is the server's start's), and the models the Ollama here
|
|
654
657
|
* listed when last asked (ollamaListing). Held to tell whether a write, or a new listing, needs the offers probed again,
|
|
655
658
|
* never shown. */
|
|
656
|
-
const offersInputs = (env) => [...SECRET_NAMES.filter((name) => !TOOL_FIELDS.includes(name)).map((name) => env[name]), ...GATEWAY_VARS.map((name) => env[name]), planOf(env)?.state, planOf(env)?.models.join(" "), claudeLoginOf(env)
|
|
659
|
+
const offersInputs = (env) => [...SECRET_NAMES.filter((name) => !TOOL_FIELDS.includes(name)).map((name) => env[name]), ...GATEWAY_VARS.map((name) => env[name]), planOf(env)?.state, planOf(env)?.models.join(" "), ...[claudeLoginOf(env)].map((login) => (login && "dir" in login ? login.dir : undefined)), ollamaListing(env)];
|
|
657
660
|
/** A sign-in step's answer; its refusal (a stale or bad pasted address, no sign-in waiting, OpenAI's no) a 400 in words. */
|
|
658
661
|
async function planStep(step) {
|
|
659
662
|
try {
|
|
@@ -892,8 +895,9 @@ export function whyNotOwnMachine(options, data, ownUser) {
|
|
|
892
895
|
}
|
|
893
896
|
/** Why `options` on `data` is not one owner's server on their own machine as far as who reaches it goes, each reason in
|
|
894
897
|
* words: whyNotOwnMachine's facts but its runner's. What may read this machine's own files for whoever asks (GET
|
|
895
|
-
* /v2/wrapped).
|
|
896
|
-
|
|
898
|
+
* /v2/wrapped). `keys`: the live API keys made in the console (api-keys.ts), each one more caller, as a second token is
|
|
899
|
+
* (claude-login.ts whyNotOneOwner counts them too); 0 where none can open the server. */
|
|
900
|
+
export function whyNotOwnersServer(options, data, keys = 0) {
|
|
897
901
|
const host = options.host ?? DEFAULT_HOST;
|
|
898
902
|
// Every token the server takes (acceptedTokens): AGENTRUN_TOKEN's as `default` beside the list's, or else DIR/.token's alone.
|
|
899
903
|
const tokens = (options.token === undefined ? 0 : 1) + (options.tokens?.length ?? 0);
|
|
@@ -902,6 +906,7 @@ export function whyNotOwnersServer(options, data) {
|
|
|
902
906
|
...(options.publicUrl ? [`has a public address (${options.publicUrl})`] : []),
|
|
903
907
|
...(options.apiOnly ? ["has no owner (the API-only profile), so anyone with its token starts runs"] : []),
|
|
904
908
|
...(tokens > 1 ? [`takes ${tokens} API tokens (AGENTRUN_TOKEN and AGENTRUN_TOKENS together), so more than one person starts runs`] : []),
|
|
909
|
+
...(keys > 0 ? [`has ${keys === 1 ? "an API key" : `${keys} API keys`} made for apps (Settings → AgentRun API keys), so more than one caller reaches it`] : []),
|
|
905
910
|
...(storeTarget(data).kind === "sqlite" ? [] : ["keeps its store in Postgres (AGENTRUN_STORE_URL), which servers elsewhere share"]),
|
|
906
911
|
];
|
|
907
912
|
}
|
|
@@ -1083,6 +1088,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1083
1088
|
// which the runner beside the server shares (Serve.attachHub), so one process holds them. A second server on this
|
|
1084
1089
|
// store is refused above (its owner lock).
|
|
1085
1090
|
const attachHub = new AttachHub();
|
|
1091
|
+
// The runner beside this server, as its run's route of a paired box names it (Serve.beside): a new name and
|
|
1092
|
+
// incarnation at each start, so a route an earlier start's runner left names a runner that is gone, and goes stale.
|
|
1093
|
+
const beside = { runner: runnerName(), incarnation: randomUUID() };
|
|
1086
1094
|
// The data root's own lock, once the store is held (so a deploy on Postgres waits at the store's owner lock first): the
|
|
1087
1095
|
// store's lock holds one store, but the data root also holds what the server writes beside it (its token, its seal key,
|
|
1088
1096
|
// uploads, harness installs, learning folders), which two servers on two stores (two Postgres schemas, or SQLite and
|
|
@@ -1126,12 +1134,26 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1126
1134
|
// the proxy's proof under the seal key (live-reach.ts); any other host is never dialled. A hosted machine a runner in a
|
|
1127
1135
|
// process of its own made is relayed to that runner's attach listener the same way (dial-relay.ts).
|
|
1128
1136
|
const reach = liveReachOf(process.env, seal.key);
|
|
1137
|
+
// A runner in a process of its own that relays its dials (dial-relay.ts): one whose attach listener said it is there
|
|
1138
|
+
// within PRESENCE_STALE_MS on the store's clock (liveRelays), at a host this server dials.
|
|
1139
|
+
const relayedNow = async () => (await liveRelays(store.runners)).some((row) => dialHost(row.host, reach) !== undefined);
|
|
1140
|
+
const attachLog = (event, fields) => (log ? log(logLine(event, fields)) : void process.stderr.write(`agentrun-serve: ${logLine(event, fields)}\n`));
|
|
1129
1141
|
const attach = createAttachRoutes({
|
|
1130
|
-
store, hub: attachHub, machinesOnly: options.apiOnly === true, runnerApart: options.runnerApart === true,
|
|
1142
|
+
store, hub: attachHub, machinesOnly: options.apiOnly === true, runnerApart: options.runnerApart === true, relayed: relayedNow,
|
|
1131
1143
|
relay: { runners: store.runners, reach },
|
|
1144
|
+
beside,
|
|
1132
1145
|
...(options.attachTiming ? { timing: options.attachTiming } : {}),
|
|
1133
|
-
log:
|
|
1146
|
+
log: attachLog,
|
|
1134
1147
|
});
|
|
1148
|
+
// A paired computer's socket goes where its route says (workspace/paired-route.ts): the tick moves a socket in the
|
|
1149
|
+
// wrong place, every PAIRED_ROUTE_MS. A runner apart takes a route whether this server's own runner runs beside it or
|
|
1150
|
+
// not (its runners on other hosts, AGENTRUN_RUNNER_HOSTS), so the tick runs on both. It does nothing while no computer
|
|
1151
|
+
// is paired; with a runner beside it, nothing past its one read of the routes while no route row is there and no box
|
|
1152
|
+
// is relayed (computer-attach.ts tick).
|
|
1153
|
+
const routeTick = options.apiOnly !== true
|
|
1154
|
+
? setInterval(() => void attach.tick().catch((error) => attachLog("computer_route_tick_failed", { error: error instanceof Error ? error.message : String(error) })), PAIRED_ROUTE_MS)
|
|
1155
|
+
: undefined;
|
|
1156
|
+
routeTick?.unref();
|
|
1135
1157
|
// This server's own key on every environment it reads its secrets from, so a reader opens what this store holds with the
|
|
1136
1158
|
// key checked against it, never another data directory's that this process booted too (secrets.ts holds one made key).
|
|
1137
1159
|
const own = (env) => withSealKey(env, seal.text);
|
|
@@ -1156,6 +1178,8 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1156
1178
|
// A start that fails aborts it too: what began on it (the host-address read's retry) stops with that start.
|
|
1157
1179
|
const stopping = new AbortController();
|
|
1158
1180
|
stops.push(async () => stopping.abort());
|
|
1181
|
+
/** monid's listing and inspects as this server's saves read them: a burst of saves reads each once (monid.ts monidReads). */
|
|
1182
|
+
const monidShared = monidReads();
|
|
1159
1183
|
/** The after-start seal by the events' schemas (composio-triggers.ts sealMarked), drained by stop. */
|
|
1160
1184
|
let schemaSealed = Promise.resolve();
|
|
1161
1185
|
// The start's sweep of ended runs whose stored cost is unknown (cost-heal.ts), once this server listens; stop drains it.
|
|
@@ -1252,9 +1276,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1252
1276
|
// turnOnClaudeLogin, through oneOwnerDeps' `turn`), one at a time: each decides by what the others left once their writes
|
|
1253
1277
|
// landed or were undone, never by a key taken out for a removal that then fails.
|
|
1254
1278
|
// The sign-in this server starts, kept for this process (claude-sign-in.ts). Its queue is the one way the login's
|
|
1255
|
-
// setting changes, the drop here included.
|
|
1279
|
+
// setting changes, the drop here included. A server whose user owns no home for the login (homeOf) drops it too.
|
|
1256
1280
|
const claudeSignIns = new ClaudeSignIns({ limitMs: options.claudeSignInLimitMs });
|
|
1257
|
-
await dropRefusedLogin(claudeSignIns, store.settings, loginOff ?? oneOwner.refused(), (line) => (log ? log(logLine("claude_login", { line })) : void process.stderr.write(`agentrun-serve: ${line}\n`)));
|
|
1281
|
+
await dropRefusedLogin(claudeSignIns, store.settings, loginOff ?? oneOwner.refused() ?? homeOf(base).refused, (line) => (log ? log(logLine("claude_login", { line })) : void process.stderr.write(`agentrun-serve: ${line}\n`)));
|
|
1258
1282
|
// The status checks' folders a server killed mid-check left in the temporary folder, each with a copy of the account
|
|
1259
1283
|
// file (the harness's sweepClaudeStatusFolders): this user's alone, and only once the check has ended by the end it
|
|
1260
1284
|
// wrote in its folder, so a check another server on this host runs now stays. Where the mode is there, as status
|
|
@@ -1295,26 +1319,43 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1295
1319
|
// What the offers held now were made from (offersInputs), and the latest probe: one a later probe overtook is dropped.
|
|
1296
1320
|
let offersFrom;
|
|
1297
1321
|
let probes = 0;
|
|
1298
|
-
// What the latest probe is made from, once it has read it, until it lands: none while no probe is out. A
|
|
1299
|
-
//
|
|
1300
|
-
// when they are made from them, and a change with any other inputs probes again.
|
|
1322
|
+
// What the latest probe is made from, once it has read it, until it lands or fails: none while no probe is out. A
|
|
1323
|
+
// probe that fails never lands; when it is the latest, it clears this as it fails, so no probe is out after it.
|
|
1301
1324
|
let probing;
|
|
1302
|
-
|
|
1325
|
+
// The latest probe's turn: it ends as that probe lands or fails, or as a later probe starts and overtakes it, whichever
|
|
1326
|
+
// is first, and never fails. A change that waits for the probe out waits for its turn (keysChanged), so a dropped
|
|
1327
|
+
// probe holds no one up and its failure is no one else's.
|
|
1328
|
+
let turn = Promise.resolve();
|
|
1329
|
+
let endTurn = () => { };
|
|
1330
|
+
const probe = (why) => {
|
|
1331
|
+
endTurn();
|
|
1332
|
+
turn = new Promise((resolve) => (endTurn = resolve));
|
|
1333
|
+
const probed = probeOffers(why);
|
|
1334
|
+
probed.then(endTurn, endTurn);
|
|
1335
|
+
return probed;
|
|
1336
|
+
};
|
|
1337
|
+
const probeOffers = async (why) => {
|
|
1303
1338
|
const mine = ++probes;
|
|
1304
1339
|
probing = undefined;
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1340
|
+
try {
|
|
1341
|
+
// The Ollama listing the offers are made from is read before they are, so the first capabilities do not remake them.
|
|
1342
|
+
if (asksOllama(env))
|
|
1343
|
+
await ollamaModels(env);
|
|
1344
|
+
const from = offersInputs(env);
|
|
1345
|
+
if (mine === probes)
|
|
1346
|
+
probing = from;
|
|
1347
|
+
const started = performance.now();
|
|
1348
|
+
const next = await harnessOffers(offersEnvOf(env));
|
|
1349
|
+
log?.(logLine("harness_offers", { why, ms: Math.round(performance.now() - started) }));
|
|
1350
|
+
if (mine !== probes)
|
|
1351
|
+
return;
|
|
1352
|
+
[offers, offersFrom] = [next, from];
|
|
1353
|
+
recompose();
|
|
1354
|
+
}
|
|
1355
|
+
finally {
|
|
1356
|
+
if (mine === probes)
|
|
1357
|
+
probing = undefined;
|
|
1358
|
+
}
|
|
1318
1359
|
};
|
|
1319
1360
|
/** Whether `a` and `b` are the same offers' inputs (offersInputs). */
|
|
1320
1361
|
const sameInputs = (a, b) => a.length === b.length && a.every((value, i) => value === b[i]);
|
|
@@ -1342,15 +1383,29 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1342
1383
|
const next = await needsOf(env);
|
|
1343
1384
|
if (mine === needsAsked)
|
|
1344
1385
|
needs = next;
|
|
1345
|
-
const inputs = offersInputs(env);
|
|
1346
1386
|
// A probe still out from other inputs (a turn-on's, after its turn-off) would put back offers made from them as it
|
|
1347
|
-
// lands: a probe of these overtakes it. Only a change starts one, one per change, so nothing loops.
|
|
1348
|
-
//
|
|
1349
|
-
//
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1387
|
+
// lands: a probe of these overtakes it. Only a change starts one, at most one per change, so nothing loops. While the
|
|
1388
|
+
// probe out has read these inputs, a change starts none: with the offers held made from them too it recomposes at
|
|
1389
|
+
// once; with them behind (a tool key saved while a turn-on's probe is out) it waits for that probe's turn, then
|
|
1390
|
+
// decides again from the inputs read then (a later change's, if one landed meanwhile): the probe landed, and it
|
|
1391
|
+
// recomposes; it failed, and the change probes for itself; a later probe overtook it, and the change goes by that
|
|
1392
|
+
// one. So it never answers another request's failure, and never waits on a dropped probe. With no probe out that has
|
|
1393
|
+
// read its inputs (none out, or the latest still reading the Ollama listing), it recomposes when the offers held are
|
|
1394
|
+
// made from these inputs and probes when not; a probe it starts itself fails it if it fails.
|
|
1395
|
+
for (;;) {
|
|
1396
|
+
const inputs = offersInputs(env);
|
|
1397
|
+
const out = probing !== undefined && sameInputs(probing, inputs);
|
|
1398
|
+
if (out && !offersMadeFrom(inputs)) {
|
|
1399
|
+
log?.(logLine("harness_offers_wait", { why: "key" }));
|
|
1400
|
+
await turn;
|
|
1401
|
+
continue;
|
|
1402
|
+
}
|
|
1403
|
+
if (offersMadeFrom(inputs) && (probing === undefined || out))
|
|
1404
|
+
recompose();
|
|
1405
|
+
else
|
|
1406
|
+
await probe("key");
|
|
1407
|
+
return;
|
|
1408
|
+
}
|
|
1354
1409
|
};
|
|
1355
1410
|
/** The Ollama here, as capabilities read it: its listing asked again behind the answer once stale (ollamaModels), and
|
|
1356
1411
|
* the reading made again, as a key's save does, once a listing differs from the one the offers were made from. So a
|
|
@@ -1401,7 +1456,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1401
1456
|
const fauxDocker = Boolean(options.faux) && options.fauxDocker === true;
|
|
1402
1457
|
// A faux server's probe is on a host, as its Docker paths are below, so a test reads the same words in a container;
|
|
1403
1458
|
// `probeContainer` sets it for a test of a real one.
|
|
1404
|
-
|
|
1459
|
+
// The probe names Docker's architecture too, which says which computerd build a Docker computer binds (below).
|
|
1460
|
+
let dockerArch;
|
|
1461
|
+
const found = await placeOffers(env, { keyOf: keyReader(store, seal.key, env), fauxDocker, dockerArch: (arch) => (dockerArch = arch), ...(options.probeContainer ? { container: options.probeContainer } : options.faux ? { container: { inside: false } } : {}) });
|
|
1405
1462
|
const docker = found.some((offer) => offer.id === "docker" && offer.available);
|
|
1406
1463
|
// Under --faux, the mountinfo a test gives (fauxMountinfo, or FAUX_MOUNTINFO_ENV in the process's own environment, which
|
|
1407
1464
|
// `env` leaves out: a server under test in a container names its own /proc/self/mountinfo there); with none, a faux
|
|
@@ -1416,9 +1473,14 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1416
1473
|
// A run's Docker computer mounts the run's folder, and the computer's daemon, by this server's paths: as they are on
|
|
1417
1474
|
// its Docker's own host, or as its named data volume's subpaths from a container of that Docker's (compose.yaml).
|
|
1418
1475
|
// Any other layout, or a daemon of another machine (DOCKER_HOST, or the current context's endpoint: box-paths.ts
|
|
1419
|
-
// remoteDockerOnce), can't run one, and
|
|
1420
|
-
//
|
|
1421
|
-
|
|
1476
|
+
// remoteDockerOnce), can't run one, and neither can a server with no computerd build for its Docker's architecture as
|
|
1477
|
+
// the probe named it (`npm run build` without `npm run build:daemon`): the computer package's dockerDaemonOf, the file
|
|
1478
|
+
// and words its create() takes. Each says so here (dockerComputerRefusal), where capabilities, the run's start
|
|
1479
|
+
// (dockerAnswers) and a place's box check all read it: no run starts only to fail at its create. A faux server checks
|
|
1480
|
+
// the build only in the directory a test names (fauxDaemonDir); an architecture the probe didn't name is left to create().
|
|
1481
|
+
const daemonDir = options.faux ? options.fauxDaemonDir : undefined;
|
|
1482
|
+
const noDaemon = dockerArch === undefined || (options.faux && daemonDir === undefined) ? undefined : (daemonDir === undefined ? dockerDaemonOf(dockerArch) : dockerDaemonOf(dockerArch, daemonDir)).missing;
|
|
1483
|
+
const dockerUnrunnable = fauxDocker || !docker ? undefined : dockerComputerRefusal(dockerPaths, await remoteDockerOnce(env), noDaemon);
|
|
1422
1484
|
// From a container, a Docker computer keeps this server's allow-list only knowing the Docker host's own addresses: the
|
|
1423
1485
|
// union of the read through the socket and AGENTRUN_DOCKER_HOST_ADDRESSES (docker-host-addresses.ts), the same read the
|
|
1424
1486
|
// runner beside this server takes. Said at the start with what was found; with none, Docker isn't offered, in words.
|
|
@@ -1431,13 +1493,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1431
1493
|
const boxesOf = (hostAddresses) => {
|
|
1432
1494
|
if (hostAddresses)
|
|
1433
1495
|
log?.(logLine("docker_host_addresses", { addresses: hostAddresses.addresses.join(",") || "none", ...(hostAddresses.why ? { read: hostAddresses.why } : {}) }));
|
|
1434
|
-
const dockerRefused =
|
|
1496
|
+
const dockerRefused = dockerUnrunnable ?? (hostAddresses && hostAddresses.addresses.length === 0 ? noHostAddresses(hostAddresses.why ?? "the read through Docker's socket found none") : undefined);
|
|
1435
1497
|
// Each box with what it reaches (place-offers.ts withNetworks).
|
|
1436
1498
|
const offers = withNetworks(found, boxAllow, { ...(dockerRefused !== undefined ? { refused: dockerRefused } : {}), ...(hostAddresses ? { hostAddresses: hostAddresses.addresses } : {}), faux: fauxDocker });
|
|
1437
1499
|
log?.(logLine("boxes", boxesLog(offers, enabledBoxes(env))));
|
|
1438
1500
|
return offers;
|
|
1439
1501
|
};
|
|
1440
|
-
const hostAddresses =
|
|
1502
|
+
const hostAddresses = dockerUnrunnable === undefined && "paths" in dockerPaths && boxAllow !== "none" ? unionOf(await hostAddressesOnce(env), dockerHostAddressesOf(env)) : undefined;
|
|
1441
1503
|
let boxOffers = boxesOf(hostAddresses);
|
|
1442
1504
|
const hostRetried = hostAddresses === undefined || hostAddresses.why === undefined
|
|
1443
1505
|
? Promise.resolve()
|
|
@@ -1507,11 +1569,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1507
1569
|
// A provider's key set where the server starts is one of its secrets, held off process.env (secrets.ts): read by name
|
|
1508
1570
|
// from what the server was started with, as computerReady below reads it.
|
|
1509
1571
|
store, sealKey, tools: kindTools, mode: folderModeOf(store, process.env), env: withSecrets(process.env, "own"),
|
|
1510
|
-
|
|
1572
|
+
// Each with its route (who holds it, on which runner, and why a route was refused), and online while relayed.
|
|
1573
|
+
paired: { rows: () => store.pairedComputers.list(), viewOf: async (row, serves, runsRefused) => pairedView(row, attachHub, serves, runsRefused, await readRoute(store.settings, row.id), attach.relayedTo(row.id) !== undefined) },
|
|
1511
1574
|
runnerApart: options.runnerApart === true,
|
|
1512
|
-
|
|
1513
|
-
// within PRESENCE_STALE_MS on the store's clock (liveRelays), at a host this server dials.
|
|
1514
|
-
relayed: async () => (await liveRelays(store.runners)).some((row) => dialHost(row.host, reach) !== undefined),
|
|
1575
|
+
relayed: relayedNow,
|
|
1515
1576
|
...(options.faux
|
|
1516
1577
|
// --faux's providers stand in for every vendor's, a local one's daemon included.
|
|
1517
1578
|
? { kinds: fauxOf().kinds, factories: fauxOf().factories, keyTable: fauxOf().keyTable }
|
|
@@ -1537,11 +1598,11 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1537
1598
|
/** A key as the runner reads it: the secrets this process was started with (withSecrets "own"), else the saved one. */
|
|
1538
1599
|
const runnerKeys = () => keyReader(store, sealKey, own(withSecrets(process.env, "own")));
|
|
1539
1600
|
// A paired computer is one more provider of the registry (workspace/attached-computers.ts), ready while its driver is
|
|
1540
|
-
// attached to this process's hub.
|
|
1601
|
+
// attached: to this process's hub, or relayed to the runner that holds a run of it.
|
|
1541
1602
|
const computerReady = async (setting) => {
|
|
1542
1603
|
const paired = await store.pairedComputers.list();
|
|
1543
1604
|
const row = paired.find((one) => one.id === setting.provider);
|
|
1544
|
-
const offline = row ? pairedRefusal(row, attachHub) : undefined;
|
|
1605
|
+
const offline = row ? pairedRefusal(row, { online: (id) => attachHub.online(id) || attach.relayedTo(id) !== undefined }) : undefined;
|
|
1545
1606
|
if (offline)
|
|
1546
1607
|
return { refused: offline };
|
|
1547
1608
|
return computerReadiness(setting, await modeNow(), withPaired(claimRegistry(), paired), runnerKeys(), dockerAnswers, boxAllow, (provider) => (Object.hasOwn(hostWhy, provider) ? hostWhy[provider] : undefined));
|
|
@@ -1600,7 +1661,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1600
1661
|
};
|
|
1601
1662
|
/** The run read's costs (A8, store-reads/learning.ts runAllInOverStore): `cost.usd` its own spend, the
|
|
1602
1663
|
* job's (its compile turn is learning's), null while unknown; what learning spent for it
|
|
1603
|
-
* (`learning_usd`) and the two (`all_in_usd`)
|
|
1664
|
+
* (`learning_usd`) and the two (`all_in_usd`), with what makes up `learning_usd` (`compile_usd`, `followup_usd`,
|
|
1665
|
+
* `shadow_usd`, `share_usd`): the figures the agent's cost page gives the run (learn/ledger.ts figuresOf, one formula).
|
|
1666
|
+
* A cost known only as a bound keeps its bound, and all-in is unknown.
|
|
1604
1667
|
* `tools_usd`: the part of `usd` its paid tool calls cost (store-view.ts toolsUsdOverStore). */
|
|
1605
1668
|
const allInViewOf = async (runId, view) => {
|
|
1606
1669
|
const cost = (view.cost ?? {});
|
|
@@ -1622,9 +1685,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1622
1685
|
}));
|
|
1623
1686
|
if (!all)
|
|
1624
1687
|
return {};
|
|
1625
|
-
// A bound stays the view's bound. Otherwise usd is the job's (
|
|
1688
|
+
// A bound stays the view's bound. Otherwise usd is the job's (its ledger row's, the same figure the cost series
|
|
1626
1689
|
// gives): known as it answered even when its compile turn's cost is not; the row's while the run is at work.
|
|
1627
|
-
|
|
1690
|
+
const { learning_usd, all_in_usd, compile_usd, followup_usd, shadow_usd, share_usd } = all;
|
|
1691
|
+
return { cost: { ...cost, ...(cost.upper_bound === true ? {} : { usd: all.usd }), tools_usd: await toolsUsdOverStore(store, runId), learning_usd, all_in_usd, compile_usd, followup_usd, shadow_usd, share_usd, ...(degraded ? { degraded: true } : {}) } };
|
|
1628
1692
|
};
|
|
1629
1693
|
// The agents accessor the routes call, over the one store (module A): the agents-store functions, with the run-row reads
|
|
1630
1694
|
// the server makes (store-reads) under `.store`. `.request` is a thin pass-through — the store runs its own transactions,
|
|
@@ -2482,8 +2546,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2482
2546
|
});
|
|
2483
2547
|
});
|
|
2484
2548
|
// GET /v2/wrapped's reads of this machine's home (wrapped.ts), each year's on the import worker, so its parsing never holds
|
|
2485
|
-
// up a request; shared and kept as keptReads says. A read the close ended answers `stopped
|
|
2486
|
-
|
|
2549
|
+
// up a request; shared and kept as keptReads says. A read the close ended answers `stopped`, a failure like any other. A
|
|
2550
|
+
// failure is logged here, once per read: the ask that started it may have had its 503 long before.
|
|
2551
|
+
const readWrapped = loggedReads((year) => onWorker("wrapped", undefined, year).then((answer) => ("wrapped" in answer ? answer : Promise.reject(new Error("the server stopped before this machine's session history was read")))), (year, error) => void (closing || process.stderr.write(`agentrun-serve: the read of this machine's session history for ${year} failed: ${error.message}\n`)));
|
|
2487
2552
|
// The count of what setup would import: started once (at start, or by the page's first read), read as it stands. One
|
|
2488
2553
|
// stopped (by close, or by setup) starts again on the next read; one that failed stays failed.
|
|
2489
2554
|
let count;
|
|
@@ -3119,7 +3184,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3119
3184
|
const blockers = await blockersOf(withCarried(envAtPlace(env, shape.place), carried), shape, settings.get(), { capped, boxes: boxOffers, computerReady, shellOf, offers, mcp: revision.kind === "agentic" ? pinnedTools : mcpTools, monid, decisionPrice: price });
|
|
3120
3185
|
if (!blockers.length)
|
|
3121
3186
|
return;
|
|
3122
|
-
|
|
3187
|
+
// An agent refused for its model in a box while its harness runs on the login at the runner, on a model the login
|
|
3188
|
+
// runs: the words say so, and how to run it there (details.login_on_runner, the console's offer to move it). Its
|
|
3189
|
+
// model is the blocker whichever field names it (runnable.ts Blocker.model: an agent that names none is refused on its
|
|
3190
|
+
// harness), and the model it would run on the runner is its own, else the runner's default for its harness
|
|
3191
|
+
// (hostModel: AGENT_MODEL first), so one whose default there is an OpenRouter model is offered no move.
|
|
3192
|
+
const runnerOnly = shape.kind === "agentic" && blockers.some((b) => b.model && b.reason === NOT_SET_UP && !b.unpriced) ? loginOnRunnerOnly(env, shape.harness, shape.model || hostModel(envAtPlace(env, { mode: "runner" }), "default", shape.harness), shape.place) : undefined;
|
|
3193
|
+
const message = [...blockers.map((b) => b.message), ...(runnerOnly ? [runnerOnly] : [])].join(" ");
|
|
3123
3194
|
// Each blocker as a 422 names its issue: its field, reason and message, and the fix when it has one.
|
|
3124
3195
|
const fields = blockers.map(issueOf);
|
|
3125
3196
|
const unbound = blockers.flatMap((b) => (b.tool ? [b.tool] : []));
|
|
@@ -3130,7 +3201,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3130
3201
|
const box = blockers.find((b) => b.box)?.box;
|
|
3131
3202
|
const named = { ...(harness ? { harness } : {}), ...(box ? { box } : {}), ...(notGrantable.length ? { not_grantable: notGrantable } : {}) };
|
|
3132
3203
|
if (revision.kind === "agentic") {
|
|
3133
|
-
const details = { unbound, missing, ...named };
|
|
3204
|
+
const details = { unbound, missing, ...named, ...(runnerOnly ? { login_on_runner: true } : {}) };
|
|
3134
3205
|
// A held run kept from running by its model alone opens (runnable.ts Blocker.model: a CLI harness that lacks only a
|
|
3135
3206
|
// model key here among them): its computer is its owner's to call, and these words are its start's refusal
|
|
3136
3207
|
// (computer-held.ts). Any other blocker refuses it here, as any run.
|
|
@@ -3289,7 +3360,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3289
3360
|
const send = await checkFetch("monid");
|
|
3290
3361
|
const before = previous?.kind === "agentic" ? { grants: previous.body.tools ?? [], pin: previous.monidPin } : undefined;
|
|
3291
3362
|
// The key as the server reads it (env: what it was started with, its handed secrets and its saved keys).
|
|
3292
|
-
const pinned = await pinMonid(tools, { key: env[MONID_KEY_ENV]?.trim(), fetch: send ?? (async () => { throw new Error("no fake of monid's API under faux"); }), signal: stopping.signal, ...(before ? { previous: before } : {}) });
|
|
3363
|
+
const pinned = await pinMonid(tools, { key: env[MONID_KEY_ENV]?.trim(), fetch: send ?? (async () => { throw new Error("no fake of monid's API under faux"); }), signal: stopping.signal, shared: monidShared, ...(before ? { previous: before } : {}) });
|
|
3293
3364
|
if (pinned && "refused" in pinned)
|
|
3294
3365
|
throw invalid(pinned.refused.map(({ tool, message }) => ({ field: tools.includes(tool) ? `definition.tools[${tools.indexOf(tool)}]` : "definition.tools", reason: "not_an_option", message })));
|
|
3295
3366
|
return pinned && { monid: pinned.pin, warnings: pinned.warnings.map(({ tool, message }) => ({ field: `definition.tools[${tools.indexOf(tool)}]`, reason: PRICED_BY_USAGE, message })) };
|
|
@@ -4176,7 +4247,16 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4176
4247
|
throw new ApiError("bad_request", "archived is true or false");
|
|
4177
4248
|
return value === "true";
|
|
4178
4249
|
}
|
|
4179
|
-
|
|
4250
|
+
/** GET /runs' `source`, once: a source's name (claude-code, codex, ...) keeps the runs imported from it, `live` the runs not imported. */
|
|
4251
|
+
function sourceParam(url) {
|
|
4252
|
+
const given = url.searchParams.getAll("source");
|
|
4253
|
+
if (given.length === 0)
|
|
4254
|
+
return undefined;
|
|
4255
|
+
if (given.length > 1 || !/^[a-z][a-z0-9-]{0,31}$/.test(given[0]))
|
|
4256
|
+
throw new ApiError("bad_request", "source is one source's name (claude-code, codex, ...), or live; once");
|
|
4257
|
+
return given[0];
|
|
4258
|
+
}
|
|
4259
|
+
async function runsPage(url, filter, origin, source) {
|
|
4180
4260
|
const limit = limitOf(url.searchParams.get("limit"));
|
|
4181
4261
|
const offset = cursorOf(url.searchParams.get("cursor"));
|
|
4182
4262
|
const status = url.searchParams.get("status");
|
|
@@ -4193,7 +4273,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4193
4273
|
// ordered and cut to the page in one query, so a list costs the same at ten runs and at thousands, however long their
|
|
4194
4274
|
// journals. An audit's shadow run is no row of the list (learn/audit.ts): it is read by id, and its cost is its served
|
|
4195
4275
|
// run's. A run's archive is its own or its agent's.
|
|
4196
|
-
const where = { ...(filter.agent !== undefined ? { agentId: filter.agent } : {}), ...(filter.revision !== undefined ? { revisionId: filter.revision } : {}), ...(labels ? { labels } : {}), archived };
|
|
4276
|
+
const where = { ...(filter.agent !== undefined ? { agentId: filter.agent } : {}), ...(filter.revision !== undefined ? { revisionId: filter.revision } : {}), ...(labels ? { labels } : {}), ...(source !== undefined ? { source } : {}), archived };
|
|
4197
4277
|
// A listing is built by the server's lister (run-listing.ts) once per change, so a list finds it current. One that is
|
|
4198
4278
|
// behind (a write landed since, or the lister has not reached it since the store was upgraded) is built here, written
|
|
4199
4279
|
// back, and shown as built: for a status filter, first every run still going whose listing is behind (its row's
|
|
@@ -5390,7 +5470,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5390
5470
|
case "listAllRuns": {
|
|
5391
5471
|
const agent = url.searchParams.get("agent") ?? undefined;
|
|
5392
5472
|
const revision = url.searchParams.get("revision") ?? undefined;
|
|
5393
|
-
return send(res, 200, await runsPage(url, { ...(agent ? { agent } : {}), ...(revision ? { revision } : {}) }, linkOrigin(req)));
|
|
5473
|
+
return send(res, 200, await runsPage(url, { ...(agent ? { agent } : {}), ...(revision ? { revision } : {}) }, linkOrigin(req), sourceParam(url)));
|
|
5394
5474
|
}
|
|
5395
5475
|
case "getRun": {
|
|
5396
5476
|
const run = await runRead(id, linkOrigin(req));
|
|
@@ -5841,10 +5921,11 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5841
5921
|
return send(res, 200, await capacityOverStore(store.runners, capacityWindowOf(url)));
|
|
5842
5922
|
case "getWrapped": {
|
|
5843
5923
|
// The session files of the machine this server runs on, read for whoever holds a token: only one owner's server on
|
|
5844
|
-
// their own machine answers (whyNotOwnersServer: loopback, no public URL, an owner, one API token
|
|
5845
|
-
//
|
|
5924
|
+
// their own machine answers (whyNotOwnersServer: loopback, no public URL, an owner, one API token and no live API key
|
|
5925
|
+
// made in the console, its own SQLite store). Keys are counted at each ask: they are made and revoked while it runs.
|
|
5926
|
+
// Dormant keys (API-only, --harness-sign-in) open nothing, so they are not callers here. A name an operator allowed (--allow-host) passes the server's Host check for its other routes, but a page
|
|
5846
5927
|
// that rebound one to this address must not read the machine's files: here the Host is a loopback name or address.
|
|
5847
|
-
const notOwn = whyNotOwnersServer(options, data);
|
|
5928
|
+
const notOwn = whyNotOwnersServer(options, data, options.apiOnly === true || options.harnessSignIn === true ? 0 : apiKeys.count);
|
|
5848
5929
|
if (!isLoopbackName(hostName(req.headers.host)))
|
|
5849
5930
|
notOwn.push("was reached at a name that is not this machine's own");
|
|
5850
5931
|
if (notOwn.length)
|
|
@@ -5856,7 +5937,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5856
5937
|
if (year > new Date().getFullYear())
|
|
5857
5938
|
throw new ApiError("bad_request", "year is this year or an earlier one");
|
|
5858
5939
|
// A long home is read on, shared, past the wait: the answer says when to ask again rather than hold the request.
|
|
5859
|
-
|
|
5940
|
+
// A failed read is kept for its minute (keptReads): each ask in it is this 500, the reason in the server's log.
|
|
5941
|
+
const read = await within(readWrapped(year), options.wrappedWaitMs ?? WRAPPED_WAIT_MS).catch(() => {
|
|
5942
|
+
throw new ApiError("internal", `This machine's session history for ${year} could not be read: the server's log says why. Ask again in a minute to read it again.`);
|
|
5943
|
+
});
|
|
5860
5944
|
if (!read)
|
|
5861
5945
|
throw new ApiError("unavailable", `This machine's session history for ${year} is still being read: ask again in a few seconds.`, { retry_after_ms: 5_000 });
|
|
5862
5946
|
const analytics = await analyticsOverStore(store, { from: new Date(year, 0, 1).toISOString(), to: new Date(year + 1, 0, 1).toISOString() });
|
|
@@ -7160,6 +7244,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
7160
7244
|
await slack.close();
|
|
7161
7245
|
// An upgraded socket is no connection closeAllConnections ends, and server.close waits for it.
|
|
7162
7246
|
viewers.close();
|
|
7247
|
+
clearInterval(routeTick);
|
|
7163
7248
|
await attach.close();
|
|
7164
7249
|
await new Promise((done) => (server.close(done), server.closeAllConnections()));
|
|
7165
7250
|
// No request is left to use a key: its last-use writes end before the store they write to closes.
|
|
@@ -7199,6 +7284,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
7199
7284
|
...(consoleSessions ? { launchCode: consoleSessions.code } : {}),
|
|
7200
7285
|
boxesLine: boxesLine(boxOffers, enabledBoxes(env), boxAllow, boxesByDefault(env)),
|
|
7201
7286
|
attachHub,
|
|
7287
|
+
beside,
|
|
7202
7288
|
dial: { ...(options.publicUrl ? { url: options.publicUrl.replace(/\/+$/, "") } : {}), tokens: attach.machineTokens, hub: attachHub },
|
|
7203
7289
|
localInstall,
|
|
7204
7290
|
ollamaHost,
|
package/dist/slots.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Slots handed out first come first served. `take` answers the slot's release (once), or rejects with the signal's
|
|
2
|
+
* reason if it aborts first, leaving the queue; with no signal it waits until a slot is free. */
|
|
3
|
+
export type Slots = {
|
|
4
|
+
readonly size: number;
|
|
5
|
+
readonly busy: number;
|
|
6
|
+
readonly waiting: number;
|
|
7
|
+
take(signal?: AbortSignal): Promise<() => void>;
|
|
8
|
+
};
|
|
9
|
+
export declare function slots(size: number): Slots;
|
package/dist/slots.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// A gate of n slots, handed out first come first served: web_save's downloads (web-save.ts), Mode 2's pieced writes
|
|
2
|
+
// (runner/big-writes.ts) and a run's subagents (runner/subagent.ts). A leaf module: it imports nothing.
|
|
3
|
+
export function slots(size) {
|
|
4
|
+
let busy = 0;
|
|
5
|
+
const queue = [];
|
|
6
|
+
const releaser = () => {
|
|
7
|
+
let done = false;
|
|
8
|
+
return () => {
|
|
9
|
+
if (done)
|
|
10
|
+
return;
|
|
11
|
+
done = true;
|
|
12
|
+
// The slot goes straight to the next waiter, so busy only drops when no one waits.
|
|
13
|
+
const next = queue.shift();
|
|
14
|
+
if (next)
|
|
15
|
+
next();
|
|
16
|
+
else
|
|
17
|
+
busy--;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
size,
|
|
22
|
+
get busy() { return busy; },
|
|
23
|
+
get waiting() { return queue.length; },
|
|
24
|
+
take(signal) {
|
|
25
|
+
if (signal?.aborted)
|
|
26
|
+
return Promise.reject(signal.reason);
|
|
27
|
+
if (busy < size) {
|
|
28
|
+
busy++;
|
|
29
|
+
return Promise.resolve(releaser());
|
|
30
|
+
}
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
const leave = () => {
|
|
33
|
+
queue.splice(queue.indexOf(grant), 1);
|
|
34
|
+
reject(signal.reason);
|
|
35
|
+
};
|
|
36
|
+
const grant = () => {
|
|
37
|
+
signal?.removeEventListener("abort", leave);
|
|
38
|
+
resolve(releaser());
|
|
39
|
+
};
|
|
40
|
+
queue.push(grant);
|
|
41
|
+
signal?.addEventListener("abort", leave, { once: true });
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
-- The store's schema on Postgres, version 28: the learning ledger (learn/ledger.ts), as store/schema.ts keeps it on
|
|
2
|
+
-- SQLite (LEARNING_LEDGER, LEARNING_SPEND). Applied once, after 0027, inside the transaction migrate.ts opens. Never edit
|
|
3
|
+
-- this file once applied: a change is a new file. Additive: a runner of version 27 or earlier never writes it; a run it
|
|
4
|
+
-- ends has no row, or a row for an earlier end (`epoch` is the run's epoch after the end it was written for, and every
|
|
5
|
+
-- end moves the epoch), and the reader records it from the run's row as it reads either way (store-reads/learning.ts).
|
|
6
|
+
--
|
|
7
|
+
-- learning_ledger: one row a run, written by each patch that leaves the run ended (run-patch.ts applyRunPatch, in that
|
|
8
|
+
-- patch's transaction): who answered it (path, null when its end named none), the revision that ran it, why it was not
|
|
9
|
+
-- served alone, the job's own $ and its rounds' look-back, and whether its cost is known. Gone with its run's purge.
|
|
10
|
+
-- learning_spend: each learning cost by the revision it is for (a compile turn by its round, a check's replay run, an
|
|
11
|
+
-- audit's shadow run with the run it audits), written with its run's ledger row. Figures only, no run text. Made only
|
|
12
|
+
-- where missing, so a store whose record of this file was lost applies it again unharmed.
|
|
13
|
+
|
|
14
|
+
CREATE TABLE IF NOT EXISTS learning_ledger (
|
|
15
|
+
run_id TEXT COLLATE "C" PRIMARY KEY,
|
|
16
|
+
agent_id TEXT COLLATE "C" NOT NULL,
|
|
17
|
+
started_at BIGINT NOT NULL,
|
|
18
|
+
path TEXT COLLATE "C" CHECK (path IS NULL OR path IN ('agent', 'handed_back', 'workflow', 'replay', 'audit')),
|
|
19
|
+
workflow TEXT COLLATE "C",
|
|
20
|
+
digest TEXT COLLATE "C",
|
|
21
|
+
not_served TEXT COLLATE "C" CHECK (not_served IS NULL OR not_served IN ('cost_stop', 'cut')),
|
|
22
|
+
job_usd DOUBLE PRECISION,
|
|
23
|
+
look_back_usd DOUBLE PRECISION,
|
|
24
|
+
cost TEXT COLLATE "C" NOT NULL CHECK (cost IN ('known', 'unknown', 'at_most')),
|
|
25
|
+
epoch BIGINT NOT NULL
|
|
26
|
+
);
|
|
27
|
+
CREATE INDEX IF NOT EXISTS learning_ledger_agent ON learning_ledger (agent_id);
|
|
28
|
+
|
|
29
|
+
CREATE TABLE IF NOT EXISTS learning_spend (
|
|
30
|
+
run_id TEXT COLLATE "C" NOT NULL,
|
|
31
|
+
kind TEXT COLLATE "C" NOT NULL CHECK (kind IN ('compile', 'check', 'audit')),
|
|
32
|
+
round BIGINT NOT NULL CHECK (round >= 0),
|
|
33
|
+
agent_id TEXT COLLATE "C" NOT NULL,
|
|
34
|
+
of_run TEXT COLLATE "C",
|
|
35
|
+
workflow TEXT COLLATE "C",
|
|
36
|
+
digest TEXT COLLATE "C",
|
|
37
|
+
usd DOUBLE PRECISION,
|
|
38
|
+
at BIGINT NOT NULL,
|
|
39
|
+
PRIMARY KEY (run_id, kind, round)
|
|
40
|
+
);
|
|
41
|
+
CREATE INDEX IF NOT EXISTS learning_spend_agent ON learning_spend (agent_id);
|
|
42
|
+
CREATE INDEX IF NOT EXISTS learning_spend_of_run ON learning_spend (of_run) WHERE of_run IS NOT NULL;
|
|
43
|
+
|
|
44
|
+
UPDATE store_meta SET schema_version = 28 WHERE singleton = 1;
|
package/dist/store/schema.d.ts
CHANGED
|
@@ -103,6 +103,23 @@ export declare const HAND_BACKS_KEPT_MS: number;
|
|
|
103
103
|
* added at a server open to a store an earlier build of this version made, as COMPUTER_INTERVALS is: a claim made before
|
|
104
104
|
* it has no row. */
|
|
105
105
|
export declare const RUN_ATTEMPTS = "CREATE TABLE IF NOT EXISTS run_attempts (\n run_id TEXT NOT NULL,\n epoch INTEGER NOT NULL,\n turn INTEGER NOT NULL CHECK (turn >= 1),\n attempt INTEGER NOT NULL CHECK (attempt >= 1),\n cause TEXT CHECK (cause IS NULL OR cause IN ('drain', 'crash', 'lease_lapse', 'retry')),\n cut TEXT CHECK (cut IS NULL OR cut IN ('drain', 'lease_lapse', 'retry')),\n runner TEXT NOT NULL,\n from_state TEXT NOT NULL,\n journal_from INTEGER NOT NULL,\n claimed_at INTEGER NOT NULL,\n PRIMARY KEY (run_id, epoch)\n ) STRICT";
|
|
106
|
+
/** The learning ledger (learn/ledger.ts): one row a run, written by each patch that leaves the run ended (applyRunPatch,
|
|
107
|
+
* in that patch's transaction) and by a healed cost: who answered it (`path`, null when its end named none), the
|
|
108
|
+
* revision that ran it, why it was not served alone, the job's own $ and its rounds' look-back, and whether its cost is
|
|
109
|
+
* known (`cost`), and the end it was written for (`epoch`: the run's epoch after that end, which every end moves).
|
|
110
|
+
* Gone with the run's purge or delete (its cost stays on the run's tombstone). Figures only, no run text. In STORE_DDL,
|
|
111
|
+
* and made at a server open on a store an earlier build of this version made: a run that ended before it has no row,
|
|
112
|
+
* and one a runner of that build ended again has a row for an earlier end; its reader records it from its run row
|
|
113
|
+
* either way (store-reads/learning.ts). */
|
|
114
|
+
export declare const LEARNING_LEDGER = "CREATE TABLE IF NOT EXISTS learning_ledger (\n run_id TEXT PRIMARY KEY,\n agent_id TEXT NOT NULL,\n started_at INTEGER NOT NULL,\n path TEXT CHECK (path IS NULL OR path IN ('agent', 'handed_back', 'workflow', 'replay', 'audit')),\n workflow TEXT,\n digest TEXT,\n not_served TEXT CHECK (not_served IS NULL OR not_served IN ('cost_stop', 'cut')),\n job_usd REAL,\n look_back_usd REAL,\n cost TEXT NOT NULL CHECK (cost IN ('known', 'unknown', 'at_most')),\n epoch INTEGER NOT NULL\n ) STRICT";
|
|
115
|
+
export declare const LEARNING_LEDGER_AGENT = "CREATE INDEX IF NOT EXISTS learning_ledger_agent ON learning_ledger (agent_id)";
|
|
116
|
+
/** Each learning cost, by the revision it is for (learn/ledger.ts SpendRow): a compile turn (`round`, the round that asked
|
|
117
|
+
* it), a check's replay run or an audit's shadow run (round 0, `of_run` the run it audits), with its $ (null: unknown).
|
|
118
|
+
* Written with its run's ledger row, replaced whole each time; gone with its run's purge or delete, and with the purge
|
|
119
|
+
* or delete of the run it audits. */
|
|
120
|
+
export declare const LEARNING_SPEND = "CREATE TABLE IF NOT EXISTS learning_spend (\n run_id TEXT NOT NULL,\n kind TEXT NOT NULL CHECK (kind IN ('compile', 'check', 'audit')),\n round INTEGER NOT NULL CHECK (round >= 0),\n agent_id TEXT NOT NULL,\n of_run TEXT,\n workflow TEXT,\n digest TEXT,\n usd REAL,\n at INTEGER NOT NULL,\n PRIMARY KEY (run_id, kind, round)\n ) STRICT";
|
|
121
|
+
export declare const LEARNING_SPEND_AGENT = "CREATE INDEX IF NOT EXISTS learning_spend_agent ON learning_spend (agent_id)";
|
|
122
|
+
export declare const LEARNING_SPEND_OF_RUN = "CREATE INDEX IF NOT EXISTS learning_spend_of_run ON learning_spend (of_run) WHERE of_run IS NOT NULL";
|
|
106
123
|
/** Version 13 → 14 on SQLite (the server's open, sqlite/store.ts), given the runs' and the agents' columns now: when each
|
|
107
124
|
* run and each agent was purged (null: none was), and the version, in one durable write. */
|
|
108
125
|
export declare function purgeUpgrade(runColumns: ReadonlySet<string>, agentColumns: ReadonlySet<string>): readonly string[];
|