@nxxxsooo/opencode-annotate 0.20.0 → 0.20.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,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.20.1 — Send AGY notes on quit
4
+
5
+ - In AGY reviews, `q` sends pending notes and closes, matching OpenCode.
6
+ With no notes, `q` just closes. `Ctrl+C` still closes without sending.
7
+ - `/annotate` in a Herdr AGY pane no longer leaves AGY showing `Working…`
8
+ after the review opens, so Send delivers right away instead of queueing.
9
+ - Model-invoked AGY reviews open in a split without stealing focus when the AGY
10
+ pane is unfocused.
11
+ - Declined AGY slash interceptions and popup outcomes are logged to
12
+ `~/.local/share/opencode-annotate/agy-review.log`.
13
+
3
14
  ## 0.20.0 — AGY reviews in Herdr
4
15
 
5
16
  - In a configured AGY pane, run `/annotate` or press `prefix+a` to open the
package/README.md CHANGED
@@ -118,7 +118,8 @@ Bind **prefix, then `a`** (`Ctrl+B`, then `a` by default) to
118
118
  `annotate.review` using the [manifest and keybinding setup](tui/README.md#herdr).
119
119
  In AGY this opens a floating Markdown reviewer without starting a model turn.
120
120
  Send starts a turn if AGY is idle or done, or queues feedback if it is working.
121
- Quit sends nothing. Claude, Codex, Pi, and OpenCode use the existing `herdr last`
121
+ Press `q` to send pending notes and close, or `Ctrl+C` to close without
122
+ sending. Claude, Codex, Pi, and OpenCode use the existing `herdr last`
122
123
  route. With the AGY hooks installed, `/annotate` can open the same popup before
123
124
  the model runs; the skill remains available as a fallback.
124
125
 
@@ -176,7 +177,8 @@ find the package under `npm root -g`) or a checkout with `npm run build:tui`:
176
177
 
177
178
  **Send** (`Ctrl+S` or the Send button) returns feedback to the captured AGY
178
179
  conversation. In Herdr it starts a turn if AGY is idle or done, or queues
179
- feedback for its lifecycle hooks if AGY is working. `q` and `Ctrl+C` do not send.
180
+ feedback for its lifecycle hooks if AGY is working. `q` sends pending notes and
181
+ closes; with no notes it just closes. `Ctrl+C` closes without sending.
180
182
 
181
183
  - **CLI Commands**:
