@parcha/agentrun-serve 0.1.0-beta.59 → 0.1.0-beta.60
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 +77 -0
- package/README.md +188 -106
- package/dist/agent-delete.d.ts +6 -9
- package/dist/agent-delete.js +5 -3
- package/dist/agent-package.js +11 -1
- package/dist/api-only.d.ts +2 -2
- package/dist/api-only.js +3 -3
- package/dist/archil-routes.d.ts +4 -1
- package/dist/archil-routes.js +15 -12
- package/dist/archil-settings.d.ts +18 -8
- package/dist/archil-settings.js +35 -17
- package/dist/chatgpt-plan.d.ts +4 -2
- package/dist/chatgpt-plan.js +13 -3
- package/dist/claude-login-token.d.ts +5 -0
- package/dist/claude-login-token.js +8 -0
- package/dist/claude-login.d.ts +49 -3
- package/dist/claude-login.js +140 -10
- package/dist/cli-learning/connections.js +1 -1
- package/dist/console/assets/{backend-BztxEAvb.js → backend-QnwGVBeU.js} +1 -1
- package/dist/console/assets/index-DZi-muIj.js +629 -0
- package/dist/console/assets/{share-L84tlUDW.js → share-pz61zIn9.js} +2 -2
- package/dist/console/assets/{styles-CaRKlHke.js → styles-CcceGcu2.js} +31 -31
- package/dist/console/assets/styles-fjQBFfMv.css +1 -0
- package/dist/console/index.html +3 -3
- package/dist/console/share.html +3 -3
- package/dist/decisions.d.ts +1 -1
- package/dist/decisions.js +2 -2
- package/dist/factory-activity.d.ts +68 -0
- package/dist/factory-activity.js +153 -0
- package/dist/factory-runs.d.ts +11 -0
- package/dist/factory-runs.js +52 -0
- package/dist/filed-tool.d.ts +32 -0
- package/dist/filed-tool.js +122 -0
- package/dist/harness-keys.d.ts +1 -2
- package/dist/harness-keys.js +1 -2
- package/dist/harness-table.d.ts +4 -0
- package/dist/harness-table.js +4 -0
- package/dist/harness.js +6 -2
- package/dist/import-worker.js +2 -2
- package/dist/import.d.ts +9 -0
- package/dist/import.js +11 -1
- package/dist/key-refusal.d.ts +5 -0
- package/dist/key-refusal.js +25 -15
- package/dist/learn/audit.d.ts +20 -22
- package/dist/learn/audit.js +72 -55
- package/dist/learn/check.js +1 -1
- package/dist/learn/commit.d.ts +35 -43
- package/dist/learn/commit.js +62 -270
- package/dist/learn/compile.d.ts +4 -4
- package/dist/learn/compile.js +6 -7
- package/dist/learn/corrections.js +1 -1
- package/dist/learn/delete.d.ts +5 -12
- package/dist/learn/delete.js +17 -30
- package/dist/learn/forget-run.d.ts +16 -0
- package/dist/learn/forget-run.js +53 -0
- package/dist/learn/index.js +1 -1
- package/dist/learn/learning-of.d.ts +0 -4
- package/dist/learn/learning-of.js +0 -5
- package/dist/learn/{folder.d.ts → legacy/folder.d.ts} +2 -1
- package/dist/learn/{folder.js → legacy/folder.js} +4 -7
- package/dist/learn/legacy/place.d.ts +16 -0
- package/dist/{workspace/learning-workspace.js → learn/legacy/place.js} +12 -42
- package/dist/learn/legacy/scrub.d.ts +28 -0
- package/dist/learn/legacy/scrub.js +258 -0
- package/dist/learn/promote.d.ts +40 -66
- package/dist/learn/promote.js +69 -207
- package/dist/learn/reset-ledger.d.ts +18 -0
- package/dist/learn/reset-ledger.js +14 -0
- package/dist/learn/rows.d.ts +186 -0
- package/dist/learn/rows.js +376 -0
- package/dist/learn/workflow-draft.d.ts +4 -1
- package/dist/learn/workflow-draft.js +12 -2
- package/dist/learning-reset.d.ts +1 -1
- package/dist/learning-reset.js +9 -11
- package/dist/learning-routes.d.ts +60 -81
- package/dist/learning-routes.js +187 -360
- package/dist/learning-words.d.ts +2 -0
- package/dist/learning-words.js +2 -0
- package/dist/learning.d.ts +18 -24
- package/dist/learning.js +35 -66
- package/dist/mcp-gateway.d.ts +6 -0
- package/dist/mcp-gateway.js +44 -8
- package/dist/mcp-resources.d.ts +1 -1
- package/dist/native/discovery.d.ts +6 -0
- package/dist/native/discovery.js +14 -1
- package/dist/native/remote.d.ts +5 -0
- package/dist/native/remote.js +16 -0
- package/dist/native/runtime.js +3 -2
- package/dist/observation/observer.d.ts +6 -6
- package/dist/openapi.js +89 -29
- package/dist/place-offers.d.ts +3 -0
- package/dist/place-offers.js +3 -0
- package/dist/place.d.ts +33 -11
- package/dist/place.js +61 -26
- package/dist/purged-workflow.d.ts +0 -33
- package/dist/purged-workflow.js +3 -71
- package/dist/redact/match.d.ts +19 -4
- package/dist/redact/match.js +123 -30
- package/dist/run-launch.d.ts +3 -3
- package/dist/run-learning-served.d.ts +3 -3
- package/dist/run-learning-served.js +1 -1
- package/dist/run-listing.d.ts +1 -1
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-timeline-served.js +6 -5
- package/dist/runnable.js +25 -8
- package/dist/runner/adapter-run-spec.js +11 -20
- package/dist/runner/audit.d.ts +2 -4
- package/dist/runner/audit.js +28 -51
- package/dist/runner/cli-run-spec.js +8 -14
- package/dist/runner/compare-end.d.ts +0 -2
- package/dist/runner/compare-end.js +6 -2
- package/dist/runner/disk-free.d.ts +15 -4
- package/dist/runner/disk-free.js +25 -7
- package/dist/runner/feedback-round.d.ts +1 -1
- package/dist/runner/feedback-round.js +2 -2
- package/dist/runner/harness-loops.js +2 -3
- package/dist/runner/held.d.ts +0 -10
- package/dist/runner/held.js +0 -25
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/journal-kinds.js +1 -1
- package/dist/runner/learned-first.d.ts +0 -2
- package/dist/runner/learned-first.js +3 -3
- package/dist/runner/learning-end.d.ts +12 -16
- package/dist/runner/learning-end.js +41 -75
- package/dist/runner/learning-seed.d.ts +13 -16
- package/dist/runner/learning-seed.js +13 -23
- package/dist/runner/main.js +1 -1
- package/dist/runner/mcp-run.d.ts +4 -0
- package/dist/runner/mcp-run.js +2 -0
- package/dist/runner/native-loop.js +2 -3
- package/dist/runner/promotion.d.ts +19 -28
- package/dist/runner/promotion.js +50 -69
- package/dist/runner/reflect-hook.d.ts +2 -2
- package/dist/runner/reflect-hook.js +4 -1
- package/dist/runner/run-child-host.d.ts +1 -9
- package/dist/runner/run-child-host.js +11 -67
- package/dist/runner/runner.d.ts +1 -1
- package/dist/runner/sdk-loop.js +2 -4
- package/dist/sdk/check.d.ts +1 -4
- package/dist/sdk/check.js +2 -3
- package/dist/sdk/runs.d.ts +20 -7
- package/dist/sdk/runs.js +105 -68
- package/dist/secrets.d.ts +4 -0
- package/dist/secrets.js +44 -10
- package/dist/server-fs.d.ts +1 -1
- package/dist/server-fs.js +1 -1
- package/dist/server-keys.d.ts +6 -0
- package/dist/server-keys.js +12 -0
- package/dist/server.d.ts +15 -15
- package/dist/server.js +214 -164
- package/dist/source-sync/auxiliary.js +2 -2
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.js +1 -1
- package/dist/store/postgres/migrations/0032_learning_rows.sql +65 -0
- package/dist/store/schema.d.ts +28 -2
- package/dist/store/schema.js +81 -5
- package/dist/store/sqlite/learning-rows.d.ts +23 -0
- package/dist/store/sqlite/learning-rows.js +559 -0
- package/dist/store/sqlite/store.d.ts +7 -1
- package/dist/store/sqlite/store.js +84 -18
- package/dist/store/store.d.ts +219 -6
- package/dist/store/store.js +13 -0
- package/dist/store-reads/journal.d.ts +33 -3
- package/dist/store-reads/journal.js +99 -4
- package/dist/store-reads/learning.d.ts +18 -22
- package/dist/store-reads/learning.js +35 -26
- package/dist/store-reads/loop.js +1 -1
- package/dist/store-view.d.ts +24 -2
- package/dist/store-view.js +40 -11
- package/dist/templates.d.ts +10 -2
- package/dist/templates.js +31 -4
- package/dist/tool-plane.d.ts +4 -2
- package/dist/tool-plane.js +9 -2
- package/dist/web-holds.d.ts +2 -0
- package/dist/web-holds.js +5 -2
- package/dist/web-run.js +2 -1
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.d.ts +1 -1
- package/dist/workspace/archil.js +1 -1
- package/dist/workspace/computer-deps.js +5 -3
- package/dist/workspace/computer-providers.d.ts +11 -1
- package/dist/workspace/computer-providers.js +29 -2
- package/dist/workspace/index.d.ts +1 -2
- package/dist/workspace/index.js +1 -2
- package/dist/workspace/paths.d.ts +0 -4
- package/dist/workspace/paths.js +0 -6
- package/dist/workspace/workspace.d.ts +1 -1
- package/dist/workspace/workspace.js +1 -1
- package/package.json +13 -13
- package/templates/TOOLS.md +46 -0
- package/dist/console/assets/index-LwNL4L9q.js +0 -619
- package/dist/console/assets/styles-DQo8rzY-.css +0 -1
- package/dist/workspace/learning-workspace.d.ts +0 -24
- /package/dist/learn/{learning.sh → legacy/learning.sh} +0 -0
package/dist/server.js
CHANGED
|
@@ -16,7 +16,7 @@ import { ObservationLearning } from "./observation/learning.js";
|
|
|
16
16
|
import { cliLearningOf } from "./store/agent-body.js";
|
|
17
17
|
import { maintainObservations, Observations } from './observation/observer.js';
|
|
18
18
|
import { isObservationRoute, observationHttp } from './observation/http.js';
|
|
19
|
-
import { SDK_MAX_OPEN_MS, SdkRuns, sdkOf, sdkRunSecret } from "./sdk/runs.js";
|
|
19
|
+
import { forgetSdkCopies, SDK_MAX_OPEN_MS, SdkRuns, sdkOf, sdkRunSecret } from "./sdk/runs.js";
|
|
20
20
|
import { learningModelOf } from "./learning-model.js";
|
|
21
21
|
import { answerSkill } from './skill-route.js';
|
|
22
22
|
import { RemoteConnectors, verifyRemote, REMOTE_COMPLETION_BODY_BYTES } from './native/remote.js';
|
|
@@ -65,15 +65,15 @@ import { HARNESS_MODULES_ENV, HARNESS_MODULES_SETTING, HARNESS_RECIPES_ENV, HARN
|
|
|
65
65
|
import { claudeCliIn, HarnessInstall, installDirOf, NPM_STOP_GRACE_MS, npmInstall } from "./harness-install.js";
|
|
66
66
|
import { DEFAULT_PORT, healthOf, hostMemory, maxRunsOf, runsThatFit } from "./host.js";
|
|
67
67
|
import { DEFAULT_HOST, elsewhereOf, listenOn, minFreeMibOf, takeOver, urlOf } from "./listen-first.js";
|
|
68
|
-
import { IMPORT_ASKED, MAX_CANDIDATES } from "./import.js";
|
|
68
|
+
import { IMPORT_ASKED, IMPORT_HEAP_MB, MAX_CANDIDATES } from "./import.js";
|
|
69
69
|
import { answerStoreCall } from "./import-proxy.js";
|
|
70
|
-
import {
|
|
70
|
+
import { inLearningQueue, LEARNING_LABEL, secretsShown, learningOf, learnsOf, RUN_LEARNING_USE, seedOf } from "./learning.js";
|
|
71
71
|
import { askReplay, ReplayRefused, replayView } from "./runner/promotion.js";
|
|
72
|
-
import { agentLearning, changeWorkflow, correctionsView, correctionsWrite,
|
|
73
|
-
import { purgedRun
|
|
72
|
+
import { agentLearning, changeWorkflow, correctionsView, correctionsWrite, learningLog, pendingCount, readLearnedFile, sendText, statusesOf, textBody, workflowAtDigest, workflowRevisions } from "./learning-routes.js";
|
|
73
|
+
import { purgedRun } from "./purged-workflow.js";
|
|
74
74
|
import { answerLlms, MCP_PATH, mcpEndpoint } from "./mcp.js";
|
|
75
75
|
import { openapiDocument, servedOpenapi, UNSUPPORTED } from "./openapi.js";
|
|
76
|
-
import { boxAvailability, boxesLine, defaultPlaceOf, NEW_AGENT_TOOLS, newAgentPlace, noBoxReason, placesOf, resolvePlace } from "./place.js";
|
|
76
|
+
import { boxAvailability, boxesLine, defaultPlaceOf, NEW_AGENT_TOOLS, newAgentPlace, noBoxReason, noBoxRefusal, placesOf, resolvePlace } from "./place.js";
|
|
77
77
|
import { boxAllowOf, boxAllowSetIn } from "./box-settings.js";
|
|
78
78
|
import { dockerLimitsOf } from "./workspace/computer-deps.js";
|
|
79
79
|
import { Owner, passwordProblem, SESSION_MS } from "./owner.js";
|
|
@@ -91,7 +91,7 @@ import { screenWaitEnded } from "./browser-wait-ended.js";
|
|
|
91
91
|
import { durationMs, logLine } from "./print.js";
|
|
92
92
|
import { keepPresence, refusedEnd, runnersRefused } from "./runner/presence.js";
|
|
93
93
|
import { approve, archiveRun, cancel, message, pause as pauseRunOverStore, prepareLaunch, raiseCap, resume as resumeRunOverStore, startInline, startRun, stop as stopRunOverStore } from "./runs-over-store.js";
|
|
94
|
-
import { builtOfNow, factsOverStore, listedItem, lookingBackEnd, momentOverStore, summaryOverStore, timelineOverStore, toolsUsdOverStore, viewOverStore, withheldOverStore } from "./store-view.js";
|
|
94
|
+
import { builtOfNow, factsOverStore, keptFactory, listedItem, liveOf, lookingBackEnd, momentOverStore, summaryOverStore, timelineOverStore, toolsUsdOverStore, viewOverStore, withheldOverStore } from "./store-view.js";
|
|
95
95
|
import { healEndedCosts } from "./cost-heal.js";
|
|
96
96
|
import { reconcileProjectCheckpoints } from "./source-sync/checkpoints.js";
|
|
97
97
|
import { acknowledgeProjects } from "./source-sync/checkpoint-gate.js";
|
|
@@ -113,23 +113,25 @@ import { ExportFailed, restoreIdsOf, runExport } from "./run-export.js";
|
|
|
113
113
|
import { triggerTargets } from "./trigger-targets.js";
|
|
114
114
|
import { labelFilter, labelsIssues } from "./run-labels.js";
|
|
115
115
|
import { listRuns as listRunsOverStore, readRun as readRunOverStore, runOfOrigin as runOfOriginOverStore } from "./store-reads/runs.js";
|
|
116
|
+
import { observationOf } from "./factory-activity.js";
|
|
117
|
+
import { factoryRunsPage } from "./factory-runs.js";
|
|
116
118
|
import { runEntries } from "./store-reads/journal.js";
|
|
117
119
|
import { metersOverStore, spendOverStore } from "./store-reads/cap.js";
|
|
118
120
|
import { watchRun } from "./live/stream.js";
|
|
119
121
|
import { stats as statsOverStore } from "./store-reads/stats.js";
|
|
120
122
|
import { analytics as analyticsOverStore } from "./store-reads/analytics.js";
|
|
121
123
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
122
|
-
import { openStore, openRunLaunch, sealRunLaunch, StoreLaunchMissing, StoreOwned, storeTarget } from "./store/index.js";
|
|
124
|
+
import { LearningRecordRefused, openStore, openRunLaunch, sealRunLaunch, StoreLaunchMissing, StoreOwned, storeTarget } from "./store/index.js";
|
|
123
125
|
import { agentDeleting, answerOf, logged, purgedAgent } from "./agents.js";
|
|
124
126
|
import { keepGrade } from "./runner/feedback-round.js";
|
|
125
127
|
import { gradeRow, notAuditableOf } from "./runner/audit.js";
|
|
126
|
-
import { namedDisksOf } from "./learn/learning-of.js";
|
|
127
128
|
import { auditsOffWords, auditWriterOf, isShadowRun, readAudits, servingLinesOf, shadowRunId } from "./learn/audit.js";
|
|
128
129
|
import { auditLoopOf, COMPILE_AFTER_MAX, holdsReservedKey, RESERVED_SEGMENT } from "./learning-setting.js";
|
|
129
130
|
import { FINAL_STATES, RUN_CHANGES_PAGE } from "./store/store.js";
|
|
130
131
|
import { championOf, forgetRunCopies, GRADE_SOURCES, gradeView, LABEL_MAX, promotionsOf, promotionsShown, servingOf, servingStateOf, shownDeep } from "./learn/promote.js";
|
|
131
132
|
import { workflowNodesOf } from "./learn/workflow-nodes.js";
|
|
132
133
|
import { deleteLearning } from "./learn/delete.js";
|
|
134
|
+
import { forgetLegacyRunLearning, legacyGradesKey, legacyPromotionsKey } from "./learn/legacy/scrub.js";
|
|
133
135
|
import { runModelRef } from "./model.js";
|
|
134
136
|
import { ollamaHostOf, ollamaHostRefused, ollamaListing, ollamaModels, ollamaReading } from "./ollama-provider.js";
|
|
135
137
|
import { REDACTED } from "./secret-cut.js";
|
|
@@ -147,7 +149,7 @@ import { hostSecrets, SECRET_NAMES, secret, withSecrets } from "./secrets.js";
|
|
|
147
149
|
import { isSecretWriteOperation, secretPageFor, secretsWritableFields, secretWriteRefusal, secretWriterFacts, writesSecretFor, writesSecretsAllowed } from "./secret-writes.js";
|
|
148
150
|
import { ChatGPTPlan, planOf, PlanSignInRefused, SIGN_OUT_UNCONFIRMED, withPlan } from "./chatgpt-plan.js";
|
|
149
151
|
import { modelGatewayRoute, readSavedGateway, withSavedGateway } from "./model-gateway.js";
|
|
150
|
-
import { CLAUDE_LOGIN_ROUTES, LOGIN_REFUSES_API_KEYS, oneOwnerDeps, ClaudeLoginRefused, claudeLoginOf, claudeLoginRouteOff, claudeLoginServed, claudeLoginSwitchedOff, claudeLoginSetting, claudeLoginView, dropRefusedLogin, envAtPlace, LOGIN_HARNESS, loginOf, loginOnRunnerOnly, loopback, startLoginHere, turnOffClaudeLogin, turnOnClaudeLogin, withClaudeLogin } from "./claude-login.js";
|
|
152
|
+
import { CLAUDE_LOGIN_ROUTES, LOGIN_REFUSES_API_KEYS, oneOwnerDeps, ClaudeLoginRefused, claudeLoginOf, claudeLoginRouteOff, claudeLoginServed, claudeLoginSwitchedOff, claudeLoginSetting, claudeLoginView, dropRefusedLogin, envAtPlace, LOGIN_HARNESS, loginOf, loginOnRunnerOnly, loopback, signOutClaudeLogin, startLoginHere, turnOffClaudeLogin, turnOnClaudeLogin, withClaudeLogin } from "./claude-login.js";
|
|
151
153
|
import { ClaudeSignIns } from "./claude-sign-in.js";
|
|
152
154
|
import { bootSealKey, parametersDigest, withSealKey } from "./seal-key.js";
|
|
153
155
|
import { ServerLockHeldError, takeServerLock } from "./server-lock.js";
|
|
@@ -262,9 +264,6 @@ const TEMPLATE_UPLOAD_BODY = Math.ceil((IMPORT_LIMITS.packageBytes * 4) / 3) + M
|
|
|
262
264
|
/** The starts that may begin setup's import without ending it (a worker that failed, a process that ended) before the
|
|
263
265
|
* owner's yes is dropped: an import that fails the same way each time is not taken up at every start for good. */
|
|
264
266
|
const IMPORT_STARTS = 3;
|
|
265
|
-
/** The heap of the worker that counts or imports this machine's sessions. A run is read whole, at most MAX_RUN_BYTES of
|
|
266
|
-
* files (import.ts), which this holds several times over. */
|
|
267
|
-
const IMPORT_HEAP_MB = 2048;
|
|
268
267
|
const MAX_MESSAGE = 20_000;
|
|
269
268
|
const MAX_WAIT_MS = 25_000;
|
|
270
269
|
/** A run body's fields that a launch hook's host can't set on a firing's run (RunCreate `trigger_firing`): its trigger's
|
|
@@ -496,6 +495,7 @@ export const ROUTES = [
|
|
|
496
495
|
{ method: "PUT", pattern: /^\/settings\/claude-login$/, name: "turnOnClaudeLogin" },
|
|
497
496
|
{ method: "DELETE", pattern: /^\/settings\/claude-login$/, name: "turnOffClaudeLogin" },
|
|
498
497
|
{ method: "POST", pattern: /^\/settings\/claude-login\/login$/, name: "startClaudeLogin" },
|
|
498
|
+
{ method: "POST", pattern: /^\/settings\/claude-login\/sign-out$/, name: "signOutClaudeLogin" },
|
|
499
499
|
// The model gateway saved in the console (model-gateway.ts): its save, removal and test the owner's session's alone.
|
|
500
500
|
{ method: "GET", pattern: /^\/settings\/model-gateway$/, name: "getModelGateway" },
|
|
501
501
|
{ method: "PUT", pattern: /^\/settings\/model-gateway$/, name: "saveModelGateway" },
|
|
@@ -751,8 +751,9 @@ function capabilitiesWith(env, maxRuns, harnesses, learning, { needs, priced, le
|
|
|
751
751
|
// their words name the model it lacks. One whose default lacks a key while another model runs is (its `needs` says
|
|
752
752
|
// what the default lacks).
|
|
753
753
|
harnesses: harnesses.map(({ keys: _keys, noModelRuns, ...offer }) => ({ ...offer, available: offer.available && !noModelRuns, max_concurrent_runs: Math.min(maxRuns, runsThatFit(offer.id, memory, env)) })),
|
|
754
|
-
/** The places a revision may name (`definition.place`), this host's default
|
|
755
|
-
|
|
754
|
+
/** The places a revision may name (`definition.place`), this host's default (null where a new agent must name one),
|
|
755
|
+
* and whether this server has each box. */
|
|
756
|
+
places: placesOf(boxes, boxAllowOf(env), !!runnerShell?.size),
|
|
756
757
|
models,
|
|
757
758
|
learning_model,
|
|
758
759
|
/** `pending`: a workflow draft with a call no price covers is kept to wait for its owner's OK, served to no run;
|
|
@@ -813,10 +814,9 @@ function capabilitiesWith(env, maxRuns, harnesses, learning, { needs, priced, le
|
|
|
813
814
|
* (tool-keys-store.ts), never in the clear. */
|
|
814
815
|
tool_keys: { routes: true, at_rest: "sealed" },
|
|
815
816
|
/** GET /settings/harness-keys and PUT/DELETE of one key: a plan-billed recipe's keys, saved for that harness alone
|
|
816
|
-
* (harness-keys.ts); `harnesses` its ids here
|
|
817
|
-
*
|
|
818
|
-
|
|
819
|
-
harness_keys: { routes: true, at_rest: "sealed", harnesses: planRecipesOf(env).map((recipe) => recipe.id), kept: [] },
|
|
817
|
+
* (harness-keys.ts); `harnesses` its ids here. The page's own GET lists the ids with keys kept whose recipe the
|
|
818
|
+
* server no longer names, so the console offers the page on `routes`, as it does tool keys'. */
|
|
819
|
+
harness_keys: { routes: true, at_rest: "sealed", harnesses: planRecipesOf(env).map((recipe) => recipe.id) },
|
|
820
820
|
/** /settings/mcp-servers: remote MCP servers previewed and saved, each credential sealed under the server's seal key,
|
|
821
821
|
* which always exists (seal-key.ts), so MCP credentials are always kept sealed. Every harness of the table runs a
|
|
822
822
|
* grant (runnable.ts takes one on any), a module's among them. `composio_per_run`: a per-run Composio server takes
|
|
@@ -978,8 +978,8 @@ export async function startServe(options) {
|
|
|
978
978
|
dockerLimitsOf(process.env);
|
|
979
979
|
// The Docker host's addresses an operator names (workspace/computer-deps.ts): a bad entry stops the start, in words.
|
|
980
980
|
dockerHostAddressesOf(process.env);
|
|
981
|
-
// The Archil settings an operator sets (archil-settings.ts ARCHIL_SETTINGS_ENV): one
|
|
982
|
-
//
|
|
981
|
+
// The Archil settings an operator sets (archil-settings.ts ARCHIL_SETTINGS_ENV): one set without the region, or a value
|
|
982
|
+
// the PUT would refuse (no S3 URL for a region serve doesn't know), stops the start, in words naming each variable.
|
|
983
983
|
archilSettingsFromEnv(process.env);
|
|
984
984
|
const boxAllow = boxAllowOf(process.env);
|
|
985
985
|
const maxRuns = maxRunsOf(process.env, options.maxRuns);
|
|
@@ -995,8 +995,9 @@ export async function startServe(options) {
|
|
|
995
995
|
// One server per data root: the store's owner lock (StoreOwned), then the data root's own (server-lock.ts), both taken
|
|
996
996
|
// when startHolding opens the store; a data directory an earlier version wrote is refused there too
|
|
997
997
|
// (StoreFromEarlierVersion), in words, to start fresh. No oldHomes/oldLayout checks, no migration.
|
|
998
|
-
// What a start that fails stops: the
|
|
999
|
-
// store handle it opened
|
|
998
|
+
// What a start that fails stops: first the timers it set (each put at the front, so none ticks on a closing store), then
|
|
999
|
+
// the rest in the order they began: the store handle it opened, its locks, and the webhook deliveries it began, which
|
|
1000
|
+
// would write the next server's outbox.
|
|
1000
1001
|
const stops = [];
|
|
1001
1002
|
try {
|
|
1002
1003
|
return await startHolding(options, data, { maxRuns, minFreeBytes, learning, boxAllow, templates, ollamaHost }, stops);
|
|
@@ -1036,7 +1037,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1036
1037
|
const learningOfAgent = async (entry) => {
|
|
1037
1038
|
if (learning === "off" || entry.revision?.kind !== "agentic" || !learnsOf(entry.revision.body.learning))
|
|
1038
1039
|
return undefined;
|
|
1039
|
-
const pending = await pendingCount(
|
|
1040
|
+
const pending = await pendingCount(store, entry.agent.id);
|
|
1040
1041
|
return pending === undefined ? undefined : { pending };
|
|
1041
1042
|
};
|
|
1042
1043
|
const log = options.log;
|
|
@@ -1108,7 +1109,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1108
1109
|
const beside = { runner: runnerName(), incarnation: randomUUID() };
|
|
1109
1110
|
// 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
|
|
1110
1111
|
// store's lock holds one store, but the data root also holds what the server writes beside it (its token, its seal key,
|
|
1111
|
-
// uploads, harness installs
|
|
1112
|
+
// uploads, harness installs), which two servers on two stores (two Postgres schemas, or SQLite and
|
|
1112
1113
|
// Postgres) would share. The lock is SQLite's EXCLUSIVE lock (server-lock.ts): the kernel drops it when its process
|
|
1113
1114
|
// dies, so a crashed server never leaves it held.
|
|
1114
1115
|
// Its wait runs from when the store was held at the earliest, since a store on Postgres may have been waited for first.
|
|
@@ -1165,10 +1166,24 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1165
1166
|
// not (its runners on other hosts, AGENTRUN_RUNNER_HOSTS), so the tick runs on both. It does nothing while no computer
|
|
1166
1167
|
// is paired; with a runner beside it, nothing past its one read of the routes while no route row is there and no box
|
|
1167
1168
|
// is relayed (computer-attach.ts tick).
|
|
1169
|
+
// The ticks still running, so a failed start and close() wait them out before the store closes.
|
|
1170
|
+
const routeTicks = new Set();
|
|
1168
1171
|
const routeTick = options.apiOnly !== true
|
|
1169
|
-
? setInterval(() =>
|
|
1172
|
+
? setInterval(() => {
|
|
1173
|
+
const ticked = attach.tick()
|
|
1174
|
+
.catch((error) => attachLog("computer_route_tick_failed", { error: error instanceof Error ? error.message : String(error) }))
|
|
1175
|
+
.finally(() => void routeTicks.delete(ticked));
|
|
1176
|
+
routeTicks.add(ticked);
|
|
1177
|
+
}, PAIRED_ROUTE_MS)
|
|
1170
1178
|
: undefined;
|
|
1171
1179
|
routeTick?.unref();
|
|
1180
|
+
// A start that fails after this point clears it as the close does. Each timer's stop goes first (unshift), ahead of
|
|
1181
|
+
// the store's close: a failed start stops its timers and waits out their ticks and sweeps, then closes the store, so
|
|
1182
|
+
// no tick or sweep ever reads a store that is closing.
|
|
1183
|
+
stops.unshift(async () => {
|
|
1184
|
+
clearInterval(routeTick);
|
|
1185
|
+
await Promise.all(routeTicks);
|
|
1186
|
+
});
|
|
1172
1187
|
// This server's own key on every environment it reads its secrets from, so a reader opens what this store holds with the
|
|
1173
1188
|
// key checked against it, never another data directory's that this process booted too (secrets.ts holds one made key).
|
|
1174
1189
|
const own = (env) => withSealKey(env, seal.text);
|
|
@@ -1339,11 +1354,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1339
1354
|
// The start-time switches as this server was started: its options, else the CLI's variables. mcpLoopback is the
|
|
1340
1355
|
// option alone, as everywhere it is read here (localInstall): the CLI sets it from AGENTRUN_MCP_ALLOW_LOOPBACK.
|
|
1341
1356
|
const switched = { mcpLoopback: options.mcpLoopback === true, webhookPrivateTargets: switchedOnBy(process.env, options).webhookPrivateTargets, apiOnlyMcpOrigins };
|
|
1342
|
-
|
|
1343
|
-
const compose = (runnerShell) => {
|
|
1344
|
-
const made = askNeeds(capabilitiesWith(env, maxRuns, offers, learning, needs, settings.get(), boxOffers, toolKeys.refused(), runnerShell, isolation, switched));
|
|
1345
|
-
return { ...made, features: { ...made.features, harness_keys: { ...made.features.harness_keys, kept: harnessKeys.unnamed() } } };
|
|
1346
|
-
};
|
|
1357
|
+
const compose = (runnerShell) => askNeeds(capabilitiesWith(env, maxRuns, offers, learning, needs, settings.get(), boxOffers, toolKeys.refused(), runnerShell, isolation, switched));
|
|
1347
1358
|
const recompose = () => void (caps = compose());
|
|
1348
1359
|
// What the offers held now were made from (offersInputs), and the latest probe: one a later probe overtook is dropped.
|
|
1349
1360
|
let offersFrom;
|
|
@@ -1791,27 +1802,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1791
1802
|
const allInViewOf = async (runId, view) => {
|
|
1792
1803
|
const cost = (view.cost ?? {});
|
|
1793
1804
|
const own = typeof cost.usd === "number" && cost.upper_bound !== true ? cost.usd : null;
|
|
1794
|
-
|
|
1795
|
-
// a 500: the revision ledger its `learning_usd` and `all_in_usd` share is read from takes the champion with no record
|
|
1796
|
-
// skipped (as before the purge), so a revision a purged run wrote may be the one it counts as serving, for this read
|
|
1797
|
-
// alone. Figures only: no text is read or shown. Every write that asks the gate still fails closed (decideCheck
|
|
1798
|
-
// throws, so no promote lands; recordPromotion trims nothing). Such a read says so: `cost.degraded`.
|
|
1799
|
-
let degraded = false;
|
|
1800
|
-
const all = await runAllInOverStore(store, runId, own, (agentId, records) => refusedFor(agentId, records).catch((error) => {
|
|
1801
|
-
degraded = true;
|
|
1802
|
-
const line = `learning: run ${runId}: its costs were read without the purge gate's answer: ${error instanceof Error ? error.message : String(error)}`;
|
|
1803
|
-
if (log)
|
|
1804
|
-
log(logLine("learning", { line }));
|
|
1805
|
-
else
|
|
1806
|
-
process.stderr.write(`agentrun-serve: ${line}\n`);
|
|
1807
|
-
return Object.assign(() => false, { unread: true });
|
|
1808
|
-
}));
|
|
1805
|
+
const all = await runAllInOverStore(store, runId, own);
|
|
1809
1806
|
if (!all)
|
|
1810
1807
|
return {};
|
|
1811
1808
|
// A bound stays the view's bound. Otherwise usd is the job's (its ledger row's, the same figure the cost series
|
|
1812
1809
|
// gives): known as it answered even when its compile turn's cost is not; the row's while the run is at work.
|
|
1813
1810
|
const { learning_usd, all_in_usd, compile_usd, followup_usd, shadow_usd, share_usd } = all;
|
|
1814
|
-
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
|
|
1811
|
+
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 } };
|
|
1815
1812
|
};
|
|
1816
1813
|
// The agents accessor the routes call, over the one store (module A): the agents-store functions, with the run-row reads
|
|
1817
1814
|
// the server makes (store-reads) under `.store`. `.request` is a thin pass-through — the store runs its own transactions,
|
|
@@ -1928,7 +1925,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1928
1925
|
};
|
|
1929
1926
|
const uploadsTimer = setInterval(sweepUploads, UPLOAD_SWEEP_EVERY_MS);
|
|
1930
1927
|
uploadsTimer.unref();
|
|
1931
|
-
stops.
|
|
1928
|
+
stops.unshift(async () => {
|
|
1932
1929
|
clearInterval(uploadsTimer);
|
|
1933
1930
|
await sweeping;
|
|
1934
1931
|
});
|
|
@@ -2006,6 +2003,11 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2006
2003
|
};
|
|
2007
2004
|
const refusedTimer = setInterval(() => void sweepRefused(), REFUSED_SWEEP_MS);
|
|
2008
2005
|
refusedTimer.unref();
|
|
2006
|
+
stops.unshift(async () => {
|
|
2007
|
+
refusedStopped = true;
|
|
2008
|
+
clearInterval(refusedTimer);
|
|
2009
|
+
await refusedSweep;
|
|
2010
|
+
});
|
|
2009
2011
|
// The runner beside this server, when its run isolation was refused (cli.ts): its word, kept in this store until the stop.
|
|
2010
2012
|
let refusedBeside;
|
|
2011
2013
|
const sourceWorkspaces = { data, sealKey, env: withSecrets(process.env, "own"), ...(options.archilControl ? { control: options.archilControl } : {}) };
|
|
@@ -2056,6 +2058,12 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2056
2058
|
};
|
|
2057
2059
|
const localSourceTimer = setInterval(() => void sweepLocalSources(), 30_000);
|
|
2058
2060
|
localSourceTimer.unref();
|
|
2061
|
+
// As close() does: aborted first, so a sync in flight stops instead of being waited out.
|
|
2062
|
+
stops.unshift(async () => {
|
|
2063
|
+
stopping.abort();
|
|
2064
|
+
clearInterval(localSourceTimer);
|
|
2065
|
+
await localSourceSweep;
|
|
2066
|
+
});
|
|
2059
2067
|
const startDeps = {
|
|
2060
2068
|
project: { ...sourceProjects, place: async (given) => {
|
|
2061
2069
|
try {
|
|
@@ -2108,17 +2116,16 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2108
2116
|
// Whether that is the operator's own setting, not the default: a browser is held to an operator's list alone.
|
|
2109
2117
|
...(boxAllowSetIn(process.env) ? { boxAllowSet: true } : {}),
|
|
2110
2118
|
modelOf,
|
|
2111
|
-
// The run's learning start: the server's learning switch, the agent's seed read now from its learning
|
|
2119
|
+
// The run's learning start: the server's learning switch, the agent's seed read now from its learning rows, and
|
|
2112
2120
|
// the host's secrets as they are shown now to cut the corrections a run is given, a loopback address kept (local): the
|
|
2113
2121
|
// run's own machine. runs-over-store.learningStartFor pins the result (seed, section, workflows) in the launch for the
|
|
2114
2122
|
// runner; a seed that cannot be read starts the run with nothing learned (a fault never refuses it). The runner's spec
|
|
2115
2123
|
// builders read it back as the run's end-of-run step (runner/learning-end.ts learningEndOfRun).
|
|
2116
2124
|
learning,
|
|
2117
2125
|
seedFor: async (agentId) => {
|
|
2118
|
-
//
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
process.stderr.write(`agentrun-serve: the agent ${agentId}'s learning folder could not be read, so its run starts with nothing learned: ${error.message}\n`);
|
|
2126
|
+
// A store fault surfaces here as a seedOf error, so the run starts with nothing learned, never refused.
|
|
2127
|
+
return seedOf(data, store, agentId).then((seed) => ({ seed }), (error) => {
|
|
2128
|
+
process.stderr.write(`agentrun-serve: the agent ${agentId}'s learning could not be read, so its run starts with nothing learned: ${error.message}\n`);
|
|
2122
2129
|
return { failed: error.message };
|
|
2123
2130
|
});
|
|
2124
2131
|
},
|
|
@@ -2137,22 +2144,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2137
2144
|
return [...serverSecrets(), ...pointers];
|
|
2138
2145
|
};
|
|
2139
2146
|
const learningShown = async (agentId) => secretsShown(await learningValues(agentId));
|
|
2140
|
-
//
|
|
2141
|
-
|
|
2142
|
-
//
|
|
2143
|
-
const
|
|
2144
|
-
// The agent's audit ledger on its learning folder's main (learn/audit.ts), oldest first.
|
|
2145
|
-
const auditsOfAgent = async (agentId) => {
|
|
2146
|
-
const { workspace, end } = learningFolderOf(data, agentId);
|
|
2147
|
-
try {
|
|
2148
|
-
return await readAudits(workspace);
|
|
2149
|
-
}
|
|
2150
|
-
finally {
|
|
2151
|
-
await end().catch(() => undefined);
|
|
2152
|
-
}
|
|
2153
|
-
};
|
|
2154
|
-
// What a run held for its owner's OK reads as it stands on its agent's learning folder's main (statusesOf).
|
|
2155
|
-
const statuses = (agentId) => statusesOf(data, agentId);
|
|
2147
|
+
// The agent's audit ledger (learn/audit.ts), oldest first.
|
|
2148
|
+
const auditsOfAgent = (agentId) => readAudits(store.learning, agentId);
|
|
2149
|
+
// What a run held for its owner's OK reads as it stands in its agent's learning (statusesOf).
|
|
2150
|
+
const statuses = (agentId) => statusesOf(store, agentId);
|
|
2156
2151
|
const viewDepsFor = (origin) => ({ origin, serverSecrets, signIns, sealKey, keyEnv: () => withSavedGateway(own(withSecrets(process.env, "all", storedKeys)), savedGateway), statuses });
|
|
2157
2152
|
// A run read as a whole (its own read, its archive) lists its recordings too, from its recordings folder on this machine
|
|
2158
2153
|
// (run-recordings.ts), where the runner beside it wrote them; every other read of the view opens no file.
|
|
@@ -2639,7 +2634,12 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2639
2634
|
// runner's child holds many).
|
|
2640
2635
|
...(process.execArgv.some((arg) => arg.startsWith("--input-type")) ? { execArgv: workerArgs(process.execArgv) } : {}),
|
|
2641
2636
|
// Its own heap, at most IMPORT_HEAP_MB whatever the machine's memory: an import that needs more ends as a failed
|
|
2642
|
-
// worker (said, and counted: IMPORT_STARTS)
|
|
2637
|
+
// worker (said, and counted: IMPORT_STARTS). A Wrapped read also starts the import package's read threads
|
|
2638
|
+
// (wrappedReading), each with a heap of its own outside this one, capped at its start: a 16 MB young generation
|
|
2639
|
+
// and the import's workerOldMb (64 MB) old one. Their finished reads wait for this thread mostly as transferred
|
|
2640
|
+
// ArrayBuffers (record indexes, request counts), memory outside this cap. So a Wrapped read holds IMPORT_HEAP_MB
|
|
2641
|
+
// for this thread's own heap, plus threads x (workerOldMb + 16) MB, plus readAhead for the replies waiting to be
|
|
2642
|
+
// taken, with up to `threads` replies in flight on top: the pool checks readAhead before it starts a read.
|
|
2643
2643
|
resourceLimits: { maxOldGenerationSizeMb: IMPORT_HEAP_MB },
|
|
2644
2644
|
});
|
|
2645
2645
|
workers.set(worker, { task, exit: once(worker, "exit").catch(() => undefined) });
|
|
@@ -2952,41 +2952,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2952
2952
|
throw new ApiError("unavailable", `${error.message.replace(/[.\s]*$/, "")}. ${again}`, { retry_after_ms: 5_000 });
|
|
2953
2953
|
}
|
|
2954
2954
|
};
|
|
2955
|
-
/**
|
|
2956
|
-
*
|
|
2957
|
-
|
|
2958
|
-
* read off its row, so a purged run whose launch is gone still names it). A run's kept disk, or a launch's kind
|
|
2959
|
-
* "agent", is the agent's own disk, mounted only while it is still the stored one (workspace/run-disk.ts runDiskOf):
|
|
2960
|
-
* one no longer stored was removed at Archil, its folder with it. */
|
|
2961
|
-
const learningDisksOf = async (agentId, agentDisk) => {
|
|
2962
|
-
const disks = new Set();
|
|
2963
|
-
const stored = agentDisk ? await agentDiskOf(store, agentId) : undefined;
|
|
2964
|
-
if (stored)
|
|
2965
|
-
disks.add(stored.diskId);
|
|
2966
|
-
for (const disk of await namedDisksOf(store, agentId))
|
|
2967
|
-
disks.add(disk);
|
|
2968
|
-
return [...disks];
|
|
2969
|
-
};
|
|
2970
|
-
/** Step 2 of DELETE /agents/{id}, and DELETE /agents/{id}/learning: the learning module's delete over the agent's
|
|
2971
|
-
* learning folder on this server's disk, as the learning routes open it (learningFolderOf), which deleteLearning ends
|
|
2972
|
-
* in its finally, and over its folder on each Archil disk a launch of its runs named and, for a reset (`agentDisk`),
|
|
2973
|
-
* on its own disk, which the agent's delete removes whole in step 3 (archil-routes.ts removeLearningFolder; Archil
|
|
2974
|
-
* off or refusing is 503 unavailable, nothing here deleted, for the next call). */
|
|
2975
|
-
const learningDelete = options.deleteLearning ?? ((given, agentId, { keepResetLedger = false, agentDisk = false } = {}) => deleteLearning(given, agentId, learningFolderOf(data, agentId), {
|
|
2976
|
-
keepResetLedger,
|
|
2977
|
-
elsewhere: async () => {
|
|
2978
|
-
for (const diskId of await learningDisksOf(agentId, agentDisk)) {
|
|
2979
|
-
try {
|
|
2980
|
-
await archil.removeLearningFolder(agentId, diskId);
|
|
2981
|
-
}
|
|
2982
|
-
catch (error) {
|
|
2983
|
-
if (!(error instanceof ApiError && ["unavailable", "upstream_failed"].includes(error.code)))
|
|
2984
|
-
throw error;
|
|
2985
|
-
throw new ApiError("unavailable", `${error.message.replace(/[.\s]*$/, "")}. The agent's learning folder on this server and its learning records are kept: send the DELETE again once it can be reached.`, { retry_after_ms: 5_000 });
|
|
2986
|
-
}
|
|
2987
|
-
}
|
|
2988
|
-
},
|
|
2989
|
-
}));
|
|
2955
|
+
/** Step 2 of DELETE /agents/{id}, and DELETE /agents/{id}/learning: the learning module's delete of the agent's
|
|
2956
|
+
* learning rows (learn/delete.ts). */
|
|
2957
|
+
const learningDelete = options.deleteLearning ?? ((given, agentId, options) => deleteLearning(given, agentId, options));
|
|
2990
2958
|
/** What DELETE /agents/{id} does outside the store's rows, on this server (agent-delete.ts AgentDeleteHost). */
|
|
2991
2959
|
const agentDeleteHost = {
|
|
2992
2960
|
store,
|
|
@@ -3039,7 +3007,8 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3039
3007
|
// DELETE. A run on its agent's own disk: with its agent's delete that disk went whole (removeDisk), its folder with
|
|
3040
3008
|
// it; deleted alone, its folder there is deleted, the disk kept, read from its disk setting, which goes after.
|
|
3041
3009
|
const launched = await store.runs.launch(runId).then((row) => readLaunchBody(row.body)?.archilDisk, (error) => (error instanceof StoreLaunchMissing ? undefined : Promise.reject(error)));
|
|
3042
|
-
// The agent's learning folder there too
|
|
3010
|
+
// The agent's learning folder there too, kept from before learning moved to the store's rows: a Mode 2 end wrote
|
|
3011
|
+
// the run's diff and correction in it, and nothing reads it (learn/legacy/scrub.ts).
|
|
3043
3012
|
if (launched?.kind === "launch") {
|
|
3044
3013
|
await notYetWith(() => archil.removeRunFolder(agentId, runId, launched.diskId), ["unavailable", "upstream_failed"], again);
|
|
3045
3014
|
await notYetWith(() => archil.removeLearningFolder(agentId, launched.diskId), ["unavailable", "upstream_failed"], again);
|
|
@@ -3062,8 +3031,11 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3062
3031
|
await forgetKept("run", runId);
|
|
3063
3032
|
},
|
|
3064
3033
|
forgetAgent: async (agentId) => {
|
|
3065
|
-
// The agent's folder (its runs' folders, its home,
|
|
3034
|
+
// The agent's folder (its runs' folders, its home, the learning folder kept from before the store's rows) and its
|
|
3035
|
+
// scratch folder, and the old learning settings keys (learn/legacy/scrub.ts), as the agent's purge took them before.
|
|
3066
3036
|
await rm(agentFolder(data, agentId), { recursive: true, force: true });
|
|
3037
|
+
for (const key of [legacyGradesKey(agentId), legacyPromotionsKey(agentId)])
|
|
3038
|
+
await store.settings.remove(key);
|
|
3067
3039
|
await rm(join(data, "scratch", agentDirName(agentId)), { recursive: true, force: true });
|
|
3068
3040
|
// Private source metadata is owned by this exact agent. Prefix siblings with dotted IDs are left alone.
|
|
3069
3041
|
for (const key of [`source-sync.agent.${agentId}`, `source-sync.local.${agentId}`])
|
|
@@ -3078,12 +3050,15 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3078
3050
|
// The replay runs of its input, its audit's shadow run and a learning run it names (the store's), and its audit's shadow
|
|
3079
3051
|
// run by its id (one whose launch is gone too).
|
|
3080
3052
|
madeFrom: async (runId) => [...new Set([...(await store.runs.madeFrom(runId)), shadowRunId(runId)])],
|
|
3081
|
-
// Its copies in the agent's promotion records
|
|
3082
|
-
//
|
|
3083
|
-
//
|
|
3053
|
+
// Its copies in the agent's promotion records. Its learning rows (its saves' words, its notes and workflow files, its
|
|
3054
|
+
// grades and audits) go with the run's rows in the store's purge (Store.learning.purgeRun). Then its text off the
|
|
3055
|
+
// learning kept from before the rows (learn/legacy/scrub.ts: the agent's old learning folder here, the old settings
|
|
3056
|
+
// keys), in the agent's queue: a folder that can't be written now is 503, the run purged or kept as the purge had
|
|
3057
|
+
// got, and the next DELETE does it again.
|
|
3084
3058
|
forgetCopies: async (agentId, runId) => {
|
|
3085
|
-
await forgetRunCopies(store.
|
|
3086
|
-
await
|
|
3059
|
+
await forgetRunCopies(store.learning, agentId, runId);
|
|
3060
|
+
await forgetSdkCopies(store, agentId, runId);
|
|
3061
|
+
await notYetWith(() => forgetLegacyRunLearning(data, agentId, runId, store), ["unavailable"], "The agent's old learning folder keeps the run's text until the DELETE is sent again.");
|
|
3087
3062
|
},
|
|
3088
3063
|
// /usage's meters and a live read's spend, from its journal, as they read now (store-reads/cap.ts), and how its
|
|
3089
3064
|
// learning ended as /stats counts it (its state and reason alone).
|
|
@@ -3110,7 +3085,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3110
3085
|
store,
|
|
3111
3086
|
deleteLearning: learningDelete,
|
|
3112
3087
|
cancel: agentDeleteHost.cancel,
|
|
3113
|
-
inQueue: (agentId, work) =>
|
|
3088
|
+
inQueue: (agentId, work) => inLearningQueue(data, agentId, work),
|
|
3114
3089
|
waitMs: agentDeleteHost.waitMs,
|
|
3115
3090
|
pollMs: agentDeleteHost.pollMs,
|
|
3116
3091
|
};
|
|
@@ -3410,8 +3385,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3410
3385
|
}
|
|
3411
3386
|
/** A definition being saved: refused (422 by field) when it can never run here; else what this host still lacks, and
|
|
3412
3387
|
* its pins (mcpListingOf, monidPinOf), each carrying from `previous` what its grants did not change. A revision that
|
|
3413
|
-
* names no place is checked where it would run (fallbackPlace).
|
|
3414
|
-
|
|
3388
|
+
* names no place is checked where it would run (fallbackPlace). `toolsUnnamed`: a create whose definition names no tools
|
|
3389
|
+
* (the store has given it its empty list by now), which would get a shell in the default box. */
|
|
3390
|
+
async function saveable(revision, previous, { toolsUnnamed = false } = {}) {
|
|
3415
3391
|
// The store's NewRevision keeps the revision's fields under `body` (AgenticBody|WorkflowBody); build the flat shape the
|
|
3416
3392
|
// host checks (runnable.ts RevisionShape) from it, as shapeOf does for a run's Revision.
|
|
3417
3393
|
const body = revision.body;
|
|
@@ -3426,6 +3402,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3426
3402
|
}
|
|
3427
3403
|
if (cliLearningOf(body) || sdkOf(body))
|
|
3428
3404
|
return { warnings: [], stamp: {} };
|
|
3405
|
+
const noPlace = await noPlaceOf(revision, toolsUnnamed);
|
|
3429
3406
|
await loginNow();
|
|
3430
3407
|
// A workflow's own issues, as POST /workflows/validate lists them (workflowIssues: the DSL's checks, the durable
|
|
3431
3408
|
// runner's refusal), refuse its save before anything is written, each at its path under definition.workflow. Asked
|
|
@@ -3464,15 +3441,31 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3464
3441
|
blockers.push(...added.filter((b) => b.unpriced || b.short));
|
|
3465
3442
|
blockers.push(...added.filter((b) => !b.unpriced && !b.short).map((b) => ({ ...b, reason: "not_an_option", fix: "Pick another provider for this tool in definition.tool_settings, or clear the agent's default cap (max_cost_usd: 0).", host: false })));
|
|
3466
3443
|
}
|
|
3467
|
-
|
|
3444
|
+
// A shell tool with no place is refused there already (runnable.ts shellOnRunner); no tools named is refused here.
|
|
3445
|
+
const never = blockers.filter((b) => !b.host).map(issueOf);
|
|
3446
|
+
if (noPlace && !never.some((issue) => issue.field === noPlace.field))
|
|
3447
|
+
never.unshift(noPlace);
|
|
3468
3448
|
if (never.length)
|
|
3469
|
-
throw invalid(never
|
|
3449
|
+
throw invalid(never);
|
|
3470
3450
|
const mcpPin = listing.pin();
|
|
3471
3451
|
// A computer every tool of which is set to deny, here or in the agent's own settings: its runs never start it.
|
|
3472
3452
|
const denied = await deniedComputer(shape, settings.get(), shellOf);
|
|
3473
3453
|
const off = denied ? [{ field: "definition.computer", reason: "not_allowed", message: computerDeniedWords(denied) }] : [];
|
|
3474
3454
|
return { warnings: [...blockers.map(issueOf), ...off, ...usage], stamp: { ...(mcpPin ? { mcpPin } : {}), ...(monid ? { monidPin: monid } : {}) } };
|
|
3475
3455
|
}
|
|
3456
|
+
/** Why a new `revision` cannot be saved for want of a place, the one check a save (saveable) and an apply's plan
|
|
3457
|
+
* (planTemplate) both make, so a plan never says a create the apply refuses: an agentic revision that names no place
|
|
3458
|
+
* and would be given Docker's box (no tools named, `toolsUnnamed`, or a shell tool), where this server has none and the
|
|
3459
|
+
* runner has no shell (Mode 1), is refused, naming a box or the runner, never given another box (place.ts
|
|
3460
|
+
* noBoxRefusal). On Mode 2 it saves for the runner, as it always did. Native, CLI-learning and SDK agents run elsewhere. */
|
|
3461
|
+
async function noPlaceOf(revision, toolsUnnamed) {
|
|
3462
|
+
const body = revision.body;
|
|
3463
|
+
if (revision.kind !== "agentic" || nativeOf(body) || cliLearningOf(body) || sdkOf(body))
|
|
3464
|
+
return undefined;
|
|
3465
|
+
if (body.place !== undefined || body.computer !== undefined)
|
|
3466
|
+
return undefined;
|
|
3467
|
+
return noBoxRefusal(toolsUnnamed ? undefined : body.tools ?? [], boxOffers, toolOf, (await shellOf({ kind: "none" })) === "local");
|
|
3468
|
+
}
|
|
3476
3469
|
/** An agentic `revision`'s monid pin (monid.ts pinMonid) and a warning per endpoint priced by usage; a grant that
|
|
3477
3470
|
* cannot be pinned refuses the save (422). Undefined when it grants none. */
|
|
3478
3471
|
async function monidPinOf(revision, previous) {
|
|
@@ -3503,16 +3496,18 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3503
3496
|
};
|
|
3504
3497
|
/** POST /agents' body made into its agent, as that route makes one, with what this host still lacks for it. A new agent
|
|
3505
3498
|
* that names no place is given this server's box (place.ts defaultPlaceOf), stamped on its revision, when it names no
|
|
3506
|
-
* tools (it gets bash) or a tool that needs a shell
|
|
3507
|
-
* (browser), keeps the runner. */
|
|
3508
|
-
async function createAgentOf(body, template) {
|
|
3499
|
+
* tools (it gets bash) or a tool that needs a shell, and refused where Docker's box is not here and the runner has no
|
|
3500
|
+
* shell (saveable); one whose tools need none, or that names a tool the box refuses (browser), keeps the runner. */
|
|
3501
|
+
async function createAgentOf(body, template, { toolsUnnamed } = {}) {
|
|
3509
3502
|
let warnings = [];
|
|
3510
3503
|
const definition = checkDefinitionBody(body, { harnesses });
|
|
3511
3504
|
const named = Array.isArray(definition.definition.tools) ? definition.definition.tools : [];
|
|
3512
3505
|
const place = fallbackPlace("agentic", definition.definition.tools === undefined ? NEW_AGENT_TOOLS : named);
|
|
3513
3506
|
const tools = defaultToolsAt(place);
|
|
3514
3507
|
const entry = await agents.create(definition, async (revision) => {
|
|
3515
|
-
|
|
3508
|
+
// A template's apply says whether its package named its tools (applyWith): one that named none, and no computer
|
|
3509
|
+
// list, is the agent that would get Docker's box, whatever its grants compiled to, and is refused where there is none.
|
|
3510
|
+
const saved = await saveable(revision, null, { toolsUnnamed: toolsUnnamed ?? definition.definition.tools === undefined });
|
|
3516
3511
|
warnings = saved.warnings;
|
|
3517
3512
|
return saved.stamp;
|
|
3518
3513
|
}, place.mode === "sandbox" && tools ? { place, tools } : undefined, template);
|
|
@@ -3553,13 +3548,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3553
3548
|
throw new ApiError("agent_archived", `The agent ${id} is archived: unarchive it, then apply the ${pkg.name} template onto it again.`);
|
|
3554
3549
|
return entry;
|
|
3555
3550
|
}
|
|
3556
|
-
/** A replay's ports for agent `entry` (runner/promotion.ts askReplay, replayView): its learning
|
|
3551
|
+
/** A replay's ports for agent `entry` (runner/promotion.ts askReplay, replayView): its learning as this server
|
|
3557
3552
|
* reads it, cut of the host's secrets as the learning reads cut them, and a replay run's launch made as a run's start
|
|
3558
3553
|
* makes one now (prepareLaunch: the agent's current revision, model, plane and learning start). */
|
|
3559
3554
|
const replayAskOf = (entry) => ({
|
|
3560
3555
|
admitAuxiliary: auxiliaryAdmitter(store, { data, project: startDeps.project }),
|
|
3561
3556
|
store, agentId: entry.agent.id, context: ctx, log: (line) => void log?.(line),
|
|
3562
|
-
|
|
3557
|
+
shown: () => learningShown(entry.agent.id),
|
|
3563
3558
|
launchOf: async (input) => {
|
|
3564
3559
|
const { launch, revision } = await prepareLaunch(startDeps, entry, { input });
|
|
3565
3560
|
return { launch, revisionId: revision.id };
|
|
@@ -3630,6 +3625,14 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3630
3625
|
* skipped for a connection this server lacks), and the computer it picks. Any other refusal is the apply's own. */
|
|
3631
3626
|
async function planTemplate(template, body) {
|
|
3632
3627
|
const p = await prepareApply(template, body, { plan: true });
|
|
3628
|
+
// A fresh apply refused for want of a place (createAgentOf's save) is refused here, in the same words: no plan of a
|
|
3629
|
+
// create the apply would refuse.
|
|
3630
|
+
if (!p.onto) {
|
|
3631
|
+
const { definition, skills } = checkDefinitionBody(p.made.agent, { harnesses });
|
|
3632
|
+
const refused = await noPlaceOf(makeRevision(definition, skills ?? {}, undefined), p.toolsUnnamed);
|
|
3633
|
+
if (refused)
|
|
3634
|
+
throw invalid([refused]);
|
|
3635
|
+
}
|
|
3633
3636
|
// A monid grant is pinned to monid's listing when the agent is saved (saveable: monidPinOf), read with the monid key:
|
|
3634
3637
|
// with none here the apply is refused, so the plan lists the key. A grant the agent's current pin carries reads
|
|
3635
3638
|
// nothing (pinMonid with no key answers before any request).
|
|
@@ -3859,12 +3862,15 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3859
3862
|
// triggers are the package's is on each trigger (its mark), not here.
|
|
3860
3863
|
const digest = parametersDigest(sealKey, stable(parameters));
|
|
3861
3864
|
const origin = { id: pkg.id, version: pkg.version, sha: pkg.origin?.sha ?? null, parameters_digest: digest, secrets: declared };
|
|
3862
|
-
|
|
3865
|
+
// A package that names no tools and no computer list makes the agent a create that names no tools makes (createAgentOf),
|
|
3866
|
+
// whatever its grants compiled to: it would get Docker's box, and is refused where there is none (noPlaceOf).
|
|
3867
|
+
const toolsUnnamed = pkg.tools === undefined && !pick;
|
|
3868
|
+
return { pkg, onto, missing, unsaved, saved, mapped, grants, pick, toolsUnnamed, made, emptyFeeds, hostless, unmade, hadByName, remade, resent, removing, digest, origin, warned: [...keyWarnings, ...skipped, ...kept, ...modelWarnings, ...computerWarnings] };
|
|
3863
3869
|
}
|
|
3864
3870
|
/** applyTemplate's work, in its turn on the agent where it has agent_id: prepareApply's reads and checks, then its
|
|
3865
3871
|
* writes. */
|
|
3866
3872
|
async function applyWith(template, body) {
|
|
3867
|
-
const { pkg, onto, saved, mapped, grants, made, emptyFeeds, hostless, unmade, hadByName, remade, resent, removing, digest, origin, warned } = await prepareApply(template, body, { plan: false });
|
|
3873
|
+
const { pkg, onto, saved, mapped, grants, toolsUnnamed, made, emptyFeeds, hostless, unmade, hadByName, remade, resent, removing, digest, origin, warned } = await prepareApply(template, body, { plan: false });
|
|
3868
3874
|
// A fresh apply of what already made a live agent here (the same package and parameters) still makes one, and says
|
|
3869
3875
|
// which is there: an apply with its agent_id updates that one instead. Read before this apply's agent is made.
|
|
3870
3876
|
const twins = (await twinsOf(onto, pkg.id, digest))
|
|
@@ -3878,7 +3884,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3878
3884
|
throw new ApiError("precondition_failed", `The agent ${onto.agent.id} changed while this apply of the ${pkg.name} template read it (an edit, or another apply, wrote a revision): nothing was changed. Apply it with agent_id again to update the agent as it is now.`);
|
|
3879
3885
|
throw error;
|
|
3880
3886
|
})
|
|
3881
|
-
: await createAgentOf(made.agent, origin);
|
|
3887
|
+
: await createAgentOf(made.agent, origin, { toolsUnnamed });
|
|
3882
3888
|
// An update's triggers are reconciled by name with the ones the agent has: the package's trigger of a name the agent
|
|
3883
3889
|
// has (of the same kind) is changed in place, keeping its id, a feed's seen items, a webhook's secret and whether the
|
|
3884
3890
|
// owner turned it off (an unmarked one is adopted so, and only so: notOurs above), its settings the package's whole
|
|
@@ -4428,6 +4434,40 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4428
4434
|
return { ...(source !== undefined ? { source } : {}), ...windowParams(url), ...(model !== undefined ? { model } : {}) };
|
|
4429
4435
|
}
|
|
4430
4436
|
async function runsPage(url, filter, origin, only = {}) {
|
|
4437
|
+
const vd = viewDepsFor(origin);
|
|
4438
|
+
// The Agent Factory's page, from the rows too: each run's list item and what its listing keeps for the factory
|
|
4439
|
+
// (store-view.ts KeptFactory), built once per change of the run as the list below builds them, so a refresh builds no
|
|
4440
|
+
// view of a run that has not moved, however many runs the board holds and however long they ran. Two reads for the
|
|
4441
|
+
// page (the listings, the runners' ticks), then per run only what is read as it stands now: who observes it
|
|
4442
|
+
// (observationOf) and its computer (runComputerRead, which reads a journal only for a desktop or phone that is up,
|
|
4443
|
+
// or a computer held for its owner). A listing behind, cut of other secrets, or built before listings kept the
|
|
4444
|
+
// factory's part is built first, once: the page shows that build whether or not its write landed (a run that moved
|
|
4445
|
+
// again meanwhile stays behind, for the lister or the next page), so a busy run costs one build a page, never the
|
|
4446
|
+
// several a status filter makes below (listNow), which this page has no need of.
|
|
4447
|
+
if (url.searchParams.has("scope"))
|
|
4448
|
+
return factoryRunsPage(store, url, filter, async (rows) => {
|
|
4449
|
+
const secrets = serverSecrets();
|
|
4450
|
+
const now = vd.now ?? Date.now;
|
|
4451
|
+
const ids = rows.map((row) => row.id);
|
|
4452
|
+
const kept = new Map((await store.runs.listings(ids)).map((read) => [read.id, read]));
|
|
4453
|
+
const ticks = new Map((await store.live.read(ids)).map((tick) => [tick.runId, tick.updatedAt]));
|
|
4454
|
+
const runs = [];
|
|
4455
|
+
for (const row of rows) {
|
|
4456
|
+
const read = kept.get(row.id);
|
|
4457
|
+
// A run purged since the page's rows were read has no listing to show (Runs.listings).
|
|
4458
|
+
if (!read)
|
|
4459
|
+
continue;
|
|
4460
|
+
const held = read.listing !== null && !read.behind && builtOfNow(read.listing, secrets) && keptFactory(read.listing, secrets) ? read.listing : undefined;
|
|
4461
|
+
const listing = held ?? (await lister.build(row.id, read.listMark, vd)).listing;
|
|
4462
|
+
const factory = listing && keptFactory(listing, secrets);
|
|
4463
|
+
if (!listing || !factory)
|
|
4464
|
+
continue;
|
|
4465
|
+
const observation = await observationOf(store, factory.observed, liveOf(row, now()), ticks.get(row.id), now);
|
|
4466
|
+
const summary = { ...listedItem(listing, origin, row.archivedAt ?? read.agentArchivedAt, secrets), factory: { ...factory.activity, observation } };
|
|
4467
|
+
runs.push({ ...summary, ...(await runComputerRead(store, row.id, summary, { context: ctx })) });
|
|
4468
|
+
}
|
|
4469
|
+
return runs;
|
|
4470
|
+
});
|
|
4431
4471
|
const limit = limitOf(url.searchParams.get("limit"));
|
|
4432
4472
|
const offset = cursorOf(url.searchParams.get("cursor"));
|
|
4433
4473
|
const status = url.searchParams.get("status");
|
|
@@ -4439,7 +4479,6 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4439
4479
|
const archived = archivedParam(url);
|
|
4440
4480
|
// `label=<key>:<value>`, once: only the runs holding it (run-labels.ts), filtered in the store.
|
|
4441
4481
|
const labels = labelFilter(url.searchParams.getAll("label"));
|
|
4442
|
-
const vd = viewDepsFor(origin);
|
|
4443
4482
|
// The page from the runs' rows alone (store/schema.ts RUN_LISTING_COLUMNS): filtered (`status` on the listing's status),
|
|
4444
4483
|
// ordered and cut to the page in one query, so a list costs the same at ten runs and at thousands, however long their
|
|
4445
4484
|
// 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
|
|
@@ -4456,7 +4495,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4456
4495
|
// A write that lands while a listing is built moves the run's mark, so the listing is not written (Runs.putListing),
|
|
4457
4496
|
// and a run still going is left with no status on its row: the build is made again from the mark that write left, up
|
|
4458
4497
|
// to LIST_TRIES builds, so a filter never leaves off a run because a write met its build. Each is the lister's build
|
|
4459
|
-
// (Lister.build), so a held listing built here has its agent's learning
|
|
4498
|
+
// (Lister.build), so a held listing built here has its agent's learning read by the lister's passes after it.
|
|
4460
4499
|
const listNow = async (runId, read) => {
|
|
4461
4500
|
for (let mark = read, tries = 1;; tries++) {
|
|
4462
4501
|
const { listing, written } = await lister.build(runId, mark, vd);
|
|
@@ -4957,16 +4996,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4957
4996
|
// skew check; left out when the store cannot say (a read that failed).
|
|
4958
4997
|
const state = await store.schemaState?.().catch(() => undefined);
|
|
4959
4998
|
const storeSchema = state ? { store_schema: { version: state.version, runner_floor: state.runnerFloor, known: state.known } } : {};
|
|
4960
|
-
//
|
|
4961
|
-
// the
|
|
4962
|
-
|
|
4963
|
-
const keptShown = byOwnerSession(req) || bearer(req.headers.authorization, req);
|
|
4964
|
-
if (!keptShown && req.headers.authorization !== undefined)
|
|
4999
|
+
// This route answers before any bearer check, the same to every caller. A bearer this server does not take still
|
|
5000
|
+
// gets the answer, and the auth_failed line any other route writes for it.
|
|
5001
|
+
if (req.headers.authorization !== undefined && !byOwnerSession(req) && !bearer(req.headers.authorization, req))
|
|
4965
5002
|
authFailed(`/v2${path}`, "wrong_token");
|
|
4966
|
-
const keptCap = { ...answer.features.harness_keys, kept: keptShown ? answer.features.harness_keys.kept : [] };
|
|
4967
5003
|
// tools[].held: the server's keyless holds on each web tool now (web-run.ts withHeld), never cached.
|
|
4968
5004
|
// features.api_keys.routes: false on an API-only server, which serves none of the keys' routes and reads no key.
|
|
4969
|
-
return send(res, 200, { ...answer, tools: withHeld(answer.tools), ...storeSchema, runner_refused: runnerRefused, features: { ...answer.features,
|
|
5005
|
+
return send(res, 200, { ...answer, tools: withHeld(answer.tools), ...storeSchema, runner_refused: runnerRefused, features: { ...answer.features, computers: await computerCapabilities(computersOf()), triggers: { ...answer.features.triggers, public_url: Boolean(options.publicUrl) }, claude_login: loginServed, api_keys: { ...answer.features.api_keys, routes: !options.apiOnly } } });
|
|
4970
5006
|
}
|
|
4971
5007
|
if (found.name === "getOpenapi")
|
|
4972
5008
|
return send(res, 200, servedOpenapi(openapi, ownerCookieName(req)));
|
|
@@ -5724,7 +5760,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5724
5760
|
case "deleteRun": {
|
|
5725
5761
|
// In its agent's delete turn (an agent's delete or purge, or another purge of one of its runs, finishes first), the
|
|
5726
5762
|
// run read in that turn, so a DELETE after one that finished is 204 again (purgeRun: a purged run's only work is
|
|
5727
|
-
// its learning
|
|
5763
|
+
// its learning rows' delete, again).
|
|
5728
5764
|
const row = ID.test(id) ? await store.runs.get(id) : undefined;
|
|
5729
5765
|
if (!row)
|
|
5730
5766
|
throw new ApiError("not_found", `no run ${id}`);
|
|
@@ -5804,11 +5840,16 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5804
5840
|
const kept = await runWrite(row.agentId, row.id, async () => {
|
|
5805
5841
|
// Kept with what it asks of the run's learning (runner/feedback-round.ts): nothing, or a look-back.
|
|
5806
5842
|
// Its feedback round is a turn with no caller's model key: on the server's key for the run's route, else not opened.
|
|
5807
|
-
|
|
5843
|
+
// A purge of the run from another process, past the check above: the grade's write refuses it in its own
|
|
5844
|
+
// transaction (Store.learning changeRecords), nothing written, and it answers as a purged run's grade does.
|
|
5845
|
+
const graded = gradeView(await keepGrade(store, row.agentId, grade, typeof body.label === "string" ? body.label : undefined, (launch) => !serverKeyMissing(env, { kind: "agentic", model: launch.model, native: Boolean(launch.native) })).catch(async (error) => {
|
|
5846
|
+
const now = error instanceof LearningRecordRefused ? await store.runs.get(row.id) : undefined;
|
|
5847
|
+
throw now && now.purgedAt !== null ? purgedRun(now) : error;
|
|
5848
|
+
}));
|
|
5808
5849
|
// A grade of a run its learned workflow answered alone is an audit row too (runner/audit.ts gradeRow): the hold rule
|
|
5809
5850
|
// reads it with the shadows'. A row not written now is logged, never the grade refused.
|
|
5810
5851
|
const said = (line) => log?.(logLine("audit", { run: row.id, said: line }));
|
|
5811
|
-
await gradeRow({ store, agentId: row.agentId, revisionId: row.revisionId, context: ctx,
|
|
5852
|
+
await gradeRow({ store, agentId: row.agentId, revisionId: row.revisionId, context: ctx, shown: () => learningShown(row.agentId), log: said }, row, grade.correct, grade.expected).catch((error) => said(`the grade wrote no audit row (${error?.message ?? error})`));
|
|
5812
5853
|
return graded;
|
|
5813
5854
|
});
|
|
5814
5855
|
// Its workflow's name cut as GET /runs/{id}/learning cuts it (learningShown); withheld whole when that cut can't be
|
|
@@ -6268,6 +6309,17 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6268
6309
|
const { revoked } = await plan.signOut();
|
|
6269
6310
|
return send(res, 200, revoked ? { revoked } : { revoked, message: SIGN_OUT_UNCONFIRMED });
|
|
6270
6311
|
}
|
|
6312
|
+
// Its sign-out (claude-login.ts signOutClaudeLogin): AgentRun's own login removed, the mode off; this machine's own
|
|
6313
|
+
// login refused in words.
|
|
6314
|
+
case "signOutClaudeLogin":
|
|
6315
|
+
try {
|
|
6316
|
+
return send(res, 200, await signOutClaudeLogin(loginDeps()), { "cache-control": "no-store" });
|
|
6317
|
+
}
|
|
6318
|
+
catch (error) {
|
|
6319
|
+
if (error instanceof ClaudeLoginRefused)
|
|
6320
|
+
throw new ApiError(error.code, error.message);
|
|
6321
|
+
throw error;
|
|
6322
|
+
}
|
|
6271
6323
|
// Claude Code's login on this machine (claude-login.ts): only its status is read, by asking the CLI.
|
|
6272
6324
|
case "getClaudeLogin":
|
|
6273
6325
|
case "turnOnClaudeLogin":
|
|
@@ -6500,24 +6552,23 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6500
6552
|
// definition's: an archived agent's too.
|
|
6501
6553
|
case "getAgentLearning": {
|
|
6502
6554
|
const entry = await needAgent(id);
|
|
6503
|
-
// The agent's learning view: its corrections, workflows and log from its learning
|
|
6555
|
+
// The agent's learning view: its corrections, workflows and log from its learning rows; its run-fared counts and
|
|
6504
6556
|
// its impact over the one store (agentLearningOverStore), from each run's launch, journal and learning end.
|
|
6505
6557
|
const { counts, impact } = await agentLearningOverStore(store, id);
|
|
6506
6558
|
// Each workflow's status past its README.md's: where it stands as GET .../learning/promotions says it (servingStateOf
|
|
6507
6559
|
// over the same records and the money rule's decision, costStopOverStore), so the view never says a workflow serves
|
|
6508
6560
|
// that does not run first.
|
|
6509
|
-
const records = await promotionsOf(store.
|
|
6510
|
-
const refused = await refusedFor(id, records);
|
|
6561
|
+
const records = await promotionsOf(store.learning, id);
|
|
6511
6562
|
const costStop = await costStopOverStore(store, id);
|
|
6512
6563
|
const body = entry.revision?.body;
|
|
6513
6564
|
const modelEnv = !body || sdkOf(body) || nativeOf(body) ? env : envAtPlace(env, resolvePlace(body.place, fallbackPlace(entry.revision.kind === "workflow" ? "workflow" : "agentic", body.tools ?? [])));
|
|
6514
|
-
return send(res, 200, { ...await agentLearning(
|
|
6565
|
+
return send(res, 200, { ...await agentLearning(store, id, await learningShown(id), counts, impact, (workflow) => servingStateOf(records, workflow, costStop)), learning_model: await learningModelOf(modelEnv, entry.revision) });
|
|
6515
6566
|
}
|
|
6516
6567
|
case "getLearningCost": {
|
|
6517
6568
|
await needAgent(id);
|
|
6518
6569
|
// The agent's cost per run over the one store (agentCostOverStore): each ended run's figures and path, aggregates only.
|
|
6519
6570
|
const { limit, csv } = learningCostQuery(url);
|
|
6520
|
-
const read = await agentCostOverStore(store, id, limit
|
|
6571
|
+
const read = await agentCostOverStore(store, id, limit);
|
|
6521
6572
|
// Each workflow's name as the other learning reads show it: one that holds a secret or a sign-in's value is cut.
|
|
6522
6573
|
const shown = await learningShown(id);
|
|
6523
6574
|
const cost = { ...read, runs: read.runs.map((run) => (run.workflow === null ? run : { ...run, workflow: shown.name(run.workflow) })), workflows: read.workflows.map((one) => ({ ...one, workflow: shown.name(one.workflow) })), bill: { ...read.bill, revisions: read.bill.revisions.map((one) => ({ ...one, workflow: shown.name(one.workflow) })), holds: read.bill.holds.map((one) => ({ ...one, workflow: shown.name(one.workflow), reason: shown.text(one.reason) })) } };
|
|
@@ -6533,28 +6584,25 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6533
6584
|
// its holds (a check's, an audit's). Every text in them cut as the other learning reads cut theirs
|
|
6534
6585
|
// (promotionsShown: a reason as well as each workflow's name). Beside what serves, each one's state, its check's
|
|
6535
6586
|
// numbers and its audit line (learn/audit.ts servingLinesOf), at the agent's numbers.
|
|
6536
|
-
const records = await promotionsOf(store.
|
|
6537
|
-
// Every champion below skips a record the purge gate refuses at its commit, as a run's claim does (championOf).
|
|
6538
|
-
const refused = await refusedFor(id, records);
|
|
6587
|
+
const records = await promotionsOf(store.learning, id);
|
|
6539
6588
|
const shown = await learningShown(id);
|
|
6540
|
-
const shownRead = promotionsShown(records, shown
|
|
6589
|
+
const shownRead = promotionsShown(records, shown);
|
|
6541
6590
|
// A ledger that can't be read now leaves each audit line at no rows, never the read refused.
|
|
6542
6591
|
const loop = auditLoopOf(entry.revision?.body?.learning);
|
|
6543
6592
|
// Each one's state with the money rule's decision a run's launch reads (costStopOverStore): a champion it stopped
|
|
6544
6593
|
// running first reads `stopped`.
|
|
6545
|
-
const lines = servingLinesOf(records, await auditsOfAgent(id).catch(() => []), loop, await costStopOverStore(store, id)
|
|
6594
|
+
const lines = servingLinesOf(records, await auditsOfAgent(id).catch(() => []), loop, await costStopOverStore(store, id));
|
|
6546
6595
|
// Why its runs are never audited, when the agent can call a tool that writes (learn/audit.ts auditWriterOf, the
|
|
6547
6596
|
// rule startAudit reads); and how many of the serving revision's runs a trigger started (never audited).
|
|
6548
6597
|
const writer = auditWriterOf(entry.revision ?? undefined);
|
|
6549
6598
|
const auditsOff = writer === undefined ? null : shown.text(auditsOffWords(writer));
|
|
6550
|
-
// The champion's own revision, read by its recorded digest
|
|
6551
|
-
//
|
|
6552
|
-
//
|
|
6599
|
+
// The champion's own revision, read by its recorded digest from the workflow's versions. Its nodes with their tiers
|
|
6600
|
+
// and code checks, and the check it was promoted on; nodes null when no version holds its text (or the rows can't
|
|
6601
|
+
// be read now).
|
|
6553
6602
|
const championRead = async (workflow, digest) => {
|
|
6554
|
-
const champion = championOf(records, workflow
|
|
6603
|
+
const champion = championOf(records, workflow);
|
|
6555
6604
|
const record = champion?.digest === digest ? champion : undefined;
|
|
6556
|
-
const
|
|
6557
|
-
const read = await workflowAtDigest(data, id, workflow, digest, commits, store).catch(() => undefined);
|
|
6605
|
+
const read = await workflowAtDigest(store, id, workflow, digest).catch(() => undefined);
|
|
6558
6606
|
let doc;
|
|
6559
6607
|
try {
|
|
6560
6608
|
doc = read ? JSON.parse(read.text) : undefined;
|
|
@@ -6564,7 +6612,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6564
6612
|
}
|
|
6565
6613
|
return shownDeep({ digest, commit: read?.commit ?? null, nodes: doc === undefined ? null : workflowNodesOf(doc), check: record?.check ?? null }, shown);
|
|
6566
6614
|
};
|
|
6567
|
-
const serving = await Promise.all(servingOf(records
|
|
6615
|
+
const serving = await Promise.all(servingOf(records).map(async (one, i) => ({
|
|
6568
6616
|
...shownRead.serving[i], ...lines[i], audits_off: auditsOff,
|
|
6569
6617
|
not_auditable: one.digest === null ? 0 : await notAuditableOf(store, id, one.workflow, one.digest, loop).catch(() => 0),
|
|
6570
6618
|
champion: one.digest === null ? null : await championRead(one.workflow, one.digest),
|
|
@@ -6573,7 +6621,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6573
6621
|
}
|
|
6574
6622
|
case "listLearningAudits": {
|
|
6575
6623
|
await needAgent(id);
|
|
6576
|
-
// The audit ledger (learn/audit.ts
|
|
6624
|
+
// The audit ledger (the agent's audit records, learn/audit.ts), oldest first: each workflow's name and every other text cut as the
|
|
6577
6625
|
// promotions read cuts its own.
|
|
6578
6626
|
const shown = await learningShown(id);
|
|
6579
6627
|
const rows = await auditsOfAgent(id);
|
|
@@ -6600,11 +6648,11 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6600
6648
|
}
|
|
6601
6649
|
case "listLearningLog":
|
|
6602
6650
|
await needAgent(id);
|
|
6603
|
-
return send(res, 200, await learningLog(
|
|
6651
|
+
return send(res, 200, await learningLog(store, id, url.searchParams, await learningShown(id)));
|
|
6604
6652
|
case "getLearningCorrections": {
|
|
6605
6653
|
await needAgent(id);
|
|
6606
6654
|
// corrections.md whole, as every run of the agent is served it under # Learned, with its ETag in the body and the header.
|
|
6607
|
-
const read = await correctionsView(
|
|
6655
|
+
const read = await correctionsView(store, id, await learningShown(id));
|
|
6608
6656
|
return send(res, 200, read, { etag: read.etag });
|
|
6609
6657
|
}
|
|
6610
6658
|
case "putLearningCorrections": {
|
|
@@ -6613,7 +6661,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6613
6661
|
// What it refuses is what the reads cut: the host's secrets and the agent's sign-in pointers.
|
|
6614
6662
|
const refuse = await learningValues(id);
|
|
6615
6663
|
// A write to the agent's learning: in its delete turn (agentWrite), the body read before, outside it.
|
|
6616
|
-
const written = await agentWrite(id, () => correctionsWrite(
|
|
6664
|
+
const written = await agentWrite(id, () => correctionsWrite(store, id, { text, ifMatch: typeof req.headers["if-match"] === "string" ? req.headers["if-match"] : undefined, refuse }));
|
|
6617
6665
|
return send(res, 200, written, { etag: written.etag });
|
|
6618
6666
|
}
|
|
6619
6667
|
case "deleteAgentLearning": {
|
|
@@ -6627,10 +6675,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6627
6675
|
}
|
|
6628
6676
|
case "listLearnedWorkflowRevisions":
|
|
6629
6677
|
await needAgent(id);
|
|
6630
|
-
return send(res, 200, await workflowRevisions(
|
|
6678
|
+
return send(res, 200, await workflowRevisions(store, id, second, url.searchParams, await learningShown(id)));
|
|
6631
6679
|
case "readLearningFile":
|
|
6632
6680
|
await needAgent(id);
|
|
6633
|
-
return sendText(res, 200, await readLearnedFile(
|
|
6681
|
+
return sendText(res, 200, await readLearnedFile(store, id, second, await learningShown(id)));
|
|
6634
6682
|
case "retireLearningFile":
|
|
6635
6683
|
case "approveLearningFile":
|
|
6636
6684
|
case "restoreLearningFile": {
|
|
@@ -6638,7 +6686,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6638
6686
|
const refuse = await learningValues(id);
|
|
6639
6687
|
const action = found.name === "approveLearningFile" ? "approve" : found.name === "restoreLearningFile" ? "restore" : "retire";
|
|
6640
6688
|
// A change to a workflow is a write to the agent's learning: in its delete turn (agentWrite).
|
|
6641
|
-
const written = await agentWrite(id, () => changeWorkflow(
|
|
6689
|
+
const written = await agentWrite(id, () => changeWorkflow(store, id, second, { action, ifMatch: typeof req.headers["if-match"] === "string" ? req.headers["if-match"] : undefined, refuse, draftTools: () => learnedDraftToolsOf(id) }));
|
|
6642
6690
|
// A run's list row that read a workflow held for the owner's OK says what the folder says now, at the next list.
|
|
6643
6691
|
await lister.learningChanged(id);
|
|
6644
6692
|
return sendText(res, written.status, { ...written, text: secretsShown(refuse).text(written.text) });
|
|
@@ -6674,7 +6722,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6674
6722
|
case "getRunLearning": {
|
|
6675
6723
|
const run = await needRun(id);
|
|
6676
6724
|
// The run's learning view over the store (learning-1's runLearningOverStore): its end, the notes it was given and its seed
|
|
6677
|
-
// from its launch, what it holds for the owner's OK as the store's run view reads it (
|
|
6725
|
+
// from its launch, what it holds for the owner's OK as the store's run view reads it (at its agent's newest save), as main.
|
|
6678
6726
|
// Cut by the run's one cut, and refused for a withheld run (run-learning-served.ts).
|
|
6679
6727
|
return send(res, 200, await servedRunLearning({ serverSecrets, signIns, sealKey, statuses }, store, run.id));
|
|
6680
6728
|
}
|
|
@@ -7477,6 +7525,8 @@ async function startHolding(options, data, checked, stops) {
|
|
|
7477
7525
|
// An upgraded socket is no connection closeAllConnections ends, and server.close waits for it.
|
|
7478
7526
|
viewers.close();
|
|
7479
7527
|
clearInterval(routeTick);
|
|
7528
|
+
// A tick already running reads the store: waited out here, before the store closes below.
|
|
7529
|
+
await Promise.all(routeTicks);
|
|
7480
7530
|
await attach.close();
|
|
7481
7531
|
await new Promise((done) => (server.close(done), server.closeAllConnections()));
|
|
7482
7532
|
// No request is left to use a key: its last-use writes end before the store they write to closes.
|
|
@@ -7514,7 +7564,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
7514
7564
|
tokenMade: stored?.made ?? false,
|
|
7515
7565
|
...(setupUrl ? { setupUrl, setupOpen: openSetup } : {}),
|
|
7516
7566
|
...(consoleSessions ? { launchCode: consoleSessions.code } : {}),
|
|
7517
|
-
boxesLine: boxesLine(boxOffers, enabledBoxes(env), boxAllow, boxesByDefault(env)),
|
|
7567
|
+
boxesLine: boxesLine(boxOffers, enabledBoxes(env), boxAllow, boxesByDefault(env), (await shellOf({ kind: "none" })) === "local"),
|
|
7518
7568
|
attachHub,
|
|
7519
7569
|
beside,
|
|
7520
7570
|
dial: { ...(options.publicUrl ? { url: options.publicUrl.replace(/\/+$/, "") } : {}), tokens: attach.machineTokens, hub: attachHub },
|