dsh-plugin-mesh 0.3.30 → 0.3.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AGENTS.md ADDED
@@ -0,0 +1,165 @@
1
+ # AGENTS.md — operating guide for coding agents
2
+
3
+ This file is for AI agents working **on** this repository. If you only want to
4
+ **use** the plugin, read [`llms.txt`](./llms.txt) instead — it is short and factual.
5
+
6
+ Project: `dsh-plugin-mesh`, a cordis plugin for DeepSeek Harness (dsh). MIT.
7
+ Language note: `README.md` is Chinese and long (it contains design rationale and
8
+ post-mortems). This file is the English, task-oriented entry point.
9
+
10
+ ---
11
+
12
+ ## 1. What this codebase is
13
+
14
+ A dsh plugin has two halves that ship in one npm package:
15
+
16
+ | Half | Entry | Runs in |
17
+ |---|---|---|
18
+ | Host | `lib/index.js` | the dsh host process (Node) |
19
+ | Client | `client/client.js` | the browser/Electron renderer |
20
+
21
+ `client/client.js` is a **hand-written bundle**, not built by a bundler. It must
22
+ call `window.__ModuleLoader__.load({ id: "<package name>", factory })` and the `id`
23
+ must equal the package name exactly. It may only `require("react")` and
24
+ `require("react/jsx-runtime")`.
25
+
26
+ The plugin is mounted by `dsh.bundle.patch` → `cordis.patch.yml`, which does one
27
+ `insert` of `{ id: mesh, name: dsh-plugin-mesh }`. Client UI is declared by
28
+ `dsh.client.platform = "web"` plus an `exports["./client"]` entry.
29
+
30
+ There is a third, separate program: `sidecar/` is a **Go** binary that runs a
31
+ userspace Tailscale node (tsnet). It is compiled per platform, published as GitHub
32
+ release assets, and downloaded at runtime by `lib/tsnet/download.js`.
33
+
34
+ ## 2. Zero to running (development)
35
+
36
+ ```bash
37
+ npm install # dev deps only; @deepseek-ai/* come from the host
38
+ npm run check # fast, always run this first
39
+ npm test # full suite, ~90 s, network-free
40
+ ```
41
+
42
+ To run a real isolated host (two instances can discover each other on one machine):
43
+
44
+ ```bash
45
+ MACHINE=meshdev PORT=45918 ./dev-setup.sh meshtest /tmp/dsh-mesh-dev
46
+ DSH_HOME=/tmp/dsh-mesh-dev ELECTRON_RUN_AS_NODE=1 \
47
+ "/Applications/DSH Desktop.app/Contents/MacOS/DSH Desktop" \
48
+ dev-boot.mjs --profile meshtest --port 8877 --no-open
49
+ ```
50
+
51
+ `dev-setup.sh` copies the plugin into the profile's `node_modules`; a **symlink
52
+ will not work** — dsh's profile package resolver rejects packages whose realpath
53
+ is outside `<profile>/node_modules`.
54
+
55
+ `dev-boot.mjs` exists because `desktop-cli.js` only installs the profile package
56
+ resolver inside `app.asar`; this installation is unpacked, so the resolver has to
57
+ be installed manually.
58
+
59
+ The dev host's web server is **not** behind DSH Desktop's request gate, so
60
+ `/mesh/api/*` can be driven with curl there — production cannot (it returns 403
61
+ unless the request carries the renderer token).
62
+
63
+ ## 3. Hard constraints — do not violate
64
+
65
+ 1. **Never let a probe failure look like a negative fact.** `ENOENT` means "not
66
+ installed"; a timeout means "we did not get an answer". These must stay
67
+ distinguishable and visible (`probeErrors`, `runtimesIncomplete`,
68
+ `routeDecision`, `dispatchError`). Collapsing them caused a real incident: a
69
+ busy Mac reported "no runtimes installed".
70
+ 2. **Never leave a documented command that does not exist.** The README is served
71
+ verbatim on the npm page, and the plugin catalog explicitly checks descriptions
72
+ against code. A made-up flag was caught in review.
73
+ 3. **Changing a schema `.default()` is usually not enough.** `cordis.patch.yml` in
74
+ the repo and in the user's profile pin values that override the default. Check
75
+ all three:
76
+ ```bash
77
+ grep -rn "theKey" cordis.patch.yml ~/.dsh/profiles/*/cordis.patch.yml
78
+ ```
79
+ 4. **`config:` in a patch is replaced wholesale, not merged.** Adding one key
80
+ without restating the others silently resets them to schema defaults.
81
+ 5. **Verify side-effecting scripts by running them, not by `bash -n`.** A reference
82
+ to an undefined `$REPO_ROOT` passed syntax checking and turned "delayed restart"
83
+ into a silent no-restart. Use `scripts/restart-dsh.sh --check-only` to exercise
84
+ the preflight without touching the running app.
85
+ 6. **`node --check` cannot catch TDZ.** `scripts/check-tdz.mjs` exists for that;
86
+ keep it in `npm run check`.
87
+ 7. **Do not trust "it looks fine".** This project has repeatedly shipped
88
+ "wired but not actually connected" changes (a gate that was only mentioned in a
89
+ comment, `install.sh` not copying `scripts/`, a placeholder that hid a missing
90
+ file). When you add a gate, prove it has teeth: break the input and watch it fail.
91
+
92
+ ## 4. Architecture map
93
+
94
+ ```
95
+ lib/index.js host half: config schema, discovery orchestration, peer HTTP
96
+ server, agent tools, UI routes, inbound task routing, wake logic
97
+ lib/discovery.js UDP multicast registry, endpoint-level liveness, fingerprint claim
98
+ lib/scan.js active subnet scan
99
+ lib/identity.js persistent UUID + OS machine fingerprint (claim only)
100
+ lib/conversation.js conversation key + reply target (both sides compute independently)
101
+ lib/capabilities.js runtime/GPU/capability collection, sanitising, staleness
102
+ lib/prompt.js task prompt text generation (pure, unit-tested)
103
+ lib/tsnet/ sidecar download/verify, process manager, tailnet HTTP bridge
104
+ client/client.js renderer: sidebar icon + Mesh panel, hand-written bundle
105
+ sidecar/ Go: tsnet node + control HTTP API + port forwarding
106
+ scripts/ build/release/verify/push/submit tooling
107
+ docs/ GitHub Pages showcase site
108
+ ```
109
+
110
+ Key data flow for an inbound task: `POST /mesh/v1/task` → `handleInboundTask` →
111
+ `classifyInbound` (gates: noWake, min length, greeting, per-thread cap, cooldown) →
112
+ reuse the session bound to the conversation key, or create one via `wakeAgent` →
113
+ inject the prompt → the peer's agent replies by calling `mesh_run`.
114
+
115
+ ## 5. Test map
116
+
117
+ | Suite | Command | Covers |
118
+ |---|---|---|
119
+ | Core | `npm run selftest` | discovery, endpoints, conversation keys (52) |
120
+ | Capabilities | `npm run selftest:caps` | sanitising, GPU parsing, retry-on-timeout, claim rules (64) |
121
+ | Client render | `npm run selftest:client` | bundle loads, `apply()` registers slots, component output (12) |
122
+ | Prompt | `npm run selftest:prompt` | reply target must be a machine name, not `machine/user` (10) |
123
+
124
+ `lib/_selftest-newsession.mjs` is a manual end-to-end check that needs a dev host
125
+ running; it is deliberately not part of `npm test` because it creates real agent
126
+ sessions (costs tokens).
127
+
128
+ Everything in `npm test` is **network-free** — the discovery self-test uses a
129
+ private multicast group so it cannot pollute a real LAN.
130
+
131
+ ## 6. Releasing
132
+
133
+ ```bash
134
+ npm run check && npm test
135
+ npm run release-plugin -- --publish # tarball -> GitHub release -> LAN mirror
136
+ npm publish # npm; publishConfig pins the public registry
137
+ ```
138
+
139
+ Then upgrade other machines with the command printed by `release-plugin.sh`.
140
+ If the dsh host is on this machine, `scripts/restart-dsh.sh --install [delay]`
141
+ restarts it from launchd so the restart survives killing the app.
142
+
143
+ Notes:
144
+ - `scripts/check-tarball.mjs` validates the **published artifact**, not the source
145
+ tree, because `files` in `package.json` decides what users actually get.
146
+ - npm's "staged publishing" makes a new version appear in metadata before its
147
+ tarball is downloadable. Do not declare success until the tarball returns 200.
148
+ - Keep `llms.txt` and `docs/llms.txt` identical: `npm run check` verifies it.
149
+
150
+ ## 7. Things that will waste your time if you do not know them
151
+
152
+ - **Android has no `/tmp`** (read-only root). Use `$TMPDIR`.
153
+ - **GUI-launched dsh inherits a minimal `PATH`**; runtime probes must augment it.
154
+ - **Windows**: `%LOCALAPPDATA%\Microsoft\WindowsApps` is full of zero-byte Store
155
+ alias stubs — it must not be treated as evidence that a runtime exists.
156
+ - **git-over-https to github.com is blocked on the author's network.** Use
157
+ `scripts/push-via-api.py` (exact commit replication via the REST API) instead of
158
+ `git push`.
159
+ - **`github.io` reachability varies** in mainland China.
160
+ - The author's machines: a Mac (this repo), `hos` (Android), `文超-win` (Windows).
161
+ Tasks are dispatched between them with `mesh_run`.
162
+
163
+ ## 8. Contact
164
+
165
+ geekstartup@163.com · https://github.com/peng456/dsh-plugin-mesh/issues
package/README.en.md ADDED
@@ -0,0 +1,107 @@
1
+ # dsh-plugin-mesh — English quickstart
2
+
3
+ > Discover other DeepSeek Harness (dsh) instances on your network and dispatch tasks
4
+ > between machines in both directions. No pairing codes, no IP entry, no Tailscale
5
+ > client to install.
6
+
7
+ [中文完整文档](README.md) · [llms.txt](llms.txt) (machine-oriented facts) · [AGENTS.md](AGENTS.md) (for coding agents)
8
+
9
+ ---
10
+
11
+ ## What it is
12
+
13
+ A dsh plugin. Install it on two or more machines and they find each other on the
14
+ LAN, show up in a sidebar panel, and accept tasks from one another. The receiving
15
+ machine wakes its own agent to do the work, and the result is dispatched back.
16
+
17
+ When machines are not on the same network, an optional bundled userspace Tailscale
18
+ node (tsnet) provides a second channel. It is a separate Go binary, downloaded per
19
+ platform on first use — end users need neither a Go toolchain nor the Tailscale
20
+ client.
21
+
22
+ ## Install
23
+
24
+ ```bash
25
+ dsh plugin add dsh-plugin-mesh # 'desktop' profile: in DSH Desktop's own terminal
26
+ dsh plugin --profile web add dsh-plugin-mesh # other profiles: a normal terminal works
27
+ ```
28
+
29
+ From source: `git clone https://github.com/peng456/dsh-plugin-mesh && cd dsh-plugin-mesh && ./install.sh`
30
+
31
+ **Restart the dsh host afterwards** — plugins load at startup. You should then see a
32
+ **Mesh** entry in the sidebar.
33
+
34
+ ## Three steps
35
+
36
+ 1. Install on every machine.
37
+ 2. Restart dsh on every machine.
38
+ 3. Open the **Mesh** panel. Seeing another machine means it worked.
39
+
40
+ If the panel is empty, check in this order: (a) same LAN, (b) the peer also installed
41
+ and restarted, (c) the peer's firewall allows TCP `45917` and UDP `45892`. Multicast
42
+ is often blocked by routers — the panel's **Scan subnet** button works around that.
43
+
44
+ ## What you get
45
+
46
+ - **Zero-config discovery** — UDP multicast heartbeat on `239.255.42.99:45892`, plus
47
+ an active subnet scan when multicast is blocked.
48
+ - **Capability cards** — each machine reports its runtimes (Node / Python / Go /
49
+ Docker / …), CPU cores, memory and GPU, so you can tell before dispatching whether
50
+ a machine can do the job.
51
+ - **Bidirectional dispatch** — the peer's agent can dispatch results back; both sides
52
+ compute the same conversation key independently, without negotiation.
53
+ - **Two channels with automatic failover** — LAN first, tsnet as backup (a free
54
+ Tailscale account and an auth key are required; create one at
55
+ <https://console.tailscale.com/admin/settings/keys>, and tick **Reusable**). The backup
56
+ channel is actively probed even while the LAN is healthy, so it is known-good
57
+ rather than assumed-good.
58
+ - **Traceable routing** — every task records why it went where it went, and why it
59
+ failed if it did. Both are readable from the peer.
60
+
61
+ ## Security defaults — read this
62
+
63
+ **With `requirePairing: false` (the default), any host that can reach TCP `45917` can
64
+ POST a task, and that task wakes an agent session** using the configured
65
+ `permissionPreset`. Discovery is intentionally public so you can see machines before
66
+ deciding to talk to them.
67
+
68
+ On an untrusted network (café, dorm, office):
69
+
70
+ 1. Flip the switch in the Mesh panel's **pairing** card — it takes effect immediately, no restart. (Writing `requirePairing: true` in `cordis.patch.yml` also works and pins it on, so the UI cannot turn it off.)
71
+ 2. Make the pairing secret identical on both machines (the Mesh panel has a field for it).
72
+
73
+ Note the token travels in a plain HTTP header: it guards against stray devices on
74
+ the network, not against a network sniffer. It lives in `~/.dsh/mesh/state.json`
75
+ (mode 0600) and is never included in the multicast card.
76
+
77
+ ## Configuration
78
+
79
+ Override by id in the profile's `cordis.patch.yml`:
80
+
81
+ ```yaml
82
+ - id: mesh
83
+ config:
84
+ requirePairing: true
85
+ permissionPreset: workspace-write
86
+ ```
87
+
88
+ `config:` is replaced **wholesale**, not merged — restate any keys you want to keep.
89
+ The full key list with defaults is in [`llms.txt`](llms.txt#configuration).
90
+
91
+ ## Requirements
92
+
93
+ - A dsh host that can load cordis plugins with a client half (DSH Desktop, or `dsh web`).
94
+ - Node >= 20 for development. `@deepseek-ai/*` packages are supplied by the host.
95
+
96
+ ## More
97
+
98
+ | | |
99
+ |---|---|
100
+ | Full documentation (Chinese) | [README.md](README.md) |
101
+ | Machine-oriented facts / config table | [llms.txt](llms.txt) |
102
+ | Guide for coding agents | [AGENTS.md](AGENTS.md) |
103
+ | Showcase page (Chinese) | https://peng456.github.io/dsh-plugin-mesh/ |
104
+ | Issues | https://github.com/peng456/dsh-plugin-mesh/issues |
105
+ | Contact | geekstartup@163.com |
106
+
107
+ MIT licensed. Not affiliated with DeepSeek.