@caplets/opencode 0.0.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.
Files changed (3) hide show
  1. package/README.md +13 -0
  2. package/dist/index.js +51 -0
  3. package/package.json +36 -0
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # @caplets/opencode
2
+
3
+ Native OpenCode plugin for Caplets.
4
+
5
+ This package exposes configured Caplets as native OpenCode tools named `caplets_<id>`. It does not start the Caplets MCP server and does not edit `opencode.json`; prompt guidance is injected through OpenCode plugin hooks.
6
+
7
+ ```jsonc
8
+ {
9
+ "plugin": ["@caplets/opencode"],
10
+ }
11
+ ```
12
+
13
+ New or removed Caplets are snapshotted at plugin load. Restart OpenCode to refresh the native tool list.
package/dist/index.js ADDED
@@ -0,0 +1,51 @@
1
+ import { tool } from "@opencode-ai/plugin";
2
+ import { createNativeCapletsService, nativeCapletsSystemGuidance } from "@caplets/core/native";
3
+ import { operations } from "@caplets/core/generated-tool-input-schema";
4
+ //#region src/schema.ts
5
+ function capletsOpenCodeArgs() {
6
+ return {
7
+ operation: tool.schema.enum(operations),
8
+ query: tool.schema.string().optional(),
9
+ limit: tool.schema.number().int().positive().optional(),
10
+ tool: tool.schema.string().optional(),
11
+ arguments: tool.schema.record(tool.schema.string(), tool.schema.unknown()).optional(),
12
+ fields: tool.schema.array(tool.schema.string().min(1)).min(1).optional()
13
+ };
14
+ }
15
+ //#endregion
16
+ //#region src/index.ts
17
+ const plugin = async (_ctx) => {
18
+ const service = createNativeCapletsService();
19
+ registerProcessCleanup(service);
20
+ return createCapletsOpenCodeHooks(service);
21
+ };
22
+ async function createCapletsOpenCodeHooks(service) {
23
+ const capletTools = service.listTools();
24
+ const toolNames = capletTools.map((caplet) => caplet.toolName);
25
+ return {
26
+ tool: Object.fromEntries(capletTools.map((caplet) => [caplet.toolName, tool({
27
+ description: caplet.description,
28
+ args: capletsOpenCodeArgs(),
29
+ async execute(args) {
30
+ const result = await service.execute(caplet.caplet, args);
31
+ return typeof result === "string" ? result : JSON.stringify(result, null, 2);
32
+ }
33
+ })])),
34
+ "experimental.chat.system.transform": async (_input, output) => {
35
+ output.system.push(nativeCapletsSystemGuidance(toolNames));
36
+ }
37
+ };
38
+ }
39
+ function registerProcessCleanup(service) {
40
+ let closed = false;
41
+ const close = () => {
42
+ if (closed) return;
43
+ closed = true;
44
+ service.close();
45
+ };
46
+ process.once("beforeExit", close);
47
+ process.once("SIGINT", close);
48
+ process.once("SIGTERM", close);
49
+ }
50
+ //#endregion
51
+ export { createCapletsOpenCodeHooks, plugin as default };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@caplets/opencode",
3
+ "version": "0.0.0",
4
+ "description": "Native OpenCode plugin for Caplets.",
5
+ "files": [
6
+ "dist",
7
+ "README.md"
8
+ ],
9
+ "type": "module",
10
+ "main": "dist/index.js",
11
+ "exports": {
12
+ ".": "./dist/index.js"
13
+ },
14
+ "scripts": {
15
+ "build": "rm -rf dist && rolldown -c",
16
+ "prepack": "pnpm build",
17
+ "typecheck": "tsc --noEmit",
18
+ "test": "vitest run"
19
+ },
20
+ "dependencies": {
21
+ "@caplets/core": "workspace:*",
22
+ "@opencode-ai/plugin": "^1.14.48"
23
+ },
24
+ "devDependencies": {
25
+ "@types/node": "^25.7.0",
26
+ "rolldown": "^1.0.0",
27
+ "typescript": "^6.0.3",
28
+ "vitest": "^4.1.6"
29
+ },
30
+ "peerDependencies": {
31
+ "@opencode-ai/plugin": ">=0.13.0"
32
+ },
33
+ "engines": {
34
+ "node": ">=22"
35
+ }
36
+ }