@ax0l0tl/agent-governance-opencode 4.0.2 → 4.0.4
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 +1 -1
- package/src/index.mjs +10 -38
package/package.json
CHANGED
package/src/index.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
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";
|
|
4
7
|
import { tool } from "@opencode-ai/plugin";
|
|
5
8
|
import {
|
|
6
9
|
checkArbitraryText,
|
|
@@ -81,15 +84,9 @@ export const AgtGovernance = async (ctx) => {
|
|
|
81
84
|
const prompt = extractPromptFromEvent(event);
|
|
82
85
|
// TODO(temporary): remove after verifying which event types reach this hook.
|
|
83
86
|
try {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
service: "agt-governance",
|
|
88
|
-
level: "info",
|
|
89
|
-
message: `[AGT] event type=${event?.type ?? "unknown"} covered=${Boolean(prompt)}`,
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
}
|
|
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");
|
|
93
90
|
} catch { /* best-effort */ }
|
|
94
91
|
if (!prompt) {
|
|
95
92
|
return;
|
|
@@ -181,35 +178,10 @@ function extractPromptFromEvent(event) {
|
|
|
181
178
|
if (!event || typeof event !== "object") {
|
|
182
179
|
return "";
|
|
183
180
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
// OpenCode emits chat.* events when the user sends a message. Different
|
|
189
|
-
// versions may key the prompt under different paths; check the common ones.
|
|
190
|
-
if (!/^(chat|message|prompt|user)\b/.test(type)) {
|
|
191
|
-
return "";
|
|
192
|
-
}
|
|
193
|
-
const props = event.properties ?? event.data ?? {};
|
|
194
|
-
const candidates = [
|
|
195
|
-
props.prompt,
|
|
196
|
-
props.message,
|
|
197
|
-
props.text,
|
|
198
|
-
props.content,
|
|
199
|
-
typeof props.message === "object" ? props.message?.content : undefined,
|
|
200
|
-
];
|
|
201
|
-
for (const candidate of candidates) {
|
|
202
|
-
if (typeof candidate === "string" && candidate.trim()) {
|
|
203
|
-
return candidate;
|
|
204
|
-
}
|
|
205
|
-
if (Array.isArray(candidate)) {
|
|
206
|
-
const joined = candidate
|
|
207
|
-
.map((part) => (typeof part === "string" ? part : part?.text ?? ""))
|
|
208
|
-
.filter(Boolean)
|
|
209
|
-
.join("\n");
|
|
210
|
-
if (joined.trim()) {
|
|
211
|
-
return joined;
|
|
212
|
-
}
|
|
181
|
+
if (event.type === "message.part.updated") {
|
|
182
|
+
const part = event.properties?.part;
|
|
183
|
+
if (part?.type === "text" && typeof part.text === "string") {
|
|
184
|
+
return part.text.trim();
|
|
213
185
|
}
|
|
214
186
|
}
|
|
215
187
|
return "";
|