@nxxxsooo/opencode-annotate 0.7.0 → 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.
@@ -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,14 +1,17 @@
1
1
  {
2
2
  "name": "@nxxxsooo/opencode-annotate",
3
- "version": "0.7.0",
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",
7
7
  "exports": {
8
8
  "./tui": "./tui.ts"
9
9
  },
10
+ "bin": {
11
+ "agy-annotate": "./agy/cli.mjs"
12
+ },
10
13
  "scripts": {
11
- "test": "node --test *.test.mjs bridge/*.test.mjs",
14
+ "test": "node --test *.test.mjs bridge/*.test.mjs agy/*.test.mjs",
12
15
  "test:browser": "node tests/browser.mjs",
13
16
  "install:bridge": "node scripts/install-bridge.mjs",
14
17
  "install:plugin": "node scripts/install-plugin.mjs",
@@ -20,12 +23,14 @@
20
23
  "tui.ts",
21
24
  "review.mjs",
22
25
  "theme.mjs",
26
+ "input-source.mjs",
23
27
  "targets.mjs",
24
28
  "web-review.mjs",
25
29
  "browser",
26
30
  "bridge/native-host.mjs",
27
31
  "bridge/receiver.mjs",
28
32
  "bridge/wire.mjs",
33
+ "agy",
29
34
  "scripts/install-bridge.mjs",
30
35
  "scripts/install-plugin.mjs",
31
36
  "scripts/migrate-page-context.mjs",
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"])
@@ -76,6 +77,10 @@ function eligibleReplies(messages) {
76
77
  return textMessages(messages).filter(message => !message.progress).map(({ id, text }) => ({ id, text }))
77
78
  }
78
79
 
80
+ // OpenCode 2.2.0 compresses API responses at roughly 80 KB/s, so a page of long
81
+ // replies took 10–30 s; uncompressed, the same local page arrives in milliseconds.
82
+ const uncompressed = { "accept-encoding": "identity" }
83
+
79
84
  // Walk the session-scoped history newest first; the UI cache holds only a recent page.
80
85
  async function* history(client, sessionID, signal) {
81
86
  const seen = new Set()
@@ -85,7 +90,7 @@ async function* history(client, sessionID, signal) {
85
90
  const page = await client.message.list({
86
91
  sessionID, type: "assistant", limit: 50,
87
92
  ...(cursor ? { cursor } : { order: "desc" }),
88
- }, { signal })
93
+ }, { signal, headers: uncompressed })
89
94
  yield page.data
90
95
  cursor = page.cursor?.next
91
96
  if (cursor && seen.has(cursor)) throw new Error("Session history returned a repeated page cursor.")
@@ -147,6 +152,7 @@ export function createReviewCommand(context, options = {}) {
147
152
  const web = createWebReview(context, options.web)
148
153
  const binary = options.binary ?? context.options.binary ?? "plannotator-tui"
149
154
  const runInteractive = options.interactive ?? interactive
155
+ const inputSource = options.inputSource ?? createInputSource(context.options.inputSource)
150
156
  let active
151
157
  let disposed = false
152
158
  const notice = (message, variant = "info") => context.ui.toast.show({
@@ -210,11 +216,19 @@ export function createReviewCommand(context, options = {}) {
210
216
  const intentPath = path.join(directory, "send-intent")
211
217
  env.PLANNOTATOR_TUI_SEND_INTENT = intentPath
212
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
+ }
213
226
  // OpenCode 2.1.1+ suspends and resumes asynchronously; resume forces a full repaint.
214
227
  await context.renderer.suspend()
215
228
  try {
216
229
  await runInteractive({ binary, file, cwd: directory, env, signal: controller.signal })
217
230
  } finally {
231
+ await inputSource.select(textSource)
218
232
  await context.renderer.resume()
219
233
  context.renderer.requestRender()
220
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
  }