opencode-agent-plus 0.3.1 → 0.3.2
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.ts +22 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-agent-plus",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "OpenCode plugin: safe-command auto-allow (no prompt for read-only calls), per-agent chat_template_kwargs (enable_thinking), sampling settings and system reminders from agent frontmatter. For llama.cpp, LiteLLM and OpenAI-compatible providers.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Anoosh Ahmadi",
|
package/src/index.ts
CHANGED
|
@@ -63,23 +63,32 @@ export default {
|
|
|
63
63
|
// `max_same_tool: n` denies a tool after n calls in a row without another tool in between.
|
|
64
64
|
// Varied work resets the count; only a streak trips it.
|
|
65
65
|
const streaks = new Map<string, { action: string; count: number }>()
|
|
66
|
+
// Serialize per session: parallel calls in one batch must not interleave on the counter.
|
|
67
|
+
const queues = new Map<string, Promise<void>>()
|
|
66
68
|
await ctx.permission.hook("evaluate", async (event: any) => {
|
|
67
69
|
if (!event.agent) return
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
event.
|
|
76
|
-
|
|
77
|
-
|
|
70
|
+
const key = String(event.sessionID)
|
|
71
|
+
const work = async () => {
|
|
72
|
+
const { keys } = await settings(event.agent)
|
|
73
|
+
const max = Number(keys.max_same_tool)
|
|
74
|
+
if (Number.isInteger(max) && max >= 1 && event.action !== "task") {
|
|
75
|
+
const prev = streaks.get(key)
|
|
76
|
+
const count = prev && prev.action === event.action ? prev.count + 1 : 1
|
|
77
|
+
streaks.set(key, { action: event.action, count })
|
|
78
|
+
if (count > max) {
|
|
79
|
+
streaks.set(key, { action: event.action, count: 0 })
|
|
80
|
+
event.effect = "deny"
|
|
81
|
+
event.message = `You already used '${event.action}' more than the maximum allowed ${max} times in a row. You are probably stuck in a doom loop. Try something else or report the issue to user.`
|
|
82
|
+
return
|
|
83
|
+
}
|
|
78
84
|
}
|
|
85
|
+
if (event.effect !== "ask") return
|
|
86
|
+
if (keys.safe_commands === "none") return
|
|
87
|
+
if (isSafe(event.action, event.resources ?? [])) event.effect = "allow"
|
|
79
88
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
89
|
+
const run = (queues.get(key) ?? Promise.resolve()).then(work, work)
|
|
90
|
+
queues.set(key, run.then(() => {}).catch(() => {}))
|
|
91
|
+
await run
|
|
83
92
|
})
|
|
84
93
|
|
|
85
94
|
await ctx.session.hook("context", async (event: any) => {
|