@parcha/agentrun-serve 0.0.0-stage → 0.1.0-beta.29

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.
Files changed (229) hide show
  1. package/CHANGELOG.md +560 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +5 -0
  4. package/README.md +1723 -2
  5. package/dist/adapters.d.ts +205 -0
  6. package/dist/adapters.js +459 -0
  7. package/dist/agents.d.ts +124 -0
  8. package/dist/agents.js +302 -0
  9. package/dist/app.d.ts +7 -0
  10. package/dist/app.js +324 -0
  11. package/dist/bound-files.d.ts +4 -0
  12. package/dist/bound-files.js +164 -0
  13. package/dist/box/record.d.ts +6 -0
  14. package/dist/box/record.js +41 -0
  15. package/dist/box/sweep.d.ts +53 -0
  16. package/dist/box/sweep.js +193 -0
  17. package/dist/box-image.d.ts +98 -0
  18. package/dist/box-image.js +283 -0
  19. package/dist/box-relay.d.ts +42 -0
  20. package/dist/box-relay.js +222 -0
  21. package/dist/boxes.d.ts +54 -0
  22. package/dist/boxes.js +182 -0
  23. package/dist/cap.d.ts +224 -0
  24. package/dist/cap.js +721 -0
  25. package/dist/catalog.d.ts +20 -0
  26. package/dist/catalog.js +53 -0
  27. package/dist/cli.d.ts +2 -0
  28. package/dist/cli.js +167 -0
  29. package/dist/coding-tools.d.ts +31 -0
  30. package/dist/coding-tools.js +81 -0
  31. package/dist/console/THIRD-PARTY-NOTICES.txt +1141 -0
  32. package/dist/console/assets/index-BN7oVcO4.js +445 -0
  33. package/dist/console/assets/index-By-jkqki.css +1 -0
  34. package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
  35. package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-CIEtRijs.woff +0 -0
  36. package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-BB5xRk30.woff +0 -0
  37. package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-EVf6-Yzo.woff2 +0 -0
  38. package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-BHyURHCj.woff +0 -0
  39. package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-C_uLvvQ5.woff2 +0 -0
  40. package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-Dj6eZy5f.woff2 +0 -0
  41. package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-DpeVePZf.woff +0 -0
  42. package/dist/console/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
  43. package/dist/console/assets/jetbrains-mono-greek-400-normal-CNojz0t3.woff +0 -0
  44. package/dist/console/assets/jetbrains-mono-greek-600-normal-3KAm9r92.woff +0 -0
  45. package/dist/console/assets/jetbrains-mono-greek-600-normal-H7WoG9Et.woff2 +0 -0
  46. package/dist/console/assets/jetbrains-mono-latin-400-normal-B11XCQ5g.woff +0 -0
  47. package/dist/console/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
  48. package/dist/console/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
  49. package/dist/console/assets/jetbrains-mono-latin-600-normal-DXv3JcnD.woff +0 -0
  50. package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
  51. package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-DHMOLxAi.woff +0 -0
  52. package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
  53. package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-DiQlUoE6.woff +0 -0
  54. package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-BeU3T8wf.woff +0 -0
  55. package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-ByoDsISC.woff2 +0 -0
  56. package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-CSpzN4cI.woff +0 -0
  57. package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-Dtizs43-.woff2 +0 -0
  58. package/dist/console/assets/schibsted-grotesk-latin-400-normal-Cph9ettZ.woff2 +0 -0
  59. package/dist/console/assets/schibsted-grotesk-latin-400-normal-DfGZKnlb.woff +0 -0
  60. package/dist/console/assets/schibsted-grotesk-latin-600-normal-BGBUNdzT.woff2 +0 -0
  61. package/dist/console/assets/schibsted-grotesk-latin-600-normal-COje25QW.woff +0 -0
  62. package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-4l4lq8zr.woff2 +0 -0
  63. package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-BGzXWJeR.woff +0 -0
  64. package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-8_E36CQj.woff2 +0 -0
  65. package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-C27an7Zc.woff +0 -0
  66. package/dist/console/index.html +15 -0
  67. package/dist/daytona-api.d.ts +21 -0
  68. package/dist/daytona-api.js +101 -0
  69. package/dist/decision-rows.d.ts +11 -0
  70. package/dist/decision-rows.js +116 -0
  71. package/dist/decisions.d.ts +94 -0
  72. package/dist/decisions.js +184 -0
  73. package/dist/effort-guidance.d.ts +5 -0
  74. package/dist/effort-guidance.js +14 -0
  75. package/dist/environment.d.ts +5 -0
  76. package/dist/environment.js +11 -0
  77. package/dist/errors.d.ts +72 -0
  78. package/dist/errors.js +66 -0
  79. package/dist/exa-keyless.d.ts +35 -0
  80. package/dist/exa-keyless.js +202 -0
  81. package/dist/fetch-page.d.ts +114 -0
  82. package/dist/fetch-page.js +182 -0
  83. package/dist/files.d.ts +60 -0
  84. package/dist/files.js +153 -0
  85. package/dist/grade.d.ts +96 -0
  86. package/dist/grade.js +348 -0
  87. package/dist/graph-view.d.ts +100 -0
  88. package/dist/graph-view.js +212 -0
  89. package/dist/harness-app.d.ts +38 -0
  90. package/dist/harness-app.js +626 -0
  91. package/dist/harness.d.ts +53 -0
  92. package/dist/harness.js +74 -0
  93. package/dist/home-path.d.ts +27 -0
  94. package/dist/home-path.js +78 -0
  95. package/dist/host-tools.d.ts +20 -0
  96. package/dist/host-tools.js +140 -0
  97. package/dist/host.d.ts +39 -0
  98. package/dist/host.js +81 -0
  99. package/dist/hosted-search.d.ts +27 -0
  100. package/dist/hosted-search.js +129 -0
  101. package/dist/import-sources.d.ts +104 -0
  102. package/dist/import-sources.js +629 -0
  103. package/dist/import-summary.d.ts +25 -0
  104. package/dist/import-summary.js +75 -0
  105. package/dist/import-worker.d.ts +26 -0
  106. package/dist/import-worker.js +41 -0
  107. package/dist/import.d.ts +145 -0
  108. package/dist/import.js +1221 -0
  109. package/dist/index.d.ts +7 -0
  110. package/dist/index.js +6 -0
  111. package/dist/key-check.d.ts +36 -0
  112. package/dist/key-check.js +108 -0
  113. package/dist/key-refusal.d.ts +51 -0
  114. package/dist/key-refusal.js +187 -0
  115. package/dist/learn/check.d.ts +99 -0
  116. package/dist/learn/check.js +259 -0
  117. package/dist/learn/grade.d.ts +79 -0
  118. package/dist/learn/grade.js +433 -0
  119. package/dist/learn/index.d.ts +7 -0
  120. package/dist/learn/index.js +11 -0
  121. package/dist/learn/invisible.d.ts +5 -0
  122. package/dist/learn/invisible.js +42 -0
  123. package/dist/learn/notes.d.ts +59 -0
  124. package/dist/learn/notes.js +146 -0
  125. package/dist/learn/reflect.d.ts +49 -0
  126. package/dist/learn/reflect.js +167 -0
  127. package/dist/learn/secrets.d.ts +18 -0
  128. package/dist/learn/secrets.js +111 -0
  129. package/dist/learn/skills.d.ts +84 -0
  130. package/dist/learn/skills.js +198 -0
  131. package/dist/learning-routes.d.ts +196 -0
  132. package/dist/learning-routes.js +609 -0
  133. package/dist/learning-run.d.ts +304 -0
  134. package/dist/learning-run.js +797 -0
  135. package/dist/learning-words.d.ts +73 -0
  136. package/dist/learning-words.js +171 -0
  137. package/dist/learning.d.ts +377 -0
  138. package/dist/learning.js +801 -0
  139. package/dist/llm.d.ts +40 -0
  140. package/dist/llm.js +37 -0
  141. package/dist/llms.txt +37 -0
  142. package/dist/mcp-servers.d.ts +115 -0
  143. package/dist/mcp-servers.js +445 -0
  144. package/dist/mcp.d.ts +51 -0
  145. package/dist/mcp.js +392 -0
  146. package/dist/model.d.ts +184 -0
  147. package/dist/model.js +484 -0
  148. package/dist/monid.d.ts +74 -0
  149. package/dist/monid.js +277 -0
  150. package/dist/openapi/agentrun-v2.openapi.json +4805 -0
  151. package/dist/openapi.d.ts +10 -0
  152. package/dist/openapi.js +1417 -0
  153. package/dist/owner.d.ts +55 -0
  154. package/dist/owner.js +222 -0
  155. package/dist/packs.d.ts +71 -0
  156. package/dist/packs.js +180 -0
  157. package/dist/page.d.ts +32 -0
  158. package/dist/page.js +133 -0
  159. package/dist/paid-calls.d.ts +46 -0
  160. package/dist/paid-calls.js +110 -0
  161. package/dist/pause.d.ts +68 -0
  162. package/dist/pause.js +97 -0
  163. package/dist/pdf-pages.d.ts +44 -0
  164. package/dist/pdf-pages.js +147 -0
  165. package/dist/place.d.ts +46 -0
  166. package/dist/place.js +105 -0
  167. package/dist/print.d.ts +20 -0
  168. package/dist/print.js +29 -0
  169. package/dist/propose.d.ts +38 -0
  170. package/dist/propose.js +82 -0
  171. package/dist/quiet-sqlite-warning.d.ts +1 -0
  172. package/dist/quiet-sqlite-warning.js +14 -0
  173. package/dist/request-start.d.ts +14 -0
  174. package/dist/request-start.js +226 -0
  175. package/dist/result.d.ts +3 -0
  176. package/dist/result.js +5 -0
  177. package/dist/rows.d.ts +46 -0
  178. package/dist/rows.js +121 -0
  179. package/dist/run-box.d.ts +134 -0
  180. package/dist/run-box.js +440 -0
  181. package/dist/run-manifest.d.ts +27 -0
  182. package/dist/run-manifest.js +60 -0
  183. package/dist/runnable.d.ts +80 -0
  184. package/dist/runnable.js +162 -0
  185. package/dist/runs.d.ts +840 -0
  186. package/dist/runs.js +2279 -0
  187. package/dist/secret-cut.d.ts +27 -0
  188. package/dist/secret-cut.js +109 -0
  189. package/dist/secrets.d.ts +50 -0
  190. package/dist/secrets.js +140 -0
  191. package/dist/server-lock.d.ts +44 -0
  192. package/dist/server-lock.js +140 -0
  193. package/dist/server.d.ts +626 -0
  194. package/dist/server.js +1756 -0
  195. package/dist/sessions.d.ts +4 -0
  196. package/dist/sessions.js +105 -0
  197. package/dist/skills.d.ts +31 -0
  198. package/dist/skills.js +68 -0
  199. package/dist/stats.d.ts +101 -0
  200. package/dist/stats.js +82 -0
  201. package/dist/tool-keys.d.ts +151 -0
  202. package/dist/tool-keys.js +273 -0
  203. package/dist/tool-plane.d.ts +143 -0
  204. package/dist/tool-plane.js +242 -0
  205. package/dist/tools.d.ts +147 -0
  206. package/dist/tools.js +253 -0
  207. package/dist/turn-end.d.ts +23 -0
  208. package/dist/turn-end.js +14 -0
  209. package/dist/turns.d.ts +34 -0
  210. package/dist/turns.js +202 -0
  211. package/dist/uploads.d.ts +104 -0
  212. package/dist/uploads.js +474 -0
  213. package/dist/usage.d.ts +29 -0
  214. package/dist/usage.js +58 -0
  215. package/dist/validate.d.ts +55 -0
  216. package/dist/validate.js +175 -0
  217. package/dist/web-fetch.d.ts +64 -0
  218. package/dist/web-fetch.js +262 -0
  219. package/dist/web-search.d.ts +54 -0
  220. package/dist/web-search.js +136 -0
  221. package/dist/webhooks.d.ts +182 -0
  222. package/dist/webhooks.js +487 -0
  223. package/dist/workspace-paths.d.ts +33 -0
  224. package/dist/workspace-paths.js +104 -0
  225. package/dist/workspace.d.ts +88 -0
  226. package/dist/workspace.js +369 -0
  227. package/launcher/agentrun-serve +109 -0
  228. package/package.json +94 -4
  229. package/skills/agentrun-serve/SKILL.md +128 -0
