diff --git a/package.json b/package.json index 7b3fa35..9358749 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@warp-dot-dev/opencode-warp", - "version": "0.1.1", + "version": "0.1.2", "description": "Warp terminal integration for OpenCode — native notifications and more", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/index.ts b/src/index.ts index 3564809..06eba70 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,8 +3,9 @@ import type { Event, Part, Permission } from "@opencode-ai/sdk" import { buildPayload } from "./payload" import { warpNotify } from "./notify" +import pkg from "../package.json" with { type: "json" } -const PLUGIN_VERSION = "0.1.0" +const PLUGIN_VERSION = pkg.version const NOTIFICATION_TITLE = "warp://cli-agent" export function truncate(str: string, maxLen: number): string { @@ -170,6 +171,18 @@ export const WarpPlugin: Plugin = async ({ client, directory }) => { warpNotify(NOTIFICATION_TITLE, body) }, + // Fires before a tool executes — used to detect the built-in + // "question" tool so Warp can notify the user that input is needed. + "tool.execute.before": async (input) => { + if (input.tool !== "question") return + + const cwd = directory || "" + const body = buildPayload("question_asked", input.sessionID, cwd, { + tool_name: input.tool, + }) + warpNotify(NOTIFICATION_TITLE, body) + }, + // Tool completion — fires after every tool call "tool.execute.after": async (input) => { const toolName = input.tool diff --git a/tests/index.test.ts b/tests/index.test.ts index 74cb408..454a3df 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -1,6 +1,7 @@ import { describe, it } from "node:test" import assert from "node:assert/strict" import { truncate, extractTextFromParts } from "../src/index" +import { buildPayload } from "../src/payload" describe("truncate", () => { it("returns string unchanged when under maxLen", () => { @@ -61,3 +62,25 @@ describe("extractTextFromParts", () => { assert.strictEqual(extractTextFromParts(parts), "") }) }) + +describe("PLUGIN_VERSION", () => { + it("resolves to a valid semver string from package.json", async () => { + const pkg = await import("../package.json", { with: { type: "json" } }) + const version = pkg.default.version + assert.ok(typeof version === "string", "version should be a string") + assert.match(version, /^\d+\.\d+\.\d+/, "version should be semver") + }) +}) + +describe("question_asked event", () => { + it("builds a valid question_asked payload", () => { + const payload = JSON.parse( + buildPayload("question_asked", "s1", "/tmp/proj", { + tool_name: "question", + }), + ) + assert.strictEqual(payload.event, "question_asked") + assert.strictEqual(payload.tool_name, "question") + assert.strictEqual(payload.session_id, "s1") + }) +}) diff --git a/tsconfig.json b/tsconfig.json index 4f4de38..e83644d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "moduleResolution": "bundler", "esModuleInterop": true, "strict": true, + "resolveJsonModule": true, "outDir": "dist", "declaration": true, "declarationMap": true,