opencode-agent-plus 0.3.0 → 0.3.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +7 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-agent-plus",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
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
@@ -60,19 +60,20 @@ export default {
60
60
  // Safe-command auto-allow is on for every agent; an agent turns it off with `safe_commands: none`.
61
61
  // It skips the ask window for read-only tool calls and safe shell commands.
62
62
  // Configured `deny` rules are final and never reach this hook; anything unsafe passes through unchanged.
63
- // `max_same_tool: n` additionally denies a tool after n calls in one session.
64
- const toolCalls = new Map<string, number>()
63
+ // `max_same_tool: n` denies a tool after n calls in a row without another tool in between.
64
+ // Varied work resets the count; only a streak trips it.
65
+ const streaks = new Map<string, { action: string; count: number }>()
65
66
  await ctx.permission.hook("evaluate", async (event: any) => {
66
67
  if (!event.agent) return
67
68
  const { keys } = await settings(event.agent)
68
69
  const max = Number(keys.max_same_tool)
69
70
  if (Number.isInteger(max) && max >= 1 && event.action !== "task") {
70
- const id = `${event.sessionID}/${event.action}`
71
- const count = (toolCalls.get(id) ?? 0) + 1
72
- toolCalls.set(id, count)
71
+ const prev = streaks.get(event.sessionID)
72
+ const count = prev && prev.action === event.action ? prev.count + 1 : 1
73
+ streaks.set(event.sessionID, { action: event.action, count })
73
74
  if (count > max) {
74
75
  event.effect = "deny"
75
- event.message = `You already used '${event.action}' more than the maximum allowed ${max} times. You are probably stuck in a doom loop. Try something else or report the issue to user.`
76
+ 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.`
76
77
  return
77
78
  }
78
79
  }