Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
15 changes: 14 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down Expand Up @@ -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")
})
})
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"moduleResolution": "bundler",
"esModuleInterop": true,
"strict": true,
"resolveJsonModule": true,
"outDir": "dist",
"declaration": true,
"declarationMap": true,
Expand Down
Loading