@claude-flow/cli 3.10.9 → 3.10.10
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/dist/src/mcp-tools/agent-execute-core.d.ts.map +1 -1
- package/dist/src/mcp-tools/agent-execute-core.js +7 -1
- package/dist/src/mcp-tools/agent-execute-core.js.map +1 -1
- package/dist/src/mcp-tools/hooks-tools.d.ts +10 -0
- package/dist/src/mcp-tools/hooks-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/hooks-tools.js +40 -6
- package/dist/src/mcp-tools/hooks-tools.js.map +1 -1
- package/dist/src/mcp-tools/tool-loop-guardrail.d.ts +31 -0
- package/dist/src/mcp-tools/tool-loop-guardrail.d.ts.map +1 -0
- package/dist/src/mcp-tools/tool-loop-guardrail.js +71 -0
- package/dist/src/mcp-tools/tool-loop-guardrail.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool-loop circuit breaker (hermes-agent tool_guardrails pattern).
|
|
3
|
+
*
|
|
4
|
+
* Detects an agent stuck repeating the same failing command — a real silent
|
|
5
|
+
* failure mode where a loop burns turns with no signal. This is ORTHOGONAL to
|
|
6
|
+
* the security `tool-output-guardrail` (which detects indirect prompt injection
|
|
7
|
+
* in tool *output*); this one watches the agent's own *call* pattern.
|
|
8
|
+
*
|
|
9
|
+
* Design (deterministic, in-memory, bounded):
|
|
10
|
+
* - `recordCommandOutcome` (called by post-command) appends (command, success)
|
|
11
|
+
* to a small ring buffer.
|
|
12
|
+
* - `checkCommandLoop` (called by pre-command) returns a verdict for a command
|
|
13
|
+
* about to run, based on its recent consecutive-failure streak.
|
|
14
|
+
* - Verdict is advisory by default (`warn`); callers decide whether to block.
|
|
15
|
+
* An orchestration layer that doesn't own the UI should not hard-stop.
|
|
16
|
+
*/
|
|
17
|
+
export type LoopVerdict = 'allow' | 'warn' | 'block';
|
|
18
|
+
/** Record a command's outcome. Called from the post-command hook. */
|
|
19
|
+
export declare function recordCommandOutcome(command: string, success: boolean): void;
|
|
20
|
+
/**
|
|
21
|
+
* Verdict for a command about to execute. Called from the pre-command hook.
|
|
22
|
+
* Returns the verdict, the failure streak, and a recovery hint when looping.
|
|
23
|
+
*/
|
|
24
|
+
export declare function checkCommandLoop(command: string): {
|
|
25
|
+
verdict: LoopVerdict;
|
|
26
|
+
consecutiveFailures: number;
|
|
27
|
+
hint?: string;
|
|
28
|
+
};
|
|
29
|
+
/** Test/reset helper — clears the in-memory history. */
|
|
30
|
+
export declare function _resetLoopHistory(): void;
|
|
31
|
+
//# sourceMappingURL=tool-loop-guardrail.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-loop-guardrail.d.ts","sourceRoot":"","sources":["../../../src/mcp-tools/tool-loop-guardrail.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC;AAerD,qEAAqE;AACrE,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAG5E;AAeD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG;IACjD,OAAO,EAAE,WAAW,CAAC;IACrB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAiBA;AAED,wDAAwD;AACxD,wBAAgB,iBAAiB,IAAI,IAAI,CAExC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool-loop circuit breaker (hermes-agent tool_guardrails pattern).
|
|
3
|
+
*
|
|
4
|
+
* Detects an agent stuck repeating the same failing command — a real silent
|
|
5
|
+
* failure mode where a loop burns turns with no signal. This is ORTHOGONAL to
|
|
6
|
+
* the security `tool-output-guardrail` (which detects indirect prompt injection
|
|
7
|
+
* in tool *output*); this one watches the agent's own *call* pattern.
|
|
8
|
+
*
|
|
9
|
+
* Design (deterministic, in-memory, bounded):
|
|
10
|
+
* - `recordCommandOutcome` (called by post-command) appends (command, success)
|
|
11
|
+
* to a small ring buffer.
|
|
12
|
+
* - `checkCommandLoop` (called by pre-command) returns a verdict for a command
|
|
13
|
+
* about to run, based on its recent consecutive-failure streak.
|
|
14
|
+
* - Verdict is advisory by default (`warn`); callers decide whether to block.
|
|
15
|
+
* An orchestration layer that doesn't own the UI should not hard-stop.
|
|
16
|
+
*/
|
|
17
|
+
const MAX_HISTORY = 64;
|
|
18
|
+
const history = [];
|
|
19
|
+
/** Consecutive-failure thresholds for the same command (exact match). */
|
|
20
|
+
const WARN_AT = 3;
|
|
21
|
+
const BLOCK_AT = 5;
|
|
22
|
+
function normalize(command) {
|
|
23
|
+
return command.trim().replace(/\s+/g, ' ');
|
|
24
|
+
}
|
|
25
|
+
/** Record a command's outcome. Called from the post-command hook. */
|
|
26
|
+
export function recordCommandOutcome(command, success) {
|
|
27
|
+
history.push({ command: normalize(command), success, at: history.length });
|
|
28
|
+
if (history.length > MAX_HISTORY)
|
|
29
|
+
history.shift();
|
|
30
|
+
}
|
|
31
|
+
/** Count the trailing run of consecutive failures of `command` (exact match),
|
|
32
|
+
* stopping at the first success of that command or a gap. */
|
|
33
|
+
function consecutiveFailures(command) {
|
|
34
|
+
const norm = normalize(command);
|
|
35
|
+
let streak = 0;
|
|
36
|
+
for (let i = history.length - 1; i >= 0; i--) {
|
|
37
|
+
if (history[i].command !== norm)
|
|
38
|
+
continue; // ignore interleaved other commands
|
|
39
|
+
if (history[i].success)
|
|
40
|
+
break; // a success breaks the streak
|
|
41
|
+
streak++;
|
|
42
|
+
}
|
|
43
|
+
return streak;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Verdict for a command about to execute. Called from the pre-command hook.
|
|
47
|
+
* Returns the verdict, the failure streak, and a recovery hint when looping.
|
|
48
|
+
*/
|
|
49
|
+
export function checkCommandLoop(command) {
|
|
50
|
+
const fails = consecutiveFailures(command);
|
|
51
|
+
if (fails >= BLOCK_AT) {
|
|
52
|
+
return {
|
|
53
|
+
verdict: 'block',
|
|
54
|
+
consecutiveFailures: fails,
|
|
55
|
+
hint: `This exact command has failed ${fails}× in a row. Stop repeating it — inspect state first (e.g. \`pwd && ls -la\`), change the approach, or ask for help.`,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (fails >= WARN_AT) {
|
|
59
|
+
return {
|
|
60
|
+
verdict: 'warn',
|
|
61
|
+
consecutiveFailures: fails,
|
|
62
|
+
hint: `This command has failed ${fails}× in a row. Before retrying, verify preconditions (paths, args, prior step output) rather than re-running the same call.`,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return { verdict: 'allow', consecutiveFailures: fails };
|
|
66
|
+
}
|
|
67
|
+
/** Test/reset helper — clears the in-memory history. */
|
|
68
|
+
export function _resetLoopHistory() {
|
|
69
|
+
history.length = 0;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=tool-loop-guardrail.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-loop-guardrail.js","sourceRoot":"","sources":["../../../src/mcp-tools/tool-loop-guardrail.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAMH,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,MAAM,OAAO,GAAc,EAAE,CAAC;AAE9B,yEAAyE;AACzE,MAAM,OAAO,GAAG,CAAC,CAAC;AAClB,MAAM,QAAQ,GAAG,CAAC,CAAC;AAEnB,SAAS,SAAS,CAAC,OAAe;IAChC,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAC7C,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,oBAAoB,CAAC,OAAe,EAAE,OAAgB;IACpE,OAAO,CAAC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