contentbase 0.0.2 → 0.0.4
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/.mcp.json +9 -0
- package/CLI.md +593 -0
- package/MCP-DESCRIPTIONS-REVIEW.md +122 -0
- package/MCP-SERVER-SPEC.md +453 -0
- package/PRIMER.md +540 -0
- package/README.md +289 -13
- package/bun.lock +43 -4
- package/dist/cnotes +0 -0
- package/docs/README.md +110 -0
- package/docs/TABLE-OF-CONTENTS.md +7 -0
- package/docs/models.ts +38 -0
- package/models.ts +38 -0
- package/package.json +12 -3
- package/public/web-demo/index.html +813 -0
- package/showcases/node_modules/.cache/.repl_history +3 -0
- package/showcases/vinyl-collection/artists/nina-simone.mdx +1 -1
- package/src/__tests__/semantic-search.integration.test.ts +284 -0
- package/src/api/endpoints/actions.ts +34 -0
- package/src/api/endpoints/doc.ts +187 -0
- package/src/api/endpoints/docs-index.ts +26 -0
- package/src/api/endpoints/document.ts +171 -0
- package/src/api/endpoints/documents.ts +71 -0
- package/src/api/endpoints/inspect.ts +16 -0
- package/src/api/endpoints/models.ts +10 -0
- package/src/api/endpoints/query.ts +88 -0
- package/src/api/endpoints/root.ts +7 -0
- package/src/api/endpoints/search-reindex.ts +65 -0
- package/src/api/endpoints/search-status.ts +55 -0
- package/src/api/endpoints/search.ts +104 -0
- package/src/api/endpoints/semantic-search.ts +120 -0
- package/src/api/endpoints/text-search.ts +63 -0
- package/src/api/endpoints/validate.ts +34 -0
- package/src/api/helpers.ts +97 -0
- package/src/base-model.ts +12 -0
- package/src/cli/commands/action.ts +82 -44
- package/src/cli/commands/console.ts +124 -0
- package/src/cli/commands/create.ts +179 -53
- package/src/cli/commands/embed.ts +323 -0
- package/src/cli/commands/export.ts +58 -24
- package/src/cli/commands/extract.ts +174 -0
- package/src/cli/commands/help.ts +81 -0
- package/src/cli/commands/index.ts +17 -0
- package/src/cli/commands/init.ts +72 -48
- package/src/cli/commands/inspect.ts +56 -46
- package/src/cli/commands/mcp.ts +1219 -0
- package/src/cli/commands/search.ts +285 -0
- package/src/cli/commands/serve.ts +348 -0
- package/src/cli/commands/summary.ts +60 -0
- package/src/cli/commands/teach.ts +86 -0
- package/src/cli/commands/text-search.ts +134 -0
- package/src/cli/commands/validate.ts +126 -64
- package/src/cli/index.ts +88 -19
- package/src/cli/load-collection.ts +144 -17
- package/src/cli/registry.ts +28 -0
- package/src/collection.ts +361 -10
- package/src/define-model.ts +101 -4
- package/src/document.ts +47 -1
- package/src/extract-sections.ts +1 -1
- package/src/index.ts +14 -2
- package/src/model-instance.ts +35 -5
- package/src/node-shortcuts.ts +1 -1
- package/src/query/collection-query.ts +96 -9
- package/src/query/index.ts +7 -0
- package/src/query/query-dsl.ts +259 -0
- package/src/relationships/has-many.ts +39 -0
- package/src/relationships/index.ts +7 -2
- package/src/section.ts +2 -0
- package/src/types.ts +23 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/match-pattern.ts +65 -0
- package/src/validator.ts +18 -1
- package/test/collection.test.ts +118 -2
- package/test/fixtures/sdlc/MODELS.md +106 -0
- package/test/fixtures/sdlc/SKILL.md +404 -0
- package/test/fixtures/sdlc/index.ts +9 -0
- package/test/fixtures/sdlc/models.ts +8 -6
- package/test/fixtures/sdlc/stories/authentication/a-user-should-be-able-to-login.mdx +20 -0
- package/test/fixtures/sdlc/templates/epic.md +23 -0
- package/test/fixtures/sdlc/templates/story.md +19 -0
- package/test/pattern.test.ts +191 -0
- package/test/query-dsl.test.ts +431 -0
- package/test/query.test.ts +29 -0
- package/test/relationships.test.ts +130 -0
- package/test/section.test.ts +61 -0
- package/test/table-of-contents.test.ts +49 -5
package/.mcp.json
ADDED
package/CLI.md
ADDED
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
# Contentbase CLI Reference
|
|
2
|
+
|
|
3
|
+
The `cnotes` CLI provides commands for managing, querying, serving, and documenting your contentbase collections from the terminal.
|
|
4
|
+
|
|
5
|
+
All commands run via the `luca` container runtime, which means you get full access to features like networking, process management, file system utilities, and more — without installing extra dependencies.
|
|
6
|
+
|
|
7
|
+
## Global Options
|
|
8
|
+
|
|
9
|
+
All commands (except `init`) support:
|
|
10
|
+
|
|
11
|
+
- `--contentFolder <path>` — Override the content folder path (relative to cwd)
|
|
12
|
+
- `--modulePath <path>` — Explicit path to an `index.ts` or `models.ts` module
|
|
13
|
+
|
|
14
|
+
### Content Folder Resolution
|
|
15
|
+
|
|
16
|
+
When no `--contentFolder` is specified, the CLI resolves the root path in this order:
|
|
17
|
+
|
|
18
|
+
1. `contentbase.contentFolder` from your `package.json`
|
|
19
|
+
2. Falls back to `./docs`
|
|
20
|
+
|
|
21
|
+
### Collection Loading Tiers
|
|
22
|
+
|
|
23
|
+
The CLI automatically discovers your project setup:
|
|
24
|
+
|
|
25
|
+
1. **index.ts** — Imports your Collection instance directly (full control)
|
|
26
|
+
2. **models.ts** — Auto-registers all exported model definitions
|
|
27
|
+
3. **Auto-discovery** — Scans subdirectories containing markdown files and generates basic models
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Commands at a Glance
|
|
32
|
+
|
|
33
|
+
| Command | Purpose |
|
|
34
|
+
|---------|---------|
|
|
35
|
+
| `cnotes init` | Scaffold a new contentbase project |
|
|
36
|
+
| `cnotes create` | Create a new document from a model template |
|
|
37
|
+
| `cnotes inspect` | Display collection metadata and model info |
|
|
38
|
+
| `cnotes validate` | Validate documents against model schemas |
|
|
39
|
+
| `cnotes export` | Export the entire collection as JSON |
|
|
40
|
+
| `cnotes extract` | Pull specific sections from documents into a combined output |
|
|
41
|
+
| `cnotes summary` | Generate MODELS.md and TABLE-OF-CONTENTS.md |
|
|
42
|
+
| `cnotes teach` | Output combined docs for LLM context |
|
|
43
|
+
| `cnotes action` | Run a named collection action |
|
|
44
|
+
| `cnotes serve` | Start an HTTP server with REST API and doc serving |
|
|
45
|
+
| `cnotes mcp` | Start an MCP server for AI agent integration |
|
|
46
|
+
| `cnotes console` | Interactive REPL with collection in scope |
|
|
47
|
+
| `cnotes help` | List available commands |
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Project Scaffolding
|
|
52
|
+
|
|
53
|
+
### `cnotes init [name]`
|
|
54
|
+
|
|
55
|
+
Scaffold a new contentbase project with sample models and documents.
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
cnotes init
|
|
59
|
+
cnotes init blog-content
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Creates:
|
|
63
|
+
- `models.ts` — sample Post model definition
|
|
64
|
+
- `index.ts` — collection setup that registers the model
|
|
65
|
+
- `posts/hello-world.mdx` — sample document
|
|
66
|
+
|
|
67
|
+
This gives you a Tier 1 project (the recommended setup) right away.
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Content Management
|
|
72
|
+
|
|
73
|
+
### `cnotes create <model> --title "<title>"`
|
|
74
|
+
|
|
75
|
+
Create a new document scaffolded from a model definition.
|
|
76
|
+
|
|
77
|
+
**Options:**
|
|
78
|
+
- `--title` (required) — Document title (becomes the H1 heading)
|
|
79
|
+
- `--meta.<field> <value>` — Override specific frontmatter fields
|
|
80
|
+
|
|
81
|
+
**Template support:** If `templates/<model>.md` exists in your content folder, it's used as the base document. The title heading is replaced and meta is merged.
|
|
82
|
+
|
|
83
|
+
**Meta merge priority:** Zod defaults < model defaults < template frontmatter < CLI flags
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# Create a story with defaults
|
|
87
|
+
cnotes create story --title "User Login Flow"
|
|
88
|
+
|
|
89
|
+
# Create an epic with meta overrides
|
|
90
|
+
cnotes create epic --title "Authentication" --meta.status active --meta.priority high
|
|
91
|
+
|
|
92
|
+
# Use a different content folder
|
|
93
|
+
cnotes create story --title "Search Results" --contentFolder ./sdlc
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The file is written to `{prefix}/{kebab-title}.mdx`. So `cnotes create story --title "User Login Flow"` creates `stories/user-login-flow.mdx`.
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## Querying and Inspection
|
|
101
|
+
|
|
102
|
+
### `cnotes inspect`
|
|
103
|
+
|
|
104
|
+
Display a summary of the collection: registered models, their schemas, sections, relationships, and document counts.
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
cnotes inspect
|
|
108
|
+
cnotes inspect --contentFolder ./sdlc
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**Example output:**
|
|
112
|
+
```
|
|
113
|
+
Collection: sdlc
|
|
114
|
+
Root: /path/to/sdlc
|
|
115
|
+
Items: 15
|
|
116
|
+
|
|
117
|
+
Model: Epic
|
|
118
|
+
Prefix: epics
|
|
119
|
+
Sections: acceptanceCriteria, stories
|
|
120
|
+
Relationships: stories
|
|
121
|
+
Documents: 3
|
|
122
|
+
|
|
123
|
+
Model: Story
|
|
124
|
+
Prefix: stories
|
|
125
|
+
Sections: acceptanceCriteria, tasks
|
|
126
|
+
Relationships: epic
|
|
127
|
+
Documents: 12
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### `cnotes export`
|
|
131
|
+
|
|
132
|
+
Export the entire collection as JSON to stdout.
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
cnotes export
|
|
136
|
+
cnotes export > collection.json
|
|
137
|
+
cnotes export | jq '.models'
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### `cnotes extract <glob> --sections "A, B"`
|
|
141
|
+
|
|
142
|
+
Extract specific sections from matching documents and combine them into a single output. Useful for pulling all acceptance criteria, all requirements, or other structured sections across your collection.
|
|
143
|
+
|
|
144
|
+
**Arguments:**
|
|
145
|
+
- `<glob>` (required) — Picomatch pattern matched against document path IDs
|
|
146
|
+
|
|
147
|
+
**Options:**
|
|
148
|
+
- `-s, --sections` — Comma-separated section headings to extract
|
|
149
|
+
- `-t, --title` — Title for the combined output document
|
|
150
|
+
- `--frontmatter` — Include frontmatter in the output
|
|
151
|
+
- `--no-normalize-headings` — Preserve original heading depths
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# Extract acceptance criteria from all stories
|
|
155
|
+
cnotes extract "stories/**/*" --sections "Acceptance Criteria"
|
|
156
|
+
|
|
157
|
+
# Combine epics with a title
|
|
158
|
+
cnotes extract "epics/*" -s "Stories" --title "All Stories"
|
|
159
|
+
|
|
160
|
+
# Multiple sections, include frontmatter
|
|
161
|
+
cnotes extract "epics/*" -s "Stories, Notes" --frontmatter --no-normalize-headings
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Sections that don't exist in a document are silently skipped. By default, heading depths are normalized so the combined output nests properly.
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Validation
|
|
169
|
+
|
|
170
|
+
### `cnotes validate [target]`
|
|
171
|
+
|
|
172
|
+
Validate documents against their model Zod schemas. Checks frontmatter fields and section schemas.
|
|
173
|
+
|
|
174
|
+
**Arguments:**
|
|
175
|
+
- `target` (optional) — What to validate:
|
|
176
|
+
- `all` (default) — Every document in the collection
|
|
177
|
+
- A path ID (e.g. `stories/user-login`) — A single document
|
|
178
|
+
- A model name (e.g. `Story`) — All documents of that type
|
|
179
|
+
|
|
180
|
+
**Options:**
|
|
181
|
+
- `--setDefaultMeta` — Write missing default frontmatter values to documents that are missing them
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
cnotes validate
|
|
185
|
+
cnotes validate stories/user-login-flow
|
|
186
|
+
cnotes validate Story
|
|
187
|
+
cnotes validate all --setDefaultMeta
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Exits with code 1 if any documents are invalid.
|
|
191
|
+
|
|
192
|
+
**Example output:**
|
|
193
|
+
```
|
|
194
|
+
INVALID: stories/user-login-flow
|
|
195
|
+
meta.status: Invalid enum value. Expected 'draft' | 'active' | 'completed', received 'unknown'
|
|
196
|
+
|
|
197
|
+
Validated 12 documents: 11 valid, 1 invalid
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## Documentation Generation
|
|
203
|
+
|
|
204
|
+
### `cnotes summary`
|
|
205
|
+
|
|
206
|
+
Generate documentation files in your content directory:
|
|
207
|
+
|
|
208
|
+
- **MODELS.md** — Documents each model's schema fields, sections, relationships, and defaults
|
|
209
|
+
- **TABLE-OF-CONTENTS.md** — A linked listing of all documents grouped by model
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
cnotes summary
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### `cnotes teach`
|
|
216
|
+
|
|
217
|
+
Output a combined document for LLM context. Concatenates MODELS.md, TABLE-OF-CONTENTS.md, CLI.md, and PRIMER.md into a single output designed to teach an AI about your content structure.
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
cnotes teach
|
|
221
|
+
cnotes teach | pbcopy # copy to clipboard (macOS)
|
|
222
|
+
cnotes teach > CONTEXT.md # save to file
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## Collection Actions
|
|
228
|
+
|
|
229
|
+
### `cnotes action <name>`
|
|
230
|
+
|
|
231
|
+
Run a named action registered on the collection.
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
cnotes action rebuild-index
|
|
235
|
+
cnotes action generate-report
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Actions are defined in your collection setup:
|
|
239
|
+
|
|
240
|
+
```ts
|
|
241
|
+
collection.action("rebuild-index", async (coll) => {
|
|
242
|
+
// custom logic
|
|
243
|
+
});
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## Search
|
|
249
|
+
|
|
250
|
+
### `cnotes text-search <pattern>`
|
|
251
|
+
|
|
252
|
+
Search file contents within the content folder using pattern matching. Powered by ripgrep (with grep fallback).
|
|
253
|
+
|
|
254
|
+
**Arguments:**
|
|
255
|
+
- `pattern` (required) — Text or regex pattern to search for
|
|
256
|
+
|
|
257
|
+
**Options:**
|
|
258
|
+
|
|
259
|
+
| Option | Default | Description |
|
|
260
|
+
|--------|---------|-------------|
|
|
261
|
+
| `--expanded` | `false` | Show line-level matches (default: distinct files only) |
|
|
262
|
+
| `--include` | | Glob filter (e.g. `"*.md"`) |
|
|
263
|
+
| `--exclude` | | Glob filter (e.g. `"node_modules"`) |
|
|
264
|
+
| `--ignoreCase` | `false` | Case insensitive search |
|
|
265
|
+
| `--maxResults` | | Limit number of results |
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
# Find files containing "TODO"
|
|
269
|
+
cnotes text-search "TODO"
|
|
270
|
+
|
|
271
|
+
# Show line-level detail
|
|
272
|
+
cnotes text-search "TODO" --expanded
|
|
273
|
+
|
|
274
|
+
# Filter to markdown, case insensitive
|
|
275
|
+
cnotes text-search "deploy" --include "*.md" --ignoreCase
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
**Example output (default):**
|
|
279
|
+
```
|
|
280
|
+
3 file(s) match:
|
|
281
|
+
|
|
282
|
+
goals/launch-website.md
|
|
283
|
+
plans/demo-setup.mdx
|
|
284
|
+
ideas/main-process-manager.md
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
**Example output (--expanded):**
|
|
288
|
+
```
|
|
289
|
+
3 file(s), 5 match(es):
|
|
290
|
+
|
|
291
|
+
goals/launch-website.md
|
|
292
|
+
12: TODO: finalize deployment target
|
|
293
|
+
45: TODO: add SSL certificate
|
|
294
|
+
|
|
295
|
+
plans/demo-setup.mdx
|
|
296
|
+
8: TODO: verify staging environment
|
|
297
|
+
|
|
298
|
+
ideas/main-process-manager.md
|
|
299
|
+
3: TODO: research process supervision patterns
|
|
300
|
+
22: TODO: define restart policy
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
## Servers
|
|
306
|
+
|
|
307
|
+
### `cnotes serve`
|
|
308
|
+
|
|
309
|
+
Start an HTTP server that exposes the collection via a REST API with content-negotiated document serving.
|
|
310
|
+
|
|
311
|
+
**Options:**
|
|
312
|
+
|
|
313
|
+
| Option | Default | Description |
|
|
314
|
+
|--------|---------|-------------|
|
|
315
|
+
| `--port` | `8000` | Port to listen on |
|
|
316
|
+
| `--contentFolder` | `./docs` | Content directory path |
|
|
317
|
+
| `--endpointsDir` | auto-detect | Directory for user-defined endpoints |
|
|
318
|
+
| `--staticDir` | `./public` | Directory for static file serving |
|
|
319
|
+
| `--cors` | `true` | Enable CORS headers |
|
|
320
|
+
| `--force` | `false` | Kill any process currently on the target port |
|
|
321
|
+
| `--anyPort` | `false` | Find an available port if the default is taken |
|
|
322
|
+
| `--open` | `false` | Open the server URL in a browser |
|
|
323
|
+
|
|
324
|
+
```bash
|
|
325
|
+
# Start with defaults
|
|
326
|
+
cnotes serve
|
|
327
|
+
|
|
328
|
+
# Custom port and content folder
|
|
329
|
+
cnotes serve --port 9000 --contentFolder ./sdlc
|
|
330
|
+
|
|
331
|
+
# Force-claim the port
|
|
332
|
+
cnotes serve --force
|
|
333
|
+
|
|
334
|
+
# Find any open port
|
|
335
|
+
cnotes serve --anyPort
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
#### Built-in API Endpoints
|
|
339
|
+
|
|
340
|
+
All endpoints return JSON unless otherwise noted.
|
|
341
|
+
|
|
342
|
+
**Collection info:**
|
|
343
|
+
|
|
344
|
+
| Method | Path | Description |
|
|
345
|
+
|--------|------|-------------|
|
|
346
|
+
| `GET` | `/api/inspect` | Collection overview — models, doc count, actions |
|
|
347
|
+
| `GET` | `/api/models` | All model definitions with schemas, sections, relationships |
|
|
348
|
+
|
|
349
|
+
**Documents:**
|
|
350
|
+
|
|
351
|
+
| Method | Path | Description |
|
|
352
|
+
|--------|------|-------------|
|
|
353
|
+
| `GET` | `/api/documents` | List all documents (`?model=` to filter by model) |
|
|
354
|
+
| `POST` | `/api/documents` | Create a new document (body: `{ pathId, title, meta?, model? }`) |
|
|
355
|
+
| `GET` | `/api/documents/:pathId` | Full document JSON (id, title, meta, content, outline, model) |
|
|
356
|
+
| `PUT` | `/api/documents/:pathId` | Update meta and/or content (body: `{ meta?, content? }`) |
|
|
357
|
+
| `PATCH` | `/api/documents/:pathId` | Edit a section (body: `{ heading, action, content? }`) |
|
|
358
|
+
| `DELETE` | `/api/documents/:pathId` | Delete a document |
|
|
359
|
+
|
|
360
|
+
**Querying:**
|
|
361
|
+
|
|
362
|
+
| Method | Path | Description |
|
|
363
|
+
|--------|------|-------------|
|
|
364
|
+
| `GET` | `/api/query` | Query model instances (`?model=&where=&select=`) |
|
|
365
|
+
| `GET` | `/api/search` | Full-text regex search (`?pattern=&model?&caseSensitive?`) |
|
|
366
|
+
| `GET` | `/api/text-search` | File-level text search (`?pattern=&expanded?&include?&exclude?&ignoreCase?&maxResults?`) |
|
|
367
|
+
|
|
368
|
+
**Validation:**
|
|
369
|
+
|
|
370
|
+
| Method | Path | Description |
|
|
371
|
+
|--------|------|-------------|
|
|
372
|
+
| `GET` | `/api/validate` | Validate a document (`?pathId=&model?`) |
|
|
373
|
+
|
|
374
|
+
**Actions:**
|
|
375
|
+
|
|
376
|
+
| Method | Path | Description |
|
|
377
|
+
|--------|------|-------------|
|
|
378
|
+
| `GET` | `/api/actions` | List available action names |
|
|
379
|
+
| `POST` | `/api/actions` | Execute an action (body: `{ name, args? }`) |
|
|
380
|
+
|
|
381
|
+
**Document serving (content-negotiated):**
|
|
382
|
+
|
|
383
|
+
| Method | Path | Description |
|
|
384
|
+
|--------|------|-------------|
|
|
385
|
+
| `GET` | `/docs/:path.json` | Document as JSON |
|
|
386
|
+
| `GET` | `/docs/:path.md` | Raw markdown with frontmatter |
|
|
387
|
+
| `GET` | `/docs/:path.html` | Rendered HTML page |
|
|
388
|
+
|
|
389
|
+
**Meta:**
|
|
390
|
+
|
|
391
|
+
| Method | Path | Description |
|
|
392
|
+
|--------|------|-------------|
|
|
393
|
+
| `GET` | `/openapi.json` | Auto-generated OpenAPI 3.1 spec |
|
|
394
|
+
|
|
395
|
+
#### Examples
|
|
396
|
+
|
|
397
|
+
```bash
|
|
398
|
+
# Start the server
|
|
399
|
+
cnotes serve --port 8000 --contentFolder .
|
|
400
|
+
|
|
401
|
+
# List all documents
|
|
402
|
+
curl localhost:8000/api/documents
|
|
403
|
+
|
|
404
|
+
# List only epics
|
|
405
|
+
curl "localhost:8000/api/documents?model=Epic"
|
|
406
|
+
|
|
407
|
+
# Get a single document
|
|
408
|
+
curl localhost:8000/api/documents/epics/authentication
|
|
409
|
+
|
|
410
|
+
# Query stories by status
|
|
411
|
+
curl "localhost:8000/api/query?model=Story&where=[{\"path\":\"meta.status\",\"value\":\"created\"}]"
|
|
412
|
+
|
|
413
|
+
# Search for a term (document-level)
|
|
414
|
+
curl "localhost:8000/api/search?pattern=login"
|
|
415
|
+
|
|
416
|
+
# Text search — files only (default)
|
|
417
|
+
curl "localhost:8000/api/text-search?pattern=login"
|
|
418
|
+
|
|
419
|
+
# Text search — expanded with line-level matches
|
|
420
|
+
curl "localhost:8000/api/text-search?pattern=login&expanded=true"
|
|
421
|
+
|
|
422
|
+
# Text search — filter to markdown files, case insensitive
|
|
423
|
+
curl "localhost:8000/api/text-search?pattern=TODO&include=*.md&ignoreCase=true"
|
|
424
|
+
|
|
425
|
+
# Validate a document
|
|
426
|
+
curl "localhost:8000/api/validate?pathId=epics/authentication"
|
|
427
|
+
|
|
428
|
+
# Get a document as rendered HTML
|
|
429
|
+
curl localhost:8000/docs/epics/authentication.html
|
|
430
|
+
|
|
431
|
+
# Get raw markdown with frontmatter
|
|
432
|
+
curl localhost:8000/docs/epics/authentication.md
|
|
433
|
+
|
|
434
|
+
# Create a new document
|
|
435
|
+
curl -X POST localhost:8000/api/documents \
|
|
436
|
+
-H 'Content-Type: application/json' \
|
|
437
|
+
-d '{"pathId":"epics/payments","title":"Payments","meta":{"priority":"high"}}'
|
|
438
|
+
|
|
439
|
+
# Update a section
|
|
440
|
+
curl -X PATCH localhost:8000/api/documents/epics/authentication \
|
|
441
|
+
-H 'Content-Type: application/json' \
|
|
442
|
+
-d '{"heading":"Stories","action":"append","content":"### New Story\n\nDetails..."}'
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
#### User-Defined Endpoints
|
|
446
|
+
|
|
447
|
+
Place TypeScript files in an `endpoints/` or `src/endpoints/` directory in your project. Each file exports a `path` and HTTP method handlers following the luca endpoint convention:
|
|
448
|
+
|
|
449
|
+
```ts
|
|
450
|
+
// endpoints/stats.ts
|
|
451
|
+
export const path = '/api/stats'
|
|
452
|
+
export const tags = ['custom']
|
|
453
|
+
|
|
454
|
+
export async function get(params: any, ctx: any) {
|
|
455
|
+
const collection = ctx.container._contentbaseCollection
|
|
456
|
+
return {
|
|
457
|
+
totalDocs: collection.available.length,
|
|
458
|
+
models: collection.modelDefinitions.map((d: any) => d.name),
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
User endpoints are loaded after built-in endpoints, so you can add custom routes or override existing ones.
|
|
464
|
+
|
|
465
|
+
---
|
|
466
|
+
|
|
467
|
+
### `cnotes mcp`
|
|
468
|
+
|
|
469
|
+
Start a Model Context Protocol server that exposes the collection to AI agents. Provides tools for querying, creating, updating, and deleting documents, plus resources for schema introspection and prompts for guided workflows.
|
|
470
|
+
|
|
471
|
+
**Options:**
|
|
472
|
+
|
|
473
|
+
| Option | Default | Description |
|
|
474
|
+
|--------|---------|-------------|
|
|
475
|
+
| `--transport` | `stdio` | Transport: `stdio` or `http` |
|
|
476
|
+
| `--port` | `3003` | Port for HTTP transport |
|
|
477
|
+
| `--contentFolder` | `./docs` | Content directory path |
|
|
478
|
+
|
|
479
|
+
```bash
|
|
480
|
+
# Start with stdio (for Claude Desktop, etc.)
|
|
481
|
+
cnotes mcp
|
|
482
|
+
|
|
483
|
+
# Start with HTTP transport
|
|
484
|
+
cnotes mcp --transport http --port 3003
|
|
485
|
+
|
|
486
|
+
# Use a specific content folder
|
|
487
|
+
cnotes mcp --contentFolder ./sdlc
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
**MCP Tools provided:** `inspect`, `list_documents`, `query`, `search_content`, `text_search`, `validate`, `create_document`, `update_document`, `update_section`, `delete_document`, `run_action`
|
|
491
|
+
|
|
492
|
+
**MCP Resources:** `contentbase://schema`, `contentbase://toc`, `contentbase://models-summary`, `contentbase://primer`, and per-document resources at `contentbase://documents/{pathId}`
|
|
493
|
+
|
|
494
|
+
**MCP Prompts:** `create-{model}` (per model), `review-document`, `teach`, `query-guide`
|
|
495
|
+
|
|
496
|
+
---
|
|
497
|
+
|
|
498
|
+
## Interactive
|
|
499
|
+
|
|
500
|
+
### `cnotes console`
|
|
501
|
+
|
|
502
|
+
Start an interactive REPL with the collection and container features in scope.
|
|
503
|
+
|
|
504
|
+
```bash
|
|
505
|
+
cnotes console
|
|
506
|
+
cnotes console --contentFolder ./sdlc
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
The REPL provides:
|
|
510
|
+
- `collection` — your loaded Collection instance
|
|
511
|
+
- All container features (fs, git, proc, etc.) as top-level variables
|
|
512
|
+
- Full async/await support
|
|
513
|
+
|
|
514
|
+
Optionally, create a `cnotes.console.ts` file in your project root to customize the REPL context:
|
|
515
|
+
|
|
516
|
+
```ts
|
|
517
|
+
// cnotes.console.ts
|
|
518
|
+
export default function setup(context: Record<string, any>) {
|
|
519
|
+
context.epics = () => context.collection.query(Epic).fetchAll()
|
|
520
|
+
}
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
### `cnotes help`
|
|
524
|
+
|
|
525
|
+
List all available commands with their descriptions.
|
|
526
|
+
|
|
527
|
+
```bash
|
|
528
|
+
cnotes help
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
---
|
|
532
|
+
|
|
533
|
+
## Typical Workflows
|
|
534
|
+
|
|
535
|
+
### Setting up a new project
|
|
536
|
+
|
|
537
|
+
```bash
|
|
538
|
+
cnotes init my-docs
|
|
539
|
+
cd my-docs
|
|
540
|
+
# Edit models.ts to define your schemas
|
|
541
|
+
# Add markdown files to your prefix folders
|
|
542
|
+
cnotes validate
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
### Creating and validating content
|
|
546
|
+
|
|
547
|
+
```bash
|
|
548
|
+
cnotes create epic --title "User Authentication"
|
|
549
|
+
# Edit the generated file in your editor...
|
|
550
|
+
cnotes validate epics/user-authentication
|
|
551
|
+
cnotes validate Epic
|
|
552
|
+
cnotes validate
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
### Running a local content API
|
|
556
|
+
|
|
557
|
+
```bash
|
|
558
|
+
# Start the server
|
|
559
|
+
cnotes serve
|
|
560
|
+
|
|
561
|
+
# In another terminal — browse your collection
|
|
562
|
+
curl localhost:8000/api/inspect
|
|
563
|
+
curl localhost:8000/api/documents
|
|
564
|
+
curl localhost:8000/docs/epics/authentication.html
|
|
565
|
+
|
|
566
|
+
# Query with filters
|
|
567
|
+
curl "localhost:8000/api/query?model=Epic&where=[{\"path\":\"meta.priority\",\"value\":\"high\"}]"
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
### Generating documentation
|
|
571
|
+
|
|
572
|
+
```bash
|
|
573
|
+
cnotes summary
|
|
574
|
+
cnotes teach > CONTEXT.md
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
### Exploring interactively
|
|
578
|
+
|
|
579
|
+
```bash
|
|
580
|
+
cnotes console
|
|
581
|
+
> const epics = await collection.query(Epic).fetchAll()
|
|
582
|
+
> epics.map(e => e.title)
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
### AI agent integration
|
|
586
|
+
|
|
587
|
+
```bash
|
|
588
|
+
# Add to Claude Desktop config
|
|
589
|
+
cnotes mcp --contentFolder ./docs
|
|
590
|
+
|
|
591
|
+
# Or expose over HTTP
|
|
592
|
+
cnotes mcp --transport http --port 3003
|
|
593
|
+
```
|