@nxxxsooo/opencode-annotate 0.16.0 → 0.16.1
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 +11 -3
- package/README.md +9 -4
- package/browser/capture.js +31 -10
- package/browser/inspector.js +12 -2
- package/browser/manifest.json +1 -1
- package/browser/panel.mjs +1 -1
- package/browser/protocol.mjs +3 -2
- package/browser/worker.mjs +60 -25
- package/package.json +1 -1
- 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/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.16.1 — picking inside frames
|
|
4
|
+
|
|
5
|
+
- Fix picking and text selection inside same-origin iframes, legacy framesets and
|
|
6
|
+
nested frames. Reveal and page markers find notes in frames after a reload.
|
|
7
|
+
- Record each note's frame in a `Frame:` line in delivered Markdown. Cross-origin
|
|
8
|
+
frames show a clear message instead of silently failing to pick.
|
|
9
|
+
- Browser protocol 7 requires matching companion files: reload the Chrome extension
|
|
10
|
+
and restart OpenCode after updating.
|
|
11
|
+
|
|
3
12
|
## 0.16.0 — /ref moves to Another
|
|
4
13
|
|
|
5
14
|
- **Breaking:** remove `/ref`, `/ref --all`, `/ref --tui` and the agent session
|
|
6
|
-
search/read tools. Conversation references now belong to Another;
|
|
7
|
-
|
|
8
|
-
Until that release, stay on Annotate 0.15.0 if you need `/ref`.
|
|
15
|
+
search/read tools. Conversation references now belong to Another; Another 0.28.0
|
|
16
|
+
ships a cross-agent `/ref`; install it and run `another setup`.
|
|
9
17
|
- Existing `opencode.json(c)` plugin entries keep working, including option sync.
|
|
10
18
|
Remove any `annotate_session_*` permission rules. Reply, document and webpage
|
|
11
19
|
annotation remain in Annotate.
|
package/README.md
CHANGED
|
@@ -116,9 +116,8 @@ Move its entry from `cli.json` to `opencode.json(c)`, retaining the whole entry
|
|
|
116
116
|
## Upgrading to 0.16.0
|
|
117
117
|
|
|
118
118
|
**Breaking:** `/ref` (including `--all` and `--tui`) and the agent session search/read
|
|
119
|
-
tools have moved out of Annotate to Another.
|
|
120
|
-
|
|
121
|
-
on Annotate 0.15.0 if you need `/ref`.
|
|
119
|
+
tools have moved out of Annotate to Another. Install Another 0.28.0 or later and run
|
|
120
|
+
`another setup` to get its cross-agent `/ref` in OpenCode.
|
|
122
121
|
|
|
123
122
|
Existing `opencode.json(c)` entries and plugin options keep working. Remove any
|
|
124
123
|
`annotate_session_*` permission rules. Annotate continues to review replies,
|
|
@@ -193,6 +192,12 @@ Plain `/annotate`, `/annotate-pick` and `/annotate-selection` use the TUI; Markd
|
|
|
193
192
|
|
|
194
193
|
### Browser safeguards and limitations
|
|
195
194
|
|
|
195
|
+
Picking and text selection work inside same-origin iframes, legacy framesets and
|
|
196
|
+
nested frames. Reveal and page markers can find those notes after reload; delivered
|
|
197
|
+
Markdown includes a `Frame:` line for frame context. Cross-origin frames cannot be
|
|
198
|
+
picked and show a clear message. After updating to 0.16.1 (browser protocol 7), reload
|
|
199
|
+
the Chrome extension and restart OpenCode.
|
|
200
|
+
|
|
196
201
|
Written drafts autosave locally and restore after panel reload or a return to the same URL, including SPA routes. Selecting another target with unfinished feedback offers **Add/Save & switch**, **Keep editing**, or **Discard & switch**. Storage failures keep the input and offer a retry; competing panels require an explicit choice of draft. Saved-note revision checks likewise prevent stale tabs overwriting newer feedback. Full JSON/Markdown exports include redacted URLs, exact selected text/context, verified selector hints, styles and accessibility. Missing/changed/ambiguous targets are labeled in the sidebar instead of silently rebound. Comments and drafts live in extension-owned UI/storage; the page receives only selection metadata and numbered markers, not your written feedback.
|
|
197
202
|
|
|
198
203
|
Native delivery requires an open local TUI and a connected destination. If the receiver closes, feedback stays pending. A failed batch retains its original target and ID for safe retry; if that session is permanently gone, export the notes before starting a new review. **Retry N notes & continue** retries that original batch; newly composed feedback stays local for the next send. Copying a round instead supersedes a failed batch. Clipboard failures expose a selectable preview and keep the round open. Browser-internal pages, PDF, cross-origin iframes, Canvas and remote SSH TUI clients are outside this version's scope. Page Context is retired only after exporting its drafts and verifying this replacement.
|
|
@@ -340,7 +345,7 @@ See [release instructions](docs/releasing.md) and [changelog](CHANGELOG.md).
|
|
|
340
345
|
- `/annotate 文档.md`:批注文档,支持中文、空格和相对路径。
|
|
341
346
|
- `/annotate-pick`:从最近的回复和运行中的进度说明里选一条批注。
|
|
342
347
|
- `/annotate-selection`:先在会话里拖选文字,再批注包含这段文字的消息。
|
|
343
|
-
- 0.16.0 移除 `/ref` 和代理会话搜索/读取工具,交由 Another
|
|
348
|
+
- 0.16.0 移除 `/ref` 和代理会话搜索/读取工具,交由 Another 提供跨代理引用:安装 Another 0.28.0 或更高版本并运行 `another setup` 即可。原有插件配置继续有效,请移除 `annotate_session_*` 权限规则。
|
|
344
349
|
- `/annotate 页面.html`、`/annotate https://…`:打开网页批注。Chrome 自动注册主机和会话,扩展目的地菜单可筛选、新建空会话、断开及重连;Safari 保持仅复制。跨页备注汇成一轮,Send 与 Copy instead 分开,确认发送后自动继续原会话。
|
|
345
350
|
- 选中文字 → `c` 写批注 → Enter 保存 → `q` 发送并返回。
|
|
346
351
|
- 写批注中途按 `Ctrl+S`,一步保存、返回并发送(中文输入法开着也有效);`Ctrl+C` 返回后由 OpenCode 询问。
|
package/browser/capture.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
if (globalThis.__opencodeAnnotate === true) throw new Error("Refresh this page once to update annotation tools. Saved notes will remain.")
|
|
3
|
+
if (globalThis.__opencodeAnnotate?.version === 7) return
|
|
3
4
|
globalThis.__opencodeAnnotate?.dispose()
|
|
4
5
|
if (!["text/html", "application/xhtml+xml"].includes(document.contentType)) throw new Error("Only HTML pages are supported")
|
|
5
6
|
const listeners = new AbortController()
|
|
@@ -15,15 +16,17 @@
|
|
|
15
16
|
const highlight = document.createElement("div"); highlight.className = "box"
|
|
16
17
|
let highlighted, highlightTimer
|
|
17
18
|
let picking = false, url = location.href, timer, markers = [], active = true
|
|
18
|
-
function send(anchor = null, error = null, modeOnly = false) {
|
|
19
|
+
function send(anchor = null, error = null, modeOnly = false, ready = false) {
|
|
19
20
|
if (!active) return
|
|
20
21
|
try {
|
|
21
|
-
chrome.runtime.sendMessage({ action: "capture", page: { url: location.href, title: document.title }, anchor, error, picking, modeOnly }).catch(dispose)
|
|
22
|
+
chrome.runtime.sendMessage({ action: "capture", page: { url: location.href, title: document.title }, frame: AnnotateInspector.frame(), anchor, error, picking, modeOnly, ready }).catch(dispose)
|
|
22
23
|
} catch { dispose() }
|
|
23
24
|
}
|
|
24
25
|
function setPicking(value, notify = true) {
|
|
25
26
|
picking = value
|
|
26
|
-
|
|
27
|
+
// Only a hover over a real element adds the box. Reapplying frame-wide
|
|
28
|
+
// picker state must not resurrect a box hidden at an iframe boundary.
|
|
29
|
+
if (!picking) box.remove()
|
|
27
30
|
if (notify) send(null, null, true)
|
|
28
31
|
}
|
|
29
32
|
function selection() {
|
|
@@ -37,14 +40,29 @@
|
|
|
37
40
|
}
|
|
38
41
|
on(document, "selectionchange", () => { clearTimeout(timer); timer = setTimeout(selection, 160) })
|
|
39
42
|
on(document, "pointerup", selection)
|
|
40
|
-
|
|
43
|
+
const hover = event => {
|
|
41
44
|
if (!picking) return
|
|
45
|
+
if (["iframe", "frame", "frameset"].includes(event.target.localName)) {
|
|
46
|
+
box.remove()
|
|
47
|
+
if (event.target.localName !== "frameset") {
|
|
48
|
+
try { if (!event.target.contentDocument) throw new Error() }
|
|
49
|
+
catch { send(null, "This frame is from another site; Annotate can't read it", true) }
|
|
50
|
+
}
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
root.append(box)
|
|
42
54
|
const rect = event.target.getBoundingClientRect()
|
|
43
55
|
box.style.cssText = `left:${rect.x}px;top:${rect.y}px;width:${rect.width}px;height:${rect.height}px`
|
|
44
|
-
}
|
|
56
|
+
}
|
|
57
|
+
on(document, "mousemove", hover, { capture: true })
|
|
58
|
+
on(document, "pointerover", hover, { capture: true })
|
|
45
59
|
on(document, "pointerdown", event => { if (picking) { event.preventDefault(); event.stopImmediatePropagation() } }, { capture: true })
|
|
46
60
|
on(document, "click", event => {
|
|
47
61
|
if (!picking) return
|
|
62
|
+
if (event.target.localName === "frameset") return
|
|
63
|
+
if (["iframe", "frame"].includes(event.target.localName)) {
|
|
64
|
+
try { if (event.target.contentDocument) { box.remove(); return } } catch { /* inaccessible frame: explain below */ }
|
|
65
|
+
}
|
|
48
66
|
event.preventDefault(); event.stopImmediatePropagation()
|
|
49
67
|
// A failed pick must never leave the page trapped in interception mode.
|
|
50
68
|
setPicking(false, false)
|
|
@@ -53,7 +71,7 @@
|
|
|
53
71
|
on(document, "keydown", event => { if (picking && event.key === "Escape") setPicking(false) })
|
|
54
72
|
const onMessage = (message, _sender, respond) => {
|
|
55
73
|
if (message.action === "annotate-ping") { respond({ ok: true }); return }
|
|
56
|
-
if (message.action === "pick") { setPicking(
|
|
74
|
+
if (message.action === "pick") { setPicking(message.picking, false); respond({ ok: true, picking }) }
|
|
57
75
|
if (message.action === "markers") { markers = message.notes || []; draw(); respond({ ok: true }) }
|
|
58
76
|
if (message.action === "locate") respond({ states: message.anchors.map(locate) })
|
|
59
77
|
if (message.action === "reveal") {
|
|
@@ -62,7 +80,7 @@
|
|
|
62
80
|
respond({ ok: false, error: `This element is ${state}. Your feedback is kept.` })
|
|
63
81
|
return
|
|
64
82
|
}
|
|
65
|
-
setPicking(false)
|
|
83
|
+
setPicking(false, false)
|
|
66
84
|
highlighted = document.querySelector(message.anchor.selector)
|
|
67
85
|
highlighted.scrollIntoView({ block: "center", inline: "nearest", behavior: matchMedia("(prefers-reduced-motion: reduce)").matches ? "instant" : "smooth" })
|
|
68
86
|
root.append(highlight); draw()
|
|
@@ -104,7 +122,10 @@
|
|
|
104
122
|
}
|
|
105
123
|
on(document, "scroll", draw, { capture: true, passive: true }); on(window, "resize", draw)
|
|
106
124
|
const observer = new MutationObserver(() => { clearTimeout(timer); timer = setTimeout(draw, 160) })
|
|
107
|
-
observer.observe(document.
|
|
125
|
+
observer.observe(document.documentElement, { childList: true, subtree: true, characterData: true })
|
|
126
|
+
on(document, "load", event => {
|
|
127
|
+
if (["iframe", "frame"].includes(event.target.localName)) chrome.runtime.sendMessage({ action: "frames-changed" }).catch(() => {})
|
|
128
|
+
}, { capture: true })
|
|
108
129
|
const routeTimer = setInterval(() => { if (!active) { observer.disconnect(); return } if (url !== location.href) { url = location.href; markers = []; draw(); send() } }, 700)
|
|
109
130
|
function dispose() {
|
|
110
131
|
if (!active) return
|
|
@@ -112,6 +133,6 @@
|
|
|
112
133
|
try { chrome.runtime.onMessage.removeListener(onMessage) } catch { /* previous extension context may already be invalidated */ }
|
|
113
134
|
delete globalThis.__opencodeAnnotate
|
|
114
135
|
}
|
|
115
|
-
globalThis.__opencodeAnnotate = { dispose }
|
|
116
|
-
send()
|
|
136
|
+
globalThis.__opencodeAnnotate = { dispose, version: 7 }
|
|
137
|
+
send(null, null, true, true)
|
|
117
138
|
})();
|
package/browser/inspector.js
CHANGED
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
return parts.join(", ")
|
|
39
39
|
}
|
|
40
40
|
function selector(element) {
|
|
41
|
+
const document = element.ownerDocument
|
|
41
42
|
const parts = []
|
|
42
43
|
for (let node = element; node?.nodeType === 1; node = node.parentElement) {
|
|
43
44
|
if (node.id && document.querySelectorAll(`#${CSS.escape(node.id)}`).length === 1) { parts.unshift(`#${CSS.escape(node.id)}`); break }
|
|
@@ -92,7 +93,8 @@
|
|
|
92
93
|
if (!element) throw new Error("Choose a visible page element")
|
|
93
94
|
const style = getComputedStyle(element)
|
|
94
95
|
if (element.closest("[hidden],script,style,noscript,template") || style.display === "none" || style.visibility === "hidden") throw new Error("Choose a visible page element")
|
|
95
|
-
if (["iframe", "
|
|
96
|
+
if (["iframe", "frame"].includes(element.localName)) throw new Error("This frame is from another site; Annotate can't read it")
|
|
97
|
+
if (["canvas", "embed", "object"].includes(element.localName)) throw new Error("This content type is unsupported")
|
|
96
98
|
const omitted = textFilter()
|
|
97
99
|
const contents = document.createRange(); contents.selectNodeContents(element)
|
|
98
100
|
const visibleText = safeText(contents, omitted).trim()
|
|
@@ -121,5 +123,13 @@
|
|
|
121
123
|
rect: Object.fromEntries(["x", "y", "width", "height"].map(key => [key, Math.round(rect[key])])),
|
|
122
124
|
viewport: { width: innerWidth, height: innerHeight, scrollX, scrollY } }
|
|
123
125
|
}
|
|
124
|
-
|
|
126
|
+
function frame() {
|
|
127
|
+
const selectors = []
|
|
128
|
+
for (let current = window; current !== current.top; current = current.parent) {
|
|
129
|
+
// Access is deliberately limited to same-origin ancestors.
|
|
130
|
+
selectors.unshift(selector(current.frameElement))
|
|
131
|
+
}
|
|
132
|
+
return selectors.length ? { selectors, url: location.href } : null
|
|
133
|
+
}
|
|
134
|
+
globalThis.AnnotateInspector = { capture, text: elementText, frame }
|
|
125
135
|
})();
|
package/browser/manifest.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"manifest_version": 3,
|
|
3
3
|
"name": "OpenCode Annotate",
|
|
4
|
-
"version": "0.16.
|
|
4
|
+
"version": "0.16.1",
|
|
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/browser/panel.mjs
CHANGED
|
@@ -74,7 +74,7 @@ function dirty(m = model) {
|
|
|
74
74
|
anchorIdentity(value.anchor) !== anchorIdentity(value.editing.anchor) : !!value.comment.trim()
|
|
75
75
|
}
|
|
76
76
|
const validDraft = () => !!model?.value?.comment.trim() && dirty()
|
|
77
|
-
const anchorIdentity = anchor => anchor ? JSON.stringify([anchor.type, anchor.selector, anchor.quote, anchor.prefix, anchor.suffix]) : ""
|
|
77
|
+
const anchorIdentity = anchor => anchor ? JSON.stringify([anchor.frame, anchor.type, anchor.selector, anchor.quote, anchor.prefix, anchor.suffix]) : ""
|
|
78
78
|
function pendingCount() {
|
|
79
79
|
const pending = state?.notes.filter(note => note.sentRevision !== note.revision) || []
|
|
80
80
|
return pending.length + (validDraft() && !pending.some(note => note.id === model.value.editing?.id) ? 1 : 0)
|
package/browser/protocol.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export const MAX_BYTES = 512 * 1024
|
|
2
2
|
export const HOST = "fun.mjshao.annotate"
|
|
3
3
|
// Bump when panel ↔ worker actions change. Chrome can keep an older worker running beside a newer panel.
|
|
4
|
-
export const PROTOCOL =
|
|
4
|
+
export const PROTOCOL = 7
|
|
5
5
|
export function safeUrl(input) {
|
|
6
6
|
const url = new URL(input)
|
|
7
7
|
if (!["http:", "https:", "file:"].includes(url.protocol)) throw new Error("Unsupported page URL")
|
|
@@ -23,7 +23,7 @@ export function validateReview(review) {
|
|
|
23
23
|
!["comment", "ask"].includes(note.kind) || typeof note.comment !== "string" || !note.comment.trim() || note.comment.length > 8000 ||
|
|
24
24
|
typeof note.anchor?.quote !== "string" || note.anchor.quote.length > 4000 || typeof note.anchor.selector !== "string" ||
|
|
25
25
|
!["text", "element"].includes(note.anchor.type)) throw new Error("Invalid annotation")
|
|
26
|
-
for (const key of ["prefix", "suffix", "styles", "accessibility", "element", "fullPath"]) {
|
|
26
|
+
for (const key of ["prefix", "suffix", "styles", "accessibility", "element", "fullPath", "frame"]) {
|
|
27
27
|
if (note.anchor[key] !== undefined && typeof note.anchor[key] !== "string") throw new Error("Invalid anchor field")
|
|
28
28
|
}
|
|
29
29
|
if (typeof note.createdAt !== "string" || Number.isNaN(Date.parse(note.createdAt))) throw new Error("Invalid annotation timestamp")
|
|
@@ -55,6 +55,7 @@ export function markdown(review) {
|
|
|
55
55
|
lines.push(`### Annotation ${index + 1} (${note.kind})`, `Captured: ${note.createdAt}`, `Selector hint: ${a.selector}`, `Element: ${a.element || a.type}`, "", "Page evidence:")
|
|
56
56
|
lines.push(...`${a.prefix || ""}【${a.quote}】${a.suffix || ""}`.split("\n").map(line => `> ${line}`))
|
|
57
57
|
if (a.fullPath) lines.push(`DOM path: ${a.fullPath}`)
|
|
58
|
+
if (a.frame) lines.push(`Frame: ${a.frame}`)
|
|
58
59
|
if (a.rect) lines.push(`Position: ${JSON.stringify(a.rect)}; viewport: ${JSON.stringify(a.viewport)}`)
|
|
59
60
|
if (a.styles) lines.push(`Styles: ${a.styles}`)
|
|
60
61
|
if (a.accessibility) lines.push(`Accessibility: ${a.accessibility}`)
|
package/browser/worker.mjs
CHANGED
|
@@ -13,30 +13,32 @@ const native = message => {
|
|
|
13
13
|
return chrome.runtime.sendNativeMessage(HOST, message)
|
|
14
14
|
}
|
|
15
15
|
const KEPT_ROUNDS = 10
|
|
16
|
-
|
|
16
|
+
// Inherited-origin blank/srcdoc documents have no HTTP URL to sanitize.
|
|
17
|
+
const frameLocator = frame => frame ? JSON.stringify({ selectors: frame.selectors, url: ["about:blank", "about:srcdoc"].includes(frame.url) ? frame.url : safeUrl(frame.url) }) : undefined
|
|
18
|
+
async function inject(tabId) {
|
|
19
|
+
try { await chrome.scripting.executeScript({ target: { tabId, allFrames: true }, files: ["inspector.js", "capture.js"] }) }
|
|
20
|
+
catch (error) { throw new Error(String(error.message).includes("HTML") ? error.message : RECONNECT) }
|
|
21
|
+
const frames = await chrome.scripting.executeScript({ target: { tabId, allFrames: true }, func: () => {
|
|
22
|
+
try { return { frame: globalThis.AnnotateInspector.frame() } } catch { return null }
|
|
23
|
+
} })
|
|
24
|
+
return frames.filter(item => item.result).map(item => ({ frameId: item.frameId, frame: frameLocator(item.result.frame) }))
|
|
25
|
+
}
|
|
26
|
+
async function pickFrames(tabId, picking, frames = undefined) {
|
|
27
|
+
frames ??= await inject(tabId)
|
|
28
|
+
await Promise.all(frames.map(({ frameId }) => chrome.tabs.sendMessage(tabId, { action: "pick", picking }, { frameId })))
|
|
29
|
+
return { picking }
|
|
30
|
+
}
|
|
31
|
+
async function anchorMessage(tabId, message, frames = undefined) {
|
|
32
|
+
frames ??= await inject(tabId)
|
|
33
|
+
const frame = frames.find(item => item.frame === message.anchor?.frame)
|
|
34
|
+
if (!frame) return { ok: false, error: "This frame is missing or has navigated. Your feedback is kept." }
|
|
35
|
+
return chrome.tabs.sendMessage(tabId, message, { frameId: frame.frameId })
|
|
36
|
+
}
|
|
17
37
|
async function activate(tab) {
|
|
18
38
|
if (!tab?.id || !/^(https?|file):/.test(tab.url || "")) throw new Error("Open an ordinary webpage or authorized local HTML")
|
|
19
39
|
await inject(tab.id)
|
|
20
40
|
await chrome.storage.session.set({ [`tab:${tab.id}`]: { page: { url: safeUrl(tab.url), title: pageTitle(tab.title || "") }, anchor: null } })
|
|
21
41
|
}
|
|
22
|
-
// A reload or navigation removes the page tools; reinject them while activeTab still grants this tab.
|
|
23
|
-
// The receiver-missing wording differs per engine, so detect it by asking the tab instead.
|
|
24
|
-
async function tabMessage(tabId, message) {
|
|
25
|
-
try { return await chrome.tabs.sendMessage(tabId, message) }
|
|
26
|
-
catch (error) {
|
|
27
|
-
if (!await receiverMissing(tabId)) throw error
|
|
28
|
-
try { await inject(tabId) } catch (injectError) {
|
|
29
|
-
throw new Error(String(injectError.message).includes("HTML") ? injectError.message : RECONNECT)
|
|
30
|
-
}
|
|
31
|
-
return chrome.tabs.sendMessage(tabId, message)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
// Chrome reports a missing content script with a fixed string; Safari does not. Probe
|
|
35
|
-
// the tab with a message only the content script answers.
|
|
36
|
-
async function receiverMissing(tabId) {
|
|
37
|
-
try { await chrome.tabs.sendMessage(tabId, { action: "annotate-ping" }); return false }
|
|
38
|
-
catch { return true }
|
|
39
|
-
}
|
|
40
42
|
async function waitLoaded(tabID) {
|
|
41
43
|
await new Promise((resolve, reject) => {
|
|
42
44
|
const finish = error => { clearTimeout(timer); chrome.tabs.onUpdated.removeListener(updated); error ? reject(error) : resolve() }
|
|
@@ -94,7 +96,13 @@ async function current(message) {
|
|
|
94
96
|
let anchorStates = notes.map(note => note.page.url === state.page.url ? "unavailable" : "elsewhere"), draftAnchorState = draft.value ? "unavailable" : undefined, detached = null
|
|
95
97
|
try {
|
|
96
98
|
const anchors = localNotes.map(note => note.anchor).concat(draft.value ? [draft.value.anchor] : [])
|
|
97
|
-
const
|
|
99
|
+
const frames = await inject(tab.id)
|
|
100
|
+
const latest = (await chrome.storage.session.get(`tab:${tab.id}`))[`tab:${tab.id}`]
|
|
101
|
+
await pickFrames(tab.id, !!latest?.picking, frames)
|
|
102
|
+
const states = await Promise.all(anchors.map(async anchor => {
|
|
103
|
+
const result = await anchorMessage(tab.id, { action: "locate", anchor, anchors: [anchor] }, frames)
|
|
104
|
+
return result.states?.[0] || "missing frame"
|
|
105
|
+
}))
|
|
98
106
|
let index = 0
|
|
99
107
|
anchorStates = notes.map(note => note.page.url === state.page.url ? states[index++] : "elsewhere")
|
|
100
108
|
if (draft.value) draftAnchorState = states[localNotes.length]
|
|
@@ -162,12 +170,27 @@ async function liveTarget(paired, targets, current) {
|
|
|
162
170
|
})
|
|
163
171
|
}
|
|
164
172
|
async function handle(message, sender) {
|
|
173
|
+
if (message.action === "frames-changed") {
|
|
174
|
+
if (!sender.tab) throw new Error("Invalid page source")
|
|
175
|
+
const state = (await chrome.storage.session.get(`tab:${sender.tab.id}`))[`tab:${sender.tab.id}`]
|
|
176
|
+
if (state?.page) await pickFrames(sender.tab.id, !!state.picking)
|
|
177
|
+
return {}
|
|
178
|
+
}
|
|
165
179
|
if (message.action === "capture") {
|
|
166
180
|
if (!sender.tab || !sender.url || new URL(message.page.url).origin !== new URL(sender.url).origin) throw new Error("Invalid page source")
|
|
167
181
|
const key = `tab:${sender.tab.id}`
|
|
168
182
|
const previous = (await chrome.storage.session.get(key))[key] || {}
|
|
169
|
-
|
|
170
|
-
|
|
183
|
+
const tab = await chrome.tabs.get(sender.tab.id)
|
|
184
|
+
if ((sender.origin || new URL(sender.url).origin) !== new URL(tab.url).origin) throw new Error("Invalid frame source")
|
|
185
|
+
const frame = sender.frameId ? frameLocator(message.frame) : undefined
|
|
186
|
+
if (sender.frameId && !frame) throw new Error("Missing frame locator")
|
|
187
|
+
const captured = !message.modeOnly
|
|
188
|
+
const changedPage = previous.page?.url !== safeUrl(tab.url)
|
|
189
|
+
const picking = changedPage || captured ? false : message.ready ? !!previous.picking : !!message.picking
|
|
190
|
+
await chrome.storage.session.set({ [key]: { ...previous, page: { url: safeUrl(tab.url), title: pageTitle(tab.title || "") }, picking,
|
|
191
|
+
...(captured ? { anchor: message.anchor ? { ...message.anchor, ...(frame ? { frame } : {}) } : null, error: message.error, captureID: crypto.randomUUID() } : changedPage ? { anchor: null, error: null } : message.error ? { error: message.error } : {}) } })
|
|
192
|
+
if (message.ready) await chrome.tabs.sendMessage(sender.tab.id, { action: "pick", picking }, { frameId: sender.frameId || 0 })
|
|
193
|
+
if (!picking && previous.picking) await pickFrames(sender.tab.id, false)
|
|
171
194
|
return {}
|
|
172
195
|
}
|
|
173
196
|
if (sender.url && !sameExtensionURL(sender.url)) throw new Error("Only the extension panel can manage feedback")
|
|
@@ -237,7 +260,12 @@ async function handle(message, sender) {
|
|
|
237
260
|
})
|
|
238
261
|
const state = await current(message)
|
|
239
262
|
if (["save", "pick"].includes(message.action) && message.url && message.url !== state.page.url) throw new Error("The active page changed; retry on the original page")
|
|
240
|
-
if (message.action === "pick")
|
|
263
|
+
if (message.action === "pick") {
|
|
264
|
+
const picking = !state.picking
|
|
265
|
+
const key = `tab:${state.tabID}`, previous = (await chrome.storage.session.get(key))[key]
|
|
266
|
+
await chrome.storage.session.set({ [key]: { ...previous, picking } })
|
|
267
|
+
return pickFrames(state.tabID, picking)
|
|
268
|
+
}
|
|
241
269
|
if (message.action === "reveal") {
|
|
242
270
|
const note = state.notes.find(note => note.id === message.noteID)
|
|
243
271
|
if (!note) throw new Error("This note is no longer on the page")
|
|
@@ -262,7 +290,10 @@ async function handle(message, sender) {
|
|
|
262
290
|
try { await activate(await chrome.tabs.get(tabID)) }
|
|
263
291
|
catch { throw new Error(RECONNECT) }
|
|
264
292
|
}
|
|
265
|
-
const
|
|
293
|
+
const key = `tab:${tabID}`, previous = (await chrome.storage.session.get(key))[key]
|
|
294
|
+
await chrome.storage.session.set({ [key]: { ...previous, picking: false } })
|
|
295
|
+
await pickFrames(tabID, false)
|
|
296
|
+
const result = await anchorMessage(tabID, { action: "reveal", anchor: note.anchor })
|
|
266
297
|
if (!result.ok) throw new Error(result.error)
|
|
267
298
|
return result
|
|
268
299
|
}
|
|
@@ -295,7 +326,11 @@ async function handle(message, sender) {
|
|
|
295
326
|
}
|
|
296
327
|
await chrome.storage.local.set(updates); return { note, draft }
|
|
297
328
|
})
|
|
298
|
-
if (message.action === "markers")
|
|
329
|
+
if (message.action === "markers") {
|
|
330
|
+
const frames = await inject(state.tabID)
|
|
331
|
+
await Promise.all(frames.map(({ frameId, frame }) => chrome.tabs.sendMessage(state.tabID, { action: "markers", notes: state.notes.map(note => ({ anchor: note.page.url === state.page.url && note.anchor.frame === frame ? note.anchor : null })) }, { frameId })))
|
|
332
|
+
return {}
|
|
333
|
+
}
|
|
299
334
|
if (message.action === "copied") return serial(async () => {
|
|
300
335
|
if (!Array.isArray(message.notes) || !message.notes.length) throw new Error("No copied feedback to record")
|
|
301
336
|
const count = await closeRound(message.notes, { sentRound: crypto.randomUUID(), sentVia: "clipboard", sentTo: null })
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxxxsooo/opencode-annotate",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.1",
|
|
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",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|