@slashfi/agents-sdk 0.69.8 → 0.69.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/dist/adk-check.d.ts +2 -6
- package/dist/adk-check.d.ts.map +1 -1
- package/dist/adk-check.js +37 -72
- package/dist/adk-check.js.map +1 -1
- package/dist/cjs/adk-check.js +35 -70
- package/dist/cjs/adk-check.js.map +1 -1
- package/package.json +1 -1
- package/src/adk-check.ts +40 -80
package/dist/adk-check.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* adk check / adk run
|
|
3
3
|
*
|
|
4
4
|
* Type-checks (and optionally runs) TypeScript files with auto-injected
|
|
5
|
-
* ADK agent type augmentation.
|
|
6
|
-
*
|
|
5
|
+
* ADK agent type augmentation. Writes a temp file next to the original
|
|
6
|
+
* so module resolution works naturally from node_modules.
|
|
7
7
|
*
|
|
8
8
|
* Usage:
|
|
9
9
|
* adk check <file> Type-check a file
|
|
@@ -12,13 +12,9 @@
|
|
|
12
12
|
* adk run -e "<code>" Type-check + execute inline code
|
|
13
13
|
*/
|
|
14
14
|
export interface CheckOptions {
|
|
15
|
-
/** File to check, or undefined if using inline code */
|
|
16
15
|
file?: string;
|
|
17
|
-
/** Inline code (-e flag) */
|
|
18
16
|
code?: string;
|
|
19
|
-
/** Also execute after type-check (adk run) */
|
|
20
17
|
run?: boolean;
|
|
21
|
-
/** ADK config dir (default: ~/.adk) */
|
|
22
18
|
configDir?: string;
|
|
23
19
|
}
|
|
24
20
|
export declare function adkCheck(opts: CheckOptions): Promise<{
|
package/dist/adk-check.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adk-check.d.ts","sourceRoot":"","sources":["../src/adk-check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;
|
|
1
|
+
{"version":3,"file":"adk-check.d.ts","sourceRoot":"","sources":["../src/adk-check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAOH,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAsB,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAqE7F"}
|
package/dist/adk-check.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* adk check / adk run
|
|
3
3
|
*
|
|
4
4
|
* Type-checks (and optionally runs) TypeScript files with auto-injected
|
|
5
|
-
* ADK agent type augmentation.
|
|
6
|
-
*
|
|
5
|
+
* ADK agent type augmentation. Writes a temp file next to the original
|
|
6
|
+
* so module resolution works naturally from node_modules.
|
|
7
7
|
*
|
|
8
8
|
* Usage:
|
|
9
9
|
* adk check <file> Type-check a file
|
|
@@ -11,10 +11,9 @@
|
|
|
11
11
|
* adk run <file> Type-check + execute
|
|
12
12
|
* adk run -e "<code>" Type-check + execute inline code
|
|
13
13
|
*/
|
|
14
|
-
import { join, dirname, resolve } from "node:path";
|
|
14
|
+
import { join, dirname, basename, resolve } from "node:path";
|
|
15
15
|
import { homedir } from "node:os";
|
|
16
|
-
import { existsSync,
|
|
17
|
-
import { tmpdir } from "node:os";
|
|
16
|
+
import { existsSync, writeFileSync, readFileSync, unlinkSync } from "node:fs";
|
|
18
17
|
import { spawnSync } from "node:child_process";
|
|
19
18
|
export async function adkCheck(opts) {
|
|
20
19
|
const configDir = opts.configDir ?? process.env.ADK_CONFIG_DIR ?? join(homedir(), ".adk");
|
|
@@ -23,19 +22,18 @@ export async function adkCheck(opts) {
|
|
|
23
22
|
if (!hasTypes) {
|
|
24
23
|
console.error("\x1b[33m\u26a0\x1b[0m No adk.d.ts found. Run `adk sync` first to generate agent types.");
|
|
25
24
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
let
|
|
30
|
-
|
|
25
|
+
const preamble = hasTypes
|
|
26
|
+
? `import ${JSON.stringify(adkTypes.replace(/\.d\.ts$/, ""))};\n`
|
|
27
|
+
: "";
|
|
28
|
+
let checkFile;
|
|
29
|
+
let originalFile;
|
|
30
|
+
let cwd;
|
|
31
31
|
if (opts.code) {
|
|
32
|
-
// Inline
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
writeFileSync(sourceFile, preamble + opts.code);
|
|
38
|
-
originalFile = sourceFile;
|
|
32
|
+
// Inline: write temp file in cwd
|
|
33
|
+
cwd = process.cwd();
|
|
34
|
+
checkFile = join(cwd, "__adk_inline.ts");
|
|
35
|
+
writeFileSync(checkFile, preamble + opts.code);
|
|
36
|
+
originalFile = checkFile; // for run, execute the same file (bun ignores types)
|
|
39
37
|
}
|
|
40
38
|
else if (opts.file) {
|
|
41
39
|
originalFile = resolve(opts.file);
|
|
@@ -43,83 +41,50 @@ export async function adkCheck(opts) {
|
|
|
43
41
|
console.error(`File not found: ${originalFile}`);
|
|
44
42
|
return { ok: false, exitCode: 1 };
|
|
45
43
|
}
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
: "";
|
|
52
|
-
writeFileSync(sourceFile, preamble + original);
|
|
44
|
+
// Write temp file next to original so module resolution works
|
|
45
|
+
cwd = dirname(originalFile);
|
|
46
|
+
const name = `__adk_check_${basename(originalFile)}`;
|
|
47
|
+
checkFile = join(cwd, name);
|
|
48
|
+
writeFileSync(checkFile, preamble + readFileSync(originalFile, "utf-8"));
|
|
53
49
|
}
|
|
54
50
|
else {
|
|
55
|
-
console.error(
|
|
51
|
+
console.error('Usage: adk check <file> | adk check -e "<code>"');
|
|
56
52
|
return { ok: false, exitCode: 1 };
|
|
57
53
|
}
|
|
58
|
-
//
|
|
59
|
-
const cwd = opts.file ? dirname(resolve(opts.file)) : process.cwd();
|
|
60
|
-
const tsconfig = {
|
|
61
|
-
compilerOptions: {
|
|
62
|
-
target: "ES2022",
|
|
63
|
-
module: "ESNext",
|
|
64
|
-
moduleResolution: "bundler",
|
|
65
|
-
esModuleInterop: true,
|
|
66
|
-
strict: true,
|
|
67
|
-
noEmit: true,
|
|
68
|
-
skipLibCheck: true,
|
|
69
|
-
types: ["node"],
|
|
70
|
-
baseUrl: cwd,
|
|
71
|
-
paths: {
|
|
72
|
-
// Ensure bare specifiers resolve from the user's project
|
|
73
|
-
"*": [join(cwd, "node_modules", "*"), "*"],
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
include: [sourceFile],
|
|
77
|
-
};
|
|
78
|
-
const tsconfigPath = join(tmpDir, "tsconfig.adk.json");
|
|
79
|
-
writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2));
|
|
80
|
-
// Find type checker: prefer tsgo, fall back to tsc
|
|
54
|
+
// Find tsgo or tsc
|
|
81
55
|
const checker = findTypeChecker();
|
|
82
|
-
//
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return { ok: false, exitCode:
|
|
56
|
+
// Type-check
|
|
57
|
+
const result = spawnSync(checker.cmd, [...checker.args, "--noEmit", checkFile], { cwd, stdio: "inherit", env: process.env });
|
|
58
|
+
// Clean up temp file
|
|
59
|
+
try {
|
|
60
|
+
unlinkSync(checkFile);
|
|
61
|
+
}
|
|
62
|
+
catch { }
|
|
63
|
+
if (result.status !== 0) {
|
|
64
|
+
return { ok: false, exitCode: result.status ?? 1 };
|
|
91
65
|
}
|
|
92
66
|
console.error("\x1b[32m\u2713\x1b[0m Type check passed");
|
|
93
|
-
//
|
|
67
|
+
// Run mode: execute original file with bun
|
|
94
68
|
if (opts.run) {
|
|
95
69
|
const runResult = spawnSync("bun", ["run", originalFile], {
|
|
96
70
|
cwd,
|
|
97
71
|
stdio: "inherit",
|
|
98
72
|
env: process.env,
|
|
99
73
|
});
|
|
100
|
-
cleanup(tmpDir);
|
|
101
74
|
return { ok: runResult.status === 0, exitCode: runResult.status ?? 1 };
|
|
102
75
|
}
|
|
103
|
-
cleanup(tmpDir);
|
|
104
76
|
return { ok: true, exitCode: 0 };
|
|
105
77
|
}
|
|
106
78
|
function findTypeChecker() {
|
|
107
79
|
// Prefer tsgo
|
|
108
|
-
const
|
|
109
|
-
if (
|
|
80
|
+
const tsgo = spawnSync("which", ["tsgo"], { stdio: "pipe" });
|
|
81
|
+
if (tsgo.status === 0)
|
|
110
82
|
return { cmd: "tsgo", args: [] };
|
|
111
|
-
//
|
|
112
|
-
const npxTsgo = spawnSync("npx", ["tsgo", "--version"], { stdio: "pipe" });
|
|
83
|
+
// npx tsgo
|
|
84
|
+
const npxTsgo = spawnSync("npx", ["tsgo", "--version"], { stdio: "pipe", timeout: 5000 });
|
|
113
85
|
if (npxTsgo.status === 0)
|
|
114
86
|
return { cmd: "npx", args: ["tsgo"] };
|
|
87
|
+
// Fallback: npx tsc
|
|
115
88
|
return { cmd: "npx", args: ["tsc"] };
|
|
116
89
|
}
|
|
117
|
-
function cleanup(tmpDir) {
|
|
118
|
-
if (tmpDir) {
|
|
119
|
-
try {
|
|
120
|
-
rmSync(tmpDir, { recursive: true });
|
|
121
|
-
}
|
|
122
|
-
catch { }
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
90
|
//# sourceMappingURL=adk-check.js.map
|
package/dist/adk-check.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adk-check.js","sourceRoot":"","sources":["../src/adk-check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"adk-check.js","sourceRoot":"","sources":["../src/adk-check.ts"],"names":[],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C,EAAE,CAAC;AACvC,CAAC"}
|
package/dist/cjs/adk-check.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* adk check / adk run
|
|
4
4
|
*
|
|
5
5
|
* Type-checks (and optionally runs) TypeScript files with auto-injected
|
|
6
|
-
* ADK agent type augmentation.
|
|
7
|
-
*
|
|
6
|
+
* ADK agent type augmentation. Writes a temp file next to the original
|
|
7
|
+
* so module resolution works naturally from node_modules.
|
|
8
8
|
*
|
|
9
9
|
* Usage:
|
|
10
10
|
* adk check <file> Type-check a file
|
|
@@ -17,7 +17,6 @@ exports.adkCheck = adkCheck;
|
|
|
17
17
|
const node_path_1 = require("node:path");
|
|
18
18
|
const node_os_1 = require("node:os");
|
|
19
19
|
const node_fs_1 = require("node:fs");
|
|
20
|
-
const node_os_2 = require("node:os");
|
|
21
20
|
const node_child_process_1 = require("node:child_process");
|
|
22
21
|
async function adkCheck(opts) {
|
|
23
22
|
const configDir = opts.configDir ?? process.env.ADK_CONFIG_DIR ?? (0, node_path_1.join)((0, node_os_1.homedir)(), ".adk");
|
|
@@ -26,19 +25,18 @@ async function adkCheck(opts) {
|
|
|
26
25
|
if (!hasTypes) {
|
|
27
26
|
console.error("\x1b[33m\u26a0\x1b[0m No adk.d.ts found. Run `adk sync` first to generate agent types.");
|
|
28
27
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
let
|
|
33
|
-
|
|
28
|
+
const preamble = hasTypes
|
|
29
|
+
? `import ${JSON.stringify(adkTypes.replace(/\.d\.ts$/, ""))};\n`
|
|
30
|
+
: "";
|
|
31
|
+
let checkFile;
|
|
32
|
+
let originalFile;
|
|
33
|
+
let cwd;
|
|
34
34
|
if (opts.code) {
|
|
35
|
-
// Inline
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
(0, node_fs_1.writeFileSync)(sourceFile, preamble + opts.code);
|
|
41
|
-
originalFile = sourceFile;
|
|
35
|
+
// Inline: write temp file in cwd
|
|
36
|
+
cwd = process.cwd();
|
|
37
|
+
checkFile = (0, node_path_1.join)(cwd, "__adk_inline.ts");
|
|
38
|
+
(0, node_fs_1.writeFileSync)(checkFile, preamble + opts.code);
|
|
39
|
+
originalFile = checkFile; // for run, execute the same file (bun ignores types)
|
|
42
40
|
}
|
|
43
41
|
else if (opts.file) {
|
|
44
42
|
originalFile = (0, node_path_1.resolve)(opts.file);
|
|
@@ -46,83 +44,50 @@ async function adkCheck(opts) {
|
|
|
46
44
|
console.error(`File not found: ${originalFile}`);
|
|
47
45
|
return { ok: false, exitCode: 1 };
|
|
48
46
|
}
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
: "";
|
|
55
|
-
(0, node_fs_1.writeFileSync)(sourceFile, preamble + original);
|
|
47
|
+
// Write temp file next to original so module resolution works
|
|
48
|
+
cwd = (0, node_path_1.dirname)(originalFile);
|
|
49
|
+
const name = `__adk_check_${(0, node_path_1.basename)(originalFile)}`;
|
|
50
|
+
checkFile = (0, node_path_1.join)(cwd, name);
|
|
51
|
+
(0, node_fs_1.writeFileSync)(checkFile, preamble + (0, node_fs_1.readFileSync)(originalFile, "utf-8"));
|
|
56
52
|
}
|
|
57
53
|
else {
|
|
58
|
-
console.error(
|
|
54
|
+
console.error('Usage: adk check <file> | adk check -e "<code>"');
|
|
59
55
|
return { ok: false, exitCode: 1 };
|
|
60
56
|
}
|
|
61
|
-
//
|
|
62
|
-
const cwd = opts.file ? (0, node_path_1.dirname)((0, node_path_1.resolve)(opts.file)) : process.cwd();
|
|
63
|
-
const tsconfig = {
|
|
64
|
-
compilerOptions: {
|
|
65
|
-
target: "ES2022",
|
|
66
|
-
module: "ESNext",
|
|
67
|
-
moduleResolution: "bundler",
|
|
68
|
-
esModuleInterop: true,
|
|
69
|
-
strict: true,
|
|
70
|
-
noEmit: true,
|
|
71
|
-
skipLibCheck: true,
|
|
72
|
-
types: ["node"],
|
|
73
|
-
baseUrl: cwd,
|
|
74
|
-
paths: {
|
|
75
|
-
// Ensure bare specifiers resolve from the user's project
|
|
76
|
-
"*": [(0, node_path_1.join)(cwd, "node_modules", "*"), "*"],
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
include: [sourceFile],
|
|
80
|
-
};
|
|
81
|
-
const tsconfigPath = (0, node_path_1.join)(tmpDir, "tsconfig.adk.json");
|
|
82
|
-
(0, node_fs_1.writeFileSync)(tsconfigPath, JSON.stringify(tsconfig, null, 2));
|
|
83
|
-
// Find type checker: prefer tsgo, fall back to tsc
|
|
57
|
+
// Find tsgo or tsc
|
|
84
58
|
const checker = findTypeChecker();
|
|
85
|
-
//
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return { ok: false, exitCode:
|
|
59
|
+
// Type-check
|
|
60
|
+
const result = (0, node_child_process_1.spawnSync)(checker.cmd, [...checker.args, "--noEmit", checkFile], { cwd, stdio: "inherit", env: process.env });
|
|
61
|
+
// Clean up temp file
|
|
62
|
+
try {
|
|
63
|
+
(0, node_fs_1.unlinkSync)(checkFile);
|
|
64
|
+
}
|
|
65
|
+
catch { }
|
|
66
|
+
if (result.status !== 0) {
|
|
67
|
+
return { ok: false, exitCode: result.status ?? 1 };
|
|
94
68
|
}
|
|
95
69
|
console.error("\x1b[32m\u2713\x1b[0m Type check passed");
|
|
96
|
-
//
|
|
70
|
+
// Run mode: execute original file with bun
|
|
97
71
|
if (opts.run) {
|
|
98
72
|
const runResult = (0, node_child_process_1.spawnSync)("bun", ["run", originalFile], {
|
|
99
73
|
cwd,
|
|
100
74
|
stdio: "inherit",
|
|
101
75
|
env: process.env,
|
|
102
76
|
});
|
|
103
|
-
cleanup(tmpDir);
|
|
104
77
|
return { ok: runResult.status === 0, exitCode: runResult.status ?? 1 };
|
|
105
78
|
}
|
|
106
|
-
cleanup(tmpDir);
|
|
107
79
|
return { ok: true, exitCode: 0 };
|
|
108
80
|
}
|
|
109
81
|
function findTypeChecker() {
|
|
110
82
|
// Prefer tsgo
|
|
111
|
-
const
|
|
112
|
-
if (
|
|
83
|
+
const tsgo = (0, node_child_process_1.spawnSync)("which", ["tsgo"], { stdio: "pipe" });
|
|
84
|
+
if (tsgo.status === 0)
|
|
113
85
|
return { cmd: "tsgo", args: [] };
|
|
114
|
-
//
|
|
115
|
-
const npxTsgo = (0, node_child_process_1.spawnSync)("npx", ["tsgo", "--version"], { stdio: "pipe" });
|
|
86
|
+
// npx tsgo
|
|
87
|
+
const npxTsgo = (0, node_child_process_1.spawnSync)("npx", ["tsgo", "--version"], { stdio: "pipe", timeout: 5000 });
|
|
116
88
|
if (npxTsgo.status === 0)
|
|
117
89
|
return { cmd: "npx", args: ["tsgo"] };
|
|
90
|
+
// Fallback: npx tsc
|
|
118
91
|
return { cmd: "npx", args: ["tsc"] };
|
|
119
92
|
}
|
|
120
|
-
function cleanup(tmpDir) {
|
|
121
|
-
if (tmpDir) {
|
|
122
|
-
try {
|
|
123
|
-
(0, node_fs_1.rmSync)(tmpDir, { recursive: true });
|
|
124
|
-
}
|
|
125
|
-
catch { }
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
93
|
//# sourceMappingURL=adk-check.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adk-check.js","sourceRoot":"","sources":["../../src/adk-check.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;
|
|
1
|
+
{"version":3,"file":"adk-check.js","sourceRoot":"","sources":["../../src/adk-check.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAcH,4BAqEC;AAjFD,yCAA6D;AAC7D,qCAAkC;AAClC,qCAA8E;AAC9E,2DAA+C;AASxC,KAAK,UAAU,QAAQ,CAAC,IAAkB;IAC/C,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,IAAA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YAChB,GAAG,EAAE,OAAO,CAAC,GAAG;SACjB,CAAC,CAAC;QACH,OAAO,EAAE,EAAE,EAAE,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;IACzE,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;AACnC,CAAC;AAED,SAAS,eAAe;IACtB,cAAc;IACd,MAAM,IAAI,GAAG,IAAA,8BAAS,EAAC,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7D,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;IAExD,WAAW;IACX,MAAM,OAAO,GAAG,IAAA,8BAAS,EAAC,KAAK,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1F,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;IAEhE,oBAAoB;IACpB,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;AACvC,CAAC"}
|
package/package.json
CHANGED
package/src/adk-check.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* adk check / adk run
|
|
3
3
|
*
|
|
4
4
|
* Type-checks (and optionally runs) TypeScript files with auto-injected
|
|
5
|
-
* ADK agent type augmentation.
|
|
6
|
-
*
|
|
5
|
+
* ADK agent type augmentation. Writes a temp file next to the original
|
|
6
|
+
* so module resolution works naturally from node_modules.
|
|
7
7
|
*
|
|
8
8
|
* Usage:
|
|
9
9
|
* adk check <file> Type-check a file
|
|
@@ -12,20 +12,15 @@
|
|
|
12
12
|
* adk run -e "<code>" Type-check + execute inline code
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import { join, dirname, resolve } from "node:path";
|
|
15
|
+
import { join, dirname, basename, resolve } from "node:path";
|
|
16
16
|
import { homedir } from "node:os";
|
|
17
|
-
import { existsSync,
|
|
18
|
-
import { tmpdir } from "node:os";
|
|
17
|
+
import { existsSync, writeFileSync, readFileSync, unlinkSync } from "node:fs";
|
|
19
18
|
import { spawnSync } from "node:child_process";
|
|
20
19
|
|
|
21
20
|
export interface CheckOptions {
|
|
22
|
-
/** File to check, or undefined if using inline code */
|
|
23
21
|
file?: string;
|
|
24
|
-
/** Inline code (-e flag) */
|
|
25
22
|
code?: string;
|
|
26
|
-
/** Also execute after type-check (adk run) */
|
|
27
23
|
run?: boolean;
|
|
28
|
-
/** ADK config dir (default: ~/.adk) */
|
|
29
24
|
configDir?: string;
|
|
30
25
|
}
|
|
31
26
|
|
|
@@ -35,115 +30,80 @@ export async function adkCheck(opts: CheckOptions): Promise<{ ok: boolean; exitC
|
|
|
35
30
|
const hasTypes = existsSync(adkTypes);
|
|
36
31
|
|
|
37
32
|
if (!hasTypes) {
|
|
38
|
-
console.error(
|
|
39
|
-
"\x1b[33m\u26a0\x1b[0m No adk.d.ts found. Run `adk sync` first to generate agent types."
|
|
40
|
-
);
|
|
33
|
+
console.error("\x1b[33m\u26a0\x1b[0m No adk.d.ts found. Run `adk sync` first to generate agent types.");
|
|
41
34
|
}
|
|
42
35
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
let tmpDir: string | null = null;
|
|
36
|
+
const preamble = hasTypes
|
|
37
|
+
? `import ${JSON.stringify(adkTypes.replace(/\.d\.ts$/, ""))};\n`
|
|
38
|
+
: "";
|
|
47
39
|
|
|
48
|
-
|
|
40
|
+
let checkFile: string;
|
|
41
|
+
let originalFile: string | undefined;
|
|
42
|
+
let cwd: string;
|
|
49
43
|
|
|
50
44
|
if (opts.code) {
|
|
51
|
-
// Inline
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
writeFileSync(sourceFile, preamble + opts.code);
|
|
57
|
-
originalFile = sourceFile;
|
|
45
|
+
// Inline: write temp file in cwd
|
|
46
|
+
cwd = process.cwd();
|
|
47
|
+
checkFile = join(cwd, "__adk_inline.ts");
|
|
48
|
+
writeFileSync(checkFile, preamble + opts.code);
|
|
49
|
+
originalFile = checkFile; // for run, execute the same file (bun ignores types)
|
|
58
50
|
} else if (opts.file) {
|
|
59
51
|
originalFile = resolve(opts.file);
|
|
60
52
|
if (!existsSync(originalFile)) {
|
|
61
53
|
console.error(`File not found: ${originalFile}`);
|
|
62
54
|
return { ok: false, exitCode: 1 };
|
|
63
55
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
? `import ${JSON.stringify(adkTypes.replace(/\.d\.ts$/, ""))};\n`
|
|
70
|
-
: "";
|
|
71
|
-
writeFileSync(sourceFile, preamble + original);
|
|
56
|
+
// Write temp file next to original so module resolution works
|
|
57
|
+
cwd = dirname(originalFile);
|
|
58
|
+
const name = `__adk_check_${basename(originalFile)}`;
|
|
59
|
+
checkFile = join(cwd, name);
|
|
60
|
+
writeFileSync(checkFile, preamble + readFileSync(originalFile, "utf-8"));
|
|
72
61
|
} else {
|
|
73
|
-
console.error(
|
|
62
|
+
console.error('Usage: adk check <file> | adk check -e "<code>"');
|
|
74
63
|
return { ok: false, exitCode: 1 };
|
|
75
64
|
}
|
|
76
65
|
|
|
77
|
-
//
|
|
78
|
-
const cwd = opts.file ? dirname(resolve(opts.file)) : process.cwd();
|
|
79
|
-
const tsconfig = {
|
|
80
|
-
compilerOptions: {
|
|
81
|
-
target: "ES2022",
|
|
82
|
-
module: "ESNext",
|
|
83
|
-
moduleResolution: "bundler",
|
|
84
|
-
esModuleInterop: true,
|
|
85
|
-
strict: true,
|
|
86
|
-
noEmit: true,
|
|
87
|
-
skipLibCheck: true,
|
|
88
|
-
types: ["node"],
|
|
89
|
-
baseUrl: cwd,
|
|
90
|
-
paths: {
|
|
91
|
-
// Ensure bare specifiers resolve from the user's project
|
|
92
|
-
"*": [join(cwd, "node_modules", "*"), "*"],
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
include: [sourceFile],
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const tsconfigPath = join(tmpDir, "tsconfig.adk.json");
|
|
99
|
-
writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2));
|
|
100
|
-
|
|
101
|
-
// Find type checker: prefer tsgo, fall back to tsc
|
|
66
|
+
// Find tsgo or tsc
|
|
102
67
|
const checker = findTypeChecker();
|
|
103
68
|
|
|
104
|
-
//
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
env: process.env,
|
|
109
|
-
|
|
69
|
+
// Type-check
|
|
70
|
+
const result = spawnSync(
|
|
71
|
+
checker.cmd,
|
|
72
|
+
[...checker.args, "--noEmit", checkFile],
|
|
73
|
+
{ cwd, stdio: "inherit", env: process.env },
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
// Clean up temp file
|
|
77
|
+
try { unlinkSync(checkFile); } catch {}
|
|
110
78
|
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
return { ok: false, exitCode: checkResult.status ?? 1 };
|
|
79
|
+
if (result.status !== 0) {
|
|
80
|
+
return { ok: false, exitCode: result.status ?? 1 };
|
|
114
81
|
}
|
|
115
82
|
|
|
116
83
|
console.error("\x1b[32m\u2713\x1b[0m Type check passed");
|
|
117
84
|
|
|
118
|
-
//
|
|
85
|
+
// Run mode: execute original file with bun
|
|
119
86
|
if (opts.run) {
|
|
120
87
|
const runResult = spawnSync("bun", ["run", originalFile!], {
|
|
121
88
|
cwd,
|
|
122
89
|
stdio: "inherit",
|
|
123
90
|
env: process.env,
|
|
124
91
|
});
|
|
125
|
-
cleanup(tmpDir);
|
|
126
92
|
return { ok: runResult.status === 0, exitCode: runResult.status ?? 1 };
|
|
127
93
|
}
|
|
128
94
|
|
|
129
|
-
cleanup(tmpDir);
|
|
130
95
|
return { ok: true, exitCode: 0 };
|
|
131
96
|
}
|
|
132
97
|
|
|
133
98
|
function findTypeChecker(): { cmd: string; args: string[] } {
|
|
134
99
|
// Prefer tsgo
|
|
135
|
-
const
|
|
136
|
-
if (
|
|
100
|
+
const tsgo = spawnSync("which", ["tsgo"], { stdio: "pipe" });
|
|
101
|
+
if (tsgo.status === 0) return { cmd: "tsgo", args: [] };
|
|
137
102
|
|
|
138
|
-
//
|
|
139
|
-
const npxTsgo = spawnSync("npx", ["tsgo", "--version"], { stdio: "pipe" });
|
|
103
|
+
// npx tsgo
|
|
104
|
+
const npxTsgo = spawnSync("npx", ["tsgo", "--version"], { stdio: "pipe", timeout: 5000 });
|
|
140
105
|
if (npxTsgo.status === 0) return { cmd: "npx", args: ["tsgo"] };
|
|
141
106
|
|
|
107
|
+
// Fallback: npx tsc
|
|
142
108
|
return { cmd: "npx", args: ["tsc"] };
|
|
143
109
|
}
|
|
144
|
-
|
|
145
|
-
function cleanup(tmpDir: string | null) {
|
|
146
|
-
if (tmpDir) {
|
|
147
|
-
try { rmSync(tmpDir, { recursive: true }); } catch {}
|
|
148
|
-
}
|
|
149
|
-
}
|