@filipc77/cowrite 0.3.0 → 0.4.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/dist/bin/cowrite.js +43 -9
- package/dist/bin/cowrite.js.map +1 -1
- package/package.json +1 -1
- package/ui/client.js +6 -3
- package/ui/index.html +30 -13
- package/ui/styles.css +306 -143
package/dist/bin/cowrite.js
CHANGED
|
@@ -213,9 +213,9 @@ function createMcpServer(store, projectDir) {
|
|
|
213
213
|
{ name: "cowrite", version: "0.1.0" },
|
|
214
214
|
{ capabilities: { logging: {} } }
|
|
215
215
|
);
|
|
216
|
-
server.tool(
|
|
216
|
+
const getPendingTool = server.tool(
|
|
217
217
|
"get_pending_comments",
|
|
218
|
-
"Get comments from the live preview.
|
|
218
|
+
"Get comments from the live preview (0 pending). Call this first to catch comments posted before you started listening.",
|
|
219
219
|
{
|
|
220
220
|
file: z.string().optional().describe("Filter by file path"),
|
|
221
221
|
status: z.enum(["pending", "resolved", "all"]).optional().describe("Filter by status (default: pending)")
|
|
@@ -299,7 +299,7 @@ function createMcpServer(store, projectDir) {
|
|
|
299
299
|
);
|
|
300
300
|
server.tool(
|
|
301
301
|
"wait_for_comment",
|
|
302
|
-
"Block until a new comment is posted in the live preview, then return it.
|
|
302
|
+
"Block until a new comment is posted in the live preview, then return it. This is the primary way to receive real-time comments \u2014 call it again after handling each comment to keep listening.",
|
|
303
303
|
{
|
|
304
304
|
timeout: z.number().optional().describe("Max seconds to wait (default: 120)")
|
|
305
305
|
},
|
|
@@ -354,14 +354,48 @@ function createMcpServer(store, projectDir) {
|
|
|
354
354
|
}).catch(() => {
|
|
355
355
|
});
|
|
356
356
|
});
|
|
357
|
-
store.on("new_comment", (
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
357
|
+
store.on("new_comment", () => {
|
|
358
|
+
const count = store.getAll({ status: "pending" }).length;
|
|
359
|
+
getPendingTool.update({
|
|
360
|
+
description: `Get comments from the live preview (${count} pending). Call this first to catch comments posted before you started listening.`
|
|
361
|
+
});
|
|
362
|
+
server.sendToolListChanged();
|
|
363
|
+
});
|
|
364
|
+
store.on("change", () => {
|
|
365
|
+
const count = store.getAll({ status: "pending" }).length;
|
|
366
|
+
getPendingTool.update({
|
|
367
|
+
description: `Get comments from the live preview (${count} pending). Call this first to catch comments posted before you started listening.`
|
|
363
368
|
});
|
|
364
369
|
});
|
|
370
|
+
server.prompt(
|
|
371
|
+
"cowrite-workflow",
|
|
372
|
+
"How to process live preview comments in a wait-handle-resolve loop",
|
|
373
|
+
() => ({
|
|
374
|
+
messages: [
|
|
375
|
+
{
|
|
376
|
+
role: "user",
|
|
377
|
+
content: {
|
|
378
|
+
type: "text",
|
|
379
|
+
text: [
|
|
380
|
+
"You are monitoring a live code preview where users leave comments on selected text.",
|
|
381
|
+
"",
|
|
382
|
+
"Follow this loop:",
|
|
383
|
+
"1. Call `get_pending_comments` to check for any comments already posted.",
|
|
384
|
+
"2. Process each pending comment: read the file, make the requested change or reply, then call `resolve_comment`.",
|
|
385
|
+
"3. Call `wait_for_comment` to block until the next comment arrives.",
|
|
386
|
+
"4. When a comment arrives, process it the same way (step 2).",
|
|
387
|
+
"5. Go back to step 3 and keep listening.",
|
|
388
|
+
"",
|
|
389
|
+
"Tips:",
|
|
390
|
+
"- Use `get_file_with_annotations` to see comments in context within the file.",
|
|
391
|
+
"- Use `reply_to_comment` to acknowledge or ask clarifying questions.",
|
|
392
|
+
"- Always `resolve_comment` after addressing feedback."
|
|
393
|
+
].join("\n")
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
]
|
|
397
|
+
})
|
|
398
|
+
);
|
|
365
399
|
return server;
|
|
366
400
|
}
|
|
367
401
|
|
package/dist/bin/cowrite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../bin/cowrite.ts","../../src/comment-store.ts","../../src/mcp-server.ts","../../src/utils.ts","../../src/preview-server.ts","../../src/file-watcher.ts"],"sourcesContent":["import { parseArgs } from \"node:util\";\nimport { resolve } from \"node:path\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport { CommentStore } from \"../src/comment-store.js\";\nimport { createMcpServer } from \"../src/mcp-server.js\";\nimport { createPreviewServer } from \"../src/preview-server.js\";\n\nconst USAGE = `\ncowrite — Live commenting plugin for coding agent sessions\n\nUsage:\n cowrite preview <file> [--port N] Open browser preview for a specific file + start MCP server\n cowrite serve [--port N] Start MCP server + preview server (browse any file)\n\nOptions:\n --port, -p Port for preview server (default: 3377)\n --help, -h Show this help\n`;\n\nfunction setupShutdown(store: CommentStore, preview: { stop: () => Promise<void> }) {\n let shuttingDown = false;\n const shutdown = () => {\n if (shuttingDown) {\n // Second signal — force exit immediately\n process.exit(1);\n }\n shuttingDown = true;\n process.stderr.write(\"Shutting down...\\n\");\n // Best-effort cleanup with a hard timeout\n Promise.allSettled([store.stopWatching(), preview.stop()])\n .finally(() => process.exit(0));\n setTimeout(() => process.exit(0), 2000);\n };\n process.on(\"SIGINT\", shutdown);\n process.on(\"SIGTERM\", shutdown);\n}\n\nasync function main() {\n const { values, positionals } = parseArgs({\n args: process.argv.slice(2),\n options: {\n port: { type: \"string\", short: \"p\", default: \"3377\" },\n help: { type: \"boolean\", short: \"h\", default: false },\n },\n allowPositionals: true,\n strict: false,\n });\n\n if (values.help || positionals.length === 0) {\n process.stderr.write(USAGE);\n process.exit(positionals.length === 0 && !values.help ? 1 : 0);\n }\n\n const command = positionals[0];\n const projectDir = process.cwd();\n const port = parseInt(values.port as string, 10);\n\n if (command === \"serve\") {\n const store = new CommentStore(projectDir);\n await store.load();\n await store.startWatching();\n\n // Start preview server (no initial file — user picks from browser)\n const preview = createPreviewServer(store, projectDir, port);\n await preview.start();\n\n // Start MCP server on stdio\n const mcpServer = createMcpServer(store, projectDir);\n const transport = new StdioServerTransport();\n await mcpServer.connect(transport);\n\n process.stderr.write(`Cowrite MCP server running on stdio\\n`);\n process.stderr.write(`Preview: http://localhost:${port}\\n`);\n\n setupShutdown(store, preview);\n } else if (command === \"preview\") {\n const filePath = positionals[1];\n if (!filePath) {\n process.stderr.write(\"Error: preview command requires a file path\\n\");\n process.stderr.write(USAGE);\n process.exit(1);\n }\n\n const resolvedFile = resolve(projectDir, filePath);\n\n const store = new CommentStore(projectDir);\n await store.load();\n await store.startWatching();\n\n // Start preview server with initial file\n const preview = createPreviewServer(store, projectDir, port, resolvedFile);\n await preview.start();\n\n // Start MCP server on stdio\n const mcpServer = createMcpServer(store, projectDir);\n const transport = new StdioServerTransport();\n await mcpServer.connect(transport);\n\n process.stderr.write(`Cowrite MCP server running on stdio\\n`);\n process.stderr.write(`Preview: http://localhost:${port}\\n`);\n\n setupShutdown(store, preview);\n } else {\n process.stderr.write(`Unknown command: ${command}\\n`);\n process.stderr.write(USAGE);\n process.exit(1);\n }\n}\n\nmain().catch((err) => {\n process.stderr.write(`Fatal error: ${err}\\n`);\n process.exit(1);\n});\n","import { EventEmitter } from \"node:events\";\nimport { readFile, writeFile } from \"node:fs/promises\";\nimport { join, resolve } from \"node:path\";\nimport { randomUUID } from \"node:crypto\";\nimport { watch as chokidarWatch, type FSWatcher } from \"chokidar\";\nimport type { Comment, Reply } from \"./types.js\";\n\nconst PERSIST_FILE = \".cowrite-comments.json\";\n\nexport class CommentStore extends EventEmitter {\n private comments: Map<string, Comment> = new Map();\n private persistPath: string;\n private lastWriteTime = 0;\n private watcher: FSWatcher | null = null;\n\n constructor(projectDir: string) {\n super();\n this.persistPath = join(resolve(projectDir), PERSIST_FILE);\n }\n\n async load(): Promise<void> {\n try {\n const data = await readFile(this.persistPath, \"utf-8\");\n const arr: Comment[] = JSON.parse(data);\n for (const c of arr) {\n this.comments.set(c.id, c);\n }\n } catch {\n // No existing file, start fresh\n }\n }\n\n private async persist(): Promise<void> {\n this.lastWriteTime = Date.now();\n const arr = Array.from(this.comments.values());\n await writeFile(this.persistPath, JSON.stringify(arr, null, 2), \"utf-8\");\n }\n\n async reload(): Promise<void> {\n try {\n const data = await readFile(this.persistPath, \"utf-8\");\n const arr: Comment[] = JSON.parse(data);\n const oldIds = new Set(this.comments.keys());\n this.comments.clear();\n for (const c of arr) {\n this.comments.set(c.id, c);\n }\n // Emit \"new_comment\" for comments that didn't exist before\n for (const c of arr) {\n if (!oldIds.has(c.id)) {\n this.emit(\"new_comment\", c);\n }\n }\n this.emit(\"change\", null);\n } catch {\n // File missing or invalid, clear state\n this.comments.clear();\n this.emit(\"change\", null);\n }\n }\n\n async startWatching(): Promise<void> {\n if (this.watcher) return;\n this.watcher = chokidarWatch(this.persistPath, {\n ignoreInitial: true,\n awaitWriteFinish: { stabilityThreshold: 100, pollInterval: 50 },\n });\n this.watcher.on(\"change\", async () => {\n if (Date.now() - this.lastWriteTime < 200) return;\n await this.reload();\n });\n this.watcher.on(\"add\", async () => {\n if (Date.now() - this.lastWriteTime < 200) return;\n await this.reload();\n });\n }\n\n async stopWatching(): Promise<void> {\n if (this.watcher) {\n await this.watcher.close();\n this.watcher = null;\n }\n }\n\n add(params: {\n file: string;\n offset: number;\n length: number;\n selectedText: string;\n comment: string;\n }): Comment {\n const comment: Comment = {\n id: randomUUID(),\n file: params.file,\n offset: params.offset,\n length: params.length,\n selectedText: params.selectedText,\n comment: params.comment,\n status: \"pending\",\n replies: [],\n createdAt: new Date().toISOString(),\n resolvedAt: null,\n };\n this.comments.set(comment.id, comment);\n this.emit(\"change\", comment);\n this.emit(\"new_comment\", comment);\n this.persist().catch((err) => process.stderr.write(`Persist error: ${err}\\n`));\n return comment;\n }\n\n resolve(commentId: string): Comment | null {\n const comment = this.comments.get(commentId);\n if (!comment) return null;\n comment.status = \"resolved\";\n comment.resolvedAt = new Date().toISOString();\n this.emit(\"change\", comment);\n this.persist().catch((err) => process.stderr.write(`Persist error: ${err}\\n`));\n return comment;\n }\n\n addReply(commentId: string, from: \"user\" | \"agent\", text: string): Reply | null {\n const comment = this.comments.get(commentId);\n if (!comment) return null;\n const reply: Reply = {\n id: randomUUID(),\n from,\n text,\n createdAt: new Date().toISOString(),\n };\n comment.replies.push(reply);\n this.emit(\"change\", comment);\n this.persist().catch((err) => process.stderr.write(`Persist error: ${err}\\n`));\n return reply;\n }\n\n get(commentId: string): Comment | null {\n return this.comments.get(commentId) ?? null;\n }\n\n getAll(filter?: { file?: string; status?: \"pending\" | \"resolved\" | \"all\" }): Comment[] {\n let results = Array.from(this.comments.values());\n if (filter?.file) {\n results = results.filter((c) => c.file === filter.file);\n }\n if (filter?.status && filter.status !== \"all\") {\n results = results.filter((c) => c.status === filter.status);\n }\n return results.sort((a, b) => a.offset - b.offset);\n }\n\n getForFile(file: string): Comment[] {\n return this.getAll({ file });\n }\n\n /** Adjust comment offsets when file content changes */\n adjustOffsets(file: string, oldContent: string, newContent: string): void {\n const fileComments = this.getForFile(file);\n if (fileComments.length === 0) return;\n\n for (const comment of fileComments) {\n // Try to find the selected text in the new content near original offset\n const searchStart = Math.max(0, comment.offset - 200);\n const searchEnd = Math.min(newContent.length, comment.offset + comment.length + 200);\n const searchRegion = newContent.slice(searchStart, searchEnd);\n const idx = searchRegion.indexOf(comment.selectedText);\n if (idx !== -1) {\n comment.offset = searchStart + idx;\n }\n // If not found, leave offset as-is (orphaned comment)\n }\n\n this.emit(\"change\", null);\n this.persist().catch((err) => process.stderr.write(`Persist error: ${err}\\n`));\n }\n\n clear(): void {\n this.comments.clear();\n this.emit(\"change\", null);\n this.persist().catch((err) => process.stderr.write(`Persist error: ${err}\\n`));\n }\n}\n","import { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport type { CommentStore } from \"./comment-store.js\";\nimport { annotateFileWithComments } from \"./utils.js\";\nimport { readFile } from \"node:fs/promises\";\nimport { relative, resolve } from \"node:path\";\n\nexport function createMcpServer(store: CommentStore, projectDir: string): McpServer {\n const server = new McpServer(\n { name: \"cowrite\", version: \"0.1.0\" },\n { capabilities: { logging: {} } },\n );\n\n // Tool: get_pending_comments\n server.tool(\n \"get_pending_comments\",\n \"Get comments from the live preview. Returns unresolved comments by default.\",\n {\n file: z.string().optional().describe(\"Filter by file path\"),\n status: z.enum([\"pending\", \"resolved\", \"all\"]).optional().describe(\"Filter by status (default: pending)\"),\n },\n async ({ file, status }) => {\n const filter: { file?: string; status?: \"pending\" | \"resolved\" | \"all\" } = {};\n if (file) filter.file = resolve(projectDir, file);\n filter.status = status ?? \"pending\";\n const comments = store.getAll(filter);\n return {\n content: [\n {\n type: \"text\" as const,\n text: comments.length === 0\n ? \"No comments found.\"\n : JSON.stringify(comments, null, 2),\n },\n ],\n };\n }\n );\n\n // Tool: resolve_comment\n server.tool(\n \"resolve_comment\",\n \"Mark a comment as resolved/addressed.\",\n {\n commentId: z.string().describe(\"The comment ID to resolve\"),\n },\n async ({ commentId }) => {\n const comment = store.resolve(commentId);\n if (!comment) {\n return {\n content: [{ type: \"text\" as const, text: `Comment ${commentId} not found.` }],\n isError: true,\n };\n }\n return {\n content: [{ type: \"text\" as const, text: `Comment ${commentId} resolved.` }],\n };\n }\n );\n\n // Tool: reply_to_comment\n server.tool(\n \"reply_to_comment\",\n \"Reply to a comment from the agent.\",\n {\n commentId: z.string().describe(\"The comment ID to reply to\"),\n reply: z.string().describe(\"The reply text\"),\n },\n async ({ commentId, reply }) => {\n const replyObj = store.addReply(commentId, \"agent\", reply);\n if (!replyObj) {\n return {\n content: [{ type: \"text\" as const, text: `Comment ${commentId} not found.` }],\n isError: true,\n };\n }\n return {\n content: [{ type: \"text\" as const, text: `Reply added to comment ${commentId}.` }],\n };\n }\n );\n\n // Tool: get_file_with_annotations\n server.tool(\n \"get_file_with_annotations\",\n \"Get file content with inline comment markers showing where comments are anchored.\",\n {\n file: z.string().describe(\"File path to annotate\"),\n },\n async ({ file }) => {\n const filePath = resolve(projectDir, file);\n try {\n const content = await readFile(filePath, \"utf-8\");\n const comments = store.getForFile(filePath);\n const annotated = annotateFileWithComments(content, comments);\n return {\n content: [{ type: \"text\" as const, text: annotated }],\n };\n } catch (err) {\n return {\n content: [{ type: \"text\" as const, text: `Error reading file: ${err}` }],\n isError: true,\n };\n }\n }\n );\n\n // Tool: wait_for_comment\n server.tool(\n \"wait_for_comment\",\n \"Block until a new comment is posted in the live preview, then return it. Call this to listen for incoming user comments in real time.\",\n {\n timeout: z.number().optional().describe(\"Max seconds to wait (default: 120)\"),\n },\n ({ timeout }) => {\n const maxWait = (timeout ?? 120) * 1000;\n return new Promise((resolve) => {\n const timer = setTimeout(() => {\n cleanup();\n resolve({\n content: [{ type: \"text\" as const, text: \"No new comments within timeout.\" }],\n });\n }, maxWait);\n\n const onComment = (comment: { id: string; file: string; selectedText: string; comment: string }) => {\n cleanup();\n const file = relative(projectDir, comment.file);\n resolve({\n content: [{\n type: \"text\" as const,\n text: JSON.stringify({ ...comment, file }, null, 2),\n }],\n });\n };\n\n const cleanup = () => {\n clearTimeout(timer);\n store.off(\"new_comment\", onComment);\n };\n\n store.on(\"new_comment\", onComment);\n });\n }\n );\n\n // Resource: cowrite://comments\n server.resource(\n \"all-comments\",\n \"cowrite://comments\",\n { description: \"Live list of all comments\", mimeType: \"application/json\" },\n async () => {\n const comments = store.getAll();\n return {\n contents: [\n {\n uri: \"cowrite://comments\",\n mimeType: \"application/json\",\n text: JSON.stringify(comments, null, 2),\n },\n ],\n };\n }\n );\n\n // Wire store changes to MCP resource notifications\n store.on(\"change\", () => {\n server.server.notification({\n method: \"notifications/resources/updated\",\n params: { uri: \"cowrite://comments\" },\n }).catch(() => {\n // Notification may fail if client doesn't support it, that's OK\n });\n });\n\n // Notify the agent when a new comment is added\n store.on(\"new_comment\", (comment: { file: string; selectedText: string; comment: string }) => {\n const file = relative(projectDir, comment.file);\n server.sendLoggingMessage({\n level: \"info\",\n data: `New comment on ${file}: \"${comment.comment}\" (on: \"${comment.selectedText}\")`,\n }).catch(() => {});\n });\n\n return server;\n}\n","import { marked } from \"marked\";\nimport type { Comment } from \"./types.js\";\n\n/**\n * Render file content as HTML. Markdown files get full rendering;\n * other text files are wrapped in <pre> with offset-tagged spans.\n */\nexport function renderToHtml(content: string, filePath: string): string {\n const isMarkdown = /\\.(md|markdown|mdx)$/i.test(filePath);\n if (isMarkdown) {\n return renderMarkdownWithOffsets(content);\n }\n return renderPlainTextWithOffsets(content);\n}\n\nfunction renderMarkdownWithOffsets(content: string): string {\n const html = marked.parse(content, { async: false }) as string;\n // Wrap the rendered HTML in a container with data attributes for offset mapping\n // The client-side JS will handle offset computation from the rendered text nodes\n return `<div class=\"markdown-body\" data-source-length=\"${content.length}\">${html}</div>`;\n}\n\nfunction renderPlainTextWithOffsets(content: string): string {\n const lines = content.split(\"\\n\");\n let offset = 0;\n const htmlLines: string[] = [];\n\n for (const line of lines) {\n const escaped = escapeHtml(line);\n htmlLines.push(`<span class=\"line\" data-offset=\"${offset}\" data-length=\"${line.length}\">${escaped}</span>`);\n offset += line.length + 1; // +1 for the newline\n }\n\n return `<pre class=\"plain-text\" data-source-length=\"${content.length}\">${htmlLines.join(\"\\n\")}</pre>`;\n}\n\nfunction escapeHtml(text: string): string {\n return text\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/\"/g, \""\");\n}\n\n/**\n * Annotate file content with inline comment markers for the agent.\n * Inserts `[COMMENT #id: \"text\"]` at the comment offsets.\n */\nexport function annotateFileWithComments(content: string, comments: Comment[]): string {\n // Sort by offset descending so insertions don't shift earlier offsets\n const sorted = [...comments].sort((a, b) => b.offset - a.offset);\n let result = content;\n\n for (const c of sorted) {\n const marker = `[COMMENT #${c.id.slice(0, 8)}: \"${c.comment}\"]`;\n const end = c.offset + c.length;\n // Insert marker after the selected text\n result = result.slice(0, end) + \" \" + marker + result.slice(end);\n }\n\n return result;\n}\n","import { createServer, type IncomingMessage, type ServerResponse } from \"node:http\";\nimport { readFile, readdir } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport { join, resolve, relative } from \"node:path\";\nimport { WebSocketServer, type WebSocket } from \"ws\";\nimport type { CommentStore } from \"./comment-store.js\";\nimport { FileWatcher } from \"./file-watcher.js\";\nimport { renderToHtml } from \"./utils.js\";\nimport type { WSClientMessage, WSServerMessage } from \"./types.js\";\n\n// In dev (tsx): import.meta.dirname is src/, so ../ui works.\n// In built (dist/bin/cowrite.js): import.meta.dirname is dist/bin/, so ../../ui.\n// We find ui/ by checking which path actually contains index.html.\nfunction findUiDir(): string {\n const dir = import.meta.dirname ?? new URL(\".\", import.meta.url).pathname;\n // Try common locations relative to this file\n const candidates = [\n join(dir, \"..\", \"ui\"), // dev: src/../ui\n join(dir, \"..\", \"..\", \"ui\"), // built: dist/bin/../../ui\n ];\n return candidates.find((d) => {\n try { return existsSync(join(d, \"index.html\")); } catch { return false; }\n }) ?? candidates[0];\n}\nconst UI_DIR = findUiDir();\n\nconst MIME_TYPES: Record<string, string> = {\n \".html\": \"text/html\",\n \".css\": \"text/css\",\n \".js\": \"application/javascript\",\n};\n\nconst IGNORED_DIRS = new Set([\"node_modules\", \".git\", \"dist\", \".next\", \".cache\", \"coverage\", \"__pycache__\"]);\n\nexport function createPreviewServer(\n store: CommentStore,\n projectDir: string,\n port: number,\n initialFile?: string\n): { start: () => Promise<void>; stop: () => Promise<void> } {\n const clients = new Set<WebSocket>();\n const clientFiles = new Map<WebSocket, string>(); // ws -> absolute file path\n const watchers = new Map<string, FileWatcher>(); // absolute path -> watcher\n const watcherListeners = new Map<string, (...args: any[]) => void>(); // path -> change listener\n\n const resolvedProjectDir = resolve(projectDir);\n\n function isInsideProject(filePath: string): boolean {\n const resolved = resolve(resolvedProjectDir, filePath);\n return resolved.startsWith(resolvedProjectDir);\n }\n\n async function getOrCreateWatcher(absPath: string): Promise<FileWatcher> {\n let watcher = watchers.get(absPath);\n if (!watcher) {\n watcher = new FileWatcher(absPath);\n await watcher.start();\n watchers.set(absPath, watcher);\n\n // Subscribe to file changes and broadcast to relevant clients\n const listener = (event: { file: string; content: string; oldContent: string }) => {\n store.adjustOffsets(event.file, event.oldContent, event.content);\n const html = renderToHtml(event.content, event.file);\n for (const [ws, file] of clientFiles) {\n if (file === absPath) {\n send(ws, { type: \"file_update\", file: event.file, content: event.content, html });\n }\n }\n };\n watcher.on(\"change\", listener);\n watcherListeners.set(absPath, listener);\n }\n return watcher;\n }\n\n async function listFiles(dir: string, prefix = \"\"): Promise<string[]> {\n const files: string[] = [];\n try {\n const entries = await readdir(dir, { withFileTypes: true });\n for (const entry of entries) {\n if (entry.name.startsWith(\".\") || IGNORED_DIRS.has(entry.name)) continue;\n const relPath = prefix ? `${prefix}/${entry.name}` : entry.name;\n if (entry.isDirectory()) {\n const sub = await listFiles(join(dir, entry.name), relPath);\n files.push(...sub);\n } else {\n files.push(relPath);\n }\n }\n } catch {\n // Permission denied or gone — skip\n }\n return files;\n }\n\n const httpServer = createServer(async (req: IncomingMessage, res: ServerResponse) => {\n const url = new URL(req.url ?? \"/\", `http://localhost:${port}`);\n const pathname = url.pathname === \"/\" ? \"/index.html\" : url.pathname;\n\n // Serve static UI files\n const ext = pathname.slice(pathname.lastIndexOf(\".\"));\n const mimeType = MIME_TYPES[ext];\n if (mimeType) {\n try {\n const filePath = join(UI_DIR, pathname);\n const content = await readFile(filePath, \"utf-8\");\n res.writeHead(200, { \"Content-Type\": mimeType });\n res.end(content);\n return;\n } catch {\n // Fall through to 404\n }\n }\n\n // API: GET /api/files — list project files for the file picker\n if (pathname === \"/api/files\") {\n const files = await listFiles(resolvedProjectDir);\n res.writeHead(200, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify({ files }));\n return;\n }\n\n // API: GET /api/state?file=... — state for a specific file\n if (pathname === \"/api/state\") {\n const fileParam = url.searchParams.get(\"file\");\n if (!fileParam) {\n res.writeHead(400, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify({ error: \"Missing file parameter\" }));\n return;\n }\n const absPath = resolve(resolvedProjectDir, fileParam);\n if (!isInsideProject(absPath)) {\n res.writeHead(403, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify({ error: \"Path outside project\" }));\n return;\n }\n try {\n const content = await readFile(absPath, \"utf-8\");\n const html = renderToHtml(content, absPath);\n const comments = store.getForFile(absPath);\n res.writeHead(200, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify({ file: absPath, content, html, comments }));\n } catch {\n res.writeHead(404, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify({ error: \"File not found\" }));\n }\n return;\n }\n\n res.writeHead(404, { \"Content-Type\": \"text/plain\" });\n res.end(\"Not found\");\n });\n\n const wss = new WebSocketServer({ server: httpServer });\n\n wss.on(\"connection\", async (ws: WebSocket) => {\n clients.add(ws);\n\n // If there's an initial file (preview mode), auto-assign it\n if (initialFile) {\n const absPath = resolve(resolvedProjectDir, initialFile);\n await switchClientFile(ws, absPath);\n }\n\n ws.on(\"message\", (data) => {\n try {\n const msg: WSClientMessage = JSON.parse(data.toString());\n handleClientMessage(ws, msg);\n } catch (err) {\n send(ws, { type: \"error\", message: `Invalid message: ${err}` });\n }\n });\n\n ws.on(\"close\", () => {\n clients.delete(ws);\n clientFiles.delete(ws);\n });\n });\n\n async function switchClientFile(ws: WebSocket, absPath: string): Promise<void> {\n if (!isInsideProject(absPath)) {\n send(ws, { type: \"error\", message: \"Path outside project\" });\n return;\n }\n try {\n const watcher = await getOrCreateWatcher(absPath);\n clientFiles.set(ws, absPath);\n const content = watcher.getContent();\n const html = renderToHtml(content, absPath);\n const comments = store.getForFile(absPath);\n send(ws, { type: \"file_update\", file: absPath, content, html });\n send(ws, { type: \"comments_update\", comments });\n } catch (err) {\n send(ws, { type: \"error\", message: `Cannot open file: ${err}` });\n }\n }\n\n function handleClientMessage(ws: WebSocket, msg: WSClientMessage): void {\n switch (msg.type) {\n case \"switch_file\": {\n const absPath = resolve(resolvedProjectDir, msg.file);\n switchClientFile(ws, absPath);\n break;\n }\n case \"comment_add\": {\n const file = clientFiles.get(ws);\n if (!file) break;\n store.add({\n file,\n offset: msg.offset,\n length: msg.length,\n selectedText: msg.selectedText,\n comment: msg.comment,\n });\n break;\n }\n case \"comment_reply\":\n store.addReply(msg.commentId, \"user\", msg.text);\n break;\n case \"comment_resolve\":\n store.resolve(msg.commentId);\n break;\n }\n }\n\n // Broadcast comment updates to clients viewing the affected file\n store.on(\"change\", (comment: any) => {\n for (const [ws, file] of clientFiles) {\n // If we know which file changed, only notify relevant clients\n // If comment is null (e.g. adjustOffsets, reload), notify all\n if (!comment || comment.file === file) {\n const comments = store.getForFile(file);\n send(ws, { type: \"comments_update\", comments });\n }\n }\n });\n\n function send(ws: WebSocket, msg: WSServerMessage): void {\n if (ws.readyState === ws.OPEN) {\n ws.send(JSON.stringify(msg));\n }\n }\n\n return {\n start: () =>\n new Promise<void>((resolve) => {\n httpServer.listen(port, () => {\n process.stderr.write(`Cowrite preview server running at http://localhost:${port}\\n`);\n resolve();\n });\n }),\n stop: async () => {\n for (const client of clients) {\n client.close();\n }\n for (const [path, watcher] of watchers) {\n const listener = watcherListeners.get(path);\n if (listener) watcher.off(\"change\", listener);\n await watcher.stop();\n }\n watchers.clear();\n watcherListeners.clear();\n await new Promise<void>((resolvePromise, reject) => {\n httpServer.close((err) => {\n if (err) reject(err);\n else resolvePromise();\n });\n });\n },\n };\n}\n","import { watch, type FSWatcher } from \"chokidar\";\nimport { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { EventEmitter } from \"node:events\";\n\nexport interface FileChangeEvent {\n file: string;\n content: string;\n}\n\nexport class FileWatcher extends EventEmitter {\n private watcher: FSWatcher | null = null;\n private filePath: string;\n private lastContent: string = \"\";\n\n constructor(filePath: string) {\n super();\n this.filePath = resolve(filePath);\n }\n\n async start(): Promise<string> {\n this.lastContent = await readFile(this.filePath, \"utf-8\");\n\n this.watcher = watch(this.filePath, {\n persistent: true,\n ignoreInitial: true,\n awaitWriteFinish: { stabilityThreshold: 100, pollInterval: 50 },\n });\n\n this.watcher.on(\"change\", async () => {\n try {\n const newContent = await readFile(this.filePath, \"utf-8\");\n if (newContent !== this.lastContent) {\n const oldContent = this.lastContent;\n this.lastContent = newContent;\n this.emit(\"change\", {\n file: this.filePath,\n content: newContent,\n oldContent,\n } as FileChangeEvent & { oldContent: string });\n }\n } catch (err) {\n process.stderr.write(`File watch read error: ${err}\\n`);\n }\n });\n\n return this.lastContent;\n }\n\n getContent(): string {\n return this.lastContent;\n }\n\n getFilePath(): string {\n return this.filePath;\n }\n\n async stop(): Promise<void> {\n if (this.watcher) {\n await this.watcher.close();\n this.watcher = null;\n }\n }\n}\n"],"mappings":";;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,WAAAA,gBAAe;AACxB,SAAS,4BAA4B;;;ACFrC,SAAS,oBAAoB;AAC7B,SAAS,UAAU,iBAAiB;AACpC,SAAS,MAAM,eAAe;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,SAAS,qBAAqC;AAGvD,IAAM,eAAe;AAEd,IAAM,eAAN,cAA2B,aAAa;AAAA,EACrC,WAAiC,oBAAI,IAAI;AAAA,EACzC;AAAA,EACA,gBAAgB;AAAA,EAChB,UAA4B;AAAA,EAEpC,YAAY,YAAoB;AAC9B,UAAM;AACN,SAAK,cAAc,KAAK,QAAQ,UAAU,GAAG,YAAY;AAAA,EAC3D;AAAA,EAEA,MAAM,OAAsB;AAC1B,QAAI;AACF,YAAM,OAAO,MAAM,SAAS,KAAK,aAAa,OAAO;AACrD,YAAM,MAAiB,KAAK,MAAM,IAAI;AACtC,iBAAW,KAAK,KAAK;AACnB,aAAK,SAAS,IAAI,EAAE,IAAI,CAAC;AAAA,MAC3B;AAAA,IACF,QAAQ;AAAA,IAER;AAAA,EACF;AAAA,EAEA,MAAc,UAAyB;AACrC,SAAK,gBAAgB,KAAK,IAAI;AAC9B,UAAM,MAAM,MAAM,KAAK,KAAK,SAAS,OAAO,CAAC;AAC7C,UAAM,UAAU,KAAK,aAAa,KAAK,UAAU,KAAK,MAAM,CAAC,GAAG,OAAO;AAAA,EACzE;AAAA,EAEA,MAA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UAAM,UAAU,QAAQ,SAAS;AAEjC,YAAQ,OAAO,MAAM;AAAA,CAAuC;AAC5D,YAAQ,OAAO,MAAM,6BAA6B,IAAI;AAAA,CAAI;AAE1D,kBAAc,OAAO,OAAO;AAAA,EAC9B,OAAO;AACL,YAAQ,OAAO,MAAM,oBAAoB,OAAO;AAAA,CAAI;AACpD,YAAQ,OAAO,MAAM,KAAK;AAC1B,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;AAEA,KAAK,EAAE,MAAM,CAAC,QAAQ;AACpB,UAAQ,OAAO,MAAM,gBAAgB,GAAG;AAAA,CAAI;AAC5C,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":["resolve","readFile","resolve","readFile","join","resolve","readFile","resolve","EventEmitter","join","resolve","readFile","resolve"]}
|
|
1
|
+
{"version":3,"sources":["../../bin/cowrite.ts","../../src/comment-store.ts","../../src/mcp-server.ts","../../src/utils.ts","../../src/preview-server.ts","../../src/file-watcher.ts"],"sourcesContent":["import { parseArgs } from \"node:util\";\nimport { resolve } from \"node:path\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport { CommentStore } from \"../src/comment-store.js\";\nimport { createMcpServer } from \"../src/mcp-server.js\";\nimport { createPreviewServer } from \"../src/preview-server.js\";\n\nconst USAGE = `\ncowrite — Live commenting plugin for coding agent sessions\n\nUsage:\n cowrite preview <file> [--port N] Open browser preview for a specific file + start MCP server\n cowrite serve [--port N] Start MCP server + preview server (browse any file)\n\nOptions:\n --port, -p Port for preview server (default: 3377)\n --help, -h Show this help\n`;\n\nfunction setupShutdown(store: CommentStore, preview: { stop: () => Promise<void> }) {\n let shuttingDown = false;\n const shutdown = () => {\n if (shuttingDown) {\n // Second signal — force exit immediately\n process.exit(1);\n }\n shuttingDown = true;\n process.stderr.write(\"Shutting down...\\n\");\n // Best-effort cleanup with a hard timeout\n Promise.allSettled([store.stopWatching(), preview.stop()])\n .finally(() => process.exit(0));\n setTimeout(() => process.exit(0), 2000);\n };\n process.on(\"SIGINT\", shutdown);\n process.on(\"SIGTERM\", shutdown);\n}\n\nasync function main() {\n const { values, positionals } = parseArgs({\n args: process.argv.slice(2),\n options: {\n port: { type: \"string\", short: \"p\", default: \"3377\" },\n help: { type: \"boolean\", short: \"h\", default: false },\n },\n allowPositionals: true,\n strict: false,\n });\n\n if (values.help || positionals.length === 0) {\n process.stderr.write(USAGE);\n process.exit(positionals.length === 0 && !values.help ? 1 : 0);\n }\n\n const command = positionals[0];\n const projectDir = process.cwd();\n const port = parseInt(values.port as string, 10);\n\n if (command === \"serve\") {\n const store = new CommentStore(projectDir);\n await store.load();\n await store.startWatching();\n\n // Start preview server (no initial file — user picks from browser)\n const preview = createPreviewServer(store, projectDir, port);\n await preview.start();\n\n // Start MCP server on stdio\n const mcpServer = createMcpServer(store, projectDir);\n const transport = new StdioServerTransport();\n await mcpServer.connect(transport);\n\n process.stderr.write(`Cowrite MCP server running on stdio\\n`);\n process.stderr.write(`Preview: http://localhost:${port}\\n`);\n\n setupShutdown(store, preview);\n } else if (command === \"preview\") {\n const filePath = positionals[1];\n if (!filePath) {\n process.stderr.write(\"Error: preview command requires a file path\\n\");\n process.stderr.write(USAGE);\n process.exit(1);\n }\n\n const resolvedFile = resolve(projectDir, filePath);\n\n const store = new CommentStore(projectDir);\n await store.load();\n await store.startWatching();\n\n // Start preview server with initial file\n const preview = createPreviewServer(store, projectDir, port, resolvedFile);\n await preview.start();\n\n // Start MCP server on stdio\n const mcpServer = createMcpServer(store, projectDir);\n const transport = new StdioServerTransport();\n await mcpServer.connect(transport);\n\n process.stderr.write(`Cowrite MCP server running on stdio\\n`);\n process.stderr.write(`Preview: http://localhost:${port}\\n`);\n\n setupShutdown(store, preview);\n } else {\n process.stderr.write(`Unknown command: ${command}\\n`);\n process.stderr.write(USAGE);\n process.exit(1);\n }\n}\n\nmain().catch((err) => {\n process.stderr.write(`Fatal error: ${err}\\n`);\n process.exit(1);\n});\n","import { EventEmitter } from \"node:events\";\nimport { readFile, writeFile } from \"node:fs/promises\";\nimport { join, resolve } from \"node:path\";\nimport { randomUUID } from \"node:crypto\";\nimport { watch as chokidarWatch, type FSWatcher } from \"chokidar\";\nimport type { Comment, Reply } from \"./types.js\";\n\nconst PERSIST_FILE = \".cowrite-comments.json\";\n\nexport class CommentStore extends EventEmitter {\n private comments: Map<string, Comment> = new Map();\n private persistPath: string;\n private lastWriteTime = 0;\n private watcher: FSWatcher | null = null;\n\n constructor(projectDir: string) {\n super();\n this.persistPath = join(resolve(projectDir), PERSIST_FILE);\n }\n\n async load(): Promise<void> {\n try {\n const data = await readFile(this.persistPath, \"utf-8\");\n const arr: Comment[] = JSON.parse(data);\n for (const c of arr) {\n this.comments.set(c.id, c);\n }\n } catch {\n // No existing file, start fresh\n }\n }\n\n private async persist(): Promise<void> {\n this.lastWriteTime = Date.now();\n const arr = Array.from(this.comments.values());\n await writeFile(this.persistPath, JSON.stringify(arr, null, 2), \"utf-8\");\n }\n\n async reload(): Promise<void> {\n try {\n const data = await readFile(this.persistPath, \"utf-8\");\n const arr: Comment[] = JSON.parse(data);\n const oldIds = new Set(this.comments.keys());\n this.comments.clear();\n for (const c of arr) {\n this.comments.set(c.id, c);\n }\n // Emit \"new_comment\" for comments that didn't exist before\n for (const c of arr) {\n if (!oldIds.has(c.id)) {\n this.emit(\"new_comment\", c);\n }\n }\n this.emit(\"change\", null);\n } catch {\n // File missing or invalid, clear state\n this.comments.clear();\n this.emit(\"change\", null);\n }\n }\n\n async startWatching(): Promise<void> {\n if (this.watcher) return;\n this.watcher = chokidarWatch(this.persistPath, {\n ignoreInitial: true,\n awaitWriteFinish: { stabilityThreshold: 100, pollInterval: 50 },\n });\n this.watcher.on(\"change\", async () => {\n if (Date.now() - this.lastWriteTime < 200) return;\n await this.reload();\n });\n this.watcher.on(\"add\", async () => {\n if (Date.now() - this.lastWriteTime < 200) return;\n await this.reload();\n });\n }\n\n async stopWatching(): Promise<void> {\n if (this.watcher) {\n await this.watcher.close();\n this.watcher = null;\n }\n }\n\n add(params: {\n file: string;\n offset: number;\n length: number;\n selectedText: string;\n comment: string;\n }): Comment {\n const comment: Comment = {\n id: randomUUID(),\n file: params.file,\n offset: params.offset,\n length: params.length,\n selectedText: params.selectedText,\n comment: params.comment,\n status: \"pending\",\n replies: [],\n createdAt: new Date().toISOString(),\n resolvedAt: null,\n };\n this.comments.set(comment.id, comment);\n this.emit(\"change\", comment);\n this.emit(\"new_comment\", comment);\n this.persist().catch((err) => process.stderr.write(`Persist error: ${err}\\n`));\n return comment;\n }\n\n resolve(commentId: string): Comment | null {\n const comment = this.comments.get(commentId);\n if (!comment) return null;\n comment.status = \"resolved\";\n comment.resolvedAt = new Date().toISOString();\n this.emit(\"change\", comment);\n this.persist().catch((err) => process.stderr.write(`Persist error: ${err}\\n`));\n return comment;\n }\n\n addReply(commentId: string, from: \"user\" | \"agent\", text: string): Reply | null {\n const comment = this.comments.get(commentId);\n if (!comment) return null;\n const reply: Reply = {\n id: randomUUID(),\n from,\n text,\n createdAt: new Date().toISOString(),\n };\n comment.replies.push(reply);\n this.emit(\"change\", comment);\n this.persist().catch((err) => process.stderr.write(`Persist error: ${err}\\n`));\n return reply;\n }\n\n get(commentId: string): Comment | null {\n return this.comments.get(commentId) ?? null;\n }\n\n getAll(filter?: { file?: string; status?: \"pending\" | \"resolved\" | \"all\" }): Comment[] {\n let results = Array.from(this.comments.values());\n if (filter?.file) {\n results = results.filter((c) => c.file === filter.file);\n }\n if (filter?.status && filter.status !== \"all\") {\n results = results.filter((c) => c.status === filter.status);\n }\n return results.sort((a, b) => a.offset - b.offset);\n }\n\n getForFile(file: string): Comment[] {\n return this.getAll({ file });\n }\n\n /** Adjust comment offsets when file content changes */\n adjustOffsets(file: string, oldContent: string, newContent: string): void {\n const fileComments = this.getForFile(file);\n if (fileComments.length === 0) return;\n\n for (const comment of fileComments) {\n // Try to find the selected text in the new content near original offset\n const searchStart = Math.max(0, comment.offset - 200);\n const searchEnd = Math.min(newContent.length, comment.offset + comment.length + 200);\n const searchRegion = newContent.slice(searchStart, searchEnd);\n const idx = searchRegion.indexOf(comment.selectedText);\n if (idx !== -1) {\n comment.offset = searchStart + idx;\n }\n // If not found, leave offset as-is (orphaned comment)\n }\n\n this.emit(\"change\", null);\n this.persist().catch((err) => process.stderr.write(`Persist error: ${err}\\n`));\n }\n\n clear(): void {\n this.comments.clear();\n this.emit(\"change\", null);\n this.persist().catch((err) => process.stderr.write(`Persist error: ${err}\\n`));\n }\n}\n","import { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport type { CommentStore } from \"./comment-store.js\";\nimport { annotateFileWithComments } from \"./utils.js\";\nimport { readFile } from \"node:fs/promises\";\nimport { relative, resolve } from \"node:path\";\n\nexport function createMcpServer(store: CommentStore, projectDir: string): McpServer {\n const server = new McpServer(\n { name: \"cowrite\", version: \"0.1.0\" },\n { capabilities: { logging: {} } },\n );\n\n // Tool: get_pending_comments\n const getPendingTool = server.tool(\n \"get_pending_comments\",\n \"Get comments from the live preview (0 pending). Call this first to catch comments posted before you started listening.\",\n {\n file: z.string().optional().describe(\"Filter by file path\"),\n status: z.enum([\"pending\", \"resolved\", \"all\"]).optional().describe(\"Filter by status (default: pending)\"),\n },\n async ({ file, status }) => {\n const filter: { file?: string; status?: \"pending\" | \"resolved\" | \"all\" } = {};\n if (file) filter.file = resolve(projectDir, file);\n filter.status = status ?? \"pending\";\n const comments = store.getAll(filter);\n return {\n content: [\n {\n type: \"text\" as const,\n text: comments.length === 0\n ? \"No comments found.\"\n : JSON.stringify(comments, null, 2),\n },\n ],\n };\n }\n );\n\n // Tool: resolve_comment\n server.tool(\n \"resolve_comment\",\n \"Mark a comment as resolved/addressed.\",\n {\n commentId: z.string().describe(\"The comment ID to resolve\"),\n },\n async ({ commentId }) => {\n const comment = store.resolve(commentId);\n if (!comment) {\n return {\n content: [{ type: \"text\" as const, text: `Comment ${commentId} not found.` }],\n isError: true,\n };\n }\n return {\n content: [{ type: \"text\" as const, text: `Comment ${commentId} resolved.` }],\n };\n }\n );\n\n // Tool: reply_to_comment\n server.tool(\n \"reply_to_comment\",\n \"Reply to a comment from the agent.\",\n {\n commentId: z.string().describe(\"The comment ID to reply to\"),\n reply: z.string().describe(\"The reply text\"),\n },\n async ({ commentId, reply }) => {\n const replyObj = store.addReply(commentId, \"agent\", reply);\n if (!replyObj) {\n return {\n content: [{ type: \"text\" as const, text: `Comment ${commentId} not found.` }],\n isError: true,\n };\n }\n return {\n content: [{ type: \"text\" as const, text: `Reply added to comment ${commentId}.` }],\n };\n }\n );\n\n // Tool: get_file_with_annotations\n server.tool(\n \"get_file_with_annotations\",\n \"Get file content with inline comment markers showing where comments are anchored.\",\n {\n file: z.string().describe(\"File path to annotate\"),\n },\n async ({ file }) => {\n const filePath = resolve(projectDir, file);\n try {\n const content = await readFile(filePath, \"utf-8\");\n const comments = store.getForFile(filePath);\n const annotated = annotateFileWithComments(content, comments);\n return {\n content: [{ type: \"text\" as const, text: annotated }],\n };\n } catch (err) {\n return {\n content: [{ type: \"text\" as const, text: `Error reading file: ${err}` }],\n isError: true,\n };\n }\n }\n );\n\n // Tool: wait_for_comment\n server.tool(\n \"wait_for_comment\",\n \"Block until a new comment is posted in the live preview, then return it. This is the primary way to receive real-time comments — call it again after handling each comment to keep listening.\",\n {\n timeout: z.number().optional().describe(\"Max seconds to wait (default: 120)\"),\n },\n ({ timeout }) => {\n const maxWait = (timeout ?? 120) * 1000;\n return new Promise((resolve) => {\n const timer = setTimeout(() => {\n cleanup();\n resolve({\n content: [{ type: \"text\" as const, text: \"No new comments within timeout.\" }],\n });\n }, maxWait);\n\n const onComment = (comment: { id: string; file: string; selectedText: string; comment: string }) => {\n cleanup();\n const file = relative(projectDir, comment.file);\n resolve({\n content: [{\n type: \"text\" as const,\n text: JSON.stringify({ ...comment, file }, null, 2),\n }],\n });\n };\n\n const cleanup = () => {\n clearTimeout(timer);\n store.off(\"new_comment\", onComment);\n };\n\n store.on(\"new_comment\", onComment);\n });\n }\n );\n\n // Resource: cowrite://comments\n server.resource(\n \"all-comments\",\n \"cowrite://comments\",\n { description: \"Live list of all comments\", mimeType: \"application/json\" },\n async () => {\n const comments = store.getAll();\n return {\n contents: [\n {\n uri: \"cowrite://comments\",\n mimeType: \"application/json\",\n text: JSON.stringify(comments, null, 2),\n },\n ],\n };\n }\n );\n\n // Wire store changes to MCP resource notifications\n store.on(\"change\", () => {\n server.server.notification({\n method: \"notifications/resources/updated\",\n params: { uri: \"cowrite://comments\" },\n }).catch(() => {\n // Notification may fail if client doesn't support it, that's OK\n });\n });\n\n // When a new comment arrives, update the get_pending_comments tool description\n // with the current count and fire sendToolListChanged() to signal Claude Code\n store.on(\"new_comment\", () => {\n const count = store.getAll({ status: \"pending\" }).length;\n getPendingTool.update({\n description: `Get comments from the live preview (${count} pending). Call this first to catch comments posted before you started listening.`,\n });\n server.sendToolListChanged();\n });\n\n // Also update count when comments are resolved\n store.on(\"change\", () => {\n const count = store.getAll({ status: \"pending\" }).length;\n getPendingTool.update({\n description: `Get comments from the live preview (${count} pending). Call this first to catch comments posted before you started listening.`,\n });\n });\n\n // Prompt: cowrite-workflow\n server.prompt(\n \"cowrite-workflow\",\n \"How to process live preview comments in a wait-handle-resolve loop\",\n () => ({\n messages: [\n {\n role: \"user\" as const,\n content: {\n type: \"text\" as const,\n text: [\n \"You are monitoring a live code preview where users leave comments on selected text.\",\n \"\",\n \"Follow this loop:\",\n \"1. Call `get_pending_comments` to check for any comments already posted.\",\n \"2. Process each pending comment: read the file, make the requested change or reply, then call `resolve_comment`.\",\n \"3. Call `wait_for_comment` to block until the next comment arrives.\",\n \"4. When a comment arrives, process it the same way (step 2).\",\n \"5. Go back to step 3 and keep listening.\",\n \"\",\n \"Tips:\",\n \"- Use `get_file_with_annotations` to see comments in context within the file.\",\n \"- Use `reply_to_comment` to acknowledge or ask clarifying questions.\",\n \"- Always `resolve_comment` after addressing feedback.\",\n ].join(\"\\n\"),\n },\n },\n ],\n })\n );\n\n return server;\n}\n","import { marked } from \"marked\";\nimport type { Comment } from \"./types.js\";\n\n/**\n * Render file content as HTML. Markdown files get full rendering;\n * other text files are wrapped in <pre> with offset-tagged spans.\n */\nexport function renderToHtml(content: string, filePath: string): string {\n const isMarkdown = /\\.(md|markdown|mdx)$/i.test(filePath);\n if (isMarkdown) {\n return renderMarkdownWithOffsets(content);\n }\n return renderPlainTextWithOffsets(content);\n}\n\nfunction renderMarkdownWithOffsets(content: string): string {\n const html = marked.parse(content, { async: false }) as string;\n // Wrap the rendered HTML in a container with data attributes for offset mapping\n // The client-side JS will handle offset computation from the rendered text nodes\n return `<div class=\"markdown-body\" data-source-length=\"${content.length}\">${html}</div>`;\n}\n\nfunction renderPlainTextWithOffsets(content: string): string {\n const lines = content.split(\"\\n\");\n let offset = 0;\n const htmlLines: string[] = [];\n\n for (const line of lines) {\n const escaped = escapeHtml(line);\n htmlLines.push(`<span class=\"line\" data-offset=\"${offset}\" data-length=\"${line.length}\">${escaped}</span>`);\n offset += line.length + 1; // +1 for the newline\n }\n\n return `<pre class=\"plain-text\" data-source-length=\"${content.length}\">${htmlLines.join(\"\\n\")}</pre>`;\n}\n\nfunction escapeHtml(text: string): string {\n return text\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/\"/g, \""\");\n}\n\n/**\n * Annotate file content with inline comment markers for the agent.\n * Inserts `[COMMENT #id: \"text\"]` at the comment offsets.\n */\nexport function annotateFileWithComments(content: string, comments: Comment[]): string {\n // Sort by offset descending so insertions don't shift earlier offsets\n const sorted = [...comments].sort((a, b) => b.offset - a.offset);\n let result = content;\n\n for (const c of sorted) {\n const marker = `[COMMENT #${c.id.slice(0, 8)}: \"${c.comment}\"]`;\n const end = c.offset + c.length;\n // Insert marker after the selected text\n result = result.slice(0, end) + \" \" + marker + result.slice(end);\n }\n\n return result;\n}\n","import { createServer, type IncomingMessage, type ServerResponse } from \"node:http\";\nimport { readFile, readdir } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport { join, resolve, relative } from \"node:path\";\nimport { WebSocketServer, type WebSocket } from \"ws\";\nimport type { CommentStore } from \"./comment-store.js\";\nimport { FileWatcher } from \"./file-watcher.js\";\nimport { renderToHtml } from \"./utils.js\";\nimport type { WSClientMessage, WSServerMessage } from \"./types.js\";\n\n// In dev (tsx): import.meta.dirname is src/, so ../ui works.\n// In built (dist/bin/cowrite.js): import.meta.dirname is dist/bin/, so ../../ui.\n// We find ui/ by checking which path actually contains index.html.\nfunction findUiDir(): string {\n const dir = import.meta.dirname ?? new URL(\".\", import.meta.url).pathname;\n // Try common locations relative to this file\n const candidates = [\n join(dir, \"..\", \"ui\"), // dev: src/../ui\n join(dir, \"..\", \"..\", \"ui\"), // built: dist/bin/../../ui\n ];\n return candidates.find((d) => {\n try { return existsSync(join(d, \"index.html\")); } catch { return false; }\n }) ?? candidates[0];\n}\nconst UI_DIR = findUiDir();\n\nconst MIME_TYPES: Record<string, string> = {\n \".html\": \"text/html\",\n \".css\": \"text/css\",\n \".js\": \"application/javascript\",\n};\n\nconst IGNORED_DIRS = new Set([\"node_modules\", \".git\", \"dist\", \".next\", \".cache\", \"coverage\", \"__pycache__\"]);\n\nexport function createPreviewServer(\n store: CommentStore,\n projectDir: string,\n port: number,\n initialFile?: string\n): { start: () => Promise<void>; stop: () => Promise<void> } {\n const clients = new Set<WebSocket>();\n const clientFiles = new Map<WebSocket, string>(); // ws -> absolute file path\n const watchers = new Map<string, FileWatcher>(); // absolute path -> watcher\n const watcherListeners = new Map<string, (...args: any[]) => void>(); // path -> change listener\n\n const resolvedProjectDir = resolve(projectDir);\n\n function isInsideProject(filePath: string): boolean {\n const resolved = resolve(resolvedProjectDir, filePath);\n return resolved.startsWith(resolvedProjectDir);\n }\n\n async function getOrCreateWatcher(absPath: string): Promise<FileWatcher> {\n let watcher = watchers.get(absPath);\n if (!watcher) {\n watcher = new FileWatcher(absPath);\n await watcher.start();\n watchers.set(absPath, watcher);\n\n // Subscribe to file changes and broadcast to relevant clients\n const listener = (event: { file: string; content: string; oldContent: string }) => {\n store.adjustOffsets(event.file, event.oldContent, event.content);\n const html = renderToHtml(event.content, event.file);\n for (const [ws, file] of clientFiles) {\n if (file === absPath) {\n send(ws, { type: \"file_update\", file: event.file, content: event.content, html });\n }\n }\n };\n watcher.on(\"change\", listener);\n watcherListeners.set(absPath, listener);\n }\n return watcher;\n }\n\n async function listFiles(dir: string, prefix = \"\"): Promise<string[]> {\n const files: string[] = [];\n try {\n const entries = await readdir(dir, { withFileTypes: true });\n for (const entry of entries) {\n if (entry.name.startsWith(\".\") || IGNORED_DIRS.has(entry.name)) continue;\n const relPath = prefix ? `${prefix}/${entry.name}` : entry.name;\n if (entry.isDirectory()) {\n const sub = await listFiles(join(dir, entry.name), relPath);\n files.push(...sub);\n } else {\n files.push(relPath);\n }\n }\n } catch {\n // Permission denied or gone — skip\n }\n return files;\n }\n\n const httpServer = createServer(async (req: IncomingMessage, res: ServerResponse) => {\n const url = new URL(req.url ?? \"/\", `http://localhost:${port}`);\n const pathname = url.pathname === \"/\" ? \"/index.html\" : url.pathname;\n\n // Serve static UI files\n const ext = pathname.slice(pathname.lastIndexOf(\".\"));\n const mimeType = MIME_TYPES[ext];\n if (mimeType) {\n try {\n const filePath = join(UI_DIR, pathname);\n const content = await readFile(filePath, \"utf-8\");\n res.writeHead(200, { \"Content-Type\": mimeType });\n res.end(content);\n return;\n } catch {\n // Fall through to 404\n }\n }\n\n // API: GET /api/files — list project files for the file picker\n if (pathname === \"/api/files\") {\n const files = await listFiles(resolvedProjectDir);\n res.writeHead(200, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify({ files }));\n return;\n }\n\n // API: GET /api/state?file=... — state for a specific file\n if (pathname === \"/api/state\") {\n const fileParam = url.searchParams.get(\"file\");\n if (!fileParam) {\n res.writeHead(400, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify({ error: \"Missing file parameter\" }));\n return;\n }\n const absPath = resolve(resolvedProjectDir, fileParam);\n if (!isInsideProject(absPath)) {\n res.writeHead(403, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify({ error: \"Path outside project\" }));\n return;\n }\n try {\n const content = await readFile(absPath, \"utf-8\");\n const html = renderToHtml(content, absPath);\n const comments = store.getForFile(absPath);\n res.writeHead(200, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify({ file: absPath, content, html, comments }));\n } catch {\n res.writeHead(404, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify({ error: \"File not found\" }));\n }\n return;\n }\n\n res.writeHead(404, { \"Content-Type\": \"text/plain\" });\n res.end(\"Not found\");\n });\n\n const wss = new WebSocketServer({ server: httpServer });\n\n wss.on(\"connection\", async (ws: WebSocket) => {\n clients.add(ws);\n\n // If there's an initial file (preview mode), auto-assign it\n if (initialFile) {\n const absPath = resolve(resolvedProjectDir, initialFile);\n await switchClientFile(ws, absPath);\n }\n\n ws.on(\"message\", (data) => {\n try {\n const msg: WSClientMessage = JSON.parse(data.toString());\n handleClientMessage(ws, msg);\n } catch (err) {\n send(ws, { type: \"error\", message: `Invalid message: ${err}` });\n }\n });\n\n ws.on(\"close\", () => {\n clients.delete(ws);\n clientFiles.delete(ws);\n });\n });\n\n async function switchClientFile(ws: WebSocket, absPath: string): Promise<void> {\n if (!isInsideProject(absPath)) {\n send(ws, { type: \"error\", message: \"Path outside project\" });\n return;\n }\n try {\n const watcher = await getOrCreateWatcher(absPath);\n clientFiles.set(ws, absPath);\n const content = watcher.getContent();\n const html = renderToHtml(content, absPath);\n const comments = store.getForFile(absPath);\n send(ws, { type: \"file_update\", file: absPath, content, html });\n send(ws, { type: \"comments_update\", comments });\n } catch (err) {\n send(ws, { type: \"error\", message: `Cannot open file: ${err}` });\n }\n }\n\n function handleClientMessage(ws: WebSocket, msg: WSClientMessage): void {\n switch (msg.type) {\n case \"switch_file\": {\n const absPath = resolve(resolvedProjectDir, msg.file);\n switchClientFile(ws, absPath);\n break;\n }\n case \"comment_add\": {\n const file = clientFiles.get(ws);\n if (!file) break;\n store.add({\n file,\n offset: msg.offset,\n length: msg.length,\n selectedText: msg.selectedText,\n comment: msg.comment,\n });\n break;\n }\n case \"comment_reply\":\n store.addReply(msg.commentId, \"user\", msg.text);\n break;\n case \"comment_resolve\":\n store.resolve(msg.commentId);\n break;\n }\n }\n\n // Broadcast comment updates to clients viewing the affected file\n store.on(\"change\", (comment: any) => {\n for (const [ws, file] of clientFiles) {\n // If we know which file changed, only notify relevant clients\n // If comment is null (e.g. adjustOffsets, reload), notify all\n if (!comment || comment.file === file) {\n const comments = store.getForFile(file);\n send(ws, { type: \"comments_update\", comments });\n }\n }\n });\n\n function send(ws: WebSocket, msg: WSServerMessage): void {\n if (ws.readyState === ws.OPEN) {\n ws.send(JSON.stringify(msg));\n }\n }\n\n return {\n start: () =>\n new Promise<void>((resolve) => {\n httpServer.listen(port, () => {\n process.stderr.write(`Cowrite preview server running at http://localhost:${port}\\n`);\n resolve();\n });\n }),\n stop: async () => {\n for (const client of clients) {\n client.close();\n }\n for (const [path, watcher] of watchers) {\n const listener = watcherListeners.get(path);\n if (listener) watcher.off(\"change\", listener);\n await watcher.stop();\n }\n watchers.clear();\n watcherListeners.clear();\n await new Promise<void>((resolvePromise, reject) => {\n httpServer.close((err) => {\n if (err) reject(err);\n else resolvePromise();\n });\n });\n },\n };\n}\n","import { watch, type FSWatcher } from \"chokidar\";\nimport { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { EventEmitter } from \"node:events\";\n\nexport interface FileChangeEvent {\n file: string;\n content: string;\n}\n\nexport class FileWatcher extends EventEmitter {\n private watcher: FSWatcher | null = null;\n private filePath: string;\n private lastContent: string = \"\";\n\n constructor(filePath: string) {\n super();\n this.filePath = resolve(filePath);\n }\n\n async start(): Promise<string> {\n this.lastContent = await readFile(this.filePath, \"utf-8\");\n\n this.watcher = watch(this.filePath, {\n persistent: true,\n ignoreInitial: true,\n awaitWriteFinish: { stabilityThreshold: 100, pollInterval: 50 },\n });\n\n this.watcher.on(\"change\", async () => {\n try {\n const newContent = await readFile(this.filePath, \"utf-8\");\n if (newContent !== this.lastContent) {\n const oldContent = this.lastContent;\n this.lastContent = newContent;\n this.emit(\"change\", {\n file: this.filePath,\n content: newContent,\n oldContent,\n } as FileChangeEvent & { oldContent: string });\n }\n } catch (err) {\n process.stderr.write(`File watch read error: ${err}\\n`);\n }\n });\n\n return this.lastContent;\n }\n\n getContent(): string {\n return this.lastContent;\n }\n\n getFilePath(): string {\n return this.filePath;\n }\n\n async stop(): Promise<void> {\n if (this.watcher) {\n await this.watcher.close();\n this.watcher = null;\n }\n }\n}\n"],"mappings":";;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,WAAAA,gBAAe;AACxB,SAAS,4BAA4B;;;ACFrC,SAAS,oBAAoB;AAC7B,SAAS,UAAU,iBAAiB;AACpC,SAAS,MAAM,eAAe;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,SAAS,qBAAqC;AAGvD,IAAM,eAAe;AAEd,IAAM,eAAN,cAA2B,aAAa;AAAA,EACrC,WAAiC,oBAAI,IAAI;AAAA,EACzC;AAAA,EACA,gBAAgB;AAAA,EAChB,UAA4B;AAAA,EAEpC,YAAY,YAAoB;AAC9B,UAAM;AACN,SAAK,cAAc,KAAK,QAAQ,UAAU,GAAG,YAAY;AAAA,EAC3D;AAAA,EAEA,MAAM,OAAsB;AAC1B,QAAI;AACF,YAAM,OAAO,MAAM,SAAS,KAAK,aAAa,OAAO;AACrD,YAAM,MAAiB,KAAK,MAAM,IAAI;AACtC,iBAAW,KAAK,KAAK;AACnB,aAAK,SAAS,IAAI,EAAE,IAAI,CAAC;AAAA,MAC3B;AAAA,IACF,QAAQ;AAAA,IAER;AAAA,EACF;AAAA,EAEA,MAAc,UAAyB;AACrC,SAAK,gBAAgB,KAAK,IAAI;AAC9B,UAAM,MAAM,MAAM,KAAK,KAAK,SAAS,OAAO,CAAC;AAC7C,UAAM,UAAU,KAAK,aAAa,KAAK,UAAU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AM;AAAA,CAAuC;AAC5D,YAAQ,OAAO,MAAM,6BAA6B,IAAI;AAAA,CAAI;AAE1D,kBAAc,OAAO,OAAO;AAAA,EAC9B,WAAW,YAAY,WAAW;AAChC,UAAM,WAAW,YAAY,CAAC;AAC9B,QAAI,CAAC,UAAU;AACb,cAAQ,OAAO,MAAM,+CAA+C;AACpE,cAAQ,OAAO,MAAM,KAAK;AAC1B,cAAQ,KAAK,CAAC;AAAA,IAChB;AAEA,UAAM,eAAeE,SAAQ,YAAY,QAAQ;AAEjD,UAAM,QAAQ,IAAI,aAAa,UAAU;AACzC,UAAM,MAAM,KAAK;AACjB,UAAM,MAAM,cAAc;AAG1B,UAAM,UAAU,oBAAoB,OAAO,YAAY,MAAM,YAAY;AACzE,UAAM,QAAQ,MAAM;AAGpB,UAAM,YAAY,gBAAgB,OAAO,UAAU;AACnD,UAAM,YAAY,IAAI,qBAAqB;AAC3C,UAAM,UAAU,QAAQ,SAAS;AAEjC,YAAQ,OAAO,MAAM;AAAA,CAAuC;AAC5D,YAAQ,OAAO,MAAM,6BAA6B,IAAI;AAAA,CAAI;AAE1D,kBAAc,OAAO,OAAO;AAAA,EAC9B,OAAO;AACL,YAAQ,OAAO,MAAM,oBAAoB,OAAO;AAAA,CAAI;AACpD,YAAQ,OAAO,MAAM,KAAK;AAC1B,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;AAEA,KAAK,EAAE,MAAM,CAAC,QAAQ;AACpB,UAAQ,OAAO,MAAM,gBAAgB,GAAG;AAAA,CAAI;AAC5C,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":["resolve","readFile","resolve","readFile","join","resolve","readFile","resolve","EventEmitter","join","resolve","readFile","resolve"]}
|
package/package.json
CHANGED
package/ui/client.js
CHANGED
|
@@ -68,7 +68,7 @@ function connect() {
|
|
|
68
68
|
ws = new WebSocket(`${protocol}//${location.host}`);
|
|
69
69
|
|
|
70
70
|
ws.onopen = () => {
|
|
71
|
-
statusEl.
|
|
71
|
+
statusEl.innerHTML = '<span class="status-dot"></span>Connected';
|
|
72
72
|
statusEl.className = "status connected";
|
|
73
73
|
|
|
74
74
|
// If URL has ?file= param, switch to that file
|
|
@@ -82,7 +82,7 @@ function connect() {
|
|
|
82
82
|
};
|
|
83
83
|
|
|
84
84
|
ws.onclose = () => {
|
|
85
|
-
statusEl.
|
|
85
|
+
statusEl.innerHTML = '<span class="status-dot"></span>Disconnected';
|
|
86
86
|
statusEl.className = "status";
|
|
87
87
|
setTimeout(connect, 2000);
|
|
88
88
|
};
|
|
@@ -149,7 +149,7 @@ document.addEventListener("mouseup", (e) => {
|
|
|
149
149
|
const rect = range.getBoundingClientRect();
|
|
150
150
|
popup.style.left = `${Math.min(rect.left, window.innerWidth - 340)}px`;
|
|
151
151
|
popup.style.top = `${rect.bottom + 8}px`;
|
|
152
|
-
popupSelection.textContent = text
|
|
152
|
+
popupSelection.textContent = text;
|
|
153
153
|
commentInput.value = "";
|
|
154
154
|
popup.hidden = false;
|
|
155
155
|
commentInput.focus();
|
|
@@ -395,6 +395,9 @@ function applyTheme(theme) {
|
|
|
395
395
|
// Update toggle icon
|
|
396
396
|
const icon = themeToggle.closest(".theme-toggle").querySelector(".toggle-icon");
|
|
397
397
|
if (icon) icon.textContent = theme === "light" ? "\u2600" : "\u263E";
|
|
398
|
+
// Update toggle label
|
|
399
|
+
const label = document.querySelector(".toggle-label");
|
|
400
|
+
if (label) label.textContent = theme === "light" ? "Light" : "Dark";
|
|
398
401
|
}
|
|
399
402
|
|
|
400
403
|
// Load saved preference, default to dark
|
package/ui/index.html
CHANGED
|
@@ -4,23 +4,37 @@
|
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>Cowrite — Live Preview</title>
|
|
7
|
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
8
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
9
|
+
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">
|
|
7
10
|
<link rel="stylesheet" href="styles.css">
|
|
8
11
|
</head>
|
|
9
12
|
<body>
|
|
10
13
|
<header>
|
|
11
|
-
<
|
|
12
|
-
|
|
13
|
-
<
|
|
14
|
-
<
|
|
14
|
+
<div class="header-left">
|
|
15
|
+
<h1><span class="logo-mark">//</span> Cowrite</h1>
|
|
16
|
+
<div class="header-divider"></div>
|
|
17
|
+
<div class="file-picker" id="filePickerWrapper">
|
|
18
|
+
<svg class="file-picker-icon" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"/><polyline points="13 2 13 9 20 9"/></svg>
|
|
19
|
+
<input type="text" id="filePicker" list="fileList" placeholder="Open file..." autocomplete="off" />
|
|
20
|
+
<datalist id="fileList"></datalist>
|
|
21
|
+
</div>
|
|
22
|
+
<span class="file-path" id="filePath"></span>
|
|
15
23
|
</div>
|
|
16
|
-
<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
<span class="toggle-track">
|
|
21
|
-
<span class="toggle-thumb"><span class="toggle-icon"></span></span>
|
|
24
|
+
<div class="header-right">
|
|
25
|
+
<span class="status" id="status">
|
|
26
|
+
<span class="status-dot"></span>
|
|
27
|
+
Connecting...
|
|
22
28
|
</span>
|
|
23
|
-
|
|
29
|
+
<div class="header-divider"></div>
|
|
30
|
+
<label class="theme-toggle" title="Toggle light/dark mode">
|
|
31
|
+
<input type="checkbox" id="themeToggle" />
|
|
32
|
+
<span class="toggle-track">
|
|
33
|
+
<span class="toggle-thumb"><span class="toggle-icon"></span></span>
|
|
34
|
+
</span>
|
|
35
|
+
</label>
|
|
36
|
+
<span class="toggle-label">Dark</span>
|
|
37
|
+
</div>
|
|
24
38
|
</header>
|
|
25
39
|
|
|
26
40
|
<main>
|
|
@@ -29,18 +43,21 @@
|
|
|
29
43
|
</div>
|
|
30
44
|
|
|
31
45
|
<div class="sidebar" id="sidebar">
|
|
32
|
-
<
|
|
46
|
+
<div class="sidebar-header">
|
|
47
|
+
<h2>Comments <span class="comment-count" id="commentCount">0</span></h2>
|
|
48
|
+
</div>
|
|
33
49
|
<div id="commentList"></div>
|
|
34
50
|
</div>
|
|
35
51
|
</main>
|
|
36
52
|
|
|
37
53
|
<!-- Floating comment button/form -->
|
|
38
54
|
<div class="comment-popup" id="commentPopup" hidden>
|
|
55
|
+
<div class="popup-header">Selection</div>
|
|
39
56
|
<div class="popup-selection" id="popupSelection"></div>
|
|
40
57
|
<textarea id="commentInput" placeholder="Leave a comment..." rows="3"></textarea>
|
|
41
58
|
<div class="popup-actions">
|
|
42
|
-
<button id="commentSubmit">Submit</button>
|
|
43
59
|
<button id="commentCancel" class="secondary">Cancel</button>
|
|
60
|
+
<button id="commentSubmit">Submit</button>
|
|
44
61
|
</div>
|
|
45
62
|
</div>
|
|
46
63
|
|
package/ui/styles.css
CHANGED
|
@@ -6,57 +6,65 @@
|
|
|
6
6
|
|
|
7
7
|
/* ---- Dark theme (default) ---- */
|
|
8
8
|
:root {
|
|
9
|
-
--bg: #
|
|
10
|
-
--bg-subtle: #
|
|
11
|
-
--surface: #
|
|
12
|
-
--surface-hover: #
|
|
13
|
-
--surface-raised: #
|
|
14
|
-
--text: #
|
|
15
|
-
--text-dim: #
|
|
16
|
-
--text-faint: #
|
|
17
|
-
--accent: #
|
|
18
|
-
--accent-hover: #
|
|
19
|
-
--accent-
|
|
20
|
-
--
|
|
21
|
-
--yellow
|
|
22
|
-
--
|
|
23
|
-
--green
|
|
24
|
-
--
|
|
25
|
-
--
|
|
26
|
-
--
|
|
27
|
-
--
|
|
28
|
-
--
|
|
29
|
-
--
|
|
30
|
-
--
|
|
31
|
-
--
|
|
32
|
-
--
|
|
33
|
-
--
|
|
34
|
-
--
|
|
9
|
+
--bg: #0c0e14;
|
|
10
|
+
--bg-subtle: #12141c;
|
|
11
|
+
--surface: #171a24;
|
|
12
|
+
--surface-hover: #1e2130;
|
|
13
|
+
--surface-raised: #1c1f2c;
|
|
14
|
+
--text: #d8dce8;
|
|
15
|
+
--text-dim: #6e7490;
|
|
16
|
+
--text-faint: #464c64;
|
|
17
|
+
--accent: #d4a554;
|
|
18
|
+
--accent-hover: #e2b96c;
|
|
19
|
+
--accent-muted: rgba(212, 165, 84, 0.10);
|
|
20
|
+
--accent-glow: rgba(212, 165, 84, 0.08);
|
|
21
|
+
--yellow: #d4a554;
|
|
22
|
+
--yellow-bg: rgba(212, 165, 84, 0.08);
|
|
23
|
+
--green: #6fbf8a;
|
|
24
|
+
--green-bg: rgba(111, 191, 138, 0.08);
|
|
25
|
+
--red: #d4616e;
|
|
26
|
+
--blue: #6ba3d4;
|
|
27
|
+
--blue-bg: rgba(107, 163, 212, 0.08);
|
|
28
|
+
--border: #222638;
|
|
29
|
+
--border-hover: #2e3348;
|
|
30
|
+
--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
|
|
31
|
+
--shadow-md: 0 4px 20px rgba(0, 0, 0, 0.5);
|
|
32
|
+
--shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.6);
|
|
33
|
+
--shadow-glow: 0 0 24px rgba(212, 165, 84, 0.06);
|
|
34
|
+
--font-mono: "JetBrains Mono", "SF Mono", "Fira Code", "Cascadia Code", monospace;
|
|
35
|
+
--font-sans: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
36
|
+
--radius-sm: 8px;
|
|
37
|
+
--radius-md: 12px;
|
|
38
|
+
--radius-lg: 16px;
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
/* ---- Light theme ---- */
|
|
38
42
|
[data-theme="light"] {
|
|
39
|
-
--bg: #
|
|
40
|
-
--bg-subtle: #
|
|
43
|
+
--bg: #f4f2ee;
|
|
44
|
+
--bg-subtle: #eae7e2;
|
|
41
45
|
--surface: #ffffff;
|
|
42
|
-
--surface-hover: #
|
|
43
|
-
--surface-raised: #
|
|
44
|
-
--text: #
|
|
45
|
-
--text-dim: #
|
|
46
|
-
--text-faint: #
|
|
47
|
-
--accent: #
|
|
48
|
-
--accent-hover: #
|
|
49
|
-
--accent-
|
|
50
|
-
--
|
|
51
|
-
--yellow
|
|
52
|
-
--
|
|
53
|
-
--green
|
|
54
|
-
--
|
|
55
|
-
--
|
|
56
|
-
--
|
|
57
|
-
--
|
|
58
|
-
--
|
|
59
|
-
--
|
|
46
|
+
--surface-hover: #f8f6f3;
|
|
47
|
+
--surface-raised: #faf9f7;
|
|
48
|
+
--text: #1c1e26;
|
|
49
|
+
--text-dim: #6b6e7a;
|
|
50
|
+
--text-faint: #9a9ca8;
|
|
51
|
+
--accent: #b07d2e;
|
|
52
|
+
--accent-hover: #c48e38;
|
|
53
|
+
--accent-muted: rgba(176, 125, 46, 0.08);
|
|
54
|
+
--accent-glow: rgba(176, 125, 46, 0.06);
|
|
55
|
+
--yellow: #b07d2e;
|
|
56
|
+
--yellow-bg: rgba(176, 125, 46, 0.06);
|
|
57
|
+
--green: #3a8a58;
|
|
58
|
+
--green-bg: rgba(58, 138, 88, 0.06);
|
|
59
|
+
--red: #c04050;
|
|
60
|
+
--blue: #3a72a0;
|
|
61
|
+
--blue-bg: rgba(58, 114, 160, 0.06);
|
|
62
|
+
--border: #ddd9d3;
|
|
63
|
+
--border-hover: #c8c4be;
|
|
64
|
+
--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
|
|
65
|
+
--shadow-md: 0 4px 20px rgba(0, 0, 0, 0.06);
|
|
66
|
+
--shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.08);
|
|
67
|
+
--shadow-glow: 0 0 24px rgba(176, 125, 46, 0.04);
|
|
60
68
|
}
|
|
61
69
|
|
|
62
70
|
body {
|
|
@@ -67,33 +75,81 @@ body {
|
|
|
67
75
|
display: flex;
|
|
68
76
|
flex-direction: column;
|
|
69
77
|
overflow: hidden;
|
|
70
|
-
transition: background 0.
|
|
78
|
+
transition: background 0.4s ease, color 0.4s ease;
|
|
79
|
+
-webkit-font-smoothing: antialiased;
|
|
80
|
+
-moz-osx-font-smoothing: grayscale;
|
|
71
81
|
}
|
|
72
82
|
|
|
73
83
|
/* ---- Header ---- */
|
|
74
84
|
header {
|
|
75
85
|
display: flex;
|
|
76
86
|
align-items: center;
|
|
77
|
-
|
|
78
|
-
padding: 0
|
|
79
|
-
height:
|
|
87
|
+
justify-content: space-between;
|
|
88
|
+
padding: 0 24px;
|
|
89
|
+
height: 56px;
|
|
80
90
|
background: var(--surface);
|
|
81
91
|
border-bottom: 1px solid var(--border);
|
|
82
92
|
flex-shrink: 0;
|
|
83
|
-
transition: background 0.
|
|
93
|
+
transition: background 0.4s ease, border-color 0.4s ease;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.header-left {
|
|
97
|
+
display: flex;
|
|
98
|
+
align-items: center;
|
|
99
|
+
gap: 16px;
|
|
100
|
+
flex: 1;
|
|
101
|
+
min-width: 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.header-right {
|
|
105
|
+
display: flex;
|
|
106
|
+
align-items: center;
|
|
107
|
+
gap: 14px;
|
|
108
|
+
flex-shrink: 0;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.header-divider {
|
|
112
|
+
width: 1px;
|
|
113
|
+
height: 20px;
|
|
114
|
+
background: var(--border);
|
|
115
|
+
flex-shrink: 0;
|
|
84
116
|
}
|
|
85
117
|
|
|
86
118
|
header h1 {
|
|
87
|
-
font-size:
|
|
88
|
-
font-weight:
|
|
89
|
-
color: var(--
|
|
90
|
-
letter-spacing: -0.
|
|
119
|
+
font-size: 14px;
|
|
120
|
+
font-weight: 600;
|
|
121
|
+
color: var(--text);
|
|
122
|
+
letter-spacing: -0.3px;
|
|
91
123
|
user-select: none;
|
|
124
|
+
white-space: nowrap;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.logo-mark {
|
|
128
|
+
color: var(--accent);
|
|
129
|
+
font-weight: 700;
|
|
130
|
+
font-family: var(--font-mono);
|
|
131
|
+
font-size: 13px;
|
|
132
|
+
letter-spacing: -1px;
|
|
133
|
+
margin-right: 1px;
|
|
92
134
|
}
|
|
93
135
|
|
|
94
136
|
/* File picker */
|
|
95
137
|
.file-picker {
|
|
96
138
|
position: relative;
|
|
139
|
+
display: flex;
|
|
140
|
+
align-items: center;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.file-picker-icon {
|
|
144
|
+
position: absolute;
|
|
145
|
+
left: 10px;
|
|
146
|
+
color: var(--text-faint);
|
|
147
|
+
pointer-events: none;
|
|
148
|
+
transition: color 0.2s;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.file-picker:focus-within .file-picker-icon {
|
|
152
|
+
color: var(--accent);
|
|
97
153
|
}
|
|
98
154
|
|
|
99
155
|
.file-picker input {
|
|
@@ -103,10 +159,10 @@ header h1 {
|
|
|
103
159
|
background: var(--bg);
|
|
104
160
|
border: 1px solid var(--border);
|
|
105
161
|
border-radius: var(--radius-sm);
|
|
106
|
-
padding:
|
|
107
|
-
width:
|
|
162
|
+
padding: 7px 12px 7px 32px;
|
|
163
|
+
width: 240px;
|
|
108
164
|
outline: none;
|
|
109
|
-
transition: border-color 0.2s, box-shadow 0.2s, background 0.
|
|
165
|
+
transition: border-color 0.2s, box-shadow 0.2s, background 0.4s ease;
|
|
110
166
|
}
|
|
111
167
|
|
|
112
168
|
.file-picker input:focus {
|
|
@@ -120,23 +176,36 @@ header h1 {
|
|
|
120
176
|
|
|
121
177
|
.file-path {
|
|
122
178
|
font-family: var(--font-mono);
|
|
123
|
-
font-size:
|
|
124
|
-
color: var(--text-
|
|
179
|
+
font-size: 11.5px;
|
|
180
|
+
color: var(--text-faint);
|
|
125
181
|
flex: 1;
|
|
126
182
|
overflow: hidden;
|
|
127
183
|
text-overflow: ellipsis;
|
|
128
184
|
white-space: nowrap;
|
|
185
|
+
letter-spacing: 0.2px;
|
|
129
186
|
}
|
|
130
187
|
|
|
131
188
|
/* Status badge */
|
|
132
189
|
.status {
|
|
190
|
+
display: flex;
|
|
191
|
+
align-items: center;
|
|
192
|
+
gap: 6px;
|
|
133
193
|
font-size: 11px;
|
|
134
194
|
font-weight: 500;
|
|
135
|
-
padding:
|
|
195
|
+
padding: 5px 12px;
|
|
136
196
|
border-radius: 100px;
|
|
137
197
|
background: var(--surface-hover);
|
|
138
198
|
color: var(--text-dim);
|
|
139
|
-
transition: all 0.
|
|
199
|
+
transition: all 0.4s ease;
|
|
200
|
+
letter-spacing: 0.1px;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.status-dot {
|
|
204
|
+
width: 6px;
|
|
205
|
+
height: 6px;
|
|
206
|
+
border-radius: 50%;
|
|
207
|
+
background: var(--text-faint);
|
|
208
|
+
transition: background 0.4s ease;
|
|
140
209
|
}
|
|
141
210
|
|
|
142
211
|
.status.connected {
|
|
@@ -144,6 +213,27 @@ header h1 {
|
|
|
144
213
|
background: var(--green-bg);
|
|
145
214
|
}
|
|
146
215
|
|
|
216
|
+
.status.connected .status-dot {
|
|
217
|
+
background: var(--green);
|
|
218
|
+
box-shadow: 0 0 6px rgba(111, 191, 138, 0.5);
|
|
219
|
+
animation: pulse-dot 2.5s ease-in-out infinite;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
@keyframes pulse-dot {
|
|
223
|
+
0%, 100% { opacity: 1; }
|
|
224
|
+
50% { opacity: 0.5; }
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/* Toggle label */
|
|
228
|
+
.toggle-label {
|
|
229
|
+
font-size: 11px;
|
|
230
|
+
font-weight: 500;
|
|
231
|
+
color: var(--text-faint);
|
|
232
|
+
user-select: none;
|
|
233
|
+
letter-spacing: 0.2px;
|
|
234
|
+
min-width: 30px;
|
|
235
|
+
}
|
|
236
|
+
|
|
147
237
|
/* ---- Theme toggle ---- */
|
|
148
238
|
.theme-toggle {
|
|
149
239
|
position: relative;
|
|
@@ -165,7 +255,7 @@ header h1 {
|
|
|
165
255
|
inset: 0;
|
|
166
256
|
background: var(--border);
|
|
167
257
|
border-radius: 100px;
|
|
168
|
-
transition: background 0.3s;
|
|
258
|
+
transition: background 0.3s ease;
|
|
169
259
|
}
|
|
170
260
|
|
|
171
261
|
.theme-toggle input:checked + .toggle-track {
|
|
@@ -178,12 +268,13 @@ header h1 {
|
|
|
178
268
|
left: 3px;
|
|
179
269
|
width: 18px;
|
|
180
270
|
height: 18px;
|
|
181
|
-
background: var(--
|
|
271
|
+
background: var(--bg);
|
|
182
272
|
border-radius: 50%;
|
|
183
273
|
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s;
|
|
184
274
|
display: flex;
|
|
185
275
|
align-items: center;
|
|
186
276
|
justify-content: center;
|
|
277
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
|
|
187
278
|
}
|
|
188
279
|
|
|
189
280
|
.theme-toggle input:checked + .toggle-track .toggle-thumb {
|
|
@@ -207,28 +298,35 @@ main {
|
|
|
207
298
|
.content-panel {
|
|
208
299
|
flex: 1;
|
|
209
300
|
overflow-y: auto;
|
|
210
|
-
padding:
|
|
301
|
+
padding: 36px 48px;
|
|
211
302
|
}
|
|
212
303
|
|
|
213
304
|
#fileContent {
|
|
214
|
-
max-width:
|
|
305
|
+
max-width: 760px;
|
|
215
306
|
margin: 0 auto;
|
|
216
|
-
line-height: 1.
|
|
307
|
+
line-height: 1.8;
|
|
308
|
+
animation: fade-in 0.3s ease;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
@keyframes fade-in {
|
|
312
|
+
from { opacity: 0; transform: translateY(4px); }
|
|
313
|
+
to { opacity: 1; transform: translateY(0); }
|
|
217
314
|
}
|
|
218
315
|
|
|
219
316
|
/* ---- Markdown styles ---- */
|
|
220
317
|
.markdown-body h1, .markdown-body h2, .markdown-body h3,
|
|
221
318
|
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
|
|
222
|
-
margin: 1.
|
|
319
|
+
margin: 1.5em 0 0.6em;
|
|
223
320
|
font-weight: 600;
|
|
224
321
|
color: var(--text);
|
|
225
322
|
line-height: 1.3;
|
|
323
|
+
letter-spacing: -0.3px;
|
|
226
324
|
}
|
|
227
325
|
|
|
228
326
|
.markdown-body h1 {
|
|
229
327
|
font-size: 1.75em;
|
|
230
328
|
border-bottom: 1px solid var(--border);
|
|
231
|
-
padding-bottom: 0.
|
|
329
|
+
padding-bottom: 0.4em;
|
|
232
330
|
}
|
|
233
331
|
|
|
234
332
|
.markdown-body h2 {
|
|
@@ -245,24 +343,26 @@ main {
|
|
|
245
343
|
|
|
246
344
|
.markdown-body code {
|
|
247
345
|
font-family: var(--font-mono);
|
|
248
|
-
font-size: 0.
|
|
346
|
+
font-size: 0.85em;
|
|
249
347
|
background: var(--surface-hover);
|
|
250
|
-
padding: 2px
|
|
251
|
-
border-radius:
|
|
348
|
+
padding: 2px 8px;
|
|
349
|
+
border-radius: 5px;
|
|
350
|
+
border: 1px solid var(--border);
|
|
252
351
|
}
|
|
253
352
|
|
|
254
353
|
.markdown-body pre {
|
|
255
354
|
background: var(--surface);
|
|
256
|
-
padding:
|
|
355
|
+
padding: 20px;
|
|
257
356
|
border-radius: var(--radius-md);
|
|
258
357
|
overflow-x: auto;
|
|
259
|
-
margin:
|
|
358
|
+
margin: 1.2em 0;
|
|
260
359
|
border: 1px solid var(--border);
|
|
261
360
|
}
|
|
262
361
|
|
|
263
362
|
.markdown-body pre code {
|
|
264
363
|
background: none;
|
|
265
364
|
padding: 0;
|
|
365
|
+
border: none;
|
|
266
366
|
}
|
|
267
367
|
|
|
268
368
|
.markdown-body blockquote {
|
|
@@ -283,7 +383,7 @@ main {
|
|
|
283
383
|
.plain-text {
|
|
284
384
|
font-family: var(--font-mono);
|
|
285
385
|
font-size: 13px;
|
|
286
|
-
line-height: 1.
|
|
386
|
+
line-height: 1.7;
|
|
287
387
|
white-space: pre-wrap;
|
|
288
388
|
word-wrap: break-word;
|
|
289
389
|
color: var(--text);
|
|
@@ -295,7 +395,8 @@ main {
|
|
|
295
395
|
border-bottom: 2px solid var(--yellow);
|
|
296
396
|
cursor: pointer;
|
|
297
397
|
position: relative;
|
|
298
|
-
transition: background 0.
|
|
398
|
+
transition: background 0.2s ease;
|
|
399
|
+
border-radius: 2px;
|
|
299
400
|
}
|
|
300
401
|
|
|
301
402
|
.comment-highlight.resolved {
|
|
@@ -304,35 +405,40 @@ main {
|
|
|
304
405
|
}
|
|
305
406
|
|
|
306
407
|
.comment-highlight:hover {
|
|
307
|
-
background: rgba(
|
|
408
|
+
background: rgba(212, 165, 84, 0.18);
|
|
308
409
|
}
|
|
309
410
|
|
|
310
411
|
[data-theme="light"] .comment-highlight:hover {
|
|
311
|
-
background: rgba(
|
|
412
|
+
background: rgba(176, 125, 46, 0.12);
|
|
312
413
|
}
|
|
313
414
|
|
|
314
415
|
/* ---- Sidebar ---- */
|
|
315
416
|
.sidebar {
|
|
316
|
-
width:
|
|
317
|
-
min-width:
|
|
417
|
+
width: 360px;
|
|
418
|
+
min-width: 360px;
|
|
318
419
|
background: var(--surface);
|
|
319
420
|
border-left: 1px solid var(--border);
|
|
320
421
|
overflow-y: auto;
|
|
321
422
|
display: flex;
|
|
322
423
|
flex-direction: column;
|
|
323
|
-
transition: background 0.
|
|
424
|
+
transition: background 0.4s ease, border-color 0.4s ease;
|
|
324
425
|
}
|
|
325
426
|
|
|
326
|
-
.sidebar
|
|
327
|
-
|
|
328
|
-
font-weight: 600;
|
|
329
|
-
padding: 14px 16px;
|
|
427
|
+
.sidebar-header {
|
|
428
|
+
padding: 16px 20px;
|
|
330
429
|
border-bottom: 1px solid var(--border);
|
|
430
|
+
flex-shrink: 0;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
.sidebar-header h2 {
|
|
434
|
+
font-size: 12px;
|
|
435
|
+
font-weight: 600;
|
|
436
|
+
text-transform: uppercase;
|
|
437
|
+
letter-spacing: 0.8px;
|
|
438
|
+
color: var(--text-dim);
|
|
331
439
|
display: flex;
|
|
332
440
|
align-items: center;
|
|
333
|
-
gap:
|
|
334
|
-
flex-shrink: 0;
|
|
335
|
-
letter-spacing: -0.1px;
|
|
441
|
+
gap: 10px;
|
|
336
442
|
}
|
|
337
443
|
|
|
338
444
|
.comment-count {
|
|
@@ -340,17 +446,18 @@ main {
|
|
|
340
446
|
color: var(--bg);
|
|
341
447
|
font-size: 10px;
|
|
342
448
|
font-weight: 700;
|
|
343
|
-
min-width:
|
|
449
|
+
min-width: 22px;
|
|
344
450
|
text-align: center;
|
|
345
|
-
padding: 2px
|
|
451
|
+
padding: 2px 8px;
|
|
346
452
|
border-radius: 100px;
|
|
347
453
|
transition: background 0.3s;
|
|
454
|
+
letter-spacing: 0;
|
|
348
455
|
}
|
|
349
456
|
|
|
350
457
|
#commentList {
|
|
351
458
|
flex: 1;
|
|
352
459
|
overflow-y: auto;
|
|
353
|
-
padding:
|
|
460
|
+
padding: 10px;
|
|
354
461
|
}
|
|
355
462
|
|
|
356
463
|
/* ---- Comment card ---- */
|
|
@@ -358,49 +465,72 @@ main {
|
|
|
358
465
|
background: var(--bg-subtle);
|
|
359
466
|
border: 1px solid var(--border);
|
|
360
467
|
border-radius: var(--radius-md);
|
|
361
|
-
padding:
|
|
468
|
+
padding: 14px;
|
|
362
469
|
margin-bottom: 8px;
|
|
363
470
|
cursor: pointer;
|
|
364
|
-
transition: border-color 0.2s, box-shadow 0.2s, background 0.
|
|
471
|
+
transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.4s ease, transform 0.2s ease;
|
|
472
|
+
animation: card-enter 0.25s ease both;
|
|
365
473
|
}
|
|
366
474
|
|
|
367
475
|
.comment-card:hover {
|
|
368
476
|
border-color: var(--border-hover);
|
|
369
477
|
box-shadow: var(--shadow-sm);
|
|
478
|
+
transform: translateY(-1px);
|
|
370
479
|
}
|
|
371
480
|
|
|
372
481
|
.comment-card.active {
|
|
373
482
|
border-color: var(--accent);
|
|
374
|
-
box-shadow: 0 0 0 2px var(--accent-glow);
|
|
483
|
+
box-shadow: 0 0 0 2px var(--accent-glow), var(--shadow-glow);
|
|
375
484
|
}
|
|
376
485
|
|
|
377
486
|
.comment-card.resolved {
|
|
378
|
-
opacity: 0.
|
|
487
|
+
opacity: 0.5;
|
|
379
488
|
}
|
|
380
489
|
|
|
381
490
|
.comment-card.resolved:hover {
|
|
382
|
-
opacity: 0.
|
|
491
|
+
opacity: 0.7;
|
|
383
492
|
}
|
|
384
493
|
|
|
494
|
+
@keyframes card-enter {
|
|
495
|
+
from {
|
|
496
|
+
opacity: 0;
|
|
497
|
+
transform: translateY(6px);
|
|
498
|
+
}
|
|
499
|
+
to {
|
|
500
|
+
opacity: 1;
|
|
501
|
+
transform: translateY(0);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
.comment-card:nth-child(1) { animation-delay: 0s; }
|
|
506
|
+
.comment-card:nth-child(2) { animation-delay: 0.04s; }
|
|
507
|
+
.comment-card:nth-child(3) { animation-delay: 0.08s; }
|
|
508
|
+
.comment-card:nth-child(4) { animation-delay: 0.12s; }
|
|
509
|
+
.comment-card:nth-child(5) { animation-delay: 0.16s; }
|
|
510
|
+
.comment-card:nth-child(6) { animation-delay: 0.2s; }
|
|
511
|
+
.comment-card:nth-child(7) { animation-delay: 0.24s; }
|
|
512
|
+
.comment-card:nth-child(8) { animation-delay: 0.28s; }
|
|
513
|
+
|
|
385
514
|
.comment-selected-text {
|
|
386
515
|
font-family: var(--font-mono);
|
|
387
516
|
font-size: 11px;
|
|
388
517
|
color: var(--text-dim);
|
|
389
518
|
background: var(--surface-hover);
|
|
390
|
-
padding:
|
|
519
|
+
padding: 8px 10px;
|
|
391
520
|
border-radius: var(--radius-sm);
|
|
392
|
-
margin-bottom:
|
|
393
|
-
max-height:
|
|
394
|
-
overflow:
|
|
395
|
-
white-space: pre;
|
|
396
|
-
text-overflow: ellipsis;
|
|
521
|
+
margin-bottom: 10px;
|
|
522
|
+
max-height: 88px;
|
|
523
|
+
overflow-y: auto;
|
|
524
|
+
white-space: pre-wrap;
|
|
397
525
|
border-left: 2px solid var(--yellow);
|
|
526
|
+
line-height: 1.5;
|
|
398
527
|
}
|
|
399
528
|
|
|
400
529
|
.comment-text {
|
|
401
530
|
font-size: 13px;
|
|
402
|
-
line-height: 1.
|
|
403
|
-
margin-bottom:
|
|
531
|
+
line-height: 1.55;
|
|
532
|
+
margin-bottom: 10px;
|
|
533
|
+
color: var(--text);
|
|
404
534
|
}
|
|
405
535
|
|
|
406
536
|
.comment-meta {
|
|
@@ -414,10 +544,10 @@ main {
|
|
|
414
544
|
.comment-status {
|
|
415
545
|
font-size: 10px;
|
|
416
546
|
font-weight: 600;
|
|
417
|
-
padding:
|
|
547
|
+
padding: 3px 10px;
|
|
418
548
|
border-radius: 100px;
|
|
419
549
|
text-transform: uppercase;
|
|
420
|
-
letter-spacing: 0.
|
|
550
|
+
letter-spacing: 0.4px;
|
|
421
551
|
}
|
|
422
552
|
|
|
423
553
|
.comment-status.pending {
|
|
@@ -432,21 +562,21 @@ main {
|
|
|
432
562
|
|
|
433
563
|
/* ---- Replies ---- */
|
|
434
564
|
.comment-replies {
|
|
435
|
-
margin-top:
|
|
436
|
-
padding-top:
|
|
565
|
+
margin-top: 12px;
|
|
566
|
+
padding-top: 12px;
|
|
437
567
|
border-top: 1px solid var(--border);
|
|
438
568
|
}
|
|
439
569
|
|
|
440
570
|
.reply {
|
|
441
571
|
font-size: 12px;
|
|
442
|
-
line-height: 1.
|
|
572
|
+
line-height: 1.55;
|
|
443
573
|
margin-bottom: 6px;
|
|
444
|
-
padding: 8px
|
|
574
|
+
padding: 8px 12px;
|
|
445
575
|
border-radius: var(--radius-sm);
|
|
446
576
|
}
|
|
447
577
|
|
|
448
578
|
.reply.user {
|
|
449
|
-
background: var(--accent-
|
|
579
|
+
background: var(--accent-muted);
|
|
450
580
|
}
|
|
451
581
|
|
|
452
582
|
.reply.agent {
|
|
@@ -457,8 +587,8 @@ main {
|
|
|
457
587
|
font-weight: 600;
|
|
458
588
|
font-size: 10px;
|
|
459
589
|
text-transform: uppercase;
|
|
460
|
-
letter-spacing: 0.
|
|
461
|
-
margin-bottom:
|
|
590
|
+
letter-spacing: 0.6px;
|
|
591
|
+
margin-bottom: 4px;
|
|
462
592
|
}
|
|
463
593
|
|
|
464
594
|
.reply-from.user { color: var(--accent); }
|
|
@@ -468,30 +598,31 @@ main {
|
|
|
468
598
|
.comment-actions {
|
|
469
599
|
display: flex;
|
|
470
600
|
gap: 6px;
|
|
471
|
-
margin-top:
|
|
601
|
+
margin-top: 12px;
|
|
472
602
|
}
|
|
473
603
|
|
|
474
604
|
.comment-actions button {
|
|
605
|
+
font-family: var(--font-sans);
|
|
475
606
|
font-size: 11px;
|
|
476
607
|
font-weight: 500;
|
|
477
|
-
padding:
|
|
608
|
+
padding: 6px 14px;
|
|
478
609
|
border-radius: var(--radius-sm);
|
|
479
610
|
border: 1px solid var(--border);
|
|
480
611
|
background: var(--surface);
|
|
481
612
|
color: var(--text-dim);
|
|
482
613
|
cursor: pointer;
|
|
483
|
-
transition: all 0.15s;
|
|
614
|
+
transition: all 0.15s ease;
|
|
484
615
|
}
|
|
485
616
|
|
|
486
617
|
.comment-actions button:hover {
|
|
487
|
-
color: var(--
|
|
618
|
+
color: var(--accent);
|
|
488
619
|
border-color: var(--accent);
|
|
489
620
|
background: var(--accent-glow);
|
|
490
621
|
}
|
|
491
622
|
|
|
492
623
|
/* Reply inline form */
|
|
493
624
|
.reply-form {
|
|
494
|
-
margin-top:
|
|
625
|
+
margin-top: 10px;
|
|
495
626
|
}
|
|
496
627
|
|
|
497
628
|
.reply-form textarea {
|
|
@@ -502,9 +633,9 @@ main {
|
|
|
502
633
|
color: var(--text);
|
|
503
634
|
border: 1px solid var(--border);
|
|
504
635
|
border-radius: var(--radius-sm);
|
|
505
|
-
padding: 8px
|
|
636
|
+
padding: 8px 12px;
|
|
506
637
|
resize: vertical;
|
|
507
|
-
transition: border-color 0.2s, box-shadow 0.2s, background 0.
|
|
638
|
+
transition: border-color 0.2s, box-shadow 0.2s, background 0.4s ease;
|
|
508
639
|
}
|
|
509
640
|
|
|
510
641
|
.reply-form textarea:focus {
|
|
@@ -520,21 +651,26 @@ main {
|
|
|
520
651
|
}
|
|
521
652
|
|
|
522
653
|
.reply-form-actions button {
|
|
654
|
+
font-family: var(--font-sans);
|
|
523
655
|
font-size: 11px;
|
|
524
656
|
font-weight: 600;
|
|
525
|
-
padding:
|
|
657
|
+
padding: 6px 16px;
|
|
526
658
|
border-radius: var(--radius-sm);
|
|
527
659
|
border: none;
|
|
528
660
|
background: var(--accent);
|
|
529
|
-
color:
|
|
661
|
+
color: var(--bg);
|
|
530
662
|
cursor: pointer;
|
|
531
|
-
transition: background 0.15s;
|
|
663
|
+
transition: background 0.15s ease, transform 0.1s ease;
|
|
532
664
|
}
|
|
533
665
|
|
|
534
666
|
.reply-form-actions button:hover {
|
|
535
667
|
background: var(--accent-hover);
|
|
536
668
|
}
|
|
537
669
|
|
|
670
|
+
.reply-form-actions button:active {
|
|
671
|
+
transform: scale(0.97);
|
|
672
|
+
}
|
|
673
|
+
|
|
538
674
|
/* ---- Comment popup ---- */
|
|
539
675
|
.comment-popup {
|
|
540
676
|
position: fixed;
|
|
@@ -542,10 +678,31 @@ main {
|
|
|
542
678
|
background: var(--surface);
|
|
543
679
|
border: 1px solid var(--border);
|
|
544
680
|
border-radius: var(--radius-lg);
|
|
545
|
-
padding:
|
|
546
|
-
width:
|
|
547
|
-
box-shadow: var(--shadow-lg);
|
|
548
|
-
transition: background 0.
|
|
681
|
+
padding: 18px;
|
|
682
|
+
width: 340px;
|
|
683
|
+
box-shadow: var(--shadow-lg), var(--shadow-glow);
|
|
684
|
+
transition: background 0.4s ease, border-color 0.4s ease;
|
|
685
|
+
animation: popup-enter 0.2s ease;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
@keyframes popup-enter {
|
|
689
|
+
from {
|
|
690
|
+
opacity: 0;
|
|
691
|
+
transform: translateY(4px) scale(0.98);
|
|
692
|
+
}
|
|
693
|
+
to {
|
|
694
|
+
opacity: 1;
|
|
695
|
+
transform: translateY(0) scale(1);
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
.popup-header {
|
|
700
|
+
font-size: 10px;
|
|
701
|
+
font-weight: 600;
|
|
702
|
+
text-transform: uppercase;
|
|
703
|
+
letter-spacing: 0.8px;
|
|
704
|
+
color: var(--text-faint);
|
|
705
|
+
margin-bottom: 6px;
|
|
549
706
|
}
|
|
550
707
|
|
|
551
708
|
.popup-selection {
|
|
@@ -553,14 +710,14 @@ main {
|
|
|
553
710
|
font-size: 11px;
|
|
554
711
|
color: var(--text-dim);
|
|
555
712
|
background: var(--bg);
|
|
556
|
-
padding:
|
|
713
|
+
padding: 10px 12px;
|
|
557
714
|
border-radius: var(--radius-sm);
|
|
558
|
-
margin-bottom:
|
|
559
|
-
max-height:
|
|
560
|
-
overflow:
|
|
561
|
-
white-space: pre;
|
|
562
|
-
text-overflow: ellipsis;
|
|
715
|
+
margin-bottom: 14px;
|
|
716
|
+
max-height: 120px;
|
|
717
|
+
overflow-y: auto;
|
|
718
|
+
white-space: pre-wrap;
|
|
563
719
|
border-left: 2px solid var(--accent);
|
|
720
|
+
line-height: 1.5;
|
|
564
721
|
}
|
|
565
722
|
|
|
566
723
|
.comment-popup textarea {
|
|
@@ -573,7 +730,7 @@ main {
|
|
|
573
730
|
border-radius: var(--radius-sm);
|
|
574
731
|
padding: 10px 12px;
|
|
575
732
|
resize: vertical;
|
|
576
|
-
transition: border-color 0.2s, box-shadow 0.2s, background 0.
|
|
733
|
+
transition: border-color 0.2s, box-shadow 0.2s, background 0.4s ease;
|
|
577
734
|
}
|
|
578
735
|
|
|
579
736
|
.comment-popup textarea:focus {
|
|
@@ -585,29 +742,34 @@ main {
|
|
|
585
742
|
.popup-actions {
|
|
586
743
|
display: flex;
|
|
587
744
|
gap: 8px;
|
|
588
|
-
margin-top:
|
|
745
|
+
margin-top: 14px;
|
|
589
746
|
justify-content: flex-end;
|
|
590
747
|
}
|
|
591
748
|
|
|
592
749
|
.popup-actions button {
|
|
750
|
+
font-family: var(--font-sans);
|
|
593
751
|
font-size: 12px;
|
|
594
752
|
font-weight: 600;
|
|
595
|
-
padding:
|
|
753
|
+
padding: 8px 20px;
|
|
596
754
|
border-radius: var(--radius-sm);
|
|
597
755
|
border: none;
|
|
598
756
|
cursor: pointer;
|
|
599
|
-
transition: all 0.15s;
|
|
757
|
+
transition: all 0.15s ease;
|
|
600
758
|
}
|
|
601
759
|
|
|
602
760
|
.popup-actions button#commentSubmit {
|
|
603
761
|
background: var(--accent);
|
|
604
|
-
color:
|
|
762
|
+
color: var(--bg);
|
|
605
763
|
}
|
|
606
764
|
|
|
607
765
|
.popup-actions button#commentSubmit:hover {
|
|
608
766
|
background: var(--accent-hover);
|
|
609
767
|
}
|
|
610
768
|
|
|
769
|
+
.popup-actions button#commentSubmit:active {
|
|
770
|
+
transform: scale(0.97);
|
|
771
|
+
}
|
|
772
|
+
|
|
611
773
|
.popup-actions button.secondary {
|
|
612
774
|
background: var(--surface-hover);
|
|
613
775
|
color: var(--text-dim);
|
|
@@ -621,7 +783,7 @@ main {
|
|
|
621
783
|
/* ---- Empty state ---- */
|
|
622
784
|
.empty-state {
|
|
623
785
|
text-align: center;
|
|
624
|
-
padding:
|
|
786
|
+
padding: 56px 28px;
|
|
625
787
|
color: var(--text-faint);
|
|
626
788
|
font-size: 13px;
|
|
627
789
|
line-height: 1.7;
|
|
@@ -630,20 +792,21 @@ main {
|
|
|
630
792
|
.empty-state p:first-child {
|
|
631
793
|
font-size: 14px;
|
|
632
794
|
color: var(--text-dim);
|
|
633
|
-
margin-bottom:
|
|
795
|
+
margin-bottom: 6px;
|
|
796
|
+
font-weight: 500;
|
|
634
797
|
}
|
|
635
798
|
|
|
636
799
|
/* ---- Scrollbar ---- */
|
|
637
|
-
::-webkit-scrollbar { width:
|
|
800
|
+
::-webkit-scrollbar { width: 6px; }
|
|
638
801
|
::-webkit-scrollbar-track { background: transparent; }
|
|
639
802
|
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 100px; }
|
|
640
803
|
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
|
|
641
804
|
|
|
642
805
|
/* ---- Selection ---- */
|
|
643
806
|
::selection {
|
|
644
|
-
background: rgba(
|
|
807
|
+
background: rgba(212, 165, 84, 0.25);
|
|
645
808
|
}
|
|
646
809
|
|
|
647
810
|
[data-theme="light"] ::selection {
|
|
648
|
-
background: rgba(
|
|
811
|
+
background: rgba(176, 125, 46, 0.2);
|
|
649
812
|
}
|