@aigne/ash 0.0.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.
- package/DESIGN.md +41 -0
- package/dist/ai-dev-loop/ash-run-result.cjs +12 -0
- package/dist/ai-dev-loop/ash-run-result.d.cts +28 -0
- package/dist/ai-dev-loop/ash-run-result.d.cts.map +1 -0
- package/dist/ai-dev-loop/ash-run-result.d.mts +28 -0
- package/dist/ai-dev-loop/ash-run-result.d.mts.map +1 -0
- package/dist/ai-dev-loop/ash-run-result.mjs +11 -0
- package/dist/ai-dev-loop/ash-run-result.mjs.map +1 -0
- package/dist/ai-dev-loop/ash-typed-error.cjs +51 -0
- package/dist/ai-dev-loop/ash-typed-error.d.cts +54 -0
- package/dist/ai-dev-loop/ash-typed-error.d.cts.map +1 -0
- package/dist/ai-dev-loop/ash-typed-error.d.mts +54 -0
- package/dist/ai-dev-loop/ash-typed-error.d.mts.map +1 -0
- package/dist/ai-dev-loop/ash-typed-error.mjs +50 -0
- package/dist/ai-dev-loop/ash-typed-error.mjs.map +1 -0
- package/dist/ai-dev-loop/ash-validate.cjs +27 -0
- package/dist/ai-dev-loop/ash-validate.d.cts +7 -0
- package/dist/ai-dev-loop/ash-validate.d.cts.map +1 -0
- package/dist/ai-dev-loop/ash-validate.d.mts +7 -0
- package/dist/ai-dev-loop/ash-validate.d.mts.map +1 -0
- package/dist/ai-dev-loop/ash-validate.mjs +28 -0
- package/dist/ai-dev-loop/ash-validate.mjs.map +1 -0
- package/dist/ai-dev-loop/dev-loop.cjs +134 -0
- package/dist/ai-dev-loop/dev-loop.d.cts +28 -0
- package/dist/ai-dev-loop/dev-loop.d.cts.map +1 -0
- package/dist/ai-dev-loop/dev-loop.d.mts +28 -0
- package/dist/ai-dev-loop/dev-loop.d.mts.map +1 -0
- package/dist/ai-dev-loop/dev-loop.mjs +135 -0
- package/dist/ai-dev-loop/dev-loop.mjs.map +1 -0
- package/dist/ai-dev-loop/index.cjs +24 -0
- package/dist/ai-dev-loop/index.d.cts +9 -0
- package/dist/ai-dev-loop/index.d.mts +9 -0
- package/dist/ai-dev-loop/index.mjs +10 -0
- package/dist/ai-dev-loop/live-mode.cjs +17 -0
- package/dist/ai-dev-loop/live-mode.d.cts +24 -0
- package/dist/ai-dev-loop/live-mode.d.cts.map +1 -0
- package/dist/ai-dev-loop/live-mode.d.mts +24 -0
- package/dist/ai-dev-loop/live-mode.d.mts.map +1 -0
- package/dist/ai-dev-loop/live-mode.mjs +17 -0
- package/dist/ai-dev-loop/live-mode.mjs.map +1 -0
- package/dist/ai-dev-loop/meta-tools.cjs +123 -0
- package/dist/ai-dev-loop/meta-tools.d.cts +24 -0
- package/dist/ai-dev-loop/meta-tools.d.cts.map +1 -0
- package/dist/ai-dev-loop/meta-tools.d.mts +24 -0
- package/dist/ai-dev-loop/meta-tools.d.mts.map +1 -0
- package/dist/ai-dev-loop/meta-tools.mjs +120 -0
- package/dist/ai-dev-loop/meta-tools.mjs.map +1 -0
- package/dist/ai-dev-loop/structured-runner.cjs +154 -0
- package/dist/ai-dev-loop/structured-runner.d.cts +12 -0
- package/dist/ai-dev-loop/structured-runner.d.cts.map +1 -0
- package/dist/ai-dev-loop/structured-runner.d.mts +12 -0
- package/dist/ai-dev-loop/structured-runner.d.mts.map +1 -0
- package/dist/ai-dev-loop/structured-runner.mjs +155 -0
- package/dist/ai-dev-loop/structured-runner.mjs.map +1 -0
- package/dist/ai-dev-loop/system-prompt.cjs +55 -0
- package/dist/ai-dev-loop/system-prompt.d.cts +20 -0
- package/dist/ai-dev-loop/system-prompt.d.cts.map +1 -0
- package/dist/ai-dev-loop/system-prompt.d.mts +20 -0
- package/dist/ai-dev-loop/system-prompt.d.mts.map +1 -0
- package/dist/ai-dev-loop/system-prompt.mjs +54 -0
- package/dist/ai-dev-loop/system-prompt.mjs.map +1 -0
- package/dist/ast.d.cts +140 -0
- package/dist/ast.d.cts.map +1 -0
- package/dist/ast.d.mts +140 -0
- package/dist/ast.d.mts.map +1 -0
- package/dist/compiler.cjs +802 -0
- package/dist/compiler.d.cts +103 -0
- package/dist/compiler.d.cts.map +1 -0
- package/dist/compiler.d.mts +103 -0
- package/dist/compiler.d.mts.map +1 -0
- package/dist/compiler.mjs +802 -0
- package/dist/compiler.mjs.map +1 -0
- package/dist/index.cjs +14 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.mjs +7 -0
- package/dist/lexer.cjs +451 -0
- package/dist/lexer.d.cts +14 -0
- package/dist/lexer.d.cts.map +1 -0
- package/dist/lexer.d.mts +14 -0
- package/dist/lexer.d.mts.map +1 -0
- package/dist/lexer.mjs +451 -0
- package/dist/lexer.mjs.map +1 -0
- package/dist/parser.cjs +734 -0
- package/dist/parser.d.cts +40 -0
- package/dist/parser.d.cts.map +1 -0
- package/dist/parser.d.mts +40 -0
- package/dist/parser.d.mts.map +1 -0
- package/dist/parser.mjs +734 -0
- package/dist/parser.mjs.map +1 -0
- package/dist/reference.cjs +130 -0
- package/dist/reference.d.cts +11 -0
- package/dist/reference.d.cts.map +1 -0
- package/dist/reference.d.mts +11 -0
- package/dist/reference.d.mts.map +1 -0
- package/dist/reference.mjs +130 -0
- package/dist/reference.mjs.map +1 -0
- package/dist/template.cjs +85 -0
- package/dist/template.mjs +84 -0
- package/dist/template.mjs.map +1 -0
- package/dist/type-checker.cjs +582 -0
- package/dist/type-checker.d.cts +31 -0
- package/dist/type-checker.d.cts.map +1 -0
- package/dist/type-checker.d.mts +31 -0
- package/dist/type-checker.d.mts.map +1 -0
- package/dist/type-checker.mjs +573 -0
- package/dist/type-checker.mjs.map +1 -0
- package/package.json +29 -0
- package/src/ai-dev-loop/ash-run-result.test.ts +113 -0
- package/src/ai-dev-loop/ash-run-result.ts +46 -0
- package/src/ai-dev-loop/ash-typed-error.test.ts +136 -0
- package/src/ai-dev-loop/ash-typed-error.ts +50 -0
- package/src/ai-dev-loop/ash-validate.test.ts +54 -0
- package/src/ai-dev-loop/ash-validate.ts +34 -0
- package/src/ai-dev-loop/dev-loop.test.ts +364 -0
- package/src/ai-dev-loop/dev-loop.ts +156 -0
- package/src/ai-dev-loop/dry-run.test.ts +107 -0
- package/src/ai-dev-loop/e2e-multi-fix.test.ts +473 -0
- package/src/ai-dev-loop/e2e.test.ts +324 -0
- package/src/ai-dev-loop/index.ts +15 -0
- package/src/ai-dev-loop/invariants.test.ts +253 -0
- package/src/ai-dev-loop/live-mode.test.ts +63 -0
- package/src/ai-dev-loop/live-mode.ts +33 -0
- package/src/ai-dev-loop/meta-tools.test.ts +120 -0
- package/src/ai-dev-loop/meta-tools.ts +142 -0
- package/src/ai-dev-loop/structured-runner.test.ts +159 -0
- package/src/ai-dev-loop/structured-runner.ts +209 -0
- package/src/ai-dev-loop/system-prompt.test.ts +102 -0
- package/src/ai-dev-loop/system-prompt.ts +81 -0
- package/src/ast.ts +186 -0
- package/src/compiler.test.ts +2933 -0
- package/src/compiler.ts +1103 -0
- package/src/e2e.test.ts +552 -0
- package/src/index.ts +16 -0
- package/src/lexer.test.ts +538 -0
- package/src/lexer.ts +222 -0
- package/src/parser.test.ts +1024 -0
- package/src/parser.ts +835 -0
- package/src/reference.test.ts +166 -0
- package/src/reference.ts +125 -0
- package/src/template.test.ts +210 -0
- package/src/template.ts +139 -0
- package/src/type-checker.test.ts +1494 -0
- package/src/type-checker.ts +785 -0
- package/tsconfig.json +9 -0
- package/tsdown.config.ts +12 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { buildCorrectionPrompt, buildSystemPrompt } from "./system-prompt.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/ai-dev-loop/dev-loop.ts
|
|
4
|
+
/**
|
|
5
|
+
* Run the AI dev loop: think → extract ASH → validate → run → observe → correct or return.
|
|
6
|
+
*/
|
|
7
|
+
async function runDevLoop(config) {
|
|
8
|
+
const mode = config.mode ?? "dry-run";
|
|
9
|
+
const observations = [];
|
|
10
|
+
let lastFailure;
|
|
11
|
+
let lastScript;
|
|
12
|
+
for (let i = 0; i < config.max_iterations; i++) {
|
|
13
|
+
let thinkResult;
|
|
14
|
+
try {
|
|
15
|
+
const messages = [];
|
|
16
|
+
if (i === 0) {
|
|
17
|
+
messages.push({
|
|
18
|
+
role: "system",
|
|
19
|
+
content: buildSystemPrompt({ max_iterations: config.max_iterations })
|
|
20
|
+
});
|
|
21
|
+
messages.push({
|
|
22
|
+
role: "user",
|
|
23
|
+
content: config.intent
|
|
24
|
+
});
|
|
25
|
+
} else messages.push({
|
|
26
|
+
role: "user",
|
|
27
|
+
content: buildCorrectionPrompt(lastFailure, lastScript)
|
|
28
|
+
});
|
|
29
|
+
thinkResult = await config.think({ messages });
|
|
30
|
+
} catch (err) {
|
|
31
|
+
return {
|
|
32
|
+
status: "error",
|
|
33
|
+
iterations: i + 1,
|
|
34
|
+
mode,
|
|
35
|
+
observations,
|
|
36
|
+
error: err.message
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const script = extractScript(thinkResult);
|
|
40
|
+
if (!script) {
|
|
41
|
+
const obs$1 = {
|
|
42
|
+
iteration: i + 1,
|
|
43
|
+
error: "empty_response"
|
|
44
|
+
};
|
|
45
|
+
observations.push(obs$1);
|
|
46
|
+
await config.observe(obs$1);
|
|
47
|
+
if (i === config.max_iterations - 1) return {
|
|
48
|
+
status: "error",
|
|
49
|
+
iterations: i + 1,
|
|
50
|
+
mode,
|
|
51
|
+
observations,
|
|
52
|
+
error: "LLM returned no script"
|
|
53
|
+
};
|
|
54
|
+
lastFailure = {
|
|
55
|
+
status: "error",
|
|
56
|
+
steps: [],
|
|
57
|
+
failedAt: {
|
|
58
|
+
kind: "RuntimeError",
|
|
59
|
+
message: "LLM returned no ASH script"
|
|
60
|
+
},
|
|
61
|
+
duration_ms: 0
|
|
62
|
+
};
|
|
63
|
+
lastScript = "";
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
lastScript = script;
|
|
67
|
+
const errors = await config.validate(script);
|
|
68
|
+
if (errors.length > 0) {
|
|
69
|
+
const obs$1 = {
|
|
70
|
+
iteration: i + 1,
|
|
71
|
+
script,
|
|
72
|
+
validation_errors: errors
|
|
73
|
+
};
|
|
74
|
+
observations.push(obs$1);
|
|
75
|
+
await config.observe(obs$1);
|
|
76
|
+
if (i === config.max_iterations - 1) return {
|
|
77
|
+
status: "error",
|
|
78
|
+
iterations: i + 1,
|
|
79
|
+
mode,
|
|
80
|
+
observations,
|
|
81
|
+
finalResult: {
|
|
82
|
+
status: "error",
|
|
83
|
+
steps: [],
|
|
84
|
+
failedAt: errors[0],
|
|
85
|
+
duration_ms: 0
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
lastFailure = {
|
|
89
|
+
status: "error",
|
|
90
|
+
steps: [],
|
|
91
|
+
failedAt: errors[0],
|
|
92
|
+
duration_ms: 0
|
|
93
|
+
};
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const result = await config.runner(script);
|
|
97
|
+
const obs = {
|
|
98
|
+
iteration: i + 1,
|
|
99
|
+
script,
|
|
100
|
+
result
|
|
101
|
+
};
|
|
102
|
+
observations.push(obs);
|
|
103
|
+
await config.observe(obs);
|
|
104
|
+
if (result.status === "ok") return {
|
|
105
|
+
status: "ok",
|
|
106
|
+
iterations: i + 1,
|
|
107
|
+
mode,
|
|
108
|
+
finalResult: result,
|
|
109
|
+
observations
|
|
110
|
+
};
|
|
111
|
+
lastFailure = result;
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
status: "error",
|
|
115
|
+
iterations: config.max_iterations,
|
|
116
|
+
mode,
|
|
117
|
+
finalResult: lastFailure,
|
|
118
|
+
observations
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function extractScript(thinkResult) {
|
|
122
|
+
const toolCalls = thinkResult?.response?.tool_calls;
|
|
123
|
+
if (Array.isArray(toolCalls)) {
|
|
124
|
+
for (const tc of toolCalls) if (tc.name === "ash_run") try {
|
|
125
|
+
const args = typeof tc.arguments === "string" ? JSON.parse(tc.arguments) : tc.arguments;
|
|
126
|
+
if (args?.script) return args.script;
|
|
127
|
+
} catch {}
|
|
128
|
+
}
|
|
129
|
+
const content = thinkResult?.response?.content;
|
|
130
|
+
if (typeof content === "string" && content.trim()) return content.trim();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
//#endregion
|
|
134
|
+
export { runDevLoop };
|
|
135
|
+
//# sourceMappingURL=dev-loop.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-loop.mjs","names":["obs"],"sources":["../../src/ai-dev-loop/dev-loop.ts"],"sourcesContent":["/**\n * AI Dev Loop Core — bounded generate → validate → run → observe → correct loop.\n *\n * Invariants enforced:\n * - INV-1: Default mode is dry-run\n * - INV-3: Observe only, never commit to long-term memory\n * - INV-4: Bounded by max_iterations\n */\n\nimport type { AshRunResult, AshRunFailure } from \"./ash-run-result.js\";\nimport type { AshTypedError } from \"./ash-typed-error.js\";\nimport { buildSystemPrompt, buildCorrectionPrompt } from \"./system-prompt.js\";\n\nexport interface DevLoopConfig {\n intent: string;\n max_iterations: number;\n mode?: \"dry-run\" | \"live\";\n think: (request: any) => Promise<any>;\n runner: (source: string) => Promise<AshRunResult>;\n validate: (source: string) => Promise<AshTypedError[]>;\n observe: (data: any) => Promise<void>;\n}\n\nexport interface DevLoopResult {\n status: \"ok\" | \"error\";\n iterations: number;\n mode: \"dry-run\" | \"live\";\n finalResult?: AshRunResult;\n observations: any[];\n error?: string;\n}\n\n/**\n * Run the AI dev loop: think → extract ASH → validate → run → observe → correct or return.\n */\nexport async function runDevLoop(config: DevLoopConfig): Promise<DevLoopResult> {\n const mode = config.mode ?? \"dry-run\";\n const observations: any[] = [];\n let lastFailure: AshRunFailure | undefined;\n let lastScript: string | undefined;\n\n for (let i = 0; i < config.max_iterations; i++) {\n // 1. Think — ask LLM for ASH script\n let thinkResult: any;\n try {\n const messages: any[] = [];\n if (i === 0) {\n messages.push({ role: \"system\", content: buildSystemPrompt({ max_iterations: config.max_iterations }) });\n messages.push({ role: \"user\", content: config.intent });\n } else {\n messages.push({ role: \"user\", content: buildCorrectionPrompt(lastFailure!, lastScript!) });\n }\n thinkResult = await config.think({ messages });\n } catch (err: any) {\n return { status: \"error\", iterations: i + 1, mode, observations, error: err.message };\n }\n\n // 2. Extract script from tool call or content\n const script = extractScript(thinkResult);\n if (!script) {\n const obs = { iteration: i + 1, error: \"empty_response\" };\n observations.push(obs);\n await config.observe(obs);\n // If no script, treat as failure for this iteration\n if (i === config.max_iterations - 1) {\n return { status: \"error\", iterations: i + 1, mode, observations, error: \"LLM returned no script\" };\n }\n // Create a synthetic failure for correction\n lastFailure = {\n status: \"error\",\n steps: [],\n failedAt: { kind: \"RuntimeError\", message: \"LLM returned no ASH script\" } as AshTypedError,\n duration_ms: 0,\n };\n lastScript = \"\";\n continue;\n }\n\n lastScript = script;\n\n // 3. Validate\n const errors = await config.validate(script);\n if (errors.length > 0) {\n const obs = { iteration: i + 1, script, validation_errors: errors };\n observations.push(obs);\n await config.observe(obs);\n\n if (i === config.max_iterations - 1) {\n return {\n status: \"error\",\n iterations: i + 1,\n mode,\n observations,\n finalResult: {\n status: \"error\",\n steps: [],\n failedAt: errors[0],\n duration_ms: 0,\n },\n };\n }\n\n lastFailure = {\n status: \"error\",\n steps: [],\n failedAt: errors[0] as AshTypedError,\n duration_ms: 0,\n };\n continue;\n }\n\n // 4. Run\n const result = await config.runner(script);\n\n // 5. Observe\n const obs = { iteration: i + 1, script, result };\n observations.push(obs);\n await config.observe(obs);\n\n // 6. Check result\n if (result.status === \"ok\") {\n return { status: \"ok\", iterations: i + 1, mode, finalResult: result, observations };\n }\n\n // Failed — prepare for correction\n lastFailure = result as AshRunFailure;\n }\n\n // Exhausted all iterations\n return {\n status: \"error\",\n iterations: config.max_iterations,\n mode,\n finalResult: lastFailure,\n observations,\n };\n}\n\nfunction extractScript(thinkResult: any): string | undefined {\n // Try tool_calls first (ash_run call)\n const toolCalls = thinkResult?.response?.tool_calls;\n if (Array.isArray(toolCalls)) {\n for (const tc of toolCalls) {\n if (tc.name === \"ash_run\") {\n try {\n const args = typeof tc.arguments === \"string\" ? JSON.parse(tc.arguments) : tc.arguments;\n if (args?.script) return args.script;\n } catch { /* ignore parse error */ }\n }\n }\n }\n // Fall back to content\n const content = thinkResult?.response?.content;\n if (typeof content === \"string\" && content.trim()) return content.trim();\n return undefined;\n}\n"],"mappings":";;;;;;AAmCA,eAAsB,WAAW,QAA+C;CAC9E,MAAM,OAAO,OAAO,QAAQ;CAC5B,MAAM,eAAsB,EAAE;CAC9B,IAAI;CACJ,IAAI;AAEJ,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,gBAAgB,KAAK;EAE9C,IAAI;AACJ,MAAI;GACF,MAAM,WAAkB,EAAE;AAC1B,OAAI,MAAM,GAAG;AACX,aAAS,KAAK;KAAE,MAAM;KAAU,SAAS,kBAAkB,EAAE,gBAAgB,OAAO,gBAAgB,CAAC;KAAE,CAAC;AACxG,aAAS,KAAK;KAAE,MAAM;KAAQ,SAAS,OAAO;KAAQ,CAAC;SAEvD,UAAS,KAAK;IAAE,MAAM;IAAQ,SAAS,sBAAsB,aAAc,WAAY;IAAE,CAAC;AAE5F,iBAAc,MAAM,OAAO,MAAM,EAAE,UAAU,CAAC;WACvC,KAAU;AACjB,UAAO;IAAE,QAAQ;IAAS,YAAY,IAAI;IAAG;IAAM;IAAc,OAAO,IAAI;IAAS;;EAIvF,MAAM,SAAS,cAAc,YAAY;AACzC,MAAI,CAAC,QAAQ;GACX,MAAMA,QAAM;IAAE,WAAW,IAAI;IAAG,OAAO;IAAkB;AACzD,gBAAa,KAAKA,MAAI;AACtB,SAAM,OAAO,QAAQA,MAAI;AAEzB,OAAI,MAAM,OAAO,iBAAiB,EAChC,QAAO;IAAE,QAAQ;IAAS,YAAY,IAAI;IAAG;IAAM;IAAc,OAAO;IAA0B;AAGpG,iBAAc;IACZ,QAAQ;IACR,OAAO,EAAE;IACT,UAAU;KAAE,MAAM;KAAgB,SAAS;KAA8B;IACzE,aAAa;IACd;AACD,gBAAa;AACb;;AAGF,eAAa;EAGb,MAAM,SAAS,MAAM,OAAO,SAAS,OAAO;AAC5C,MAAI,OAAO,SAAS,GAAG;GACrB,MAAMA,QAAM;IAAE,WAAW,IAAI;IAAG;IAAQ,mBAAmB;IAAQ;AACnE,gBAAa,KAAKA,MAAI;AACtB,SAAM,OAAO,QAAQA,MAAI;AAEzB,OAAI,MAAM,OAAO,iBAAiB,EAChC,QAAO;IACL,QAAQ;IACR,YAAY,IAAI;IAChB;IACA;IACA,aAAa;KACX,QAAQ;KACR,OAAO,EAAE;KACT,UAAU,OAAO;KACjB,aAAa;KACd;IACF;AAGH,iBAAc;IACZ,QAAQ;IACR,OAAO,EAAE;IACT,UAAU,OAAO;IACjB,aAAa;IACd;AACD;;EAIF,MAAM,SAAS,MAAM,OAAO,OAAO,OAAO;EAG1C,MAAM,MAAM;GAAE,WAAW,IAAI;GAAG;GAAQ;GAAQ;AAChD,eAAa,KAAK,IAAI;AACtB,QAAM,OAAO,QAAQ,IAAI;AAGzB,MAAI,OAAO,WAAW,KACpB,QAAO;GAAE,QAAQ;GAAM,YAAY,IAAI;GAAG;GAAM,aAAa;GAAQ;GAAc;AAIrF,gBAAc;;AAIhB,QAAO;EACL,QAAQ;EACR,YAAY,OAAO;EACnB;EACA,aAAa;EACb;EACD;;AAGH,SAAS,cAAc,aAAsC;CAE3D,MAAM,YAAY,aAAa,UAAU;AACzC,KAAI,MAAM,QAAQ,UAAU,EAC1B;OAAK,MAAM,MAAM,UACf,KAAI,GAAG,SAAS,UACd,KAAI;GACF,MAAM,OAAO,OAAO,GAAG,cAAc,WAAW,KAAK,MAAM,GAAG,UAAU,GAAG,GAAG;AAC9E,OAAI,MAAM,OAAQ,QAAO,KAAK;UACxB;;CAKd,MAAM,UAAU,aAAa,UAAU;AACvC,KAAI,OAAO,YAAY,YAAY,QAAQ,MAAM,CAAE,QAAO,QAAQ,MAAM"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const require_system_prompt = require('./system-prompt.cjs');
|
|
2
|
+
const require_dev_loop = require('./dev-loop.cjs');
|
|
3
|
+
const require_ash_typed_error = require('./ash-typed-error.cjs');
|
|
4
|
+
const require_structured_runner = require('./structured-runner.cjs');
|
|
5
|
+
const require_ash_validate = require('./ash-validate.cjs');
|
|
6
|
+
const require_ash_run_result = require('./ash-run-result.cjs');
|
|
7
|
+
const require_live_mode = require('./live-mode.cjs');
|
|
8
|
+
const require_meta_tools = require('./meta-tools.cjs');
|
|
9
|
+
|
|
10
|
+
exports.META_TOOL_DEFS = require_meta_tools.META_TOOL_DEFS;
|
|
11
|
+
exports.ashExplainErrorToolDef = require_meta_tools.ashExplainErrorToolDef;
|
|
12
|
+
exports.ashRunToolDef = require_meta_tools.ashRunToolDef;
|
|
13
|
+
exports.ashValidate = require_ash_validate.ashValidate;
|
|
14
|
+
exports.ashValidateToolDef = require_meta_tools.ashValidateToolDef;
|
|
15
|
+
exports.buildCorrectionPrompt = require_system_prompt.buildCorrectionPrompt;
|
|
16
|
+
exports.buildSystemPrompt = require_system_prompt.buildSystemPrompt;
|
|
17
|
+
exports.checkLivePermission = require_live_mode.checkLivePermission;
|
|
18
|
+
exports.executeMetaTool = require_meta_tools.executeMetaTool;
|
|
19
|
+
exports.fromJobError = require_ash_typed_error.fromJobError;
|
|
20
|
+
exports.isAshRunFailure = require_ash_run_result.isAshRunFailure;
|
|
21
|
+
exports.isAshRunSuccess = require_ash_run_result.isAshRunSuccess;
|
|
22
|
+
exports.isAshTypedError = require_ash_typed_error.isAshTypedError;
|
|
23
|
+
exports.runDevLoop = require_dev_loop.runDevLoop;
|
|
24
|
+
exports.runStructured = require_structured_runner.runStructured;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AshTypedError, fromJobError, isAshTypedError } from "./ash-typed-error.cjs";
|
|
2
|
+
import { AshRunFailure, AshRunResult, AshRunSuccess, AshStepResult, isAshRunFailure, isAshRunSuccess } from "./ash-run-result.cjs";
|
|
3
|
+
import { DevLoopConfig, DevLoopResult, runDevLoop } from "./dev-loop.cjs";
|
|
4
|
+
import { runStructured } from "./structured-runner.cjs";
|
|
5
|
+
import { ashValidate } from "./ash-validate.cjs";
|
|
6
|
+
import { LiveModePolicy, checkLivePermission } from "./live-mode.cjs";
|
|
7
|
+
import { buildCorrectionPrompt, buildSystemPrompt } from "./system-prompt.cjs";
|
|
8
|
+
import { META_TOOL_DEFS, ashExplainErrorToolDef, ashRunToolDef, ashValidateToolDef, executeMetaTool } from "./meta-tools.cjs";
|
|
9
|
+
export { type AshRunFailure, type AshRunResult, type AshRunSuccess, type AshStepResult, type AshTypedError, type DevLoopConfig, type DevLoopResult, type LiveModePolicy, META_TOOL_DEFS, ashExplainErrorToolDef, ashRunToolDef, ashValidate, ashValidateToolDef, buildCorrectionPrompt, buildSystemPrompt, checkLivePermission, executeMetaTool, fromJobError, isAshRunFailure, isAshRunSuccess, isAshTypedError, runDevLoop, runStructured };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AshTypedError, fromJobError, isAshTypedError } from "./ash-typed-error.mjs";
|
|
2
|
+
import { AshRunFailure, AshRunResult, AshRunSuccess, AshStepResult, isAshRunFailure, isAshRunSuccess } from "./ash-run-result.mjs";
|
|
3
|
+
import { DevLoopConfig, DevLoopResult, runDevLoop } from "./dev-loop.mjs";
|
|
4
|
+
import { runStructured } from "./structured-runner.mjs";
|
|
5
|
+
import { ashValidate } from "./ash-validate.mjs";
|
|
6
|
+
import { LiveModePolicy, checkLivePermission } from "./live-mode.mjs";
|
|
7
|
+
import { buildCorrectionPrompt, buildSystemPrompt } from "./system-prompt.mjs";
|
|
8
|
+
import { META_TOOL_DEFS, ashExplainErrorToolDef, ashRunToolDef, ashValidateToolDef, executeMetaTool } from "./meta-tools.mjs";
|
|
9
|
+
export { type AshRunFailure, type AshRunResult, type AshRunSuccess, type AshStepResult, type AshTypedError, type DevLoopConfig, type DevLoopResult, type LiveModePolicy, META_TOOL_DEFS, ashExplainErrorToolDef, ashRunToolDef, ashValidate, ashValidateToolDef, buildCorrectionPrompt, buildSystemPrompt, checkLivePermission, executeMetaTool, fromJobError, isAshRunFailure, isAshRunSuccess, isAshTypedError, runDevLoop, runStructured };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { buildCorrectionPrompt, buildSystemPrompt } from "./system-prompt.mjs";
|
|
2
|
+
import { runDevLoop } from "./dev-loop.mjs";
|
|
3
|
+
import { fromJobError, isAshTypedError } from "./ash-typed-error.mjs";
|
|
4
|
+
import { runStructured } from "./structured-runner.mjs";
|
|
5
|
+
import { ashValidate } from "./ash-validate.mjs";
|
|
6
|
+
import { isAshRunFailure, isAshRunSuccess } from "./ash-run-result.mjs";
|
|
7
|
+
import { checkLivePermission } from "./live-mode.mjs";
|
|
8
|
+
import { META_TOOL_DEFS, ashExplainErrorToolDef, ashRunToolDef, ashValidateToolDef, executeMetaTool } from "./meta-tools.mjs";
|
|
9
|
+
|
|
10
|
+
export { META_TOOL_DEFS, ashExplainErrorToolDef, ashRunToolDef, ashValidate, ashValidateToolDef, buildCorrectionPrompt, buildSystemPrompt, checkLivePermission, executeMetaTool, fromJobError, isAshRunFailure, isAshRunSuccess, isAshTypedError, runDevLoop, runStructured };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/ai-dev-loop/live-mode.ts
|
|
3
|
+
/**
|
|
4
|
+
* Check if live mode is permitted. Checks in priority order:
|
|
5
|
+
* 1. Capability (ash.live)
|
|
6
|
+
* 2. Debug flag
|
|
7
|
+
* 3. User confirmation
|
|
8
|
+
*/
|
|
9
|
+
async function checkLivePermission(policy) {
|
|
10
|
+
if (policy.capabilities.has("ash.live")) return true;
|
|
11
|
+
if (policy.debug) return true;
|
|
12
|
+
if (policy.confirm) return policy.confirm();
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
exports.checkLivePermission = checkLivePermission;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/ai-dev-loop/live-mode.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Live Mode Permission — gates upgrade from dry-run to live execution.
|
|
4
|
+
*
|
|
5
|
+
* Per INTENT §6.1, live mode requires one of:
|
|
6
|
+
* a) ash.live capability in proc caps
|
|
7
|
+
* b) User confirmation callback
|
|
8
|
+
* c) Debug profile flag
|
|
9
|
+
*/
|
|
10
|
+
interface LiveModePolicy {
|
|
11
|
+
capabilities: Set<string>;
|
|
12
|
+
confirm?: () => Promise<boolean>;
|
|
13
|
+
debug?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Check if live mode is permitted. Checks in priority order:
|
|
17
|
+
* 1. Capability (ash.live)
|
|
18
|
+
* 2. Debug flag
|
|
19
|
+
* 3. User confirmation
|
|
20
|
+
*/
|
|
21
|
+
declare function checkLivePermission(policy: LiveModePolicy): Promise<boolean>;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { LiveModePolicy, checkLivePermission };
|
|
24
|
+
//# sourceMappingURL=live-mode.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live-mode.d.cts","names":[],"sources":["../../src/ai-dev-loop/live-mode.ts"],"mappings":";;AASA;;;;;;;UAAiB,cAAA;EACf,YAAA,EAAc,GAAA;EACd,OAAA,SAAgB,OAAA;EAChB,KAAA;AAAA;;;;;;;iBASoB,mBAAA,CAAoB,MAAA,EAAQ,cAAA,GAAiB,OAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/ai-dev-loop/live-mode.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Live Mode Permission — gates upgrade from dry-run to live execution.
|
|
4
|
+
*
|
|
5
|
+
* Per INTENT §6.1, live mode requires one of:
|
|
6
|
+
* a) ash.live capability in proc caps
|
|
7
|
+
* b) User confirmation callback
|
|
8
|
+
* c) Debug profile flag
|
|
9
|
+
*/
|
|
10
|
+
interface LiveModePolicy {
|
|
11
|
+
capabilities: Set<string>;
|
|
12
|
+
confirm?: () => Promise<boolean>;
|
|
13
|
+
debug?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Check if live mode is permitted. Checks in priority order:
|
|
17
|
+
* 1. Capability (ash.live)
|
|
18
|
+
* 2. Debug flag
|
|
19
|
+
* 3. User confirmation
|
|
20
|
+
*/
|
|
21
|
+
declare function checkLivePermission(policy: LiveModePolicy): Promise<boolean>;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { LiveModePolicy, checkLivePermission };
|
|
24
|
+
//# sourceMappingURL=live-mode.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live-mode.d.mts","names":[],"sources":["../../src/ai-dev-loop/live-mode.ts"],"mappings":";;AASA;;;;;;;UAAiB,cAAA;EACf,YAAA,EAAc,GAAA;EACd,OAAA,SAAgB,OAAA;EAChB,KAAA;AAAA;;;;;;;iBASoB,mBAAA,CAAoB,MAAA,EAAQ,cAAA,GAAiB,OAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/ai-dev-loop/live-mode.ts
|
|
2
|
+
/**
|
|
3
|
+
* Check if live mode is permitted. Checks in priority order:
|
|
4
|
+
* 1. Capability (ash.live)
|
|
5
|
+
* 2. Debug flag
|
|
6
|
+
* 3. User confirmation
|
|
7
|
+
*/
|
|
8
|
+
async function checkLivePermission(policy) {
|
|
9
|
+
if (policy.capabilities.has("ash.live")) return true;
|
|
10
|
+
if (policy.debug) return true;
|
|
11
|
+
if (policy.confirm) return policy.confirm();
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { checkLivePermission };
|
|
17
|
+
//# sourceMappingURL=live-mode.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live-mode.mjs","names":[],"sources":["../../src/ai-dev-loop/live-mode.ts"],"sourcesContent":["/**\n * Live Mode Permission — gates upgrade from dry-run to live execution.\n *\n * Per INTENT §6.1, live mode requires one of:\n * a) ash.live capability in proc caps\n * b) User confirmation callback\n * c) Debug profile flag\n */\n\nexport interface LiveModePolicy {\n capabilities: Set<string>;\n confirm?: () => Promise<boolean>;\n debug?: boolean;\n}\n\n/**\n * Check if live mode is permitted. Checks in priority order:\n * 1. Capability (ash.live)\n * 2. Debug flag\n * 3. User confirmation\n */\nexport async function checkLivePermission(policy: LiveModePolicy): Promise<boolean> {\n // 1. Capability takes priority\n if (policy.capabilities.has(\"ash.live\")) return true;\n\n // 2. Debug profile\n if (policy.debug) return true;\n\n // 3. User confirmation\n if (policy.confirm) return policy.confirm();\n\n return false;\n}\n"],"mappings":";;;;;;;AAqBA,eAAsB,oBAAoB,QAA0C;AAElF,KAAI,OAAO,aAAa,IAAI,WAAW,CAAE,QAAO;AAGhD,KAAI,OAAO,MAAO,QAAO;AAGzB,KAAI,OAAO,QAAS,QAAO,OAAO,SAAS;AAE3C,QAAO"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
const require_ash_typed_error = require('./ash-typed-error.cjs');
|
|
2
|
+
const require_structured_runner = require('./structured-runner.cjs');
|
|
3
|
+
const require_ash_validate = require('./ash-validate.cjs');
|
|
4
|
+
|
|
5
|
+
//#region src/ai-dev-loop/meta-tools.ts
|
|
6
|
+
const ashRunToolDef = {
|
|
7
|
+
name: "ash_run",
|
|
8
|
+
description: "Execute an ASH script. Default mode is dry-run (no side effects).",
|
|
9
|
+
parameters: {
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
script: {
|
|
13
|
+
type: "string",
|
|
14
|
+
description: "ASH script source code"
|
|
15
|
+
},
|
|
16
|
+
mode: {
|
|
17
|
+
type: "string",
|
|
18
|
+
enum: ["dry-run", "live"],
|
|
19
|
+
description: "Execution mode. Default: dry-run"
|
|
20
|
+
},
|
|
21
|
+
timeout_ms: {
|
|
22
|
+
type: "number",
|
|
23
|
+
description: "Timeout in milliseconds. Default: 30000"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
required: ["script"]
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const ashValidateToolDef = {
|
|
30
|
+
name: "ash_validate",
|
|
31
|
+
description: "Validate an ASH script for syntax and type errors without executing it.",
|
|
32
|
+
parameters: {
|
|
33
|
+
type: "object",
|
|
34
|
+
properties: { script: {
|
|
35
|
+
type: "string",
|
|
36
|
+
description: "ASH script source code to validate"
|
|
37
|
+
} },
|
|
38
|
+
required: ["script"]
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const ashExplainErrorToolDef = {
|
|
42
|
+
name: "ash_explain_error",
|
|
43
|
+
description: "Get a human-readable explanation of an ASH error with repair suggestions.",
|
|
44
|
+
parameters: {
|
|
45
|
+
type: "object",
|
|
46
|
+
properties: { error: { description: "The AshTypedError object to explain" } },
|
|
47
|
+
required: ["error"]
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const META_TOOL_DEFS = [
|
|
51
|
+
ashRunToolDef,
|
|
52
|
+
ashValidateToolDef,
|
|
53
|
+
ashExplainErrorToolDef
|
|
54
|
+
];
|
|
55
|
+
/**
|
|
56
|
+
* Execute a meta tool by name.
|
|
57
|
+
*/
|
|
58
|
+
async function executeMetaTool(name, args, ctx) {
|
|
59
|
+
switch (name) {
|
|
60
|
+
case "ash_run":
|
|
61
|
+
if (!args.script || typeof args.script !== "string") throw new Error("ash_run: script field is required and must be a string");
|
|
62
|
+
return require_structured_runner.runStructured(args.script, ctx, {
|
|
63
|
+
mode: args.mode ?? "dry-run",
|
|
64
|
+
timeout_ms: args.timeout_ms ?? 3e4
|
|
65
|
+
});
|
|
66
|
+
case "ash_validate":
|
|
67
|
+
if (!args.script || typeof args.script !== "string") throw new Error("ash_validate: script field is required and must be a string");
|
|
68
|
+
return require_ash_validate.ashValidate(args.script);
|
|
69
|
+
case "ash_explain_error": {
|
|
70
|
+
const error = args.error;
|
|
71
|
+
if (require_ash_typed_error.isAshTypedError(error)) return explainTypedError(error);
|
|
72
|
+
return {
|
|
73
|
+
explanation: `Unknown error: ${JSON.stringify(error)}`,
|
|
74
|
+
suggestion: "Check the error details."
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
default: throw new Error(`Unknown meta tool: ${name}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function explainTypedError(error) {
|
|
81
|
+
switch (error.kind) {
|
|
82
|
+
case "IntentDenied": return {
|
|
83
|
+
explanation: `IntentDenied: ${error.message}. Violated invariant: ${error.invariant}.`,
|
|
84
|
+
suggestion: error.suggestion ?? "Check the action permissions."
|
|
85
|
+
};
|
|
86
|
+
case "CapabilityMissing": return {
|
|
87
|
+
explanation: `CapabilityMissing: Required capability "${error.capability}" is not available.`,
|
|
88
|
+
suggestion: "Request the capability or use a different approach."
|
|
89
|
+
};
|
|
90
|
+
case "ToolNotFound": return {
|
|
91
|
+
explanation: `ToolNotFound: Tool "${error.name}" not found. Available: [${error.available?.join(", ")}].`,
|
|
92
|
+
suggestion: "Use one of the available tools."
|
|
93
|
+
};
|
|
94
|
+
case "ValidationFailed": return {
|
|
95
|
+
explanation: `ValidationFailed: Field "${error.field}" expected ${error.expected}, got ${error.got}.`,
|
|
96
|
+
suggestion: "Fix the field value to match the expected type."
|
|
97
|
+
};
|
|
98
|
+
case "BudgetExceeded": return {
|
|
99
|
+
explanation: `BudgetExceeded: Device "${error.device}" used ${error.used}/${error.limit}.`,
|
|
100
|
+
suggestion: "Reduce token usage or wait for budget reset."
|
|
101
|
+
};
|
|
102
|
+
case "Timeout": return {
|
|
103
|
+
explanation: `Timeout: Step "${error.step}" exceeded ${error.limit_ms}ms limit.`,
|
|
104
|
+
suggestion: "Simplify the query or increase the timeout."
|
|
105
|
+
};
|
|
106
|
+
case "ParseError": return {
|
|
107
|
+
explanation: `ParseError: ${error.message}${error.line ? ` at line ${error.line}` : ""}.`,
|
|
108
|
+
suggestion: "Fix the syntax error in the ASH script."
|
|
109
|
+
};
|
|
110
|
+
case "RuntimeError": return {
|
|
111
|
+
explanation: `RuntimeError: ${error.message}.`,
|
|
112
|
+
suggestion: "Check the runtime context and data."
|
|
113
|
+
};
|
|
114
|
+
default: return { explanation: `Error: ${error.message ?? JSON.stringify(error)}` };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
//#endregion
|
|
119
|
+
exports.META_TOOL_DEFS = META_TOOL_DEFS;
|
|
120
|
+
exports.ashExplainErrorToolDef = ashExplainErrorToolDef;
|
|
121
|
+
exports.ashRunToolDef = ashRunToolDef;
|
|
122
|
+
exports.ashValidateToolDef = ashValidateToolDef;
|
|
123
|
+
exports.executeMetaTool = executeMetaTool;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { JobContext } from "../compiler.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/ai-dev-loop/meta-tools.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Meta Tools — LLM-callable tool definitions for ASH AI Dev Loop.
|
|
6
|
+
*
|
|
7
|
+
* These tools are Proc-internal, not registered in Discovery.
|
|
8
|
+
*/
|
|
9
|
+
interface LLMToolDef {
|
|
10
|
+
name: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
parameters?: unknown;
|
|
13
|
+
}
|
|
14
|
+
declare const ashRunToolDef: LLMToolDef;
|
|
15
|
+
declare const ashValidateToolDef: LLMToolDef;
|
|
16
|
+
declare const ashExplainErrorToolDef: LLMToolDef;
|
|
17
|
+
declare const META_TOOL_DEFS: LLMToolDef[];
|
|
18
|
+
/**
|
|
19
|
+
* Execute a meta tool by name.
|
|
20
|
+
*/
|
|
21
|
+
declare function executeMetaTool(name: string, args: Record<string, unknown>, ctx: JobContext): Promise<any>;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { META_TOOL_DEFS, ashExplainErrorToolDef, ashRunToolDef, ashValidateToolDef, executeMetaTool };
|
|
24
|
+
//# sourceMappingURL=meta-tools.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta-tools.d.cts","names":[],"sources":["../../src/ai-dev-loop/meta-tools.ts"],"mappings":";;;;;;;;UAOU,UAAA;EACR,IAAA;EACA,WAAA;EACA,UAAA;AAAA;AAAA,cAOW,aAAA,EAAe,UAAA;AAAA,cAcf,kBAAA,EAAoB,UAAA;AAAA,cAYpB,sBAAA,EAAwB,UAAA;AAAA,cAYxB,cAAA,EAAc,UAAA;;;AAxB3B;iBA6BsB,eAAA,CACpB,IAAA,UACA,IAAA,EAAM,MAAA,mBACN,GAAA,EAAK,UAAA,GACJ,OAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { JobContext } from "../compiler.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/ai-dev-loop/meta-tools.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Meta Tools — LLM-callable tool definitions for ASH AI Dev Loop.
|
|
6
|
+
*
|
|
7
|
+
* These tools are Proc-internal, not registered in Discovery.
|
|
8
|
+
*/
|
|
9
|
+
interface LLMToolDef {
|
|
10
|
+
name: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
parameters?: unknown;
|
|
13
|
+
}
|
|
14
|
+
declare const ashRunToolDef: LLMToolDef;
|
|
15
|
+
declare const ashValidateToolDef: LLMToolDef;
|
|
16
|
+
declare const ashExplainErrorToolDef: LLMToolDef;
|
|
17
|
+
declare const META_TOOL_DEFS: LLMToolDef[];
|
|
18
|
+
/**
|
|
19
|
+
* Execute a meta tool by name.
|
|
20
|
+
*/
|
|
21
|
+
declare function executeMetaTool(name: string, args: Record<string, unknown>, ctx: JobContext): Promise<any>;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { META_TOOL_DEFS, ashExplainErrorToolDef, ashRunToolDef, ashValidateToolDef, executeMetaTool };
|
|
24
|
+
//# sourceMappingURL=meta-tools.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta-tools.d.mts","names":[],"sources":["../../src/ai-dev-loop/meta-tools.ts"],"mappings":";;;;;;;;UAOU,UAAA;EACR,IAAA;EACA,WAAA;EACA,UAAA;AAAA;AAAA,cAOW,aAAA,EAAe,UAAA;AAAA,cAcf,kBAAA,EAAoB,UAAA;AAAA,cAYpB,sBAAA,EAAwB,UAAA;AAAA,cAYxB,cAAA,EAAc,UAAA;;;AAxB3B;iBA6BsB,eAAA,CACpB,IAAA,UACA,IAAA,EAAM,MAAA,mBACN,GAAA,EAAK,UAAA,GACJ,OAAA"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { isAshTypedError } from "./ash-typed-error.mjs";
|
|
2
|
+
import { runStructured } from "./structured-runner.mjs";
|
|
3
|
+
import { ashValidate } from "./ash-validate.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/ai-dev-loop/meta-tools.ts
|
|
6
|
+
const ashRunToolDef = {
|
|
7
|
+
name: "ash_run",
|
|
8
|
+
description: "Execute an ASH script. Default mode is dry-run (no side effects).",
|
|
9
|
+
parameters: {
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
script: {
|
|
13
|
+
type: "string",
|
|
14
|
+
description: "ASH script source code"
|
|
15
|
+
},
|
|
16
|
+
mode: {
|
|
17
|
+
type: "string",
|
|
18
|
+
enum: ["dry-run", "live"],
|
|
19
|
+
description: "Execution mode. Default: dry-run"
|
|
20
|
+
},
|
|
21
|
+
timeout_ms: {
|
|
22
|
+
type: "number",
|
|
23
|
+
description: "Timeout in milliseconds. Default: 30000"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
required: ["script"]
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const ashValidateToolDef = {
|
|
30
|
+
name: "ash_validate",
|
|
31
|
+
description: "Validate an ASH script for syntax and type errors without executing it.",
|
|
32
|
+
parameters: {
|
|
33
|
+
type: "object",
|
|
34
|
+
properties: { script: {
|
|
35
|
+
type: "string",
|
|
36
|
+
description: "ASH script source code to validate"
|
|
37
|
+
} },
|
|
38
|
+
required: ["script"]
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const ashExplainErrorToolDef = {
|
|
42
|
+
name: "ash_explain_error",
|
|
43
|
+
description: "Get a human-readable explanation of an ASH error with repair suggestions.",
|
|
44
|
+
parameters: {
|
|
45
|
+
type: "object",
|
|
46
|
+
properties: { error: { description: "The AshTypedError object to explain" } },
|
|
47
|
+
required: ["error"]
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const META_TOOL_DEFS = [
|
|
51
|
+
ashRunToolDef,
|
|
52
|
+
ashValidateToolDef,
|
|
53
|
+
ashExplainErrorToolDef
|
|
54
|
+
];
|
|
55
|
+
/**
|
|
56
|
+
* Execute a meta tool by name.
|
|
57
|
+
*/
|
|
58
|
+
async function executeMetaTool(name, args, ctx) {
|
|
59
|
+
switch (name) {
|
|
60
|
+
case "ash_run":
|
|
61
|
+
if (!args.script || typeof args.script !== "string") throw new Error("ash_run: script field is required and must be a string");
|
|
62
|
+
return runStructured(args.script, ctx, {
|
|
63
|
+
mode: args.mode ?? "dry-run",
|
|
64
|
+
timeout_ms: args.timeout_ms ?? 3e4
|
|
65
|
+
});
|
|
66
|
+
case "ash_validate":
|
|
67
|
+
if (!args.script || typeof args.script !== "string") throw new Error("ash_validate: script field is required and must be a string");
|
|
68
|
+
return ashValidate(args.script);
|
|
69
|
+
case "ash_explain_error": {
|
|
70
|
+
const error = args.error;
|
|
71
|
+
if (isAshTypedError(error)) return explainTypedError(error);
|
|
72
|
+
return {
|
|
73
|
+
explanation: `Unknown error: ${JSON.stringify(error)}`,
|
|
74
|
+
suggestion: "Check the error details."
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
default: throw new Error(`Unknown meta tool: ${name}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function explainTypedError(error) {
|
|
81
|
+
switch (error.kind) {
|
|
82
|
+
case "IntentDenied": return {
|
|
83
|
+
explanation: `IntentDenied: ${error.message}. Violated invariant: ${error.invariant}.`,
|
|
84
|
+
suggestion: error.suggestion ?? "Check the action permissions."
|
|
85
|
+
};
|
|
86
|
+
case "CapabilityMissing": return {
|
|
87
|
+
explanation: `CapabilityMissing: Required capability "${error.capability}" is not available.`,
|
|
88
|
+
suggestion: "Request the capability or use a different approach."
|
|
89
|
+
};
|
|
90
|
+
case "ToolNotFound": return {
|
|
91
|
+
explanation: `ToolNotFound: Tool "${error.name}" not found. Available: [${error.available?.join(", ")}].`,
|
|
92
|
+
suggestion: "Use one of the available tools."
|
|
93
|
+
};
|
|
94
|
+
case "ValidationFailed": return {
|
|
95
|
+
explanation: `ValidationFailed: Field "${error.field}" expected ${error.expected}, got ${error.got}.`,
|
|
96
|
+
suggestion: "Fix the field value to match the expected type."
|
|
97
|
+
};
|
|
98
|
+
case "BudgetExceeded": return {
|
|
99
|
+
explanation: `BudgetExceeded: Device "${error.device}" used ${error.used}/${error.limit}.`,
|
|
100
|
+
suggestion: "Reduce token usage or wait for budget reset."
|
|
101
|
+
};
|
|
102
|
+
case "Timeout": return {
|
|
103
|
+
explanation: `Timeout: Step "${error.step}" exceeded ${error.limit_ms}ms limit.`,
|
|
104
|
+
suggestion: "Simplify the query or increase the timeout."
|
|
105
|
+
};
|
|
106
|
+
case "ParseError": return {
|
|
107
|
+
explanation: `ParseError: ${error.message}${error.line ? ` at line ${error.line}` : ""}.`,
|
|
108
|
+
suggestion: "Fix the syntax error in the ASH script."
|
|
109
|
+
};
|
|
110
|
+
case "RuntimeError": return {
|
|
111
|
+
explanation: `RuntimeError: ${error.message}.`,
|
|
112
|
+
suggestion: "Check the runtime context and data."
|
|
113
|
+
};
|
|
114
|
+
default: return { explanation: `Error: ${error.message ?? JSON.stringify(error)}` };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
//#endregion
|
|
119
|
+
export { META_TOOL_DEFS, ashExplainErrorToolDef, ashRunToolDef, ashValidateToolDef, executeMetaTool };
|
|
120
|
+
//# sourceMappingURL=meta-tools.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta-tools.mjs","names":[],"sources":["../../src/ai-dev-loop/meta-tools.ts"],"sourcesContent":["/**\n * Meta Tools — LLM-callable tool definitions for ASH AI Dev Loop.\n *\n * These tools are Proc-internal, not registered in Discovery.\n */\n\n// Tool definition type inline (avoid circular dependency with kernel)\ninterface LLMToolDef {\n name: string;\n description?: string;\n parameters?: unknown;\n}\nimport type { JobContext } from \"../compiler.js\";\nimport { runStructured } from \"./structured-runner.js\";\nimport { ashValidate } from \"./ash-validate.js\";\nimport { isAshTypedError } from \"./ash-typed-error.js\";\n\nexport const ashRunToolDef: LLMToolDef = {\n name: \"ash_run\",\n description: \"Execute an ASH script. Default mode is dry-run (no side effects).\",\n parameters: {\n type: \"object\",\n properties: {\n script: { type: \"string\", description: \"ASH script source code\" },\n mode: { type: \"string\", enum: [\"dry-run\", \"live\"], description: \"Execution mode. Default: dry-run\" },\n timeout_ms: { type: \"number\", description: \"Timeout in milliseconds. Default: 30000\" },\n },\n required: [\"script\"],\n },\n};\n\nexport const ashValidateToolDef: LLMToolDef = {\n name: \"ash_validate\",\n description: \"Validate an ASH script for syntax and type errors without executing it.\",\n parameters: {\n type: \"object\",\n properties: {\n script: { type: \"string\", description: \"ASH script source code to validate\" },\n },\n required: [\"script\"],\n },\n};\n\nexport const ashExplainErrorToolDef: LLMToolDef = {\n name: \"ash_explain_error\",\n description: \"Get a human-readable explanation of an ASH error with repair suggestions.\",\n parameters: {\n type: \"object\",\n properties: {\n error: { description: \"The AshTypedError object to explain\" },\n },\n required: [\"error\"],\n },\n};\n\nexport const META_TOOL_DEFS = [ashRunToolDef, ashValidateToolDef, ashExplainErrorToolDef];\n\n/**\n * Execute a meta tool by name.\n */\nexport async function executeMetaTool(\n name: string,\n args: Record<string, unknown>,\n ctx: JobContext,\n): Promise<any> {\n switch (name) {\n case \"ash_run\": {\n if (!args.script || typeof args.script !== \"string\") {\n throw new Error(\"ash_run: script field is required and must be a string\");\n }\n return runStructured(args.script as string, ctx, {\n mode: (args.mode as \"dry-run\" | \"live\") ?? \"dry-run\",\n timeout_ms: (args.timeout_ms as number) ?? 30000,\n });\n }\n\n case \"ash_validate\": {\n if (!args.script || typeof args.script !== \"string\") {\n throw new Error(\"ash_validate: script field is required and must be a string\");\n }\n return ashValidate(args.script as string);\n }\n\n case \"ash_explain_error\": {\n const error = args.error;\n if (isAshTypedError(error)) {\n return explainTypedError(error);\n }\n return { explanation: `Unknown error: ${JSON.stringify(error)}`, suggestion: \"Check the error details.\" };\n }\n\n default:\n throw new Error(`Unknown meta tool: ${name}`);\n }\n}\n\nfunction explainTypedError(error: any): { explanation: string; suggestion?: string } {\n switch (error.kind) {\n case \"IntentDenied\":\n return {\n explanation: `IntentDenied: ${error.message}. Violated invariant: ${error.invariant}.`,\n suggestion: error.suggestion ?? \"Check the action permissions.\",\n };\n case \"CapabilityMissing\":\n return {\n explanation: `CapabilityMissing: Required capability \"${error.capability}\" is not available.`,\n suggestion: \"Request the capability or use a different approach.\",\n };\n case \"ToolNotFound\":\n return {\n explanation: `ToolNotFound: Tool \"${error.name}\" not found. Available: [${error.available?.join(\", \")}].`,\n suggestion: \"Use one of the available tools.\",\n };\n case \"ValidationFailed\":\n return {\n explanation: `ValidationFailed: Field \"${error.field}\" expected ${error.expected}, got ${error.got}.`,\n suggestion: \"Fix the field value to match the expected type.\",\n };\n case \"BudgetExceeded\":\n return {\n explanation: `BudgetExceeded: Device \"${error.device}\" used ${error.used}/${error.limit}.`,\n suggestion: \"Reduce token usage or wait for budget reset.\",\n };\n case \"Timeout\":\n return {\n explanation: `Timeout: Step \"${error.step}\" exceeded ${error.limit_ms}ms limit.`,\n suggestion: \"Simplify the query or increase the timeout.\",\n };\n case \"ParseError\":\n return {\n explanation: `ParseError: ${error.message}${error.line ? ` at line ${error.line}` : \"\"}.`,\n suggestion: \"Fix the syntax error in the ASH script.\",\n };\n case \"RuntimeError\":\n return {\n explanation: `RuntimeError: ${error.message}.`,\n suggestion: \"Check the runtime context and data.\",\n };\n default:\n return { explanation: `Error: ${error.message ?? JSON.stringify(error)}` };\n }\n}\n"],"mappings":";;;;;AAiBA,MAAa,gBAA4B;CACvC,MAAM;CACN,aAAa;CACb,YAAY;EACV,MAAM;EACN,YAAY;GACV,QAAQ;IAAE,MAAM;IAAU,aAAa;IAA0B;GACjE,MAAM;IAAE,MAAM;IAAU,MAAM,CAAC,WAAW,OAAO;IAAE,aAAa;IAAoC;GACpG,YAAY;IAAE,MAAM;IAAU,aAAa;IAA2C;GACvF;EACD,UAAU,CAAC,SAAS;EACrB;CACF;AAED,MAAa,qBAAiC;CAC5C,MAAM;CACN,aAAa;CACb,YAAY;EACV,MAAM;EACN,YAAY,EACV,QAAQ;GAAE,MAAM;GAAU,aAAa;GAAsC,EAC9E;EACD,UAAU,CAAC,SAAS;EACrB;CACF;AAED,MAAa,yBAAqC;CAChD,MAAM;CACN,aAAa;CACb,YAAY;EACV,MAAM;EACN,YAAY,EACV,OAAO,EAAE,aAAa,uCAAuC,EAC9D;EACD,UAAU,CAAC,QAAQ;EACpB;CACF;AAED,MAAa,iBAAiB;CAAC;CAAe;CAAoB;CAAuB;;;;AAKzF,eAAsB,gBACpB,MACA,MACA,KACc;AACd,SAAQ,MAAR;EACE,KAAK;AACH,OAAI,CAAC,KAAK,UAAU,OAAO,KAAK,WAAW,SACzC,OAAM,IAAI,MAAM,yDAAyD;AAE3E,UAAO,cAAc,KAAK,QAAkB,KAAK;IAC/C,MAAO,KAAK,QAA+B;IAC3C,YAAa,KAAK,cAAyB;IAC5C,CAAC;EAGJ,KAAK;AACH,OAAI,CAAC,KAAK,UAAU,OAAO,KAAK,WAAW,SACzC,OAAM,IAAI,MAAM,8DAA8D;AAEhF,UAAO,YAAY,KAAK,OAAiB;EAG3C,KAAK,qBAAqB;GACxB,MAAM,QAAQ,KAAK;AACnB,OAAI,gBAAgB,MAAM,CACxB,QAAO,kBAAkB,MAAM;AAEjC,UAAO;IAAE,aAAa,kBAAkB,KAAK,UAAU,MAAM;IAAI,YAAY;IAA4B;;EAG3G,QACE,OAAM,IAAI,MAAM,sBAAsB,OAAO;;;AAInD,SAAS,kBAAkB,OAA0D;AACnF,SAAQ,MAAM,MAAd;EACE,KAAK,eACH,QAAO;GACL,aAAa,iBAAiB,MAAM,QAAQ,wBAAwB,MAAM,UAAU;GACpF,YAAY,MAAM,cAAc;GACjC;EACH,KAAK,oBACH,QAAO;GACL,aAAa,2CAA2C,MAAM,WAAW;GACzE,YAAY;GACb;EACH,KAAK,eACH,QAAO;GACL,aAAa,uBAAuB,MAAM,KAAK,2BAA2B,MAAM,WAAW,KAAK,KAAK,CAAC;GACtG,YAAY;GACb;EACH,KAAK,mBACH,QAAO;GACL,aAAa,4BAA4B,MAAM,MAAM,aAAa,MAAM,SAAS,QAAQ,MAAM,IAAI;GACnG,YAAY;GACb;EACH,KAAK,iBACH,QAAO;GACL,aAAa,2BAA2B,MAAM,OAAO,SAAS,MAAM,KAAK,GAAG,MAAM,MAAM;GACxF,YAAY;GACb;EACH,KAAK,UACH,QAAO;GACL,aAAa,kBAAkB,MAAM,KAAK,aAAa,MAAM,SAAS;GACtE,YAAY;GACb;EACH,KAAK,aACH,QAAO;GACL,aAAa,eAAe,MAAM,UAAU,MAAM,OAAO,YAAY,MAAM,SAAS,GAAG;GACvF,YAAY;GACb;EACH,KAAK,eACH,QAAO;GACL,aAAa,iBAAiB,MAAM,QAAQ;GAC5C,YAAY;GACb;EACH,QACE,QAAO,EAAE,aAAa,UAAU,MAAM,WAAW,KAAK,UAAU,MAAM,IAAI"}
|