@parcha/agentrun-serve 0.1.0-beta.41 → 0.1.0-beta.42
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 +53 -0
- package/NOTICE +2 -0
- package/README.md +77 -12
- package/dist/agent-rows.d.ts +1 -1
- package/dist/agents-store.js +3 -1
- package/dist/calendar/address.d.ts +49 -0
- package/dist/calendar/address.js +153 -0
- package/dist/calendar/fetch.d.ts +24 -0
- package/dist/calendar/fetch.js +146 -0
- package/dist/calendar/ics-faux.d.ts +39 -0
- package/dist/calendar/ics-faux.js +236 -0
- package/dist/calendar/labels.d.ts +3 -0
- package/dist/calendar/labels.js +61 -0
- package/dist/calendar/names.d.ts +52 -0
- package/dist/calendar/names.js +54 -0
- package/dist/calendar/parse.d.ts +108 -0
- package/dist/calendar/parse.js +625 -0
- package/dist/calendar/routes.d.ts +17 -0
- package/dist/calendar/routes.js +81 -0
- package/dist/calendar/tools.d.ts +23 -0
- package/dist/calendar/tools.js +124 -0
- package/dist/cli.js +3 -1
- package/dist/computer-record.d.ts +55 -0
- package/dist/computer-record.js +315 -0
- package/dist/computer-setting.d.ts +1 -0
- package/dist/computer-setting.js +15 -2
- package/dist/computers.js +2 -14
- package/dist/console/assets/index-DYJ_wj27.js +711 -0
- package/dist/console/index.html +1 -1
- package/dist/eval-feed.d.ts +2 -2
- package/dist/eval-feed.js +9 -5
- package/dist/feed/parse.d.ts +3 -2
- package/dist/feed/parse.js +9 -18
- package/dist/feed/pointer.d.ts +2 -0
- package/dist/feed/pointer.js +17 -0
- package/dist/file-types.js +1 -0
- package/dist/host-command.d.ts +3 -0
- package/dist/host-command.js +18 -0
- package/dist/host.d.ts +3 -0
- package/dist/host.js +3 -0
- package/dist/learn/check.d.ts +14 -0
- package/dist/learn/check.js +194 -14
- package/dist/learn/compile.d.ts +48 -27
- package/dist/learn/compile.js +134 -101
- package/dist/learn/promote.d.ts +61 -5
- package/dist/learn/promote.js +12 -2
- package/dist/learning-setting.d.ts +23 -0
- package/dist/learning-setting.js +51 -0
- package/dist/learning-words.d.ts +3 -0
- package/dist/learning-words.js +3 -0
- package/dist/learning.d.ts +3 -2
- package/dist/learning.js +5 -3
- package/dist/mcp-oauth.d.ts +8 -0
- package/dist/mcp-oauth.js +7 -0
- package/dist/mcp-private-hosts.d.ts +13 -0
- package/dist/mcp-private-hosts.js +16 -0
- package/dist/openapi.d.ts +1 -0
- package/dist/openapi.js +105 -9
- package/dist/run-files.d.ts +6 -2
- package/dist/run-files.js +29 -7
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/run-reads-over-store.d.ts +5 -1
- package/dist/run-reads-over-store.js +8 -4
- package/dist/run-recordings.d.ts +20 -0
- package/dist/run-recordings.js +133 -0
- package/dist/runner/adapter-loop.d.ts +1 -1
- package/dist/runner/adapter-loop.js +3 -6
- package/dist/runner/adapter-run-spec.d.ts +16 -1
- package/dist/runner/adapter-run-spec.js +20 -6
- package/dist/runner/beside.js +1 -1
- package/dist/runner/cli-run-spec.js +10 -7
- package/dist/runner/feedback-round.d.ts +9 -25
- package/dist/runner/feedback-round.js +22 -40
- package/dist/runner/learning-end.d.ts +17 -7
- package/dist/runner/learning-end.js +79 -53
- package/dist/runner/main.d.ts +11 -0
- package/dist/runner/main.js +29 -2
- package/dist/runner/mcp-run.d.ts +2 -2
- package/dist/runner/promotion.d.ts +36 -4
- package/dist/runner/promotion.js +280 -20
- package/dist/runner/reflect-hook.d.ts +5 -0
- package/dist/runner/reflect-hook.js +22 -14
- package/dist/runner/store-secrets.js +3 -1
- package/dist/runner/workflow-first.d.ts +0 -6
- package/dist/runner/workflow-first.js +7 -13
- package/dist/runs-over-store.d.ts +1 -1
- package/dist/sdk/runs.js +2 -1
- package/dist/secrets.js +2 -2
- package/dist/server.d.ts +4 -3
- package/dist/server.js +72 -11
- package/dist/store/agent-body.d.ts +5 -3
- package/dist/store/agent-body.js +14 -10
- package/dist/store-reads/learning.d.ts +1 -1
- package/dist/store-reads/loop.d.ts +1 -0
- package/dist/store-reads/loop.js +14 -4
- package/dist/store-view.d.ts +5 -0
- package/dist/store-view.js +4 -0
- package/dist/template-eval.d.ts +7 -0
- package/dist/template-eval.js +54 -6
- package/dist/templates.d.ts +3 -1
- package/dist/templates.js +14 -1
- package/dist/timeline/computer.js +2 -1
- package/dist/tool-list.js +1 -0
- package/dist/tools.d.ts +7 -0
- package/dist/tools.js +11 -0
- package/dist/trigger-feed.js +67 -18
- package/dist/validate.js +7 -2
- package/dist/workspace/computer-for-claim.d.ts +7 -0
- package/dist/workspace/computer-for-claim.js +12 -2
- package/dist/workspace/paths.d.ts +4 -0
- package/dist/workspace/paths.js +9 -0
- package/dist/workspace/resolve-computer.d.ts +3 -1
- package/launcher/agentrun-serve +31 -24
- package/package.json +10 -9
- package/templates/README.md +11 -2
- package/dist/console/assets/index-COGhx_2Z.js +0 -711
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,59 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## 0.1.0-beta.42 (2026-11-17)
|
|
6
|
+
|
|
7
|
+
- A learned workflow is compiled once and checked once against the agent's own answers. An agent definition's `learning` takes an object, `{ compile_after?, agree_min?, alone_min? }`, which is on (as `true`) with those numbers set; each one left out is its default (20, 0.8, 0.7), and `true` is every default. A number out of range or an unknown key is a 422 `wrong_type` on `definition.learning`.
|
|
8
|
+
- The first compile is asked once the agent has `compile_after` completed runs of its own. A count of kept notes no longer triggers it.
|
|
9
|
+
- A new revision's first claim replays it on the inputs of the agent's last `compile_after` completed runs. Each input is scored against the agent's own recorded answer, not a grade. The revision is promoted (promotion `source: "check"`) when it answered at least `alone_min` of them alone and at least `agree_min` of those said what the agent said. An input a guard or a recorded escalate would hand back when serving is not answered alone. Every reserved input counts in `n`: a replay run never created, or not ended by the check's deadline, is a failed input. A draft with nothing to check it on (no input of the agent's it takes, or every input skipped at a write) is never promoted: it stops (`check.stopped`, `n: 0`) with a reason that starts "nothing to check it on", shown as the compile's draft error, and asks no recompile. Under either bar it is held, and the agent's next run asks one revision with the inputs it disagreed on. That revision is checked the same way; held again, it stops (`check.stopped`), the agent keeps its runs, and nothing compiles again.
|
|
10
|
+
- The promotion record carries `check`: the bar, `n`, `agreed`, `alone`, the runs read, the tools that stopped skipped inputs (`skipped_tools`), and on a hold the disagreements. A promotion by check is not moved by later grades or refits, and a newer revision waits for a running check instead of queueing.
|
|
11
|
+
- Upgrading: promotion is now by agreement with the agent's own answers, not by grades. To compile sooner or hold drafts to a stricter bar, set `learning: { compile_after: 5, agree_min: 0.9 }` on the agent. A client that reads `definition.learning` as a boolean or `"notes"` must also accept an object, and treat it as on.
|
|
12
|
+
- A run's phone can carry real apps: the operator names APK files on the machine that drives the phones in `PHONE_HARNESS_APKS`, a comma list of `<absolute path>@sha256:<hex>`, and each phone installs them before the agent starts on it. A file that is not there, or whose bytes are not its pin, refuses the claim in words before a phone is rented. Breaking: the phone-harness provider's `apks` option takes `{ path, sha256 }` entries, not bare paths.
|
|
13
|
+
- The timeline names a phone's Clock, Contacts and Files apps and the Wikipedia app by the names on their icons (it said "Deskclock" for the Clock).
|
|
14
|
+
- A calendar for agents: an owner saves the server's one calendar by its secret iCal address (Google Calendar's "Secret address in iCal format", Outlook's ICS link, iCloud's public link), and the new host tool `calendar_events {from?, to?}` reads its events.
|
|
15
|
+
- The calendar's routes (the console's page for it comes next): `GET`, `PUT` and `DELETE /v2/settings/calendar` and `POST /v2/settings/calendar/test`, the owner's signed-in session alone (a secret write; the token is 403). `PUT {url}` takes https, and reads `webcal://` as https. The address is sealed in the store's sealed keys. It is in no answer, event, log line, error or run input, a failed fetch's words and the calendar's own name included. Each text is scrubbed before it is cut short, and the address's secret token (a path segment or query value that reads as one) is scrubbed on its own too, so no part of it gets through. When the address redirects, the address it was redirected to is scrubbed too, in every one of those places. `GET` answers `{configured, host, name, time_zone}`. The test answers in words, "Work: 214 events, time zone America/New_York, next: Standup, Mon Nov 17 09:30", for the saved address or the body's, saving nothing.
|
|
16
|
+
- `calendar_events`: the window defaults to now through 7 days on, and is at most 62 days (a longer one is refused in words). A `from` or `to` whose parts name no time (Feb 30, 25:00, 24:00, minute 61), with or without an offset, is refused in words, never rolled over to another day. It answers `{calendar, time_zone, from, to, count, truncated, events}` sorted by start, at most 200 events. Each event: `{title, start, end, all_day, location, description (cut at 500), status, recurring, organizer, attendees: [{name, email}]}`. Repeating events are expanded in the window (RRULE, RDATE, EXDATE). An RDATE period keeps its own end or duration. A moved instance (RECURRENCE-ID) is in its new place, and a cancelled one is left out; with RANGE=THISANDFUTURE, the move or cancellation applies to every later instance too. One read has a work budget across all its series: 15,000 rule steps, and at most 1 s. A calendar that needs more, such as hundreds of old every-minute series, is answered in words (it has too many repeating events to read), never as a partial list. A rule that ended before the window is not walked, and a plain rule starts just before the window instead of at its first instance years back. Each event keeps its own time zone, so a 09:30 meeting stays at 09:30 across a DST change, and floating times read in the calendar's X-WR-TIMEZONE, else the server's. As RFC 5545 says, a time a spring-forward skips takes the offset from before the change (02:30 reads 03:30), and a time a fall-back repeats is its first occurrence, whether the zone is named or is the file's own VTIMEZONE. An all-day event's start and end are dates. It runs on every harness, beside `web_fetch` and the email tools. An event's words are untrusted, as a page's are. It is allowed by default and not metered. The timeline reads "Calendar: 8 events, Nov 17-23", or "Calendar: couldn't read the calendar".
|
|
17
|
+
- The fetch is held to the server's one address rule, the one an MCP server's is: https only, a private address refused unless its host is allowed in Settings → MCP servers (private hosts), link-local and this machine never, loopback only on a local install and never at the server's own ports (where it listens, and its public address when that is on loopback), each redirect checked again and every hop dialled at the address checked. The tool's read on the runner beside a local install is held to the same own ports as the server's read: the server tells that runner its addresses (`Serve.own`), so a calendar saved at the server's address, or one that redirects there, is refused in words before anything is sent. 10 MB, 20 s, 5 redirects. A read is reused for 5 minutes, then revalidated with its ETag and Last-Modified (a 304 keeps the parsed copy). Those go only to the address the kept copy came from, so an address that now redirects somewhere else is read there in full.
|
|
18
|
+
- Templates: a package's `tools` may name `calendar_events`. With no calendar saved, it applies as the email tools do, and the tool answers that no calendar is saved. A template eval case may say `calendar: <file>.ics`: a fake calendar server on loopback serves it as the eval server's calendar, and the case's `now` is the window's clock.
|
|
19
|
+
- New dependency: `ical.js` 2.2.1, pinned exact (MPL-2.0, no dependencies of its own; 268 KB `dist/ical.js`, 1.2 MB unpacked). It loads at a calendar read only, never with the server.
|
|
20
|
+
- The compile turn's worked example is now the cascade a repeated job compiles to, and two checks hold drafts to it. The example fetches a page with a call step, has a fast-tier extract step copy compact facts from it, answers on the agent's model from those facts and its own draft alone, re-picks once in a loop of 2 until its quotes pass `quote_missing`, then hands back a second miss or a case the policy does not cover at an escalate step. It carries no guard.
|
|
21
|
+
- DSL: a whole-string placeholder marked optional, `"{draft?}"`, is null while its path is absent and the path's value once present. A re-pick loop's answer step reads its failed draft that way through its `state` map: null on the first pass, the draft on the second. An unmarked placeholder still fails with `missing_interpolation`, and `{x?}` inside a longer string stays literal text. The Lean model and the conformance corpus cover it. `placeholderValue(state, path)` is exported: the lookup every placeholder reads through (the path as written, then the path after `state.`), for a host that checks what a step reads. So is `placeholdersOf(text)`: the placeholders a string holds as interpolation fills them (a marked one only as the whole string).
|
|
22
|
+
- Compact state: a learned workflow draft is refused when a model step off the fast tier reads a page a call step fetched, through its `state` map or, with no map, the whole state. One refusal line names the step and what to give it.
|
|
23
|
+
- The quote check's re-pick now asks for that `state` map (the compact facts and `"draft": "{answer?}"`), where it asked for no map at all, which read every page on the agent's model.
|
|
24
|
+
- Upgrading: the compile turn asks for no step guard and refuses a draft with one (`guard`, its threshold and signal). Learned workflows already saved keep running as they are; a revision of one drops its guards.
|
|
25
|
+
- A Morph provider: `providerFor("morph", { apiKey })`, or `@parcha/agentrun-computer/morph`. A Morph computer is kind `linux`, an instance started from a snapshot over Morph's REST API, with its lifetime as Morph's TTL (action stop) and every command over SSH through Morph's gateway, as the instance id with the instance's own key (read over REST), so the account's key never goes over SSH. Its image is a snapshot id; `prepareImage()` finds or builds the box image as a snapshot in the key's account (digest `agentrun-box-<recipe hash>`). It has no Archil mount and no desktop yet. Network none, open and a list are init's, since Morph has no egress control. serve reads its key as `MORPH_API_KEY`.
|
|
26
|
+
- Conformance: `AGENTRUN_COMPUTER_LIVE_MORPH=1 COMPUTER_MORPH_API_KEY=... npm run conformance -w @parcha/agentrun-computer -- --provider morph`, and the live sweep takes `--provider morph`.
|
|
27
|
+
- A feed trigger reading a JSON list takes two optional pointers. `fields`, 1 to 50 JSON Pointers into an item (`["/number", "/title", "/user/login"]`), keeps only those in the payload's `item`, each at its own place, before the 16 KB cap: a GitHub pull request, which is over the cap whole, now fires without `item_truncated`. `updated`, a pointer to the item's date (`"/updated_at"`), lets an item fire again with `update: true` when that date moves on; without it a JSON list's item fires only once, as before.
|
|
28
|
+
- `validate-template` now refuses an eval case's `web:` fixture with no `search` (or any other shape `eval-template` refuses), in the same words.
|
|
29
|
+
- An eval's feed fake matches the item it delivers by the trigger's `id` pointer, not by `.id`, so a JSON list read at `/number` gets an update in place of the pull request it names, not a duplicate.
|
|
30
|
+
- `fields` and every feed pointer (`items`, `id`, `updated`) read and write an item's own keys only: a name such as `__proto__` or `constructor` is never reached through the prototype.
|
|
31
|
+
- A feed's seen set now tells a missing date from a real one: an item dated 1970-01-01 or earlier fires `update: true` when its date moves on. A cursor saved before this reads a JSON list's recorded 0 as a missing date, once.
|
|
32
|
+
- Fly Machines is a computer provider (`fly`, `@parcha/agentrun-computer/fly`): a dial host whose machines boot the box image and dial the server, with `FLY_API_TOKEN` and `FLY_APP` (the Fly app its machines live in) saved in Settings → Computers. Its Core runs inside the server the machines dial: `node packages/serve/scripts/dial-conformance.mjs --provider fly`, with `COMPUTER_FLY_API_TOKEN`, `COMPUTER_FLY_APP`, `AGENTRUN_PUBLIC_URL` and `PORT` set, which the server's image carries. It prints its report between two marker lines and then idles until stopped (`--exit` exits instead), so a host that restarts an exited process does not start a second run.
|
|
33
|
+
- A learned workflow is asked for a revision only when its promotion record holds it, once per hold. A hand-back, a stop by the money rule and a wrong grade of a served run no longer each ask a compile turn: one bad case is one sample, and the hold (a replay under the bar, or graded runs under the agent's accuracy) reads it among the workflow's others. The first compile is still asked as before.
|
|
34
|
+
- A wrong grade of a run its learned workflow answered opens no feedback round. The grade is kept (PUT /runs/{id}/grade answers `feedback: null`), and the graded hold, replay and refit read it. The `revise` feedback round is gone; `look_back` is the only one.
|
|
35
|
+
- The money rule still stops a workflow that costs more than the agent and may hold it. The stop asks for no compile; the agent takes the run.
|
|
36
|
+
- An agent run of an agent with `learning: true` asks no look-back turn unless its owner gave feedback on it: a grade's words, or a message after the run's first. A run without it spends $0 looking back and keeps its learning dropped `empty`, saying it looks back only on feedback. A compile that is due is still asked. `learning: "notes"` runs look back as before. An SDK run carries no owner feedback, so an SDK agent with `learning: true` learns through its compile turn alone.
|
|
37
|
+
- A new draft's compile ask asks for no step guard, Jev or `self`, whether or not the run can call Jev, and the checks refuse a draft with one (see the compile turn's upgrading note above).
|
|
38
|
+
- Upgrading: a workflow agent's runs stop looking back on their own; give feedback (a grade with words, or a follow-up message) on the runs it should learn from. A client that read `feedback: "revise"` on a grade reads `null` for a served run now.
|
|
39
|
+
- An agent's desktop or phone can record a video of each run's screen: `definition.computer.record: true` (off by default).
|
|
40
|
+
- The recorder watches the screen on a connection of its own, from the claim's attach until the computer's release or the run's end, with or without a viewer open. A park pauses it; the resumed run goes on in a new file. It never holds up the live view or the agent: a frame that comes while the encoder is busy replaces the one waiting, and is counted.
|
|
41
|
+
- One ffmpeg per recorded computer, frames piped in and stamped as they come: at most 10 frames a second, 1280 pixels on the long side, no audio, H.264 in fragmented MP4. A frame of another format (a phone's PNG, then JPEG) goes on in the next file.
|
|
42
|
+
- The files are `recordings/<computer>.mp4` in the run's folder on the machine that runs it, beside `work/`, never in it. Caps: 500 MB across a run's files, and 2 hours from the recording's start or the run's resume. A cap, an encoder that stops (a crash, a full disk) or a screen that stops answering ends the recording with a line on the run's timeline; the run never fails because of it.
|
|
43
|
+
- The video shows everything on the screen, a person's typing during a take-over and any secret included: pixels can't be redacted.
|
|
44
|
+
- A server without ffmpeg on its `PATH` refuses `record: true` at save: 422 `not_allowed` on `definition.computer.record`, naming the fix. The published image now has an `ffmpeg` built for the recorder alone (about 6 MB). A desktop or a phone only: on another kind, 422 `not_allowed`.
|
|
45
|
+
- A runner in its own process (`agentrun-serve runner`, beside a server started with `--no-runner` or in a service of its own) now honours `AGENTRUN_MCP_ALLOW_LOOPBACK=1` from its own environment, as the server and the runner inside the server's process already did. Before, every call such a runner made to an MCP server on loopback was refused as a private address, nothing sent.
|
|
46
|
+
Each process reads only its own variable, never the server's, the store's or the data directory's, so a runner never inherits it. Loopback means the machine (or container) the runner runs on: a runner in another container or service needs its own server or forwarder at the MCP server's address, and its own `=1`. A runner with the variable never reaches loopback at a server's own port: 7340 (where a server listens unless `--port` says otherwise), the port of a loopback `AGENTRUN_PUBLIC_URL` in its environment, and the addresses the server now keeps in the store at each start (`mcp.server_own`: where it listens, whatever its port), read at each claim. Those addresses are all a runner reads of the server. It says on stderr at its start that it takes the variable. A runner without it is refused as before, even when the server has it.
|
|
47
|
+
On a server started without the variable, a run of a revision saved before pins (pinned at its first run) whose MCP server is on loopback was refused (409) with "save the agent again to pin it", though a save is refused too. The 409 now names the cause: `its server <name> can't be listed here to pin it: 127.0.0.1 is this machine; set AGENTRUN_MCP_ALLOW_LOOPBACK=1 when starting the server, ...`. With the variable set on the server, such a revision is pinned at its first run and runs, as before.
|
|
48
|
+
- The image's ffmpeg is one static binary of about 6 MB built for the screen recorder alone (PNG and JPEG frames in, H.264 in fragmented MP4 out), in place of Debian's `ffmpeg` and its libraries: the image is 163 MB smaller than with Debian's, and 2.8 MB larger than with no ffmpeg at all. FFmpeg 9.0.2, x264 and zlib, each pinned by sha256, cross-compiled for arm64. The image build runs the recorder on it and fails unless it makes H.264 files from both kinds of frame. It is GPL, as Debian's ffmpeg is; the licence files are in `/usr/local/share/doc/ffmpeg`.
|
|
49
|
+
- The launcher (`agentrun-serve`) hands over secrets of any total size. Before, it refused to start once the secrets it names came to more than 4,096 bytes, which a host with a dozen real keys, or one RSA `AGENT37_SSH_KEY`, could reach. A fork of the launcher's shell now writes the pipe as the server reads it, and exits once the last byte is in, or at its next write once a server that exited without reading leaves no read end. No secret goes into an argument, the server's environment or a file, as before.
|
|
50
|
+
- A run's screen recordings can be read through the API and exported from the console.
|
|
51
|
+
- The run read lists them in `recordings`: each one's `path`, `computer`, `seconds`, `bytes` and whether it is `finished`. Empty when the agent doesn't record.
|
|
52
|
+
- `GET /v2/runs/{run_id}/files/recordings/<computer>.mp4` serves one as `video/mp4`, read-only, to whoever may read the run's other files; `?download=1` for an attachment. One still being written is served as it stands.
|
|
53
|
+
- The files route answers one byte range (`Range`, `206` with `Content-Range`; past the end, `416 range_not_satisfiable`) for every file, so a `<video>` can seek: `features.files.range` is now true.
|
|
54
|
+
- A recording reaches the disk as it is made, a fragment every 2 seconds or so: a quiet screen's few frames no longer sit in ffmpeg's input probe (and a phone's PNG frames in its decoder's threads) until the recording's end.
|
|
55
|
+
- The console's Screen tab says "Recording" while a recording is written, and offers Export once it is finished.
|
|
56
|
+
- Breaking: a folder an agent makes named `recordings` at the root of its run's `work/` is no longer listed or served: that path is the run's recordings.
|
|
57
|
+
|
|
5
58
|
## 0.1.0-beta.41 (2026-11-16)
|
|
6
59
|
|
|
7
60
|
- A message sent to a working `claude-agent` run now steers it mid-turn. Before, it waited for the turn's end, and a run whose whole job is one turn read it only after the work was done. The model now reads it at its next step, after the tool calls in flight finish, in the same turn. `POST /v2/runs/{id}/messages` answers mode `steer` for a working claude-agent run (it answered `follow_up`), and `GET /v2/capabilities` lists `claude-agent` with `steer: true`.
|
package/NOTICE
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
AgentRun
|
|
2
2
|
Copyright 2026 Parcha Labs, Inc.
|
|
3
3
|
|
|
4
|
+
The boxd computer provider (packages/computer/src/boxd.ts) was contributed by Michiel Voortman.
|
|
5
|
+
|
|
4
6
|
The console in dist/console bundles third-party software. dist/console/THIRD-PARTY-NOTICES.txt names each
|
|
5
7
|
package it holds, with its version, its license and its license text.
|
|
6
8
|
|
package/README.md
CHANGED
|
@@ -640,6 +640,10 @@ has the Docker client (Debian's `docker-cli`) and no daemon; `group_add` gives t
|
|
|
640
640
|
with the file tools and no shell.
|
|
641
641
|
- On a host the server finds no container of its own and asks Docker nothing: a box binds this machine's paths and its
|
|
642
642
|
proxy's directory is under `/tmp`, as before.
|
|
643
|
+
- **ffmpeg.** The image has an `ffmpeg` built for the screen recorder alone, which records an agent's screen where its
|
|
644
|
+
computer says `record: true` ([A video of each run](#computers)): one static binary of about 6 MB that reads PNG and
|
|
645
|
+
JPEG frames and writes H.264 in MP4, and nothing else. FFmpeg 9.0.2 with x264, so it is GPL, as Debian's ffmpeg is;
|
|
646
|
+
the licence files are in `/usr/local/share/doc/ffmpeg`.
|
|
643
647
|
|
|
644
648
|
<a id="boxes"></a>
|
|
645
649
|
|
|
@@ -651,8 +655,8 @@ Settings → Computers. The kind says what the agent is given, and the provider
|
|
|
651
655
|
| Kind | What the agent gets | Providers |
|
|
652
656
|
|---|---|---|
|
|
653
657
|
| `none` | The run's folder alone: no computer, and no provider (`{"kind": "none"}`) | |
|
|
654
|
-
| `sandbox` | A Linux shell, with files and processes | `docker`, `daytona`, `modal`, `e2b` |
|
|
655
|
-
| `desktop` | The computer's tools (`computer_observe`, `computer_act`, `computer_screenshot`), the computer as `codemode`'s `computer`, and a shell where its provider mounts the run's folder | `docker` (with an image that has an X server), `e2b`, `orgo`, or [a paired computer](#a-persons-own-computer) by its id |
|
|
658
|
+
| `sandbox` | A Linux shell, with files and processes | `docker`, `daytona`, `modal`, `e2b`, `boxd`, `cloudflare` (through a relay Worker you deploy) |
|
|
659
|
+
| `desktop` | The computer's tools (`computer_observe`, `computer_act`, `computer_screenshot`), the computer as `codemode`'s `computer`, and a shell where its provider mounts the run's folder | `docker` (with an image that has an X server), `e2b`, `orgo`, `boxd`, or [a paired computer](#a-persons-own-computer) by its id |
|
|
656
660
|
| `phone` | A rented Android, through the same computer tools | `phone-harness` |
|
|
657
661
|
| `browser` | A hosted browser (the browser tools) | `browserbase`, `kernel` |
|
|
658
662
|
|
|
@@ -686,8 +690,11 @@ whether this server offers it now, the tools it brings, and each provider with i
|
|
|
686
690
|
the owner's signed-in session only (the API token is 403), and `POST /v2/computers/{provider}/test` makes one read at
|
|
687
691
|
the provider with them and starts nothing. A key set in the server's environment wins over the saved one. The keys are
|
|
688
692
|
`DAYTONA_API_KEY` (with `DAYTONA_API_URL` and `DAYTONA_TARGET` optional), `MODAL_TOKEN_ID` and `MODAL_TOKEN_SECRET`,
|
|
689
|
-
`E2B_API_KEY`, `
|
|
690
|
-
`
|
|
693
|
+
`E2B_API_KEY`, `AGENT37_API_KEY` and `AGENT37_SSH_KEY`, `MORPH_API_KEY`, `ORGO_API_KEY`, `PHONE_HARNESS_API_KEY`,
|
|
694
|
+
`BROWSERBASE_API_KEY` and `BROWSERBASE_PROJECT_ID`, `KERNEL_API_KEY`, `BOXD_API_KEY` (with `BOXD_ORG` and
|
|
695
|
+
`BOXD_REGION` optional), `CLOUDFLARE_RELAY_URL` and `CLOUDFLARE_RELAY_TOKEN` (the relay Worker's,
|
|
696
|
+
`packages/computer/relays/cloudflare`), and `FLY_API_TOKEN` and `FLY_APP`; Docker takes none.
|
|
697
|
+
The vendors bill their computers by time on their own pages: this server meters no
|
|
691
698
|
computer time. The older [`place`](#place) is this setting's v2 view: `{"mode": "runner"}` is kind `none`, and
|
|
692
699
|
`{"mode": "sandbox", "box": X}` is a sandbox on provider X. Writing either sets both.
|
|
693
700
|
|
|
@@ -700,6 +707,13 @@ They apply to Docker computers only: a vendor's computer (Daytona, Modal, E2B, O
|
|
|
700
707
|
size its provider makes it, and is never given them. A value the Docker provider refuses stops the server's start, in
|
|
701
708
|
the provider's words.
|
|
702
709
|
|
|
710
|
+
**A phone's apps.** A phone has its stock apps. To give every phone more, the operator names APK files on the machine
|
|
711
|
+
that drives the phones (the server's, or its runner's) in that machine's environment, each pinned by its sha256:
|
|
712
|
+
`PHONE_HARNESS_APKS=/srv/apks/wikipedia.apk@sha256:<64 hex digits>`, a comma list. Only the operator sets it: no agent
|
|
713
|
+
setting, API or Settings page names an APK, and the server downloads nothing. Each phone installs them
|
|
714
|
+
(`pm install -r`) before the agent starts on it. A file that is not there, or whose bytes are not its pin, refuses the
|
|
715
|
+
claim in words before a phone is rented; a value that is not such a list refuses every phone, naming the entry.
|
|
716
|
+
|
|
703
717
|
**GPUs.** A sandbox may ask for GPUs: `computer: {"kind": "sandbox", "provider": "daytona", "gpu": {"type": "H100",
|
|
704
718
|
"count": 1}}`. `GET /v2/computers` shows each sandbox provider's `gpu`: the types it gives, by the vendor's own names, the
|
|
705
719
|
most one computer gets, and where a GPU computer differs from its others. A provider whose GPU computers cannot hold
|
|
@@ -734,6 +748,37 @@ one computer that it keeps between runs, instead of a fresh one for each run:
|
|
|
734
748
|
- The computer is owned by this server's id (kept in its store) and the agent's id, so two servers on one vendor
|
|
735
749
|
account never take each other's. The janitor deletes an agent's computer only once its agent no longer wants it.
|
|
736
750
|
|
|
751
|
+
**A video of each run.** `computer: {"kind": "desktop", "provider": "e2b", "record": true}` records the computer's
|
|
752
|
+
screen during each of the agent's runs. Off by default; a desktop or a phone only (another kind is 422).
|
|
753
|
+
|
|
754
|
+
- **It shows everything on the screen.** That includes what a person types while they have taken over the computer, and
|
|
755
|
+
any password, key or private page shown on it. Pixels can't be redacted. Turn it on only for an agent whose screen
|
|
756
|
+
you would be fine to keep and share.
|
|
757
|
+
- **What it records.** The screen while the run holds its computer: from the claim's attach until the computer's
|
|
758
|
+
release or the run's end. A parked run's recording pauses and goes on in a new file when the run resumes. At most 10
|
|
759
|
+
frames a second, 1280 pixels on the long side, no sound, H.264 in fragmented MP4, so a file cut short still plays.
|
|
760
|
+
Each frame is stamped with the time it came, so the video plays at the screen's own pace. The recorder watches the screen on a connection of its own, so it
|
|
761
|
+
records with no viewer open, and it never holds up the live view or the agent: a frame that comes while the encoder is
|
|
762
|
+
still busy replaces the one waiting.
|
|
763
|
+
- **Where it goes.** `recordings/<computer>.mp4` in the run's folder on the machine that runs it
|
|
764
|
+
(`<data>/disk/agents/<agent>/runs/<run>/recordings`, beside the run's `work/` folder, never in it, so the agent can't
|
|
765
|
+
read or change it). It is kept with the run's files. A phone whose frames change from PNG to JPEG, and a resumed run,
|
|
766
|
+
go on in `<computer>-2.mp4` and so on.
|
|
767
|
+
- **Reading it.** The run read (`GET /v2/runs/{run_id}`) lists them in `recordings`: each one's `path`, `computer`,
|
|
768
|
+
`seconds`, `bytes` and whether it is `finished` (false while it is still being written; every file is finished a few
|
|
769
|
+
seconds after the run ends, once its encoder has let go of it). A recording reaches the disk as it is made, a
|
|
770
|
+
fragment every 2 seconds or so. `GET /v2/runs/{run_id}/files/recordings/<computer>.mp4` serves one as `video/mp4`, read-only, to
|
|
771
|
+
whoever may read the run's other files, with byte ranges (`206`) so a `<video>` can seek, and `?download=1` for an
|
|
772
|
+
attachment. One still being written is served as it stands: it plays up to its last whole fragment. The console's
|
|
773
|
+
Screen tab says "Recording" while one is written and offers Export once it is finished. The server reads the folder
|
|
774
|
+
on its own machine, where the runner beside it recorded. A folder the agent makes named `recordings` at the root of
|
|
775
|
+
its `work/` is neither listed nor served: that path is its recordings. What the video can show is said above.
|
|
776
|
+
- **Its caps.** 500 MB across a run's files, a resumed run's included, and 2 hours of recording from its start or the
|
|
777
|
+
run's resume, whichever comes first. At a cap the recording stops, and the run's timeline says so. So does an encoder that stops by itself (a crash, a full disk) or a screen that stops
|
|
778
|
+
answering. The run itself never fails because of its recording.
|
|
779
|
+
- **It needs ffmpeg** on the server's `PATH` (the published image has it). A server without it refuses `record: true`
|
|
780
|
+
when the agent is saved, with 422 `not_allowed` naming the fix.
|
|
781
|
+
|
|
737
782
|
#### A person's own computer
|
|
738
783
|
|
|
739
784
|
A computer of your own (a laptop, a desktop, a phone) can be an agent's computer. A driver on it dials this server and
|
|
@@ -790,7 +835,8 @@ passes the binding's conformance cases (below) needs no change here.
|
|
|
790
835
|
client hangs on its sandboxes. On a self-hosted Daytona target whose sandboxes reach Archil through an Archil egress
|
|
791
836
|
relay, save the relay's address as `DAYTONA_ARCHIL_EGRESS` (Settings → Computers, beside `DAYTONA_API_KEY`) and name
|
|
792
837
|
a snapshot of `box/Dockerfile` in `AGENTRUN_DAYTONA_SNAPSHOT` (below): the Daytona sandbox then mounts the run's
|
|
793
|
-
folder and is ready. With the relay but no snapshot named, it is refused, saying to name one.
|
|
838
|
+
folder and is ready. With the relay but no snapshot named, it is refused, saying to name one. A boxd sandbox takes no
|
|
839
|
+
mount yet, so it is refused in both modes; a boxd desktop runs in either.
|
|
794
840
|
|
|
795
841
|
The PUT is a secret write, so it takes the owner's signed-in session. A server with none to give it (API only, or
|
|
796
842
|
`AGENTRUN_ACCOUNTS=0` reached beyond loopback) is set where it is started instead: `AGENTRUN_ARCHIL_REGION` and
|
|
@@ -1783,9 +1829,21 @@ every request to one) must be `https` and resolve to no private, loopback or lin
|
|
|
1783
1829
|
refresh is refused with words and nothing is sent. A loopback MCP server (a `127.0.0.1` or `localhost` URL) is taken only
|
|
1784
1830
|
by a server started with `AGENTRUN_MCP_ALLOW_LOOPBACK=1`, which says this is a local install: set it only on a machine you
|
|
1785
1831
|
alone use, since loopback is this machine's other services too. Without it such a URL is refused at the save, the preview
|
|
1786
|
-
and the sign-in, in words naming the variable, and a runner never reaches one
|
|
1787
|
-
|
|
1788
|
-
tells it as it starts
|
|
1832
|
+
and the sign-in, in words naming the variable, and a runner never reaches one. The runner beside such a server reaches
|
|
1833
|
+
one, never at that server's own ports (where it listens, and its public address when that is on loopback), which the
|
|
1834
|
+
server tells it as it starts.
|
|
1835
|
+
|
|
1836
|
+
A runner in its own process (`agentrun-serve runner`, in the server's container or in a service of its own) takes the
|
|
1837
|
+
variable from its own environment alone, never from the server, the store or the data directory. Started with
|
|
1838
|
+
`AGENTRUN_MCP_ALLOW_LOOPBACK=1`, its runs reach an MCP server on its own loopback: the machine (or container) that runner
|
|
1839
|
+
runs on, which is the server's only when they share one. So each such runner needs the variable and, at the MCP
|
|
1840
|
+
server's address, a server or forwarder on its own loopback. Without the variable it is refused, whatever the server
|
|
1841
|
+
says. Such a runner never reaches loopback at a server's own port: 7340 (where a server listens unless `--port` says
|
|
1842
|
+
otherwise), its own `AGENTRUN_PUBLIC_URL`'s port when that address is on loopback, and the addresses the server keeps in
|
|
1843
|
+
the store at each start (where it listens, whatever its port), read at each claim. Those addresses are all it reads of
|
|
1844
|
+
the server; it says on stderr at its start that it takes the variable. For any runner, an MCP server, a refresh's endpoint or a calendar at a refused port is refused unsent, as at a
|
|
1845
|
+
save.
|
|
1846
|
+
|
|
1789
1847
|
An MCP server's URL is shown on every read as its origin and `/…`: its path and query are held as a secret, sent only to
|
|
1790
1848
|
the server itself, and sending the shown URL back for a saved server keeps the saved one. A loopback MCP server is a development-only exception: its
|
|
1791
1849
|
authorization server may name endpoints on the MCP server's own loopback host, exactly as its URL writes it (never
|
|
@@ -2394,7 +2452,7 @@ failed, 2 when nothing ran. The runner, the graders and the report are in
|
|
|
2394
2452
|
| `POST /runs/{id}/messages` | To an agentic run: `steer` while the agent works, `answer` when it asked the person, `follow_up` after a stop or after it completed: a completed run opens again, the same run on its own session and store, takes a place under `--max-runs` (it waits for one when none is free), and completes again. A failed or cancelled run, an archived run and a run of an archived agent are `409 not_continuable`; a workflow run takes none (`501`). |
|
|
2395
2453
|
| `POST /runs/{id}/stop`, `POST /runs/{id}/cancel` | Stop ends an agentic run's turn and leaves the run `input_required` and idle. Cancel ends a run `cancelled` once its process has exited. |
|
|
2396
2454
|
| `POST /runs/{id}/archive`, `POST /runs/{id}/unarchive` | [Archiving](#archiving) one run. Answers the run, with `archived_at`. |
|
|
2397
|
-
| `GET /runs/{id}/files`, `GET /runs/{id}/files/{path}` | The files under the run's `work/`, raw. |
|
|
2455
|
+
| `GET /runs/{id}/files`, `GET /runs/{id}/files/{path}` | The files under the run's `work/`, raw, one byte range at a time on asking (`Range`, `206`); and its screen recordings under `recordings/` ([A video of each run](#computers)). |
|
|
2398
2456
|
| `POST /files`, `PUT /files/{id}`, `GET /files`, `GET` and `DELETE /files/{id}` | [Uploads](#uploads): a file sent in one call (`POST /v2/files?path=...`, its bytes the body), or reserved and then sent (`PUT /v2/files/{id}`); the server's uploads listed, read and deleted. |
|
|
2399
2457
|
| `GET /agents/{id}/home/files`, and `GET`, `PUT`, `DELETE` on a file's path below it | The files in the agent's home, listed, read, written and deleted ([agent home](#agent-home)). This server's own routes (`x-agentrun-serve: "home/1"`). |
|
|
2400
2458
|
| `GET /stats` | This server's own route, outside the contract (`x-agentrun-serve: "stats/1"`): the agents, the runs (`total`, `active`, `needs_input`, `failed`, `needs_review`, `status_unknown`), each agent's run count, the cost and what is archived, read from the agent store's aggregates alone, no run's files opened. Archived agents and runs are left out of every number but `archived`. A completed or cancelled run counts only in `runs.total`, but for an escalated one (completed, waiting for a person's review), which `needs_review` (`stats/3`) counts; `failed` never does. Each running run is in exactly one of `active` (queued or working) and `needs_input` (`input_required`), both from the runs this server holds, and `status_unknown`: a running run it does not hold, or holds as ended before its end is written. `cost.usd` sums the runs that ended with a cost and is null when none did, never $0, with `basis` `estimate`, or null beside a null `usd`; `unknown_runs` counts the rest. `analytics` (`stats/2`) sums the runs' metrics over the runs not archived that `from` and `to` (RFC 3339 date-times to the millisecond, an impossible one or a finer fraction refused; runs started in [`from`, `to`)) and `agent` pick, each optional, 400 when malformed: `filter` echoes them; `totals` (runs, completed, an escalated run included, `needs_review` (`stats/3`), failed, never an escalated run, `runs_with_metrics`, tokens and each token kind, requests, unmetered, `cost_usd` and `unknown_cost_runs`), `time` (`wall_ms` over the ended runs, `active_ms` where metrics have it), `by_harness_effort`, `by_day` (UTC), `by_source` (`live` or the import source) and the top 20 `tools`. A run with no metrics counts in `runs` and in no token sum. `learning` (`learning/1`) counts the runs that tried to learn over the same filters, from the store ([Learning](#learning)). The query bounds `analytics` and `learning` alone. |
|
|
@@ -2440,7 +2498,9 @@ incident that is updated); items with no id are told apart by link, then by titl
|
|
|
2440
2498
|
the items it has seen, the larger of 1,000 and twice the feed's length, so an item that drops off and comes back stays seen.
|
|
2441
2499
|
One poll starts 20 runs at most across all its URLs, oldest first; the rest wait for the next poll, which the check says
|
|
2442
2500
|
(`Read <feed>: 26 new, 6 more at the next check.`). Each read is conditional on the last ETag and Last-Modified, and a
|
|
2443
|
-
`304` reads nothing.
|
|
2501
|
+
`304` reads nothing. A JSON list's item has no feed date of its own: it fires once, and again with `update: true` only when
|
|
2502
|
+
the source names an `updated` pointer (`"/updated_at"`) and the date there moves on. An item first seen with no date there
|
|
2503
|
+
does not fire when it gains one.
|
|
2444
2504
|
|
|
2445
2505
|
**When a feed fails.** A read that fails (no answer, an HTTP error, a body that isn't a feed) is said in the trigger's last
|
|
2446
2506
|
check and read again at the next poll; nothing it saw is lost. A `410`, or a `404` three checks running, stops that URL:
|
|
@@ -2456,7 +2516,9 @@ A feed that declares an entity in a DTD is refused.
|
|
|
2456
2516
|
**The payload.** An RSS, Atom or JSON Feed item: `{id, link, title, published, updated, author, summary, categories,
|
|
2457
2517
|
feed: {title, url}, update}`, with `summary` as plain text of 4,000 characters at most and `update` true when the item
|
|
2458
2518
|
was seen before and has been updated since. A JSON list item: `{id, link, title, item, update}`, `item` the raw object (cut down,
|
|
2459
|
-
with `item_truncated`, when it would pass 16 KB). A
|
|
2519
|
+
with `item_truncated`, when it would pass 16 KB). A JSON list's source may name `fields`, 1 to 50 JSON Pointers into an
|
|
2520
|
+
item (`["/number", "/title", "/html_url", "/user/login"]`): `item` then keeps only those, each at its own place, before the
|
|
2521
|
+
16 KB cap, so a pull request that is large whole fires without `item_truncated`. A run it starts is titled `Feed <trigger name>: <item title>`, and its payload is marked untrusted.
|
|
2460
2522
|
|
|
2461
2523
|
### API only
|
|
2462
2524
|
|
|
@@ -3058,7 +3120,10 @@ less the active notes), that `No notes.` is a fine answer, and what not to keep.
|
|
|
3058
3120
|
with no reserve, and within 5 minutes; its rows are labelled `learning`, and the run's answer stays the job's. While it
|
|
3059
3121
|
runs, the run reads `reflecting` on every harness. A run whose only tool work was its learned workflows, each answering,
|
|
3060
3122
|
with nothing said after its first message, is not asked: no request is sent, and its learning ends `dropped` (`empty`),
|
|
3061
|
-
"Nothing new: the run only ran a learned workflow."
|
|
3123
|
+
"Nothing new: the run only ran a learned workflow." A run of an agent with `learning: true` (one that compiles workflows)
|
|
3124
|
+
is not asked either unless its owner gave feedback on it: a grade's words, or a message after the run's first. It spends
|
|
3125
|
+
$0 looking back, its learning ends `dropped` (`empty`) saying it looks back only on feedback, and a compile turn that is
|
|
3126
|
+
due is still asked. A `learning: "notes"` run is asked as above.
|
|
3062
3127
|
|
|
3063
3128
|
The same turn may give one skill (only when the job completed) and one workflow draft, when the work repeats. Once a
|
|
3064
3129
|
learned skill the run was given has been given to 3 earlier runs of its agent, with no learned workflow of that name,
|
package/dist/agent-rows.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ export type AgenticBody = {
|
|
|
36
36
|
harness?: string;
|
|
37
37
|
place?: RevisionPlace;
|
|
38
38
|
computer?: RevisionComputer;
|
|
39
|
-
learning?:
|
|
39
|
+
learning?: import("./learning-setting.js").LearningSetting;
|
|
40
40
|
toolSettings?: Record<string, Record<string, string>>;
|
|
41
41
|
approvals?: "never";
|
|
42
42
|
maxCostUsd?: number;
|
package/dist/agents-store.js
CHANGED
|
@@ -10,6 +10,7 @@ import { agentLink } from "./console-links.js";
|
|
|
10
10
|
import { approvalsOf } from "./approvals.js";
|
|
11
11
|
import { ApiError, invalid } from "./errors.js";
|
|
12
12
|
import { harnessOfBody } from "./harness.js";
|
|
13
|
+
import { learningSettingIssue } from "./learning-setting.js";
|
|
13
14
|
import { storedHarness } from "./harness-table.js";
|
|
14
15
|
import { AgentBodyInvalid, RevisionMoved, bodyOf, canonical, isObject, StoreConstraint, } from "./store/index.js";
|
|
15
16
|
import { canonicalToolSettings, settingsIssues } from "./tool-plane.js";
|
|
@@ -102,7 +103,8 @@ function revisionInputOf(definition, files) {
|
|
|
102
103
|
// permissionOf with the revision's approvals): a call node on a tool set to ask runs under never, as on main.
|
|
103
104
|
if (isObject(definition.workflow))
|
|
104
105
|
return { kind: "workflow", workflow: definition.workflow, ...(definition.approvals === "never" ? { approvals: "never" } : {}), ...common, ...capped };
|
|
105
|
-
|
|
106
|
+
// true, false, "notes" or the loop's numbers (learning-setting.ts), checked by validate.ts and again by the body.
|
|
107
|
+
const learning = definition.learning !== undefined && learningSettingIssue(definition.learning) === undefined ? { learning: definition.learning } : {};
|
|
106
108
|
return {
|
|
107
109
|
kind: "agentic",
|
|
108
110
|
instructions: definition.instructions,
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ApiError } from "../errors.js";
|
|
2
|
+
import type { SealedKeys } from "../store/index.js";
|
|
3
|
+
export type CalendarStore = {
|
|
4
|
+
sealedKeys: Pick<SealedKeys, "get" | "put" | "remove">;
|
|
5
|
+
flush?(): Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
/** The calendar as the server keeps it: its address (https, or http to a loopback fake), and its own name
|
|
8
|
+
* (X-WR-CALNAME) and time zone as the save read them, null when that read failed. */
|
|
9
|
+
export type SavedCalendar = {
|
|
10
|
+
url: string;
|
|
11
|
+
name: string | null;
|
|
12
|
+
time_zone: string | null;
|
|
13
|
+
};
|
|
14
|
+
/** A loopback hostname as written: only there is plain http taken, for the fakes. */
|
|
15
|
+
export declare const LOOPBACK_NAME: RegExp;
|
|
16
|
+
/** The address a body gives, as it is kept: `webcal://` (and `webcals://`) read as https, any other scheme but https
|
|
17
|
+
* refused, and plain http taken to a loopback address alone. 422 by `field`, in words, never echoing the address. */
|
|
18
|
+
export declare function addressOf(value: unknown, field?: string): string;
|
|
19
|
+
/** Every form of `url` that text may carry it in, longest first: as kept, as webcal, decoded, its path with its query
|
|
20
|
+
* (where a provider keeps the secret part) when that is long enough to be one, and each path segment and query value
|
|
21
|
+
* that is a token on its own (tokenLike), so text that holds the address cut short holds none of its secret. What the
|
|
22
|
+
* redactors hold. */
|
|
23
|
+
export declare function addressForms(url: string): string[];
|
|
24
|
+
/** Each form of `url` cut from `text` (a fetch error, a calendar's own text): the address is never said. `url` may be the
|
|
25
|
+
* saved address and each address a read was redirected to (fetch.ts ReadCalendar followed), every one a secret: their
|
|
26
|
+
* forms are cut together, longest first. */
|
|
27
|
+
export declare function scrubAddress(text: string, url: string | readonly string[] | undefined): string;
|
|
28
|
+
/** The address of an opened calendar row, in each of its forms (runner/store-secrets.ts: the one redactor holds them, not
|
|
29
|
+
* the row's JSON). */
|
|
30
|
+
export declare const calendarRowSecrets: (plain: string) => string[];
|
|
31
|
+
/** The calendar kept now, opened with `sealKey`; undefined when none is kept, or its row does not open (sealed under
|
|
32
|
+
* another key) or read. */
|
|
33
|
+
export declare function openCalendar(store: CalendarStore, sealKey: Buffer): Promise<SavedCalendar | undefined>;
|
|
34
|
+
/** The calendar's view (GET /settings/calendar): whether one is kept, the host it is read from, and its own name and time
|
|
35
|
+
* zone. Never its address. */
|
|
36
|
+
export declare function calendarView(store: CalendarStore, sealKey: Buffer): Promise<{
|
|
37
|
+
configured: boolean;
|
|
38
|
+
host: string | null;
|
|
39
|
+
name: string | null;
|
|
40
|
+
time_zone: string | null;
|
|
41
|
+
}>;
|
|
42
|
+
/** The calendar saved whole, in one write. */
|
|
43
|
+
export declare function saveCalendar(store: CalendarStore, sealKey: Buffer, calendar: SavedCalendar): Promise<void>;
|
|
44
|
+
/** The calendar forgotten: its one row, in one write. */
|
|
45
|
+
export declare function removeCalendar(store: CalendarStore): Promise<void>;
|
|
46
|
+
/** A PUT's or a test's body, `{url}`, read: its address, or 422 in words. */
|
|
47
|
+
export declare function bodyAddress(body: unknown): string;
|
|
48
|
+
/** The refusal for a test of the saved calendar when none is kept. */
|
|
49
|
+
export declare const noCalendar: () => ApiError;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// The server's one calendar (saved with PUT /v2/settings/calendar, routes.ts): its iCal address, which is a credential (anyone
|
|
2
|
+
// who has it reads the calendar), kept in ONE row of the one store's sealed keys (CALENDAR_ROW, beside the tool keys and
|
|
3
|
+
// the email account) with the calendar's own name and time zone as the save last read them. Opened only with the seal
|
|
4
|
+
// key: by the server for the settings view and the test, and by a runner for a run whose revision names calendar_events
|
|
5
|
+
// (tools.ts). No answer, event, log line or run input holds the address: the runner's one redactor holds each of its
|
|
6
|
+
// forms (addressForms), read out of this row (runner/store-secrets.ts), and the server's list holds the ones saved since
|
|
7
|
+
// it started (server.ts).
|
|
8
|
+
import { ApiError, invalid } from "../errors.js";
|
|
9
|
+
import { getSealedKey, putSealedKey, removeSealedKey } from "../server-keys.js";
|
|
10
|
+
import { isObject, unknownFields } from "../validate.js";
|
|
11
|
+
import { ADDRESS_MAX, CALENDAR_ROW, NO_CALENDAR } from "./names.js";
|
|
12
|
+
/** A loopback hostname as written: only there is plain http taken, for the fakes. */
|
|
13
|
+
export const LOOPBACK_NAME = /^(?:localhost|\[::1\]|127(?:[.]\d{1,3}){3})$/; // key-gate: loopback-rule only a loopback fake calendar is read over plain http
|
|
14
|
+
const CONTROL = /[\u0000- \u007f-\u009f]/;
|
|
15
|
+
/** The address a body gives, as it is kept: `webcal://` (and `webcals://`) read as https, any other scheme but https
|
|
16
|
+
* refused, and plain http taken to a loopback address alone. 422 by `field`, in words, never echoing the address. */
|
|
17
|
+
export function addressOf(value, field = "url") {
|
|
18
|
+
const bad = (message) => invalid([{ field, reason: "invalid", message }]);
|
|
19
|
+
if (typeof value !== "string")
|
|
20
|
+
throw invalid([{ field, reason: value === undefined ? "missing" : "wrong_type", message: `${field} is the calendar's iCal address, as text (https://… or webcal://…).` }]);
|
|
21
|
+
const given = value.trim();
|
|
22
|
+
if (!given || given.length > ADDRESS_MAX)
|
|
23
|
+
throw bad(`${field} is 1 to ${ADDRESS_MAX} characters.`);
|
|
24
|
+
if (CONTROL.test(given))
|
|
25
|
+
throw bad(`${field} holds a space or a control character: paste the address whole, on one line.`);
|
|
26
|
+
const swapped = given.replace(/^webcals?:\/\//i, "https://");
|
|
27
|
+
const url = URL.parse(swapped);
|
|
28
|
+
if (!url)
|
|
29
|
+
throw bad(`${field} is not an address: paste the calendar's iCal address (https://… or webcal://…).`);
|
|
30
|
+
if (url.username || url.password)
|
|
31
|
+
throw bad(`${field} carries a user and password: use the calendar's secret iCal address, which needs none.`);
|
|
32
|
+
if (url.protocol === "http:" && !LOOPBACK_NAME.test(url.hostname))
|
|
33
|
+
throw bad(`${field} is http: a calendar is read over https only (webcal:// is read as https://).`);
|
|
34
|
+
if (url.protocol !== "https:" && url.protocol !== "http:")
|
|
35
|
+
throw bad(`${field} is ${url.protocol.replace(/:$/, "")}: a calendar is read over https only (webcal:// is read as https://).`);
|
|
36
|
+
url.hash = "";
|
|
37
|
+
return url.href;
|
|
38
|
+
}
|
|
39
|
+
/** A part of an address that reads as its secret on its own: decoded, no "@" (an owner's email in the path is said in the
|
|
40
|
+
* calendar's events as its organizer's), and a run of at least 16 letters, digits, "-" and "_" with a letter and a digit
|
|
41
|
+
* in it: Google's private-<hex>, iCloud's and Outlook's long ids, a feed's ?token=. */
|
|
42
|
+
function tokenLike(part) {
|
|
43
|
+
if (part.includes("@"))
|
|
44
|
+
return false;
|
|
45
|
+
const longest = (part.match(/[A-Za-z0-9_-]+/g) ?? []).reduce((a, b) => (b.length > a.length ? b : a), "");
|
|
46
|
+
return longest.length >= 16 && /[A-Za-z]/.test(longest) && /[0-9]/.test(longest);
|
|
47
|
+
}
|
|
48
|
+
/** Every form of `url` that text may carry it in, longest first: as kept, as webcal, decoded, its path with its query
|
|
49
|
+
* (where a provider keeps the secret part) when that is long enough to be one, and each path segment and query value
|
|
50
|
+
* that is a token on its own (tokenLike), so text that holds the address cut short holds none of its secret. What the
|
|
51
|
+
* redactors hold. */
|
|
52
|
+
export function addressForms(url) {
|
|
53
|
+
const forms = new Set([url]);
|
|
54
|
+
const parsed = URL.parse(url);
|
|
55
|
+
if (parsed) {
|
|
56
|
+
forms.add(parsed.href);
|
|
57
|
+
if (parsed.protocol === "https:")
|
|
58
|
+
forms.add(`webcal://${parsed.href.slice("https://".length)}`);
|
|
59
|
+
const secret = `${parsed.pathname}${parsed.search}`;
|
|
60
|
+
if (secret.length >= 16)
|
|
61
|
+
forms.add(secret);
|
|
62
|
+
const decode = (part) => {
|
|
63
|
+
try {
|
|
64
|
+
return decodeURIComponent(part);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return part;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
for (const part of [...parsed.pathname.split("/"), ...[...parsed.searchParams.values()]]) {
|
|
71
|
+
for (const one of new Set([part, decode(part)]))
|
|
72
|
+
if (tokenLike(decode(one)))
|
|
73
|
+
forms.add(one);
|
|
74
|
+
}
|
|
75
|
+
for (const one of [...forms]) {
|
|
76
|
+
try {
|
|
77
|
+
forms.add(decodeURIComponent(one));
|
|
78
|
+
}
|
|
79
|
+
catch { }
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return [...forms].filter((one) => one.length >= 8).sort((a, b) => b.length - a.length);
|
|
83
|
+
}
|
|
84
|
+
/** Each form of `url` cut from `text` (a fetch error, a calendar's own text): the address is never said. `url` may be the
|
|
85
|
+
* saved address and each address a read was redirected to (fetch.ts ReadCalendar followed), every one a secret: their
|
|
86
|
+
* forms are cut together, longest first. */
|
|
87
|
+
export function scrubAddress(text, url) {
|
|
88
|
+
const urls = (typeof url === "string" ? [url] : (url ?? [])).filter((one) => one);
|
|
89
|
+
if (urls.length === 0)
|
|
90
|
+
return text;
|
|
91
|
+
const forms = urls.length === 1 ? addressForms(urls[0]) : [...new Set(urls.flatMap((one) => addressForms(one)))].sort((a, b) => b.length - a.length);
|
|
92
|
+
let out = text;
|
|
93
|
+
for (const form of forms)
|
|
94
|
+
out = out.split(form).join("[the calendar's address]");
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
/** An opened row read: the calendar, or undefined when it is not the shape a save writes. */
|
|
98
|
+
function keptOf(plain) {
|
|
99
|
+
let value;
|
|
100
|
+
try {
|
|
101
|
+
value = plain === undefined ? undefined : JSON.parse(plain);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
if (!isObject(value) || value.v !== 1 || typeof value.url !== "string")
|
|
107
|
+
return undefined;
|
|
108
|
+
const text = (one) => (typeof one === "string" ? one : null);
|
|
109
|
+
return { url: value.url, name: text(value.name), time_zone: text(value.time_zone) };
|
|
110
|
+
}
|
|
111
|
+
/** The address of an opened calendar row, in each of its forms (runner/store-secrets.ts: the one redactor holds them, not
|
|
112
|
+
* the row's JSON). */
|
|
113
|
+
export const calendarRowSecrets = (plain) => {
|
|
114
|
+
const url = keptOf(plain)?.url;
|
|
115
|
+
return url ? addressForms(url) : [];
|
|
116
|
+
};
|
|
117
|
+
/** The calendar kept now, opened with `sealKey`; undefined when none is kept, or its row does not open (sealed under
|
|
118
|
+
* another key) or read. */
|
|
119
|
+
export async function openCalendar(store, sealKey) {
|
|
120
|
+
if ((await store.sealedKeys.get(CALENDAR_ROW)) === undefined)
|
|
121
|
+
return undefined;
|
|
122
|
+
return keptOf(await getSealedKey(store, sealKey, CALENDAR_ROW));
|
|
123
|
+
}
|
|
124
|
+
/** The calendar's view (GET /settings/calendar): whether one is kept, the host it is read from, and its own name and time
|
|
125
|
+
* zone. Never its address. */
|
|
126
|
+
export async function calendarView(store, sealKey) {
|
|
127
|
+
const kept = await openCalendar(store, sealKey);
|
|
128
|
+
if (!kept)
|
|
129
|
+
return { configured: false, host: null, name: null, time_zone: null };
|
|
130
|
+
// A name saved before saves scrubbed it is scrubbed here too.
|
|
131
|
+
return { configured: true, host: URL.parse(kept.url)?.host ?? null, name: kept.name === null ? null : scrubAddress(kept.name, kept.url), time_zone: kept.time_zone };
|
|
132
|
+
}
|
|
133
|
+
/** The calendar saved whole, in one write. */
|
|
134
|
+
export async function saveCalendar(store, sealKey, calendar) {
|
|
135
|
+
await putSealedKey(store, sealKey, CALENDAR_ROW, JSON.stringify({ v: 1, url: calendar.url, name: calendar.name, time_zone: calendar.time_zone }));
|
|
136
|
+
await store.flush?.();
|
|
137
|
+
}
|
|
138
|
+
/** The calendar forgotten: its one row, in one write. */
|
|
139
|
+
export async function removeCalendar(store) {
|
|
140
|
+
await removeSealedKey(store, CALENDAR_ROW);
|
|
141
|
+
await store.flush?.();
|
|
142
|
+
}
|
|
143
|
+
/** A PUT's or a test's body, `{url}`, read: its address, or 422 in words. */
|
|
144
|
+
export function bodyAddress(body) {
|
|
145
|
+
if (!isObject(body))
|
|
146
|
+
throw invalid([{ field: "", reason: "wrong_type", message: "The body is {url}: the calendar's iCal address." }]);
|
|
147
|
+
const unknown = unknownFields(body, ["url"]);
|
|
148
|
+
if (unknown.length)
|
|
149
|
+
throw invalid(unknown);
|
|
150
|
+
return addressOf(body.url);
|
|
151
|
+
}
|
|
152
|
+
/** The refusal for a test of the saved calendar when none is kept. */
|
|
153
|
+
export const noCalendar = () => new ApiError("input_invalid", NO_CALENDAR, { fields: [{ field: "url", reason: "not_set", message: NO_CALENDAR }] });
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { OAuthNetwork, Reach } from "../mcp-oauth.js";
|
|
2
|
+
import { type ParsedCalendar } from "./parse.js";
|
|
3
|
+
/** A read that failed, in words that never hold the address. */
|
|
4
|
+
export declare class CalendarError extends Error {
|
|
5
|
+
}
|
|
6
|
+
/** Where a read may go beyond public hosts (mcp-oauth.ts Reach): `loopback`, a local install's (its fakes); `allowed`, the
|
|
7
|
+
* private-network hosts the owner allows (Settings → MCP servers); `own`, this server's own origins, never dialled on
|
|
8
|
+
* loopback. */
|
|
9
|
+
export type CalendarReach = Reach;
|
|
10
|
+
/** The network a read resolves and dials through (mcp-oauth.ts OAuthNetwork), for a test. Default the system's. */
|
|
11
|
+
export type CalendarNetwork = OAuthNetwork;
|
|
12
|
+
/** A calendar read: parsed, with `followed`, every address a redirect took the read to (the saved one's host may send it
|
|
13
|
+
* to another secret address), each scrubbed from what the calendar says as the saved one is (address.ts scrubAddress). */
|
|
14
|
+
export type ReadCalendar = ParsedCalendar & {
|
|
15
|
+
followed: readonly string[];
|
|
16
|
+
};
|
|
17
|
+
/** Every kept read made stale, its parsed copy and validators kept: the next read of each revalidates (a test's, standing in
|
|
18
|
+
* for five minutes passing). */
|
|
19
|
+
export declare function staleCalendarsForTests(): void;
|
|
20
|
+
/** Every kept read forgotten (a test's). */
|
|
21
|
+
export declare function forgetCalendarsForTests(): void;
|
|
22
|
+
/** The calendar at `url`, parsed: the kept copy while it is fresh, else fetched (a 304 keeps the kept copy, the addresses
|
|
23
|
+
* this read was redirected to added to its own). */
|
|
24
|
+
export declare function readCalendar(url: string, reach?: CalendarReach, network?: CalendarNetwork, signal?: AbortSignal): Promise<ReadCalendar>;
|