@crocs-muni/scrutiny-fabric-mcp 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 +21 -0
- package/README.md +213 -2
- package/dist/approval/summary.d.ts +19 -0
- package/dist/approval/summary.d.ts.map +1 -0
- package/dist/approval/summary.js +53 -0
- package/dist/approval/summary.js.map +1 -0
- package/dist/artifacts/blossom.d.ts +38 -0
- package/dist/artifacts/blossom.d.ts.map +1 -0
- package/dist/artifacts/blossom.js +95 -0
- package/dist/artifacts/blossom.js.map +1 -0
- package/dist/artifacts/url.d.ts +18 -0
- package/dist/artifacts/url.d.ts.map +1 -0
- package/dist/artifacts/url.js +53 -0
- package/dist/artifacts/url.js.map +1 -0
- package/dist/bin.d.ts +8 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +25 -0
- package/dist/bin.js.map +1 -0
- package/dist/cli/main.d.ts +25 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +147 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/terminal.d.ts +7 -0
- package/dist/cli/terminal.d.ts.map +1 -0
- package/dist/cli/terminal.js +57 -0
- package/dist/cli/terminal.js.map +1 -0
- package/dist/compose/content.d.ts +61 -0
- package/dist/compose/content.d.ts.map +1 -0
- package/dist/compose/content.js +116 -0
- package/dist/compose/content.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/package.d.ts +6 -0
- package/dist/package.d.ts.map +1 -0
- package/dist/package.js +8 -0
- package/dist/package.js.map +1 -0
- package/dist/plan/draft.d.ts +109 -0
- package/dist/plan/draft.d.ts.map +1 -0
- package/dist/plan/draft.js +405 -0
- package/dist/plan/draft.js.map +1 -0
- package/dist/plan/files.d.ts +32 -0
- package/dist/plan/files.d.ts.map +1 -0
- package/dist/plan/files.js +69 -0
- package/dist/plan/files.js.map +1 -0
- package/dist/plan/hash.d.ts +12 -0
- package/dist/plan/hash.d.ts.map +1 -0
- package/dist/plan/hash.js +32 -0
- package/dist/plan/hash.js.map +1 -0
- package/dist/plan/schema.d.ts +128 -0
- package/dist/plan/schema.d.ts.map +1 -0
- package/dist/plan/schema.js +157 -0
- package/dist/plan/schema.js.map +1 -0
- package/dist/preflight/gates.d.ts +31 -0
- package/dist/preflight/gates.d.ts.map +1 -0
- package/dist/preflight/gates.js +119 -0
- package/dist/preflight/gates.js.map +1 -0
- package/dist/publish/journal.d.ts +44 -0
- package/dist/publish/journal.d.ts.map +1 -0
- package/dist/publish/journal.js +107 -0
- package/dist/publish/journal.js.map +1 -0
- package/dist/publish/lock.d.ts +7 -0
- package/dist/publish/lock.d.ts.map +1 -0
- package/dist/publish/lock.js +28 -0
- package/dist/publish/lock.js.map +1 -0
- package/dist/publish/run.d.ts +90 -0
- package/dist/publish/run.d.ts.map +1 -0
- package/dist/publish/run.js +341 -0
- package/dist/publish/run.js.map +1 -0
- package/dist/refusal.d.ts +30 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +8 -0
- package/dist/refusal.js.map +1 -0
- package/dist/relay/client.d.ts +30 -0
- package/dist/relay/client.d.ts.map +1 -0
- package/dist/relay/client.js +104 -0
- package/dist/relay/client.js.map +1 -0
- package/dist/relay/http-base.d.ts +3 -0
- package/dist/relay/http-base.d.ts.map +1 -0
- package/dist/relay/http-base.js +7 -0
- package/dist/relay/http-base.js.map +1 -0
- package/dist/relay/network.d.ts +13 -0
- package/dist/relay/network.d.ts.map +1 -0
- package/dist/relay/network.js +41 -0
- package/dist/relay/network.js.map +1 -0
- package/dist/relay/nip11.d.ts +30 -0
- package/dist/relay/nip11.d.ts.map +1 -0
- package/dist/relay/nip11.js +82 -0
- package/dist/relay/nip11.js.map +1 -0
- package/dist/relay/socket.d.ts +57 -0
- package/dist/relay/socket.d.ts.map +1 -0
- package/dist/relay/socket.js +255 -0
- package/dist/relay/socket.js.map +1 -0
- package/dist/server/guidance.d.ts +71 -0
- package/dist/server/guidance.d.ts.map +1 -0
- package/dist/server/guidance.js +190 -0
- package/dist/server/guidance.js.map +1 -0
- package/dist/server/live.d.ts +12 -0
- package/dist/server/live.d.ts.map +1 -0
- package/dist/server/live.js +56 -0
- package/dist/server/live.js.map +1 -0
- package/dist/server/plans.d.ts +21 -0
- package/dist/server/plans.d.ts.map +1 -0
- package/dist/server/plans.js +45 -0
- package/dist/server/plans.js.map +1 -0
- package/dist/server/schemas.d.ts +185 -0
- package/dist/server/schemas.d.ts.map +1 -0
- package/dist/server/schemas.js +115 -0
- package/dist/server/schemas.js.map +1 -0
- package/dist/server/server.d.ts +33 -0
- package/dist/server/server.d.ts.map +1 -0
- package/dist/server/server.js +429 -0
- package/dist/server/server.js.map +1 -0
- package/dist/signer/event.d.ts +17 -0
- package/dist/signer/event.d.ts.map +1 -0
- package/dist/signer/event.js +48 -0
- package/dist/signer/event.js.map +1 -0
- package/dist/signer/identity.d.ts +15 -0
- package/dist/signer/identity.d.ts.map +1 -0
- package/dist/signer/identity.js +41 -0
- package/dist/signer/identity.js.map +1 -0
- package/dist/signer/keys.d.ts +32 -0
- package/dist/signer/keys.d.ts.map +1 -0
- package/dist/signer/keys.js +116 -0
- package/dist/signer/keys.js.map +1 -0
- package/dist/signer/signer.d.ts +47 -0
- package/dist/signer/signer.d.ts.map +1 -0
- package/dist/signer/signer.js +111 -0
- package/dist/signer/signer.js.map +1 -0
- package/package.json +56 -3
- package/src/approval/summary.ts +68 -0
- package/src/artifacts/blossom.ts +134 -0
- package/src/artifacts/url.ts +62 -0
- package/src/bin.ts +25 -0
- package/src/cli/main.ts +189 -0
- package/src/cli/terminal.ts +55 -0
- package/src/compose/content.ts +152 -0
- package/src/index.ts +36 -0
- package/src/package.ts +13 -0
- package/src/plan/draft.ts +782 -0
- package/src/plan/files.ts +79 -0
- package/src/plan/hash.ts +33 -0
- package/src/plan/schema.ts +214 -0
- package/src/preflight/gates.ts +139 -0
- package/src/publish/journal.ts +139 -0
- package/src/publish/lock.ts +34 -0
- package/src/publish/run.ts +483 -0
- package/src/refusal.ts +57 -0
- package/src/relay/client.ts +126 -0
- package/src/relay/http-base.ts +6 -0
- package/src/relay/network.ts +44 -0
- package/src/relay/nip11.ts +112 -0
- package/src/relay/socket.ts +314 -0
- package/src/server/guidance.ts +205 -0
- package/src/server/live.ts +73 -0
- package/src/server/plans.ts +61 -0
- package/src/server/schemas.ts +137 -0
- package/src/server/server.ts +641 -0
- package/src/signer/event.ts +50 -0
- package/src/signer/identity.ts +50 -0
- package/src/signer/keys.ts +134 -0
- package/src/signer/signer.ts +166 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 CRoCS
|
|
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,214 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @crocs-muni/scrutiny-fabric-mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An MCP server that turns a publisher's local security files (datasheets, test reports, advisories)
|
|
4
|
+
into [SCRUTINY Fabric](https://github.com/crocs-muni/scrutiny-fabric) events and publishes them to
|
|
5
|
+
Nostr relays after the user approves the exact plan. The agent drafts a plan; the server composes,
|
|
6
|
+
checks, signs and publishes it. Design: [docs/specs/mcp-publishing.md](../../docs/specs/mcp-publishing.md).
|
|
7
|
+
|
|
8
|
+
Requires Node.js 22 or later. The signing key lives in the OS keystore (macOS Keychain, Windows
|
|
9
|
+
Credential Manager, Linux Secret Service); it is never in a file, an environment variable or the
|
|
10
|
+
host's configuration.
|
|
11
|
+
|
|
12
|
+
## 1. Create your key (once per laptop)
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npx @crocs-muni/scrutiny-fabric-mcp@0.2.0 keygen
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`keygen` stores the key in the OS keystore and prints two things:
|
|
19
|
+
|
|
20
|
+
- your **npub**: send it to the relay operator, who adds it to the relay's publisher allowlist;
|
|
21
|
+
- an **ncryptsec** backup (the key encrypted with a password you choose): store it, with the
|
|
22
|
+
password, somewhere safe.
|
|
23
|
+
|
|
24
|
+
In a terminal it asks for the backup password twice, with no echo. With no terminal it reads
|
|
25
|
+
**exactly one** line from stdin instead, so a script or an agent can create the key and keep the
|
|
26
|
+
password it generated:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
printf '%s\n' "$BACKUP_PASSWORD" | npx @crocs-muni/scrutiny-fabric-mcp@0.2.0 keygen
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Either way the password is never an argument (shell history) and the key itself is never printed.
|
|
33
|
+
|
|
34
|
+
`import` loads an existing key instead (it prompts for it; never pass a key as an argument), and
|
|
35
|
+
`whoami` prints the npub in use.
|
|
36
|
+
|
|
37
|
+
## 2. Warm the npx cache (once)
|
|
38
|
+
|
|
39
|
+
The first `npx` run downloads the package and the native keyring binary, which can take longer
|
|
40
|
+
than a host's default server-start timeout. Run the server once in a terminal, wait until it is
|
|
41
|
+
silent (it is waiting for a host on stdin), then press Ctrl+C:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npx -y @crocs-muni/scrutiny-fabric-mcp@0.2.0
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 3. Add the server to your host
|
|
48
|
+
|
|
49
|
+
Every snippet pins the **exact** version, so a later (possibly tampered) release is never picked
|
|
50
|
+
up silently. When you upgrade, change the version on purpose.
|
|
51
|
+
|
|
52
|
+
Each snippet also raises the host's timeouts where it has them: 120 s for server start (a cold
|
|
53
|
+
`npx` start), and 120 s for a tool call (`publish_plan` returns within about 25 s and resumes on
|
|
54
|
+
the next call, so this is margin).
|
|
55
|
+
|
|
56
|
+
On Windows, plain `npx` works in every host below that documents Windows. If a host reports that
|
|
57
|
+
it cannot find `npx` (`ENOENT`), use `"command": "cmd"` with `"args": ["/c", "npx", "-y",
|
|
58
|
+
"@crocs-muni/scrutiny-fabric-mcp@0.2.0"]` instead.
|
|
59
|
+
|
|
60
|
+
### Claude Code
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
claude mcp add --scope user scrutiny-fabric -- npx -y @crocs-muni/scrutiny-fabric-mcp@0.2.0
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
or, shared with a project, in `.mcp.json`:
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"mcpServers": {
|
|
71
|
+
"scrutiny-fabric": {
|
|
72
|
+
"command": "npx",
|
|
73
|
+
"args": ["-y", "@crocs-muni/scrutiny-fabric-mcp@0.2.0"],
|
|
74
|
+
"timeout": 120000
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Server start: the `MCP_TIMEOUT` environment variable, in ms (default 30000). Start Claude Code with
|
|
81
|
+
`MCP_TIMEOUT=120000 claude` (PowerShell: `$env:MCP_TIMEOUT=120000; claude`), or warm the cache
|
|
82
|
+
first (step 2).
|
|
83
|
+
|
|
84
|
+
### Claude Desktop
|
|
85
|
+
|
|
86
|
+
Settings → Developer → Edit Config opens `claude_desktop_config.json`
|
|
87
|
+
(`%APPDATA%\Claude\` on Windows, `~/Library/Application Support/Claude/` on macOS):
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"mcpServers": {
|
|
92
|
+
"scrutiny-fabric": {
|
|
93
|
+
"command": "npx",
|
|
94
|
+
"args": ["-y", "@crocs-muni/scrutiny-fabric-mcp@0.2.0"]
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Quit and restart Claude Desktop afterwards. It has no documented timeout setting, so warm the cache
|
|
101
|
+
first (step 2). The server's log is `mcp-server-scrutiny-fabric.log` in Claude's `logs` folder.
|
|
102
|
+
|
|
103
|
+
### Codex (CLI, ChatGPT desktop app, IDE extension)
|
|
104
|
+
|
|
105
|
+
All three read `~/.codex/config.toml` (`%USERPROFILE%\.codex\config.toml` on Windows):
|
|
106
|
+
|
|
107
|
+
```toml
|
|
108
|
+
[mcp_servers.scrutiny-fabric]
|
|
109
|
+
command = "npx"
|
|
110
|
+
args = ["-y", "@crocs-muni/scrutiny-fabric-mcp@0.2.0"]
|
|
111
|
+
startup_timeout_sec = 120 # default 10: too short for a cold npx start
|
|
112
|
+
tool_timeout_sec = 120 # default 60
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
`codex mcp add scrutiny-fabric -- npx -y @crocs-muni/scrutiny-fabric-mcp@0.2.0` adds the first
|
|
116
|
+
three lines; add the timeouts by hand. The approval dialog needs `approval_policy` to let MCP
|
|
117
|
+
elicitations through: `"never"` declines them, and so does a granular policy without
|
|
118
|
+
`mcp_elicitations = true`.
|
|
119
|
+
|
|
120
|
+
### opencode
|
|
121
|
+
|
|
122
|
+
In `opencode.json` (project) or `~/.config/opencode/opencode.json` (global):
|
|
123
|
+
|
|
124
|
+
```json
|
|
125
|
+
{
|
|
126
|
+
"$schema": "https://opencode.ai/config.json",
|
|
127
|
+
"mcp": {
|
|
128
|
+
"servers": {
|
|
129
|
+
"scrutiny-fabric": {
|
|
130
|
+
"type": "local",
|
|
131
|
+
"command": ["npx", "-y", "@crocs-muni/scrutiny-fabric-mcp@0.2.0"],
|
|
132
|
+
"timeout": { "startup": 120000, "execution": 120000 }
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Older opencode versions (config format V1) take the server directly under `mcp`, with
|
|
140
|
+
`"enabled": true` and a single `"timeout": 120000`.
|
|
141
|
+
|
|
142
|
+
### omp (oh-my-pi)
|
|
143
|
+
|
|
144
|
+
In `~/.omp/agent/mcp.json` (user) or `.omp/mcp.json` (project); omp also reads a project's
|
|
145
|
+
`.mcp.json`:
|
|
146
|
+
|
|
147
|
+
```json
|
|
148
|
+
{
|
|
149
|
+
"mcpServers": {
|
|
150
|
+
"scrutiny-fabric": {
|
|
151
|
+
"type": "stdio",
|
|
152
|
+
"command": "npx",
|
|
153
|
+
"args": ["-y", "@crocs-muni/scrutiny-fabric-mcp@0.2.0"],
|
|
154
|
+
"timeout": 120000
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
omp uses one timer, default 30 s, for both server start and each tool call (`OMP_MCP_TIMEOUT_MS`
|
|
161
|
+
overrides it for all servers), so set `timeout`.
|
|
162
|
+
|
|
163
|
+
### VS Code (GitHub Copilot) and Cursor
|
|
164
|
+
|
|
165
|
+
Both take the same `mcpServers` shape, in `~/.copilot/mcp-config.json` (VS Code) or
|
|
166
|
+
`~/.cursor/mcp.json` / `.cursor/mcp.json` (Cursor):
|
|
167
|
+
|
|
168
|
+
```json
|
|
169
|
+
{
|
|
170
|
+
"mcpServers": {
|
|
171
|
+
"scrutiny-fabric": {
|
|
172
|
+
"type": "stdio",
|
|
173
|
+
"command": "npx",
|
|
174
|
+
"args": ["-y", "@crocs-muni/scrutiny-fabric-mcp@0.2.0"]
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Neither documents a timeout setting; warm the cache first (step 2).
|
|
181
|
+
|
|
182
|
+
## 4. Check it
|
|
183
|
+
|
|
184
|
+
Ask the agent to call the `status` tool. `signer.state` must be `ready` and `signer.npub` must be
|
|
185
|
+
the npub you sent the relay operator. Otherwise `signer.fix` says what to do.
|
|
186
|
+
|
|
187
|
+
## How publishing works
|
|
188
|
+
|
|
189
|
+
1. Point the agent at a folder with your files and ask it to publish them. It reads the
|
|
190
|
+
`scrutiny://publisher-guide` resource, drafts a plan, and calls `draft_plan`.
|
|
191
|
+
2. `draft_plan` checks the plan and returns a preview plus **open questions**; the agent asks you
|
|
192
|
+
the ones it cannot settle and drafts again until the plan is ready.
|
|
193
|
+
3. `publish_plan` asks for your approval of that exact plan (its hash):
|
|
194
|
+
- in hosts with MCP form dialogs (elicitation), as an approve/decline dialog;
|
|
195
|
+
- otherwise in the chat: the agent shows you a summary and a six-character code, and you reply
|
|
196
|
+
with the code to approve. This also happens when a host announces dialogs but cancels the
|
|
197
|
+
dialog or never shows it (reported for Claude Desktop chat and Cowork). Declining the dialog
|
|
198
|
+
stops there, with no code offered.
|
|
199
|
+
4. The server signs and publishes in a fixed order, reads each event back from the relay, and
|
|
200
|
+
records progress in `.scrutiny/` inside your folder, so an interrupted run resumes without
|
|
201
|
+
duplicates. `verify` re-checks published events at any time.
|
|
202
|
+
|
|
203
|
+
Published events are immutable; corrections are new events. The preview says which fields can
|
|
204
|
+
never change.
|
|
205
|
+
|
|
206
|
+
## Development
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
pnpm -C packages/mcp test # unit and integration tests
|
|
210
|
+
pnpm -r build && pnpm -C packages/mcp run e2e # real relay (needs Go) and the built bin over stdio
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
The e2e builds `relay/cmd/relay`, starts it on a loopback port and publishes through it. Without Go
|
|
214
|
+
it fails; it never skips.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The approval summary (spec §7.1), rendered by the server from the template graph, never from
|
|
3
|
+
* agent text, and the chat-fallback approval code (§7).
|
|
4
|
+
*/
|
|
5
|
+
import type { TemplateGraph } from '../plan/draft.js';
|
|
6
|
+
/**
|
|
7
|
+
* Six characters derived from the plan hash. It proves only that the agent called publish_plan
|
|
8
|
+
* twice for the same plan (§7): the Level 1 chat fallback, stated openly in the spec.
|
|
9
|
+
*/
|
|
10
|
+
export declare function approvalCode(planHash: string): string;
|
|
11
|
+
export declare function renderSummary(opts: {
|
|
12
|
+
readonly graph: TemplateGraph;
|
|
13
|
+
readonly npub: string;
|
|
14
|
+
readonly planHash: string;
|
|
15
|
+
readonly planPath: string;
|
|
16
|
+
/** Events already acked in earlier calls (§7.3); 0 for a fresh run. */
|
|
17
|
+
readonly published: number;
|
|
18
|
+
}): string;
|
|
19
|
+
//# sourceMappingURL=summary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summary.d.ts","sourceRoot":"","sources":["../../src/approval/summary.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAIrD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAIrD;AAUD,wBAAgB,aAAa,CAAC,IAAI,EAAE;IAClC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAA;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,uEAAuE;IACvE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAC3B,GAAG,MAAM,CA+BT"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The approval summary (spec §7.1), rendered by the server from the template graph, never from
|
|
3
|
+
* agent text, and the chat-fallback approval code (§7).
|
|
4
|
+
*/
|
|
5
|
+
import { sha256 } from '@noble/hashes/sha2.js';
|
|
6
|
+
import { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js';
|
|
7
|
+
const MAX_PRODUCTS = 5;
|
|
8
|
+
/**
|
|
9
|
+
* Six characters derived from the plan hash. It proves only that the agent called publish_plan
|
|
10
|
+
* twice for the same plan (§7): the Level 1 chat fallback, stated openly in the spec.
|
|
11
|
+
*/
|
|
12
|
+
export function approvalCode(planHash) {
|
|
13
|
+
return bytesToHex(sha256(utf8ToBytes(`scrutiny-approval:${planHash}`)))
|
|
14
|
+
.slice(0, 6)
|
|
15
|
+
.toUpperCase();
|
|
16
|
+
}
|
|
17
|
+
function typeOf(event) {
|
|
18
|
+
return event.ref.slice(0, event.ref.indexOf(':'));
|
|
19
|
+
}
|
|
20
|
+
function plural(n, one, many) {
|
|
21
|
+
return `${n} ${n === 1 ? one : many}`;
|
|
22
|
+
}
|
|
23
|
+
export function renderSummary(opts) {
|
|
24
|
+
const { graph } = opts;
|
|
25
|
+
const count = (type) => graph.events.filter((e) => typeOf(e) === type).length;
|
|
26
|
+
const total = graph.events.length;
|
|
27
|
+
const uploads = graph.blobs.filter((b) => b.via === 'upload');
|
|
28
|
+
const urls = graph.blobs.length - uploads.length;
|
|
29
|
+
const megabytes = (uploads.reduce((sum, b) => sum + b.size, 0) / 1e6).toFixed(1);
|
|
30
|
+
const products = graph.events.filter((e) => typeOf(e) === 'product');
|
|
31
|
+
const productLines = products.slice(0, MAX_PRODUCTS).map((e) => {
|
|
32
|
+
const headline = e.content.split('\n')[0] ?? '';
|
|
33
|
+
const indexers = e.tags.filter((t) => t[0] === 'i').map((t) => t[1]);
|
|
34
|
+
return ` - ${headline} [${indexers.join(', ')}]`;
|
|
35
|
+
});
|
|
36
|
+
if (products.length > MAX_PRODUCTS)
|
|
37
|
+
productLines.push(` … and ${products.length - MAX_PRODUCTS} more`);
|
|
38
|
+
return [
|
|
39
|
+
`Publish to SCRUTINY Fabric as ${opts.npub}`,
|
|
40
|
+
`Relays: ${graph.relays.map((r, i) => `${r} (${i === 0 ? 'primary' : 'mirror'})`).join(', ')}`,
|
|
41
|
+
`Events: ${plural(count('profile'), 'profile', 'profiles')} · ${plural(count('product'), 'product', 'products')} · ${count('metadata')} metadata · ${plural(count('binding'), 'binding', 'bindings')} = ${total}`,
|
|
42
|
+
`Files: ${plural(uploads.length, 'upload', 'uploads')} (${megabytes} MB) · ${plural(urls, 'verified URL', 'verified URLs')}`,
|
|
43
|
+
'Products:',
|
|
44
|
+
...productLines,
|
|
45
|
+
...(opts.published > 0
|
|
46
|
+
? [`${opts.published} of ${total} already published; ${total - opts.published} remaining.`]
|
|
47
|
+
: []),
|
|
48
|
+
'These are permanent and public. Indexers and files cannot be changed later.',
|
|
49
|
+
`Full plan: ${opts.planPath}`,
|
|
50
|
+
`Plan hash: ${opts.planHash}`,
|
|
51
|
+
].join('\n');
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=summary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summary.js","sourceRoot":"","sources":["../../src/approval/summary.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAGhE,MAAM,YAAY,GAAG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AE,UAAU,CAAC,MAAM,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,MAAM,KAAK,CAAC,UAAU,CAAC,eAAe,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,MAAM,KAAK,EAAE;QACjN,WAAW,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,KAAK,SAAS,UAAU,MAAM,CAAC,IAAI,EAAE,cAAc,EAAE,eAAe,CAAC,EAAE;QAC7H,WAAW;QACX,GAAG,YAAY;QACf,GAAG,CAAC,IAAI,CAAC,SAAS,GAAG,CAAC;YACpB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,OAAO,KAAK,uBAAuB,KAAK,GAAG,IAAI,CAAC,SAAS,aAAa,CAAC;YAC3F,CAAC,CAAC,EAAE,CAAC;QACP,6EAA6E;QAC7E,cAAc,IAAI,CAAC,QAAQ,EAAE;QAC7B,cAAc,IAAI,CAAC,QAAQ,EAAE;KAC9B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Blossom client (spec §9.3), used by the run engine before an event citing the blob is signed.
|
|
3
|
+
*
|
|
4
|
+
* 1. `HEAD /<x>`: present → done (uploads are idempotent by hash).
|
|
5
|
+
* 2. `PUT /upload`, authorised by a kind-24242 event signed with the publisher key, tags
|
|
6
|
+
* `t upload`, `x`, `expiration` (now + 300) and `server` (URL form).
|
|
7
|
+
* 3. The returned descriptor's `sha256` must equal `x`.
|
|
8
|
+
*
|
|
9
|
+
* The URL the plan cites is fixed by the client, `https://<primary-host>/<x><ext>`; the relay
|
|
10
|
+
* serves a blob by hash whatever extension a request uses.
|
|
11
|
+
*/
|
|
12
|
+
import type { Refusal } from '../refusal.js';
|
|
13
|
+
import type { SignerPort } from '../signer/signer.js';
|
|
14
|
+
export interface BlobRef {
|
|
15
|
+
readonly x: string;
|
|
16
|
+
readonly size: number;
|
|
17
|
+
readonly m: string;
|
|
18
|
+
/** URL extension with its dot, from the extension map (spec §9.1). */
|
|
19
|
+
readonly ext: string;
|
|
20
|
+
}
|
|
21
|
+
export declare class BlossomError extends Error {
|
|
22
|
+
readonly refusal: Refusal;
|
|
23
|
+
constructor(refusal: Refusal);
|
|
24
|
+
}
|
|
25
|
+
export declare function blobUrl(primary: string, blob: Pick<BlobRef, 'x' | 'ext'>): string;
|
|
26
|
+
export declare function ensureBlob(opts: {
|
|
27
|
+
readonly primary: string;
|
|
28
|
+
readonly blob: BlobRef;
|
|
29
|
+
readonly bytes: () => Promise<Uint8Array>;
|
|
30
|
+
readonly signer: SignerPort;
|
|
31
|
+
/** Unix seconds, the signer's clock. */
|
|
32
|
+
readonly now: () => number;
|
|
33
|
+
readonly fetch: typeof fetch;
|
|
34
|
+
}): Promise<{
|
|
35
|
+
readonly state: 'present' | 'uploaded';
|
|
36
|
+
readonly url: string;
|
|
37
|
+
}>;
|
|
38
|
+
//# sourceMappingURL=blossom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blossom.d.ts","sourceRoot":"","sources":["../../src/artifacts/blossom.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAErD,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAA;IAClB,sEAAsE;IACtE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CACrB;AAED,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;gBACb,OAAO,EAAE,OAAO;CAK7B;AAID,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,GAAG,KAAK,CAAC,GAAG,MAAM,CAEjF;AAkBD,wBAAsB,UAAU,CAAC,IAAI,EAAE;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAA;IACzC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAA;IAC3B,wCAAwC;IACxC,QAAQ,CAAC,GAAG,EAAE,MAAM,MAAM,CAAA;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,KAAK,CAAA;CAC7B,GAAG,OAAO,CAAC;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,UAAU,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CAsE5E"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Blossom client (spec §9.3), used by the run engine before an event citing the blob is signed.
|
|
3
|
+
*
|
|
4
|
+
* 1. `HEAD /<x>`: present → done (uploads are idempotent by hash).
|
|
5
|
+
* 2. `PUT /upload`, authorised by a kind-24242 event signed with the publisher key, tags
|
|
6
|
+
* `t upload`, `x`, `expiration` (now + 300) and `server` (URL form).
|
|
7
|
+
* 3. The returned descriptor's `sha256` must equal `x`.
|
|
8
|
+
*
|
|
9
|
+
* The URL the plan cites is fixed by the client, `https://<primary-host>/<x><ext>`; the relay
|
|
10
|
+
* serves a blob by hash whatever extension a request uses.
|
|
11
|
+
*/
|
|
12
|
+
import { httpBase } from '../relay/http-base.js';
|
|
13
|
+
export class BlossomError extends Error {
|
|
14
|
+
refusal;
|
|
15
|
+
constructor(refusal) {
|
|
16
|
+
super(refusal.problem);
|
|
17
|
+
this.name = 'BlossomError';
|
|
18
|
+
this.refusal = refusal;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const AUTH_TTL_S = 300;
|
|
22
|
+
export function blobUrl(primary, blob) {
|
|
23
|
+
return `${httpBase(primary)}/${blob.x}${blob.ext}`;
|
|
24
|
+
}
|
|
25
|
+
function fail(code, problem, fix, relayMessage = null) {
|
|
26
|
+
return new BlossomError({
|
|
27
|
+
code,
|
|
28
|
+
field: null,
|
|
29
|
+
problem,
|
|
30
|
+
fix,
|
|
31
|
+
source: 'artifact',
|
|
32
|
+
relay_message: relayMessage,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export async function ensureBlob(opts) {
|
|
36
|
+
const base = httpBase(opts.primary);
|
|
37
|
+
const url = blobUrl(opts.primary, opts.blob);
|
|
38
|
+
try {
|
|
39
|
+
const head = await opts.fetch(`${base}/${opts.blob.x}`, {
|
|
40
|
+
method: 'HEAD',
|
|
41
|
+
signal: AbortSignal.timeout(15_000),
|
|
42
|
+
});
|
|
43
|
+
if (head.ok)
|
|
44
|
+
return { state: 'present', url };
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// Treated as absent: the upload below will say whether the server is reachable.
|
|
48
|
+
}
|
|
49
|
+
const now = opts.now();
|
|
50
|
+
const auth = await opts.signer.sign({
|
|
51
|
+
kind: 24242,
|
|
52
|
+
created_at: now,
|
|
53
|
+
tags: [
|
|
54
|
+
['t', 'upload'],
|
|
55
|
+
['x', opts.blob.x],
|
|
56
|
+
['expiration', String(now + AUTH_TTL_S)],
|
|
57
|
+
['server', base],
|
|
58
|
+
],
|
|
59
|
+
content: `Upload ${opts.blob.x}`,
|
|
60
|
+
});
|
|
61
|
+
const body = await opts.bytes();
|
|
62
|
+
let response;
|
|
63
|
+
try {
|
|
64
|
+
response = await opts.fetch(`${base}/upload`, {
|
|
65
|
+
method: 'PUT',
|
|
66
|
+
headers: {
|
|
67
|
+
authorization: `Nostr ${Buffer.from(JSON.stringify(auth), 'utf8').toString('base64')}`,
|
|
68
|
+
'content-type': opts.blob.m,
|
|
69
|
+
'x-sha-256': opts.blob.x,
|
|
70
|
+
},
|
|
71
|
+
body,
|
|
72
|
+
signal: AbortSignal.timeout(300_000),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
catch (cause) {
|
|
76
|
+
throw fail('artifact.upload_failed', `uploading ${opts.blob.x} failed: ${cause instanceof Error ? cause.message : 'unknown'}`, 'Check the connection and call publish_plan again to resume.');
|
|
77
|
+
}
|
|
78
|
+
if (!response.ok) {
|
|
79
|
+
const reason = response.headers.get('x-reason');
|
|
80
|
+
throw fail('artifact.upload_failed', `the Blossom server refused ${opts.blob.x} with HTTP ${response.status}`, 'Read the relay message; if the key is not allowlisted, send the npub to the relay operator.', reason);
|
|
81
|
+
}
|
|
82
|
+
let descriptor;
|
|
83
|
+
try {
|
|
84
|
+
descriptor = await response.json();
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
descriptor = null;
|
|
88
|
+
}
|
|
89
|
+
const returned = descriptor?.sha256;
|
|
90
|
+
if (returned !== opts.blob.x) {
|
|
91
|
+
throw fail('artifact.upload_mismatch', `the Blossom server stored a blob whose sha256 is not ${opts.blob.x}`, 'Do not publish events citing this blob; report it to the relay operator.');
|
|
92
|
+
}
|
|
93
|
+
return { state: 'uploaded', url };
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=blossom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blossom.js","sourceRoot":"","sources":["../../src/artifacts/blossom.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAWhD,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,OAAO,CAAS;IACzB,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QACtB,IAAI,CAAC,IAAI,GAAG,cAAc,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AC/C,MAAM,IAAI,CACR,wBAAwB,EACxB,8BAA8B,IAAI,CAAC,IAAI,CAAC,CAAC,cAAc,QAAQ,CAAC,MAAM,EAAE,EACxE,6FAA6F,EAC7F,MAAM,CACP,CAAA;IACH,CAAC;IACD,IAAI,UAAmB,CAAA;IACvB,IAAI,CAAC;QACH,UAAU,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;IACpC,CAAC;IAAC,MAAM,CAAC;QACP,UAAU,GAAG,IAAI,CAAA;IACnB,CAAC;IACD,MAAM,QAAQ,GAAI,UAA0C,EAAE,MAAM,CAAA;IACpE,IAAI,QAAQ,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,CACR,0BAA0B,EAC1B,wDAAwD,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,EACrE,0EAA0E,CAC3E,CAAA;IACH,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,CAAA;AACnC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Publisher-hosted URL check (spec §9.2): download over HTTPS only, at most 3 redirects, capped at
|
|
3
|
+
* 50 MiB, and compare SHA-256 with the local file. Nothing is uploaded.
|
|
4
|
+
*/
|
|
5
|
+
export type UrlCheck = {
|
|
6
|
+
readonly kind: 'match';
|
|
7
|
+
} | {
|
|
8
|
+
readonly kind: 'mismatch';
|
|
9
|
+
readonly x: string;
|
|
10
|
+
} | {
|
|
11
|
+
readonly kind: 'error';
|
|
12
|
+
readonly message: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function verifyUrl(url: string, expectedX: string, deps: {
|
|
15
|
+
readonly fetch: typeof fetch;
|
|
16
|
+
readonly maxBytes?: number;
|
|
17
|
+
}): Promise<UrlCheck>;
|
|
18
|
+
//# sourceMappingURL=url.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/artifacts/url.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,MAAM,MAAM,QAAQ,GAChB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GACjD;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAA;AAIxD,wBAAsB,SAAS,CAC7B,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,KAAK,CAAC;IAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GACjE,OAAO,CAAC,QAAQ,CAAC,CAyCnB"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Publisher-hosted URL check (spec §9.2): download over HTTPS only, at most 3 redirects, capped at
|
|
3
|
+
* 50 MiB, and compare SHA-256 with the local file. Nothing is uploaded.
|
|
4
|
+
*/
|
|
5
|
+
import { sha256 } from '@noble/hashes/sha2.js';
|
|
6
|
+
import { bytesToHex } from '@noble/hashes/utils.js';
|
|
7
|
+
import { MAX_ARTIFACT_BYTES } from '../plan/files.js';
|
|
8
|
+
const MAX_REDIRECTS = 3;
|
|
9
|
+
export async function verifyUrl(url, expectedX, deps) {
|
|
10
|
+
const maxBytes = deps.maxBytes ?? MAX_ARTIFACT_BYTES;
|
|
11
|
+
let current = url;
|
|
12
|
+
for (let hop = 0;; hop++) {
|
|
13
|
+
if (new URL(current).protocol !== 'https:') {
|
|
14
|
+
return { kind: 'error', message: `${current} is not HTTPS` };
|
|
15
|
+
}
|
|
16
|
+
let response;
|
|
17
|
+
try {
|
|
18
|
+
response = await deps.fetch(current, {
|
|
19
|
+
redirect: 'manual',
|
|
20
|
+
signal: AbortSignal.timeout(60_000),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
catch (cause) {
|
|
24
|
+
return {
|
|
25
|
+
kind: 'error',
|
|
26
|
+
message: `download failed: ${cause instanceof Error ? cause.message : 'unknown'}`,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (response.status >= 300 && response.status < 400) {
|
|
30
|
+
const location = response.headers.get('location');
|
|
31
|
+
if (location === null)
|
|
32
|
+
return { kind: 'error', message: `HTTP ${response.status} without a Location` };
|
|
33
|
+
if (hop === MAX_REDIRECTS)
|
|
34
|
+
return { kind: 'error', message: `more than ${MAX_REDIRECTS} redirects` };
|
|
35
|
+
current = new URL(location, current).href;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (!response.ok || response.body === null) {
|
|
39
|
+
return { kind: 'error', message: `HTTP ${response.status}` };
|
|
40
|
+
}
|
|
41
|
+
const hash = sha256.create();
|
|
42
|
+
let total = 0;
|
|
43
|
+
for await (const chunk of response.body) {
|
|
44
|
+
total += chunk.length;
|
|
45
|
+
if (total > maxBytes)
|
|
46
|
+
return { kind: 'error', message: `larger than ${maxBytes} bytes` };
|
|
47
|
+
hash.update(chunk);
|
|
48
|
+
}
|
|
49
|
+
const x = bytesToHex(hash.digest());
|
|
50
|
+
return x === expectedX ? { kind: 'match' } : { kind: 'mismatch', x };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.js","sourceRoot":"","sources":["../../src/artifacts/url.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAOrD,MAAM,aAAa,GAAG,CAAC,CA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aAAa,aAAa,YAAY,EAAE,CAAA;YAC3E,OAAO,GAAG,IAAI,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAA;YACzC,SAAQ;QACV,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,QAAQ,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YAC3C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAA;QAC9D,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,CAAA;QAC5B,IAAI,KAAK,GAAG,CAAC,CAAA;QACb,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;YACxC,KAAK,IAAI,KAAK,CAAC,MAAM,CAAA;YACrB,IAAI,KAAK,GAAG,QAAQ;gBAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,QAAQ,QAAQ,EAAE,CAAA;YACxF,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QACpB,CAAC;QACD,MAAM,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;QACnC,OAAO,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,EAAE,CAAA;IACtE,CAAC;AACH,CAAC"}
|
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Package binary (spec §13.1). With no subcommand it runs the MCP server on stdio; with one it
|
|
4
|
+
* runs the key-management CLI (spec §11.1). The key is resolved lazily on each call, so a missing
|
|
5
|
+
* key never stops the server (spec §17).
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=bin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA;;;;GAIG"}
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Package binary (spec §13.1). With no subcommand it runs the MCP server on stdio; with one it
|
|
4
|
+
* runs the key-management CLI (spec §11.1). The key is resolved lazily on each call, so a missing
|
|
5
|
+
* key never stops the server (spec §17).
|
|
6
|
+
*/
|
|
7
|
+
import { homedir } from 'node:os';
|
|
8
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
9
|
+
import { runCli } from './cli/main.js';
|
|
10
|
+
import { terminalIo } from './cli/terminal.js';
|
|
11
|
+
import { liveDeps } from './server/live.js';
|
|
12
|
+
import { createServer } from './server/server.js';
|
|
13
|
+
import { identityPath } from './signer/identity.js';
|
|
14
|
+
import { osKeystore } from './signer/signer.js';
|
|
15
|
+
const args = process.argv.slice(2);
|
|
16
|
+
if (args.length === 0) {
|
|
17
|
+
await createServer(liveDeps()).connect(new StdioServerTransport());
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
process.exitCode = await runCli(args, terminalIo(), {
|
|
21
|
+
store: osKeystore,
|
|
22
|
+
identityPath: identityPath(process.platform, process.env, homedir()),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=bin.js.map
|
package/dist/bin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAE/C,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAClC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;IACtB,MAAM,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,oBAAoB,EAAE,CAAC,CAAA;AACpE,CAAC;KAAM,CAAC;IACN,OAAO,CAAC,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE;QAClD,KAAK,EAAE,UAAU;QACjB,YAAY,EAAE,YAAY,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,CAAC;KACrE,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Key-management CLI (spec §11.1): `keygen`, `import`, `whoami`. It never runs as an agent tool;
|
|
3
|
+
* the secret is never accepted as a command-line argument (shell history) and never printed. Where
|
|
4
|
+
* input is needed, a hidden TTY prompt and piped stdin are both accepted, so a script can drive it:
|
|
5
|
+
* `keygen` prints only the NIP-49 backup and the npub.
|
|
6
|
+
*/
|
|
7
|
+
import type { SecretStore } from '../signer/signer.js';
|
|
8
|
+
export interface CliIo {
|
|
9
|
+
out(text: string): void;
|
|
10
|
+
err(text: string): void;
|
|
11
|
+
readonly stdinIsTTY: boolean;
|
|
12
|
+
/** All of piped stdin. */
|
|
13
|
+
readStdin(): Promise<string>;
|
|
14
|
+
/** A line typed on the terminal without echo. */
|
|
15
|
+
promptHidden(prompt: string): Promise<string>;
|
|
16
|
+
}
|
|
17
|
+
export interface CliDeps {
|
|
18
|
+
readonly store: () => Promise<SecretStore>;
|
|
19
|
+
readonly identityPath: string;
|
|
20
|
+
readonly randomSecret?: () => Uint8Array;
|
|
21
|
+
/** NIP-49 scrypt cost; tests lower it. */
|
|
22
|
+
readonly logN?: number;
|
|
23
|
+
}
|
|
24
|
+
export declare function runCli(argv: readonly string[], io: CliIo, deps: CliDeps): Promise<number>;
|
|
25
|
+
//# sourceMappingURL=main.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAEtD,MAAM,WAAW,KAAK;IACpB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAA;IAC5B,0BAA0B;IAC1B,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAAA;IAC5B,iDAAiD;IACjD,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CAC9C;AAED,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAA;IAC1C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,UAAU,CAAA;IACxC,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CACvB;AAyBD,wBAAsB,MAAM,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CA6B/F"}
|