@dr-co/dsh-secret-form 0.2.0 → 0.4.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/README.md CHANGED
@@ -1,17 +1,24 @@
1
1
  # dsh-secret-form
2
2
 
3
- A **one-time web link for secrets** in [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness).
3
+ **One-time secret links in both directions** for [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness).
4
4
 
5
- The model needs an API key. Today the usual answer is "paste it in the chat",
6
- which puts the secret into the session log, the transcript, every later provider
5
+ The model needs an API key. The usual answer is "paste it in the chat", which
6
+ puts the secret into the session log, the transcript, every later provider
7
7
  request, and anything the session is exported to. This plugin replaces that with
8
- a link:
8
+ a link — and it works the other way round too, when the model has a secret the
9
+ human needs:
9
10
 
10
- 1. the model calls `secret_create` and gets an absolute URL;
11
- 2. the human opens it on a phone or a desktop, types the value, presses Save;
12
- 3. the plugin writes it into the host credential store or into a document file;
13
- 4. the model calls `secret_result` and learns `saved`, `length: 51` — never the
14
- value itself.
11
+ | | inbound (`secret_create`) | outbound (`secret_share`) |
12
+ | --- | --- | --- |
13
+ | who has the secret | the human | the model |
14
+ | the link | works exactly once | may be opened any number of times |
15
+ | the action on the page | Save | a reveal button that works **exactly once** |
16
+ | where the value ends up | credential store, a document file, or a directory | the browser, shown once with a copy button |
17
+ | what the model learns | `saved`, `length: 51`, a file sha256 | `revealed`, `views: 3` — never the value back |
18
+
19
+ Both directions live in SQLite, so a link created before a restart of the harness
20
+ still works afterwards. Filling a form in — or a human collecting a shared
21
+ secret — wakes the session that asked, through the schedule service.
15
22
 
16
23
  The page is one self-contained HTML document: inline CSS, no assets, no
17
24
  frameworks, light and dark from the same markup.
@@ -35,16 +42,13 @@ Pin a tag when you want a revision you can point at later; the repository root i
35
42
  the package, so no build step is involved.
36
43
 
37
44
  ```sh
38
- dsh plugin --profile <profile> add "git+https://github.com/unera/dsh-secret-form.git#v0.1.0"
45
+ dsh plugin --profile <profile> add "git+https://github.com/unera/dsh-secret-form.git#v0.4.0"
39
46
  # a particular commit
40
47
  dsh plugin --profile <profile> add "git+https://github.com/unera/dsh-secret-form.git#<sha>"
41
48
  # or a local checkout while developing
42
49
  dsh plugin --profile <profile> add file:$PWD/dsh-secret-form
43
50
  ```
44
51
 
45
- Either way the package ships no `dsh.bundle`, so it lands as a plain dependency
46
- and the profile patch row below is what actually mounts it.
47
-
48
52
  Mount it next to the two services it uses — the Web GUI host and the agent's
49
53
  tools:
50
54
 
@@ -56,6 +60,11 @@ tools:
56
60
  defaultTtlSeconds: 300 # default; every value is clamped to 30..3600
57
61
  defaultLocale: en # default; en|ru|de|fr|es|pt|zh|ja
58
62
  publicUrl: https://dsh.example.org # optional; see below
