@ax0l0tl/agent-governance-opencode 4.0.3 → 4.0.5
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/package.json +2 -3
- package/src/index.mjs +7 -42
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ax0l0tl/agent-governance-opencode",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.5",
|
|
4
4
|
"description": "Public Preview — OpenCode CLI governance plugin for Agent Governance Toolkit developer protection policies",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.mjs",
|
|
@@ -42,8 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"homepage": "https://github.com/microsoft/agent-governance-toolkit/tree/main/agent-governance-opencode",
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@microsoft/agent-governance-sdk": "3.7.0"
|
|
46
|
-
"@opencode-ai/plugin": "1.17.1"
|
|
45
|
+
"@microsoft/agent-governance-sdk": "3.7.0"
|
|
47
46
|
},
|
|
48
47
|
"engines": {
|
|
49
48
|
"node": ">=22.0.0"
|
package/src/index.mjs
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
|
-
import { appendFileSync } from "node:fs";
|
|
5
|
-
import { homedir } from "node:os";
|
|
6
|
-
import { join } from "node:path";
|
|
7
|
-
import { tool } from "@opencode-ai/plugin";
|
|
8
4
|
import {
|
|
9
5
|
checkArbitraryText,
|
|
10
6
|
evaluateOpenCodePrompt,
|
|
@@ -82,12 +78,6 @@ export const AgtGovernance = async (ctx) => {
|
|
|
82
78
|
// OpenCode emits a wide range of events. Only inspect prompt-bearing
|
|
83
79
|
// events; ignore the rest cheaply.
|
|
84
80
|
const prompt = extractPromptFromEvent(event);
|
|
85
|
-
// TODO(temporary): remove after verifying which event types reach this hook.
|
|
86
|
-
try {
|
|
87
|
-
const logPath = join(homedir(), ".config", "opencode", "agt", "event-debug.ndjson");
|
|
88
|
-
const entry = JSON.stringify({ ts: new Date().toISOString(), type: event?.type ?? null, covered: Boolean(prompt), event }) + "\n";
|
|
89
|
-
appendFileSync(logPath, entry, "utf8");
|
|
90
|
-
} catch { /* best-effort */ }
|
|
91
81
|
if (!prompt) {
|
|
92
82
|
return;
|
|
93
83
|
}
|
|
@@ -159,9 +149,9 @@ export const AgtGovernance = async (ctx) => {
|
|
|
159
149
|
agt_policy_check_text: {
|
|
160
150
|
description:
|
|
161
151
|
"Check text against AGT prompt, context-poisoning, and MCP-style threat detectors.",
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
152
|
+
args: {
|
|
153
|
+
text: { type: "string", description: "Text to inspect." },
|
|
154
|
+
},
|
|
165
155
|
async execute(args) {
|
|
166
156
|
const state = await getState();
|
|
167
157
|
const text = typeof args?.text === "string" ? args.text : "";
|
|
@@ -178,35 +168,10 @@ function extractPromptFromEvent(event) {
|
|
|
178
168
|
if (!event || typeof event !== "object") {
|
|
179
169
|
return "";
|
|
180
170
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
// OpenCode emits chat.* events when the user sends a message. Different
|
|
186
|
-
// versions may key the prompt under different paths; check the common ones.
|
|
187
|
-
if (!/^(chat|message|prompt|user)\b/.test(type)) {
|
|
188
|
-
return "";
|
|
189
|
-
}
|
|
190
|
-
const props = event.properties ?? event.data ?? {};
|
|
191
|
-
const candidates = [
|
|
192
|
-
props.prompt,
|
|
193
|
-
props.message,
|
|
194
|
-
props.text,
|
|
195
|
-
props.content,
|
|
196
|
-
typeof props.message === "object" ? props.message?.content : undefined,
|
|
197
|
-
];
|
|
198
|
-
for (const candidate of candidates) {
|
|
199
|
-
if (typeof candidate === "string" && candidate.trim()) {
|
|
200
|
-
return candidate;
|
|
201
|
-
}
|
|
202
|
-
if (Array.isArray(candidate)) {
|
|
203
|
-
const joined = candidate
|
|
204
|
-
.map((part) => (typeof part === "string" ? part : part?.text ?? ""))
|
|
205
|
-
.filter(Boolean)
|
|
206
|
-
.join("\n");
|
|
207
|
-
if (joined.trim()) {
|
|
208
|
-
return joined;
|
|
209
|
-
}
|
|
171
|
+
if (event.type === "message.part.updated") {
|
|
172
|
+
const part = event.properties?.part;
|
|
173
|
+
if (part?.type === "text" && typeof part.text === "string") {
|
|
174
|
+
return part.text.trim();
|
|
210
175
|
}
|
|
211
176
|
}
|
|
212
177
|
return "";
|