# vscode-cowriting-plugin Non-shippable **proof-of-concept** (Feature #2 of Epic #1): a standalone VS Code extension that drives **[`@cline/sdk`](https://www.npmjs.com/package/@cline/sdk)** — validating Approach A (own coauthoring extension on the Cline SDK, no fork). ## What it does Registers one command, **`Cowriting: Show Cline SDK Info`**, which loads `@cline/sdk` and shows the SDK build version plus the agent's builtin tool catalog (a pure, key-free SDK call) in a notification and the "Cowriting (Cline SDK)" output channel. Features shipped so far: F2 region-anchored threads (Feature #4), F3 live human/Claude attribution (Feature #6). ## Architecture - CommonJS extension bundled with esbuild (`src/extension.ts` → `out/extension.cjs`). - `@cline/sdk` is ESM-only (Node ≥22) and uses `createRequire(import.meta.url)`, so it is **not** bundled — it is shipped in `node_modules` and loaded at runtime via dynamic `import()` from the vscode-free `src/cline.ts`. ## Run it (F5) 1. `npm install` 2. `npm run build` 3. Press **F5** (or Run → "Run Extension") to launch the Extension Development Host. 4. In the new window: **Cmd/Ctrl+Shift+P** → **"Cowriting: Show Cline SDK Info"**. ## F2 — Region-anchored threads (Feature #4) Attach durable, region-anchored discussion threads to any document. Threads render in the native VS Code **Comments** gutter and persist as git-native sidecars under `.threads/.json` (plain, diffable JSON — no server). - **Create:** select text → run **"Cowriting: Add Coauthoring Thread on Selection"** (or the Comments gutter "+"). - **Reply / Resolve:** use the native Comments reply box and the thread's Resolve/Reopen actions. - **Survives edits, reload, and external change (`git pull`):** a hybrid anchor (durable content fingerprint + live offset tracking) re-resolves the thread. If the anchored text can't be confidently re-found, the thread is shown as **orphaned** at its last-known line — never silently moved. Design: `vscode-cowriting-plugin-content/specs/coauthoring-inner-loop.md`. No live `@cline/sdk` turn and no credentials are involved in F2. ## F3 — Live human/Claude attribution (Feature #6) As you and Claude coauthor, every span in the buffer carries an author: human edits render with a subtle left border, Claude-authored spans with a background tint. Text that predates tracking stays plain — the honest record. Edits that touch a boundary (split, merge, partial overwrite) are handled char-precisely. Attribution is persisted git-natively in the same `.threads/` sidecars (`attributions[]`, sharing the same `anchors` fingerprints as F2 threads). On reload, fingerprints re-resolve spans against the current document; spans that can't be confidently re-found are **orphaned** (status-bar count + "Cowriting Attribution" output channel) rather than silently moved or discarded. **Commands** - **`Cowriting: Ask Claude to Edit Selection`** — select text → enter an instruction → a live `@cline/sdk` turn runs on the built-in `claude-code` provider (rides your local Claude Code Pro/Max login; the extension stores no credentials). The replacement lands in the buffer as a Claude-attributed span. - **`Cowriting: Toggle Attribution`** — show/hide attribution decorations. - `cowriting.applyAgentEdit` _(palette-hidden)_ — the single machine-edit ingress seam. Tests drive this directly so CI requires no LLM. Design: `vscode-cowriting-plugin-content/specs/coauthoring-attribution.md`. ## Develop - `npm run watch` — rebuild on change. - `npx vitest run` — unit suite (SDK driver, schema, store, anchorer, thread mutations, attribution split/merge). - `npm run test:e2e` — `@vscode/test-electron` host E2E (create → reply → resolve → persist → reload → re-anchor → orphan; drives `cowriting.applyAgentEdit` directly — no LLM required). - `npm run smoke:live` — scripted live-turn smoke test for F3; requires Claude Code installed and signed in. See [`docs/MANUAL-SMOKE-F3.md`](docs/MANUAL-SMOKE-F3.md). - `npm run typecheck` — type-check without emit.