agentic-documents 0.0.0-stage → 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pooria Arab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,185 @@
1
- # Temporary Holding Version
1
+ # agentic-documents
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm version](https://img.shields.io/npm/v/agentic-documents)](https://www.npmjs.com/package/agentic-documents)
4
+ [![MIT license](https://img.shields.io/badge/license-MIT-blue)](https://opensource.org/license/mit)
5
+
6
+ [Package](https://www.npmjs.com/package/agentic-documents) · [Source](https://github.com/pooriaarab/agentic-documents) · [Support](https://github.com/pooriaarab/agentic-documents/issues)
7
+
8
+ Write documents with people and agents in real time.
9
+
10
+ > Status: early, version 0.1.0. The document model, the text operations, the CLI, the MCP server,
11
+ > and the Worker API work. The web UI is not built yet.
12
+
13
+ ## Install
14
+
15
+ ```sh
16
+ npm install agentic-documents
17
+ ```
18
+
19
+ ## Quick start
20
+
21
+ ```ts
22
+ import { AgenticDoc, Suggestions, Threads } from "agentic-documents";
23
+
24
+ const agent = { kind: "agent_of_human", name: "scribe" } as const;
25
+
26
+ const doc = AgenticDoc.fromMarkdown("# Plan\n\nShip on Friday.", agent);
27
+ const [plan] = doc.outline();
28
+
29
+ doc.replace({ text: "Friday" }, "Monday", agent);
30
+ doc.insert({ section: plan.id, at: "end" }, "- [ ] Write notes", agent);
31
+
32
+ console.log(doc.toMarkdown());
33
+ console.log(doc.edits()); // each edit keeps the author kind and name
34
+
35
+ const person = { kind: "human", name: "Ada" } as const;
36
+ const suggestions = new Suggestions(doc);
37
+ const id = suggestions.add({ text: "Monday" }, "Tuesday", agent);
38
+ suggestions.accept(id, person); // the text changes now
39
+ new Threads(doc).add({ text: "Tuesday" }, "Is this date firm?", agent);
40
+ ```
41
+
42
+ ## CLI
43
+
44
+ Every change needs an author: `--as <kind>:<name>` or `AGENTIC_DOCS_AS`. An agent that may accept
45
+ suggestions also needs `--scopes docs:accept` (or `AGENTIC_DOCS_SCOPES`). Documents live in
46
+ `--dir` (or `AGENTIC_DOCS_DIR`, default `.agentic-documents`) as Yjs update files.
47
+
48
+ ```sh
49
+ export AGENTIC_DOCS_AS=agent_of_human:scribe
50
+ printf '# Plan\n\nShip on Friday.\n' > plan.md
51
+ npx agentic-documents new plan --file plan.md
52
+ npx agentic-documents outline plan
53
+ npx agentic-documents replace plan --text Friday --content Monday
54
+ npx agentic-documents suggest plan --text Monday --replacement Tuesday
55
+ npx agentic-documents comment plan --text Monday --body "Is this date firm?"
56
+ npx agentic-documents export plan --format md --out plan.md
57
+ npx agentic-documents export plan --format odt --out plan.odt # OpenDocument text
58
+ ```
59
+
60
+ Run `npx agentic-documents --help` for every command.
61
+
62
+ ## MCP
63
+
64
+ `npx agentic-documents mcp --as agent_of_human:claude` starts a stdio server. It has one tool
65
+ per command, named `doc_<command>` (`doc_read`, `doc_replace`, `doc_suggest`, and so on). The
66
+ author is fixed when the server starts. A tool call cannot pick another author.
67
+
68
+ ## HTTP API
69
+
70
+ A Cloudflare Worker (Hono) mirrors the CLI one to one under `/api/v1/docs`. A read command is a
71
+ `GET` (flags are query parameters). A write command is a `POST` (flags are the JSON body).
72
+
73
+ ```sh
74
+ curl -X POST $URL/api/v1/docs -H "authorization: Bearer $TOKEN" -d '{"id":"plan","markdown":"# Plan"}'
75
+ curl "$URL/api/v1/docs/plan/outline" -H "authorization: Bearer $TOKEN"
76
+ curl -X POST $URL/api/v1/docs/plan/replace -H "authorization: Bearer $TOKEN" -d '{"text":"Plan","content":"Roadmap"}'
77
+ curl "$URL/api/v1/docs/plan/export?format=html" -H "authorization: Bearer $TOKEN"
78
+ # add &remoteImages=true to keep web images; the default shows only images stored inside the document
79
+ ```
80
+
81
+ - Each token stands for one author. Set `AGENTIC_DOCS_TOKENS` as a secret:
82
+ `wrangler secret put AGENTIC_DOCS_TOKENS`. The value is a JSON object from token to author:
83
+ `{"<32 or more random bytes>":"agent_of_human:scribe"}`. To give an agent the right to accept
84
+ suggestions, use `{"as":"agent_of_human:approver","scopes":["docs:accept"]}` as the value.
85
+ Make a token with `openssl rand -hex 32`.
86
+ - A token under 32 bytes, a value that is not a valid author, or a value that is not a JSON
87
+ object makes the Worker refuse every request (401). It logs the reason once, never the token.
88
+ A body cannot name its own author. With no tokens the API refuses every request.
89
+ - Errors are `{ "error": { "code", "message", "matches" } }`. Status: 400 bad input, 401 no
90
+ valid token, 403 `FORBIDDEN` (for example an agent without `docs:accept` that accepts), 404 not
91
+ found, 409 a conflict (ambiguous match, stale anchor, already decided), 503 `LOCKED`.
92
+ - `GET /health` needs no token. It reveals nothing else.
93
+ - Create an R2 bucket with `wrangler r2 bucket create agentic-documents-data --jurisdiction eu` and a D1
94
+ database with `wrangler d1 create agentic-documents --jurisdiction eu`. Put the database id in
95
+ `wrangler.jsonc`. Set `AGENTIC_DOCS_REGION` to `eu` or `us`. It is a claim that you make: it has no
96
+ default, and the Worker answers 500 `MISCONFIGURED` without it. Local D1 reports no region, so under
97
+ `wrangler dev` only, add `--var AGENTIC_DOCS_REGION:unknown --var AGENTIC_DOCS_UNSAFE_REGION:1`. That turns the
98
+ residency check off.
99
+ - Run it locally with `npx wrangler dev`. Set `WRANGLER_SEND_METRICS=false` to turn off wrangler telemetry.
100
+
101
+ ## Features
102
+
103
+ - A Yjs document that a Tiptap editor can open. It uses the y-prosemirror layout.
104
+ - Headings, paragraphs, lists, task lists, tables, code, images, links, and marks.
105
+ - Markdown in and out.
106
+ - An outline. Each section has an id that stays the same when people edit around it. Blocks before the
107
+ first heading are the `preamble` section (level 0). It is listed when they exist, and it is always a
108
+ valid target. A replace or delete on it has no heading to keep.
109
+ - Insert, replace, and delete by section id or by exact text. Append to the end.
110
+ - Text anchors that follow their text when other replicas edit.
111
+ - Clear errors: `NO_MATCH`, `AMBIGUOUS_MATCH`, `STALE_ANCHOR`, `NO_SECTION`, `FORBIDDEN`.
112
+ - Comment threads on text, with replies and resolve. A thread follows its text.
113
+ - Suggested edits (insert, replace, delete). Nothing changes until a person accepts.
114
+ An accepted edit is logged with the accepter as editor and the suggester as origin.
115
+ - Who may decide: a `human` or a `user_token` who is not the suggester. An agent cannot accept
116
+ unless its principal carries the `docs:accept` scope. Nobody accepts their own suggestion.
117
+ A person can withdraw their own suggestion. An agent can never accept or reject its own. Other
118
+ deciders get `FORBIDDEN`. Accepting an accepted
119
+ suggestion changes nothing. Editor roles come with `agentic-identity`.
120
+ - Two replicas can accept one suggestion before they meet. After the merge every replica keeps
121
+ one application and undoes the other, so the text and the edit log hold it once. An accept
122
+ beats a reject made at the same moment.
123
+ - Export to ODT (OpenDocument text): headings, paragraphs, bold, italic, strike, code, links, lists,
124
+ quotes, rules, tables, and images as embedded files. The package follows ODF 1.3 with the mimetype
125
+ stored first. The CLI and the API send the file bytes. LibreOffice opens it, lists keep their
126
+ numbers, and its own re-save reads back to the same Markdown (checked by hand with LibreOffice 24.8
127
+ in the PR that added it).
128
+ - Export to Markdown and to self-contained HTML. The HTML loads nothing from other hosts. An image
129
+ stored in the document as a `data:` URI (PNG, JPEG, GIF, or WebP) shows. Any other image becomes
130
+ its alt text, because a remote image tells its host who opened the file. `remoteImages` turns
131
+ that back on.
132
+ - Every edit, message, and suggestion needs an author. The edit log keeps the kind and the name, so
133
+ agent work stays labeled. The log holds no content.
134
+
135
+ ## Rules for text matching
136
+
137
+ - A match is exact and case sensitive.
138
+ - A match stays inside one block. It cannot cross a paragraph, a cell, or a hard break.
139
+ - More than one match is an error, and matches may overlap: `ana` matches twice in `banana`. Pass `occurrence` (1 is the first start) to choose.
140
+ - A replacement takes the marks of the first matched character.
141
+
142
+ ## Limits
143
+
144
+ - No web UI yet.
145
+ - The Worker keeps each document in R2 and a catalog (who made it, and when) in D1. Both come from the
146
+ shared `agentic-identity` ports. A save is conditional on the version it read, so two writers cannot
147
+ overwrite each other. The CLI and MCP server keep the same data in local files.
148
+ - The CLI and MCP server keep files under `<dir>/blobs` and `<dir>/store`. Files from an older release that sit
149
+ directly in `<dir>` are not read.
150
+ - Token auth is a stopgap until the `Auth` port exists. There is no per-document sharing or role yet.
151
+ - A save is a compare-and-set. The file store takes a lock file, checks the version, and renames a
152
+ uniquely named temp file into place. A writer that loses loads the document again and runs
153
+ its change again. A lock older than 10 seconds counts as dead and is taken over. A lock that
154
+ cannot be read, or that is dated in the future, counts as live. A writer that waits more than
155
+ 5 seconds fails with `LOCKED`. A writer that loses 64 times in a row fails with `CONFLICT`. The lock
156
+ is for one machine. Two machines on a network file system need a store with its own
157
+ conditional write.
158
+ - `--as` and `AGENTIC_DOCS_AS` are self-declared labels. The CLI does not prove who runs it, so
159
+ `--as human:Ada` labels work as human on any machine that can run the command. Only the HTTP API
160
+ (tokens) and an MCP server that a trusted host starts fix the author for the caller.
161
+ - Suggestions work on text, not on whole sections.
162
+ - A scope on a principal is trusted as given. Nothing here proves who a caller is.
163
+ - Export covers Markdown, HTML, and ODT. DOCX export, and ODT and DOCX import, are planned.
164
+ - ODT export: comments and suggestions are not written. A code block loses its language. A table
165
+ cell span is not written (the model has none yet). A task list becomes a bullet list that starts each
166
+ item with `☐` or `☑`. A remote image is not linked, because an office program would ask its host
167
+ for it when the file opens. It becomes its alt text.
168
+ - Markdown with footnotes, or any syntax the model has no place for, is refused with
169
+ `INVALID_INPUT`. Nothing is stored. Reference links and image references are resolved to
170
+ their URL. An unused reference definition is dropped.
171
+ - Markdown import drops link titles, table column alignment, and the part of a code fence
172
+ line after the language.
173
+ - Markdown output trims whitespace at the edge of a block and skips empty paragraphs. A text
174
+ target that includes a trailing space can match in the document and not in `read` output.
175
+
176
+ ## Develop
177
+
178
+ ```sh
179
+ npm ci
180
+ npm run ci:local
181
+ ```
182
+
183
+ ## License
184
+
185
+ MIT.
package/SECURITY.md ADDED
@@ -0,0 +1,23 @@
1
+ # Security policy
2
+
3
+ ## Report a vulnerability
4
+
5
+ Do not open a public issue for a security problem. Report it in private with
6
+ GitHub security advisories:
7
+ https://github.com/pooriaarab/agentic-documents/security/advisories/new
8
+
9
+ Include the version (`npm ls agentic-documents`), the steps to reproduce, and the
10
+ impact you expect. We aim to reply within 7 days.
11
+
12
+ ## Supported versions
13
+
14
+ Only the latest published version gets fixes.
15
+
16
+ ## Scope
17
+
18
+ In scope: the package code (the SDK, CLI, MCP server, and Worker API) and the
19
+ export formats it writes.
20
+
21
+ Out of scope: a deployment that sets its own tokens or region without following
22
+ the README, and a self-declared `--as` label on the CLI. The README says that
23
+ label is not proof of identity.
package/SKILL.md ADDED
@@ -0,0 +1,35 @@
1
+ ---
2
+ name: agentic-documents
3
+ description: Read and edit rich-text documents by section or exact text, as Markdown, with every edit labeled by author. Keywords: documents,editor,rich-text,tiptap,yjs,agents.
4
+ ---
5
+
6
+ # agentic-documents
7
+
8
+ Write documents with people and agents in real time.
9
+
10
+ ## Use the SDK
11
+
12
+ ```ts
13
+ import { AgenticDoc } from "agentic-documents";
14
+
15
+ const me = { kind: "agent_of_human", name: "scribe" } as const;
16
+ const doc = AgenticDoc.fromMarkdown("# Plan\n\nShip on Friday.", me);
17
+ doc.replace({ text: "Friday" }, "Monday", me);
18
+ doc.toMarkdown();
19
+ ```
20
+
21
+ ## Use the CLI or MCP
22
+
23
+ ```sh
24
+ agentic-documents outline plan --as agent_of_human:scribe
25
+ agentic-documents mcp --as agent_of_human:scribe
26
+ ```
27
+
28
+ Tools are named `doc_<command>`: `doc_read`, `doc_outline`, `doc_replace`, `doc_suggest`.
29
+
30
+ ## Rules
31
+
32
+ - Pass your author kind and name on every change.
33
+ - Read the outline, then the section, before you edit.
34
+ - On an ambiguous match, pass `occurrence`.
35
+ - Report errors as failures.