@parcha/agentrun-serve 0.1.0-beta.55 → 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 +32 -0
- package/README.md +44 -10
- package/dist/adapters.d.ts +3 -2
- package/dist/adapters.js +6 -3
- package/dist/answer-json.d.ts +6 -2
- package/dist/answer-json.js +22 -4
- package/dist/api-only.js +2 -0
- 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/console/assets/{backend-D5EmB4N3.js → backend-Boh7tC4i.js} +1 -1
- package/dist/console/assets/{index-DUYLaqiR.js → index-CQ3cJRzI.js} +130 -130
- package/dist/console/assets/index-DKkaS3a0.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/host-check.d.ts +4 -0
- package/dist/host-check.js +4 -0
- package/dist/key-refusal.d.ts +21 -5
- package/dist/key-refusal.js +231 -37
- package/dist/learn/secrets.d.ts +20 -10
- package/dist/learn/secrets.js +44 -184
- package/dist/llms.txt +1 -1
- package/dist/openapi.d.ts +3 -3
- package/dist/openapi.js +70 -18
- package/dist/place-offers.d.ts +14 -6
- package/dist/place-offers.js +26 -13
- package/dist/redact/match.d.ts +74 -0
- package/dist/redact/match.js +771 -0
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-timeline-served.js +4 -4
- package/dist/runner/adapter-loop.d.ts +3 -0
- package/dist/runner/adapter-loop.js +1 -1
- package/dist/runner/adapter-run-spec.js +4 -1
- package/dist/runner/beside.js +7 -3
- package/dist/runner/cli-run-spec.js +3 -1
- package/dist/runner/loop-contract.d.ts +4 -0
- package/dist/runner/main.js +8 -4
- package/dist/runner/presence.d.ts +4 -3
- package/dist/runner/presence.js +4 -2
- package/dist/runner/run-child-host.d.ts +2 -0
- package/dist/runner/run-child-host.js +2 -2
- package/dist/runner/runner.d.ts +4 -0
- package/dist/runner/runner.js +33 -3
- package/dist/server.d.ts +5 -2
- package/dist/server.js +41 -10
- package/dist/store/dialect.d.ts +3 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.js +1 -1
- package/dist/store/postgres/dialect.js +3 -0
- package/dist/store/sqlite/store.js +43 -13
- package/dist/store/store.d.ts +10 -1
- package/dist/store/store.js +7 -0
- package/dist/store-view.js +1 -1
- package/dist/template-eval.d.ts +2 -2
- package/dist/template-eval.js +9 -8
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/timeline.d.ts +12 -7
- package/dist/timeline/timeline.js +14 -6
- package/dist/tool-gate.js +3 -1
- package/dist/validate.js +1 -1
- 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/package.json +11 -11
- package/templates/README.md +8 -7
- package/dist/console/assets/index-DYhU4adm.css +0 -1
|
@@ -17,7 +17,10 @@
|
|
|
17
17
|
// not asked, since it reads labels alone and can't tell this server's parts from another's.
|
|
18
18
|
//
|
|
19
19
|
// A desktop or a phone kept at a run's park (computer-kept.ts) goes by its own row, on any provider: each sweep ends one
|
|
20
|
-
// past its time or whose run ended, and the janitor wakes again at the earliest time still ahead.
|
|
20
|
+
// past its time or whose run ended, and the janitor wakes again at the earliest time still ahead. One pinned to another
|
|
21
|
+
// runner still there is that runner's (computer-kept.ts heldElsewhere): the kept pass leaves its row, and the provider
|
|
22
|
+
// sweep leaves its machine out of every list by the same rule (sparedKept), so a run that ended on this runner never has
|
|
23
|
+
// this janitor end a machine another runner keeps.
|
|
21
24
|
//
|
|
22
25
|
// A provider whose sweep fails is logged, once per distinct failure, and the others are swept. It runs only where its
|
|
23
26
|
// start asks for it (the CLI's runner and the runner subcommand), never under --faux, and never two sweeps at once. Its
|
|
@@ -32,7 +35,7 @@ import { KEY_TABLE, providerOptions } from "../computer-keys.js";
|
|
|
32
35
|
import { FAUX_ENV } from "../model.js";
|
|
33
36
|
import { FINAL_STATES } from "../store/index.js";
|
|
34
37
|
import { deleteUnderHold, ownerGoneOf, serverIdOf, wantsOn } from "./agent-computer.js";
|
|
35
|
-
import { sweepKept } from "./computer-kept.js";
|
|
38
|
+
import { sparedKept, sweepKept } from "./computer-kept.js";
|
|
36
39
|
import { storeLedger } from "./computer-ledger.js";
|
|
37
40
|
import { providerKeys } from "./resolve-computer.js";
|
|
38
41
|
import { intervalWrites } from "./computer-intervals.js";
|
|
@@ -79,7 +82,7 @@ async function sweepable(store, info, byHash, serverId) {
|
|
|
79
82
|
* now: a server that stopped before its run's end let go of an earlier claim's computer (run-end-computers.ts) leaves
|
|
80
83
|
* it for this sweep, never for its day-long deadline. Each call goes to the provider itself, so its own state is used
|
|
81
84
|
* as it is. */
|
|
82
|
-
function thisServers(provider, store, byHash, serverId, at, ended) {
|
|
85
|
+
function thisServers(provider, store, byHash, serverId, at, ended, spared) {
|
|
83
86
|
// The agents' own computers the list kept, by id: their delete goes under the agent's hold (deleteUnderHold), which
|
|
84
87
|
// also clears the agent's record of it, so its view no longer shows it deleting.
|
|
85
88
|
const ownedBy = new Map();
|
|
@@ -113,6 +116,9 @@ function thisServers(provider, store, byHash, serverId, at, ended) {
|
|
|
113
116
|
return listed;
|
|
114
117
|
const kept = [];
|
|
115
118
|
for (const info of listed.value) {
|
|
119
|
+
// A machine kept at a park for another runner still there (sparedKept): that runner's to end, never this sweep's.
|
|
120
|
+
if (spared(info.ref.id))
|
|
121
|
+
continue;
|
|
116
122
|
const mine = await sweepable(store, info, byHash, serverId);
|
|
117
123
|
if (!mine)
|
|
118
124
|
continue;
|
|
@@ -144,8 +150,11 @@ async function bounded(ms, signal, work) {
|
|
|
144
150
|
}
|
|
145
151
|
}
|
|
146
152
|
/** One sweep of every provider this server can list: each provider whose keys it has and whose computers the janitor
|
|
147
|
-
* ends, its computers past their deadline that are this server's and unheld ended. A
|
|
148
|
-
*
|
|
153
|
+
* ends, its computers past their deadline that are this server's and unheld ended. A computer kept at a park pinned to
|
|
154
|
+
* another runner still there is left out of every list (computer-kept.ts sparedKept, by the kept pass's own rule): a
|
|
155
|
+
* provider both runners list (a dial vendor's account, a shared Docker engine) would otherwise end, once its run is
|
|
156
|
+
* over, a machine the kept pass left to its runner. Where the kept rows can't be read, each provider is answered as not
|
|
157
|
+
* swept this pass. A provider that fails is answered in its words; nothing throws. */
|
|
149
158
|
export async function sweepServerComputers(deps, signal) {
|
|
150
159
|
const { store, computers } = deps;
|
|
151
160
|
const writes = intervalWrites(store, deps.log, deps.now);
|
|
@@ -154,6 +163,16 @@ export async function sweepServerComputers(deps, signal) {
|
|
|
154
163
|
const byHash = runsByHash(store);
|
|
155
164
|
// This server's id and its agents: its agents' own computers are swept by their owner (ownerGoneOf).
|
|
156
165
|
const { settings, agents } = store;
|
|
166
|
+
// The kept machines this sweep leaves, read once for every provider; with no settings, nothing is kept.
|
|
167
|
+
let spared = () => false;
|
|
168
|
+
if (settings) {
|
|
169
|
+
try {
|
|
170
|
+
spared = await sparedKept({ settings, ...(store.runners ? { runners: store.runners } : {}), ...(deps.self ? { self: deps.self } : {}) });
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
spared = { unread: `the computers kept at a park could not be read, so none of its computers is swept this pass: ${error instanceof Error ? error.message : String(error)}` };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
157
176
|
const serverId = settings && agents ? await serverIdOf({ settings }) : undefined;
|
|
158
177
|
const out = [];
|
|
159
178
|
for (const entry of computers.kinds.PROVIDERS) {
|
|
@@ -172,8 +191,13 @@ export async function sweepServerComputers(deps, signal) {
|
|
|
172
191
|
// A vendor that ends its own computers needs no janitor.
|
|
173
192
|
if (provider.capabilities().lifetime !== "janitor")
|
|
174
193
|
continue;
|
|
194
|
+
if (typeof spared !== "function") {
|
|
195
|
+
out.push({ provider: entry.id, swept: { ok: false, error: { code: "unreachable", message: spared.unread } } });
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const leaves = spared;
|
|
175
199
|
const ownerGone = serverId !== undefined && settings && agents ? ownerGoneOf({ agents, settings, runs: store.runs }, serverId, entry.id) : undefined;
|
|
176
|
-
out.push({ provider: entry.id, swept: await bounded(deps.providerMs ?? JANITOR_PROVIDER_MS, signal, (cut) => sweep(thisServers(provider, store, byHash, serverId, at, (id) => writes.ended(entry.id, id)), { now: new Date(at), signal: cut, ...(ownerGone ? { ownerGone } : {}) })) });
|
|
200
|
+
out.push({ provider: entry.id, swept: await bounded(deps.providerMs ?? JANITOR_PROVIDER_MS, signal, (cut) => sweep(thisServers(provider, store, byHash, serverId, at, (id) => writes.ended(entry.id, id), (id) => leaves(entry.id, id)), { now: new Date(at), signal: cut, ...(ownerGone ? { ownerGone } : {}) })) });
|
|
177
201
|
}
|
|
178
202
|
catch (error) {
|
|
179
203
|
out.push({ provider: entry.id, swept: { ok: false, error: { code: "refused", message: error instanceof Error ? error.message : String(error) } } });
|
|
@@ -183,7 +207,8 @@ export async function sweepServerComputers(deps, signal) {
|
|
|
183
207
|
}
|
|
184
208
|
/** The pass over the desktops and phones kept at a run's park (computer-kept.ts sweepKept): one past its time, or whose
|
|
185
209
|
* run ended, is ended through its provider, made with this server's keys, whatever its lifetime (a vendor's own end is
|
|
186
|
-
* hours away)
|
|
210
|
+
* hours away); one pinned to another runner still there (the store's runners) is left to that runner. Undefined without
|
|
211
|
+
* the store's settings, where none is kept. Never throws. */
|
|
187
212
|
export async function sweepKeptComputers(deps) {
|
|
188
213
|
const { store, computers } = deps;
|
|
189
214
|
const writes = intervalWrites(store, deps.log, deps.now);
|
|
@@ -197,7 +222,7 @@ export async function sweepKeptComputers(deps) {
|
|
|
197
222
|
const options = providerOptions(id, await keysOf(id), computers.settings ?? {}, computers.keyTable ?? KEY_TABLE);
|
|
198
223
|
return options.ok ? make(options.options, { ledger: storeLedger(store.computerLedger, id) }) : undefined;
|
|
199
224
|
};
|
|
200
|
-
return sweepKept({ settings: store.settings, runs: store.runs, now: (deps.now ?? Date.now)(), providerOf, deleted: (provider, id) => writes.ended(provider, id) });
|
|
225
|
+
return sweepKept({ settings: store.settings, runs: store.runs, now: (deps.now ?? Date.now)(), providerOf, deleted: (provider, id) => writes.ended(provider, id), ...(store.runners ? { runners: store.runners } : {}), ...(deps.self ? { self: deps.self } : {}) });
|
|
201
226
|
}
|
|
202
227
|
/** The janitor: one sweep now, then one every `everyMs`, never two at once, and a kept pass at the earliest time a kept
|
|
203
228
|
* computer is due (sweepKeptComputers; each delete bounded, KEPT_DELETE_MS), so a park's keep ends on time though the
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type Settings, type Store } from "../store/index.js";
|
|
1
|
+
import { type ComputerProvider, type MountKind, type ProviderEntry } from "@parcha/agentrun-computer";
|
|
2
|
+
import { type Runners, type Settings, type Store } from "../store/index.js";
|
|
3
3
|
/** How long a park keeps the run's computer for its resume: 10 minutes. */
|
|
4
4
|
export declare const KEEP_MS: number;
|
|
5
5
|
/** KEEP_MS in words. */
|
|
@@ -17,9 +17,13 @@ export type ParkedEnd = {
|
|
|
17
17
|
export declare const parkedWords: (kind: string, cause: ParkCause) => string;
|
|
18
18
|
/** Why the run's computer at its resume is a new one: the one kept at its park was ended at its time. */
|
|
19
19
|
export declare const computerLapsedWords: (kind: string) => string;
|
|
20
|
+
/** Why the run's computer at its resume is a new one: the one kept at its park was pinned to the runner that kept it
|
|
21
|
+
* (pinnedOf), that runner was gone by the resume, and the claiming runner could not reach it. Never names the runner:
|
|
22
|
+
* a runner's name carries its host's. */
|
|
23
|
+
export declare const computerLostWords: (kind: string) => string;
|
|
20
24
|
/** The live view's words once the kept computer's time passed, the run still parked. */
|
|
21
25
|
export declare const lapsedWords: (kind: string) => string;
|
|
22
|
-
/** The settings key prefix of the kept computers, one row per run. */
|
|
26
|
+
/** The settings key prefix of the kept computers, one row per run (the store's, which its claim rule reads). */
|
|
23
27
|
export declare const KEPT_PREFIX = "computer_kept:";
|
|
24
28
|
/** The settings key of `runId`'s kept computer. */
|
|
25
29
|
export declare const keptKeyOf: (runId: string) => string;
|
|
@@ -36,9 +40,45 @@ export type Kept = {
|
|
|
36
40
|
/** The kind of the run's folder it holds (a bind, an Archil mount or a synced folder); none: it holds none. A claim
|
|
37
41
|
* takes it back only to hold the folder the same way (computer-for-claim.ts reattach). */
|
|
38
42
|
readonly folder?: MountKind;
|
|
43
|
+
/** The runner that kept it and that runner's process (its presence incarnation), where only that runner can reach it
|
|
44
|
+
* again (pinnedOf): both or neither. Absent: any runner takes it back. */
|
|
45
|
+
readonly runner?: string;
|
|
46
|
+
readonly incarnation?: string;
|
|
39
47
|
readonly ending?: true;
|
|
40
48
|
readonly ended?: true;
|
|
41
49
|
};
|
|
50
|
+
/** The runner a claim runs in: its name (the claim's runner) and its process's presence incarnation. */
|
|
51
|
+
export type KeptHolder = {
|
|
52
|
+
readonly runner: string;
|
|
53
|
+
readonly incarnation: string;
|
|
54
|
+
};
|
|
55
|
+
/** Whether a computer of `entry`, made with `options` (its settings' options under the configuration's, as the claim makes
|
|
56
|
+
* its provider), can be reached again only by the runner that kept it: a local provider's (a container on that
|
|
57
|
+
* runner's Docker engine), or one whose machines dial this server (the computer package's connectOf "dial": its socket
|
|
58
|
+
* is in that runner's attach hub, its token names that runner). A connect the computer package refuses reads as exec,
|
|
59
|
+
* as resolve-computer.ts reads it. */
|
|
60
|
+
export declare function pinnedOf(entry: Pick<ProviderEntry, "label" | "connect" | "local">, options?: Readonly<Record<string, unknown>>): boolean;
|
|
61
|
+
/** Whether `kept` names `holder` as the runner that keeps it (the same name and the same process). */
|
|
62
|
+
export declare const keptBy: (kept: Pick<Kept, "runner" | "incarnation">, holder: KeptHolder | undefined) => boolean;
|
|
63
|
+
/** Who holds what, for one janitor pass: the runners there now (Runners.live) and the runner the pass runs in (`self`). */
|
|
64
|
+
export type KeptHolders = {
|
|
65
|
+
/** Absent: none is read, and no row counts as held elsewhere. */
|
|
66
|
+
readonly runners?: Pick<Runners, "live">;
|
|
67
|
+
readonly self?: KeptHolder;
|
|
68
|
+
};
|
|
69
|
+
/** The one rule both janitor sweeps leave a kept machine by (sweepKept, and the provider sweep through sparedKept): its
|
|
70
|
+
* row is pinned to a runner other than `self` that is still there under the row's incarnation (seen within
|
|
71
|
+
* PRESENCE_STALE_MS). Only that runner's engine or hub has the machine, so a delete from here either finds nothing (and
|
|
72
|
+
* marks the row ended, leaking it) or, where both runners list it (a dial vendor's account, a shared Docker engine),
|
|
73
|
+
* ends a machine its runner still keeps. The runners are read once per maker's call. A read that fails counts every
|
|
74
|
+
* pinned row as held elsewhere: ending another runner's machine blind would leak it or take it. */
|
|
75
|
+
export declare function heldElsewhere(holders: KeptHolders): (kept: Pick<Kept, "runner" | "incarnation">) => Promise<boolean>;
|
|
76
|
+
/** The kept machines a provider sweep leaves this pass, by provider id and computer id: each row not yet ended whose
|
|
77
|
+
* machine is held elsewhere (heldElsewhere, the kept pass's own rule). Throws when the rows can't be read: the sweep
|
|
78
|
+
* then can't tell which machines are kept, and must not guess. */
|
|
79
|
+
export declare function sparedKept(deps: KeptHolders & {
|
|
80
|
+
readonly settings: Pick<KeptSettings, "all">;
|
|
81
|
+
}): Promise<(provider: string, id: string) => boolean>;
|
|
42
82
|
/** How long one delete of a kept computer may take at the janitor's pass: past it the pass goes on, the row is left
|
|
43
83
|
* ending, and the next pass deletes it again (a Docker command has no timeout of its own). */
|
|
44
84
|
export declare const KEPT_DELETE_MS = 60000;
|
|
@@ -71,7 +111,10 @@ export type KeptSweep = {
|
|
|
71
111
|
* deleted (unless its time already ended it) and the row removed; one past its time, or left ending, is ended (endKept),
|
|
72
112
|
* each delete bounded by `deleteMs` (KEPT_DELETE_MS). The rest are left, the earliest of their times answered as `next`.
|
|
73
113
|
* `providerOf`: the provider a row names, made with this server's keys, or undefined when this server can't make it (its
|
|
74
|
-
* keys gone): that row is left and said.
|
|
114
|
+
* keys gone): that row is left and said. A row pinned to a runner other than this one (`self`) that is still there under
|
|
115
|
+
* the row's incarnation (`runners`, seen within PRESENCE_STALE_MS) is left whatever its time or its run: only that
|
|
116
|
+
* runner's engine or hub has its machine, so a delete from here would find nothing, mark it ended and leak the machine.
|
|
117
|
+
* That runner's own timer, or its janitor, ends it; once it is gone the row is ended here as any other. Never throws.
|
|
75
118
|
*/
|
|
76
119
|
export declare function sweepKept(deps: {
|
|
77
120
|
readonly settings: KeptSettings;
|
|
@@ -82,6 +125,11 @@ export declare function sweepKept(deps: {
|
|
|
82
125
|
/** Told of each kept computer whose delete answered ok, by its provider and id (its interval's end,
|
|
83
126
|
* computer-intervals.ts). Never throws. */
|
|
84
127
|
readonly deleted?: (provider: string, id: string) => Promise<void>;
|
|
128
|
+
/** The runners there now (Runners.live): a row pinned to one of them, not `self`, is left. Absent: none is read, and
|
|
129
|
+
* every row is swept as before. */
|
|
130
|
+
readonly runners?: Pick<Runners, "live">;
|
|
131
|
+
/** The runner this sweep runs in (its name and presence incarnation): the rows pinned to it are its own to end. */
|
|
132
|
+
readonly self?: KeptHolder;
|
|
85
133
|
}): Promise<KeptSweep>;
|
|
86
134
|
/** Deletes the kept computer through its provider; one already gone (its run's end let it go, run-end-computers.ts, or
|
|
87
135
|
* its vendor ended it) is as good as deleted. Throws the provider's words on any other failure. True when the
|
|
@@ -1,4 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
// A desktop, a phone or a sandbox kept through its run's park. A run's own computer goes with its claim, and a park
|
|
2
|
+
// releases the claim; so a run that parked for a person (a tool's approval, a cap raise, a question) would resume on a new
|
|
3
|
+
// machine, with nothing the agent set up on the old one. Instead, the claim that parks keeps a desktop, a phone or a
|
|
4
|
+
// sandbox it made (or took back) for KEEP_MS: an answer within that time resumes the run on the same machine, its screen,
|
|
5
|
+
// files and programs as they were (computer-for-claim.ts: the claim's park, and the resumed claim's re-attach). After it,
|
|
6
|
+
// the kept computer is ended, and a later resume makes a new one, said as any replaced computer is, and why.
|
|
7
|
+
//
|
|
8
|
+
// One server setting per run holds it (`computer_kept:<run id>`): its provider, its kind, its ref, the claim epoch its
|
|
9
|
+
// labels carry, and the time it is kept until. The claim that parks writes it; the claim that resumes in time takes it
|
|
10
|
+
// off and attaches the computer. At its time it is ended by the parking runner's own timer and, whatever became of
|
|
11
|
+
// that process (a server's restart), by the janitor (computer-janitor.ts), which reads every row at each sweep and wakes
|
|
12
|
+
// at the earliest time still ahead. Ending one marks its row ending (no claim takes it after), deletes the computer, then
|
|
13
|
+
// marks the row ended, so the resume says why its computer is new; a row left ending (its process died, or its delete
|
|
14
|
+
// failed or hung mid-way) is deleted again at the janitor's next pass. A row whose run is final is removed, its computer
|
|
15
|
+
// deleted first.
|
|
16
|
+
//
|
|
17
|
+
// A sandbox's run folder is the run's either way (bound from this machine, or on Archil, as before); what the keep adds is
|
|
18
|
+
// the rest of the machine (its other files, its processes). A synced folder's delta lands on the disk at the park; what
|
|
19
|
+
// its programs write after it is read back whole by the claim that takes it back. One whose keep lapses is deleted, by
|
|
20
|
+
// the parking runner's own timer or the janitor, with no read-back: those writes are lost, as a runner lost loses an
|
|
21
|
+
// unanswered call's. A claim takes one back only to hold the run's folder the same way (its row's `folder`). An agent's
|
|
22
|
+
// own computer and a paired one outlive every claim already, and are never kept here; a runner lost, a crash or a
|
|
23
|
+
// server's stop still gives a new one.
|
|
24
|
+
//
|
|
25
|
+
// While the run is parked, its owner's live view says what it waits for and that the computer is kept, until when, then
|
|
26
|
+
// that it wasn't kept once its time passed (parkedWords, lapsedWords): the viewer's page, as the claim's park closes it
|
|
27
|
+
// (computer-live.ts), and the console's Screen tab, until when from the park's row on the run's timeline
|
|
28
|
+
// (computerKeptWords) and its lapse from GET /v2/runs/{id}/computer (computer-view.ts lapsedOf).
|
|
29
|
+
//
|
|
30
|
+
// A machine only the runner that kept it can reach again is pinned to that runner (pinnedOf): a container on its Docker
|
|
31
|
+
// engine (a local provider), or a machine that dials this server, whose socket is in that runner's attach hub. Its row
|
|
32
|
+
// names the runner and its process (`runner`, `incarnation`: the presence incarnation, runner/presence.ts), and while
|
|
33
|
+
// that runner is there under that incarnation and the keep lasts, the claim rule gives the run to that runner alone
|
|
34
|
+
// (store KEPT_PREFIX: no other runner's poll picks it, nothing is claimed and given back). A stop or cancel is exempt:
|
|
35
|
+
// any runner claims the run at once and ends it with no loop, never taking the row (runner.ts claimMore), and the
|
|
36
|
+
// row's runner ends the machine at its time, or at its janitor's pass once the run is over. Once it is gone (its row stale
|
|
37
|
+
// for PRESENCE_STALE_MS, a new incarnation, a refusal) any runner claims the run; a claim that then finds the machine gone
|
|
38
|
+
// says so (computerLostWords), and its janitor never ends a row pinned to another runner still there (sweepKept): that
|
|
39
|
+
// runner's own timer or janitor does. A machine any runner reaches by its id (an exec vendor's sandbox, a phone) is not
|
|
40
|
+
// pinned, and moves.
|
|
41
|
+
import { connectOf } from "@parcha/agentrun-computer";
|
|
42
|
+
import { PRESENCE_STALE_MS } from "../runner/presence.js";
|
|
43
|
+
import { FINAL_STATES, KEPT_PREFIX as KEPT_ROWS } from "../store/index.js";
|
|
2
44
|
/** How long a park keeps the run's computer for its resume: 10 minutes. */
|
|
3
45
|
export const KEEP_MS = 10 * 60_000;
|
|
4
46
|
/** KEEP_MS in words. */
|
|
@@ -16,12 +58,64 @@ const WAITING = {
|
|
|
16
58
|
export const parkedWords = (kind, cause) => `${WAITING[cause]} The ${kind} is kept for ${KEEP_WORDS}.`;
|
|
17
59
|
/** Why the run's computer at its resume is a new one: the one kept at its park was ended at its time. */
|
|
18
60
|
export const computerLapsedWords = (kind) => `The ${kind} wasn't kept: ${KEEP_WORDS} passed.`;
|
|
61
|
+
/** Why the run's computer at its resume is a new one: the one kept at its park was pinned to the runner that kept it
|
|
62
|
+
* (pinnedOf), that runner was gone by the resume, and the claiming runner could not reach it. Never names the runner:
|
|
63
|
+
* a runner's name carries its host's. */
|
|
64
|
+
export const computerLostWords = (kind) => `The ${kind} wasn't kept: the runner that kept it is gone.`;
|
|
19
65
|
/** The live view's words once the kept computer's time passed, the run still parked. */
|
|
20
66
|
export const lapsedWords = (kind) => `${computerLapsedWords(kind)} A new one starts when the run goes on.`;
|
|
21
|
-
/** The settings key prefix of the kept computers, one row per run. */
|
|
22
|
-
export const KEPT_PREFIX =
|
|
67
|
+
/** The settings key prefix of the kept computers, one row per run (the store's, which its claim rule reads). */
|
|
68
|
+
export const KEPT_PREFIX = KEPT_ROWS;
|
|
23
69
|
/** The settings key of `runId`'s kept computer. */
|
|
24
70
|
export const keptKeyOf = (runId) => `${KEPT_PREFIX}${runId}`;
|
|
71
|
+
/** Whether a computer of `entry`, made with `options` (its settings' options under the configuration's, as the claim makes
|
|
72
|
+
* its provider), can be reached again only by the runner that kept it: a local provider's (a container on that
|
|
73
|
+
* runner's Docker engine), or one whose machines dial this server (the computer package's connectOf "dial": its socket
|
|
74
|
+
* is in that runner's attach hub, its token names that runner). A connect the computer package refuses reads as exec,
|
|
75
|
+
* as resolve-computer.ts reads it. */
|
|
76
|
+
export function pinnedOf(entry, options = {}) {
|
|
77
|
+
if (entry.local === true)
|
|
78
|
+
return true;
|
|
79
|
+
try {
|
|
80
|
+
return connectOf(entry, options) === "dial";
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** Whether `kept` names `holder` as the runner that keeps it (the same name and the same process). */
|
|
87
|
+
export const keptBy = (kept, holder) => holder !== undefined && kept.runner === holder.runner && kept.incarnation === holder.incarnation;
|
|
88
|
+
/** The one rule both janitor sweeps leave a kept machine by (sweepKept, and the provider sweep through sparedKept): its
|
|
89
|
+
* row is pinned to a runner other than `self` that is still there under the row's incarnation (seen within
|
|
90
|
+
* PRESENCE_STALE_MS). Only that runner's engine or hub has the machine, so a delete from here either finds nothing (and
|
|
91
|
+
* marks the row ended, leaking it) or, where both runners list it (a dial vendor's account, a shared Docker engine),
|
|
92
|
+
* ends a machine its runner still keeps. The runners are read once per maker's call. A read that fails counts every
|
|
93
|
+
* pinned row as held elsewhere: ending another runner's machine blind would leak it or take it. */
|
|
94
|
+
export function heldElsewhere(holders) {
|
|
95
|
+
let there;
|
|
96
|
+
return async (kept) => {
|
|
97
|
+
const { runners } = holders;
|
|
98
|
+
if (kept.runner === undefined || keptBy(kept, holders.self) || !runners)
|
|
99
|
+
return false;
|
|
100
|
+
there ??= runners.live(PRESENCE_STALE_MS).then((live) => new Set(live.map((one) => `${one.runner}\n${one.incarnation}`)), () => "unknown");
|
|
101
|
+
const live = await there;
|
|
102
|
+
return live === "unknown" || live.has(`${kept.runner}\n${kept.incarnation}`);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** The kept machines a provider sweep leaves this pass, by provider id and computer id: each row not yet ended whose
|
|
106
|
+
* machine is held elsewhere (heldElsewhere, the kept pass's own rule). Throws when the rows can't be read: the sweep
|
|
107
|
+
* then can't tell which machines are kept, and must not guess. */
|
|
108
|
+
export async function sparedKept(deps) {
|
|
109
|
+
const rows = await deps.settings.all({ prefix: KEPT_PREFIX });
|
|
110
|
+
const elsewhere = heldElsewhere(deps);
|
|
111
|
+
const spared = new Set();
|
|
112
|
+
for (const row of rows) {
|
|
113
|
+
const kept = keptOf(row.value);
|
|
114
|
+
if (kept && !kept.ended && (await elsewhere(kept)))
|
|
115
|
+
spared.add(`${kept.provider}\n${kept.id}`);
|
|
116
|
+
}
|
|
117
|
+
return (provider, id) => spared.has(`${provider}\n${id}`);
|
|
118
|
+
}
|
|
25
119
|
/** How long one delete of a kept computer may take at the janitor's pass: past it the pass goes on, the row is left
|
|
26
120
|
* ending, and the next pass deletes it again (a Docker command has no timeout of its own). */
|
|
27
121
|
export const KEPT_DELETE_MS = 60_000;
|
|
@@ -29,14 +123,19 @@ export const KEPT_DELETE_MS = 60_000;
|
|
|
29
123
|
export function keptOf(value) {
|
|
30
124
|
if (!value || typeof value !== "object")
|
|
31
125
|
return undefined;
|
|
32
|
-
const { provider, kind, id, name, epoch, until, folder, ending, ended } = value;
|
|
126
|
+
const { provider, kind, id, name, epoch, until, folder, runner, incarnation, ending, ended } = value;
|
|
33
127
|
if (typeof provider !== "string" || (kind !== "desktop" && kind !== "phone" && kind !== "sandbox") || typeof id !== "string" || typeof name !== "string")
|
|
34
128
|
return undefined;
|
|
35
129
|
if (typeof epoch !== "number" || !Number.isSafeInteger(epoch) || typeof until !== "number" || !Number.isFinite(until))
|
|
36
130
|
return undefined;
|
|
37
131
|
if (folder !== undefined && folder !== "bind" && folder !== "archil" && folder !== "sync")
|
|
38
132
|
return undefined;
|
|
39
|
-
|
|
133
|
+
// Its runner and incarnation together, or neither.
|
|
134
|
+
if ((runner === undefined) !== (incarnation === undefined))
|
|
135
|
+
return undefined;
|
|
136
|
+
if (runner !== undefined && (typeof runner !== "string" || typeof incarnation !== "string"))
|
|
137
|
+
return undefined;
|
|
138
|
+
const held = { ...(folder === undefined ? {} : { folder: folder }), ...(typeof runner === "string" && typeof incarnation === "string" ? { runner, incarnation } : {}) };
|
|
40
139
|
if (ended === true)
|
|
41
140
|
return { provider, kind, id, name, epoch, until, ...held, ended: true };
|
|
42
141
|
return { provider, kind, id, name, epoch, until, ...held, ...(ending === true ? { ending: true } : {}) };
|
|
@@ -45,6 +144,7 @@ export function keptOf(value) {
|
|
|
45
144
|
const rowOf = (kept, state) => ({
|
|
46
145
|
provider: kept.provider, kind: kept.kind, id: kept.id, name: kept.name, epoch: kept.epoch, until: kept.until,
|
|
47
146
|
...(kept.folder === undefined ? {} : { folder: kept.folder }),
|
|
147
|
+
...(kept.runner === undefined || kept.incarnation === undefined ? {} : { runner: kept.runner, incarnation: kept.incarnation }),
|
|
48
148
|
...(state === "ending" ? { ending: true } : state === "ended" ? { ended: true } : {}),
|
|
49
149
|
});
|
|
50
150
|
/** `runId`'s kept computer, as its row reads now; undefined when there is none. */
|
|
@@ -79,7 +179,10 @@ export async function endKept(settings, runId, kept, end) {
|
|
|
79
179
|
* deleted (unless its time already ended it) and the row removed; one past its time, or left ending, is ended (endKept),
|
|
80
180
|
* each delete bounded by `deleteMs` (KEPT_DELETE_MS). The rest are left, the earliest of their times answered as `next`.
|
|
81
181
|
* `providerOf`: the provider a row names, made with this server's keys, or undefined when this server can't make it (its
|
|
82
|
-
* keys gone): that row is left and said.
|
|
182
|
+
* keys gone): that row is left and said. A row pinned to a runner other than this one (`self`) that is still there under
|
|
183
|
+
* the row's incarnation (`runners`, seen within PRESENCE_STALE_MS) is left whatever its time or its run: only that
|
|
184
|
+
* runner's engine or hub has its machine, so a delete from here would find nothing, mark it ended and leak the machine.
|
|
185
|
+
* That runner's own timer, or its janitor, ends it; once it is gone the row is ended here as any other. Never throws.
|
|
83
186
|
*/
|
|
84
187
|
export async function sweepKept(deps) {
|
|
85
188
|
const ended = [];
|
|
@@ -92,6 +195,9 @@ export async function sweepKept(deps) {
|
|
|
92
195
|
catch (error) {
|
|
93
196
|
return { ended, failed: [`the kept computers could not be read: ${words(error)}`] };
|
|
94
197
|
}
|
|
198
|
+
// The runners there now, read once for the pass, only where a row is pinned to another runner (heldElsewhere: the
|
|
199
|
+
// provider sweep leaves the same machines by the same rule, computer-janitor.ts).
|
|
200
|
+
const othersThere = heldElsewhere(deps);
|
|
95
201
|
for (const row of rows) {
|
|
96
202
|
const runId = row.key.slice(KEPT_PREFIX.length);
|
|
97
203
|
const kept = keptOf(row.value);
|
|
@@ -107,6 +213,12 @@ export async function sweepKept(deps) {
|
|
|
107
213
|
await deps.settings.removeIf(row.key, kept);
|
|
108
214
|
continue;
|
|
109
215
|
}
|
|
216
|
+
if (await othersThere(kept)) {
|
|
217
|
+
// Its runner's own: woken again at its time while that is ahead, by then that runner may be gone.
|
|
218
|
+
if (!kept.ending && deps.now < kept.until)
|
|
219
|
+
next = Math.min(next ?? kept.until, kept.until);
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
110
222
|
if (!over && !kept.ending && deps.now < kept.until) {
|
|
111
223
|
next = Math.min(next ?? kept.until, kept.until);
|
|
112
224
|
continue;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Store } from "../store/index.js";
|
|
2
2
|
import type { ComputerDeps } from "./computer-deps.js";
|
|
3
|
+
import { type KeptHolder } from "./computer-kept.js";
|
|
3
4
|
/** The longest a run's end may spend on its computers, every try with its pauses: past it the provider's calls are cut
|
|
4
5
|
* (one that takes no signal, a release, left to finish on its own) and the run's end goes on, said in the log. */
|
|
5
6
|
export declare const RUN_END_COMPUTERS_MS = 120000;
|
|
@@ -8,7 +9,7 @@ export declare const RUN_END_RETRY_MS = 5000;
|
|
|
8
9
|
export interface RunEndComputersDeps {
|
|
9
10
|
/** The run's row and launch (its revision and place) and the agent's revision, where its computer setting is; the
|
|
10
11
|
* computer ledger, for a provider that keeps one. */
|
|
11
|
-
readonly store: Pick<Store, "agents" | "computerLedger"> & {
|
|
12
|
+
readonly store: Pick<Store, "agents" | "computerLedger" | "settings"> & {
|
|
12
13
|
readonly runs: Pick<Store["runs"], "get" | "launch">;
|
|
13
14
|
readonly computerIntervals?: Store["computerIntervals"];
|
|
14
15
|
};
|
|
@@ -17,6 +18,9 @@ export interface RunEndComputersDeps {
|
|
|
17
18
|
readonly computers: Pick<ComputerDeps, "kinds" | "providers" | "keyOf" | "keyTable" | "settings" | "launch" | "launches">;
|
|
18
19
|
/** Where what was let go, and a provider that failed, are said. */
|
|
19
20
|
readonly log: (line: string) => void;
|
|
21
|
+
/** The runner this end runs in (its name and presence incarnation), read at each end: a computer kept pinned to it is
|
|
22
|
+
* its own to let go here. Absent: every kept row that names a runner is another's. */
|
|
23
|
+
readonly self?: () => KeptHolder | undefined;
|
|
20
24
|
/** The bound on every try. Default RUN_END_COMPUTERS_MS. */
|
|
21
25
|
readonly timeoutMs?: number;
|
|
22
26
|
/** The pause between tries. Default RUN_END_RETRY_MS. */
|
|
@@ -15,10 +15,16 @@
|
|
|
15
15
|
// at all (its key is not in this runner's environment or the store) is not. Either is said in the runner's log, and the
|
|
16
16
|
// run's end stands. The janitor (computer-janitor.ts) ends a computer of a run that is over on its next sweep too, for a
|
|
17
17
|
// server that stopped before this ran, or a vendor that stayed down past the bound.
|
|
18
|
+
//
|
|
19
|
+
// Nor a computer the run's park kept pinned to a runner other than this one while that keep lasts (computer-kept.ts: its
|
|
20
|
+
// row names that runner, and is neither ending nor ended): a stop or cancel ends the run on whichever runner claims it,
|
|
21
|
+
// and the machine is the keeping runner's to end, at its time or its janitor's pass. A vendor's list (a dial machine's)
|
|
22
|
+
// shows it here too; it is left out of the list, so nothing under its id is deleted from here.
|
|
18
23
|
import { releaseOlder } from "@parcha/agentrun-computer";
|
|
19
24
|
import { KEY_TABLE, providerOptions } from "../computer-keys.js";
|
|
20
25
|
import { readLaunchBody } from "../run-launch.js";
|
|
21
26
|
import { settingOf } from "./computer-for-claim.js";
|
|
27
|
+
import { keptBy, readKept } from "./computer-kept.js";
|
|
22
28
|
import { storeLedger } from "./computer-ledger.js";
|
|
23
29
|
import { providerKeys } from "./resolve-computer.js";
|
|
24
30
|
import { endingDeletes, intervalWrites } from "./computer-intervals.js";
|
|
@@ -46,6 +52,19 @@ const pause = (ms, signal) => new Promise((resolve) => {
|
|
|
46
52
|
}, ms);
|
|
47
53
|
signal.addEventListener("abort", done, { once: true });
|
|
48
54
|
});
|
|
55
|
+
/** `provider` with the computer `id` left out of its lists: releaseOlder never sees it, so never deletes it. */
|
|
56
|
+
const sparing = (provider, id) => new Proxy(provider, {
|
|
57
|
+
get(target, key) {
|
|
58
|
+
if (key !== "list") {
|
|
59
|
+
const value = Reflect.get(target, key, target);
|
|
60
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
61
|
+
}
|
|
62
|
+
return async (...args) => {
|
|
63
|
+
const listed = await target.list(...args);
|
|
64
|
+
return listed.ok ? { ...listed, value: listed.value.filter((info) => info.ref.id !== id) } : listed;
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
});
|
|
49
68
|
/** The run's end for its computers (RunEndComputersDeps): given the claim that ended the run, every computer of the run
|
|
50
69
|
* at or below its epoch deleted, a provider that did not answer asked again until the bound. Never throws: a failure
|
|
51
70
|
* is said in the log. */
|
|
@@ -79,6 +98,12 @@ export function runEndComputers(deps) {
|
|
|
79
98
|
// A throw from here on is the vendor's or the daemon's (Docker's architecture asked): asked again.
|
|
80
99
|
return endingDeletes(await make(options.options, { ledger: storeLedger(store.computerLedger, entry.id) }), entry.id, writes);
|
|
81
100
|
};
|
|
101
|
+
/** The id of the run's computer its park kept pinned to a runner other than this one, while the keep lasts; a read
|
|
102
|
+
* that fails throws, and is asked again (a delete from here must not guess). */
|
|
103
|
+
const keptElsewhere = async (runId) => {
|
|
104
|
+
const kept = await readKept(store.settings, runId);
|
|
105
|
+
return kept && kept.runner !== undefined && !kept.ending && !kept.ended && !keptBy(kept, deps.self?.()) ? kept.id : undefined;
|
|
106
|
+
};
|
|
82
107
|
return async ({ runId, epoch }) => {
|
|
83
108
|
if (epoch <= 1)
|
|
84
109
|
return;
|
|
@@ -99,8 +124,9 @@ export function runEndComputers(deps) {
|
|
|
99
124
|
const provider = await providerOf(runId, epoch);
|
|
100
125
|
if (!provider)
|
|
101
126
|
return;
|
|
127
|
+
const spared = await keptElsewhere(runId);
|
|
102
128
|
// Every claim's at or below this one's: a computer of a later epoch fences the call (a later claim holds the run).
|
|
103
|
-
const released = await releaseOlder(provider, runId, epoch + 1, { signal });
|
|
129
|
+
const released = await releaseOlder(spared === undefined ? provider : sparing(provider, spared), runId, epoch + 1, { signal });
|
|
104
130
|
if (released.ok) {
|
|
105
131
|
const names = released.value.released.map((ref) => ref.name);
|
|
106
132
|
if (names.length > 0)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Wrapped } from "@parcha/agentrun-import";
|
|
2
|
+
/** `wrapped` (the import package's) as GET /v2/wrapped serves it, and the runs imported from each source (`imported`). */
|
|
3
|
+
export declare function wrappedView(wrapped: Wrapped, imported: readonly {
|
|
4
|
+
source: string;
|
|
5
|
+
runs: number;
|
|
6
|
+
}[], unreadFiles?: number): {
|
|
7
|
+
year: number;
|
|
8
|
+
sessions: number;
|
|
9
|
+
turns: number;
|
|
10
|
+
requests: number;
|
|
11
|
+
tokens: {
|
|
12
|
+
input: number;
|
|
13
|
+
output: number;
|
|
14
|
+
cache_read: number;
|
|
15
|
+
cache_write: number;
|
|
16
|
+
};
|
|
17
|
+
cost_usd: number;
|
|
18
|
+
unpriced_requests: number;
|
|
19
|
+
days: {
|
|
20
|
+
day: string;
|
|
21
|
+
requests: number;
|
|
22
|
+
tokens: number;
|
|
23
|
+
}[];
|
|
24
|
+
hours: number[];
|
|
25
|
+
weekdays: number[];
|
|
26
|
+
active_ms: number;
|
|
27
|
+
harnesses: {
|
|
28
|
+
harness: string;
|
|
29
|
+
sessions: number;
|
|
30
|
+
requests: number;
|
|
31
|
+
tokens: number;
|
|
32
|
+
}[];
|
|
33
|
+
models: {
|
|
34
|
+
model: string;
|
|
35
|
+
requests: number;
|
|
36
|
+
tokens: number;
|
|
37
|
+
cost_usd: number;
|
|
38
|
+
}[];
|
|
39
|
+
sources: {
|
|
40
|
+
source: string;
|
|
41
|
+
sessions: number;
|
|
42
|
+
requests: number;
|
|
43
|
+
}[];
|
|
44
|
+
imported: {
|
|
45
|
+
source: string;
|
|
46
|
+
runs: number;
|
|
47
|
+
}[];
|
|
48
|
+
unread_files: number;
|
|
49
|
+
};
|
|
50
|
+
type Read = {
|
|
51
|
+
wrapped: Wrapped;
|
|
52
|
+
unread: number;
|
|
53
|
+
};
|
|
54
|
+
/** The year's wrappedHome over this machine's home, shared by the reads of the minute, and how many session files it could
|
|
55
|
+
* not read (one gone since it was listed, or one this user cannot open): the numbers are short by those, and say so. */
|
|
56
|
+
export declare function readWrapped(year: number, now?: number): Promise<Read>;
|
|
57
|
+
export {};
|
package/dist/wrapped.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// GET /v2/wrapped: a year of the work under this machine's home (Claude Code, Codex, pi and every other source the import
|
|
2
|
+
// package reads), as numbers. The import package's wrappedHome does the reading; this is its answer in the API's words,
|
|
3
|
+
// with the runs imported here beside it. Numbers and names only: no prompt, title, path or project is in it.
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
const total = ({ input, output, cacheRead, cacheWrite }) => input + output + cacheRead + cacheWrite;
|
|
6
|
+
/** `wrapped` (the import package's) as GET /v2/wrapped serves it, and the runs imported from each source (`imported`). */
|
|
7
|
+
export function wrappedView(wrapped, imported, unreadFiles = 0) {
|
|
8
|
+
const { input, output, cacheRead, cacheWrite } = wrapped.tokens;
|
|
9
|
+
return {
|
|
10
|
+
year: wrapped.year,
|
|
11
|
+
sessions: wrapped.sessions,
|
|
12
|
+
turns: wrapped.turns,
|
|
13
|
+
requests: wrapped.requests,
|
|
14
|
+
tokens: { input, output, cache_read: cacheRead, cache_write: cacheWrite },
|
|
15
|
+
cost_usd: wrapped.cost,
|
|
16
|
+
unpriced_requests: wrapped.unpricedRequests,
|
|
17
|
+
days: wrapped.days,
|
|
18
|
+
hours: wrapped.hours,
|
|
19
|
+
weekdays: wrapped.weekdays,
|
|
20
|
+
active_ms: wrapped.activeMs,
|
|
21
|
+
harnesses: wrapped.harnesses,
|
|
22
|
+
models: wrapped.models.map(({ model, requests, tokens, cost }) => ({ model, requests, tokens: total(tokens), cost_usd: cost })),
|
|
23
|
+
sources: wrapped.sources,
|
|
24
|
+
imported: imported.map(({ source, runs }) => ({ source, runs })),
|
|
25
|
+
unread_files: unreadFiles,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** A year read lately is not read again for a minute: a whole home is a long read, and the page asks for it on every open.
|
|
29
|
+
* A read still going is shared however long it takes; its minute starts when it ends. */
|
|
30
|
+
const KEEP_MS = 60_000;
|
|
31
|
+
const kept = new Map();
|
|
32
|
+
/** The year's wrappedHome over this machine's home, shared by the reads of the minute, and how many session files it could
|
|
33
|
+
* not read (one gone since it was listed, or one this user cannot open): the numbers are short by those, and say so. */
|
|
34
|
+
export function readWrapped(year, now = Date.now()) {
|
|
35
|
+
const home = homedir();
|
|
36
|
+
const key = `${home}:${year}`;
|
|
37
|
+
const held = kept.get(key);
|
|
38
|
+
if (held && (held.at === undefined || now - held.at < KEEP_MS))
|
|
39
|
+
return held.read;
|
|
40
|
+
const failures = [];
|
|
41
|
+
const read = import("@parcha/agentrun-import").then(async ({ wrappedHome }) => ({ wrapped: await wrappedHome(home, year, { failures }), unread: failures.length }));
|
|
42
|
+
const entry = { read };
|
|
43
|
+
kept.set(key, entry);
|
|
44
|
+
read.then(() => {
|
|
45
|
+
entry.at = Date.now();
|
|
46
|
+
}, () => {
|
|
47
|
+
if (kept.get(key) === entry)
|
|
48
|
+
kept.delete(key);
|
|
49
|
+
});
|
|
50
|
+
return read;
|
|
51
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcha/agentrun-serve",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.56",
|
|
4
4
|
"description": "The AgentRun server: the /v2 API and console over one store, with runners that run your agents; the deployable process of the AgentRun platform.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentrun",
|
|
@@ -66,16 +66,16 @@
|
|
|
66
66
|
"@earendil-works/pi-coding-agent": "1.5.2",
|
|
67
67
|
"@modelcontextprotocol/client": "2.4.0",
|
|
68
68
|
"@modelcontextprotocol/server": "2.4.0",
|
|
69
|
-
"@parcha/agentrun-computer": "0.1.0-beta.
|
|
70
|
-
"@parcha/agentrun-decisions": "0.1.0-beta.
|
|
71
|
-
"@parcha/agentrun-dsl": "0.1.0-beta.
|
|
72
|
-
"@parcha/agentrun-harness-acp": "0.1.0-beta.
|
|
73
|
-
"@parcha/agentrun-harness-claude": "0.1.0-beta.
|
|
74
|
-
"@parcha/agentrun-harness-codex": "0.1.0-beta.
|
|
75
|
-
"@parcha/agentrun-import": "0.1.0-beta.
|
|
76
|
-
"@parcha/agentrun-jev": "0.1.0-beta.
|
|
77
|
-
"@parcha/agentrun-kernel": "0.1.0-beta.
|
|
78
|
-
"@parcha/pi-browser": "0.1.0-beta.
|
|
69
|
+
"@parcha/agentrun-computer": "0.1.0-beta.56",
|
|
70
|
+
"@parcha/agentrun-decisions": "0.1.0-beta.56",
|
|
71
|
+
"@parcha/agentrun-dsl": "0.1.0-beta.56",
|
|
72
|
+
"@parcha/agentrun-harness-acp": "0.1.0-beta.56",
|
|
73
|
+
"@parcha/agentrun-harness-claude": "0.1.0-beta.56",
|
|
74
|
+
"@parcha/agentrun-harness-codex": "0.1.0-beta.56",
|
|
75
|
+
"@parcha/agentrun-import": "0.1.0-beta.56",
|
|
76
|
+
"@parcha/agentrun-jev": "0.1.0-beta.56",
|
|
77
|
+
"@parcha/agentrun-kernel": "0.1.0-beta.56",
|
|
78
|
+
"@parcha/pi-browser": "0.1.0-beta.56",
|
|
79
79
|
"@secretlint/core": "14.1.0",
|
|
80
80
|
"@secretlint/profiler": "14.1.0",
|
|
81
81
|
"croner": "11.0.0",
|