@nxxxsooo/opencode-annotate 0.16.1 → 0.17.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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.17.0 — clear the round
4
+
5
+ - **Clear** in the notes header removes every unsent note in the round; each page
6
+ group also has its own **Clear**. One **Undo** restores the whole removed batch.
7
+ - Keep delivered history, **Restore last round** and page-local drafts. A pending
8
+ retry batch is dropped only after inline confirmation when clearing the round.
9
+ - Browser protocol 8 requires matching companion files: reload the Chrome extension
10
+ and restart OpenCode after updating.
11
+
3
12
  ## 0.16.1 — picking inside frames
4
13
 
5
14
  - Fix picking and text selection inside same-origin iframes, legacy framesets and
package/README.md CHANGED
@@ -180,6 +180,8 @@ Choose **Pick element** or select text, then write a comment or question. The co
180
180
 
181
181
  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
182
 
183
+ **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.
184
+
183
185
  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
186
 
185
187
  **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 +197,7 @@ Plain `/annotate`, `/annotate-pick` and `/annotate-selection` use the TUI; Markd
195
197
  Picking and text selection work inside same-origin iframes, legacy framesets and
196
198
  nested frames. Reveal and page markers can find those notes after reload; delivered
197
199
  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
200
+ picked and show a clear message. After updating to 0.17.0 (browser protocol 8), reload
199
201
  the Chrome extension and restart OpenCode.
200
202
 
201
203
  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,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "OpenCode Annotate",
4
- "version": "0.16.1",
4
+ "version": "0.17.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/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.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",
Binary file
Binary file
Binary file
Binary file
Binary file