@@ -0,0 +1,75 @@
1
+ // The lines an import ends with: how many sessions it found and from where, how many agents they make, and what they
2
+ // used, from every session found, those imported before included. A number with no data behind it reads unknown.
3
+ import { existsSync } from "node:fs";
4
+ import { SOURCES } from "./import-sources.js";
5
+ const NAMES = { "claude-code": "Claude Code", codex: "Codex", pi: "pi" };
6
+ /** Requests by local hour of the day, from their times (ms). */
7
+ export function hoursOf(times) {
8
+ const hours = new Array(24).fill(0);
9
+ for (const at of times)
10
+ if (Number.isFinite(at))
11
+ hours[new Date(at).getHours()] += 1;
12
+ return hours;
13
+ }
14
+ /** An imported run of `store`, as found: its metrics as the store keeps them, and its requests' times from its transcript,
15
+ * read by SQLite's JSON functions (no record is parsed here). Undefined for a run the store does not hold as imported. */
16
+ export async function foundIn(store, runId) {
17
+ const run = store.readRun(runId);
18
+ if (!run?.importedFrom)
19
+ return undefined;
20
+ const metrics = store.runMetrics(runId);
21
+ const file = store.runStorePath(runId);
22
+ let hours;
23
+ if (existsSync(file)) {
24
+ const { DatabaseSync } = await import("node:sqlite");
25
+ const db = new DatabaseSync(file, { readOnly: true });
26
+ try {
27
+ const rows = db.prepare("SELECT json_extract(record, '$.model[0].timestamp') AS at FROM entries WHERE json_extract(record, '$.kind') = 'pi.assistant'").all();
28
+ hours = hoursOf(rows.map((row) => Number(row.at)));
29
+ }
30
+ finally {
31
+ db.close();
32
+ }
33
+ }
34
+ return { source: run.importedFrom.source, agent: run.agent, ...(metrics ? { metrics } : {}), ...(hours ? { hours } : {}) };
35
+ }
36
+ const count = (n) => n.toLocaleString("en-US");
37
+ const compact = new Intl.NumberFormat("en-US", { notation: "compact", maximumFractionDigits: 1 });
38
+ const plural = (n, one) => `${count(n)} ${one}${n === 1 ? "" : "s"}`;
39
+ /** The summary's lines for `found`, ending with where to open the server (`open`, its address). `dryRun`: what an import
40
+ * would take, nothing taken yet. */
41
+ export function summaryLines(everything, open, { dryRun = false } = {}) {
42
+ // Sessions, agents, time and hours are the sessions'; tokens and tool calls take in the untied subagents' too.
43
+ const found = everything.filter((f) => !f.untied);
44
+ const by = SOURCES.map((source) => [source, found.filter((f) => f.source === source).length]).filter(([, n]) => n > 0);
45
+ const agents = new Set(found.map((f) => f.agent)).size;
46
+ const measured = everything.flatMap((f) => (f.metrics ? [f.metrics] : []));
47
+ const sum = (of) => measured.reduce((n, m) => n + of(m), 0);
48
+ const prompt = sum((m) => m.input + m.cacheRead + m.cacheWrite);
49
+ const tokens = prompt + sum((m) => m.output);
50
+ const timed = found.flatMap((f) => (f.metrics?.activeMs !== undefined ? [f.metrics] : []));
51
+ const hours = timed.reduce((n, m) => n + m.activeMs, 0) / 3_600_000;
52
+ const unknown = found.filter((f) => !f.metrics).length;
53
+ const used = [
54
+ tokens > 0 ? `${compact.format(tokens)} tokens (${prompt ? Math.round((100 * sum((m) => m.cacheRead)) / prompt) : 0}% cached)` : "tokens unknown",
55
+ timed.length ? `${hours < 10 ? hours.toFixed(1) : count(Math.round(hours))} h of agent time` : "agent time unknown",
56
+ ...(unknown && measured.length ? [`${plural(unknown, "session")} unknown`] : []),
57
+ ];
58
+ // The hour of the day (local time) with the most requests, the earliest of a tie.
59
+ const byHour = found.reduce((all, f) => (f.hours ? all.map((n, h) => n + f.hours[h]) : all), new Array(24).fill(0));
60
+ const busiest = byHour.some((n) => n > 0) ? byHour.indexOf(Math.max(...byHour)) : undefined;
61
+ const calls = new Map();
62
+ for (const m of measured)
63
+ for (const [name, tool] of Object.entries(m.tools))
64
+ calls.set(name, (calls.get(name) ?? 0) + tool.calls);
65
+ const total = [...calls.values()].reduce((n, c) => n + c, 0);
66
+ const [top, topCalls] = [...calls].sort(([a, x], [b, y]) => y - x || a.localeCompare(b))[0] ?? [];
67
+ const tool = !measured.length ? "unknown" : top === undefined || !total ? "none" : `${top} (${Math.round((100 * topCalls) / total)}%)`;
68
+ return [
69
+ `Found ${plural(found.length, "session")}${by.length ? ` ${by.map(([source, n]) => `${NAMES[source]} ${count(n)}`).join(" · ")}` : ""}`,
70
+ `${dryRun ? "Would import into" : "Imported into"} ${plural(agents, "agent")} (one per project)`,
71
+ `+ ${used.join(" · ")}`,
72
+ `+ Busiest hour: ${busiest === undefined ? "unknown" : `${String(busiest).padStart(2, "0")}:00`} · top tool: ${tool}`,
73
+ `Open ${open}/`,
74
+ ];
75
+ }
@@ -0,0 +1,26 @@
1
+ import "./quiet-sqlite-warning.js";
2
+ /** `secrets`: the server's own, and `stored`: the keys saved on its Tool keys page (tool-keys.ts' `values`), both cut
3
+ * out of everything the import writes; never put in an environment. */
4
+ export type ImportTask = {
5
+ task: "plan" | "import";
6
+ data: string;
7
+ home: string;
8
+ temp?: string;
9
+ secrets?: Record<string, string>;
10
+ stored?: Record<string, string>;
11
+ };
12
+ /** `took`: what this start's import took (stopped too: what it took before it stopped), its agents by id, so the server
13
+ * adds it to what earlier starts took. */
14
+ export type ImportAnswer = {
15
+ projects: number;
16
+ sessions: number;
17
+ } | {
18
+ took: {
19
+ agents: string[];
20
+ runs: number;
21
+ skipped: number;
22
+ };
23
+ stopped?: true;
24
+ } | {
25
+ stopped: true;
26
+ };
@@ -0,0 +1,41 @@
1
+ // Setup's import of this machine's sessions, on a worker thread: node:sqlite's wait for a busy store and the parsing of
2
+ // every session line happen here, so neither holds up a request the server answers. `plan` counts what an import would
3
+ // take; `import` takes it. The message "stop" ends either between two files or two sessions; what is written stays, and
4
+ // the next import goes on from there. Its one message back is its answer.
5
+ // Before anything loads node:sqlite, as in the server's own thread: its ExperimentalWarning is not the server's to print.
6
+ import "./quiet-sqlite-warning.js";
7
+ import { parentPort, workerData } from "node:worker_threads";
8
+ import { openStore } from "@parcha/pi-durable-agent";
9
+ import { ownSecrets, planImport, runImport } from "./import.js";
10
+ const { task, data, home, temp, secrets = {}, stored = {} } = workerData;
11
+ const stop = new AbortController();
12
+ parentPort.on("message", (message) => void (message === "stop" && stop.abort()));
13
+ // The port does not keep the thread alive: the task does, and the thread ends with it.
14
+ parentPort.unref();
15
+ // The values to cut: this thread's environment (the server's, which holds none of its secrets) with the server's secrets as
16
+ // properties that do not enumerate, as secrets.ts's withSecrets gives them: read by name, left out of a spread or a spawn.
17
+ const env = { ...process.env };
18
+ for (const [name, value] of Object.entries(secrets))
19
+ Object.defineProperty(env, name, { value, enumerable: false });
20
+ const options = { home, ...(temp ? { temp } : {}), env, stored, signal: stop.signal };
21
+ const answer = async () => {
22
+ if (task === "plan") {
23
+ // A count keeps no transcript: no key scan (a whole history read through secretlint at every start).
24
+ const plan = await planImport({ ...options, keys: false });
25
+ // Sessions as the import takes them: a session written in several files (a resumed thread) is one run.
26
+ return stop.signal.aborted ? { stopped: true } : { projects: plan.projects.length, sessions: plan.projects.reduce((n, p) => n + new Set(p.sessions.map((s) => `${s.source}:${s.id}`)).size, 0) };
27
+ }
28
+ // A connection of its own, which may wait for the store: only this thread waits.
29
+ const store = openStore(data);
30
+ try {
31
+ // The secrets this server made and keeps, read as the import starts: cut by their values too.
32
+ const taking = { ...options, own: ownSecrets(data, env) };
33
+ const report = await runImport(store, await planImport(taking, store), taking);
34
+ const took = { agents: report.agents.filter((a) => a.runs + a.finished > 0).map((a) => a.id), runs: report.agents.reduce((n, a) => n + a.runs + a.finished, 0), skipped: report.skipped.length };
35
+ return stop.signal.aborted ? { took, stopped: true } : { took };
36
+ }
37
+ finally {
38
+ store.close();
39
+ }
40
+ };
41
+ parentPort.postMessage(await answer());
@@ -0,0 +1,145 @@
1
+ import { type AgentStore, type AgentStoreReader } from "@parcha/pi-durable-agent";
2
+ import { type Session, type Source } from "./import-sources.js";
3
+ import { type Found } from "./import-summary.js";
4
+ /** In the data directory while an import the owner asked for at setup has not ended: the server's next start goes on with it. */
5
+ export declare const IMPORT_ASKED = ".import-at-setup";
6
+ /** A session file written to this recently may still be running: it is left for a later import. */
7
+ export declare const LIVE_MS: number;
8
+ /** The most of one session file read. */
9
+ export declare const MAX_SESSION_BYTES: number;
10
+ /** The most of one instructions or skill file read, and of one agent's skill files together. */
11
+ export declare const MAX_FILE_BYTES: number;
12
+ export declare const MAX_SKILL_BYTES: number;
13
+ /** The project's skill folders, each `<dir>/<name>/` with its SKILL.md, by where each harness keeps them. */
14
+ export declare const SKILL_DIRS: string[];
15
+ export type ImportOptions = {
16
+ /** The home whose sessions are read (the person's own). */
17
+ home: string;
18
+ sources?: readonly Source[];
19
+ /** Keep projects whose directory is gone or under the temp directory, and sessions with no message of the person's. */
20
+ all?: boolean;
21
+ /** Keep projects whose directory is gone (a deleted worktree's, a moved checkout's): each still its own agent, with no
22
+ * instructions or skills to read. */
23
+ deleted?: boolean;
24
+ /** The environment whose key-shaped values are cut out of everything written. */
25
+ env: NodeJS.ProcessEnv;
26
+ /** The tool keys saved through the settings API, opened (tool-keys.ts' `values`): cut out by the same rule. */
27
+ stored?: Record<string, string>;
28
+ /** The secrets this server made and keeps (`ownSecrets`), cut out by their values as the environment's are. */
29
+ own?: readonly string[];
30
+ now?: number;
31
+ /** The temp directory whose projects are left out (default the OS's). */
32
+ temp?: string;
33
+ /** Stops the import between two session files, planned or taken (a server shutting down): what is written stays, and
34
+ * the next import goes on from there. */
35
+ signal?: AbortSignal;
36
+ /** Each key secretlint finds, as it finds it: for what the CLI prints, cut with the keys the import cuts. */
37
+ onKeys?: (keys: readonly string[]) => void;
38
+ /** Read each session file through secretlint for the cut (default). Setup's count sets it false: a count keeps no
39
+ * transcript, so it reads none, and a server's start never scans a whole history to say how many sessions it has. */
40
+ keys?: boolean;
41
+ /** Read each session's turns while planning, and measure it (`Plan.found`): what a dry run's summary counts. */
42
+ measure?: boolean;
43
+ };
44
+ /** Why a session file or a project's file is left out, by kind, as the left-out counts group them (leftOutLines). */
45
+ export type LeftOut = "gone" | "temp" | "live" | "large" | "unread" | "no-project" | "no-words" | "copies" | "vanished" | "file";
46
+ /** `session`, when the file was read: the session it holds (`<source>:<id>`), so a session of two files (a resumed Codex
47
+ * thread) is counted once. */
48
+ export type Skipped = {
49
+ what: string;
50
+ why: string;
51
+ kind: LeftOut;
52
+ session?: string;
53
+ };
54
+ export type ProjectPlan = {
55
+ cwd: string;
56
+ agentId: string;
57
+ name: string;
58
+ sessions: Session[];
59
+ };
60
+ /** `already`: the session files an earlier import took whole, left unread; `held`, the runs an import would not take
61
+ * again: theirs, and (when measuring) those of planned sessions the store holds already. `children`: the files of each
62
+ * 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
63
+ * no parent, counted in a summary's totals alone. `found`: each other planned session measured,
64
+ * when the plan was made to (`measure`). */
65
+ export type Plan = {
66
+ projects: ProjectPlan[];
67
+ skipped: Skipped[];
68
+ already: number;
69
+ held: string[];
70
+ children: Map<string, string[]>;
71
+ untied: {
72
+ file: string;
73
+ source: Source;
74
+ }[];
75
+ found?: Found[];
76
+ secretsFound?: number;
77
+ };
78
+ export type ImportReport = {
79
+ agents: {
80
+ id: string;
81
+ name: string;
82
+ cwd: string;
83
+ created: boolean;
84
+ runs: number;
85
+ already: number;
86
+ /** Imports an earlier one left without their transcript, finished now. */
87
+ finished: number;
88
+ }[];
89
+ skipped: Skipped[];
90
+ already: number;
91
+ /** Keys and tokens cut out of what it wrote (secret-cut.ts): the environment's values, the saved keys, and those of a
92
+ * known format secretlint found. */
93
+ secretsRemoved?: number;
94
+ };
95
+ export declare const agentIdOf: (cwd: string) => string;
96
+ /** What an import would take: the sessions under `home`, by project, with what it leaves out and why. Keeps no turns
97
+ * (with `measure`, only until each session is measured), and reads no file `store`'s imports already read whole and
98
+ * that has not changed since. */
99
+ export declare function planImport({ home, sources, all, deleted, now, temp: tempDir, measure, env, stored, own, signal, keys: scan, onKeys }: ImportOptions, store?: AgentStoreReader): Promise<Plan>;
100
+ /** The subagents tied to no session: each one's tokens and tool calls, for a summary's totals, each response once. */
101
+ export declare function untiedFound(plan: Plan): Promise<Found[]>;
102
+ /** The sessions `files` write, as the import takes them: one per source and session id, however many files write it
103
+ * (`byRun`), with its cost known when each of its files' is (as `merged` prices it). What a dry run counts. */
104
+ export declare const sessionsOf: (files: readonly Session[]) => {
105
+ source: Source;
106
+ key: `${Source}:${string}`;
107
+ priced: boolean;
108
+ }[];
109
+ /** A project's instructions file and skill folders, read through no link and within their caps. Each file left out is
110
+ * in `skipped`, named, with why: a link, not text, over its cap, or a folder with no SKILL.md. */
111
+ export declare function projectFiles(cwd: string, skipped: Skipped[]): Promise<{
112
+ instructions: Record<string, string>;
113
+ skills: Record<string, string>;
114
+ }>;
115
+ /** The secrets this server made and keeps in data directory `data`, by value: its API token (`ar_local_...`) and its
116
+ * door token (server.ts), its sign-in sessions' secret (owner.ts) and its webhook's signing secret (`whsec_...`;
117
+ * webhooks.ts), opened with the seal key of `env`, so left out when that key is not there. One pasted into a session is
118
+ * this server's own, so an import cuts it wherever it is, as it cuts the environment's keys. Not among them: a run's own
119
+ * door token (one file a run; not read at each import), and a key-shaped value this server did not make (a `whsec_`
120
+ * from elsewhere). A webhook secret that does not open is said to `say`, as ToolKeys says a saved key that does not:
121
+ * the import goes on, and does not cut it. */
122
+ export declare function ownSecrets(data: string, env: NodeJS.ProcessEnv, say?: (fields: Record<string, string>) => void): string[];
123
+ /** The plan, into `store`: the agents it does not hold, and the runs it does not. A run an earlier import made whose
124
+ * transcript never landed (the process stopped between the two) has it written now. */
125
+ export declare function runImport(store: AgentStore, plan: Plan, options: ImportOptions): Promise<ImportReport>;
126
+ /** What an import left out, by why: one group per kind, the most first (a project's files last), each counted in words
127
+ * ("84 sessions from folders that no longer exist"): a session by its id where the file was read, so one of two files
128
+ * counts once, else each file. */
129
+ export declare function leftOutOf(skipped: readonly Pick<Skipped, "kind" | "what" | "session">[]): {
130
+ kind: LeftOut;
131
+ count: number;
132
+ label: string;
133
+ }[];
134
+ /** The plan as a person reads it: one line per project, its sessions counted as the import takes them, then (`verbose`)
135
+ * each file left out and why. */
136
+ export declare function describePlan(plan: Plan, store?: AgentStoreReader, { verbose }?: {
137
+ verbose?: boolean;
138
+ }): string[];
139
+ /** `agentrun-serve import ARGS`: its exit code. */
140
+ export declare function importCommand(args: string[], usage: string, { home, temp, env, out, }?: {
141
+ home?: string;
142
+ env?: NodeJS.ProcessEnv;
143
+ out?: (line: string) => void;
144
+ temp?: string;
145
+ }): Promise<number>;