63
+ database: /home/dsh/.dsh/storages/dsh-secret-form.sqlite # default
64
+ language: en # default; wording of the notes: en|ru|zh
65
+ notify: true # default; wake the creating session
66
+ maxUploadBytes: 67108864 # default 64 MiB; 1 KiB..1 GiB
67
+ retainSeconds: 3600 # default; how long finished records stay answerable
59
68
  ```
60
69
 
61
70
  `publicUrl` matters behind a proxy: the listener usually binds loopback, so its
@@ -68,13 +77,16 @@ over as-is rather than invent a hostname.
68
77
  rewriter needs. `defaultTtlSeconds` is the TTL used when a call omits
69
78
  `ttlSeconds`. `defaultLocale` is the wording used when neither the link nor the
70
79
  browser asks for a language; any other value is refused at mount time.
80
+ `database` defaults to `$DSH_HOME/storages/dsh-secret-form.sqlite`; the file is
81
+ created with mode `0600` inside a directory with mode `0700`.
71
82
 
72
83
  The plugin declares `inject: ['tools', 'webServer']`: it cannot do anything
73
- without a Web GUI server to serve the page, and it registers its four tools on
74
- the agent surface. The credentials service is read lazily, so a host that only
75
- writes to files does not need a credential provider.
84
+ without a Web GUI server to serve the page, and it registers its five tools on
85
+ the agent surface. Two more services are looked up lazily and never required: the
86
+ credentials service (only for a credential target or a credential share) and the
87
+ schedule service (only to place a note on a session).
76
88
 
77
- ## The four tools
89
+ ## The five tools
78
90
 
79
91
  ### `secret_create`
80
92
 
@@ -82,58 +94,96 @@ Open a form and return its link.
82
94
 
83
95
  | argument | type | required | meaning |
84
96
  | --- | --- | --- | --- |
85
- | `ref` | string | yes | Key name. Default target: the credential reference, such as `OPENAI_API_KEY`. File target: the path inside the document — `provider.apiKey` for yaml/json, a bare key for `.env`. |
97
+ | `ref` | string | for text kinds | Key name. Default target: the credential reference, such as `OPENAI_API_KEY`. File target: the path inside the document — `provider.apiKey` for yaml/json, a bare key for `.env`. For `kind: "file"` it is only a label unless `upload.name` is omitted. |
86
98
  | `label` | string | yes | Form title, 2 to 5 words. |
87
- | `kind` | `'single'` \| `'multi'` | yes | One-line masked input, or a monospace textarea for multi-line secrets. |
99
+ | `kind` | `'single'` \| `'multi'` \| `'file'` | no | Default `single`. One-line masked input, a monospace textarea, or a file picker. |
88
100
  | `description` | string | no | One or two sentences under the title, at most 300 characters. |
89
- | `save` | object | no | Default `{ "kind": "credentials" }`. A file target is `{ "kind": "file", "path": "…" }`. |
101
+ | `save` | object | no | Default `{ "kind": "credentials" }`. A file target is `{ "kind": "file", "path": "…" }`. Ignored for `kind: "file"`. |
102
+ | `upload` | object | for `kind: "file"` | `{ "dir": "/abs/dir", "name": "app.log" }`. `dir` receives the file (created when missing, mode `0700`); `name` defaults to the name the browser sent. |
90
103
  | `ttlSeconds` | integer | no | Default 300, clamped to 30..3600. |
91
104
  | `allowEmpty` | boolean | no | Default `false`. When true an empty submit is accepted and reported as `empty`. |
92
105
  | `expect` | string | no | Regular expression as text. The result carries `matchesExpect`; the page warns on a mismatch but still saves. |
93
- | `data` | object | no | Up to 1 KB of bookkeeping for the model. Echoed verbatim by all four tools, never rendered on the page. |
106
+ | `notify` | boolean | no | Wake the creating session when the form is filled in or cancelled. Default: the plugin setting. |
107
+ | `data` | object | no | Up to 1 KB of bookkeeping for the model. Echoed verbatim by all five tools, never rendered on the page. |
108
+
109
+ Returns `{ uuid, url, expiresAt, kind, data }`. `url` is absolute: the web
110
+ server's `getOrigin()` (or `publicUrl`) plus `routePrefix` plus a 43-character
111
+ token.
94
112
 
95
- Returns `{ uuid, url, expiresAt, data }`. `url` is absolute: the web server's
96
- `getOrigin()` plus `routePrefix` plus a 43-character token.
113
+ ### `secret_share`
114
+
115
+ Hand a secret to the human. **The value never passes through the call**: name a
116
+ source and the plugin reads the bytes itself, seals them with a one-shot
117
+ AES-256-GCM key and stores both ciphertext and key in SQLite.
118
+
119
+ | argument | type | required | meaning |
120
+ | --- | --- | --- | --- |
121
+ | `label` | string | yes | Page title, 2 to 5 words. |
122
+ | `kind` | `'single'` \| `'multi'` | no | Wording and layout only. Default `single`. |
123
+ | `file` | string | one of two | Absolute path of a text file on this host. At most 256 KiB; a file with a NUL byte is refused as binary. |
124
+ | `credential` | string | one of two | A credential reference such as `OPENAI_API_KEY`, read through `ctx.credentials.resolve()`. |
125
+ | `description` | string | no | One or two sentences under the title. |
126
+ | `ttlSeconds` | integer | no | 30..3600, default 300. After that the sealed value is deleted unread. |
127
+ | `notify` | boolean | no | Wake the creating session when the human collects the secret. Default: the plugin setting. |
128
+ | `data` | object | no | Up to 1 KB of bookkeeping. |
129
+
130
+ Returns `{ uuid, url, expiresAt, source, length, data }` — `length`, not the
131
+ value.
97
132
 
98
133
  ### `secret_result`
99
134
 
100
135
  | argument | type | required | meaning |
101
136
  | --- | --- | --- | --- |
102
- | `uuid` | string | yes | The uuid `secret_create` returned. |
103
- | `waitSeconds` | integer | no | 0..30, default 0. Above zero it waits for the form to leave `pending`, then reports whatever state it reached. |
137
+ | `uuid` | string | yes | The uuid `secret_create` or `secret_share` returned. |
138
+ | `waitSeconds` | integer | no | 0..30, default 0. Above zero it waits for the record to leave `pending`, then reports whatever state it reached. |
104
139
 
105
- Returns `{ status, data, ref, label }` plus, once a value was submitted,
106
- `length` (characters), `lines`, `trimmed` (whether surrounding whitespace was
107
- stripped) and `matchesExpect` when `expect` was given. `status` is one of
108
- `pending`, `saved`, `empty`, `cancelled`, `expired`.
140
+ For a form: `{ type: "form", status, data, ref, label }` plus, once a value was
141
+ submitted, `length` (characters), `lines`, `trimmed` and `matchesExpect` when
142
+ `expect` was given — or `fileName`, `size`, `sha256`, `path` for a file form.
143
+ `status` is one of `pending`, `saved`, `empty`, `cancelled`, `expired`.
109
144
 
110
- The submitted value never appears in a tool result. Not truncated, not masked,
111
- not hashed — absent.
145
+ For a share: `{ type: "share", status, label, views, data, revealedAt? }`.
146
+ `status` is one of `pending`, `revealed`, `cancelled`, `expired`; `pending` with
147
+ `views > 0` means the human opened the page but has not pressed the button yet.
148
+
149
+ Neither the submitted value nor the shared secret ever appears in a tool result.
150
+ Not truncated, not masked, not hashed — absent.
112
151
 
113
152
  ### `secret_list`
114
153
 
115
- No arguments. Returns every form this process created, oldest first:
154
+ No arguments. Every form and share still held, oldest first:
116
155
 
117
156
  ```json
