@dr-co/dsh-secret-form 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dmitry Oboukhov
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,265 @@
1
- # Temporary Holding Version
1
+ # dsh-secret-form
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
+ A **one-time web link for secrets** in [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness).
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
7
+ request, and anything the session is exported to. This plugin replaces that with
8
+ a link:
9
+
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.
15
+
16
+ The page is one self-contained HTML document: inline CSS, no assets, no
17
+ frameworks, light and dark from the same markup.
18
+
19
+ ## Install
20
+
21
+ The package ships no `dsh.bundle`, so `dsh plugin add` installs it as a plain
22
+ dependency and a profile patch row actually mounts it.
23
+
24
+ ### From npm
25
+
26
+ ```sh
27
+ dsh plugin --profile <profile> add @dr-co/dsh-secret-form
28
+ ```
29
+
30
+ ### From GitHub
31
+
32
+ Pin a tag when you want a revision you can point at later; the repository root is
33
+ the package, so no build step is involved.
34
+
35
+ ```sh
36
+ dsh plugin --profile <profile> add "git+https://github.com/unera/dsh-secret-form.git#v0.1.0"
37
+ # a particular commit
38
+ dsh plugin --profile <profile> add "git+https://github.com/unera/dsh-secret-form.git#<sha>"
39
+ # or a local checkout while developing
40
+ dsh plugin --profile <profile> add file:$PWD/dsh-secret-form
41
+ ```
42
+
43
+ Either way the package ships no `dsh.bundle`, so it lands as a plain dependency
44
+ and the profile patch row below is what actually mounts it.
45
+
46
+ Mount it next to the two services it uses — the Web GUI host and the agent's
47
+ tools:
48
+
49
+ ```yaml
50
+ - id: secret-form
51
+ name: '@dr-co/dsh-secret-form'
52
+ config:
53
+ routePrefix: /secret # default; must start with "/"
54
+ defaultTtlSeconds: 300 # default; every value is clamped to 30..3600
55
+ defaultLocale: en # default; en|ru|de|fr|es|pt|zh|ja
56
+ publicUrl: https://dsh.example.org # optional; see below
57
+ ```
58
+
59
+ `publicUrl` matters behind a proxy: the listener usually binds loopback, so its
60
+ own origin would produce a `http://127.0.0.1:3080/...` link that no phone can
61
+ open. When `publicUrl` is set the returned link is built from it; when it is not,
62
+ the plugin returns the listener origin unchanged and the model is told to hand it
63
+ over as-is rather than invent a hostname.
64
+
65
+ `routePrefix` moves the whole surface, which is what a host behind a path
66
+ rewriter needs. `defaultTtlSeconds` is the TTL used when a call omits
67
+ `ttlSeconds`. `defaultLocale` is the wording used when neither the link nor the
68
+ browser asks for a language; any other value is refused at mount time.
69
+
70
+ The plugin declares `inject: ['tools', 'webServer']`: it cannot do anything
71
+ without a Web GUI server to serve the page, and it registers its four tools on
72
+ the agent surface. The credentials service is read lazily, so a host that only
73
+ writes to files does not need a credential provider.
74
+
75
+ ## The four tools
76
+
77
+ ### `secret_create`
78
+
79
+ Open a form and return its link.
80
+
81
+ | argument | type | required | meaning |
82
+ | --- | --- | --- | --- |
83
+ | `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`. |
84
+ | `label` | string | yes | Form title, 2 to 5 words. |
85
+ | `kind` | `'single'` \| `'multi'` | yes | One-line masked input, or a monospace textarea for multi-line secrets. |
86
+ | `description` | string | no | One or two sentences under the title, at most 300 characters. |
87
+ | `save` | object | no | Default `{ "kind": "credentials" }`. A file target is `{ "kind": "file", "path": "…" }`. |
88
+ | `ttlSeconds` | integer | no | Default 300, clamped to 30..3600. |
89
+ | `allowEmpty` | boolean | no | Default `false`. When true an empty submit is accepted and reported as `empty`. |
90
+ | `expect` | string | no | Regular expression as text. The result carries `matchesExpect`; the page warns on a mismatch but still saves. |
91
+ | `data` | object | no | Up to 1 KB of bookkeeping for the model. Echoed verbatim by all four tools, never rendered on the page. |
92
+
93
+ Returns `{ uuid, url, expiresAt, data }`. `url` is absolute: the web server's
94
+ `getOrigin()` plus `routePrefix` plus a 43-character token.
95
+
96
+ ### `secret_result`
97
+
98
+ | argument | type | required | meaning |
99
+ | --- | --- | --- | --- |
100
+ | `uuid` | string | yes | The uuid `secret_create` returned. |
101
+ | `waitSeconds` | integer | no | 0..30, default 0. Above zero it waits for the form to leave `pending`, then reports whatever state it reached. |
102
+
103
+ Returns `{ status, data, ref, label }` plus, once a value was submitted,
104
+ `length` (characters), `lines`, `trimmed` (whether surrounding whitespace was
105
+ stripped) and `matchesExpect` when `expect` was given. `status` is one of
106
+ `pending`, `saved`, `empty`, `cancelled`, `expired`.
107
+
108
+ The submitted value never appears in a tool result. Not truncated, not masked,
109
+ not hashed — absent.
110
+
111
+ ### `secret_list`
112
+
113
+ No arguments. Returns every form this process created, oldest first:
114
+
115
+ ```json
116
+ [{ "uuid": "…", "ref": "OPENAI_API_KEY", "label": "OpenAI key", "status": "saved",
117
+ "createdAt": "2026-10-21T12:28:30.263Z", "expiresAt": "2026-10-21T12:33:30.263Z", "data": {} }]
118
+ ```
119
+
120
+ ### `secret_cancel`
121
+
122
+ | argument | type | required | meaning |
123
+ | --- | --- | --- | --- |
124
+ | `uuid` | string | yes | The uuid `secret_create` returned. |
125
+
126
+ Cancels a pending form; a form that already finished reports its current status
127
+ and is left alone.
128
+
129
+ ## The web surface
130
+
131
+ | route | method | body | result |
132
+ | --- | --- | --- | --- |
133
+ | `<prefix>/<token>` | `GET`, `HEAD` | — | the form, or an outcome page |
134
+ | `<prefix>/<token>` | `POST` | `application/x-www-form-urlencoded` with `value`, `action` (`save` or `cancel`) and the hidden `lang` | an outcome page |
135
+
136
+ Both responses carry `Cache-Control: no-store`, `Referrer-Policy: no-referrer`,
137
+ `X-Content-Type-Options: nosniff`, `X-Frame-Options: DENY` and
138
+
139
+ ```
140
+ Content-Security-Policy: default-src 'none'; style-src 'unsafe-inline';
141
+ script-src 'unsafe-inline'; form-action 'self'; base-uri 'none'
142
+ ```
143
+
144
+ The label and description come from the model and are escaped as untrusted HTML;
145
+ the only script on the page is the reveal toggle and the `expect` hint, both
146
+ inline and both from this origin.
147
+
148
+ Outcome pages have distinct wording: **Saved**, **Nothing stored** (empty
149
+ submit), **Cancelled**, **Link already used**, **Link expired**, **Link not
150
+ recognised**.
151
+
152
+ ### Languages
153
+
154
+ The page's own wording exists in `en`, `ru`, `de`, `fr`, `es`, `pt`, `zh` and
155
+ `ja`; the table lives in `lib/i18n.mjs`. The locale is chosen in this order:
156
+
157
+ 1. `?lang=de` on the link (`/secret/<token>?lang=de`), which also lets the model
158
+ pin one language for a link it hands over;
159
+ 2. the browser's `Accept-Language`, ranked by q-values and matched by primary
160
+ subtag, so `de-AT` and `zh-CN`/`zh-TW`/`zh-Hans` resolve as `de` and `zh`;
161
+ 3. `defaultLocale`, and English last.
162
+
163
+ The form carries the resolved locale in a hidden `lang` field, which outranks
164
+ the header on submit, so the outcome page stays in the language the reader
165
+ started in. `<html lang="…">` follows the same value. The ref (`OPENAI_API_KEY`)
166
+ is an identifier and stays as it is; everything around it is translated.
167
+
168
+ ## Where the value goes
169
+
170
+ **Credentials (default).** `ctx.credentials.set(ref, value)` — the same store an
171
+ adapter reads through `apiKeyEnv`, so a rotated key applies to the next request.
172
+ The store refuses an empty value, which is why an empty submit is reported as
173
+ `empty` and stored nowhere.
174
+
175
+ **File.** `{ "kind": "file", "path": "/abs/or/relative/path" }`. The extension
176
+ picks the format and nothing else does — `.yaml`, `.yml`, `.json`, `.env`; any
177
+ other extension is rejected when the form is created, never guessed.
178
+
179
+ - `.env` — append the `KEY=value` line or replace the existing one in place.
180
+ Values with spaces, quotes or newlines are double-quoted with escapes.
181
+ - `.json` — parse, set the dotted path, re-serialise with 2-space indent.
182
+ - `.yaml` / `.yml` — parse, set the dotted path, re-serialise.
183
+
184
+ Writes create parent directories, go through a temp file beside the target
185
+ followed by `rename`, and land with mode `0600`. Nested objects are created when
186
+ missing; a path that already holds a scalar where a mapping is needed, or a
187
+ mapping where the leaf goes, is refused instead of destroyed. `__proto__`,
188
+ `prototype` and `constructor` are refused as path segments.
189
+
190
+ ### The YAML writer is deliberately small
191
+
192
+ The reader understands block mappings, plain and quoted scalars, comments and
193
+ blank lines. Anything else — sequences, flow collections, block scalars (`|`,
194
+ `>`), anchors, aliases, tags, multiple documents — is **refused with an error
195
+ and the file is left untouched**, because a partial implementation that rewrites
196
+ a document it half-understands is worse than a refusal. Leaf values keep their
197
+ original spelling (`port: 8080` stays `port: 8080`); **comments are dropped** by
198
+ the rewrite. Use `.json` or `.env` when a hand-written YAML file must keep its
199
+ comments.
200
+
201
+ ## Security notes
202
+
203
+ - **The token is the capability.** 256 bits of `crypto.randomBytes`, base64url,
204
+ single use. A successful submit or a cancel kills it: the link still opens, but
205
+ only to say "already used" or "cancelled". Nothing else can read a form.
206
+ - **The value only ever travels browser → host.** It is not logged, not echoed
207
+ back into the page, and not returned to the model. Logs carry at most the first
208
+ eight characters of a token.
209
+ - **The page never accepts a value twice.** A second POST on the same token is a
210
+ `410` and writes nothing.
211
+ - **The page holds no third-party content.** `default-src 'none'` with inline
212
+ style and script only, `form-action 'self'`, `base-uri 'none'`, no referrer,
213
+ no store, no framing.
214
+ - **One-time links are visible to whoever can read the chat.** The URL is safe to
215
+ post because it carries no secret; anything that can submit it first wins.
216
+ Treat the window as `ttlSeconds`, and cancel a form you no longer need.
217
+ - **A link is bound to this process.** Nothing about it is durable, which is why
218
+ a restart is safe — and why every form disappears with it.
219
+
220
+ ## In-memory by design
221
+
222
+ Forms live in a `Map` in the plugin instance. There is no database, no file, no
223
+ token on disk. Consequences, all intentional:
224
+
225
+ - a restart makes every form `expired`; ask for a new link;
226
+ - an expired form, a used link and a cancelled form stay answerable for an hour
227
+ past their TTL, then a lazy sweep drops them and the token becomes unknown;
228
+ - two DSH processes do not share forms, so a link created by one is unknown to
229
+ the other;
230
+ - `secret_list` shows this process's forms only.
231
+
232
+ ## Development
233
+
234
+ ```sh
235
+ npm test # node --test, no dependencies
236
+ npm pack --dry-run # what would ship
237
+ ```
238
+
239
+ The suite drives the real `apply()` against a stub host: tool definitions are
240
+ captured as a real agent would call them, and the route handler is invoked with
241
+ `node:stream` request doubles, so no port is opened. TTL cases move the clock
242
+ with `node:test` mock timers instead of sleeping.
243
+
244
+ ## Limits
245
+
246
+ - Node >= 22, zero runtime dependencies.
247
+ - The page is served by the Web GUI host only; a headless composition with no
248
+ `webServer` cannot use this plugin.
249
+ - `label` is 2..5 words and `description` 300 characters: the form is a prompt
250
+ for one value, not a second chat.
251
+ - `kind: 'single'` removes embedded newlines, so a pasted key file must use
252
+ `kind: 'multi'`.
253
+
254
+ ## License
255
+
256
+ MIT — see [LICENSE](LICENSE).
257
+
258
+ ## Why the single-line field is a textarea
259
+
260
+ Firefox offers its password manager on `input[type=password]`, and on text inputs
261
+ it heuristically reads as login fields (the same problem the Telegram bot card
262
+ hit with its group reference). A `textarea` is never treated as a login field, so
263
+ the single-line form uses a one-row textarea; the value is hidden by an overlay
264
+ of bullets rather than by the element type, which keeps the reveal toggle working
265
+ in every browser, including those without `-webkit-text-security`.