@webpresso/opencode-plugin 3.1.3
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/LICENSE +104 -0
- package/README.md +11 -0
- package/index.js +209 -0
- package/package.json +34 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
Elastic License 2.0
|
|
2
|
+
===================
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2026 Webpresso, Inc.
|
|
5
|
+
|
|
6
|
+
Acceptance
|
|
7
|
+
----------
|
|
8
|
+
|
|
9
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
10
|
+
|
|
11
|
+
Copyright License
|
|
12
|
+
-----------------
|
|
13
|
+
|
|
14
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide,
|
|
15
|
+
non-sublicensable, non-transferable license to use, copy, distribute, make
|
|
16
|
+
available, and prepare derivative works of the software, in each case subject
|
|
17
|
+
to the limitations and conditions below.
|
|
18
|
+
|
|
19
|
+
Limitations
|
|
20
|
+
-----------
|
|
21
|
+
|
|
22
|
+
You may not provide the software to third parties as a hosted or managed
|
|
23
|
+
service, where the service provides users with access to any substantial set of
|
|
24
|
+
the features or functionality of the software.
|
|
25
|
+
|
|
26
|
+
You may not move, change, disable, or circumvent the license key
|
|
27
|
+
functionality in the software, and you may not remove or obscure any
|
|
28
|
+
functionality in the software that is protected by the license key.
|
|
29
|
+
|
|
30
|
+
You may not alter, remove, or obscure any licensing, copyright, or other
|
|
31
|
+
notices of the licensor in the software. Any use of the licensor's trademarks
|
|
32
|
+
is subject to applicable law.
|
|
33
|
+
|
|
34
|
+
Patents
|
|
35
|
+
-------
|
|
36
|
+
|
|
37
|
+
The licensor grants you a license, under any patent claims the licensor can
|
|
38
|
+
license, or becomes able to license, to make, have made, use, sell, offer for
|
|
39
|
+
sale, import and have imported the software, in each case subject to the
|
|
40
|
+
limitations and conditions in this license. This license does not cover any
|
|
41
|
+
patent claims that you cause to be infringed by modifications or additions to
|
|
42
|
+
the software.
|
|
43
|
+
|
|
44
|
+
If you or your company make any written claim that the software infringes or
|
|
45
|
+
contributes to infringement of any patent, your patent license for the software
|
|
46
|
+
granted under these terms ends immediately. If your company makes such a claim,
|
|
47
|
+
your patent license ends immediately for work on behalf of your company.
|
|
48
|
+
|
|
49
|
+
Notices
|
|
50
|
+
-------
|
|
51
|
+
|
|
52
|
+
You must ensure that anyone who gets a copy of any part of the software from
|
|
53
|
+
you also gets a copy of these terms.
|
|
54
|
+
|
|
55
|
+
If you modify the software, you must include in any modified copies of the
|
|
56
|
+
software prominent notices stating that you have modified the software.
|
|
57
|
+
|
|
58
|
+
No Other Rights
|
|
59
|
+
---------------
|
|
60
|
+
|
|
61
|
+
These terms do not imply any licenses other than those expressly granted in
|
|
62
|
+
these terms.
|
|
63
|
+
|
|
64
|
+
Termination
|
|
65
|
+
-----------
|
|
66
|
+
|
|
67
|
+
If you use the software in violation of these terms, such use is not licensed,
|
|
68
|
+
and your licenses will automatically terminate. If the licensor provides you
|
|
69
|
+
with a notice of your violation, and you cease all violation of this license no
|
|
70
|
+
later than 30 days after you receive that notice, your licenses will be
|
|
71
|
+
reinstated retroactively. However, if you violate these terms after such
|
|
72
|
+
reinstatement, any additional violation of these terms will cause your licenses
|
|
73
|
+
to terminate automatically and permanently.
|
|
74
|
+
|
|
75
|
+
No Liability
|
|
76
|
+
------------
|
|
77
|
+
|
|
78
|
+
As far as the law allows, the software comes as is, without any warranty or
|
|
79
|
+
condition, and the licensor will not be liable to you for any damages arising
|
|
80
|
+
out of these terms or the use or nature of the software, under any kind of
|
|
81
|
+
legal claim.
|
|
82
|
+
|
|
83
|
+
Definitions
|
|
84
|
+
-----------
|
|
85
|
+
|
|
86
|
+
The licensor is the entity offering these terms, and the software is the
|
|
87
|
+
software the licensor makes available under these terms, including any portion
|
|
88
|
+
of it.
|
|
89
|
+
|
|
90
|
+
you refers to the individual or entity agreeing to these terms.
|
|
91
|
+
|
|
92
|
+
your company is any legal entity, sole proprietorship, or other kind of
|
|
93
|
+
organization that you work for, plus all organizations that have control over,
|
|
94
|
+
are under the control of, or are under common control with that organization.
|
|
95
|
+
control means ownership of substantially all the assets of an entity, or the
|
|
96
|
+
power to direct its management and policies by vote, contract, or otherwise.
|
|
97
|
+
Control can be direct or indirect.
|
|
98
|
+
|
|
99
|
+
your licenses are all the licenses granted to you for the software under these
|
|
100
|
+
terms.
|
|
101
|
+
|
|
102
|
+
use means anything you do with the software requiring one of your licenses.
|
|
103
|
+
|
|
104
|
+
trademark means trademarks, service marks, and similar rights.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @webpresso/opencode-plugin
|
|
2
|
+
|
|
3
|
+
`@webpresso/opencode-plugin` is the OpenCode host adapter package for Agent
|
|
4
|
+
Kit. It provides the native OpenCode npm plugin surface, registered through
|
|
5
|
+
`opencode.json`, with the package module exports and metadata OpenCode expects.
|
|
6
|
+
|
|
7
|
+
The root `@webpresso/agent-kit` package is CLI/core only: it ships `wp`, MCP
|
|
8
|
+
tools, audits, blueprints, session memory, docs, and catalog sources, but it
|
|
9
|
+
does not ship this OpenCode payload from the root package. OpenCode delivery is
|
|
10
|
+
native npm plugin registration only; there is no generated bridge, MCP bridge,
|
|
11
|
+
or MCP injection payload in this package.
|
package/index.js
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
const SESSION_START_HOOKS = ["sessionstart-routing"];
|
|
5
|
+
const PRE_TOOL_HOOKS = ["pretool-guard"];
|
|
6
|
+
const POST_TOOL_HOOKS = ["post-tool"];
|
|
7
|
+
|
|
8
|
+
function extractAdditionalContext(envelope) {
|
|
9
|
+
return envelope?.hookSpecificOutput?.additionalContext ?? null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function extractDenyReason(envelope) {
|
|
13
|
+
const output = envelope?.hookSpecificOutput;
|
|
14
|
+
if (output?.permissionDecision === "deny") {
|
|
15
|
+
return output.permissionDecisionReason ?? "webpresso denied this tool call";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function hookInputForTool(tool, args, directory) {
|
|
22
|
+
const base = {
|
|
23
|
+
cwd: directory,
|
|
24
|
+
hook_event_name: "PreToolUse",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
switch (tool) {
|
|
28
|
+
case "bash":
|
|
29
|
+
return {
|
|
30
|
+
...base,
|
|
31
|
+
tool_name: "Bash",
|
|
32
|
+
tool_input: {
|
|
33
|
+
command: args?.command ?? "",
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
case "write":
|
|
37
|
+
return {
|
|
38
|
+
...base,
|
|
39
|
+
tool_name: "Write",
|
|
40
|
+
tool_input: {
|
|
41
|
+
file_path: args?.filePath ?? "",
|
|
42
|
+
content: args?.content ?? "",
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
case "edit":
|
|
46
|
+
return {
|
|
47
|
+
...base,
|
|
48
|
+
tool_name: "Edit",
|
|
49
|
+
tool_input: {
|
|
50
|
+
file_path: args?.filePath ?? "",
|
|
51
|
+
old_string: args?.oldString ?? "",
|
|
52
|
+
new_string: args?.newString ?? "",
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
case "read":
|
|
56
|
+
return {
|
|
57
|
+
...base,
|
|
58
|
+
tool_name: "Read",
|
|
59
|
+
tool_input: {
|
|
60
|
+
file_path: args?.filePath ?? "",
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
case "apply_patch":
|
|
64
|
+
return {
|
|
65
|
+
...base,
|
|
66
|
+
tool_name: "Write",
|
|
67
|
+
tool_input: {
|
|
68
|
+
patch_text: args?.patchText ?? "",
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
default:
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function shellQuote(value) {
|
|
77
|
+
return `'${String(value).replaceAll("'", "'\\''")}'`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function resolveWpHookCommand($, directory, hookName) {
|
|
81
|
+
const repoLauncher = join(directory, "bin", process.platform === "win32" ? "wp.cmd" : "wp");
|
|
82
|
+
const candidates = [process.env.WEBPRESSO_WP_BIN, repoLauncher].filter(Boolean);
|
|
83
|
+
|
|
84
|
+
for (const candidate of candidates) {
|
|
85
|
+
if (existsSync(candidate)) {
|
|
86
|
+
return `${shellQuote(candidate)} hook ${hookName}`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const found = await $`command -v wp`.cwd(directory).quiet().nothrow();
|
|
91
|
+
const resolved = found.stdout?.toString().trim().split(/\r?\n/u)[0] ?? "";
|
|
92
|
+
if ((found.exitCode === undefined || found.exitCode === 0) && resolved.length > 0) {
|
|
93
|
+
return `${shellQuote(resolved)} hook ${hookName}`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
throw new Error(
|
|
97
|
+
"webpresso wp launcher not found; run wp setup after installing @webpresso/agent-kit",
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function runHook($, directory, hookName, payload, options = {}) {
|
|
102
|
+
const stdinPayload = payload === null ? "" : JSON.stringify(payload);
|
|
103
|
+
const command = await resolveWpHookCommand($, directory, hookName);
|
|
104
|
+
const result =
|
|
105
|
+
await $`printf '%s' ${stdinPayload} | env CLAUDE_PROJECT_DIR=${directory} WP_HOOK_HOST=opencode sh -lc ${command}`
|
|
106
|
+
.cwd(directory)
|
|
107
|
+
.quiet()
|
|
108
|
+
.nothrow();
|
|
109
|
+
|
|
110
|
+
const stdout = result.stdout.toString().trim();
|
|
111
|
+
const stderr = result.stderr?.toString().trim() ?? "";
|
|
112
|
+
const exitCode = result.exitCode ?? 0;
|
|
113
|
+
const required = options.required === true;
|
|
114
|
+
|
|
115
|
+
if (exitCode !== 0) {
|
|
116
|
+
if (required) {
|
|
117
|
+
throw new Error(
|
|
118
|
+
`webpresso hook ${hookName} failed with exit ${exitCode}${stderr ? `: ${stderr}` : ""}`,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (stdout === "") {
|
|
125
|
+
if (required) {
|
|
126
|
+
throw new Error(`webpresso hook ${hookName} produced no JSON response`);
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
return JSON.parse(stdout);
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (required) {
|
|
135
|
+
throw new Error(
|
|
136
|
+
`webpresso hook ${hookName} produced invalid JSON${stderr ? `: ${stderr}` : ""}`,
|
|
137
|
+
{ cause: error },
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async function collectSessionStartContext($, directory) {
|
|
145
|
+
const contexts = [];
|
|
146
|
+
|
|
147
|
+
for (const hookName of SESSION_START_HOOKS) {
|
|
148
|
+
const envelope = await runHook($, directory, hookName, null);
|
|
149
|
+
const message = extractAdditionalContext(envelope);
|
|
150
|
+
if (message === null) {
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
contexts.push(message);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return contexts;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export const WebpressoHooksPlugin = async ({ $, directory }) => {
|
|
161
|
+
let cachedSessionContexts = [];
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
event: async ({ event }) => {
|
|
165
|
+
if (event?.type === "session.created") {
|
|
166
|
+
cachedSessionContexts = await collectSessionStartContext($, directory);
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
"shell.env": async (input, output) => {
|
|
170
|
+
output.env.CLAUDE_PROJECT_DIR = input.cwd;
|
|
171
|
+
},
|
|
172
|
+
"tool.execute.before": async (input, output) => {
|
|
173
|
+
const payload = hookInputForTool(input?.tool, output?.args ?? input?.args ?? {}, directory);
|
|
174
|
+
if (payload === null) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
for (const hookName of PRE_TOOL_HOOKS) {
|
|
179
|
+
const envelope = await runHook($, directory, hookName, payload, { required: true });
|
|
180
|
+
const denyReason = extractDenyReason(envelope);
|
|
181
|
+
if (denyReason !== null) {
|
|
182
|
+
throw new Error(denyReason);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
"tool.execute.after": async (input, output) => {
|
|
187
|
+
const payload = hookInputForTool(input?.tool, output?.args ?? input?.args ?? {}, directory);
|
|
188
|
+
if (payload === null) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
for (const hookName of POST_TOOL_HOOKS) {
|
|
193
|
+
await runHook($, directory, hookName, payload);
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
"experimental.session.compacting": async (_input, output) => {
|
|
197
|
+
cachedSessionContexts = await collectSessionStartContext($, directory);
|
|
198
|
+
if (output && Array.isArray(output.context)) {
|
|
199
|
+
for (const message of cachedSessionContexts) {
|
|
200
|
+
output.context.push(message);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const webpressoOpenCodePlugins = [WebpressoHooksPlugin];
|
|
208
|
+
|
|
209
|
+
export default webpressoOpenCodePlugins;
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webpresso/opencode-plugin",
|
|
3
|
+
"version": "3.1.3",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "OpenCode plugin adapter package for Webpresso agent-kit.",
|
|
6
|
+
"homepage": "https://github.com/webpresso/agent-kit#readme",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/webpresso/agent-kit/issues"
|
|
9
|
+
},
|
|
10
|
+
"license": "Elastic-2.0",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/webpresso/agent-kit.git",
|
|
14
|
+
"directory": "packages/opencode-plugin"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"index.js",
|
|
18
|
+
"LICENSE",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"main": "./index.js",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": "./index.js"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public",
|
|
29
|
+
"registry": "https://registry.npmjs.org/"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=24"
|
|
33
|
+
}
|
|
34
|
+
}
|