open-agents-ai 0.187.153 → 0.187.154
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/index.js +101 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -265520,8 +265520,19 @@ ${top.map((t2) => `- ${t2.name}: ${t2.desc}`).join("\n")}`
|
|
|
265520
265520
|
const turnBudget = turnTier === "small" ? 5 : turnTier === "medium" ? 8 : 0;
|
|
265521
265521
|
if (turnBudget > 0 && turn > 0 && turn % turnBudget === 0) {
|
|
265522
265522
|
const repetitionRatio = this.detectRepetition(toolCallLog);
|
|
265523
|
+
const recentToolResults2 = messages2.slice(-16).filter((m2) => m2.role === "tool" && typeof m2.content === "string");
|
|
265524
|
+
const recentErrors = recentToolResults2.filter((m2) => /error|failed|not found|permission denied/i.test(String(m2.content))).length;
|
|
265525
|
+
const errorRatio = recentToolResults2.length > 0 ? recentErrors / recentToolResults2.length : 0;
|
|
265523
265526
|
const noProgress = this._taskState.completedSteps.length === 0 && turn >= turnBudget;
|
|
265524
265527
|
const isLooping = repetitionRatio > 0.4;
|
|
265528
|
+
const highArousal = errorRatio > 0.5 || isLooping;
|
|
265529
|
+
if (highArousal && !isLooping && !noProgress) {
|
|
265530
|
+
this.pendingUserMessages.push(`[COGNITIVE STATE: HIGH AROUSAL] Recent error rate is ${Math.round(errorRatio * 100)}%. Your current approach may be hitting a wall. Consider:
|
|
265531
|
+
1. Read related files you haven't examined yet
|
|
265532
|
+
2. Search for similar patterns in the codebase
|
|
265533
|
+
3. Check if your assumptions about the API/framework are correct
|
|
265534
|
+
State what you've learned from the errors before trying again.`);
|
|
265535
|
+
}
|
|
265525
265536
|
if (isLooping || noProgress) {
|
|
265526
265537
|
const progress = this._taskState.completedSteps.slice(-3).join("; ");
|
|
265527
265538
|
const failures = this._taskState.failedApproaches.slice(-2).join("; ");
|
|
@@ -265795,7 +265806,7 @@ If you're stuck, try a completely different approach. Do NOT repeat what failed
|
|
|
265795
265806
|
const toolStart = performance.now();
|
|
265796
265807
|
toolCallCount++;
|
|
265797
265808
|
const argsKey = Object.entries(tc.arguments ?? {}).sort(([a2], [b]) => a2.localeCompare(b)).map(([k, v]) => `${k}=${typeof v === "string" ? v.slice(0, 80) : JSON.stringify(v)}`).join(",");
|
|
265798
|
-
toolCallLog.push({ name: tc.name, argsKey });
|
|
265809
|
+
toolCallLog.push({ name: tc.name, argsKey, turn, timestampMs: Date.now() });
|
|
265799
265810
|
const budgetRemaining = toolCallBudget.get(tc.name);
|
|
265800
265811
|
if (budgetRemaining !== void 0) {
|
|
265801
265812
|
if (budgetRemaining <= 0) {
|
|
@@ -266629,6 +266640,95 @@ Full content available via: repl_exec(code="data = retrieve('${handleId}')") or
|
|
|
266629
266640
|
success: completed,
|
|
266630
266641
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
266631
266642
|
});
|
|
266643
|
+
try {
|
|
266644
|
+
const extractPaths = (entries, toolNames) => {
|
|
266645
|
+
return [...new Set(entries.filter((tc) => toolNames.includes(tc.name)).map((tc) => {
|
|
266646
|
+
const pathMatch = tc.argsKey.match(/path=([^,]+)/);
|
|
266647
|
+
return pathMatch?.[1] || "";
|
|
266648
|
+
}).filter(Boolean))];
|
|
266649
|
+
};
|
|
266650
|
+
const consolidation = {
|
|
266651
|
+
sessionId: this._sessionId,
|
|
266652
|
+
task: task.slice(0, 500),
|
|
266653
|
+
outcome: completed ? "success" : this.aborted ? "aborted" : "timeout",
|
|
266654
|
+
turns: messages2.filter((m2) => m2.role === "assistant").length,
|
|
266655
|
+
toolsUsed: [...new Set(toolCallLog.map((tc) => tc.name))],
|
|
266656
|
+
filesModified: extractPaths(toolCallLog, ["file_write", "file_edit", "file_patch", "batch_edit"]),
|
|
266657
|
+
filesRead: extractPaths(toolCallLog, ["file_read"]),
|
|
266658
|
+
totalToolCalls: toolCallLog.length,
|
|
266659
|
+
durationMs,
|
|
266660
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
266661
|
+
};
|
|
266662
|
+
const fs4 = await import("node:fs");
|
|
266663
|
+
const path5 = await import("node:path");
|
|
266664
|
+
const consolidDir = path5.join(process.cwd(), ".oa", "consolidations");
|
|
266665
|
+
fs4.mkdirSync(consolidDir, { recursive: true });
|
|
266666
|
+
fs4.writeFileSync(path5.join(consolidDir, `${this._sessionId}.json`), JSON.stringify(consolidation, null, 2));
|
|
266667
|
+
const provenanceDir = path5.join(process.cwd(), ".oa", "provenance");
|
|
266668
|
+
fs4.mkdirSync(provenanceDir, { recursive: true });
|
|
266669
|
+
const provenanceGraph = {
|
|
266670
|
+
sessionId: this._sessionId,
|
|
266671
|
+
task: task.slice(0, 500),
|
|
266672
|
+
outcome: consolidation.outcome,
|
|
266673
|
+
timestamp: consolidation.timestamp,
|
|
266674
|
+
// Full action trace — every tool call with sequence ordering
|
|
266675
|
+
actions: toolCallLog.map((tc, idx) => ({
|
|
266676
|
+
id: `${this._sessionId}-${idx}`,
|
|
266677
|
+
tool: tc.name,
|
|
266678
|
+
args_fingerprint: tc.argsKey.slice(0, 200),
|
|
266679
|
+
turn: tc.turn,
|
|
266680
|
+
timestamp_ms: tc.timestampMs,
|
|
266681
|
+
// Causal links: which earlier action informed this one?
|
|
266682
|
+
// Heuristic: if this action reads a file that a previous action wrote, they're linked
|
|
266683
|
+
caused_by: toolCallLog.slice(0, idx).filter((prev) => {
|
|
266684
|
+
const prevPath = prev.argsKey.match(/path=([^,]+)/)?.[1];
|
|
266685
|
+
const thisPath = tc.argsKey.match(/path=([^,]+)/)?.[1];
|
|
266686
|
+
return prevPath && thisPath && prevPath === thisPath && ["file_write", "file_edit"].includes(prev.name) && ["file_read", "grep_search"].includes(tc.name);
|
|
266687
|
+
}).map((_, prevIdx) => `${this._sessionId}-${prevIdx}`)
|
|
266688
|
+
})),
|
|
266689
|
+
// File dependency graph: which files were read before being modified?
|
|
266690
|
+
file_provenance: (() => {
|
|
266691
|
+
const readTurns = /* @__PURE__ */ new Map();
|
|
266692
|
+
const writeTurns = /* @__PURE__ */ new Map();
|
|
266693
|
+
for (const tc of toolCallLog) {
|
|
266694
|
+
const filePath = tc.argsKey.match(/path=([^,]+)/)?.[1];
|
|
266695
|
+
if (!filePath)
|
|
266696
|
+
continue;
|
|
266697
|
+
if (tc.name === "file_read" && !readTurns.has(filePath))
|
|
266698
|
+
readTurns.set(filePath, tc.turn ?? 0);
|
|
266699
|
+
if (["file_write", "file_edit"].includes(tc.name))
|
|
266700
|
+
writeTurns.set(filePath, tc.turn ?? 0);
|
|
266701
|
+
}
|
|
266702
|
+
const deps = [];
|
|
266703
|
+
for (const [file, writeTurn] of writeTurns) {
|
|
266704
|
+
const readTurn = readTurns.get(file);
|
|
266705
|
+
if (readTurn !== void 0 && readTurn < writeTurn) {
|
|
266706
|
+
deps.push({ file, read_turn: readTurn, write_turn: writeTurn });
|
|
266707
|
+
}
|
|
266708
|
+
}
|
|
266709
|
+
return deps;
|
|
266710
|
+
})()
|
|
266711
|
+
};
|
|
266712
|
+
fs4.writeFileSync(path5.join(provenanceDir, `${this._sessionId}.json`), JSON.stringify(provenanceGraph, null, 2));
|
|
266713
|
+
if (completed && this.tools.has("memory_write")) {
|
|
266714
|
+
const memTool = this.tools.get("memory_write");
|
|
266715
|
+
const lessonContent = `Task "${task.slice(0, 100)}" completed successfully. Tools: ${consolidation.toolsUsed.join(", ")}. Files: ${consolidation.filesModified.slice(0, 3).join(", ")}. Duration: ${Math.round(durationMs / 1e3)}s, ${consolidation.turns} turns.`;
|
|
266716
|
+
try {
|
|
266717
|
+
await memTool.execute({
|
|
266718
|
+
topic: "task_lessons",
|
|
266719
|
+
key: this._sessionId,
|
|
266720
|
+
value: lessonContent
|
|
266721
|
+
});
|
|
266722
|
+
} catch {
|
|
266723
|
+
}
|
|
266724
|
+
}
|
|
266725
|
+
this.emit({
|
|
266726
|
+
type: "status",
|
|
266727
|
+
content: `Task consolidation: ${consolidation.outcome}, ${consolidation.toolsUsed.length} tools, ${consolidation.filesModified.length} files modified`,
|
|
266728
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
266729
|
+
});
|
|
266730
|
+
} catch {
|
|
266731
|
+
}
|
|
266632
266732
|
this._hookManager.runSessionHook("session_end", this._sessionId);
|
|
266633
266733
|
try {
|
|
266634
266734
|
const fs4 = await import("node:fs");
|
package/package.json
CHANGED