md-annotator 0.5.8 → 0.7.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/README.md +13 -5
- package/client/dist/index.html +627 -441
- package/client/src/utils/parser.js +1 -1
- package/package.json +3 -1
- package/server/config.js +18 -0
- package/server/feedback.js +20 -4
- package/server/routes.js +13 -1
- package/server/workspace.js +43 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "md-annotator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Browser-based Markdown annotator for AI-assisted review",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -41,6 +41,8 @@
|
|
|
41
41
|
"highlight.js": "^11.11.0",
|
|
42
42
|
"mermaid": "^11.12.3",
|
|
43
43
|
"open": "^10.1.0",
|
|
44
|
+
"pako": "^2.1.0",
|
|
45
|
+
"plantuml-encoder": "^1.4.0",
|
|
44
46
|
"portfinder": "^1.0.32",
|
|
45
47
|
"react": "^19.0.0",
|
|
46
48
|
"react-dom": "^19.0.0",
|
package/server/config.js
CHANGED
|
@@ -27,10 +27,28 @@ function getHeartbeatTimeoutMs() {
|
|
|
27
27
|
return DEFAULT_HEARTBEAT_TIMEOUT_MS
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
function getPlantumlServerUrl() {
|
|
31
|
+
const envUrl = process.env.PLANTUML_SERVER_URL
|
|
32
|
+
if (envUrl) {
|
|
33
|
+
return envUrl.replace(/\/+$/, '')
|
|
34
|
+
}
|
|
35
|
+
return 'https://www.plantuml.com/plantuml'
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function getKrokiServerUrl() {
|
|
39
|
+
const envUrl = process.env.KROKI_SERVER_URL
|
|
40
|
+
if (envUrl) {
|
|
41
|
+
return envUrl.replace(/\/+$/, '')
|
|
42
|
+
}
|
|
43
|
+
return 'https://kroki.io'
|
|
44
|
+
}
|
|
45
|
+
|
|
30
46
|
export const config = {
|
|
31
47
|
port: getServerPort(),
|
|
32
48
|
browser: process.env.MD_ANNOTATOR_BROWSER || null,
|
|
33
49
|
heartbeatTimeoutMs: getHeartbeatTimeoutMs(),
|
|
34
50
|
forceExitTimeoutMs: 5000,
|
|
35
51
|
jsonLimit: '10mb',
|
|
52
|
+
plantumlServerUrl: getPlantumlServerUrl(),
|
|
53
|
+
krokiServerUrl: getKrokiServerUrl(),
|
|
36
54
|
}
|
package/server/feedback.js
CHANGED
|
@@ -20,11 +20,27 @@ function formatAnnotation(ann, block, heading) {
|
|
|
20
20
|
return output + '\n'
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
if (ann.targetType === 'pinpoint') {
|
|
24
|
+
const isDeletion = ann.type === 'DELETION'
|
|
25
|
+
const label = isDeletion ? 'Remove block' : 'Comment on block'
|
|
26
|
+
let output = `${heading} ${label} (Line ${blockStartLine})\n`
|
|
27
|
+
const preview = (block?.content || ann.originalText || '').slice(0, 200)
|
|
28
|
+
output += `\`\`\`\n${preview}\n\`\`\`\n`
|
|
29
|
+
if (isDeletion) {
|
|
30
|
+
output += `> User wants this block removed from the document.\n`
|
|
31
|
+
} else {
|
|
32
|
+
output += `> ${(ann.text ?? '').replace(/\n/g, '\n> ')}\n`
|
|
33
|
+
}
|
|
34
|
+
return output + '\n'
|
|
35
|
+
}
|
|
36
|
+
|
|
23
37
|
if (ann.targetType === 'diagram') {
|
|
24
38
|
const isDeletion = ann.type === 'DELETION'
|
|
25
|
-
const
|
|
39
|
+
const diagramLang = block?.language === 'plantuml' ? 'PlantUML' : 'Mermaid'
|
|
40
|
+
const fence = block?.language === 'plantuml' ? 'plantuml' : 'mermaid'
|
|
41
|
+
const label = isDeletion ? `Remove ${diagramLang} diagram` : `Comment on ${diagramLang} diagram`
|
|
26
42
|
let output = `${heading} ${label} (Line ${blockStartLine})\n`
|
|
27
|
-
output +=
|
|
43
|
+
output += `\`\`\`${fence}\n${block?.content || ann.originalText}\n\`\`\`\n`
|
|
28
44
|
if (isDeletion) {
|
|
29
45
|
output += `> User wants this diagram removed from the document.\n`
|
|
30
46
|
} else {
|
|
@@ -50,13 +66,13 @@ function formatAnnotation(ann, block, heading) {
|
|
|
50
66
|
} else if (ann.type === 'COMMENT') {
|
|
51
67
|
output += `Comment on (${lineRef})\n`
|
|
52
68
|
output += `\`\`\`\n${ann.originalText}\n\`\`\`\n`
|
|
53
|
-
output += `> ${ann.text.replace(/\n/g, '\n> ')}\n`
|
|
69
|
+
output += `> ${(ann.text ?? '').replace(/\n/g, '\n> ')}\n`
|
|
54
70
|
} else if (ann.type === 'INSERTION') {
|
|
55
71
|
output += `Insert text (${lineRef})\n`
|
|
56
72
|
if (ann.afterContext) {
|
|
57
73
|
output += `After: \`${ann.afterContext}\`\n`
|
|
58
74
|
}
|
|
59
|
-
output += `\`\`\`\n${ann.text}\n\`\`\`\n`
|
|
75
|
+
output += `\`\`\`\n${ann.text ?? ''}\n\`\`\`\n`
|
|
60
76
|
output += `> User wants this text inserted at this point in the document.\n`
|
|
61
77
|
}
|
|
62
78
|
|
package/server/routes.js
CHANGED
|
@@ -3,6 +3,8 @@ import { relative, resolve, dirname, isAbsolute } from 'node:path'
|
|
|
3
3
|
import { createHash } from 'node:crypto'
|
|
4
4
|
import { readMarkdownFile, isMarkdownFile } from './file.js'
|
|
5
5
|
import { exportFeedback, exportMultiFileFeedback } from './feedback.js'
|
|
6
|
+
import { listWorkspaceFiles } from './workspace.js'
|
|
7
|
+
import { config } from './config.js'
|
|
6
8
|
|
|
7
9
|
function success(data) {
|
|
8
10
|
return { success: true, data }
|
|
@@ -15,6 +17,16 @@ function failure(error) {
|
|
|
15
17
|
export function createApiRouter(filePaths, resolveDecision, origin = 'cli', stores = []) {
|
|
16
18
|
const router = Router()
|
|
17
19
|
|
|
20
|
+
// Workspace file listing for @-reference autocomplete
|
|
21
|
+
router.get('/api/workspace/files', async (_req, res) => {
|
|
22
|
+
try {
|
|
23
|
+
const files = await listWorkspaceFiles()
|
|
24
|
+
res.json(success({ files }))
|
|
25
|
+
} catch (error) {
|
|
26
|
+
res.status(500).json(failure(error.message))
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
|
|
18
30
|
// Multi-file endpoint — returns all files
|
|
19
31
|
router.get('/api/files', async (_req, res) => {
|
|
20
32
|
try {
|
|
@@ -32,7 +44,7 @@ export function createApiRouter(filePaths, resolveDecision, origin = 'cli', stor
|
|
|
32
44
|
}
|
|
33
45
|
})
|
|
34
46
|
)
|
|
35
|
-
res.json(success({ files, origin }))
|
|
47
|
+
res.json(success({ files, origin, config: { plantumlServerUrl: config.plantumlServerUrl, krokiServerUrl: config.krokiServerUrl } }))
|
|
36
48
|
} catch (error) {
|
|
37
49
|
res.status(500).json(failure(error.message))
|
|
38
50
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process'
|
|
2
|
+
import { readdir } from 'node:fs/promises'
|
|
3
|
+
import { relative, join } from 'node:path'
|
|
4
|
+
|
|
5
|
+
const MAX_FILES = 5000
|
|
6
|
+
const EXCLUDE_DIRS = new Set([
|
|
7
|
+
'node_modules', '.git', 'dist', 'build', 'coverage',
|
|
8
|
+
'__pycache__', '.next', '.cache', '.turbo', '.output'
|
|
9
|
+
])
|
|
10
|
+
|
|
11
|
+
function gitListFiles(cwd) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
execFile('git', ['ls-files'], { cwd, maxBuffer: 10 * 1024 * 1024, timeout: 10_000 }, (err, stdout) => {
|
|
14
|
+
if (err) { return reject(err) }
|
|
15
|
+
const files = stdout.split('\n').filter(Boolean)
|
|
16
|
+
resolve(files.slice(0, MAX_FILES))
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function fallbackListFiles(cwd) {
|
|
22
|
+
const entries = await readdir(cwd, { recursive: true, withFileTypes: true })
|
|
23
|
+
const files = []
|
|
24
|
+
for (const entry of entries) {
|
|
25
|
+
if (!entry.isFile()) { continue }
|
|
26
|
+
const parentPath = entry.parentPath || entry.path
|
|
27
|
+
const rel = relative(cwd, join(parentPath, entry.name))
|
|
28
|
+
const parts = rel.split('/')
|
|
29
|
+
if (parts.some(p => EXCLUDE_DIRS.has(p))) { continue }
|
|
30
|
+
files.push(rel)
|
|
31
|
+
if (files.length >= MAX_FILES) { break }
|
|
32
|
+
}
|
|
33
|
+
return files.sort()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function listWorkspaceFiles() {
|
|
37
|
+
const cwd = process.cwd()
|
|
38
|
+
try {
|
|
39
|
+
return await gitListFiles(cwd)
|
|
40
|
+
} catch {
|
|
41
|
+
return await fallbackListFiles(cwd)
|
|
42
|
+
}
|
|
43
|
+
}
|