@nxxxsooo/opencode-annotate 0.16.1 → 0.17.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 CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.17.1 — picking inside modal drawers
4
+
5
+ - Keep element highlights, saved-note markers and reveal outlines visible above
6
+ modal dialogs and drawers, including nested dialogs and same-origin frames.
7
+ - Restore the overlay as dialogs open, close or reopen without intercepting page
8
+ clicks. Saved notes and browser protocol 8 are unchanged.
9
+ - Reload the Chrome extension and refresh pages already using annotation tools
10
+ after updating. Saved notes remain available.
11
+
12
+ ## 0.17.0 — clear the round
13
+
14
+ - **Clear** in the notes header removes every unsent note in the round; each page
15
+ group also has its own **Clear**. One **Undo** restores the whole removed batch.
16
+ - Keep delivered history, **Restore last round** and page-local drafts. A pending
17
+ retry batch is dropped only after inline confirmation when clearing the round.
18
+ - Browser protocol 8 requires matching companion files: reload the Chrome extension
19
+ and restart OpenCode after updating.
20
+
3
21
  ## 0.16.1 — picking inside frames
4
22
 
5
23
  - Fix picking and text selection inside same-origin iframes, legacy framesets and
package/README.md CHANGED
@@ -107,6 +107,27 @@ Browser setup is separate from the plugin install. Safari supports local notes a
107
107
 
108
108
  Numbered `/annotate N`, `/annotate-last` and `/annotate-web` are retired. Use `/annotate-pick` for earlier text, `/annotate` for the latest reply, and `/annotate <url-or-html>` for a page. Browser connection controls live in the extension's destination menu.
109
109
 