118
- [{ "uuid": "…", "ref": "OPENAI_API_KEY", "label": "OpenAI key", "status": "saved",
119
- "createdAt": "2026-10-21T12:28:30.263Z", "expiresAt": "2026-10-21T12:33:30.263Z", "data": {} }]
157
+ [{ "uuid": "…", "type": "form", "ref": "OPENAI_API_KEY", "label": "OpenAI key",
158
+ "status": "saved", "createdAt": "2026-10-21T12:28:30.263Z",
159
+ "expiresAt": "2026-10-21T12:33:30.263Z", "data": {} },
160
+ { "uuid": "…", "type": "share", "label": "Router password", "status": "pending",
161
+ "views": 2, "createdAt": "…", "expiresAt": "…", "data": {} }]
120
162
  ```
121
163
 
164
+ The list is read from SQLite, so it also holds records created before a restart.
165
+
122
166
  ### `secret_cancel`
123
167
 
124
168
  | argument | type | required | meaning |
125
169
  | --- | --- | --- | --- |
126
- | `uuid` | string | yes | The uuid `secret_create` returned. |
170
+ | `uuid` | string | yes | The uuid of a form or a share. |
127
171
 
128
- Cancels a pending form; a form that already finished reports its current status
129
- and is left alone.
172
+ Cancels a pending record; one that already finished reports its current status
173
+ and is left alone. For a share this also deletes the sealed value and its key.
130
174
 
131
175
  ## The web surface
132
176
 
133
177
  | route | method | body | result |
134
178
  | --- | --- | --- | --- |
135
- | `<prefix>/<token>` | `GET`, `HEAD` | — | the form, or an outcome page |
136
- | `<prefix>/<token>` | `POST` | `application/x-www-form-urlencoded` with `value`, `action` (`save` or `cancel`) and the hidden `lang` | an outcome page |
179
+ | `<prefix>/<token>` | `GET`, `HEAD` | — | the form, the reveal page, or an outcome page |
180
+ | `<prefix>/<token>` | `POST` | `application/x-www-form-urlencoded` with `value`, `action` (`save`/`cancel`/`reveal`) and the hidden `lang` | an outcome page |
181
+ | `<prefix>/<token>` | `POST` | `multipart/form-data` with a `file` part, `action` and `lang` | an outcome page |
182
+
183
+ A `kind: "file"` form posts multipart; everything else posts urlencoded. The
184
+ multipart parser is about eighty lines in `lib/upload.mjs`: one boundary, parts
185
+ made of headers and bytes, no nested encodings. The body is read into memory and
186
+ bounded by `maxUploadBytes`, which is what makes that acceptable.
137
187
 
138
188
  Both responses carry `Cache-Control: no-store`, `Referrer-Policy: no-referrer`,
139
189
  `X-Content-Type-Options: nosniff`, `X-Frame-Options: DENY` and
@@ -144,12 +194,12 @@ script-src 'unsafe-inline'; form-action 'self'; base-uri 'none'
144
194
  ```
