@slashfi/agents-sdk 0.69.8 → 0.69.10
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 -12
- package/dist/adk-check.d.ts.map +1 -1
- package/dist/adk-check.js +41 -70
- package/dist/adk-check.js.map +1 -1
- package/dist/cjs/adk-check.js +39 -68
- package/dist/cjs/adk-check.js.map +1 -1
- package/package.json +1 -1
- package/src/adk-check.ts +41 -77
package/dist/adk-check.d.ts
CHANGED
|
@@ -2,23 +2,13 @@
|
|
|
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
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Usage:
|
|
9
|
-
* adk check <file> Type-check a file
|
|
10
|
-
* adk check -e "<code>" Type-check inline code
|
|
11
|
-
* adk run <file> Type-check + execute
|
|
12
|
-
* adk run -e "<code>" Type-check + execute inline code
|
|
5
|
+
* ADK agent type augmentation. Writes a temp file next to the original
|
|
6
|
+
* so module resolution works naturally from node_modules.
|
|
13
7
|
*/
|
|
14
8
|
export interface CheckOptions {
|
|
15
|
-
/** File to check, or undefined if using inline code */
|
|
16
9
|
file?: string;
|
|
17
|
-
/** Inline code (-e flag) */
|
|
18
10
|
code?: string;
|
|
19
|
-
/** Also execute after type-check (adk run) */
|
|
20
11
|
run?: boolean;
|
|
21
|
-
/** ADK config dir (default: ~/.adk) */
|
|
22
12
|
configDir?: string;
|
|
23
13
|
}
|
|
24
14
|
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
|
|
1
|
+
{"version":3,"file":"adk-check.d.ts","sourceRoot":"","sources":["../src/adk-check.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;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,CAkF7F"}
|
package/dist/adk-check.js
CHANGED
|
@@ -2,19 +2,12 @@
|
|
|
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
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Usage:
|
|
9
|
-
* adk check <file> Type-check a file
|
|
10
|
-
* adk check -e "<code>" Type-check inline code
|
|
11
|
-
* adk run <file> Type-check + execute
|
|
12
|
-
* adk run -e "<code>" Type-check + execute inline code
|
|
5
|
+
* ADK agent type augmentation. Writes a temp file next to the original
|
|
6
|
+
* so module resolution works naturally from node_modules.
|
|
13
7
|
*/
|
|
14
|
-
import { join, dirname, resolve } from "node:path";
|
|
8
|
+
import { join, dirname, basename, resolve } from "node:path";
|
|
15
9
|
import { homedir } from "node:os";
|
|
16
|
-
import { existsSync,
|
|
17
|
-
import { tmpdir } from "node:os";
|
|
10
|
+
import { existsSync, writeFileSync, readFileSync, unlinkSync } from "node:fs";
|
|
18
11
|
import { spawnSync } from "node:child_process";
|
|
19
12
|
export async function adkCheck(opts) {
|
|
20
13
|
const configDir = opts.configDir ?? process.env.ADK_CONFIG_DIR ?? join(homedir(), ".adk");
|
|
@@ -23,19 +16,18 @@ export async function adkCheck(opts) {
|
|
|
23
16
|
if (!hasTypes) {
|
|
24
17
|
console.error("\x1b[33m\u26a0\x1b[0m No adk.d.ts found. Run `adk sync` first to generate agent types.");
|
|
25
18
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
let
|
|
30
|
-
|
|
19
|
+
const preamble = hasTypes
|
|
20
|
+
? `import ${JSON.stringify(adkTypes.replace(/\.d\.ts$/, ""))};\n`
|
|
21
|
+
: "";
|
|
22
|
+
let checkFile;
|
|
23
|
+
let tsconfigFile;
|
|
24
|
+
let originalFile;
|
|
25
|
+
let cwd;
|
|
31
26
|
if (opts.code) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
: "";
|
|
37
|
-
writeFileSync(sourceFile, preamble + opts.code);
|
|
38
|
-
originalFile = sourceFile;
|
|
27
|
+
cwd = process.cwd();
|
|
28
|
+
checkFile = join(cwd, ".adk_check.ts");
|
|
29
|
+
writeFileSync(checkFile, preamble + opts.code);
|
|
30
|
+
originalFile = checkFile;
|
|
39
31
|
}
|
|
40
32
|
else if (opts.file) {
|
|
41
33
|
originalFile = resolve(opts.file);
|
|
@@ -43,21 +35,17 @@ export async function adkCheck(opts) {
|
|
|
43
35
|
console.error(`File not found: ${originalFile}`);
|
|
44
36
|
return { ok: false, exitCode: 1 };
|
|
45
37
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const preamble = hasTypes
|
|
50
|
-
? `import ${JSON.stringify(adkTypes.replace(/\.d\.ts$/, ""))};\n`
|
|
51
|
-
: "";
|
|
52
|
-
writeFileSync(sourceFile, preamble + original);
|
|
38
|
+
cwd = dirname(originalFile);
|
|
39
|
+
checkFile = join(cwd, `.adk_check_${basename(originalFile)}`);
|
|
40
|
+
writeFileSync(checkFile, preamble + readFileSync(originalFile, "utf-8"));
|
|
53
41
|
}
|
|
54
42
|
else {
|
|
55
|
-
console.error(
|
|
43
|
+
console.error('Usage: adk check <file> | adk check -e "<code>"');
|
|
56
44
|
return { ok: false, exitCode: 1 };
|
|
57
45
|
}
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
|
|
46
|
+
// Write a minimal tsconfig next to the check file
|
|
47
|
+
tsconfigFile = join(cwd, ".adk_tsconfig.json");
|
|
48
|
+
writeFileSync(tsconfigFile, JSON.stringify({
|
|
61
49
|
compilerOptions: {
|
|
62
50
|
target: "ES2022",
|
|
63
51
|
module: "ESNext",
|
|
@@ -66,60 +54,43 @@ export async function adkCheck(opts) {
|
|
|
66
54
|
strict: true,
|
|
67
55
|
noEmit: true,
|
|
68
56
|
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
57
|
},
|
|
76
|
-
include: [
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2));
|
|
80
|
-
// Find type checker: prefer tsgo, fall back to tsc
|
|
58
|
+
include: [basename(checkFile)],
|
|
59
|
+
}, null, 2));
|
|
60
|
+
// Find tsgo or tsc
|
|
81
61
|
const checker = findTypeChecker();
|
|
82
|
-
//
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
62
|
+
// Type-check
|
|
63
|
+
const result = spawnSync(checker.cmd, [...checker.args, "--project", tsconfigFile], { cwd, stdio: "inherit", env: process.env });
|
|
64
|
+
// Clean up
|
|
65
|
+
try {
|
|
66
|
+
unlinkSync(checkFile);
|
|
67
|
+
}
|
|
68
|
+
catch { }
|
|
69
|
+
try {
|
|
70
|
+
unlinkSync(tsconfigFile);
|
|
71
|
+
}
|
|
72
|
+
catch { }
|
|
73
|
+
if (result.status !== 0) {
|
|
74
|
+
return { ok: false, exitCode: result.status ?? 1 };
|
|
91
75
|
}
|
|
92
76
|
console.error("\x1b[32m\u2713\x1b[0m Type check passed");
|
|
93
|
-
// If run mode, execute the original file with bun
|
|
94
77
|
if (opts.run) {
|
|
95
78
|
const runResult = spawnSync("bun", ["run", originalFile], {
|
|
96
79
|
cwd,
|
|
97
80
|
stdio: "inherit",
|
|
98
81
|
env: process.env,
|
|
99
82
|
});
|
|
100
|
-
cleanup(tmpDir);
|
|
101
83
|
return { ok: runResult.status === 0, exitCode: runResult.status ?? 1 };
|
|
102
84
|
}
|
|
103
|
-
cleanup(tmpDir);
|
|
104
85
|
return { ok: true, exitCode: 0 };
|
|
105
86
|
}
|
|
106
87
|
function findTypeChecker() {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (tsgoResult.status === 0)
|
|
88
|
+
const tsgo = spawnSync("which", ["tsgo"], { stdio: "pipe" });
|
|
89
|
+
if (tsgo.status === 0)
|
|
110
90
|
return { cmd: "tsgo", args: [] };
|
|
111
|
-
|
|
112
|
-
const npxTsgo = spawnSync("npx", ["tsgo", "--version"], { stdio: "pipe" });
|
|
91
|
+
const npxTsgo = spawnSync("npx", ["tsgo", "--version"], { stdio: "pipe", timeout: 5000 });
|
|
113
92
|
if (npxTsgo.status === 0)
|
|
114
93
|
return { cmd: "npx", args: ["tsgo"] };
|
|
115
94
|
return { cmd: "npx", args: ["tsc"] };
|
|
116
95
|
}
|
|
117
|
-
function cleanup(tmpDir) {
|
|
118
|
-
if (tmpDir) {
|
|
119
|
-
try {
|
|
120
|
-
rmSync(tmpDir, { recursive: true });
|
|
121
|
-
}
|
|
122
|
-
catch { }
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
96
|
//# 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
|
|
1
|
+
{"version":3,"file":"adk-check.js","sourceRoot":"","sources":["../src/adk-check.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAE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AE,IAAI,EAAE,EAAE,EAAE,CAAC;IAExD,MAAM,OAAO,GAAG,SAAS,CAAC,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,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;AACvC,CAAC"}
|
package/dist/cjs/adk-check.js
CHANGED
|
@@ -3,21 +3,14 @@
|
|
|
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
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* Usage:
|
|
10
|
-
* adk check <file> Type-check a file
|
|
11
|
-
* adk check -e "<code>" Type-check inline code
|
|
12
|
-
* adk run <file> Type-check + execute
|
|
13
|
-
* adk run -e "<code>" Type-check + execute inline code
|
|
6
|
+
* ADK agent type augmentation. Writes a temp file next to the original
|
|
7
|
+
* so module resolution works naturally from node_modules.
|
|
14
8
|
*/
|
|
15
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
10
|
exports.adkCheck = adkCheck;
|
|
17
11
|
const node_path_1 = require("node:path");
|
|
18
12
|
const node_os_1 = require("node:os");
|
|
19
13
|
const node_fs_1 = require("node:fs");
|
|
20
|
-
const node_os_2 = require("node:os");
|
|
21
14
|
const node_child_process_1 = require("node:child_process");
|
|
22
15
|
async function adkCheck(opts) {
|
|
23
16
|
const configDir = opts.configDir ?? process.env.ADK_CONFIG_DIR ?? (0, node_path_1.join)((0, node_os_1.homedir)(), ".adk");
|
|
@@ -26,19 +19,18 @@ async function adkCheck(opts) {
|
|
|
26
19
|
if (!hasTypes) {
|
|
27
20
|
console.error("\x1b[33m\u26a0\x1b[0m No adk.d.ts found. Run `adk sync` first to generate agent types.");
|
|
28
21
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
let
|
|
33
|
-
|
|
22
|
+
const preamble = hasTypes
|
|
23
|
+
? `import ${JSON.stringify(adkTypes.replace(/\.d\.ts$/, ""))};\n`
|
|
24
|
+
: "";
|
|
25
|
+
let checkFile;
|
|
26
|
+
let tsconfigFile;
|
|
27
|
+
let originalFile;
|
|
28
|
+
let cwd;
|
|
34
29
|
if (opts.code) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
: "";
|
|
40
|
-
(0, node_fs_1.writeFileSync)(sourceFile, preamble + opts.code);
|
|
41
|
-
originalFile = sourceFile;
|
|
30
|
+
cwd = process.cwd();
|
|
31
|
+
checkFile = (0, node_path_1.join)(cwd, ".adk_check.ts");
|
|
32
|
+
(0, node_fs_1.writeFileSync)(checkFile, preamble + opts.code);
|
|
33
|
+
originalFile = checkFile;
|
|
42
34
|
}
|
|
43
35
|
else if (opts.file) {
|
|
44
36
|
originalFile = (0, node_path_1.resolve)(opts.file);
|
|
@@ -46,21 +38,17 @@ async function adkCheck(opts) {
|
|
|
46
38
|
console.error(`File not found: ${originalFile}`);
|
|
47
39
|
return { ok: false, exitCode: 1 };
|
|
48
40
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const preamble = hasTypes
|
|
53
|
-
? `import ${JSON.stringify(adkTypes.replace(/\.d\.ts$/, ""))};\n`
|
|
54
|
-
: "";
|
|
55
|
-
(0, node_fs_1.writeFileSync)(sourceFile, preamble + original);
|
|
41
|
+
cwd = (0, node_path_1.dirname)(originalFile);
|
|
42
|
+
checkFile = (0, node_path_1.join)(cwd, `.adk_check_${(0, node_path_1.basename)(originalFile)}`);
|
|
43
|
+
(0, node_fs_1.writeFileSync)(checkFile, preamble + (0, node_fs_1.readFileSync)(originalFile, "utf-8"));
|
|
56
44
|
}
|
|
57
45
|
else {
|
|
58
|
-
console.error(
|
|
46
|
+
console.error('Usage: adk check <file> | adk check -e "<code>"');
|
|
59
47
|
return { ok: false, exitCode: 1 };
|
|
60
48
|
}
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
49
|
+
// Write a minimal tsconfig next to the check file
|
|
50
|
+
tsconfigFile = (0, node_path_1.join)(cwd, ".adk_tsconfig.json");
|
|
51
|
+
(0, node_fs_1.writeFileSync)(tsconfigFile, JSON.stringify({
|
|
64
52
|
compilerOptions: {
|
|
65
53
|
target: "ES2022",
|
|
66
54
|
module: "ESNext",
|
|
@@ -69,60 +57,43 @@ async function adkCheck(opts) {
|
|
|
69
57
|
strict: true,
|
|
70
58
|
noEmit: true,
|
|
71
59
|
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
60
|
},
|
|
79
|
-
include: [
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
(0, node_fs_1.writeFileSync)(tsconfigPath, JSON.stringify(tsconfig, null, 2));
|
|
83
|
-
// Find type checker: prefer tsgo, fall back to tsc
|
|
61
|
+
include: [(0, node_path_1.basename)(checkFile)],
|
|
62
|
+
}, null, 2));
|
|
63
|
+
// Find tsgo or tsc
|
|
84
64
|
const checker = findTypeChecker();
|
|
85
|
-
//
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
65
|
+
// Type-check
|
|
66
|
+
const result = (0, node_child_process_1.spawnSync)(checker.cmd, [...checker.args, "--project", tsconfigFile], { cwd, stdio: "inherit", env: process.env });
|
|
67
|
+
// Clean up
|
|
68
|
+
try {
|
|
69
|
+
(0, node_fs_1.unlinkSync)(checkFile);
|
|
70
|
+
}
|
|
71
|
+
catch { }
|
|
72
|
+
try {
|
|
73
|
+
(0, node_fs_1.unlinkSync)(tsconfigFile);
|
|
74
|
+
}
|
|
75
|
+
catch { }
|
|
76
|
+
if (result.status !== 0) {
|
|
77
|
+
return { ok: false, exitCode: result.status ?? 1 };
|
|
94
78
|
}
|
|
95
79
|
console.error("\x1b[32m\u2713\x1b[0m Type check passed");
|
|
96
|
-
// If run mode, execute the original file with bun
|
|
97
80
|
if (opts.run) {
|
|
98
81
|
const runResult = (0, node_child_process_1.spawnSync)("bun", ["run", originalFile], {
|
|
99
82
|
cwd,
|
|
100
83
|
stdio: "inherit",
|
|
101
84
|
env: process.env,
|
|
102
85
|
});
|
|
103
|
-
cleanup(tmpDir);
|
|
104
86
|
return { ok: runResult.status === 0, exitCode: runResult.status ?? 1 };
|
|
105
87
|
}
|
|
106
|
-
cleanup(tmpDir);
|
|
107
88
|
return { ok: true, exitCode: 0 };
|
|
108
89
|
}
|
|
109
90
|
function findTypeChecker() {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (tsgoResult.status === 0)
|
|
91
|
+
const tsgo = (0, node_child_process_1.spawnSync)("which", ["tsgo"], { stdio: "pipe" });
|
|
92
|
+
if (tsgo.status === 0)
|
|
113
93
|
return { cmd: "tsgo", args: [] };
|
|
114
|
-
|
|
115
|
-
const npxTsgo = (0, node_child_process_1.spawnSync)("npx", ["tsgo", "--version"], { stdio: "pipe" });
|
|
94
|
+
const npxTsgo = (0, node_child_process_1.spawnSync)("npx", ["tsgo", "--version"], { stdio: "pipe", timeout: 5000 });
|
|
116
95
|
if (npxTsgo.status === 0)
|
|
117
96
|
return { cmd: "npx", args: ["tsgo"] };
|
|
118
97
|
return { cmd: "npx", args: ["tsc"] };
|
|
119
98
|
}
|
|
120
|
-
function cleanup(tmpDir) {
|
|
121
|
-
if (tmpDir) {
|
|
122
|
-
try {
|
|
123
|
-
(0, node_fs_1.rmSync)(tmpDir, { recursive: true });
|
|
124
|
-
}
|
|
125
|
-
catch { }
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
99
|
//# sourceMappingURL=adk-check.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adk-check.js","sourceRoot":"","sources":["../../src/adk-check.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"adk-check.js","sourceRoot":"","sources":["../../src/adk-check.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AAcH,4BAkFC;AA9FD,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,gBAAI,EAAC,IAAA,iBAAO,GAAE,EAAE,MAAM,CAAC,CAAC;IAC1F,MAAM,QAAQ,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAC7C,MAAM,QAAQ,GAAG,IAAA,oBAAU,EAAC,QAAQ,CAAC,CAAC;IAEtC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,CAAC,KAAK,CAAC,wFAAwF,CAAC,CAAC;IAC1G,CAAC;IAED,MAAM,QAAQ,GAAG,QAAQ;QACvB,CAAC,CAAC,UAAU,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,KAAK;QACjE,CAAC,CAAC,EAAE,CAAC;IAEP,IAAI,SAAiB,CAAC;IACtB,IAAI,YAAoB,CAAC;IACzB,IAAI,YAAgC,CAAC;IACrC,IAAI,GAAW,CAAC;IAEhB,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;QACd,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;QACpB,SAAS,G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,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;AACnC,CAAC;AAED,SAAS,eAAe;IACtB,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,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,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,30 +2,19 @@
|
|
|
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
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Usage:
|
|
9
|
-
* adk check <file> Type-check a file
|
|
10
|
-
* adk check -e "<code>" Type-check inline code
|
|
11
|
-
* adk run <file> Type-check + execute
|
|
12
|
-
* adk run -e "<code>" Type-check + execute inline code
|
|
5
|
+
* ADK agent type augmentation. Writes a temp file next to the original
|
|
6
|
+
* so module resolution works naturally from node_modules.
|
|
13
7
|
*/
|
|
14
8
|
|
|
15
|
-
import { join, dirname, resolve } from "node:path";
|
|
9
|
+
import { join, dirname, basename, resolve } from "node:path";
|
|
16
10
|
import { homedir } from "node:os";
|
|
17
|
-
import { existsSync,
|
|
18
|
-
import { tmpdir } from "node:os";
|
|
11
|
+
import { existsSync, writeFileSync, readFileSync, unlinkSync } from "node:fs";
|
|
19
12
|
import { spawnSync } from "node:child_process";
|
|
20
13
|
|
|
21
14
|
export interface CheckOptions {
|
|
22
|
-
/** File to check, or undefined if using inline code */
|
|
23
15
|
file?: string;
|
|
24
|
-
/** Inline code (-e flag) */
|
|
25
16
|
code?: string;
|
|
26
|
-
/** Also execute after type-check (adk run) */
|
|
27
17
|
run?: boolean;
|
|
28
|
-
/** ADK config dir (default: ~/.adk) */
|
|
29
18
|
configDir?: string;
|
|
30
19
|
}
|
|
31
20
|
|
|
@@ -35,48 +24,40 @@ export async function adkCheck(opts: CheckOptions): Promise<{ ok: boolean; exitC
|
|
|
35
24
|
const hasTypes = existsSync(adkTypes);
|
|
36
25
|
|
|
37
26
|
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
|
-
);
|
|
27
|
+
console.error("\x1b[33m\u26a0\x1b[0m No adk.d.ts found. Run `adk sync` first to generate agent types.");
|
|
41
28
|
}
|
|
42
29
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
let tmpDir: string | null = null;
|
|
30
|
+
const preamble = hasTypes
|
|
31
|
+
? `import ${JSON.stringify(adkTypes.replace(/\.d\.ts$/, ""))};\n`
|
|
32
|
+
: "";
|
|
47
33
|
|
|
48
|
-
|
|
34
|
+
let checkFile: string;
|
|
35
|
+
let tsconfigFile: string;
|
|
36
|
+
let originalFile: string | undefined;
|
|
37
|
+
let cwd: string;
|
|
49
38
|
|
|
50
39
|
if (opts.code) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
: "";
|
|
56
|
-
writeFileSync(sourceFile, preamble + opts.code);
|
|
57
|
-
originalFile = sourceFile;
|
|
40
|
+
cwd = process.cwd();
|
|
41
|
+
checkFile = join(cwd, ".adk_check.ts");
|
|
42
|
+
writeFileSync(checkFile, preamble + opts.code);
|
|
43
|
+
originalFile = checkFile;
|
|
58
44
|
} else if (opts.file) {
|
|
59
45
|
originalFile = resolve(opts.file);
|
|
60
46
|
if (!existsSync(originalFile)) {
|
|
61
47
|
console.error(`File not found: ${originalFile}`);
|
|
62
48
|
return { ok: false, exitCode: 1 };
|
|
63
49
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
sourceFile = join(tmpDir, "__adk_check.ts");
|
|
68
|
-
const preamble = hasTypes
|
|
69
|
-
? `import ${JSON.stringify(adkTypes.replace(/\.d\.ts$/, ""))};\n`
|
|
70
|
-
: "";
|
|
71
|
-
writeFileSync(sourceFile, preamble + original);
|
|
50
|
+
cwd = dirname(originalFile);
|
|
51
|
+
checkFile = join(cwd, `.adk_check_${basename(originalFile)}`);
|
|
52
|
+
writeFileSync(checkFile, preamble + readFileSync(originalFile, "utf-8"));
|
|
72
53
|
} else {
|
|
73
|
-
console.error(
|
|
54
|
+
console.error('Usage: adk check <file> | adk check -e "<code>"');
|
|
74
55
|
return { ok: false, exitCode: 1 };
|
|
75
56
|
}
|
|
76
57
|
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
|
|
58
|
+
// Write a minimal tsconfig next to the check file
|
|
59
|
+
tsconfigFile = join(cwd, ".adk_tsconfig.json");
|
|
60
|
+
writeFileSync(tsconfigFile, JSON.stringify({
|
|
80
61
|
compilerOptions: {
|
|
81
62
|
target: "ES2022",
|
|
82
63
|
module: "ESNext",
|
|
@@ -85,65 +66,48 @@ export async function adkCheck(opts: CheckOptions): Promise<{ ok: boolean; exitC
|
|
|
85
66
|
strict: true,
|
|
86
67
|
noEmit: true,
|
|
87
68
|
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
69
|
},
|
|
95
|
-
include: [
|
|
96
|
-
};
|
|
70
|
+
include: [basename(checkFile)],
|
|
71
|
+
}, null, 2));
|
|
97
72
|
|
|
98
|
-
|
|
99
|
-
writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2));
|
|
100
|
-
|
|
101
|
-
// Find type checker: prefer tsgo, fall back to tsc
|
|
73
|
+
// Find tsgo or tsc
|
|
102
74
|
const checker = findTypeChecker();
|
|
103
75
|
|
|
104
|
-
//
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
env: process.env,
|
|
109
|
-
|
|
76
|
+
// Type-check
|
|
77
|
+
const result = spawnSync(
|
|
78
|
+
checker.cmd,
|
|
79
|
+
[...checker.args, "--project", tsconfigFile],
|
|
80
|
+
{ cwd, stdio: "inherit", env: process.env },
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
// Clean up
|
|
84
|
+
try { unlinkSync(checkFile); } catch {}
|
|
85
|
+
try { unlinkSync(tsconfigFile); } catch {}
|
|
110
86
|
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
return { ok: false, exitCode: checkResult.status ?? 1 };
|
|
87
|
+
if (result.status !== 0) {
|
|
88
|
+
return { ok: false, exitCode: result.status ?? 1 };
|
|
114
89
|
}
|
|
115
90
|
|
|
116
91
|
console.error("\x1b[32m\u2713\x1b[0m Type check passed");
|
|
117
92
|
|
|
118
|
-
// If run mode, execute the original file with bun
|
|
119
93
|
if (opts.run) {
|
|
120
94
|
const runResult = spawnSync("bun", ["run", originalFile!], {
|
|
121
95
|
cwd,
|
|
122
96
|
stdio: "inherit",
|
|
123
97
|
env: process.env,
|
|
124
98
|
});
|
|
125
|
-
cleanup(tmpDir);
|
|
126
99
|
return { ok: runResult.status === 0, exitCode: runResult.status ?? 1 };
|
|
127
100
|
}
|
|
128
101
|
|
|
129
|
-
cleanup(tmpDir);
|
|
130
102
|
return { ok: true, exitCode: 0 };
|
|
131
103
|
}
|
|
132
104
|
|
|
133
105
|
function findTypeChecker(): { cmd: string; args: string[] } {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (tsgoResult.status === 0) return { cmd: "tsgo", args: [] };
|
|
106
|
+
const tsgo = spawnSync("which", ["tsgo"], { stdio: "pipe" });
|
|
107
|
+
if (tsgo.status === 0) return { cmd: "tsgo", args: [] };
|
|
137
108
|
|
|
138
|
-
|
|
139
|
-
const npxTsgo = spawnSync("npx", ["tsgo", "--version"], { stdio: "pipe" });
|
|
109
|
+
const npxTsgo = spawnSync("npx", ["tsgo", "--version"], { stdio: "pipe", timeout: 5000 });
|
|
140
110
|
if (npxTsgo.status === 0) return { cmd: "npx", args: ["tsgo"] };
|
|
141
111
|
|
|
142
112
|
return { cmd: "npx", args: ["tsc"] };
|
|
143
113
|
}
|
|
144
|
-
|
|
145
|
-
function cleanup(tmpDir: string | null) {
|
|
146
|
-
if (tmpDir) {
|
|
147
|
-
try { rmSync(tmpDir, { recursive: true }); } catch {}
|
|
148
|
-
}
|
|
149
|
-
}
|