@filipc77/cowrite 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 Cowrite Contributors
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 ADDED
@@ -0,0 +1,202 @@
1
+ # Cowrite
2
+
3
+ Live commenting plugin for coding agent sessions. Select text in a browser preview, leave comments, and your coding agent receives them in real time via MCP.
4
+
5
+ **The problem:** When working with AI coding agents, there's no way to give inline, contextual feedback on specific parts of a file while the agent is working. You either interrupt with a chat message (losing spatial context) or wait until the agent is done.
6
+
7
+ **The solution:** Cowrite opens a live preview of any text file where you can select text and leave comments. The comments propagate directly into the agent session via MCP tools — so the agent can act on your feedback immediately.
8
+
9
+ ## How it works
10
+
11
+ ```
12
+ Browser (Preview UI) Node.js Process Claude Code
13
+ ┌─────────────────┐ ┌──────────────────────┐ ┌──────────────┐
14
+ │ File preview │ │ HTTP + WebSocket │ │ │
15
+ │ Text selection │◄───►│ server (port 3377) │ │ MCP tools: │
16
+ │ Comment creation │ │ │ │ │
17
+ │ Comment sidebar │ │ ┌────────────────┐ │ │ get_pending │
18
+ └─────────────────┘ │ │ CommentStore │ │ │ resolve │
19
+ │ │ (shared memory)│ │ │ reply │
20
+ │ └───────┬────────┘ │ │ get_annotated│
21
+ │ │ │ │ │
22
+ │ ┌───────▼────────┐ │ │ │
23
+ │ │ MCP Server │◄─╋────►│ │
24
+ │ │ (stdio) │ │ │ │
25
+ │ └────────────────┘ │ └──────────────┘
26
+ │ │
27
+ │ File Watcher │
28
+ └──────────────────────┘
29
+ ```
30
+
31
+ A single Node.js process runs both the HTTP/WebSocket preview server and the MCP stdio server, sharing one in-memory comment store.
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ npm install -g cowrite
37
+ ```
38
+
39
+ Or use directly with `npx`:
40
+
41
+ ```bash
42
+ npx cowrite preview ./README.md
43
+ ```
44
+
45
+ ## Quick Start
46
+
47
+ ### 1. Add Cowrite as an MCP server in Claude Code
48
+
49
+ ```bash
50
+ # Preview mode — opens browser preview + MCP server on stdio
51
+ claude mcp add cowrite -- npx cowrite preview ./README.md
52
+
53
+ # Or serve mode — MCP only, no preview UI
54
+ claude mcp add cowrite -- npx cowrite serve
55
+ ```
56
+
57
+ ### 2. Open the preview
58
+
59
+ When using preview mode, Cowrite starts an HTTP server at `http://localhost:3377`. Open it in your browser.
60
+
61
+ ### 3. Select text and comment
62
+
63
+ Select any text in the preview and click the comment button that appears. Write your feedback and submit.
64
+
65
+ ### 4. The agent sees your comments
66
+
67
+ The agent can use these MCP tools to read and respond to your comments:
68
+
69
+ - `get_pending_comments` — retrieve unresolved comments
70
+ - `resolve_comment` — mark a comment as addressed
71
+ - `reply_to_comment` — send a reply visible in the browser
72
+ - `get_file_with_annotations` — see the file with inline comment markers
73
+
74
+ ## CLI Reference
75
+
76
+ ```
77
+ cowrite preview <file> [--port N] Open browser preview + start MCP server
78
+ cowrite serve MCP-only mode (stdio, no preview)
79
+
80
+ Options:
81
+ --port, -p Port for preview server (default: 3377)
82
+ --help, -h Show help
83
+ ```
84
+
85
+ ## MCP Tools
86
+
87
+ ### `get_pending_comments`
88
+
89
+ Returns unresolved comments from the live preview.
90
+
91
+ | Parameter | Type | Default | Description |
92
+ |-----------|------|---------|-------------|
93
+ | `file` | string | — | Filter by file path (optional) |
94
+ | `status` | `"pending"` \| `"resolved"` \| `"all"` | `"pending"` | Filter by status |
95
+
96
+ ### `resolve_comment`
97
+
98
+ Marks a comment as addressed. The browser UI updates to show the resolved state.
99
+
100
+ | Parameter | Type | Description |
101
+ |-----------|------|-------------|
102
+ | `commentId` | string | The comment ID to resolve |
103
+
104
+ ### `reply_to_comment`
105
+
106
+ Sends a reply from the agent, visible in the browser comment sidebar.
107
+
108
+ | Parameter | Type | Description |
109
+ |-----------|------|-------------|
110
+ | `commentId` | string | The comment ID to reply to |
111
+ | `reply` | string | The reply text |
112
+
113
+ ### `get_file_with_annotations`
114
+
115
+ Returns the file content with inline comment markers at the positions where comments are anchored:
116
+
117
+ ```
118
+ Hello world, this is a test. [COMMENT #a1b2c3d4: "Should be uppercase"]
119
+ ```
120
+
121
+ | Parameter | Type | Description |
122
+ |-----------|------|-------------|
123
+ | `file` | string | File path to annotate |
124
+
125
+ ## MCP Resources
126
+
127
+ | URI | Description |
128
+ |-----|-------------|
129
+ | `cowrite://comments` | Live list of all comments (subscribable) |
130
+
131
+ ## Features
132
+
133
+ - **Live file watching** — Edit the file externally and the preview updates instantly. Comments re-anchor to their selected text automatically.
134
+ - **Markdown rendering** — `.md` files are rendered as formatted HTML. All other text files display with syntax-preserved plain text.
135
+ - **Persistent comments** — Comments are saved to `.cowrite-comments.json` in the project directory and survive restarts.
136
+ - **Offset-based anchoring** — Comments are anchored by character offset and selected text, not line numbers. When the file changes, Cowrite searches for the selected text near the original offset to re-anchor.
137
+ - **Agent replies** — The agent can reply to comments, and replies appear in the browser sidebar in real time.
138
+
139
+ ## Using the `/review` Skill
140
+
141
+ Cowrite ships with a built-in skill. When working in Claude Code with Cowrite active, you can use:
142
+
143
+ ```
144
+ /review
145
+ ```
146
+
147
+ This instructs the agent to check all pending comments, address them, reply, and resolve each one.
148
+
149
+ ## Development
150
+
151
+ ```bash
152
+ git clone https://github.com/your-username/cowrite.git
153
+ cd cowrite
154
+ npm install
155
+
156
+ # Run in dev mode (uses tsx for live TS execution)
157
+ npm run dev -- preview ./README.md
158
+
159
+ # Run tests
160
+ npm test
161
+
162
+ # Type-check
163
+ npm run lint
164
+
165
+ # Build for distribution
166
+ npm run build
167
+ ```
168
+
169
+ ## Project Structure
170
+
171
+ ```
172
+ cowrite/
173
+ ├── bin/cowrite.ts # CLI entry point
174
+ ├── src/
175
+ │ ├── types.ts # TypeScript interfaces
176
+ │ ├── comment-store.ts # In-memory comment store with persistence
177
+ │ ├── mcp-server.ts # MCP tools and resources
178
+ │ ├── preview-server.ts # HTTP + WebSocket server
179
+ │ ├── file-watcher.ts # File change detection
180
+ │ └── utils.ts # Markdown rendering, annotation
181
+ ├── ui/
182
+ │ ├── index.html # Browser preview app
183
+ │ ├── styles.css # Dark theme styles
184
+ │ └── client.js # Selection handling, WebSocket client
185
+ ├── skills/review/SKILL.md # Agent skill for reviewing comments
186
+ └── test/ # Vitest tests
187
+ ```
188
+
189
+ ## How Comments Flow
190
+
191
+ 1. You select text in the browser and submit a comment
192
+ 2. The browser sends a WebSocket message to the server
193
+ 3. The server adds the comment to the shared `CommentStore`
194
+ 4. The store emits a `"change"` event
195
+ 5. The MCP server sends a `notifications/resources/updated` notification
196
+ 6. The agent calls `get_pending_comments` to retrieve the comment
197
+ 7. The agent makes changes, then calls `resolve_comment`
198
+ 8. The browser receives the update via WebSocket and shows the resolved state
199
+
200
+ ## License
201
+
202
+ MIT