@polyweave/preston 0.0.0-stage → 1.1.0
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/LICENSE +21 -0
- package/README.md +119 -2
- package/assets/logo.png +0 -0
- package/assets/logo.webp +0 -0
- package/dist/agents/migration.js +29 -0
- package/dist/agents/migration.js.map +1 -0
- package/dist/agents/updater.js +385 -0
- package/dist/agents/updater.js.map +1 -0
- package/dist/channels/chat.js +236 -0
- package/dist/channels/chat.js.map +1 -0
- package/dist/channels/discord/index.js +491 -0
- package/dist/channels/discord/index.js.map +1 -0
- package/dist/channels/discord/transport.js +130 -0
- package/dist/channels/discord/transport.js.map +1 -0
- package/dist/channels/fake/index.js +104 -0
- package/dist/channels/fake/index.js.map +1 -0
- package/dist/channels/hub.js +153 -0
- package/dist/channels/hub.js.map +1 -0
- package/dist/channels/outbox.js +219 -0
- package/dist/channels/outbox.js.map +1 -0
- package/dist/channels/registry.js +67 -0
- package/dist/channels/registry.js.map +1 -0
- package/dist/channels/router.js +50 -0
- package/dist/channels/router.js.map +1 -0
- package/dist/channels/shared/delivery.js +74 -0
- package/dist/channels/shared/delivery.js.map +1 -0
- package/dist/channels/shared/files.js +87 -0
- package/dist/channels/shared/files.js.map +1 -0
- package/dist/channels/shared/pairing.js +99 -0
- package/dist/channels/shared/pairing.js.map +1 -0
- package/dist/channels/shared/secrets.js +75 -0
- package/dist/channels/shared/secrets.js.map +1 -0
- package/dist/channels/shared/text.js +68 -0
- package/dist/channels/shared/text.js.map +1 -0
- package/dist/channels/shared/typing.js +59 -0
- package/dist/channels/shared/typing.js.map +1 -0
- package/dist/channels/slack/index.js +560 -0
- package/dist/channels/slack/index.js.map +1 -0
- package/dist/channels/slack/transport.js +184 -0
- package/dist/channels/slack/transport.js.map +1 -0
- package/dist/channels/terminal.js +67 -0
- package/dist/channels/terminal.js.map +1 -0
- package/dist/channels/types.js +6 -0
- package/dist/channels/types.js.map +1 -0
- package/dist/cli-args.js +92 -0
- package/dist/cli-args.js.map +1 -0
- package/dist/cli.js +120 -0
- package/dist/cli.js.map +1 -0
- package/dist/clock.js +76 -0
- package/dist/clock.js.map +1 -0
- package/dist/config/config.js +184 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/schema.js +209 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/coordinator/coordinator.js +494 -0
- package/dist/coordinator/coordinator.js.map +1 -0
- package/dist/coordinator/inbox.js +64 -0
- package/dist/coordinator/inbox.js.map +1 -0
- package/dist/coordinator/input.js +75 -0
- package/dist/coordinator/input.js.map +1 -0
- package/dist/daemon/daemon.js +228 -0
- package/dist/daemon/daemon.js.map +1 -0
- package/dist/daemon/ensure.js +87 -0
- package/dist/daemon/ensure.js.map +1 -0
- package/dist/daemon/lock.js +54 -0
- package/dist/daemon/lock.js.map +1 -0
- package/dist/daemon/start-at-login.js +20 -0
- package/dist/daemon/start-at-login.js.map +1 -0
- package/dist/daemon/stop.js +51 -0
- package/dist/daemon/stop.js.map +1 -0
- package/dist/goals/agents.js +36 -0
- package/dist/goals/agents.js.map +1 -0
- package/dist/goals/brief.js +51 -0
- package/dist/goals/brief.js.map +1 -0
- package/dist/goals/checks.js +75 -0
- package/dist/goals/checks.js.map +1 -0
- package/dist/goals/engine.js +1253 -0
- package/dist/goals/engine.js.map +1 -0
- package/dist/goals/messages.js +110 -0
- package/dist/goals/messages.js.map +1 -0
- package/dist/goals/status.js +118 -0
- package/dist/goals/status.js.map +1 -0
- package/dist/goals/store.js +285 -0
- package/dist/goals/store.js.map +1 -0
- package/dist/home.js +52 -0
- package/dist/home.js.map +1 -0
- package/dist/i18n/index.js +37 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/ipc/client.js +82 -0
- package/dist/ipc/client.js.map +1 -0
- package/dist/ipc/private-dir.js +23 -0
- package/dist/ipc/private-dir.js.map +1 -0
- package/dist/ipc/protocol.js +50 -0
- package/dist/ipc/protocol.js.map +1 -0
- package/dist/ipc/server.js +110 -0
- package/dist/ipc/server.js.map +1 -0
- package/dist/landing/exec.js +38 -0
- package/dist/landing/exec.js.map +1 -0
- package/dist/landing/git.js +93 -0
- package/dist/landing/git.js.map +1 -0
- package/dist/landing/github.js +154 -0
- package/dist/landing/github.js.map +1 -0
- package/dist/landing/hooks.js +2 -0
- package/dist/landing/hooks.js.map +1 -0
- package/dist/landing/landing.js +777 -0
- package/dist/landing/landing.js.map +1 -0
- package/dist/landing/messages.js +157 -0
- package/dist/landing/messages.js.map +1 -0
- package/dist/landing/migration.js +50 -0
- package/dist/landing/migration.js.map +1 -0
- package/dist/landing/paths.js +54 -0
- package/dist/landing/paths.js.map +1 -0
- package/dist/landing/project.js +95 -0
- package/dist/landing/project.js.map +1 -0
- package/dist/landing/publishing.js +208 -0
- package/dist/landing/publishing.js.map +1 -0
- package/dist/landing/stage.js +129 -0
- package/dist/landing/stage.js.map +1 -0
- package/dist/landing/store.js +160 -0
- package/dist/landing/store.js.map +1 -0
- package/dist/landing/tools.js +38 -0
- package/dist/landing/tools.js.map +1 -0
- package/dist/landing/workspace.js +349 -0
- package/dist/landing/workspace.js.map +1 -0
- package/dist/log.js +77 -0
- package/dist/log.js.map +1 -0
- package/dist/mcp/coordinator-tools.js +500 -0
- package/dist/mcp/coordinator-tools.js.map +1 -0
- package/dist/mcp/names.js +8 -0
- package/dist/mcp/names.js.map +1 -0
- package/dist/mcp/owner-turn.js +15 -0
- package/dist/mcp/owner-turn.js.map +1 -0
- package/dist/mcp/setup-tools.js +243 -0
- package/dist/mcp/setup-tools.js.map +1 -0
- package/dist/mcp/stdio.js +74 -0
- package/dist/mcp/stdio.js.map +1 -0
- package/dist/mcp/tools.js +76 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/mcp/worker-tools.js +53 -0
- package/dist/mcp/worker-tools.js.map +1 -0
- package/dist/memory/files.js +183 -0
- package/dist/memory/files.js.map +1 -0
- package/dist/memory/index.js +174 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/service.js +319 -0
- package/dist/memory/service.js.map +1 -0
- package/dist/memory/tools.js +82 -0
- package/dist/memory/tools.js.map +1 -0
- package/dist/notify/index.js +122 -0
- package/dist/notify/index.js.map +1 -0
- package/dist/prompts/coordinator.js +76 -0
- package/dist/prompts/coordinator.js.map +1 -0
- package/dist/prompts/grilling.js +8 -0
- package/dist/prompts/grilling.js.map +1 -0
- package/dist/prompts/teaching.js +17 -0
- package/dist/prompts/teaching.js.map +1 -0
- package/dist/prompts/worker.js +50 -0
- package/dist/prompts/worker.js.map +1 -0
- package/dist/questions/questions.js +209 -0
- package/dist/questions/questions.js.map +1 -0
- package/dist/quota/monitor.js +399 -0
- package/dist/quota/monitor.js.map +1 -0
- package/dist/quota/schedule.js +38 -0
- package/dist/quota/schedule.js.map +1 -0
- package/dist/quota/store.js +94 -0
- package/dist/quota/store.js.map +1 -0
- package/dist/quota/time.js +41 -0
- package/dist/quota/time.js.map +1 -0
- package/dist/review/digest.js +202 -0
- package/dist/review/digest.js.map +1 -0
- package/dist/review/reviewer.js +113 -0
- package/dist/review/reviewer.js.map +1 -0
- package/dist/runtime.js +456 -0
- package/dist/runtime.js.map +1 -0
- package/dist/schedule/cron.js +354 -0
- package/dist/schedule/cron.js.map +1 -0
- package/dist/schedule/service.js +425 -0
- package/dist/schedule/service.js.map +1 -0
- package/dist/schedule/store.js +210 -0
- package/dist/schedule/store.js.map +1 -0
- package/dist/schedule/tools.js +246 -0
- package/dist/schedule/tools.js.map +1 -0
- package/dist/selfupdate/npm.js +114 -0
- package/dist/selfupdate/npm.js.map +1 -0
- package/dist/selfupdate/start.js +113 -0
- package/dist/selfupdate/start.js.map +1 -0
- package/dist/selfupdate/state.js +22 -0
- package/dist/selfupdate/state.js.map +1 -0
- package/dist/selfupdate/updater.js +120 -0
- package/dist/selfupdate/updater.js.map +1 -0
- package/dist/service/host.js +46 -0
- package/dist/service/host.js.map +1 -0
- package/dist/service/index.js +142 -0
- package/dist/service/index.js.map +1 -0
- package/dist/service/launchd.js +88 -0
- package/dist/service/launchd.js.map +1 -0
- package/dist/service/spec.js +9 -0
- package/dist/service/spec.js.map +1 -0
- package/dist/service/systemd.js +90 -0
- package/dist/service/systemd.js.map +1 -0
- package/dist/service/windows.js +122 -0
- package/dist/service/windows.js.map +1 -0
- package/dist/setup/pairing.js +143 -0
- package/dist/setup/pairing.js.map +1 -0
- package/dist/setup/setup.js +76 -0
- package/dist/setup/setup.js.map +1 -0
- package/dist/standing/defaults.js +80 -0
- package/dist/standing/defaults.js.map +1 -0
- package/dist/standing/model.js +72 -0
- package/dist/standing/model.js.map +1 -0
- package/dist/standing/service.js +228 -0
- package/dist/standing/service.js.map +1 -0
- package/dist/standing/tools.js +184 -0
- package/dist/standing/tools.js.map +1 -0
- package/dist/store/db.js +67 -0
- package/dist/store/db.js.map +1 -0
- package/dist/store/migrations.js +280 -0
- package/dist/store/migrations.js.map +1 -0
- package/dist/supervisor/processes.js +128 -0
- package/dist/supervisor/processes.js.map +1 -0
- package/dist/supervisor/stalls.js +103 -0
- package/dist/supervisor/stalls.js.map +1 -0
- package/dist/terminal/activity.js +97 -0
- package/dist/terminal/activity.js.map +1 -0
- package/dist/terminal/conversation.js +231 -0
- package/dist/terminal/conversation.js.map +1 -0
- package/dist/util/async-queue.js +41 -0
- package/dist/util/async-queue.js.map +1 -0
- package/dist/util/command.js +29 -0
- package/dist/util/command.js.map +1 -0
- package/dist/util/ids.js +9 -0
- package/dist/util/ids.js.map +1 -0
- package/dist/util/process-tree.js +62 -0
- package/dist/util/process-tree.js.map +1 -0
- package/dist/util/secrets.js +31 -0
- package/dist/util/secrets.js.map +1 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/dist/workers/claude/classify.js +172 -0
- package/dist/workers/claude/classify.js.map +1 -0
- package/dist/workers/claude/index.js +440 -0
- package/dist/workers/claude/index.js.map +1 -0
- package/dist/workers/claude/process.js +135 -0
- package/dist/workers/claude/process.js.map +1 -0
- package/dist/workers/claude/quota.js +37 -0
- package/dist/workers/claude/quota.js.map +1 -0
- package/dist/workers/claude/stream.js +286 -0
- package/dist/workers/claude/stream.js.map +1 -0
- package/dist/workers/codex/index.js +181 -0
- package/dist/workers/codex/index.js.map +1 -0
- package/dist/workers/codex/mapping.js +166 -0
- package/dist/workers/codex/mapping.js.map +1 -0
- package/dist/workers/codex/process.js +124 -0
- package/dist/workers/codex/process.js.map +1 -0
- package/dist/workers/codex/protocol.js +7 -0
- package/dist/workers/codex/protocol.js.map +1 -0
- package/dist/workers/codex/rpc.js +145 -0
- package/dist/workers/codex/rpc.js.map +1 -0
- package/dist/workers/codex/run.js +556 -0
- package/dist/workers/codex/run.js.map +1 -0
- package/dist/workers/env.js +49 -0
- package/dist/workers/env.js.map +1 -0
- package/dist/workers/fake/index.js +283 -0
- package/dist/workers/fake/index.js.map +1 -0
- package/dist/workers/models.js +171 -0
- package/dist/workers/models.js.map +1 -0
- package/dist/workers/registry.js +63 -0
- package/dist/workers/registry.js.map +1 -0
- package/dist/workers/types.js +6 -0
- package/dist/workers/types.js.map +1 -0
- package/package.json +66 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Polyweave
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,120 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center"><img src="assets/logo.png" alt="Preston" width="160"></p>
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# Preston
|
|
4
|
+
|
|
5
|
+
A self-hosted chief of staff for your coding agents. Give it a goal. Get a result.
|
|
6
|
+
|
|
7
|
+
Preston takes ownership of an outcome you describe in plain language, hands the work to the coding agent already on your computer (Claude Code or Codex), keeps it going through stalls, crashes and restarts, checks the result itself, and tells you briefly how it went: **Verified**, **Unverified** or **Blocked**. It asks you only for real product decisions or for authority beyond what you gave it.
|
|
8
|
+
|
|
9
|
+
You talk to Preston only through chat. There are no commands to learn.
|
|
10
|
+
|
|
11
|
+
## Requirements
|
|
12
|
+
|
|
13
|
+
- Node.js 22.13 or later, on macOS, Windows or Linux.
|
|
14
|
+
- [Claude Code](https://claude.com/claude-code) or [Codex](https://developers.openai.com/codex), installed and signed in.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm i -g @polyweave/preston
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Commands
|
|
23
|
+
|
|
24
|
+
There are only two: `preston` opens the conversation (and starts the background service if needed), and `preston stop` stops the background service. Work in progress is saved and picks up the next time Preston starts. `preston -h` shows the usage. If you work on Preston itself, `npm run build` keeps `dist/cli.js` executable, so an `npm link` keeps working after a rebuild.
|
|
25
|
+
|
|
26
|
+
## Updates
|
|
27
|
+
|
|
28
|
+
Preston keeps itself current. Each time you run `preston`, and every six hours in the background, it asks npm for a newer version. When there is one:
|
|
29
|
+
|
|
30
|
+
- `preston` installs it, restarts the background service and carries on with the new version.
|
|
31
|
+
- The background service installs it only while nothing is running (no Goal in progress), restarts itself, and tells you in chat.
|
|
32
|
+
|
|
33
|
+
It only updates a copy installed with `npm i -g`. A development checkout, a project install, `npx` or another package manager's copy is left alone, and Preston tells you the command to update by hand. If an install fails (usually npm's folder permissions), it explains why, keeps running the current version, and tries that version again after a day. Your Goals, settings and history carry over. To turn this off, tell Preston to set `selfUpdate.enabled` to false, or run `npm i -g @polyweave/preston@latest` yourself whenever you like.
|
|
34
|
+
|
|
35
|
+
## Run
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
preston
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The first time, Preston starts its background service, sets it to start by itself whenever you sign in to your computer, finds the coding agents installed, and asks which to use. Then it offers to connect a chat app, so you can talk to it away from this computer, and walks you through it step by step:
|
|
42
|
+
|
|
43
|
+
- **Discord**: you create your own Discord bot and paste its token. You need a Discord server to add the bot to; you can create one for free.
|
|
44
|
+
- **Slack**: Preston gives you a ready-made app manifest to paste into Slack's "Create an app" page, then asks for the two tokens Slack shows you.
|
|
45
|
+
|
|
46
|
+
If you have both Claude Code and Codex and let Preston use both, setup also asks which of them should do Preston's own thinking (understanding you and planning). Codex is offered first and is the default (just press Enter); choose Claude Code if you prefer it. You can change it later by telling Preston. Preston's own thinking is separate from the work itself, which is shared between the agents by quota.
|
|
47
|
+
|
|
48
|
+
Preston asks which language you want the first time you run it: English or Simplified Chinese (简体中文). Everything it says to you follows that choice, including the setup steps, and the words `状态`, `停止`, `暂停` and `继续` work like `status`, `stop`, `pause` and `resume`. To change it later, just tell Preston.
|
|
49
|
+
|
|
50
|
+
You can send Preston pictures, videos, GIFs and other files in Discord or Slack, and ask it to send files back (for example "send me hello.txt"). Files you send are saved under `~/.preston/attachments` and handed to a coding agent that can open them; Preston itself only reads the message and the file list. Preston can send any file on your computer when you ask, up to 25 MB on Discord and 100 MB on Slack; anything bigger it tells you the location of instead. Emoji and GIF links in your messages arrive as plain text.
|
|
51
|
+
|
|
52
|
+
Preston speaks with one voice: when you give it a Goal, it answers you itself, and when the Goal ends it tells you in its own words, in the language you write in, with any files attached. Tell it how you want to be reached ("I'm going to sleep, let's chat tomorrow morning") and it holds the messages until then. If Preston's own agent is unavailable when a Goal ends, a plain standard message is sent after three minutes instead, so you are never left without a result.
|
|
53
|
+
|
|
54
|
+
If you ask for something to be made (a picture, a document, a chart), Preston hands it to a coding agent and sends you the file with the result. What can be made is whatever your Claude Code or Codex can do on your computer: drawing with code and installed tools, or an image tool if your agent has one. Preston has no image model of its own.
|
|
55
|
+
|
|
56
|
+
Slack apps created before this feature need the `files:read` and `files:write` permissions added under "OAuth & Permissions", then a reinstall, or files will not work there.
|
|
57
|
+
|
|
58
|
+
While Preston is thinking, the terminal shows a spinner with a changing message, so you can tell it is working. During Discord or Slack setup it can also save its logo to your Downloads folder, ready to use as your app's picture.
|
|
59
|
+
|
|
60
|
+
Any of them, or none: the terminal always works. Each one is paired with your own account, and only you can give Preston instructions there.
|
|
61
|
+
|
|
62
|
+
After that, `preston` opens a conversation with Preston. Tell it what you want done. Press Ctrl+C to leave; Preston keeps working in the background. Run `preston` again to pick up where you left off, including anything left unfinished.
|
|
63
|
+
|
|
64
|
+
You can always type `status`, `stop`, `pause` or `resume`. Preston answers these straight away, even when its own agent has run out of quota. If Preston loses a chat connection, such as a revoked bot token, it shows a notification on your computer.
|
|
65
|
+
|
|
66
|
+
## Looking back and improving
|
|
67
|
+
|
|
68
|
+
About once a day, Preston looks back over the work it did: what failed or could not be checked, where a coding agent kept getting stuck, which checks failed, which questions you had to answer, and requests that came back. If something repeats, it sends you one short message with up to three suggestions, such as a standing order, a note to remember, a schedule or a better way of writing its instructions. Nothing changes until you agree in chat. A quiet day sends nothing. You can also ask "how did things go this week?" at any time. Each look back is kept as readable text in `~/.preston/reviews`. To turn it off, tell Preston to set `review.enabled` to false.
|
|
69
|
+
|
|
70
|
+
## What happens to the finished work
|
|
71
|
+
|
|
72
|
+
In a Git project, Preston gives each Goal its own separate working copy, so your own checkout, branch and unsaved edits are never touched and several Goals can run side by side. When the work is Verified it merges it for you: through a pull request on GitHub if the project has one and the GitHub tool (`gh`) is signed in (it waits for the project's required checks first), otherwise straight into your main branch on your computer. If your main branch is checked out and clean, it is brought up to date; if you are on another branch, Preston leaves you there and says so. If a merge would also publish something (deploy a site, release a build, publish a package), Preston asks you first; you can change that in chat. Work it could not check is left on its own branch, not merged. Files that look installed or built (such as `node_modules`) or are very large binaries are left out of the merge unless your project already tracks them, and Preston says so. A Goal that did not finish keeps its separate working copy for two weeks and then only its branch, never losing unsaved work; if you change your mind about work it held back, ask it to merge it. Folders that are not Git projects are worked on in place.
|
|
73
|
+
|
|
74
|
+
## Teach Preston by chatting: standing orders, schedules, memory
|
|
75
|
+
|
|
76
|
+
Everything below is done by telling Preston, not by editing files.
|
|
77
|
+
|
|
78
|
+
- **Standing orders** are lasting rules about how Preston works: "ask before spending anything", "in my website folder always check accessibility", "merge routine PRs without asking". Preston starts with a few sensible ones (own the objective, recover from routine problems itself, ask you only when it really needs you, prove results, keep messages short). Ask to see, change, switch off or roll back any of them, including those.
|
|
79
|
+
- **Schedules** make Preston do something later or on a repeat: "every weekday at 9 check the build", "on Friday at 4pm summarise the week". Each time, Preston starts a normal Goal. It can also run a plain check and speak up only when it fails. If your computer was asleep or off at the time, Preston catches up once when it is back (or skips, if you prefer); it can't run anything while the computer is asleep. Ask it to pause, resume, run now, or show what happened.
|
|
80
|
+
- **Memory** is what Preston remembers about you: preferences and facts you tell it ("I prefer short replies", "my staging site is..."). It is kept as readable text in `~/.preston/memory` that you can edit, and it never stores passwords or keys. Ask it to forget something and it does.
|
|
81
|
+
|
|
82
|
+
## Where Preston keeps things
|
|
83
|
+
|
|
84
|
+
All of Preston's state, config and logs live in `~/.preston` (or `$PRESTON_HOME`), never inside your projects. Its config file is readable only by you, and tokens are masked in its logs, which are in `~/.preston/logs`.
|
|
85
|
+
|
|
86
|
+
To start at login, Preston registers itself with your computer's own service manager, for your user only and without administrator rights:
|
|
87
|
+
|
|
88
|
+
- **macOS:** a LaunchAgent, `~/Library/LaunchAgents/ai.polyweave.preston.plist`.
|
|
89
|
+
- **Linux:** a systemd user service, `~/.config/systemd/user/preston.service`. Where systemd user services are unavailable (for example in WSL or a container), it uses `~/.config/autostart/preston.desktop` on a desktop; otherwise it tells you to run `preston` after you sign in.
|
|
90
|
+
- **Windows:** a scheduled task named `Preston` that runs when you sign in, or `Preston.cmd` in your Startup folder if scheduled tasks are not allowed.
|
|
91
|
+
|
|
92
|
+
A different `PRESTON_HOME` gets its own registration, named with a short suffix. After upgrading Node or reinstalling Preston, run `preston` once so the registration uses the new location.
|
|
93
|
+
|
|
94
|
+
## Stopping or removing Preston
|
|
95
|
+
|
|
96
|
+
To stop the background service and keep it from starting at login, remove its registration: on macOS run `launchctl bootout gui/$(id -u)/ai.polyweave.preston` and delete the plist; on Linux run `systemctl --user disable --now preston.service`; on Windows run `schtasks /Delete /TN Preston /F` (or delete `Preston.cmd` from the Startup folder) and end Preston's `node` process. Running `preston` again sets it up again. To remove Preston completely, also run `npm rm -g @polyweave/preston` and delete `~/.preston`.
|
|
97
|
+
|
|
98
|
+
## Your agents and their terms
|
|
99
|
+
|
|
100
|
+
Preston drives your own, unmodified `claude` and `codex` CLIs under the logins you already have. It never reads, stores or forwards your credentials. Anthropic's terms let you use Claude Code with your own subscription. They also expect plan limits to reflect ordinary, individual usage, and long unattended work may sit uneasily with that. OpenAI allows ChatGPT-plan use in open-source, locally run tools through the Codex App Server. Check the current terms for your plan.
|
|
101
|
+
|
|
102
|
+
## Keeping your agents current
|
|
103
|
+
|
|
104
|
+
Preston keeps your agent CLIs up to date: about once a day, and only when no work is using that CLI, it runs the CLI's own updater and checks that it still starts and is still signed in. It never uses administrator rights; if you installed a CLI with Homebrew, apt, winget or similar, it says so in `status` and leaves it to you. To stop automatic updates, tell Preston so (it sets `agents.autoUpdate` to false).
|
|
105
|
+
|
|
106
|
+
## Development
|
|
107
|
+
|
|
108
|
+
```sh
|
|
109
|
+
npm install
|
|
110
|
+
npm run check # typecheck, lint and tests
|
|
111
|
+
npm run build # compiles to dist/
|
|
112
|
+
npm run test:pack # packs, installs into a temporary prefix, runs the installed preston
|
|
113
|
+
npm run smoke # uses your real Claude Code and Codex logins (a few cents of quota); see docs/smoke-tests.md
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
The [architecture](docs/architecture.md), the [glossary](CONTEXT.md) and the [decisions](docs/adr/) describe how Preston is put together.
|
|
117
|
+
|
|
118
|
+
## Licence
|
|
119
|
+
|
|
120
|
+
MIT
|
package/assets/logo.png
ADDED
|
Binary file
|
package/assets/logo.webp
ADDED
|
Binary file
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema for what Preston knows about the agent CLIs it keeps current. Appended to the numbered
|
|
3
|
+
* migrations in `src/store/migrations.ts`; never edit it once released.
|
|
4
|
+
*/
|
|
5
|
+
export const AGENT_CLI_MIGRATION = `
|
|
6
|
+
-- One row per agent CLI: the version last seen, how the last update check went, and why Preston
|
|
7
|
+
-- stopped updating it (needs attention, or installed through a package manager).
|
|
8
|
+
CREATE TABLE agent_cli (
|
|
9
|
+
agent TEXT PRIMARY KEY,
|
|
10
|
+
version TEXT,
|
|
11
|
+
checked_at TEXT,
|
|
12
|
+
result TEXT NOT NULL,
|
|
13
|
+
detail TEXT,
|
|
14
|
+
attention TEXT,
|
|
15
|
+
managed_version TEXT,
|
|
16
|
+
managed_reason TEXT
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
-- Every version change Preston saw, by its own update or made outside it.
|
|
20
|
+
CREATE TABLE agent_cli_versions (
|
|
21
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
22
|
+
agent TEXT NOT NULL,
|
|
23
|
+
from_version TEXT,
|
|
24
|
+
to_version TEXT NOT NULL,
|
|
25
|
+
how TEXT NOT NULL,
|
|
26
|
+
at TEXT NOT NULL
|
|
27
|
+
);
|
|
28
|
+
`;
|
|
29
|
+
//# sourceMappingURL=migration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.js","sourceRoot":"","sources":["../../src/agents/migration.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;CAuBlC,CAAC"}
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import { accessSync, constants, realpathSync } from "node:fs";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import { isoNow } from "../clock.js";
|
|
4
|
+
import { pick } from "../i18n/index.js";
|
|
5
|
+
import { errorMessage } from "../log.js";
|
|
6
|
+
import { formatResetTime } from "../quota/time.js";
|
|
7
|
+
import { all, one, recordEvent, run } from "../store/db.js";
|
|
8
|
+
import { agentLabel } from "../workers/registry.js";
|
|
9
|
+
/** First check after the daemon starts: lets recovery settle before anything else runs. */
|
|
10
|
+
export const UPDATE_START_DELAY_MS = 30_000;
|
|
11
|
+
/** How long to wait before looking again when the CLI is in use or setup is unfinished. */
|
|
12
|
+
export const UPDATE_RETRY_MS = 5 * 60_000;
|
|
13
|
+
/** A restart does not check again sooner than this after the last check (a crash loop is quiet). */
|
|
14
|
+
const MIN_RECHECK_MS = 10 * 60_000;
|
|
15
|
+
/** Each interval is spread by up to this share of itself, so agents do not line up. */
|
|
16
|
+
const JITTER_RATIO = 0.1;
|
|
17
|
+
/**
|
|
18
|
+
* Keeps the agent CLIs current without a model: on start (after recovery) and then every
|
|
19
|
+
* `agents.updateIntervalMs`, each enabled agent whose adapter can update is updated, but only
|
|
20
|
+
* while nothing uses that CLI and setup is finished; otherwise it is looked at again shortly.
|
|
21
|
+
* Afterwards the CLI must still start and still be signed in. If not, the agent is marked as
|
|
22
|
+
* needing attention and the user is told once; nothing is rolled back and nothing more is tried.
|
|
23
|
+
* Installs managed by a package manager or an administrator are never touched. Persisted, so
|
|
24
|
+
* versions and results survive restarts.
|
|
25
|
+
*/
|
|
26
|
+
export class AgentUpdater {
|
|
27
|
+
deps;
|
|
28
|
+
timers = new Map();
|
|
29
|
+
running = new Set();
|
|
30
|
+
cycles = new Map();
|
|
31
|
+
stopped = true;
|
|
32
|
+
constructor(deps) {
|
|
33
|
+
this.deps = deps;
|
|
34
|
+
}
|
|
35
|
+
start() {
|
|
36
|
+
this.stopped = false;
|
|
37
|
+
for (const agent of this.updatable())
|
|
38
|
+
this.schedule(agent, this.firstDelay(agent));
|
|
39
|
+
}
|
|
40
|
+
stop() {
|
|
41
|
+
this.stopped = true;
|
|
42
|
+
for (const timer of this.timers.values())
|
|
43
|
+
timer.cancel();
|
|
44
|
+
this.timers.clear();
|
|
45
|
+
}
|
|
46
|
+
/** What is recorded about an agent CLI; undefined until it has been looked at. */
|
|
47
|
+
state(agent) {
|
|
48
|
+
const row = one(this.deps.db, "SELECT * FROM agent_cli WHERE agent = :agent", {
|
|
49
|
+
agent,
|
|
50
|
+
});
|
|
51
|
+
return row ? toState(row) : undefined;
|
|
52
|
+
}
|
|
53
|
+
/** Version changes seen for an agent, oldest first. */
|
|
54
|
+
versionChanges(agent) {
|
|
55
|
+
return all(this.deps.db, "SELECT * FROM agent_cli_versions WHERE agent = :agent ORDER BY id", { agent }).map((row) => ({
|
|
56
|
+
agent: row.agent,
|
|
57
|
+
from: row.from_version ?? undefined,
|
|
58
|
+
to: row.to_version,
|
|
59
|
+
how: row.how,
|
|
60
|
+
at: row.at,
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
/** One short line per agent CLI Preston keeps current, for the status text. */
|
|
64
|
+
statusLines() {
|
|
65
|
+
return this.updatable()
|
|
66
|
+
.filter((agent) => this.deps.config.get().agents.enabled.includes(agent))
|
|
67
|
+
.map((agent) => this.line(agent))
|
|
68
|
+
.filter((line) => line !== undefined);
|
|
69
|
+
}
|
|
70
|
+
/** "Claude Code 2.1.4: up to date (checked 9:00am)." Undefined before the first look. */
|
|
71
|
+
line(agent) {
|
|
72
|
+
const state = this.state(agent);
|
|
73
|
+
if (!state)
|
|
74
|
+
return undefined;
|
|
75
|
+
const label = agentLabel(agent);
|
|
76
|
+
const name = state.version ? `${label} ${state.version}` : label;
|
|
77
|
+
const when = state.checkedAt ? formatResetTime(state.checkedAt, this.deps.clock.now()) : "";
|
|
78
|
+
if (state.attention)
|
|
79
|
+
return `${name}: needs attention. ${state.attention}`;
|
|
80
|
+
if (state.managedVersion && state.managedVersion === state.version) {
|
|
81
|
+
return `${name}: ${state.managedReason ?? "managed outside Preston"}. Update it yourself.`;
|
|
82
|
+
}
|
|
83
|
+
const off = this.deps.config.get().agents.autoUpdate ? "" : " Automatic updates are off.";
|
|
84
|
+
const checked = when ? ` (checked ${when})` : "";
|
|
85
|
+
switch (state.result) {
|
|
86
|
+
case "updated": {
|
|
87
|
+
const from = this.versionChanges(agent).at(-1)?.from;
|
|
88
|
+
return `${name}: updated${from ? ` from ${from}` : ""}${checked}.${off}`;
|
|
89
|
+
}
|
|
90
|
+
case "failed":
|
|
91
|
+
return `${name}: the last update check failed${checked}; I'll try again.${off}`;
|
|
92
|
+
case "skipped":
|
|
93
|
+
return `${name}: not checked${checked}${state.detail ? ` - ${state.detail}` : ""}.${off}`;
|
|
94
|
+
default:
|
|
95
|
+
return `${name}: up to date${checked}.${off}`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// ---- Scheduling ---------------------------------------------------------------------------
|
|
99
|
+
updatable() {
|
|
100
|
+
return this.deps.adapters.kinds().filter((agent) => this.deps.adapters.get(agent)?.update);
|
|
101
|
+
}
|
|
102
|
+
firstDelay(agent) {
|
|
103
|
+
const checked = this.state(agent)?.checkedAt;
|
|
104
|
+
const since = checked ? this.deps.clock.now() - Date.parse(checked) : Number.POSITIVE_INFINITY;
|
|
105
|
+
return since < MIN_RECHECK_MS
|
|
106
|
+
? MIN_RECHECK_MS - since + UPDATE_START_DELAY_MS
|
|
107
|
+
: UPDATE_START_DELAY_MS;
|
|
108
|
+
}
|
|
109
|
+
schedule(agent, delayMs) {
|
|
110
|
+
if (this.stopped)
|
|
111
|
+
return;
|
|
112
|
+
this.timers.get(agent)?.cancel();
|
|
113
|
+
this.timers.set(agent, this.deps.clock.setTimeout(() => {
|
|
114
|
+
this.timers.delete(agent);
|
|
115
|
+
void this.tick(agent).catch((err) => this.deps.log.error("agent update check failed", { agent, error: err }));
|
|
116
|
+
}, delayMs));
|
|
117
|
+
}
|
|
118
|
+
/** The next regular check: the interval, spread so agents (and restarts) do not line up. */
|
|
119
|
+
nextDelay(agent) {
|
|
120
|
+
const cycle = (this.cycles.get(agent) ?? 0) + 1;
|
|
121
|
+
this.cycles.set(agent, cycle);
|
|
122
|
+
const base = this.deps.config.get().agents.updateIntervalMs;
|
|
123
|
+
const jitter = (unitHash(`${agent}:${cycle}`) * 2 - 1) * JITTER_RATIO;
|
|
124
|
+
return Math.round(base * (1 + jitter));
|
|
125
|
+
}
|
|
126
|
+
async tick(agent) {
|
|
127
|
+
if (this.stopped || this.running.has(agent))
|
|
128
|
+
return;
|
|
129
|
+
const config = this.deps.config.get();
|
|
130
|
+
if (!config.agents.autoUpdate || !config.agents.enabled.includes(agent)) {
|
|
131
|
+
this.schedule(agent, this.nextDelay(agent));
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
// Never mid-setup, never while work is using this CLI: look again at the next quiet moment.
|
|
135
|
+
if (!config.setup.complete || this.deps.busy(agent)) {
|
|
136
|
+
this.schedule(agent, UPDATE_RETRY_MS);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
this.running.add(agent);
|
|
140
|
+
try {
|
|
141
|
+
await this.update(agent);
|
|
142
|
+
}
|
|
143
|
+
finally {
|
|
144
|
+
this.running.delete(agent);
|
|
145
|
+
}
|
|
146
|
+
this.schedule(agent, this.nextDelay(agent));
|
|
147
|
+
}
|
|
148
|
+
// ---- One update -----------------------------------------------------------------------------
|
|
149
|
+
async update(agent) {
|
|
150
|
+
const adapter = this.deps.adapters.get(agent);
|
|
151
|
+
if (!adapter?.update)
|
|
152
|
+
return;
|
|
153
|
+
const { log } = this.deps;
|
|
154
|
+
const label = agentLabel(agent);
|
|
155
|
+
const stored = this.state(agent);
|
|
156
|
+
const before = await detect(adapter);
|
|
157
|
+
if (this.stopped)
|
|
158
|
+
return;
|
|
159
|
+
if (!healthy(before)) {
|
|
160
|
+
// Not ours to fix: a CLI that is missing or signed out is the setup and sign-in paths' job.
|
|
161
|
+
this.save(agent, {
|
|
162
|
+
version: before.version ?? stored?.version,
|
|
163
|
+
result: stored?.attention ? "needs_attention" : "skipped",
|
|
164
|
+
detail: before.problem ?? "it is not installed or not signed in",
|
|
165
|
+
keepAttention: true,
|
|
166
|
+
});
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
this.noteOutsideChange(agent, stored?.version, before.version);
|
|
170
|
+
const cleared = stored?.attention !== undefined;
|
|
171
|
+
if (cleared)
|
|
172
|
+
log.info("agent works again", { agent });
|
|
173
|
+
if (stored?.managedVersion && stored.managedVersion === before.version) {
|
|
174
|
+
// Already known to be managed elsewhere at this version: stop retrying until it changes.
|
|
175
|
+
this.save(agent, {
|
|
176
|
+
version: before.version,
|
|
177
|
+
result: "managed_externally",
|
|
178
|
+
detail: stored.managedReason,
|
|
179
|
+
managed: { version: before.version, reason: stored.managedReason ?? "" },
|
|
180
|
+
});
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const blocked = (this.deps.checkInstall ?? checkInstall)(before.path);
|
|
184
|
+
if (blocked) {
|
|
185
|
+
this.markManaged(agent, before.version, blocked);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
let result;
|
|
189
|
+
try {
|
|
190
|
+
result = await adapter.update();
|
|
191
|
+
}
|
|
192
|
+
catch (err) {
|
|
193
|
+
result = { updated: false, failed: true, detail: errorMessage(err) };
|
|
194
|
+
}
|
|
195
|
+
if (this.stopped)
|
|
196
|
+
return;
|
|
197
|
+
log.info("agent update ran", { agent, ...result });
|
|
198
|
+
if (!result.updated && (result.managedExternally || managedFromOutput(result.detail))) {
|
|
199
|
+
this.markManaged(agent, before.version, managedReason(result.detail));
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const after = await detect(adapter);
|
|
203
|
+
if (this.stopped)
|
|
204
|
+
return;
|
|
205
|
+
const version = after.version ?? result.toVersion ?? before.version;
|
|
206
|
+
if (!healthy(after)) {
|
|
207
|
+
this.needsAttention(agent, before.version, version, after, label);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const changed = Boolean(version && before.version && version !== before.version);
|
|
211
|
+
if (changed && version)
|
|
212
|
+
this.recordChange(agent, before.version, version, "update");
|
|
213
|
+
this.save(agent, {
|
|
214
|
+
version,
|
|
215
|
+
result: changed ? "updated" : result.failed ? "failed" : "up_to_date",
|
|
216
|
+
detail: result.detail,
|
|
217
|
+
});
|
|
218
|
+
if (changed && version)
|
|
219
|
+
this.maybeTell(agent, before.version, version);
|
|
220
|
+
}
|
|
221
|
+
markManaged(agent, version, reason) {
|
|
222
|
+
this.deps.log.info("agent is managed outside Preston", { agent, version, reason });
|
|
223
|
+
this.save(agent, {
|
|
224
|
+
version,
|
|
225
|
+
result: "managed_externally",
|
|
226
|
+
detail: reason,
|
|
227
|
+
managed: { version: version ?? "", reason },
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
needsAttention(agent, from, to, after, label) {
|
|
231
|
+
const problem = after.problem ??
|
|
232
|
+
pick({
|
|
233
|
+
en: `${label} did not start or says you are signed out.`,
|
|
234
|
+
"zh-CN": `${label} 无法启动,或提示您已退出登录。`,
|
|
235
|
+
});
|
|
236
|
+
const reason = pick({
|
|
237
|
+
en: `${label} stopped working after an update. ${problem} I have not changed anything else and I will not undo the update myself.`,
|
|
238
|
+
"zh-CN": `${label} 在更新后无法正常工作。${problem} 我没有改动其他任何东西,也不会自己撤销这次更新。`,
|
|
239
|
+
});
|
|
240
|
+
this.deps.log.warn("agent needs attention after update", { agent, from, to, problem });
|
|
241
|
+
this.save(agent, {
|
|
242
|
+
version: to ?? from,
|
|
243
|
+
result: "needs_attention",
|
|
244
|
+
detail: problem,
|
|
245
|
+
attention: reason,
|
|
246
|
+
});
|
|
247
|
+
recordEvent(this.deps.db, this.deps.clock, "agent_needs_attention", {}, { agent, from, to });
|
|
248
|
+
this.deps.outbox.broadcast({
|
|
249
|
+
kind: "notice",
|
|
250
|
+
text: reason,
|
|
251
|
+
dedupeKey: `agent-attention:${agent}:${from ?? "?"}:${to ?? "?"}`,
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
/** Tells the user only about a new major version; routine updates are logged and in status. */
|
|
255
|
+
maybeTell(agent, from, to) {
|
|
256
|
+
const major = (v) => /^v?(\d+)\./.exec(v ?? "")?.[1];
|
|
257
|
+
const before = major(from);
|
|
258
|
+
const after = major(to);
|
|
259
|
+
if (!before || !after || before === after)
|
|
260
|
+
return;
|
|
261
|
+
this.deps.outbox.broadcast({
|
|
262
|
+
kind: "notice",
|
|
263
|
+
text: pick({
|
|
264
|
+
en: `I updated ${agentLabel(agent)} to ${to}, a new major version. Work carries on as normal; tell me if anything seems different.`,
|
|
265
|
+
"zh-CN": `我把 ${agentLabel(agent)} 更新到了 ${to}(一个新的大版本)。工作照常进行;如果觉得有什么不同,请告诉我。`,
|
|
266
|
+
}),
|
|
267
|
+
dedupeKey: `agent-major:${agent}:${to}`,
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
// ---- Persistence ----------------------------------------------------------------------------
|
|
271
|
+
/** The CLI changed version without Preston's update (the user did it). */
|
|
272
|
+
noteOutsideChange(agent, known, seen) {
|
|
273
|
+
if (seen && known && seen !== known)
|
|
274
|
+
this.recordChange(agent, known, seen, "outside");
|
|
275
|
+
}
|
|
276
|
+
recordChange(agent, from, to, how) {
|
|
277
|
+
run(this.deps.db, "INSERT INTO agent_cli_versions (agent, from_version, to_version, how, at) VALUES (:agent, :from, :to, :how, :at)", { agent, from: from ?? null, to, how, at: isoNow(this.deps.clock) });
|
|
278
|
+
this.deps.log.info("agent version changed", { agent, from, to, how });
|
|
279
|
+
}
|
|
280
|
+
save(agent, next) {
|
|
281
|
+
const before = this.state(agent);
|
|
282
|
+
const attention = next.attention ?? (next.keepAttention ? before?.attention : undefined);
|
|
283
|
+
const managed = next.managed ??
|
|
284
|
+
(before?.managedVersion && before.managedVersion === next.version
|
|
285
|
+
? { version: before.managedVersion, reason: before.managedReason ?? "" }
|
|
286
|
+
: undefined);
|
|
287
|
+
run(this.deps.db, `INSERT INTO agent_cli (agent, version, checked_at, result, detail, attention, managed_version, managed_reason)
|
|
288
|
+
VALUES (:agent, :version, :at, :result, :detail, :attention, :mv, :mr)
|
|
289
|
+
ON CONFLICT (agent) DO UPDATE SET version = :version, checked_at = :at, result = :result,
|
|
290
|
+
detail = :detail, attention = :attention, managed_version = :mv, managed_reason = :mr`, {
|
|
291
|
+
agent,
|
|
292
|
+
version: next.version ?? null,
|
|
293
|
+
at: isoNow(this.deps.clock),
|
|
294
|
+
result: next.result,
|
|
295
|
+
detail: next.detail?.slice(0, 500) ?? null,
|
|
296
|
+
attention: attention ?? null,
|
|
297
|
+
mv: managed?.version || null,
|
|
298
|
+
mr: managed?.reason || null,
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
// ---- Install checks -------------------------------------------------------------------------
|
|
303
|
+
/** Install locations owned by a package manager, which updates them (and may need rights). */
|
|
304
|
+
const PACKAGE_MANAGED = [
|
|
305
|
+
[/^\/opt\/homebrew\/|\/Cellar\/|\/Caskroom\/|\/linuxbrew\//, "installed with Homebrew"],
|
|
306
|
+
[/^\/snap\/|\/snap\/bin\//, "installed with Snap"],
|
|
307
|
+
[/^\/nix\/store\/|\/\.nix-profile\/|^\/run\/current-system\//, "installed with Nix"],
|
|
308
|
+
[/^\/usr\/(?:s?bin|lib|libexec|share)\//, "installed by your system's package manager"],
|
|
309
|
+
[/\\WinGet\\|\\Microsoft\\WindowsApps\\/i, "installed with winget"],
|
|
310
|
+
[/\\chocolatey\\/i, "installed with Chocolatey"],
|
|
311
|
+
];
|
|
312
|
+
/** Why this path is a package manager's install, or undefined. */
|
|
313
|
+
export function managedByPackageManager(path) {
|
|
314
|
+
return PACKAGE_MANAGED.find(([pattern]) => pattern.test(path))?.[1];
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Why Preston must not update an install itself, or undefined when it may try: it sits where a
|
|
318
|
+
* package manager keeps it, or its folder is not writable for this user (so updating would need
|
|
319
|
+
* administrator rights, which Preston never uses).
|
|
320
|
+
*/
|
|
321
|
+
export function checkInstall(path) {
|
|
322
|
+
if (!path)
|
|
323
|
+
return undefined;
|
|
324
|
+
let real;
|
|
325
|
+
try {
|
|
326
|
+
real = realpathSync(path);
|
|
327
|
+
}
|
|
328
|
+
catch {
|
|
329
|
+
return undefined;
|
|
330
|
+
}
|
|
331
|
+
const managed = managedByPackageManager(path) ?? managedByPackageManager(real);
|
|
332
|
+
if (managed)
|
|
333
|
+
return managed;
|
|
334
|
+
try {
|
|
335
|
+
accessSync(dirname(real), constants.W_OK);
|
|
336
|
+
}
|
|
337
|
+
catch {
|
|
338
|
+
return "installed where only an administrator can change it";
|
|
339
|
+
}
|
|
340
|
+
return undefined;
|
|
341
|
+
}
|
|
342
|
+
const NEEDS_RIGHTS = /\b(sudo|administrator|elevated|eacces|eperm|permission denied|operation not permitted|requires? (?:root|admin))\b|managed by|installed (?:with|via|using|through) (?:homebrew|brew|apt|winget|snap|chocolatey|scoop|nix)|\b(?:brew|apt(?:-get)?|dnf|winget|choco) (?:upgrade|install|update)\b/i;
|
|
343
|
+
function managedFromOutput(detail) {
|
|
344
|
+
return NEEDS_RIGHTS.test(detail);
|
|
345
|
+
}
|
|
346
|
+
function managedReason(detail) {
|
|
347
|
+
return /sudo|administrator|elevated|eacces|eperm|permission denied|operation not permitted|root|admin/i.test(detail)
|
|
348
|
+
? "updating it needs administrator rights"
|
|
349
|
+
: "managed by a package manager";
|
|
350
|
+
}
|
|
351
|
+
// ---- Helpers --------------------------------------------------------------------------------
|
|
352
|
+
async function detect(adapter) {
|
|
353
|
+
try {
|
|
354
|
+
return await adapter.detect();
|
|
355
|
+
}
|
|
356
|
+
catch (err) {
|
|
357
|
+
return { installed: false, problem: errorMessage(err) };
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
/** Starts, and is not known to be signed out ("unknown" cannot be checked cheaply). */
|
|
361
|
+
function healthy(detection) {
|
|
362
|
+
return detection.installed && detection.loggedIn !== false;
|
|
363
|
+
}
|
|
364
|
+
function toState(row) {
|
|
365
|
+
return {
|
|
366
|
+
agent: row.agent,
|
|
367
|
+
version: row.version ?? undefined,
|
|
368
|
+
checkedAt: row.checked_at ?? undefined,
|
|
369
|
+
result: row.result,
|
|
370
|
+
detail: row.detail ?? undefined,
|
|
371
|
+
attention: row.attention ?? undefined,
|
|
372
|
+
managedVersion: row.managed_version ?? undefined,
|
|
373
|
+
managedReason: row.managed_reason ?? undefined,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
/** A stable number in [0, 1) for a string (FNV-1a), so jitter is repeatable in tests. */
|
|
377
|
+
function unitHash(text) {
|
|
378
|
+
let hash = 0x811c9dc5;
|
|
379
|
+
for (let i = 0; i < text.length; i++) {
|
|
380
|
+
hash ^= text.charCodeAt(i);
|
|
381
|
+
hash = Math.imul(hash, 0x01000193);
|
|
382
|
+
}
|
|
383
|
+
return (hash >>> 0) / 2 ** 32;
|
|
384
|
+
}
|
|
385
|
+
//# sourceMappingURL=updater.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updater.js","sourceRoot":"","sources":["../../src/agents/updater.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU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