pi-pocket 0.30.0-beta.2 → 0.30.0-beta.3
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/AGENTS.md +1 -1
- package/docs/desktop-app.md +3 -3
- package/docs/extensions/modules.md +1 -1
- package/docs/extensions/policies/api-stability.md +2 -2
- package/docs/extensions/reference/types.md +2 -2
- package/docs/macos.md +10 -8
- package/docs/map.md +2 -1
- package/docs/windows.md +21 -15
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/src/server/app.ts +18 -8
- package/src/server/dropin-config.ts +144 -0
- package/src/server/extension-document-imports.ts +39 -3
- package/src/server/reload.ts +25 -17
package/AGENTS.md
CHANGED
|
@@ -7,7 +7,7 @@ Pi Pocket is often edited from inside itself, while it runs. [docs/map.md](docs/
|
|
|
7
7
|
- `web/**` changes reload every open browser right away. Keep the app loadable after each save: a syntax error blanks the screen for everyone, including you. Check with `node --check web/<file>.js` after editing.
|
|
8
8
|
- `src/server/extensions/*.ts` changes are reinstalled into the running server. A file that fails to load keeps its previous version and reports the error. Each module default-exports `(host, web) => Extension | Extension[] | void`, possibly async (`web` adds routes and a browser module to the app: [docs/extensions/app.md](docs/extensions/app.md)). Start each module with a `/** … */` comment: its first sentence is the description in the app's Extensions sheet, where the owner can turn modules off (a module that is off is not loaded, even when edited).
|
|
9
9
|
- Other `src/server/**` changes need a restart (menu → Restart server). Running work resumes after it, but a tool call cut off mid-run that is not replay-safe comes back as interrupted. Do not restart while your own tool call is running; finish the edit, run `npm run check` and `npm test`, then ask the user to restart.
|
|
10
|
-
- The owner's drop-in extensions in `~/.pi-pocket/extensions/` load the same way, after the built-in ones, and stay off until the owner turns them on.
|
|
10
|
+
- The owner's drop-in extensions in `~/.pi-pocket/extensions/` load the same way, after the built-in ones, and stay off until the owner turns them on. They import Pi Pocket's packages by name with no link (the resolve hook in `src/server/extension-document-imports.ts`); a `node_modules` link and a `tsconfig.json` there serve editors.
|
|
11
11
|
- Document kinds in `src/server/docs.ts` are stored data. Do not rename them, or change their scope, history, or fork settings: Pi Durable checks those against what is stored.
|
|
12
12
|
- The server is plain TypeScript run by Node's type stripping: only erasable syntax (no enums, no parameter properties, no namespaces). Imports use `.ts` extensions.
|
|
13
13
|
- Code style is Prettier (`.prettierrc.json`: 4 spaces, 100 columns) plus ESLint's layout rules (`eslint.config.js`): braces on every `if` and loop, and a blank line after declarations, around blocks, and before `return` and `throw`. Run `npm run format` after editing. Prettier leaves the markup in `html` templates alone, so lay it out by hand the same way: 4 spaces per level, and a tag that runs past 100 columns gets one attribute per line and its children on their own lines. In htm a line break is not a space: break only where there is no space, or between tags, never inside running text.
|
package/docs/desktop-app.md
CHANGED
|
@@ -17,7 +17,7 @@ The console launcher stays, as **Pi Pocket (console)**: it has the access menu (
|
|
|
17
17
|
|
|
18
18
|
1. **One app per user.** A second start (the Start menu again, Spotlight, the Dock) asks the first one to show its window, then exits. Windows uses a named mutex and event in the session's `Local\` namespace; macOS a distributed notification. `--quit` asks the running one to quit, as its **Quit** does; the installers use it.
|
|
19
19
|
2. **A server that runs already is used.** Each launcher writes `launcher-running.json` in the data folder when its server is ready, and removes it when it quits ([`src/launcher/desktop.ts`](../src/launcher/desktop.ts)): its process, the server's local address, and whether a desktop app started it. The app uses that server when the process is there and `GET /api/pocket/info` answers. **Quit** then leaves it running: another launcher, such as Pi Pocket (console), started it.
|
|
20
|
-
3. **Otherwise the app starts a launcher
|
|
20
|
+
3. **Otherwise the app checks the package, then starts a launcher.** It reads the version in the `package.json` of the `pi-pocket` package in `app\` (Windows) or `app/` (macOS). When there is none, it is older than the app's own version, or (on Windows) `app\setup-finished.txt` is missing, which Setup writes after it copied the package, it shows a message that says what is wrong and to run Setup or the package again, writes it to the log, and starts nothing: a launcher older than the app does not know `--desktop`, and would fail with only "Unknown argument" in the log. A newer package is an in-app update, and starts. The installers put their own package in place, so only an install that did not finish leaves an older one. Then the app starts `pi-pocket --desktop`, with the install's own Node.js. `--desktop` means: this device only (unless `--access` says otherwise), no access menu, no keys, no sign-in link and no QR code in its output, and the choice is not saved as the console's last one. It stops when its standard input closes. The app holds that input: **Quit** closes it, and so does the end of the app, also when it crashes.
|
|
21
21
|
4. **The window signs in.** See below.
|
|
22
22
|
|
|
23
23
|
On Windows the launcher and everything it starts (the server, the commands of the agents, the Edge window) are in a job object that ends with the app, so nothing runs on after it, even when the app is killed. Edge's window closes on **Quit**, with the server it shows. Without Edge, the default browser opens the one-time link; it is not in the job, and stays.
|
|
@@ -41,7 +41,7 @@ On Windows the one-time link is on Edge's command line, and only there: it is sp
|
|
|
41
41
|
|
|
42
42
|
## What the apps rely on
|
|
43
43
|
|
|
44
|
-
A newer installer replaces the app; Menu → **Update Pi Pocket**
|
|
44
|
+
A newer installer replaces the app and its package; Menu → **Update Pi Pocket** replaces only the package. So an installed app runs against newer `pi-pocket` packages, never older ones (it refuses them), and these stay as they are: `--desktop`, `launcher-running.json` (its fields only grow), `/api/pocket/info`, `/api/sign-in-link`, `/login?once=`, and `/api/restart`.
|
|
45
45
|
|
|
46
46
|
## What the window does not do yet
|
|
47
47
|
|
|
@@ -51,4 +51,4 @@ A newer installer replaces the app; Menu → **Update Pi Pocket** does not. So a
|
|
|
51
51
|
|
|
52
52
|
## How it is tested
|
|
53
53
|
|
|
54
|
-
[`test/launcher-desktop.test.ts`](../test/launcher-desktop.test.ts) runs `--desktop`: `launcher-running.json`, the one-time link, no token in the output, and the stop when its input closes. On each pull request, [`windows.yml`](../.github/workflows/windows.yml) and [`macos.yml`](../.github/workflows/macos.yml) install the app, open it as the Start menu or Finder does, and check: no console or Terminal window, the server on this computer only, a window that signed in (on Windows, Edge spent the one-time link; on macOS, the window's own `/api/me` answers 200), no token in the log or on a command line, one instance only, and **Quit** that stops the launcher, the server, and the window. They also take a screenshot of the window. Nobody has tried them yet on a real PC or Mac, only on GitHub's runners.
|
|
54
|
+
[`test/launcher-desktop.test.ts`](../test/launcher-desktop.test.ts) runs `--desktop`: `launcher-running.json`, the one-time link, no token in the output, and the stop when its input closes. On each pull request, [`windows.yml`](../.github/workflows/windows.yml) and [`macos.yml`](../.github/workflows/macos.yml) install the app, open it as the Start menu or Finder does, and check: no console or Terminal window, the server on this computer only, a window that signed in (on Windows, Edge spent the one-time link; on macOS, the window's own `/api/me` answers 200), no token in the log or on a command line, one instance only, and **Quit** that stops the launcher, the server, and the window. They also take a screenshot of the window. Then they write an older version into the package's `package.json`, and check that the app shows its message, writes it to the log, and starts no launcher. Nobody has tried them yet on a real PC or Mac, only on GitHub's runners.
|
|
@@ -5,7 +5,7 @@ A module is one file that Pi Pocket loads. This page tells what the file must be
|
|
|
5
5
|
## The file
|
|
6
6
|
|
|
7
7
|
- **TypeScript that Node runs as it is.** Use only erasable syntax: no `enum`, no `namespace`, and no constructor parameter properties. A local import ends in `.ts`.
|
|
8
|
-
- **Packages by name.** Import `@earendil-works/pi-durable`, `@earendil-works/pi-ai`, `@earendil-works/pi-mcp` (Pi's MCP client), and the other packages of Pi Pocket by name.
|
|
8
|
+
- **Packages by name.** Import `@earendil-works/pi-durable`, `@earendil-works/pi-ai`, `@earendil-works/pi-mcp` (Pi's MCP client), and the other packages of Pi Pocket by name. Pi Pocket resolves a package that a drop-in does not have of its own from its own packages, so a drop-in gets the same modules that the server runs. This needs no link: it also works where the system refuses links. A package in the drop-in's own `node_modules` folder comes first. Where links work, the drop-in folder also has a `node_modules` link to Pi Pocket's packages, for tools that read the folder.
|
|
9
9
|
- **A name of its own.** The file name must be different from the name of each built-in module. For example, Pi Pocket does not load a drop-in named `browser.ts`. Give each extension and tool in it a name with a prefix of your own, for example `my-words` and `my_word_count`. Pi Pocket does not load a module that takes a name that Pi Pocket keeps (such as `pocket-…`, or a built-in tool's), or a name that another module has. See [Names](reference/names.md).
|
|
10
10
|
- **A description.** Start the file with a `/** … */` comment. Its first sentence says what the module does. The Extensions sheet shows it.
|
|
11
11
|
|
|
@@ -18,7 +18,7 @@ Each item below is public as the reference and the guides describe it: its names
|
|
|
18
18
|
|
|
19
19
|
### 1. The module
|
|
20
20
|
|
|
21
|
-
- A `.ts` file in the drop-in folder (`extensions/` in the data folder),
|
|
21
|
+
- A `.ts` file in the drop-in folder (`extensions/` in the data folder), which imports Pi Pocket's packages by name.
|
|
22
22
|
- The default export `(host, web)`. It can be `async`. It returns one extension, a list, or nothing. Pi Pocket installs all of it or none of it.
|
|
23
23
|
- `export const pocketApi`.
|
|
24
24
|
- The first sentence of the module's `/** … */` comment, which is its description.
|
|
@@ -127,7 +127,7 @@ The host's members do not change while modules reload. A new member comes only a
|
|
|
127
127
|
|
|
128
128
|
## Packages from Earendil
|
|
129
129
|
|
|
130
|
-
Extensions import `@earendil-works/pi-durable`, `@earendil-works/pi-ai`, and the other packages that Pi Pocket has. Earendil makes them, not Pi Pocket. Pi Durable is experimental, and its API can change between its releases. Pi Pocket pins their versions in `package.json`, and a drop-in gets the same versions
|
|
130
|
+
Extensions import `@earendil-works/pi-durable`, `@earendil-works/pi-ai`, and the other packages that Pi Pocket has. Earendil makes them, not Pi Pocket. Pi Durable is experimental, and its API can change between its releases. Pi Pocket pins their versions in `package.json`, and a drop-in gets the same versions: Pi Pocket resolves them from its own packages.
|
|
131
131
|
|
|
132
132
|
- **A1. The release notes name each update of a pinned package** in "For extension authors".\
|
|
133
133
|
_Reason:_ an author can then find the cause when a module breaks after an update.
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
Use one of these:
|
|
8
8
|
|
|
9
|
-
1. **`_pocket.d.ts` in the drop-in folder.** Pi Pocket makes this link to its types file each time that it starts
|
|
9
|
+
1. **`_pocket.d.ts` in the drop-in folder.** Pi Pocket makes this link to its types file each time that it starts. Its leading `_` keeps it from loading as a module. The same import then works on all machines. If you point the link at another readable file, such as your own checkout's types, Pi Pocket leaves it as it is. A file of your own with this name also stays.
|
|
10
10
|
2. **The path in Pi Pocket's folder:** `/path/to/pi-pocket/types/pocket.d.ts`.
|
|
11
11
|
3. **The copy on the documentation site:** `https://tannermidd.github.io/pi-pocket/docs/pocket.d.ts`. It is for the latest release.
|
|
12
12
|
|
|
@@ -37,7 +37,7 @@ export default function setup(pocket) {
|
|
|
37
37
|
|
|
38
38
|
From a browser module in a folder, the path is `../_pocket.d.ts`.
|
|
39
39
|
|
|
40
|
-
The types file imports types from Pi Durable, Pi AI, and Preact by package name. The drop-in folder's `node_modules` link gives
|
|
40
|
+
The types file imports types from Pi Durable, Pi AI, and Preact by package name. The drop-in folder's `tsconfig.json` gives them, also where the system refuses links: Pi Pocket writes it at each start, and its `paths` lead each of Pi Pocket's packages to its types. Its first line says that Pi Pocket made it, and Pi Pocket refreshes it when its folders change. Do not edit it. To use your own settings, replace it with a file of your own, without that first line: Pi Pocket then leaves it as it is. Where links work, the drop-in folder's `node_modules` link to Pi Pocket's packages gives the types to tools that do not read `tsconfig.json`.
|
|
41
41
|
|
|
42
42
|
`tsc` skips `<name>.js` when there is a `<name>.ts`. To check both with `tsc`, put the browser module in the folder `<name>/`. An editor checks each file that you open.
|
|
43
43
|
|
package/docs/macos.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Each release has `Pi-Pocket-<version>.pkg` on its [GitHub release page](https://github.com/TannerMidd/pi-pocket/releases), with a `.sha256` file beside it. It installs Pi Pocket for your macOS account, with no admin password and no Node.js of your own. macOS 13.5 (Ventura) or newer, on Apple silicon or Intel: one package fits both.
|
|
4
4
|
|
|
5
|
-
The package
|
|
5
|
+
The package holds everything: Node.js, the `pi-pocket` package of its release with its dependencies, and the desktop app. The install needs no internet and no npm, so it works behind a company proxy or firewall that blocks npm, and as soon as the release is out, before npm has it.
|
|
6
6
|
|
|
7
7
|
## Gatekeeper
|
|
8
8
|
|
|
@@ -24,12 +24,12 @@ The installer has one place to install: **Install for me only**. Everything goes
|
|
|
24
24
|
| Folder or file | What it is |
|
|
25
25
|
| ---------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
26
26
|
| `node/` | Node.js, from the official `darwin-arm64` and `darwin-x64` tarballs. The build checks each against the SHA256 pinned in [`packaging/macos/build.sh`](../packaging/macos/build.sh), and joins their two `node` files into one universal file; each half is the official file, byte for byte, with its signature. |
|
|
27
|
-
| `app/` | A private npm prefix that holds the `pi-pocket` package. It is yours, so updates from the app work.
|
|
27
|
+
| `app/` | A private npm prefix that holds the `pi-pocket` package. It is yours, so updates from the app work. The package's build made it with npm, as `npm install --global` does. |
|
|
28
28
|
| `pi-pocket` | Starts the launcher with that Node.js and prefix. Arguments go to `pi-pocket` (`pi-pocket --help`). |
|
|
29
29
|
| `Pi Pocket.command` | What Terminal runs for Pi Pocket (console). |
|
|
30
30
|
| `uninstall.sh`, `login-item.sh`, `stop-pi-pocket.sh` | The uninstaller, the switch of the sign-in item, and what stops a running Pi Pocket for the installer and the uninstaller. |
|
|
31
|
-
| `
|
|
32
|
-
| `npm-cache/`, `install.log` | npm's cache, and what
|
|
31
|
+
| `place-app.mjs` | Puts the package's `pi-pocket` (in `app.new/` until then) in place of `app/` during the install, with no network, unless `app/` holds a newer one. |
|
|
32
|
+
| `npm-cache/`, `install.log` | npm's cache, for in-app updates, and what `place-app.mjs` did during the install. |
|
|
33
33
|
|
|
34
34
|
The package always uses its own Node.js, also when you have one (from Homebrew, nvm, or nodejs.org): an update of your Node.js, or its removal, does not break Pi Pocket, and in-app updates always have a prefix that they can write. Your own Node.js and npm are not changed.
|
|
35
35
|
|
|
@@ -52,7 +52,9 @@ Inside sessions, `node` and `npm` are the package's own, and a global npm instal
|
|
|
52
52
|
|
|
53
53
|
## Updates
|
|
54
54
|
|
|
55
|
-
Menu → **Update Pi Pocket** updates the package in `app/`, as for any global npm install, and restarts. The Node.js in `node/` stays the one that the package installed. A newer package brings a newer Node.js
|
|
55
|
+
Menu → **Update Pi Pocket** updates the package in `app/`, as for any global npm install, and restarts; it needs npm's registry. The Node.js in `node/` stays the one that the package installed. A newer package brings a newer Node.js and its own `pi-pocket`; install it over the old one. It stops a running Pi Pocket first (work in progress continues when Pi Pocket starts again), and it keeps a newer `pi-pocket` that the app already updated to.
|
|
56
|
+
|
|
57
|
+
Pi Pocket.app checks the package before it starts it: when `app/` holds an older `pi-pocket` than the app itself (an install that did not finish), it says so in an alert and starts nothing. Install the same package again to put its `pi-pocket` back.
|
|
56
58
|
|
|
57
59
|
## Uninstall
|
|
58
60
|
|
|
@@ -70,13 +72,13 @@ Run it in Terminal, not from a Pi Pocket session: it must stop Pi Pocket, so it
|
|
|
70
72
|
installer -pkg Pi-Pocket-0.29.0.pkg -target CurrentUserHomeDirectory
|
|
71
73
|
```
|
|
72
74
|
|
|
73
|
-
No `sudo`: the package refuses to install as root. For the sign-in item too, pass `-applyChoiceChangesXML` with a file that selects the choice `login`, as [`.github/workflows/macos.yml`](../.github/workflows/macos.yml) does. The install fails when the
|
|
75
|
+
No `sudo`: the package refuses to install as root. For the sign-in item too, pass `-applyChoiceChangesXML` with a file that selects the choice `login`, as [`.github/workflows/macos.yml`](../.github/workflows/macos.yml) does. The install fails when `place-app.mjs` cannot put the package in place; `install.log` says why.
|
|
74
76
|
|
|
75
77
|
## How it is built
|
|
76
78
|
|
|
77
|
-
[`.github/workflows/macos-installer.yml`](../.github/workflows/macos-installer.yml) builds it on GitHub's macOS runner for each published release with `pkgbuild` and `productbuild`, and attaches it to the release. Pi Pocket.app is compiled there with `swiftc` for arm64 and x86_64, joined with `lipo`, and signed ad hoc, unless the `macos-signing` environment also has a "Developer ID Application" certificate (`MACOS_APPLICATION_CERTIFICATE` and `MACOS_APPLICATION_PASSWORD`): then it is signed with it and the hardened runtime. Without that certificate the package is not notarized, as notarization refuses code that is signed ad hoc. It runs beside the npm publish and does not
|
|
79
|
+
[`.github/workflows/macos-installer.yml`](../.github/workflows/macos-installer.yml) builds it on GitHub's macOS runner for each published release with `pkgbuild` and `productbuild`, and attaches it to the release. [`packaging/bundle-app.mjs`](../packaging/bundle-app.mjs) makes the app folder there: with the package's Node.js and its npm, it packs the release tag (with `npm-shrinkwrap.json`, as the npm release has it), installs that package globally into a new prefix without install scripts, and checks the version, the start script, the shrinkwrap, and that no dependency is for one platform only, so the one folder fits both kinds of Mac. With the "Developer ID Application" certificate, the build signs the native modules in it (Mach-O files) with the hardened runtime, as notarization needs. Pi Pocket.app is compiled there with `swiftc` for arm64 and x86_64, joined with `lipo`, and signed ad hoc, unless the `macos-signing` environment also has a "Developer ID Application" certificate (`MACOS_APPLICATION_CERTIFICATE` and `MACOS_APPLICATION_PASSWORD`): then it is signed with it and the hardened runtime. Without that certificate the package is not notarized, as notarization refuses code that is signed ad hoc. It runs beside the npm publish and does not need it. Only a release build is signed, and only when the `macos-signing` environment has the "Developer ID Installer" certificate that the workflow names; with the notary secrets too, it is notarized and stapled. Limit that environment to `v*` tags and give it a reviewer.
|
|
78
80
|
|
|
79
|
-
[`.github/workflows/macos.yml`](../.github/workflows/macos.yml) runs on each pull request, on Apple silicon and on Intel: it builds the package with
|
|
81
|
+
[`.github/workflows/macos.yml`](../.github/workflows/macos.yml) runs on each pull request, on Apple silicon and on Intel: it builds the package with the package of the pull request, blocks npm's registry (its names in `/etc/hosts`, and an `NPM_CONFIG_REGISTRY` that refuses), installs it without `sudo`, starts the console launcher, checks that it answers HTTP and that the sign-in link works, and uninstalls it while it runs. Then it installs it again with the sign-in item and opens Pi Pocket.app: it checks that no Terminal opens, that the window signed in with a one-time link, that a second start opens the first, and that **Quit** stops everything. With an older version in the package's `package.json`, the app must show its alert and start nothing, and an install must put its own `pi-pocket` back; with a newer one, an install must keep it. It starts the sign-in item, installs over the running Pi Pocket (which keeps the sign-in item), and uninstalls it with the data. It also runs `npm run check` and the test suite, without the tests that do not pass on macOS yet. The workflow skips them by name, and `test/pip-board-ui.test.ts` as a whole:
|
|
80
82
|
|
|
81
83
|
- Tests that press Ctrl or Alt for a shortcut. On a Mac the app takes ⌘ and Option instead (`APPLE` in `web/ui.js`), so the shortcut does not come. The PiP board tests stop at their first Alt+A, and each later test in that file needs the page that it left.
|
|
82
84
|
- Time limits and animations: the performance limits of the design lint and the RSS parser, the stall limits of helpers, and the glide of new rows. The macOS runner is slower than these limits allow.
|
package/docs/map.md
CHANGED
|
@@ -106,6 +106,7 @@ A module split into parts keeps its name for the part others import, with the re
|
|
|
106
106
|
| `extension-sessions.ts` | Ordinary sessions an extension starts (`ExtensionSessions`, `host.sessions` as `SessionsApi` in `host.ts`): a top-level session, like New session, for the person Pi works for in the source, with its model and thinking written in that same commit and its first message sent once; the call's record is an item of `LinkedSessionCallsDoc`, written in the commit that makes the session (since 0.28.0) |
|
|
107
107
|
| `entry-presentation.ts` | How a module asks the transcript to show an input it sends (`web.presentEntry`): one line that opens to the text, live while the module is on; nothing is stored (since 0.28.0) |
|
|
108
108
|
| `extension-pi-ai-compat.ts` | The `@earendil-works/pi-ai` that drop-ins get: pi-ai plus TypeBox's `Type` and a `StringEnum`, which pi-ai's main entry dropped in Pi 1.5 (since 0.28.0) |
|
|
109
|
+
| `dropin-config.ts` | The drop-in folder's `tsconfig.json`: `paths` to the types of Pi Pocket's packages, for editors where no `node_modules` link can be made (drop-ins import those packages without one: `extension-document-imports.ts` resolves them from Pi Pocket's own) |
|
|
109
110
|
| `linked-sessions.ts` | Linked sessions (`LinkedSessions`, `host.linkedSessions` as `LinkedSessionsApi` in `host.ts`): starting a session from another and sending its first message, with a record of the call that makes a repeat find the first; the addresses each session knows its linked ones by; messages between them, sent once, as the person Pi works for, through `Commands.submit`; stopping a run and archiving a session of the team (`stop`, `archive`, since 0.28.0); and a team's bounds (one level; since 0.19.0, no count of sessions or messages) |
|
|
110
111
|
|
|
111
112
|
### Workspace providers
|
|
@@ -209,7 +210,7 @@ The agent's side of Design mode. `extensions/design.ts` installs it (see Extensi
|
|
|
209
210
|
| `updates.ts`, `update-state.ts`, `npm-install.ts`, `npm-update.ts` | Updates of Pi Pocket itself (`app.updates`, `host.updates`): how the copy was installed (`installKind`), the newest version (the registry's `latest` for npm, and `beta` too with the beta channel on; GitHub for the notes and for a git checkout; `versions.ts`'s `compareReleases` orders pre-releases for it), what stands in the way, packages installed beside the checkout or a package staged beside a global npm install, the move forward or the swap, the restart, and `recover`; `update-state.ts` keeps `.pocket-update/` and the copy kept for a swap back, and the launcher imports it to go back; `npm-install.ts` tells how the copy was installed and whether npm's folders can be written, and `npm-update.ts` stages a version beside a global install |
|
|
210
211
|
| `versions.ts` | Pi Pocket's versions compared, for gallery entries' and themes' `minPocket` (a pre-release counts as its release), and `compareReleases`, which orders pre-releases for updates |
|
|
211
212
|
|
|
212
|
-
Outside `src/`: `flake.nix` and `nix/` build Pi Pocket with Nix (`nix/package.nix`) and run it as a NixOS service (`nix/module.nix`, with `nix/manage-extensions.sh` to copy declared drop-ins). `nix/tests/` runs only under Nix; `npm test` skips it. The container build is `docker/Dockerfile` and `docker/entrypoint.sh` (with `.dockerignore` for the build context), `docker-compose.yml` runs it, and `.env.example` lists the host-side variables for Compose; [docker.md](docker.md) explains them. `packaging/windows/` is the Windows installer (`pi-pocket.iss` for Inno Setup, `build.ps1`, the desktop app `PiPocket.cs` with its manifest, the `pi-pocket.cmd` start script, `stop-pi-pocket.ps1
|
|
213
|
+
Outside `src/`: `flake.nix` and `nix/` build Pi Pocket with Nix (`nix/package.nix`) and run it as a NixOS service (`nix/module.nix`, with `nix/manage-extensions.sh` to copy declared drop-ins). `nix/tests/` runs only under Nix; `npm test` skips it. The container build is `docker/Dockerfile` and `docker/entrypoint.sh` (with `.dockerignore` for the build context), `docker-compose.yml` runs it, and `.env.example` lists the host-side variables for Compose; [docker.md](docker.md) explains them. `packaging/windows/` is the Windows installer (`pi-pocket.iss` for Inno Setup, `build.ps1`, the desktop app `PiPocket.cs` with its manifest, the `pi-pocket.cmd` start script, and `stop-pi-pocket.ps1`); `.github/workflows/windows-installer.yml` builds it for each release and `windows.yml` tests it, and [windows.md](windows.md) explains it. `packaging/macos/` is the macOS package (`build.sh` for `pkgbuild` and `productbuild`, `distribution.xml`, the package scripts in `scripts/`, the desktop app `app/main.swift`, the `pi-pocket` launcher and its `.command` file for Terminal, `place-app.mjs`, which puts the package in place during the install, `uninstall.sh`, and `login-item.sh`); `.github/workflows/macos-installer.yml` builds it for each release and `macos.yml` tests it, and [macos.md](macos.md) explains it. `packaging/bundle-app.mjs` makes the app folder that both installers hold: the package of a checkout with its dependencies, so no install needs npm (`test/packaging-app.test.ts` tests it and `place-app.mjs`). [desktop-app.md](desktop-app.md) explains the two desktop apps.
|
|
213
214
|
|
|
214
215
|
## Extensions: `src/server/extensions/`
|
|
215
216
|
|
package/docs/windows.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Each release has `Pi-Pocket-Setup-<version>.exe` on its [GitHub release page](https://github.com/TannerMidd/pi-pocket/releases), with a `.sha256` file beside it. It installs Pi Pocket for your Windows account, with no admin rights and no Node.js of your own. Windows 10 (1809) or newer on x64, or Windows 11 on Arm through x64 emulation.
|
|
4
4
|
|
|
5
|
-
The installer
|
|
5
|
+
The installer holds everything: Node.js, the `pi-pocket` package of its release with its dependencies, and the desktop app. Setup needs no internet and no npm, so it works behind a company proxy or firewall that blocks npm, and as soon as the release is out, before npm has it.
|
|
6
6
|
|
|
7
7
|
## SmartScreen
|
|
8
8
|
|
|
@@ -16,16 +16,16 @@ Get-FileHash .\Pi-Pocket-Setup-0.29.0.exe -Algorithm SHA256
|
|
|
16
16
|
|
|
17
17
|
Everything goes in `%LOCALAPPDATA%\Pi Pocket` (`C:\Users\<you>\AppData\Local\Pi Pocket`):
|
|
18
18
|
|
|
19
|
-
| Folder or file
|
|
20
|
-
|
|
|
21
|
-
| `node\`
|
|
22
|
-
| `app\`
|
|
23
|
-
| `Pi Pocket.exe`
|
|
24
|
-
| `pi-pocket.cmd`
|
|
25
|
-
| `stop-pi-pocket.ps1`
|
|
26
|
-
| `Edge profile\`
|
|
27
|
-
| `launcher.log`
|
|
28
|
-
| `npm-cache
|
|
19
|
+
| Folder or file | What it is |
|
|
20
|
+
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
21
|
+
| `node\` | A portable Node.js LTS, the official `win-x64` zip. The build checks its SHA256 against the value pinned in [`packaging/windows/build.ps1`](../packaging/windows/build.ps1). |
|
|
22
|
+
| `app\` | A private npm prefix that holds the `pi-pocket` package. It is yours, so updates from the app work. The installer's build made it with npm, as `npm install --global` does. |
|
|
23
|
+
| `Pi Pocket.exe` | The desktop app ([desktop-app.md](desktop-app.md)): the icon in the notification area and the window. Setup's build compiles it from `PiPocket.cs`. |
|
|
24
|
+
| `pi-pocket.cmd` | Starts the launcher with that Node.js and prefix, in a console. Arguments go to `pi-pocket` (`pi-pocket.cmd --help`). |
|
|
25
|
+
| `stop-pi-pocket.ps1` | What stops a running Pi Pocket for Setup and the uninstaller: the app, its launcher and server with the agents' commands, the window's Edge, and the tunnel. |
|
|
26
|
+
| `Edge profile\` | The Edge profile of the app's window, with its sign-in cookie. |
|
|
27
|
+
| `launcher.log` | What the app's launcher and server print, and `launcher.old.log` from the run before. It has no sign-in link. |
|
|
28
|
+
| `npm-cache\` | npm's cache, for in-app updates. |
|
|
29
29
|
|
|
30
30
|
Setup always uses its own Node.js, also when you have one: an update of your Node.js, or its removal, does not break Pi Pocket, and in-app updates always have a prefix that they can write. Your own Node.js and npm are not changed.
|
|
31
31
|
|
|
@@ -48,9 +48,15 @@ Background tasks (Pi's `background` tool) work on Windows since 0.30.0, with Git
|
|
|
48
48
|
- The task's first process holds a handle to its job, so a restarted server finds the job again while that process runs. Once it ended, a restarted server knows the processes found before the restart, and what they start directly; a process started through Git Bash (which starts a program as a new process) is then not followed.
|
|
49
49
|
- A PowerShell in Constrained Language mode (a locked-down machine) cannot load the helper: then background tasks do not start, and say why.
|
|
50
50
|
|
|
51
|
+
## Machines that block links
|
|
52
|
+
|
|
53
|
+
Some enterprise policies refuse links and junctions. Drop-in extensions work there too: Pi Pocket resolves the packages that they import (`@earendil-works/pi-mcp`, `preact`, and the rest) from its own packages, with no link. The drop-in folder then has no `node_modules` junction, and the server log says once why. `_pocket.d.ts` is a copy of the types file, and the folder's `tsconfig.json` gives an editor the packages' types. See [extensions/modules.md](extensions/modules.md) and [extensions/reference/types.md](extensions/reference/types.md).
|
|
54
|
+
|
|
51
55
|
## Updates
|
|
52
56
|
|
|
53
|
-
Menu → **Update Pi Pocket** updates the package in `app\`, as for any global npm install, and restarts. The Node.js in `node\` stays the one that Setup installed. A newer installer brings a newer Node.js; run it over the old install. It stops a running Pi Pocket first (it asks), and it keeps a newer package that the app already updated to.
|
|
57
|
+
Menu → **Update Pi Pocket** updates the package in `app\`, as for any global npm install, and restarts; it needs npm's registry. The Node.js in `node\` stays the one that Setup installed. A newer installer brings a newer Node.js and its own package; run it over the old install. It stops a running Pi Pocket first (it asks), and it keeps a newer package that the app already updated to.
|
|
58
|
+
|
|
59
|
+
The desktop app checks the package before it starts it: when `app\` holds an older `pi-pocket` than the app itself (an install that did not finish), it says so in a message and starts nothing. Run the same Setup again to put its package back.
|
|
54
60
|
|
|
55
61
|
## Uninstall
|
|
56
62
|
|
|
@@ -62,12 +68,12 @@ Settings → Apps → Installed apps → **Pi Pocket** → Uninstall. It quits t
|
|
|
62
68
|
.\Pi-Pocket-Setup-0.29.0.exe /VERYSILENT /SUPPRESSMSGBOXES /NORESTART /TASKS=startup
|
|
63
69
|
```
|
|
64
70
|
|
|
65
|
-
Leave out `/TASKS=startup` for no sign-in shortcut.
|
|
71
|
+
Leave out `/TASKS=startup` for no sign-in shortcut.
|
|
66
72
|
|
|
67
73
|
## How it is built
|
|
68
74
|
|
|
69
|
-
[`.github/workflows/windows-installer.yml`](../.github/workflows/windows-installer.yml) builds it on GitHub's Windows runner for each published release, with Inno Setup (its installer checked against a pinned SHA256 too), and attaches it to the release. `Pi Pocket.exe` is compiled with the C# compiler of the .NET Framework 4.x in Windows itself (`csc.exe`), so it needs no download. It runs beside the npm publish and does not
|
|
75
|
+
[`.github/workflows/windows-installer.yml`](../.github/workflows/windows-installer.yml) builds it on GitHub's Windows runner for each published release, with Inno Setup (its installer checked against a pinned SHA256 too), and attaches it to the release. [`packaging/bundle-app.mjs`](../packaging/bundle-app.mjs) makes `app\` there: with the pinned Node.js and its npm, it packs the release tag (with `npm-shrinkwrap.json`, as the npm release has it), installs that package globally into a new prefix without install scripts, and checks the version, the start script, the shrinkwrap, and that no dependency is for one platform only. `Pi Pocket.exe` is compiled with the C# compiler of the .NET Framework 4.x in Windows itself (`csc.exe`), so it needs no download. It runs beside the npm publish and does not need it. Only a release build is signed, and only when the `windows-signing` environment has the signing secrets that the workflow names; limit that environment to `v*` tags and give it a reviewer.
|
|
70
76
|
|
|
71
|
-
[`.github/workflows/windows.yml`](../.github/workflows/windows.yml) runs on each pull request: it builds the installer with
|
|
77
|
+
[`.github/workflows/windows.yml`](../.github/workflows/windows.yml) runs on each pull request: it builds the installer with the package of the pull request, blocks npm's registry (its names in `hosts`, and an `NPM_CONFIG_REGISTRY` that refuses), installs it silently, starts the console launcher, checks that it answers HTTP and that the sign-in link works, and stops it. Then it opens the app from its Start menu entry, and checks that no console window shows, that Edge's window signed in with a one-time link, that a second start opens the first, and that **Quit** stops everything. With an older version in the package's `package.json`, the app must show its message and start nothing, and Setup must put its own package back; with a newer one, Setup must keep it. It starts the app as the Startup shortcut does, and uninstalls it while it runs. It also runs `npm run check` and the part of the test suite that passes on Windows.
|
|
72
78
|
|
|
73
79
|
Windows is still the least tested platform. The browser tests and most of the test suite do not run on Windows yet, and the app has been tried only on GitHub's runners, not yet on a PC of its own.
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-pocket",
|
|
3
|
-
"version": "0.30.0-beta.
|
|
3
|
+
"version": "0.30.0-beta.3",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pi-pocket",
|
|
9
|
-
"version": "0.30.0-beta.
|
|
9
|
+
"version": "0.30.0-beta.3",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@earendil-works/chord": "1.6.0",
|
package/package.json
CHANGED
package/src/server/app.ts
CHANGED
|
@@ -124,6 +124,7 @@ import { measureModelStreams } from "./timing.ts";
|
|
|
124
124
|
import { Providers } from "./providers.ts";
|
|
125
125
|
import { CustomProviders } from "./custom-providers.ts";
|
|
126
126
|
import { type EmbedderMessage, PushStore } from "./push.ts";
|
|
127
|
+
import { writeDropInConfig } from "./dropin-config.ts";
|
|
127
128
|
import { type ExtensionInfo, ExtensionLoader, linkTypes, prepareDropInFolder } from "./reload.ts";
|
|
128
129
|
import { ResendTask } from "./resend.ts";
|
|
129
130
|
import {
|
|
@@ -969,20 +970,29 @@ export class PocketApp {
|
|
|
969
970
|
|
|
970
971
|
this.#registry = registry;
|
|
971
972
|
const dropIn = join(this.dataDir, "extensions");
|
|
973
|
+
const packageModules = Object.fromEntries(
|
|
974
|
+
Object.keys(pocketPackage.dependencies ?? {}).map((name) => [name, modulesWith(name)]),
|
|
975
|
+
);
|
|
972
976
|
|
|
973
977
|
try {
|
|
974
|
-
prepareDropInFolder(
|
|
978
|
+
const refused = prepareDropInFolder(
|
|
975
979
|
dropIn,
|
|
976
980
|
modulesWith("@earendil-works/pi-durable"),
|
|
977
|
-
|
|
978
|
-
Object.keys(pocketPackage.dependencies ?? {}).map((name) => [
|
|
979
|
-
name,
|
|
980
|
-
modulesWith(name),
|
|
981
|
-
]),
|
|
982
|
-
),
|
|
981
|
+
packageModules,
|
|
983
982
|
);
|
|
983
|
+
|
|
984
|
+
// Drop-ins import Pi Pocket's packages without the link: only tools that read the folder miss it.
|
|
985
|
+
if (refused !== undefined) {
|
|
986
|
+
this.#log(`The drop-in folder has no node_modules link: ${describe(refused)}`);
|
|
987
|
+
}
|
|
988
|
+
} catch (error) {
|
|
989
|
+
this.#log(`The drop-in folder cannot be made: ${describe(error)}`);
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
try {
|
|
993
|
+
writeDropInConfig(dropIn, packageModules);
|
|
984
994
|
} catch (error) {
|
|
985
|
-
this.#log(`
|
|
995
|
+
this.#log(`The drop-in folder has no tsconfig.json: ${describe(error)}`);
|
|
986
996
|
}
|
|
987
997
|
|
|
988
998
|
try {
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `tsconfig.json` that Pi Pocket keeps in the drop-in folder, so an editor finds Pi Pocket's packages and their
|
|
3
|
+
* types there with no `node_modules` link: where a system refuses links, that link is missing.
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
|
|
8
|
+
/** The first line of a `tsconfig.json` Pi Pocket made: it refreshes only such a file, never the owner's own. */
|
|
9
|
+
export const CONFIG_MARK =
|
|
10
|
+
"// Pi Pocket made this file so editors find its packages: it refreshes it at each start. Edits here are lost.\n";
|
|
11
|
+
|
|
12
|
+
/** Conditions that lead to a package's types, in the order TypeScript reads them for an `import`. */
|
|
13
|
+
const CONDITIONS = ["types", "import", "node", "default"];
|
|
14
|
+
|
|
15
|
+
/** The types file an `exports` entry leads to, as a path in the package, or undefined when it has none. */
|
|
16
|
+
function typesOf(entry: unknown, folder: string): string | undefined {
|
|
17
|
+
if (typeof entry === "string") {
|
|
18
|
+
if (/\.d\.[cm]?ts$/.test(entry)) {
|
|
19
|
+
return entry;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const declared = entry.replace(/\.([cm]?)js$/, ".d.$1ts");
|
|
23
|
+
|
|
24
|
+
return declared !== entry && (entry.includes("*") || existsSync(join(folder, declared)))
|
|
25
|
+
? declared
|
|
26
|
+
: undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (Array.isArray(entry)) {
|
|
30
|
+
return entry.map((each) => typesOf(each, folder)).find((each) => each !== undefined);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (entry !== null && typeof entry === "object") {
|
|
34
|
+
const conditions = entry as Record<string, unknown>;
|
|
35
|
+
|
|
36
|
+
for (const condition of CONDITIONS) {
|
|
37
|
+
const found =
|
|
38
|
+
condition in conditions ? typesOf(conditions[condition], folder) : undefined;
|
|
39
|
+
|
|
40
|
+
if (found !== undefined) {
|
|
41
|
+
return found;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** `paths` entries for one package in `modules`: each of its exports leads to its types, as Node resolves it. */
|
|
50
|
+
function pathsOf(name: string, modules: string): [string, string[]][] {
|
|
51
|
+
const folder = join(modules, name);
|
|
52
|
+
let manifest: { exports?: unknown };
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
manifest = JSON.parse(
|
|
56
|
+
readFileSync(join(folder, "package.json"), "utf8"),
|
|
57
|
+
) as typeof manifest;
|
|
58
|
+
} catch {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const slashes = (path: string) => path.replaceAll("\\", "/");
|
|
63
|
+
const exports = manifest.exports;
|
|
64
|
+
|
|
65
|
+
if (exports === undefined || exports === null) {
|
|
66
|
+
return [
|
|
67
|
+
[name, [slashes(folder)]],
|
|
68
|
+
[`${name}/*`, [slashes(join(folder, "*"))]],
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const subpaths =
|
|
73
|
+
typeof exports === "object" &&
|
|
74
|
+
!Array.isArray(exports) &&
|
|
75
|
+
Object.keys(exports).some((key) => key.startsWith("."))
|
|
76
|
+
? (exports as Record<string, unknown>)
|
|
77
|
+
: { ".": exports };
|
|
78
|
+
const paths: [string, string[]][] = [];
|
|
79
|
+
|
|
80
|
+
for (const [key, entry] of Object.entries(subpaths)) {
|
|
81
|
+
const types = typesOf(entry, folder);
|
|
82
|
+
|
|
83
|
+
if (types !== undefined && (key === "." || key.startsWith("./"))) {
|
|
84
|
+
paths.push([
|
|
85
|
+
key === "." ? name : `${name}/${key.slice(2)}`,
|
|
86
|
+
[slashes(join(folder, types))],
|
|
87
|
+
]);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return paths;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Write `tsconfig.json` in the drop-in folder: TypeScript's `paths` lead each of Pi Pocket's packages (`packageModules`
|
|
96
|
+
* says where each is) to its types, and `typeRoots` to Node's own. A file the owner made stays as it is; Pi Pocket's
|
|
97
|
+
* own is written again when its folders change (an update moves them).
|
|
98
|
+
*/
|
|
99
|
+
export function writeDropInConfig(
|
|
100
|
+
directory: string,
|
|
101
|
+
packageModules: Readonly<Record<string, string>>,
|
|
102
|
+
): void {
|
|
103
|
+
const file = join(directory, "tsconfig.json");
|
|
104
|
+
let current: string | undefined;
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
current = readFileSync(file, "utf8");
|
|
108
|
+
} catch {
|
|
109
|
+
// Missing: written below.
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (current !== undefined && !current.startsWith(CONFIG_MARK)) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const paths = Object.fromEntries(
|
|
117
|
+
Object.entries(packageModules).flatMap(([name, modules]) => pathsOf(name, modules)),
|
|
118
|
+
);
|
|
119
|
+
const typeRoots = [...new Set(Object.values(packageModules))]
|
|
120
|
+
.map((modules) => join(modules, "@types"))
|
|
121
|
+
.filter((folder) => existsSync(join(folder, "node")))
|
|
122
|
+
.map((folder) => folder.replaceAll("\\", "/"));
|
|
123
|
+
const config = {
|
|
124
|
+
compilerOptions: {
|
|
125
|
+
target: "esnext",
|
|
126
|
+
// Not `nodenext`: with no `package.json` of type module here, it reads each drop-in as CommonJS, where
|
|
127
|
+
// `import.meta` and top-level `await` are errors. Node runs them as ES modules.
|
|
128
|
+
module: "esnext",
|
|
129
|
+
moduleResolution: "bundler",
|
|
130
|
+
strict: true,
|
|
131
|
+
noEmit: true,
|
|
132
|
+
allowImportingTsExtensions: true,
|
|
133
|
+
skipLibCheck: true,
|
|
134
|
+
...(typeRoots.length === 0 ? {} : { typeRoots }),
|
|
135
|
+
paths,
|
|
136
|
+
},
|
|
137
|
+
exclude: ["node_modules", ".pocket-packages"],
|
|
138
|
+
};
|
|
139
|
+
const content = CONFIG_MARK + JSON.stringify(config, undefined, 4) + "\n";
|
|
140
|
+
|
|
141
|
+
if (content !== current) {
|
|
142
|
+
writeFileSync(file, content);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Native drop-in imports retain the pre-1.4 document checkpoint default without changing Pi Durable itself, and get
|
|
3
|
-
* TypeBox's `Type` from `@earendil-works/pi-ai` as before Pi 1.5.
|
|
3
|
+
* TypeBox's `Type` from `@earendil-works/pi-ai` as before Pi 1.5. A package a drop-in does not have of its own comes
|
|
4
|
+
* from Pi Pocket's, with no `node_modules` link.
|
|
4
5
|
*/
|
|
5
|
-
import { registerHooks } from "node:module";
|
|
6
|
+
import { createRequire, registerHooks } from "node:module";
|
|
6
7
|
import { sep } from "node:path";
|
|
7
8
|
import { pathToFileURL } from "node:url";
|
|
8
9
|
|
|
9
10
|
const compatUrl = new URL("./extension-document-compat.ts", import.meta.url).href;
|
|
10
11
|
const piAiUrl = new URL("./extension-pi-ai-compat.ts", import.meta.url).href;
|
|
12
|
+
/** Pi Pocket's own package root: a package resolved from here is the very one the server runs. */
|
|
13
|
+
const appUrl = new URL("../../package.json", import.meta.url).href;
|
|
14
|
+
const appRequire = createRequire(appUrl);
|
|
15
|
+
|
|
16
|
+
/** What Node throws for a package it does not find, from `import` and from `require`. */
|
|
17
|
+
const NOT_FOUND = new Set(["ERR_MODULE_NOT_FOUND", "MODULE_NOT_FOUND"]);
|
|
18
|
+
|
|
19
|
+
/** A package name, not a path or a URL: `preact`, `@earendil-works/pi-mcp/oauth`. */
|
|
20
|
+
function isBare(specifier: string): boolean {
|
|
21
|
+
return !/^(\.{0,2}\/|[a-zA-Z][a-zA-Z\d+.-]*:|#|\\)/.test(specifier);
|
|
22
|
+
}
|
|
11
23
|
|
|
12
24
|
type Scope = { directory: string; report: (message: string) => void; warned: Set<string> };
|
|
13
25
|
type Owner = { scope: Scope; module: string; root: string };
|
|
@@ -59,7 +71,31 @@ export function documentImports(directory: string, report: (message: string) =>
|
|
|
59
71
|
return { url: piAiUrl, shortCircuit: true };
|
|
60
72
|
}
|
|
61
73
|
|
|
62
|
-
|
|
74
|
+
let resolved: ReturnType<typeof nextResolve>;
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
resolved = nextResolve(specifier, context);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
// Where links are blocked, the drop-in folder has no `node_modules` link to Pi Pocket's packages:
|
|
80
|
+
// resolve as Pi Pocket itself does. A package the drop-in has of its own resolved above.
|
|
81
|
+
if (
|
|
82
|
+
parent === undefined ||
|
|
83
|
+
!isBare(specifier) ||
|
|
84
|
+
!NOT_FOUND.has((error as NodeJS.ErrnoException).code ?? "")
|
|
85
|
+
) {
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
// `require` ignores another `parentURL`: Pi Pocket's own `require` finds it instead.
|
|
91
|
+
return (error as NodeJS.ErrnoException).code === "MODULE_NOT_FOUND"
|
|
92
|
+
? { url: pathToFileURL(appRequire.resolve(specifier)).href }
|
|
93
|
+
: nextResolve(specifier, { ...context, parentURL: appUrl });
|
|
94
|
+
} catch {
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
63
99
|
// Node resolves symlinks before the next parentURL. Follow only imports inside extension source
|
|
64
100
|
// trees, not arbitrary shared dependencies: a shared helper can also run on behalf of core.
|
|
65
101
|
const requestedUrl = specifier.startsWith("file:")
|
package/src/server/reload.ts
CHANGED
|
@@ -212,21 +212,31 @@ function moduleFiles(directory: string): string[] {
|
|
|
212
212
|
}
|
|
213
213
|
|
|
214
214
|
/**
|
|
215
|
-
* Make the drop-in folder, with a `node_modules` link to Pi Pocket's own packages. Drop-ins
|
|
216
|
-
*
|
|
217
|
-
* `node_modules` folder the owner made there stays as it is; a link to another place is replaced. Where npm
|
|
218
|
-
* Pocket's packages between folders (a local install beside other versions of them), `packageModules` says
|
|
219
|
-
* is, and the link leads to a hidden folder with a link to each one instead.
|
|
215
|
+
* Make the drop-in folder, with a `node_modules` link to Pi Pocket's own packages for editors and other tools. Drop-ins
|
|
216
|
+
* import Pi Pocket's packages without it too (`documentImports` resolves them), and get the very modules the server
|
|
217
|
+
* runs. A `node_modules` folder the owner made there stays as it is; a link to another place is replaced. Where npm
|
|
218
|
+
* split Pi Pocket's packages between folders (a local install beside other versions of them), `packageModules` says
|
|
219
|
+
* where each is, and the link leads to a hidden folder with a link to each one instead. A link the system refuses (an
|
|
220
|
+
* enterprise policy, say) is left out: the first such error comes back, for one line in the log.
|
|
220
221
|
*/
|
|
221
222
|
export function prepareDropInFolder(
|
|
222
223
|
directory: string,
|
|
223
224
|
appModules: string,
|
|
224
225
|
packageModules: Readonly<Record<string, string>> = {},
|
|
225
|
-
):
|
|
226
|
+
): unknown {
|
|
226
227
|
mkdirSync(directory, { recursive: true });
|
|
227
228
|
// A junction on Windows: no administrator rights needed.
|
|
228
229
|
const type = process.platform === "win32" ? "junction" : "dir";
|
|
229
230
|
let target = appModules;
|
|
231
|
+
let failure: unknown;
|
|
232
|
+
|
|
233
|
+
const link = (path: string, to: string) => {
|
|
234
|
+
try {
|
|
235
|
+
keepLink(path, to, type);
|
|
236
|
+
} catch (error) {
|
|
237
|
+
failure ??= error;
|
|
238
|
+
}
|
|
239
|
+
};
|
|
230
240
|
|
|
231
241
|
// All in one folder, as in a checkout and most installs: one link to it, as before.
|
|
232
242
|
if (Object.values(packageModules).some((modules) => modules !== appModules)) {
|
|
@@ -234,16 +244,16 @@ export function prepareDropInFolder(
|
|
|
234
244
|
mkdirSync(target, { recursive: true });
|
|
235
245
|
|
|
236
246
|
for (const [name, modules] of Object.entries(packageModules)) {
|
|
237
|
-
const link = join(target, name);
|
|
238
|
-
|
|
239
247
|
if (existsSync(join(modules, name))) {
|
|
240
|
-
mkdirSync(dirname(
|
|
241
|
-
|
|
248
|
+
mkdirSync(dirname(join(target, name)), { recursive: true });
|
|
249
|
+
link(join(target, name), join(modules, name));
|
|
242
250
|
}
|
|
243
251
|
}
|
|
244
252
|
}
|
|
245
253
|
|
|
246
|
-
|
|
254
|
+
link(join(directory, "node_modules"), target);
|
|
255
|
+
|
|
256
|
+
return failure;
|
|
247
257
|
}
|
|
248
258
|
|
|
249
259
|
/** The first line of a copy of the types that Pi Pocket made where it cannot link: it refreshes only such a copy. */
|
|
@@ -254,8 +264,8 @@ const TYPES_COPY =
|
|
|
254
264
|
* Link `_pocket.d.ts` in the drop-in folder to Pi Pocket's public types (`types/pocket.d.ts`), so a drop-in imports them
|
|
255
265
|
* from beside it on any machine. Its leading `_` keeps it from loading as a module. A link that leads to a file that can
|
|
256
266
|
* be read stays as it is, wherever it leads (the owner's own checkout, say); a link to nowhere is made again. A file the
|
|
257
|
-
* owner made stays as it is. Where links cannot be made (Windows, or a
|
|
258
|
-
*
|
|
267
|
+
* owner made stays as it is. Where links cannot be made (Windows, or a system that refuses them), it is a copy
|
|
268
|
+
* instead, refreshed when the types change.
|
|
259
269
|
*/
|
|
260
270
|
export function linkTypes(directory: string, types: string): void {
|
|
261
271
|
const link = join(directory, "_pocket.d.ts");
|
|
@@ -292,10 +302,8 @@ export function linkTypes(directory: string, types: string): void {
|
|
|
292
302
|
symlinkSync(types, link, "file");
|
|
293
303
|
|
|
294
304
|
return;
|
|
295
|
-
} catch
|
|
296
|
-
|
|
297
|
-
throw error;
|
|
298
|
-
}
|
|
305
|
+
} catch {
|
|
306
|
+
// Refused (`EPERM`, `EACCES`, a policy): a copy instead, below.
|
|
299
307
|
}
|
|
300
308
|
}
|
|
301
309
|
|