worktrust 0.11.12 → 0.11.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/README.md +16 -3
- package/SECURITY.md +7 -0
- package/cli-menu-remote.mjs +4 -1
- package/engine-release.json +1 -1
- package/package-release.json +1 -1
- package/package.json +4 -2
- package/remote-cli.mjs +3 -1
- package/remote-daemon.mjs +16 -4
- package/remote-desk-sessions.mjs +192 -0
- package/remote-health.mjs +220 -0
- package/remote-protocol.mjs +166 -14
- package/remote-run.mjs +27 -5
- package/remote-sessions.mjs +2 -2
- package/remote-terminal-sessions.mjs +1 -0
- package/worktrust.mjs +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,35 @@
|
|
|
2
2
|
|
|
3
3
|
The WorkTrust CLI, newest first. What the tool is and how to use it: [README.md](README.md).
|
|
4
4
|
|
|
5
|
+
## 0.11.13: computer health in Remote Agent, and continue a session on this computer
|
|
6
|
+
|
|
7
|
+
**This computer's health, live on your phone and in the browser.** The Remote Agent service reads memory pressure, free
|
|
8
|
+
memory, swap and its growth over two minutes, the load per core, the GPU's utilisation (Apple silicon) and the three
|
|
9
|
+
programs using the most memory (by name only) every 15 seconds, with no model and no sudo, and sends them sealed to your
|
|
10
|
+
linked phones and browsers; the relay passes them on and keeps none. Red (critical pressure, or under 5 % free while swap
|
|
11
|
+
grows for two minutes) shows in `remote status` and the Remote Agent menu, and a new session is refused with "This
|
|
12
|
+
computer is under heavy memory load" until it eases; running sessions continue.
|
|
13
|
+
|
|
14
|
+
**Continue a session on this computer.**
|
|
15
|
+
**Carry on in the chat from your phone or a browser.** Remote Agent now lists this computer's recent Claude Code sessions
|
|
16
|
+
(the last 20 by activity) to the WorkTrust app and the web Remote Console, and continues the one you pick through the same
|
|
17
|
+
start as a session begun from the phone: Claude Code's own `--resume`, the approval tool, the deny rules (no release,
|
|
18
|
+
pipeline or deploy from a remote session) and the agent modes you allowed here. From then on it is a remote session like
|
|
19
|
+
any other, in the normal sessions list, and its turns from the phone are not your AI Hours.
|
|
20
|
+
|
|
21
|
+
**Only what it needs, only from folders you granted.** The CLI opens Claude Code's own transcript folders for your granted
|
|
22
|
+
projects and roots' projects only, never the store as a whole, and drops a transcript whose recorded folder is another. Per
|
|
23
|
+
session it sends, sealed end to end, only its id, the project's id, the last activity time, a title (Claude Code's own
|
|
24
|
+
summary when there is one, else the first line you typed, cut to 80 characters) and the model when recorded. Nothing
|
|
25
|
+
else of a transcript leaves this computer, and WorkTrust's servers see none of it. The list goes only to a phone or
|
|
26
|
+
browser that asks for it; an older app never receives it.
|
|
27
|
+
|
|
28
|
+
**One owner per conversation.** A session is refused while it is open here: its transcript was written in the last 30
|
|
29
|
+
seconds, a Claude Code process names it (`--resume`), or a Claude Code window open in that project folder started before
|
|
30
|
+
its last line. The phone and the browser say "This session is open on the computer. Close it there first." Agents running
|
|
31
|
+
in that window do not come along. On Windows, where the CLI cannot read the process list without a shell, the list stays
|
|
32
|
+
empty for now.
|
|
33
|
+
|
|
5
34
|
## 0.11.12: a smaller code to link a phone, access chosen at once, Esc stops a command, and decoy keys
|
|
6
35
|
|
|
7
36
|
**Decoy keys beside the real one.** `connect` and `update` write a few decoy credential files next to the computer's key,
|
package/README.md
CHANGED
|
@@ -67,7 +67,7 @@ computer in WorkTrust under Sources, Devices. More under [Undo](#undo).
|
|
|
67
67
|
On a computer that is not connected yet:
|
|
68
68
|
|
|
69
69
|
```
|
|
70
|
-
WorkTrust CLI 0.11.
|
|
70
|
+
WorkTrust CLI 0.11.13
|
|
71
71
|
Not connected yet
|
|
72
72
|
|
|
73
73
|
> 1 Look at this computer npx worktrust look
|
|
@@ -84,13 +84,13 @@ On a computer that is not connected yet:
|
|
|
84
84
|
Once it is connected (80 columns; on a wide terminal each row's sentence stands on the row itself, as a fourth column):
|
|
85
85
|
|
|
86
86
|
```
|
|
87
|
-
WorkTrust CLI 0.11.
|
|
87
|
+
WorkTrust CLI 0.11.13
|
|
88
88
|
Account you@example.com
|
|
89
89
|
This computer imac · connected since 2026-11-03
|
|
90
90
|
Remote Agent approved, 2 connections
|
|
91
91
|
Sharing session hook on · AI apps on (7) · Remote Agent approved
|
|
92
92
|
|
|
93
|
-
1 Update WorkTrust · up to date (0.11.
|
|
93
|
+
1 Update WorkTrust · up to date (0.11.13) npx worktrust update
|
|
94
94
|
> 2 Check this computer npx worktrust
|
|
95
95
|
3 Remote Agent › npx worktrust remote …
|
|
96
96
|
4 Import earlier history › npx worktrust history …
|
|
@@ -198,6 +198,14 @@ here with `remote modes allow`. The computer refuses a mode above what you allow
|
|
|
198
198
|
**Sealed end to end.** The computer holds one outbound connection and opens no port. Messages are sealed between your
|
|
199
199
|
phone and this computer; the relay passes them on and cannot read a prompt, a file, a path, an output or a model name.
|
|
200
200
|
|
|
201
|
+
**This computer's health, on your phone.** While Remote Agent runs, it reads a few numbers of this computer every 15
|
|
202
|
+
seconds, itself, with no model and no sudo: memory pressure, free memory, swap and how fast it grows, the CPU load per
|
|
203
|
+
core, the GPU's utilisation on Apple silicon, and the three programs using the most memory, by name only (never their
|
|
204
|
+
arguments, paths or window titles). The newest reading stays in `~/.worktrust/remote/health.json`; it goes sealed to
|
|
205
|
+
your linked phones and browsers only, and the relay keeps none of it. When memory runs out (critical pressure, or under
|
|
206
|
+
5 % free while swap keeps growing), `remote status` and the menu say so in red, and a phone cannot start a new session
|
|
207
|
+
until it eases; sessions already running continue.
|
|
208
|
+
|
|
201
209
|
A session steered from a phone is recorded as an agent run. It never counts as your AI Hours.
|
|
202
210
|
|
|
203
211
|
The details: [Remote Agent: steer this computer's agents](#remote-agent-steer-this-computers-agents-from-your-phone-or-browser-npx-worktrust-remote).
|
|
@@ -774,6 +782,11 @@ Off until you run `npx worktrust remote app` (or `remote web`) at this keyboard;
|
|
|
774
782
|
told why.
|
|
775
783
|
- One outbound connection to the WorkTrust gateway, end-to-end encrypted: the gateway relays sealed messages and reads no
|
|
776
784
|
prompt, file, path, output or model name. No port is opened on this computer.
|
|
785
|
+
- Continue a session on this computer (0.11.13): the phone or the browser lists this computer's recent Claude Code
|
|
786
|
+
sessions in your granted folders (the last 20; per session only its id, the project, the last activity, a title of at
|
|
787
|
+
most 80 characters and the model, sealed end to end) and continues the one you pick with Claude Code's own `--resume`,
|
|
788
|
+
under the same rules as a session started from the phone. A session open here (written in the last 30 seconds, named
|
|
789
|
+
by a running Claude Code, or in a Claude Code window open in that folder) is refused until you close it here.
|
|
777
790
|
- A session steered from a phone is never your AI Hours: the service records it in `~/.worktrust/remote/steered.jsonl`
|
|
778
791
|
before the agent starts, and the session hook sends it as an agent run (`session_kind` headless, `steered_from`
|
|
779
792
|
remote).
|
package/SECURITY.md
CHANGED
|
@@ -264,6 +264,13 @@ What it is: standing remote execution of AI agents on this computer, steered fro
|
|
|
264
264
|
grant only folders whose code you trust. The phone's keys are on the phone: until you revoke it, whoever unlocks it can
|
|
265
265
|
steer agents within these rules. macOS asks for folder access per program, so the access you grant the service's `node`
|
|
266
266
|
covers every script that `node` runs.
|
|
267
|
+
- Continuing a desk session (0.11.13). The daemon reads Claude Code's transcript folders of granted projects only (the
|
|
268
|
+
encoded folder of each granted path, never the whole store; a transcript whose recorded folder is another is dropped),
|
|
269
|
+
at most the first and last 64 KB of a file, and sends per session only its id, the project's id, the last activity, an
|
|
270
|
+
80-character title and the model, sealed, to a phone that asked. A resume is refused unless the id is in that list,
|
|
271
|
+
under the project named, and nothing on this computer holds it (`ps`, and `lsof` or /proc for a window's folder; a
|
|
272
|
+
process list it cannot read counts as holding it). The title is the first line typed when Claude Code wrote no summary:
|
|
273
|
+
what you typed first in a session reaches your own phones and browsers.
|
|
267
274
|
- Hours. A remote-steered session is never your AI Hours (see README).
|
|
268
275
|
|
|
269
276
|
## Python distribution and explicit agent observations
|
package/cli-menu-remote.mjs
CHANGED
|
@@ -14,6 +14,7 @@ import { makeProjectsFolder, pickFolder, pickerCommand, suggestedFolders } from
|
|
|
14
14
|
import { awaitingName, awaitingRow, connections } from "./remote-connections.mjs";
|
|
15
15
|
import { loadIdentity, loadProjects, loadRoots, loadSettings } from "./remote-store.mjs";
|
|
16
16
|
import { allowedModes } from "./remote-settings.mjs";
|
|
17
|
+
import { HEALTH_REFUSAL, keptHealth } from "./remote-health.mjs";
|
|
17
18
|
|
|
18
19
|
const BACK = { label: "← Back", hint: "Esc", back: true }; // its name and its key say it: no sentence of its own (owner, 2026-11-14)
|
|
19
20
|
const tilde = (path) => (path.startsWith(homedir()) ? `~${path.slice(homedir().length)}` : path);
|
|
@@ -213,7 +214,9 @@ export async function remoteMenu(term, io, header) {
|
|
|
213
214
|
const road = (which) => async () => ((await runShown(term, io, ["remote", which, ...(approved ? ["--repair"] : [])])) === false ? false : approved === false && approval() === true ? "back" : true);
|
|
214
215
|
// 0.11.12: a linked phone with no reach chosen yet is said first, and its row opens the access step (awaitingRow).
|
|
215
216
|
const waiting = state?.remoteAccess === "premium_required" ? null : awaitingName();
|
|
216
|
-
|
|
217
|
+
// HEAVY MEMORY LOAD (remote-health.mjs): the remote service's newest sample, red, is said first, in red; Enter shows the figures.
|
|
218
|
+
const red = keptHealth()?.level === "red" ? [{ label: "Health: heavy memory load", note: { text: "red", tone: "red" }, hint: "npx worktrust remote status", info: `${HEALTH_REFUSAL}. New sessions wait; running ones continue. Enter shows the figures.`, run: () => runShown(term, io, ["remote", "status"]) }] : [];
|
|
219
|
+
return [...red, ...(waiting ? [awaitingRow(waiting, (args) => runShown(term, io, args))] : []), ...remoteItems(approved, paused, {
|
|
217
220
|
approve: () => level(term, header, approved ? "Approve this computer again (new keys)" : "Approve this computer", () => [
|
|
218
221
|
{ label: "With the WorkTrust app", hint: `npx worktrust remote app${approved ? " --repair" : ""}`, info: "One QR: the app approves and links this phone.", run: road("app") },
|
|
219
222
|
{ label: "In the browser", hint: `npx worktrust remote web${approved ? " --repair" : ""}`, info: "Opens WorkTrust in your browser, where you approve.", run: road("web") },
|
package/engine-release.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"chat-exports.mjs":"f026c5a063f62c22ba6f25474a9d9fdbb6074beebbfe1faff2a876c437a1a000","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","cli-colour.mjs":"9736ab0801b3889967134a916680acb9dc3d614db6fd221be9c5ae7079d9d173","cli-look.mjs":"1c8eea30fa57dbdbf260e5e45f017a9ca85c77bd511569f931bfd80c8cdb648a","cli-menu-remote.mjs":"
|
|
1
|
+
{"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"chat-exports.mjs":"f026c5a063f62c22ba6f25474a9d9fdbb6074beebbfe1faff2a876c437a1a000","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","cli-colour.mjs":"9736ab0801b3889967134a916680acb9dc3d614db6fd221be9c5ae7079d9d173","cli-look.mjs":"1c8eea30fa57dbdbf260e5e45f017a9ca85c77bd511569f931bfd80c8cdb648a","cli-menu-remote.mjs":"eb7a9ada12cf566f668cbcf1f248412c1812b45d0f8845108facbd5f27dfc7a0","cli-menu.mjs":"f6eb43e71c8c941c79736f5073c393d3a349077a2a21af5cd75687b24731178b","cli-stop.mjs":"34f63fb7d27723d52650475582c3b8d36aa57e37457ebf55ab24449743df9847","commit-rules.mjs":"e94cc32a5415f6d9e978145ab9505ac4ae0bac9431e6e9104b9b37155260b51f","config-edits.mjs":"527a7674f9d52b284bfda3b8089eb4b930a709bf14aedbec7f6eef1e59ef52ee","count-behaviour.mjs":"06b0ecbc222087160dc64c0b302391631e8e799038364c317c6cd28449c5044d","credential-decoy.mjs":"8b9a264a3739fb9f58f8b9102b93a14292962689c8557ff7fad332dcfac3f7d9","credential-store.mjs":"8a83e7086fadaba31b0923101851d348d67cf3c87610f6d3e73a774f64435392","credential-vault-scripts.mjs":"7e42fe1db3885c2dec6f1de87bebfbefe2292d29179a68f3da87d19eb6c7704b","credential-vault.mjs":"279baabb217e2a3f170e8d7f2b271a88484531f9031c441360ea91561a70da99","export-facts.mjs":"3bbb46c80e8678b5cea7e15dcbfc456a2b48595053241c2b3cea508092f9b917","folder-picker.mjs":"daeb379626d5716f91f588064c6b4083618279320c006c177960cc93f056d96a","git-commits.mjs":"af0ed45a2a42c8e17cabfb3649a2f524dbf80230f8a6ec1c6b775fed7d34dc9c","history-outbox.mjs":"85c70389effc5b4ec9d9b33af9192314e67f47af2752515b42a7959344ce2354","history-progress.mjs":"dcc25ee94b727f2605a763349a4d8764640335d6cf0043fb6108cebeed16dcb9","log-session.mjs":"171f4abb0d603d58446129e007de9e9dc0f707bde33b1b4481a134376ed301c8","node-guide.mjs":"5bf52c5028b07a80ec4d41be365eb025dfce74328f41f928a26ce6737b1f9cc4","orchestration-contract.mjs":"ec08f303a166365b99e70b675de4cfe76c6156c2567e14b5569f6d992f0231b7","orchestration-evidence.mjs":"d0d06cecf0eb08e5c6e653c62a4f45b1eddf2119c2acb8341056b34f488d214a","orchestration-report.mjs":"d4e0a9ad8e4a01b462d22c6b1866aac291565c533ff476085d3367cb6d59bc1b","package-integrity.mjs":"a8210c9494a56bfb9a5ea3d10064c7a269f0b6330c0af7c0700e706c3c0224e3","preserve-lines.mjs":"2df64a69687aa51219bf7b86b88d175cc50990fa29574b31897e41a9ebeecf43","preserve-summary.mjs":"137f781ed7021596a3f0ea67afcf2ab8616ac293f833dbb8f176e838e0ed8321","preserve.mjs":"cd111cae0f53a25a2d878a158479abfb1ace353361454843f91a16d241101d46","project-modes.mjs":"ada26e68297fbeb90e4e91d75a90fd2d7cc107b999a9702840675b5a7529463e","remote-adapter-claude-code.mjs":"d0558bb123a29a934db1bf8162e7c3f37e8ccde4c502178d47e9b4cbb3a0491b","remote-adapter-codex.mjs":"0370611044e6f5f6ef3ca370e0f6ef237468f01ecc890b019da8167730eb75eb","remote-adapter-opencode.mjs":"062c571cc4ab972412044066c236a9f20794cfb841c66cc9c0e9e5ec1133699e","remote-adapter-terminal.mjs":"c047a362474abb90b7968b8a624358af40a989ad137166a03bc955409ff1dc82","remote-admin.mjs":"ac4d434c0a374159b27accac3fdd0324ff96ffe32227fba054cc62d00e58d35b","remote-agent-switch.mjs":"7ff5448f29f05a47d7298d730b21243a1bcf8a215b434a0c7fbf5f3cb0889041","remote-approval-bridge.mjs":"092f17b7969e4f35bea064315d04dcde1faa6a3fd3e737dcc05aece82c7a37c4","remote-approvals.mjs":"63847226e398f9eb5b8d3989ba2b2436fbedd898385eb5f2f63bbdf07fbe6852","remote-attachments.mjs":"2e9c1277329a45cf26c0c62abda632cf0ab9fad78d0504416ecee9805220e16c","remote-cdp.mjs":"70e333a1ebe845e872cc3a703a0a507391f8ce59640bdbd662bdad55eeff216b","remote-changes.mjs":"2141fece4961a5bc1bb1b046f78222812617457b1ba6452275eac6a897e62e19","remote-claude-events.mjs":"58822471203c6a1b66cf81c115c4d713657c3dea5c7b98df959f894ee5b2e704","remote-claude-progress.mjs":"2ca626d3dbc16d8d570abe1df6477b7e44ffb43c1d9145228ec5ea1928e415ca","remote-cli.mjs":"b047d324265921ae280bfa4907165e8e0dc8709e6d270e0bea3b788113920f5a","remote-coalesce.mjs":"cb0967d9cfe81e3892bcade8349d6814db98be8c2adbdb54df0b8d1b142f65d1","remote-codex-events.mjs":"58657d6070a50c837737cb85f5a1eaf9c2cbc4e1adfe3e970748ab3b2af94631","remote-connections.mjs":"099963cfa6c53bca62a18a266be847f7da4ed8fe611eb9b052b575f5f6d5f0bc","remote-countdown.mjs":"b1020c59fcae3cbf6c355976b2a5ef80a3476ffadcd9949e8e884bedfd1efa06","remote-daemon.mjs":"e2e05064271800b6790d474c15f72aa65c0a99131ecf2c43fd075d5dbbb6c933","remote-desk-sessions.mjs":"3a342e525fdf43ba54b40576f84a2399baa0c03c54f9184bfc153242fb50e4a3","remote-endorse.mjs":"89eda4883567176703e01e44d83e987271bc2a6134e108f517b3b213719a21f9","remote-health.mjs":"0f37d08f97fc6e08c69792cf3d22201b3103a28bdb19613b5abb02b80eb91983","remote-inventory.mjs":"98a65a066772ef183f405a1455c02db6827f06e80ed601796c65c19f9be10f09","remote-journal.mjs":"907ebd48c53162b22dc743ef95b53c1a6be6886a7495605b5cfa820b8de9d330","remote-live-preview.mjs":"faa70f9260ac05037204c2a0c3facf4ffe42f68408948390b341b453a2932289","remote-opencode-events.mjs":"3108375501ead2c2c78bce1435cc2a9fe6d2af1d7ff1fb42e12ff3e0f5d9af9c","remote-opencode-session.mjs":"681b201d833a7d7d025122b3a79663bcdc0a989aefd39d8018a28113d8810caf","remote-pairing.mjs":"b27625cc3b5313091252bc8ae907b4b969b96be0fe8c2ee3e9000c767ea60175","remote-pipeline-config.mjs":"00cde6a61ce21144c51ac56fce42fee159aa9dba6586218a7ea790ce4a6bd40b","remote-pipeline-parsers.mjs":"43ca0d332d7bc883c4759a754a555815ae5dfe133446b91ba9f2e48a350fa20f","remote-pipeline.mjs":"b856ead989b29ddb618ef69bbacd104bae2b02c9d1c5214291d08ce469a8b24e","remote-policy.mjs":"16ea015ad5de3c357bce730ea8ea98571dc981d8591fb5156b1941b2c557a381","remote-preview.mjs":"fe504ad6f83dcb4a4ebdcc018686a9a5a900c47cdf8c45b75e7d02e2f3056155","remote-projects.mjs":"ec8c530ad3e880bca21a4d4078ecd68b6aaafcc442b50087127868d952034d5f","remote-protocol.mjs":"53a83b8842139b492504fd29435d51fb4da6e143e9ff326b89ec821f70b1316c","remote-qr.mjs":"a0f4044f0afe8a636be14cf5afe10f53404b57262c23fea37f8cf30b6d0a5220","remote-release-plans.mjs":"11884a62b7d6dcccb5e154a26603bdf650f7b40f946329fb174d8c13729bec74","remote-releases.mjs":"fb08b72593ea00013c8b679e0c0d7dee95b0fd7cc5fd31b80ac575d0e340927d","remote-run.mjs":"7bdb3aa1327dd64ce79bd3038ad844ba32ccf9c82eb436116f437d3a48e4e871","remote-screen-approvals.mjs":"c43ab286d36a38d17639d155782ffa017f1a9b6806a09b82ed0142a1290b6000","remote-screen-push.mjs":"4ee8bd48d24b2c87581e9f33d8354a86381f7febd82f89ed509a7a87c1442608","remote-screen-states.mjs":"7c3c86a584bebf52461f3cab39c05ea2a13910061704d48fc622956e842940f7","remote-service.mjs":"a3a5502e0f6f43b04e37ee778f43d88f4c219776439cfed0d8fa0b511e0c9637","remote-session-list.mjs":"494fdbe20f0542806ac6c42ad149c52e2d3ace23a3a7567f96dc7e80d092c727","remote-sessions.mjs":"b4028b4247245013e9c2e4451f8dbb0ebff531066b78a4ea62499985464a4c43","remote-settings.mjs":"ca16f39416a457bd5ceb1df847596e1b4bcd2894310eb6514664a619dee4981f","remote-steered.mjs":"d7afde92c62c87abbdb84b0cfea2eea4752e90a2e453e52a54812c4fe0395190","remote-steering.mjs":"593447f3b7abbf3b91237d6d8a1aebcce9fbddc5ea5874341241ee45d83e5196","remote-store.mjs":"592a87f0ab8f53cc8eee1318a309310e27cb01d4549caebad6d51c3fad1b75ac","remote-terminal-cli.mjs":"82a048b75e412d0b6db076afbb84cab7c754dec72b6c8b6af4d4906b38e988a7","remote-terminal-sessions.mjs":"51b8140d46962eb035ff4ae60e5afea3c83244ea824412ca20e74a8318bbc3a5","remote-transport.mjs":"68650fd77ea09b5762377f87cabdc1c73a34d77324aa5bf0cd9742094a50c32b","runtime-install.mjs":"aab47b52c79d726ef428a24f982c648fa3f1c2dc2b574f633611d02924864e5f","self-update.mjs":"378e3620d48c72cf0bf812be408883b995cdb2223de34a20f762dd73eeffb258","session-databases.mjs":"a16ffbc50ccc0e78f370ebe07f871d1a80f1977472e478e3599e7abfdc90c1b7","session-local-models.mjs":"bacd38ff8dd3056b552982ec52eb57c7b8ca86e1a46cd4cba30fc340e3e28fd4","session-readers.mjs":"14cbd2c92d87511b396feaa54710f00d5e3929b55e01dc559f39c5def13777a2","setup-mcp.mjs":"b732e3dd9b3e522b7cc8acf167ce28ba8f1a8dee797ee15bd7c3b02919b13e6f","stack-rules.mjs":"b23c56e72ec56ba02b17ed895f869172d988c468a697e8d6026b0e268f61e489","stretch-evidence.mjs":"5f5667b92adf11b1a5a6330a0f26dd6db73d56fe60823d9a5246dab71d27d380","transcript-readers.mjs":"3dfdd9d2189063f24dbd5c2abec6bb21e2bb36f22b89d0d84282e12216022670","worktrust-launch.mjs":"84801bd29d472d48188c126b9ebe3989a3132b54e13cc4fe534ff7c383a294ee","worktrust.mjs":"717455cda6a4a7b598ae834408a954a0c5716a527ffbfb581fdf861a7c867477"},"format":"worktrust-package/1","kind":"engine","version":"0.11.13"},"signature":"3yH78qR7IKPwaG4_cS8c9qZ8doIYoxE_RdMp5_w6K3SoCvHI4ytZ1QFllb-DAjXcFlQwxfQnn58h16fC9nTFCw"}
|
package/package-release.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"AGENTS.md":"e8abb38c293b57b71d3a6163d6242d1f375e773372b91b6d8ce39c584c51262a","CHANGELOG.md":"
|
|
1
|
+
{"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"AGENTS.md":"e8abb38c293b57b71d3a6163d6242d1f375e773372b91b6d8ce39c584c51262a","CHANGELOG.md":"edbd976af2ed18928b63bcbd2265e51b9d54a29bcff71b1abedecfa77e55bd94","CLAUDE.md":"5933504f93e5a40369a4790e96dd5dad791d849d3178b1833eb64088e456aaeb","LICENSE":"eb210c9cab5dbb6a2c293a003a7604e7fb6e5f7b95ab22b382171dc7adeed41a","README.md":"95043d00907ab3debfb0525f050d3f621cd42625434217694d3db83dfaaefeea","SECURITY.md":"9fe29600eca56b992d1a22bbdd62a7f1bf60210884d244a2c37165e0c327dd27","chat-exports.mjs":"f026c5a063f62c22ba6f25474a9d9fdbb6074beebbfe1faff2a876c437a1a000","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","cli-colour.mjs":"9736ab0801b3889967134a916680acb9dc3d614db6fd221be9c5ae7079d9d173","cli-look.mjs":"1c8eea30fa57dbdbf260e5e45f017a9ca85c77bd511569f931bfd80c8cdb648a","cli-menu-remote.mjs":"eb7a9ada12cf566f668cbcf1f248412c1812b45d0f8845108facbd5f27dfc7a0","cli-menu.mjs":"f6eb43e71c8c941c79736f5073c393d3a349077a2a21af5cd75687b24731178b","cli-stop.mjs":"34f63fb7d27723d52650475582c3b8d36aa57e37457ebf55ab24449743df9847","commit-rules.mjs":"e94cc32a5415f6d9e978145ab9505ac4ae0bac9431e6e9104b9b37155260b51f","config-edits.mjs":"527a7674f9d52b284bfda3b8089eb4b930a709bf14aedbec7f6eef1e59ef52ee","count-behaviour.mjs":"06b0ecbc222087160dc64c0b302391631e8e799038364c317c6cd28449c5044d","credential-decoy.mjs":"8b9a264a3739fb9f58f8b9102b93a14292962689c8557ff7fad332dcfac3f7d9","credential-store.mjs":"8a83e7086fadaba31b0923101851d348d67cf3c87610f6d3e73a774f64435392","credential-vault-scripts.mjs":"7e42fe1db3885c2dec6f1de87bebfbefe2292d29179a68f3da87d19eb6c7704b","credential-vault.mjs":"279baabb217e2a3f170e8d7f2b271a88484531f9031c441360ea91561a70da99","engine-release.json":"04ba620d1480f94659da3e57aa8b44197098128255c5c8dc32c7eb1a95683cbb","export-facts.mjs":"3bbb46c80e8678b5cea7e15dcbfc456a2b48595053241c2b3cea508092f9b917","folder-picker.mjs":"daeb379626d5716f91f588064c6b4083618279320c006c177960cc93f056d96a","git-commits.mjs":"af0ed45a2a42c8e17cabfb3649a2f524dbf80230f8a6ec1c6b775fed7d34dc9c","history-outbox.mjs":"85c70389effc5b4ec9d9b33af9192314e67f47af2752515b42a7959344ce2354","history-progress.mjs":"dcc25ee94b727f2605a763349a4d8764640335d6cf0043fb6108cebeed16dcb9","log-session.mjs":"171f4abb0d603d58446129e007de9e9dc0f707bde33b1b4481a134376ed301c8","node-guide.mjs":"5bf52c5028b07a80ec4d41be365eb025dfce74328f41f928a26ce6737b1f9cc4","orchestration-contract.mjs":"ec08f303a166365b99e70b675de4cfe76c6156c2567e14b5569f6d992f0231b7","orchestration-evidence.mjs":"d0d06cecf0eb08e5c6e653c62a4f45b1eddf2119c2acb8341056b34f488d214a","orchestration-report.mjs":"d4e0a9ad8e4a01b462d22c6b1866aac291565c533ff476085d3367cb6d59bc1b","package-integrity.mjs":"a8210c9494a56bfb9a5ea3d10064c7a269f0b6330c0af7c0700e706c3c0224e3","package.json":"79e3f0de638203aa2a227b14483c1e9d828be24d0043b2b84faa499009024bf6","preserve-lines.mjs":"2df64a69687aa51219bf7b86b88d175cc50990fa29574b31897e41a9ebeecf43","preserve-summary.mjs":"137f781ed7021596a3f0ea67afcf2ab8616ac293f833dbb8f176e838e0ed8321","preserve.mjs":"cd111cae0f53a25a2d878a158479abfb1ace353361454843f91a16d241101d46","project-modes.mjs":"ada26e68297fbeb90e4e91d75a90fd2d7cc107b999a9702840675b5a7529463e","remote-adapter-claude-code.mjs":"d0558bb123a29a934db1bf8162e7c3f37e8ccde4c502178d47e9b4cbb3a0491b","remote-adapter-codex.mjs":"0370611044e6f5f6ef3ca370e0f6ef237468f01ecc890b019da8167730eb75eb","remote-adapter-opencode.mjs":"062c571cc4ab972412044066c236a9f20794cfb841c66cc9c0e9e5ec1133699e","remote-adapter-terminal.mjs":"c047a362474abb90b7968b8a624358af40a989ad137166a03bc955409ff1dc82","remote-admin.mjs":"ac4d434c0a374159b27accac3fdd0324ff96ffe32227fba054cc62d00e58d35b","remote-agent-switch.mjs":"7ff5448f29f05a47d7298d730b21243a1bcf8a215b434a0c7fbf5f3cb0889041","remote-approval-bridge.mjs":"092f17b7969e4f35bea064315d04dcde1faa6a3fd3e737dcc05aece82c7a37c4","remote-approvals.mjs":"63847226e398f9eb5b8d3989ba2b2436fbedd898385eb5f2f63bbdf07fbe6852","remote-attachments.mjs":"2e9c1277329a45cf26c0c62abda632cf0ab9fad78d0504416ecee9805220e16c","remote-cdp.mjs":"70e333a1ebe845e872cc3a703a0a507391f8ce59640bdbd662bdad55eeff216b","remote-changes.mjs":"2141fece4961a5bc1bb1b046f78222812617457b1ba6452275eac6a897e62e19","remote-claude-events.mjs":"58822471203c6a1b66cf81c115c4d713657c3dea5c7b98df959f894ee5b2e704","remote-claude-progress.mjs":"2ca626d3dbc16d8d570abe1df6477b7e44ffb43c1d9145228ec5ea1928e415ca","remote-cli.mjs":"b047d324265921ae280bfa4907165e8e0dc8709e6d270e0bea3b788113920f5a","remote-coalesce.mjs":"cb0967d9cfe81e3892bcade8349d6814db98be8c2adbdb54df0b8d1b142f65d1","remote-codex-events.mjs":"58657d6070a50c837737cb85f5a1eaf9c2cbc4e1adfe3e970748ab3b2af94631","remote-connections.mjs":"099963cfa6c53bca62a18a266be847f7da4ed8fe611eb9b052b575f5f6d5f0bc","remote-countdown.mjs":"b1020c59fcae3cbf6c355976b2a5ef80a3476ffadcd9949e8e884bedfd1efa06","remote-daemon.mjs":"e2e05064271800b6790d474c15f72aa65c0a99131ecf2c43fd075d5dbbb6c933","remote-desk-sessions.mjs":"3a342e525fdf43ba54b40576f84a2399baa0c03c54f9184bfc153242fb50e4a3","remote-endorse.mjs":"89eda4883567176703e01e44d83e987271bc2a6134e108f517b3b213719a21f9","remote-health.mjs":"0f37d08f97fc6e08c69792cf3d22201b3103a28bdb19613b5abb02b80eb91983","remote-inventory.mjs":"98a65a066772ef183f405a1455c02db6827f06e80ed601796c65c19f9be10f09","remote-journal.mjs":"907ebd48c53162b22dc743ef95b53c1a6be6886a7495605b5cfa820b8de9d330","remote-live-preview.mjs":"faa70f9260ac05037204c2a0c3facf4ffe42f68408948390b341b453a2932289","remote-opencode-events.mjs":"3108375501ead2c2c78bce1435cc2a9fe6d2af1d7ff1fb42e12ff3e0f5d9af9c","remote-opencode-session.mjs":"681b201d833a7d7d025122b3a79663bcdc0a989aefd39d8018a28113d8810caf","remote-pairing.mjs":"b27625cc3b5313091252bc8ae907b4b969b96be0fe8c2ee3e9000c767ea60175","remote-pipeline-config.mjs":"00cde6a61ce21144c51ac56fce42fee159aa9dba6586218a7ea790ce4a6bd40b","remote-pipeline-parsers.mjs":"43ca0d332d7bc883c4759a754a555815ae5dfe133446b91ba9f2e48a350fa20f","remote-pipeline.mjs":"b856ead989b29ddb618ef69bbacd104bae2b02c9d1c5214291d08ce469a8b24e","remote-policy.mjs":"16ea015ad5de3c357bce730ea8ea98571dc981d8591fb5156b1941b2c557a381","remote-preview.mjs":"fe504ad6f83dcb4a4ebdcc018686a9a5a900c47cdf8c45b75e7d02e2f3056155","remote-projects.mjs":"ec8c530ad3e880bca21a4d4078ecd68b6aaafcc442b50087127868d952034d5f","remote-protocol.mjs":"53a83b8842139b492504fd29435d51fb4da6e143e9ff326b89ec821f70b1316c","remote-qr.mjs":"a0f4044f0afe8a636be14cf5afe10f53404b57262c23fea37f8cf30b6d0a5220","remote-release-plans.mjs":"11884a62b7d6dcccb5e154a26603bdf650f7b40f946329fb174d8c13729bec74","remote-releases.mjs":"fb08b72593ea00013c8b679e0c0d7dee95b0fd7cc5fd31b80ac575d0e340927d","remote-run.mjs":"7bdb3aa1327dd64ce79bd3038ad844ba32ccf9c82eb436116f437d3a48e4e871","remote-screen-approvals.mjs":"c43ab286d36a38d17639d155782ffa017f1a9b6806a09b82ed0142a1290b6000","remote-screen-push.mjs":"4ee8bd48d24b2c87581e9f33d8354a86381f7febd82f89ed509a7a87c1442608","remote-screen-states.mjs":"7c3c86a584bebf52461f3cab39c05ea2a13910061704d48fc622956e842940f7","remote-service.mjs":"a3a5502e0f6f43b04e37ee778f43d88f4c219776439cfed0d8fa0b511e0c9637","remote-session-list.mjs":"494fdbe20f0542806ac6c42ad149c52e2d3ace23a3a7567f96dc7e80d092c727","remote-sessions.mjs":"b4028b4247245013e9c2e4451f8dbb0ebff531066b78a4ea62499985464a4c43","remote-settings.mjs":"ca16f39416a457bd5ceb1df847596e1b4bcd2894310eb6514664a619dee4981f","remote-steered.mjs":"d7afde92c62c87abbdb84b0cfea2eea4752e90a2e453e52a54812c4fe0395190","remote-steering.mjs":"593447f3b7abbf3b91237d6d8a1aebcce9fbddc5ea5874341241ee45d83e5196","remote-store.mjs":"592a87f0ab8f53cc8eee1318a309310e27cb01d4549caebad6d51c3fad1b75ac","remote-terminal-cli.mjs":"82a048b75e412d0b6db076afbb84cab7c754dec72b6c8b6af4d4906b38e988a7","remote-terminal-sessions.mjs":"51b8140d46962eb035ff4ae60e5afea3c83244ea824412ca20e74a8318bbc3a5","remote-transport.mjs":"68650fd77ea09b5762377f87cabdc1c73a34d77324aa5bf0cd9742094a50c32b","runtime-install.mjs":"aab47b52c79d726ef428a24f982c648fa3f1c2dc2b574f633611d02924864e5f","self-update.mjs":"378e3620d48c72cf0bf812be408883b995cdb2223de34a20f762dd73eeffb258","session-databases.mjs":"a16ffbc50ccc0e78f370ebe07f871d1a80f1977472e478e3599e7abfdc90c1b7","session-local-models.mjs":"bacd38ff8dd3056b552982ec52eb57c7b8ca86e1a46cd4cba30fc340e3e28fd4","session-readers.mjs":"14cbd2c92d87511b396feaa54710f00d5e3929b55e01dc559f39c5def13777a2","setup-mcp.mjs":"b732e3dd9b3e522b7cc8acf167ce28ba8f1a8dee797ee15bd7c3b02919b13e6f","stack-rules.mjs":"b23c56e72ec56ba02b17ed895f869172d988c468a697e8d6026b0e268f61e489","stretch-evidence.mjs":"5f5667b92adf11b1a5a6330a0f26dd6db73d56fe60823d9a5246dab71d27d380","transcript-readers.mjs":"3dfdd9d2189063f24dbd5c2abec6bb21e2bb36f22b89d0d84282e12216022670","worktrust-launch.mjs":"84801bd29d472d48188c126b9ebe3989a3132b54e13cc4fe534ff7c383a294ee","worktrust.mjs":"717455cda6a4a7b598ae834408a954a0c5716a527ffbfb581fdf861a7c867477"},"format":"worktrust-package/1","kind":"npm","version":"0.11.13"},"signature":"s_B96oTxz8bpZwkwUYjS_8GVcievlUjKDY8TvKTiO9ksFmZsNU6XZjuMyKj54amdqQWz2KlTenthwOGHuREQCQ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "worktrust",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.13",
|
|
4
4
|
"description": "Couple this computer to WorkTrust: approve a code in your browser, and every AI app here reports what you built. Metadata only, no dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -84,6 +84,7 @@
|
|
|
84
84
|
"remote-approvals.mjs",
|
|
85
85
|
"remote-sessions.mjs",
|
|
86
86
|
"remote-session-list.mjs",
|
|
87
|
+
"remote-desk-sessions.mjs",
|
|
87
88
|
"remote-changes.mjs",
|
|
88
89
|
"remote-endorse.mjs",
|
|
89
90
|
"remote-daemon.mjs",
|
|
@@ -104,7 +105,8 @@
|
|
|
104
105
|
"node-guide.mjs",
|
|
105
106
|
"remote-countdown.mjs",
|
|
106
107
|
"remote-connections.mjs",
|
|
107
|
-
"remote-admin.mjs"
|
|
108
|
+
"remote-admin.mjs",
|
|
109
|
+
"remote-health.mjs"
|
|
108
110
|
],
|
|
109
111
|
"engines": {
|
|
110
112
|
"node": ">=18"
|
package/remote-cli.mjs
CHANGED
|
@@ -49,6 +49,7 @@ import { accessCommand, askLine, connectionsCommand, disconnectCommand, linkedSu
|
|
|
49
49
|
import { installService, removeService, serviceState, servicePlatform } from "./remote-service.mjs";
|
|
50
50
|
import { terminalQr } from "./remote-qr.mjs";
|
|
51
51
|
import { webSocketAvailable } from "./remote-transport.mjs";
|
|
52
|
+
import { healthLine, keptHealth } from "./remote-health.mjs";
|
|
52
53
|
import { guideToNode, remoteStopsHere } from "./node-guide.mjs";
|
|
53
54
|
import { inventory } from "./remote-inventory.mjs";
|
|
54
55
|
import { allowCommand, parsePipelineConfig, PIPELINE_FILE } from "./remote-pipeline-config.mjs";
|
|
@@ -282,9 +283,10 @@ function status(io) {
|
|
|
282
283
|
const agents = inventory({ env: { ...process.env, PATH: settings.agent_path ?? process.env.PATH } }).reports.filter((r) => r.installed);
|
|
283
284
|
const summary = { enabled: settings.enabled, paused: settings.paused, paired: Boolean(identity), device_id: identity?.device_id ?? null, fingerprint: keys ? fingerprintOf(keys) : null,
|
|
284
285
|
gateway: gatewayOf(settings), gateway_default: settings.gateway === null || settings.gateway === undefined, service, node_websocket: webSocketAvailable(), phones: { confirmed: phonesList.confirmed.length, pending: phonesList.pending.length, browsers_added: phonesList.confirmed.filter((p) => p.how === "endorsed").length, allow_endorse: settings.allow_endorse === true }, projects: loadProjects().length, modes_allowed: allowedModes(settings), admin: settings.admin !== false,
|
|
285
|
-
agents: agents.map((a) => ({ adapter: a.adapter, version: a.version, adapter_ready: a.capabilities.start, switched_off: a.capabilities.start && (a.adapter === "codex" || a.adapter === "opencode") && settings[a.adapter] !== true, models: a.models === null ? "not listed" : a.models.length })), invite_open: Boolean(readJson("invite.json")?.used === false) };
|
|
286
|
+
agents: agents.map((a) => ({ adapter: a.adapter, version: a.version, adapter_ready: a.capabilities.start, switched_off: a.capabilities.start && (a.adapter === "codex" || a.adapter === "opencode") && settings[a.adapter] !== true, models: a.models === null ? "not listed" : a.models.length })), invite_open: Boolean(readJson("invite.json")?.used === false), health: keptHealth() };
|
|
286
287
|
if (io.has("json")) { io.say(JSON.stringify(summary, null, 2)); return; }
|
|
287
288
|
io.say(` Remote: ${settings.enabled ? (settings.paused ? `paused (${settings.paused === "desk" ? "here" : "from a phone"})` : "on") : "off"}`);
|
|
289
|
+
io.say(healthLine(summary.health)); // the remote service's newest sample, a minute old at most (remote-health.mjs)
|
|
288
290
|
io.say(` Paired: ${identity ? `${identity.device_id} · key ${summary.fingerprint}` : "no"}`);
|
|
289
291
|
io.say(` Gateway: ${summary.gateway === PRODUCTION_GATEWAY ? `${new URL(PRODUCTION_GATEWAY).host} (WorkTrust's)` : `${summary.gateway}${isLoopbackGateway(summary.gateway) ? " (this computer: dev relay)" : " (chosen here)"}`}`);
|
|
290
292
|
io.say(` Service: ${service.kind === "foreground" ? "none on this system: run `npx worktrust remote run`" : `${service.installed ? "installed" : "not installed"}, ${service.running ? "running" : "not running"}`}`);
|
package/remote-daemon.mjs
CHANGED
|
@@ -18,15 +18,17 @@ import { createProject, rootLabel, sessionProjects, worktreeMain } from "./remot
|
|
|
18
18
|
import { agentOptionsOf } from "./remote-inventory.mjs";
|
|
19
19
|
import { allowedModes, applySettingsChange } from "./remote-settings.mjs";
|
|
20
20
|
import { adminInventory } from "./remote-admin.mjs";
|
|
21
|
+
import { deskBodyFor } from "./remote-desk-sessions.mjs";
|
|
21
22
|
|
|
22
23
|
// What a paused computer still answers: reading, configuring, disconnecting, and taking work away (a pipeline's cancel).
|
|
23
24
|
const LIVE_COMMANDS = new Set(["preview.live_start", "preview.live_input", "preview.live_viewport", "preview.live_follow"]);
|
|
24
25
|
const DEVICE_COMMANDS = new Set(["inventory.get", "device.configure", "status.get", "pairing.revoke", "release.list", "pipeline.cancel"]);
|
|
26
|
+
const NEW_SESSIONS = new Set(["agent.start", "release.start"]);
|
|
25
27
|
const KEEP_REMOVED = 20;
|
|
26
28
|
const MAX_PENDING_PHONES = 10;
|
|
27
29
|
|
|
28
30
|
export function createDaemonCore(o) {
|
|
29
|
-
// o: { local, issuerKeys, journal, now, random, send(frame), inventory(refresh), log(kind, fields), sessions?, approvals? }
|
|
31
|
+
// o: { local, issuerKeys, journal, now, random, send(frame), inventory(refresh), log(kind, fields), sessions?, approvals?, health?() }
|
|
30
32
|
const channels = new Map(loadChannels().map((c) => [c.channel_id, c]));
|
|
31
33
|
const confirmed = () => confirmedFingerprints(loadPhones());
|
|
32
34
|
const self = o.local.claims.device_id;
|
|
@@ -39,9 +41,10 @@ export function createDaemonCore(o) {
|
|
|
39
41
|
* asks again on every inventory.get.
|
|
40
42
|
*/
|
|
41
43
|
const extendedPeers = new Set(), switchPeers = new Set(); // release 33: `model_switch` only for a phone that asked for it
|
|
42
|
-
const
|
|
44
|
+
const deskPeers = new Set(); // release 36: `desk_sessions` (and the `in_use` refusal) only for a phone that asked for them
|
|
45
|
+
const EXTENDED_KEYS = ["agent_options", "modes_allowed", "admin", "folders", "connections", "desk_sessions"];
|
|
43
46
|
const withoutSwitch = (body) => (body.agent_options ? { ...body, agent_options: body.agent_options.map(({ model_switch: _drop, ...o }) => o) } : body);
|
|
44
|
-
const bodyFor = (channel, record) => (record.type !== "device.inventory" ? record.body
|
|
47
|
+
const bodyFor = (channel, record) => deskBodyFor(deskPeers.has(channel.peer_device_id), record.type, record.type !== "device.inventory" ? record.body
|
|
45
48
|
: extendedPeers.has(channel.peer_device_id) ? (switchPeers.has(channel.peer_device_id) ? record.body : withoutSwitch(record.body))
|
|
46
49
|
: Object.fromEntries(Object.entries(record.body).filter(([key]) => !EXTENDED_KEYS.includes(key))));
|
|
47
50
|
|
|
@@ -88,7 +91,7 @@ export function createDaemonCore(o) {
|
|
|
88
91
|
function inventoryBody(refresh) {
|
|
89
92
|
const settings = loadSettings();
|
|
90
93
|
const inv = o.inventory(refresh);
|
|
91
|
-
|
|
94
|
+
const body = {
|
|
92
95
|
remote_enabled: settings.enabled && settings.paused === null,
|
|
93
96
|
default_adapter: settings.default_adapter ?? null,
|
|
94
97
|
default_model: settings.default_model ?? null,
|
|
@@ -108,6 +111,9 @@ export function createDaemonCore(o) {
|
|
|
108
111
|
// Every session this computer knows, live or in the journal, newest activity first, with its name and its release task.
|
|
109
112
|
sessions: (sessions?.listAll?.() ?? sessions?.list() ?? []).map((s) => ({ ...s, ...(releases?.ownerOf(s.session_id) ?? {}) })).slice(0, 100),
|
|
110
113
|
};
|
|
114
|
+
// Release 36, read only while a phone that asked is linked: this computer's own Claude Code sessions, under the projects above.
|
|
115
|
+
if (o.desk && deskPeers.size > 0) { try { body.desk_sessions = o.desk.list().filter((d) => body.projects.some((p) => p.project_id === d.project_id)); } catch { o.log("desk_unreadable", {}); } }
|
|
116
|
+
return body;
|
|
111
117
|
}
|
|
112
118
|
|
|
113
119
|
function resendReceipts(entry) {
|
|
@@ -184,6 +190,7 @@ export function createDaemonCore(o) {
|
|
|
184
190
|
if (env.type === "inventory.get") {
|
|
185
191
|
if (payload.extended === true && env.sender_device_id) extendedPeers.add(env.sender_device_id);
|
|
186
192
|
if (payload.extended === true && payload.model_switch === true && env.sender_device_id) switchPeers.add(env.sender_device_id); // kept, as extendedPeers
|
|
193
|
+
if (payload.extended === true && payload.desk_sessions === true && env.sender_device_id) deskPeers.add(env.sender_device_id);
|
|
187
194
|
if (payload.device_name && env.sender_device_id) rememberName(env.sender_device_id, payload.device_name);
|
|
188
195
|
emit(null, "device.inventory", inventoryBody(payload.refresh_models));
|
|
189
196
|
return "taken";
|
|
@@ -208,6 +215,9 @@ export function createDaemonCore(o) {
|
|
|
208
215
|
return "taken";
|
|
209
216
|
}
|
|
210
217
|
if (env.type === "approval.decision") return approvals.decide(payload.decision_token).ok ? "taken" : "approval_invalid";
|
|
218
|
+
// HEAVY MEMORY LOAD (remote-health.mjs, 2026-11-15): while red, no NEW session starts; running sessions continue. `busy`
|
|
219
|
+
// is the reason every phone already knows; the run terminal says "This computer is under heavy memory load".
|
|
220
|
+
if (NEW_SESSIONS.has(env.type) && o.health?.()?.refusing === true) { o.log("session_refused", { reason: "memory_load", type: env.type }); return "busy"; }
|
|
211
221
|
if (P.RELEASE_COMMANDS.has(env.type)) return releases ? releases.handle(env, payload) : "unsupported"; // remote-releases.mjs
|
|
212
222
|
if (env.type === "attachment.put" || env.type === "attachment.clear") return o.attachments ? o.attachments.handle(env, payload) : "unsupported"; // remote-attachments.mjs
|
|
213
223
|
if (env.type === "preview.targets" || env.type === "preview.render") return o.preview ? o.preview.handle(env, payload) : "unsupported"; // remote-preview.mjs
|
|
@@ -271,6 +281,8 @@ export function createDaemonCore(o) {
|
|
|
271
281
|
|
|
272
282
|
return {
|
|
273
283
|
emit, replay, receiveCommand, receiveHello, inventoryBody,
|
|
284
|
+
/** The computer's health (remote-health.mjs): device-wide on the transient lane, to every open channel, never journaled. */
|
|
285
|
+
emitHealth(body) { if (channels.size > 0) emit(null, "device.health", body, null, "none", { transient: true }); },
|
|
274
286
|
/** The gateway's device.revoked: a phone this computer will no longer hear from. */
|
|
275
287
|
peerRevoked(event) { return dropPhone(event.device_id, event.reason === "unpaired" ? "phone" : "revoked"); },
|
|
276
288
|
attach(s, a, r = null) { sessions = s; approvals = a; releases = r; },
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CONTINUE A SESSION ON THIS COMPUTER (release 36, owner 2026-11-15: "via the remote link, get into the current session, so
|
|
3
|
+
* we don't have to scan tomorrow"; docs/remote-agents/DESK-SESSIONS.md). The phone or the browser lists this computer's
|
|
4
|
+
* recent Claude Code sessions and continues one through the daemon's own start (`agent.start` with `resume`).
|
|
5
|
+
*
|
|
6
|
+
* WHAT IS READ: Claude Code's own transcript store, `~/.claude/projects/<the folder, encoded>/<session uuid>.jsonl`, and only
|
|
7
|
+
* the folders of GRANTED projects (the inventory's own list, roots' projects included): the encoded folder of each granted
|
|
8
|
+
* path is opened, never the store as a whole, and a transcript whose recorded `cwd` is not that project's path is dropped.
|
|
9
|
+
* Of a file only its first and last 64 KB are read, for the working folder, a title and the model.
|
|
10
|
+
*
|
|
11
|
+
* WHAT IS SENT, sealed in device.inventory and only to a phone that asked `desk_sessions` (remote-daemon.mjs): per session
|
|
12
|
+
* its uuid, its project's id, the last activity time, a title (Claude Code's own name or summary line when the transcript
|
|
13
|
+
* has one, else the first line the person typed, cut to 80 characters) and the model when one is recorded. Never more of the
|
|
14
|
+
* transcript. The last 20 by activity; sessions the remote already runs or ran (its journal) are its own rows.
|
|
15
|
+
*
|
|
16
|
+
* ONE OWNER PER CONVERSATION: a resume is refused (`in_use`) while the session is held on the computer: its transcript was
|
|
17
|
+
* written in the last 30 seconds, a Claude Code process names its id (`--resume <id>`, `--session-id <id>`), or a Claude
|
|
18
|
+
* Code process that names no session (an open interactive window, `--continue`) works in that project folder and started
|
|
19
|
+
* before the transcript's last line. A computer whose processes cannot be read counts as holding it (fails closed).
|
|
20
|
+
*/
|
|
21
|
+
import { spawnSync } from "node:child_process";
|
|
22
|
+
import { closeSync, fstatSync, lstatSync, openSync, readdirSync, readSync, readlinkSync, realpathSync } from "node:fs";
|
|
23
|
+
import { homedir } from "node:os";
|
|
24
|
+
import { join } from "node:path";
|
|
25
|
+
import * as P from "./remote-protocol.mjs";
|
|
26
|
+
|
|
27
|
+
export const HELD_WINDOW_MS = 30_000;
|
|
28
|
+
const SLICE = 64 * 1024;
|
|
29
|
+
const MAX_READS = 60; // transcripts opened per listing at most, newest first
|
|
30
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
31
|
+
const UUIDS = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi;
|
|
32
|
+
|
|
33
|
+
/** Claude Code's name for a project's folder in its store: every character that is not a letter or a digit becomes "-". */
|
|
34
|
+
export const encodeProjectDir = (path) => path.replace(/[^A-Za-z0-9]/g, "-");
|
|
35
|
+
const real = (path) => { try { return realpathSync(path); } catch { return path; } };
|
|
36
|
+
const samePath = (a, b) => typeof a === "string" && typeof b === "string" && (a === b || real(a) === real(b));
|
|
37
|
+
|
|
38
|
+
/** The first and the last 64 KB of a file, as whole JSON lines (a line cut at a slice's edge is left out). */
|
|
39
|
+
function headAndTail(file) {
|
|
40
|
+
const fd = openSync(file, "r");
|
|
41
|
+
try {
|
|
42
|
+
const size = fstatSync(fd).size;
|
|
43
|
+
const read = (at, length) => { const buf = Buffer.alloc(length); const n = readSync(fd, buf, 0, length, at); return buf.subarray(0, n).toString("utf8"); };
|
|
44
|
+
const head = read(0, Math.min(size, SLICE));
|
|
45
|
+
const tail = size > SLICE ? read(Math.max(SLICE, size - SLICE), Math.min(SLICE, size - SLICE)) : "";
|
|
46
|
+
const lines = (text, cutFirst, cutLast) => { const all = text.split("\n"); if (cutFirst) all.shift(); if (cutLast) all.pop(); return all; };
|
|
47
|
+
const parse = (all) => all.map((l) => { try { const v = JSON.parse(l); return v && typeof v === "object" ? v : null; } catch { return null; } }).filter(Boolean);
|
|
48
|
+
return { head: parse(lines(head, false, size > SLICE)), tail: parse(lines(tail, true, false)) };
|
|
49
|
+
} finally { closeSync(fd); }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const oneLine = (text) => text.replace(/\s+/g, " ").trim();
|
|
53
|
+
const cut = (text, max) => { const t = oneLine(text); return t.length > max ? `${t.slice(0, max - 1).trimEnd()}…` : t; };
|
|
54
|
+
/** The words of a person's own message: a string, or its text blocks; never a tool result, a command's output or a caveat. */
|
|
55
|
+
function typed(line) {
|
|
56
|
+
if (line.type !== "user" || line.isMeta === true || line.isSidechain === true || line.message?.role !== "user") return null;
|
|
57
|
+
const c = line.message.content;
|
|
58
|
+
const text = typeof c === "string" ? c : Array.isArray(c) && c.every((b) => b?.type === "text") ? c.map((b) => b.text ?? "").join(" ") : null;
|
|
59
|
+
if (!text || /^\s*<(command-|local-command-|bash-|system-reminder)/.test(text) || /^\s*Caveat:/.test(text)) return null;
|
|
60
|
+
return oneLine(text) || null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** What one transcript tells: its working folder, a title and the model. Nothing else is kept. */
|
|
64
|
+
export function transcriptFacts(file) {
|
|
65
|
+
const { head, tail } = headAndTail(file);
|
|
66
|
+
const all = [...head, ...tail];
|
|
67
|
+
const cwd = head.find((l) => typeof l.cwd === "string")?.cwd ?? null;
|
|
68
|
+
const named = all.filter((l) => l.type === "custom-title" && typeof l.customTitle === "string").at(-1)?.customTitle
|
|
69
|
+
?? all.filter((l) => l.type === "summary" && typeof l.summary === "string").at(-1)?.summary ?? null;
|
|
70
|
+
const first = head.map(typed).find(Boolean) ?? null;
|
|
71
|
+
const title = named && oneLine(named) ? cut(named, P.MAX_DESK_TITLE) : first ? cut(first, P.MAX_DESK_TITLE) : null;
|
|
72
|
+
const models = all.filter((l) => l.type === "assistant" && typeof l.message?.model === "string" && /^[A-Za-z0-9._:@\[\]-]{1,128}$/.test(l.message.model) && l.message.model !== "<synthetic>");
|
|
73
|
+
return { cwd, title, model: models.at(-1)?.message.model ?? null };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The newest Claude Code sessions of the granted projects, at most MAX_DESK_SESSIONS: `{ session_ref, project_id,
|
|
78
|
+
* last_activity_at, title, model }` plus, kept on this computer, the transcript's file and the project's path.
|
|
79
|
+
* `exclude`: the agent ids the remote's own journal holds. `cache`: facts by file, size and time, so a listing rereads none.
|
|
80
|
+
*/
|
|
81
|
+
export function deskSessions({ home = homedir(), projects, exclude = new Set(), cache = new Map() }) {
|
|
82
|
+
const store = join(home, ".claude", "projects"), found = [];
|
|
83
|
+
for (const project of projects) {
|
|
84
|
+
const dir = join(store, encodeProjectDir(project.path));
|
|
85
|
+
let names = [];
|
|
86
|
+
try { if (!lstatSync(dir).isDirectory()) continue; names = readdirSync(dir); } catch { continue; }
|
|
87
|
+
for (const name of names) {
|
|
88
|
+
const ref = name.endsWith(".jsonl") ? name.slice(0, -6) : null;
|
|
89
|
+
if (!ref || !UUID.test(ref) || exclude.has(ref)) continue;
|
|
90
|
+
try { const st = lstatSync(join(dir, name)); if (st.isFile()) found.push({ ref, file: join(dir, name), project, mtime: Math.floor(st.mtimeMs), size: st.size }); } catch { /* gone */ }
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
found.sort((a, b) => b.mtime - a.mtime);
|
|
94
|
+
const out = [], seen = new Set();
|
|
95
|
+
for (const f of found.slice(0, MAX_READS)) {
|
|
96
|
+
if (out.length >= P.MAX_DESK_SESSIONS) break;
|
|
97
|
+
if (seen.has(f.ref)) continue; // two granted paths, one folder
|
|
98
|
+
const key = `${f.file}|${f.size}|${f.mtime}`;
|
|
99
|
+
let facts = cache.get(key);
|
|
100
|
+
if (!facts) { try { facts = transcriptFacts(f.file); } catch { continue; } cache.set(key, facts); }
|
|
101
|
+
if (!samePath(facts.cwd, f.project.path)) continue; // another folder whose name encodes the same: not this project
|
|
102
|
+
seen.add(f.ref);
|
|
103
|
+
out.push({ session_ref: f.ref, project_id: f.project.project_id, last_activity_at: f.mtime, title: facts.title, model: facts.model, file: f.file, projectPath: f.project.path });
|
|
104
|
+
}
|
|
105
|
+
if (cache.size > 200) for (const k of [...cache.keys()].slice(0, cache.size - 200)) cache.delete(k);
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** What leaves the computer, field by field: never the file or the path. */
|
|
110
|
+
export const deskRow = (d) => ({ session_ref: d.session_ref, project_id: d.project_id, last_activity_at: d.last_activity_at, title: d.title, model: d.model });
|
|
111
|
+
|
|
112
|
+
/** "[[dd-]hh:]mm:ss" from ps, in milliseconds. */
|
|
113
|
+
export function elapsedMs(text) {
|
|
114
|
+
const m = /^(?:(\d+)-)?(?:(\d+):)?(\d+):(\d+)$/.exec(String(text).trim());
|
|
115
|
+
return m ? ((Number(m[1] ?? 0) * 24 + Number(m[2] ?? 0)) * 3600 + Number(m[3]) * 60 + Number(m[4])) * 1000 : null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const CLAUDE_BIN = /(^|[/\\])claude(\.exe)?$/i;
|
|
119
|
+
/** Whether a command line is Claude Code: its `claude` program, its npm package, or a native build in its versions folder. */
|
|
120
|
+
export const isClaudeCommand = (args) => {
|
|
121
|
+
const first = String(args).trim().split(/\s+/)[0] ?? "";
|
|
122
|
+
return CLAUDE_BIN.test(first) || /@anthropic-ai[/\\]claude-code[/\\]/.test(args) || /[/\\]claude[/\\]versions[/\\][^\s/\\]+(\s|$)/.test(args);
|
|
123
|
+
};
|
|
124
|
+
/** One process as the held rule reads it: the session ids its command line names, whether it continues the newest one. */
|
|
125
|
+
export const processOf = (pid, args, startedAt, cwd) => ({ pid, startedAt, cwd, ids: [...new Set((String(args).match(UUIDS) ?? []).map((u) => u.toLowerCase()))], continues: /(^|\s)(-c|--continue)(\s|$)/.test(args) });
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The Claude Code processes running on this computer, or null when they cannot be read. Fixed arguments, no shell: `ps`
|
|
129
|
+
* (and the working folder from /proc on Linux, `lsof` on macOS). Windows has no process list without a shell, so there the
|
|
130
|
+
* answer is null: nothing can be shown free, and the desk lists nothing (createDesk).
|
|
131
|
+
*/
|
|
132
|
+
export function claudeProcesses({ platform = process.platform, now = Date.now(), run = spawnSync } = {}) {
|
|
133
|
+
if (platform === "win32") return null;
|
|
134
|
+
const output = (file, args) => { const r = run(file, args, { encoding: "utf8", timeout: 5_000, stdio: ["ignore", "pipe", "ignore"], maxBuffer: 8 * 1024 * 1024, windowsHide: true }); return r.status === 0 ? `${r.stdout ?? ""}` : null; };
|
|
135
|
+
const out = output("ps", ["axww", "-o", "pid=,etime=,args="]);
|
|
136
|
+
if (out === null) return null;
|
|
137
|
+
const procs = [];
|
|
138
|
+
for (const line of out.split("\n")) {
|
|
139
|
+
const m = /^\s*(\d+)\s+(\S+)\s+(.*)$/.exec(line);
|
|
140
|
+
if (!m || Number(m[1]) === process.pid || !isClaudeCommand(m[3])) continue;
|
|
141
|
+
const age = elapsedMs(m[2]);
|
|
142
|
+
procs.push(processOf(Number(m[1]), m[3], age === null ? 0 : now - age, null));
|
|
143
|
+
}
|
|
144
|
+
if (procs.length === 0) return procs;
|
|
145
|
+
if (platform === "linux") for (const p of procs) { try { p.cwd = readlinkSync(`/proc/${p.pid}/cwd`); } catch { /* not ours to read: unknown */ } }
|
|
146
|
+
else {
|
|
147
|
+
const lsof = output("lsof", ["-a", "-d", "cwd", "-Fn", "-p", procs.map((p) => p.pid).join(",")]);
|
|
148
|
+
let pid = null;
|
|
149
|
+
for (const l of (lsof ?? "").split("\n")) { if (l.startsWith("p")) pid = Number(l.slice(1)); else if (l.startsWith("n") && pid !== null) { const p = procs.find((x) => x.pid === pid); if (p) p.cwd = l.slice(1); } }
|
|
150
|
+
}
|
|
151
|
+
return procs;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Why a session is held on the computer, or null when it is free to continue here. */
|
|
155
|
+
export function heldBy(entry, { now, procs }) {
|
|
156
|
+
if (now - entry.last_activity_at < HELD_WINDOW_MS) return "recent";
|
|
157
|
+
if (procs === null) return "unknown";
|
|
158
|
+
for (const p of procs) {
|
|
159
|
+
if (p.ids.includes(entry.session_ref)) return "process";
|
|
160
|
+
if (p.ids.length === 0 && (p.cwd === null || samePath(p.cwd, entry.projectPath)) && (p.continues || p.startedAt <= entry.last_activity_at)) return "window";
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* The daemon's desk: `list()` the inventory's rows, `resumable(ref, projectId)` → null, `not_found` (not in this computer's
|
|
167
|
+
* own list, or not under that project) or `in_use` (held). Both read the store afresh; nothing from a phone is trusted.
|
|
168
|
+
*/
|
|
169
|
+
export function createDesk({ projects, journal, now = Date.now, home = homedir(), processes = () => claudeProcesses(), platform = process.platform }) {
|
|
170
|
+
const cache = new Map();
|
|
171
|
+
const own = () => new Set(journal.sessions().map((j) => j.agent_session_ref).filter((r) => typeof r === "string"));
|
|
172
|
+
const scan = () => deskSessions({ home, projects: projects(), exclude: own(), cache });
|
|
173
|
+
return {
|
|
174
|
+
list: () => (platform === "win32" ? [] : scan().map(deskRow)), // Windows: no process list without a shell, so none is shown free
|
|
175
|
+
resumable(ref, projectId) {
|
|
176
|
+
const found = typeof ref === "string" ? scan().find((d) => d.session_ref === ref) : null;
|
|
177
|
+
if (!found || found.project_id !== projectId) return "not_found";
|
|
178
|
+
return heldBy(found, { now: now(), procs: processes() }) ? "in_use" : null;
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* What a channel hears of the desk (remote-daemon.mjs bodyFor): a phone that asked `desk_sessions` hears all of it; any
|
|
185
|
+
* other never receives the key it would refuse, and a refusal it does not know (`in_use`) reaches it as `busy`.
|
|
186
|
+
*/
|
|
187
|
+
export function deskBodyFor(asked, type, body) {
|
|
188
|
+
if (asked) return body;
|
|
189
|
+
if (type === "device.inventory" && body && "desk_sessions" in body) { const { desk_sessions: _drop, ...rest } = body; return rest; }
|
|
190
|
+
if (type === "command.rejected" && body?.reason === "in_use") return { ...body, reason: "busy" };
|
|
191
|
+
return body;
|
|
192
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE COMPUTER'S HEALTH, MEASURED HERE (owner, 2026-11-15: "the computer sometimes crashes from RAM/GPU load").
|
|
3
|
+
* The Remote daemon reads a few numbers of this machine every 15 seconds, without a model (no tokens) and without sudo,
|
|
4
|
+
* keeps the newest in ~/.worktrust/remote/health.json (0600, this computer only) for `remote status` and the menu, and
|
|
5
|
+
* seals it for the paired phones and browsers on the transient lane (remote-protocol health.ts): the server never sees
|
|
6
|
+
* or stores a sample. While red, the daemon starts no new session (remote-daemon.mjs); running sessions continue.
|
|
7
|
+
*
|
|
8
|
+
* What is run, each through execFile with FIXED arguments, a fixed PATH, a timeout and an output cap; nothing from a
|
|
9
|
+
* phone, a file or the environment reaches an argument:
|
|
10
|
+
* macOS /usr/sbin/sysctl kern.memorystatus_vm_pressure_level kern.memorystatus_level vm.swapusage hw.memsize
|
|
11
|
+
* (the kernel's own pressure level 1/2/4 and the share of memory available, which `memory_pressure` prints
|
|
12
|
+
* too; sysctl reads them in one call without sudo, where `memory_pressure` runs a slower test of its own)
|
|
13
|
+
* /usr/sbin/ioreg -r -d 1 -cIOAccelerator ("Device Utilization %" of the Apple GPU; null when absent)
|
|
14
|
+
* /bin/ps -axo rss=,comm= (resident memory and the program, never `args` or `command`)
|
|
15
|
+
* Linux /proc/meminfo, /proc/pressure/memory (when the kernel has PSI), /proc/loadavg, and ps -eo rss=,comm=
|
|
16
|
+
* Windows free memory (os.freemem) and the load from the CPU times between two samples; nothing is run
|
|
17
|
+
* A program is named by its BASENAME only (a path is cut to its last part), summed over its processes; a name the
|
|
18
|
+
* protocol would refuse (an argument, a setting, a URL) is left out. A read that failed is null, never 0.
|
|
19
|
+
*/
|
|
20
|
+
import { execFile } from "node:child_process";
|
|
21
|
+
import { readFileSync } from "node:fs";
|
|
22
|
+
import os from "node:os";
|
|
23
|
+
import * as P from "./remote-protocol.mjs";
|
|
24
|
+
import { readJson, writeJson } from "./remote-store.mjs";
|
|
25
|
+
|
|
26
|
+
const TIMEOUT_MS = 4000, MAX_BUFFER = 4 * 1024 * 1024;
|
|
27
|
+
const SAFE_ENV = { PATH: "/usr/bin:/bin:/usr/sbin:/sbin", LC_ALL: "C" };
|
|
28
|
+
/** Every command this module may run, whole. check-remote-cli rule H reads this list: no `args`, no `command`. */
|
|
29
|
+
export const HEALTH_COMMANDS = Object.freeze({
|
|
30
|
+
sysctl: Object.freeze(["/usr/sbin/sysctl", Object.freeze(["kern.memorystatus_vm_pressure_level", "kern.memorystatus_level", "vm.swapusage", "hw.memsize"])]),
|
|
31
|
+
ioreg: Object.freeze(["/usr/sbin/ioreg", Object.freeze(["-r", "-d", "1", "-cIOAccelerator"])]),
|
|
32
|
+
psMac: Object.freeze(["/bin/ps", Object.freeze(["-axo", "rss=,comm="])]),
|
|
33
|
+
psLinux: Object.freeze(["ps", Object.freeze(["-eo", "rss=,comm="])]),
|
|
34
|
+
});
|
|
35
|
+
export const HEALTH_REFUSAL = "This computer is under heavy memory load";
|
|
36
|
+
const MB = 1024 * 1024;
|
|
37
|
+
|
|
38
|
+
/** One fixed command; its output, or null (failed, timed out, too long). A command that printed and exited non-zero still counts. */
|
|
39
|
+
export function runFixed(key) {
|
|
40
|
+
const [file, args] = HEALTH_COMMANDS[key];
|
|
41
|
+
return new Promise((done) => {
|
|
42
|
+
execFile(file, [...args], { timeout: TIMEOUT_MS, maxBuffer: MAX_BUFFER, windowsHide: true, env: SAFE_ENV, encoding: "utf8" }, (error, stdout) => {
|
|
43
|
+
done(error && (error.killed || typeof error.code !== "number" || !stdout) ? null : String(stdout ?? ""));
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const int = (v) => (Number.isFinite(v) ? Math.round(v) : null);
|
|
49
|
+
|
|
50
|
+
/** `sysctl` (names shown) on macOS: by name, so one missing key leaves the others readable. */
|
|
51
|
+
export function parseMacSysctl(text) {
|
|
52
|
+
const out = { pressure: null, memory_total_mb: null, memory_free_mb: null, swap_used_mb: null };
|
|
53
|
+
if (typeof text !== "string") return out;
|
|
54
|
+
const value = (name) => text.match(new RegExp(`^${name.replace(/\./g, "\\.")}:\\s*(.+)$`, "m"))?.[1]?.trim() ?? null;
|
|
55
|
+
out.pressure = { 1: "normal", 2: "warn", 4: "critical" }[Number(value("kern.memorystatus_vm_pressure_level"))] ?? null;
|
|
56
|
+
const bytes = Number(value("hw.memsize"));
|
|
57
|
+
if (Number.isSafeInteger(bytes) && bytes > 0) out.memory_total_mb = int(bytes / MB);
|
|
58
|
+
const level = Number(value("kern.memorystatus_level"));
|
|
59
|
+
if (out.memory_total_mb !== null && value("kern.memorystatus_level") !== null && level >= 0 && level <= 100) out.memory_free_mb = int((out.memory_total_mb * level) / 100);
|
|
60
|
+
out.swap_used_mb = parseSwapUsage(value("vm.swapusage"));
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** "total = 10240.00M used = 8911.38M free = 1328.62M (encrypted)" → 8911. */
|
|
65
|
+
export function parseSwapUsage(text) {
|
|
66
|
+
const m = typeof text === "string" ? text.match(/used\s*=\s*([\d.]+)([KMG])/) : null;
|
|
67
|
+
if (!m) return null;
|
|
68
|
+
return int(Number(m[1]) * { K: 1 / 1024, M: 1, G: 1024 }[m[2]]);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The highest "Device Utilization %" of any accelerator, 0 to 100; null when none reports one. */
|
|
72
|
+
export function parseIoreg(text) {
|
|
73
|
+
if (typeof text !== "string") return null;
|
|
74
|
+
const all = [...text.matchAll(/"Device Utilization %"\s*=\s*(\d+)/g)].map((m) => Number(m[1])).filter((n) => n >= 0 && n <= 100);
|
|
75
|
+
return all.length ? Math.max(...all) : null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** A program's name for the sample: the basename, without control characters, at most 64; null when the protocol refuses it. */
|
|
79
|
+
export function programName(comm) {
|
|
80
|
+
const base = String(comm).trim().split(/[/\\]/).pop().replace(/[\u0000-\u001f\u007f]/g, "").trim().slice(0, P.MAX_PROCESS_NAME);
|
|
81
|
+
return base && P.processNameRefusal(base) === null ? base : null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** `ps -o rss=,comm=`: the three programs holding the most memory, summed over their processes, largest first. */
|
|
85
|
+
export function parsePs(text) {
|
|
86
|
+
if (typeof text !== "string") return [];
|
|
87
|
+
const sums = new Map();
|
|
88
|
+
for (const line of text.split("\n")) {
|
|
89
|
+
const m = line.match(/^\s*(\d+)\s+(.+)$/);
|
|
90
|
+
if (!m) continue;
|
|
91
|
+
const name = programName(m[2]);
|
|
92
|
+
if (name) sums.set(name, (sums.get(name) ?? 0) + Number(m[1]));
|
|
93
|
+
}
|
|
94
|
+
return [...sums].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1)).slice(0, 3).map(([name, kb]) => ({ name, memory_mb: Math.round(kb / 1024) }))
|
|
95
|
+
.filter((p, n, all) => n === 0 || p.memory_mb <= all[n - 1].memory_mb);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** /proc/meminfo: total, available, swap used (MB). */
|
|
99
|
+
export function parseMeminfo(text) {
|
|
100
|
+
const kb = (key) => { const m = typeof text === "string" ? text.match(new RegExp(`^${key}:\\s+(\\d+) kB`, "m")) : null; return m ? Number(m[1]) : null; };
|
|
101
|
+
const total = kb("MemTotal"), available = kb("MemAvailable"), swapTotal = kb("SwapTotal"), swapFree = kb("SwapFree");
|
|
102
|
+
return { memory_total_mb: total === null ? null : int(total / 1024), memory_free_mb: available === null ? null : int(available / 1024), swap_used_mb: swapTotal === null || swapFree === null ? null : int((swapTotal - swapFree) / 1024) };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** /proc/pressure/memory (PSI): critical when tasks were fully stalled 10 % of the last 10 s, warn when some were; else normal. */
|
|
106
|
+
export function parsePsi(text) {
|
|
107
|
+
const avg = (kind) => { const m = typeof text === "string" ? text.match(new RegExp(`^${kind} avg10=([\\d.]+)`, "m")) : null; return m ? Number(m[1]) : null; };
|
|
108
|
+
const some = avg("some"), full = avg("full");
|
|
109
|
+
if (some === null && full === null) return null;
|
|
110
|
+
if ((full ?? 0) >= 10) return "critical";
|
|
111
|
+
return (some ?? 0) >= 10 ? "warn" : "normal";
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export const parseLoadavg = (text) => { const n = typeof text === "string" ? Number(text.trim().split(/\s+/)[0]) : NaN; return Number.isFinite(n) && n >= 0 ? n : null; };
|
|
115
|
+
|
|
116
|
+
const cpuTimes = (cpus) => cpus.reduce((t, c) => { const v = c.times; const all = v.user + v.nice + v.sys + v.idle + v.irq; return { busy: t.busy + all - v.idle, all: t.all + all }; }, { busy: 0, all: 0 });
|
|
117
|
+
|
|
118
|
+
/** Swap used now minus the newest reading at least SWAP_GROWTH_WINDOW_MS old; null until there is one. */
|
|
119
|
+
export function swapGrowth(history, now, used) {
|
|
120
|
+
if (used === null) return null;
|
|
121
|
+
const old = history.filter((h) => h.at <= now - P.SWAP_GROWTH_WINDOW_MS && h.used !== null).at(-1);
|
|
122
|
+
return old ? used - old.used : null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* ONE SAMPLE. `o`: { platform, run(key) → text | null, read(path) → text | null, os: { totalmem, freemem, loadavg, cpus },
|
|
127
|
+
* now, swapHistory[] (kept by the caller), lastCpu (kept by the caller) }. Returns the protocol's body and the CPU times for the next.
|
|
128
|
+
*/
|
|
129
|
+
export async function sampleHealth(o) {
|
|
130
|
+
const now = o.now();
|
|
131
|
+
let reading = { pressure: null, memory_total_mb: null, memory_free_mb: null, swap_used_mb: null }, load = null, gpu = null, top = [];
|
|
132
|
+
const cores = o.os.cpus()?.length || null;
|
|
133
|
+
if (o.platform === "darwin") {
|
|
134
|
+
const [sys, io, ps] = await Promise.all([o.run("sysctl"), o.run("ioreg"), o.run("psMac")]);
|
|
135
|
+
reading = parseMacSysctl(sys);
|
|
136
|
+
gpu = parseIoreg(io);
|
|
137
|
+
top = parsePs(ps);
|
|
138
|
+
const avg = o.os.loadavg()[0];
|
|
139
|
+
load = Number.isFinite(avg) ? avg : null;
|
|
140
|
+
} else if (o.platform === "linux") {
|
|
141
|
+
const mem = parseMeminfo(o.read("/proc/meminfo"));
|
|
142
|
+
reading = { pressure: parsePsi(o.read("/proc/pressure/memory")), ...mem };
|
|
143
|
+
load = parseLoadavg(o.read("/proc/loadavg"));
|
|
144
|
+
top = parsePs(await o.run("psLinux"));
|
|
145
|
+
} else {
|
|
146
|
+
const total = o.os.totalmem(), free = o.os.freemem();
|
|
147
|
+
reading = { ...reading, memory_total_mb: total > 0 ? int(total / MB) : null, memory_free_mb: total > 0 && free >= 0 ? int(free / MB) : null };
|
|
148
|
+
}
|
|
149
|
+
// The load where no load average exists (Windows): the share of CPU time busy since the last sample, times the cores.
|
|
150
|
+
const cpu = cpuTimes(o.os.cpus() ?? []);
|
|
151
|
+
if (o.platform === "win32" && o.lastCpu && cpu.all > o.lastCpu.all && cores) load = ((cpu.busy - o.lastCpu.busy) / (cpu.all - o.lastCpu.all)) * cores;
|
|
152
|
+
if (reading.memory_free_mb !== null && reading.memory_total_mb !== null) reading.memory_free_mb = Math.min(reading.memory_free_mb, reading.memory_total_mb);
|
|
153
|
+
const swap_growth_mb = swapGrowth(o.swapHistory ?? [], now, reading.swap_used_mb);
|
|
154
|
+
const judged = P.healthLevel({ ...reading, swap_growth_mb });
|
|
155
|
+
const body = { sampled_at: now, level: judged.level, reasons: [...judged.reasons], ...reading, swap_growth_mb,
|
|
156
|
+
load_centi: load === null ? null : Math.min(100_000_000, int(load * 100)), cores, gpu_busy: gpu, top, refusing: judged.level === "red" };
|
|
157
|
+
return { body, cpu };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* The daemon's sampler: every HEALTH_SAMPLE_MS, one sample, never two at once. `onSample(body)` sends and keeps it.
|
|
162
|
+
* Readers are parameters so tests stub them with recorded output.
|
|
163
|
+
*/
|
|
164
|
+
export function createHealthMonitor({ onSample, platform = process.platform, run = runFixed, read = (p) => { try { return readFileSync(p, "utf8"); } catch { return null; } }, osInfo = os, now = Date.now, log = () => {}, intervalMs = P.HEALTH_SAMPLE_MS } = {}) {
|
|
165
|
+
let swapHistory = [], lastCpu = null, latest = null, busy = false, timer = null;
|
|
166
|
+
const tick = async () => {
|
|
167
|
+
if (busy) return;
|
|
168
|
+
busy = true;
|
|
169
|
+
try {
|
|
170
|
+
const { body, cpu } = await sampleHealth({ platform, run, read, os: osInfo, now, swapHistory, lastCpu });
|
|
171
|
+
lastCpu = cpu;
|
|
172
|
+
swapHistory = [...swapHistory.filter((h) => h.at > body.sampled_at - P.SWAP_GROWTH_WINDOW_MS * 2), { at: body.sampled_at, used: body.swap_used_mb }];
|
|
173
|
+
const checked = P.validateEventBody("device.health", body);
|
|
174
|
+
if (!checked.ok) { log("health_refused", { code: checked.code }); return; }
|
|
175
|
+
latest = body;
|
|
176
|
+
onSample(body);
|
|
177
|
+
} catch (e) { log("health_failed", { name: e?.name ?? "Error" }); } finally { busy = false; }
|
|
178
|
+
};
|
|
179
|
+
return {
|
|
180
|
+
start() { void tick(); timer = setInterval(tick, intervalMs); timer.unref?.(); },
|
|
181
|
+
stop() { clearInterval(timer); timer = null; },
|
|
182
|
+
tick,
|
|
183
|
+
latest: () => latest,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** The newest sample, kept on this computer only (0600) for `remote status` and the menu; a minute old at most counts. */
|
|
188
|
+
export const HEALTH_FILE = "health.json";
|
|
189
|
+
export const HEALTH_FRESH_MS = 60_000;
|
|
190
|
+
export function keepHealth(body) { try { writeJson(HEALTH_FILE, body); } catch { /* the next sample tries again */ } }
|
|
191
|
+
export function keptHealth(now = Date.now()) {
|
|
192
|
+
try { const b = readJson(HEALTH_FILE); return b && P.validateEventBody("device.health", b).ok && now - b.sampled_at <= HEALTH_FRESH_MS ? b : null; } catch { return null; }
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* RECORDED OUTPUT FOR TESTS AGAINST THE DEV RELAY (remote-run.mjs honours WORKTRUST_REMOTE_HEALTH_FIXTURE only for a
|
|
197
|
+
* loopback gateway): { platform, outputs: { sysctl, ioreg, psMac, psLinux }, files: { "/proc/meminfo": … } }, read again
|
|
198
|
+
* at every sample, so an end-to-end test never depends on (or is refused by) the memory of the computer it runs on.
|
|
199
|
+
*/
|
|
200
|
+
export function fixtureReaders(path) {
|
|
201
|
+
const load = () => { try { return JSON.parse(readFileSync(path, "utf8")); } catch { return {}; } };
|
|
202
|
+
return { platform: load().platform ?? "darwin", run: async (key) => load().outputs?.[key] ?? null, read: (p) => load().files?.[p] ?? null };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const gb = (mb) => (mb >= 1024 ? `${(mb / 1024).toFixed(1)} GB` : `${mb} MB`);
|
|
206
|
+
/** The one line the menu and `remote status` show; red starts with ✗ (the painter makes it red), yellow with !. */
|
|
207
|
+
export function healthLine(body) {
|
|
208
|
+
if (!body) return " Health: not known (the remote service has not measured yet)";
|
|
209
|
+
const parts = [];
|
|
210
|
+
if (body.memory_total_mb && body.memory_free_mb !== null) parts.push(`memory ${Math.round((1 - body.memory_free_mb / body.memory_total_mb) * 100)} % in use`);
|
|
211
|
+
if (body.pressure) parts.push(`pressure ${body.pressure}`);
|
|
212
|
+
if (body.swap_used_mb !== null) parts.push(`swap ${gb(body.swap_used_mb)}${body.swap_growth_mb !== null && body.swap_growth_mb > 0 ? ` (+${gb(body.swap_growth_mb)} in 2 min)` : ""}`);
|
|
213
|
+
if (body.load_centi !== null && body.cores) parts.push(`CPU load ${(body.load_centi / 100 / body.cores).toFixed(2)} per core`);
|
|
214
|
+
if (body.gpu_busy !== null) parts.push(`GPU ${body.gpu_busy} %`);
|
|
215
|
+
if (body.top[0]) parts.push(`largest ${body.top[0].name} ${gb(body.top[0].memory_mb)}`);
|
|
216
|
+
const facts = parts.length ? parts.join(", ") : "nothing could be read";
|
|
217
|
+
if (body.level === "red") return ` ✗ Health: red. ${HEALTH_REFUSAL}: ${facts}. New sessions wait; running ones continue.`;
|
|
218
|
+
if (body.level === "yellow") return ` ! Health: yellow: ${facts}`;
|
|
219
|
+
return ` Health: ${body.level === "green" ? "green" : "not known"}: ${facts}`;
|
|
220
|
+
}
|
package/remote-protocol.mjs
CHANGED
|
@@ -1717,6 +1717,110 @@ export function agentsActiveRule(a ) {
|
|
|
1717
1717
|
return null;
|
|
1718
1718
|
}
|
|
1719
1719
|
|
|
1720
|
+
// ---- packages/remote-protocol/src/health.ts
|
|
1721
|
+
/**
|
|
1722
|
+
* THE COMPUTER'S HEALTH (owner, 2026-11-15: "the computer sometimes crashes from RAM/GPU load"). The Remote daemon reads
|
|
1723
|
+
* a few numbers of its own machine every 15 seconds, without a model and without sudo, and seals one `device.health`
|
|
1724
|
+
* body for each paired phone and browser. It travels on the TRANSIENT LANE (envelopes.ts), device-wide: the relay passes
|
|
1725
|
+
* it on to a phone that is there and keeps, buffers and records none of it, so the server never sees or stores a sample.
|
|
1726
|
+
*
|
|
1727
|
+
* Every field is a number, an enum or a flag, except a process's NAME: the program's basename (`ps -o comm=`), never its
|
|
1728
|
+
* arguments, its path or a window title. healthRule refuses a name that looks like a path or an argument, and refuses a
|
|
1729
|
+
* level that is not what healthLevel says of the numbers, so no sender can call a critical computer green.
|
|
1730
|
+
*
|
|
1731
|
+
* A reading that failed is null, never 0. `gpu_busy` is the GPU's own "Device Utilization %" reading (IOAccelerator),
|
|
1732
|
+
* 0 to 100, passed through as the device states it: no figure computed by the sender. Memory and load travel as counts
|
|
1733
|
+
* (MB, the load average times 100, the cores); a surface derives a share from them (healthView in the client).
|
|
1734
|
+
*/
|
|
1735
|
+
|
|
1736
|
+
/** How often the daemon samples, and how far back "swap growing" looks. */
|
|
1737
|
+
export const HEALTH_SAMPLE_MS = 15_000;
|
|
1738
|
+
export const SWAP_GROWTH_WINDOW_MS = 120_000;
|
|
1739
|
+
/** Swap that grew by at least this much over the window is "growing" (a few MB of churn is not). */
|
|
1740
|
+
export const SWAP_GROWTH_MIN_MB = 64;
|
|
1741
|
+
/** Below this share of the memory free (with swap growing) the computer is red. */
|
|
1742
|
+
export const LOW_MEMORY_SHARE = 0.05;
|
|
1743
|
+
/** An hour of samples, in memory only (the client's history; never stored). */
|
|
1744
|
+
export const HEALTH_HISTORY_MS = 3_600_000;
|
|
1745
|
+
export const MAX_PROCESS_NAME = 64;
|
|
1746
|
+
|
|
1747
|
+
export const HEALTH_LEVELS = ["green", "yellow", "red", "unknown"] ;
|
|
1748
|
+
|
|
1749
|
+
/** macOS kern.memorystatus_vm_pressure_level 1, 2, 4; Linux PSI memory (`some`/`full` avg10). */
|
|
1750
|
+
export const MEMORY_PRESSURES = ["normal", "warn", "critical"] ;
|
|
1751
|
+
|
|
1752
|
+
export const HEALTH_REASONS = ["pressure_critical", "low_memory_swap_growing", "pressure_warn", "swap_growing"] ;
|
|
1753
|
+
|
|
1754
|
+
const MB = int(0, 16_777_216);
|
|
1755
|
+
export const HEALTH_PROCESS_SPEC = object({ name: text(MAX_PROCESS_NAME, 1), memory_mb: MB });
|
|
1756
|
+
|
|
1757
|
+
export const HEALTH_BODY_SPEC = object({
|
|
1758
|
+
sampled_at: int(0),
|
|
1759
|
+
level: oneOf(HEALTH_LEVELS),
|
|
1760
|
+
reasons: list(oneOf(HEALTH_REASONS), HEALTH_REASONS.length),
|
|
1761
|
+
pressure: nullable(oneOf(MEMORY_PRESSURES)),
|
|
1762
|
+
memory_total_mb: nullable(MB),
|
|
1763
|
+
memory_free_mb: nullable(MB),
|
|
1764
|
+
swap_used_mb: nullable(MB),
|
|
1765
|
+
/** Swap used now minus SWAP_GROWTH_WINDOW_MS ago; null until the daemon has a reading that old. */
|
|
1766
|
+
swap_growth_mb: nullable(int(-16_777_216, 16_777_216)),
|
|
1767
|
+
/** The one-minute load average times 100, and the logical cores it is shared by. */
|
|
1768
|
+
load_centi: nullable(int(0, 100_000_000)),
|
|
1769
|
+
cores: nullable(int(1, 4096)),
|
|
1770
|
+
gpu_busy: nullable(int(0, 100)),
|
|
1771
|
+
/** The three programs holding the most memory, by basename, summed over their processes. */
|
|
1772
|
+
top: list(HEALTH_PROCESS_SPEC, 3),
|
|
1773
|
+
/** True while the daemon starts no new session (level red); running sessions continue. */
|
|
1774
|
+
refusing: bool(),
|
|
1775
|
+
});
|
|
1776
|
+
|
|
1777
|
+
/**
|
|
1778
|
+
* THE THRESHOLDS, ONE PURE FUNCTION (the daemon, the CLI line and every surface read this). Red: pressure critical, or
|
|
1779
|
+
* under 5 % of the memory free while swap grew for two minutes. Yellow: pressure warn, or swap growing. Unknown: no
|
|
1780
|
+
* reading to judge by at all. Green otherwise.
|
|
1781
|
+
*/
|
|
1782
|
+
export function healthLevel(input ) {
|
|
1783
|
+
const swapGrowing = input.swap_growth_mb !== null && input.swap_growth_mb >= SWAP_GROWTH_MIN_MB;
|
|
1784
|
+
const share = input.memory_total_mb && input.memory_free_mb !== null ? input.memory_free_mb / input.memory_total_mb : null;
|
|
1785
|
+
const reasons = [];
|
|
1786
|
+
if (input.pressure === "critical") reasons.push("pressure_critical");
|
|
1787
|
+
if (share !== null && share < LOW_MEMORY_SHARE && swapGrowing) reasons.push("low_memory_swap_growing");
|
|
1788
|
+
if (input.pressure === "warn") reasons.push("pressure_warn");
|
|
1789
|
+
if (swapGrowing) reasons.push("swap_growing");
|
|
1790
|
+
if (reasons.includes("pressure_critical") || reasons.includes("low_memory_swap_growing")) return { level: "red", reasons };
|
|
1791
|
+
if (reasons.length > 0) return { level: "yellow", reasons };
|
|
1792
|
+
if (input.pressure === null && share === null && input.swap_growth_mb === null) return { level: "unknown", reasons };
|
|
1793
|
+
return { level: "green", reasons };
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1796
|
+
/**
|
|
1797
|
+
* A NAME THAT IS A PROGRAM'S BASENAME AND NOTHING ELSE. Refused: a path separator, a control character, a leading dash,
|
|
1798
|
+
* an argument after a space (` -x`, ` --flag`), an `=` (a setting), a URL scheme. Spaces and brackets stay: "Google
|
|
1799
|
+
* Chrome Helper (Renderer)" is one program's name.
|
|
1800
|
+
*/
|
|
1801
|
+
export function processNameRefusal(name ) {
|
|
1802
|
+
if (name.length === 0 || name.length > MAX_PROCESS_NAME) return "length";
|
|
1803
|
+
if (/[/\\]/.test(name)) return "a path";
|
|
1804
|
+
if (/[\u0000-\u001f\u007f]/.test(name)) return "a control character";
|
|
1805
|
+
if (/^-|\s-{1,2}\S|=|:\/\//.test(name)) return "an argument";
|
|
1806
|
+
return null;
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
/** The rules between fields, after the schema (events.ts validateEventBody). */
|
|
1810
|
+
export function healthRule(body ) {
|
|
1811
|
+
for (const p of body.top) {
|
|
1812
|
+
const bad = processNameRefusal(p.name);
|
|
1813
|
+
if (bad) return `top: a process name with ${bad}`;
|
|
1814
|
+
}
|
|
1815
|
+
if (new Set(body.top.map((p) => p.name)).size !== body.top.length) return "top: a name twice";
|
|
1816
|
+
if (body.top.some((p, n) => n > 0 && p.memory_mb > body.top[n - 1] .memory_mb)) return "top: largest first";
|
|
1817
|
+
if (body.memory_total_mb !== null && body.memory_free_mb !== null && body.memory_free_mb > body.memory_total_mb) return "memory_free_mb: above the total";
|
|
1818
|
+
const judged = healthLevel(body);
|
|
1819
|
+
if (judged.level !== body.level || judged.reasons.join() !== body.reasons.join()) return "level: not what the numbers say";
|
|
1820
|
+
if (body.refusing && body.level !== "red") return "refusing: only while red";
|
|
1821
|
+
return null;
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1720
1824
|
// ---- packages/remote-protocol/src/latency.ts
|
|
1721
1825
|
/**
|
|
1722
1826
|
* HOW LONG EACH HOP TOOK (owner, 2026-11-07: a prompt sent while the agent is busy waits, and the app must show it).
|
|
@@ -1734,6 +1838,41 @@ export function deliveryHops(r )
|
|
|
1734
1838
|
return { to_relay_ms: span(r.sent_at, r.relay_ack_seen_at), on_computer_ms: span(r.received_at, r.accepted_at) };
|
|
1735
1839
|
}
|
|
1736
1840
|
|
|
1841
|
+
// ---- packages/remote-protocol/src/desk.ts
|
|
1842
|
+
/**
|
|
1843
|
+
* CONTINUE A SESSION ON THIS COMPUTER (release 36, owner 2026-11-15; docs/remote-agents/DESK-SESSIONS.md). The computer's
|
|
1844
|
+
* newest Claude Code sessions in GRANTED projects, sealed in device.inventory `desk_sessions`, only for a phone that asked
|
|
1845
|
+
* `inventory.get` `desk_sessions` (an older phone refuses unknown keys and never receives it). Per session ONLY: Claude
|
|
1846
|
+
* Code's own session id, the project's id, the last activity, a title of at most 80 characters (Claude Code's own summary,
|
|
1847
|
+
* else the first line typed) and the model when recorded. Never more of the transcript. A phone continues one with
|
|
1848
|
+
* `agent.start` `resume` = `session_ref` under that project; the computer checks it is in its own list, that the project is
|
|
1849
|
+
* granted, and that nothing on the computer holds it (`in_use`).
|
|
1850
|
+
*/
|
|
1851
|
+
|
|
1852
|
+
export const MAX_DESK_SESSIONS = 20;
|
|
1853
|
+
export const MAX_DESK_TITLE = 80;
|
|
1854
|
+
const CLAUDE_SESSION_REF = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
1855
|
+
|
|
1856
|
+
export const DESK_SESSION_SPEC = object({
|
|
1857
|
+
session_ref: text(36, 36),
|
|
1858
|
+
project_id: id("prj"),
|
|
1859
|
+
last_activity_at: int(0),
|
|
1860
|
+
title: nullable(text(MAX_DESK_TITLE, 1)),
|
|
1861
|
+
model: nullable(text(128, 1)),
|
|
1862
|
+
});
|
|
1863
|
+
|
|
1864
|
+
/** device.inventory's field (events.ts spreads it): sealed only for a phone that asked `inventory.get` `desk_sessions`. */
|
|
1865
|
+
export const DESK_INVENTORY_FIELDS = { desk_sessions: optional(list(DESK_SESSION_SPEC, MAX_DESK_SESSIONS)) } ;
|
|
1866
|
+
|
|
1867
|
+
/** The rules between fields: a uuid each, each once, each under a project the same inventory lists. → null, or what is wrong. */
|
|
1868
|
+
export function deskRule(desk , projects ) {
|
|
1869
|
+
const rows = desk ?? [];
|
|
1870
|
+
if (rows.some((d) => !CLAUDE_SESSION_REF.test(d.session_ref))) return "a session_ref is Claude Code's own uuid";
|
|
1871
|
+
if (new Set(rows.map((d) => d.session_ref)).size !== rows.length) return "a session twice";
|
|
1872
|
+
if (rows.some((d) => !projects.some((p) => p.project_id === d.project_id))) return "under a project the inventory lists";
|
|
1873
|
+
return null;
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1737
1876
|
// ---- packages/remote-protocol/src/state-machine.ts
|
|
1738
1877
|
/**
|
|
1739
1878
|
* DELIVERY AND EXECUTION, AS A PURE FUNCTION. One command's state, from the phone's draft to its end:
|
|
@@ -2477,6 +2616,11 @@ export const COMMAND_PAYLOAD_SPECS = {
|
|
|
2477
2616
|
* An older computer refuses the unknown field; the phone then asks again with `extended` alone (client-core.ts).
|
|
2478
2617
|
*/
|
|
2479
2618
|
model_switch: optional(bool()),
|
|
2619
|
+
/**
|
|
2620
|
+
* Release 36: this phone reads `desk_sessions` (events.ts) and may continue one. Only with `extended`; an older computer
|
|
2621
|
+
* drops the unknown field, so the phone asks it by a probe of its own (client-core.ts, inventory-asks.ts).
|
|
2622
|
+
*/
|
|
2623
|
+
desk_sessions: optional(bool()),
|
|
2480
2624
|
}),
|
|
2481
2625
|
/** This computer's remote settings, each optional. Pausing from the phone is soft; `worktrust remote disable` at the
|
|
2482
2626
|
* desk is the hard off, which no message can undo. */
|
|
@@ -2636,6 +2780,7 @@ export function validateCommandPayload (type , value
|
|
|
2636
2780
|
const i = payload ;
|
|
2637
2781
|
if (i.device_name !== undefined && (i.extended !== true || !deviceNameOk(i.device_name))) return refuse("payload", "$payload.device_name: printable words, with extended");
|
|
2638
2782
|
if (i.model_switch !== undefined && i.extended !== true) return refuse("payload", "$payload.model_switch: with extended");
|
|
2783
|
+
if (i.desk_sessions !== undefined && i.extended !== true) return refuse("payload", "$payload.desk_sessions: with extended");
|
|
2639
2784
|
}
|
|
2640
2785
|
if (type === "attachment.put") { const bad = attachmentRule(payload ); if (bad) return refuse("payload", `$payload: ${bad}`); }
|
|
2641
2786
|
if (type === "preview.render") { const bad = previewRule(payload ); if (bad) return refuse("payload", `$payload: ${bad}`); }
|
|
@@ -2753,6 +2898,7 @@ export const REJECT_REASONS = [
|
|
|
2753
2898
|
"busy", // the agent is mid-turn and the command needs it idle (a release: its tasks still run, or no slot for a pipeline)
|
|
2754
2899
|
"unreviewed", // the project's pipeline file was not reviewed at the keyboard, or changed since (2026-11-07)
|
|
2755
2900
|
"not_allowed", // the computer did not allow it at its keyboard (a browser endorsement without allow-endorse), or the sender may not (2026-11-09)
|
|
2901
|
+
"in_use", // release 36: the desk session to continue is open on the computer; sent only to a phone that asked `desk_sessions` (others hear `busy`)
|
|
2756
2902
|
] ;
|
|
2757
2903
|
|
|
2758
2904
|
export const FAIL_REASONS = ["agent_exited", "adapter_error", "not_ready", "timeout", "internal"] ;
|
|
@@ -2902,7 +3048,7 @@ export const EVENT_BODY_SPECS = {
|
|
|
2902
3048
|
agent_options: optional(list(AGENT_OPTIONS_SPEC, 16)),
|
|
2903
3049
|
modes_allowed: optional(list(oneOf(AGENT_MODES), AGENT_MODES.length)),
|
|
2904
3050
|
/** Part B (owner, 2026-11-12), only for an `extended` phone: the settings page's admin switch, folders, connections (crypto/admin.ts). */
|
|
2905
|
-
...ADMIN_INVENTORY_FIELDS,
|
|
3051
|
+
...ADMIN_INVENTORY_FIELDS, ...DESK_INVENTORY_FIELDS, // release 36: `desk_sessions`, only for a phone that asked (desk.ts)
|
|
2906
3052
|
sessions: list(
|
|
2907
3053
|
object({
|
|
2908
3054
|
session_id: id("ses"),
|
|
@@ -2940,19 +3086,16 @@ export const EVENT_BODY_SPECS = {
|
|
|
2940
3086
|
...TRANSFER_EVENT_SPECS,
|
|
2941
3087
|
/** The live preview (release 19, live-preview.ts): its state, and its frames on the transient lane only. */
|
|
2942
3088
|
...LIVE_EVENT_SPECS,
|
|
3089
|
+
/** The computer's health (health.ts), every 15 s on the transient lane, device-wide: passed on, kept by nobody. */
|
|
3090
|
+
"device.health": HEALTH_BODY_SPEC,
|
|
2943
3091
|
} ;
|
|
2944
3092
|
|
|
2945
3093
|
export const DEVICE_EVENT_TYPES = Object.keys(EVENT_BODY_SPECS) ;
|
|
2946
3094
|
|
|
2947
3095
|
/** The one device event about the computer as a whole; every other names a session. */
|
|
2948
|
-
export const DEVICE_SCOPED_EVENTS = new Set (["device.inventory", "project.created", "preview.targets", "preview.image", "preview.rendered", "release.updated", "release.page", "pipeline.updated", "agents.active"]);
|
|
3096
|
+
export const DEVICE_SCOPED_EVENTS = new Set (["device.inventory", "project.created", "preview.targets", "preview.image", "preview.rendered", "release.updated", "release.page", "pipeline.updated", "agents.active", "device.health"]);
|
|
2949
3097
|
/** Events that answer one command, so their envelope names it (command_id is required). */
|
|
2950
|
-
export const COMMAND_RECEIPT_EVENTS = new Set ([
|
|
2951
|
-
"command.device_received",
|
|
2952
|
-
"command.agent_accepted",
|
|
2953
|
-
"command.rejected",
|
|
2954
|
-
"command.queued",
|
|
2955
|
-
]);
|
|
3098
|
+
export const COMMAND_RECEIPT_EVENTS = new Set (["command.device_received", "command.agent_accepted", "command.rejected", "command.queued"]);
|
|
2956
3099
|
|
|
2957
3100
|
export const isDeviceEventType = (value ) =>
|
|
2958
3101
|
typeof value === "string" && Object.hasOwn(EVENT_BODY_SPECS, value);
|
|
@@ -3004,6 +3147,10 @@ export function validateEventBody (type , value
|
|
|
3004
3147
|
const bad = agentsActiveRule(checked.value );
|
|
3005
3148
|
if (bad) return refuse("payload", `$body: ${bad}`);
|
|
3006
3149
|
}
|
|
3150
|
+
if (type === "device.health") {
|
|
3151
|
+
const bad = healthRule(checked.value );
|
|
3152
|
+
if (bad) return refuse("payload", `$body: ${bad}`);
|
|
3153
|
+
}
|
|
3007
3154
|
if (type === "agent.attention") {
|
|
3008
3155
|
const a = validateAttention(value, "$body");
|
|
3009
3156
|
if (!a.ok) return refuse("payload", a.detail);
|
|
@@ -3016,6 +3163,7 @@ export function validateEventBody (type , value
|
|
|
3016
3163
|
}
|
|
3017
3164
|
// One report per (adapter, mode) since release 19: Claude Code structured and in a terminal are two reports.
|
|
3018
3165
|
if (new Set(inv.adapters.map((a) => `${a.adapter}/${a.mode}`)).size !== inv.adapters.length) return refuse("payload", "$body.adapters: an adapter twice");
|
|
3166
|
+
{ const desk = deskRule(inv.desk_sessions, inv.projects); if (desk) return refuse("payload", `$body.desk_sessions: ${desk}`); }
|
|
3019
3167
|
}
|
|
3020
3168
|
return checked;
|
|
3021
3169
|
}
|
|
@@ -3100,9 +3248,12 @@ export const COMMAND_ENVELOPE_SPEC = object({
|
|
|
3100
3248
|
* So the stream stays gap-free for every phone, whoever followed. Only the types below may take the lane.
|
|
3101
3249
|
*/
|
|
3102
3250
|
export const EVENT_LANES = ["transient"] ;
|
|
3103
|
-
export const TRANSIENT_EVENT_TYPES = new Set (["agent.screen", "preview.frame"]);
|
|
3104
|
-
/**
|
|
3105
|
-
|
|
3251
|
+
export const TRANSIENT_EVENT_TYPES = new Set (["agent.screen", "preview.frame", "device.health"]);
|
|
3252
|
+
/**
|
|
3253
|
+
* Types that may ONLY travel on the transient lane (a live preview's frames: never journaled, never replayed), and the
|
|
3254
|
+
* computer's health (health.ts, 2026-11-15): device-wide, so its lane is the device stream's, with its own rising number.
|
|
3255
|
+
*/
|
|
3256
|
+
export const TRANSIENT_ONLY_TYPES = new Set (["preview.frame", "device.health"]);
|
|
3106
3257
|
export const isTransientEvent = (e ) => e.lane === "transient";
|
|
3107
3258
|
|
|
3108
3259
|
export const EVENT_ENVELOPE_SPEC = object({
|
|
@@ -3243,9 +3394,10 @@ export function validateEventEnvelope(value ) {
|
|
|
3243
3394
|
if (!COMMAND_RECEIPT_EVENTS.has(type) && DEVICE_SCOPED_EVENTS.has(type) !== (e.session_id === null))
|
|
3244
3395
|
return refuse("shape", "$event.session_id: a session event names a session, a device event none");
|
|
3245
3396
|
if (COMMAND_RECEIPT_EVENTS.has(type) && e.command_id === null) return refuse("shape", "$event.command_id: a receipt names its command");
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3397
|
+
// A session's screen or frame names its session; the computer's health names none (DEVICE_SCOPED_EVENTS, checked above).
|
|
3398
|
+
if (isTransientEvent(e) && (!TRANSIENT_EVENT_TYPES.has(type) || e.command_id !== null || (e.session_id === null) !== DEVICE_SCOPED_EVENTS.has(type) || e.notify !== "none"))
|
|
3399
|
+
return refuse("shape", "$event.lane: only a pushed screen or frame of a session, or the computer's health, without a command or a push hint, is transient");
|
|
3400
|
+
if (TRANSIENT_ONLY_TYPES.has(type) && !isTransientEvent(e)) return refuse("shape", "$event.lane: a live preview's frame and the computer's health travel on the transient lane only");
|
|
3249
3401
|
return checked;
|
|
3250
3402
|
}
|
|
3251
3403
|
|
package/remote-run.mjs
CHANGED
|
@@ -15,7 +15,7 @@ import { fileURLToPath } from "node:url";
|
|
|
15
15
|
import * as P from "./remote-protocol.mjs";
|
|
16
16
|
import { loadPreviewGrants, loadRoots } from "./remote-store.mjs";
|
|
17
17
|
import { sessionProjects } from "./remote-projects.mjs";
|
|
18
|
-
import { ensureRemoteDir, gatewayOf, issuerKeys, loadDeskMarks, loadIdentity, loadKeys, loadPipelineReviews, loadProjects, loadSettings, readJson, remotePath, random, saveIdentity } from "./remote-store.mjs";
|
|
18
|
+
import { ensureRemoteDir, gatewayOf, isLoopbackGateway, issuerKeys, loadDeskMarks, loadIdentity, loadKeys, loadPipelineReviews, loadProjects, loadSettings, readJson, remotePath, random, saveIdentity } from "./remote-store.mjs";
|
|
19
19
|
import { openJournal } from "./remote-journal.mjs";
|
|
20
20
|
import { inventory as listAgents, offered } from "./remote-inventory.mjs";
|
|
21
21
|
|
|
@@ -34,7 +34,9 @@ import { createLivePreview } from "./remote-live-preview.mjs";
|
|
|
34
34
|
import { SETTING_WORDS } from "./remote-admin.mjs";
|
|
35
35
|
import { appendPipelineMark } from "./remote-steered.mjs";
|
|
36
36
|
import { createDaemonCore } from "./remote-daemon.mjs";
|
|
37
|
+
import { createDesk } from "./remote-desk-sessions.mjs";
|
|
37
38
|
import { connectGateway, webSocketAvailable } from "./remote-transport.mjs";
|
|
39
|
+
import { createHealthMonitor, fixtureReaders, HEALTH_REFUSAL, healthLine, keepHealth } from "./remote-health.mjs";
|
|
38
40
|
|
|
39
41
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
40
42
|
const log = (kind, fields = {}) => process.stderr.write(`${JSON.stringify({ at: new Date().toISOString(), kind, ...fields })}\n`);
|
|
@@ -42,6 +44,7 @@ const log = (kind, fields = {}) => process.stderr.write(`${JSON.stringify({ at:
|
|
|
42
44
|
const notice = (kind, fields) => {
|
|
43
45
|
if (kind === "browser_endorsed") process.stderr.write(` ! A browser was added by your phone ${fields.by}: ${fields.fingerprint}. See or remove it: npx worktrust remote phones\n`);
|
|
44
46
|
// Part B: a change approved in the app or on the web with the authenticator, signed by WorkTrust and verified here.
|
|
47
|
+
if (kind === "session_refused") process.stderr.write(` ! A new session from a phone or browser was refused: ${HEALTH_REFUSAL}. Running sessions continue.\n`);
|
|
45
48
|
if (kind === "settings_changed") process.stderr.write(` ! ${SETTING_WORDS[fields.setting] ?? "a remote setting"} changed from ${fields.by}, approved there with your authenticator. To keep every change at this keyboard: npx worktrust remote admin off\n`);
|
|
46
49
|
};
|
|
47
50
|
const logged = (kind, fields = {}) => { log(kind, fields); notice(kind, fields); };
|
|
@@ -135,7 +138,10 @@ export async function runDaemon({ say = (l) => process.stdout.write(`${l}\n`) }
|
|
|
135
138
|
// The live preview (release 19): the session's granted page, live, over the browser's pipe; one per computer.
|
|
136
139
|
const live = createLivePreview({ emit: (...a) => core.emit(...a), grants: loadPreviewGrants, env: () => agentEnv(loadSettings()), log, now: Date.now,
|
|
137
140
|
sessionProject: (id) => { const s = journal.session(id); return s ? loadProjects().find((p) => p.project_id === s.project_id) ?? null : null; } });
|
|
138
|
-
|
|
141
|
+
// Continue a session on this computer (release 36): its own Claude Code sessions in the projects a phone may reach.
|
|
142
|
+
const desk = createDesk({ projects: () => sessionProjects({ projects: loadProjects, roots: loadRoots, projectSecret: keys.projectSecret }), journal });
|
|
143
|
+
let health = null; // the sampler below (remote-health.mjs): every 15 s, local numbers, no model
|
|
144
|
+
const core = createDaemonCore({ local, issuerKeys: keysOf, journal, projectSecret: keys.projectSecret, attachments, preview, live, desk, now: Date.now, random, log: logged, health: () => health?.latest() ?? null, send: (f) => transport?.send(f) ?? false, inventory: (refresh) => inventory({ env: agentEnv(loadSettings()), refresh }), online: () => transport?.ready() ?? false, approvals: null });
|
|
139
145
|
const ctx = { journal, now: Date.now, random, deviceId: identity.device_id, emit: core.emit, paused: () => loadSettings().paused !== null || !loadSettings().enabled, phoneOnline: core.phoneOnline, controllers: core.controllers };
|
|
140
146
|
const approvals = createApprovals(ctx);
|
|
141
147
|
const socket = await approvals.listen(runDir);
|
|
@@ -144,13 +150,13 @@ export async function runDaemon({ say = (l) => process.stdout.write(`${l}\n`) }
|
|
|
144
150
|
// A session runs in a granted project or in an existing project inside a root (0.11.7), each by the inventory's id.
|
|
145
151
|
settings: loadSettings, projects: () => sessionProjects({ projects: loadProjects, roots: loadRoots, projectSecret: keys.projectSecret }), inventory: () => inventory({ env: agentEnv(loadSettings()) }), agentEnv: () => agentEnv(loadSettings()), replay: core.replay,
|
|
146
152
|
onTaskEnded: (id, outcome) => releases.taskEnded(id, outcome), onActivity: () => releases?.activity(),
|
|
147
|
-
onSessionsChanged: () => core.emit(null, "device.inventory", core.inventoryBody(false)), attachments });
|
|
153
|
+
onSessionsChanged: () => core.emit(null, "device.inventory", core.inventoryBody(false)), attachments, desk });
|
|
148
154
|
ctx.onApprovalOpened = sessions.onApprovalOpened; ctx.onApprovalSettled = sessions.onApprovalSettled;
|
|
149
155
|
// Terminal sessions (release 19, off until `worktrust remote terminal on`): Claude Code in tmux on WorkTrust's own socket.
|
|
150
156
|
const tmuxFile = listAgents({ env: agentEnv(loadSettings()) }).files.tmux;
|
|
151
157
|
const tmux = tmuxFile ? createTmux({ file: tmuxFile, config: writeTmuxConfig(runDir), env: agentEnv(loadSettings()) }) : NO_TMUX;
|
|
152
158
|
const terminal = createTerminalSessions({ journal, now: Date.now, emit: core.emit, settings: loadSettings, projects: loadProjects, inventory: () => inventory({ env: agentEnv(loadSettings()) }),
|
|
153
|
-
tmux, claudeFile: () => listAgents({ env: agentEnv(loadSettings()) }).files["claude-code"], replay: core.replay, running: () => sessions.runningCount(), detect: (lines) => detectScreen("claude-code", lines), approvals,
|
|
159
|
+
tmux, claudeFile: () => listAgents({ env: agentEnv(loadSettings()) }).files["claude-code"], replay: core.replay, running: () => sessions.runningCount(), detect: (lines) => detectScreen("claude-code", lines), approvals, desk,
|
|
154
160
|
onSessionsChanged: () => core.emit(null, "device.inventory", core.inventoryBody(false)) });
|
|
155
161
|
const registry = withTerminal(sessions, terminal);
|
|
156
162
|
// Releases and pipelines (2026-11-07): one queue for every release's tasks, the reviewed pipeline of each project.
|
|
@@ -168,8 +174,22 @@ export async function runDaemon({ say = (l) => process.stdout.write(`${l}\n`) }
|
|
|
168
174
|
if (frame.frame === "hello") core.receiveHello(frame.hello);
|
|
169
175
|
else if (frame.frame === "command") await core.receiveCommand(frame.envelope);
|
|
170
176
|
else if (frame.frame === "relay") { log("relay", { type: frame.event?.type ?? null }); if (frame.event?.type === "device.revoked") core.peerRevoked(frame.event); }
|
|
171
|
-
else if (frame.frame === "error")
|
|
177
|
+
else if (frame.frame === "error") {
|
|
178
|
+
log("gateway_error", { reason: typeof frame.reason === "string" ? frame.reason.slice(0, 40) : null });
|
|
179
|
+
// A gateway older than device.health answers it `error: shape` (and closes nothing): rest the samples half an hour.
|
|
180
|
+
if (frame.reason === "shape" && Date.now() - healthSentAt < 5000) { healthRestUntil = Date.now() + 30 * 60_000; log("health_rested", { minutes: 30 }); }
|
|
181
|
+
}
|
|
172
182
|
};
|
|
183
|
+
// THE COMPUTER'S HEALTH (2026-11-15): kept here for `remote status` and the menu, said in the run terminal when it turns
|
|
184
|
+
// red or back, and sealed for the paired phones and browsers on the transient lane (the gateway keeps none of it).
|
|
185
|
+
let healthSentAt = 0, healthRestUntil = 0, healthSaid = null;
|
|
186
|
+
const healthFixture = isLoopbackGateway(gateway) ? process.env.WORKTRUST_REMOTE_HEALTH_FIXTURE ?? null : null; // tests on the dev relay only
|
|
187
|
+
health = createHealthMonitor({ log, ...(healthFixture ? fixtureReaders(healthFixture) : {}), onSample: (body) => {
|
|
188
|
+
keepHealth(body);
|
|
189
|
+
if (body.level !== healthSaid && (body.level === "red" || healthSaid === "red")) process.stderr.write(`${healthLine(body)}\n`);
|
|
190
|
+
healthSaid = body.level;
|
|
191
|
+
if (Date.now() >= healthRestUntil && transport?.ready()) { healthSentAt = Date.now(); core.emitHealth(body); }
|
|
192
|
+
} });
|
|
173
193
|
let sentCode = null;
|
|
174
194
|
const registerCode = (again = false) => {
|
|
175
195
|
const invite = readJson("invite.json");
|
|
@@ -186,6 +206,7 @@ export async function runDaemon({ say = (l) => process.stdout.write(`${l}\n`) }
|
|
|
186
206
|
if (stopping) return;
|
|
187
207
|
stopping = true;
|
|
188
208
|
approvals.close();
|
|
209
|
+
health.stop();
|
|
189
210
|
await pipelines.stopAll();
|
|
190
211
|
await live.stopAll(); // the browser ended, its profile removed
|
|
191
212
|
await registry.stopAll(); // the structured agents; a terminal session lives on in tmux
|
|
@@ -202,5 +223,6 @@ export async function runDaemon({ say = (l) => process.stdout.write(`${l}\n`) }
|
|
|
202
223
|
const grantsChanged = () => { const now = [...loadRoots().map((r) => r.root_id), "|", ...loadProjects().map((p) => p.project_id)].join(","); const changed = grants !== null && now !== grants; grants = now; return changed; };
|
|
203
224
|
setInterval(() => { const s = loadSettings(); if (!s.enabled) stop(0); registerCode(); releases.poll(); try { if (grantsChanged()) core.emit(null, "device.inventory", core.inventoryBody(false)); } catch { /* an unreadable list: told at the next ask */ } }, 3000).unref();
|
|
204
225
|
releases.schedule(); // queued tasks a restart kept
|
|
226
|
+
health.start();
|
|
205
227
|
return new Promise(() => {});
|
|
206
228
|
}
|
package/remote-sessions.mjs
CHANGED
|
@@ -32,7 +32,6 @@ const LEDGER_EVERY_MS = 10 * 60_000;
|
|
|
32
32
|
/** Per agent: the shape of its own session id (a resume names one), and a fresh stream state. */
|
|
33
33
|
const AGENT_ID = { "claude-code": isClaudeSessionId, codex: isCodexThreadId, opencode: isOpenCodeSessionId };
|
|
34
34
|
const FRESH_STATE = { "claude-code": emptyClaudeState, codex: emptyCodexState, opencode: emptyOpenCodeState };
|
|
35
|
-
|
|
36
35
|
export { createCoalescer } from "./remote-coalesce.mjs"; // kept here for the modules that import it from sessions
|
|
37
36
|
|
|
38
37
|
export function createSessions(ctx) {
|
|
@@ -216,9 +215,10 @@ export function createSessions(ctx) {
|
|
|
216
215
|
const refused = P.checkStart(payload, adapterOf(ctx.inventory(), payload.adapter)); if (refused) return refused;
|
|
217
216
|
const choice = startChoice(payload, project.project_id, ctx.inventory(), ctx.settings(), known); if (typeof choice === "string") return choice;
|
|
218
217
|
if (!AGENT_ID[payload.adapter] || (payload.resume !== null && !AGENT_ID[payload.adapter](payload.resume))) return "unsupported";
|
|
218
|
+
const desk = payload.resume !== null && env.task !== true ? (ctx.desk ? ctx.desk.resumable(payload.resume, project.project_id) : "not_found") : null; if (desk) return desk; // release 36: only a session of the computer's own list, free
|
|
219
219
|
if (deskGranted(payload.adapter, project.path)) return "not_allowed"; // S0: Codex's own allow rules cannot be denied per session
|
|
220
220
|
const s = { session_id: env.session_id, project_id: project.project_id, projectPath: project.path, adapter: payload.adapter, model: payload.model, mode: payload.permission_mode,
|
|
221
|
-
agent_ref: payload.resume ?? (payload.adapter === "codex" ? null : payload.adapter === "opencode" ? mintOpenCodeSessionId(ctx.now(), ctx.random) : randomUUID()), how: "started", first: ctx.now(), queue: [], state: FRESH_STATE[payload.adapter](),
|
|
221
|
+
agent_ref: payload.resume ?? (payload.adapter === "codex" ? null : payload.adapter === "opencode" ? mintOpenCodeSessionId(ctx.now(), ctx.random) : randomUUID()), how: payload.resume !== null && env.task !== true ? "attached" : "started", first: ctx.now(), queue: [], state: FRESH_STATE[payload.adapter](),
|
|
222
222
|
coalesce: createCoalescer({ now: ctx.now }), attention: null, command_id: null, waiting: null, turnOpen: false, run: null, steers: [], interrupting: false, ownTurn: null, task: env.task === true, tokens: P.NO_TOKENS, subagents: new Map(), turnStartedAt: null, name: payload.name ?? null, active: 0, countedTurn: null,
|
|
223
223
|
agentMode: payload.agent_mode ?? null, effort: choice.effort, extraIds: choice.extraProjectIds, extraPaths: choice.extras.map((p) => p.path) };
|
|
224
224
|
live.set(s.session_id, s);
|
|
@@ -85,6 +85,7 @@ export function createTerminalSessions(ctx) {
|
|
|
85
85
|
const project = ctx.projects().find((p) => p.project_id === env.project_id);
|
|
86
86
|
if (!project) return "not_found";
|
|
87
87
|
if (payload.resume !== null && !UUID.test(payload.resume)) return "unsupported";
|
|
88
|
+
const held = payload.resume !== null ? (ctx.desk ? ctx.desk.resumable(payload.resume, project.project_id) : "not_found") : null; if (held) return held; // release 36: the computer's own list, free
|
|
88
89
|
const s = sessionOf({ session_id: env.session_id, project_id: project.project_id, projectPath: project.path, name: payload.name ?? null, model: payload.model, origin: "phone", how: "started",
|
|
89
90
|
tmux: tmuxNameOf(env.session_id), agent_ref: payload.resume ?? randomUUID(), command_id: env.command_id });
|
|
90
91
|
let argv;
|
package/worktrust.mjs
CHANGED
|
@@ -83,7 +83,7 @@ const command = args.includes("--help") ? "help" : args.includes("--version") ?
|
|
|
83
83
|
const flag = (name) => { const at = args.indexOf(`--${name}`); return at >= 0 ? args[at + 1] : undefined; };
|
|
84
84
|
const has = (name) => args.includes(`--${name}`);
|
|
85
85
|
/** This CLI's version, said to the door so the app can tell which computer runs an old one (check-cli-package holds it equal to package.json). */
|
|
86
|
-
const CLI_VERSION = "0.11.
|
|
86
|
+
const CLI_VERSION = "0.11.13";
|
|
87
87
|
/**
|
|
88
88
|
* HOW THIS CLI MEASURES, AS A NUMBER OF ITS OWN (0.10.31; owner, 2026-10-28: 0.10.30 offered a re-measure it had no reason
|
|
89
89
|
* to offer). Raised ONLY when what is measured changes: the timeline, the seconds, the tokens, the steering, the session
|
|
@@ -119,7 +119,7 @@ const ORIGIN = (flag("origin") ?? process.env.WORKTRUST_ORIGIN ?? "https://app.w
|
|
|
119
119
|
const MCP = flag("url") ?? process.env.WORKTRUST_MCP_URL ?? `${ORIGIN}/api/mcp`;
|
|
120
120
|
const HOME_DIR = join(homedir(), ".worktrust");
|
|
121
121
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
122
|
-
const SCRIPTS = ["credential-store.mjs", "remote-protocol.mjs", "remote-store.mjs", "remote-policy.mjs", "remote-journal.mjs", "remote-steered.mjs", "remote-inventory.mjs", "remote-claude-events.mjs", "remote-claude-progress.mjs", "remote-attachments.mjs", "remote-preview.mjs", "remote-coalesce.mjs", "remote-steering.mjs", "remote-codex-events.mjs", "remote-adapter-codex.mjs", "remote-opencode-events.mjs", "remote-adapter-opencode.mjs", "remote-opencode-session.mjs", "remote-adapter-terminal.mjs", "remote-terminal-sessions.mjs", "remote-terminal-cli.mjs", "remote-screen-states.mjs", "remote-screen-approvals.mjs", "remote-screen-push.mjs", "remote-cdp.mjs", "remote-live-preview.mjs", "remote-projects.mjs", "remote-pipeline-config.mjs", "remote-pipeline-parsers.mjs", "remote-pipeline.mjs", "remote-releases.mjs", "remote-release-plans.mjs", "remote-adapter-claude-code.mjs", "remote-approval-bridge.mjs", "remote-approvals.mjs", "remote-sessions.mjs", "remote-session-list.mjs", "remote-changes.mjs", "remote-endorse.mjs", "remote-daemon.mjs", "remote-transport.mjs", "remote-run.mjs", "remote-service.mjs", "remote-pairing.mjs", "remote-qr.mjs", "remote-cli.mjs", "remote-agent-switch.mjs", "remote-settings.mjs", "folder-picker.mjs", "cli-menu.mjs", "cli-menu-remote.mjs", "cli-colour.mjs", "cli-stop.mjs", "cli-look.mjs", "node-guide.mjs", "remote-countdown.mjs", "remote-connections.mjs", "remote-admin.mjs", "credential-vault.mjs", "credential-vault-scripts.mjs", "credential-decoy.mjs", "history-outbox.mjs", "setup-mcp.mjs", "log-session.mjs", "count-behaviour.mjs", "transcript-readers.mjs", "session-readers.mjs", "session-databases.mjs", "session-local-models.mjs", "config-edits.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "export-facts.mjs", "stack-rules.mjs", "runtime-install.mjs", "orchestration-contract.mjs", "orchestration-evidence.mjs", "orchestration-report.mjs", "claude-mod.mjs", "package-integrity.mjs", "worktrust-launch.mjs", "project-modes.mjs", "commit-rules.mjs", "git-commits.mjs", "self-update.mjs", "history-progress.mjs"];
|
|
122
|
+
const SCRIPTS = ["credential-store.mjs", "remote-protocol.mjs", "remote-store.mjs", "remote-policy.mjs", "remote-journal.mjs", "remote-steered.mjs", "remote-inventory.mjs", "remote-claude-events.mjs", "remote-claude-progress.mjs", "remote-attachments.mjs", "remote-preview.mjs", "remote-coalesce.mjs", "remote-steering.mjs", "remote-codex-events.mjs", "remote-adapter-codex.mjs", "remote-opencode-events.mjs", "remote-adapter-opencode.mjs", "remote-opencode-session.mjs", "remote-adapter-terminal.mjs", "remote-terminal-sessions.mjs", "remote-terminal-cli.mjs", "remote-screen-states.mjs", "remote-screen-approvals.mjs", "remote-screen-push.mjs", "remote-cdp.mjs", "remote-live-preview.mjs", "remote-projects.mjs", "remote-pipeline-config.mjs", "remote-pipeline-parsers.mjs", "remote-pipeline.mjs", "remote-releases.mjs", "remote-release-plans.mjs", "remote-adapter-claude-code.mjs", "remote-approval-bridge.mjs", "remote-approvals.mjs", "remote-sessions.mjs", "remote-session-list.mjs", "remote-desk-sessions.mjs", "remote-changes.mjs", "remote-endorse.mjs", "remote-daemon.mjs", "remote-transport.mjs", "remote-run.mjs", "remote-service.mjs", "remote-pairing.mjs", "remote-qr.mjs", "remote-cli.mjs", "remote-agent-switch.mjs", "remote-settings.mjs", "folder-picker.mjs", "cli-menu.mjs", "cli-menu-remote.mjs", "cli-colour.mjs", "cli-stop.mjs", "cli-look.mjs", "node-guide.mjs", "remote-countdown.mjs", "remote-connections.mjs", "remote-admin.mjs", "remote-health.mjs", "credential-vault.mjs", "credential-vault-scripts.mjs", "credential-decoy.mjs", "history-outbox.mjs", "setup-mcp.mjs", "log-session.mjs", "count-behaviour.mjs", "transcript-readers.mjs", "session-readers.mjs", "session-databases.mjs", "session-local-models.mjs", "config-edits.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "export-facts.mjs", "stack-rules.mjs", "runtime-install.mjs", "orchestration-contract.mjs", "orchestration-evidence.mjs", "orchestration-report.mjs", "claude-mod.mjs", "package-integrity.mjs", "worktrust-launch.mjs", "project-modes.mjs", "commit-rules.mjs", "git-commits.mjs", "self-update.mjs", "history-progress.mjs"];
|
|
123
123
|
/** The modules the scripts import by name from beside them; a download keeps that name. */
|
|
124
124
|
const IMPORTED = new Set(["project-modes.mjs", "transcript-readers.mjs", "session-readers.mjs", "session-databases.mjs", "session-local-models.mjs", "config-edits.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "export-facts.mjs", "stack-rules.mjs", "runtime-install.mjs", "orchestration-contract.mjs", "orchestration-evidence.mjs", "orchestration-report.mjs", "commit-rules.mjs", "git-commits.mjs"]);
|
|
125
125
|
const downloaded = (name) => (IMPORTED.has(name) ? name : `${name}.download.mjs`);
|