Skip to content

Commit a066f40

Browse files
facundofariasclaude
andcommitted
Update README and CLAUDE.md for v0.2.0
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 08eb262 commit a066f40

2 files changed

Lines changed: 135 additions & 44 deletions

File tree

CLAUDE.md

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Part of [Rumbo Labs](https://github.com/draftmark-app) alongside the main Draftm
1515
- **HTTP:** Built-in `fetch` (Node 18+)
1616
- **Build:** `tsc``dist/`
1717
- **Package:** `draftmark` on npm, binary is `dm`
18+
- **Publish:** GitHub release triggers `npm publish` via Actions workflow
1819

1920
## Dev Workflow
2021

@@ -31,66 +32,77 @@ dm --help # Verify it works
3132
```
3233
src/
3334
cli.ts — Entry point, commander setup, all command definitions
34-
api.ts — Fetch wrapper (base URL, auth headers, JSON/text responses)
35-
config.ts — .draftmark.json read/write, slug/apiKey/magicToken resolution
36-
format.ts — ANSI color helpers, label formatting, comment formatting
35+
api.ts — Fetch wrapper (base URL, auth headers, structured error normalization)
36+
config.ts — Local (.draftmark.json) + global (~/.config/draftmark/config.json) config, resolution helpers
37+
format.ts — ANSI color helpers, label/table/comment formatting, quiet mode
3738
```
3839

3940
Four files. Keep it that way — no unnecessary abstractions.
4041

4142
## Architecture Decisions
4243

4344
- **Single entry point:** All commands defined in `cli.ts`. Don't split into separate command files unless there are 20+ commands.
44-
- **Config resolution:** CLI flag > env var > `.draftmark.json`. This order is intentional — flags for one-off overrides, env vars for CI, config file for project context.
45-
- **Output convention:** `stderr` for status messages (creating, fetching...), `stdout` for data (URLs, JSON, raw markdown). This makes piping work: `dm raw | head`.
46-
- **No dependencies beyond Commander:** Use built-in `fetch`, `fs`, `path`. Don't add axios, chalk, ora, or similar.
45+
- **Config resolution:** CLI flag → env var → `.draftmark.json` → global config (`~/.config/draftmark/config.json`). This order is intentional — flags for one-off overrides, env vars for CI, local config for project context, global for account-wide defaults.
46+
- **Output convention:** `stderr` for status messages (creating, fetching...), `stdout` for data (URLs, JSON, raw markdown). This makes piping work: `dm raw | head`. The `--quiet` flag suppresses all stderr.
47+
- **Structured errors:** All API errors are normalized to `{ error, code, details }` in `api.ts`. Commands use `fail()` helper for consistent exit codes.
48+
- **Exit codes:** 0 ok, 1 general error, 2 auth (401/403), 3 not found (404), 4 conflict (409).
49+
- **No dependencies beyond Commander:** Use built-in `fetch`, `fs`, `path`, `os`, `child_process`. Don't add axios, chalk, ora, or similar.
4750
- **ANSI colors:** Implemented manually in `format.ts` (6 colors + reset). No chalk dependency.
4851

4952
## API Reference
5053

5154
The Draftmark API spec lives in the main repo: `draftmark-app/draftmark/openapi.yaml`
5255

53-
Base URL: `https://draftmark.app/api/v1` (override with `DM_BASE_URL` env var).
56+
Base URL: `https://draftmark.app/api/v1` (override with `--base-url` flag or `DM_BASE_URL` env var).
5457

5558
### Auth model
5659

5760
| Token | Prefix | Use |
5861
|-------|--------|-----|
5962
| Doc API Key | `key_` | Read private docs, list comments |
6063
| Magic Token | _(none)_ | Owner operations (update, close, delete) |
61-
| Account API Key | `acct_` | Account-level operations |
64+
| Account API Key | `acct_` | Account-level operations (create private docs) |
6265

6366
### Key endpoints used by the CLI
6467

65-
- `POST /docs` — create doc
68+
- `POST /docs` — create doc (optional `Authorization` header for private docs)
6669
- `GET /docs/:slug` — get doc (with `?format=raw` for markdown)
67-
- `PATCH /docs/:slug` — update status (requires magic token)
70+
- `PATCH /docs/:slug` — update content/status (requires magic token)
6871
- `DELETE /docs/:slug` — delete (requires magic token)
6972
- `GET /docs/:slug/comments` — list comments
7073
- `POST /docs/:slug/comments` — add comment
74+
- `POST /docs/:slug/reactions` — add reaction
7175
- `POST /docs/:slug/reviews` — mark reviewed
7276

7377
## Commands
7478

7579
| Command | API Call | Auth |
7680
|---------|----------|------|
77-
| `dm create <file>` | POST /docs | None |
81+
| `dm create <file>` | POST /docs | api_key (required for --private) |
82+
| `dm update <file> [slug]` | PATCH /docs/:slug | magic_token |
7883
| `dm status [slug]` | GET /docs/:slug | api_key |
7984
| `dm comments [slug]` | GET /docs/:slug/comments | api_key |
8085
| `dm comment [slug] <body>` | POST /docs/:slug/comments | api_key |
86+
| `dm react [slug] <emoji>` | POST /docs/:slug/reactions | api_key |
8187
| `dm review [slug]` | POST /docs/:slug/reviews | api_key |
8288
| `dm raw [slug]` | GET /docs/:slug?format=raw | api_key |
8389
| `dm close [slug]` | PATCH /docs/:slug | magic_token |
8490
| `dm open [slug]` | PATCH /docs/:slug | magic_token |
8591
| `dm delete [slug]` | DELETE /docs/:slug | magic_token |
92+
| `dm browse [slug]` | _(local)_ | none |
93+
| `dm list` | _(local)_ | none |
94+
| `dm login` | _(local)_ | none |
95+
| `dm logout` | _(local)_ | none |
96+
| `dm whoami` | _(local)_ | none |
97+
| `dm config` | _(local)_ | none |
8698

8799
## Testing
88100

89101
No test framework yet. To manually test:
90102

91103
```bash
92104
# Create a test doc
93-
echo "# Test" | dm create /dev/stdin
105+
echo "# Test" | dm create -
94106

95107
# Check it
96108
dm status
@@ -103,9 +115,8 @@ dm delete --confirm
103115

104116
## Publishing
105117

118+
Create a GitHub release — the Actions workflow handles `npm publish`:
119+
106120
```bash
107-
npm version patch
108-
npm publish
121+
gh release create v0.x.0 --repo draftmark-app/cli --title "v0.x.0" --notes "..."
109122
```
110-
111-
`prepublishOnly` runs `tsc` automatically.

README.md

Lines changed: 108 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,31 @@ Requires Node.js 18+.
1616
# Publish a markdown file and get a share link
1717
dm create draft.md
1818

19+
# Pipe from stdin
20+
echo "# Hello world" | dm create -
21+
22+
# Create as an agent with metadata
23+
dm create draft.md --agent --meta '{"model":"claude-4"}'
24+
1925
# Check review status
2026
dm status
2127

22-
# Read comments
28+
# Read comments (with filtering)
2329
dm comments
30+
dm comments --since 2026-03-27 --format minimal
2431

2532
# Add a comment (as an agent)
2633
dm comment "LGTM, ship it" --author-type agent --author "claude"
2734

35+
# Add a reaction
36+
dm react 👍
37+
2838
# Mark as reviewed
2939
dm review --name "claude" --type agent
3040

41+
# Push an update
42+
dm update revised.md
43+
3144
# Fetch raw markdown (pipeable)
3245
dm raw | head -20
3346

@@ -37,83 +50,150 @@ dm close
3750

3851
## Commands
3952

53+
### Document lifecycle
54+
4055
| Command | Description |
4156
|---------|-------------|
42-
| `dm create <file>` | Publish a markdown file |
57+
| `dm create <file>` | Publish a markdown file (use `-` for stdin) |
58+
| `dm update <file> [slug]` | Update document content (use `-` for stdin) |
4359
| `dm status [slug]` | Show document status |
44-
| `dm comments [slug]` | List comments |
45-
| `dm comment [slug] <body>` | Add a comment |
46-
| `dm review [slug]` | Mark document as reviewed |
4760
| `dm raw [slug]` | Print raw markdown to stdout |
61+
| `dm browse [slug]` | Open document in the default browser |
4862
| `dm close [slug]` | Close document for review |
4963
| `dm open [slug]` | Re-open document for review |
5064
| `dm delete [slug]` | Delete document (requires `--confirm`) |
5165

66+
### Feedback
67+
68+
| Command | Description |
69+
|---------|-------------|
70+
| `dm comments [slug]` | List comments |
71+
| `dm comment [slug] <body>` | Add a comment |
72+
| `dm react [slug] <emoji>` | Add a reaction |
73+
| `dm review [slug]` | Mark document as reviewed |
74+
75+
### Config & auth
76+
77+
| Command | Description |
78+
|---------|-------------|
79+
| `dm login` | Save credentials globally (`~/.config/draftmark/config.json`) |
80+
| `dm logout` | Remove global credentials |
81+
| `dm whoami` | Show current authentication sources |
82+
| `dm config` | Show resolved configuration from all sources |
83+
| `dm list` | List all documents in `.draftmark.json` |
84+
5285
The `[slug]` argument is optional when a `.draftmark.json` file exists in the current directory (auto-created by `dm create`).
5386

87+
## Global options
88+
89+
| Option | Description |
90+
|--------|-------------|
91+
| `-q, --quiet` | Suppress all stderr output (stdout only — ideal for piping) |
92+
| `--base-url <url>` | Override API base URL (default: `https://draftmark.app/api/v1`) |
93+
5494
## Authentication
5595

56-
Three values control access. Each resolves in order: **CLI flag > env var > `.draftmark.json`**.
96+
Credentials resolve in order: **CLI flag env var `.draftmark.json` → global config (`dm login`)**.
5797

5898
| Value | Flag | Env var | Purpose |
5999
|-------|------|---------|---------|
60-
| API Key | `--api-key` | `DM_API_KEY` | Read private docs, list comments |
100+
| API Key | `--api-key` | `DM_API_KEY` | Read private docs, list comments, add feedback |
61101
| Magic Token | `--magic-token` | `DM_MAGIC_TOKEN` | Owner ops (update, close, delete) |
62-
| Base URL | | `DM_BASE_URL` | Override API endpoint (default: `https://draftmark.app/api/v1`) |
102+
| Base URL | `--base-url` | `DM_BASE_URL` | Override API endpoint |
63103

64-
## `.draftmark.json`
104+
### Global credentials
65105

66-
Created automatically by `dm create`. Stores credentials for the current project:
106+
```bash
107+
# Save your account API key globally
108+
dm login --api-key acct_abc123
67109

68-
```json
69-
[
70-
{
71-
"slug": "a1b2c3d4",
72-
"api_key": "key_...",
73-
"magic_token": "...",
74-
"url": "https://draftmark.app/share/a1b2c3d4"
75-
}
76-
]
77-
```
110+
# Works from any directory now
111+
dm status abc123
78112

79-
Add `.draftmark.json` to your `.gitignore` — it contains secrets.
113+
# Check what's configured
114+
dm whoami
115+
dm config
116+
```
80117

81118
## `dm create` options
82119

83120
```
84-
--private Create as private (magic link only)
121+
--private Create as private (magic link only, requires --api-key)
85122
--title <title> Document title
86123
--expected-reviews <n> Number of reviews before review_complete flag
87124
--review-deadline <date> ISO date after which feedback is rejected
125+
--api-key <key> Account API key (required for --private)
126+
--agent Mark as agent-authored (inherited by comment/review)
127+
--meta <json> Arbitrary JSON metadata
88128
--json Output raw JSON response
89129
```
90130

91-
## JSON output
131+
## Output formats
92132

93-
All read commands accept `--json` to output the raw API response:
133+
Commands that display data support `--json` and `--format`:
94134

95135
```bash
136+
# JSON for programmatic consumption
96137
dm status --json | jq '.accepting_feedback'
97138
dm comments --json | jq '.[].body'
139+
140+
# Minimal for scripting
141+
dm status --format minimal # abc123 open public 3c 2r
142+
dm comments --format minimal # one line per comment
143+
144+
# Table (default) for humans
145+
dm status
146+
dm comments
98147
```
99148

149+
## `.draftmark.json`
150+
151+
Created automatically by `dm create`. Stores credentials for the current project:
152+
153+
```json
154+
[
155+
{
156+
"slug": "a1b2c3d4",
157+
"api_key": "key_...",
158+
"magic_token": "...",
159+
"url": "https://draftmark.app/share/a1b2c3d4",
160+
"author_type": "agent"
161+
}
162+
]
163+
```
164+
165+
Add `.draftmark.json` to your `.gitignore` — it contains secrets.
166+
167+
The `--agent` flag on `create` stores `author_type: "agent"` here. Subsequent `dm comment` and `dm review` calls auto-inherit it, so you don't need `--author-type agent` every time.
168+
169+
## Exit codes
170+
171+
| Code | Meaning |
172+
|------|---------|
173+
| `0` | Success |
174+
| `1` | General error (bad input, network failure, server error) |
175+
| `2` | Authentication error (401/403) |
176+
| `3` | Not found (404) |
177+
| `4` | Conflict (409 — review closed/expired) |
178+
100179
## Agent workflow
101180

102181
Typical agent loop using the CLI:
103182

104183
```bash
105184
# 1. Agent writes markdown and publishes
106-
dm create analysis.md --expected-reviews 2
185+
dm create analysis.md --agent --expected-reviews 2
107186

108187
# 2. Share the URL with reviewers (printed by create)
109188

110189
# 3. Poll for feedback
111-
dm status # Check if reviews are in
112-
dm comments # Read inline comments
190+
dm status --format minimal
191+
dm comments --since 2026-03-25 --json > feedback.json
113192

114193
# 4. Consume raw content + feedback, iterate
115194
dm raw > current.md
116-
dm comments --json > feedback.json
195+
# ... agent processes feedback and rewrites ...
196+
dm update revised.md --version-note "Addressed review comments"
117197

118198
# 5. Close when done
119199
dm close

0 commit comments

Comments
 (0)