@ax0l0tl/agent-governance-opencode 4.0.1 → 4.0.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/package.json +3 -4
- package/src/index.mjs +10 -9
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ax0l0tl/agent-governance-opencode",
|
|
3
|
-
"version": "4.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "4.0.3",
|
|
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",
|
|
7
7
|
"exports": {
|
|
@@ -43,9 +43,8 @@
|
|
|
43
43
|
"homepage": "https://github.com/microsoft/agent-governance-toolkit/tree/main/agent-governance-opencode",
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@microsoft/agent-governance-sdk": "3.7.0",
|
|
46
|
-
"@opencode-ai/plugin": "
|
|
46
|
+
"@opencode-ai/plugin": "1.17.1"
|
|
47
47
|
},
|
|
48
|
-
"devDependencies": {},
|
|
49
48
|
"engines": {
|
|
50
49
|
"node": ">=22.0.0"
|
|
51
50
|
}
|
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,
|
|
@@ -17,7 +20,7 @@ import {
|
|
|
17
20
|
* Loads the AGT policy once per OpenCode process and wires it into the
|
|
18
21
|
* OpenCode plugin contract:
|
|
19
22
|
*
|
|
20
|
-
* - session.created
|
|
23
|
+
* - session.created — log AGT governance status at session start
|
|
21
24
|
* - event (chat.params/start) — scan submitted prompts; throw to block
|
|
22
25
|
* - tool.execute.before — enforce policy; throw to deny, mark args
|
|
23
26
|
* for OpenCode's permission prompt on review
|
|
@@ -55,8 +58,6 @@ export const AgtGovernance = async (ctx) => {
|
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
return {
|
|
58
|
-
// Bug 1 fixed: session.start is not a valid OpenCode hook; use session.created.
|
|
59
|
-
// The additionalContext return value is also not part of the OpenCode contract.
|
|
60
61
|
"session.created": async () => {
|
|
61
62
|
try {
|
|
62
63
|
const state = await getState();
|
|
@@ -81,6 +82,12 @@ export const AgtGovernance = async (ctx) => {
|
|
|
81
82
|
// OpenCode emits a wide range of events. Only inspect prompt-bearing
|
|
82
83
|
// events; ignore the rest cheaply.
|
|
83
84
|
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 */ }
|
|
84
91
|
if (!prompt) {
|
|
85
92
|
return;
|
|
86
93
|
}
|
|
@@ -94,8 +101,6 @@ export const AgtGovernance = async (ctx) => {
|
|
|
94
101
|
throw new Error(result.reason || "AGT governance blocked the submitted prompt.");
|
|
95
102
|
}
|
|
96
103
|
},
|
|
97
|
-
|
|
98
|
-
// Bug 2 fixed: OpenCode expects flat string keys, not nested objects.
|
|
99
104
|
"tool.execute.before": async (input, output) => {
|
|
100
105
|
const state = await getState();
|
|
101
106
|
const result = await evaluateOpenCodeTool(state, {
|
|
@@ -142,10 +147,6 @@ export const AgtGovernance = async (ctx) => {
|
|
|
142
147
|
}
|
|
143
148
|
},
|
|
144
149
|
|
|
145
|
-
// Bug 3 fixed: `tool` (singular) with `args` (not `tools` with `parameters`).
|
|
146
|
-
// Bug 4 fixed: execute returns a plain string, not an MCP { content: [...] } envelope.
|
|
147
|
-
// tool.schema (Zod) is provided by @opencode-ai/plugin (devDependency), which OpenCode
|
|
148
|
-
// always makes available in its plugin runtime environment.
|
|
149
150
|
tool: {
|
|
150
151
|
agt_policy_status: {
|
|
151
152
|
description: "Return the active AGT OpenCode governance policy status and source.",
|