145
195
 
146
196
  The label and description come from the model and are escaped as untrusted HTML;
147
- the only script on the page is the reveal toggle and the `expect` hint, both
148
- inline and both from this origin.
197
+ the only scripts on a page are the reveal toggle, the `expect` hint and the copy
198
+ button, all inline and all from this origin.
149
199
 
150
- Outcome pages have distinct wording: **Saved**, **Nothing stored** (empty
151
- submit), **Cancelled**, **Link already used**, **Link expired**, **Link not
152
- recognised**.
200
+ Outcome pages have distinct wording: **Saved**, **File received**, **Nothing
201
+ stored** (empty submit), **Cancelled**, **Link already used**, **Secret already
202
+ shown**, **Link expired**, **Link not recognised**.
153
203
 
154
204
  ### Languages
155
205
 
@@ -167,6 +217,10 @@ the header on submit, so the outcome page stays in the language the reader
167
217
  started in. `<html lang="…">` follows the same value. The ref (`OPENAI_API_KEY`)
168
218
  is an identifier and stays as it is; everything around it is translated.
169
219
 
220
+ The **notes** are a separate matter: their wording follows the plugin's
221
+ `language` setting (`en`, `ru`, `zh`), because they are read by the model rather
222
+ than by the person holding the phone.
223
+
170
224
  ## Where the value goes
171
225
 
172
226
  **Credentials (default).** `ctx.credentials.set(ref, value)` — the same store an
@@ -189,6 +243,13 @@ missing; a path that already holds a scalar where a mapping is needed, or a
189
243
  mapping where the leaf goes, is refused instead of destroyed. `__proto__`,
