@dr-co/dsh-secret-form 0.0.0-stage → 0.2.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,267 @@
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 a `dsh.bundle` layer, so `dsh plugin add` both installs it and
22
+ mounts it: it shows up in the settings plugin list, where it can be switched off
23
+ or removed like any other plugin. Host-specific settings belong in the profile's
24
+ own patch as an id-targeted override.
25
+
26
+ ### From npm
27
+
28
+ ```sh
29
+ dsh plugin --profile <profile> add @dr-co/dsh-secret-form
30
+ ```
31
+
32
+ ### From GitHub
33
+
34
+ Pin a tag when you want a revision you can point at later; the repository root is
35
+ the package, so no build step is involved.
36
+
37
+ ```sh
38
+ dsh plugin --profile <profile> add "git+https://github.com/unera/dsh-secret-form.git#v0.1.0"
39
+ # a particular commit
40
+ dsh plugin --profile <profile> add "git+https://github.com/unera/dsh-secret-form.git#<sha>"
41
+ # or a local checkout while developing
42
+ dsh plugin --profile <profile> add file:$PWD/dsh-secret-form
43
+ ```
44
+
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
+ Mount it next to the two services it uses — the Web GUI host and the agent's
49
+ tools:
50
+
51
+ ```yaml
52
+ - id: secret-form
53
+ name: '@dr-co/dsh-secret-form'
54
+ config:
55
+ routePrefix: /secret # default; must start with "/"
56
+ defaultTtlSeconds: 300 # default; every value is clamped to 30..3600
57
+ defaultLocale: en # default; en|ru|de|fr|es|pt|zh|ja
58
+ publicUrl: https://dsh.example.org # optional; see below
59
+ ```
60
+
61
+ `publicUrl` matters behind a proxy: the listener usually binds loopback, so its
62
+ own origin would produce a `http://127.0.0.1:3080/...` link that no phone can
63
+ open. When `publicUrl` is set the returned link is built from it; when it is not,
64
+ the plugin returns the listener origin unchanged and the model is told to hand it
65
+ over as-is rather than invent a hostname.
66
+
67
+ `routePrefix` moves the whole surface, which is what a host behind a path
68
+ rewriter needs. `defaultTtlSeconds` is the TTL used when a call omits
69
+ `ttlSeconds`. `defaultLocale` is the wording used when neither the link nor the
70
+ browser asks for a language; any other value is refused at mount time.
71
+
72
+ 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.
76
+
77
+ ## The four tools
78
+
79
+ ### `secret_create`
80
+
81
+ Open a form and return its link.
82
+
83
+ | argument | type | required | meaning |
84
+ | --- | --- | --- | --- |
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`. |
86
+ | `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. |
88
+ | `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": "…" }`. |
90
+ | `ttlSeconds` | integer | no | Default 300, clamped to 30..3600. |
91
+ | `allowEmpty` | boolean | no | Default `false`. When true an empty submit is accepted and reported as `empty`. |
92
+ | `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. |
94
+
95
+ Returns `{ uuid, url, expiresAt, data }`. `url` is absolute: the web server's
96
+ `getOrigin()` plus `routePrefix` plus a 43-character token.
97
+
98
+ ### `secret_result`
99
+
100
+ | argument | type | required | meaning |
101
+ | --- | --- | --- | --- |
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. |
104
+
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`.
109
+
110
+ The submitted value never appears in a tool result. Not truncated, not masked,
111
+ not hashed — absent.
112
+
113
+ ### `secret_list`
114
+
115
+ No arguments. Returns every form this process created, oldest first:
116
+
117
+ ```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": {} }]
120
+ ```
121
+
122
+ ### `secret_cancel`
123
+
124
+ | argument | type | required | meaning |
125
+ | --- | --- | --- | --- |
126
+ | `uuid` | string | yes | The uuid `secret_create` returned. |
127
+
128
+ Cancels a pending form; a form that already finished reports its current status
129
+ and is left alone.
130
+
131
+ ## The web surface
132
+
133
+ | route | method | body | result |
134
+ | --- | --- | --- | --- |
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 |
137
+
138
+ Both responses carry `Cache-Control: no-store`, `Referrer-Policy: no-referrer`,
139
+ `X-Content-Type-Options: nosniff`, `X-Frame-Options: DENY` and
140
+
141
+ ```
142
+ Content-Security-Policy: default-src 'none'; style-src 'unsafe-inline';
143
+ script-src 'unsafe-inline'; form-action 'self'; base-uri 'none'
144
+ ```
145
+
146
+ 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.
149
+
150
+ Outcome pages have distinct wording: **Saved**, **Nothing stored** (empty
151
+ submit), **Cancelled**, **Link already used**, **Link expired**, **Link not
152
+ recognised**.
153
+
154
+ ### Languages
155
+
156
+ The page's own wording exists in `en`, `ru`, `de`, `fr`, `es`, `pt`, `zh` and
157
+ `ja`; the table lives in `lib/i18n.mjs`. The locale is chosen in this order:
158
+
159
+ 1. `?lang=de` on the link (`/secret/<token>?lang=de`), which also lets the model
160
+ pin one language for a link it hands over;
161
+ 2. the browser's `Accept-Language`, ranked by q-values and matched by primary
162
+ subtag, so `de-AT` and `zh-CN`/`zh-TW`/`zh-Hans` resolve as `de` and `zh`;
163
+ 3. `defaultLocale`, and English last.
164
+
165
+ The form carries the resolved locale in a hidden `lang` field, which outranks
166
+ the header on submit, so the outcome page stays in the language the reader
167
+ started in. `<html lang="…">` follows the same value. The ref (`OPENAI_API_KEY`)
168
+ is an identifier and stays as it is; everything around it is translated.
169
+
170
+ ## Where the value goes
171
+
172
+ **Credentials (default).** `ctx.credentials.set(ref, value)` — the same store an
173
+ adapter reads through `apiKeyEnv`, so a rotated key applies to the next request.
174
+ The store refuses an empty value, which is why an empty submit is reported as
175
+ `empty` and stored nowhere.
176
+
177
+ **File.** `{ "kind": "file", "path": "/abs/or/relative/path" }`. The extension
178
+ picks the format and nothing else does — `.yaml`, `.yml`, `.json`, `.env`; any
179
+ other extension is rejected when the form is created, never guessed.
180
+
181
+ - `.env` — append the `KEY=value` line or replace the existing one in place.
182
+ Values with spaces, quotes or newlines are double-quoted with escapes.
183
+ - `.json` — parse, set the dotted path, re-serialise with 2-space indent.
184
+ - `.yaml` / `.yml` — parse, set the dotted path, re-serialise.
185
+
186
+ Writes create parent directories, go through a temp file beside the target
187
+ followed by `rename`, and land with mode `0600`. Nested objects are created when
188
+ missing; a path that already holds a scalar where a mapping is needed, or a
189
+ mapping where the leaf goes, is refused instead of destroyed. `__proto__`,
190
+ `prototype` and `constructor` are refused as path segments.
191
+
192
+ ### The YAML writer is deliberately small
193
+
194
+ The reader understands block mappings, plain and quoted scalars, comments and
195
+ blank lines. Anything else — sequences, flow collections, block scalars (`|`,
196
+ `>`), anchors, aliases, tags, multiple documents — is **refused with an error
197
+ and the file is left untouched**, because a partial implementation that rewrites
198
+ a document it half-understands is worse than a refusal. Leaf values keep their
199
+ original spelling (`port: 8080` stays `port: 8080`); **comments are dropped** by
200
+ the rewrite. Use `.json` or `.env` when a hand-written YAML file must keep its
201
+ comments.
202
+
203
+ ## Security notes
204
+
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.
213
+ - **The page holds no third-party content.** `default-src 'none'` with inline
214
+ style and script only, `form-action 'self'`, `base-uri 'none'`, no referrer,
215
+ 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.
233
+
234
+ ## Development
235
+
236
+ ```sh
237
+ npm test # node --test, no dependencies
238
+ npm pack --dry-run # what would ship
239
+ ```
240
+
241
+ The suite drives the real `apply()` against a stub host: tool definitions are
242
+ 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.
245
+
246
+ ## Limits
247
+
248
+ - Node >= 22, zero runtime dependencies.
249
+ - The page is served by the Web GUI host only; a headless composition with no
250
+ `webServer` cannot use this plugin.
251
+ - `label` is 2..5 words and `description` 300 characters: the form is a prompt
252
+ for one value, not a second chat.
253
+ - `kind: 'single'` removes embedded newlines, so a pasted key file must use
254
+ `kind: 'multi'`.
255
+
256
+ ## License
257
+
258
+ MIT — see [LICENSE](LICENSE).
259
+
260
+ ## Why the single-line field is a textarea
261
+
262
+ Firefox offers its password manager on `input[type=password]`, and on text inputs
263
+ it heuristically reads as login fields (the same problem the Telegram bot card
264
+ hit with its group reference). A `textarea` is never treated as a login field, so
265
+ the single-line form uses a one-row textarea; the value is hidden by an overlay
266
+ of bullets rather than by the element type, which keeps the reveal toggle working
267
+ in every browser, including those without `-webkit-text-security`.
@@ -0,0 +1,14 @@
1
+ # Bundle layer for dsh-secret-form.
2
+ #
3
+ # A profile that installs this package gets the plugin mounted here, so the
4
+ # settings list can switch it off or remove it. Anything host-specific — most
5
+ # often publicUrl — belongs in the profile's own patch as an id-targeted
6
+ # override of `secret-form`, because a package cannot know the host's public
7
+ # origin.
8
+ - insert:
9
+ - id: secret-form
10
+ name: '@dr-co/dsh-secret-form'
11
+ config:
12
+ routePrefix: /secret
13
+ defaultTtlSeconds: 300
14
+ defaultLocale: en