@slashfi/agents-sdk 0.70.0 → 0.70.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/dist/adk-check.d.ts.map +1 -1
- package/dist/adk-check.js +146 -50
- package/dist/adk-check.js.map +1 -1
- package/dist/cjs/adk-check.js +146 -50
- package/dist/cjs/adk-check.js.map +1 -1
- package/package.json +1 -1
- package/src/adk-check.ts +207 -70
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;;;;;;;;;;;;;GAaG;
|
|
1
|
+
{"version":3,"file":"adk-check.d.ts","sourceRoot":"","sources":["../src/adk-check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAaH,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA4CD,wBAAsB,QAAQ,CAC5B,IAAI,EAAE,YAAY,GACjB,OAAO,CAAC;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CA4K5C"}
|
package/dist/adk-check.js
CHANGED
|
@@ -12,48 +12,70 @@
|
|
|
12
12
|
* adk run --no-check <file> Execute without type-checking
|
|
13
13
|
* adk run --no-check -e "code" Execute inline without type-checking
|
|
14
14
|
*/
|
|
15
|
-
import { join, dirname, basename, resolve } from "node:path";
|
|
16
|
-
import { homedir } from "node:os";
|
|
17
|
-
import { existsSync, writeFileSync, readFileSync, unlinkSync, copyFileSync } from "node:fs";
|
|
18
15
|
import { spawnSync } from "node:child_process";
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
16
|
+
import { copyFileSync, existsSync, readFileSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
17
|
+
import { homedir } from "node:os";
|
|
18
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
19
|
+
/**
|
|
20
|
+
* Resolve the absolute path to the @slashfi/agents-sdk package.
|
|
21
|
+
* This ensures the preamble works regardless of the script's working directory,
|
|
22
|
+
* since bare specifiers like "@slashfi/agents-sdk" may not resolve from arbitrary cwds.
|
|
23
|
+
*/
|
|
24
|
+
function resolveAgentsSdkPath() {
|
|
25
|
+
try {
|
|
26
|
+
// require.resolve gives us the main entry point, e.g.
|
|
27
|
+
// /root/.bun/install/global/node_modules/@slashfi/agents-sdk/dist/index.js
|
|
28
|
+
const resolved = require.resolve("@slashfi/agents-sdk");
|
|
29
|
+
// Extract package root path
|
|
30
|
+
const marker = "@slashfi/agents-sdk";
|
|
31
|
+
const idx = resolved.indexOf(marker);
|
|
32
|
+
if (idx !== -1) {
|
|
33
|
+
return resolved.substring(0, idx + marker.length);
|
|
34
|
+
}
|
|
35
|
+
return "@slashfi/agents-sdk";
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return "@slashfi/agents-sdk";
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function makePreambleCheck(sdkPath) {
|
|
42
|
+
return `import "./.adk_types";\nimport { createAdk, createLocalFsStore } from "${sdkPath}";\nimport { join } from "node:path";\nimport { homedir } from "node:os";\nconst adk = createAdk(\n createLocalFsStore(process.env.ADK_CONFIG_DIR ?? join(homedir(), ".adk")),\n { token: process.env.ATLAS_TOKEN ?? process.env.ADK_TOKEN ?? "" },\n);\n`;
|
|
43
|
+
}
|
|
44
|
+
function makePreambleRun(sdkPath) {
|
|
45
|
+
return `import { createAdk, createLocalFsStore } from "${sdkPath}";\nimport { join } from "node:path";\nimport { homedir } from "node:os";\nconst adk = createAdk(\n createLocalFsStore(process.env.ADK_CONFIG_DIR ?? join(homedir(), ".adk")),\n { token: process.env.ATLAS_TOKEN ?? process.env.ADK_TOKEN ?? "" },\n);\n`;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Create a run wrapper file that injects the adk preamble before the user's code.
|
|
49
|
+
* Works for both inline (-e) and file mode.
|
|
50
|
+
*/
|
|
51
|
+
function writeRunWrapper(tmpFile, preamble, userCode) {
|
|
52
|
+
writeFileSync(tmpFile, preamble + userCode);
|
|
53
|
+
}
|
|
34
54
|
export async function adkCheck(opts) {
|
|
35
55
|
const configDir = opts.configDir ?? process.env.ADK_CONFIG_DIR ?? join(homedir(), ".adk");
|
|
36
56
|
const adkTypes = join(configDir, "adk.d.ts");
|
|
37
57
|
const hasTypes = existsSync(adkTypes);
|
|
38
58
|
const isInline = !!opts.code;
|
|
59
|
+
const sdkPath = resolveAgentsSdkPath();
|
|
60
|
+
const PREAMBLE_RUN = makePreambleRun(sdkPath);
|
|
39
61
|
// --no-check: skip typecheck, just run
|
|
40
62
|
if (opts.noCheck && opts.run) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
return { ok: r.status === 0, exitCode: r.status ?? 1 };
|
|
63
|
+
const cwd = isInline ? process.cwd() : dirname(resolve(opts.file));
|
|
64
|
+
const userCode = isInline
|
|
65
|
+
? opts.code
|
|
66
|
+
: readFileSync(resolve(opts.file), "utf-8");
|
|
67
|
+
const tmpFile = join(cwd, ".adk_run.ts");
|
|
68
|
+
writeRunWrapper(tmpFile, PREAMBLE_RUN, userCode);
|
|
69
|
+
const r = spawnSync("bun", ["run", tmpFile], {
|
|
70
|
+
cwd,
|
|
71
|
+
stdio: "inherit",
|
|
72
|
+
env: process.env,
|
|
73
|
+
});
|
|
74
|
+
try {
|
|
75
|
+
unlinkSync(tmpFile);
|
|
56
76
|
}
|
|
77
|
+
catch { }
|
|
78
|
+
return { ok: r.status === 0, exitCode: r.status ?? 1 };
|
|
57
79
|
}
|
|
58
80
|
if (!hasTypes) {
|
|
59
81
|
console.error("\x1b[33m\u26a0\x1b[0m No adk.d.ts found. Run `adk sync` first to generate agent types.");
|
|
@@ -62,10 +84,11 @@ export async function adkCheck(opts) {
|
|
|
62
84
|
let checkFile;
|
|
63
85
|
let originalFile;
|
|
64
86
|
const cleanup = [];
|
|
87
|
+
const PREAMBLE_CHECK = makePreambleCheck("@slashfi/agents-sdk");
|
|
65
88
|
if (isInline) {
|
|
66
89
|
cwd = process.cwd();
|
|
67
90
|
checkFile = join(cwd, ".adk_check.ts");
|
|
68
|
-
writeFileSync(checkFile,
|
|
91
|
+
writeFileSync(checkFile, PREAMBLE_CHECK + opts.code);
|
|
69
92
|
cleanup.push(checkFile);
|
|
70
93
|
}
|
|
71
94
|
else if (opts.file) {
|
|
@@ -76,8 +99,10 @@ export async function adkCheck(opts) {
|
|
|
76
99
|
}
|
|
77
100
|
cwd = dirname(originalFile);
|
|
78
101
|
checkFile = join(cwd, `.adk_check_${basename(originalFile)}`);
|
|
102
|
+
// File mode: inject preamble so `adk` is typed and available
|
|
79
103
|
const typesImport = hasTypes ? `import "./.adk_types";\n` : "";
|
|
80
|
-
|
|
104
|
+
const preambleNoTypes = PREAMBLE_CHECK.replace(`import "./.adk_types";\n`, "");
|
|
105
|
+
writeFileSync(checkFile, typesImport + preambleNoTypes + readFileSync(originalFile, "utf-8"));
|
|
81
106
|
cleanup.push(checkFile);
|
|
82
107
|
}
|
|
83
108
|
else {
|
|
@@ -108,9 +133,39 @@ export async function adkCheck(opts) {
|
|
|
108
133
|
cleanup.push(tsconfigFile);
|
|
109
134
|
// Find type checker
|
|
110
135
|
const checker = findTypeChecker();
|
|
136
|
+
if (!checker) {
|
|
137
|
+
console.error("\x1b[33m\u26a0\x1b[0m No TypeScript type checker found (tsgo or tsc). Skipping type check.");
|
|
138
|
+
for (const f of cleanup) {
|
|
139
|
+
try {
|
|
140
|
+
unlinkSync(f);
|
|
141
|
+
}
|
|
142
|
+
catch { }
|
|
143
|
+
}
|
|
144
|
+
// Still run if requested
|
|
145
|
+
if (opts.run) {
|
|
146
|
+
const userCode = isInline
|
|
147
|
+
? opts.code
|
|
148
|
+
: readFileSync(originalFile, "utf-8");
|
|
149
|
+
const tmpFile = join(cwd, ".adk_run.ts");
|
|
150
|
+
writeRunWrapper(tmpFile, PREAMBLE_RUN, userCode);
|
|
151
|
+
const r = spawnSync("bun", ["run", tmpFile], {
|
|
152
|
+
cwd,
|
|
153
|
+
stdio: "inherit",
|
|
154
|
+
env: process.env,
|
|
155
|
+
});
|
|
156
|
+
try {
|
|
157
|
+
unlinkSync(tmpFile);
|
|
158
|
+
}
|
|
159
|
+
catch { }
|
|
160
|
+
return { ok: r.status === 0, exitCode: r.status ?? 1 };
|
|
161
|
+
}
|
|
162
|
+
return { ok: true, exitCode: 0 };
|
|
163
|
+
}
|
|
111
164
|
// Type-check
|
|
112
165
|
const result = spawnSync(checker.cmd, [...checker.args, "--project", tsconfigFile], {
|
|
113
|
-
cwd,
|
|
166
|
+
cwd,
|
|
167
|
+
stdio: "inherit",
|
|
168
|
+
env: process.env,
|
|
114
169
|
});
|
|
115
170
|
// Clean up
|
|
116
171
|
for (const f of cleanup) {
|
|
@@ -125,30 +180,71 @@ export async function adkCheck(opts) {
|
|
|
125
180
|
console.error("\x1b[32m\u2713\x1b[0m Type check passed");
|
|
126
181
|
// Run
|
|
127
182
|
if (opts.run) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
183
|
+
const userCode = isInline
|
|
184
|
+
? opts.code
|
|
185
|
+
: readFileSync(originalFile, "utf-8");
|
|
186
|
+
const tmpFile = join(cwd, ".adk_run.ts");
|
|
187
|
+
writeRunWrapper(tmpFile, PREAMBLE_RUN, userCode);
|
|
188
|
+
const runResult = spawnSync("bun", ["run", tmpFile], {
|
|
189
|
+
cwd,
|
|
190
|
+
stdio: "inherit",
|
|
191
|
+
env: process.env,
|
|
192
|
+
});
|
|
193
|
+
try {
|
|
194
|
+
unlinkSync(tmpFile);
|
|
140
195
|
}
|
|
196
|
+
catch { }
|
|
141
197
|
return { ok: runResult.status === 0, exitCode: runResult.status ?? 1 };
|
|
142
198
|
}
|
|
143
199
|
return { ok: true, exitCode: 0 };
|
|
144
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Find a working TypeScript type checker.
|
|
203
|
+
* Returns null if none found — callers should skip type checking gracefully.
|
|
204
|
+
*
|
|
205
|
+
* Checks:
|
|
206
|
+
* 1. tsgo binary (fastest — native TypeScript compiler)
|
|
207
|
+
* 2. npx tsgo (if installed as a package)
|
|
208
|
+
* 3. tsc binary (standard TypeScript compiler, verified via --version)
|
|
209
|
+
* 4. npx tsc — but ONLY if it's the real TypeScript compiler, not the
|
|
210
|
+
* unrelated `tsc` npm package that prints "This is not the tsc command
|
|
211
|
+
* you are looking for"
|
|
212
|
+
*/
|
|
145
213
|
function findTypeChecker() {
|
|
214
|
+
// 1. tsgo binary
|
|
146
215
|
const tsgo = spawnSync("which", ["tsgo"], { stdio: "pipe" });
|
|
147
216
|
if (tsgo.status === 0)
|
|
148
217
|
return { cmd: "tsgo", args: [] };
|
|
149
|
-
|
|
218
|
+
// 2. npx tsgo
|
|
219
|
+
const npxTsgo = spawnSync("npx", ["tsgo", "--version"], {
|
|
220
|
+
stdio: "pipe",
|
|
221
|
+
timeout: 5000,
|
|
222
|
+
});
|
|
150
223
|
if (npxTsgo.status === 0)
|
|
151
224
|
return { cmd: "npx", args: ["tsgo"] };
|
|
152
|
-
|
|
225
|
+
// 3. tsc binary (e.g. from `npm install -g typescript`)
|
|
226
|
+
const tscWhich = spawnSync("which", ["tsc"], { stdio: "pipe" });
|
|
227
|
+
if (tscWhich.status === 0) {
|
|
228
|
+
// Verify it's the real TypeScript compiler, not the bogus `tsc` npm package
|
|
229
|
+
const tscVersion = spawnSync("tsc", ["--version"], {
|
|
230
|
+
stdio: "pipe",
|
|
231
|
+
timeout: 5000,
|
|
232
|
+
});
|
|
233
|
+
const output = tscVersion.stdout?.toString() ?? "";
|
|
234
|
+
if (tscVersion.status === 0 && output.includes("Version")) {
|
|
235
|
+
return { cmd: "tsc", args: [] };
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
// 4. npx tsc — validate it's actually TypeScript
|
|
239
|
+
const npxTsc = spawnSync("npx", ["--no-install", "tsc", "--version"], {
|
|
240
|
+
stdio: "pipe",
|
|
241
|
+
timeout: 10000,
|
|
242
|
+
});
|
|
243
|
+
const npxOutput = npxTsc.stdout?.toString() ?? "";
|
|
244
|
+
if (npxTsc.status === 0 && npxOutput.includes("Version")) {
|
|
245
|
+
return { cmd: "npx", args: ["tsc"] };
|
|
246
|
+
}
|
|
247
|
+
// No type checker found
|
|
248
|
+
return null;
|
|
153
249
|
}
|
|
154
250
|
//# 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;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"adk-check.js","sourceRoot":"","sources":["../src/adk-check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EACL,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,UAAU,EACV,aAAa,GACd,MAA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AE,KAAK,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;IACvC,CAAC;IAED,wBAAwB;IACxB,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/cjs/adk-check.js
CHANGED
|
@@ -15,48 +15,70 @@
|
|
|
15
15
|
*/
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.adkCheck = adkCheck;
|
|
18
|
-
const node_path_1 = require("node:path");
|
|
19
|
-
const node_os_1 = require("node:os");
|
|
20
|
-
const node_fs_1 = require("node:fs");
|
|
21
18
|
const node_child_process_1 = require("node:child_process");
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
19
|
+
const node_fs_1 = require("node:fs");
|
|
20
|
+
const node_os_1 = require("node:os");
|
|
21
|
+
const node_path_1 = require("node:path");
|
|
22
|
+
/**
|
|
23
|
+
* Resolve the absolute path to the @slashfi/agents-sdk package.
|
|
24
|
+
* This ensures the preamble works regardless of the script's working directory,
|
|
25
|
+
* since bare specifiers like "@slashfi/agents-sdk" may not resolve from arbitrary cwds.
|
|
26
|
+
*/
|
|
27
|
+
function resolveAgentsSdkPath() {
|
|
28
|
+
try {
|
|
29
|
+
// require.resolve gives us the main entry point, e.g.
|
|
30
|
+
// /root/.bun/install/global/node_modules/@slashfi/agents-sdk/dist/index.js
|
|
31
|
+
const resolved = require.resolve("@slashfi/agents-sdk");
|
|
32
|
+
// Extract package root path
|
|
33
|
+
const marker = "@slashfi/agents-sdk";
|
|
34
|
+
const idx = resolved.indexOf(marker);
|
|
35
|
+
if (idx !== -1) {
|
|
36
|
+
return resolved.substring(0, idx + marker.length);
|
|
37
|
+
}
|
|
38
|
+
return "@slashfi/agents-sdk";
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return "@slashfi/agents-sdk";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function makePreambleCheck(sdkPath) {
|
|
45
|
+
return `import "./.adk_types";\nimport { createAdk, createLocalFsStore } from "${sdkPath}";\nimport { join } from "node:path";\nimport { homedir } from "node:os";\nconst adk = createAdk(\n createLocalFsStore(process.env.ADK_CONFIG_DIR ?? join(homedir(), ".adk")),\n { token: process.env.ATLAS_TOKEN ?? process.env.ADK_TOKEN ?? "" },\n);\n`;
|
|
46
|
+
}
|
|
47
|
+
function makePreambleRun(sdkPath) {
|
|
48
|
+
return `import { createAdk, createLocalFsStore } from "${sdkPath}";\nimport { join } from "node:path";\nimport { homedir } from "node:os";\nconst adk = createAdk(\n createLocalFsStore(process.env.ADK_CONFIG_DIR ?? join(homedir(), ".adk")),\n { token: process.env.ATLAS_TOKEN ?? process.env.ADK_TOKEN ?? "" },\n);\n`;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Create a run wrapper file that injects the adk preamble before the user's code.
|
|
52
|
+
* Works for both inline (-e) and file mode.
|
|
53
|
+
*/
|
|
54
|
+
function writeRunWrapper(tmpFile, preamble, userCode) {
|
|
55
|
+
(0, node_fs_1.writeFileSync)(tmpFile, preamble + userCode);
|
|
56
|
+
}
|
|
37
57
|
async function adkCheck(opts) {
|
|
38
58
|
const configDir = opts.configDir ?? process.env.ADK_CONFIG_DIR ?? (0, node_path_1.join)((0, node_os_1.homedir)(), ".adk");
|
|
39
59
|
const adkTypes = (0, node_path_1.join)(configDir, "adk.d.ts");
|
|
40
60
|
const hasTypes = (0, node_fs_1.existsSync)(adkTypes);
|
|
41
61
|
const isInline = !!opts.code;
|
|
62
|
+
const sdkPath = resolveAgentsSdkPath();
|
|
63
|
+
const PREAMBLE_RUN = makePreambleRun(sdkPath);
|
|
42
64
|
// --no-check: skip typecheck, just run
|
|
43
65
|
if (opts.noCheck && opts.run) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
58
|
-
return { ok: r.status === 0, exitCode: r.status ?? 1 };
|
|
66
|
+
const cwd = isInline ? process.cwd() : (0, node_path_1.dirname)((0, node_path_1.resolve)(opts.file));
|
|
67
|
+
const userCode = isInline
|
|
68
|
+
? opts.code
|
|
69
|
+
: (0, node_fs_1.readFileSync)((0, node_path_1.resolve)(opts.file), "utf-8");
|
|
70
|
+
const tmpFile = (0, node_path_1.join)(cwd, ".adk_run.ts");
|
|
71
|
+
writeRunWrapper(tmpFile, PREAMBLE_RUN, userCode);
|
|
72
|
+
const r = (0, node_child_process_1.spawnSync)("bun", ["run", tmpFile], {
|
|
73
|
+
cwd,
|
|
74
|
+
stdio: "inherit",
|
|
75
|
+
env: process.env,
|
|
76
|
+
});
|
|
77
|
+
try {
|
|
78
|
+
(0, node_fs_1.unlinkSync)(tmpFile);
|
|
59
79
|
}
|
|
80
|
+
catch { }
|
|
81
|
+
return { ok: r.status === 0, exitCode: r.status ?? 1 };
|
|
60
82
|
}
|
|
61
83
|
if (!hasTypes) {
|
|
62
84
|
console.error("\x1b[33m\u26a0\x1b[0m No adk.d.ts found. Run `adk sync` first to generate agent types.");
|
|
@@ -65,10 +87,11 @@ async function adkCheck(opts) {
|
|
|
65
87
|
let checkFile;
|
|
66
88
|
let originalFile;
|
|
67
89
|
const cleanup = [];
|
|
90
|
+
const PREAMBLE_CHECK = makePreambleCheck("@slashfi/agents-sdk");
|
|
68
91
|
if (isInline) {
|
|
69
92
|
cwd = process.cwd();
|
|
70
93
|
checkFile = (0, node_path_1.join)(cwd, ".adk_check.ts");
|
|
71
|
-
(0, node_fs_1.writeFileSync)(checkFile,
|
|
94
|
+
(0, node_fs_1.writeFileSync)(checkFile, PREAMBLE_CHECK + opts.code);
|
|
72
95
|
cleanup.push(checkFile);
|
|
73
96
|
}
|
|
74
97
|
else if (opts.file) {
|
|
@@ -79,8 +102,10 @@ async function adkCheck(opts) {
|
|
|
79
102
|
}
|
|
80
103
|
cwd = (0, node_path_1.dirname)(originalFile);
|
|
81
104
|
checkFile = (0, node_path_1.join)(cwd, `.adk_check_${(0, node_path_1.basename)(originalFile)}`);
|
|
105
|
+
// File mode: inject preamble so `adk` is typed and available
|
|
82
106
|
const typesImport = hasTypes ? `import "./.adk_types";\n` : "";
|
|
83
|
-
|
|
107
|
+
const preambleNoTypes = PREAMBLE_CHECK.replace(`import "./.adk_types";\n`, "");
|
|
108
|
+
(0, node_fs_1.writeFileSync)(checkFile, typesImport + preambleNoTypes + (0, node_fs_1.readFileSync)(originalFile, "utf-8"));
|
|
84
109
|
cleanup.push(checkFile);
|
|
85
110
|
}
|
|
86
111
|
else {
|
|
@@ -111,9 +136,39 @@ async function adkCheck(opts) {
|
|
|
111
136
|
cleanup.push(tsconfigFile);
|
|
112
137
|
// Find type checker
|
|
113
138
|
const checker = findTypeChecker();
|
|
139
|
+
if (!checker) {
|
|
140
|
+
console.error("\x1b[33m\u26a0\x1b[0m No TypeScript type checker found (tsgo or tsc). Skipping type check.");
|
|
141
|
+
for (const f of cleanup) {
|
|
142
|
+
try {
|
|
143
|
+
(0, node_fs_1.unlinkSync)(f);
|
|
144
|
+
}
|
|
145
|
+
catch { }
|
|
146
|
+
}
|
|
147
|
+
// Still run if requested
|
|
148
|
+
if (opts.run) {
|
|
149
|
+
const userCode = isInline
|
|
150
|
+
? opts.code
|
|
151
|
+
: (0, node_fs_1.readFileSync)(originalFile, "utf-8");
|
|
152
|
+
const tmpFile = (0, node_path_1.join)(cwd, ".adk_run.ts");
|
|
153
|
+
writeRunWrapper(tmpFile, PREAMBLE_RUN, userCode);
|
|
154
|
+
const r = (0, node_child_process_1.spawnSync)("bun", ["run", tmpFile], {
|
|
155
|
+
cwd,
|
|
156
|
+
stdio: "inherit",
|
|
157
|
+
env: process.env,
|
|
158
|
+
});
|
|
159
|
+
try {
|
|
160
|
+
(0, node_fs_1.unlinkSync)(tmpFile);
|
|
161
|
+
}
|
|
162
|
+
catch { }
|
|
163
|
+
return { ok: r.status === 0, exitCode: r.status ?? 1 };
|
|
164
|
+
}
|
|
165
|
+
return { ok: true, exitCode: 0 };
|
|
166
|
+
}
|
|
114
167
|
// Type-check
|
|
115
168
|
const result = (0, node_child_process_1.spawnSync)(checker.cmd, [...checker.args, "--project", tsconfigFile], {
|
|
116
|
-
cwd,
|
|
169
|
+
cwd,
|
|
170
|
+
stdio: "inherit",
|
|
171
|
+
env: process.env,
|
|
117
172
|
});
|
|
118
173
|
// Clean up
|
|
119
174
|
for (const f of cleanup) {
|
|
@@ -128,30 +183,71 @@ async function adkCheck(opts) {
|
|
|
128
183
|
console.error("\x1b[32m\u2713\x1b[0m Type check passed");
|
|
129
184
|
// Run
|
|
130
185
|
if (opts.run) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
186
|
+
const userCode = isInline
|
|
187
|
+
? opts.code
|
|
188
|
+
: (0, node_fs_1.readFileSync)(originalFile, "utf-8");
|
|
189
|
+
const tmpFile = (0, node_path_1.join)(cwd, ".adk_run.ts");
|
|
190
|
+
writeRunWrapper(tmpFile, PREAMBLE_RUN, userCode);
|
|
191
|
+
const runResult = (0, node_child_process_1.spawnSync)("bun", ["run", tmpFile], {
|
|
192
|
+
cwd,
|
|
193
|
+
stdio: "inherit",
|
|
194
|
+
env: process.env,
|
|
195
|
+
});
|
|
196
|
+
try {
|
|
197
|
+
(0, node_fs_1.unlinkSync)(tmpFile);
|
|
143
198
|
}
|
|
199
|
+
catch { }
|
|
144
200
|
return { ok: runResult.status === 0, exitCode: runResult.status ?? 1 };
|
|
145
201
|
}
|
|
146
202
|
return { ok: true, exitCode: 0 };
|
|
147
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* Find a working TypeScript type checker.
|
|
206
|
+
* Returns null if none found — callers should skip type checking gracefully.
|
|
207
|
+
*
|
|
208
|
+
* Checks:
|
|
209
|
+
* 1. tsgo binary (fastest — native TypeScript compiler)
|
|
210
|
+
* 2. npx tsgo (if installed as a package)
|
|
211
|
+
* 3. tsc binary (standard TypeScript compiler, verified via --version)
|
|
212
|
+
* 4. npx tsc — but ONLY if it's the real TypeScript compiler, not the
|
|
213
|
+
* unrelated `tsc` npm package that prints "This is not the tsc command
|
|
214
|
+
* you are looking for"
|
|
215
|
+
*/
|
|
148
216
|
function findTypeChecker() {
|
|
217
|
+
// 1. tsgo binary
|
|
149
218
|
const tsgo = (0, node_child_process_1.spawnSync)("which", ["tsgo"], { stdio: "pipe" });
|
|
150
219
|
if (tsgo.status === 0)
|
|
151
220
|
return { cmd: "tsgo", args: [] };
|
|
152
|
-
|
|
221
|
+
// 2. npx tsgo
|
|
222
|
+
const npxTsgo = (0, node_child_process_1.spawnSync)("npx", ["tsgo", "--version"], {
|
|
223
|
+
stdio: "pipe",
|
|
224
|
+
timeout: 5000,
|
|
225
|
+
});
|
|
153
226
|
if (npxTsgo.status === 0)
|
|
154
227
|
return { cmd: "npx", args: ["tsgo"] };
|
|
155
|
-
|
|
228
|
+
// 3. tsc binary (e.g. from `npm install -g typescript`)
|
|
229
|
+
const tscWhich = (0, node_child_process_1.spawnSync)("which", ["tsc"], { stdio: "pipe" });
|
|
230
|
+
if (tscWhich.status === 0) {
|
|
231
|
+
// Verify it's the real TypeScript compiler, not the bogus `tsc` npm package
|
|
232
|
+
const tscVersion = (0, node_child_process_1.spawnSync)("tsc", ["--version"], {
|
|
233
|
+
stdio: "pipe",
|
|
234
|
+
timeout: 5000,
|
|
235
|
+
});
|
|
236
|
+
const output = tscVersion.stdout?.toString() ?? "";
|
|
237
|
+
if (tscVersion.status === 0 && output.includes("Version")) {
|
|
238
|
+
return { cmd: "tsc", args: [] };
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// 4. npx tsc — validate it's actually TypeScript
|
|
242
|
+
const npxTsc = (0, node_child_process_1.spawnSync)("npx", ["--no-install", "tsc", "--version"], {
|
|
243
|
+
stdio: "pipe",
|
|
244
|
+
timeout: 10000,
|
|
245
|
+
});
|
|
246
|
+
const npxOutput = npxTsc.stdout?.toString() ?? "";
|
|
247
|
+
if (npxTsc.status === 0 && npxOutput.includes("Version")) {
|
|
248
|
+
return { cmd: "npx", args: ["tsc"] };
|
|
249
|
+
}
|
|
250
|
+
// No type checker found
|
|
251
|
+
return null;
|
|
156
252
|
}
|
|
157
253
|
//# sourceMappingURL=adk-check.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adk-check.js","sourceRoot":"","sources":["../../src/adk-check.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;
|
|
1
|
+
{"version":3,"file":"adk-check.js","sourceRoot":"","sources":["../../src/adk-check.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;AA+DH,4BA8KC;AA3OD,2DAA+C;AAC/C,qCAMiB;AACjB,qCAAkC;AAClC,yCAA6D;AAU7D;;;;GAIG;AACH,SAAS,oBAAoB;IAC3B,IAAI,CAAC;QACH,sDAAsD;QACtD,2EAA2E;QAC3E,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;QACxD,4BAA4B;QAC5B,MAAM,MAAM,GAAG,qBAAqB,CAAC;QACrC,MAAM,GAAG,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACrC,IAAI,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;YACf,OAAO,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,qBAAqB,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,O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EAAE,CAAC,CAAC;IAChE,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,4EAA4E;QAC5E,MAAM,UAAU,GAAG,IAAA,8BAAS,EAAC,KAAK,EAAE,CAAC,WAAW,CAAC,EAAE;YACjD,KAAK,EAAE,MAAM;YACb,OAAO,EAAE,IAAI;SACd,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;QACnD,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;YAC1D,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;QAClC,CAAC;IACH,CAAC;IAED,iDAAiD;IACjD,MAAM,MAAM,GAAG,IAAA,8BAAS,EAAC,KAAK,EAAE,CAAC,cAAc,EAAE,KAAK,EAAE,WAAW,CAAC,EAAE;QACpE,KAAK,EAAE,MAAM;QACb,OAAO,EAAE,KAAK;KACf,CAAC,CAAC;IACH,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAClD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QACzD,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;IACvC,CAAC;IAED,wBAAwB;IACxB,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
package/src/adk-check.ts
CHANGED
|
@@ -13,10 +13,16 @@
|
|
|
13
13
|
* adk run --no-check -e "code" Execute inline without type-checking
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import { join, dirname, basename, resolve } from "node:path";
|
|
17
|
-
import { homedir } from "node:os";
|
|
18
|
-
import { existsSync, writeFileSync, readFileSync, unlinkSync, copyFileSync } from "node:fs";
|
|
19
16
|
import { spawnSync } from "node:child_process";
|
|
17
|
+
import {
|
|
18
|
+
copyFileSync,
|
|
19
|
+
existsSync,
|
|
20
|
+
readFileSync,
|
|
21
|
+
unlinkSync,
|
|
22
|
+
writeFileSync,
|
|
23
|
+
} from "node:fs";
|
|
24
|
+
import { homedir } from "node:os";
|
|
25
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
20
26
|
|
|
21
27
|
export interface CheckOptions {
|
|
22
28
|
file?: string;
|
|
@@ -26,62 +32,94 @@ export interface CheckOptions {
|
|
|
26
32
|
configDir?: string;
|
|
27
33
|
}
|
|
28
34
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Resolve the absolute path to the @slashfi/agents-sdk package.
|
|
37
|
+
* This ensures the preamble works regardless of the script's working directory,
|
|
38
|
+
* since bare specifiers like "@slashfi/agents-sdk" may not resolve from arbitrary cwds.
|
|
39
|
+
*/
|
|
40
|
+
function resolveAgentsSdkPath(): string {
|
|
41
|
+
try {
|
|
42
|
+
// require.resolve gives us the main entry point, e.g.
|
|
43
|
+
// /root/.bun/install/global/node_modules/@slashfi/agents-sdk/dist/index.js
|
|
44
|
+
const resolved = require.resolve("@slashfi/agents-sdk");
|
|
45
|
+
// Extract package root path
|
|
46
|
+
const marker = "@slashfi/agents-sdk";
|
|
47
|
+
const idx = resolved.indexOf(marker);
|
|
48
|
+
if (idx !== -1) {
|
|
49
|
+
return resolved.substring(0, idx + marker.length);
|
|
50
|
+
}
|
|
51
|
+
return "@slashfi/agents-sdk";
|
|
52
|
+
} catch {
|
|
53
|
+
return "@slashfi/agents-sdk";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function makePreambleCheck(sdkPath: string): string {
|
|
58
|
+
return `import "./.adk_types";\nimport { createAdk, createLocalFsStore } from "${sdkPath}";\nimport { join } from "node:path";\nimport { homedir } from "node:os";\nconst adk = createAdk(\n createLocalFsStore(process.env.ADK_CONFIG_DIR ?? join(homedir(), ".adk")),\n { token: process.env.ATLAS_TOKEN ?? process.env.ADK_TOKEN ?? "" },\n);\n`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function makePreambleRun(sdkPath: string): string {
|
|
62
|
+
return `import { createAdk, createLocalFsStore } from "${sdkPath}";\nimport { join } from "node:path";\nimport { homedir } from "node:os";\nconst adk = createAdk(\n createLocalFsStore(process.env.ADK_CONFIG_DIR ?? join(homedir(), ".adk")),\n { token: process.env.ATLAS_TOKEN ?? process.env.ADK_TOKEN ?? "" },\n);\n`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Create a run wrapper file that injects the adk preamble before the user's code.
|
|
67
|
+
* Works for both inline (-e) and file mode.
|
|
68
|
+
*/
|
|
69
|
+
function writeRunWrapper(
|
|
70
|
+
tmpFile: string,
|
|
71
|
+
preamble: string,
|
|
72
|
+
userCode: string,
|
|
73
|
+
): void {
|
|
74
|
+
writeFileSync(tmpFile, preamble + userCode);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export async function adkCheck(
|
|
78
|
+
opts: CheckOptions,
|
|
79
|
+
): Promise<{ ok: boolean; exitCode: number }> {
|
|
80
|
+
const configDir =
|
|
81
|
+
opts.configDir ?? process.env.ADK_CONFIG_DIR ?? join(homedir(), ".adk");
|
|
52
82
|
const adkTypes = join(configDir, "adk.d.ts");
|
|
53
83
|
const hasTypes = existsSync(adkTypes);
|
|
54
84
|
const isInline = !!opts.code;
|
|
85
|
+
const sdkPath = resolveAgentsSdkPath();
|
|
86
|
+
const PREAMBLE_RUN = makePreambleRun(sdkPath);
|
|
55
87
|
|
|
56
88
|
// --no-check: skip typecheck, just run
|
|
57
89
|
if (opts.noCheck && opts.run) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
90
|
+
const cwd = isInline ? process.cwd() : dirname(resolve(opts.file!));
|
|
91
|
+
const userCode = isInline
|
|
92
|
+
? opts.code!
|
|
93
|
+
: readFileSync(resolve(opts.file!), "utf-8");
|
|
94
|
+
const tmpFile = join(cwd, ".adk_run.ts");
|
|
95
|
+
writeRunWrapper(tmpFile, PREAMBLE_RUN, userCode);
|
|
96
|
+
const r = spawnSync("bun", ["run", tmpFile], {
|
|
97
|
+
cwd,
|
|
98
|
+
stdio: "inherit",
|
|
99
|
+
env: process.env,
|
|
100
|
+
});
|
|
101
|
+
try {
|
|
102
|
+
unlinkSync(tmpFile);
|
|
103
|
+
} catch {}
|
|
104
|
+
return { ok: r.status === 0, exitCode: r.status ?? 1 };
|
|
70
105
|
}
|
|
71
106
|
|
|
72
107
|
if (!hasTypes) {
|
|
73
|
-
console.error(
|
|
108
|
+
console.error(
|
|
109
|
+
"\x1b[33m\u26a0\x1b[0m No adk.d.ts found. Run `adk sync` first to generate agent types.",
|
|
110
|
+
);
|
|
74
111
|
}
|
|
75
112
|
|
|
76
113
|
let cwd: string;
|
|
77
114
|
let checkFile: string;
|
|
78
115
|
let originalFile: string | undefined;
|
|
79
116
|
const cleanup: string[] = [];
|
|
117
|
+
const PREAMBLE_CHECK = makePreambleCheck("@slashfi/agents-sdk");
|
|
80
118
|
|
|
81
119
|
if (isInline) {
|
|
82
120
|
cwd = process.cwd();
|
|
83
121
|
checkFile = join(cwd, ".adk_check.ts");
|
|
84
|
-
writeFileSync(checkFile,
|
|
122
|
+
writeFileSync(checkFile, PREAMBLE_CHECK + opts.code);
|
|
85
123
|
cleanup.push(checkFile);
|
|
86
124
|
} else if (opts.file) {
|
|
87
125
|
originalFile = resolve(opts.file);
|
|
@@ -91,8 +129,16 @@ export async function adkCheck(opts: CheckOptions): Promise<{ ok: boolean; exitC
|
|
|
91
129
|
}
|
|
92
130
|
cwd = dirname(originalFile);
|
|
93
131
|
checkFile = join(cwd, `.adk_check_${basename(originalFile)}`);
|
|
132
|
+
// File mode: inject preamble so `adk` is typed and available
|
|
94
133
|
const typesImport = hasTypes ? `import "./.adk_types";\n` : "";
|
|
95
|
-
|
|
134
|
+
const preambleNoTypes = PREAMBLE_CHECK.replace(
|
|
135
|
+
`import "./.adk_types";\n`,
|
|
136
|
+
"",
|
|
137
|
+
);
|
|
138
|
+
writeFileSync(
|
|
139
|
+
checkFile,
|
|
140
|
+
typesImport + preambleNoTypes + readFileSync(originalFile, "utf-8"),
|
|
141
|
+
);
|
|
96
142
|
cleanup.push(checkFile);
|
|
97
143
|
} else {
|
|
98
144
|
console.error('Usage: adk check <file> | adk check -e "<code>"');
|
|
@@ -108,31 +154,74 @@ export async function adkCheck(opts: CheckOptions): Promise<{ ok: boolean; exitC
|
|
|
108
154
|
|
|
109
155
|
// Write minimal tsconfig
|
|
110
156
|
const tsconfigFile = join(cwd, ".adk_tsconfig.json");
|
|
111
|
-
writeFileSync(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
157
|
+
writeFileSync(
|
|
158
|
+
tsconfigFile,
|
|
159
|
+
JSON.stringify({
|
|
160
|
+
compilerOptions: {
|
|
161
|
+
target: "ES2022",
|
|
162
|
+
module: "ESNext",
|
|
163
|
+
moduleResolution: "bundler",
|
|
164
|
+
esModuleInterop: true,
|
|
165
|
+
strict: true,
|
|
166
|
+
noEmit: true,
|
|
167
|
+
skipLibCheck: true,
|
|
168
|
+
types: ["node"],
|
|
169
|
+
},
|
|
170
|
+
include: [basename(checkFile)],
|
|
171
|
+
}),
|
|
172
|
+
);
|
|
124
173
|
cleanup.push(tsconfigFile);
|
|
125
174
|
|
|
126
175
|
// Find type checker
|
|
127
176
|
const checker = findTypeChecker();
|
|
128
177
|
|
|
178
|
+
if (!checker) {
|
|
179
|
+
console.error(
|
|
180
|
+
"\x1b[33m\u26a0\x1b[0m No TypeScript type checker found (tsgo or tsc). Skipping type check.",
|
|
181
|
+
);
|
|
182
|
+
for (const f of cleanup) {
|
|
183
|
+
try {
|
|
184
|
+
unlinkSync(f);
|
|
185
|
+
} catch {}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Still run if requested
|
|
189
|
+
if (opts.run) {
|
|
190
|
+
const userCode = isInline
|
|
191
|
+
? opts.code!
|
|
192
|
+
: readFileSync(originalFile!, "utf-8");
|
|
193
|
+
const tmpFile = join(cwd, ".adk_run.ts");
|
|
194
|
+
writeRunWrapper(tmpFile, PREAMBLE_RUN, userCode);
|
|
195
|
+
const r = spawnSync("bun", ["run", tmpFile], {
|
|
196
|
+
cwd,
|
|
197
|
+
stdio: "inherit",
|
|
198
|
+
env: process.env,
|
|
199
|
+
});
|
|
200
|
+
try {
|
|
201
|
+
unlinkSync(tmpFile);
|
|
202
|
+
} catch {}
|
|
203
|
+
return { ok: r.status === 0, exitCode: r.status ?? 1 };
|
|
204
|
+
}
|
|
205
|
+
return { ok: true, exitCode: 0 };
|
|
206
|
+
}
|
|
207
|
+
|
|
129
208
|
// Type-check
|
|
130
|
-
const result = spawnSync(
|
|
131
|
-
|
|
132
|
-
|
|
209
|
+
const result = spawnSync(
|
|
210
|
+
checker.cmd,
|
|
211
|
+
[...checker.args, "--project", tsconfigFile],
|
|
212
|
+
{
|
|
213
|
+
cwd,
|
|
214
|
+
stdio: "inherit",
|
|
215
|
+
env: process.env,
|
|
216
|
+
},
|
|
217
|
+
);
|
|
133
218
|
|
|
134
219
|
// Clean up
|
|
135
|
-
for (const f of cleanup) {
|
|
220
|
+
for (const f of cleanup) {
|
|
221
|
+
try {
|
|
222
|
+
unlinkSync(f);
|
|
223
|
+
} catch {}
|
|
224
|
+
}
|
|
136
225
|
|
|
137
226
|
if (result.status !== 0) {
|
|
138
227
|
return { ok: false, exitCode: result.status ?? 1 };
|
|
@@ -142,25 +231,73 @@ export async function adkCheck(opts: CheckOptions): Promise<{ ok: boolean; exitC
|
|
|
142
231
|
|
|
143
232
|
// Run
|
|
144
233
|
if (opts.run) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
234
|
+
const userCode = isInline
|
|
235
|
+
? opts.code!
|
|
236
|
+
: readFileSync(originalFile!, "utf-8");
|
|
237
|
+
const tmpFile = join(cwd, ".adk_run.ts");
|
|
238
|
+
writeRunWrapper(tmpFile, PREAMBLE_RUN, userCode);
|
|
239
|
+
const runResult = spawnSync("bun", ["run", tmpFile], {
|
|
240
|
+
cwd,
|
|
241
|
+
stdio: "inherit",
|
|
242
|
+
env: process.env,
|
|
243
|
+
});
|
|
244
|
+
try {
|
|
245
|
+
unlinkSync(tmpFile);
|
|
246
|
+
} catch {}
|
|
154
247
|
return { ok: runResult.status === 0, exitCode: runResult.status ?? 1 };
|
|
155
248
|
}
|
|
156
249
|
|
|
157
250
|
return { ok: true, exitCode: 0 };
|
|
158
251
|
}
|
|
159
252
|
|
|
160
|
-
|
|
253
|
+
/**
|
|
254
|
+
* Find a working TypeScript type checker.
|
|
255
|
+
* Returns null if none found — callers should skip type checking gracefully.
|
|
256
|
+
*
|
|
257
|
+
* Checks:
|
|
258
|
+
* 1. tsgo binary (fastest — native TypeScript compiler)
|
|
259
|
+
* 2. npx tsgo (if installed as a package)
|
|
260
|
+
* 3. tsc binary (standard TypeScript compiler, verified via --version)
|
|
261
|
+
* 4. npx tsc — but ONLY if it's the real TypeScript compiler, not the
|
|
262
|
+
* unrelated `tsc` npm package that prints "This is not the tsc command
|
|
263
|
+
* you are looking for"
|
|
264
|
+
*/
|
|
265
|
+
function findTypeChecker(): { cmd: string; args: string[] } | null {
|
|
266
|
+
// 1. tsgo binary
|
|
161
267
|
const tsgo = spawnSync("which", ["tsgo"], { stdio: "pipe" });
|
|
162
268
|
if (tsgo.status === 0) return { cmd: "tsgo", args: [] };
|
|
163
|
-
|
|
269
|
+
|
|
270
|
+
// 2. npx tsgo
|
|
271
|
+
const npxTsgo = spawnSync("npx", ["tsgo", "--version"], {
|
|
272
|
+
stdio: "pipe",
|
|
273
|
+
timeout: 5000,
|
|
274
|
+
});
|
|
164
275
|
if (npxTsgo.status === 0) return { cmd: "npx", args: ["tsgo"] };
|
|
165
|
-
|
|
276
|
+
|
|
277
|
+
// 3. tsc binary (e.g. from `npm install -g typescript`)
|
|
278
|
+
const tscWhich = spawnSync("which", ["tsc"], { stdio: "pipe" });
|
|
279
|
+
if (tscWhich.status === 0) {
|
|
280
|
+
// Verify it's the real TypeScript compiler, not the bogus `tsc` npm package
|
|
281
|
+
const tscVersion = spawnSync("tsc", ["--version"], {
|
|
282
|
+
stdio: "pipe",
|
|
283
|
+
timeout: 5000,
|
|
284
|
+
});
|
|
285
|
+
const output = tscVersion.stdout?.toString() ?? "";
|
|
286
|
+
if (tscVersion.status === 0 && output.includes("Version")) {
|
|
287
|
+
return { cmd: "tsc", args: [] };
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// 4. npx tsc — validate it's actually TypeScript
|
|
292
|
+
const npxTsc = spawnSync("npx", ["--no-install", "tsc", "--version"], {
|
|
293
|
+
stdio: "pipe",
|
|
294
|
+
timeout: 10000,
|
|
295
|
+
});
|
|
296
|
+
const npxOutput = npxTsc.stdout?.toString() ?? "";
|
|
297
|
+
if (npxTsc.status === 0 && npxOutput.includes("Version")) {
|
|
298
|
+
return { cmd: "npx", args: ["tsc"] };
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// No type checker found
|
|
302
|
+
return null;
|
|
166
303
|
}
|