182
184
  ```sh
package/agy/cli.mjs CHANGED
@@ -13,7 +13,7 @@ import { enqueueAnnotations, listPendingBatches } from "./inbox.mjs"
13
13
  import { prepareTheme } from "../theme.mjs"
14
14
  import { createInputSource } from "../input-source.mjs"
15
15
  import { resolveTuiBinary } from "../tui/binary.mjs"
16
- import { captureHerdrConversation, deliverHerdrReview, focusedPane, herdrCommand, readHerdrAgent } from "./herdr.mjs"
16
+ import { captureHerdrConversation, deliverHerdrReview, focusedPane, herdrCommand, readHerdrAgent, recordHerdrOutcome } from "./herdr.mjs"
17
17
 
18
18
  const execute = promisify(execFile)
19
19
 
@@ -180,14 +180,20 @@ async function openTuiWindow(directory, title) {
180
180
  }
181
181
  }
182
182
 
183
+ export function herdrTuiPlacement(pane) {
184
+ // Herdr overlays belong to the active pane; --target-pane is split-only. The
185
+ // model often finishes after Mingjian has moved on, so never steal focus then.
186
+ return pane.focused
187
+ ? ["--placement", "overlay", "--focus"]
188
+ : ["--placement", "split", "--target-pane", pane.pane_id, "--direction", "right", "--no-focus"]
189
+ }
190
+
183
191
  async function openHerdrTui({ bin, pane }, directory) {
184
- // Herdr overlays belong to the active pane; --target-pane is split-only.
185
- if (!pane.focused) throw new Error("Focus the AGY pane in Herdr and retry /annotate.")
186
192
  try {
187
193
  const { stdout } = await execute(bin, [
188
194
  "plugin", "pane", "open", "--plugin", "annotate", "--entrypoint", "agy",
189
- "--placement", "overlay",
190
- "--focus", "--cwd", directory, "--env", `ANNOTATE_AGY_REVIEW_DIR=${directory}`,
195
+ ...herdrTuiPlacement(pane),
196
+ "--cwd", directory, "--env", `ANNOTATE_AGY_REVIEW_DIR=${directory}`,
191
197
  ], { timeout: 5000 })
192
198
  const opened = JSON.parse(stdout).result?.plugin_pane?.pane
193
199
  if (!opened?.pane_id) throw new Error("Herdr did not return the opened pane ID.")
@@ -195,6 +201,9 @@ async function openHerdrTui({ bin, pane }, directory) {
195
201
  await execute(bin, ["pane", "close", opened.pane_id], { timeout: 2000 })
196
202
  throw new Error("Herdr placed the overlay outside the AGY tab. Focus the AGY tab and try again.")
197
203
  }
204
+ if (!pane.focused) {
205
+ await herdrCommand(bin, ["notification", "show", "Annotate", "--body", "Review opened beside the AGY pane."]).catch(() => {})
206
+ }
198
207
  return opened.pane_id
199
208
  } catch (err) {
200
209
  throw new Error(`Failed to open the Herdr review overlay. Check that the annotate plugin has the agy pane entrypoint.\n${err.message}`)
@@ -298,8 +307,10 @@ async function cmdHerdrReview(options, shortcut) {
298
307
  }
299
308
  const session = { conversationId: captured.conversationId, title: `AGY ${captured.conversationId.slice(0, 8)}` }
300
309
  const status = await reviewTui(shortcut?.document, { session, binary, opener: { kind: "popup" }, captured })
310
+ await recordHerdrOutcome(captured.conversationId, status)
301
311
  if (status) await herdrCommand(bin, ["notification", "show", "Annotate", "--body", status]).catch(() => {})
302
312
  } catch (err) {
313
+ await recordHerdrOutcome(shortcut?.conversationId, `error: ${err.message}`)
303
314
  await herdrCommand(bin, ["notification", "show", "Annotate", "--body", err.message]).catch(() => {})
304
315
  throw err
305
316
  }
@@ -351,7 +362,6 @@ async function reviewTui(targetPath, { session, binary, opener, captured }) {
351
362
  PLANNOTATOR_DATA_DIR: dataDir,
352
363
  PLANNOTATOR_FEEDBACK_HISTORY: "0",
353
364
  PLANNOTATOR_TUI_SEND_INTENT: intentPath,
354
- PLANNOTATOR_TUI_EXPLICIT_SEND: "1",
355
365
  }
356
366
  if (themed.PLANNOTATOR_TUI_CONFIG) env.PLANNOTATOR_TUI_CONFIG = themed.PLANNOTATOR_TUI_CONFIG
357
367
 
package/agy/cli.test.mjs CHANGED
@@ -3,7 +3,7 @@ import assert from "node:assert/strict"
3
3
  import path from "node:path"
4
4
  import os from "node:os"
5
5
  import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"
6
- import { finishTuiReview, getAdaptedThemeTokens, selectTuiOpener } from "./cli.mjs"
6
+ import { finishTuiReview, getAdaptedThemeTokens, herdrTuiPlacement, selectTuiOpener } from "./cli.mjs"
7
7
  import { handlePreInvocation, handleStop } from "./hooks.mjs"
8
8
  import { enqueueAnnotations } from "./inbox.mjs"
9
9
  import { bundledBinary, resolveTuiBinary } from "../tui/binary.mjs"
@@ -25,6 +25,12 @@ test("Herdr opens an overlay only via a reachable calling pane; other calls keep
25
25
  assert.deepEqual(await selectTuiOpener({ env: { AGENT_TOOL_CALL: "1" }, tty: true }), { kind: "window" })
26
26
  })
27
27
 
28
+ test("a focused AGY pane gets an overlay; an unfocused one gets a split without stealing focus", () => {
29
+ assert.deepEqual(herdrTuiPlacement({ pane_id: "w5:p2", focused: true }), ["--placement", "overlay", "--focus"])
30
+ assert.deepEqual(herdrTuiPlacement({ pane_id: "w5:p2", focused: false }),
31
+ ["--placement", "split", "--target-pane", "w5:p2", "--direction", "right", "--no-focus"])
32
+ })
33
+
28
34
  test("only exact Send intent may export or enqueue; only one target hook gets the notes", async t => {
29
35
  const root = await mkdtemp(path.join(os.tmpdir(), "agy-finish-test-"))
30
36
  t.after(() => rm(root, { recursive: true, force: true }))
package/agy/herdr.mjs CHANGED
@@ -1,4 +1,7 @@
1
1
  import { execFile } from "node:child_process"
2
+ import { appendFile, mkdir } from "node:fs/promises"
3
+ import os from "node:os"
4
+ import path from "node:path"
2
5
  import { promisify } from "node:util"
3
6
  import { getActiveAgySessions } from "./session.mjs"
4
7
  import { enqueueAnnotations } from "./inbox.mjs"
@@ -13,6 +16,15 @@ export function focusedPane(env) {
13
16
  return context.focused_pane_id
14
17
  }
15
18
 
19
+ // Herdr notifications vanish; keep each popup outcome and declined slash
20
+ // interception so a lost review can be traced afterwards.
21
+ export async function recordHerdrOutcome(conversationId, status) {
22
+ const log = path.join(os.homedir(), ".local/share/opencode-annotate/agy-review.log")
23
+ const line = `${new Date().toISOString()}\t${conversationId ?? "-"}\t${String(status).replace(/\s+/g, " ")}\n`
24
+ await mkdir(path.dirname(log), { recursive: true, mode: 0o700 })
25
+ .then(() => appendFile(log, line, { mode: 0o600 })).catch(() => {})
26
+ }
27
+
16
28
  export async function herdrCommand(bin, args, timeout = 5000) {
17
29
  const { stdout } = await execute(bin, args, { timeout })
18
30
  return JSON.parse(stdout).result
package/agy/hooks.mjs CHANGED
@@ -44,10 +44,21 @@ export async function handleSessionStart(payload, { root = registryRoot(), inbox
44
44
  return {}
45
45
  }
46
46
 
47
+ const openedStep = {
48
+ systemMessage: {
49
+ systemMessage: "",
50
+ metadata: { user_markdown: "Annotate opened. `q` sends notes; `Ctrl+C` discards them." },
51
+ },
52
+ }
53
+
47
54
  export async function handlePreInvocation(payload, { inboxRoot = defaultInboxRoot(), intercept = interceptAnnotateSlash } = {}) {
48
55
  const conversationId = payload.conversationId
49
56
  if (!conversationId) return {}
50
- if (await intercept(payload, { inboxRoot })) return { terminationBehavior: "terminate" }
57
+ const intercepted = await intercept(payload, { inboxRoot })
58
+ // AGY's prompt ignores an idle update that adds no step after the user's
59
+ // input and keeps spinning, so the first termination shows one UI-only step.
60
+ if (intercepted === "opened") return { injectSteps: [openedStep], terminationBehavior: "terminate" }
61
+ if (intercepted) return { terminationBehavior: "terminate" }
51
62
 
52
63
  const dequeued = await dequeueAnnotations(conversationId, inboxRoot)
53
64
  if (!dequeued || !dequeued.combinedMarkdown.trim()) {
@@ -18,7 +18,7 @@ Run the command:
18
18
  ```bash