190
244
  `prototype` and `constructor` are refused as path segments.
191
245
 
246
+ **Directory (uploads).** `kind: "file"` writes the received bytes into the
247
+ `upload.dir` the model named — never anywhere else, and never into the page. The
248
+ browser's own file name is reduced to a base name, so `../../etc/passwd` becomes
249
+ `passwd` inside the directory, and the resolved path is checked against the
250
+ directory once more. The write is atomic (temp file, `fsync`, `rename`) and lands
251
+ with mode `0600`. The model gets `fileName`, `size`, `sha256` and `path`.
252
+
192
253
  ### The YAML writer is deliberately small
193
254
 
194
255
  The reader understands block mappings, plain and quoted scalars, comments and
@@ -200,36 +261,72 @@ original spelling (`port: 8080` stays `port: 8080`); **comments are dropped** by
200
261
  the rewrite. Use `.json` or `.env` when a hand-written YAML file must keep its
201
262
  comments.
202
263
 
203
- ## Security notes
264
+ ## Notes to the session
204
265
 
205
- - **The token is the capability.** 256 bits of `crypto.randomBytes`, base64url,
206
- single use. A successful submit or a cancel kills it: the link still opens, but
207
- only to say "already used" or "cancelled". Nothing else can read a form.
208
- - **The value only ever travels browser → host.** It is not logged, not echoed
209
- back into the page, and not returned to the model. Logs carry at most the first
210
- eight characters of a token.
211
- - **The page never accepts a value twice.** A second POST on the same token is a
212
- `410` and writes nothing.
266
+ A form is filled in minutes after the model asked for it, usually after that turn
267
+ has ended. Polling `secret_result` would be slow and wasteful, so the plugin
268
+ wakes the session instead — the same route the
269
+ [graceful-restart](https://github.com/unera/dsh-graceful-restart) plugin uses for
270
+ its post-restart note:
271
+
272
+ ```js
273
+ await schedule.create(sessionId, { title, prompt, after_seconds: 1 })
274
+ ```
275
+
276
+ `ScheduleService` owns the timer and resumes the session itself, so this plugin
277
+ never races session start-up: it asks, and the service answers when it can. The
278
+ session id comes from `exec.agent.session.id` at creation time and is stored with
279
+ the record.
280
+
281
+ - one note per event: **Secret received**, **File received**, **Form cancelled**,
282
+ **Secret collected**;
283
+ - the note names the uuid, the label and where the value went, never the value;
284
+ - undelivered notes wait in the `note` table — the schedule service may mount
285
+ after this plugin, or not at all — and are retried at start-up, when the
286
+ service appears, and every few seconds after that;
287
+ - a note is dropped after eight attempts, or immediately for a subagent, which
288
+ has no delivery path at all;
289
+ - `notify: false` on a single call, or `notify: false` in the config, silences it.
290
+
291
+ ## Storage and security
292
+
293
+ Records live in one SQLite file (`node:sqlite`, no dependency), in WAL mode:
294
+
295
+ | table | holds |
296
+ | --- | --- |
297
+ | `form` | inbound requests: label, ref, target, TTL, status, aggregate result, session id |
298
+ | `share` | outbound links: label, TTL, status, view count, session id |
299
+ | `share_secret` | the sealed value: algorithm, iv, tag, ciphertext |
300
+ | `share_key` | the one-shot AES-256-GCM key, in its own row |
301
+ | `note` | notes waiting for a session |
302
+ | `meta` | schema version; a mismatch is a refusal, not a migration |
303
+
304
+ - **The token is the capability and is never stored.** Only its SHA-256 hash is
305
+ written, so a copy of the database opens no link. 256 bits of
306
+ `crypto.randomBytes`, base64url.
307
+ - **The inbound value never touches the database.** It is written to its target
308
+ and nowhere else; the row keeps `length`, `lines` and the file's sha256.
309
+ - **An outbound value is encrypted with a key that lives in the same file.** It
310
+ protects a half-copied database and a row surviving a crash mid-delete, not a
311
+ person who can read both rows while the link is still open — that person owns
312
+ the host anyway. Revealing, cancelling and expiry all delete both rows.
313
+ - **The page never accepts a value twice.** A second POST on a form token is a
314
+ `410` and writes nothing; a second POST on a share token cannot reveal anything
315
+ because there is nothing left to decrypt.
213
316
  - **The page holds no third-party content.** `default-src 'none'` with inline
214
317
  style and script only, `form-action 'self'`, `base-uri 'none'`, no referrer,
215
318
  no store, no framing.
216
- - **One-time links are visible to whoever can read the chat.** The URL is safe to
217
- post because it carries no secret; anything that can submit it first wins.
218
- Treat the window as `ttlSeconds`, and cancel a form you no longer need.
219
- - **A link is bound to this process.** Nothing about it is durable, which is why
220
- a restart is safe — and why every form disappears with it.
221
-
222
- ## In-memory by design
223
-
224
- Forms live in a `Map` in the plugin instance. There is no database, no file, no
225
- token on disk. Consequences, all intentional:
226
-
227
- - a restart makes every form `expired`; ask for a new link;
228
- - an expired form, a used link and a cancelled form stay answerable for an hour
229
- past their TTL, then a lazy sweep drops them and the token becomes unknown;
230
- - two DSH processes do not share forms, so a link created by one is unknown to
231
- the other;
232
- - `secret_list` shows this process's forms only.
319
+ - **A link is visible to whoever can read the chat.** The URL is safe to post
320
+ because it carries no secret; anything that can submit it first wins. Treat the
321
+ window as `ttlSeconds`, and cancel a record you no longer need.
322
+ - **One process owns the file.** SQLite serialises concurrent access, but two DSH
323
+ processes sharing one database would share their forms as well — point
324
+ `database` at separate files if that ever becomes a question.
325
+
326
+ Retention: an expired, used or cancelled record keeps answering its link for
327
+ `retainSeconds` (default an hour) past its end, then a lazy sweep drops it and
328
+ the link reads as unknown. Expired shares have their sealed rows deleted
329
+ immediately, not at the sweep.
233
330
 
234
331
  ## Development
235
332
 
@@ -240,18 +337,26 @@ npm pack --dry-run # what would ship
240
337
 
241
338
  The suite drives the real `apply()` against a stub host: tool definitions are
242
339
  captured as a real agent would call them, and the route handler is invoked with
243
- `node:stream` request doubles, so no port is opened. TTL cases move the clock
244
- with `node:test` mock timers instead of sleeping.
340
+ `node:stream` request doubles, so no port is opened. Every host gets its own
341
+ SQLite file in a temporary directory, which is also how a restart is tested: a
342
+ second `apply()` on the same file has to find the record. Expiry cases move the
343
+ clock with SQL instead of sleeping.
245
344
 
246
345
  ## Limits
247
346
 
248
- - Node >= 22, zero runtime dependencies.
347
+ - Node >= 22.13, zero runtime dependencies: `node:sqlite` stopped needing
348
+ `--experimental-sqlite` in 22.13.0, and on 22 it still prints an experimental
349
+ warning.
249
350
  - The page is served by the Web GUI host only; a headless composition with no
250
351
  `webServer` cannot use this plugin.
251
- - `label` is 2..5 words and `description` 300 characters: the form is a prompt
352
+ - `label` is 2..5 words and `description` 300 characters: the page is a prompt
252
353
  for one value, not a second chat.
253
354
  - `kind: 'single'` removes embedded newlines, so a pasted key file must use
254
355
  `kind: 'multi'`.
356
+ - A share carries text only: 256 KiB, no NUL bytes. A binary file needs another
357
+ route.
358
+ - Uploads go to the directory the model named. There is no default inbox, so a
359
+ file form without `upload.dir` is refused at creation.
255
360
 
256
361
  ## License
257
362