jeopi-ai 16.7.0 → 16.7.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/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [16.7.2] - 2026-11-20
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- Detect when consecutive reads of the same file return identical text even if the requested page changes, while allowing reads that return new content.
|
|
10
|
+
|
|
11
|
+
## [16.7.1] - 2026-11-20
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- Enhanced `ToolCallLoopGuard` to normalize Python/JS subprocess array arguments (e.g. `["git", "status"]`), strip bash redirect and pipeline filters (`head`, `tail`, `cat`), and detect repetitive `read` offset patterns across turns to halt unproductive tool loops.
|
|
16
|
+
|
|
5
17
|
## [16.6.27] - 2026-11-17
|
|
6
18
|
|
|
7
19
|
### Added
|
|
@@ -27,7 +27,7 @@ export interface CyclicalToolCallDetection {
|
|
|
27
27
|
readonly windowSize: number;
|
|
28
28
|
}
|
|
29
29
|
export type ToolCallLoopDetection = RepeatedToolCallDetection | CyclicalToolCallDetection;
|
|
30
|
-
/** Detects consecutive identical assistant tool calls across model turns. */
|
|
30
|
+
/** Detects consecutive identical or semantically repeated assistant tool calls across model turns. */
|
|
31
31
|
export declare class ToolCallLoopGuard {
|
|
32
32
|
#private;
|
|
33
33
|
constructor(options: ToolCallLoopGuardOptions);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "jeopi-ai",
|
|
4
|
-
"version": "16.7.
|
|
4
|
+
"version": "16.7.2",
|
|
5
5
|
"description": "Unified LLM API with automatic model discovery and provider configuration",
|
|
6
6
|
"homepage": "https://github.com/akillness/jeopi",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@bufbuild/protobuf": "^2.12.0",
|
|
41
|
-
"jeopi-catalog": "16.7.
|
|
42
|
-
"jeopi-utils": "16.7.
|
|
43
|
-
"jeopi-wire": "16.7.
|
|
41
|
+
"jeopi-catalog": "16.7.2",
|
|
42
|
+
"jeopi-utils": "16.7.2",
|
|
43
|
+
"jeopi-wire": "16.7.2",
|
|
44
44
|
"arktype": "2.2.3",
|
|
45
45
|
"zod": "^4"
|
|
46
46
|
},
|
|
@@ -76,14 +76,98 @@ function summarizeToolResult(toolResults: readonly ToolResultMessage[], toolCall
|
|
|
76
76
|
return summarizeText(textParts.join("\n"), RESULT_SUMMARY_LIMIT);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
const EVAL_MUTATION_RE =
|
|
80
|
+
/\b(?:write_text|write_bytes|os\.remove|os\.unlink|os\.rename|os\.replace|shutil\.\w+|os\.mkdir|os\.makedirs|Bun\.write|fs\.write\w*|fs\.rm\w*|fs\.unlink\w*|git\s+(?:commit|checkout|reset|apply|merge|rebase)|sed\s+-i|perl\s+-pi)\b|\.write\s*\(|open\s*\([^)]*,\s*["'][wa+]/;
|
|
81
|
+
const EVAL_CMD_TOKEN_RE =
|
|
82
|
+
/\b(?:git\s+(?:status|diff|log|show|branch|rev-parse)|bun\s+(?:run\s+)?(?:typecheck|test|check|lint)|pytest|tsc|cargo\s+(?:test|check|clippy)|jev(?:\s+status)?|node\s+.*?jev-harness\.mjs\s+.*status)\b/g;
|
|
83
|
+
const EVAL_PATH_LITERAL_RE =
|
|
84
|
+
/["']((?:\.\/|\.\.\/|\/|~\/|src\/|packages\/|test\/|tests\/|crates\/|python\/)[^"'\n]{1,120})["']/g;
|
|
85
|
+
const EVAL_API_TOKEN_RE = /\b(?:os\.walk|glob\.glob|os\.listdir|subprocess\.(?:run|check_output|Popen)|read_text)\b/g;
|
|
86
|
+
const READ_PATH_RANGE_RE = /^(.*?)(?::(\d+)(?:-\d+)?)?$/;
|
|
87
|
+
|
|
88
|
+
function normalizeEvalCommandToken(token: string): string {
|
|
89
|
+
const collapsed = token.replace(/\s+/g, " ").trim();
|
|
90
|
+
if (collapsed.startsWith("bun run ")) return `bun ${collapsed.slice(8)}`;
|
|
91
|
+
if (/^git\s+status\b/.test(collapsed)) return "git status";
|
|
92
|
+
if (/jev-harness\.mjs.*status/.test(collapsed)) return "jev status";
|
|
93
|
+
return collapsed;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function normalizeBashCommand(command: string): string {
|
|
97
|
+
const stripped = command
|
|
98
|
+
.replace(/\b2>&1\b/g, "")
|
|
99
|
+
.replace(/\|\s*(?:head|tail|cat)\b[^|;&]*$/g, "")
|
|
100
|
+
.replace(/\s+/g, " ")
|
|
101
|
+
.trim();
|
|
102
|
+
|
|
103
|
+
if (/^git\s+status\b/.test(stripped)) return "git status";
|
|
104
|
+
if (/^node\s+.*?jev-harness\.mjs\s+.*status\b/.test(stripped)) return "jev status";
|
|
105
|
+
if (/^bun\s+(?:run\s+)?(?:test|typecheck|check|lint)\b/.test(stripped)) {
|
|
106
|
+
return stripped.replace(/^bun\s+run\s+/, "bun ");
|
|
107
|
+
}
|
|
108
|
+
return stripped;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function parseReadTarget(args: Record<string, unknown>): { basePath: string; startLine: number } | null {
|
|
112
|
+
const rawPath =
|
|
113
|
+
typeof args.path === "string" ? args.path.trim() : typeof args.filePath === "string" ? args.filePath.trim() : "";
|
|
114
|
+
if (!rawPath) return null;
|
|
115
|
+
const match = READ_PATH_RANGE_RE.exec(rawPath);
|
|
116
|
+
const basePath = (match?.[1] || rawPath).trim();
|
|
117
|
+
const rangeStart = match?.[2] ? Number.parseInt(match[2], 10) : undefined;
|
|
118
|
+
const lineRange = typeof args.lineRange === "string" ? args.lineRange.trim() : "";
|
|
119
|
+
const lineRangeMatch = lineRange ? /^(\d+)/.exec(lineRange) : null;
|
|
120
|
+
const lineRangeStart = lineRangeMatch?.[1] ? Number.parseInt(lineRangeMatch[1], 10) : undefined;
|
|
121
|
+
const offsetStart =
|
|
122
|
+
typeof args.offset === "number" && Number.isFinite(args.offset) ? Math.trunc(args.offset) : undefined;
|
|
123
|
+
const startLine = Math.max(1, rangeStart ?? lineRangeStart ?? offsetStart ?? 1);
|
|
124
|
+
return { basePath, startLine };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function buildEvalLookupKey(args: Record<string, unknown>, canonicalArgs: string): string {
|
|
128
|
+
const lang = typeof args.language === "string" ? args.language.trim() : "";
|
|
129
|
+
const code = typeof args.code === "string" ? args.code.trim() : "";
|
|
130
|
+
if (!code || EVAL_MUTATION_RE.test(code)) {
|
|
131
|
+
const stripped: Record<string, unknown> = { ...args };
|
|
132
|
+
delete stripped.title;
|
|
133
|
+
delete stripped.description;
|
|
134
|
+
delete stripped.timeout;
|
|
135
|
+
return `eval:${JSON.stringify(canonicalizeToolCallValue(stripped))}`;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const normalizedListCode = code.replace(/["']\s*,\s*["']/g, " ");
|
|
139
|
+
const cmds = new Set<string>();
|
|
140
|
+
for (const match of normalizedListCode.matchAll(EVAL_CMD_TOKEN_RE)) {
|
|
141
|
+
cmds.add(normalizeEvalCommandToken(match[0]));
|
|
142
|
+
}
|
|
143
|
+
if (cmds.size > 0) {
|
|
144
|
+
return `eval:ro:cmds:${lang}:${[...cmds].sort().join(",")}`;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const paths = new Set<string>();
|
|
148
|
+
for (const match of code.matchAll(EVAL_PATH_LITERAL_RE)) {
|
|
149
|
+
const cleaned = match[1]!.split(":")[0]!.trim();
|
|
150
|
+
if (cleaned) paths.add(cleaned);
|
|
151
|
+
}
|
|
152
|
+
const apis = new Set<string>();
|
|
153
|
+
for (const match of code.matchAll(EVAL_API_TOKEN_RE)) {
|
|
154
|
+
apis.add(match[0].trim());
|
|
155
|
+
}
|
|
156
|
+
if (paths.size > 0 || apis.size > 0) {
|
|
157
|
+
return `eval:ro:query:${lang}:paths=${[...paths].sort().join(",")}:apis=${[...apis].sort().join(",")}`;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const normalizedCode = code.replace(/\d+/g, "#").replace(/\s+/g, " ").trim();
|
|
161
|
+
return normalizedCode ? `eval:ro:norm:${lang}:${normalizedCode}` : `eval:${canonicalArgs}`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Detects consecutive identical or semantically repeated assistant tool calls across model turns. */
|
|
80
165
|
export class ToolCallLoopGuard {
|
|
81
166
|
#threshold: number;
|
|
82
167
|
#exemptTools: ReadonlySet<string>;
|
|
83
|
-
#
|
|
84
|
-
#count = 0;
|
|
168
|
+
#callStreaks = new Map<string, number>();
|
|
85
169
|
#cycleWindowSize: number;
|
|
86
|
-
#recentCalls: Array<{ hash: string;
|
|
170
|
+
#recentCalls: Array<{ hash: string; toolNames: string[] }> = [];
|
|
87
171
|
#lastCycleSignature: string | undefined;
|
|
88
172
|
|
|
89
173
|
constructor(options: ToolCallLoopGuardOptions) {
|
|
@@ -92,41 +176,123 @@ export class ToolCallLoopGuard {
|
|
|
92
176
|
this.#cycleWindowSize = Math.max(3, Math.trunc(options.cycleWindowSize ?? 6));
|
|
93
177
|
}
|
|
94
178
|
|
|
179
|
+
#isExemptToolCall(toolCall: ToolCall): boolean {
|
|
180
|
+
if (!this.#exemptTools.has(toolCall.name)) return false;
|
|
181
|
+
if (
|
|
182
|
+
(toolCall.name === "subagent" || toolCall.name === "job") &&
|
|
183
|
+
toolCall.arguments &&
|
|
184
|
+
typeof toolCall.arguments === "object" &&
|
|
185
|
+
(toolCall.arguments as Record<string, unknown>).action === "list"
|
|
186
|
+
) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
#reset(): void {
|
|
193
|
+
this.#callStreaks.clear();
|
|
194
|
+
this.#recentCalls = [];
|
|
195
|
+
this.#lastCycleSignature = undefined;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
#computeLookupKey(toolCall: ToolCall, canonicalArgs: string, toolResults: readonly ToolResultMessage[]): string {
|
|
199
|
+
const args =
|
|
200
|
+
toolCall.arguments && typeof toolCall.arguments === "object" && !Array.isArray(toolCall.arguments)
|
|
201
|
+
? (toolCall.arguments as Record<string, unknown>)
|
|
202
|
+
: undefined;
|
|
203
|
+
|
|
204
|
+
if (toolCall.name === "eval" && args) {
|
|
205
|
+
return buildEvalLookupKey(args, canonicalArgs);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (toolCall.name === "bash" && args && typeof args.command === "string") {
|
|
209
|
+
const normalizedCmd = normalizeBashCommand(args.command);
|
|
210
|
+
if (normalizedCmd) {
|
|
211
|
+
return `bash:cmd:${normalizedCmd}`;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (toolCall.name === "read" && args) {
|
|
216
|
+
const target = parseReadTarget(args);
|
|
217
|
+
if (target) {
|
|
218
|
+
// A changing selector is only progress if the read actually returns new content.
|
|
219
|
+
const result = toolResults.find(candidate => candidate.toolCallId === toolCall.id);
|
|
220
|
+
if (result && !result.isError && result.content.every(block => block.type === "text")) {
|
|
221
|
+
const textParts = result.content.map(block => block.text);
|
|
222
|
+
if (textParts.some(text => text.trim().length > 0)) {
|
|
223
|
+
return `read:result:${target.basePath}:${Bun.hash(JSON.stringify(textParts))}`;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return `read:page:${target.basePath}:${target.startLine}`;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return `${toolCall.name}:${canonicalArgs}`;
|
|
231
|
+
}
|
|
232
|
+
|
|
95
233
|
/** Records one completed turn and returns the threshold/cycle hit, if any. */
|
|
96
234
|
recordTurn(turn: ToolCallLoopTurn): ToolCallLoopDetection | null {
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
99
|
-
this.#
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
235
|
+
const allToolCalls = turn.message.content.filter((part): part is ToolCall => part.type === "toolCall");
|
|
236
|
+
if (allToolCalls.length === 0) {
|
|
237
|
+
this.#reset();
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const trackedCalls = allToolCalls.filter(call => !this.#isExemptToolCall(call));
|
|
242
|
+
if (trackedCalls.length === 0) {
|
|
103
243
|
return null;
|
|
104
244
|
}
|
|
105
245
|
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
246
|
+
const turnEntries: Array<{
|
|
247
|
+
lookupKey: string;
|
|
248
|
+
toolCall: ToolCall;
|
|
249
|
+
canonicalArgs: string;
|
|
250
|
+
}> = [];
|
|
251
|
+
const seenLookupKeys = new Set<string>();
|
|
252
|
+
|
|
253
|
+
for (const toolCall of trackedCalls) {
|
|
254
|
+
const canonicalArgs = JSON.stringify(canonicalizeToolCallValue(toolCall.arguments));
|
|
255
|
+
const lookupKey = this.#computeLookupKey(toolCall, canonicalArgs, turn.toolResults);
|
|
256
|
+
if (seenLookupKeys.has(lookupKey)) continue;
|
|
257
|
+
seenLookupKeys.add(lookupKey);
|
|
258
|
+
turnEntries.push({ lookupKey, toolCall, canonicalArgs });
|
|
114
259
|
}
|
|
115
260
|
|
|
116
|
-
|
|
261
|
+
const nextStreaks = new Map<string, number>();
|
|
262
|
+
let hitEntry: { toolCall: ToolCall; canonicalArgs: string; count: number } | undefined;
|
|
263
|
+
|
|
264
|
+
for (const entry of turnEntries) {
|
|
265
|
+
const count = (this.#callStreaks.get(entry.lookupKey) ?? 0) + 1;
|
|
266
|
+
nextStreaks.set(entry.lookupKey, count);
|
|
267
|
+
if (count >= this.#threshold && (!hitEntry || count > hitEntry.count)) {
|
|
268
|
+
hitEntry = { toolCall: entry.toolCall, canonicalArgs: entry.canonicalArgs, count };
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
this.#callStreaks = nextStreaks;
|
|
273
|
+
|
|
274
|
+
if (hitEntry) {
|
|
117
275
|
return {
|
|
118
276
|
kind: "repeated_tool_call",
|
|
119
|
-
toolName: toolCall.name,
|
|
120
|
-
count:
|
|
121
|
-
resultSummary: summarizeToolResult(turn.toolResults, toolCall.id),
|
|
122
|
-
argumentsSummary: summarizeText(canonicalArgs, ARGUMENT_SUMMARY_LIMIT),
|
|
277
|
+
toolName: hitEntry.toolCall.name,
|
|
278
|
+
count: hitEntry.count,
|
|
279
|
+
resultSummary: summarizeToolResult(turn.toolResults, hitEntry.toolCall.id),
|
|
280
|
+
argumentsSummary: summarizeText(hitEntry.canonicalArgs, ARGUMENT_SUMMARY_LIMIT),
|
|
123
281
|
};
|
|
124
282
|
}
|
|
125
283
|
|
|
126
284
|
// Alternating A,B,A,B,… pattern: exact-repeat detection above never fires
|
|
127
285
|
// (the hash changes every turn), but the model is still spinning between
|
|
128
|
-
//
|
|
129
|
-
|
|
286
|
+
// two distinct calls/turn-signatures without making progress.
|
|
287
|
+
const turnHash = turnEntries.map(entry => entry.lookupKey).join("\u001f");
|
|
288
|
+
const turnToolNames: string[] = [];
|
|
289
|
+
for (const entry of turnEntries) {
|
|
290
|
+
if (!turnToolNames.includes(entry.toolCall.name)) {
|
|
291
|
+
turnToolNames.push(entry.toolCall.name);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
this.#recentCalls.push({ hash: turnHash, toolNames: turnToolNames });
|
|
130
296
|
if (this.#recentCalls.length > this.#cycleWindowSize) this.#recentCalls.shift();
|
|
131
297
|
if (this.#recentCalls.length < this.#cycleWindowSize) return null;
|
|
132
298
|
|
|
@@ -141,7 +307,9 @@ export class ToolCallLoopGuard {
|
|
|
141
307
|
|
|
142
308
|
const toolNames: string[] = [];
|
|
143
309
|
for (const call of this.#recentCalls) {
|
|
144
|
-
|
|
310
|
+
for (const name of call.toolNames) {
|
|
311
|
+
if (!toolNames.includes(name)) toolNames.push(name);
|
|
312
|
+
}
|
|
145
313
|
}
|
|
146
314
|
return { kind: "cyclical_tool_calls", toolNames, windowSize: this.#cycleWindowSize };
|
|
147
315
|
}
|