19
19
  agy-annotate tui
20
20
  ```
21
- This opens the bundled reviewer in the configured Herdr overlay or in Ghostty/Terminal outside Herdr. Keep the command running until the user finishes. Only **Send** (`Ctrl+S` or the Send button) delivers feedback to the captured conversation; `q` and `Ctrl+C` close without sending. The command returns status only. Wait for delivered annotations before acting on them.
21
+ This opens the bundled reviewer in Herdr or in Ghostty/Terminal outside Herdr. Keep the command running until the user finishes. **Send** (`Ctrl+S` or the Send button) delivers feedback to the captured conversation. `q` sends pending notes and closes; with no notes it just closes. `Ctrl+C` closes without sending. The command returns status only. Wait for delivered annotations before acting on them.
22
22
 
23
23
  ### 2. When the user specifies a document (e.g., `/annotate path/to/doc.md`):
24
24
  Run the command:
package/agy/slash.mjs CHANGED
@@ -2,7 +2,7 @@ import { spawn } from "node:child_process"
2
2
  import { mkdir, rm, stat } from "node:fs/promises"
3
3
  import path from "node:path"
4
4
  import { fileURLToPath } from "node:url"
5
- import { herdrCommand, readHerdrAgent, resolveHerdrConversation } from "./herdr.mjs"
5
+ import { herdrCommand, readHerdrAgent, recordHerdrOutcome, resolveHerdrConversation } from "./herdr.mjs"
6
6
  import { defaultInboxRoot } from "./inbox.mjs"
7
7
 
8
8
  export function annotateSlash(text) {
@@ -48,43 +48,54 @@ async function claimTurn(inboxRoot, conversationId, count) {
48
48
 
49
49
  export async function interceptAnnotateSlash(payload, {
50
50
  env = process.env, readAgent = readHerdrAgent, command = herdrCommand, launch = start,
51
- inboxRoot = defaultInboxRoot(),
51
+ inboxRoot = defaultInboxRoot(), record = recordHerdrOutcome,
52
52
  } = {}) {
53
53
  const argument = annotateSlash(payload.lastUserInput)
54
+ if (argument === undefined) return false
55
+ const decline = async reason => {
56
+ await record(payload.conversationId, `slash not intercepted: ${reason}`)
57
+ return false
58
+ }
54
59
  const { HERDR_ENV, HERDR_PANE_ID: pane, HERDR_SOCKET_PATH: socket, HERDR_BIN_PATH: bin = "herdr" } = env
55
- if (argument === undefined || payload.invocationNum !== 0 || !Number.isSafeInteger(payload.initialNumSteps) ||
56
- payload.initialNumSteps < 1 || !payload.conversationId ||
57
- HERDR_ENV !== "1" || !pane || !socket) return false
60
+ if (payload.invocationNum !== 0 || !Number.isSafeInteger(payload.initialNumSteps) ||
61
+ payload.initialNumSteps < 1 || !payload.conversationId) {
62
+ return decline(`payload invocationNum=${payload.invocationNum} initialNumSteps=${payload.initialNumSteps}`)
63
+ }
64
+ if (HERDR_ENV !== "1" || !pane || !socket) return decline("not in a Herdr pane")
58
65
 
59
66
  try {
60
67
  const [agent, pluginList] = await Promise.all([
61
68
  readAgent(bin, pane, 200),
62
69
  command(bin, ["plugin", "list", "--json"], 200),
63
70
  ])
64
- if (agent.agent !== "agy" || !agent.focused || !agent.agent_session ||
65
- resolveHerdrConversation(agent).conversationId !== payload.conversationId) return false
71
+ if (agent.agent !== "agy") return decline(`pane agent is ${agent.agent}`)
72
+ if (!agent.focused) return decline("AGY pane not focused")
73
+ if (!agent.agent_session) return decline("Herdr reports no AGY session")
74
+ if (resolveHerdrConversation(agent).conversationId !== payload.conversationId) {
75
+ return decline("Herdr session does not match the conversation")
76
+ }
66
77
  const plugin = pluginList?.plugins?.find(plugin => plugin.plugin_id === "annotate" && plugin.enabled)
67
78
  const popup = plugin?.panes?.find(pane => pane.id === "agy-popup" && pane.placement === "popup")
68
- if (!popup) return false
79
+ if (!popup) return decline("annotate plugin has no agy-popup entrypoint")
69
80
  const [executable, namespace, entrypoint] = popup.command ?? []
70
81
  const binary = namespace === "herdr" && entrypoint === "hosted-pane" && path.isAbsolute(executable)
71
82
  ? executable : undefined
72
83
  let document
73
84
  if (argument !== null) {
74
- if (!path.isAbsolute(payload.cwd ?? "")) return false
85
+ if (!path.isAbsolute(payload.cwd ?? "")) return decline("relative cwd")
75
86
  document = path.resolve(payload.cwd, argument)
76
- if (!(await stat(document)).isFile()) return false
87
+ if (!(await stat(document)).isFile()) return decline("document is not a file")
77
88
  }
78
89
  const release = await claimTurn(inboxRoot, payload.conversationId, payload.initialNumSteps)
79
- if (!release) return true
90
+ if (!release) return "replayed"
80
91
  let launched = false
81
92
  try {
82
93
  launched = await launch({ pane, conversationId: payload.conversationId, document, binary, env })
83
- return launched
94
+ return launched ? "opened" : decline("popup launcher failed to start")
84
95
  } finally {
85
96
  if (!launched) await release()
86
97
  }
87
- } catch {
88
- return false
98
+ } catch (err) {
99
+ return decline(err.message)
89
100
  }
90
101
  }
@@ -27,15 +27,23 @@ test("only terminates the initial invocation after handing off the verified pane
27
27
  const inboxRoot = await mkdtemp(path.join(os.tmpdir(), "annotate-slash-test-"))
28
28
  t.after(() => rm(inboxRoot, { force: true, recursive: true }))
29
29
  const calls = []
30
+ const declined = []
30
31
  const options = { env, inboxRoot, readAgent: async () => agent, command: async () => ({ plugins: [plugin] }),
31
- launch: async captured => { calls.push(captured); return true } }
32
+ launch: async captured => { calls.push(captured); return true },
33
+ record: async (_, reason) => { declined.push(reason) } }
32
34
  const intercept = p => interceptAnnotateSlash(p, options)
33
- assert.deepEqual(await handlePreInvocation(payload, { intercept }), { terminationBehavior: "terminate" })
35
+ const opened = await handlePreInvocation(payload, { intercept })
36
+ assert.equal(opened.terminationBehavior, "terminate")
37
+ assert.equal(opened.injectSteps.length, 1, "AGY needs a step after the input to leave Working…")
38
+ assert.equal(opened.injectSteps[0].systemMessage.systemMessage, "", "the model never reads the UI step")
39
+ assert.match(opened.injectSteps[0].systemMessage.metadata.user_markdown, /Annotate opened/)
34
40
  assert.deepEqual(calls.shift(), { pane, conversationId, document: undefined, binary: undefined, env })
35
- assert.equal(await intercept(payload), true)
41
+ assert.equal(await intercept(payload), "replayed")
42
+ assert.deepEqual(await handlePreInvocation(payload, { intercept }), { terminationBehavior: "terminate" },
43
+ "a replayed invocation adds no second UI step")
36
44
  assert.deepEqual(calls, [], "a repeated hook must not open the same turn again")
37
45
  const cwd = fileURLToPath(new URL("../", import.meta.url))
38
- assert.equal(await intercept({ ...payload, initialNumSteps: 2, cwd, lastUserInput: '/annotate "README.md"' }), true)
46
+ assert.equal(await intercept({ ...payload, initialNumSteps: 2, cwd, lastUserInput: '/annotate "README.md"' }), "opened")
39
47
  assert.equal(calls.shift().document, fileURLToPath(new URL("../README.md", import.meta.url)))
40
48
  assert.equal(await intercept({ ...payload, invocationNum: 1 }), false)
41
49
  assert.equal(await intercept({ ...payload, cwd, lastUserInput: "/annotate missing.md" }), false)
@@ -44,9 +52,11 @@ test("only terminates the initial invocation after handing off the verified pane
44
52
  assert.equal(await interceptAnnotateSlash({ ...payload, conversationId: "different" }, options), false)
45
53
  assert.equal(await interceptAnnotateSlash(payload, { ...options, command: async () => ({ plugins: [] }) }), false)
46
54
  assert.deepEqual(calls, [])
55
+ assert.ok(declined.includes("slash not intercepted: AGY pane not focused"), "a declined slash records why")
56
+ assert.equal(declined.length, 6)
47
57
  const failed = { ...payload, initialNumSteps: 3 }
48
58
  assert.equal(await interceptAnnotateSlash(failed, { ...options, launch: async () => false }), false)
49
- assert.equal(await intercept(failed), true, "failed spawn releases the claim")
59
+ assert.equal(await intercept(failed), "opened", "failed spawn releases the claim")
50
60
  })
51
61
 
52
62
  test("a terminated local slash turn does not restart the model or consume queued notes", async t => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "OpenCode Annotate",
4
- "version": "0.20.0",
4
+ "version": "0.20.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxxxsooo/opencode-annotate",
3
- "version": "0.20.0",
3
+ "version": "0.20.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
@@ -133,8 +133,8 @@ the reviewer, so it does not use this route.
133
133
 
134
134
  For AGY, the `agy-popup` pane runs `herdr hosted-pane` on a private Markdown
135
135
  snapshot. The `agy` pane runs `agy-annotate tui-pane` for the skill fallback.
136
- Keep the AGY pane focused while the overlay opens. Only **Send** submits
137
- feedback; `q` and `Ctrl+C` close without sending.
136
+ Keep the AGY pane focused while the popup opens. `q` sends pending notes and
137
+ closes; with no notes it just closes. `Ctrl+C` closes without sending.
138
138
 
139
139
 
140
140
  ## Local image-toolbar trial
Binary file
Binary file
Binary file
Binary file
Binary file