@parcha/agentrun-serve 0.1.0-beta.54 → 0.1.0-beta.56
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 +142 -2
- package/README.md +310 -98
- package/dist/adapters.d.ts +11 -0
- package/dist/adapters.js +49 -0
- package/dist/agent-package.d.ts +3 -3
- package/dist/agent-package.js +6 -13
- package/dist/agents-store.js +6 -5
- package/dist/answer-json.d.ts +6 -2
- package/dist/answer-json.js +22 -4
- package/dist/api-only.d.ts +16 -4
- package/dist/api-only.js +23 -7
- package/dist/calendar/tools.js +3 -2
- package/dist/chatgpt-plan.d.ts +16 -1
- package/dist/chatgpt-plan.js +116 -12
- package/dist/claude-login.d.ts +34 -5
- package/dist/claude-login.js +31 -7
- package/dist/claude-sign-in.d.ts +35 -0
- package/dist/claude-sign-in.js +90 -0
- package/dist/cli.js +5 -3
- package/dist/composio-made.d.ts +26 -1
- package/dist/composio-made.js +39 -2
- package/dist/composio-preset.d.ts +3 -2
- package/dist/composio-preset.js +46 -14
- package/dist/computer-held-routes.js +2 -3
- package/dist/computer-setting.d.ts +4 -2
- package/dist/computer-setting.js +0 -2
- package/dist/computers-running.d.ts +8 -0
- package/dist/computers-running.js +27 -0
- package/dist/console/assets/backend-Boh7tC4i.js +166 -0
- package/dist/console/assets/index-CQ3cJRzI.js +746 -0
- package/dist/console/assets/index-DKkaS3a0.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/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/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 +6 -0
- package/dist/host-check.js +10 -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/key-refusal.d.ts +21 -5
- package/dist/key-refusal.js +231 -37
- 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.d.ts +20 -10
- package/dist/learn/secrets.js +44 -176
- package/dist/learning-routes.d.ts +22 -17
- package/dist/learning-routes.js +40 -39
- package/dist/learning.js +2 -2
- package/dist/llms.txt +1 -1
- 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-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.d.ts +3 -3
- package/dist/openapi.js +197 -55
- package/dist/page.d.ts +11 -3
- package/dist/page.js +22 -7
- package/dist/place-offers.d.ts +25 -1
- package/dist/place-offers.js +62 -8
- package/dist/print.js +1 -1
- package/dist/purged-workflow.d.ts +35 -7
- package/dist/purged-workflow.js +73 -26
- package/dist/redact/match.d.ts +74 -0
- package/dist/redact/match.js +771 -0
- 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/run-timeline-served.d.ts +1 -1
- package/dist/run-timeline-served.js +4 -4
- package/dist/runner/adapter-loop.d.ts +9 -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 +9 -4
- package/dist/runner/audit.js +8 -4
- package/dist/runner/beside.d.ts +2 -1
- package/dist/runner/beside.js +13 -5
- 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 +41 -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 +9 -4
- package/dist/runner/main.js +12 -6
- 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 -10
- package/dist/runner/metrics.js +19 -38
- package/dist/runner/model-route.d.ts +3 -0
- package/dist/runner/model-route.js +6 -2
- package/dist/runner/presence.d.ts +4 -3
- package/dist/runner/presence.js +4 -2
- package/dist/runner/promotion.d.ts +15 -9
- package/dist/runner/promotion.js +25 -15
- package/dist/runner/run-child-host.d.ts +2 -0
- package/dist/runner/run-child-host.js +19 -9
- package/dist/runner/run-child.js +3 -1
- package/dist/runner/runner.d.ts +4 -0
- package/dist/runner/runner.js +33 -3
- 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 +49 -10
- package/dist/server.js +324 -118
- package/dist/standard-webhooks.d.ts +11 -0
- package/dist/standard-webhooks.js +20 -2
- package/dist/store/dialect.d.ts +3 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/postgres/dialect.js +3 -0
- package/dist/store/schema.js +5 -2
- package/dist/store/sqlite/store.js +133 -47
- package/dist/store/store.d.ts +64 -15
- package/dist/store/store.js +7 -0
- 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 +10 -9
- package/dist/template-eval.d.ts +51 -6
- package/dist/template-eval.js +177 -53
- package/dist/template-import.js +4 -2
- package/dist/templates.d.ts +5 -3
- package/dist/templates.js +19 -40
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/labels.d.ts +2 -2
- package/dist/timeline/labels.js +2 -2
- package/dist/timeline/timeline.d.ts +14 -9
- package/dist/timeline/timeline.js +15 -7
- package/dist/tool-gate.js +3 -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 +16 -8
- package/dist/trigger-launch-hook.js +32 -23
- 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.js +1 -1
- 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/computer-deps.d.ts +2 -1
- package/dist/workspace/computer-deps.js +5 -4
- package/dist/workspace/computer-for-claim.d.ts +8 -2
- package/dist/workspace/computer-for-claim.js +28 -9
- package/dist/workspace/computer-janitor.d.ts +15 -7
- package/dist/workspace/computer-janitor.js +33 -8
- package/dist/workspace/computer-kept.d.ts +52 -4
- package/dist/workspace/computer-kept.js +118 -6
- package/dist/workspace/run-end-computers.d.ts +5 -1
- package/dist/workspace/run-end-computers.js +27 -1
- package/dist/wrapped.d.ts +57 -0
- package/dist/wrapped.js +51 -0
- package/launcher/agentrun-serve +5 -1
- package/package.json +17 -13
- package/templates/README.md +10 -9
- package/dist/console/assets/index-B_85An2t.js +0 -745
- package/dist/console/assets/index-n1YsbnYh.css +0 -1
- package/dist/import-sources.d.ts +0 -116
- package/dist/import-sources.js +0 -693
package/dist/import.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type StorageWrite } from "@earendil-works/pi-durable";
|
|
2
2
|
import { type EntryLike } from "./timeline/index.js";
|
|
3
|
-
import { type Session, type Source } from "
|
|
3
|
+
import { type Locator, type Session, type Source } from "@parcha/agentrun-import";
|
|
4
4
|
import { type Found } from "./import-summary.js";
|
|
5
5
|
import { type Store } from "./store/index.js";
|
|
6
6
|
/** What `runImport`, `planImport` and the CLI reach of the server's open store: the agents it reads and writes, the runs it
|
|
@@ -111,8 +111,8 @@ export type ProjectPlan = {
|
|
|
111
111
|
sessions: Session[];
|
|
112
112
|
};
|
|
113
113
|
/** `already`: the session files an earlier import took whole, left unread; `held`, the runs an import would not take
|
|
114
|
-
* again: theirs, and (when measuring) those of planned sessions the store holds already. `children`: the
|
|
115
|
-
* session's subagents, whose usage is its run's: Claude Code's by the session file beside them, Codex's by `source:thread`; `untied`, those of subagents whose file names
|
|
114
|
+
* again: theirs, and (when measuring) those of planned sessions the store holds already. `children`: the locators of each
|
|
115
|
+
* session's subagents, whose usage is its run's: Claude Code's by the locator (locatorKey) of the session file beside them, Codex's by `source:thread`; `untied`, those of subagents whose file names
|
|
116
116
|
* no parent, counted in a summary's totals alone. `found`: each other planned session measured,
|
|
117
117
|
* when the plan was made to (`measure`). `stopped`: `signal` ended the listing with session files still unlisted. */
|
|
118
118
|
export type Plan = {
|
|
@@ -120,9 +120,9 @@ export type Plan = {
|
|
|
120
120
|
skipped: Skipped[];
|
|
121
121
|
already: number;
|
|
122
122
|
held: string[];
|
|
123
|
-
children: Map<string,
|
|
123
|
+
children: Map<string, Locator[]>;
|
|
124
124
|
untied: {
|
|
125
|
-
|
|
125
|
+
locator: Locator;
|
|
126
126
|
source: Source;
|
|
127
127
|
}[];
|
|
128
128
|
found?: Found[];
|
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,
|
package/dist/key-refusal.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare function runKeyOf(env: NodeJS.ProcessEnv, harness?: string, ref?:
|
|
|
17
17
|
* form (6 times it, for JSON's \uXXXX; percent is 3, hex 2, base64 4/3) and 16 more. A key whose start the cut can show
|
|
18
18
|
* starts before SHOWN, so it ends inside that head and is found whole; one that starts later is never shown. So a long
|
|
19
19
|
* error costs no more to redact than a short one, whatever it holds. `shown`: a head of another length, for a reader
|
|
20
|
-
* that is shown more
|
|
20
|
+
* that is shown more. */
|
|
21
21
|
export declare function redacted(text: string, secrets: readonly string[], shown?: number): string;
|
|
22
22
|
/** How many texts redactedAnswer has read in this process: a test reads it to see a run's view served from what an
|
|
23
23
|
* earlier view redacted (runs.ts servedOnce). */
|
|
@@ -28,11 +28,27 @@ export declare const answerPasses: {
|
|
|
28
28
|
* in it, and NEVER cut: an answer is shown whole. The same rule as redacted() (redactSecrets over `secrets`), over the
|
|
29
29
|
* whole text, read in pieces of about ANSWER_PIECE characters cut at whitespace. No form of a held value redactSecrets
|
|
30
30
|
* finds as it stands (as written, JSON-escaped, base64, hex) holds whitespace, so a cut there splits none; the one shape
|
|
31
|
-
* read across whitespace, a Bearer scheme and its token, is never cut between the two (endsInScheme). A run
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
31
|
+
* read across whitespace, a Bearer scheme and its token, is never cut between the two (endsInScheme). A run with no
|
|
32
|
+
* whitespace past a piece is cut at the end of a JSON string in it (never in a URL's user and password), or, a run of
|
|
33
|
+
* a JSON array's numbers only, after a comma (runCut), so compact JSON reads in pieces too. A run of more than ANSWER_PIECE characters with neither is no
|
|
34
|
+
* person's text and is shown as "[redacted]", unread, from where its run starts. A value or a secret shape split across
|
|
35
|
+
* a cut, or a form only found across pieces, still shows to one pass over the joined pieces (heldIn: valueLeft over
|
|
36
|
+
* them as they came, and secretShapes over them redacted; with the head of each run left unread, where the rest of a
|
|
37
|
+
* value split before it would be), and then the whole answer is "[redacted]", as redactSecrets does with a text that
|
|
38
|
+
* still holds a value. So is an answer whose pieces, as shown, read as a held value together (heldIn reads the text it
|
|
39
|
+
* returns too). A value split inside one piece withholds only that piece, by the piece's own redaction. */
|
|
35
40
|
export declare function redactedAnswer(text: string, secrets: readonly string[]): string;
|
|
41
|
+
/** `text`, a call's result as a grader's read shows it (timeline calls, tool_result_text), with no held secret in it:
|
|
42
|
+
* read in pieces as redactedAnswer reads an answer, each piece redacted, then shown as `show` makes it (the timeline's
|
|
43
|
+
* scrubUrls), then one pass over the pieces (heldIn). Every check reads the text as it came, redacted, and not only as
|
|
44
|
+
* shown: shown, a URL's query, fragment and userinfo are cut apart, and a held value in one no longer reads as itself;
|
|
45
|
+
* what it returns is read too, for a held value its pieces show only together. A piece
|
|
46
|
+
* never splits a URL (it is cut at whitespace, after a quote, or in a run of numbers), so a piece shows as the whole
|
|
47
|
+
* text would. Only the head the reader is shown is read: pieces stop once they show more than `shown` characters, and
|
|
48
|
+
* the pass also reads the text where they stopped (peek), so a value or a shape the stop split is seen whole. Every
|
|
49
|
+
* character returned was read; the caller cuts it to `shown`. So no redaction pass reads more than a piece, however long
|
|
50
|
+
* the result or its head. */
|
|
51
|
+
export declare function redactedCall(text: string, secrets: readonly string[], shown: number, show?: (piece: string) => string): string;
|
|
36
52
|
/** Whether a number shows a held value. A held value can be all digits (a gateway's key), and a record or a call's
|
|
37
53
|
* arguments can quote it as a number: one whose digits hold a held value, by the same rule as a string's, is held. A
|
|
38
54
|
* number can also EQUAL a held value whose text differs from its own (a leading zero, 1e21, a long key read lossy). A
|