wiki-viewer 1.0.0 → 1.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/.next/standalone/README.md +365 -99
- package/.next/standalone/agents/bootstrap-prompt.md +1 -0
- package/.next/standalone/agents/wiki-viewer-skill/SKILL.md +236 -0
- package/.next/standalone/bin/wiki-viewer.js +431 -33
- package/.next/standalone/docs/agent-collab-plan.md +1615 -0
- package/.next/standalone/docs/agent-collab-v2-plan.md +771 -0
- package/.next/standalone/package.json +19 -2
- package/.next/standalone/pnpm-lock.yaml +1368 -325
- package/.next/standalone/pnpm-workspace.yaml +7 -1
- package/.next/standalone/src/app/api/agent/activity/route.ts +58 -0
- package/.next/standalone/src/app/api/agent/admin/agents/[agentId]/revoke/route.ts +40 -0
- package/.next/standalone/src/app/api/agent/admin/agents/route.ts +33 -0
- package/.next/standalone/src/app/api/agent/admin/registrations/[regId]/approve/route.ts +83 -0
- package/.next/standalone/src/app/api/agent/admin/registrations/[regId]/deny/route.ts +36 -0
- package/.next/standalone/src/app/api/agent/admin/registrations/route.ts +27 -0
- package/.next/standalone/src/app/api/agent/events/[...path]/route.ts +136 -0
- package/.next/standalone/src/app/api/agent/files/[...path]/route.ts +202 -0
- package/.next/standalone/src/app/api/agent/internal/span/route.ts +117 -0
- package/.next/standalone/src/app/api/agent/register/[regId]/route.ts +50 -0
- package/.next/standalone/src/app/api/agent/register/route.ts +110 -0
- package/.next/standalone/src/app/api/agent/settings/route.ts +30 -0
- package/.next/standalone/src/app/api/agent/settings/token/regenerate/route.ts +20 -0
- package/.next/standalone/src/app/api/agent/sidecar/[...path]/route.ts +49 -0
- package/.next/standalone/src/app/api/agents/install/route.ts +83 -0
- package/.next/standalone/src/app/api/agents/skill/route.ts +20 -0
- package/.next/standalone/src/app/api/agents/skill.tar.gz/route.ts +87 -0
- package/.next/standalone/src/app/api/auth/[...all]/route.ts +7 -0
- package/.next/standalone/src/app/api/owner/init/route.ts +14 -0
- package/.next/standalone/src/app/api/system/auth-settings/route.ts +85 -0
- package/.next/standalone/src/app/api/system/browse/route.ts +4 -0
- package/.next/standalone/src/app/api/system/clear-root/route.ts +8 -1
- package/.next/standalone/src/app/api/system/config/route.ts +5 -1
- package/.next/standalone/src/app/api/system/pins/route.ts +7 -0
- package/.next/standalone/src/app/api/system/reveal/route.ts +7 -0
- package/.next/standalone/src/app/api/system/root-status/route.ts +5 -1
- package/.next/standalone/src/app/api/system/set-root/route.ts +7 -0
- package/.next/standalone/src/app/api/wiki/app/route.ts +15 -0
- package/.next/standalone/src/app/api/wiki/content/route.ts +110 -11
- package/.next/standalone/src/app/api/wiki/folder/route.ts +7 -0
- package/.next/standalone/src/app/api/wiki/move/route.ts +7 -0
- package/.next/standalone/src/app/api/wiki/new-file/route.ts +55 -0
- package/.next/standalone/src/app/api/wiki/page/route.ts +7 -0
- package/.next/standalone/src/app/api/wiki/route.ts +10 -0
- package/.next/standalone/src/app/api/wiki/slugs/route.ts +5 -1
- package/.next/standalone/src/app/api/wiki/upload/route.ts +7 -0
- package/.next/standalone/src/app/api/wiki/watch/route.ts +6 -1
- package/.next/standalone/src/app/globals.css +70 -0
- package/.next/standalone/src/app/page.tsx +461 -217
- package/.next/standalone/src/app/signin/page.tsx +217 -0
- package/.next/standalone/src/components/ai-panel/activity-row.tsx +64 -0
- package/.next/standalone/src/components/ai-panel/ai-panel.tsx +322 -0
- package/.next/standalone/src/components/ai-panel/token-section.tsx +312 -0
- package/.next/standalone/src/components/auth-settings-sheet.tsx +209 -0
- package/.next/standalone/src/components/editor/bubble-menu.tsx +41 -2
- package/.next/standalone/src/components/editor/comment-pip.tsx +56 -0
- package/.next/standalone/src/components/editor/comment-thread.tsx +252 -0
- package/.next/standalone/src/components/editor/editor.tsx +513 -10
- package/.next/standalone/src/components/editor/extensions/proof-span.ts +60 -0
- package/.next/standalone/src/components/editor/extensions.ts +2 -0
- package/.next/standalone/src/components/editor/proof-span-popover.tsx +161 -0
- package/.next/standalone/src/components/editor/suggest-edit-popover.tsx +228 -0
- package/.next/standalone/src/components/editor/suggestion-card.tsx +201 -0
- package/.next/standalone/src/components/view-width-toggle.tsx +47 -0
- package/.next/standalone/src/components/wiki/markdown-preview.tsx +120 -0
- package/.next/standalone/src/lib/auth/allowlist.ts +50 -0
- package/.next/standalone/src/lib/auth/client.ts +4 -0
- package/.next/standalone/src/lib/auth/csrf.ts +68 -0
- package/.next/standalone/src/lib/auth/server.ts +164 -0
- package/.next/standalone/src/lib/config.ts +4 -0
- package/.next/standalone/src/lib/markdown/parse-frontmatter.ts +20 -0
- package/.next/standalone/src/lib/markdown/sanitize-schema.ts +106 -0
- package/.next/standalone/src/lib/markdown/to-html.ts +46 -8
- package/.next/standalone/src/lib/markdown/to-markdown.ts +14 -0
- package/.next/standalone/src/lib/proof/activity-shared.ts +31 -0
- package/.next/standalone/src/lib/proof/activity.ts +74 -0
- package/.next/standalone/src/lib/proof/auth.ts +132 -0
- package/.next/standalone/src/lib/proof/block-refs.ts +133 -0
- package/.next/standalone/src/lib/proof/blocks.ts +73 -0
- package/.next/standalone/src/lib/proof/client-auth.ts +23 -0
- package/.next/standalone/src/lib/proof/event-bus.ts +47 -0
- package/.next/standalone/src/lib/proof/file-lock.ts +38 -0
- package/.next/standalone/src/lib/proof/glob.ts +51 -0
- package/.next/standalone/src/lib/proof/idempotency.ts +32 -0
- package/.next/standalone/src/lib/proof/mutex.ts +32 -0
- package/.next/standalone/src/lib/proof/ops-applier.ts +678 -0
- package/.next/standalone/src/lib/proof/owner-auth.ts +2 -0
- package/.next/standalone/src/lib/proof/pending.ts +97 -0
- package/.next/standalone/src/lib/proof/proof-span.ts +141 -0
- package/.next/standalone/src/lib/proof/rate-limit.ts +53 -0
- package/.next/standalone/src/lib/proof/register-rate-limit.ts +53 -0
- package/.next/standalone/src/lib/proof/registry.ts +190 -0
- package/.next/standalone/src/lib/proof/sidecar.ts +66 -0
- package/.next/standalone/src/lib/proof/suggest-capture.ts +69 -0
- package/.next/standalone/src/lib/proof/types.ts +170 -0
- package/.next/standalone/src/lib/proof-config.ts +14 -0
- package/.next/standalone/src/middleware.ts +38 -0
- package/.next/standalone/src/stores/ai-panel-store.ts +58 -3
- package/.next/standalone/src/stores/editor-store.ts +115 -9
- package/.next/standalone/src/stores/proof-store.ts +123 -0
- package/.next/standalone/src/stores/view-width-store.ts +62 -0
- package/.next/standalone/src/tests/proof/activity-aggregator.test.ts +146 -0
- package/.next/standalone/src/tests/proof/agent-ownership.test.ts +140 -0
- package/.next/standalone/src/tests/proof/agents-install.test.ts +57 -0
- package/.next/standalone/src/tests/proof/better-auth.test.ts +68 -0
- package/.next/standalone/src/tests/proof/block-refs.test.ts +108 -0
- package/.next/standalone/src/tests/proof/blocks.test.ts +92 -0
- package/.next/standalone/src/tests/proof/comments-ops.test.ts +177 -0
- package/.next/standalone/src/tests/proof/editor-roundtrip.test.ts +85 -0
- package/.next/standalone/src/tests/proof/external-edit.test.ts +58 -0
- package/.next/standalone/src/tests/proof/file-lock.test.ts +80 -0
- package/.next/standalone/src/tests/proof/glob.test.ts +82 -0
- package/.next/standalone/src/tests/proof/helpers/auth-session.ts +27 -0
- package/.next/standalone/src/tests/proof/markdown-to-html.test.ts +46 -0
- package/.next/standalone/src/tests/proof/ops-applier.test.ts +368 -0
- package/.next/standalone/src/tests/proof/owner-init.test.ts +2 -0
- package/.next/standalone/src/tests/proof/parse-frontmatter.test.ts +60 -0
- package/.next/standalone/src/tests/proof/proof-span.test.ts +98 -0
- package/.next/standalone/src/tests/proof/rate-limit.test.ts +54 -0
- package/.next/standalone/src/tests/proof/registration-flow.test.ts +330 -0
- package/.next/standalone/src/tests/proof/registry.test.ts +169 -0
- package/.next/standalone/src/tests/proof/routes.test.ts +516 -0
- package/.next/standalone/src/tests/proof/sidecar-trim.test.ts +58 -0
- package/.next/standalone/src/tests/proof/suggestion-ops.test.ts +280 -0
- package/.next/standalone/src/tests/proof/wiki-content-put.test.ts +140 -0
- package/.next/standalone/src/tests/proof/wiki-routes-auth.test.ts +208 -0
- package/README.md +365 -99
- package/bin/wiki-viewer.js +431 -33
- package/package.json +19 -2
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: wiki-viewer
|
|
3
|
+
description: Read and edit markdown files in a running wiki-viewer instance over its HTTP collab API. Use when the user mentions wiki-viewer, asks you to edit local notes, or shares a localhost wiki-viewer URL. Handles agent registration, scoped capabilities, block-level edits with provenance marks, comments, and suggestions.
|
|
4
|
+
license: MIT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# wiki-viewer agent skill
|
|
8
|
+
|
|
9
|
+
You are working with **wiki-viewer**, a local-first markdown viewer that exposes a Proof-SDK-compatible HTTP API for agents. Files on disk are the source of truth. Every AI-authored edit is wrapped in an inline `<proof-span>` mark so the human can see, accept, or revert your contribution.
|
|
10
|
+
|
|
11
|
+
## Discovery
|
|
12
|
+
|
|
13
|
+
The server publishes everything you need at one URL:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
GET http://<host>:<port>/api/agents/install
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
This returns JSON with: bootstrap instructions, route table, op vocabulary, the current registration endpoint, and the human-facing approval workflow. Fetch this first and treat it as authoritative for the running instance you're talking to.
|
|
20
|
+
|
|
21
|
+
If the user pasted only the wiki-viewer URL, append `/api/agents/install` and fetch it before doing anything else.
|
|
22
|
+
|
|
23
|
+
## Authentication
|
|
24
|
+
|
|
25
|
+
wiki-viewer uses **TOFU (Trust On First Use)**:
|
|
26
|
+
|
|
27
|
+
1. You register anonymously. Server stores a pending request.
|
|
28
|
+
2. The human approves you in the wiki-viewer AI Panel.
|
|
29
|
+
3. You poll, receive a one-shot token, and use it from then on.
|
|
30
|
+
|
|
31
|
+
### Register
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
POST /api/agent/register
|
|
35
|
+
Content-Type: application/json
|
|
36
|
+
|
|
37
|
+
{
|
|
38
|
+
"id": "ai:<your-name>",
|
|
39
|
+
"displayName": "<readable name>",
|
|
40
|
+
"scope": {
|
|
41
|
+
"paths": ["**/*"],
|
|
42
|
+
"ops": ["read", "mutate"]
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
- `id` must match `^ai:[a-z][a-z0-9-]{0,30}$`. Pick something stable per agent identity (e.g. `ai:claude`, `ai:cursor`, `ai:my-script`).
|
|
48
|
+
- `displayName` 1-80 chars. What the human sees in the approval UI.
|
|
49
|
+
- `scope.paths` is a glob list. Use `**/*` for full repo access, or restrict to a subtree like `notes/**`.
|
|
50
|
+
- `scope.ops` ⊆ `["read", "mutate"]`.
|
|
51
|
+
|
|
52
|
+
Response:
|
|
53
|
+
|
|
54
|
+
```json
|
|
55
|
+
{
|
|
56
|
+
"registrationId": "reg_<32hex>",
|
|
57
|
+
"pollUrl": "/api/agent/register/<regId>",
|
|
58
|
+
"status": "pending"
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Tell the human**: "Open the wiki-viewer AI Panel and approve my registration."
|
|
63
|
+
|
|
64
|
+
### Poll
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
GET /api/agent/register/<registrationId>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
- `202 {status:"pending"}` — keep polling, every 2-5s.
|
|
71
|
+
- `200 {status:"approved", agentId, token}` — capture token immediately. Pickup is **one-shot**; you cannot fetch it again.
|
|
72
|
+
- `410 {status:"denied"}` or `{status:"consumed"}` — abort or restart registration.
|
|
73
|
+
- `404` — registration expired, re-register.
|
|
74
|
+
|
|
75
|
+
### Use the token
|
|
76
|
+
|
|
77
|
+
Every subsequent request:
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
Authorization: Bearer <token>
|
|
81
|
+
X-Agent-Id: ai:<your-name>
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The `X-Agent-Id` must match the id the token was issued for. Spoofing rejected with `401`.
|
|
85
|
+
|
|
86
|
+
## Reading
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
GET /api/agent/files/<url-encoded-path>.md
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Returns a Snapshot:
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"path": "notes/plan.md",
|
|
97
|
+
"revision": 7,
|
|
98
|
+
"fingerprint": "sha256:...",
|
|
99
|
+
"blocks": [
|
|
100
|
+
{ "ref": "b1a3f0", "type": "heading", "level": 1, "markdown": "# Plan" },
|
|
101
|
+
{ "ref": "b7f2c1", "type": "paragraph", "markdown": "Ship in June." }
|
|
102
|
+
],
|
|
103
|
+
"comments": [...],
|
|
104
|
+
"suggestions": [...],
|
|
105
|
+
"lastEventId": 12
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Block `ref` strings are stable across edits. Use them to target mutations. **Always read a fresh snapshot before mutating** so you have the current `revision`.
|
|
110
|
+
|
|
111
|
+
## Mutating
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
POST /api/agent/files/<path>.md
|
|
115
|
+
Authorization: Bearer <token>
|
|
116
|
+
X-Agent-Id: ai:<your-name>
|
|
117
|
+
Content-Type: application/json
|
|
118
|
+
Idempotency-Key: <uuid you generate per request>
|
|
119
|
+
|
|
120
|
+
{
|
|
121
|
+
"baseRevision": <revision from snapshot>,
|
|
122
|
+
"by": "ai:<your-name>",
|
|
123
|
+
"ops": [ <op>, ... ]
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Requirements:
|
|
128
|
+
|
|
129
|
+
- `Idempotency-Key` header mandatory. Same key + same body within 5 minutes returns the cached response. Same key + different body returns `409 IDEMPOTENCY_KEY_REUSED`.
|
|
130
|
+
- `by` must equal your `X-Agent-Id` or you get `403 FORBIDDEN`.
|
|
131
|
+
- If `baseRevision` is stale, response is `409 STALE_REVISION` with a fresh snapshot. Read the new revision, rebuild your op against current refs, retry.
|
|
132
|
+
|
|
133
|
+
### Op vocabulary
|
|
134
|
+
|
|
135
|
+
**Block ops** — content edits:
|
|
136
|
+
|
|
137
|
+
```json
|
|
138
|
+
{ "type": "block.replace", "ref": "b7f2c1", "markdown": "New content." }
|
|
139
|
+
{ "type": "block.insertAfter", "ref": "b7f2c1", "markdown": "..." }
|
|
140
|
+
{ "type": "block.insertBefore", "ref": "b7f2c1", "markdown": "..." }
|
|
141
|
+
{ "type": "block.delete", "ref": "b7f2c1" }
|
|
142
|
+
{ "type": "block.append", "markdown": "..." }
|
|
143
|
+
{ "type": "block.prepend", "markdown": "..." }
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Any text you insert is automatically wrapped in a `<proof-span>` mark by the server. Provide optional metadata to make your contribution legible:
|
|
147
|
+
|
|
148
|
+
```json
|
|
149
|
+
{
|
|
150
|
+
"type": "block.insertAfter",
|
|
151
|
+
"ref": "b7f2c1",
|
|
152
|
+
"markdown": "Three pillars: infra, tooling, launch.",
|
|
153
|
+
"basis": "described",
|
|
154
|
+
"basisDetail": "user asked for an opening paragraph",
|
|
155
|
+
"inResponseTo": "c4a1"
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
`basis` ∈ `"described" | "inferred" | "suggested"`. Defaults to `"inferred"`. Always set `basis` and a short `basisDetail` so the human reviewer knows where your edit came from.
|
|
160
|
+
|
|
161
|
+
**Comment ops** — threaded discussion attached to a block:
|
|
162
|
+
|
|
163
|
+
```json
|
|
164
|
+
{ "type": "comment.add", "ref": "b7f2c1", "text": "Why end of June?" }
|
|
165
|
+
{ "type": "comment.reply", "commentId": "c4a1", "text": "Because of API freeze." }
|
|
166
|
+
{ "type": "comment.resolve", "commentId": "c4a1" }
|
|
167
|
+
{ "type": "comment.reopen", "commentId": "c4a1" }
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**Suggestion ops** — proposed edits the human must accept:
|
|
171
|
+
|
|
172
|
+
```json
|
|
173
|
+
{
|
|
174
|
+
"type": "suggestion.add",
|
|
175
|
+
"ref": "b7f2c1",
|
|
176
|
+
"kind": "replace",
|
|
177
|
+
"markdown": "Ship the rewrite by July 15.",
|
|
178
|
+
"basis": "described",
|
|
179
|
+
"basisDetail": "user mentioned slippage in chat"
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Suggestion kinds: `"replace" | "insertAfter" | "insertBefore" | "delete"`.
|
|
184
|
+
|
|
185
|
+
Default for AI-initiated content edits: **prefer suggestions over direct block ops** unless the human explicitly asked you to write directly. Suggestions render as inline cards in the editor with Accept / Reject buttons. Block ops apply immediately and only show up as proof-span decorations.
|
|
186
|
+
|
|
187
|
+
## Polling events
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
GET /api/agent/events/<path>.md?after=<lastEventId>
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Returns events emitted since `lastEventId`: human comments, accepted suggestions, external file edits (the human opened the file in vim), and so on. Use this to react when the human responds to one of your comments or suggestions.
|
|
194
|
+
|
|
195
|
+
Acknowledge:
|
|
196
|
+
|
|
197
|
+
```
|
|
198
|
+
POST /api/agent/events/<path>.md
|
|
199
|
+
{ "upToId": <id>, "by": "ai:<your-name>" }
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Acks are advisory; events are never deleted.
|
|
203
|
+
|
|
204
|
+
## Error codes
|
|
205
|
+
|
|
206
|
+
| Status | Code | Meaning |
|
|
207
|
+
| ------ | ---------------------- | -------------------------------------------------- |
|
|
208
|
+
| 401 | UNAUTHORIZED | bad/missing token or X-Agent-Id |
|
|
209
|
+
| 403 | FORBIDDEN | scope mismatch, or `by` doesn't match `X-Agent-Id` |
|
|
210
|
+
| 404 | FILE_NOT_FOUND | path doesn't exist under server root |
|
|
211
|
+
| 409 | STALE_REVISION | `baseRevision` wrong, retry with included snapshot |
|
|
212
|
+
| 409 | BLOCK_NOT_FOUND | ref no longer exists, refetch snapshot |
|
|
213
|
+
| 409 | IDEMPOTENCY_KEY_REUSED | same key, different body |
|
|
214
|
+
| 422 | INVALID_MARKDOWN | op's markdown failed to parse |
|
|
215
|
+
| 429 | RATE_LIMITED | bucket exhausted, honor `Retry-After` header |
|
|
216
|
+
|
|
217
|
+
## Working style
|
|
218
|
+
|
|
219
|
+
- Read before write. Always GET a fresh snapshot to capture current `revision` and block `ref`s.
|
|
220
|
+
- One file per request. There is no batch-across-files endpoint.
|
|
221
|
+
- Atomic ops. Each POST applies all its ops or none. Order matters within a batch.
|
|
222
|
+
- Be transparent. Set `basis` + `basisDetail` on every content op.
|
|
223
|
+
- Prefer comments and suggestions over silent edits. The human is your collaborator, not your reviewer-of-last-resort.
|
|
224
|
+
- Poll events between turns when the human is reviewing your work; respond to their comments rather than re-litigating.
|
|
225
|
+
|
|
226
|
+
## Sample first interaction
|
|
227
|
+
|
|
228
|
+
```
|
|
229
|
+
1. GET /api/agents/install # discovery
|
|
230
|
+
2. POST /api/agent/register # register
|
|
231
|
+
3. tell human: "approve me in the AI Panel"
|
|
232
|
+
4. GET /api/agent/register/<regId> # poll until approved
|
|
233
|
+
5. GET /api/agent/files/<path>.md # read
|
|
234
|
+
6. POST /api/agent/files/<path>.md # suggest or mutate
|
|
235
|
+
7. GET /api/agent/events/<path>.md?after=<id> # listen for replies
|
|
236
|
+
```
|