agenr 1.9.2 → 2.0.0
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 +40 -0
- package/README.md +25 -15
- package/dist/adapters/openclaw/index.js +132 -10
- package/dist/{chunk-I6A6DPNF.js → chunk-XD3446YW.js} +2 -2
- package/dist/{chunk-EMRMV2QR.js → chunk-Y2BC7RCE.js} +1347 -110
- package/dist/chunk-ZYADFKX3.js +115 -0
- package/dist/cli.js +767 -252
- package/dist/core/recall/index.js +1 -2
- package/dist/internal-recall-eval-server.js +131 -12
- package/package.json +5 -4
- package/dist/chunk-ETQPUJGS.js +0 -0
- package/dist/{chunk-GUDCFFRV.js → chunk-MEHOGUZE.js} +175 -175
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// src/core/procedures/hashing.ts
|
|
2
|
+
import { createHash } from "crypto";
|
|
3
|
+
function computeProcedureSourceHash(sourceText) {
|
|
4
|
+
return createHash("sha256").update(sourceText).digest("hex");
|
|
5
|
+
}
|
|
6
|
+
function computeProcedureRevisionHash(procedure) {
|
|
7
|
+
return createHash("sha256").update(stringifyCanonical(procedure)).digest("hex");
|
|
8
|
+
}
|
|
9
|
+
function stringifyCanonical(value) {
|
|
10
|
+
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
11
|
+
return JSON.stringify(value);
|
|
12
|
+
}
|
|
13
|
+
if (Array.isArray(value)) {
|
|
14
|
+
return `[${value.map((item) => stringifyCanonical(item)).join(",")}]`;
|
|
15
|
+
}
|
|
16
|
+
const keys = Object.keys(value).sort((left, right) => left.localeCompare(right));
|
|
17
|
+
return `{${keys.map((key) => `${JSON.stringify(key)}:${stringifyCanonical(value[key])}`).join(",")}}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// src/core/procedures/recall-text.ts
|
|
21
|
+
function composeProcedureRecallText(procedure) {
|
|
22
|
+
const lines = [
|
|
23
|
+
`procedure_key: ${procedure.procedure_key}`,
|
|
24
|
+
`title: ${procedure.title}`,
|
|
25
|
+
`goal: ${procedure.goal}`,
|
|
26
|
+
...formatSection("when_to_use", procedure.when_to_use),
|
|
27
|
+
...formatSection("when_not_to_use", procedure.when_not_to_use),
|
|
28
|
+
...formatSection("prerequisites", procedure.prerequisites),
|
|
29
|
+
"steps:",
|
|
30
|
+
...procedure.steps.flatMap((step, index) => formatStep(step, index)),
|
|
31
|
+
...formatSection("verification", procedure.verification),
|
|
32
|
+
...formatSection("failure_modes", procedure.failure_modes),
|
|
33
|
+
"sources:",
|
|
34
|
+
...procedure.sources.map((source, index) => ` ${index + 1}. ${formatSource(source)}`)
|
|
35
|
+
];
|
|
36
|
+
return lines.join("\n");
|
|
37
|
+
}
|
|
38
|
+
function formatSection(label, values) {
|
|
39
|
+
if (values.length === 0) {
|
|
40
|
+
return [`${label}: none`];
|
|
41
|
+
}
|
|
42
|
+
return [`${label}:`, ...values.map((value, index) => ` ${index + 1}. ${value}`)];
|
|
43
|
+
}
|
|
44
|
+
function formatStep(step, index) {
|
|
45
|
+
const lines = [` ${index + 1}. [${step.kind}] ${step.id} - ${step.instruction}`];
|
|
46
|
+
switch (step.kind) {
|
|
47
|
+
case "run_command":
|
|
48
|
+
lines.push(` command: ${step.command}`);
|
|
49
|
+
break;
|
|
50
|
+
case "read_reference":
|
|
51
|
+
lines.push(` ref: ${formatSource(step.ref)}`);
|
|
52
|
+
break;
|
|
53
|
+
case "inspect_state":
|
|
54
|
+
if (step.target) {
|
|
55
|
+
lines.push(` target: ${step.target}`);
|
|
56
|
+
}
|
|
57
|
+
if (step.query) {
|
|
58
|
+
lines.push(` query: ${step.query}`);
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
case "edit_file":
|
|
62
|
+
lines.push(` path: ${step.path}`);
|
|
63
|
+
lines.push(` edit: ${step.edit}`);
|
|
64
|
+
break;
|
|
65
|
+
case "ask_user":
|
|
66
|
+
lines.push(` prompt: ${step.prompt}`);
|
|
67
|
+
break;
|
|
68
|
+
case "invoke_tool":
|
|
69
|
+
lines.push(` tool: ${step.tool}`);
|
|
70
|
+
if (step.arguments) {
|
|
71
|
+
lines.push(` arguments: ${JSON.stringify(step.arguments)}`);
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
case "verify":
|
|
75
|
+
lines.push(...step.checks.map((check, checkIndex) => ` check ${checkIndex + 1}: ${check}`));
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
if (step.conditions?.length) {
|
|
79
|
+
lines.push(` conditions: ${step.conditions.map((condition) => formatCondition(condition)).join("; ")}`);
|
|
80
|
+
}
|
|
81
|
+
if (step.stop_if?.length) {
|
|
82
|
+
lines.push(` stop_if: ${step.stop_if.map((condition) => formatCondition(condition)).join("; ")}`);
|
|
83
|
+
}
|
|
84
|
+
return lines;
|
|
85
|
+
}
|
|
86
|
+
function formatCondition(condition) {
|
|
87
|
+
switch (condition.kind) {
|
|
88
|
+
case "file_exists":
|
|
89
|
+
case "path_exists":
|
|
90
|
+
return `${condition.kind}=${condition.path}`;
|
|
91
|
+
case "env_flag":
|
|
92
|
+
return condition.value ? `${condition.kind}=${condition.name}:${condition.value}` : `${condition.kind}=${condition.name}`;
|
|
93
|
+
default:
|
|
94
|
+
return `${condition.kind}=${condition.value}`;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function formatSource(source) {
|
|
98
|
+
const parts = [source.kind];
|
|
99
|
+
if (source.path) {
|
|
100
|
+
parts.push(`path=${source.path}`);
|
|
101
|
+
}
|
|
102
|
+
if (source.locator) {
|
|
103
|
+
parts.push(`locator=${source.locator}`);
|
|
104
|
+
}
|
|
105
|
+
if (source.label) {
|
|
106
|
+
parts.push(`label=${source.label}`);
|
|
107
|
+
}
|
|
108
|
+
return parts.join(" ");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export {
|
|
112
|
+
computeProcedureSourceHash,
|
|
113
|
+
computeProcedureRevisionHash,
|
|
114
|
+
composeProcedureRecallText
|
|
115
|
+
};
|