dsh-rayrun-bots 0.0.0-stage → 0.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 RayrunOS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,277 @@
1
- # Temporary Holding Version
1
+ # dsh-rayrun-bots
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The Rayrun Bot plugin package. Status: **client shell with a local roster and
4
+ local sessions** — the bundle loads, the client half renders the v0.1 screens,
5
+ and the host half answers health, persists the bot roster, and stores a durable
6
+ per-bot session/transcript. With `dsh-rayrun-computer` 1.1+, a turn is posted as
7
+ a detached `dsh.start` task, its task id is persisted, and `reply.md` is
8
+ collected from the task result directory; 1.0.x falls back to the single-turn
9
+ `rayrun_agent` tool, and without either surface `session.send` fails closed with
10
+ `E_RUNTIME_UNAVAILABLE`. One-turn and detached live Rayrun smokes were verified
11
+ on 2026-11-22; the detached smoke closed the page and restarted the local DSH
12
+ while the task ran, and the restarted host collected `reply.md`. A second-turn
13
+ smoke stopped the machine, restarted DSH, and the next turn answered from the
14
+ persisted transcript. With 1.2+, a host-side `runtime.*` client is ready for
15
+ the platform-supervised bot host. The opt-in `cloudHost` runtime adapter ships
16
+ the host assets in this package, projects them with a SHA-256 manifest through
17
+ the dependency's `rayrun_files` tool, and wires one multi-bot host process into
18
+ `session.*`. It is preview and has passed a dev page E2E.
19
+ Approval execution now follows ADR-019: the local host is the authority and
20
+ executor for typed local actions, while the cloud side may only propose. The
21
+ first allowlist is `rayrun.machine.start/stop/pause/resume`; an approved
22
+ request gets a durable at-most-once execution claim, and denied, expired, or
23
+ crashed requests never execute. A cloud bot emits a structured `rayrun-approval`
24
+ block; the cloud host writes the proposal and the local `approvals.sync` bridge
25
+ imports it. A live cloud proposal -> local approve -> real machine stop -> stopped
26
+ result outbox -> restart flush, plus a start approval and next-turn outcome
27
+ context, passed on 2026-11-23. Other action types and
28
+ cloud-only credential actions are still pending. The conversation UI
29
+ uses the host session and real approval cards for roster bots; sample bots,
30
+ receipts and settings remain an in-memory preview. Real bots can create, pause
31
+ and remove local routines; the local scheduler enqueues one ordinary turn when a
32
+ routine is due. The page-level create/reload path was verified on 2026-11-21,
33
+ and the approval card deny/fail-closed path on 2026-11-23. Repository-level
34
+ status and verified combinations live in
35
+ [docs/12-status.md](../../docs/12-status.md).
36
+
37
+ ## What it does today
38
+
39
+ - Host half: `GET /plugins/rayrun-bots?action=health` returns
40
+ `{ ok: true, plugin: "rayrun-bots", version, ready: false, dependency, runtime }`.
41
+ `dependency` reports `dsh-rayrun-computer` as `ok`, `missing` (`E_DEP_MISSING`),
42
+ `incompatible` (`E_DEP_VERSION`), or `unknown` when no profile context exists.
43
+ `runtime` reports the adapter name and whether its tool is currently
44
+ registered. `POST` is same-origin gated: a browser `Origin` that does not
45
+ match the request `Host` is refused with 403. No credentials are touched.
46
+ - Host half: `bots.list`, `bots.get`, `bots.create`, `bots.update` and
47
+ `bots.delete` persist validated `bot.json` files under
48
+ `$DSH_HOME/state/rayrun-bot/bots/<id>/` (atomic writes, private modes, stable
49
+ `E_BOT_*` errors). The roster is the user's intent store until the cloud
50
+ runtime lands; the machine will become the runtime truth. Ids are derived
51
+ from the name when the client does not send one, and collisions get a numeric
52
+ suffix.
53
+ - Host half: `routines.list/create/update/remove/sync` persist at most 32
54
+ validated routines per bot in `routines.json` beside `bot.json`. A routine has
55
+ a title, prompt, 1–10080 minute interval, enabled flag and next-run time. In
56
+ the default non-cloudHost mode, the local scheduler checks every 30 seconds,
57
+ enqueues at most one ordinary session turn per bot per tick, skips a busy bot,
58
+ and does not backfill missed intervals. It claims the run
59
+ (`lastRunAt`/next `nextAt`) before enqueueing, so a crash cannot replay it; a
60
+ failed enqueue waits for the next interval instead. In cloudHost mode the
61
+ local scheduler is disabled: the bridge mirrors `routines.json` and `bot.json`
62
+ while the machine is Running, the cloud host claims schedule state and
63
+ enqueues the task, expands it with the mirrored bot instructions and approval
64
+ hint (the DSH session carries the conversation), and `routines.sync` imports
65
+ routine results into local history. That cloud path has a fake E2E and a
66
+ Rayrun dev/test live E2E (2026-11-24); production is still waiting for the
67
+ platform deployment. A routine is a normal user turn and does not bypass
68
+ approval. Because it uses the normal send path, a due routine may
69
+ wake a stopped or paused machine and incur machine-hour charges; the interval
70
+ and enabled switch are standing authorization, not per-run approval.
71
+ - Host half: `session.send`, `session.history` and `session.status` persist a
72
+ per-bot `session.json` and append-only `transcript.jsonl` beside `bot.json`.
73
+ Sends are queued one turn at a time; a runtime failure writes a redacted
74
+ system line and leaves the transcript intact; a host restart marks a running
75
+ turn `interrupted` instead of replaying it. When the dependency's
76
+ `rayrun_agent` tool is registered, a queued turn is sent to the existing cloud
77
+ computer (the adapter refuses to auto-create one); a stopped or paused machine
78
+ is woken by the dependency, which may incur machine-hour charges. Without the
79
+ tool, `session.send` returns `E_RUNTIME_UNAVAILABLE` and writes no session.
80
+ - Host half: `approvals.list/get/decide/propose/sync` operate on one request,
81
+ decision and execution claim per approval under `bots/<id>/approvals/`.
82
+ Requests carry an action id, nonce and canonical SHA-256 action hash; background
83
+ requests expire after 30 minutes, chat requests wait; duplicate decisions are
84
+ idempotent and a conflicting or replayed decision is refused. Every request,
85
+ decision, refusal and execution is appended to `logs/audit.log` without the
86
+ action payload. `propose` is host-side only and validates a typed action
87
+ (`rayrun.machine.start`, `stop`, `pause`, `resume`). On approve, the local
88
+ executor writes an `exec-<id>.json` claim and calls the dependency's Rayrun RPC
89
+ with the token kept in the Harness vault; a failed execution is recorded and
90
+ not retried. `sync` imports typed proposals from the cloud workspace with
91
+ `rayrun_files`, validates them again and deduplicates by proposal id; decisions
92
+ and execution results are written back to `approval-results/` (a stopped
93
+ machine queues results locally for the next sync). The next cloud prompt also
94
+ includes recent approval kind/target/state/execution/status, without payloads. Other action kinds are not
95
+ built; the proposal bridge has fake-tool tests, and a live cloud-bot proposal
96
+ E2E is still pending.
97
+ - Client half: a `Bots` sidebar entry and the three-column shell from
98
+ [docs/design/ui-design.md](../../docs/design/ui-design.md) — chat list, conversation,
99
+ details (Activity / Library), new bot, the four-step setup wizard, and
100
+ settings. When the host roster has entries, the chat list shows those bots
101
+ instead of the sample list; creating a bot in the new-bot screen or the setup
102
+ wizard writes through to the host and selects the saved bot. For real roster
103
+ bots, messages and approval cards come from the host session and approval
104
+ store; real bots also create, pause and remove routines through the host, and
105
+ the five-second poll imports cloud routine results into the conversation.
106
+ Sample bots, receipts, sample routines and settings still live in the page
107
+ only. Deny /
108
+ Allow once for real approvals goes through the host and can execute a typed
109
+ local action; after a decision the real card offers Continue bot, which sends
110
+ the next turn only when the user clicks it. Sample cards update in-memory state. The client
111
+ activates Bots on load and covers the DSH
112
+ sidebar and bottom bar; there is no in-product return to the Harness shell
113
+ (ADR-017). The setup Rayrun step calls the cloud-computer plugin's
114
+ same-origin RPC with a pasted token and shows the real balance/machine count.
115
+ The computer step calls `overview` and adopts an existing machine, or calls
116
+ `machine.create` with the plugin's defaults; a pasted DeepSeek key is passed as
117
+ `modelKey` and becomes the machine's Rayrun credential, then the input is
118
+ cleared. The step says the machine is billable, and the button is disabled
119
+ until Rayrun is connected. When several machines exist, Bots prefers
120
+ `rayrun-bot`, then a machine with a desktop URL, then the first. Creating a
121
+ machine was run on a real Rayrun account from a local harness with test keys
122
+ (the keys never entered the sandbox); the Bots page adoption and Continue
123
+ paths were run in a local DSH page, but the page-level create button itself
124
+ still needs a pass with no existing machine.
125
+ `Open` / `Take over` on the computer card uses the same RPC to start or resume
126
+ the machine, wait for `Running`, repair the desktop service, read `desktop_url` and the desktop password,
127
+ then open the desktop in a new tab and show the password in a dismissible
128
+ toast; both buttons currently run the same path. It fails closed with one
129
+ actionable line when Rayrun is not connected, there is no machine, the popup
130
+ is blocked, the machine does not start in time, or it has no desktop. The
131
+ start/repair/desktop/password path was run locally against a real machine, and
132
+ the Bots page Open flow was run in a local DSH page (desktop window and
133
+ password toast). When the machine is running, `Stop` asks for inline
134
+ confirmation, calls `machine.action` with `stop`, polls to Stopped, and never
135
+ destroys; the page-level Open to Stop path was also run in the local page.
136
+ The Settings Usage row reads the real balance, machine-hours and machine count
137
+ through the same RPC; without a connection it says so instead of showing sample
138
+ numbers. The details panel's computer and usage blocks use the same overview
139
+ data: real machine name/status, balance and machine-hours when connected, and
140
+ an explicit Not connected / connect prompt when not. The copy ships in Chinese
141
+ and English, Chinese primary and following the DSH language; the Settings
142
+ language row writes the choice back to DSH so it survives a reload. The rest
143
+ stays in the page, and the client keeps neither the token nor a DeepSeek key.
144
+
145
+ Not built yet: approval actions beyond machine start/stop/pause/resume, cloud-only
146
+ credential approvals, a Bots-page-level verified computer-creation success path,
147
+ production validation of the cloud-host routine scheduler, cron/event triggers,
148
+ a production cloud image, and the npm release path. The local routine store/
149
+ scheduler, cloud routine bridge, cloud scheduler, failed-result history and
150
+ result merge have plain-Node coverage, a fake end-to-end test, and a Rayrun
151
+ dev/test live E2E (cloud run while local DSH was stopped); the detail-panel
152
+ create, pause and remove paths passed a local DSH + Firefox smoke on 2026-11-23
153
+ without a Rayrun token, but no local scheduled turn was waited on. Approved
154
+ start/stop, denial/Continue, and the next-turn approval context were verified live
155
+ on 2026-11-23; pause/resume is also live. See the repo-level
156
+ [MVP plan](../../docs/plans/mvp-plan.md) and [client plan](../../docs/plans/client-plan.md).
157
+
158
+ ## DSH compatibility
159
+
160
+ `package.json` declares `engines.dsh: >=0.2.0-rc.2 <0.3.0`. DSH `0.2.2-rc.5`'s
161
+ compatibility check reads that range: an out-of-range install is refused and the
162
+ profile is restored, and an incompatible row is disabled at composition. Older
163
+ runtimes that ignore `engines.dsh` still load the bundle. The range covers the verified runtimes: `0.2.0-rc.2` (the Rayrun
164
+ cloud image), `0.2.2-rc.5`, and `0.2.1-rc.5` from the CI matrix. It is not a claim
165
+ that every feature works on every version; see the repository's
166
+ [version matrix](../../docs/version-matrix.md) for the combinations actually
167
+ verified.
168
+
169
+ ## Install from a checkout
170
+
171
+ Install this directory into the current DSH profile: **Plugins → Add plugin** and
172
+ point it at `packages/dsh-rayrun-bots`, or use the `plugin_manager`
173
+ `install_bundle` action with the package's absolute path. Refresh the DSH page;
174
+ the client half loads when the page starts.
175
+
176
+ The cloud-computer dependency (`dsh-rayrun-computer`) is **not declared as a
177
+ package dependency yet**: whether one bundle can declare it so one install brings
178
+ both is spike S6. Until then a user installs both plugins separately; the host
179
+ detects the installed version at runtime and reports it through health.
180
+
181
+ Install the packed artifact instead of the checkout:
182
+
183
+ ```bash
184
+ npm pack ./packages/dsh-rayrun-bots --pack-destination /tmp
185
+ dsh plugin --profile web add /tmp/dsh-rayrun-bots-0.1.0-alpha.0.tgz
186
+ ```
187
+
188
+ `test/package-contents.mjs` checks the tarball with `npm pack --dry-run`: the
189
+ host half, client half, locale, bundle patch, `lib/*.js`, icon, README and
190
+ LICENSE must ship; tests, docs, tools and environment files must not.
191
+
192
+ ## Checks
193
+
194
+ No build step, no runtime dependencies. Plain ESM, Node 24+.
195
+
196
+ ```bash
197
+ node --check index.js
198
+ node --check client.js
199
+ node test/manifest-check.mjs
200
+ node test/locale-audit.mjs
201
+ node test/rpc-contract.mjs
202
+ node test/client-contract.mjs
203
+ node test/bot-schema.mjs
204
+ node test/bot-store.mjs
205
+ node test/session-runtime.mjs
206
+ node test/rayrun-runtime.mjs
207
+ node test/rayrun-detached-runtime.mjs
208
+ node test/runtime-rpc.mjs
209
+ node test/cloud-host-runtime.mjs
210
+ node test/host-projection.mjs
211
+ node test/cloud-host.mjs
212
+ node test/cloud-host-routines.mjs
213
+ node test/cloud-host-dsh-agent.mjs
214
+ node test/cloud-routine-bridge.mjs
215
+ node test/cloud-routine-e2e.mjs
216
+ node test/bot-workspace.mjs
217
+ node test/dependency.mjs
218
+ node test/approvals.mjs
219
+ node test/approval-executor.mjs
220
+ node test/cloud-approval-bridge.mjs
221
+ node test/cloud-host-proposal.mjs
222
+ node test/routines.mjs
223
+ node test/routine-results.mjs
224
+ node test/package-contents.mjs
225
+ ```
226
+
227
+ The same commands run in the repository's checks-only CI workflow on push and
228
+ pull requests, on Node 24 and 26: [`.github/workflows/checks.yml`](../../.github/workflows/checks.yml).
229
+ CI also installs this package into a throwaway DSH profile and composes its
230
+ config against DSH `0.2.1-rc.5` and `0.2.2-rc.5`; it does not start the web app,
231
+ test the cloud-computer plugin, or make Rayrun calls. Live integration tests
232
+ need real Rayrun credentials and never run in CI.
233
+
234
+ ## Layout
235
+
236
+ ```
237
+ package.json # name, exports, dsh.bundle + dsh.client
238
+ cordis.patch.yml # the bundle row (id rayrun-bots -> package dsh-rayrun-bots)
239
+ index.js # host half: same-origin RPC, health + bots.* + session.* + approvals.*
240
+ client.js # client half: v0.1 shell, roster read/write, preview conversation
241
+ lib/approvals.js # approval request/decision protocol, TTL, action hash, audit
242
+ lib/approval-actions.js # typed local action allowlist (machine start/stop/pause/resume)
243
+ lib/approval-executor.js # local at-most-once execution claim and audit
244
+ lib/cloud-approval-bridge.js # import cloud proposals and write results
245
+ lib/bots.js # persistent roster: list/get/create/update/delete
246
+ lib/bot-schema.js # bot.json validation, defaults and creation
247
+ lib/bot-workspace.js # per-bot local git checkout for detached tasks
248
+ lib/dependency.js # dsh-rayrun-computer detection, version, detached/runtime gates
249
+ lib/errors.js # stable error codes (shared with docs/plans/mvp-plan.md §4.3)
250
+ lib/local-store.js # state-directory resolution and atomic JSON writes
251
+ lib/rpc.js # JSON responses and request-body parsing
252
+ lib/runtime.js # single-turn and detached runtime contracts
253
+ lib/runtime-rpc.js # host-side runtime.* client (cloud bot host)
254
+ lib/cloud-host-runtime.js # opt-in persistent host runtime over runtime.* + rayrun_files
255
+ lib/host-projection.js # SHA-256 manifest and projection of cloud-host assets
256
+ lib/routines.js # per-bot routine definitions and local schedule state
257
+ lib/routine-scheduler.js # local due checks and ordinary session turns
258
+ lib/routine-results.js # imported cloud routine results for history
259
+ lib/cloud-routine-bridge.js # definitions upload and result import; never starts a machine
260
+ cloud-host/host.mjs # cloud host entry point (projected to the machine)
261
+ cloud-host/lib/host.mjs # queue/transcript/outbox/session id/DSH agent wiring
262
+ cloud-host/lib/dsh-agent.mjs # headless DSH profile + --session-id runner
263
+ cloud-host/lib/proposal.mjs # structured approval block parser/writer
264
+ cloud-host/lib/routines.mjs # cloud routine definitions/state and due selection
265
+ cloud-host/lib/prompt.mjs # full routine prompt from bot.json + cloud transcript
266
+ cloud-host/bin/propose.mjs # typed approval proposal writer for the bot
267
+ lib/rayrun-rpc.js # shared same-origin dependency RPC caller
268
+ lib/rayrun-runtime.js # rayrun_agent-backed runtime adapter
269
+ lib/rayrun-detached-runtime.js # dsh.start/status/result adapter
270
+ lib/sessions.js # per-bot queue, transcript and detached polling
271
+ locale/en.json # source copy
272
+ locale/zh.json # mirror; keys must match
273
+ icon.svg # plugin icon (Rayrun blue, monitor mark)
274
+ test/ # plain-Node checks, no framework
275
+ ```
276
+
277
+ MIT © RayrunOS.