@parcha/agentrun-serve 0.1.0-beta.59 → 0.1.0-beta.61
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 +135 -0
- package/README.md +230 -120
- package/dist/acp-package.d.ts +4 -0
- 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 +21 -3
- package/dist/api-only.js +41 -6
- 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/browser-person.d.ts +1 -1
- package/dist/browser-person.js +1 -1
- package/dist/calendar/tools.js +1 -1
- 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/cli.js +42 -10
- package/dist/console/assets/{backend-BztxEAvb.js → backend-C9ffXUR5.js} +1 -1
- package/dist/console/assets/index-BnZV3lvW.js +639 -0
- package/dist/console/assets/{share-L84tlUDW.js → share-B1o5mJ56.js} +2 -2
- package/dist/console/assets/{styles-CaRKlHke.js → styles-D_znYrHR.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/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- 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-check.js +2 -1
- package/dist/harness-keys.d.ts +1 -2
- package/dist/harness-keys.js +1 -2
- package/dist/harness-recipe.d.ts +13 -2
- package/dist/harness-recipe.js +30 -7
- package/dist/harness-sign-in.js +2 -1
- package/dist/harness-table.d.ts +9 -3
- package/dist/harness-table.js +11 -5
- 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 +30 -18
- 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/secrets.d.ts +2 -1
- package/dist/learn/secrets.js +2 -2
- package/dist/learn/workflow-draft.d.ts +4 -1
- package/dist/learn/workflow-draft.js +12 -2
- package/dist/learned-nodes.d.ts +36 -0
- package/dist/learned-nodes.js +23 -0
- 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/local-model.d.ts +144 -0
- package/dist/local-model.js +214 -0
- package/dist/mcp-gateway.d.ts +6 -0
- package/dist/mcp-gateway.js +44 -8
- package/dist/mcp-probe.d.ts +7 -0
- package/dist/mcp-probe.js +7 -0
- 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/ollama-provider.d.ts +35 -0
- package/dist/ollama-provider.js +108 -2
- package/dist/openapi.js +147 -35
- package/dist/place-offers.d.ts +3 -0
- package/dist/place-offers.js +3 -0
- package/dist/place.d.ts +35 -12
- package/dist/place.js +67 -29
- package/dist/print.js +1 -1
- package/dist/purged-workflow.d.ts +0 -33
- package/dist/purged-workflow.js +3 -71
- package/dist/redact/match.d.ts +36 -8
- package/dist/redact/match.js +179 -44
- package/dist/run-export.js +4 -2
- 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/run-usage.js +3 -2
- package/dist/runnable.js +25 -8
- package/dist/runner/adapter-loop.d.ts +8 -1
- package/dist/runner/adapter-loop.js +100 -20
- package/dist/runner/adapter-run-spec.d.ts +3 -5
- package/dist/runner/adapter-run-spec.js +35 -61
- package/dist/runner/adapters/pi.d.ts +3 -2
- package/dist/runner/adapters/pi.js +3 -1
- package/dist/runner/audit.d.ts +3 -5
- package/dist/runner/audit.js +28 -51
- package/dist/runner/cli-run-spec.js +19 -22
- package/dist/runner/compare-end.d.ts +1 -3
- 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/dispatch.js +2 -2
- package/dist/runner/feedback-round.d.ts +1 -1
- package/dist/runner/feedback-round.js +2 -2
- package/dist/runner/harness-loops.d.ts +9 -0
- package/dist/runner/harness-loops.js +49 -7
- package/dist/runner/held.d.ts +4 -11
- 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/live-ticker.js +3 -4
- package/dist/runner/main.js +1 -1
- package/dist/runner/mcp-claim.js +3 -2
- package/dist/runner/mcp-run.d.ts +23 -4
- package/dist/runner/mcp-run.js +31 -2
- package/dist/runner/metrics.d.ts +4 -0
- package/dist/runner/metrics.js +9 -3
- package/dist/runner/monid-run.js +3 -1
- package/dist/runner/native-loop.js +3 -4
- package/dist/runner/promotion.d.ts +19 -28
- package/dist/runner/promotion.js +50 -69
- package/dist/runner/redact.d.ts +3 -0
- package/dist/runner/redact.js +7 -0
- 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 +12 -68
- package/dist/runner/runner.d.ts +1 -1
- package/dist/runner/sdk-loop.js +7 -7
- package/dist/runner/workflow-calls.d.ts +4 -1
- package/dist/runner/workflow-calls.js +35 -18
- package/dist/runner/workflow-loop.d.ts +1 -1
- package/dist/runner/workflow-loop.js +3 -1
- package/dist/runner/workflow-spec.d.ts +4 -0
- package/dist/runner/workflow-spec.js +18 -13
- package/dist/runs-over-store.d.ts +2 -2
- package/dist/runs-over-store.js +1 -1
- 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/secret-cut.js +7 -4
- package/dist/secret-rules.js +97 -83
- 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 +22 -15
- package/dist/server.js +311 -198
- package/dist/slack.js +2 -1
- 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/migrate.js +3 -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 +23 -26
- package/dist/store-reads/learning.js +42 -30
- 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 +27 -3
- package/dist/tool-plane.js +79 -4
- package/dist/tools.d.ts +12 -2
- package/dist/tools.js +42 -7
- package/dist/trigger-launch-hook.d.ts +2 -2
- package/dist/trigger-launch-hook.js +1 -1
- package/dist/triggers.d.ts +7 -4
- package/dist/triggers.js +4 -4
- 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/sdk/check.js
CHANGED
|
@@ -25,14 +25,13 @@ function notBaseline(inbox, reported) {
|
|
|
25
25
|
* the check (sdkCheckTurn: kept until the check holds compile_after rows, the one that makes compile_after deciding on
|
|
26
26
|
* them all); any other turn is given back (releaseSdkCheck) and the check waits for the next turn; a turn the backend
|
|
27
27
|
* never completed before its inbox expired is one failed row (sdkCheckDeadline). Exact retries and reclaims compete on
|
|
28
|
-
* the reservation.
|
|
29
|
-
* readers serve (purged-workflow.ts refusedIn). */
|
|
28
|
+
* the reservation. */
|
|
30
29
|
export async function settleSdkCheck(deps) {
|
|
31
30
|
const { inbox } = deps;
|
|
32
31
|
const check = inbox.learning_check;
|
|
33
32
|
if (!check)
|
|
34
33
|
return;
|
|
35
|
-
const record = promotionOf(await promotionsOf(deps.store.
|
|
34
|
+
const record = promotionOf(await promotionsOf(deps.store.learning, deps.agentId), check.workflow.name, check.digest);
|
|
36
35
|
if (record?.decided !== "replaying" || record.via !== "sdk" || record.replay_id !== check.id || !record.check || record.commit !== check.revision || record.runs?.[0] !== inbox.run_id)
|
|
37
36
|
return;
|
|
38
37
|
const completion = inbox.completion;
|
package/dist/sdk/runs.d.ts
CHANGED
|
@@ -64,8 +64,10 @@ export type SdkInbox = {
|
|
|
64
64
|
}[];
|
|
65
65
|
/** Exact promoted executable workflows delivered by the start receipt. */
|
|
66
66
|
learning_workflows?: LearnedWorkflow[];
|
|
67
|
-
/** The
|
|
68
|
-
*
|
|
67
|
+
/** The runs whose text learning_workflows and learning_check's draft are, every file's writer (a README.md's as well
|
|
68
|
+
* as a workflow.json's): a receipt sent again after one of them is purged answers 410 purged (receipt). */
|
|
69
|
+
learning_writers?: string[];
|
|
70
|
+
/** Legacy: a server before learning rows wrote this (the save each workflow was read at) and no learning_writers. */
|
|
69
71
|
learning_commits?: Record<string, string>;
|
|
70
72
|
/** The learned workflow a learned_workflow start names, by its call's id as stored, where its input is stored withheld (a held
|
|
71
73
|
* value split across its arguments, withheldParts): the parent check of a callback nested in it reads its name here
|
|
@@ -86,6 +88,14 @@ export declare const sdkRunKey: (id: string) => string;
|
|
|
86
88
|
export declare const SDK_MAX_OPEN_MS = 86400000;
|
|
87
89
|
export declare const sdkOf: (body: unknown) => SdkBinding | undefined;
|
|
88
90
|
export declare function sdkInbox(store: Pick<Store, "settings">, runId: string): Promise<SdkInbox>;
|
|
91
|
+
/** What every SDK run's inbox holds of run `runId`'s text, gone (its purge; `agentId` the run's agent): an inbox whose
|
|
92
|
+
* workflows or check draft it wrote (`learning_writers` names it) keeps none of them, its writers kept, so its receipt
|
|
93
|
+
* answers 410 purged. An inbox that names no writers (unwritten) is emptied by the purge of any run of its own agent,
|
|
94
|
+
* since the run may be one of them, its learning_commits kept, so its receipt is refused still. A run of another agent
|
|
95
|
+
* never wrote that agent's learning, so its purge writes no row of such an inbox. Run after the run's purge committed,
|
|
96
|
+
* and a start checks its writers after its inbox is written (start), so one of the two always sees the other: no
|
|
97
|
+
* inbox keeps a purged run's workflow text. */
|
|
98
|
+
export declare function forgetSdkCopies(store: Pick<Store, "settings" | "runs">, agentId: string, runId: string): Promise<void>;
|
|
89
99
|
/** Completion and closure compete on the same inbox. A stale runner cannot close it, and a completion that won
|
|
90
100
|
* remains available to the next claim even if this one cannot read or journal it. No external SDK call is replayed.
|
|
91
101
|
* An expiry is checked against the row it replaces: an events batch that moved the deadline keeps the inbox open. */
|
|
@@ -137,12 +147,15 @@ export declare class SdkRuns {
|
|
|
137
147
|
workflows: LearnedWorkflow[];
|
|
138
148
|
};
|
|
139
149
|
}>;
|
|
140
|
-
/** The
|
|
141
|
-
* text
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
*
|
|
150
|
+
/** The workflows a start delivers, each the seed's or its champion's text read at its record's save, and the runs whose
|
|
151
|
+
* text each is (`writers`: every run that wrote one of its files there, its README.md's description as well as its
|
|
152
|
+
* workflow.json's text); the drafts a check may take, and the runs whose text each is (`drafts`, by name). A text and
|
|
153
|
+
* its writer are two reads, and a purge rewrites the saves they read in place: it adds a save of its own after the
|
|
154
|
+
* newest (Store.learning purgeRun), so a selection a purge save moved under is read again (a normal save rewrites
|
|
155
|
+
* nothing it read), and one that keeps moving refuses the start, to start again. Never the purged run's text named as
|
|
156
|
+
* no run's. */
|
|
145
157
|
private selectedWorkflows;
|
|
158
|
+
private selectedOnce;
|
|
146
159
|
private modify;
|
|
147
160
|
private writable;
|
|
148
161
|
events(runId: string, body: Record<string, unknown>): Promise<{
|
package/dist/sdk/runs.js
CHANGED
|
@@ -10,15 +10,15 @@ import { uuidv7 } from "../ids.js";
|
|
|
10
10
|
import { launchBody } from "../run-launch.js";
|
|
11
11
|
import { learningStartFor } from "../runs-over-store.js";
|
|
12
12
|
import { labelsIssues, labelsOf } from "../run-labels.js";
|
|
13
|
-
import { chooseWorkflows,
|
|
13
|
+
import { chooseWorkflows, inLearningQueue, seedAt, secretsShown } from "../learning.js";
|
|
14
14
|
import { INSTRUCTION_EVIDENCE_BYTES } from "../native/instructions.js";
|
|
15
15
|
import { CLI_POLICY_BYTES } from "../cli-learning/policy.js";
|
|
16
16
|
import { refuseWhileNoRunner } from "../runner/presence.js";
|
|
17
17
|
import { secretRedactor } from "../runner/redact.js";
|
|
18
18
|
import { redactedOutput, withheldWhole } from "../key-refusal.js";
|
|
19
19
|
import { decodedStrings, draftProblems } from "../learn/workflow-draft.js";
|
|
20
|
-
import {
|
|
21
|
-
import { purgedRun,
|
|
20
|
+
import { learningOf } from "../learn/rows.js";
|
|
21
|
+
import { purgedRun, purgedRows } from "../purged-workflow.js";
|
|
22
22
|
import { sdkWorkflowManifest, sdkDraftTools } from "./workflows.js";
|
|
23
23
|
import { promotionOf, promotionsOf, resetAtOf } from "../learn/promote.js";
|
|
24
24
|
import { championTextOf, releaseSdkCheck, reserveSdkCheck } from "../runner/promotion.js";
|
|
@@ -105,6 +105,36 @@ export async function sdkInbox(store, runId) {
|
|
|
105
105
|
throw new ApiError("not_found", "No backend SDK run with that id.");
|
|
106
106
|
return row;
|
|
107
107
|
}
|
|
108
|
+
/** An inbox a server before learning rows wrote: it holds learning and names no writers (a start now always names them,
|
|
109
|
+
* none too), so whether a purged run wrote its text can't be known. Its receipt is refused (receipt). */
|
|
110
|
+
const unwritten = (inbox) => inbox.learning_writers === undefined && (inbox.learning_commits !== undefined || !!inbox.learning_workflows?.length || !!inbox.learning_check);
|
|
111
|
+
/** What every SDK run's inbox holds of run `runId`'s text, gone (its purge; `agentId` the run's agent): an inbox whose
|
|
112
|
+
* workflows or check draft it wrote (`learning_writers` names it) keeps none of them, its writers kept, so its receipt
|
|
113
|
+
* answers 410 purged. An inbox that names no writers (unwritten) is emptied by the purge of any run of its own agent,
|
|
114
|
+
* since the run may be one of them, its learning_commits kept, so its receipt is refused still. A run of another agent
|
|
115
|
+
* never wrote that agent's learning, so its purge writes no row of such an inbox. Run after the run's purge committed,
|
|
116
|
+
* and a start checks its writers after its inbox is written (start), so one of the two always sees the other: no
|
|
117
|
+
* inbox keeps a purged run's workflow text. */
|
|
118
|
+
export async function forgetSdkCopies(store, agentId, runId) {
|
|
119
|
+
for (const row of await store.settings.all({ prefix: keyOf("") })) {
|
|
120
|
+
for (let value = row.value, retry = 0; retry < 20; retry++) {
|
|
121
|
+
if (!isObject(value))
|
|
122
|
+
break;
|
|
123
|
+
const inbox = value;
|
|
124
|
+
if (!inbox.learning_workflows?.length && !inbox.learning_check)
|
|
125
|
+
break;
|
|
126
|
+
const legacy = unwritten(inbox);
|
|
127
|
+
if (!legacy && !inbox.learning_writers?.includes(runId))
|
|
128
|
+
break;
|
|
129
|
+
if (legacy && (await store.runs.get(inbox.run_id))?.agentId !== agentId)
|
|
130
|
+
break;
|
|
131
|
+
const { learning_check: _check, ...rest } = inbox;
|
|
132
|
+
if (await store.settings.replaceIf(row.key, value, { ...rest, learning_workflows: [], ...(legacy ? { learning_commits: inbox.learning_commits ?? {} } : {}) }))
|
|
133
|
+
break;
|
|
134
|
+
value = await store.settings.get(row.key);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
108
138
|
/** Completion and closure compete on the same inbox. A stale runner cannot close it, and a completion that won
|
|
109
139
|
* remains available to the next claim even if this one cannot read or journal it. No external SDK call is replayed.
|
|
110
140
|
* An expiry is checked against the row it replaces: an events batch that moved the deadline keeps the inbox open. */
|
|
@@ -340,7 +370,7 @@ export class SdkRuns {
|
|
|
340
370
|
if (!cli)
|
|
341
371
|
await compile.check(learning.model);
|
|
342
372
|
if (learning.seedFailed)
|
|
343
|
-
throw new ApiError("unavailable", "The learning seed could not be read. Retry
|
|
373
|
+
throw new ApiError("unavailable", "The learning seed could not be read. Retry the start.");
|
|
344
374
|
}
|
|
345
375
|
const revision = entry.revision;
|
|
346
376
|
const admit = async () => {
|
|
@@ -349,17 +379,18 @@ export class SdkRuns {
|
|
|
349
379
|
const reset = learning ? await resetAtOf(this.store.settings, entry.agent.id) : undefined;
|
|
350
380
|
if (learning && reset !== undefined && !(learning.seededAt !== undefined && learning.seededAt > reset))
|
|
351
381
|
throw new ApiError("unavailable", "The agent's learning was reset while this run started: start it again.", { retry_after_ms: 1_000 });
|
|
352
|
-
const selected = learning && !learning.noWorkflows && workflow ? await this.selectedWorkflows(entry.agent.id, learning.seed, workflow) : { workflows: [],
|
|
382
|
+
const selected = learning && !learning.noWorkflows && workflow ? await this.selectedWorkflows(entry.agent.id, learning.seed, workflow) : { workflows: [], writers: new Map(), candidates: [], drafts: {} };
|
|
353
383
|
const cleaned = this.clean({ instructions, ...(model ? { model } : {}) });
|
|
354
384
|
const runId = uuidv7();
|
|
355
385
|
const redacted = cleanedInput !== input || cleaned.instructions !== instructions;
|
|
356
386
|
// A turn is a check only when it can be one's baseline: no protected value in its task or policy, and an input the
|
|
357
387
|
// draft takes (sdkTakes). A prose turn whose input the client cannot resolve is given back (releaseSdkCheck).
|
|
358
388
|
const takes = (flow) => !redacted && sdkTakes(flow, input, resolveSchemaForWorkflow);
|
|
359
|
-
const checkDeps = { store: this.store, agentId: entry.agent.id, log: () => { }, shown: async () => secretsShown(this.secrets(), { local: true })
|
|
389
|
+
const checkDeps = { store: this.store, agentId: entry.agent.id, log: () => { }, shown: async () => secretsShown(this.secrets(), { local: true }) };
|
|
360
390
|
const check = learning ? await reserveSdkCheck(checkDeps, { runId, revision: learning.seed, learning: revisionBody.learning, flows: selected.candidates, takes }) : undefined;
|
|
361
391
|
// A shadow check needs the original agent's own answer, not an answer produced by its existing champion.
|
|
362
392
|
const workflows = check ? [] : selected.workflows;
|
|
393
|
+
const writers = [...new Set([...workflows.flatMap((flow) => selected.writers.get(flow) ?? []), ...(check ? (selected.drafts[check.workflow.name] ?? []) : [])])];
|
|
363
394
|
const launch = {
|
|
364
395
|
input: { content: cleanedInput },
|
|
365
396
|
title: title === undefined ? cleanedInput.trim().replace(/\s+/g, " ").slice(0, 80) : this.clean({ title }).title,
|
|
@@ -381,11 +412,16 @@ export class SdkRuns {
|
|
|
381
412
|
expires_at: now + (cli ? SDK_MAX_OPEN_MS : SDK_OPEN_MS),
|
|
382
413
|
batches: [],
|
|
383
414
|
learning_workflows: workflows,
|
|
384
|
-
|
|
415
|
+
// Named whenever it holds learning, none too: an inbox without the key is an earlier server's (unwritten).
|
|
416
|
+
...(workflows.length || check ? { learning_writers: writers } : {}),
|
|
385
417
|
...(check ? { learning_check: check } : {}),
|
|
386
418
|
...(redacted ? { check_redacted: true } : {}),
|
|
387
419
|
...(cli && cleanedInput !== input ? { evidence_incomplete: true } : {}),
|
|
388
420
|
});
|
|
421
|
+
// A writer purged since the selection read it (the purge's own scrub of inboxes, forgetSdkCopies, runs after it
|
|
422
|
+
// commits, so it sees this inbox unless this read sees the purge): the start is refused, its inbox removed.
|
|
423
|
+
if (writers.length && (await purgedRows(this.store, writers)).size)
|
|
424
|
+
throw new ApiError("unavailable", "The agent's learning changed while this run started: start it again.", { retry_after_ms: 1_000 });
|
|
389
425
|
await this.store.runs.create({ id: runId, agentId: entry.agent.id, revisionId: revision.id, ...(cli ? { expectedCurrent, settingsGuards: sourceGuards } : {}), ...(origin ? { origin } : {}), ...(labels ? { labels } : {}), ...(startedAt !== undefined ? { startedAt } : {}) }, { body: launchBody(launch) });
|
|
390
426
|
}
|
|
391
427
|
catch (error) {
|
|
@@ -393,7 +429,7 @@ export class SdkRuns {
|
|
|
393
429
|
// The reservation comes first because the launch it is created with withholds the champion from a check's turn.
|
|
394
430
|
// No turn ran, so the check waits for the next one, the release uncounted: never a hold of a draft never compared.
|
|
395
431
|
if (check) {
|
|
396
|
-
const record = promotionOf(await promotionsOf(this.store.
|
|
432
|
+
const record = promotionOf(await promotionsOf(this.store.learning, entry.agent.id).catch(() => []), check.workflow.name, check.digest);
|
|
397
433
|
if (record?.decided === "replaying" && record.replay_id === check.id)
|
|
398
434
|
await releaseSdkCheck(checkDeps, record, "its start could not be admitted", false).catch(() => undefined);
|
|
399
435
|
}
|
|
@@ -411,11 +447,11 @@ export class SdkRuns {
|
|
|
411
447
|
}
|
|
412
448
|
return runId;
|
|
413
449
|
};
|
|
414
|
-
// A learning start is admitted in its agent's learning queue (learning.ts
|
|
450
|
+
// A learning start is admitted in its agent's learning queue (learning.ts inLearningQueue), the one a reset of the
|
|
415
451
|
// agent's learning deletes it in: either the reset comes first, and the seed read before it is refused above, or this
|
|
416
452
|
// run's row is made first, and the reset refuses while it goes (409 learning_busy). No check of a draft the reset
|
|
417
453
|
// deleted is reserved, and no run starts on it.
|
|
418
|
-
const runId = learning ? await
|
|
454
|
+
const runId = learning ? await inLearningQueue(this.data, entry.agent.id, admit) : await admit();
|
|
419
455
|
return this.receipt(runId, consoleOrigin);
|
|
420
456
|
}
|
|
421
457
|
async receipt(runId, consoleOrigin) {
|
|
@@ -425,13 +461,10 @@ export class SdkRuns {
|
|
|
425
461
|
const launch = (await this.store.runs.launch(runId)).body;
|
|
426
462
|
const inbox = await sdkInbox(this.store, runId);
|
|
427
463
|
const workflows = inbox.learning_workflows ?? [];
|
|
464
|
+
if (unwritten(inbox))
|
|
465
|
+
throw new ApiError("not_continuable", "This SDK start was pinned before a server upgrade, so the runs that wrote its learning can't be checked. Start a new run with a new Idempotency-Key.");
|
|
428
466
|
// A start sent again answers the receipt it pinned, never a workflow a purged run wrote: 410 purged, as its file read.
|
|
429
|
-
|
|
430
|
-
const seed = launch.learning?.seed ?? null;
|
|
431
|
-
const purged = seed === null ? undefined : await this.purgedPinned(run.agentId, [
|
|
432
|
-
...workflows.map((flow) => [flow, inbox.learning_commits?.[flow.name] ?? seed]),
|
|
433
|
-
...(inbox.learning_check ? [[inbox.learning_check.workflow, seed]] : []),
|
|
434
|
-
]);
|
|
467
|
+
const purged = [...(await purgedRows(this.store, inbox.learning_writers ?? [])).values()][0];
|
|
435
468
|
if (purged)
|
|
436
469
|
throw purgedRun(purged);
|
|
437
470
|
const shown = secretsShown(this.secrets(), { local: true });
|
|
@@ -455,62 +488,66 @@ export class SdkRuns {
|
|
|
455
488
|
},
|
|
456
489
|
};
|
|
457
490
|
}
|
|
458
|
-
/** The
|
|
459
|
-
* text
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
return undefined;
|
|
473
|
-
}
|
|
474
|
-
finally {
|
|
475
|
-
await folder.end();
|
|
491
|
+
/** The workflows a start delivers, each the seed's or its champion's text read at its record's save, and the runs whose
|
|
492
|
+
* text each is (`writers`: every run that wrote one of its files there, its README.md's description as well as its
|
|
493
|
+
* workflow.json's text); the drafts a check may take, and the runs whose text each is (`drafts`, by name). A text and
|
|
494
|
+
* its writer are two reads, and a purge rewrites the saves they read in place: it adds a save of its own after the
|
|
495
|
+
* newest (Store.learning purgeRun), so a selection a purge save moved under is read again (a normal save rewrites
|
|
496
|
+
* nothing it read), and one that keeps moving refuses the start, to start again. Never the purged run's text named as
|
|
497
|
+
* no run's. */
|
|
498
|
+
async selectedWorkflows(agentId, revision, binding) {
|
|
499
|
+
const newest = () => this.store.learning.newestPurge(agentId);
|
|
500
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
501
|
+
const before = await newest();
|
|
502
|
+
const selected = await this.selectedOnce(agentId, revision, binding);
|
|
503
|
+
if ((await newest()) === before)
|
|
504
|
+
return selected;
|
|
476
505
|
}
|
|
506
|
+
throw new ApiError("unavailable", "The agent's learning changed while this run started: start it again.", { retry_after_ms: 1_000 });
|
|
477
507
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
const
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
const
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
+
async selectedOnce(agentId, revision, binding) {
|
|
509
|
+
const learning = learningOf(this.store, agentId);
|
|
510
|
+
const reads = new Map();
|
|
511
|
+
const readSave = (save) => reads.get(save) ?? reads.set(save, this.store.learning.itemsAt(agentId, save)).get(save);
|
|
512
|
+
// Every run whose file of workflow `name` save `save` holds: its README.md's (the description delivered) as well as
|
|
513
|
+
// its workflow.json's (the item's run), and any other file's, so a purge of any of them refuses the receipt.
|
|
514
|
+
const writersAt = async (name, save) => {
|
|
515
|
+
const item = save === null ? undefined : (await readSave(save))?.items.find((one) => one.kind === "workflow" && one.name === name);
|
|
516
|
+
if (!item)
|
|
517
|
+
return [];
|
|
518
|
+
return [...new Set([item.byRun, ...Object.values(item.writers ?? {})].filter((run) => typeof run === "string"))];
|
|
519
|
+
};
|
|
520
|
+
const seed = await seedAt(learning, revision);
|
|
521
|
+
const { flows } = chooseWorkflows(seed, secretsShown(this.secrets(), { local: true }));
|
|
522
|
+
const dsl = await import("@parcha/agentrun-dsl");
|
|
523
|
+
const { tools, gated, deniedBy } = sdkDraftTools(binding.workflow_tools);
|
|
524
|
+
const records = await promotionsOf(this.store.learning, agentId);
|
|
525
|
+
let room = 256 * 1024;
|
|
526
|
+
const compatible = (flow) => {
|
|
527
|
+
const bytes = Buffer.byteLength(JSON.stringify(flow));
|
|
528
|
+
if (bytes > room || draftProblems(dsl, flow.workflow, tools, gated, deniedBy, undefined, binding.workflow_adapters).length)
|
|
529
|
+
return false;
|
|
530
|
+
room -= bytes;
|
|
531
|
+
return true;
|
|
532
|
+
};
|
|
533
|
+
const workflows = [], candidates = [], writers = new Map(), drafts = {};
|
|
534
|
+
const atSave = async (name, save) => chooseWorkflows(await seedAt(learning, save), secretsShown(this.secrets(), { local: true })).flows.find((one) => one.name === name);
|
|
535
|
+
for (const flow of flows) {
|
|
536
|
+
const { text: serving, champion } = await championTextOf(records, flow, atSave);
|
|
537
|
+
if (serving && compatible(serving)) {
|
|
538
|
+
workflows.push(serving);
|
|
539
|
+
const runs = await writersAt(serving.name, serving === flow ? seed.sha : champion.commit ?? null);
|
|
540
|
+
if (runs.length)
|
|
541
|
+
writers.set(serving, runs);
|
|
542
|
+
}
|
|
543
|
+
if ((!serving || workflowDigest(serving) !== workflowDigest(flow)) && compatible(flow)) {
|
|
544
|
+
candidates.push(flow);
|
|
545
|
+
const runs = await writersAt(flow.name, seed.sha);
|
|
546
|
+
if (runs.length)
|
|
547
|
+
drafts[flow.name] = runs;
|
|
508
548
|
}
|
|
509
|
-
return { workflows, commits, candidates };
|
|
510
|
-
}
|
|
511
|
-
finally {
|
|
512
|
-
await folder.end();
|
|
513
549
|
}
|
|
550
|
+
return { workflows, writers, candidates, drafts };
|
|
514
551
|
}
|
|
515
552
|
async modify(runId, change, limit = TOTAL_LIMIT) {
|
|
516
553
|
for (let retry = 0; retry < 20; retry++) {
|
package/dist/secret-cut.js
CHANGED
|
@@ -10,6 +10,7 @@ secretLintProfiler.setEnabled(false);
|
|
|
10
10
|
import { keyShaped } from "./secret-name.js";
|
|
11
11
|
import { secretValues } from "./api-token.js";
|
|
12
12
|
import { MIN_SECRET, valueMatcher } from "./learn/secrets.js";
|
|
13
|
+
import { SEPARATOR } from "./redact/match.js";
|
|
13
14
|
import { userInfo } from "node:os";
|
|
14
15
|
import { commandReadPath, decodedTimes, inputSpan, isPlaceholder, KEY_RUN_MAX, lineBounds, lineCount, RESTORABLE, SCRUB_RULES, shapeOf, viewsOf } from "./secret-rules.js";
|
|
15
16
|
export { isPlaceholder, RESTORABLE, RULE_PATTERNS, SCRUB_RULES, viewsOf } from "./secret-rules.js";
|
|
@@ -378,7 +379,9 @@ function contextOf(view, opts) {
|
|
|
378
379
|
/** Whether a cut text holds nothing the scrub must cut: no known format the format rules still find in any view of any
|
|
379
380
|
* chunk of it (each marker read as a blank, so a marker is never one), and no held value in any form (valueMatcher:
|
|
380
381
|
* split by whitespace, partly encoded) in the text as written or in any decoding of it, each marker read as a
|
|
381
|
-
* character no form holds
|
|
382
|
+
* character no form holds and every view keeps (SEPARATOR, read with valueMatcher's `separated`: a NUL would not do,
|
|
383
|
+
* as the views drop control characters). A U+FFFF the text brought is read as a NUL first, nothing to the views, so
|
|
384
|
+
* only a marker separates. The time budget holds here too (a throw). */
|
|
382
385
|
async function clean(rules, out, opts, run) {
|
|
383
386
|
const blanked = out.replace(MARKER, (found) => " ".repeat(found.length));
|
|
384
387
|
const formats = rules.filter((rule) => rule.kind === "format");
|
|
@@ -395,9 +398,9 @@ async function clean(rules, out, opts, run) {
|
|
|
395
398
|
const held = heldOf(opts);
|
|
396
399
|
if (!held.length)
|
|
397
400
|
return true;
|
|
398
|
-
const matches = valueMatcher(held);
|
|
399
|
-
for (const view of viewsOf(out
|
|
400
|
-
if (matches(view.source))
|
|
401
|
+
const matches = valueMatcher(held, { separated: true });
|
|
402
|
+
for (const view of viewsOf(out)) {
|
|
403
|
+
if (matches(view.source.replaceAll(SEPARATOR, "\u0000").replace(MARKER, SEPARATOR)))
|
|
401
404
|
return false;
|
|
402
405
|
inTime(run);
|
|
403
406
|
}
|