md-annotator 0.5.7 → 0.6.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 +1 -0
- package/client/dist/index.html +334 -332
- package/client/src/utils/parser.js +1 -1
- package/package.json +1 -1
- package/server/feedback.js +2 -2
- package/server/routes.js +11 -0
- package/server/workspace.js +43 -0
package/package.json
CHANGED
package/server/feedback.js
CHANGED
|
@@ -50,13 +50,13 @@ function formatAnnotation(ann, block, heading) {
|
|
|
50
50
|
} else if (ann.type === 'COMMENT') {
|
|
51
51
|
output += `Comment on (${lineRef})\n`
|
|
52
52
|
output += `\`\`\`\n${ann.originalText}\n\`\`\`\n`
|
|
53
|
-
output += `> ${ann.text.replace(/\n/g, '\n> ')}\n`
|
|
53
|
+
output += `> ${(ann.text ?? '').replace(/\n/g, '\n> ')}\n`
|
|
54
54
|
} else if (ann.type === 'INSERTION') {
|
|
55
55
|
output += `Insert text (${lineRef})\n`
|
|
56
56
|
if (ann.afterContext) {
|
|
57
57
|
output += `After: \`${ann.afterContext}\`\n`
|
|
58
58
|
}
|
|
59
|
-
output += `\`\`\`\n${ann.text}\n\`\`\`\n`
|
|
59
|
+
output += `\`\`\`\n${ann.text ?? ''}\n\`\`\`\n`
|
|
60
60
|
output += `> User wants this text inserted at this point in the document.\n`
|
|
61
61
|
}
|
|
62
62
|
|
package/server/routes.js
CHANGED
|
@@ -3,6 +3,7 @@ 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'
|
|
6
7
|
|
|
7
8
|
function success(data) {
|
|
8
9
|
return { success: true, data }
|
|
@@ -15,6 +16,16 @@ function failure(error) {
|
|
|
15
16
|
export function createApiRouter(filePaths, resolveDecision, origin = 'cli', stores = []) {
|
|
16
17
|
const router = Router()
|
|
17
18
|
|
|
19
|
+
// Workspace file listing for @-reference autocomplete
|
|
20
|
+
router.get('/api/workspace/files', async (_req, res) => {
|
|
21
|
+
try {
|
|
22
|
+
const files = await listWorkspaceFiles()
|
|
23
|
+
res.json(success({ files }))
|
|
24
|
+
} catch (error) {
|
|
25
|
+
res.status(500).json(failure(error.message))
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
|
|
18
29
|
// Multi-file endpoint — returns all files
|
|
19
30
|
router.get('/api/files', async (_req, res) => {
|
|
20
31
|
try {
|
|
@@ -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
|
+
}
|