@parcha/agentrun-serve 0.1.0-beta.49 → 0.1.0-beta.51
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 +173 -9
- package/README.md +246 -39
- package/dist/agent-delete.d.ts +3 -2
- package/dist/agent-delete.js +29 -4
- package/dist/agents-store.js +7 -3
- package/dist/api-only.d.ts +8 -10
- package/dist/api-only.js +11 -12
- package/dist/capacity.d.ts +50 -0
- package/dist/capacity.js +49 -0
- package/dist/cli-learning/claude-wire.d.ts +41 -0
- package/dist/cli-learning/claude-wire.js +258 -0
- package/dist/cli-learning/cli.d.ts +11 -0
- package/dist/cli-learning/cli.js +241 -0
- package/dist/cli-learning/codex-worktree.d.ts +10 -0
- package/dist/cli-learning/codex-worktree.js +119 -0
- package/dist/cli-learning/connections.d.ts +62 -0
- package/dist/cli-learning/connections.js +87 -0
- package/dist/cli-learning/entry.d.ts +1 -0
- package/dist/cli-learning/entry.js +4 -0
- package/dist/cli-learning/evidence.d.ts +78 -0
- package/dist/cli-learning/evidence.js +492 -0
- package/dist/cli-learning/hook.d.ts +33 -0
- package/dist/cli-learning/hook.js +544 -0
- package/dist/cli-learning/install.d.ts +33 -0
- package/dist/cli-learning/install.js +335 -0
- package/dist/cli-learning/observation-proof.d.ts +14 -0
- package/dist/cli-learning/observation-proof.js +10 -0
- package/dist/cli-learning/policy.d.ts +48 -0
- package/dist/cli-learning/policy.js +363 -0
- package/dist/cli-learning/schema.d.ts +16 -0
- package/dist/cli-learning/schema.js +27 -0
- package/dist/cli-learning/state.d.ts +23 -0
- package/dist/cli-learning/state.js +61 -0
- package/dist/cli.js +24 -2
- package/dist/compute-cost.d.ts +101 -0
- package/dist/compute-cost.js +250 -0
- package/dist/console/assets/index-Bt1B51b7.js +733 -0
- package/dist/console/assets/index-sVftE9Ht.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/email/email-faux.d.ts +3 -1
- package/dist/email/email-faux.js +3 -2
- package/dist/email/routes.js +22 -12
- package/dist/eval-previous.d.ts +52 -0
- package/dist/eval-previous.js +164 -0
- package/dist/file-types.d.ts +2 -0
- package/dist/file-types.js +3 -1
- package/dist/harness-install.d.ts +6 -2
- package/dist/harness-install.js +40 -8
- package/dist/harness.d.ts +1 -1
- package/dist/harness.js +3 -2
- package/dist/learn/check.d.ts +8 -5
- package/dist/learn/check.js +25 -24
- package/dist/learn/repick.d.ts +22 -13
- package/dist/learn/repick.js +57 -56
- package/dist/learn/secrets.js +14 -3
- package/dist/learn/workflow-draft.d.ts +4 -0
- package/dist/learn/workflow-draft.js +10 -7
- package/dist/learned-workflow.js +8 -8
- package/dist/learning-setting.js +2 -2
- package/dist/learning-words.d.ts +1 -1
- package/dist/learning-words.js +1 -1
- package/dist/mcp-pin-first.js +2 -1
- package/dist/mcp-private-hosts.d.ts +24 -3
- package/dist/mcp-private-hosts.js +53 -3
- package/dist/model-gateway.d.ts +2 -0
- package/dist/model-gateway.js +3 -1
- package/dist/native/runtimes.d.ts +2 -0
- package/dist/native/runtimes.js +2 -0
- package/dist/observation/learning.d.ts +32 -0
- package/dist/observation/learning.js +66 -0
- package/dist/observation/observer.d.ts +8 -1
- package/dist/observation/observer.js +89 -9
- package/dist/observation/schema.js +12 -4
- package/dist/observation/usage-identity.d.ts +9 -0
- package/dist/observation/usage-identity.js +11 -0
- package/dist/openapi.js +113 -29
- package/dist/paid-calls.d.ts +13 -6
- package/dist/paid-calls.js +14 -8
- package/dist/run-launch.d.ts +16 -2
- package/dist/run-launch.js +6 -1
- package/dist/run-timeline-served.js +5 -3
- package/dist/run-usage.d.ts +23 -8
- package/dist/run-usage.js +100 -18
- package/dist/run-view.d.ts +2 -0
- package/dist/run-view.js +12 -7
- package/dist/runner/adapter-loop.d.ts +4 -0
- package/dist/runner/adapter-loop.js +44 -27
- package/dist/runner/adapter-run-spec.d.ts +8 -3
- package/dist/runner/adapter-run-spec.js +15 -8
- package/dist/runner/beside.d.ts +13 -0
- package/dist/runner/beside.js +27 -8
- package/dist/runner/big-writes.d.ts +33 -0
- package/dist/runner/big-writes.js +105 -0
- package/dist/runner/cli-run-spec.js +16 -8
- package/dist/runner/disk-free.d.ts +44 -0
- package/dist/runner/disk-free.js +96 -0
- package/dist/runner/feedback-round.d.ts +12 -8
- package/dist/runner/feedback-round.js +16 -30
- package/dist/runner/harness-loops.js +3 -1
- package/dist/runner/held.d.ts +4 -1
- package/dist/runner/journal-kinds.d.ts +1 -1
- package/dist/runner/learning-end.js +13 -4
- package/dist/runner/main.d.ts +17 -6
- package/dist/runner/main.js +187 -45
- package/dist/runner/metrics.d.ts +4 -0
- package/dist/runner/metrics.js +9 -0
- package/dist/runner/presence.d.ts +11 -2
- package/dist/runner/presence.js +31 -3
- package/dist/runner/run-child-host.d.ts +27 -17
- package/dist/runner/run-child-host.js +70 -116
- package/dist/runner/run-child.js +3 -0
- package/dist/runner/run-errors.js +2 -0
- package/dist/runner/runner-check.d.ts +51 -0
- package/dist/runner/runner-check.js +206 -0
- package/dist/runner/runner-metrics.d.ts +19 -0
- package/dist/runner/runner-metrics.js +49 -0
- package/dist/runner/runner.d.ts +37 -0
- package/dist/runner/runner.js +43 -3
- package/dist/runner/save-slots.d.ts +9 -0
- package/dist/runner/save-slots.js +91 -0
- package/dist/runner/sdk-loop.js +34 -22
- package/dist/runs-over-store.d.ts +8 -1
- package/dist/runs-over-store.js +57 -9
- package/dist/sdk/runs.d.ts +25 -6
- package/dist/sdk/runs.js +107 -35
- package/dist/sdk/runtimes.d.ts +19 -0
- package/dist/sdk/runtimes.js +23 -0
- package/dist/sdk/schema.d.ts +14 -8
- package/dist/sdk/schema.js +18 -6
- package/dist/server.d.ts +7 -0
- package/dist/server.js +151 -28
- package/dist/skills/agentrun-serve/SKILL.md +52 -7
- package/dist/start-switches.js +2 -0
- package/dist/stats.d.ts +4 -0
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.d.ts +13 -2
- package/dist/store/agent-body.js +19 -4
- package/dist/store/dialect.d.ts +2 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/postgres/connection.d.ts +5 -2
- package/dist/store/postgres/connection.js +19 -7
- package/dist/store/postgres/dialect.js +1 -0
- package/dist/store/postgres/migrate.d.ts +30 -0
- package/dist/store/postgres/migrate.js +72 -5
- package/dist/store/postgres/migration-lint.d.ts +8 -0
- package/dist/store/postgres/migration-lint.js +119 -0
- package/dist/store/postgres/migrations/0023_computer_interval_resources.sql +14 -0
- package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
- package/dist/store/postgres/store.d.ts +8 -3
- package/dist/store/postgres/store.js +31 -11
- package/dist/store/schema.d.ts +26 -4
- package/dist/store/schema.js +45 -4
- package/dist/store/sqlite/connection.d.ts +3 -3
- package/dist/store/sqlite/connection.js +3 -3
- package/dist/store/sqlite/run-launch.d.ts +9 -1
- package/dist/store/sqlite/run-launch.js +44 -0
- package/dist/store/sqlite/store.d.ts +19 -4
- package/dist/store/sqlite/store.js +180 -93
- package/dist/store/store-schema.d.ts +34 -0
- package/dist/store/store-schema.js +125 -0
- package/dist/store/store.d.ts +61 -2
- package/dist/store/store.js +13 -0
- package/dist/store-reads/analytics.d.ts +3 -2
- package/dist/store-reads/analytics.js +20 -8
- package/dist/store-reads/cap.d.ts +9 -5
- package/dist/store-reads/cap.js +28 -2
- package/dist/store-reads/decisions.d.ts +21 -0
- package/dist/store-reads/decisions.js +22 -0
- package/dist/store-reads/journal.d.ts +8 -2
- package/dist/store-reads/journal.js +27 -8
- package/dist/store-view.d.ts +9 -4
- package/dist/store-view.js +48 -25
- package/dist/template-eval.d.ts +15 -1
- package/dist/template-eval.js +92 -13
- package/dist/templates.d.ts +4 -3
- package/dist/templates.js +4 -3
- package/dist/timeline/labels.js +17 -0
- package/dist/tool-gate.d.ts +4 -2
- package/dist/tool-list.js +1 -0
- package/dist/tools.d.ts +6 -2
- package/dist/tools.js +13 -1
- package/dist/trigger-targets.d.ts +21 -5
- package/dist/trigger-targets.js +13 -10
- package/dist/unified-usage.d.ts +24 -0
- package/dist/unified-usage.js +400 -0
- package/dist/uploads-archil.d.ts +100 -0
- package/dist/uploads-archil.js +430 -0
- package/dist/uploads.d.ts +55 -1
- package/dist/uploads.js +185 -98
- package/dist/validate.js +1 -1
- package/dist/web-fake.d.ts +25 -0
- package/dist/web-fake.js +38 -1
- package/dist/web-save.d.ts +75 -0
- package/dist/web-save.js +235 -0
- package/dist/workspace/archil-claim.d.ts +5 -2
- package/dist/workspace/archil-claim.js +5 -2
- package/dist/workspace/archil-disk.d.ts +11 -1
- package/dist/workspace/archil-disk.js +43 -10
- package/dist/workspace/archil.d.ts +3 -0
- package/dist/workspace/archil.js +102 -16
- package/dist/workspace/computer-for-claim.d.ts +14 -0
- package/dist/workspace/computer-for-claim.js +46 -7
- package/dist/workspace/computer-intervals.d.ts +9 -3
- package/dist/workspace/computer-intervals.js +17 -8
- package/dist/workspace/pieced.d.ts +14 -0
- package/dist/workspace/pieced.js +23 -0
- package/dist/workspace/run-disk.js +32 -12
- package/dist/workspace/run-workspace.d.ts +1 -1
- package/dist/workspace/run-workspace.js +11 -6
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +52 -7
- package/templates/README.md +36 -7
- package/dist/console/assets/index-Bzn4eUYF.js +0 -715
- package/dist/console/assets/index-CR2ZGei1.css +0 -1
package/dist/runner/sdk-loop.js
CHANGED
|
@@ -7,7 +7,7 @@ import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
|
7
7
|
import { freeModelRequestsOf } from "@parcha/agentrun-kernel/kernel/cap";
|
|
8
8
|
import { learningFolderOf, secretsShown } from "../learning.js";
|
|
9
9
|
import { said, STOPPED } from "../learning-words.js";
|
|
10
|
-
import { closeSdkInbox, sdkInbox } from "../sdk/runs.js";
|
|
10
|
+
import { cliPolicyOf, closeSdkInbox, sdkInbox } from "../sdk/runs.js";
|
|
11
11
|
import { settleSdkCheck } from "../sdk/check.js";
|
|
12
12
|
import { runPathOverStore } from "../store-reads/learning.js";
|
|
13
13
|
import { capSpendOf, learningEndOfRun } from "./learning-end.js";
|
|
@@ -20,15 +20,17 @@ import { stopEnd } from "./loop-contract.js";
|
|
|
20
20
|
import { END_PATCH_MS, END_PATCH_UNKNOWN } from "./loop.js";
|
|
21
21
|
import { storeSecrets } from "./store-secrets.js";
|
|
22
22
|
import { pathMetrics } from "./workflow-first.js";
|
|
23
|
-
const ROOT = ROOT_CONVERSATION_ID
|
|
23
|
+
const ROOT = ROOT_CONVERSATION_ID;
|
|
24
24
|
export function createSdkLoop(launch, host, route) {
|
|
25
|
+
const execution = launch.cli_learning ?? launch.sdk;
|
|
26
|
+
const MARK = launch.cli_learning ? "agentrun.cli" : "agentrun.sdk";
|
|
25
27
|
return (deps) => {
|
|
26
28
|
let stopped;
|
|
27
29
|
const abort = new AbortController(), signal = AbortSignal.any([deps.signal, abort.signal]);
|
|
28
30
|
let settled;
|
|
29
31
|
return {
|
|
30
32
|
command: async () => ({
|
|
31
|
-
refused: "This run is owned by your backend SDK. Start a fresh SDK call for another task.",
|
|
33
|
+
refused: launch.cli_learning ? "This run belongs to your coding CLI. Continue in the original session." : "This run is owned by your backend SDK. Start a fresh SDK call for another task.",
|
|
32
34
|
}),
|
|
33
35
|
stop: async (reason) => {
|
|
34
36
|
stopped = reason;
|
|
@@ -143,8 +145,8 @@ export function createSdkLoop(launch, host, route) {
|
|
|
143
145
|
{
|
|
144
146
|
kind: `${MARK}.started`,
|
|
145
147
|
data: {
|
|
146
|
-
runtime:
|
|
147
|
-
model:
|
|
148
|
+
runtime: execution.runtime,
|
|
149
|
+
model: execution.model ?? null,
|
|
148
150
|
learning_revision: launch.learning?.seed ?? null,
|
|
149
151
|
},
|
|
150
152
|
},
|
|
@@ -177,6 +179,8 @@ export function createSdkLoop(launch, host, route) {
|
|
|
177
179
|
for (const event of batch.events) {
|
|
178
180
|
if (event.type === "text")
|
|
179
181
|
partial = (partial + event.text).slice(-16_000);
|
|
182
|
+
else if (event.type === "message")
|
|
183
|
+
entries.push({ kind: KINDS.message, data: { role: event.role === "user" ? "person" : "model", text: event.text, at: Date.now() } });
|
|
180
184
|
else if (event.type === "session")
|
|
181
185
|
entries.push({ kind: `${MARK}.session`, data: { session_id: event.session_id } });
|
|
182
186
|
else if (event.type === "workflow_check")
|
|
@@ -216,14 +220,18 @@ export function createSdkLoop(launch, host, route) {
|
|
|
216
220
|
if (inbox.completion)
|
|
217
221
|
break;
|
|
218
222
|
if (inbox.closed)
|
|
219
|
-
throw new Error(
|
|
220
|
-
?
|
|
221
|
-
|
|
223
|
+
throw new Error(launch.cli_learning
|
|
224
|
+
? inbox.closed === "expired"
|
|
225
|
+
? "The coding CLI did not report completion within 24 hours; execution outcome is unknown. No source prompt was replayed."
|
|
226
|
+
: "This CLI prompt window closed before completion was recorded; execution outcome is unknown. No source prompt was replayed."
|
|
227
|
+
: inbox.closed === "expired"
|
|
228
|
+
? "The backend did not complete this SDK run before its deadline; execution outcome is unknown. No SDK request was replayed."
|
|
229
|
+
: "This SDK run closed before its completion was recorded; execution outcome is unknown. No SDK request was replayed.");
|
|
222
230
|
await delay(100, undefined, { signal });
|
|
223
231
|
}
|
|
224
|
-
const result = inbox.completion;
|
|
232
|
+
const result = launch.cli_learning && inbox.evidence_incomplete ? { ...inbox.completion, evidence_complete: false } : inbox.completion;
|
|
225
233
|
// Reported usage still counts, but a known partial trace cannot prove which execution path it took.
|
|
226
|
-
const completeEvidence = result.evidence_complete !== false;
|
|
234
|
+
const completeEvidence = launch.cli_learning ? result.evidence_complete === true : result.evidence_complete !== false;
|
|
227
235
|
const usage = result.usage;
|
|
228
236
|
const tools = {};
|
|
229
237
|
for (const event of inbox.batches.flatMap((batch) => batch.events)) {
|
|
@@ -242,9 +250,8 @@ export function createSdkLoop(launch, host, route) {
|
|
|
242
250
|
cacheWrite: usage?.cache_write_tokens ?? null,
|
|
243
251
|
requests: null,
|
|
244
252
|
unmetered: null,
|
|
245
|
-
model: result.model ??
|
|
246
|
-
|
|
247
|
-
sdk_session_id: result.session_id ?? null,
|
|
253
|
+
model: result.model ?? execution.model ?? null,
|
|
254
|
+
...(launch.cli_learning ? { cli_runtime: execution.runtime, cli_session_id: result.session_id ?? launch.cli_learning.session_id } : { sdk_runtime: execution.runtime, sdk_session_id: result.session_id ?? null }),
|
|
248
255
|
models: {},
|
|
249
256
|
tools,
|
|
250
257
|
};
|
|
@@ -254,7 +261,7 @@ export function createSdkLoop(launch, host, route) {
|
|
|
254
261
|
{ kind: KINDS.message, data: { role: "model", text: redacted(result.answer), at: Date.now() } },
|
|
255
262
|
{
|
|
256
263
|
kind: "runner.request",
|
|
257
|
-
data: { turn: 1, model: result.model ??
|
|
264
|
+
data: { turn: 1, model: result.model ?? execution.model ?? execution.runtime, aggregate: true },
|
|
258
265
|
},
|
|
259
266
|
{
|
|
260
267
|
kind: "runner.turn",
|
|
@@ -282,11 +289,12 @@ export function createSdkLoop(launch, host, route) {
|
|
|
282
289
|
});
|
|
283
290
|
if (end) {
|
|
284
291
|
const evidence = JSON.stringify({
|
|
285
|
-
application_instructions: launch.
|
|
292
|
+
application_instructions: cliPolicyOf(launch, result)?.instructions ?? execution.instructions,
|
|
286
293
|
supplied_workflows: inbox.learning_workflows ?? [],
|
|
287
|
-
workflow_tools: launch.sdk
|
|
288
|
-
workflow_adapters: launch.sdk
|
|
294
|
+
workflow_tools: launch.sdk?.workflow_tools ?? [],
|
|
295
|
+
workflow_adapters: launch.sdk?.workflow_adapters ?? [],
|
|
289
296
|
user_input: launch.input.content,
|
|
297
|
+
...(launch.cli_learning ? { dialogue: inbox.batches.flatMap(batch => batch.events.filter(event => event.type === "message")), source_session_id: launch.cli_learning.session_id, source_turn_id: launch.cli_learning.turn_id, seed_observed: result.seed_observed === true } : {}),
|
|
290
298
|
tool_events: inbox.batches.flatMap((batch) => batch.events.filter((event) => event.type === "tool")),
|
|
291
299
|
final_answer: result.answer,
|
|
292
300
|
});
|
|
@@ -299,11 +307,15 @@ export function createSdkLoop(launch, host, route) {
|
|
|
299
307
|
// A compile-only round has no plain look-back request. Its first ask keeps the same task figures.
|
|
300
308
|
keptOf: round => keptOf(previous, reflectRequestId(claim.runId, false, round), true),
|
|
301
309
|
ask: async (prompt, opts) => {
|
|
302
|
-
|
|
310
|
+
// Capture-only CLI connections have no executable workflow bridge. Their source prompts
|
|
311
|
+
// never receive an extra compile request; they only read the owner's pinned corrections.
|
|
312
|
+
if (launch.cli_learning)
|
|
313
|
+
return { failed: { code: "cli_workflows_unavailable", message: "CLI capture does not provide a workflow execution bridge." } };
|
|
314
|
+
if (!completeEvidence)
|
|
303
315
|
return {
|
|
304
316
|
failed: {
|
|
305
317
|
code: "sdk_evidence_incomplete",
|
|
306
|
-
message: "The backend reported incomplete run evidence; no learning was inferred from a partial trace.",
|
|
318
|
+
message: launch.cli_learning ? "The coding CLI reported incomplete evidence; no learning was inferred from a partial trace." : "The backend reported incomplete run evidence; no learning was inferred from a partial trace.",
|
|
307
319
|
},
|
|
308
320
|
};
|
|
309
321
|
if (evidence.length > 384_000)
|
|
@@ -417,20 +429,20 @@ export function createSdkLoop(launch, host, route) {
|
|
|
417
429
|
kind: KINDS.end,
|
|
418
430
|
data: {
|
|
419
431
|
state: cancelled ? "stopped" : "failed",
|
|
420
|
-
error: result.error ?? "The backend SDK run did not complete.",
|
|
432
|
+
error: result.error ?? (launch.cli_learning ? "The source CLI prompt did not complete." : "The backend SDK run did not complete."),
|
|
421
433
|
},
|
|
422
434
|
},
|
|
423
435
|
], {
|
|
424
436
|
state: cancelled ? "stopped" : "failed",
|
|
425
437
|
outcome: cancelled ? "cancelled" : null,
|
|
426
|
-
summary: result.error ?? "The backend SDK run did not complete.",
|
|
438
|
+
summary: result.error ?? (launch.cli_learning ? "The source CLI prompt did not complete." : "The backend SDK run did not complete."),
|
|
427
439
|
...patch,
|
|
428
440
|
}, also);
|
|
429
441
|
return cancelled
|
|
430
442
|
? { state: "stopped" }
|
|
431
443
|
: {
|
|
432
444
|
state: "failed",
|
|
433
|
-
error: { code: "sdk_failed", message: result.error ?? "Backend SDK run failed." },
|
|
445
|
+
error: { code: launch.cli_learning ? "cli_failed" : "sdk_failed", message: result.error ?? (launch.cli_learning ? "Source CLI prompt failed." : "Backend SDK run failed.") },
|
|
434
446
|
};
|
|
435
447
|
}
|
|
436
448
|
catch (error) {
|
|
@@ -140,6 +140,13 @@ export interface StartDeps {
|
|
|
140
140
|
readonly files?: {
|
|
141
141
|
hold(runId: string, ids: readonly string[]): Promise<void>;
|
|
142
142
|
release(runId: string): Promise<void>;
|
|
143
|
+
/** In Mode 2, the run's files copied into its folder before its row is written (uploads-archil.ts placeRunFiles):
|
|
144
|
+
* its launch, saying so and naming its disk, and how to undo it when the row is not written. Undefined in Mode 1:
|
|
145
|
+
* the files are held (hold) for the claim to copy. */
|
|
146
|
+
place?(runId: string, agentId: string, launch: RunLaunch): Promise<{
|
|
147
|
+
readonly launch: RunLaunch;
|
|
148
|
+
undo(): Promise<void>;
|
|
149
|
+
} | undefined>;
|
|
143
150
|
};
|
|
144
151
|
/** Where a revision naming these tools and no place runs here (server.ts fallbackPlace). */
|
|
145
152
|
fallbackPlace(kind: "agentic" | "workflow", tools: readonly unknown[]): Place;
|
|
@@ -239,7 +246,7 @@ export interface InlineAgent {
|
|
|
239
246
|
* agent already mapped to the reference is the run's (its id, its learning), so a run of a later version learns from the
|
|
240
247
|
* earlier ones. A different definition under a version already run is 409 external_body_conflict, nothing written; under
|
|
241
248
|
* `origin`, a key that already started a run gets that run, as startRun's. */
|
|
242
|
-
export declare function startInline(store: Pick<Store, "runs" | "runOfOrigin" | "agents">, deps: StartDeps, inline: InlineAgent, body: Json,
|
|
249
|
+
export declare function startInline(store: Pick<Store, "runs" | "runOfOrigin" | "agents">, deps: StartDeps, inline: InlineAgent, body: Json, options?: Pick<StartOptions, "origin" | "sealed">): Promise<RunRow>;
|
|
243
250
|
/** A run's launch from its create body, with every check the old start made before a run started, in the same order and
|
|
244
251
|
* words: the body's fields, the revision it pins, the input against its schema, the cap rules, the plane this host
|
|
245
252
|
* resolves, whether the revision can run here; then its title, plane, model and learning start. Nothing is written: the
|
package/dist/runs-over-store.js
CHANGED
|
@@ -132,6 +132,8 @@ async function controlLaunchBody(store, runId) {
|
|
|
132
132
|
/** Only the application can abort its SDK and tools. An HTTP acknowledgement must not pretend that it did. */
|
|
133
133
|
async function refuseSdkStop(store, runId) {
|
|
134
134
|
const launch = await controlLaunchBody(store, runId);
|
|
135
|
+
if (isObject(launch) && launch.cli_learning)
|
|
136
|
+
throw new ApiError("not_continuable", "This run belongs to your existing CLI session. Stop it in that session; AgentRun does not control its execution.");
|
|
135
137
|
if (isObject(launch) && launch.sdk)
|
|
136
138
|
throw new ApiError("not_continuable", "This agent runs in your backend SDK. Cancel it using the original application's cancellation signal; its wrapper will report that outcome here.");
|
|
137
139
|
}
|
|
@@ -164,6 +166,8 @@ export async function message(store, moment, content, { requestId, answers = tru
|
|
|
164
166
|
if (moment.importedSource !== undefined)
|
|
165
167
|
throw importedRefusal(moment);
|
|
166
168
|
const launchBody = await controlLaunchBody(store, moment.id);
|
|
169
|
+
if (isObject(launchBody) && launchBody.cli_learning)
|
|
170
|
+
throw new ApiError("not_continuable", "Continue in the original CLI session.");
|
|
167
171
|
if (isObject(launchBody) && launchBody.sdk)
|
|
168
172
|
throw new ApiError("not_continuable", "Backend SDK runs are single-task sessions. Start a new SDK call for another task.");
|
|
169
173
|
if (nativeOf(launchBody))
|
|
@@ -439,6 +443,8 @@ export async function learningStartFor(deps, entry, revision, rbody, { use = fal
|
|
|
439
443
|
* runner's. Under `origin`, a key that already started a run gets that run (the store's one-run-per-key), so a retry never
|
|
440
444
|
* starts a second. */
|
|
441
445
|
export async function startRun(store, deps, entry, body, { trigger, origin, capped = false, from, title, sealed } = {}) {
|
|
446
|
+
if (entry.revision?.body?.cli_learning)
|
|
447
|
+
throw new ApiError("agent_not_runnable", "Start the next prompt in your existing CLI session. AgentRun records its learning; it does not launch this connection.");
|
|
442
448
|
if (entry.revision?.body?.sdk)
|
|
443
449
|
throw new ApiError("agent_not_runnable", "This agent runs in your backend SDK. Start it through its SDK learning wrapper; AgentRun does not launch its tools or credentials.");
|
|
444
450
|
const { launch, revision } = await prepareLaunch(deps, entry, body, { ...(trigger ? { trigger } : {}), capped, ...(from ? { from } : {}), ...(title !== undefined ? { title } : {}) });
|
|
@@ -446,7 +452,7 @@ export async function startRun(store, deps, entry, body, { trigger, origin, capp
|
|
|
446
452
|
const runId = (deps.newRunId ?? uuidv7)();
|
|
447
453
|
try {
|
|
448
454
|
const labels = labelsOf(body.labels);
|
|
449
|
-
return await withHeldFiles(deps, runId, launch, () => store.runs.create({ id: runId, agentId: entry.agent.id, revisionId: revision.id, ...(origin ? { origin } : {}), ...(labels ? { labels } : {}) }, { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId, launch, revision.kind) } : {}) }));
|
|
455
|
+
return await withHeldFiles(deps, runId, entry.agent.id, launch, (launch) => store.runs.create({ id: runId, agentId: entry.agent.id, revisionId: revision.id, ...(origin ? { origin } : {}), ...(labels ? { labels } : {}) }, { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId, launch, revision.kind) } : {}) }));
|
|
450
456
|
}
|
|
451
457
|
catch (error) {
|
|
452
458
|
// Only another writer of the store got here first under the same origin key: its run is the one asked for.
|
|
@@ -466,15 +472,30 @@ function keyedOrRefused(deps, launch, kind, sealed) {
|
|
|
466
472
|
if (!sealed && serverKeyMissing(deps.planeEnv(), { kind, model: launch.model, native: Boolean(launch.native) }))
|
|
467
473
|
throw modelKeyRequired(false);
|
|
468
474
|
}
|
|
469
|
-
/** Writes run `runId` with `write`, its files (launch.files) held for it first (StartDeps.files): a
|
|
470
|
-
* way, a write that fails, or one that answers another run (an origin key's run started before),
|
|
471
|
-
|
|
475
|
+
/** Writes run `runId` of agent `agentId` with `write`, its files (launch.files) held for it first (StartDeps.files): a
|
|
476
|
+
* hold that fails part way, a write that fails, or one that answers another run (an origin key's run started before),
|
|
477
|
+
* lets go of the hold. In Mode 2 they are placed in the run's folder instead (StartDeps.files.place), and the run is
|
|
478
|
+
* written with the launch that says so; the same failures undo the placing. */
|
|
479
|
+
async function withHeldFiles(deps, runId, agentId, launch, write) {
|
|
472
480
|
const ids = launch.files ?? [];
|
|
473
481
|
if (!ids.length || !deps.files)
|
|
474
|
-
return await write();
|
|
482
|
+
return await write(launch);
|
|
483
|
+
const placed = await deps.files.place?.(runId, agentId, launch);
|
|
484
|
+
if (placed) {
|
|
485
|
+
try {
|
|
486
|
+
const row = await write(placed.launch);
|
|
487
|
+
if (row.id !== runId)
|
|
488
|
+
await placed.undo();
|
|
489
|
+
return row;
|
|
490
|
+
}
|
|
491
|
+
catch (error) {
|
|
492
|
+
await placed.undo().catch(() => undefined);
|
|
493
|
+
throw error;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
475
496
|
try {
|
|
476
497
|
await deps.files.hold(runId, ids);
|
|
477
|
-
const row = await write();
|
|
498
|
+
const row = await write(launch);
|
|
478
499
|
if (row.id !== runId)
|
|
479
500
|
await deps.files.release(runId);
|
|
480
501
|
return row;
|
|
@@ -492,7 +513,34 @@ const bodyConflict = ({ source, kind, id, version }) => new ApiError("external_b
|
|
|
492
513
|
* agent already mapped to the reference is the run's (its id, its learning), so a run of a later version learns from the
|
|
493
514
|
* earlier ones. A different definition under a version already run is 409 external_body_conflict, nothing written; under
|
|
494
515
|
* `origin`, a key that already started a run gets that run, as startRun's. */
|
|
495
|
-
export async function startInline(store, deps, inline, body,
|
|
516
|
+
export async function startInline(store, deps, inline, body, options = {}) {
|
|
517
|
+
const ref = externalKey(inline.external);
|
|
518
|
+
// A reference's first starts that overlap in this server share one agent id: each prepares its launch, and in Mode 2
|
|
519
|
+
// places its files (uploads-archil.ts place), under the id the agent is written with, whichever start's transaction
|
|
520
|
+
// writes it (createInline writes the agent once per reference and reads it back). They run at once; none waits on
|
|
521
|
+
// another. (One server writes a store: its owner lock.)
|
|
522
|
+
let tentative = tentativeAgents.get(ref);
|
|
523
|
+
if (!tentative)
|
|
524
|
+
tentativeAgents.set(ref, (tentative = { id: uuidv7(), starts: 0 }));
|
|
525
|
+
tentative.starts += 1;
|
|
526
|
+
let written = false;
|
|
527
|
+
try {
|
|
528
|
+
const row = await startInlineOnce(store, deps, inline, body, options, tentative.id);
|
|
529
|
+
written = true;
|
|
530
|
+
return row;
|
|
531
|
+
}
|
|
532
|
+
finally {
|
|
533
|
+
tentative.starts -= 1;
|
|
534
|
+
// A first start that failed keeps the id for its reference: what it made under it (in Mode 2, the agent's disk, made
|
|
535
|
+
// before the agent is written) is found again by the next start, never made anew. Once a start is written, the
|
|
536
|
+
// reference maps to its agent and the id is let go.
|
|
537
|
+
if (tentative.starts === 0 && written && tentativeAgents.get(ref) === tentative)
|
|
538
|
+
tentativeAgents.delete(ref);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
/** The agent id each reference's first starts in progress share, and a failed first start's kept (startInline). */
|
|
542
|
+
const tentativeAgents = new Map();
|
|
543
|
+
async function startInlineOnce(store, deps, inline, body, { origin, sealed }, newAgentId) {
|
|
496
544
|
const { external, revision, stored: storedRevision } = inline;
|
|
497
545
|
const ref = externalKey(external);
|
|
498
546
|
// A version's body never changes here: a different one is refused before anything else is read or written.
|
|
@@ -511,7 +559,7 @@ export async function startInline(store, deps, inline, body, { origin, sealed }
|
|
|
511
559
|
const entry = stored
|
|
512
560
|
? firstOfVersion ? { ...stored, agent: { ...stored.agent, name: inline.name, description: inline.description } } : stored
|
|
513
561
|
: {
|
|
514
|
-
agent: { id:
|
|
562
|
+
agent: { id: newAgentId, name: inline.name, description: inline.description, currentRevision: null, createdAt: Date.now(), archivedAt: null, externalRef: ref, purgedAt: null },
|
|
515
563
|
revision: null, version: 0, revisions: 0, sizes: new Map(),
|
|
516
564
|
};
|
|
517
565
|
// A store revision is the revision the run path reads as a pi Revision (its body is the revision body), as pinnedOf hands
|
|
@@ -521,7 +569,7 @@ export async function startInline(store, deps, inline, body, { origin, sealed }
|
|
|
521
569
|
const runId = (deps.newRunId ?? uuidv7)();
|
|
522
570
|
const labels = labelsOf(body.labels);
|
|
523
571
|
try {
|
|
524
|
-
return await withHeldFiles(deps, runId, launch, () => store.runs.createInline({
|
|
572
|
+
return await withHeldFiles(deps, runId, entry.agent.id, launch, (launch) => store.runs.createInline({
|
|
525
573
|
agent: { id: entry.agent.id, name: inline.name, description: inline.description, ref },
|
|
526
574
|
revision: { id: revision.id, version: external.version, kind: revision.kind, body: revision.body, skills: revision.skills, ...(revision.note !== undefined ? { note: revision.note } : {}), ...(revision.mcpPin !== undefined ? { mcpPin: revision.mcpPin } : {}), ...(revision.monidPin !== undefined ? { monidPin: revision.monidPin } : {}) },
|
|
527
575
|
run: { id: runId, ...(origin ? { origin } : {}), ...(labels ? { labels } : {}) },
|
package/dist/sdk/runs.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { Claim, RunOrigin, Store } from "../store/store.js";
|
|
2
2
|
import type { AgentEntry } from "../agents-store.js";
|
|
3
|
+
import { type RunLaunch } from "../run-launch.js";
|
|
3
4
|
import { type StartDeps } from "../runs-over-store.js";
|
|
4
5
|
import { type LearnedWorkflow } from "../learning.js";
|
|
5
6
|
import type { SdkWorkflowCheckEvent } from "./check.js";
|
|
6
7
|
import { type SdkWorkflowCheck } from "../runner/promotion.js";
|
|
7
|
-
|
|
8
|
+
import { type SdkBinding } from "./runtimes.js";
|
|
9
|
+
export { SDK_RUNTIMES, isSdkRuntime, type SdkRuntime } from "./runtimes.js";
|
|
8
10
|
export type SdkUsage = {
|
|
9
11
|
input_tokens: number | null;
|
|
10
12
|
output_tokens: number | null;
|
|
@@ -18,6 +20,10 @@ export type SdkEvent = SdkWorkflowCheckEvent | {
|
|
|
18
20
|
} | {
|
|
19
21
|
type: "session";
|
|
20
22
|
session_id: string;
|
|
23
|
+
} | {
|
|
24
|
+
type: "message";
|
|
25
|
+
role: "user" | "assistant";
|
|
26
|
+
text: string;
|
|
21
27
|
} | {
|
|
22
28
|
type: "tool";
|
|
23
29
|
id: string;
|
|
@@ -32,10 +38,22 @@ export type SdkCompletion = {
|
|
|
32
38
|
answer: string;
|
|
33
39
|
error?: string;
|
|
34
40
|
evidence_complete?: boolean;
|
|
41
|
+
seed_observed?: boolean;
|
|
42
|
+
seed_revision?: string;
|
|
43
|
+
/** Claude records the effective same-prompt policy only after UserPromptSubmit. */
|
|
44
|
+
source_policy?: {
|
|
45
|
+
instructions: string;
|
|
46
|
+
complete: boolean;
|
|
47
|
+
};
|
|
35
48
|
model?: string;
|
|
36
49
|
session_id?: string;
|
|
37
50
|
usage?: SdkUsage;
|
|
38
51
|
};
|
|
52
|
+
/** Claude's begin snapshot is provisional; only its immutable same-window completion can establish policy. */
|
|
53
|
+
export declare function cliPolicyOf(launch: RunLaunch, completion?: SdkCompletion): {
|
|
54
|
+
instructions: string;
|
|
55
|
+
complete: boolean;
|
|
56
|
+
} | undefined;
|
|
39
57
|
export type SdkInbox = {
|
|
40
58
|
run_id: string;
|
|
41
59
|
created_at: number;
|
|
@@ -51,14 +69,14 @@ export type SdkInbox = {
|
|
|
51
69
|
/** Server cleaning changed evidence: two different secret-bearing answers must never agree by their placeholder. */
|
|
52
70
|
check_redacted?: true;
|
|
53
71
|
completion?: SdkCompletion;
|
|
72
|
+
/** CLI source evidence was withheld by the redactor; never infer learning from that partial trace. */
|
|
73
|
+
evidence_incomplete?: true;
|
|
54
74
|
/** Internal terminal admission fence. No later evidence can be newly acknowledged after this CAS wins. */
|
|
55
75
|
closed?: "expired" | "failed" | "cancelled";
|
|
56
76
|
};
|
|
57
77
|
/** The settings key an SDK run's record is kept under (the run's delete with its agent's: agent-delete.ts). */
|
|
58
78
|
export declare const sdkRunKey: (id: string) => string;
|
|
59
|
-
export declare const sdkOf: (body: unknown) =>
|
|
60
|
-
runtime: SdkRuntime;
|
|
61
|
-
} | undefined;
|
|
79
|
+
export declare const sdkOf: (body: unknown) => SdkBinding | undefined;
|
|
62
80
|
export declare function sdkInbox(store: Pick<Store, "settings">, runId: string): Promise<SdkInbox>;
|
|
63
81
|
/** Completion and closure compete on the same inbox. A stale runner cannot close it, and a completion that won
|
|
64
82
|
* remains available to the next claim even if this one cannot read or journal it. No external SDK call is replayed. */
|
|
@@ -72,16 +90,17 @@ export declare class SdkRuns {
|
|
|
72
90
|
private readonly secret;
|
|
73
91
|
private readonly secrets;
|
|
74
92
|
private readonly earlier;
|
|
93
|
+
private readonly lane;
|
|
75
94
|
/** `earlier` are the keys credentials were once signed with (the server's API tokens, before `secret` was its seal
|
|
76
95
|
* key's): a credential any of them signed is still taken, so a run started before an upgrade keeps its credential. */
|
|
77
|
-
constructor(store: Store, data: string, secret: string, secrets?: () => readonly string[], earlier?: readonly string[]);
|
|
96
|
+
constructor(store: Store, data: string, secret: string, secrets?: () => readonly string[], earlier?: readonly string[], lane?: "sdk" | "cli");
|
|
78
97
|
token(runId: string): string;
|
|
79
98
|
authenticate(runId: string, token: string): Promise<void>;
|
|
80
99
|
private clean;
|
|
81
100
|
start(entry: AgentEntry, body: Record<string, unknown>, deps: StartDeps, origin: RunOrigin | undefined, compile: {
|
|
82
101
|
readonly model?: string;
|
|
83
102
|
check(model: string): Promise<void>;
|
|
84
|
-
}, consoleOrigin: string): Promise<{
|
|
103
|
+
}, consoleOrigin: string, cli?: NonNullable<RunLaunch["cli_learning"]>): Promise<{
|
|
85
104
|
run_id: string;
|
|
86
105
|
agent_id: string;
|
|
87
106
|
console_url: string;
|