slimwiki 0.1.0 → 0.1.1
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 +3 -199
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,30 +4,14 @@ Agent-friendly CLI for [SlimWiki](https://slimwiki.com). Lets a human or an
|
|
|
4
4
|
AI agent sign in to a SlimWiki account, browse pages, and create new
|
|
5
5
|
ones from Tiptap JSON.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
- **End users + their AI agents** — install the CLI, authenticate it
|
|
10
|
-
once, then either run commands by hand or let an agent drive it. Jump
|
|
11
|
-
to [Install & use](#install--use).
|
|
12
|
-
- **Contributors** — clone the monorepo, run a local stack, edit CLI
|
|
13
|
-
source. Jump to [Development](#development).
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
## Install & use
|
|
18
|
-
|
|
19
|
-
### 1. Install the CLI
|
|
20
|
-
|
|
21
|
-
Once published:
|
|
7
|
+
## Install
|
|
22
8
|
|
|
23
9
|
```sh
|
|
24
10
|
npm i -g slimwiki # or pnpm add -g, bun i -g
|
|
25
11
|
slimwiki --version
|
|
26
12
|
```
|
|
27
13
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
### 2. Authenticate
|
|
14
|
+
## Authenticate
|
|
31
15
|
|
|
32
16
|
```sh
|
|
33
17
|
slimwiki auth login
|
|
@@ -57,7 +41,7 @@ slimwiki auth status
|
|
|
57
41
|
|
|
58
42
|
`slimwiki auth logout` revokes the session and wipes the local file.
|
|
59
43
|
|
|
60
|
-
|
|
44
|
+
## Wire up an AI agent
|
|
61
45
|
|
|
62
46
|
The CLI ships two artefacts so agents can learn its contract without
|
|
63
47
|
you re-explaining each session:
|
|
@@ -252,183 +236,3 @@ slimwiki page list --archived --limit 100
|
|
|
252
236
|
- `0` — success.
|
|
253
237
|
- `1` — any error (auth, validation, network, API). Stderr carries
|
|
254
238
|
`{"error":"..."}` so agents can branch on it.
|
|
255
|
-
|
|
256
|
-
---
|
|
257
|
-
|
|
258
|
-
## Development
|
|
259
|
-
|
|
260
|
-
The CLI is a workspace package inside the SlimWiki monorepo at
|
|
261
|
-
`/cli/`, alongside `/api/` and `/frontend/`.
|
|
262
|
-
|
|
263
|
-
### Repo layout
|
|
264
|
-
|
|
265
|
-
```
|
|
266
|
-
cli/
|
|
267
|
-
├── package.json # bin: slimwiki, deps: commander, env-paths, open, zod
|
|
268
|
-
├── tsconfig.json # strict TS, NodeNext, ESM
|
|
269
|
-
├── tsup.config.ts # bundles src/index.ts → dist/index.js (single file)
|
|
270
|
-
├── AGENT.md # contract for AI agents
|
|
271
|
-
├── SKILL.md # Claude Code skill stub
|
|
272
|
-
├── README.md # this file
|
|
273
|
-
└── src/
|
|
274
|
-
├── index.ts # commander root, registers subcommands
|
|
275
|
-
├── commands/
|
|
276
|
-
│ ├── auth.ts # login (browser device flow), logout, status
|
|
277
|
-
│ ├── account.ts # account list
|
|
278
|
-
│ ├── wiki.ts # wiki list
|
|
279
|
-
│ ├── page.ts # page list, get, create
|
|
280
|
-
│ └── agent-help.ts # prints AGENT.md
|
|
281
|
-
├── lib/
|
|
282
|
-
│ ├── api-client.ts # fetch wrapper: bearer auth, JSON parsing, error mapping
|
|
283
|
-
│ ├── config.ts # ~/.config/slimwiki/credentials.json + SLIMWIKI_TOKEN
|
|
284
|
-
│ ├── output.ts # JSON-default vs --human, stderr error path
|
|
285
|
-
│ ├── selectors.ts # resolve --account/--wiki/--parent flags into IDs
|
|
286
|
-
│ └── tiptap-schema.ts # Zod schema for the page-create body
|
|
287
|
-
└── types.ts # public response shapes (no UUIDs)
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
The CLI talks to the SlimWiki API over HTTPS only. It does **not**
|
|
291
|
-
import anything from `api/` — bringing Drizzle, Better Auth server,
|
|
292
|
-
etc. into a CLI binary would balloon its size and tie its release
|
|
293
|
-
cadence to the API's.
|
|
294
|
-
|
|
295
|
-
### Local install for users
|
|
296
|
-
|
|
297
|
-
End users who want to try the CLI without waiting for an npm release:
|
|
298
|
-
|
|
299
|
-
```sh
|
|
300
|
-
git clone git@github.com:slimwiki/slimwiki.git
|
|
301
|
-
cd slimwiki
|
|
302
|
-
pnpm install
|
|
303
|
-
pnpm --filter slimwiki build
|
|
304
|
-
|
|
305
|
-
# Put `slimwiki` on PATH. Either:
|
|
306
|
-
cd cli && npm link # uses your existing Node bin dir
|
|
307
|
-
# or:
|
|
308
|
-
pnpm setup && pnpm link --global # one-time pnpm bin setup
|
|
309
|
-
|
|
310
|
-
slimwiki --version
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
Note that `pnpm link --global` requires `pnpm setup` to have been run
|
|
314
|
-
once on the machine (it adds `PNPM_HOME` to your shell rc).
|
|
315
|
-
|
|
316
|
-
### Local dev loop
|
|
317
|
-
|
|
318
|
-
With the API and frontend running locally:
|
|
319
|
-
|
|
320
|
-
```sh
|
|
321
|
-
# Terminal 1 — API
|
|
322
|
-
cd api && pnpm dev # listens on :3001
|
|
323
|
-
|
|
324
|
-
# Terminal 2 — Frontend
|
|
325
|
-
cd frontend && pnpm dev # listens on :3000
|
|
326
|
-
|
|
327
|
-
# Terminal 3 — CLI
|
|
328
|
-
cd cli
|
|
329
|
-
pnpm dev # tsup --watch, rebuilds dist/ on save
|
|
330
|
-
|
|
331
|
-
# In another terminal, run commands against the local stack:
|
|
332
|
-
node dist/index.js auth login --api-base http://localhost:3001
|
|
333
|
-
node dist/index.js account list --api-base http://localhost:3001
|
|
334
|
-
```
|
|
335
|
-
|
|
336
|
-
`--api-base` is a global flag, so any command can be redirected at
|
|
337
|
-
localhost without re-running `auth login`. The flag is more convenient
|
|
338
|
-
during development than baking the value into credentials.
|
|
339
|
-
|
|
340
|
-
`pnpm dev` runs tsup in watch mode — every save rebuilds
|
|
341
|
-
`dist/index.js`. If you've run `npm link` once, your global `slimwiki`
|
|
342
|
-
points at the same `dist/`, so subsequent invocations pick up changes
|
|
343
|
-
automatically.
|
|
344
|
-
|
|
345
|
-
### Typecheck / build / clean
|
|
346
|
-
|
|
347
|
-
```sh
|
|
348
|
-
pnpm --filter slimwiki typecheck # tsc --noEmit
|
|
349
|
-
pnpm --filter slimwiki build # tsup → dist/index.js
|
|
350
|
-
```
|
|
351
|
-
|
|
352
|
-
The bundle is a single ESM file with a `#!/usr/bin/env node` shebang.
|
|
353
|
-
There's no separate type-declaration output — the CLI isn't intended to
|
|
354
|
-
be imported as a library.
|
|
355
|
-
|
|
356
|
-
### How auth works under the hood
|
|
357
|
-
|
|
358
|
-
`slimwiki auth login` runs a **device-code OAuth flow** modelled on
|
|
359
|
-
`gh auth login` and `vercel login`:
|
|
360
|
-
|
|
361
|
-
1. CLI POSTs `/api/v1/auth/cli/init`. API generates a 32-byte
|
|
362
|
-
`deviceCode` and an 8-character `userCode` (e.g. `WXYZ-1234`),
|
|
363
|
-
inserts them into `cli_auth_codes` with a 10-minute TTL.
|
|
364
|
-
2. CLI prints the `userCode` to stderr and `open()`s the browser at
|
|
365
|
-
`${client.url}/cli-auth?code=<userCode>`.
|
|
366
|
-
3. Frontend's `/cli-auth` page (`frontend/src/app/[locale]/cli-auth/`)
|
|
367
|
-
gates on session, displays the code, and POSTs `/api/v1/auth/cli/approve`
|
|
368
|
-
when the user clicks Allow.
|
|
369
|
-
4. API mints a fresh `ba_session` row tied to the user, attaches its
|
|
370
|
-
`id` to the device-code row.
|
|
371
|
-
5. CLI polls `/api/v1/auth/cli/poll` every ~2s. While unapproved →
|
|
372
|
-
`{ status: "pending" }`. Once approved → `{ status: "approved",
|
|
373
|
-
token, expiresAt, user, account, wiki }`. CLI persists everything
|
|
374
|
-
to `credentials.json`.
|
|
375
|
-
|
|
376
|
-
The session token is a regular Better Auth `ba_session.token` — the
|
|
377
|
-
CLI sends it as `Authorization: Bearer <token>`, and the API's
|
|
378
|
-
existing `bearer()` plugin handles every subsequent request without
|
|
379
|
-
CLI-specific code paths.
|
|
380
|
-
|
|
381
|
-
Server endpoints live in `api/src/routes/v1/auth.ts` and
|
|
382
|
-
`api/src/services/CliAuthService.ts`; the table schema is in
|
|
383
|
-
`api/src/db/schema/cliAuthCodes.ts` (migration 0011).
|
|
384
|
-
|
|
385
|
-
### Adding a new command
|
|
386
|
-
|
|
387
|
-
1. Create `src/commands/<name>.ts`. Export a single
|
|
388
|
-
`register<Name>Commands(program: Command)` function that attaches
|
|
389
|
-
subcommands to the passed-in commander program.
|
|
390
|
-
2. Reuse `requireAuth({ apiBaseOverride: apiBaseOverride(cmd) })` for
|
|
391
|
-
anything that needs the bearer token.
|
|
392
|
-
3. Use `writeResult(cmd, value, humanFormatter?)` for the success path
|
|
393
|
-
and `exitWithError(err)` for the failure path. Don't `console.log`
|
|
394
|
-
directly — those helpers handle JSON-vs-human output and exit codes.
|
|
395
|
-
4. Strip API responses to a narrow public shape before emitting them.
|
|
396
|
-
Defining a new type in `src/types.ts` keeps that contract obvious.
|
|
397
|
-
5. Register the new file in `src/index.ts`.
|
|
398
|
-
6. Document the command in this README + `AGENT.md`. The two should
|
|
399
|
-
stay in sync — `AGENT.md` is what agents read first.
|
|
400
|
-
|
|
401
|
-
### Adding a Tiptap node type
|
|
402
|
-
|
|
403
|
-
The Zod schema in `src/lib/tiptap-schema.ts` is the contract documented
|
|
404
|
-
in `AGENT.md`. To add a new node:
|
|
405
|
-
|
|
406
|
-
1. Add a discriminated-union branch to the `Node` schema. Use
|
|
407
|
-
`.passthrough()` so unknown attrs survive the round-trip.
|
|
408
|
-
2. Update the table in `AGENT.md` (and this README) — node name and
|
|
409
|
-
required attrs.
|
|
410
|
-
3. Verify the same node name and attrs are registered on the frontend
|
|
411
|
-
in `frontend/src/extensions/index.ts` and in the API's hocuspocus
|
|
412
|
-
shadow extensions in
|
|
413
|
-
`api/src/lib/collaboration/extensions/extensions.ts`. All three
|
|
414
|
-
must agree, or pages saved through the CLI won't render in the
|
|
415
|
-
editor.
|
|
416
|
-
|
|
417
|
-
A real-world example of why this matters: the `math` node is named
|
|
418
|
-
`math` (not `mathematics`) with attr `latex` (not `formula`). Getting
|
|
419
|
-
that wrong meant the frontend rejected docs the CLI happily accepted.
|
|
420
|
-
|
|
421
|
-
### Releasing
|
|
422
|
-
|
|
423
|
-
(Pre-launch — workflow TBD when the package goes public on npm.)
|
|
424
|
-
|
|
425
|
-
Rough plan:
|
|
426
|
-
|
|
427
|
-
1. Bump `cli/package.json` version.
|
|
428
|
-
2. `pnpm --filter slimwiki build`.
|
|
429
|
-
3. `cd cli && npm publish --access public`.
|
|
430
|
-
4. Tag the repo: `git tag cli-vX.Y.Z && git push --tags`.
|
|
431
|
-
|
|
432
|
-
`AGENT.md` and `SKILL.md` are listed in `package.json#files` so they
|
|
433
|
-
ship with the npm package; `slimwiki agent-help` reads `AGENT.md` from
|
|
434
|
-
the package's installed location at runtime.
|
package/package.json
CHANGED