110
+ ## Herdr
111
+
112
+ Run the bundled `annotate-tui` directly from a Herdr pane. Herdr needs an enabled
113
+ `annotate` plugin with a `doc` pane entrypoint; see the [TUI setup](tui/README.md#herdr).
114
+ OpenCode's `/annotate` keeps its own session delivery, even when OpenCode runs in Herdr.
115
+
116
+ ```sh
117
+ annotate-tui herdr open docs/plan.md --placement split --deliver-to w1:p2
118
+ annotate-tui herdr open docs/ --deliver-to w1:p2
119
+ annotate-tui herdr last --deliver-to w1:p2
120
+ annotate-tui herdr terminal --lines 20 --deliver-to w1:p2
121
+ annotate-tui herdr terminal --lines 5 --print
122
+ ```
123
+
124
+ - `open`, `last` and `terminal` accept `--placement overlay|split|tab|zoomed`. The default is `overlay`.
125
+ - `last` opens a reply picker; add `--newest` to open the newest reply directly. With `--deliver-to`, it reads that pane's agent session.
126
+ - `terminal` reviews recent output from the calling pane, even if feedback goes to a different pane. `--print` writes a fenced Markdown block to stdout instead of opening a reviewer.
127
+ - Replace `w1:p2` with the receiving agent's pane ID. **Send** submits the feedback as a prompt, including Enter. If Herdr reports the agent is blocked at a dialog, no prompt is sent. Annotate keeps the notes pending and tries to copy the feedback to the terminal clipboard; resolve the dialog and retry when ready.
128
+
129
+ Outside Herdr, use `annotate-tui docs/plan.md` to copy feedback via a terminal that supports OSC 52. `herdr open` requires a Herdr pane.
130
+
110
131
  ## Upgrading from the TUI-only package
111
132
 
112
133
  `opencode-annotate` replaces `opencode-plannotator-tui` (0.4.2 and earlier). To switch, run `opencode plugin remove opencode-plannotator-tui@latest` and then install this package as shown above.
@@ -180,6 +201,8 @@ Choose **Pick element** or select text, then write a comment or question. The co
180
201
 
181
202
  The queue groups notes by page, with contiguous numbers matching page markers and delivered Markdown. Click a note's quoted target to show it on its page without activating the element; off-page notes can open their page. **Edit** changes the feedback, and **Undo** restores a deleted note. The delivery bar shows the whole round's count and destination; drafts remain page-local.
182
203
 
204
+ **Clear** in the notes header removes every unsent note in the round; each page group has its own **Clear**. One **Undo** restores the whole removed batch. Drafts, delivered history and **Restore last round** stay intact. Clearing the round drops a pending retry batch only after inline confirmation.
205
+
183
206
  Each send closes the global review round: delivered notes leave the list and the panel is ready for the next round. **Restore last round** returns the most recent round's notes across pages; the last ten rounds are kept globally.
184
207
 
185
208
  **Send** and **Copy instead** remain separate actions. Send requires a live destination; Copy instead copies the grouped round as Markdown for any agent and closes it the same way. If a session drops during Send, notes remain available for retry or copying. **More review options** contains a non-closing Markdown copy, JSON export, and a preview of the current round.
@@ -195,7 +218,7 @@ Plain `/annotate`, `/annotate-pick` and `/annotate-selection` use the TUI; Markd
195
218
  Picking and text selection work inside same-origin iframes, legacy framesets and
196
219
  nested frames. Reveal and page markers can find those notes after reload; delivered
197
220
  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
221
+ picked and show a clear message. After updating to 0.17.0 (browser protocol 8), reload
199
222
  the Chrome extension and restart OpenCode.
200
223
 
201
224
  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.
@@ -1,12 +1,15 @@
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
+ if (globalThis.__opencodeAnnotate?.version === 8) return
4
4
  globalThis.__opencodeAnnotate?.dispose()
5
5
  if (!["text/html", "application/xhtml+xml"].includes(document.contentType)) throw new Error("Only HTML pages are supported")
6
6
  const listeners = new AbortController()
7
7
  const on = (target, event, handler, options = {}) => target.addEventListener(event, handler, { ...options, signal: listeners.signal })
8
8
  const host = document.createElement("div")
9
9
  host.setAttribute("data-opencode-annotate", "")
10
+ // A manual popover puts the pointer-transparent viewport overlay in the top
11
+ // layer without moving it under transformed/clipping dialog ancestors.
12
+ host.setAttribute("popover", "manual")
10
13
  host.style.cssText = "all:initial!important;position:fixed!important;inset:0!important;pointer-events:none!important;z-index:2147483647!important"
11
14
  const root = host.attachShadow({ mode: "closed" })
12
15
  const style = document.createElement("style")
@@ -16,6 +19,16 @@
16
19
  const highlight = document.createElement("div"); highlight.className = "box"
17
20
  let highlighted, highlightTimer
18
21
  let picking = false, url = location.href, timer, markers = [], active = true
22
+ let modals = []
23
+ function syncLayer(force = false) {
24
+ const next = [...document.querySelectorAll("dialog:modal")]
25
+ const changed = force || next.length !== modals.length || next.some((node, index) => node !== modals[index])
26
+ if (changed) box.remove()
27
+ if (changed && host.matches(":popover-open")) host.hidePopover()
28
+ if (!host.matches(":popover-open")) host.showPopover()
29
+ modals = next
30
+ }
31
+ syncLayer()
19
32
  function send(anchor = null, error = null, modeOnly = false, ready = false) {
20
33
  if (!active) return
21
34
  try {
@@ -42,6 +55,7 @@
42
55
  on(document, "pointerup", selection)
43
56
  const hover = event => {
44
57
  if (!picking) return
58
+ syncLayer()
45
59
  if (["iframe", "frame", "frameset"].includes(event.target.localName)) {
46
60
  box.remove()
47
61
  if (event.target.localName !== "frameset") {
@@ -103,6 +117,7 @@
103
117
  } catch { return "invalid selector" }
104
118
  }
105
119
  function draw() {
120
+ syncLayer()
106
121
  if (highlighted?.isConnected) {
107
122
  const rect = highlighted.getBoundingClientRect()
108
123
  highlight.style.cssText = `left:${rect.left}px;top:${rect.top}px;width:${rect.width}px;height:${rect.height}px`
@@ -121,8 +136,13 @@
121
136
  }
122
137
  }
123
138
  on(document, "scroll", draw, { capture: true, passive: true }); on(window, "resize", draw)
124
- const observer = new MutationObserver(() => { clearTimeout(timer); timer = setTimeout(draw, 160) })
125
- observer.observe(document.documentElement, { childList: true, subtree: true, characterData: true })
139
+ const observer = new MutationObserver(records => {
140
+ // showModal/close mutate `open`; observe it as well as removed dialogs.
141
+ // Force a raise even if a dialog closes and reopens in one mutation batch.
142
+ syncLayer(records.some(record => record.type === "attributes" && record.target.localName === "dialog"))
143
+ clearTimeout(timer); timer = setTimeout(draw, 160)
144
+ })
145
+ observer.observe(document.documentElement, { childList: true, subtree: true, characterData: true, attributes: true, attributeFilter: ["open"] })
126
146
  on(document, "load", event => {
127
147
  if (["iframe", "frame"].includes(event.target.localName)) chrome.runtime.sendMessage({ action: "frames-changed" }).catch(() => {})
128
148
  }, { capture: true })
@@ -133,6 +153,6 @@
133
153
  try { chrome.runtime.onMessage.removeListener(onMessage) } catch { /* previous extension context may already be invalidated */ }
134
154
  delete globalThis.__opencodeAnnotate
135
155
  }
136
- globalThis.__opencodeAnnotate = { dispose, version: 7 }
156
+ globalThis.__opencodeAnnotate = { dispose, version: 8 }
137
157
  send(null, null, true, true)
138
158
  })();
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "OpenCode Annotate",
4
- "version": "0.16.1",
4
+ "version": "0.17.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.css CHANGED
@@ -138,3 +138,6 @@ pre { max-height: 240px; overflow: auto; white-space: pre-wrap; overflow-wrap: a
138
138
  @media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
139
139
  .page-group { list-style: none; display: grid; gap: 2px; padding: 12px 0 4px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
140
140
  .page-group strong { color: var(--text); font-size: 13px; font-weight: 650; }
141
+ .page-group-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
142
+ .page-group-heading strong { min-width: 0; overflow-wrap: anywhere; }
143
+ .page-group-heading button { flex-shrink: 0; }
@@ -38,8 +38,8 @@
38
38
  <div id="draft-error" class="draft-error" hidden><p id="draft-error-text" class="error" role="alert"></p><div class="switch-actions"><button id="retry-draft">Retry saving draft</button><button id="reload-draft">Load saved draft</button><button id="keep-draft">Keep my draft</button><button id="copy-draft" class="text-button">Copy my draft</button></div></div>
39
39
  <div class="composer-actions"><button id="save" aria-keyshortcuts="Control+Enter Meta+Enter"><span id="save-label">Add note</span><kbd id="save-shortcut" title="Command or Control + Enter" aria-hidden="true">⌘↵</kbd></button><button id="cancel" class="text-button">Discard draft</button></div>
40
40
  </section>
41
- <div id="undo-notice" class="inline-notice" aria-live="polite" hidden><span>Note removed.</span><button id="undo" class="text-button">Undo</button></div>
42
- <section id="notes-section" class="notes-section" aria-label="Collected notes" hidden><div class="section-heading"><h2>Notes</h2><span id="count">0 notes</span></div><ol id="notes"></ol></section>
41
+ <div id="undo-notice" class="inline-notice" aria-live="polite" hidden><span id="undo-text">Note removed.</span><button id="undo" class="text-button">Undo</button></div>
42
+ <section id="notes-section" class="notes-section" aria-label="Collected notes" hidden><div class="section-heading"><h2>Notes</h2><span id="count">0 notes</span><button id="clear" class="text-button" aria-label="Clear whole round">Clear</button></div><div id="clear-warning" class="inline-notice" role="status" hidden><span>The pending retry batch will be dropped. Undo restores notes only.</span><button id="confirm-clear" class="text-button">Clear anyway</button><button id="cancel-clear" class="text-button">Cancel</button></div><ol id="notes"></ol></section>
43
43
  <section id="empty-state" class="empty-state"><h2 id="empty-title">Start with what you see.</h2><p>Pick an element or highlight text on the page, then describe what needs attention.</p><p id="empty-footnote" class="empty-footnote">Send one note straight away, or collect a few first. Your feedback stays local until you send.</p><button id="restore-round" class="text-button" hidden>Restore last round</button></section>
44
44
  </main>
45
45
  <footer class="delivery">
package/browser/panel.mjs CHANGED
@@ -12,7 +12,7 @@ let state, model, destination, available, targets = [], workspaces = [], disconn
12
12
  // Safari has no reachable bridge, so the panel offers copy instead of session delivery.
13
13
  let deliverySupported = true
14
14
  let refreshID = 0, connectionRevision = 0, connectionRefresh, connectionRefreshRevision, connectionTimer, scheduledRefresh
15
- let pendingAction, pendingFocus, undoRecord, selectedNoteID, noteRenderKey, notice, outdated = false
15
+ let pendingAction, pendingFocus, undoRecord, clearBatchID, selectedNoteID, noteRenderKey, notice, outdated = false
16
16
  let sessionSort = localStorage.getItem("sessionSort") || "updated", showAllSessions = false
17
17
 
18
18
  function icon(name) {
@@ -59,7 +59,7 @@ async function run(id, fn) {
59
59
  model.conflict = error; model.error = error
60
60
  renderComposer()
61
61
  }
62
- status(error.message, "error", ["send", "copy-round", "restore-round", "undo", "delete"].includes(id) ? null : page)
62
+ status(error.message, "error", ["send", "copy-round", "restore-round", "undo", "delete", "clear"].includes(id) ? null : page)
63
63
  } finally {
64
64
  busy.delete(id); if ($(id)) $(id).disabled = false; controls()
65
65
  if (!flushFocus() && !pendingFocus && document.activeElement === document.body && page === state?.page.url &&
@@ -79,7 +79,7 @@ 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)
81
81
  }
82
- function locked() { return ["save", "send", "copy-round", "restore-round", "cancel", "save-switch", "discard-switch", "delete", "undo", "reload-draft", "keep-draft", "targets", "new-session", "disconnect", "change-target"].some(id => busy.has(id)) }
82
+ function locked() { return ["clear", "save", "send", "copy-round", "restore-round", "cancel", "save-switch", "discard-switch", "delete", "undo", "reload-draft", "keep-draft", "targets", "new-session", "disconnect", "change-target"].some(id => busy.has(id)) }
83
83
  function controls() {
84
84
  const lock = locked() || outdated
85
85
  $("comment").disabled = lock
@@ -100,6 +100,7 @@ function controls() {
100
100
  $("disconnect").disabled = lock || !available
101
101
  $("copy").disabled = $("export").disabled = !state?.notes.length
102
102
  for (const button of $("notes").querySelectorAll("button")) button.disabled = lock
103
+ for (const id of ["clear", "confirm-clear", "cancel-clear"]) $(id).disabled = lock || !state?.notes.length
103
104
  for (const id of busy) if ($(id)) $(id).disabled = true
104
105
  if (outdated) for (const button of document.querySelectorAll("button:not(#reload-extension)")) button.disabled = true
105
106
  renderDelivery()
@@ -206,7 +207,18 @@ async function deleteNote(id) {
206
207
  const result = await call({ action: "delete", url: state.page.url, note, baseRevision: note.revision,
207
208
  ...(clearDraft ? { draftRevision: m.record.revision, captures: m.value.captures } : {}) })
208
209
  if (clearDraft) { m.record = result.draft; m.value = null; m.touched = false }
209
- undoRecord = { note: result.note }
210
+ undoRecord = { notes: [result.note] }
211
+ await refresh(); focusWhenReady("#undo")
212
+ }
213
+
214
+ async function clearNotes(url, dropBatchID) {
215
+ if (!url && state.outbox && dropBatchID !== state.outbox.batchID) {
216
+ clearBatchID = state.outbox.batchID; $("clear-warning").hidden = false
217
+ focusWhenReady("#confirm-clear"); return
218
+ }
219
+ const notes = state.notes.filter(note => !url || note.page.url === url)
220
+ const result = await call({ action: "clear", notes: notes.map(note => ({ url: note.page.url, id: note.id, revision: note.revision })), wholeRound: !url, dropBatchID })
221
+ undoRecord = { notes: result.notes }; clearBatchID = null; $("clear-warning").hidden = true
210
222
  await refresh(); focusWhenReady("#undo")
211
223
  }
212
224
 
@@ -261,7 +273,12 @@ function renderNotes() {
261
273
  pageURL = note.page.url
262
274
  const page = note.page, url = new URL(page.url), header = make("li"), title = make("strong", page.title)
263
275
  header.className = "page-group"; header.title = page.url
264
- header.append(title, make("span", `${url.host}${url.pathname}${page.url === state.page.url ? " · This page" : ""}`))
276
+ const heading = make("div"), clear = make("button", "Clear")
277
+ heading.className = "page-group-heading"; clear.className = "text-button"
278
+ clear.setAttribute("aria-label", `Clear notes from ${page.title}`)
279
+ clear.onclick = () => run("clear", () => clearNotes(page.url))
280
+ heading.append(title, clear)
281
+ header.append(heading, make("span", `${url.host}${url.pathname}${page.url === state.page.url ? " · This page" : ""}`))
265
282
  $("notes").append(header)
266
283
  }
267
284
  const item = make("li"), number = make("span", index + 1), content = make("div"), target = make("button"), bottom = make("div"), meta = make("span")
@@ -340,6 +357,7 @@ function renderDelivery() {
340
357
  function render() {
341
358
  renderComposer(); renderNotes()
342
359
  $("undo-notice").hidden = !undoRecord
360
+ $("undo-text").textContent = undoRecord ? `${plural(undoRecord.notes.length)} removed.` : ""
343
361
  controls()
344
362
  }
345
363
  function scheduleRefresh() { clearTimeout(scheduledRefresh); scheduledRefresh = setTimeout(() => refresh(), 30) }
@@ -520,10 +538,13 @@ task("copy-draft", async () => {
520
538
  catch { $("comment").focus(); $("comment").select(); status("Automatic copy was blocked. Press Cmd/Ctrl+C to copy your draft.", "error") }
521
539
  })
522
540
  task("undo", async () => {
523
- const { note } = undoRecord
524
- await call({ action: "restore", note, baseRevision: note.revision }); undoRecord = null
525
- await refresh(); status("Note restored"); focusWhenReady(`[data-note-id="${CSS.escape(note.id)}"] .note-target`)
541
+ const { notes } = undoRecord
542
+ await call({ action: "restore-notes", notes: notes.map(note => ({ url: note.page.url, id: note.id, revision: note.revision })) }); undoRecord = null
543
+ await refresh(); status(`${plural(notes.length)} restored`); focusWhenReady(`[data-note-id="${CSS.escape(notes[0].id)}"] .note-target`)
526
544
  })
545
+ task("clear", () => clearNotes())
546
+ $("confirm-clear").addEventListener("click", () => run("clear", () => clearNotes(undefined, clearBatchID)))
547
+ task("cancel-clear", () => { clearBatchID = null; $("clear-warning").hidden = true; focusWhenReady("#clear") })
527
548
  task("more", () => { const show = $("utilities").hidden; $("utilities").hidden = !show; $("more").setAttribute("aria-expanded", String(show)); if (show) $("panel-body").scrollTop = 0 })
528
549
  task("change-target", async () => { showSessionOptions($("session-options").hidden); if (!$("session-options").hidden) await refreshConnection() })
529
550
  $("session-sort").value = sessionSort
@@ -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 = 7
4
+ export const PROTOCOL = 8
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")
@@ -49,6 +49,17 @@ async function waitLoaded(tabID) {
49
49
  })
50
50
  }
51
51
  const delivered = note => !note.deleted && note.sentRevision === note.revision
52
+ async function updateMarkers(notes) {
53
+ const session = await chrome.storage.session.get(null)
54
+ await Promise.all((await chrome.tabs.query({})).map(async tab => {
55
+ const page = session[`tab:${tab.id}`]?.page
56
+ if (!page) return
57
+ try {
58
+ const frames = await inject(tab.id)
59
+ await Promise.all(frames.map(({ frameId, frame }) => chrome.tabs.sendMessage(tab.id, { action: "markers", notes: notes.map(note => ({ anchor: note.page.url === page.url && note.anchor.frame === frame ? note.anchor : null })) }, { frameId })))
60
+ } catch { /* Closed or navigated tabs are refreshed when reopened. */ }
61
+ }))
62
+ }
52
63
  async function closeRound(annotations, details) {
53
64
  const storage = await chrome.storage.local.get(null), sentAt = new Date().toISOString(), updates = {}
54
65
  for (const sent of annotations) {
@@ -108,7 +119,7 @@ async function current(message) {
108
119
  if (draft.value) draftAnchorState = states[localNotes.length]
109
120
  } catch (error) { if (error.message === RECONNECT) detached = RECONNECT /* otherwise visibly unavailable while navigating */ }
110
121
  return { protocol: PROTOCOL, tabID: tab.id, ...state, notes, anchorStates, hash, draft, draftAnchorState, detached, lastRound: lastRound(entries),
111
- outbox: outbox ? { targetID: outbox.targetID, count: outbox.review.annotations.length } : null }
122
+ outbox: outbox ? { batchID: outbox.batchID, targetID: outbox.targetID, count: outbox.review.annotations.length } : null }
112
123
  }
113
124
  function draftConflict(draft) {
114
125
  return Object.assign(new Error("This draft changed in another panel. Choose which version to keep."), { code: "draft-conflict", draft })
@@ -297,6 +308,30 @@ async function handle(message, sender) {
297
308
  if (!result.ok) throw new Error(result.error)
298
309
  return result
299
310
  }
311
+ if (["clear", "restore-notes"].includes(message.action)) return serial(async () => {
312
+ if (!Array.isArray(message.notes) || !message.notes.length) throw new Error("No notes to change")
313
+ const storage = await chrome.storage.local.get(null), updates = {}, restoring = message.action === "restore-notes"
314
+ for (const ref of message.notes) {
315
+ const key = `note:${await pageKey(safeUrl(ref.url))}:${ref.id}`, old = storage[key]
316
+ if (!old || old.revision !== ref.revision || !!old.deleted !== restoring || delivered(old))
317
+ throw Object.assign(new Error("A note changed in another tab. Refresh and try again."), { code: "note-conflict", note: old || null })
318
+ if (updates[key]) throw new Error("Duplicate note")
319
+ updates[key] = { ...old, revision: old.revision + 1, deleted: !restoring }
320
+ }
321
+ if (restoring) {
322
+ const round = Object.entries(storage).filter(([key, note]) => key.startsWith("note:") && !note.deleted && !delivered(note)).map(([, note]) => note)
323
+ if (round.length + Object.keys(updates).length > 200) throw new Error("This round would exceed 200 notes; send or remove some first")
324
+ validateReview({ version: 2, annotations: [...round, ...Object.values(updates)] })
325
+ }
326
+ const notes = Object.values(updates)
327
+ if (!restoring && message.wholeRound && storage.outbox) {
328
+ if (message.dropBatchID !== storage.outbox.batchID) throw new Error("A pending retry batch will be dropped. Confirm Clear again.")
329
+ updates.outbox = null
330
+ }
331
+ await chrome.storage.local.set(updates)
332
+ await updateMarkers(orderedNotes(Object.entries({ ...storage, ...updates }).filter(([key, note]) => key.startsWith("note:") && !note.deleted && !delivered(note)).map(([, note]) => note)))
333
+ return { notes }
334
+ })
300
335
  if (["save", "delete", "restore"].includes(message.action)) return serial(async () => {
301
336
  const page = message.note.page || state.page
302
337
  const key = `note:${await pageKey(page.url)}:${message.note.id}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxxxsooo/opencode-annotate",
3
- "version": "0.16.1",
3
+ "version": "0.17.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",
package/tui/README.md CHANGED
@@ -55,6 +55,38 @@ Standalone annotation data defaults to `~/.local/share/opencode-annotate/tui`
55
55
  (`%LOCALAPPDATA%/opencode-annotate/tui` on Windows). Hosted reviews use their own private
56
56
  snapshot stores. An explicit `PLANNOTATOR_DATA_DIR` can still open a retained older draft.
57
57
 
58
+ ## Herdr
59
+
60
+ The [Herdr commands](../README.md#herdr) use an enabled plugin with ID `annotate`.
61
+ For a local setup on macOS (tested with Herdr 0.9.5), save this as `herdr-plugin.toml`
62
+ and run `herdr plugin link /absolute/path/to/plugin-directory`:
63
+
64
+ ```toml
65
+ id = "annotate"
66
+ name = "Annotate"
67
+ version = "0.1.0"
68
+ min_herdr_version = "0.9.5"
69
+ platforms = ["macos"]
70
+
71
+ [[panes]]
72
+ id = "doc"
73
+ title = "Annotate"
74
+ placement = "overlay"
75
+ command = ["/absolute/path/to/annotate-tui", "herdr", "pane"]
76
+ ```
77
+
78
+ `herdr pane` is the plugin entrypoint: it reads the file, reply or terminal source
79
+ passed by the launcher. Set `--placement overlay|split|tab|zoomed` on `herdr open`,
80
+ `herdr last` or `herdr terminal`; the default is `overlay`. Remove any old
81
+ `popup_width` and `popup_height` settings and replace `placement = "popup"` with
82
+ one of the supported values. Agent delivery uses `herdr agent prompt`; a blocked send
83
+ leaves notes pending for a manual retry and attempts an OSC 52 clipboard copy.
84
+ OpenCode's `/annotate` clears the inherited `HERDR_*` variables before launching
85
+ the reviewer, so it does not use this route.
86
+
87
+ Runtime checks used fixture panes and a local transcript. Real model turns and
88
+ OS clipboard integration were not tested.
89
+
58
90
  ## Local image-toolbar trial
59
91
 
60
92
  The default toolbar remains Unicode. To opt in, add to the TUI config selected by
Binary file
Binary file
Binary file
Binary file
Binary file