@americanumberoneaokgoodtimes/p-plugin 1.0.0 → 1.0.1
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/opencode/plugin.d.ts +14 -3
- package/opencode/plugin.js +28 -3
- package/package.json +1 -1
- package/scripts/prompt-manager.test.mjs +19 -1
package/opencode/plugin.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface PromptManagerPluginHooks {
|
|
2
2
|
config: (config: Record<string, any>) => Promise<void>;
|
|
3
3
|
"command.execute.before": (
|
|
4
4
|
input: { sessionID?: string; command: string; arguments?: string },
|
|
@@ -8,6 +8,17 @@ export declare const PromptManagerPlugin: (ctx: unknown) => Promise<{
|
|
|
8
8
|
input: { sessionID?: string; messageID?: string; [key: string]: unknown },
|
|
9
9
|
output: { message?: unknown; parts: Array<{ type: string; text?: string; [key: string]: unknown }> },
|
|
10
10
|
) => Promise<void>;
|
|
11
|
-
}
|
|
11
|
+
}
|
|
12
12
|
|
|
13
|
-
export
|
|
13
|
+
export declare const createPromptManagerHooks: (ctx: unknown) => Promise<PromptManagerPluginHooks>;
|
|
14
|
+
export declare const PromptManagerPlugin: (ctx: unknown) => Promise<PromptManagerPluginHooks>;
|
|
15
|
+
|
|
16
|
+
export interface OpenCodePluginDefinition {
|
|
17
|
+
id: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
setup: (ctx: unknown) => Promise<PromptManagerPluginHooks>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export declare const plugin: OpenCodePluginDefinition;
|
|
24
|
+
export default plugin;
|
package/opencode/plugin.js
CHANGED
|
@@ -45,9 +45,9 @@ function replacementForResult(result) {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
* OpenCode plugin
|
|
48
|
+
* OpenCode plugin hook factory.
|
|
49
49
|
*/
|
|
50
|
-
export const
|
|
50
|
+
export const createPromptManagerHooks = async (_ctx) => {
|
|
51
51
|
const recentlyHandled = new Map();
|
|
52
52
|
const DEDUP_TTL_MS = 5000;
|
|
53
53
|
|
|
@@ -130,4 +130,29 @@ export const PromptManagerPlugin = async (_ctx) => {
|
|
|
130
130
|
};
|
|
131
131
|
};
|
|
132
132
|
|
|
133
|
-
|
|
133
|
+
/**
|
|
134
|
+
* OpenCode v1 function-style plugin entrypoint.
|
|
135
|
+
*/
|
|
136
|
+
export const PromptManagerPlugin = async (ctx) => {
|
|
137
|
+
return await createPromptManagerHooks(ctx);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* OpenCode v2 definition object.
|
|
142
|
+
* OpenCode v2 requires the default export to be an object with an `id` string
|
|
143
|
+
* and a `setup` (or `effect`) function:
|
|
144
|
+
* Schema.Union([
|
|
145
|
+
* Schema.Struct({ id: Schema.String, setup: Schema.Function }),
|
|
146
|
+
* Schema.Struct({ id: Schema.String, effect: Schema.Function })
|
|
147
|
+
* ])
|
|
148
|
+
*/
|
|
149
|
+
export const plugin = {
|
|
150
|
+
id: "@americanumberoneaokgoodtimes/p-plugin",
|
|
151
|
+
name: "prompt-manager",
|
|
152
|
+
description: "Prompt Manager plugin for OpenCode (/p)",
|
|
153
|
+
setup: async (ctx) => {
|
|
154
|
+
return await createPromptManagerHooks(ctx);
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export default plugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@americanumberoneaokgoodtimes/p-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Multi-tool Prompt Manager plugin for Antigravity, Claude Code, and OpenCode (/p <id>, /p e <id> <text>, /p d <id>).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
import { executePromptCommand } from "./handler.mjs";
|
|
18
18
|
import { isFirstInvocationOfTurn } from "./p-hook.mjs";
|
|
19
19
|
import { handleMessage } from "./mcp-server.mjs";
|
|
20
|
-
import { PromptManagerPlugin } from "../opencode/plugin.js";
|
|
20
|
+
import defaultPlugin, { plugin, PromptManagerPlugin, createPromptManagerHooks } from "../opencode/plugin.js";
|
|
21
21
|
|
|
22
22
|
const PLUGIN_ROOT = path.resolve(import.meta.dirname, "..");
|
|
23
23
|
|
|
@@ -570,6 +570,24 @@ test("isFirstInvocationOfTurn scans across >64KB tool output chunks", () => {
|
|
|
570
570
|
}
|
|
571
571
|
});
|
|
572
572
|
|
|
573
|
+
test("OpenCode plugin exports support both v2 plugin definition and v1 function", async () => {
|
|
574
|
+
assert.equal(typeof defaultPlugin, "object");
|
|
575
|
+
assert.equal(defaultPlugin.id, "@americanumberoneaokgoodtimes/p-plugin");
|
|
576
|
+
assert.equal(typeof defaultPlugin.setup, "function");
|
|
577
|
+
assert.equal(defaultPlugin, plugin);
|
|
578
|
+
|
|
579
|
+
const hooksFromSetup = await defaultPlugin.setup({});
|
|
580
|
+
assert.equal(typeof hooksFromSetup["command.execute.before"], "function");
|
|
581
|
+
assert.equal(typeof hooksFromSetup["chat.message"], "function");
|
|
582
|
+
assert.equal(typeof hooksFromSetup.config, "function");
|
|
583
|
+
|
|
584
|
+
const hooksFromV1 = await PromptManagerPlugin({});
|
|
585
|
+
assert.equal(typeof hooksFromV1["command.execute.before"], "function");
|
|
586
|
+
|
|
587
|
+
const hooksFromFactory = await createPromptManagerHooks({});
|
|
588
|
+
assert.equal(typeof hooksFromFactory["command.execute.before"], "function");
|
|
589
|
+
});
|
|
590
|
+
|
|
573
591
|
test("OpenCode plugin normalizes leading slash, handles missing sessionID, and supports /p d", async () => {
|
|
574
592
|
const { dir, storePath } = makeTempStore();
|
|
575
593
|
const prevStore = process.env.PROMPT_MANAGER_STORE_PATH;
|