@parcha/agentrun-serve 0.1.0-beta.53 → 0.1.0-beta.55
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 +138 -3
- package/README.md +346 -99
- package/dist/adapters.d.ts +10 -0
- package/dist/adapters.js +46 -0
- package/dist/agent-package.d.ts +3 -3
- package/dist/agent-package.js +7 -14
- package/dist/agent-rows.d.ts +1 -1
- package/dist/agents-store.js +7 -6
- package/dist/api-only.d.ts +17 -6
- package/dist/api-only.js +22 -9
- package/dist/cli.js +11 -4
- package/dist/composio-made.d.ts +26 -1
- package/dist/composio-made.js +39 -2
- package/dist/composio-preset.d.ts +6 -4
- package/dist/composio-preset.js +50 -17
- package/dist/computer-held-routes.js +2 -3
- package/dist/computer-needs.d.ts +1 -1
- package/dist/computer-needs.js +1 -1
- package/dist/computer-setting.d.ts +8 -4
- package/dist/computer-setting.js +0 -2
- package/dist/computers-running.d.ts +8 -0
- package/dist/computers-running.js +27 -0
- package/dist/computers.d.ts +0 -2
- package/dist/computers.js +1 -1
- package/dist/console/assets/backend-D5EmB4N3.js +166 -0
- package/dist/console/assets/index-DUYLaqiR.js +746 -0
- package/dist/console/assets/index-DYhU4adm.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/docker-host-addresses.d.ts +23 -3
- package/dist/docker-host-addresses.js +90 -18
- package/dist/errors.d.ts +4 -0
- package/dist/errors.js +7 -0
- package/dist/exa-keyless.d.ts +2 -3
- package/dist/exa-keyless.js +43 -127
- package/dist/firecrawl-keyless.d.ts +41 -0
- package/dist/firecrawl-keyless.js +152 -0
- package/dist/github-connection.d.ts +50 -1
- package/dist/github-connection.js +96 -3
- package/dist/github-faux.d.ts +11 -2
- package/dist/github-faux.js +138 -7
- package/dist/github-pull-request.d.ts +37 -0
- package/dist/github-pull-request.js +110 -0
- package/dist/handed-secret.d.ts +3 -1
- package/dist/handed-secret.js +4 -2
- package/dist/harness-keys.d.ts +98 -0
- package/dist/harness-keys.js +247 -0
- package/dist/harness-recipe-entry.d.ts +14 -9
- package/dist/harness-recipe-entry.js +25 -14
- package/dist/harness-table.d.ts +16 -1
- package/dist/harness-table.js +19 -7
- package/dist/harness.d.ts +4 -0
- package/dist/harness.js +12 -1
- package/dist/host-check.d.ts +2 -0
- package/dist/host-check.js +6 -0
- package/dist/import-summary.d.ts +1 -1
- package/dist/import-summary.js +1 -1
- package/dist/import.d.ts +5 -5
- package/dist/import.js +54 -67
- package/dist/keyless-mcp.d.ts +36 -0
- package/dist/keyless-mcp.js +127 -0
- package/dist/learn/audit.d.ts +3 -3
- package/dist/learn/audit.js +3 -3
- package/dist/learn/commit.d.ts +8 -7
- package/dist/learn/commit.js +60 -20
- package/dist/learn/compile.d.ts +4 -3
- package/dist/learn/compile.js +7 -5
- package/dist/learn/folder.d.ts +16 -3
- package/dist/learn/folder.js +46 -13
- package/dist/learn/promote.d.ts +37 -13
- package/dist/learn/promote.js +112 -40
- package/dist/learn/secrets.js +10 -2
- package/dist/learning-routes.d.ts +22 -17
- package/dist/learning-routes.js +40 -39
- package/dist/learning.js +2 -2
- package/dist/live-reach.d.ts +34 -7
- package/dist/live-reach.js +76 -11
- package/dist/manifest.d.ts +10 -0
- package/dist/manifest.js +30 -0
- package/dist/mcp-pin-first.d.ts +4 -2
- package/dist/mcp-pin-first.js +5 -2
- package/dist/mcp-probe.js +2 -2
- package/dist/mcp-secret-writes.d.ts +16 -7
- package/dist/mcp-secret-writes.js +35 -27
- package/dist/mcp-servers-store.d.ts +30 -6
- package/dist/mcp-servers-store.js +112 -28
- package/dist/mcp-sources.d.ts +10 -2
- package/dist/mcp-sources.js +9 -2
- package/dist/mcp-store.d.ts +13 -7
- package/dist/mcp-store.js +12 -9
- package/dist/model-form.d.ts +3 -2
- package/dist/model-form.js +11 -7
- package/dist/model.d.ts +20 -4
- package/dist/model.js +68 -9
- package/dist/native/history.d.ts +1 -1
- package/dist/native/history.js +2 -2
- package/dist/ollama-provider.d.ts +92 -0
- package/dist/ollama-provider.js +495 -0
- package/dist/openapi/agentrun-v2.openapi.json +2 -2
- package/dist/openapi.js +235 -41
- package/dist/page.d.ts +11 -3
- package/dist/page.js +22 -7
- package/dist/place-offers.d.ts +17 -1
- package/dist/place-offers.js +46 -5
- package/dist/print.js +1 -1
- package/dist/purged-workflow.d.ts +35 -7
- package/dist/purged-workflow.js +73 -26
- package/dist/run-computer.d.ts +2 -0
- package/dist/run-computer.js +2 -0
- package/dist/run-files.d.ts +4 -0
- package/dist/run-files.js +4 -0
- package/dist/run-keys.d.ts +2 -4
- package/dist/run-keys.js +6 -7
- package/dist/run-launch.d.ts +4 -0
- package/dist/run-launch.js +4 -0
- package/dist/run-reads-over-store.d.ts +3 -2
- package/dist/run-reads-over-store.js +66 -2
- package/dist/run-secrets.js +5 -2
- package/dist/runner/adapter-loop.d.ts +6 -3
- package/dist/runner/adapter-loop.js +34 -15
- package/dist/runner/adapter-run-spec.d.ts +3 -0
- package/dist/runner/adapter-run-spec.js +6 -4
- package/dist/runner/audit.js +8 -4
- package/dist/runner/beside.d.ts +2 -1
- package/dist/runner/beside.js +6 -2
- package/dist/runner/claim-secrets.d.ts +5 -8
- package/dist/runner/claim-secrets.js +6 -0
- package/dist/runner/cli-run-spec.d.ts +1 -1
- package/dist/runner/cli-run-spec.js +39 -7
- package/dist/runner/harness-loops.d.ts +22 -9
- package/dist/runner/harness-loops.js +21 -11
- package/dist/runner/held.d.ts +3 -0
- package/dist/runner/learning-end.d.ts +1 -1
- package/dist/runner/learning-end.js +8 -3
- package/dist/runner/loop-contract.d.ts +5 -4
- package/dist/runner/main.js +4 -2
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +26 -2
- package/dist/runner/mcp-run.d.ts +3 -0
- package/dist/runner/mcp-run.js +2 -1
- package/dist/runner/metrics.d.ts +10 -8
- package/dist/runner/metrics.js +20 -27
- package/dist/runner/model-route.d.ts +3 -0
- package/dist/runner/model-route.js +6 -2
- package/dist/runner/pr-checkout.d.ts +21 -4
- package/dist/runner/pr-checkout.js +103 -4
- package/dist/runner/promotion.d.ts +15 -9
- package/dist/runner/promotion.js +25 -15
- package/dist/runner/run-child-host.js +24 -11
- package/dist/runner/run-child.js +3 -1
- package/dist/runner/runner-check.d.ts +3 -0
- package/dist/runner/runner-check.js +23 -0
- package/dist/runner/sdk-loop.js +2 -0
- package/dist/runner/workflow-loop.d.ts +2 -2
- package/dist/runner/workflow-loop.js +1 -2
- package/dist/runner/workflow-spec.d.ts +1 -1
- package/dist/runner/workflow-spec.js +6 -6
- package/dist/sdk/check.d.ts +4 -1
- package/dist/sdk/check.js +2 -1
- package/dist/sdk/runs.d.ts +2 -2
- package/dist/sdk/runs.js +8 -6
- package/dist/secret-cut.js +2 -1
- package/dist/secret-writes.d.ts +3 -2
- package/dist/secret-writes.js +1 -1
- package/dist/server.d.ts +55 -8
- package/dist/server.js +363 -118
- package/dist/standard-webhooks.d.ts +11 -0
- package/dist/standard-webhooks.js +20 -2
- package/dist/store/agent-body.d.ts +2 -2
- package/dist/store/agent-body.js +2 -2
- package/dist/store/index.d.ts +1 -1
- package/dist/store/schema.js +5 -2
- package/dist/store/sqlite/store.js +90 -34
- package/dist/store/store.d.ts +54 -14
- package/dist/store-reads/journal.d.ts +7 -2
- package/dist/store-reads/journal.js +9 -6
- package/dist/store-reads/learning.d.ts +12 -9
- package/dist/store-reads/learning.js +18 -24
- package/dist/store-view.d.ts +0 -5
- package/dist/store-view.js +9 -8
- package/dist/suggestions.d.ts +282 -0
- package/dist/suggestions.js +919 -0
- package/dist/telemetry.d.ts +8 -1
- package/dist/telemetry.js +12 -4
- package/dist/template-eval.d.ts +49 -4
- package/dist/template-eval.js +168 -45
- package/dist/template-import.d.ts +17 -0
- package/dist/template-import.js +36 -2
- package/dist/templates.d.ts +83 -76
- package/dist/templates.js +29 -48
- package/dist/timeline/labels.d.ts +2 -2
- package/dist/timeline/labels.js +2 -2
- package/dist/timeline/timeline.d.ts +2 -2
- package/dist/timeline/timeline.js +1 -1
- package/dist/tool-plane.d.ts +17 -9
- package/dist/tool-plane.js +38 -17
- package/dist/tools.js +2 -2
- package/dist/trigger-launch-hook.d.ts +19 -9
- package/dist/trigger-launch-hook.js +35 -25
- package/dist/trigger-targets.d.ts +18 -8
- package/dist/trigger-targets.js +42 -19
- package/dist/triggers.d.ts +85 -23
- package/dist/triggers.js +303 -96
- package/dist/validate.d.ts +1 -1
- package/dist/validate.js +2 -2
- package/dist/web-fake.js +3 -3
- package/dist/web-fetch-direct.d.ts +4 -0
- package/dist/web-fetch-direct.js +8 -1
- package/dist/web-fetch.d.ts +12 -3
- package/dist/web-fetch.js +47 -14
- package/dist/web-search.d.ts +33 -4
- package/dist/web-search.js +100 -41
- package/dist/webhooks.js +4 -5
- package/dist/workspace/synced-folder.d.ts +1 -1
- package/dist/workspace/synced-folder.js +11 -14
- package/launcher/agentrun-serve +5 -1
- package/package.json +17 -13
- package/templates/README.md +5 -4
- package/templates/agent-scout/agent.md +46 -0
- package/templates/agent-scout/skills/scout/SKILL.md +88 -0
- package/templates/agent-scout/skills/scout/suggestions.schema.json +112 -0
- package/dist/console/assets/index-BFgyZzF_.js +0 -734
- package/dist/console/assets/index-DbilxljH.css +0 -1
- package/dist/import-sources.d.ts +0 -116
- package/dist/import-sources.js +0 -693
package/dist/import.js
CHANGED
|
@@ -8,13 +8,13 @@ import { createHash, randomUUID } from "node:crypto";
|
|
|
8
8
|
import { existsSync } from "node:fs";
|
|
9
9
|
import { lstat, open, realpath, stat } from "node:fs/promises";
|
|
10
10
|
import { homedir, tmpdir } from "node:os";
|
|
11
|
-
import { basename,
|
|
11
|
+
import { basename, join, sep } from "node:path";
|
|
12
12
|
import { parseArgs } from "node:util";
|
|
13
13
|
import { BACKGROUND_CONTEXT as ctx } from "@earendil-works/chord/context";
|
|
14
14
|
import { AssistantEntry, ROOT_CONVERSATION_ID, ToolResultEntry, UserEntry } from "@earendil-works/pi-durable";
|
|
15
15
|
import { REQUEST_COST, runMetricsOf } from "./timeline/index.js";
|
|
16
16
|
import { defaultData } from "./files.js";
|
|
17
|
-
import {
|
|
17
|
+
import { childrenOf, HARNESS_OF, inOrder, locatorKey, locatorOf, mostEffortOf, priceRequests, readSession, SOURCE_NAMES, SOURCES, sessionLocators } from "@parcha/agentrun-import";
|
|
18
18
|
import { hoursOf, summaryLines } from "./import-summary.js";
|
|
19
19
|
import { stopOnce } from "./stop-signals.js";
|
|
20
20
|
import { catalogPrices, providerModels } from "./model.js";
|
|
@@ -43,9 +43,10 @@ export async function exportRemoteHistory(target, options = {}) {
|
|
|
43
43
|
if (!Number.isSafeInteger(cursor) || cursor < 0)
|
|
44
44
|
throw new Error('Invalid history cursor.');
|
|
45
45
|
const project = await realpath(target.project), selected = [], skipped = new Map(), stamps = new Map();
|
|
46
|
-
const sourceEnv = options.env ?? process.env
|
|
46
|
+
const sourceEnv = options.env ?? process.env;
|
|
47
47
|
const skip = (reason) => skipped.set(reason, (skipped.get(reason) ?? 0) + 1);
|
|
48
|
-
for (const {
|
|
48
|
+
for (const { locator, stats } of await inOrder(await sessionLocators(options.home ?? homedir(), target.runtime, { env: sourceEnv }), target.runtime)) {
|
|
49
|
+
const file = locator.file;
|
|
49
50
|
if (stats.size > MAX_SESSION_BYTES) {
|
|
50
51
|
skip('Source session project could not be checked: file exceeds the metadata limit.');
|
|
51
52
|
continue;
|
|
@@ -72,11 +73,11 @@ export async function exportRemoteHistory(target, options = {}) {
|
|
|
72
73
|
skip('Still being written or modified within ten minutes.');
|
|
73
74
|
continue;
|
|
74
75
|
}
|
|
75
|
-
selected.push({ source: target.runtime, id: header.id, file });
|
|
76
|
-
stamps.set(
|
|
76
|
+
selected.push({ source: target.runtime, id: header.id, file, ...(locator.id === undefined ? {} : { within: locator.id }) });
|
|
77
|
+
stamps.set(locatorKey(locator), remoteHistoryStamp(stats));
|
|
77
78
|
}
|
|
78
79
|
const groups = byRun(selected).sort((a, b) => a[0].id.localeCompare(b[0].id));
|
|
79
|
-
const inventory = hash(JSON.stringify({ project, runtime: target.runtime, groups: groups.map(files => ({ id: files[0].id, files: files.map(file => ({ path: file
|
|
80
|
+
const inventory = hash(JSON.stringify({ project, runtime: target.runtime, groups: groups.map(files => ({ id: files[0].id, files: files.map(file => ({ path: locatorKey(locatorOf(file)), stamp: stamps.get(locatorKey(locatorOf(file))) })).sort((a, b) => a.path.localeCompare(b.path)) })) }));
|
|
80
81
|
if ((cursor > 0 && options.inventory === undefined) || (options.inventory !== undefined && options.inventory !== inventory))
|
|
81
82
|
throw new Error('The selected history inventory changed or is missing. Restart the import from its preview; previously imported sessions are safe to retry.');
|
|
82
83
|
const report = () => [...skipped].map(([reason, count]) => ({ reason, count }));
|
|
@@ -92,12 +93,12 @@ export async function exportRemoteHistory(target, options = {}) {
|
|
|
92
93
|
let changed = false, child = false;
|
|
93
94
|
for (const listed of groups[index]) {
|
|
94
95
|
const before = await stat(listed.file).catch(() => undefined);
|
|
95
|
-
const approvedStamp = stamps.get(listed
|
|
96
|
+
const approvedStamp = stamps.get(locatorKey(locatorOf(listed)));
|
|
96
97
|
if (!before || remoteHistoryStamp(before) !== approvedStamp || now - before.mtimeMs < LIVE_MS || before.size > REMOTE_HISTORY_SOURCE_BYTES) {
|
|
97
98
|
changed = true;
|
|
98
99
|
break;
|
|
99
100
|
}
|
|
100
|
-
const part = await readSession(listed
|
|
101
|
+
const part = await readSession(locatorOf(listed), target.runtime, { seen }).catch(() => undefined), after = await stat(listed.file).catch(() => undefined);
|
|
101
102
|
if (!part || !after || remoteHistoryStamp(after) !== approvedStamp || !part.cwd || (await realpath(part.cwd).catch(() => part.cwd)) !== project || part.id !== listed.id) {
|
|
102
103
|
changed = true;
|
|
103
104
|
break;
|
|
@@ -159,7 +160,8 @@ const REMOTE_HISTORY_SOURCE_BYTES = 8_000_000;
|
|
|
159
160
|
* Keep at most one bounded JSONL record and never read past the remote source limit, even if a file grows. */
|
|
160
161
|
async function remoteHistoryMetadata(file, source) {
|
|
161
162
|
const handle = await open(file, 'r');
|
|
162
|
-
|
|
163
|
+
// Claude Code's id is its file's name (<id>.jsonl), as readSession reads it; the others' come from a record.
|
|
164
|
+
let id = source === 'claude-code' ? basename(file, '.jsonl') : undefined, cwd, child = false;
|
|
163
165
|
const str = (value) => typeof value === 'string' && value !== '' ? value : undefined;
|
|
164
166
|
const metadataOf = (parts) => {
|
|
165
167
|
try {
|
|
@@ -167,7 +169,6 @@ async function remoteHistoryMetadata(file, source) {
|
|
|
167
169
|
if (!row || typeof row !== 'object' || Array.isArray(row))
|
|
168
170
|
return;
|
|
169
171
|
if (source === 'claude-code') {
|
|
170
|
-
id ??= str(row.sessionId);
|
|
171
172
|
cwd ??= str(row.cwd);
|
|
172
173
|
child ||= row.isSidechain === true;
|
|
173
174
|
}
|
|
@@ -338,16 +339,16 @@ async function findKeys(plan, add, cut, held, signal, onProgress) {
|
|
|
338
339
|
const parts = [];
|
|
339
340
|
const budget = budgetOf();
|
|
340
341
|
let over = false;
|
|
341
|
-
for (const
|
|
342
|
-
const stats = await stat(file).catch(() => null);
|
|
342
|
+
for (const entry of files) {
|
|
343
|
+
const stats = await stat(entry.file).catch(() => null);
|
|
343
344
|
if (stats && !fits(budget, stats.size)) {
|
|
344
345
|
over = true;
|
|
345
346
|
break;
|
|
346
347
|
}
|
|
347
|
-
const part = stats ? await readSession(
|
|
348
|
+
const part = stats ? await readSession(locatorOf(entry), listed.source, { seen }).catch(() => undefined) : undefined;
|
|
348
349
|
if (!part || !stats)
|
|
349
350
|
continue;
|
|
350
|
-
stamps.set(
|
|
351
|
+
stamps.set(locatorKey(locatorOf(entry)), stampOf(stats));
|
|
351
352
|
parts.push(part);
|
|
352
353
|
}
|
|
353
354
|
if (over) {
|
|
@@ -368,7 +369,7 @@ async function findKeys(plan, add, cut, held, signal, onProgress) {
|
|
|
368
369
|
for (const child of subagents) {
|
|
369
370
|
const stats = await stat(child.file).catch(() => null);
|
|
370
371
|
if (stats)
|
|
371
|
-
stamps.set(child
|
|
372
|
+
stamps.set(locatorKey(locatorOf(child)), stampOf(stats));
|
|
372
373
|
}
|
|
373
374
|
add(await keysInSessions(subagents));
|
|
374
375
|
}
|
|
@@ -411,7 +412,7 @@ export async function planImport({ home, sources = SOURCES, all = false, deleted
|
|
|
411
412
|
const held = [];
|
|
412
413
|
const found = [];
|
|
413
414
|
const children = new Map();
|
|
414
|
-
const child = (owner,
|
|
415
|
+
const child = (owner, locator) => void children.set(owner, [...(children.get(owner) ?? []), locator]);
|
|
415
416
|
const untied = [];
|
|
416
417
|
const projects = new Map();
|
|
417
418
|
let stopped = false;
|
|
@@ -419,12 +420,13 @@ export async function planImport({ home, sources = SOURCES, all = false, deleted
|
|
|
419
420
|
const rank = new Map();
|
|
420
421
|
const temps = [...new Set([tempDir, await realpath(tempDir).catch(() => tempDir)])];
|
|
421
422
|
for (const source of sources) {
|
|
422
|
-
for (const {
|
|
423
|
+
for (const { locator, stats } of await inOrder(await sessionLocators(home, source), source)) {
|
|
424
|
+
const { file } = locator;
|
|
423
425
|
if (signal?.aborted) {
|
|
424
426
|
stopped = true;
|
|
425
427
|
break;
|
|
426
428
|
}
|
|
427
|
-
const known = seen.get(hash(
|
|
429
|
+
const known = seen.get(hash(locatorKey(locator)));
|
|
428
430
|
if (sameFile(known, stats)) {
|
|
429
431
|
already += 1;
|
|
430
432
|
held.push(known.run);
|
|
@@ -439,7 +441,7 @@ export async function planImport({ home, sources = SOURCES, all = false, deleted
|
|
|
439
441
|
continue;
|
|
440
442
|
}
|
|
441
443
|
// One file this user cannot read, or one gone since its stat, is named and passed over: the rest still import.
|
|
442
|
-
const session = await readSession(
|
|
444
|
+
const session = await readSession(locator, source, { turns: false }).catch((error) => leave(unread(file, error), source));
|
|
443
445
|
if (!session)
|
|
444
446
|
continue;
|
|
445
447
|
session.id = await idOf(session.id, scan);
|
|
@@ -448,7 +450,7 @@ export async function planImport({ home, sources = SOURCES, all = false, deleted
|
|
|
448
450
|
// A subagent's session is no run of its own: its usage is its parent's, when its file names the parent (a Codex
|
|
449
451
|
// thread's, whichever of its files); else it counts in the totals alone, where its project would.
|
|
450
452
|
if (session.child && session.parent) {
|
|
451
|
-
child(`${source}:${session.parent}`,
|
|
453
|
+
child(`${source}:${session.parent}`, locator);
|
|
452
454
|
continue;
|
|
453
455
|
}
|
|
454
456
|
if (!session.cwd) {
|
|
@@ -473,7 +475,7 @@ export async function planImport({ home, sources = SOURCES, all = false, deleted
|
|
|
473
475
|
}
|
|
474
476
|
}
|
|
475
477
|
if (session.child) {
|
|
476
|
-
untied.push({
|
|
478
|
+
untied.push({ locator, source });
|
|
477
479
|
continue;
|
|
478
480
|
}
|
|
479
481
|
let project = projects.get(cwd);
|
|
@@ -487,9 +489,8 @@ export async function planImport({ home, sources = SOURCES, all = false, deleted
|
|
|
487
489
|
rank.set(session, rank.size);
|
|
488
490
|
project.sessions.push(session);
|
|
489
491
|
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
child(of, file);
|
|
492
|
+
for (const { locator, of } of await childrenOf(home, source))
|
|
493
|
+
child(locatorKey(of), locator);
|
|
493
494
|
}
|
|
494
495
|
ownRuns(projects, rank);
|
|
495
496
|
// The owner's choice, once each session has its one project: a project not chosen is no part of the plan.
|
|
@@ -546,7 +547,7 @@ export async function planImport({ home, sources = SOURCES, all = false, deleted
|
|
|
546
547
|
over = true;
|
|
547
548
|
break;
|
|
548
549
|
}
|
|
549
|
-
const part = await readSession(listed
|
|
550
|
+
const part = await readSession(locatorOf(listed), listed.source, { seen: seen(listed.source) }).catch(() => undefined);
|
|
550
551
|
if (part)
|
|
551
552
|
read.push(part);
|
|
552
553
|
}
|
|
@@ -594,11 +595,11 @@ export async function untiedFound(plan) {
|
|
|
594
595
|
const counted = (source) => seen.get(source) ?? seen.set(source, new Set()).get(source);
|
|
595
596
|
// A thread resumed in a second file of the same id is one: its own subagents, which name it, count once with it.
|
|
596
597
|
const threads = new Map();
|
|
597
|
-
for (const {
|
|
598
|
-
const stats = await stat(file).catch(() => null);
|
|
598
|
+
for (const { locator, source } of plan.untied) {
|
|
599
|
+
const stats = await stat(locator.file).catch(() => null);
|
|
599
600
|
if (!stats || stats.size > MAX_SESSION_BYTES)
|
|
600
601
|
continue;
|
|
601
|
-
const session = await readSession(
|
|
602
|
+
const session = await readSession(locator, source, { seen: counted(source) }).catch(() => undefined);
|
|
602
603
|
if (session)
|
|
603
604
|
threads.set(`${source}:${session.id}`, [...(threads.get(`${source}:${session.id}`) ?? []), session]);
|
|
604
605
|
}
|
|
@@ -692,20 +693,6 @@ function merged(parts) {
|
|
|
692
693
|
...(effort ? { effort } : {}),
|
|
693
694
|
};
|
|
694
695
|
}
|
|
695
|
-
/** The files of `source`, each with its stats (one gone since it was listed is passed over), in the import's order:
|
|
696
|
-
* Claude Code's by project folder, oldest written first (the first file holding a copied record keeps it); Codex's and
|
|
697
|
-
* pi's as their dated names sort. */
|
|
698
|
-
async function inOrder(files, source) {
|
|
699
|
-
const out = [];
|
|
700
|
-
for (const file of files) {
|
|
701
|
-
const stats = await stat(file).catch(() => null);
|
|
702
|
-
if (stats)
|
|
703
|
-
out.push({ file, stats });
|
|
704
|
-
}
|
|
705
|
-
if (source === "claude-code")
|
|
706
|
-
out.sort((a, b) => dirname(a.file).localeCompare(dirname(b.file)) || a.stats.mtimeMs - b.stats.mtimeMs || a.file.localeCompare(b.file));
|
|
707
|
-
return out;
|
|
708
|
-
}
|
|
709
696
|
/** A session that holds only records an earlier file of the import holds (a resumed session's copy of them). */
|
|
710
697
|
const ownless = (session) => session.copies > 0 && !session.turns.some((turn) => turn.role !== "note");
|
|
711
698
|
/** The records and responses an import has counted, by source, for one project: first those its runs in `store` hold
|
|
@@ -723,6 +710,10 @@ async function seenIn(store, agentId) {
|
|
|
723
710
|
const id = entry.model?.[0]?.responseId;
|
|
724
711
|
if (typeof id === "string" && id)
|
|
725
712
|
seen("claude-code").add(`m:${id}`);
|
|
713
|
+
// A run imported before a request's key held its request id (message id:request id) keeps the bare message id:
|
|
714
|
+
// the reader matches it against a request's message id alone.
|
|
715
|
+
if (typeof id === "string" && id && !id.includes(":"))
|
|
716
|
+
seen("claude-code").add(`l:${id}`);
|
|
726
717
|
const uuids = entry.data?.record_uuids;
|
|
727
718
|
if (Array.isArray(uuids))
|
|
728
719
|
for (const uuid of uuids)
|
|
@@ -740,18 +731,19 @@ async function readChildren(plan, session, parts, seen, budget) {
|
|
|
740
731
|
const out = [];
|
|
741
732
|
const visited = new Set();
|
|
742
733
|
const under = async (owner) => {
|
|
743
|
-
for (const
|
|
744
|
-
|
|
734
|
+
for (const locator of plan.children.get(owner) ?? []) {
|
|
735
|
+
const key = locatorKey(locator);
|
|
736
|
+
if (visited.has(key))
|
|
745
737
|
continue;
|
|
746
|
-
visited.add(
|
|
747
|
-
const stats = await stat(file).catch(() => null);
|
|
738
|
+
visited.add(key);
|
|
739
|
+
const stats = await stat(locator.file).catch(() => null);
|
|
748
740
|
if (!stats)
|
|
749
741
|
continue;
|
|
750
742
|
// Every subagent read is held with the run: one more than the run's cap holds ends the read, and the run is left out.
|
|
751
743
|
// No subagent is passed over for its size: the run would be kept without its usage.
|
|
752
744
|
if (!fits(budget, stats.size))
|
|
753
745
|
throw new RunTooLarge();
|
|
754
|
-
const child = await readSession(
|
|
746
|
+
const child = await readSession(locator, session.source, { seen }).catch(() => undefined);
|
|
755
747
|
if (!child)
|
|
756
748
|
continue;
|
|
757
749
|
out.push(child);
|
|
@@ -760,7 +752,7 @@ async function readChildren(plan, session, parts, seen, budget) {
|
|
|
760
752
|
}
|
|
761
753
|
};
|
|
762
754
|
for (const part of parts)
|
|
763
|
-
await under(part
|
|
755
|
+
await under(locatorKey(locatorOf(part)));
|
|
764
756
|
await under(`${session.source}:${session.id}`);
|
|
765
757
|
return out;
|
|
766
758
|
}
|
|
@@ -1038,22 +1030,15 @@ async function estimateOf(entries, catalog) {
|
|
|
1038
1030
|
// Unknown when one answer priced here has unknown tokens (a failed one's counts are its own, as runMetricsOf reads them).
|
|
1039
1031
|
if (runMetricsOf(entries.filter((entry) => entry.kind === "pi.assistant")).unmetered > 0)
|
|
1040
1032
|
return undefined;
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
for (const entry of entries) {
|
|
1033
|
+
// Each answer's request at its own provider's entry, as @parcha/agentrun-import prices a session's totals.
|
|
1034
|
+
const requests = entries.flatMap((entry) => {
|
|
1044
1035
|
const answer = entry.kind === "pi.assistant" ? entry.model?.[0] : undefined;
|
|
1045
1036
|
if (!answer?.usage)
|
|
1046
|
-
|
|
1037
|
+
return [];
|
|
1047
1038
|
const { input = 0, output = 0, cacheRead = 0, cacheWrite = 0, cacheWrite1h } = answer.usage;
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
if (!cost)
|
|
1052
|
-
return undefined;
|
|
1053
|
-
const usage = { input, output, cacheRead, cacheWrite, ...(cacheWrite1h !== undefined ? { cacheWrite1h } : {}), totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } };
|
|
1054
|
-
total += calculateCost({ cost }, usage).total;
|
|
1055
|
-
}
|
|
1056
|
-
return Math.round(total * 1e6) / 1e6;
|
|
1039
|
+
return [{ ...(answer.provider && answer.model ? { model: `${answer.provider}/${answer.model}` } : {}), usage: { input, output, cacheRead, cacheWrite, ...(cacheWrite1h !== undefined ? { cacheWrite1h } : {}) } }];
|
|
1040
|
+
});
|
|
1041
|
+
return priceRequests(requests, await catalog());
|
|
1057
1042
|
}
|
|
1058
1043
|
/** What an imported agent is told when its project has no CLAUDE.md or AGENTS.md (or the harness's own file): an agentic
|
|
1059
1044
|
* revision with no instructions is refused every run (runnable.ts), so an import never writes one. */
|
|
@@ -1215,13 +1200,15 @@ export async function runImport(store, plan, options) {
|
|
|
1215
1200
|
// copies the import leaves out.
|
|
1216
1201
|
let titled;
|
|
1217
1202
|
let changed = false;
|
|
1218
|
-
for (const
|
|
1203
|
+
for (const entry of files) {
|
|
1204
|
+
const { file } = entry;
|
|
1205
|
+
const key = locatorKey(locatorOf(entry));
|
|
1219
1206
|
const stats = await stat(file).catch(() => null);
|
|
1220
1207
|
if (stats && !fits(budget, stats.size)) {
|
|
1221
1208
|
over = true;
|
|
1222
1209
|
break;
|
|
1223
1210
|
}
|
|
1224
|
-
const part = stats ? await readSession(
|
|
1211
|
+
const part = stats ? await readSession(locatorOf(entry), listed.source, { seen: seen(listed.source) }).catch((error) => void report.skipped.push(unread(file, error))) : void report.skipped.push({ what: file, why: "gone since it was listed", kind: "vanished" });
|
|
1225
1212
|
if (!part || !stats)
|
|
1226
1213
|
continue;
|
|
1227
1214
|
searched.push(part);
|
|
@@ -1232,9 +1219,9 @@ export async function runImport(store, plan, options) {
|
|
|
1232
1219
|
report.skipped.push({ what: file, why: "holds only records of sessions imported already", kind: "copies" });
|
|
1233
1220
|
continue;
|
|
1234
1221
|
}
|
|
1235
|
-
read ??= { path_sha256: hash(
|
|
1222
|
+
read ??= { path_sha256: hash(key), size: stats.size, mtime_ms: stats.mtimeMs };
|
|
1236
1223
|
parts.push(part);
|
|
1237
|
-
if (scannedAs.get(
|
|
1224
|
+
if (scannedAs.get(key) !== stampOf(stats))
|
|
1238
1225
|
changed = true;
|
|
1239
1226
|
}
|
|
1240
1227
|
if (over) {
|
|
@@ -1261,7 +1248,7 @@ export async function runImport(store, plan, options) {
|
|
|
1261
1248
|
});
|
|
1262
1249
|
if (!subagents)
|
|
1263
1250
|
continue;
|
|
1264
|
-
const moved = await Promise.all(subagents.map(async (child) => scannedAs.get(child
|
|
1251
|
+
const moved = await Promise.all(subagents.map(async (child) => scannedAs.get(locatorKey(locatorOf(child))) !== stampOf((await stat(child.file).catch(() => null)) ?? { size: -1, mtimeMs: -1 })));
|
|
1265
1252
|
if (moved.some(Boolean))
|
|
1266
1253
|
add(await keysInSessions(subagents));
|
|
1267
1254
|
// The transcript as the store's own write batches, each string cut; its subagents' requests marked after its turns,
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** The MCP revision this client speaks; the server answers the one it takes. */
|
|
2
|
+
export declare const PROTOCOL = "2025-06-18";
|
|
3
|
+
/** The most of an answer read: a search's text is a few kilobytes, a page's markdown more; past this the rest is never
|
|
4
|
+
* read. */
|
|
5
|
+
export declare const MAX_BYTES: number;
|
|
6
|
+
/** What a free web search answers when its free limit holds, in our words: a backend's own (a link to sign up, a key in
|
|
7
|
+
* its MCP URL) mean nothing to a person here, so they are never passed on. */
|
|
8
|
+
export declare const RATE_LIMITED = "Free web search is rate-limited right now. Try again in a minute; add the free Parallel Search server in Settings \u2192 MCP servers and grant the agent its web_search; or add a Parallel key in Settings \u2192 API Keys to search with a key.";
|
|
9
|
+
/** One tool call's outcome: `status`, a non-2xx answer to `step` (with the seconds its Retry-After named); `error`, a
|
|
10
|
+
* JSON-RPC error's message, or that the server answered no initialize; else the call's `result` (undefined: no answer
|
|
11
|
+
* to the call came). */
|
|
12
|
+
export type Called = {
|
|
13
|
+
status: number;
|
|
14
|
+
retryAfterS?: number;
|
|
15
|
+
step: "initialize" | "the call";
|
|
16
|
+
} | {
|
|
17
|
+
error: string;
|
|
18
|
+
rpc: boolean;
|
|
19
|
+
} | {
|
|
20
|
+
result: Record<string, unknown> | undefined;
|
|
21
|
+
};
|
|
22
|
+
/** A call given its own bound: as Called, or `over`, its answer ran past that bound (in bytes), unread. */
|
|
23
|
+
export type Bounded = Called | {
|
|
24
|
+
over: number;
|
|
25
|
+
};
|
|
26
|
+
/** The seconds a Retry-After names, as seconds or a date; undefined when it names none. */
|
|
27
|
+
export declare function retryAfterOf(response: Response): number | undefined;
|
|
28
|
+
/** `ms` of waiting that `signal` ends, rejecting with its reason. */
|
|
29
|
+
export declare const sleep: (ms: number, signal: AbortSignal) => Promise<void>;
|
|
30
|
+
/** A tool result's text blocks, joined by lines; empty when it has none. */
|
|
31
|
+
export declare const textBlocks: (result: Record<string, unknown> | undefined) => string;
|
|
32
|
+
/** The tool `name` called with `args` on the MCP server at `endpoint` through `dial`, each request ended by `deadline`:
|
|
33
|
+
* one exchange (initialize, notifications/initialized, tools/call). `maxBytes`: the call's answer's own bound, past
|
|
34
|
+
* which it is `over` (none: its first MAX_BYTES read). A failure to reach the server throws. */
|
|
35
|
+
export declare function callTool(endpoint: string, dial: typeof fetch, deadline: AbortSignal, name: string, args: Record<string, unknown>): Promise<Called>;
|
|
36
|
+
export declare function callTool(endpoint: string, dial: typeof fetch, deadline: AbortSignal, name: string, args: Record<string, unknown>, maxBytes: number): Promise<Bounded>;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// The MCP client the keyless web backends share (firecrawl-keyless.ts, exa-keyless.ts): one tool call is one exchange
|
|
2
|
+
// over MCP's streamable HTTP transport. `initialize` (its session id, when the server names one), then
|
|
3
|
+
// `notifications/initialized`, then `tools/call`, each request carrying the session id only where one came back. An
|
|
4
|
+
// answer is JSON or an event stream's `data:` lines, and no more than 1 MiB of one is read, but for a call's answer given
|
|
5
|
+
// its own bound: one past that bound is `over`, never parsed cut. No key and no header beyond
|
|
6
|
+
// the transport's own is sent. What a refusal means (a free limit, a connection refused) is each backend's to read.
|
|
7
|
+
/** The MCP revision this client speaks; the server answers the one it takes. */
|
|
8
|
+
export const PROTOCOL = "2025-06-18";
|
|
9
|
+
const ACCEPT = "application/json, text/event-stream";
|
|
10
|
+
/** The most of an answer read: a search's text is a few kilobytes, a page's markdown more; past this the rest is never
|
|
11
|
+
* read. */
|
|
12
|
+
export const MAX_BYTES = 1 << 20;
|
|
13
|
+
/** What a free web search answers when its free limit holds, in our words: a backend's own (a link to sign up, a key in
|
|
14
|
+
* its MCP URL) mean nothing to a person here, so they are never passed on. */
|
|
15
|
+
export const RATE_LIMITED = "Free web search is rate-limited right now. Try again in a minute; add the free Parallel Search server in Settings → MCP servers and grant the agent its web_search; or add a Parallel key in Settings → API Keys to search with a key.";
|
|
16
|
+
/** The seconds a Retry-After names, as seconds or a date; undefined when it names none. */
|
|
17
|
+
export function retryAfterOf(response) {
|
|
18
|
+
const said = response.headers.get("retry-after")?.trim();
|
|
19
|
+
if (!said)
|
|
20
|
+
return undefined;
|
|
21
|
+
if (/^\d+$/.test(said))
|
|
22
|
+
return Number(said);
|
|
23
|
+
const at = Date.parse(said);
|
|
24
|
+
return Number.isNaN(at) ? undefined : Math.max(0, Math.ceil((at - Date.now()) / 1000));
|
|
25
|
+
}
|
|
26
|
+
/** `ms` of waiting that `signal` ends, rejecting with its reason. */
|
|
27
|
+
export const sleep = (ms, signal) => new Promise((resolve, reject) => {
|
|
28
|
+
if (signal.aborted)
|
|
29
|
+
return reject(signal.reason);
|
|
30
|
+
const stop = () => {
|
|
31
|
+
clearTimeout(timer);
|
|
32
|
+
reject(signal.reason);
|
|
33
|
+
};
|
|
34
|
+
const timer = setTimeout(() => {
|
|
35
|
+
signal.removeEventListener("abort", stop);
|
|
36
|
+
resolve();
|
|
37
|
+
}, ms);
|
|
38
|
+
signal.addEventListener("abort", stop, { once: true });
|
|
39
|
+
});
|
|
40
|
+
/** At most MAX_BYTES of a body, as text; the rest is not read. */
|
|
41
|
+
async function boundedText(response) {
|
|
42
|
+
const reader = response.body?.getReader();
|
|
43
|
+
const chunks = [];
|
|
44
|
+
for (let size = 0; reader && size < MAX_BYTES;) {
|
|
45
|
+
const { done, value } = await reader.read();
|
|
46
|
+
if (done)
|
|
47
|
+
break;
|
|
48
|
+
chunks.push(value);
|
|
49
|
+
size += value.byteLength;
|
|
50
|
+
}
|
|
51
|
+
await reader?.cancel().catch(() => undefined);
|
|
52
|
+
return Buffer.concat(chunks).subarray(0, MAX_BYTES).toString("utf8");
|
|
53
|
+
}
|
|
54
|
+
/** A body of at most `max` bytes, as text; undefined where it runs past them (the rest is not read). */
|
|
55
|
+
async function cappedText(response, max) {
|
|
56
|
+
const reader = response.body?.getReader();
|
|
57
|
+
const chunks = [];
|
|
58
|
+
for (let size = 0; reader;) {
|
|
59
|
+
const { done, value } = await reader.read();
|
|
60
|
+
if (done)
|
|
61
|
+
break;
|
|
62
|
+
chunks.push(value);
|
|
63
|
+
size += value.byteLength;
|
|
64
|
+
if (size > max) {
|
|
65
|
+
await reader.cancel().catch(() => undefined);
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
70
|
+
}
|
|
71
|
+
/** A JSON-RPC answer's body: JSON, or the `data:` lines of an event stream, the one answering `id`. With `max`, a body
|
|
72
|
+
* past it is "over"; without, its first MAX_BYTES are read. */
|
|
73
|
+
async function answerOf(response, id, max) {
|
|
74
|
+
const text = max === undefined ? await boundedText(response) : await cappedText(response, max);
|
|
75
|
+
if (text === undefined)
|
|
76
|
+
return "over";
|
|
77
|
+
const messages = /event-stream/i.test(response.headers.get("content-type") ?? "")
|
|
78
|
+
? text.split("\n").filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trim())
|
|
79
|
+
: [text];
|
|
80
|
+
for (const message of messages) {
|
|
81
|
+
try {
|
|
82
|
+
const parsed = JSON.parse(message);
|
|
83
|
+
if (parsed.id === id)
|
|
84
|
+
return parsed;
|
|
85
|
+
}
|
|
86
|
+
catch { }
|
|
87
|
+
}
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
/** A tool result's text blocks, joined by lines; empty when it has none. */
|
|
91
|
+
export const textBlocks = (result) => (Array.isArray(result?.content) ? result.content : []).flatMap((part) => (part.type === "text" && typeof part.text === "string" ? [part.text] : [])).join("\n");
|
|
92
|
+
export async function callTool(endpoint, dial, deadline, name, args, maxBytes) {
|
|
93
|
+
let session;
|
|
94
|
+
const post = (body) => dial(endpoint, {
|
|
95
|
+
method: "POST",
|
|
96
|
+
headers: { "content-type": "application/json", accept: ACCEPT, "mcp-protocol-version": PROTOCOL, ...(session ? { "mcp-session-id": session } : {}) },
|
|
97
|
+
body: JSON.stringify({ jsonrpc: "2.0", ...body }),
|
|
98
|
+
signal: deadline,
|
|
99
|
+
});
|
|
100
|
+
const refused = async (response, step) => {
|
|
101
|
+
if (response.ok)
|
|
102
|
+
return undefined;
|
|
103
|
+
await response.body?.cancel().catch(() => undefined);
|
|
104
|
+
const retryAfterS = retryAfterOf(response);
|
|
105
|
+
return { status: response.status, step, ...(retryAfterS === undefined ? {} : { retryAfterS }) };
|
|
106
|
+
};
|
|
107
|
+
const opened = await post({ id: 1, method: "initialize", params: { protocolVersion: PROTOCOL, capabilities: {}, clientInfo: { name: "agentrun-serve", version: "1" } } });
|
|
108
|
+
const failed = await refused(opened, "initialize");
|
|
109
|
+
if (failed)
|
|
110
|
+
return failed;
|
|
111
|
+
session = opened.headers.get("mcp-session-id") ?? undefined;
|
|
112
|
+
const hello = await answerOf(opened, 1);
|
|
113
|
+
if (hello === "over" || !hello?.result)
|
|
114
|
+
return { error: "", rpc: false };
|
|
115
|
+
const ready = await post({ method: "notifications/initialized" });
|
|
116
|
+
await ready.body?.cancel().catch(() => undefined);
|
|
117
|
+
const called = await post({ id: 2, method: "tools/call", params: { name, arguments: args } });
|
|
118
|
+
const late = await refused(called, "the call");
|
|
119
|
+
if (late)
|
|
120
|
+
return late;
|
|
121
|
+
const answer = await answerOf(called, 2, maxBytes);
|
|
122
|
+
if (answer === "over")
|
|
123
|
+
return { over: maxBytes };
|
|
124
|
+
if (answer?.error)
|
|
125
|
+
return { error: typeof answer.error.message === "string" ? answer.error.message : "", rpc: true };
|
|
126
|
+
return { result: answer?.result };
|
|
127
|
+
}
|
package/dist/learn/audit.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Workspace } from "../workspace/index.js";
|
|
|
2
2
|
import type { AuditLoop } from "../learning-setting.js";
|
|
3
3
|
import type { RunLaunch } from "../run-launch.js";
|
|
4
4
|
import { AUDITS_FILE, type FolderChange, type FolderRead } from "./folder.js";
|
|
5
|
-
import { type CostStop, type PromotionRecord, type ServingState } from "./promote.js";
|
|
5
|
+
import { type CostStop, type PromotionRecord, type Refused, type ServingState } from "./promote.js";
|
|
6
6
|
export { AUDITS_FILE };
|
|
7
7
|
/** The newest rows the ledger keeps: twice the widest window a definition may set (AUDIT_MAX), and a file well under the
|
|
8
8
|
* folder's file cap (a line is a few hundred bytes); with them, the started lines of theirs, and every open one. */
|
|
@@ -109,7 +109,7 @@ export declare function auditLineOf(rows: readonly AuditRow[], workflow: string,
|
|
|
109
109
|
/** What the promotions read says of each learned workflow beside what serves (learn/promote.ts servingOf, in its order):
|
|
110
110
|
* `state` (learn/promote.ts servingStateOf with the money rule's decision, `costStop`: the word the learning view's
|
|
111
111
|
* `status` says too), its newest decided check's numbers, and its audit line over the rows of the serving (else the
|
|
112
|
-
* newest) revision's newest promotion (the ones the hold rule counts). */
|
|
112
|
+
* newest) revision's newest promotion (the ones the hold rule counts). Its champions skip `refused` (championOf). */
|
|
113
113
|
export type ServingLine = {
|
|
114
114
|
readonly state: ServingState;
|
|
115
115
|
readonly check: {
|
|
@@ -120,4 +120,4 @@ export type ServingLine = {
|
|
|
120
120
|
} | null;
|
|
121
121
|
readonly audit: AuditLine | null;
|
|
122
122
|
};
|
|
123
|
-
export declare function servingLinesOf(records: readonly PromotionRecord[], rows: readonly AuditRow[], loop: Pick<AuditLoop, "hold_window" | "hold_disagree">, costStop: CostStop): ServingLine[];
|
|
123
|
+
export declare function servingLinesOf(records: readonly PromotionRecord[], rows: readonly AuditRow[], loop: Pick<AuditLoop, "hold_window" | "hold_disagree">, costStop: CostStop, refused?: Refused): ServingLine[];
|
package/dist/learn/audit.js
CHANGED
|
@@ -140,14 +140,14 @@ export function auditLineOf(rows, workflow, digest, promotedAt, loop) {
|
|
|
140
140
|
const counted = windowOf(rows, workflow, digest, promotedAt, loop);
|
|
141
141
|
return { window: loop.hold_window, disagree: loop.hold_disagree, rows: counted.length, disagreed: counted.filter((row) => row.agreed === false).length };
|
|
142
142
|
}
|
|
143
|
-
export function servingLinesOf(records, rows, loop, costStop) {
|
|
144
|
-
return servingOf(records).map(({ workflow, digest }) => {
|
|
143
|
+
export function servingLinesOf(records, rows, loop, costStop, refused) {
|
|
144
|
+
return servingOf(records, refused).map(({ workflow, digest }) => {
|
|
145
145
|
const own = records.filter((one) => one.workflow === workflow);
|
|
146
146
|
const newest = own.at(-1);
|
|
147
147
|
const checked = own.findLast((one) => one.check?.n !== undefined)?.check;
|
|
148
148
|
const at = digest ?? newest?.digest;
|
|
149
149
|
return {
|
|
150
|
-
state: servingStateOf(records, workflow, costStop),
|
|
150
|
+
state: servingStateOf(records, workflow, costStop, refused),
|
|
151
151
|
check: checked ? { n: checked.n, agreed: checked.agreed ?? 0, alone: checked.alone ?? 0, attempt: checked.attempt } : null,
|
|
152
152
|
audit: at === undefined ? null : auditLineOf(rows, workflow, at, promotionStartOf(records, workflow, at)?.at ?? null, loop),
|
|
153
153
|
};
|
package/dist/learn/commit.d.ts
CHANGED
|
@@ -110,14 +110,15 @@ export declare function putCorrections(ws: Workspace, input: {
|
|
|
110
110
|
}>;
|
|
111
111
|
/**
|
|
112
112
|
* Run `runId`'s text taken off the folder's current files, at its purge (agent-delete.ts purgeRun): first its learned
|
|
113
|
-
* workflows (forgetRunWorkflows), whether or not it left a diff file; then the
|
|
114
|
-
* corrections.md, as its diff file keeps them, dropped from main in one host commit
|
|
115
|
-
* since is theirs and stays); each other merge's diff that shows such a line as
|
|
116
|
-
* run's diff files deleted, last, so a call stopped part way finds what it has
|
|
117
|
-
* folder's git history until a learning reset or its agent's purge deletes the
|
|
118
|
-
* lands once, nothing left to drop makes no commit, and a run with no diff file
|
|
113
|
+
* workflows (forgetRunWorkflows; `purged`: whether another run is purged), whether or not it left a diff file; then the
|
|
114
|
+
* lines each of its merges added to corrections.md, as its diff file keeps them, dropped from main in one host commit
|
|
115
|
+
* per merge (a line a person edited since is theirs and stays); each other merge's diff that shows such a line as
|
|
116
|
+
* context written without it; then the run's diff files deleted, last, so a call stopped part way finds what it has
|
|
117
|
+
* left to do. Its merges stay in the folder's git history until a learning reset or its agent's purge deletes the
|
|
118
|
+
* folder. Idempotent: each merge's scrub lands once, nothing left to drop makes no commit, and a run with no diff file
|
|
119
|
+
* and no workflow here is no work.
|
|
119
120
|
* `commit`: the host's last commit, when one was made.
|
|
120
121
|
*/
|
|
121
|
-
export declare function forgetRunText(ws: Workspace, runId: string): Promise<{
|
|
122
|
+
export declare function forgetRunText(ws: Workspace, runId: string, purged: (run: string) => Promise<boolean>): Promise<{
|
|
122
123
|
commit?: string;
|
|
123
124
|
}>;
|