@illumiarq/lumis 1.2.8 → 1.2.9
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/README.md +38 -0
- package/dist/adapter-loader.d.ts +67 -0
- package/dist/adapter-loader.d.ts.map +1 -0
- package/dist/adapter-loader.js +273 -0
- package/dist/adapter-loader.js.map +1 -0
- package/dist/cli.d.ts +16 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +173 -402
- package/dist/cli.js.map +1 -1
- package/dist/commands/commands.command.d.ts +38 -0
- package/dist/commands/commands.command.d.ts.map +1 -0
- package/dist/commands/commands.command.js +176 -0
- package/dist/commands/commands.command.js.map +1 -0
- package/dist/commands/doctor.command.d.ts +9 -0
- package/dist/commands/doctor.command.d.ts.map +1 -0
- package/dist/commands/doctor.command.js +640 -0
- package/dist/commands/doctor.command.js.map +1 -0
- package/dist/commands/init.command.d.ts +9 -0
- package/dist/commands/init.command.d.ts.map +1 -0
- package/dist/commands/init.command.js +121 -0
- package/dist/commands/init.command.js.map +1 -0
- package/dist/commands/intent.command.d.ts +26 -0
- package/dist/commands/intent.command.d.ts.map +1 -0
- package/dist/commands/intent.command.js +211 -0
- package/dist/commands/intent.command.js.map +1 -0
- package/dist/commands/ir-rebuild.command.d.ts +9 -0
- package/dist/commands/ir-rebuild.command.d.ts.map +1 -0
- package/dist/commands/ir-rebuild.command.js +36 -0
- package/dist/commands/ir-rebuild.command.js.map +1 -0
- package/dist/commands/ir-show.command.d.ts +9 -0
- package/dist/commands/ir-show.command.d.ts.map +1 -0
- package/dist/commands/ir-show.command.js +32 -0
- package/dist/commands/ir-show.command.js.map +1 -0
- package/dist/commands/make.command.d.ts +9 -0
- package/dist/commands/make.command.d.ts.map +1 -0
- package/dist/commands/make.command.js +93 -0
- package/dist/commands/make.command.js.map +1 -0
- package/dist/commands/pack.command.d.ts +16 -0
- package/dist/commands/pack.command.d.ts.map +1 -0
- package/dist/commands/pack.command.js +44 -0
- package/dist/commands/pack.command.js.map +1 -0
- package/dist/commands/runtime.command.d.ts +6 -0
- package/dist/commands/runtime.command.d.ts.map +1 -0
- package/dist/commands/runtime.command.js +379 -0
- package/dist/commands/runtime.command.js.map +1 -0
- package/dist/commands/runtime.d.ts +45 -0
- package/dist/commands/runtime.d.ts.map +1 -0
- package/dist/commands/runtime.js +66 -0
- package/dist/commands/runtime.js.map +1 -0
- package/dist/commands/tinker-agent-plan.d.ts +26 -0
- package/dist/commands/tinker-agent-plan.d.ts.map +1 -0
- package/dist/commands/tinker-agent-plan.js +115 -0
- package/dist/commands/tinker-agent-plan.js.map +1 -0
- package/dist/commands/tinker-chat-commands.d.ts +19 -0
- package/dist/commands/tinker-chat-commands.d.ts.map +1 -0
- package/dist/commands/tinker-chat-commands.js +263 -0
- package/dist/commands/tinker-chat-commands.js.map +1 -0
- package/dist/commands/tinker-chat-runtime.d.ts +30 -0
- package/dist/commands/tinker-chat-runtime.d.ts.map +1 -0
- package/dist/commands/tinker-chat-runtime.js +227 -0
- package/dist/commands/tinker-chat-runtime.js.map +1 -0
- package/dist/commands/tinker-classic-mode.d.ts +15 -0
- package/dist/commands/tinker-classic-mode.d.ts.map +1 -0
- package/dist/commands/tinker-classic-mode.js +160 -0
- package/dist/commands/tinker-classic-mode.js.map +1 -0
- package/dist/commands/tinker-eval.command.d.ts +3 -0
- package/dist/commands/tinker-eval.command.d.ts.map +1 -0
- package/dist/commands/tinker-eval.command.js +151 -0
- package/dist/commands/tinker-eval.command.js.map +1 -0
- package/dist/commands/tinker-repl-display.d.ts +15 -0
- package/dist/commands/tinker-repl-display.d.ts.map +1 -0
- package/dist/commands/tinker-repl-display.js +147 -0
- package/dist/commands/tinker-repl-display.js.map +1 -0
- package/dist/commands/tinker-session-runtime.d.ts +27 -0
- package/dist/commands/tinker-session-runtime.d.ts.map +1 -0
- package/dist/commands/tinker-session-runtime.js +196 -0
- package/dist/commands/tinker-session-runtime.js.map +1 -0
- package/dist/commands/tinker.command.d.ts +9 -0
- package/dist/commands/tinker.command.d.ts.map +1 -0
- package/dist/commands/tinker.command.js +142 -0
- package/dist/commands/tinker.command.js.map +1 -0
- package/dist/commands/use.command.d.ts +10 -0
- package/dist/commands/use.command.d.ts.map +1 -0
- package/dist/commands/use.command.js +69 -0
- package/dist/commands/use.command.js.map +1 -0
- package/dist/config-loader.d.ts +68 -0
- package/dist/config-loader.d.ts.map +1 -0
- package/dist/config-loader.js +81 -0
- package/dist/config-loader.js.map +1 -0
- package/dist/index.d.ts +19 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -12
- package/dist/index.js.map +1 -1
- package/dist/launcher.d.ts +16 -0
- package/dist/launcher.d.ts.map +1 -0
- package/dist/launcher.js +301 -0
- package/dist/launcher.js.map +1 -0
- package/dist/lib/file-scanner.d.ts +8 -0
- package/dist/lib/file-scanner.d.ts.map +1 -0
- package/dist/lib/file-scanner.js +70 -0
- package/dist/lib/file-scanner.js.map +1 -0
- package/dist/lib/tinker-memory.d.ts +19 -0
- package/dist/lib/tinker-memory.d.ts.map +1 -0
- package/dist/lib/tinker-memory.js +107 -0
- package/dist/lib/tinker-memory.js.map +1 -0
- package/dist/lib/tinker-observer.d.ts +47 -0
- package/dist/lib/tinker-observer.d.ts.map +1 -0
- package/dist/lib/tinker-observer.js +77 -0
- package/dist/lib/tinker-observer.js.map +1 -0
- package/dist/lib/tinker-policy.d.ts +21 -0
- package/dist/lib/tinker-policy.d.ts.map +1 -0
- package/dist/lib/tinker-policy.js +102 -0
- package/dist/lib/tinker-policy.js.map +1 -0
- package/dist/lib/tinker-replay.d.ts +51 -0
- package/dist/lib/tinker-replay.d.ts.map +1 -0
- package/dist/lib/tinker-replay.js +123 -0
- package/dist/lib/tinker-replay.js.map +1 -0
- package/dist/{console.d.ts → output/ansi.d.ts} +4 -8
- package/dist/output/ansi.d.ts.map +1 -0
- package/dist/{console.js → output/ansi.js} +4 -12
- package/dist/output/ansi.js.map +1 -0
- package/dist/output/plan-display.d.ts +4 -0
- package/dist/output/plan-display.d.ts.map +1 -0
- package/dist/output/plan-display.js +49 -0
- package/dist/output/plan-display.js.map +1 -0
- package/dist/output/result-display.d.ts +5 -0
- package/dist/output/result-display.d.ts.map +1 -0
- package/dist/output/result-display.js +17 -0
- package/dist/output/result-display.js.map +1 -0
- package/dist/plugins/tinker-plugin.d.ts +86 -0
- package/dist/plugins/tinker-plugin.d.ts.map +1 -0
- package/dist/plugins/tinker-plugin.js +42 -0
- package/dist/plugins/tinker-plugin.js.map +1 -0
- package/dist/router-preferences.d.ts +5 -0
- package/dist/router-preferences.d.ts.map +1 -0
- package/dist/router-preferences.js +22 -0
- package/dist/router-preferences.js.map +1 -0
- package/dist/runtime/executor.d.ts +33 -0
- package/dist/runtime/executor.d.ts.map +1 -0
- package/dist/runtime/executor.js +180 -0
- package/dist/runtime/executor.js.map +1 -0
- package/dist/runtime/orchestration.d.ts +43 -0
- package/dist/runtime/orchestration.d.ts.map +1 -0
- package/dist/runtime/orchestration.js +209 -0
- package/dist/runtime/orchestration.js.map +1 -0
- package/dist/runtime/policy.d.ts +23 -0
- package/dist/runtime/policy.d.ts.map +1 -0
- package/dist/runtime/policy.js +43 -0
- package/dist/runtime/policy.js.map +1 -0
- package/dist/runtime/profiles.d.ts +15 -0
- package/dist/runtime/profiles.d.ts.map +1 -0
- package/dist/runtime/profiles.js +131 -0
- package/dist/runtime/profiles.js.map +1 -0
- package/dist/runtime/transcripts.d.ts +59 -0
- package/dist/runtime/transcripts.d.ts.map +1 -0
- package/dist/runtime/transcripts.js +172 -0
- package/dist/runtime/transcripts.js.map +1 -0
- package/dist/tools/git-diff.d.ts +3 -0
- package/dist/tools/git-diff.d.ts.map +1 -0
- package/dist/tools/git-diff.js +16 -0
- package/dist/tools/git-diff.js.map +1 -0
- package/dist/tools/index.d.ts +24 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +88 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/lint.d.ts +3 -0
- package/dist/tools/lint.d.ts.map +1 -0
- package/dist/tools/lint.js +35 -0
- package/dist/tools/lint.js.map +1 -0
- package/dist/tools/read-file.d.ts +3 -0
- package/dist/tools/read-file.d.ts.map +1 -0
- package/dist/tools/read-file.js +47 -0
- package/dist/tools/read-file.js.map +1 -0
- package/dist/tools/run-command.d.ts +3 -0
- package/dist/tools/run-command.d.ts.map +1 -0
- package/dist/tools/run-command.js +71 -0
- package/dist/tools/run-command.js.map +1 -0
- package/dist/tools/run-tests.d.ts +3 -0
- package/dist/tools/run-tests.d.ts.map +1 -0
- package/dist/tools/run-tests.js +49 -0
- package/dist/tools/run-tests.js.map +1 -0
- package/dist/tools/tool-dispatch.d.ts +32 -0
- package/dist/tools/tool-dispatch.d.ts.map +1 -0
- package/dist/tools/tool-dispatch.js +120 -0
- package/dist/tools/tool-dispatch.js.map +1 -0
- package/dist/tools/typecheck.d.ts +3 -0
- package/dist/tools/typecheck.d.ts.map +1 -0
- package/dist/tools/typecheck.js +48 -0
- package/dist/tools/typecheck.js.map +1 -0
- package/dist/tools/types.d.ts +62 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +7 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/tools/write-file.d.ts +15 -0
- package/dist/tools/write-file.d.ts.map +1 -0
- package/dist/tools/write-file.js +52 -0
- package/dist/tools/write-file.js.map +1 -0
- package/dist/tracing/types.d.ts +10 -0
- package/dist/tracing/types.d.ts.map +1 -0
- package/dist/tracing/types.js +2 -0
- package/dist/tracing/types.js.map +1 -0
- package/package.json +37 -19
- package/dist/bridges/project-bridge.d.ts +0 -2
- package/dist/bridges/project-bridge.d.ts.map +0 -1
- package/dist/bridges/project-bridge.js +0 -171
- package/dist/bridges/project-bridge.js.map +0 -1
- package/dist/commands/app/cache-workflows.d.ts +0 -7
- package/dist/commands/app/cache-workflows.d.ts.map +0 -1
- package/dist/commands/app/cache-workflows.js +0 -139
- package/dist/commands/app/cache-workflows.js.map +0 -1
- package/dist/commands/app/command-runtime.d.ts +0 -11
- package/dist/commands/app/command-runtime.d.ts.map +0 -1
- package/dist/commands/app/command-runtime.js +0 -41
- package/dist/commands/app/command-runtime.js.map +0 -1
- package/dist/commands/app/config-cache.d.ts +0 -3
- package/dist/commands/app/config-cache.d.ts.map +0 -1
- package/dist/commands/app/config-cache.js +0 -75
- package/dist/commands/app/config-cache.js.map +0 -1
- package/dist/commands/app/config-publish.d.ts +0 -2
- package/dist/commands/app/config-publish.d.ts.map +0 -1
- package/dist/commands/app/config-publish.js +0 -68
- package/dist/commands/app/config-publish.js.map +0 -1
- package/dist/commands/app/config-stubs.d.ts +0 -3
- package/dist/commands/app/config-stubs.d.ts.map +0 -1
- package/dist/commands/app/config-stubs.js +0 -154
- package/dist/commands/app/config-stubs.js.map +0 -1
- package/dist/commands/app/database.d.ts +0 -3
- package/dist/commands/app/database.d.ts.map +0 -1
- package/dist/commands/app/database.js +0 -221
- package/dist/commands/app/database.js.map +0 -1
- package/dist/commands/app/docs.d.ts +0 -7
- package/dist/commands/app/docs.d.ts.map +0 -1
- package/dist/commands/app/docs.js +0 -61
- package/dist/commands/app/docs.js.map +0 -1
- package/dist/commands/app/routes.d.ts +0 -5
- package/dist/commands/app/routes.d.ts.map +0 -1
- package/dist/commands/app/routes.js +0 -95
- package/dist/commands/app/routes.js.map +0 -1
- package/dist/commands/app/security.d.ts +0 -3
- package/dist/commands/app/security.d.ts.map +0 -1
- package/dist/commands/app/security.js +0 -15
- package/dist/commands/app/security.js.map +0 -1
- package/dist/commands/app/worker-schedule.d.ts +0 -5
- package/dist/commands/app/worker-schedule.d.ts.map +0 -1
- package/dist/commands/app/worker-schedule.js +0 -94
- package/dist/commands/app/worker-schedule.js.map +0 -1
- package/dist/commands/app-commands.d.ts +0 -19
- package/dist/commands/app-commands.d.ts.map +0 -1
- package/dist/commands/app-commands.js +0 -77
- package/dist/commands/app-commands.js.map +0 -1
- package/dist/commands/build-vercel-fn.d.ts +0 -9
- package/dist/commands/build-vercel-fn.d.ts.map +0 -1
- package/dist/commands/build-vercel-fn.js +0 -32
- package/dist/commands/build-vercel-fn.js.map +0 -1
- package/dist/commands/build.d.ts +0 -14
- package/dist/commands/build.d.ts.map +0 -1
- package/dist/commands/build.js +0 -24
- package/dist/commands/build.js.map +0 -1
- package/dist/commands/info.d.ts +0 -2
- package/dist/commands/info.d.ts.map +0 -1
- package/dist/commands/info.js +0 -25
- package/dist/commands/info.js.map +0 -1
- package/dist/commands/keys.d.ts +0 -3
- package/dist/commands/keys.d.ts.map +0 -1
- package/dist/commands/keys.js +0 -60
- package/dist/commands/keys.js.map +0 -1
- package/dist/commands/maintenance.d.ts +0 -9
- package/dist/commands/maintenance.d.ts.map +0 -1
- package/dist/commands/maintenance.js +0 -38
- package/dist/commands/maintenance.js.map +0 -1
- package/dist/commands/module-list.d.ts +0 -2
- package/dist/commands/module-list.d.ts.map +0 -1
- package/dist/commands/module-list.js +0 -27
- package/dist/commands/module-list.js.map +0 -1
- package/dist/commands/preview.d.ts +0 -14
- package/dist/commands/preview.d.ts.map +0 -1
- package/dist/commands/preview.js +0 -49
- package/dist/commands/preview.js.map +0 -1
- package/dist/commands/serve.d.ts +0 -16
- package/dist/commands/serve.d.ts.map +0 -1
- package/dist/commands/serve.js +0 -61
- package/dist/commands/serve.js.map +0 -1
- package/dist/console.d.ts.map +0 -1
- package/dist/console.js.map +0 -1
- package/dist/paths.d.ts +0 -21
- package/dist/paths.d.ts.map +0 -1
- package/dist/paths.js +0 -47
- package/dist/paths.js.map +0 -1
- package/dist/server-wrapper.d.ts +0 -12
- package/dist/server-wrapper.d.ts.map +0 -1
- package/dist/server-wrapper.js +0 -63
- package/dist/server-wrapper.js.map +0 -1
- package/dist/vercel-wrapper.d.ts +0 -6
- package/dist/vercel-wrapper.d.ts.map +0 -1
- package/dist/vercel-wrapper.js +0 -50
- package/dist/vercel-wrapper.js.map +0 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
const MAX_BYTES = 250_000;
|
|
4
|
+
export async function readFileTool(filePath, projectRoot) {
|
|
5
|
+
const start = Date.now();
|
|
6
|
+
const absolute = path.isAbsolute(filePath) ? filePath : path.join(projectRoot, filePath);
|
|
7
|
+
try {
|
|
8
|
+
const stat = await fs.stat(absolute);
|
|
9
|
+
if (!stat.isFile()) {
|
|
10
|
+
return {
|
|
11
|
+
tool: 'read-file',
|
|
12
|
+
outcome: 'failure',
|
|
13
|
+
output: '',
|
|
14
|
+
error: `Not a file: ${filePath}`,
|
|
15
|
+
durationMs: Date.now() - start,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
if (stat.size > MAX_BYTES) {
|
|
19
|
+
return {
|
|
20
|
+
tool: 'read-file',
|
|
21
|
+
outcome: 'failure',
|
|
22
|
+
output: '',
|
|
23
|
+
error: `File too large (${stat.size} bytes, max ${MAX_BYTES})`,
|
|
24
|
+
durationMs: Date.now() - start,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const content = await fs.readFile(absolute, 'utf8');
|
|
28
|
+
const lines = content.split('\n');
|
|
29
|
+
const numbered = lines.map((line, i) => `${String(i + 1).padStart(4, ' ')} ${line}`).join('\n');
|
|
30
|
+
return {
|
|
31
|
+
tool: 'read-file',
|
|
32
|
+
outcome: 'success',
|
|
33
|
+
output: numbered,
|
|
34
|
+
durationMs: Date.now() - start,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
return {
|
|
39
|
+
tool: 'read-file',
|
|
40
|
+
outcome: 'failure',
|
|
41
|
+
output: '',
|
|
42
|
+
error: error instanceof Error ? error.message : String(error),
|
|
43
|
+
durationMs: Date.now() - start,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=read-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-file.js","sourceRoot":"","sources":["../../src/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,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAEhG,OAAO;YACN,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,SAAS;YAClB,MAAM,EAAE,QAAQ;YAChB,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;SAC9B,CAAA;IACF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO;YACN,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,SAAS;YAClB,MAAM,EAAE,EAAE;YACV,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;YAC7D,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;SAC9B,CAAA;IACF,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-command.d.ts","sourceRoot":"","sources":["../../src/tools/run-command.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAK5C,wBAAsB,cAAc,CACnC,GAAG,EAAE,MAAM,EAAE,EACb,GAAG,EAAE,MAAM,EACX,SAAS,SAAqB,GAC5B,OAAO,CAAC,UAAU,CAAC,CA6ErB"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
3
|
+
const MAX_OUTPUT_CHARS = 40_000;
|
|
4
|
+
export async function runCommandTool(cmd, cwd, timeoutMs = DEFAULT_TIMEOUT_MS) {
|
|
5
|
+
const start = Date.now();
|
|
6
|
+
if (cmd.length === 0) {
|
|
7
|
+
return { tool: 'run-command', outcome: 'failure', output: '', error: 'Empty command array', durationMs: 0 };
|
|
8
|
+
}
|
|
9
|
+
const executable = cmd[0];
|
|
10
|
+
const args = cmd.slice(1);
|
|
11
|
+
return new Promise((resolve) => {
|
|
12
|
+
const chunks = [];
|
|
13
|
+
let timedOut = false;
|
|
14
|
+
const child = spawn(executable, args, {
|
|
15
|
+
cwd,
|
|
16
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
17
|
+
shell: false,
|
|
18
|
+
});
|
|
19
|
+
const timer = setTimeout(() => {
|
|
20
|
+
timedOut = true;
|
|
21
|
+
child.kill('SIGTERM');
|
|
22
|
+
}, timeoutMs);
|
|
23
|
+
const onData = (data) => {
|
|
24
|
+
const text = data.toString();
|
|
25
|
+
chunks.push(text);
|
|
26
|
+
// Truncate live to avoid holding huge buffers
|
|
27
|
+
const total = chunks.reduce((acc, c) => acc + c.length, 0);
|
|
28
|
+
if (total > MAX_OUTPUT_CHARS * 2) {
|
|
29
|
+
chunks.splice(0, Math.floor(chunks.length / 2));
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
child.stdout?.on('data', onData);
|
|
33
|
+
child.stderr?.on('data', onData);
|
|
34
|
+
child.on('close', (code) => {
|
|
35
|
+
clearTimeout(timer);
|
|
36
|
+
const rawOutput = chunks.join('');
|
|
37
|
+
const output = rawOutput.length > MAX_OUTPUT_CHARS
|
|
38
|
+
? rawOutput.slice(-MAX_OUTPUT_CHARS) + `\n... (truncated, kept last ${MAX_OUTPUT_CHARS} chars)`
|
|
39
|
+
: rawOutput;
|
|
40
|
+
const durationMs = Date.now() - start;
|
|
41
|
+
if (timedOut) {
|
|
42
|
+
resolve({
|
|
43
|
+
tool: 'run-command',
|
|
44
|
+
outcome: 'failure',
|
|
45
|
+
output,
|
|
46
|
+
error: `Command timed out after ${timeoutMs}ms`,
|
|
47
|
+
durationMs,
|
|
48
|
+
});
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
resolve({
|
|
52
|
+
tool: 'run-command',
|
|
53
|
+
outcome: code === 0 ? 'success' : 'failure',
|
|
54
|
+
output,
|
|
55
|
+
...(code !== 0 ? { error: `Exit code ${code ?? 'null'}` } : {}),
|
|
56
|
+
durationMs,
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
child.on('error', (err) => {
|
|
60
|
+
clearTimeout(timer);
|
|
61
|
+
resolve({
|
|
62
|
+
tool: 'run-command',
|
|
63
|
+
outcome: 'failure',
|
|
64
|
+
output: '',
|
|
65
|
+
error: err.message,
|
|
66
|
+
durationMs: Date.now() - start,
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=run-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-command.js","sourceRoot":"","sources":["../../src/tools/run-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAG1C,MAAM,kBAAkB,GAAG,MAAM,CAAA;AACjC,MAAM,gBAAgB,GAAG,MAAM,CAAA;AAE/B,MAAM,CAAC,KAAK,UAAU,cAAc,CACnC,GAAa,EACb,GAAW,EACX,SAAS,GAAG,kBAAkB;IAE9B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IAExB,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,qBAAqB,EAAE,UAAU,EAAE,CAAC,EAAE,CAAA;IAC5G,CAAC;IAED,MAAM,UAAU,GAAG,GAAG,CAAC,CAAC,CAAE,CAAA;IAC1B,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAEzB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE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sourceRoot":"","sources":["../../src/tools/run-tests.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAc,UAAU,EAAE,MAAM,YAAY,CAAA;AAqCxD,wBAAsB,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAgB7F"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { runCommandTool } from './run-command.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parse vitest/jest output lines into Diagnostic[].
|
|
4
|
+
* Captures FAIL file lines and lines like:
|
|
5
|
+
* ✗ test description (AssertionError)
|
|
6
|
+
* × test description
|
|
7
|
+
* ● test description
|
|
8
|
+
*/
|
|
9
|
+
function parseTestOutput(output) {
|
|
10
|
+
const diagnostics = [];
|
|
11
|
+
// Lines starting with FAIL or failing test markers
|
|
12
|
+
const failFileRegex = /^(FAIL|ERR!)\s+(.+)$/gm;
|
|
13
|
+
let match;
|
|
14
|
+
while ((match = failFileRegex.exec(output)) !== null) {
|
|
15
|
+
const [, , file] = match;
|
|
16
|
+
if (!file)
|
|
17
|
+
continue;
|
|
18
|
+
diagnostics.push({
|
|
19
|
+
severity: 'error',
|
|
20
|
+
file: file.trim(),
|
|
21
|
+
message: `Test file failed: ${file.trim()}`,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
// Vitest × or jest ●
|
|
25
|
+
const failTestRegex = /^\s+[×●✗]\s+(.+)$/gm;
|
|
26
|
+
while ((match = failTestRegex.exec(output)) !== null) {
|
|
27
|
+
const [, message] = match;
|
|
28
|
+
if (!message)
|
|
29
|
+
continue;
|
|
30
|
+
diagnostics.push({ severity: 'error', message: message.trim() });
|
|
31
|
+
}
|
|
32
|
+
return diagnostics;
|
|
33
|
+
}
|
|
34
|
+
export async function runTestsTool(projectRoot, pattern) {
|
|
35
|
+
const cmd = pattern
|
|
36
|
+
? ['pnpm', 'test', '--', '--reporter=verbose', pattern]
|
|
37
|
+
: ['pnpm', 'test', '--', '--reporter=verbose'];
|
|
38
|
+
const result = await runCommandTool(cmd, projectRoot, 120_000);
|
|
39
|
+
const diagnostics = parseTestOutput(result.output);
|
|
40
|
+
return {
|
|
41
|
+
...result,
|
|
42
|
+
tool: 'run-tests',
|
|
43
|
+
output: result.output.length > 12000
|
|
44
|
+
? result.output.slice(-12000) + '\n... (output truncated)'
|
|
45
|
+
: result.output,
|
|
46
|
+
diagnostics,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=run-tests.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-tests.js","sourceRoot":"","sources":["../../src/tools/run-tests.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAGjD;;;;;;GAMG;AACH,SAAS,eAAe,CAAC,MAAc;IACtC,MAAM,WAAW,GAAiB,EAAE,CAAA;IAEpC,mDAAmD;IACnD,MAAM,aAAa,GAAG,wBAAwB,CAAA;IAC9C,IAAI,KAA6B,CAAA;IAEjC,OAAO,CAAC,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QACtD,MAAM,CAAC,EAAE,AAAD,EAAG,IAAI,CAAC,GAAG,KAAK,CAAA;QACxB,IAAI,CAAC,IAAI;YAAE,SAAQ;QACnB,WAAW,CAAC,IAAI,CAAC;YAChB,QAAQ,EAAE,OAAO;YACjB,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE;YACjB,OAAO,EAAE,qBAAqB,IAAI,CAAC,IAAI,EAAE,EAAE;SAC3C,CAAC,CAAA;IACH,CAAC;IAED,qBAAqB;IACrB,MAAM,aAAa,GAAG,qBAAqB,CAAA;IAC3C,OAAO,CAAC,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QACtD,MAAM,CAAC,EAAE,OAAO,CAAC,GAAG,KAAK,CAAA;QACzB,IAAI,CAAC,OAAO;YAAE,SAAQ;QACtB,WAAW,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;IACjE,CAAC;IAED,OAAO,WAAW,CAAA;AACnB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,WAAmB,EAAE,OAAgB;IACvE,MAAM,GAAG,GAAG,OAAO;QAClB,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,EAAE,OAAO,CAAC;QACvD,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,CAAC,CAAA;IAE/C,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,GAAG,EAAE,WAAW,EAAE,OAAO,CAAC,CAAA;IAC9D,MAAM,WAAW,GAAG,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAElD,OAAO;QACN,GAAG,MAAM;QACT,IAAI,EAAE,WAAW;QACjB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,KAAK;YACnC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,GAAG,0BAA0B;YAC1D,CAAC,CAAC,MAAM,CAAC,MAAM;QAChB,WAAW;KACX,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 5: LLM Tool-Call Dispatch
|
|
3
|
+
*
|
|
4
|
+
* The AI is instructed to emit tool calls as fenced JSON blocks:
|
|
5
|
+
* ```tool_call
|
|
6
|
+
* { "tool": "read-file", "path": "src/foo.ts" }
|
|
7
|
+
* ```
|
|
8
|
+
* This module parses those blocks, executes the calls, and formats
|
|
9
|
+
* the results for injection back into the message stream.
|
|
10
|
+
*/
|
|
11
|
+
import type { ToolCall, ToolResult } from './types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Extract all tool_call fenced blocks from an LLM reply text.
|
|
14
|
+
* Returns the parsed ToolCall objects (invalid JSON blocks are skipped).
|
|
15
|
+
*/
|
|
16
|
+
export declare function extractToolCalls(text: string): ToolCall[];
|
|
17
|
+
/**
|
|
18
|
+
* Format a ToolResult as a `tool` role message content block.
|
|
19
|
+
* The LLM sees this verbatim to continue reasoning.
|
|
20
|
+
*/
|
|
21
|
+
export declare function formatToolResult(result: ToolResult): string;
|
|
22
|
+
/**
|
|
23
|
+
* Strip tool_call fences from LLM reply text so only the
|
|
24
|
+
* conversational prose is shown to the user.
|
|
25
|
+
*/
|
|
26
|
+
export declare function stripToolCalls(text: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Build the tool-call capability section for the Tinker system prompt.
|
|
29
|
+
* Describes available tools and their JSON schemas.
|
|
30
|
+
*/
|
|
31
|
+
export declare const TOOL_CALL_SYSTEM_SECTION: string;
|
|
32
|
+
//# sourceMappingURL=tool-dispatch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-dispatch.d.ts","sourceRoot":"","sources":["../../src/tools/tool-dispatch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAItD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,EAAE,CAkBzD;AA4CD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAc3D;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;GAGG;AACH,eAAO,MAAM,wBAAwB,QAsB7B,CAAA"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
const TOOL_CALL_FENCE_RE = /```tool_call\s*\n([\s\S]*?)```/g;
|
|
2
|
+
/**
|
|
3
|
+
* Extract all tool_call fenced blocks from an LLM reply text.
|
|
4
|
+
* Returns the parsed ToolCall objects (invalid JSON blocks are skipped).
|
|
5
|
+
*/
|
|
6
|
+
export function extractToolCalls(text) {
|
|
7
|
+
const calls = [];
|
|
8
|
+
let match;
|
|
9
|
+
// Reset lastIndex for each invocation
|
|
10
|
+
TOOL_CALL_FENCE_RE.lastIndex = 0;
|
|
11
|
+
while ((match = TOOL_CALL_FENCE_RE.exec(text)) !== null) {
|
|
12
|
+
const raw = match[1]?.trim();
|
|
13
|
+
if (!raw)
|
|
14
|
+
continue;
|
|
15
|
+
try {
|
|
16
|
+
const parsed = JSON.parse(raw);
|
|
17
|
+
if (isValidToolCall(parsed)) {
|
|
18
|
+
calls.push(parsed);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// Skip malformed JSON
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return calls;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Narrow an unknown value to a ToolCall.
|
|
29
|
+
*/
|
|
30
|
+
function isValidToolCall(value) {
|
|
31
|
+
if (typeof value !== 'object' || value === null)
|
|
32
|
+
return false;
|
|
33
|
+
const v = value;
|
|
34
|
+
const tool = v['tool'];
|
|
35
|
+
if (typeof tool !== 'string')
|
|
36
|
+
return false;
|
|
37
|
+
const validTools = new Set([
|
|
38
|
+
'read-file',
|
|
39
|
+
'write-file',
|
|
40
|
+
'run-command',
|
|
41
|
+
'search-repo',
|
|
42
|
+
'git-diff',
|
|
43
|
+
'typecheck',
|
|
44
|
+
'run-tests',
|
|
45
|
+
'lint',
|
|
46
|
+
]);
|
|
47
|
+
if (!validTools.has(tool))
|
|
48
|
+
return false;
|
|
49
|
+
// Minimal required field checks per tool
|
|
50
|
+
switch (tool) {
|
|
51
|
+
case 'read-file':
|
|
52
|
+
return typeof v['path'] === 'string';
|
|
53
|
+
case 'write-file':
|
|
54
|
+
return typeof v['path'] === 'string' && typeof v['content'] === 'string';
|
|
55
|
+
case 'run-command':
|
|
56
|
+
return Array.isArray(v['cmd']) && v['cmd'].every((c) => typeof c === 'string');
|
|
57
|
+
case 'search-repo':
|
|
58
|
+
return typeof v['query'] === 'string';
|
|
59
|
+
case 'git-diff':
|
|
60
|
+
case 'typecheck':
|
|
61
|
+
case 'run-tests':
|
|
62
|
+
case 'lint':
|
|
63
|
+
return true;
|
|
64
|
+
default:
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Format a ToolResult as a `tool` role message content block.
|
|
70
|
+
* The LLM sees this verbatim to continue reasoning.
|
|
71
|
+
*/
|
|
72
|
+
export function formatToolResult(result) {
|
|
73
|
+
const header = `[tool:${result.tool} outcome:${result.outcome} ${result.durationMs}ms]`;
|
|
74
|
+
const body = result.output.length > 6000
|
|
75
|
+
? result.output.slice(0, 6000) + '\n... (truncated)'
|
|
76
|
+
: result.output;
|
|
77
|
+
const errorPart = result.error ? `\nError: ${result.error}` : '';
|
|
78
|
+
const diagPart = result.diagnostics && result.diagnostics.length > 0
|
|
79
|
+
? '\n' + result.diagnostics
|
|
80
|
+
.slice(0, 20)
|
|
81
|
+
.map((d) => ` ${d.severity} ${d.file ? `${d.file}${d.line ? `:${d.line}` : ''}` : ''}: ${d.message}`)
|
|
82
|
+
.join('\n')
|
|
83
|
+
: '';
|
|
84
|
+
return `${header}\n${body}${errorPart}${diagPart}`;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Strip tool_call fences from LLM reply text so only the
|
|
88
|
+
* conversational prose is shown to the user.
|
|
89
|
+
*/
|
|
90
|
+
export function stripToolCalls(text) {
|
|
91
|
+
return text.replace(TOOL_CALL_FENCE_RE, '').replace(/\n{3,}/g, '\n\n').trim();
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Build the tool-call capability section for the Tinker system prompt.
|
|
95
|
+
* Describes available tools and their JSON schemas.
|
|
96
|
+
*/
|
|
97
|
+
export const TOOL_CALL_SYSTEM_SECTION = `
|
|
98
|
+
You have access to the following tools. When you need information or want to perform an action, emit a tool_call block:
|
|
99
|
+
\`\`\`tool_call
|
|
100
|
+
{ "tool": "<tool-name>", ...args }
|
|
101
|
+
\`\`\`
|
|
102
|
+
|
|
103
|
+
Available tools and their argument shapes:
|
|
104
|
+
- read-file { "tool": "read-file", "path": "<relative-path>" }
|
|
105
|
+
- write-file { "tool": "write-file", "path": "<relative-path>", "content": "<full-file-content>" }
|
|
106
|
+
- run-command { "tool": "run-command", "cmd": ["<executable>", "...args"], "cwd"?: "<dir>", "timeoutMs"?: 30000 }
|
|
107
|
+
- search-repo { "tool": "search-repo", "query": "<text>", "fileGlob"?: "*.ts", "maxResults"?: 20 }
|
|
108
|
+
- git-diff { "tool": "git-diff", "base"?: "<ref>", "path"?: "<file>" }
|
|
109
|
+
- typecheck { "tool": "typecheck", "cwd"?: "<dir>" }
|
|
110
|
+
- run-tests { "tool": "run-tests", "pattern"?: "<glob>", "cwd"?: "<dir>" }
|
|
111
|
+
- lint { "tool": "lint", "fix"?: true, "paths"?: ["<dir>"], "cwd"?: "<dir>" }
|
|
112
|
+
|
|
113
|
+
Rules:
|
|
114
|
+
1. Emit at most ONE tool_call block per reply.
|
|
115
|
+
2. After receiving tool results, continue reasoning or emit another tool_call.
|
|
116
|
+
3. When all needed information is gathered or all changes are made, reply with your final answer — no tool_call block.
|
|
117
|
+
4. ALWAYS typecheck after writing files.
|
|
118
|
+
5. For write-file, provide the COMPLETE new file content — never partial diffs.
|
|
119
|
+
`.trim();
|
|
120
|
+
//# sourceMappingURL=tool-dispatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-dispatch.js","sourceRoot":"","sources":["../../src/tools/tool-dispatch.ts"],"names":[],"mappings":"AAYA,MAAM,kBAAkB,GAAG,iCAAiC,CAAA;AAE5D;;;GAGG;AACH,MAAM,UAAU,gBAAg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AW;aACzB,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;aACZ,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;aACrG,IAAI,CAAC,IAAI,CAAC;QACZ,CAAC,CAAC,EAAE,CAAA;IAEL,OAAO,GAAG,MAAM,KAAK,IAAI,GAAG,SAAS,GAAG,QAAQ,EAAE,CAAA;AACnD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IAC1C,OAAO,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAA;AAC9E,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG;;;;;;;;;;;;;;;;;;;;;;CAsBvC,CAAC,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typecheck.d.ts","sourceRoot":"","sources":["../../src/tools/typecheck.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAc,UAAU,EAAE,MAAM,YAAY,CAAA;AA6BxD,wBAAsB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAwB5E"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { runCommandTool } from './run-command.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parse tsc --noEmit output into structured Diagnostic[].
|
|
4
|
+
* Handles the standard `file(line,col): error/warning TSxxxx: message` format.
|
|
5
|
+
*/
|
|
6
|
+
function parseTscOutput(output) {
|
|
7
|
+
const diagnostics = [];
|
|
8
|
+
// e.g.: src/foo.ts(10,5): error TS2322: Type 'string' is not assignable to type 'number'.
|
|
9
|
+
const lineRegex = /^(.+?)\((\d+),(\d+)\):\s+(error|warning|info)\s+(TS\d+):\s+(.+)$/gm;
|
|
10
|
+
let match;
|
|
11
|
+
while ((match = lineRegex.exec(output)) !== null) {
|
|
12
|
+
const [, file, line, column, severity, code, message] = match;
|
|
13
|
+
if (!file || !line || !column || !severity || !message)
|
|
14
|
+
continue;
|
|
15
|
+
diagnostics.push({
|
|
16
|
+
severity: severity,
|
|
17
|
+
file: file.trim(),
|
|
18
|
+
line: parseInt(line, 10),
|
|
19
|
+
column: parseInt(column, 10),
|
|
20
|
+
message: message.trim(),
|
|
21
|
+
...(code ? { code } : {}),
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return diagnostics;
|
|
25
|
+
}
|
|
26
|
+
export async function typecheckTool(projectRoot) {
|
|
27
|
+
const result = await runCommandTool(['pnpm', 'typecheck'], projectRoot, 60_000);
|
|
28
|
+
const diagnostics = parseTscOutput(result.output);
|
|
29
|
+
const errorCount = diagnostics.filter((d) => d.severity === 'error').length;
|
|
30
|
+
const warnCount = diagnostics.filter((d) => d.severity === 'warning').length;
|
|
31
|
+
const summary = [
|
|
32
|
+
result.outcome === 'success' ? 'Typecheck passed.' : `Typecheck failed.`,
|
|
33
|
+
errorCount > 0 ? `${errorCount} error(s).` : '',
|
|
34
|
+
warnCount > 0 ? `${warnCount} warning(s).` : '',
|
|
35
|
+
]
|
|
36
|
+
.filter(Boolean)
|
|
37
|
+
.join(' ');
|
|
38
|
+
return {
|
|
39
|
+
...result,
|
|
40
|
+
tool: 'typecheck',
|
|
41
|
+
output: result.output.length > 8000
|
|
42
|
+
? result.output.slice(-8000) + '\n... (output truncated)'
|
|
43
|
+
: result.output,
|
|
44
|
+
diagnostics,
|
|
45
|
+
...(result.error ? { error: result.error + '\n' + summary } : {}),
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
|
+
* All tools are synchronous or async file-safe operations only.
|
|
4
|
+
* No network calls, no spawning shells without the run-command tool.
|
|
5
|
+
*/
|
|
6
|
+
export type ToolCallType = 'read-file' | 'write-file' | 'run-command' | 'search-repo' | 'git-diff' | 'typecheck' | 'run-tests' | 'lint';
|
|
7
|
+
export type ToolCall = {
|
|
8
|
+
tool: 'read-file';
|
|
9
|
+
path: string;
|
|
10
|
+
} | {
|
|
11
|
+
tool: 'write-file';
|
|
12
|
+
path: string;
|
|
13
|
+
content: string;
|
|
14
|
+
} | {
|
|
15
|
+
tool: 'run-command';
|
|
16
|
+
cmd: string[];
|
|
17
|
+
cwd?: string;
|
|
18
|
+
timeoutMs?: number;
|
|
19
|
+
} | {
|
|
20
|
+
tool: 'search-repo';
|
|
21
|
+
query: string;
|
|
22
|
+
fileGlob?: string;
|
|
23
|
+
maxResults?: number;
|
|
24
|
+
} | {
|
|
25
|
+
tool: 'git-diff';
|
|
26
|
+
base?: string;
|
|
27
|
+
path?: string;
|
|
28
|
+
} | {
|
|
29
|
+
tool: 'typecheck';
|
|
30
|
+
cwd?: string;
|
|
31
|
+
} | {
|
|
32
|
+
tool: 'run-tests';
|
|
33
|
+
pattern?: string;
|
|
34
|
+
cwd?: string;
|
|
35
|
+
} | {
|
|
36
|
+
tool: 'lint';
|
|
37
|
+
fix?: boolean;
|
|
38
|
+
paths?: string[];
|
|
39
|
+
cwd?: string;
|
|
40
|
+
};
|
|
41
|
+
export type ToolOutcome = 'success' | 'failure' | 'skipped';
|
|
42
|
+
export type ToolResult = {
|
|
43
|
+
tool: ToolCallType;
|
|
44
|
+
outcome: ToolOutcome;
|
|
45
|
+
output: string;
|
|
46
|
+
/** Non-empty when outcome is 'failure'. */
|
|
47
|
+
error?: string;
|
|
48
|
+
/** Structured diagnostics (compile errors, lint warnings, test failures). */
|
|
49
|
+
diagnostics?: Diagnostic[];
|
|
50
|
+
/** Wall-clock milliseconds. */
|
|
51
|
+
durationMs: number;
|
|
52
|
+
};
|
|
53
|
+
export type DiagnosticSeverity = 'error' | 'warning' | 'info';
|
|
54
|
+
export type Diagnostic = {
|
|
55
|
+
severity: DiagnosticSeverity;
|
|
56
|
+
file?: string;
|
|
57
|
+
line?: number;
|
|
58
|
+
column?: number;
|
|
59
|
+
message: string;
|
|
60
|
+
code?: string;
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,YAAY,GACrB,WAAW,GACX,YAAY,GACZ,aAAa,GACb,aAAa,GACb,UAAU,GACV,WAAW,GACX,WAAW,GACX,MAAM,CAAA;AAET,MAAM,MAAM,QAAQ,GACjB;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,GAAG,EAAE,MAAM,EAAE,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GACxE;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GAC9E;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAElE,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;AAE3D,MAAM,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,YAAY,CAAA;IAClB,OAAO,EAAE,WAAW,CAAA;IACpB,MAAM,EAAE,MAAM,CAAA;IACd,2CAA2C;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,6EAA6E;IAC7E,WAAW,CAAC,EAAE,UAAU,EAAE,CAAA;IAC1B,+BAA+B;IAC/B,UAAU,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAA;AAE7D,MAAM,MAAM,UAAU,GAAG;IACxB,QAAQ,EAAE,kBAAkB,CAAA;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;CACb,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ToolResult } from './types.js';
|
|
2
|
+
export type WriteRecord = {
|
|
3
|
+
path: string;
|
|
4
|
+
previousContent: string | null;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Write `content` to `filePath` (relative to projectRoot or absolute).
|
|
8
|
+
* Captures original content for rollback via the returned WriteRecord.
|
|
9
|
+
*/
|
|
10
|
+
export declare function writeFileTool(filePath: string, content: string, projectRoot: string, writeLog: WriteRecord[]): Promise<ToolResult>;
|
|
11
|
+
/**
|
|
12
|
+
* Undo the last write captured by writeLog.
|
|
13
|
+
*/
|
|
14
|
+
export declare function rollbackLastWrite(writeLog: WriteRecord[]): Promise<string | null>;
|
|
15
|
+
//# sourceMappingURL=write-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-file.d.ts","sourceRoot":"","sources":["../../src/tools/write-file.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C,MAAM,MAAM,WAAW,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAA;AAE1E;;;GAGG;AACH,wBAAsB,aAAa,CAClC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,WAAW,EAAE,GACrB,OAAO,CAAC,UAAU,CAAC,CAgCrB;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAWvF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Write `content` to `filePath` (relative to projectRoot or absolute).
|
|
5
|
+
* Captures original content for rollback via the returned WriteRecord.
|
|
6
|
+
*/
|
|
7
|
+
export async function writeFileTool(filePath, content, projectRoot, writeLog) {
|
|
8
|
+
const start = Date.now();
|
|
9
|
+
const absolute = path.isAbsolute(filePath) ? filePath : path.join(projectRoot, filePath);
|
|
10
|
+
try {
|
|
11
|
+
let previousContent = null;
|
|
12
|
+
try {
|
|
13
|
+
previousContent = await fs.readFile(absolute, 'utf8');
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
// File does not exist yet — previousContent stays null
|
|
17
|
+
}
|
|
18
|
+
await fs.mkdir(path.dirname(absolute), { recursive: true });
|
|
19
|
+
await fs.writeFile(absolute, content, 'utf8');
|
|
20
|
+
writeLog.push({ path: absolute, previousContent });
|
|
21
|
+
return {
|
|
22
|
+
tool: 'write-file',
|
|
23
|
+
outcome: 'success',
|
|
24
|
+
output: `Wrote ${content.length} chars to ${filePath}`,
|
|
25
|
+
durationMs: Date.now() - start,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
return {
|
|
30
|
+
tool: 'write-file',
|
|
31
|
+
outcome: 'failure',
|
|
32
|
+
output: '',
|
|
33
|
+
error: error instanceof Error ? error.message : String(error),
|
|
34
|
+
durationMs: Date.now() - start,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Undo the last write captured by writeLog.
|
|
40
|
+
*/
|
|
41
|
+
export async function rollbackLastWrite(writeLog) {
|
|
42
|
+
const record = writeLog.pop();
|
|
43
|
+
if (!record)
|
|
44
|
+
return null;
|
|
45
|
+
if (record.previousContent === null) {
|
|
46
|
+
await fs.unlink(record.path);
|
|
47
|
+
return `Deleted new file: ${record.path}`;
|
|
48
|
+
}
|
|
49
|
+
await fs.writeFile(record.path, record.previousContent, 'utf8');
|
|
50
|
+
return `Restored: ${record.path}`;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=write-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-file.js","sourceRoot":"","sources":["../../src/tools/write-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAA;AACjC,OAAO,IAAI,MAAM,WAAW,CAAA;AAK5B;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAClC,QAAgB,EAChB,OAAe,EACf,WAA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AC;AACF,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,QAAuB;IAC9D,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAA;IAC7B,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAExB,IAAI,MAAM,CAAC,eAAe,KAAK,IAAI,EAAE,CAAC;QACrC,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAC5B,OAAO,qBAAqB,MAAM,CAAC,IAAI,EAAE,CAAA;IAC1C,CAAC;IAED,MAAM,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,CAAA;IAC/D,OAAO,aAAa,MAAM,CAAC,IAAI,EAAE,CAAA;AAClC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type LumisTraceStatus = 'start' | 'success' | 'failure' | 'info';
|
|
2
|
+
export type LumisTraceEvent = {
|
|
3
|
+
type: 'config-load' | 'command-dispatch' | 'plan-execution' | 'runtime-task';
|
|
4
|
+
status: LumisTraceStatus;
|
|
5
|
+
name: string;
|
|
6
|
+
message?: string;
|
|
7
|
+
context?: Record<string, unknown>;
|
|
8
|
+
};
|
|
9
|
+
export type LumisTraceListener = (event: LumisTraceEvent) => void | Promise<void>;
|
|
10
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tracing/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,CAAA;AAEvE,MAAM,MAAM,eAAe,GAAG;IAC7B,IAAI,EAAE,aAAa,GAAG,kBAAkB,GAAG,gBAAgB,GAAG,cAAc,CAAA;IAC5E,MAAM,EAAE,gBAAgB,CAAA;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACjC,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tracing/types.ts"],"names":[],"mappings":""}
|