@nxxxsooo/opencode-annotate 0.8.1 → 0.9.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,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.0 — input-method-safe keys
4
+
5
+ - Switch to Slash Saver's ASCII input source while a TUI review is browsed (OpenCode and
6
+ `agy-annotate`) and while an OpenCode permission prompt is open, then restore the previous
7
+ source. A Chinese input method otherwise swallows single-letter keys. The fork switches
8
+ the comment and edit boxes back to the writing source and binds `Ctrl+E` to edit. New
9
+ `inputSource` option: `false` disables, a path selects another helper.
10
+
3
11
  ## 0.8.1 — Antigravity (AGY) support and uncompressed history
4
12
 
5
13
  - Antigravity CLI (AGY) support via `agy-annotate`:
package/README.md CHANGED
@@ -210,13 +210,25 @@ delivery path is **q → confirm** and does not need clipboard access.
210
210
  With the [fork](#match-opencodes-colors-fork-required) (branch `local/opencode`; proposed
211
211
  upstream in [plannotator/plannotator-tui#109](https://github.com/plannotator/plannotator-tui/pull/109)),
212
212
  **`q`** with notes returns and submits them without the OpenCode dialog. **`Ctrl+S`**
213
- does the same mid-comment, saving the comment first, and also works while a Chinese
214
- input method is active. The header's **Send N back (q)** button does the same.
213
+ does the same mid-comment, saving the comment first. The header's **Send N back (q)**
214
+ button does the same as `q`.
215
215
  **`Ctrl+C`** returns without sending, and OpenCode asks whether to send. `E` and `S` send as well,
216
216
  following any `[keys]` rebinding, and the clipboard copy and Review menu (resend, finish, archive) are hidden
217
217
  because OpenCode owns delivery. Upstream binaries ignore the handoff and keep
218
218
  **q → confirm**.
219
219
 
220
+ ### Chinese and other input methods
221
+
222
+ An input method holds plain letters while it composes, so review keys such as `e`, `q`
223
+ and `s`, and OpenCode's permission shortcuts, do nothing. With
224
+ [Slash Saver](https://github.com/nxxxsooo/slash-saver) 1.1+ installed in `/Applications`,
225
+ the plugin selects its configured ASCII source while you browse a review or answer a
226
+ permission prompt, and restores your source afterwards. With the fork, the comment and edit
227
+ boxes switch back to your writing source while open. Set `"inputSource": false` in the
228
+ plugin's `options` to turn this off, or a path to another helper with the same
229
+ `input-source current|select|ascii` commands. The fork also binds **`Ctrl+E`** to edit,
230
+ which an input method passes through.
231
+
220
232
  Opening a review makes no model call. Confirming sends a normal user prompt and
221
233
  resumes the **original session**, even if the active tab changes. Empty and
222
234
  cancelled reviews submit nothing.
package/agy/cli.mjs CHANGED
@@ -14,6 +14,7 @@ import { startAgyDaemon } from "./daemon.mjs"
14
14
  import { listTargets, registryRoot } from "../bridge/receiver.mjs"
15
15
  import { browserTarget } from "../targets.mjs"
16
16
  import { prepareTheme } from "../theme.mjs"
17
+ import { createInputSource } from "../input-source.mjs"
17
18
 
18
19
  const execute = promisify(execFile)
19
20
 
@@ -267,6 +268,14 @@ async function cmdTui(targetPath, options) {
267
268
  // If binary does not support theme command, fallback to base env
268
269
  }
269
270
 
271
+ // Browse in ASCII so an input method cannot swallow review keys; see input-source.mjs.
272
+ const inputSource = createInputSource()
273
+ const textSource = await inputSource.ascii()
274
+ if (inputSource.command && textSource) {
275
+ env.PLANNOTATOR_TUI_INPUT_SOURCE = inputSource.command
276
+ env.PLANNOTATOR_TUI_TEXT_INPUT_SOURCE = textSource
277
+ }
278
+
270
279
  try {
271
280
  // Run Plannotator interactively
272
281
  const child = spawn(binary, [snapshotFile], {
@@ -281,7 +290,7 @@ async function cmdTui(targetPath, options) {
281
290
  else resolve(code)
282
291
  })
283
292
  child.on("error", reject)
284
- })
293
+ }).finally(() => inputSource.select(textSource))
285
294
 
286
295
  // Export annotations
287
296
  const { stdout } = await execute(binary, ["--export", snapshotFile], {
@@ -0,0 +1,61 @@
1
+ import { execFile } from "node:child_process"
2
+ import { accessSync, constants } from "node:fs"
3
+ import { promisify } from "node:util"
4
+
5
+ const execute = promisify(execFile)
6
+ export const slashSaver = "/Applications/Slash Saver.app/Contents/MacOS/SlashSaver"
7
+
8
+ // A Chinese input method swallows single-letter shortcuts, so key-driven screens switch to
9
+ // the ASCII source Slash Saver is configured with and restore the previous source after.
10
+ // `option` is a command path, false to disable, or undefined to use Slash Saver if installed.
11
+ export function createInputSource(option) {
12
+ const command = resolve(option)
13
+ const run = async args => (await execute(command, ["input-source", ...args], { timeout: 3000 })).stdout.trim()
14
+ // Switching is a convenience: a missing or failing helper never blocks a review.
15
+ const quietly = async args => {
16
+ try {
17
+ return await run(args)
18
+ } catch {
19
+ return undefined
20
+ }
21
+ }
22
+ return {
23
+ command,
24
+ /** Selects the ASCII source; returns the previous source ID. */
25
+ ascii: () => command ? quietly(["ascii"]) : Promise.resolve(undefined),
26
+ select: id => command && id ? quietly(["select", id]) : Promise.resolve(undefined),
27
+ }
28
+ }
29
+
30
+ function resolve(option) {
31
+ if (option === false) return undefined
32
+ if (typeof option === "string") return option
33
+ if (process.platform !== "darwin") return undefined
34
+ try {
35
+ accessSync(slashSaver, constants.X_OK)
36
+ return slashSaver
37
+ } catch {
38
+ return undefined
39
+ }
40
+ }
41
+
42
+ // Holds ASCII while any key-driven prompt is open and restores the source once all close.
43
+ export function createAsciiHold(inputSource) {
44
+ const open = new Set()
45
+ let previous
46
+ let pending = Promise.resolve()
47
+ const queue = step => (pending = pending.then(step))
48
+ return {
49
+ enter: id => queue(async () => {
50
+ if (open.has(id)) return
51
+ open.add(id)
52
+ if (open.size === 1) previous = await inputSource.ascii()
53
+ }),
54
+ leave: id => queue(async () => {
55
+ if (!open.delete(id) || open.size > 0) return
56
+ const restore = previous
57
+ previous = undefined
58
+ await inputSource.select(restore)
59
+ }),
60
+ }
61
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxxxsooo/opencode-annotate",
3
- "version": "0.8.1",
3
+ "version": "0.9.0",
4
4
  "description": "Unofficial OpenCode plugin: annotate replies, documents and webpages, then send the feedback to the originating session.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -23,6 +23,7 @@
23
23
  "tui.ts",
24
24
  "review.mjs",
25
25
  "theme.mjs",
26
+ "input-source.mjs",
26
27
  "targets.mjs",
27
28
  "web-review.mjs",
28
29
  "browser",
package/review.mjs CHANGED
@@ -7,6 +7,7 @@ import { promisify } from "node:util"
7
7
  import { createWebReview } from "./web-review.mjs"
8
8
  import { wantsBrowser } from "./targets.mjs"
9
9
  import { prepareTheme } from "./theme.mjs"
10
+ import { createInputSource } from "./input-source.mjs"
10
11
 
11
12
  const execute = promisify(execFile)
12
13
  const documentExtensions = new Set([".md", ".mdx", ".markdown", ".txt"])
@@ -151,6 +152,7 @@ export function createReviewCommand(context, options = {}) {
151
152
  const web = createWebReview(context, options.web)
152
153
  const binary = options.binary ?? context.options.binary ?? "plannotator-tui"
153
154
  const runInteractive = options.interactive ?? interactive
155
+ const inputSource = options.inputSource ?? createInputSource(context.options.inputSource)
154
156
  let active
155
157
  let disposed = false
156
158
  const notice = (message, variant = "info") => context.ui.toast.show({
@@ -214,11 +216,19 @@ export function createReviewCommand(context, options = {}) {
214
216
  const intentPath = path.join(directory, "send-intent")
215
217
  env.PLANNOTATOR_TUI_SEND_INTENT = intentPath
216
218
  context.ui.dialog.clear()
219
+ // Review keys are single letters an input method would swallow: browse in ASCII, and
220
+ // let a capable binary switch back to the user's source while a comment is written.
221
+ const textSource = await inputSource.ascii()
222
+ if (inputSource.command && textSource) {
223
+ env.PLANNOTATOR_TUI_INPUT_SOURCE = inputSource.command
224
+ env.PLANNOTATOR_TUI_TEXT_INPUT_SOURCE = textSource
225
+ }
217
226
  // OpenCode 2.1.1+ suspends and resumes asynchronously; resume forces a full repaint.
218
227
  await context.renderer.suspend()
219
228
  try {
220
229
  await runInteractive({ binary, file, cwd: directory, env, signal: controller.signal })
221
230
  } finally {
231
+ await inputSource.select(textSource)
222
232
  await context.renderer.resume()
223
233
  context.renderer.requestRender()
224
234
  }
package/tui.ts CHANGED
@@ -1,10 +1,16 @@
1
1
  import { Plugin } from "@opencode/plugin/tui"
2
2
  import { createReviewCommand } from "./review.mjs"
3
+ import { createAsciiHold, createInputSource } from "./input-source.mjs"
3
4
 
4
5
  export default Plugin.define({
5
6
  id: "opencode-annotate",
6
7
  setup(context) {
7
- const review = createReviewCommand(context)
8
+ const inputSource = createInputSource(context.options.inputSource)
9
+ const review = createReviewCommand(context, { inputSource })
10
+ // Permission prompts answer with single letters, which an input method swallows.
11
+ const hold = createAsciiHold(inputSource)
12
+ const stopAsked = context.data.on("permission.asked", event => hold.enter(event.data.id))
13
+ const stopReplied = context.data.on("permission.replied", event => hold.leave(event.data.requestID))
8
14
  // 2.0.22's keymap.layer needs the mounted provider; newer hosts also allow setup().
9
15
  const unmount = context.ui.slot({
10
16
  append: "app",
@@ -59,6 +65,8 @@ export default Plugin.define({
59
65
  },
60
66
  })
61
67
  return () => {
68
+ stopAsked()
69
+ stopReplied()
62
70
  review.dispose()
63
71
  unmount()
64
72
  }