pi-pocket 0.28.0-beta.3 → 0.28.0-beta.5
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/README.md +2 -2
- package/contrib/systemd/pi-pocket@.service +1 -1
- package/docs/architecture.md +10 -2
- package/docs/customizing.md +5 -2
- package/docs/desktop.md +105 -0
- package/docs/extensions/linked-sessions.md +20 -4
- package/docs/extensions/policies/api-stability.md +10 -2
- package/docs/extensions/policies/core-or-extension.md +1 -1
- package/docs/extensions/reference/api-versions.md +2 -0
- package/docs/extensions/reference/host.md +64 -7
- package/docs/extensions/reference/pocket.md +62 -1
- package/docs/extensions/reference/theme-surface.md +2 -0
- package/docs/extensions/reference/web.md +3 -1
- package/docs/extensions/routes.md +1 -1
- package/docs/extensions/services-settings.md +8 -8
- package/docs/extensions/workspaces.md +25 -0
- package/docs/extensions.md +4 -0
- package/docs/features.md +9 -8
- package/docs/index.md +1 -0
- package/docs/map.md +86 -76
- package/docs/systemd.md +1 -1
- package/npm-shrinkwrap.json +89 -2
- package/package.json +4 -1
- package/src/launcher/access.ts +8 -1
- package/src/launcher/main.ts +101 -41
- package/src/launcher/options.ts +1 -1
- package/src/launcher/serve.ts +51 -22
- package/src/server/alerts.ts +44 -16
- package/src/server/app-events.ts +11 -1
- package/src/server/app.ts +322 -21
- package/src/server/background.ts +67 -29
- package/src/server/browser/urls.ts +3 -0
- package/src/server/build.ts +1 -1
- package/src/server/commands.ts +53 -20
- package/src/server/design/files.ts +10 -0
- package/src/server/design/guide.ts +6 -0
- package/src/server/design/index.ts +16 -2
- package/src/server/design/scan-facts.ts +4 -0
- package/src/server/design/scan-fig-container.ts +390 -0
- package/src/server/design/scan-fig-kiwi.ts +466 -0
- package/src/server/design/scan-fig-nodes.ts +385 -0
- package/src/server/design/scan-fig.ts +404 -0
- package/src/server/design/scan-files.ts +54 -2
- package/src/server/design/scan-import-convert.ts +1 -1
- package/src/server/design/scan-import-eval.ts +15 -8
- package/src/server/design/scan-import.ts +16 -4
- package/src/server/design/scan-infer.ts +2 -0
- package/src/server/design/scan-tree.ts +18 -0
- package/src/server/design/scan.ts +87 -25
- package/src/server/design/system-types.ts +6 -0
- package/src/server/design/system.ts +111 -8
- package/src/server/design/tokens-resync.ts +542 -0
- package/src/server/design/tokens.ts +34 -3
- package/src/server/docs.ts +30 -1
- package/src/server/entry-presentation.ts +20 -0
- package/src/server/extension-request.ts +15 -0
- package/src/server/extension-web.ts +38 -4
- package/src/server/extensions/agent-teams.ts +1 -1
- package/src/server/extensions/artifacts.ts +15 -2
- package/src/server/extensions/browser.ts +6 -1
- package/src/server/extensions/design/system-routes.ts +9 -2
- package/src/server/extensions/diagrams/index.js +344 -0
- package/src/server/extensions/diagrams/math.css +1 -0
- package/src/server/extensions/diagrams/style.css +42 -0
- package/src/server/extensions/diagrams.ts +6 -0
- package/src/server/extensions/pip.ts +1 -1
- package/src/server/extensions/prompt.ts +10 -3
- package/src/server/extensions/subagents.ts +1 -1
- package/src/server/guides/design.md +1 -0
- package/src/server/heic-convert.d.ts +11 -0
- package/src/server/heic-worker.ts +12 -0
- package/src/server/heic.ts +129 -0
- package/src/server/hooks.ts +29 -0
- package/src/server/host.ts +32 -0
- package/src/server/http/api.ts +12 -4
- package/src/server/http/assets.ts +13 -0
- package/src/server/http/browser-routes.ts +5 -1
- package/src/server/http/conversation-routes.ts +20 -5
- package/src/server/http/events.ts +1 -0
- package/src/server/http/extension-routes.ts +2 -0
- package/src/server/http/push-routes.ts +5 -2
- package/src/server/http.ts +33 -1
- package/src/server/linked-sessions.ts +233 -9
- package/src/server/memory.ts +6 -0
- package/src/server/model-images.ts +46 -8
- package/src/server/paths.ts +8 -0
- package/src/server/pip-compact.ts +1 -1
- package/src/server/pip.ts +5 -1
- package/src/server/push.ts +10 -0
- package/src/server/reload.ts +2 -0
- package/src/server/room.ts +22 -1
- package/src/server/shell.ts +10 -6
- package/src/server/watches.ts +8 -0
- package/src/server/workspace.ts +30 -0
- package/src/server/worktrees.ts +5 -0
- package/types/pocket.d.ts +128 -3
- package/web/app.js +2 -0
- package/web/composer.js +24 -4
- package/web/desktop.js +117 -0
- package/web/extension-ui.js +124 -5
- package/web/files-panel.js +17 -3
- package/web/host.js +78 -0
- package/web/index.html +50 -0
- package/web/markdown-ext.js +45 -0
- package/web/math.js +58 -0
- package/web/notify.js +15 -2
- package/web/peeks.js +3 -2
- package/web/pip.js +3 -2
- package/web/quote-reply.js +8 -7
- package/web/quote-text.js +26 -0
- package/web/running-board.js +107 -32
- package/web/seen.js +3 -2
- package/web/sheets/extensions.js +11 -18
- package/web/sheets/find.js +8 -2
- package/web/sheets/gallery.js +0 -2
- package/web/sheets/hooks.js +112 -5
- package/web/sheets/menu.js +11 -0
- package/web/sheets.js +0 -1
- package/web/store.js +26 -6
- package/web/style.css +260 -28
- package/web/text-hash.d.ts +2 -0
- package/web/{fingerprint.js → text-hash.js} +2 -1
- package/web/theme-surface.js +6 -0
- package/web/transcript.js +145 -16
- package/web/ui.js +94 -7
- package/web/window-controls.js +327 -0
- package/web/fingerprint.d.ts +0 -2
package/README.md
CHANGED
|
@@ -82,7 +82,7 @@ Choose a mode in the launcher, or pass `--access`:
|
|
|
82
82
|
| `tailscale` | Your tailnet | Plain http on the tailnet address |
|
|
83
83
|
| `tailscale-serve` | Your tailnet | https at the tailnet name; needs `tailscale` 1.52 or newer |
|
|
84
84
|
|
|
85
|
-
`tailscale-serve` needs the `tailscale` command on your `PATH`, signed in, with MagicDNS and HTTPS certificates enabled in the tailnet. It serves port 443 at the machine's tailnet name, and a server restart keeps the address. When the launcher quits it takes down the mount it made; one it found already in place is left where it is. Without the command the launcher says so and stops rather than falling back to this device only when nobody is there to pick another mode. `--host` cannot be combined with it: serve always listens on `127.0.0.1` and lets tailscaled reach it. For another tunnel (ngrok), choose `local` and point it at port 8787.
|
|
85
|
+
`tailscale-serve` needs the `tailscale` command on your `PATH`, signed in, with MagicDNS and HTTPS certificates enabled in the tailnet, and, when the launcher does not run as root, that user as tailscaled's operator (`sudo tailscale set --operator=$USER`). It serves port 443 at the machine's tailnet name, and a server restart keeps the address. When the launcher quits it takes down the mount it made; one it found already in place is left where it is. Without the command the launcher says so and stops rather than falling back to this device only when nobody is there to pick another mode. `--host` cannot be combined with it: serve always listens on `127.0.0.1` and lets tailscaled reach it. For another tunnel (ngrok), choose `local` and point it at port 8787.
|
|
86
86
|
|
|
87
87
|
Other options: `--port` (8787), `--cwd`, `--data` (`~/.pi-pocket`), `--host`, and `-y` to reuse the last access choice. `--host` overrides the address a named mode would listen on, and one launcher runs per data folder (a second one says which pid holds it). `npm start -- --help` lists them all. `PI_POCKET_BROWSER` and `PI_POCKET_BROWSER_ARGS` pick the built-in browser and its flags when Chromium or Chrome is not found by itself. `PI_POCKET_PROMPT_DATE=1` puts today's date in Pi's system prompt; it is left out by default, so the prompt cache does not start over when the date changes. `PI_POCKET_SESSION_CACHE=off` keeps browsers from saving the sessions they open on the device (IndexedDB), so that they keep them in each tab's memory only; it is on by default. `PI_POCKET_CACHE_KEEPER=off` turns off the prompt cache keeper, which keeps a model's prompt cache warm while a run waits on a tool call ([features](docs/features.md)).
|
|
88
88
|
|
|
@@ -118,6 +118,6 @@ The [full list](docs/features.md#limitations) has the details.
|
|
|
118
118
|
|
|
119
119
|
## Credits and license
|
|
120
120
|
|
|
121
|
-
Inspired by [Mario Zechner's demo](https://x.com/badlogicgames/status/2106452296087302173) of his own Pi app. Pi Pocket is an independent project, not affiliated with Earendil. The bundled fonts keep their own licenses, which are beside them in [web/fonts/](web/fonts/).
|
|
121
|
+
Inspired by [Mario Zechner's demo](https://x.com/badlogicgames/status/2106452296087302173) of his own Pi app. Pi Pocket is an independent project, not affiliated with Earendil. The bundled fonts keep their own licenses, which are beside them in [web/fonts/](web/fonts/). Dependencies keep their own licenses too; one is not MIT: HEIC photos are decoded with [libheif-js](https://github.com/catdad-experiments/libheif-js) (LGPL-3.0), installed as an ordinary npm package that you can replace.
|
|
122
122
|
|
|
123
123
|
[MIT](LICENSE). To report a security problem, see [SECURITY.md](SECURITY.md).
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[Unit]
|
|
4
4
|
Description=Pi Pocket (%i access)
|
|
5
5
|
Documentation=https://github.com/TannerMidd/pi-pocket/blob/main/docs/systemd.md
|
|
6
|
-
Wants=network-online.target
|
|
6
|
+
Wants=network-online.target tailscaled.service
|
|
7
7
|
After=network-online.target tailscaled.service
|
|
8
8
|
|
|
9
9
|
[Service]
|
package/docs/architecture.md
CHANGED
|
@@ -18,7 +18,7 @@ Some state lives in this process alone, and a restart forgets it. For example:
|
|
|
18
18
|
- who is connected, typing, or away;
|
|
19
19
|
- which tool calls wait for approval;
|
|
20
20
|
- the browser's pages;
|
|
21
|
-
- when each run ended, which peek tiles and session-list squares use
|
|
21
|
+
- when each run ended, which peek tiles and session-list squares use (why a session's last run failed is kept: `pocket.run-failure`);
|
|
22
22
|
- provider sign-ins in progress;
|
|
23
23
|
- the edit and write calls Changes found in each session's history, so a look reads only the entries added since.
|
|
24
24
|
|
|
@@ -47,6 +47,10 @@ The native extension loader registers one scoped resolve hook for drop-in import
|
|
|
47
47
|
|
|
48
48
|
Extensions never see `PocketApp`. They get `PocketHost` (`host.ts`), whose functions call into the app lazily, and `web`, through which they add routes and a browser module to the app. `ExtensionWebs` (`extension-web.ts`) keeps what each module's version added, which the loader commits once the module installed and removes with it, running its cleanups. The HTTP layer parses a request, checks it, calls a part, and writes the answer; it holds no state of its own beyond invites and the event streams' pollers.
|
|
49
49
|
|
|
50
|
+
## Workspace execution providers
|
|
51
|
+
|
|
52
|
+
`PocketApp` selects the execution environment by the session's working folder. Local folders keep the existing Node environment; URI workspaces use the last registered provider for their scheme. Removal restores the previous registration, and a missing provider fails closed. Resolution checks the provider identity and cancellation after awaited work. Only the owner can use a workspace URI. The provider's module, a drop-in outside the core package, owns host-key trust, connections, remote project context, and cleanup. Files/Git actions and managed worktrees remain local-only.
|
|
53
|
+
|
|
50
54
|
## Favorite folders
|
|
51
55
|
|
|
52
56
|
`FolderFavoritesDoc` (`pocket.folder-favorites`) stores each person's ordered favorite working folders in SQLite. `folder-favorites.ts` reads and changes only the signed-in person's list; explicit star/unstar operations run inside one harness transaction, so concurrent devices do not overwrite unrelated changes. The commit coordinator sends each connected client only its person's list as a `folder-favorites` event. `hello.folderFavorites` supplies the initial list and refreshes it on reconnect. The folder picker shows only what the server committed, so a failed save leaves its list as it was.
|
|
@@ -77,6 +81,8 @@ PiP's header model chip opens the existing picker with its own conversation ID a
|
|
|
77
81
|
|
|
78
82
|
A PR watch (`watches.ts`) is a `WatchDoc` in its session and a durable task there, which sleeps until its next look, looks with `gh` (`watches.gh`, which tests replace), and puts what to tell Pi in its checkpoint before sending it: the send's request id is the watch's task and count, so a restart sends it once. Comment ids told, and the commits whose failures and conflicts were told, stay in the watch. Webhooks (`hooks.ts`) are app-wide (`HooksDoc`); `/hook/…` is outside `/api` and its sign-in, and lets a post in only by its hook's secret. Both send through `Commands.submit` as their person, with a `via` that marks the message (`[via PR watch]`, `[via webhook NAME]`), so that person's checks and spend limit apply, and what came from outside is fenced (`fence.ts`, as PiP's session text is): no closing tag survives inside, in any case or spacing. A hook's address and secret are checked before its body is read. A signed hook (`signed`, for GitHub) lets a post in only by GitHub's signature: its secret is never in its address, so the address GitHub shows a repository's admins cannot post. Pi's `watch_pr` names a PR by number, which `gh` finds in the session's own repository, or one elsewhere by address only where `gh`'s account can push (`requirePush` in `github.ts`); what follows `--` is never an option.
|
|
79
83
|
|
|
84
|
+
Webhook edits require steering rights. `Hooks.update` checks creator-or-owner access in the same transaction that changes the instructions, leaving the hook's other fields unchanged. Deliveries already in progress keep their original instructions.
|
|
85
|
+
|
|
80
86
|
A repository watch (`repo-watches.ts`) is an item of the app-wide `RepoWatchesDoc` and a durable task in the conversation it messages (PiP's, or a session's), with the same wait, look, and send phases as a PR watch: a look puts the message in the task's checkpoint, and the send's request id is the task's and its count's, so it goes once. It reads the repository's issues, pulls, workflow runs, releases, and comments through `gh api`, and keeps the ids it told. PiP's tools (`repo_watch`, `session_watch_pr`, `session_start` with `repo`) act through `Pip` as its person; a repository is worked on or watched only where `gh`'s account can push, and `Pip.checkout` finds a session's checkout whose `origin` is the repository, or clones it once into `repos/`.
|
|
81
87
|
|
|
82
88
|
## Who chooses models
|
|
@@ -173,7 +179,7 @@ A full view for a tab of protocol 4 has the order of every entry in the active c
|
|
|
173
179
|
|
|
174
180
|
A tab of protocol 5 gets those entries light at first (`lightEntry` in `projection.ts`, marked `partial`): without a thought's words, with a tool's input and output cut to their first 300 characters, and without large details. That is what shows only when a step is opened, and most of a session's weight: the first view of a long session goes from hundreds of kilobytes to tens. The server does not count a light entry as sent, so the update right after the first view (`Room.push`) brings it whole. A long poll answers the first time as soon as the first view is built, so the whole entries come in the next answer. Until then, a call's line may say nothing of its outcome (a result of 300 characters or fewer, with small details, is never made light: it comes whole, so its line can show it), and a thought does not open.
|
|
175
181
|
|
|
176
|
-
A tab of protocol 6 keeps the sessions it leaves (`keptViews` in `web/store.js`: the newest 1,500 entries of each, as many sessions as fit in 16 million characters of JSON, about 25 MB once parsed, the one left longest ago dropped first), and shows the one it goes back to at once, before the server answers. It tells the server what it kept (`have=<from>.<count>.<key>.<build>`): the first `count` ids of the order, as a fingerprint (`key`, from `web/
|
|
182
|
+
A tab of protocol 6 keeps the sessions it leaves (`keptViews` in `web/store.js`: the newest 1,500 entries of each, as many sessions as fit in 16 million characters of JSON, about 25 MB once parsed, the one left longest ago dropped first), and shows the one it goes back to at once, before the server answers. It tells the server what it kept (`have=<from>.<count>.<key>.<build>`): the first `count` ids of the order, as a fingerprint (`key`, from `web/text-hash.js`), whose entries it has whole from `from` on, as a server of build `build` sent them. The build (`src/server/build.ts`) is a hash of the server's code and its package: an entry is as that code projects it, so what a tab kept is good across a restart with the same code, and not across new code. The server checks `have` against the session (`Room.push`): its own build, and an order that still starts with those ids (no compaction since). If it fits, the full view counts those entries as sent, and its order is only what comes after them, with `orderFrom` where it goes on: a session that did not change sends no entries and no order. If it does not, the tab gets the full view any tab gets. An update to a tab of protocol 6 likewise sends only the end of the order when entries were only added: a long session's order has thousands of ids, and each entry added sent them all again. A view whose `orderFrom` does not fit the order the tab has, which should not happen, makes the tab drop what it kept and connect again. The tab keeps only views a server of the running build sent whole. It forgets them all when the server runs other code, when the person's rights change or another person signs in, or when a session leaves the list; and a session's own when the server says it is missing. Each of these but the last also keeps the view on screen from being kept when the tab leaves it: after a reconnect the list can come first, and a tab that leaves at once never hears that the session is missing.
|
|
177
183
|
|
|
178
184
|
The browser also keeps those sessions on the device (`web/session-cache.js`, IndexedDB), for every tab of it: about 100 MB of JSON in all (`DEVICE_CHARS`), the session used longest ago dropped first. A session saved there shows at once after a reload, a tab the system closed in the background, or a restart of a server with the same build, and a tab opens a session its memory no longer holds from there in a moment. A tab that starts reads the ones used last back into its memory while it is idle, as many as its memory keeps, so that going to them after a reload is as quick as before it. A tab saves a session there as it leaves it, and the one it shows a few seconds after it last changed and as the page goes to the background. Each record names its build and whose it is (a fingerprint of the person's id, role, and shared sessions): a tab uses only one of its server's build and of the person signed in with the same rights, and the server checks `have` as for one from memory. What the device kept goes when the tab forgets what it kept (above), on sign-out, and, per session, when the server says it is missing. `PI_POCKET_SESSION_CACHE=off` keeps sessions off devices (`hello.server.deviceCache` false): tabs keep them in memory only, and drop what their browser kept on the device.
|
|
179
185
|
|
|
@@ -252,6 +258,8 @@ In the browser, the composer keeps a command's request id while its send is unre
|
|
|
252
258
|
|
|
253
259
|
Plain ES modules, served as they are, with no build. Editing a file under `web/` reloads every open tab, and a syntax error blanks the screen for everyone.
|
|
254
260
|
|
|
261
|
+
**Markdown's extension points (`markdown-ext.js`, `math.js`).** `pocket.fence` and `pocket.mathInline` let a browser module draw code fences and set math. `extension-ui.js` fills in the two lookups and `ui.js` asks them, so neither imports the other; a revision that goes up on every change draws Markdown again. Math is parsed only while a `mathInline` registration is live, and each formula reaches the mounter through a random marker that exists for one parse, so reply HTML cannot impersonate math. The built-in `extensions/diagrams/` module registers a Mermaid fence, a math fence, and the math mounter; Pele and KaTeX load from `/vendor/` on first use.
|
|
262
|
+
|
|
255
263
|
**Loading order matters.** `store.js` is the root, and a few modules do work when they load (listed in [map.md](map.md#web-web-preact-and-htm-no-build)). `theme.js` must load before anything that reads `prefs()` as it loads. `store.set` calls subscribers in the order they subscribed. When moving code between modules, keep both orders. `back.js` sits under `store.js` and imports nothing of the app's, so anything may use it.
|
|
256
264
|
|
|
257
265
|
**Drawing while an answer streams (`app.js`, `ui.js`).** Every `store.set` draws the app again from the top, once per microtask; components read `store.state` as they draw. A streaming answer changes `view` (or PiP's `pipView`) several times a second, and the chat, people, and the connection change too, so what is big and reads little of the store is wrapped in `drawnFor(keys, component)`, which draws it again only when one of `keys` changes: the session list and the rail (`LIST_KEYS`, `RAIL_KEYS` in `sessions.js`). Its keys must name every key it reads as it draws, and every key that the functions it calls read (`prefs()` reads `appearance`, `canSteer()` reads `me`, `isPinned` reads `pinned`); a key left out shows stale data until another change draws it. `store.set({})` still draws it. Inside the list, each row is memoized (`memo`, compared by its props): the list works out what a row shows and passes it, the row reads nothing of the store, and a minute tick (`useMinute`) and `extensionsRev` draw rows again as their times and extensions' chips change. The server sends `hello`, the session list, and the people again on each connect: their handlers keep what is the same (`kept` in `store.js`), and set nothing when nothing changed, so a reconnect draws only what changed. The server's clock in `hello` (`server.now`) is no change: it goes to `serverClockOffset()`. On narrow screens the sidebar and the home screen's splash are not drawn, and on touch screens rows draw no hover buttons (`WIDE`, `NO_HOVER` in `ui.js`, the same queries as `style.css`; a change draws the app again). Markdown still growing (`cache={false}`) is drawn block by block (`liveBlocks`): each top-level block keeps its HTML from the update before unless its text changed, so an update parses, sanitizes, and colors only the last block. The blocks are found again in the whole text each time, so a later line that changes an earlier block shows; a reference link defined in another block shows as written until the text is whole, and an HTML block with a blank line inside it shows split until then.
|
package/docs/customizing.md
CHANGED
|
@@ -25,11 +25,14 @@ Keep the files short and true. They go with each request, and a rule that Pi can
|
|
|
25
25
|
|
|
26
26
|
## PiP's instructions
|
|
27
27
|
|
|
28
|
-
PiP has no project, so it does not read AGENTS.md files. Write the rules for PiP
|
|
28
|
+
PiP has no project, so it does not read AGENTS.md files. Write the rules for PiP in `pip.md` in Pi Pocket's data folder: `~/.pi-pocket/pip.md`, unless `--data` or `PI_POCKET_DIR` names another folder (since 0.28.0).
|
|
29
29
|
|
|
30
30
|
- PiP gets the file with each message. When the file changes, the next message has the new text.
|
|
31
31
|
- Only PiP reads it: sessions, subagents, and Pi's terminal app do not.
|
|
32
|
-
|
|
32
|
+
|
|
33
|
+
## The language agents write in
|
|
34
|
+
|
|
35
|
+
Since 0.28.0, agents write to each other in the language of the person they work for: PiP to the sessions it starts or messages, a session to its linked sessions and its subagents, and each answer back. A session you open later, that PiP or another session worked in, reads in your language, with no setting. PiP takes the language from your messages to it, and for a watch, a webhook, or a schedule from the instructions you gave it. In English they write Simplified Technical English (ASD-STE100); in another language, the same short, plain style. Their answers to you follow your own messages, as before. To choose another language for PiP's messages to sessions, say so in `pip.md`.
|
|
33
36
|
|
|
34
37
|
## Skills: procedures that Pi follows on request
|
|
35
38
|
|
package/docs/desktop.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Desktop apps
|
|
2
|
+
|
|
3
|
+
A desktop app can show Pi Pocket in a window of its own: an Electron or Tauri wrapper, for example, with a tray icon, native notifications, and a menu of its own. [Pi Pocket GUI](https://github.com/vitalNohj/pi-pocket-gui) is one. Pi Pocket stays a web app on its server; the desktop app loads the server's address, and the person signs in there as in a browser.
|
|
4
|
+
|
|
5
|
+
A browser tab cannot do some things that such an app can, and Web Push does not reach a page in Electron. The **host bridge** joins the two: the app puts `window.pocketHost` in the page, and Pi Pocket uses what it offers. In a browser there is no bridge, and nothing changes.
|
|
6
|
+
|
|
7
|
+
## Finding Pi Pocket
|
|
8
|
+
|
|
9
|
+
`GET /api/pocket/info` answers without a sign-in:
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
{ "name": "pi-pocket", "bridge": 1 }
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`bridge` is the version of the host bridge that this server's web app speaks. The answer never has Pi Pocket's version. A server older than the bridge answers 401 there; its web app manifest (`/manifest.webmanifest`) still has `"name": "Pi Pocket"`.
|
|
16
|
+
|
|
17
|
+
## The bridge
|
|
18
|
+
|
|
19
|
+
The app's preload script puts one object in the top page of the server's origin, and nowhere else: never in a frame (artifacts run in frames), never on another origin.
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
window.pocketHost = {
|
|
23
|
+
kind: "pi-pocket-gui", // which app; for logs only
|
|
24
|
+
apiVersion: 1,
|
|
25
|
+
capabilities: ["menu", "badge", "notify", "visibility", "pinned", "open"],
|
|
26
|
+
|
|
27
|
+
menuItems(), // [{ id, label, hint? }]: items for the menu's Desktop group, at its end
|
|
28
|
+
invoke(id), // one of them was chosen; false when it could not be done
|
|
29
|
+
setBadge(count), // sessions that need you, as the home-screen icon counts them
|
|
30
|
+
notify(message), // a notification for the app to show (below)
|
|
31
|
+
visible(), // whether the app's window shows: false while hidden in a tray or minimized
|
|
32
|
+
setPinned(list), // [{ id, title, state, label, url }]: the pinned sessions, in order
|
|
33
|
+
subscribe(listener), // the app's events (below)
|
|
34
|
+
};
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`web/host.js` reads it: `host`, `hostCan(capability)`, and `callHost(name, …)`, which catches what the app throws. `web/desktop.js` does the rest. Pi Pocket uses only the capabilities the app names, and ignores ones it does not know. A newer bridge keeps version 1's calls.
|
|
38
|
+
|
|
39
|
+
### Capabilities
|
|
40
|
+
|
|
41
|
+
| Capability | What Pi Pocket does |
|
|
42
|
+
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
43
|
+
| `menu` | Shows `menuItems()` in a **Desktop** group at the end of the menu, below its App part. Choosing one calls `invoke(id)`. Pi Pocket GUI offers **Server settings…**. |
|
|
44
|
+
| `badge` | Calls `setBadge(count)` instead of the Badging API whenever the count changes. |
|
|
45
|
+
| `notify` | Opens its event stream with `host=notify`. The server then sends this connection every notification it would push to the person (`desktop-notify`), and the page passes each to `notify(message)`. |
|
|
46
|
+
| `visibility` | Reads `visible()` with the page's own visibility: the page counts as hidden while either says so. It tells the server (`POST /api/visibility`), so the server knows the person is away and lets notifications through, and seen marks and peek tiles wait as they do in a hidden tab. |
|
|
47
|
+
| `pinned` | Calls `setPinned(list)` when a pinned session's title or state changes, for a tray menu. `state` is the square's shape from `sessionMark`: `waiting`, `limited`, `working`, `failed`, `fresh` (finished, not read), or `seen`. The session list's theme states `done` and `idle` do not change these bridge names. `label` says it in words. |
|
|
48
|
+
| `open` | Opens what the app asks for (an `open` event), also without `notify`. |
|
|
49
|
+
|
|
50
|
+
A page in an Electron window keeps running at full speed while the window hides in the tray, so `document.visibilityState` stays `visible` there. That is why `visible()` exists: without it, the server would think the person is looking, and hold every notification back.
|
|
51
|
+
|
|
52
|
+
### Notifications
|
|
53
|
+
|
|
54
|
+
The server decides as for Web Push (`alerts.ts`): who can see the session, the kinds each person turned on in Menu → Notifications, and whether they are looking at it. Then it sends the message through Web Push to their subscribed devices, and to each of their desktop apps' connections (`PocketApp.notifyDesktops`). An app that is not running gets nothing: nothing waits for it.
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
{
|
|
58
|
+
title: "Pi needs approval · Deploy",
|
|
59
|
+
body: "bash: npm run deploy", // cut at 400 characters, as for Web Push
|
|
60
|
+
url: "/s/12", // what a click opens: a session, PiP ("/?pip=1"), or "/"
|
|
61
|
+
tag: "approval-…", // one notification per tag: a newer one replaces it
|
|
62
|
+
urgency: "high", // "normal", or "high" for approvals and questions
|
|
63
|
+
approval: { // approvals only
|
|
64
|
+
id: "…",
|
|
65
|
+
allow: true, // Web Push's rule: the person may allow it, and the whole call fits on one short line
|
|
66
|
+
may: true, // the person may allow it at all
|
|
67
|
+
call: "bash: npm run deploy", // the whole call, never cut
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The app chooses how much of an approval to show and whether to offer **Allow**, from `may`, `allow`, and `call`. It always offers **Deny**. The server checks again, when the answer comes, that the person may give it.
|
|
73
|
+
|
|
74
|
+
### The app's events
|
|
75
|
+
|
|
76
|
+
`subscribe(listener)` takes one function. The app calls it with:
|
|
77
|
+
|
|
78
|
+
- `{ type: "visibility" }`: its window was shown or hidden. The page reads `visible()` again.
|
|
79
|
+
- `{ type: "open", url }`: open this, such as a notification or a tray item that was clicked. Only addresses of the server's own origin open.
|
|
80
|
+
- `{ type: "approve", id, allow }`: the person answered an approval in a notification. The page answers it with its own sign-in.
|
|
81
|
+
|
|
82
|
+
## The window's buttons
|
|
83
|
+
|
|
84
|
+
An app that hides its title bar, and shows Pi Pocket up to its window's top edge with the window's own buttons over it (close, minimize, zoom), tells the page where they are through the web's standard for it, the Window Controls Overlay (`navigator.windowControlsOverlay`). An installed web app with `"display_override": ["window-controls-overlay"]` does the same. The bridge is not needed for it.
|
|
85
|
+
|
|
86
|
+
`web/window-controls.js` makes room only under the buttons, and only as much as they take; the rest of the layout keeps its whole height:
|
|
87
|
+
|
|
88
|
+
- A bar under them (the session tabs, the conversation's top bar, a panel's, a viewer's) keeps what it holds beside them, and the window can be dragged by it.
|
|
89
|
+
- A window without one (the sidebar on wide screens, an extension's page) starts below them. Tiled, its margin moves it, so the tiles' gap stays above it.
|
|
90
|
+
- A strip beside the buttons, as wide as the windows that moved down, moves the window too. What floats over the app (sheets, the launcher, viewers, PiP) takes clicks there.
|
|
91
|
+
- Tiled, the window whose bar is under the buttons has its corner cut around them (`corner-shape`), so its border and focus ring go down, around them, and back up, instead of under them. A browser without `corner-shape` keeps the rounded corner.
|
|
92
|
+
|
|
93
|
+
The page reads the layout, not the screen: a window, a bar, or a panel that opens (the subagents board, Design, Files, Browser, People) has its room and its cut before the frame that first shows it, and a window that pops in is measured where it lands. Nothing shows under the buttons first and moves after.
|
|
94
|
+
|
|
95
|
+
On `<html>`, `data-window-controls` is `left` (macOS), `right` (Windows, Linux), or `none`, and `--controls-h` is how far down the buttons reach. What makes room has `data-under-controls`, `bar` or `push`, and `--controls-room`. The window cut around the buttons has `data-controls-notch`, and `--notch-w` and `--notch-h`. The page sets `data-window-controls` before its first paint, so an app can tell that it makes its own room. For a page without it (an older Pi Pocket, a sign-in page), Pi Pocket GUI instead sets a top safe-area inset as tall as the buttons, which Pi Pocket's bars have long kept clear of on phones.
|
|
96
|
+
|
|
97
|
+
## Security
|
|
98
|
+
|
|
99
|
+
The bridge is only as safe as the app that offers it. An app must:
|
|
100
|
+
|
|
101
|
+
- put it only in the top frame of the server's origin, and take it away when that frame goes elsewhere;
|
|
102
|
+
- check, in its main process, the frame and origin of every call that comes from the page: the sender frame's own origin (`senderFrame.origin`), not its `url`, because the server's origin also serves sandboxed artifact pages, whose origin is opaque;
|
|
103
|
+
- give the page no Node.js, and keep its sandbox and context isolation on.
|
|
104
|
+
|
|
105
|
+
Pi Pocket gives the bridge nothing that the page could not do over the API itself: the notifications are the person's own, and an approval's answer goes through the same route and checks as a tap in the app.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Starting and messaging sessions
|
|
2
2
|
|
|
3
|
-
A tool can start a session from the session that it runs in,
|
|
3
|
+
A tool can start a session from the session that it runs in, send messages between such sessions, and stop or archive one. Agent Teams does this ([agent-teams.ts](../../src/server/extensions/agent-teams.ts)). A team or orchestration extension uses the same calls. Use `host.linkedSessions`. Its members are in [the host reference](reference/host.md).
|
|
4
4
|
|
|
5
5
|
**Experimental** in 0.14: it can change in a minor release, but never in a patch release ([API stability](policies/api-stability.md#experimental)).
|
|
6
6
|
|
|
@@ -44,18 +44,34 @@ Check for `web.conversationRoute` at runtime and set gallery `minPocket: "0.16.0
|
|
|
44
44
|
- `send` returns when the session takes the message, not when it answers.
|
|
45
45
|
- The session that gets the message reads it in a fence. Words before it say that another session's agent wrote it, that it is a request and not an order from a person, and which address to reply to.
|
|
46
46
|
|
|
47
|
+
## Stop a run
|
|
48
|
+
|
|
49
|
+
`stop(source, { to }, key)` stops the run of the linked session at the address `to`, and withdraws what waits in its queue. Stopping is the safe direction: it needs the same access as `send`, including the turn and room under the spend limit.
|
|
50
|
+
|
|
51
|
+
- When the session is idle, it has no run to stop: the call only withdraws what waits in its queue.
|
|
52
|
+
- It returns `{ busy }`. `busy` is true when the session was working.
|
|
53
|
+
- Since 0.28.0. An older Pi Pocket has no `stop`, so a module checks for it and sets `minPocket` to `0.28.0` when it needs it.
|
|
54
|
+
|
|
55
|
+
## Archive a session
|
|
56
|
+
|
|
57
|
+
`archive(source, { to, archived? }, key)` archives the linked session at the address `to`. With `archived: false`, it brings the session back. Without `archived`, it archives.
|
|
58
|
+
|
|
59
|
+
- It returns `{ archived, repeating }`. `archived` says whether the session is archived now. `repeating` is how many of its repeating schedules keep running: an archive does not stop them.
|
|
60
|
+
- It needs the same access as `send`.
|
|
61
|
+
- Since 0.28.0, with the same check as `stop`.
|
|
62
|
+
|
|
47
63
|
## List the sessions
|
|
48
64
|
|
|
49
65
|
`list(source)` gives the sessions linked to the source, at any distance, that the person whom Pi works for can see.
|
|
50
66
|
|
|
51
67
|
- Each one has an `address` of the source's own, so no session's id goes into the source's transcript.
|
|
52
|
-
- Each one has its title, folder, and state only when all the people who see the source also see it.
|
|
68
|
+
- Each one has its title, folder, and state only when all the people who see the source also see it. Since 0.28.0 that state includes `failed`: why its last run gave up, the same short line the session list shows, and only while that failure stands. A later run clears it. A run that was stopped is not a failure.
|
|
53
69
|
|
|
54
70
|
Addresses belong to the session that has them. A fork starts with none, so it leaves the team: the addresses in the history that it copied do not work there.
|
|
55
71
|
|
|
56
72
|
## Who it acts for
|
|
57
73
|
|
|
58
|
-
`start` and `
|
|
74
|
+
`start`, `send`, `stop`, and `archive` act for the person whom Pi works for in the source. They need that person's access and right to steer. To start a session, that person must also have access to all sessions. `stop` and `archive` reach only a session of this team that the person can see.
|
|
59
75
|
|
|
60
76
|
Pi Pocket refuses them while the source is in plan mode, past a spend limit, or while another person has the turn. `send` also needs the turn, and room under the spend limit, in the target session.
|
|
61
77
|
|
|
@@ -73,6 +89,6 @@ Pi Pocket keeps a team small. Past these limits ([Limits](reference/limits.md#li
|
|
|
73
89
|
|
|
74
90
|
## Replays
|
|
75
91
|
|
|
76
|
-
Give a `key` that stays the same when the call runs again: `${api.taskId}:${api.callId}`. A
|
|
92
|
+
Give a `key` that stays the same when the call runs again: `${api.taskId}:${api.callId}`. A call with a key that Pi Pocket saw before returns what the first call returned, and does not act again. So a replay makes one session, sends one message, stops one run, and archives once. A repeated `stop` returns the first call's `{ busy }`. A repeated `archive` returns the first call's `{ archived, repeating }`, not a state someone changed later. Pi Pocket keeps the record of a key for a limited time, and for a limited number of calls ([limits](reference/limits.md#linked-sessions)).
|
|
77
93
|
|
|
78
94
|
The errors say what is wrong. They do not tell Pi what to do about it: your tool tells Pi that.
|
|
@@ -42,10 +42,12 @@ These members are public:
|
|
|
42
42
|
- `notice(level, message, id?)`
|
|
43
43
|
- `resolveModel(spec)`, `subagentModels()`, `modelProblem(ref, fresh?)`, `modelInfo(spec)` (exact local metadata, since 0.16.0)
|
|
44
44
|
- `requesterOf(conversationId)`
|
|
45
|
+
- `cwdOf(conversationId)` (experimental, since 0.28.0)
|
|
46
|
+
- `registerWorkspaceProvider(scheme, provider)` and `WorkspaceProvider` (experimental, since 0.28.0: [Execution environments for workspaces](../workspaces.md))
|
|
45
47
|
- `roleOf(personId)` (experimental, since 0.27.0)
|
|
46
48
|
- `skillPaths()`, `skills(cwd)`
|
|
47
49
|
- `heldBack(conversationId)`, `onLimitsChanged(listener)`
|
|
48
|
-
- `linkedSessions`: `start`, `send`, `list` (experimental in 0.14, see [Experimental](#experimental))
|
|
50
|
+
- `linkedSessions`: `start`, `send`, `list` (experimental in 0.14, see [Experimental](#experimental)); `stop`, `archive` (experimental, since 0.28.0)
|
|
49
51
|
- `text`: `quoted`, `defang`
|
|
50
52
|
- `thinkingLevels`
|
|
51
53
|
- `fetchPublic(url, init)` (experimental, since 0.20.0)
|
|
@@ -62,7 +64,7 @@ The host's members do not change while modules reload. A new member comes only a
|
|
|
62
64
|
- `provide`, `use`, `onService`, `settings`, `setting`, and `onSettings` (experimental, since 0.22.0: [Events, services, and settings](../services-settings.md)).
|
|
63
65
|
- `publicPage` and `links` (experimental, since 0.22.0): pages at `/l/<token>` for anyone with a module's link, what a page handler gets (`PublicPageRequest`), and what its answer does ([Public pages](../public-pages.md)).
|
|
64
66
|
- `presentEntry` (experimental, since 0.28.0), with `PresentEntry`: how an input this module sends shows in the transcript. The model still reads that message in full ([Adding to the app](../app.md)).
|
|
65
|
-
- What a route handler gets (`WebRequest`: `method`, `params`, `query`, `body`, `user`, `signal`; since 0.16.0 also request-lifetime `snapshot`, `context`, `commit`), and what its answer does.
|
|
67
|
+
- What a route handler gets (`WebRequest`: `method`, `params`, `query`, `body`, `user`, `signal`; since 0.16.0 also request-lifetime `snapshot`, `context`, `commit`), and what its answer does. `createSession` is experimental since 0.28.0.
|
|
66
68
|
- A conversation-bound request's `conversation` metadata and human `linkedSessions.start` / `list`, with their authenticated-actor, receipt, and admission checks (since 0.16.0).
|
|
67
69
|
- `ConversationWebRequest.conversationUsage`, with `UsageTotals` and `ConversationUsage` (experimental, since 0.28.0): read-only usage for a visible conversation and its visible descendants.
|
|
68
70
|
- The route paths, the methods, the `access` values (`owner`, `steer`, `view`), and the `X-Pocket` header that every call to a route must have.
|
|
@@ -168,6 +170,12 @@ Since 0.27.0, `host.roleOf(personId)` is experimental, and so is the `scroll` fi
|
|
|
168
170
|
|
|
169
171
|
Since 0.28.0, `web.presentEntry` and `pocket.entryPresentation` are experimental, with `PresentEntry`; so is `ConversationWebRequest.conversationUsage`, with `UsageTotals` and `ConversationUsage`. A module names how an input it sends shows. The model still reads that message in full. Since then too, `pocket.messages` leaves out an input stored as a module's own kind: before, such an input was not a message in the transcript at all.
|
|
170
172
|
|
|
173
|
+
Since 0.28.0, `host.registerWorkspaceProvider`, `WorkspaceProvider`, `host.cwdOf`, and `WebRequest.createSession` are experimental: [Execution environments for workspaces](../workspaces.md).
|
|
174
|
+
|
|
175
|
+
Since 0.28.0, `pocket.fence` and `pocket.mathInline` are experimental, with `FenceSpec`, `MathInlineSpec`, and `FenceProps`.
|
|
176
|
+
|
|
177
|
+
Since 0.28.0, `run.ended` carries `outcome` (`done`, `failed`, or `aborted`) and, when the run gave up, `failure`: the same short line the session list shows. `LinkedSession.failed` carries that line for a linked session's last run, with the same audience rule as its title, and only while the failure stands. Both are experimental.
|
|
178
|
+
|
|
171
179
|
Since 0.20.0, the session list's extension points are experimental: `pocket.sessionChips`, `sessionAction`, `sessionFilter`, and `sessionSearch`, `WebRequest.sessions`, and their types. So is `pocket.composerKey`, with `ComposerKeySpec` and `ComposerBox`, and so are `pocket.onConversation`, `messages`, and `reveal`, with `MessagesOptions`, `MessagePage`, and `MessageInfo`. So are `host.registerModelProvider`, and `host.fetchPublic` with `PublicFetchInit`.
|
|
172
180
|
|
|
173
181
|
### Deprecated
|
|
@@ -54,7 +54,7 @@ Ask these questions in this order. The first "yes" gives the answer.
|
|
|
54
54
|
|
|
55
55
|
### Linked sessions and Agent Teams
|
|
56
56
|
|
|
57
|
-
- **Core: linked sessions** (`linked-sessions.ts`, `host.linkedSessions`). Core starts a linked session, carries messages, and
|
|
57
|
+
- **Core: linked sessions** (`linked-sessions.ts`, `host.linkedSessions`). Core starts a linked session, carries messages, lists the sessions, and stops or archives one of the team. It acts with the rights of the person Pi works for. It refuses work in plan mode. It counts the cost of the team against the budget of the top session. It stops a team at its [limits](../reference/limits.md#linked-sessions) of sessions, and of messages with no message from a person. It uses keys, so a replay acts once. It gives sessions addresses, so no session ID goes into a transcript.
|
|
58
58
|
- **Extension: Agent Teams** (`extensions/agent-teams.ts` and `agent-teams.js`). The `team` tool, its words to Pi, and how its calls show. It is off by default. At run time it uses only `host` and `web`, as a drop-in does.
|
|
59
59
|
- **Why:** pull request #84 first put Agent Teams in core. In 0.14 the mechanism stayed in core, because it decides permissions, stored data, and spend (C1 to C3). The workflow became a built-in extension (C6, C7). Another team workflow can use the same linked sessions.
|
|
60
60
|
|
|
@@ -75,6 +75,7 @@ Each member in the reference has its own Since line. These parts came together:
|
|
|
75
75
|
| `pocket.panel` and `pocket.status` (experimental) | 0.19.0 |
|
|
76
76
|
| Slots: `pocket.topbar`, `composerButton`, `replyAction`, `insertText`, `arrange` (experimental) | 0.19.0 |
|
|
77
77
|
| `cwd` in `host.linkedSessions.start` and the human-bound `linkedSessions.start` | 0.19.0 |
|
|
78
|
+
| `stop` and `archive` on `host.linkedSessions` (experimental) | 0.28.0 |
|
|
78
79
|
| The session list: `pocket.sessionChips`, `sessionAction`, `sessionFilter`, `sessionSearch`, and `WebRequest.sessions` (experimental) | 0.20.0 |
|
|
79
80
|
| `host.registerModelProvider` (experimental) | 0.20.0 |
|
|
80
81
|
| `host.fetchPublic` (experimental) | 0.20.0 |
|
|
@@ -89,3 +90,4 @@ Each member in the reference has its own Since line. These parts came together:
|
|
|
89
90
|
| The page's scroll position: `scroll` in the `host.browser` snapshot (experimental) | 0.27.0 |
|
|
90
91
|
| Answers to pick on an ask's card: `header`, `choices`, `multiple`, and `other` in `AskField` (experimental) | 0.27.0 |
|
|
91
92
|
| Read-only conversation and descendant usage: `ConversationWebRequest.conversationUsage` (experimental) | 0.28.0 |
|
|
93
|
+
| How a run stopped: `outcome` and `failure` on `run.ended`, and `failed` on a linked session (experimental) | 0.28.0 |
|
|
@@ -40,6 +40,16 @@ Since 0.1.0 · Stable
|
|
|
40
40
|
|
|
41
41
|
Pi's own folder, usually `~/.pi/agent`. Pi keeps its sign-ins, models, settings, skills, and prompt templates there.
|
|
42
42
|
|
|
43
|
+
### `cwdOf`
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
cwdOf(conversationId: ConversationId): string;
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Since 0.28.0 · Experimental
|
|
50
|
+
|
|
51
|
+
The conversation's current working folder, or its canonical workspace URI for a remote session. It reads the current agent state, so a module must not cache it across folder changes.
|
|
52
|
+
|
|
43
53
|
## Skills
|
|
44
54
|
|
|
45
55
|
### `skillPaths`
|
|
@@ -162,6 +172,18 @@ The thinking levels, lowest first. They have the names that models and sessions
|
|
|
162
172
|
|
|
163
173
|
## People and limits
|
|
164
174
|
|
|
175
|
+
### `registerWorkspaceProvider`
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
registerWorkspaceProvider(scheme: string, provider: WorkspaceProvider): () => void;
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Since 0.28.0 · Experimental
|
|
182
|
+
|
|
183
|
+
Registers the execution environment for a URI scheme such as `ssh`. `resolveCwd` returns the canonical address. It must keep the same scheme. Pi Pocket stores that address and refuses to use the local machine when no provider is active. The returned disposer removes only its own registration. See [Execution environments for workspaces](../workspaces.md).
|
|
184
|
+
|
|
185
|
+
`WorkspaceProvider` has `env(cwd: string): ExecutionEnv` and `resolveCwd(cwd: string, signal?: AbortSignal): Promise<string>`. `env` returns promptly. It receives the canonical workspace address. `resolveCwd` can check and canonicalize the address. `signal` is optional: in 0.28, session creation and settings do not pass one yet.
|
|
186
|
+
|
|
165
187
|
### `requesterOf`
|
|
166
188
|
|
|
167
189
|
```ts
|
|
@@ -216,9 +238,9 @@ Calls `listener` each time something happens in the app: a session is made, rena
|
|
|
216
238
|
|
|
217
239
|
```typescript
|
|
218
240
|
web.onDispose(
|
|
219
|
-
host.on("run.ended", ({ conversationId, session }) => {
|
|
220
|
-
if (conversationId === session) {
|
|
221
|
-
|
|
241
|
+
host.on("run.ended", ({ conversationId, session, outcome, failure }) => {
|
|
242
|
+
if (conversationId === session && outcome === "failed") {
|
|
243
|
+
log.push({ session, failure });
|
|
222
244
|
}
|
|
223
245
|
}),
|
|
224
246
|
);
|
|
@@ -391,7 +413,7 @@ readonly linkedSessions: LinkedSessions;
|
|
|
391
413
|
|
|
392
414
|
Since 0.14.0 · Experimental
|
|
393
415
|
|
|
394
|
-
Lets a tool start sessions from the session that it runs in,
|
|
416
|
+
Lets a tool start sessions from the session that it runs in, send messages between them, and stop or archive one, as Agent Teams does. A team or orchestration extension uses the same calls. A linked session is an ordinary session. [Starting and messaging sessions](../linked-sessions.md) tells you how they work, what they cannot do, and how to call them.
|
|
395
417
|
|
|
396
418
|
Each call acts as the person that Pi works for in `source`, and that person's checks apply. Give each call a `key` that stays the same when the call runs again, such as `${api.taskId}:${api.callId}`. A second call with the same `key` does nothing again: it returns what the first call returned.
|
|
397
419
|
|
|
@@ -431,6 +453,34 @@ Sends `message` to the linked session at the address `to`. Without `steer`, the
|
|
|
431
453
|
|
|
432
454
|
The session that gets the message reads it between tags. Words before it say that the agent of another session wrote it, and that it is a request, not a person's order. They also give the address to reply to.
|
|
433
455
|
|
|
456
|
+
#### `linkedSessions.stop`
|
|
457
|
+
|
|
458
|
+
```ts
|
|
459
|
+
stop(
|
|
460
|
+
source: ConversationId,
|
|
461
|
+
request: { to: string },
|
|
462
|
+
key: string,
|
|
463
|
+
): Promise<{ busy: boolean }>;
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
Since 0.28.0 · Experimental
|
|
467
|
+
|
|
468
|
+
Stops the run of the linked session at the address `to`, and withdraws what waits in its queue. When the session is idle, it has no run to stop, and the call only withdraws what waits in its queue. `busy` is true when it was working. It needs the same access as `send`, and it reaches only a session of this team. An older Pi Pocket has no `stop`: check for it, and set `minPocket` to `0.28.0` when you need it.
|
|
469
|
+
|
|
470
|
+
#### `linkedSessions.archive`
|
|
471
|
+
|
|
472
|
+
```ts
|
|
473
|
+
archive(
|
|
474
|
+
source: ConversationId,
|
|
475
|
+
request: { to: string; archived?: boolean },
|
|
476
|
+
key: string,
|
|
477
|
+
): Promise<{ archived: boolean; repeating: number }>;
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
Since 0.28.0 · Experimental
|
|
481
|
+
|
|
482
|
+
Archives the linked session at the address `to`. With `archived: false`, it brings the session back. Without `archived`, it archives. `archived` in the result says whether the session is archived now. `repeating` is how many of its repeating schedules keep running: an archive does not stop them. It needs the same access as `send`. An older Pi Pocket has no `archive`.
|
|
483
|
+
|
|
434
484
|
#### `linkedSessions.list`
|
|
435
485
|
|
|
436
486
|
```ts
|
|
@@ -450,6 +500,7 @@ interface LinkedSession {
|
|
|
450
500
|
cwd?: string;
|
|
451
501
|
busy?: boolean;
|
|
452
502
|
archived?: boolean;
|
|
503
|
+
failed?: string;
|
|
453
504
|
}
|
|
454
505
|
```
|
|
455
506
|
|
|
@@ -458,7 +509,8 @@ Since 0.14.0 · Experimental
|
|
|
458
509
|
A linked session, as `list` gives it.
|
|
459
510
|
|
|
460
511
|
- `address`: the address that the asking session uses for it. It is never the session's id.
|
|
461
|
-
- `title`, `cwd` (its folder), `busy` (Pi works in it now), and `
|
|
512
|
+
- `title`, `cwd` (its folder), `busy` (Pi works in it now), `archived`, and `failed`: these are there only when all the people who see the asking session see this session too.
|
|
513
|
+
- `failed` (since 0.28.0): why its last run gave up, the same short line the session list shows. It is there only while that failure stands. A later run clears it, and a run that was stopped leaves none.
|
|
462
514
|
|
|
463
515
|
## Types for events
|
|
464
516
|
|
|
@@ -483,7 +535,12 @@ interface AppEvents {
|
|
|
483
535
|
via?: string;
|
|
484
536
|
};
|
|
485
537
|
"run.started": { conversationId: number; session: number };
|
|
486
|
-
"run.ended": {
|
|
538
|
+
"run.ended": {
|
|
539
|
+
conversationId: number;
|
|
540
|
+
session: number;
|
|
541
|
+
outcome: "done" | "failed" | "aborted";
|
|
542
|
+
failure?: string;
|
|
543
|
+
};
|
|
487
544
|
}
|
|
488
545
|
```
|
|
489
546
|
|
|
@@ -494,7 +551,7 @@ What each event's listener gets.
|
|
|
494
551
|
- `session.created`: a session in the list was made, by a person, a fork (`forkedFrom`), a linked start (`linkedFrom`), or a resend. `createdBy` is a person's id. Subagents are not sessions in the list, and send none.
|
|
495
552
|
- `session.renamed`, `session.archived`: its new title, or whether it is archived now.
|
|
496
553
|
- `message.sent`: a person's message to Pi, a steer or a queued one too. `by` is their id. `text` is the words as stored, with values that extensions hide already hidden and attachments left out. `via` names what sent it for them, such as PiP or a schedule.
|
|
497
|
-
- `run.started`, `run.ended`: Pi started or stopped working in a conversation. `conversationId` is that conversation, a session's or a subagent's; `session` is the session it belongs to.
|
|
554
|
+
- `run.started`, `run.ended`: Pi started or stopped working in a conversation. `conversationId` is that conversation, a session's or a subagent's; `session` is the session it belongs to. Since 0.28.0, `run.ended` also says how the run stopped: `outcome` is `done` when it finished, `failed` when it gave up, or `aborted` when it was stopped. `failure` is why it gave up, the same short line the session list shows, and only when `outcome` is `failed`. A session's failure stands until a later run starts.
|
|
498
555
|
|
|
499
556
|
### `AppEventName`
|
|
500
557
|
|
|
@@ -569,6 +569,26 @@ pocket.composerKey({
|
|
|
569
569
|
});
|
|
570
570
|
```
|
|
571
571
|
|
|
572
|
+
### `fence`
|
|
573
|
+
|
|
574
|
+
```ts
|
|
575
|
+
fence(spec: FenceSpec): Added<FenceSpec>;
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
Since 0.28.0 · Experimental
|
|
579
|
+
|
|
580
|
+
Registers a component for one or more fenced-code languages. The app renders it with exactly `{ source, lang, streaming }`: the code text, the language label from the fence, and whether the Markdown is still streaming. The component uses the app's Preact and can use the Preact functions in `pocket`. Language matching ignores case. When registrations match the same language, the first one in server module order, then registration order, wins. See [`FenceSpec`](#fencespec), [`FenceProps`](#fenceprops), and [`Added`](#added).
|
|
581
|
+
|
|
582
|
+
### `mathInline`
|
|
583
|
+
|
|
584
|
+
```ts
|
|
585
|
+
mathInline(spec: MathInlineSpec): Added<MathInlineSpec>;
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
Since 0.28.0 · Experimental
|
|
589
|
+
|
|
590
|
+
Registers the renderer for inline `$…$` and display `$$…$$` math. The app calls `mount(element, source, display)` for each math element: `element` is the code element, `source` is the formula without delimiters, and `display` is true for display math. Math parsing is on only while a registration is active. When multiple registrations exist, the first one in server module order, then registration order, wins. See [`MathInlineSpec`](#mathinlinespec) and [`Added`](#added).
|
|
591
|
+
|
|
572
592
|
### `insertText`
|
|
573
593
|
|
|
574
594
|
```ts
|
|
@@ -1259,6 +1279,33 @@ Since 0.14.0 · Stable
|
|
|
1259
1279
|
|
|
1260
1280
|
What a sheet's component gets: the fields of the `props` that `openSheet` gave, and `pocket` and `close`.
|
|
1261
1281
|
|
|
1282
|
+
### `FenceSpec`
|
|
1283
|
+
|
|
1284
|
+
```ts
|
|
1285
|
+
interface FenceSpec {
|
|
1286
|
+
id: string;
|
|
1287
|
+
langs: string[];
|
|
1288
|
+
component: ComponentType<FenceProps>;
|
|
1289
|
+
}
|
|
1290
|
+
```
|
|
1291
|
+
|
|
1292
|
+
Since 0.28.0 · Experimental
|
|
1293
|
+
|
|
1294
|
+
The registration's id, the code fence languages it handles, and the Preact component the app renders. Language matching ignores case. See [`FenceProps`](#fenceprops).
|
|
1295
|
+
|
|
1296
|
+
### `MathInlineSpec`
|
|
1297
|
+
|
|
1298
|
+
```ts
|
|
1299
|
+
interface MathInlineSpec {
|
|
1300
|
+
id: string;
|
|
1301
|
+
mount(element: HTMLElement, source: string, display: boolean): void;
|
|
1302
|
+
}
|
|
1303
|
+
```
|
|
1304
|
+
|
|
1305
|
+
Since 0.28.0 · Experimental
|
|
1306
|
+
|
|
1307
|
+
The registration's id and its math mounter. The app calls the mounter with the rendered code element, formula text without delimiters, and whether the formula uses display math.
|
|
1308
|
+
|
|
1262
1309
|
### `ToolCallSpec`
|
|
1263
1310
|
|
|
1264
1311
|
```ts
|
|
@@ -1309,7 +1356,7 @@ interface Added<S> {
|
|
|
1309
1356
|
|
|
1310
1357
|
Since 0.14.0 · Stable
|
|
1311
1358
|
|
|
1312
|
-
What `rail`, `menu`, `launcher`, `page`, and `
|
|
1359
|
+
What `rail`, `menu`, `launcher`, `page`, `sheet`, `fence`, and `mathInline` return.
|
|
1313
1360
|
|
|
1314
1361
|
- `update`: changes the fields in `patch`. An update that changes nothing draws nothing again. Values count as the same only when they are the very same value: a new array or function is a change.
|
|
1315
1362
|
- `remove`: removes what was added.
|
|
@@ -1356,6 +1403,20 @@ Since 0.14.0 · Stable
|
|
|
1356
1403
|
|
|
1357
1404
|
`text` is the Markdown to show.
|
|
1358
1405
|
|
|
1406
|
+
### `FenceProps`
|
|
1407
|
+
|
|
1408
|
+
```ts
|
|
1409
|
+
interface FenceProps {
|
|
1410
|
+
source: string;
|
|
1411
|
+
lang: string;
|
|
1412
|
+
streaming: boolean;
|
|
1413
|
+
}
|
|
1414
|
+
```
|
|
1415
|
+
|
|
1416
|
+
Since 0.28.0 · Experimental
|
|
1417
|
+
|
|
1418
|
+
The exact props the app passes to a `pocket.fence` component. `source` is the code text, `lang` is the language label from the fence, and `streaming` says whether the Markdown is still streaming.
|
|
1419
|
+
|
|
1359
1420
|
### `SwitchProps`
|
|
1360
1421
|
|
|
1361
1422
|
```ts
|
|
@@ -143,6 +143,8 @@ Each is a `data-part` attribute. Some elements have two (`data-part="composer-bu
|
|
|
143
143
|
| `prompt` | A person's message |
|
|
144
144
|
| `prompt-head`, `author-mark`, `prompt-author` | Its head: who sent it and when; their initials; their name |
|
|
145
145
|
| `prompt-text` | What it says (its skill chip, words, and files) |
|
|
146
|
+
| `linked-head`, `linked-mark`, `linked-name` | A linked session's message (`data-from` `linked`): its head, square mark, session name (since 0.28.0) |
|
|
147
|
+
| `linked-open`, `linked-body`, `linked-more` | Its Open button, its text as Markdown, and Show all on a long one (since 0.28.0) |
|
|
146
148
|
| `presented-input`, `presented-head` | An extension's input (`web.presentEntry`), folded: its card and the line that opens it (since 0.28.0) |
|
|
147
149
|
| `presented-chevron`, `presented-tag` | That line's chevron; the input's label in its head, when shown open (since 0.28.0) |
|
|
148
150
|
| `presented-more` | The button beside that line that opens its message sheet (since 0.28.0) |
|
|
@@ -251,6 +251,7 @@ Answers the requests of a route. The value that it returns goes back as JSON, an
|
|
|
251
251
|
|
|
252
252
|
```ts
|
|
253
253
|
interface WebRequest {
|
|
254
|
+
createSession(request: { cwd: string; title?: string }): Promise<{ id: number }>;
|
|
254
255
|
readonly method: WebMethod;
|
|
255
256
|
readonly params: Readonly<Record<string, string>>;
|
|
256
257
|
readonly query: URLSearchParams;
|
|
@@ -278,6 +279,7 @@ What a handler gets.
|
|
|
278
279
|
- Document operations recheck the current person. Retaining a request, its context, or a callback does not extend its lifetime: commits after disconnect or handler return are refused, and an unfinished callback rolls back. Await all writes before returning. These APIs are for module documents, not core's internal documents or a way to start model work.
|
|
279
280
|
- An unbound catalog save has no source plan, turn, or spend checks. A bound commit also requires the source's current steering and turn rights.
|
|
280
281
|
- Since 0.20.0 (experimental), `sessions()` gives the sessions that the person who asked can see now, as their session list shows them, archived ones too. See [`WebSession`](#websession). Use it to check the ids that a browser sends, and to keep data about sessions from people who cannot see them. Each call reads the list again.
|
|
282
|
+
- Since 0.28.0 (experimental), `createSession` starts an ordinary session on owner-only routes. It refuses anyone but the owner. See [Execution environments for workspaces](../workspaces.md).
|
|
281
283
|
|
|
282
284
|
### `WebSession`
|
|
283
285
|
|
|
@@ -643,7 +645,7 @@ Who can use a route, or whose tabs load a browser module.
|
|
|
643
645
|
- `"steer"`: the owner, and guests who can steer all sessions.
|
|
644
646
|
- `"view"`: the owner, guests, and viewers who can see all sessions.
|
|
645
647
|
|
|
646
|
-
A person invited to one session never can, because these parts belong to the whole app. Each route has its own `access`, so a browser module for everyone can call a route for the owner alone.
|
|
648
|
+
A person invited to one session never can, because these parts belong to the whole app. The one exception is the built-in Diagrams browser module, which draws Mermaid and math in their replies. They get its browser module and no routes. Each route has its own `access`, so a browser module for everyone can call a route for the owner alone.
|
|
647
649
|
|
|
648
650
|
`access` is the same for all methods. A POST route with `"view"` lets viewers change something through it, though they cannot steer a session. Give `"owner"` or `"steer"` to a route that changes things.
|
|
649
651
|
|
|
@@ -98,7 +98,7 @@ Routes and the browser module are for the owner alone, unless their `access` say
|
|
|
98
98
|
| `"steer"` | The owner, and guests who can steer every session |
|
|
99
99
|
| `"view"` | The owner, guests, and viewers who see every session |
|
|
100
100
|
|
|
101
|
-
- A person invited to one session never may use them: these parts belong to the whole app.
|
|
101
|
+
- A person invited to one session never may use them: these parts belong to the whole app. The one exception is the built-in Diagrams browser module, which draws Mermaid and math in their replies. They get its browser module and no routes.
|
|
102
102
|
- Each route checks its own `access`. So a browser module for everyone can have a route for the owner alone.
|
|
103
103
|
- `access` is the same for each method. A `POST` route open to `"view"` lets viewers change something through it, though they cannot steer a session. Give a route that changes things `"owner"` or `"steer"`.
|
|
104
104
|
- A browser module runs with the rights of the person whose tab loads it. So it can do nothing in a guest's tab that the guest cannot do.
|