Skip to content

Commit a0ef6e8

Browse files
authored
add hook for ask question tool (#9)
* add hook for ask question tool * fix typo
1 parent 70eea60 commit a0ef6e8

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@warp-dot-dev/opencode-warp",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "Warp terminal integration for OpenCode — native notifications and more",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/index.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import type { Event, Part, Permission } from "@opencode-ai/sdk"
33

44
import { buildPayload } from "./payload"
55
import { warpNotify } from "./notify"
6+
import pkg from "../package.json" with { type: "json" }
67

7-
const PLUGIN_VERSION = "0.1.0"
8+
const PLUGIN_VERSION = pkg.version
89
const NOTIFICATION_TITLE = "warp://cli-agent"
910

1011
export function truncate(str: string, maxLen: number): string {
@@ -58,7 +59,7 @@ export const WarpPlugin: Plugin = async ({ client, directory }) => {
5859
service: "opencode-warp",
5960
level: "warn",
6061
message:
61-
"⚠️ Detected unsupported Warp version. Please update Warp to use this pluginDetected unsupported Warp version. Please update Warp to use this plugin",
62+
"⚠️ Detected unsupported Warp version. Please update Warp to use this plugin.",
6263
},
6364
})
6465
return {}
@@ -170,6 +171,18 @@ export const WarpPlugin: Plugin = async ({ client, directory }) => {
170171
warpNotify(NOTIFICATION_TITLE, body)
171172
},
172173

174+
// Fires before a tool executes — used to detect the built-in
175+
// "question" tool so Warp can notify the user that input is needed.
176+
"tool.execute.before": async (input) => {
177+
if (input.tool !== "question") return
178+
179+
const cwd = directory || ""
180+
const body = buildPayload("question_asked", input.sessionID, cwd, {
181+
tool_name: input.tool,
182+
})
183+
warpNotify(NOTIFICATION_TITLE, body)
184+
},
185+
173186
// Tool completion — fires after every tool call
174187
"tool.execute.after": async (input) => {
175188
const toolName = input.tool

tests/index.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, it } from "node:test"
22
import assert from "node:assert/strict"
33
import { truncate, extractTextFromParts } from "../src/index"
4+
import { buildPayload } from "../src/payload"
45

56
describe("truncate", () => {
67
it("returns string unchanged when under maxLen", () => {
@@ -61,3 +62,25 @@ describe("extractTextFromParts", () => {
6162
assert.strictEqual(extractTextFromParts(parts), "")
6263
})
6364
})
65+
66+
describe("PLUGIN_VERSION", () => {
67+
it("resolves to a valid semver string from package.json", async () => {
68+
const pkg = await import("../package.json", { with: { type: "json" } })
69+
const version = pkg.default.version
70+
assert.ok(typeof version === "string", "version should be a string")
71+
assert.match(version, /^\d+\.\d+\.\d+/, "version should be semver")
72+
})
73+
})
74+
75+
describe("question_asked event", () => {
76+
it("builds a valid question_asked payload", () => {
77+
const payload = JSON.parse(
78+
buildPayload("question_asked", "s1", "/tmp/proj", {
79+
tool_name: "question",
80+
}),
81+
)
82+
assert.strictEqual(payload.event, "question_asked")
83+
assert.strictEqual(payload.tool_name, "question")
84+
assert.strictEqual(payload.session_id, "s1")
85+
})
86+
})

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"moduleResolution": "bundler",
66
"esModuleInterop": true,
77
"strict": true,
8+
"resolveJsonModule": true,
89
"outDir": "dist",
910
"declaration": true,
1011
"declarationMap": true,

0 commit comments

Comments
 (0)