@nxxxsooo/opencode-annotate 0.19.0 → 0.20.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 +8 -0
- package/README.md +26 -4
- package/agy/cli.mjs +243 -124
- package/agy/cli.test.mjs +51 -2
- package/agy/herdr.mjs +103 -0
- package/agy/herdr.test.mjs +54 -0
- package/agy/hooks.mjs +9 -2
- package/agy/inbox.mjs +22 -8
- package/agy/session.mjs +1 -2
- package/agy/skills/annotate/SKILL.md +9 -5
- package/agy/slash.mjs +90 -0
- package/agy/slash.test.mjs +62 -0
- package/agy/transcript.mjs +5 -2
- package/agy/transcript.test.mjs +1 -0
- package/browser/manifest.json +1 -1
- package/package.json +1 -1
- package/tui/README.md +58 -5
- package/tui/bin/darwin-arm64/annotate-tui +0 -0
- package/tui/bin/darwin-x64/annotate-tui +0 -0
- package/tui/bin/linux-arm64/annotate-tui +0 -0
- package/tui/bin/linux-x64/annotate-tui +0 -0
- package/tui/bin/win32-x64/annotate-tui.exe +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.20.0 — AGY reviews in Herdr
|
|
4
|
+
|
|
5
|
+
- In a configured AGY pane, run `/annotate` or press `prefix+a` to open the
|
|
6
|
+
native reviewer as a Herdr overlay without starting a model turn. **Send**
|
|
7
|
+
returns notes to the originating conversation; `q` and `Ctrl+C` do not send.
|
|
8
|
+
- Configured Kitty toolbar images render at full size in Herdr instead of
|
|
9
|
+
showing only their upper-left portion.
|
|
10
|
+
|
|
3
11
|
## 0.19.0 — Annotate files
|
|
4
12
|
|
|
5
13
|
- Choose **Annotate a file (TUI)** or run `/annotate-file [query]` to find text
|
package/README.md
CHANGED
|
@@ -114,6 +114,14 @@ Numbered `/annotate N`, `/annotate-last` and `/annotate-web` are retired. Use `/
|
|
|
114
114
|
|
|
115
115
|
## Herdr
|
|
116
116
|
|
|
117
|
+
Bind **prefix, then `a`** (`Ctrl+B`, then `a` by default) to
|
|
118
|
+
`annotate.review` using the [manifest and keybinding setup](tui/README.md#herdr).
|
|
119
|
+
In AGY this opens a floating Markdown reviewer without starting a model turn.
|
|
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`
|
|
122
|
+
route. With the AGY hooks installed, `/annotate` can open the same popup before
|
|
123
|
+
the model runs; the skill remains available as a fallback.
|
|
124
|
+
|
|
117
125
|
Run the bundled `annotate-tui` directly from a Herdr pane. Herdr needs an enabled
|
|
118
126
|
`annotate` plugin with a `doc` pane entrypoint; see the [TUI setup](tui/README.md#herdr).
|
|
119
127
|
OpenCode's `/annotate` keeps its own session delivery, even when OpenCode runs in Herdr.
|
|
@@ -151,11 +159,25 @@ documents and webpages.
|
|
|
151
159
|
|
|
152
160
|
## Antigravity (AGY) support
|
|
153
161
|
|
|
154
|
-
|
|
162
|
+
In a configured Herdr AGY pane, `/annotate` opens a native overlay before the
|
|
163
|
+
model runs. `prefix+a` opens the latest reply, and `/annotate <local-document>`
|
|
164
|
+
can review a file. Outside Herdr on macOS, the skill opens Ghostty or Terminal
|
|
165
|
+
for text reviews. URL and HTML targets use the browser companion.
|
|
166
|
+
|
|
167
|
+
Set up AGY manually from one installed package (`npm install -g @nxxxsooo/opencode-annotate`;
|
|
168
|
+
find the package under `npm root -g`) or a checkout with `npm run build:tui`:
|
|
169
|
+
|
|
170
|
+
1. Link the package's `agy/skills/annotate` directory as `~/.agents/skills/annotate`.
|
|
171
|
+
2. Merge the `agy-annotate` entries from `agy/hooks.json` into
|
|
172
|
+
`~/.gemini/config/hooks.json`, replacing `./hooks.mjs` in all three commands
|
|
173
|
+
with the absolute path to `agy/hooks.mjs` from that installation.
|
|
174
|
+
3. For Herdr, follow the [manifest and keybinding setup](tui/README.md#herdr)
|
|
175
|
+
using the CLI and native reviewer from the same installation.
|
|
176
|
+
|
|
177
|
+
**Send** (`Ctrl+S` or the Send button) returns feedback to the captured AGY
|
|
178
|
+
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.
|
|
155
180
|
|
|
156
|
-
- **Slash command `/annotate`**: Built-in AGY skill at `agy/skills/annotate/` handles text and explicit URL/HTML review within active AGY sessions.
|
|
157
|
-
- **Interactive TUI**: Uses the same bundled reviewer as OpenCode, with Dracula theme inheritance and one-key send.
|
|
158
|
-
- **Native Delivery**: Hooks into AGY lifecycle (`SessionStart`, `PreInvocation`, `Stop`) to deliver feedback directly into the conversation turn without network listeners.
|
|
159
181
|
- **CLI Commands**:
|
|
160
182
|
```sh
|
|
161
183
|
npx --package @nxxxsooo/opencode-annotate@latest agy-annotate status
|
package/agy/cli.mjs
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { spawn, execFile } from "node:child_process"
|
|
3
3
|
import { promisify } from "node:util"
|
|
4
|
-
import { mkdtemp, mkdir, rm, readFile, writeFile } from "node:fs/promises"
|
|
4
|
+
import { mkdtemp, mkdir, rename, rm, readFile, writeFile } from "node:fs/promises"
|
|
5
|
+
import { setTimeout as wait } from "node:timers/promises"
|
|
5
6
|
import path from "node:path"
|
|
6
7
|
import os from "node:os"
|
|
7
8
|
import { fileURLToPath } from "node:url"
|
|
8
9
|
import { randomUUID, createHash } from "node:crypto"
|
|
9
10
|
import { findSessionForDirectory, getActiveAgySessions } from "./session.mjs"
|
|
10
|
-
import { extractAgyReplies,
|
|
11
|
-
import { enqueueAnnotations, listPendingBatches
|
|
12
|
-
import { startAgyDaemon } from "./daemon.mjs"
|
|
13
|
-
import { listTargets, registryRoot } from "../bridge/receiver.mjs"
|
|
14
|
-
import { browserTarget } from "../targets.mjs"
|
|
15
|
-
import { openInBrowser } from "../scripts/browser-target.mjs"
|
|
11
|
+
import { extractAgyReplies, defaultBrainDir } from "./transcript.mjs"
|
|
12
|
+
import { enqueueAnnotations, listPendingBatches } from "./inbox.mjs"
|
|
16
13
|
import { prepareTheme } from "../theme.mjs"
|
|
17
14
|
import { createInputSource } from "../input-source.mjs"
|
|
18
15
|
import { resolveTuiBinary } from "../tui/binary.mjs"
|
|
16
|
+
import { captureHerdrConversation, deliverHerdrReview, focusedPane, herdrCommand, readHerdrAgent } from "./herdr.mjs"
|
|
19
17
|
|
|
20
18
|
const execute = promisify(execFile)
|
|
21
19
|
|
|
@@ -71,6 +69,7 @@ async function resolveSession(targetId) {
|
|
|
71
69
|
}
|
|
72
70
|
|
|
73
71
|
async function cmdStatus() {
|
|
72
|
+
const { listTargets } = await import("../bridge/receiver.mjs")
|
|
74
73
|
const sessions = getActiveAgySessions()
|
|
75
74
|
const targets = await listTargets()
|
|
76
75
|
|
|
@@ -93,6 +92,7 @@ async function cmdStatus() {
|
|
|
93
92
|
}
|
|
94
93
|
|
|
95
94
|
async function cmdWeb(targetArg, options) {
|
|
95
|
+
const { listTargets } = await import("../bridge/receiver.mjs")
|
|
96
96
|
const session = await resolveSession(options.session)
|
|
97
97
|
const targets = await listTargets()
|
|
98
98
|
let paired = targets.find(t => t.sessionID === session.conversationId)
|
|
@@ -121,10 +121,12 @@ async function cmdWeb(targetArg, options) {
|
|
|
121
121
|
console.log(` Open the "Annotate" extension and choose this session (Safari copies notes locally).`)
|
|
122
122
|
|
|
123
123
|
if (targetArg && targetArg.trim()) {
|
|
124
|
+
const { browserTarget } = await import("../targets.mjs")
|
|
124
125
|
const target = await browserTarget(targetArg, session.directory)
|
|
125
126
|
if (target?.url) {
|
|
126
127
|
console.log(` Opening target: ${target.url}`)
|
|
127
128
|
if (process.platform === "darwin") {
|
|
129
|
+
const { openInBrowser } = await import("../scripts/browser-target.mjs")
|
|
128
130
|
await openInBrowser(target.url, options)
|
|
129
131
|
}
|
|
130
132
|
}
|
|
@@ -148,86 +150,175 @@ async function cmdQueue(options) {
|
|
|
148
150
|
}
|
|
149
151
|
}
|
|
150
152
|
|
|
151
|
-
async function
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
153
|
+
export async function selectTuiOpener({ env, tty, exec = execute }) {
|
|
154
|
+
if (env.HERDR_ENV === "1" && env.HERDR_PANE_ID) {
|
|
155
|
+
const bin = env.HERDR_BIN_PATH || "herdr"
|
|
156
|
+
const response = await exec(bin, ["pane", "get", env.HERDR_PANE_ID], { env, timeout: 2000 }).catch(() => null)
|
|
157
|
+
if (response) {
|
|
158
|
+
const { result } = JSON.parse(response.stdout)
|
|
159
|
+
if (result?.pane?.pane_id && result.pane.tab_id) return { kind: "herdr", bin, pane: result.pane }
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const calledByAgent = Boolean(env.ANTIGRAVITY_CONVERSATION_ID || env.ANTIGRAVITY_AGENT || env.AGENT_TOOL_CALL)
|
|
163
|
+
return { kind: tty && !calledByAgent ? "tty" : "window" }
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async function openTuiWindow(directory, title) {
|
|
167
|
+
const launcher = path.join(directory, "launch.sh")
|
|
168
|
+
const quote = value => `'${value.replaceAll("'", "'\\''")}'`
|
|
169
|
+
const windowTitle = `Annotate: ${title}`.replace(/[\x00-\x1f\x7f-\x9f]/g, "")
|
|
170
|
+
const command = [process.execPath, fileURLToPath(import.meta.url), "tui-pane", directory].map(quote).join(" ")
|
|
171
|
+
await writeFile(launcher, `#!/bin/sh\nprintf '\\033]0;%s\\007' ${quote(windowTitle)}\nexec ${command}\n`, { mode: 0o700 })
|
|
172
|
+
try {
|
|
173
|
+
await execute("open", ["-na", "Ghostty", "--args", "--window-width=172", "--window-height=48", `--title=${windowTitle}`, "-e", launcher])
|
|
174
|
+
} catch {
|
|
173
175
|
try {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
} catch {
|
|
178
|
-
try {
|
|
179
|
-
await execute("osascript", ["-e", `tell application "Terminal" to do script "${launcherScript}"`, "-e", 'tell application "Terminal" to activate'])
|
|
180
|
-
launched = true
|
|
181
|
-
} catch (err) {
|
|
182
|
-
throw new Error(`Failed to spawn interactive review window: ${err.message}`)
|
|
183
|
-
}
|
|
176
|
+
await execute("osascript", ["-e", `tell application "Terminal" to do script ${JSON.stringify(quote(launcher))}`, "-e", 'tell application "Terminal" to activate'])
|
|
177
|
+
} catch (err) {
|
|
178
|
+
throw new Error(`Failed to spawn interactive review window: ${err.message}`)
|
|
184
179
|
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
185
182
|
|
|
186
|
-
|
|
187
|
-
|
|
183
|
+
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
|
+
try {
|
|
187
|
+
const { stdout } = await execute(bin, [
|
|
188
|
+
"plugin", "pane", "open", "--plugin", "annotate", "--entrypoint", "agy",
|
|
189
|
+
"--placement", "overlay",
|
|
190
|
+
"--focus", "--cwd", directory, "--env", `ANNOTATE_AGY_REVIEW_DIR=${directory}`,
|
|
191
|
+
], { timeout: 5000 })
|
|
192
|
+
const opened = JSON.parse(stdout).result?.plugin_pane?.pane
|
|
193
|
+
if (!opened?.pane_id) throw new Error("Herdr did not return the opened pane ID.")
|
|
194
|
+
if (opened.tab_id !== pane.tab_id) {
|
|
195
|
+
await execute(bin, ["pane", "close", opened.pane_id], { timeout: 2000 })
|
|
196
|
+
throw new Error("Herdr placed the overlay outside the AGY tab. Focus the AGY tab and try again.")
|
|
197
|
+
}
|
|
198
|
+
return opened.pane_id
|
|
199
|
+
} catch (err) {
|
|
200
|
+
throw new Error(`Failed to open the Herdr review overlay. Check that the annotate plugin has the agy pane entrypoint.\n${err.message}`)
|
|
201
|
+
}
|
|
202
|
+
}
|
|
188
203
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
// Still waiting
|
|
212
|
-
}
|
|
204
|
+
function runReviewer({ binary, snapshotFile, env }, directory) {
|
|
205
|
+
const child = spawn(binary, [snapshotFile], {
|
|
206
|
+
cwd: directory,
|
|
207
|
+
env: { ...process.env, ...env },
|
|
208
|
+
stdio: "inherit",
|
|
209
|
+
})
|
|
210
|
+
return new Promise((resolve, reject) => {
|
|
211
|
+
child.on("exit", (code, signal) => {
|
|
212
|
+
if (code === 0) resolve()
|
|
213
|
+
else reject(new Error(`Reviewer exited with ${signal || code}.`))
|
|
214
|
+
})
|
|
215
|
+
child.on("error", reject)
|
|
216
|
+
})
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async function runTuiPane(directory) {
|
|
220
|
+
if (!directory || !path.isAbsolute(directory)) throw new Error("Missing AGY review directory.")
|
|
221
|
+
let result = "closed"
|
|
222
|
+
try {
|
|
223
|
+
const request = JSON.parse(await readFile(path.join(directory, "request.json"), "utf8"))
|
|
224
|
+
if (request.sourcePane && focusedPane(process.env) !== request.sourcePane) {
|
|
225
|
+
throw new Error("Herdr focus changed before the popup opened. Open Annotate again from the AGY pane.")
|
|
213
226
|
}
|
|
214
|
-
|
|
227
|
+
await runReviewer(request, directory)
|
|
228
|
+
} catch (err) {
|
|
229
|
+
result = err.message
|
|
215
230
|
}
|
|
231
|
+
await writeFile(path.join(directory, "done.tmp"), result, { mode: 0o600 })
|
|
232
|
+
await rename(path.join(directory, "done.tmp"), path.join(directory, "done"))
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
async function readOptional(file) {
|
|
236
|
+
return readFile(file, "utf8").catch(err => {
|
|
237
|
+
if (err.code !== "ENOENT") throw err
|
|
238
|
+
return null
|
|
239
|
+
})
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
async function waitForTuiPane(directory, herdrPane) {
|
|
243
|
+
const deadline = Date.now() + 300_000
|
|
244
|
+
while (Date.now() < deadline) {
|
|
245
|
+
const result = await readOptional(path.join(directory, "done"))
|
|
246
|
+
if (result === "closed") return true
|
|
247
|
+
if (result !== null) throw new Error(result)
|
|
248
|
+
if (herdrPane) {
|
|
249
|
+
const { bin, id } = herdrPane
|
|
250
|
+
const missing = await execute(bin, ["pane", "get", id], { timeout: 2000 }).then(() => false, err => {
|
|
251
|
+
try { return JSON.parse(err.stderr).error?.code === "pane_not_found" } catch { return false }
|
|
252
|
+
})
|
|
253
|
+
if (missing && await readOptional(path.join(directory, "done")) === null) return false
|
|
254
|
+
}
|
|
255
|
+
await wait(500)
|
|
256
|
+
}
|
|
257
|
+
throw new Error("Timed out waiting for Annotate.")
|
|
258
|
+
}
|
|
216
259
|
|
|
260
|
+
// The hook is the only feedback channel. Neither the pane nor the waiting tool
|
|
261
|
+
// returns the Markdown, and no other pending batch can finish this review.
|
|
262
|
+
export async function finishTuiReview({ intentPath, conversationId, header, exportFeedback, enqueue = enqueueAnnotations, deliver }) {
|
|
263
|
+
if (await readOptional(intentPath) !== "send\n") return "Review closed without sending annotations."
|
|
264
|
+
const feedback = (await exportFeedback()).trim()
|
|
265
|
+
if (!feedback || feedback === "No annotations.") return "No annotations to send."
|
|
266
|
+
const batch = {
|
|
267
|
+
batchID: `tui-${randomUUID()}`,
|
|
268
|
+
markdown: `${header}\n\n${feedback}`,
|
|
269
|
+
promptID: `msg_${randomUUID()}`,
|
|
270
|
+
}
|
|
271
|
+
if (deliver) return deliver(batch)
|
|
272
|
+
await enqueue(conversationId, batch)
|
|
273
|
+
return "Annotations queued for this AGY conversation. The lifecycle hook will deliver them."
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
async function cmdTui(targetPath, options) {
|
|
277
|
+
const session = await resolveSession(options.session || process.env.ANTIGRAVITY_CONVERSATION_ID)
|
|
278
|
+
const binary = path.resolve(resolveTuiBinary(options.binary))
|
|
279
|
+
const opener = await selectTuiOpener({ env: process.env, tty: process.stdin.isTTY })
|
|
280
|
+
await reviewTui(targetPath, { session, binary, opener })
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
async function cmdHerdrReview(options, shortcut) {
|
|
284
|
+
const bin = process.env.HERDR_BIN_PATH || "herdr"
|
|
285
|
+
const binary = path.resolve(resolveTuiBinary(options.binary))
|
|
286
|
+
try {
|
|
287
|
+
const pane = shortcut?.pane ?? focusedPane(process.env)
|
|
288
|
+
const agent = await readHerdrAgent(bin, pane)
|
|
289
|
+
if (!shortcut && ["claude", "codex", "pi", "opencode"].includes(agent.agent)) {
|
|
290
|
+
const { stdout } = await execute(binary, ["herdr", "last", "--newest", "--deliver-to", pane], { timeout: 5000 })
|
|
291
|
+
console.log(stdout.trim())
|
|
292
|
+
return
|
|
293
|
+
}
|
|
294
|
+
if (agent.agent !== "agy") throw new Error("This action supports AGY, Claude, Codex, Pi, and OpenCode panes.")
|
|
295
|
+
const captured = { ...await captureHerdrConversation(bin, pane, agent), bin, pane, terminalId: agent.terminal_id }
|
|
296
|
+
if (shortcut && (!agent.focused || captured.conversationId !== shortcut.conversationId)) {
|
|
297
|
+
throw new Error("The AGY pane or conversation changed before Annotate opened.")
|
|
298
|
+
}
|
|
299
|
+
const session = { conversationId: captured.conversationId, title: `AGY ${captured.conversationId.slice(0, 8)}` }
|
|
300
|
+
const status = await reviewTui(shortcut?.document, { session, binary, opener: { kind: "popup" }, captured })
|
|
301
|
+
if (status) await herdrCommand(bin, ["notification", "show", "Annotate", "--body", status]).catch(() => {})
|
|
302
|
+
} catch (err) {
|
|
303
|
+
await herdrCommand(bin, ["notification", "show", "Annotate", "--body", err.message]).catch(() => {})
|
|
304
|
+
throw err
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
async function reviewTui(targetPath, { session, binary, opener, captured }) {
|
|
217
309
|
let sourceText = ""
|
|
218
310
|
let snapshotName = "last-reply.md"
|
|
219
311
|
let filePath = null
|
|
220
312
|
let sourceHash = null
|
|
221
313
|
|
|
222
314
|
if (targetPath) {
|
|
223
|
-
const resolvedPath = path.resolve(session.directory, targetPath)
|
|
315
|
+
const resolvedPath = path.isAbsolute(targetPath) ? targetPath : path.resolve(session.directory, targetPath)
|
|
224
316
|
sourceText = await readFile(resolvedPath, "utf8")
|
|
225
317
|
filePath = resolvedPath
|
|
226
318
|
snapshotName = path.basename(resolvedPath)
|
|
227
319
|
sourceHash = createHash("sha256").update(Buffer.from(sourceText)).digest("hex")
|
|
228
320
|
} else {
|
|
229
|
-
const
|
|
230
|
-
const latest = latestCompletedReply(replies)
|
|
321
|
+
const [latest] = await extractAgyReplies(defaultBrainDir(session.conversationId), { latestOnly: true })
|
|
231
322
|
if (!latest || !latest.text.trim()) {
|
|
232
323
|
throw new Error(`No completed assistant replies found in session "${session.title}".`)
|
|
233
324
|
}
|
|
@@ -243,67 +334,83 @@ async function cmdTui(targetPath, options) {
|
|
|
243
334
|
await mkdir(dataDir, { recursive: true, mode: 0o700 })
|
|
244
335
|
await writeFile(snapshotFile, sourceText, { mode: 0o600 })
|
|
245
336
|
|
|
246
|
-
let env = {
|
|
247
|
-
...process.env,
|
|
248
|
-
PLANNOTATOR_DATA_DIR: dataDir,
|
|
249
|
-
PLANNOTATOR_FEEDBACK_HISTORY: "0",
|
|
250
|
-
PLANNOTATOR_TUI_SEND_INTENT: intentPath,
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
env = await prepareTheme({ binary, theme: getAdaptedThemeTokens(), directory: tempDir, env })
|
|
254
|
-
|
|
255
|
-
// Browse in ASCII so an input method cannot swallow review keys; see input-source.mjs.
|
|
256
337
|
const inputSource = createInputSource()
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
env.PLANNOTATOR_TUI_INPUT_SOURCE = inputSource.command
|
|
260
|
-
env.PLANNOTATOR_TUI_TEXT_INPUT_SOURCE = textSource
|
|
261
|
-
}
|
|
338
|
+
let textSource
|
|
339
|
+
let complete = false
|
|
262
340
|
|
|
263
341
|
try {
|
|
264
|
-
//
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
env,
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}).finally(() => inputSource.select(textSource))
|
|
278
|
-
|
|
279
|
-
// Export annotations
|
|
280
|
-
const { stdout } = await execute(binary, ["--export", snapshotFile], {
|
|
281
|
-
cwd: tempDir,
|
|
282
|
-
env,
|
|
283
|
-
timeout: 15000,
|
|
284
|
-
})
|
|
285
|
-
const feedback = stdout.trim()
|
|
286
|
-
|
|
287
|
-
if (!feedback || feedback === "No annotations.") {
|
|
288
|
-
console.log("No annotations created. Returned to terminal.")
|
|
289
|
-
return
|
|
342
|
+
// Keep ASCII active before the first usable frame. Run the switch alongside
|
|
343
|
+
// theme setup, but wait for it even if the theme fails so it can be restored.
|
|
344
|
+
const [themedResult] = await Promise.allSettled([
|
|
345
|
+
prepareTheme({ binary, theme: getAdaptedThemeTokens(), directory: tempDir, env: process.env }),
|
|
346
|
+
inputSource.ascii().then(previous => { textSource = previous }),
|
|
347
|
+
])
|
|
348
|
+
if (themedResult.status === "rejected") throw themedResult.reason
|
|
349
|
+
const themed = themedResult.value
|
|
350
|
+
const env = {
|
|
351
|
+
PLANNOTATOR_DATA_DIR: dataDir,
|
|
352
|
+
PLANNOTATOR_FEEDBACK_HISTORY: "0",
|
|
353
|
+
PLANNOTATOR_TUI_SEND_INTENT: intentPath,
|
|
354
|
+
PLANNOTATOR_TUI_EXPLICIT_SEND: "1",
|
|
290
355
|
}
|
|
356
|
+
if (themed.PLANNOTATOR_TUI_CONFIG) env.PLANNOTATOR_TUI_CONFIG = themed.PLANNOTATOR_TUI_CONFIG
|
|
291
357
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
358
|
+
if (inputSource.command && textSource) {
|
|
359
|
+
env.PLANNOTATOR_TUI_INPUT_SOURCE = inputSource.command
|
|
360
|
+
env.PLANNOTATOR_TUI_TEXT_INPUT_SOURCE = textSource
|
|
361
|
+
}
|
|
362
|
+
const request = { binary, snapshotFile, env, sourcePane: captured?.pane }
|
|
363
|
+
if (opener.kind === "tty") {
|
|
364
|
+
await runReviewer(request, tempDir)
|
|
365
|
+
} else {
|
|
366
|
+
await writeFile(path.join(tempDir, "request.json"), JSON.stringify(request), { mode: 0o600 })
|
|
367
|
+
let herdrPane
|
|
368
|
+
if (captured) {
|
|
369
|
+
const { bin } = captured
|
|
370
|
+
const popupEnv = {
|
|
371
|
+
...env,
|
|
372
|
+
PLANNOTATOR_TUI_FILE: snapshotFile,
|
|
373
|
+
ANNOTATE_AGY_REVIEW_DIR: tempDir,
|
|
374
|
+
ANNOTATE_AGY_SOURCE_PANE: captured.pane,
|
|
375
|
+
}
|
|
376
|
+
const result = await herdrCommand(bin, [
|
|
377
|
+
"plugin", "pane", "open", "--plugin", process.env.HERDR_PLUGIN_ID || "annotate",
|
|
378
|
+
"--entrypoint", "agy-popup", "--cwd", tempDir,
|
|
379
|
+
...Object.entries(popupEnv).flatMap(([key, value]) => ["--env", `${key}=${value}`]),
|
|
380
|
+
])
|
|
381
|
+
if (result?.type !== "ok") throw new Error("The agy-popup entrypoint must declare placement = \"popup\".")
|
|
382
|
+
} else if (opener.kind === "herdr") herdrPane = { bin: opener.bin, id: await openHerdrTui(opener, tempDir) }
|
|
383
|
+
else await openTuiWindow(tempDir, session.title)
|
|
384
|
+
console.log(`Opened Annotate ${opener.kind === "herdr" ? "overlay" : opener.kind}. Waiting for Send or quit…`)
|
|
385
|
+
if (!await waitForTuiPane(tempDir, herdrPane)) {
|
|
386
|
+
console.log(`Review pane closed without sending. Review files retained at ${tempDir}`)
|
|
387
|
+
return
|
|
388
|
+
}
|
|
389
|
+
}
|
|
296
390
|
|
|
297
|
-
await
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
391
|
+
const status = await finishTuiReview({
|
|
392
|
+
intentPath,
|
|
393
|
+
conversationId: session.conversationId,
|
|
394
|
+
deliver: captured && (batch => deliverHerdrReview(captured, batch)),
|
|
395
|
+
header: filePath
|
|
396
|
+
? `Annotations on document \`${filePath}\` (SHA-256: ${sourceHash}):`
|
|
397
|
+
: `Annotations on latest assistant response in session "${session.title}":`,
|
|
398
|
+
exportFeedback: async () => {
|
|
399
|
+
const { stdout } = await execute(binary, ["--export", snapshotFile], {
|
|
400
|
+
cwd: tempDir, env: { ...process.env, ...env }, timeout: 15000,
|
|
401
|
+
})
|
|
402
|
+
await writeFile(path.join(tempDir, "feedback.md"), stdout, { mode: 0o600 })
|
|
403
|
+
return stdout
|
|
404
|
+
},
|
|
301
405
|
})
|
|
302
|
-
|
|
303
|
-
console.log(
|
|
304
|
-
|
|
406
|
+
complete = true
|
|
407
|
+
console.log(status)
|
|
408
|
+
return status
|
|
409
|
+
} catch (err) {
|
|
410
|
+
throw new Error(`${err.message} Review files retained at ${tempDir}`, { cause: err })
|
|
305
411
|
} finally {
|
|
306
|
-
await
|
|
412
|
+
await inputSource.select(textSource)
|
|
413
|
+
if (complete) await rm(tempDir, { recursive: true, force: true })
|
|
307
414
|
}
|
|
308
415
|
}
|
|
309
416
|
|
|
@@ -315,6 +422,17 @@ async function main() {
|
|
|
315
422
|
}
|
|
316
423
|
|
|
317
424
|
const command = args[0]
|
|
425
|
+
if (command === "tui-pane") {
|
|
426
|
+
await runTuiPane(args[1] || process.env.ANNOTATE_AGY_REVIEW_DIR)
|
|
427
|
+
return
|
|
428
|
+
}
|
|
429
|
+
if (command === "herdr-slash") {
|
|
430
|
+
const [, pane, conversationId, binary, document] = args
|
|
431
|
+
if (process.env.HERDR_ENV !== "1" || !pane || pane !== process.env.HERDR_PANE_ID ||
|
|
432
|
+
!conversationId || (document && !path.isAbsolute(document))) throw new Error("Invalid AGY slash launch.")
|
|
433
|
+
await cmdHerdrReview({ binary: binary || undefined }, { pane, conversationId, document })
|
|
434
|
+
return
|
|
435
|
+
}
|
|
318
436
|
const options = {}
|
|
319
437
|
let posArg = null
|
|
320
438
|
|
|
@@ -323,8 +441,6 @@ async function main() {
|
|
|
323
441
|
options.session = args[++i]
|
|
324
442
|
} else if (args[i] === "--binary") {
|
|
325
443
|
options.binary = args[++i]
|
|
326
|
-
} else if (args[i] === "--interactive-tty") {
|
|
327
|
-
options.interactiveTty = true
|
|
328
444
|
} else if (args[i] === "--browser") {
|
|
329
445
|
options.browser = args[++i]
|
|
330
446
|
} else if (!args[i].startsWith("-") && !posArg) {
|
|
@@ -342,6 +458,9 @@ async function main() {
|
|
|
342
458
|
case "tui":
|
|
343
459
|
await cmdTui(posArg, options)
|
|
344
460
|
break
|
|
461
|
+
case "herdr-review":
|
|
462
|
+
await cmdHerdrReview(options)
|
|
463
|
+
break
|
|
345
464
|
case "queue":
|
|
346
465
|
await cmdQueue(options)
|
|
347
466
|
break
|
package/agy/cli.test.mjs
CHANGED
|
@@ -2,11 +2,60 @@ import { test } from "node:test"
|
|
|
2
2
|
import assert from "node:assert/strict"
|
|
3
3
|
import path from "node:path"
|
|
4
4
|
import os from "node:os"
|
|
5
|
-
import { mkdir, rm } from "node:fs/promises"
|
|
6
|
-
import { getAdaptedThemeTokens } from "./cli.mjs"
|
|
5
|
+
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"
|
|
6
|
+
import { finishTuiReview, getAdaptedThemeTokens, selectTuiOpener } from "./cli.mjs"
|
|
7
|
+
import { handlePreInvocation, handleStop } from "./hooks.mjs"
|
|
8
|
+
import { enqueueAnnotations } from "./inbox.mjs"
|
|
7
9
|
import { bundledBinary, resolveTuiBinary } from "../tui/binary.mjs"
|
|
8
10
|
import { prepareTheme } from "../theme.mjs"
|
|
9
11
|
|
|
12
|
+
test("Herdr opens an overlay only via a reachable calling pane; other calls keep their opener", async () => {
|
|
13
|
+
const env = { HERDR_ENV: "1", HERDR_PANE_ID: "w5:p2", HERDR_BIN_PATH: "/fixture/herdr" }
|
|
14
|
+
const pane = { pane_id: "w5:p2", workspace_id: "w5", tab_id: "w5:t2" }
|
|
15
|
+
const exec = async (bin, args, options) => {
|
|
16
|
+
assert.equal(bin, env.HERDR_BIN_PATH)
|
|
17
|
+
assert.deepEqual(args, ["pane", "get", env.HERDR_PANE_ID])
|
|
18
|
+
assert.equal(options.env, env)
|
|
19
|
+
return { stdout: JSON.stringify({ result: { pane } }) }
|
|
20
|
+
}
|
|
21
|
+
assert.deepEqual(await selectTuiOpener({ env, exec, tty: false }), { kind: "herdr", bin: env.HERDR_BIN_PATH, pane })
|
|
22
|
+
const unavailable = async () => { throw new Error("no server") }
|
|
23
|
+
assert.deepEqual(await selectTuiOpener({ env, exec: unavailable, tty: false }), { kind: "window" })
|
|
24
|
+
assert.deepEqual(await selectTuiOpener({ env: {}, tty: true }), { kind: "tty" })
|
|
25
|
+
assert.deepEqual(await selectTuiOpener({ env: { AGENT_TOOL_CALL: "1" }, tty: true }), { kind: "window" })
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
test("only exact Send intent may export or enqueue; only one target hook gets the notes", async t => {
|
|
29
|
+
const root = await mkdtemp(path.join(os.tmpdir(), "agy-finish-test-"))
|
|
30
|
+
t.after(() => rm(root, { recursive: true, force: true }))
|
|
31
|
+
const intentPath = path.join(root, "intent")
|
|
32
|
+
const inboxRoot = path.join(root, "inbox")
|
|
33
|
+
const conversationId = "captured"
|
|
34
|
+
const note = "Private review content"
|
|
35
|
+
let exports = 0
|
|
36
|
+
const finish = () => finishTuiReview({
|
|
37
|
+
intentPath, conversationId, header: "Review header",
|
|
38
|
+
exportFeedback: async () => { exports++; return note },
|
|
39
|
+
enqueue: (id, batch) => enqueueAnnotations(id, batch, inboxRoot),
|
|
40
|
+
})
|
|
41
|
+
assert.match(await finish(), /without sending/)
|
|
42
|
+
await writeFile(intentPath, "cancel\n")
|
|
43
|
+
assert.match(await finish(), /without sending/)
|
|
44
|
+
assert.equal(exports, 0)
|
|
45
|
+
await writeFile(intentPath, "send\n")
|
|
46
|
+
const status = await finish()
|
|
47
|
+
assert.match(status, /queued/)
|
|
48
|
+
assert.ok(!status.includes(note))
|
|
49
|
+
assert.equal(exports, 1)
|
|
50
|
+
assert.deepEqual(await handleStop({ conversationId: "unrelated" }, { inboxRoot }), {})
|
|
51
|
+
const outcomes = await Promise.all([
|
|
52
|
+
handleStop({ conversationId }, { inboxRoot }),
|
|
53
|
+
handlePreInvocation({ conversationId }, { inboxRoot }),
|
|
54
|
+
])
|
|
55
|
+
assert.equal(JSON.stringify(outcomes).split(note).length - 1, 1)
|
|
56
|
+
assert.deepEqual(await handleStop({ conversationId }, { inboxRoot }), {})
|
|
57
|
+
})
|
|
58
|
+
|
|
10
59
|
test("both adapters resolve the packaged reviewer or an explicit custom binary", () => {
|
|
11
60
|
const custom = "/custom/bin/annotate-tui"
|
|
12
61
|
assert.equal(resolveTuiBinary(custom), custom)
|
package/agy/herdr.mjs
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { execFile } from "node:child_process"
|
|
2
|
+
import { promisify } from "node:util"
|
|
3
|
+
import { getActiveAgySessions } from "./session.mjs"
|
|
4
|
+
import { enqueueAnnotations } from "./inbox.mjs"
|
|
5
|
+
|
|
6
|
+
const execute = promisify(execFile)
|
|
7
|
+
const uuid = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i
|
|
8
|
+
|
|
9
|
+
export function focusedPane(env) {
|
|
10
|
+
if (env.HERDR_ENV !== "1") throw new Error("Run Annotate from a Herdr plugin action.")
|
|
11
|
+
const context = JSON.parse(env.HERDR_PLUGIN_CONTEXT_JSON || "{}")
|
|
12
|
+
if (!context.focused_pane_id) throw new Error("Focus an agent pane before opening Annotate.")
|
|
13
|
+
return context.focused_pane_id
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function herdrCommand(bin, args, timeout = 5000) {
|
|
17
|
+
const { stdout } = await execute(bin, args, { timeout })
|
|
18
|
+
return JSON.parse(stdout).result
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function readHerdrAgent(bin, pane, timeout) {
|
|
22
|
+
const agent = (await herdrCommand(bin, ["agent", "get", pane], timeout)).agent
|
|
23
|
+
if (!agent?.terminal_id) throw new Error("Herdr did not identify the focused agent terminal.")
|
|
24
|
+
return agent
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function promptHerdrAgent(bin, pane, markdown) {
|
|
28
|
+
try {
|
|
29
|
+
await herdrCommand(bin, ["agent", "prompt", pane, markdown])
|
|
30
|
+
} catch (err) {
|
|
31
|
+
let code
|
|
32
|
+
try { code = JSON.parse(err.stderr).error?.code } catch {}
|
|
33
|
+
if (code === "agent_blocked") throw new Error("AGY is blocked and needs input. Nothing was sent.")
|
|
34
|
+
if (code === "pane_not_found" || code === "agent_not_found" || code === "agent_not_ready") {
|
|
35
|
+
throw new Error("The AGY pane is no longer ready. Nothing was sent.")
|
|
36
|
+
}
|
|
37
|
+
throw new Error("Herdr did not confirm submission. Check the AGY conversation before retrying.")
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function resolveHerdrConversation(agent, processes = [], sessions = []) {
|
|
42
|
+
const ref = agent.agent_session
|
|
43
|
+
if (ref) {
|
|
44
|
+
const id = ref.kind === "id" ? ref.value
|
|
45
|
+
: ref.kind === "path" ? /(?:^|[/\\])brain[/\\]([^/\\]+)[/\\]\.system_generated[/\\]logs[/\\]transcript(?:_full)?\.jsonl$/.exec(ref.value)?.[1]
|
|
46
|
+
: undefined
|
|
47
|
+
if (!uuid.test(id ?? "")) throw new Error("Herdr did not report a valid AGY conversation ID.")
|
|
48
|
+
return { conversationId: id, reported: true }
|
|
49
|
+
}
|
|
50
|
+
// A cwd can be shared by multiple AGY panes. Match the live presence lock
|
|
51
|
+
// to the foreground AGY process instead of picking a directory match.
|
|
52
|
+
const pids = new Set(processes.map(p => p.pid))
|
|
53
|
+
const matches = sessions.filter(session => pids.has(session.pid))
|
|
54
|
+
if (matches.length !== 1 || !uuid.test(matches[0].conversationId)) {
|
|
55
|
+
throw new Error("Cannot identify one AGY conversation in this pane. Enable Herdr's Antigravity CLI session integration.")
|
|
56
|
+
}
|
|
57
|
+
return { conversationId: matches[0].conversationId, reported: false, pid: matches[0].pid }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function captureHerdrConversation(bin, pane, agent) {
|
|
61
|
+
if (agent.agent_session) return resolveHerdrConversation(agent)
|
|
62
|
+
const { process_info } = await herdrCommand(bin, ["pane", "process-info", "--pane", pane])
|
|
63
|
+
return resolveHerdrConversation(agent, process_info.foreground_processes, getActiveAgySessions())
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function herdrDeliveryRoute(captured, agent, current) {
|
|
67
|
+
if (agent.agent !== "agy" || agent.terminal_id !== captured.terminalId ||
|
|
68
|
+
current.conversationId !== captured.conversationId ||
|
|
69
|
+
(captured.reported && !current.reported) ||
|
|
70
|
+
(!captured.reported && !current.reported && captured.pid !== current.pid)) {
|
|
71
|
+
throw new Error("The pane no longer matches the captured AGY conversation. Nothing was sent.")
|
|
72
|
+
}
|
|
73
|
+
switch (agent.agent_status) {
|
|
74
|
+
case "idle":
|
|
75
|
+
case "done":
|
|
76
|
+
return "prompt"
|
|
77
|
+
case "working":
|
|
78
|
+
return "inbox"
|
|
79
|
+
case "blocked":
|
|
80
|
+
throw new Error("AGY is blocked and needs input. Nothing was sent.")
|
|
81
|
+
default:
|
|
82
|
+
throw new Error("AGY is not ready to receive feedback: Herdr could not determine its state. Nothing was sent.")
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function deliverHerdrReview(captured, batch, {
|
|
87
|
+
getAgent = readHerdrAgent, getConversation = captureHerdrConversation,
|
|
88
|
+
prompt = promptHerdrAgent,
|
|
89
|
+
enqueue = enqueueAnnotations,
|
|
90
|
+
} = {}) {
|
|
91
|
+
const { bin, pane, conversationId } = captured
|
|
92
|
+
const agent = await getAgent(bin, pane)
|
|
93
|
+
if (agent.agent !== "agy") throw new Error("The pane no longer contains AGY. Nothing was sent.")
|
|
94
|
+
const current = await getConversation(bin, pane, agent)
|
|
95
|
+
if (herdrDeliveryRoute(captured, agent, current) === "inbox") {
|
|
96
|
+
await enqueue(conversationId, batch)
|
|
97
|
+
return "Annotations queued for the captured AGY conversation."
|
|
98
|
+
}
|
|
99
|
+
// Herdr blocks a prompt if the pane needs input. Never retry or enqueue
|
|
100
|
+
// after an attempted prompt: a transport error may have followed admission.
|
|
101
|
+
await prompt(bin, pane, batch.markdown)
|
|
102
|
+
return "Annotations submitted to AGY."
|
|
103
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { test } from "node:test"
|
|
2
|
+
import assert from "node:assert/strict"
|
|
3
|
+
import { deliverHerdrReview, focusedPane, resolveHerdrConversation } from "./herdr.mjs"
|
|
4
|
+
|
|
5
|
+
const id = "605c8a34-bd80-4007-9164-345de6a351bd"
|
|
6
|
+
const other = "650229ca-30db-4a36-bb7c-b226a482c677"
|
|
7
|
+
const reference = { kind: "id", value: id }
|
|
8
|
+
|
|
9
|
+
test("action targets the focused pane from context, not the plugin process", () => {
|
|
10
|
+
const env = { HERDR_ENV: "1", HERDR_PANE_ID: "w1:p9", HERDR_PLUGIN_CONTEXT_JSON: '{"focused_pane_id":"w1:p2"}' }
|
|
11
|
+
assert.equal(focusedPane(env), "w1:p2")
|
|
12
|
+
assert.throws(() => focusedPane({ ...env, HERDR_PLUGIN_CONTEXT_JSON: "{}" }), /Focus an agent pane/)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
test("conversation routing prefers Herdr identity and refuses ambiguous foreground locks", () => {
|
|
16
|
+
const exact = resolveHerdrConversation({ agent_session: reference })
|
|
17
|
+
assert.deepEqual(exact, { conversationId: id, reported: true })
|
|
18
|
+
const path = `/home/.gemini/antigravity-cli/brain/${id}/.system_generated/logs/transcript.jsonl`
|
|
19
|
+
assert.deepEqual(resolveHerdrConversation({ agent_session: { kind: "path", value: path } }), exact)
|
|
20
|
+
assert.throws(() => resolveHerdrConversation({ agent_session: { kind: "id", value: "../unsafe" } }), /valid AGY/)
|
|
21
|
+
const processes = [{ pid: 14 }]
|
|
22
|
+
const session = { pid: 14, conversationId: id }
|
|
23
|
+
assert.deepEqual(resolveHerdrConversation({}, processes, [session, { pid: 15, conversationId: other }]),
|
|
24
|
+
{ conversationId: id, reported: false, pid: 14 })
|
|
25
|
+
for (const sessions of [[], [session, { ...session, conversationId: other }]]) {
|
|
26
|
+
assert.throws(() => resolveHerdrConversation({}, processes, sessions), /Cannot identify one/)
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test("delivery chooses exactly one route and refuses an unavailable or changed destination", async () => {
|
|
31
|
+
const captured = { bin: "herdr", pane: "w1:p2", terminalId: "term-a", conversationId: id, reported: true }
|
|
32
|
+
const batch = { markdown: "Feedback" }
|
|
33
|
+
const calls = []
|
|
34
|
+
const send = (agent_status, overrides = {}, promptError) => deliverHerdrReview(captured, batch, {
|
|
35
|
+
getAgent: async () => ({ agent: "agy", agent_status, terminal_id: "term-a", agent_session: reference, ...overrides }),
|
|
36
|
+
getConversation: async (_bin, _pane, agent) => resolveHerdrConversation(agent),
|
|
37
|
+
prompt: async (...args) => { calls.push(["prompt", ...args]); if (promptError) throw promptError },
|
|
38
|
+
enqueue: async (...args) => { calls.push(["inbox", ...args]) },
|
|
39
|
+
})
|
|
40
|
+
for (const status of ["idle", "done"]) {
|
|
41
|
+
assert.match(await send(status), /submitted/)
|
|
42
|
+
assert.deepEqual(calls.splice(0), [["prompt", "herdr", "w1:p2", "Feedback"]])
|
|
43
|
+
}
|
|
44
|
+
assert.match(await send("working"), /queued/)
|
|
45
|
+
assert.deepEqual(calls.splice(0), [["inbox", id, batch]])
|
|
46
|
+
await assert.rejects(send("blocked"), /blocked/)
|
|
47
|
+
await assert.rejects(send("unknown"), /not ready/)
|
|
48
|
+
await assert.rejects(send("working", { terminal_id: "term-b" }), /no longer matches/)
|
|
49
|
+
await assert.rejects(send("idle", { agent_session: { ...reference, value: other } }), /no longer matches/)
|
|
50
|
+
await assert.rejects(send("idle", { agent: "shell" }), /no longer contains AGY/)
|
|
51
|
+
assert.deepEqual(calls, [])
|
|
52
|
+
await assert.rejects(send("idle", {}, new Error("timeout")), /timeout/)
|
|
53
|
+
assert.deepEqual(calls, [["prompt", "herdr", "w1:p2", "Feedback"]])
|
|
54
|
+
})
|
package/agy/hooks.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { fileURLToPath } from "node:url"
|
|
|
3
3
|
import path from "node:path"
|
|
4
4
|
import { dequeueAnnotations, defaultInboxRoot } from "./inbox.mjs"
|
|
5
5
|
import { listTargets, registryRoot } from "../bridge/receiver.mjs"
|
|
6
|
+
import { annotateSlash, interceptAnnotateSlash } from "./slash.mjs"
|
|
6
7
|
|
|
7
8
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
8
9
|
|
|
@@ -43,9 +44,10 @@ export async function handleSessionStart(payload, { root = registryRoot(), inbox
|
|
|
43
44
|
return {}
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
export async function handlePreInvocation(payload, { inboxRoot = defaultInboxRoot() } = {}) {
|
|
47
|
+
export async function handlePreInvocation(payload, { inboxRoot = defaultInboxRoot(), intercept = interceptAnnotateSlash } = {}) {
|
|
47
48
|
const conversationId = payload.conversationId
|
|
48
49
|
if (!conversationId) return {}
|
|
50
|
+
if (await intercept(payload, { inboxRoot })) return { terminationBehavior: "terminate" }
|
|
49
51
|
|
|
50
52
|
const dequeued = await dequeueAnnotations(conversationId, inboxRoot)
|
|
51
53
|
if (!dequeued || !dequeued.combinedMarkdown.trim()) {
|
|
@@ -61,9 +63,14 @@ export async function handlePreInvocation(payload, { inboxRoot = defaultInboxRoo
|
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
|
|
64
|
-
export async function handleStop(payload, { inboxRoot = defaultInboxRoot() } = {}) {
|
|
66
|
+
export async function handleStop(payload, { inboxRoot = defaultInboxRoot(), env = process.env } = {}) {
|
|
65
67
|
const conversationId = payload.conversationId
|
|
66
68
|
if (!conversationId) return {}
|
|
69
|
+
// Draining here would restart the model immediately after slash interception.
|
|
70
|
+
if (env.HERDR_ENV === "1" && env.HERDR_PANE_ID && payload.terminationReason === "TERMINAL_CUSTOM_HOOK" &&
|
|
71
|
+
annotateSlash(payload.lastUserInput) !== undefined) {
|
|
72
|
+
return {}
|
|
73
|
+
}
|
|
67
74
|
|
|
68
75
|
const dequeued = await dequeueAnnotations(conversationId, inboxRoot)
|
|
69
76
|
if (!dequeued || !dequeued.combinedMarkdown.trim()) {
|
package/agy/inbox.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { mkdir, readdir, readFile, rm, writeFile, chmod } from "node:fs/promises"
|
|
1
|
+
import { mkdir, readdir, readFile, rename, rm, writeFile, chmod } from "node:fs/promises"
|
|
2
|
+
import { randomUUID } from "node:crypto"
|
|
2
3
|
import path from "node:path"
|
|
3
4
|
import os from "node:os"
|
|
4
5
|
|
|
@@ -20,7 +21,13 @@ export async function enqueueAnnotations(conversationId, payload, inboxRoot = de
|
|
|
20
21
|
review: payload.review,
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
const draft = path.join(sessionInbox, `.${randomUUID()}.tmp`)
|
|
25
|
+
try {
|
|
26
|
+
await writeFile(draft, JSON.stringify(record, null, 2), { mode: 0o600 })
|
|
27
|
+
await rename(draft, file)
|
|
28
|
+
} finally {
|
|
29
|
+
await rm(draft, { force: true })
|
|
30
|
+
}
|
|
24
31
|
return { file, batchID }
|
|
25
32
|
}
|
|
26
33
|
|
|
@@ -55,18 +62,25 @@ export async function dequeueAnnotations(conversationId, inboxRoot = defaultInbo
|
|
|
55
62
|
const batchIDs = []
|
|
56
63
|
|
|
57
64
|
for (const batch of batches) {
|
|
58
|
-
|
|
59
|
-
batchIDs.push(batch.batchID)
|
|
65
|
+
const claim = `${batch.filePath}.${randomUUID()}.claim`
|
|
60
66
|
try {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
// Read from the claimed path, never the listing: concurrent hooks
|
|
68
|
+
// cannot both read the moved batch from their unique claim paths.
|
|
69
|
+
await rename(batch.filePath, claim)
|
|
70
|
+
const claimed = JSON.parse(await readFile(claim, "utf8"))
|
|
71
|
+
if (claimed.markdown) markdowns.push(claimed.markdown)
|
|
72
|
+
batchIDs.push(claimed.batchID)
|
|
73
|
+
} catch (err) {
|
|
74
|
+
if (err.code !== "ENOENT") throw err
|
|
75
|
+
} finally {
|
|
76
|
+
await rm(claim, { force: true })
|
|
64
77
|
}
|
|
65
78
|
}
|
|
66
79
|
|
|
80
|
+
if (!batchIDs.length) return null
|
|
67
81
|
return {
|
|
68
82
|
batchIDs,
|
|
69
83
|
combinedMarkdown: markdowns.join("\n\n---\n\n"),
|
|
70
|
-
count:
|
|
84
|
+
count: batchIDs.length,
|
|
71
85
|
}
|
|
72
86
|
}
|
package/agy/session.mjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process"
|
|
2
|
-
import { DatabaseSync } from "node:sqlite"
|
|
3
2
|
import { fileURLToPath } from "node:url"
|
|
4
3
|
import path from "node:path"
|
|
5
4
|
import os from "node:os"
|
|
6
|
-
import { getAgySessionTitle } from "./receiver.mjs"
|
|
7
5
|
|
|
8
6
|
export const agyConfigDir = () => path.join(os.homedir(), ".gemini/antigravity-cli")
|
|
9
7
|
|
|
@@ -31,6 +29,7 @@ export function getActiveAgySessions(baseDir = agyConfigDir()) {
|
|
|
31
29
|
|
|
32
30
|
let db
|
|
33
31
|
try {
|
|
32
|
+
const { DatabaseSync } = process.getBuiltinModule("node:sqlite")
|
|
34
33
|
db = new DatabaseSync(dbPath, { open: true, readOnly: true })
|
|
35
34
|
} catch {
|
|
36
35
|
// Database might be temporarily locked or not exist
|
|
@@ -7,24 +7,28 @@ description: Review assistant replies or local documents in the bundled Annotate
|
|
|
7
7
|
|
|
8
8
|
Use this skill when the user runs `/annotate` or asks to annotate assistant responses, documents, or webpages.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
In a configured Herdr AGY pane, `/annotate` and `/annotate <local-document>` can be handled directly by the PreInvocation hook before the model runs. The Herdr shortcut `prefix+a` opens the latest reply the same way. These direct actions do not need the skill.
|
|
11
|
+
|
|
12
|
+
## Execution Guide for the Agent
|
|
13
|
+
|
|
14
|
+
If the request reaches this skill, run the matching command immediately. Use `agy-annotate` from the same installation as the AGY hooks. For a linked skill with no `agy-annotate` on PATH, run `node` with the absolute `agy/cli.mjs` path from that installation (`cli.mjs` is two directories above the linked skill's real directory).
|
|
11
15
|
|
|
12
16
|
### 1. When the user types `/annotate` (or asks to review the last reply):
|
|
13
17
|
Run the command:
|
|
14
18
|
```bash
|
|
15
|
-
|
|
19
|
+
agy-annotate tui
|
|
16
20
|
```
|
|
17
|
-
This opens the bundled reviewer in
|
|
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.
|
|
18
22
|
|
|
19
23
|
### 2. When the user specifies a document (e.g., `/annotate path/to/doc.md`):
|
|
20
24
|
Run the command:
|
|
21
25
|
```bash
|
|
22
|
-
|
|
26
|
+
agy-annotate tui "<path/to/doc.md>"
|
|
23
27
|
```
|
|
24
28
|
|
|
25
29
|
### 3. When the user provides a URL/HTML file (e.g., `/annotate page.html`) or asks for webpage review:
|
|
26
30
|
Run the command:
|
|
27
31
|
```bash
|
|
28
|
-
|
|
32
|
+
agy-annotate web [url-or-html-path]
|
|
29
33
|
```
|
|
30
34
|
Inform the user that the session is paired with Chrome and ready in the Annotate side panel (`Alt+Shift+A`). When the user sends notes from Chrome, they are delivered directly to this session.
|
package/agy/slash.mjs
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { spawn } from "node:child_process"
|
|
2
|
+
import { mkdir, rm, stat } from "node:fs/promises"
|
|
3
|
+
import path from "node:path"
|
|
4
|
+
import { fileURLToPath } from "node:url"
|
|
5
|
+
import { herdrCommand, readHerdrAgent, resolveHerdrConversation } from "./herdr.mjs"
|
|
6
|
+
import { defaultInboxRoot } from "./inbox.mjs"
|
|
7
|
+
|
|
8
|
+
export function annotateSlash(text) {
|
|
9
|
+
if (typeof text !== "string" || /[\r\n\0]/.test(text)) return undefined
|
|
10
|
+
const match = /^\/annotate(?:[ \t]+(.+))?$/.exec(text.trim())
|
|
11
|
+
if (!match) return undefined
|
|
12
|
+
let argument = match[1]
|
|
13
|
+
if (!argument) return null
|
|
14
|
+
const quote = argument[0]
|
|
15
|
+
if (quote === '"' || quote === "'") {
|
|
16
|
+
if (argument.length < 3 || !argument.endsWith(quote)) return undefined
|
|
17
|
+
argument = argument.slice(1, -1)
|
|
18
|
+
}
|
|
19
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(argument) || /\.html?$/i.test(argument)) return undefined
|
|
20
|
+
return argument
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function start({ pane, conversationId, document, binary, env }) {
|
|
24
|
+
const cli = fileURLToPath(new URL("./cli.mjs", import.meta.url))
|
|
25
|
+
const args = [cli, "herdr-slash", pane, conversationId, binary ?? ""]
|
|
26
|
+
if (document) args.push(document)
|
|
27
|
+
const child = spawn(process.execPath, args, { detached: true, stdio: "ignore", env })
|
|
28
|
+
return new Promise(resolve => {
|
|
29
|
+
child.once("error", () => resolve(false))
|
|
30
|
+
child.once("spawn", () => { child.unref(); resolve(true) })
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function claimTurn(inboxRoot, conversationId, count) {
|
|
35
|
+
const inbox = path.join(inboxRoot, conversationId)
|
|
36
|
+
await mkdir(inbox, { recursive: true, mode: 0o700 })
|
|
37
|
+
// AGY can replay invocation zero after a custom termination. The step
|
|
38
|
+
// count stays fixed on replay and advances on a newly submitted command.
|
|
39
|
+
const claim = path.join(inbox, `.slash-${count}`)
|
|
40
|
+
try {
|
|
41
|
+
await mkdir(claim, { mode: 0o700 })
|
|
42
|
+
return () => rm(claim, { force: true, recursive: true })
|
|
43
|
+
} catch (err) {
|
|
44
|
+
if (err.code !== "EEXIST") throw err
|
|
45
|
+
return null
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function interceptAnnotateSlash(payload, {
|
|
50
|
+
env = process.env, readAgent = readHerdrAgent, command = herdrCommand, launch = start,
|
|
51
|
+
inboxRoot = defaultInboxRoot(),
|
|
52
|
+
} = {}) {
|
|
53
|
+
const argument = annotateSlash(payload.lastUserInput)
|
|
54
|
+
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
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
const [agent, pluginList] = await Promise.all([
|
|
61
|
+
readAgent(bin, pane, 200),
|
|
62
|
+
command(bin, ["plugin", "list", "--json"], 200),
|
|
63
|
+
])
|
|
64
|
+
if (agent.agent !== "agy" || !agent.focused || !agent.agent_session ||
|
|
65
|
+
resolveHerdrConversation(agent).conversationId !== payload.conversationId) return false
|
|
66
|
+
const plugin = pluginList?.plugins?.find(plugin => plugin.plugin_id === "annotate" && plugin.enabled)
|
|
67
|
+
const popup = plugin?.panes?.find(pane => pane.id === "agy-popup" && pane.placement === "popup")
|
|
68
|
+
if (!popup) return false
|
|
69
|
+
const [executable, namespace, entrypoint] = popup.command ?? []
|
|
70
|
+
const binary = namespace === "herdr" && entrypoint === "hosted-pane" && path.isAbsolute(executable)
|
|
71
|
+
? executable : undefined
|
|
72
|
+
let document
|
|
73
|
+
if (argument !== null) {
|
|
74
|
+
if (!path.isAbsolute(payload.cwd ?? "")) return false
|
|
75
|
+
document = path.resolve(payload.cwd, argument)
|
|
76
|
+
if (!(await stat(document)).isFile()) return false
|
|
77
|
+
}
|
|
78
|
+
const release = await claimTurn(inboxRoot, payload.conversationId, payload.initialNumSteps)
|
|
79
|
+
if (!release) return true
|
|
80
|
+
let launched = false
|
|
81
|
+
try {
|
|
82
|
+
launched = await launch({ pane, conversationId: payload.conversationId, document, binary, env })
|
|
83
|
+
return launched
|
|
84
|
+
} finally {
|
|
85
|
+
if (!launched) await release()
|
|
86
|
+
}
|
|
87
|
+
} catch {
|
|
88
|
+
return false
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { test } from "node:test"
|
|
2
|
+
import assert from "node:assert/strict"
|
|
3
|
+
import { fileURLToPath } from "node:url"
|
|
4
|
+
import { mkdtemp, rm } from "node:fs/promises"
|
|
5
|
+
import path from "node:path"
|
|
6
|
+
import os from "node:os"
|
|
7
|
+
import { annotateSlash, interceptAnnotateSlash } from "./slash.mjs"
|
|
8
|
+
import { handlePreInvocation, handleStop } from "./hooks.mjs"
|
|
9
|
+
import { enqueueAnnotations } from "./inbox.mjs"
|
|
10
|
+
|
|
11
|
+
const conversationId = "605c8a34-bd80-4007-9164-345de6a351bd"
|
|
12
|
+
const pane = "w1:p1"
|
|
13
|
+
const env = { HERDR_ENV: "1", HERDR_PANE_ID: pane, HERDR_SOCKET_PATH: "/fixture/socket" }
|
|
14
|
+
const plugin = { plugin_id: "annotate", enabled: true, panes: [{ id: "agy-popup", placement: "popup" }] }
|
|
15
|
+
const agent = { agent: "agy", focused: true, agent_session: { kind: "id", value: conversationId } }
|
|
16
|
+
const payload = { conversationId, invocationNum: 0, initialNumSteps: 1, lastUserInput: "/annotate" }
|
|
17
|
+
|
|
18
|
+
test("recognizes standalone text and local document commands, not web or mixed input", () => {
|
|
19
|
+
assert.equal(annotateSlash("/annotate"), null)
|
|
20
|
+
assert.equal(annotateSlash('/annotate "file name.md"'), "file name.md")
|
|
21
|
+
for (const text of ["look at /annotate", "/annotated", "/annotate\nthen run it", "/annotate https://example.com", "/annotate note.html", '/annotate "unterminated']) {
|
|
22
|
+
assert.equal(annotateSlash(text), undefined)
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test("only terminates the initial invocation after handing off the verified pane and conversation", async t => {
|
|
27
|
+
const inboxRoot = await mkdtemp(path.join(os.tmpdir(), "annotate-slash-test-"))
|
|
28
|
+
t.after(() => rm(inboxRoot, { force: true, recursive: true }))
|
|
29
|
+
const calls = []
|
|
30
|
+
const options = { env, inboxRoot, readAgent: async () => agent, command: async () => ({ plugins: [plugin] }),
|
|
31
|
+
launch: async captured => { calls.push(captured); return true } }
|
|
32
|
+
const intercept = p => interceptAnnotateSlash(p, options)
|
|
33
|
+
assert.deepEqual(await handlePreInvocation(payload, { intercept }), { terminationBehavior: "terminate" })
|
|
34
|
+
assert.deepEqual(calls.shift(), { pane, conversationId, document: undefined, binary: undefined, env })
|
|
35
|
+
assert.equal(await intercept(payload), true)
|
|
36
|
+
assert.deepEqual(calls, [], "a repeated hook must not open the same turn again")
|
|
37
|
+
const cwd = fileURLToPath(new URL("../", import.meta.url))
|
|
38
|
+
assert.equal(await intercept({ ...payload, initialNumSteps: 2, cwd, lastUserInput: '/annotate "README.md"' }), true)
|
|
39
|
+
assert.equal(calls.shift().document, fileURLToPath(new URL("../README.md", import.meta.url)))
|
|
40
|
+
assert.equal(await intercept({ ...payload, invocationNum: 1 }), false)
|
|
41
|
+
assert.equal(await intercept({ ...payload, cwd, lastUserInput: "/annotate missing.md" }), false)
|
|
42
|
+
assert.equal(await interceptAnnotateSlash(payload, { ...options, env: {} }), false)
|
|
43
|
+
assert.equal(await interceptAnnotateSlash(payload, { ...options, readAgent: async () => ({ ...agent, focused: false }) }), false)
|
|
44
|
+
assert.equal(await interceptAnnotateSlash({ ...payload, conversationId: "different" }, options), false)
|
|
45
|
+
assert.equal(await interceptAnnotateSlash(payload, { ...options, command: async () => ({ plugins: [] }) }), false)
|
|
46
|
+
assert.deepEqual(calls, [])
|
|
47
|
+
const failed = { ...payload, initialNumSteps: 3 }
|
|
48
|
+
assert.equal(await interceptAnnotateSlash(failed, { ...options, launch: async () => false }), false)
|
|
49
|
+
assert.equal(await intercept(failed), true, "failed spawn releases the claim")
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test("a terminated local slash turn does not restart the model or consume queued notes", async t => {
|
|
53
|
+
const inboxRoot = await mkdtemp(path.join(os.tmpdir(), "annotate-slash-test-"))
|
|
54
|
+
t.after(() => rm(inboxRoot, { force: true, recursive: true }))
|
|
55
|
+
const note = "Previously queued note"
|
|
56
|
+
await enqueueAnnotations(conversationId, { batchID: "kept-note", markdown: note }, inboxRoot)
|
|
57
|
+
const intercepted = { ...payload, terminationReason: "TERMINAL_CUSTOM_HOOK" }
|
|
58
|
+
assert.deepEqual(await handleStop(intercepted, { env, inboxRoot }), {})
|
|
59
|
+
const next = await handlePreInvocation({ ...payload, lastUserInput: "Continue" }, { env, inboxRoot })
|
|
60
|
+
assert.match(next.injectSteps[0].userMessage, /Previously queued note/)
|
|
61
|
+
assert.deepEqual(await handleStop({ conversationId }, { env, inboxRoot }), {})
|
|
62
|
+
})
|
package/agy/transcript.mjs
CHANGED
|
@@ -35,7 +35,7 @@ export async function readFullStep(brainDir, stepIndex) {
|
|
|
35
35
|
return null
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export async function extractAgyReplies(brainDir, { signal } = {}) {
|
|
38
|
+
export async function extractAgyReplies(brainDir, { signal, latestOnly = false } = {}) {
|
|
39
39
|
const logPath = path.join(brainDir, ".system_generated/logs/transcript.jsonl")
|
|
40
40
|
let text
|
|
41
41
|
try {
|
|
@@ -54,6 +54,8 @@ export async function extractAgyReplies(brainDir, { signal } = {}) {
|
|
|
54
54
|
if (!step) continue
|
|
55
55
|
if (step.source !== "MODEL" || step.type !== "PLANNER_RESPONSE" || step.status !== "DONE") continue
|
|
56
56
|
|
|
57
|
+
const hasToolCalls = Array.isArray(step.tool_calls) && step.tool_calls.length > 0
|
|
58
|
+
if (latestOnly && hasToolCalls) continue
|
|
57
59
|
let content = step.content || ""
|
|
58
60
|
if (step.truncated_fields && step.truncated_fields.includes("content")) {
|
|
59
61
|
const full = await readFullStep(brainDir, step.step_index)
|
|
@@ -61,8 +63,8 @@ export async function extractAgyReplies(brainDir, { signal } = {}) {
|
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
const cleaned = cleanModelContent(content)
|
|
64
|
-
const hasToolCalls = Array.isArray(step.tool_calls) && step.tool_calls.length > 0
|
|
65
66
|
if (!cleaned && hasToolCalls) continue
|
|
67
|
+
if (latestOnly && !cleaned) continue
|
|
66
68
|
|
|
67
69
|
replies.push({
|
|
68
70
|
id: String(step.step_index),
|
|
@@ -71,6 +73,7 @@ export async function extractAgyReplies(brainDir, { signal } = {}) {
|
|
|
71
73
|
created: Date.parse(step.created_at) || Date.now(),
|
|
72
74
|
toolCalls: step.tool_calls?.map(t => t.name) || [],
|
|
73
75
|
})
|
|
76
|
+
if (latestOnly) break
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
return replies
|
package/agy/transcript.test.mjs
CHANGED
|
@@ -68,6 +68,7 @@ test("extractAgyReplies extracts completed and in-progress replies, handling tru
|
|
|
68
68
|
const latest = latestCompletedReply(replies)
|
|
69
69
|
assert.ok(latest)
|
|
70
70
|
assert.equal(latest.id, "2")
|
|
71
|
+
assert.deepEqual(await extractAgyReplies(root, { latestOnly: true }), [latest])
|
|
71
72
|
})
|
|
72
73
|
|
|
73
74
|
test("extractAgyReplies returns empty array when transcript does not exist", async () => {
|
package/browser/manifest.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"manifest_version": 3,
|
|
3
3
|
"name": "OpenCode Annotate",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.20.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxxxsooo/opencode-annotate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.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",
|
package/tui/README.md
CHANGED
|
@@ -73,19 +73,69 @@ id = "doc"
|
|
|
73
73
|
title = "Annotate"
|
|
74
74
|
placement = "overlay"
|
|
75
75
|
command = ["/absolute/path/to/annotate-tui", "herdr", "pane"]
|
|
76
|
+
|
|
77
|
+
# Optional: AGY overlay. Use absolute paths from the same Annotate installation.
|
|
78
|
+
[[panes]]
|
|
79
|
+
id = "agy"
|
|
80
|
+
title = "Annotate AGY"
|
|
81
|
+
placement = "overlay"
|
|
82
|
+
command = ["/absolute/path/to/agy-annotate", "tui-pane"]
|
|
83
|
+
|
|
84
|
+
[[panes]]
|
|
85
|
+
id = "agy-popup"
|
|
86
|
+
title = "Annotate AGY"
|
|
87
|
+
placement = "popup"
|
|
88
|
+
width = "90%"
|
|
89
|
+
height = "90%"
|
|
90
|
+
command = ["/absolute/path/to/annotate-tui", "herdr", "hosted-pane"]
|
|
91
|
+
|
|
92
|
+
[[actions]]
|
|
93
|
+
id = "review"
|
|
94
|
+
title = "Annotate latest reply"
|
|
95
|
+
contexts = ["pane"]
|
|
96
|
+
command = ["/absolute/path/to/agy-annotate", "herdr-review", "--binary", "/absolute/path/to/annotate-tui"]
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
For a built macOS checkout, use its executable `agy/cli.mjs` and the
|
|
100
|
+
native `tui/bin/darwin-arm64/annotate-tui` (or `darwin-x64` on Intel).
|
|
101
|
+
|
|
102
|
+
Add this to Herdr's `config.toml` and reload the server configuration:
|
|
103
|
+
|
|
104
|
+
```toml
|
|
105
|
+
[[keys.command]]
|
|
106
|
+
key = "prefix+a"
|
|
107
|
+
type = "plugin_action"
|
|
108
|
+
command = "annotate.review"
|
|
109
|
+
description = "Annotate latest reply"
|
|
76
110
|
```
|
|
77
111
|
|
|
112
|
+
Press your prefix (default `Ctrl+B`) then `a` in the agent pane. The AGY action
|
|
113
|
+
opens a 90% × 90% modal using the pane manifest's `popup` placement. Herdr 0.9.5
|
|
114
|
+
does not accept `popup` as a `--placement` CLI override. Send rechecks the AGY
|
|
115
|
+
conversation before starting a turn in an idle/done pane or queuing to the AGY
|
|
116
|
+
hooks while Herdr reports it is working. A blocked, unknown, or changed
|
|
117
|
+
destination keeps the notes and shows the recovery path. With matching AGY
|
|
118
|
+
hooks, `/annotate` and `/annotate <local-document>` also open this popup before
|
|
119
|
+
the model runs. See the [AGY setup](../README.md#antigravity-agy-support) for
|
|
120
|
+
`SessionStart`, `PreInvocation`, and `Stop`. If the pane or conversation
|
|
121
|
+
cannot be verified, the skill handles the command instead.
|
|
122
|
+
|
|
78
123
|
`herdr pane` is the plugin entrypoint: it reads the file, reply or terminal source
|
|
79
124
|
passed by the launcher. Set `--placement overlay|split|tab|zoomed` on `herdr open`,
|
|
80
|
-
`herdr last` or `herdr terminal`; the default is `overlay`.
|
|
81
|
-
`
|
|
82
|
-
|
|
125
|
+
`herdr last` or `herdr terminal`; the default is `overlay`. If your Annotate
|
|
126
|
+
`tui.toml` uses `popup_width` or `popup_height`, remove those settings and
|
|
127
|
+
replace its `placement = "popup"` with a supported value. This does not
|
|
128
|
+
affect `placement = "popup"` in the Herdr plugin manifest above.
|
|
129
|
+
Agent delivery uses `herdr agent prompt`; a blocked send
|
|
83
130
|
leaves notes pending for a manual retry and attempts an OSC 52 clipboard copy.
|
|
84
131
|
OpenCode's `/annotate` clears the inherited `HERDR_*` variables before launching
|
|
85
132
|
the reviewer, so it does not use this route.
|
|
86
133
|
|
|
87
|
-
|
|
88
|
-
|
|
134
|
+
For AGY, the `agy-popup` pane runs `herdr hosted-pane` on a private Markdown
|
|
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.
|
|
138
|
+
|
|
89
139
|
|
|
90
140
|
## Local image-toolbar trial
|
|
91
141
|
|
|
@@ -113,6 +163,9 @@ multiplexer settings. Unknown transports still require your own verification. Di
|
|
|
113
163
|
removing all three `toolbar_image*` keys if your terminal cannot display it. Restart after
|
|
114
164
|
changing font/cell pixel size. A configured cell-size override takes precedence and skips
|
|
115
165
|
the ioctl; measure at the actual display's DPI, including through any PTY proxy.
|
|
166
|
+
Cell pixels determine the artwork canvas; the Kitty virtual placement declares its
|
|
167
|
+
column count and one-row height explicitly so the placeholder grid does not depend on
|
|
168
|
+
the terminal or PTY proxy reporting the same pixel dimensions.
|
|
116
169
|
|
|
117
170
|
Artwork is approximately square, centered at 85% of one cell row's height, with a bold,
|
|
118
171
|
action-colored key beside each
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|