# Analytics and health Source: https://docs.kiwifs.com/api/analytics Measure page views and search success, find content gaps, and check knowledge base health. These endpoints answer two questions: what are people and agents reading and failing to find, and which pages need attention. Analytics and health endpoints need the default SQLite search backend and return `501` when KiwiFS runs with `search.engine = "grep"`. KiwiFS records a page view on every `GET /api/kiwi/file` for a markdown page, except from known bots. Tag views with `?source=` or the `X-Kiwi-Source` header (default `api`) to break them down by client. ## Health dashboard Return page counts, health issues, link coverage, recent updates, and engagement in one call. The web UI's analytics panel uses this. ```http theme={null} GET /api/kiwi/analytics ``` Path prefix. Only pages under it are counted. Days used for the stale check. See [Stale pages](#stale-pages). ```bash theme={null} curl 'http://localhost:3333/api/kiwi/analytics?scope=concepts/' ``` Indexed pages. Sum of word counts. Issue groups. Each has `count` and `paths`. Orphans, broken links, and empty pages come from the latest [janitor scan](#janitor-scan). Pages past review. See [Stale pages](#stale-pages). Pages no other page links to. Pages containing a wiki link that doesn't resolve. Pages with no body. Pages without frontmatter. `paths` is always empty. Pages with at least one outgoing link. Pages with none. Mean outgoing links per page. The 10 most recently updated pages, each with `path` and `updated_at`. All recorded page views. Most viewed pages. Same shape as [page views](#page-views). Most frequent searches with no results. Same shape as [failed searches](#failed-searches). ```json theme={null} { "total_pages": 142, "total_words": 58210, "health": { "stale": { "count": 2, "paths": ["concepts/legacy-auth.md", "concepts/sso.md"] }, "orphans": { "count": 1, "paths": ["concepts/caching.md"] }, "broken_links": { "count": 1, "paths": ["concepts/billing.md"] }, "empty": { "count": 0, "paths": [] }, "no_frontmatter": { "count": 12, "paths": [] } }, "coverage": { "pages_with_links": 120, "pages_without_links": 22, "avg_links_per_page": 3.4 }, "top_updated": [ { "path": "concepts/auth.md", "updated_at": "2026-10-18T14:30:00Z" } ], "engagement": { "total_views": 3120, "top_viewed": [ { "path": "concepts/auth.md", "count": 412, "first_seen": 1758000000, "last_seen": 1760880000 } ], "failed_searches": [ { "query": "oauth refresh token", "search_type": "search", "count": 7, "first_seen": 1759000000, "last_seen": 1760870000 } ] } } ``` ## Analytics overview Return headline numbers for a period, each compared with the period before it. ```http theme={null} GET /api/kiwi/analytics/overview ``` Number of days followed by `d`, such as `7d`, `30d`, or `90d`. Invalid values fall back to `7d`. ```bash theme={null} curl 'http://localhost:3333/api/kiwi/analytics/overview?period=30d' ``` Period used. Page views in the period. Change in views versus the previous period, in percent. Searches in the period. Change in searches, in percent. Share of searches that returned results. Change in success rate, in percentage points. Distinct pages viewed. Change in distinct pages viewed, in percent. ```json theme={null} { "period": "30d", "total_views": 3120, "views_delta_percent": 12.5, "total_searches": 860, "searches_delta_percent": -3.1, "search_success_rate": 0.91, "success_rate_delta_pp": 2.0, "unique_pages_viewed": 97, "unique_pages_delta_percent": 4.3 } ``` ## Page views Return the most viewed pages, optionally for one page or since a point in time. ```http theme={null} GET /api/kiwi/analytics/views ``` Maximum rows, up to 200. Only return views of this page. Unix timestamp or RFC 3339 time. Returns `400` if it is neither. ```bash theme={null} curl 'http://localhost:3333/api/kiwi/analytics/views?top=5&since=2026-10-01T00:00:00Z' ``` Row limit used. Path filter, if given. Start time as a Unix timestamp, if given. Page path. Views. First view, Unix seconds. Latest view, Unix seconds. ```json theme={null} { "top": 5, "since": 1759276800, "results": [ { "path": "concepts/auth.md", "count": 212, "first_seen": 1759280000, "last_seen": 1760880000 } ] } ``` ## Page view time series Return page views bucketed over time, plus the top 20 pages for the period. Buckets are hourly for periods up to 7 days and daily beyond that. ```http theme={null} GET /api/kiwi/analytics/views/v2 ``` Number of days followed by `d`. Limit the time series to one page. `top_pages` always covers every page. ```bash theme={null} curl 'http://localhost:3333/api/kiwi/analytics/views/v2?period=7d&path=concepts/auth.md' ``` Period used. Path filter, if given. Buckets, each with `timestamp` (Unix seconds, bucket start) and `count`. Up to 20 pages, same shape as [page views](#page-views) results. ```json theme={null} { "period": "7d", "path": "concepts/auth.md", "time_series": [ { "timestamp": 1760839200, "count": 4 }, { "timestamp": 1760842800, "count": 9 } ], "top_pages": [ { "path": "concepts/auth.md", "count": 61, "first_seen": 1760300000, "last_seen": 1760880000 } ] } ``` ## Search analytics Return search volume over time, the success rate, and the 20 most frequent failed queries for a period. ```http theme={null} GET /api/kiwi/analytics/searches ``` Number of days followed by `d`. ```bash theme={null} curl 'http://localhost:3333/api/kiwi/analytics/searches?period=30d' ``` Period used. Share of searches that returned results. Buckets, each with `timestamp` and `count`. Query text. Which search ran it, such as `search` or `semantic`. Times it was run. Times it returned results. ```json theme={null} { "period": "30d", "search_success_rate": 0.91, "time_series": [{ "timestamp": 1758240000, "count": 31 }], "top_failed": [ { "query": "oauth refresh token", "search_type": "search", "count": 7, "had_results": 0 } ] } ``` ## Failed searches Return the most frequent searches that returned no results. ```http theme={null} GET /api/kiwi/analytics/failed-searches ``` Maximum rows, up to 200. Unix timestamp or RFC 3339 time. Returns `400` if it is neither. ```bash theme={null} curl 'http://localhost:3333/api/kiwi/analytics/failed-searches?top=10' ``` Row limit used. Start time as a Unix timestamp, if given. Query text. Which search ran it. Times it failed. First failure, Unix seconds. Latest failure, Unix seconds. ```json theme={null} { "top": 10, "results": [ { "query": "oauth refresh token", "search_type": "search", "count": 7, "first_seen": 1759000000, "last_seen": 1760870000 } ] } ``` ## Trends Return pages whose views rose or fell most compared with the previous period. ```http theme={null} GET /api/kiwi/analytics/trends ``` Number of days followed by `d`. ```bash theme={null} curl 'http://localhost:3333/api/kiwi/analytics/trends?period=7d' ``` Period used. Pages with rising views. Pages with falling views. Both arrays share this shape: Page path. Views in this period. Views in the previous period. Change, in percent. ```json theme={null} { "period": "7d", "trending": [{ "path": "runbooks/deploy.md", "current_views": 48, "previous_views": 12, "delta_percent": 300 }], "declining": [{ "path": "concepts/legacy-auth.md", "current_views": 2, "previous_views": 15, "delta_percent": -86.7 }] } ``` ## Content gaps Return failed queries that suggest missing pages. Dismissed queries are excluded. ```http theme={null} GET /api/kiwi/analytics/content-gaps ``` Maximum rows, up to 200. ```bash theme={null} curl 'http://localhost:3333/api/kiwi/analytics/content-gaps?limit=10' ``` Same shape as [failed searches](#failed-searches) results. ```json theme={null} { "results": [ { "query": "oauth refresh token", "search_type": "search", "count": 7, "first_seen": 1759000000, "last_seen": 1760870000 } ] } ``` ## Dismiss a content gap Hide a query from the content gaps list, for example after writing the missing page. ```http theme={null} POST /api/kiwi/analytics/content-gaps/dismiss ``` Query text, exactly as listed. `search_type` from the content gap entry. ```bash theme={null} curl -X POST 'http://localhost:3333/api/kiwi/analytics/content-gaps/dismiss' \ -H "Content-Type: application/json" \ -d '{"query": "oauth refresh token"}' ``` Returns `400` if `query` is missing. ```json theme={null} { "dismissed": "oauth refresh token" } ``` ## View sources Return page views in a period grouped by source. The source is the `source` query parameter or `X-Kiwi-Source` header sent with the file read, or `api` when neither is set. ```http theme={null} GET /api/kiwi/analytics/sources ``` Number of days followed by `d`. ```bash theme={null} curl 'http://localhost:3333/api/kiwi/analytics/sources?period=30d' ``` Period used. Map from source name to view count. ```json theme={null} { "period": "30d", "sources": { "ui": 2410, "api": 530, "mcp": 180 } } ``` ## Page health check Return size, link, and freshness metrics and open issues for one page. ```http theme={null} GET /api/kiwi/health-check ``` Page path. ```bash theme={null} curl 'http://localhost:3333/api/kiwi/health-check?path=concepts/auth.md' ``` Returns `400` if `path` is missing. A page that isn't indexed returns `200` with the issue `page not found in index`. Page path. Words in the page. Outgoing links. Incoming links. Days since the page last changed. Frontmatter `quality_score`, if set. Issues from the latest janitor scan, formatted `kind: message`. ```json theme={null} { "path": "concepts/billing.md", "word_count": 342, "link_count": 5, "backlink_count": 8, "days_since_update": 2.4, "issues": ["broken-link: link [[payments-v1]] does not resolve"] } ``` ## Stale pages List pages due for review. A page is stale when its `next-review` date has passed, or, if it has no `next-review`, when its `reviewed` date is older than `days`. Pages with `status: deprecated` or `status: archived` are skipped. ```http theme={null} GET /api/kiwi/stale ``` Age threshold for the `reviewed` fallback. ```bash theme={null} curl 'http://localhost:3333/api/kiwi/stale?days=60' ``` Threshold used. Stale pages found. Pages, each with `path` and `frontmatter`. ```json theme={null} { "staleDays": 60, "count": 1, "results": [ { "path": "concepts/legacy-auth.md", "frontmatter": { "title": "Legacy authentication", "next-review": "2026-08-01", "status": "active" } } ] } ``` ## Contradictions List pages that may conflict with a given page. A page is a candidate when it shares a `tags` or `topics` value with the given page and either has a different `status`, or both pages set `source-of-truth: true`. ```http theme={null} GET /api/kiwi/contradictions ``` Page path. ```bash theme={null} curl 'http://localhost:3333/api/kiwi/contradictions?path=concepts/auth.md' ``` Page checked. Paths of possibly conflicting pages. ```json theme={null} { "path": "concepts/auth.md", "contradictions": ["runbooks/login-flow.md"] } ``` ## Janitor scan Return the results of a knowledge base health scan. The server runs scans on a schedule; this endpoint returns the cached result unless you ask for a fresh one or a non-default threshold. ```http theme={null} GET /api/kiwi/janitor ``` Days without changes before a page counts as stale. The default comes from the janitor configuration. Run a new scan instead of returning the cached result. ```bash theme={null} curl 'http://localhost:3333/api/kiwi/janitor?fresh=true' ``` Cached responses include an `X-Kiwi-Janitor-LastScan` header with the scan time. `stale`, `orphan`, `duplicate`, `contradiction`, `missing-owner`, `missing-status`, `empty-page`, `broken-link`, `no-review-date`, `decision-found`, `expired-memory`, or `execution-stale`. Affected page. What's wrong. Other pages involved, such as the duplicate. How to fix it. `error`, `warning`, or `info`. Pages scanned. Pages with no issues. When the scan ran. ```json theme={null} { "issues": [ { "kind": "orphan", "path": "concepts/caching.md", "message": "no other page links here", "suggestion": "link it from a parent topic", "severity": "warning" } ], "scanned": 142, "healthy": 131, "timestamp": "2026-10-19T06:00:00Z" } ``` ## Memory report Summarize episodic memory: how many episode files exist, how many have been merged into durable pages, and which haven't. See [Episodic memory](/concepts/episodic-memory). ```http theme={null} GET /api/kiwi/memory/report ``` Folder holding episode files. Defaults to `[memory] episodes_path_prefix` in config. Maximum entries in `episodic_files` and `unmerged`. Entries to skip in `episodic_files` and `unmerged`. ```bash theme={null} curl 'http://localhost:3333/api/kiwi/memory/report?limit=50' ``` Returns `400` for a negative or non-numeric `limit` or `offset`. Results are cached for 30 seconds. Episode files found. Episode files before pagination. Unmerged episodes before pagination. `merged-from` references across all pages. Percentage of episodes referenced by a `merged-from` entry. Pages flagged as contradicting each other. Mean age of active pages, in days. Pages whose `expires_at` has passed. Pages with `memory_status: contested`. Map from frontmatter `scope` value to page count. Episode files, each with `path` and optional `episode_id` and `memory_kind`. Episodes not yet merged, same shape. Problems found while scanning. Omitted when empty. ```json theme={null} { "episodic_count": 23, "total_episodic": 23, "total_unmerged": 8, "contradictions": 0, "merged_from_refs": 15, "coverage_pct": 65.2, "avg_age_days": 41.7, "expired_count": 1, "contested_count": 0, "scope_counts": { "team": 18, "personal": 5 }, "episodic_files": [{ "path": "episodes/ep-001.md", "episode_id": "ep-001" }], "unmerged": [{ "path": "episodes/ep-012.md", "episode_id": "ep-012" }] } ``` ## MCP equivalents `kiwi_analytics` (health dashboard), `kiwi_health_check`, and `kiwi_memory_report`. ## Related Find and fix broken links and orphan pages. The analytics panel built on these endpoints. # Canvas Source: https://docs.kiwifs.com/api/canvas List, read, write, patch, query, lay out, and generate JSON Canvas files. Canvases are [JSON Canvas](https://jsoncanvas.org) documents stored as `.canvas.json` files in the knowledge base. Every write goes through the normal write pipeline, so each change is a git commit and broadcasts an SSE event. See [Canvas](/concepts/canvas) for the data model. Every endpoint that takes a `path` rejects paths that don't end in `.canvas.json` with `400`. ## List canvases Return every `.canvas.json` file in the knowledge base. ```http theme={null} GET /api/kiwi/canvases ``` ```bash theme={null} curl 'http://localhost:3333/api/kiwi/canvases' ``` One entry per canvas file. Empty array when there are none. Path relative to the knowledge root. File name without the `.canvas.json` suffix. ```json theme={null} { "canvases": [ { "path": "maps/site.canvas.json", "name": "site" }, { "path": "research/ideas.canvas.json", "name": "ideas" } ] } ``` ## Read a canvas Return the raw canvas document. ```http theme={null} GET /api/kiwi/canvas ``` Canvas file path. ```bash theme={null} curl 'http://localhost:3333/api/kiwi/canvas?path=maps/site.canvas.json' ``` Returns the stored JSON as-is with `Content-Type: application/json`. Returns `404` if the file does not exist and `500` if it is not a valid canvas. ```json theme={null} { "nodes": [ { "id": "n1", "type": "file", "file": "concepts/auth.md", "x": 0, "y": 0, "width": 400, "height": 300 }, { "id": "n2", "type": "text", "text": "Open questions", "x": 480, "y": 0, "width": 240, "height": 120 } ], "edges": [ { "id": "e1", "fromNode": "n1", "toNode": "n2", "label": "see" } ] } ``` ## Write a canvas Create or replace a canvas. The body is the full JSON Canvas document. ```http theme={null} PUT /api/kiwi/canvas ``` Canvas file path. Git commit author attribution. JSON Canvas nodes. An empty array is allowed. JSON Canvas edges. An empty array is allowed. ```bash theme={null} curl -X PUT 'http://localhost:3333/api/kiwi/canvas?path=maps/site.canvas.json' \ -H "Content-Type: application/json" \ -H "X-Actor: agent:mapper" \ -d '{"nodes":[{"id":"n1","type":"file","file":"concepts/auth.md","x":0,"y":0,"width":400,"height":300}],"edges":[]}' ``` Returns `400` if the body is not JSON with `nodes` and `edges` arrays. Canvas path that was written. Git blob hash of the new content. ```json theme={null} { "path": "maps/site.canvas.json", "etag": "3f2a9c1e8b7d6a5f4e3d2c1b0a9f8e7d6c5b4a39" } ``` ## Patch a canvas Apply a batch of node and edge operations without sending the whole document. The batch is atomic: if any operation fails, nothing is written. If the canvas does not exist yet, the operations apply to an empty canvas. ```http theme={null} PATCH /api/kiwi/canvas ``` Canvas file path. Git commit author attribution. Operations, applied in order. Must not be empty. One of `add_node`, `update_node`, `remove_node`, `add_edge`, `update_edge`, `remove_edge`. Target ID for `update_*` and `remove_*`. For `update_*` you can omit it and put `id` inside `node` or `edge` instead. Full node for `add_node`, or the fields to merge for `update_node`. Full edge for `add_edge`, or the fields to merge for `update_edge`. ```bash theme={null} curl -X PATCH 'http://localhost:3333/api/kiwi/canvas?path=maps/site.canvas.json' \ -H "Content-Type: application/json" \ -d '{ "operations": [ { "op": "add_node", "node": { "id": "n3", "type": "file", "file": "concepts/oauth.md", "x": 0, "y": 400, "width": 400, "height": 300 } }, { "op": "update_node", "id": "n1", "node": { "x": 120 } }, { "op": "add_edge", "edge": { "id": "e2", "fromNode": "n1", "toNode": "n3", "label": "depends on" } }, { "op": "remove_node", "id": "n2" } ] }' ``` Returns `400` for an unparseable body or an empty `operations` array, and `422` when an operation is invalid (unknown `op`, duplicate ID on add, or unknown ID on update or remove). Removing a node also removes every edge connected to it. Canvas path. Git blob hash of the new content. Counts of what changed. Nodes inserted. Nodes merged in place. Nodes deleted. Edges inserted. Edges merged in place. Edges deleted, including edges removed with a node. ```json theme={null} { "path": "maps/site.canvas.json", "etag": "9b8a7c6d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b", "applied": { "nodes_added": 1, "nodes_updated": 1, "nodes_removed": 1, "edges_added": 1, "edges_updated": 0, "edges_removed": 1 } } ``` ## Delete a canvas Delete a canvas file and record the deletion as a git commit. ```http theme={null} DELETE /api/kiwi/canvas ``` Canvas file path. Git commit author attribution. ```bash theme={null} curl -X DELETE 'http://localhost:3333/api/kiwi/canvas?path=maps/site.canvas.json' ``` Returns `404` if the canvas does not exist. Path that was deleted. ```json theme={null} { "deleted": "maps/site.canvas.json" } ``` ## Query canvas nodes Filter the nodes and edges of one canvas. ```http theme={null} GET /api/kiwi/canvas/query ``` Canvas file path. Case-insensitive substring match against a node's `id`, `text`, `file`, and `url`, and an edge's `id` and `label`. Edges touching a matched node are also returned. Node type: `text`, `file`, `link`, or `group`. Node ID. Returns that node and every edge whose `fromNode` or `toNode` is that ID. Omit edges from the result. Omit nodes from the result. ```bash theme={null} curl 'http://localhost:3333/api/kiwi/canvas/query?path=maps/site.canvas.json&connected=n1' ``` Returns `404` if the canvas does not exist. Matching JSON Canvas nodes. Matching JSON Canvas edges. ```json theme={null} { "nodes": [ { "id": "n1", "type": "file", "file": "concepts/auth.md", "x": 120, "y": 0, "width": 400, "height": 300 } ], "edges": [ { "id": "e2", "fromNode": "n1", "toNode": "n3", "label": "depends on" } ] } ``` ## Auto-layout a canvas Reposition the existing nodes of a canvas with a Graphviz layout engine and save the result. This does not add nodes; use [generate](#generate-a-canvas-from-the-link-graph) to build a canvas from wiki links. ```http theme={null} POST /api/kiwi/canvas/auto-layout ``` Canvas file to lay out in place. Git commit author attribution. Graphviz engine: `dot`, `neato`, `fdp`, or `circo`. The body is optional. ```bash theme={null} curl -X POST 'http://localhost:3333/api/kiwi/canvas/auto-layout?path=maps/site.canvas.json' \ -H "Content-Type: application/json" \ -d '{"layout": "neato"}' ``` Returns `404` if the canvas does not exist. Canvas path. Git blob hash of the new content. Nodes in the canvas. Edges in the canvas. ```json theme={null} { "path": "maps/site.canvas.json", "etag": "c4d3e2f1a0b9c8d7e6f5a4b3c2d1e0f9a8b7c6d5", "node_count": 2, "edge_count": 1 } ``` ## Generate a canvas from the link graph Build a canvas with one file node per page and one edge per wiki link, lay it out, and write it to disk. Existing content at the output path is replaced. ```http theme={null} POST /api/kiwi/canvas/generate ``` Git commit author attribution. Output file. `.canvas.json` is appended if missing. `hierarchical`, `radial`, `force`, or `circular`. Unknown values fall back to `hierarchical`. Path prefix. Only links whose source and target both start with this prefix become edges. Color nodes by detected link community. ```bash theme={null} curl -X POST 'http://localhost:3333/api/kiwi/canvas/generate' \ -H "Content-Type: application/json" \ -d '{"path": "maps/concepts", "layout": "radial", "folder": "concepts/"}' ``` Returns `503` if the link index is unavailable. Canvas path that was written. Git blob hash of the new content. Nodes generated. Edges generated. ```json theme={null} { "path": "maps/concepts.canvas.json", "etag": "0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b", "node_count": 42, "edge_count": 97 } ``` ## MCP equivalents MCP exposes `kiwi_canvas_list`, `kiwi_canvas_read`, and `kiwi_canvas_write`. Patch, query, auto-layout, and generate are REST-only. ## Related Node types, edges, and how canvases render in the web UI. The full list of MCP tools, including the canvas tools. # Claims Source: https://docs.kiwifs.com/api/claims Claim, release, and list cooperative leases on file paths. A claim is a time-limited lease that tells other agents you are working on a path. Claims are cooperative: they don't block writes, but agents that check claims before working avoid doing the same task twice. Refactor plans also refuse to move claimed pages and keep claims attached to pages they move. See [Claims](/concepts/claims) for patterns. Claims are stored in `.kiwi/state/` and are on by default. If the claim store can't open, every endpoint returns `503` with `claims not enabled`. ## Claim a path Acquire a lease on an existing file, or extend a lease you already hold. ```http theme={null} POST /api/kiwi/claim ``` Who is claiming the path. Returns `400` if missing. File path. Returns `404` if the file does not exist. Go duration such as `45m` or `2h`. Values under `1m` are raised to `1m`. Values over `24h` return `400`. ```bash theme={null} curl -X POST 'http://localhost:3333/api/kiwi/claim' \ -H "Content-Type: application/json" \ -H "X-Actor: agent:deployer" \ -d '{"path": "runbooks/deploy.md", "lease_duration": "45m"}' ``` Claimed path. Actor holding the lease. When the lease started (RFC 3339, UTC). When the lease ends (RFC 3339, UTC). ```json theme={null} { "path": "runbooks/deploy.md", "claimed_by": "agent:deployer", "claimed_at": "2026-10-19T14:00:00Z", "expires_at": "2026-10-19T14:45:00Z" } ``` If another actor holds an unexpired lease, the server returns `409` with that lease: ```json theme={null} { "error": "already claimed", "active_claim": { "path": "runbooks/deploy.md", "claimed_by": "agent:other", "claimed_at": "2026-10-19T13:50:00Z", "expires_at": "2026-10-19T14:20:00Z" } } ``` ## Release a claim Release a lease you hold. The body goes on a `DELETE` request. ```http theme={null} DELETE /api/kiwi/claim ``` Must match the actor that holds the lease. Claimed path. ```bash theme={null} curl -X DELETE 'http://localhost:3333/api/kiwi/claim' \ -H "Content-Type: application/json" \ -H "X-Actor: agent:deployer" \ -d '{"path": "runbooks/deploy.md"}' ``` Returns `403` if the caller does not hold a claim on the path. ```json theme={null} { "status": "released" } ``` ## List active claims Return every unexpired claim. ```http theme={null} GET /api/kiwi/claims ``` ```bash theme={null} curl 'http://localhost:3333/api/kiwi/claims' ``` Active claims, with the same fields as the [claim response](#claim-a-path). ```json theme={null} { "claims": [ { "path": "runbooks/deploy.md", "claimed_by": "agent:deployer", "claimed_at": "2026-10-19T14:00:00Z", "expires_at": "2026-10-19T14:45:00Z" } ] } ``` ## MCP equivalents `kiwi_claim`, `kiwi_release`, and `kiwi_claims_list`. ## Related How agents coordinate with leases. Move claimed tasks through workflow states. # Drafts Source: https://docs.kiwifs.com/api/drafts Create git-backed draft branches, edit files in them, then merge or discard. A draft is a git branch with its own worktree. An agent can write a batch of changes there, you review the diff, and then merge it into main in one fast-forward or throw it away. Main stays untouched until the merge. Drafts are off by default. Turn them on in `.kiwi/config.toml`: ```toml .kiwi/config.toml theme={null} [drafts] enabled = true max_active = 10 # default 10 ``` When drafts are off, every endpoint on this page returns `501`. All paths are relative to `http://localhost:3333/api/kiwi`. See [Draft spaces](/concepts/draft-spaces) for the workflow. ## Create a draft Branches from the current `HEAD` and returns the new draft. **`POST /drafts`** Who owns the draft. Falls back to `X-Actor`, then `api`. ```bash theme={null} curl -X POST 'http://localhost:3333/api/kiwi/drafts' \ -H "Content-Type: application/json" \ -d '{"actor": "agent:planner"}' ``` Eight-character hex ID used in every other draft route. Git branch, `draft/{id}`. Owner. Creation time (RFC 3339). ```json 201 Created theme={null} { "id": "3fa9c21e", "branch": "draft/3fa9c21e", "actor": "agent:planner", "created_at": "2026-10-19T09:30:00Z" } ``` Returns `409` when `max_active` drafts already exist or the repository has no commits yet. ## List drafts Returns all active drafts as an array of the same objects. **`GET /drafts`** ```bash theme={null} curl 'http://localhost:3333/api/kiwi/drafts' ``` ```json Response theme={null} [ {"id": "3fa9c21e", "branch": "draft/3fa9c21e", "actor": "agent:planner", "created_at": "2026-10-19T09:30:00Z"} ] ``` ## Get a draft Returns one draft. **`GET /drafts/:id`** Draft ID. ```bash theme={null} curl 'http://localhost:3333/api/kiwi/drafts/3fa9c21e' ``` Returns the draft object, or `404` if the ID is unknown. ## Read a file in a draft Returns a file's content as it is in the draft, with an `ETag` header. **`GET /drafts/:id/file`** Draft ID. File path. ```bash theme={null} curl -i 'http://localhost:3333/api/kiwi/drafts/3fa9c21e/file?path=concepts/auth.md' ``` The body is `text/markdown`. Returns `404` if the draft or file does not exist. ## Write a file in a draft Creates or replaces a file on the draft branch. The body is the full file content. **`PUT /drafts/:id/file`** Draft ID. File path. Commit author on the draft branch. ```bash theme={null} curl -X PUT 'http://localhost:3333/api/kiwi/drafts/3fa9c21e/file?path=concepts/auth.md' \ -H "X-Actor: agent:planner" \ --data-binary @auth.md ``` ```json Response theme={null} {"path": "concepts/auth.md", "etag": "c3d4e5f6..."} ``` Draft writes do not check `If-Match`. The merge is a plain git fast-forward, so review the diff before you merge. ## Delete a file in a draft Deletes a file on the draft branch. **`DELETE /drafts/:id/file`** Draft ID. File path. Commit author. ```bash theme={null} curl -X DELETE 'http://localhost:3333/api/kiwi/drafts/3fa9c21e/file?path=concepts/old.md' ``` Returns `204` with no body. ## Get a draft's tree Returns the draft's folder hierarchy, in the same shape as [`GET /tree`](/api/files#get-the-directory-tree). **`GET /drafts/:id/tree`** Draft ID. Folder to start from. ```bash theme={null} curl 'http://localhost:3333/api/kiwi/drafts/3fa9c21e/tree' ``` ## Diff a draft Returns everything the draft changed since it branched from main, as a unified diff. **`GET /drafts/:id/diff`** Draft ID. ```bash theme={null} curl 'http://localhost:3333/api/kiwi/drafts/3fa9c21e/diff' ``` ```json Response theme={null} {"diff": "diff --git a/concepts/auth.md b/concepts/auth.md\n--- a/concepts/auth.md\n+++ b/concepts/auth.md\n@@ -1,3 +1,3 @@\n..."} ``` ## Merge a draft Fast-forwards main to the draft branch, then removes the draft. Uncommitted files in the draft worktree are committed first. **`POST /drafts/:id/merge`** Draft ID. ```bash theme={null} curl -X POST 'http://localhost:3333/api/kiwi/drafts/3fa9c21e/merge' ``` ```json Response theme={null} {"status": "merged"} ``` Returns `409` when main has moved since the draft was created, because only fast-forward merges are allowed. Recreate the draft from the new `HEAD`, or apply the changes to main directly. ## Discard a draft Deletes the draft's branch and worktree. Main is unchanged. **`DELETE /drafts/:id`** Draft ID. ```bash theme={null} curl -X DELETE 'http://localhost:3333/api/kiwi/drafts/3fa9c21e' ``` Returns `204` with no body, or `404` if the ID is unknown. ## Related When to stage changes in a draft. The `kiwi_draft_*` tools do the same from an agent. # Files Source: https://docs.kiwifs.com/api/files Read, write, patch, append, rename, upload, and serve files through the KiwiFS REST API. File endpoints are the core of the API. Every write goes through the write pipeline: it lands on disk, becomes a git commit, updates the search index, and is broadcast to SSE subscribers. All paths below are relative to `http://localhost:3333/api/kiwi` unless they start with `/raw`. File paths in `?path=` are relative to the knowledge root; paths that escape the root or point into hidden directories return `400`. ## Get the directory tree Returns the folder hierarchy as a nested object, up to 20 levels deep. **`GET /tree`** Folder to start from. ```bash theme={null} curl 'http://localhost:3333/api/kiwi/tree?path=concepts' ``` Path relative to the root. File or folder name. `true` for folders. File size in bytes. Omitted for folders. Public URL for the file. Present only for files when a public URL is configured. Nested entries with the same shape. Omitted when empty. ```json Response theme={null} { "path": "concepts", "name": "concepts", "isDir": true, "children": [ { "path": "concepts/auth.md", "name": "auth.md", "isDir": false, "size": 1420, "permalink": "https://wiki.example.com/page/concepts/auth.md" } ] } ``` Returns `404` if the folder does not exist. ## Read a file Returns the raw file bytes with an `ETag` you can use for [conditional writes](/api/overview#optimistic-concurrency). **`GET /file`** File path. Return only the parsed frontmatter as a JSON object. Rewrite wiki links to absolute URLs. Requires a configured public URL. Label stored with the page view in [analytics](/api/analytics). Also accepted as the `X-Kiwi-Source` header. ETag from an earlier read. Returns `304` when it still matches. HTTP date. Returns `304` when the file has not changed since. ```bash Content theme={null} curl -i 'http://localhost:3333/api/kiwi/file?path=concepts/auth.md' ``` ```bash Frontmatter only theme={null} curl 'http://localhost:3333/api/kiwi/file?path=concepts/auth.md&metadata_only=true' ``` ```http Response theme={null} HTTP/1.1 200 OK Content-Type: text/markdown; charset=utf-8 ETag: "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2" Last-Modified: Sun, 19 Oct 2026 09:30:00 GMT Cache-Control: no-cache X-Permalink: https://wiki.example.com/page/concepts/auth.md --- title: Authentication status: verified --- # Authentication OAuth2 + JWT based authentication system. ``` Response headers: | Header | Meaning | | - | - | | `ETag` | Quoted git blob hash of the content | | `Last-Modified` | File modification time | | `X-Permalink` | Public URL, when a public URL is configured | | `X-File-Type` | `symlink` when the path is a symbolic link | Returns `404` if the file does not exist. ## Write a file Creates or replaces a file. The request body is the full file content, up to 32 MB. **`PUT /file`** File path. Parent folders are created as needed. ETag the file must still have. Returns `409` on mismatch. Commit author. `type:id` pair appended to the page's `derived-from` frontmatter list, for example `run:run-249`. Send `application/x-symlink` to create a symbolic link whose target is the body. ```bash Create or replace theme={null} curl -X PUT 'http://localhost:3333/api/kiwi/file?path=concepts/auth.md' \ -H "Content-Type: text/markdown" \ -H "X-Actor: agent:docs-writer" \ --data-binary @auth.md ``` ```bash Conditional write theme={null} curl -X PUT 'http://localhost:3333/api/kiwi/file?path=concepts/auth.md' \ -H "Content-Type: text/markdown" \ -H "X-Actor: agent:docs-writer" \ -H 'If-Match: "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2"' \ --data-binary @auth.md ``` ```bash Create a symlink theme={null} curl -X PUT 'http://localhost:3333/api/kiwi/file?path=latest.md' \ -H "Content-Type: application/x-symlink" \ -d 'reports/2026-10.md' ``` Path written. New ETag (also in the `ETag` header). ```json Response theme={null} {"path": "concepts/auth.md", "etag": "c3d4e5f6a7b8c3d4e5f6a7b8c3d4e5f6a7b8c3d4"} ``` A symlink write returns `{"path": "latest.md", "type": "symlink"}`. | Status | When | | - | - | | `409` | `If-Match` mismatch, denied workflow transition, rejected by a write hook, or the file is append-only | | `413` | Body over 32 MB | | `422` | Content fails the [schema](/api/schemas) for its type | ## Patch frontmatter Merges fields into a page's YAML frontmatter and leaves the body byte-for-byte unchanged. Two equivalent routes exist. The body wraps the fields in a `fields` object. ```bash theme={null} curl -X PATCH 'http://localhost:3333/api/kiwi/file/frontmatter?path=decisions/adr-12.md' \ -H "Content-Type: application/json" \ -H "X-Field-Manager: agent:reviewer" \ -d '{"fields": {"reviewed_by": "alice", "status": "accepted"}}' ``` The body is the field map itself. `merge=frontmatter` is required; other values return `400`. ```bash theme={null} curl -X PATCH 'http://localhost:3333/api/kiwi/file?path=runbooks/high-cpu.md&merge=frontmatter' \ -H "Content-Type: application/json" \ -H 'If-Match: "abc123..."' \ -d '{"last_executed": "2026-10-19", "execution_count": 5}' ``` Markdown file to update. Must already exist. Take over keys that another field manager owns. ETag the file must still have. Name that owns the keys you set. Another manager changing an owned key gets `409` unless it sends `force=true`. Commit author. ```json Response theme={null} {"path": "decisions/adr-12.md", "etag": "d4e5f6a7..."} ``` When a key belongs to another manager, nothing is written and the response lists the conflicts: ```json 409 Conflict theme={null} { "error": "decisions/adr-12.md: status (managed by agent:triage); force to take them over", "conflicts": [{"key": "status", "manager": "agent:triage"}] } ``` Returns `400` for a non-markdown file or an empty field map, and `404` if the file does not exist. ## Append to a file Adds content to the end of a file without a read-modify-write cycle. Creates the file if it does not exist. **`POST /file/append`** File path. Inserted between the existing content and the new content. Commit author. ```bash theme={null} curl -X POST 'http://localhost:3333/api/kiwi/file/append?path=log/agent.md' \ -H "X-Actor: agent:logger" \ --data-binary $'## Entry 42\n\nNew finding from run 249.' ``` ```json Response theme={null} {"path": "log/agent.md", "etag": "b2c3d4e5..."} ``` Use append for agent logs, episodic memory, and append-only files. The body limit is 32 MB. ## Delete a file Deletes a file and records the deletion as a commit. **`DELETE /file`** File path. Commit author. ```bash theme={null} curl -X DELETE 'http://localhost:3333/api/kiwi/file?path=concepts/old.md' \ -H "X-Actor: agent:cleanup" ``` ```json Response theme={null} {"deleted": "concepts/old.md"} ``` Returns `404` if the file does not exist. ## Bulk write Writes several files in one git commit. If any file fails a check, nothing is written. **`POST /bulk`** Files to write. File path. Full file content. ETag this file must still have. One mismatch fails the whole batch with `409`. Commit author. Falls back to `X-Actor`. Commit message. `type:id` pair added to every file's `derived-from` list. ```bash theme={null} curl -X POST 'http://localhost:3333/api/kiwi/bulk' \ -H "Content-Type: application/json" \ -d '{ "actor": "agent:importer", "message": "Import billing concepts", "files": [ {"path": "concepts/billing.md", "content": "# Billing\n\nStripe integration."}, {"path": "concepts/users.md", "content": "# Users\n\nUser management."} ] }' ``` Number of files written. `path` and new `etag` for each file. ```json Response theme={null} { "count": 2, "files": [ {"path": "concepts/billing.md", "etag": "e5f6a7b8..."}, {"path": "concepts/users.md", "etag": "f6a7b8c9..."} ] } ``` ## Rename a file Moves a file and rewrites every wiki link and markdown link that points to it, in one commit. **`POST /rename`** Current path. New path. Must not exist unless `overwrite=true`. Set `false` to move the file and leave references as written. Replace an existing destination, like `rename(2)`. Meant for protocol clients that save by writing a temp file and renaming it over the original. Commit author. ```bash theme={null} curl -X POST 'http://localhost:3333/api/kiwi/rename' \ -H "Content-Type: application/json" \ -d '{"from": "concepts/auth.md", "to": "concepts/authentication.md"}' ``` Original path. New path. ETag of the moved file. Other pages whose links were rewritten. Omitted when none changed. ```json Response theme={null} { "from": "concepts/auth.md", "to": "concepts/authentication.md", "etag": "c3d4e5f6...", "updated_links": ["concepts/users.md", "runbooks/login-outage.md"] } ``` Returns `404` if the source does not exist and `409` if the destination exists or a link could not be kept pointing at the file. ## Rename a folder Moves a folder, rewrites links into it from elsewhere, and fixes relative links inside it, in one commit. **`POST /rename-dir`** Current folder. New folder. No destination file may exist. Set `false` to leave references as written. ```bash theme={null} curl -X POST 'http://localhost:3333/api/kiwi/rename-dir' \ -H "Content-Type: application/json" \ -d '{"from": "concepts", "to": "docs/concepts"}' ``` ```json Response theme={null} { "from": "concepts", "to": "docs/concepts", "renamed": 15, "updated_links": ["index.md", "runbooks/onboarding.md"] } ``` `renamed` is the number of files moved. For multi-file moves and merges with a review step, see [Refactor](/api/refactor). ## Upload an asset Uploads an image, video, audio file, or PDF as multipart form data and returns a ready-to-paste markdown link. **`POST /assets`** Folder to store the file in, for example `assets/diagrams`. Defaults to the root. The file (multipart field name `file`). Hidden names starting with `.` are rejected. Commit author. ```bash theme={null} curl -X POST 'http://localhost:3333/api/kiwi/assets?path=assets' \ -H "X-Actor: agent:uploader" \ -F "file=@diagram.png" ``` Stored path. Embed (`![]()`) for images, video, and audio; a link for other types. Detected MIME type. Size in bytes. ETag of the stored file. ```json Response theme={null} { "path": "assets/diagram.png", "markdown": "![diagram](/raw/assets/diagram.png)", "contentType": "image/png", "size": 48213, "etag": "0a1b2c3d..." } ``` The default limit is 100 MiB and the default allowlist covers common image, video, and audio types plus PDF. Override both with `[assets] max_file_size` and `allowed_types`. Too large returns `413`; a type outside the allowlist returns `415`. ## Serve a raw file Serves file bytes at a stable URL for ``, `