@nxxxsooo/opencode-annotate 0.18.0 → 0.19.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/CHANGELOG.md +9 -0
- package/README.md +9 -3
- package/browser/manifest.json +1 -1
- package/package.json +1 -1
- package/review.mjs +75 -11
- package/tui/bin/darwin-arm64/annotate-tui +0 -0
- package/tui/bin/darwin-x64/annotate-tui +0 -0
- package/tui/bin/linux-arm64/annotate-tui +0 -0
- package/tui/bin/linux-x64/annotate-tui +0 -0
- package/tui/bin/win32-x64/annotate-tui.exe +0 -0
- package/tui.ts +8 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.19.0 — Annotate files
|
|
4
|
+
|
|
5
|
+
- Choose **Annotate a file (TUI)** or run `/annotate-file [query]` to find text
|
|
6
|
+
and config files in the current session's directory using OpenCode's `@`
|
|
7
|
+
file search.
|
|
8
|
+
- Pass a supported file path directly to `/annotate` as before. Non-Markdown
|
|
9
|
+
files display as code blocks, preserving their formatting. `.env` and
|
|
10
|
+
credential-looking filenames are excluded.
|
|
11
|
+
|
|
3
12
|
## 0.18.0 — Select page areas
|
|
4
13
|
|
|
5
14
|
- Choose **Select area** in the browser panel and drag a rectangle. Feedback
|
package/README.md
CHANGED
|
@@ -63,15 +63,19 @@ Empty and cancelled reviews submit nothing. Opening a review makes no model call
|
|
|
63
63
|
|
|
64
64
|
For a selection that spans messages, `/annotate-selection` reviews just the selected text.
|
|
65
65
|
|
|
66
|
-
### Review
|
|
66
|
+
### Review text and config files
|
|
67
67
|
|
|
68
68
|
```text
|
|
69
69
|
/annotate docs/plan.md # Review a Markdown document
|
|
70
70
|
/annotate "docs/release plan.md" # Path with spaces
|
|
71
71
|
/annotate ~/Documents/notes.txt # Plain text
|
|
72
|
+
/annotate-file # Pick a file from this session's directory
|
|
73
|
+
/annotate-file settings # Narrow the file search
|
|
72
74
|
```
|
|
73
75
|
|
|
74
|
-
|
|
76
|
+
`/annotate-file` uses OpenCode's `@` file search in the session's directory and its subdirectories, then lets you filter the results in the picker. You can also pass a supported path directly to `/annotate`.
|
|
77
|
+
|
|
78
|
+
Supported files include Markdown, plain text, CSV, logs, JSON, YAML, TOML, XML, and common config files such as `.editorconfig`, `.gitignore`, `Dockerfile`, and `Makefile`. Files must be local UTF-8 and no larger than 2 MiB. `.env` and credential-looking names are excluded. Relative paths resolve against the captured session's working directory; absolute and `~/` paths work too.
|
|
75
79
|
|
|
76
80
|
The reviewer reads a fixed snapshot and does not edit the original file. Feedback includes the original path and snapshot hash, with instructions to re-read the current file before applying suggestions. Document review works even before the session has an assistant reply.
|
|
77
81
|
|
|
@@ -99,6 +103,7 @@ Browser setup is separate from the plugin install. Safari supports local notes a
|
|
|
99
103
|
/annotate docs/plan.md Review a Markdown document
|
|
100
104
|
/annotate "docs/release plan.md" Review a path containing spaces
|
|
101
105
|
/annotate ~/Documents/notes.txt Review a plain-text document
|
|
106
|
+
/annotate-file [query] Choose a text or config file in the session directory
|
|
102
107
|
/annotate-pick Choose a recent reply or mid-turn progress update
|
|
103
108
|
/annotate-selection Review the message containing your last transcript selection
|
|
104
109
|
/annotate page.html Review local HTML in the configured browser
|
|
@@ -211,7 +216,7 @@ After a page reload or same-site navigation, the panel reconnects its page tools
|
|
|
211
216
|
|
|
212
217
|
### Explicit routing
|
|
213
218
|
|
|
214
|
-
Plain `/annotate`, `/annotate-pick` and `/annotate-selection` use the TUI;
|
|
219
|
+
Plain `/annotate`, `/annotate-file`, `/annotate-pick` and `/annotate-selection` use the TUI; text and config paths do too. Explicit URLs and HTML paths passed to `/annotate` enter the browser workflow. A reply containing HTML links or code fences does not change the default.
|
|
215
220
|
|
|
216
221
|
### Browser safeguards and limitations
|
|
217
222
|
|
|
@@ -366,6 +371,7 @@ See [release instructions](docs/releasing.md) and [changelog](CHANGELOG.md).
|
|
|
366
371
|
|
|
367
372
|
- `/annotate`:批注上一条完整回复。
|
|
368
373
|
- `/annotate 文档.md`:批注文档,支持中文、空格和相对路径。
|
|
374
|
+
- `/annotate-file [关键词]`:从当前会话目录及其子目录中选择文本或配置文件。
|
|
369
375
|
- `/annotate-pick`:从最近的回复和运行中的进度说明里选一条批注。
|
|
370
376
|
- `/annotate-selection`:先在会话里拖选文字,再批注包含这段文字的消息。
|
|
371
377
|
- 0.16.0 移除 `/ref` 和代理会话搜索/读取工具,交由 Another 提供跨代理引用:安装 Another 0.28.0 或更高版本并运行 `another setup` 即可。原有插件配置继续有效,请移除 `annotate_session_*` 权限规则。
|
package/browser/manifest.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"manifest_version": 3,
|
|
3
3
|
"name": "OpenCode Annotate",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.19.0",
|
|
5
5
|
"description": "Annotate HTML-based page feedback, private drafts, and paired OpenCode delivery.",
|
|
6
6
|
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp7TG2yzekNKpQvHBtj4jqkOxtoeDIBhNIjPi37Os/ksuhzPp1pHnrJPV4WV2ToatUaD5x5/SpLP8qZKLBD+wuraEE/TeclEZ8HvEs1yhlnx/S7piTG/s0eV5umuTEx2w66Hi0w3dhTC7ZZfJXCLyqs1feBtWzQx6ClgaHNYly4iJ03pV7RfguqpIaG9LV8Oa8ELA+7Ubr0BAujXrSlvqLF5oAKGoXXcpvTL5rgMRIH4Q/85tnvrk0pRVg+1z9IGNzSfjN82iveC/JAriyWABp8YuswtvKfI2Wb+KspaisBh39Y3BRqlyo8I2Cr+01uE6G5pWiJIWMLhe0glrMr5I2wIDAQAB",
|
|
7
7
|
"permissions": ["activeTab", "scripting", "storage", "sidePanel", "nativeMessaging", "clipboardWrite"],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxxxsooo/opencode-annotate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "Unofficial OpenCode annotation plugin: review AI replies and Markdown with a bundled terminal reviewer; annotate webpages with the browser companion.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/review.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { spawn, execFile } from "node:child_process"
|
|
2
2
|
import { createHash, randomUUID } from "node:crypto"
|
|
3
|
-
import { mkdtemp, mkdir, readFile, readdir, rm, stat, writeFile } from "node:fs/promises"
|
|
3
|
+
import { mkdtemp, mkdir, readFile, readdir, realpath, rm, stat, writeFile } from "node:fs/promises"
|
|
4
4
|
import os from "node:os"
|
|
5
5
|
import path from "node:path"
|
|
6
6
|
import { promisify } from "node:util"
|
|
@@ -12,23 +12,61 @@ import { createInputSource } from "./input-source.mjs"
|
|
|
12
12
|
import { resolveTuiBinary } from "./tui/binary.mjs"
|
|
13
13
|
|
|
14
14
|
const execute = promisify(execFile)
|
|
15
|
-
const
|
|
15
|
+
const markdownExtensions = new Set(["md", "mdx", "markdown"])
|
|
16
|
+
const documentLanguages = new Set([
|
|
17
|
+
"txt", "rst", "adoc", "org", "tex", "csv", "tsv", "log",
|
|
18
|
+
"json", "jsonc", "json5", "yaml", "yml", "toml", "ini", "cfg", "conf", "properties", "xml", "plist",
|
|
19
|
+
])
|
|
20
|
+
const documentNames = new Map([
|
|
21
|
+
[".editorconfig", "ini"], [".gitignore", "text"], [".gitattributes", "text"],
|
|
22
|
+
[".dockerignore", "text"], ["dockerfile", "dockerfile"], ["makefile", "makefile"],
|
|
23
|
+
])
|
|
24
|
+
const languageAliases = { txt: "text", log: "text", yml: "yaml", plist: "xml" }
|
|
16
25
|
const maxDocumentBytes = 2 * 1024 * 1024
|
|
17
26
|
|
|
27
|
+
function documentLanguage(file) {
|
|
28
|
+
const name = path.basename(file).toLowerCase()
|
|
29
|
+
if (name.startsWith(".env") ||
|
|
30
|
+
/(?:^|[._-])(?:credentials?|secrets?|passwords?|private[._-]?keys?|id_(?:rsa|dsa|ecdsa|ed25519)|pem|key|p12|pfx|ppk)(?:[._-]|$)/.test(name)) return
|
|
31
|
+
const extension = path.extname(name).slice(1)
|
|
32
|
+
if (markdownExtensions.has(extension)) return "markdown"
|
|
33
|
+
if (documentLanguages.has(extension)) return languageAliases[extension] ?? extension
|
|
34
|
+
return documentNames.get(name)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function sessionDirectory(client, sessionID, signal) {
|
|
38
|
+
const session = await client.session.get({ sessionID }, { signal })
|
|
39
|
+
const directory = session.location?.directory
|
|
40
|
+
if (!directory) throw new Error("Can't determine the current session's working directory.")
|
|
41
|
+
return directory
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function documentSnapshot(text, language) {
|
|
45
|
+
if (language === "markdown") return text
|
|
46
|
+
// Let the Markdown reviewer display the source literally, even if it contains fences.
|
|
47
|
+
let length = 3
|
|
48
|
+
for (const run of text.matchAll(/`{3,}/g)) length = Math.max(length, run[0].length + 1)
|
|
49
|
+
const fence = "`".repeat(length)
|
|
50
|
+
return `${fence}${language}\n${text}${text.endsWith("\n") ? "" : "\n"}${fence}\n`
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function withinDirectory(directory, file) {
|
|
54
|
+
const relative = path.relative(directory, file)
|
|
55
|
+
return relative && !path.isAbsolute(relative) && relative !== ".." && !relative.startsWith(`..${path.sep}`)
|
|
56
|
+
}
|
|
57
|
+
|
|
18
58
|
async function documentSource(input, client, sessionID, signal) {
|
|
19
59
|
let target = input.trim()
|
|
20
60
|
if ((target.startsWith('"') && target.endsWith('"')) || (target.startsWith("'") && target.endsWith("'"))) {
|
|
21
61
|
target = target.slice(1, -1)
|
|
22
62
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
63
|
+
const language = documentLanguage(target)
|
|
64
|
+
if (!language) throw new Error("Choose a supported text or config file. Credential files are excluded.")
|
|
26
65
|
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(target)) throw new Error("Use a local file path.")
|
|
27
66
|
if (target.startsWith("~/")) target = path.join(os.homedir(), target.slice(2))
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const filePath = path.isAbsolute(target) ? path.normalize(target) : path.resolve(directory, target)
|
|
67
|
+
const filePath = path.isAbsolute(target)
|
|
68
|
+
? path.normalize(target)
|
|
69
|
+
: path.resolve(await sessionDirectory(client, sessionID, signal), target)
|
|
32
70
|
try {
|
|
33
71
|
const info = await stat(filePath)
|
|
34
72
|
if (!info.isFile()) throw new Error("The target is not a file.")
|
|
@@ -43,7 +81,7 @@ async function documentSource(input, client, sessionID, signal) {
|
|
|
43
81
|
throw new Error("Use a UTF-8 text file.")
|
|
44
82
|
}
|
|
45
83
|
return {
|
|
46
|
-
text, filePath,
|
|
84
|
+
text: documentSnapshot(text, language), filePath,
|
|
47
85
|
sourceHash: createHash("sha256").update(bytes).digest("hex"),
|
|
48
86
|
snapshot: path.join("source", path.basename(filePath)),
|
|
49
87
|
}
|
|
@@ -373,6 +411,32 @@ export function createReviewCommand(context, options = {}) {
|
|
|
373
411
|
return texts.find(text => text.id === chosen)
|
|
374
412
|
})
|
|
375
413
|
|
|
414
|
+
const file = (query = "") => start(async ({ sessionID, signal }) => {
|
|
415
|
+
const directory = await sessionDirectory(context.client, sessionID, signal)
|
|
416
|
+
const { location, data } = await context.client.file.find(
|
|
417
|
+
{ query: query.trim(), type: "file", limit: 200, location: { directory } }, { signal },
|
|
418
|
+
)
|
|
419
|
+
if (signal.aborted) return
|
|
420
|
+
const options = data.flatMap(entry => {
|
|
421
|
+
if (entry.type !== "file" || path.isAbsolute(entry.path) || !documentLanguage(entry.path)) return []
|
|
422
|
+
const value = path.resolve(location.directory, entry.path)
|
|
423
|
+
if (!withinDirectory(directory, value)) return []
|
|
424
|
+
return [{ title: entry.path, value, description: path.dirname(entry.path) }]
|
|
425
|
+
})
|
|
426
|
+
if (!options.length) {
|
|
427
|
+
notice("No eligible text or config files found in this session's directory.")
|
|
428
|
+
return
|
|
429
|
+
}
|
|
430
|
+
const chosen = await context.ui.dialog.select({ title: "Annotate file", options })
|
|
431
|
+
if (chosen === undefined || signal.aborted) return
|
|
432
|
+
// The search result is a relative name, but a symlink can still leave the tree.
|
|
433
|
+
const [root, resolved] = await Promise.all([realpath(directory), realpath(chosen)])
|
|
434
|
+
if (!withinDirectory(root, resolved) || !documentLanguage(resolved)) {
|
|
435
|
+
throw new Error("Choose a supported text or config file inside this session's directory.")
|
|
436
|
+
}
|
|
437
|
+
return documentSource(chosen, context.client, sessionID, signal)
|
|
438
|
+
})
|
|
439
|
+
|
|
376
440
|
const annotateSelection = () => start(async ({ sessionID, signal }) => {
|
|
377
441
|
const selected = selection?.sessionID === sessionID ? selection.text : ""
|
|
378
442
|
const needle = compact(selected)
|
|
@@ -385,7 +449,7 @@ export function createReviewCommand(context, options = {}) {
|
|
|
385
449
|
})
|
|
386
450
|
|
|
387
451
|
return {
|
|
388
|
-
run, auto, pick, selection: annotateSelection, webReady: web.ready,
|
|
452
|
+
run, auto, pick, file, selection: annotateSelection, webReady: web.ready,
|
|
389
453
|
dispose() {
|
|
390
454
|
context.renderer.off("selection", remember)
|
|
391
455
|
disposed = true
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/tui.ts
CHANGED
|
@@ -49,6 +49,14 @@ export default Plugin.define({
|
|
|
49
49
|
palette: true,
|
|
50
50
|
slash: { name: "annotate", arguments: true },
|
|
51
51
|
run: review.run,
|
|
52
|
+
}, {
|
|
53
|
+
id: "opencode-annotate.annotate-file",
|
|
54
|
+
title: "Annotate a file (TUI)",
|
|
55
|
+
description: "Choose a text or config file in this session's directory",
|
|
56
|
+
group: "Annotate",
|
|
57
|
+
palette: true,
|
|
58
|
+
slash: { name: "annotate-file", arguments: true },
|
|
59
|
+
run: review.file,
|
|
52
60
|
}, {
|
|
53
61
|
id: "opencode-annotate.annotate-pick",
|
|
54
62
|
title: "Annotate earlier text (TUI)",
|