thinkwell 0.3.2 → 0.4.0
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/bin/thinkwell +245 -122
- package/dist/cli/loader.d.ts +129 -0
- package/dist/cli/loader.d.ts.map +1 -0
- package/dist/cli/loader.js +381 -0
- package/dist/cli/loader.js.map +1 -0
- package/dist/cli/main-pkg.d.ts +18 -0
- package/dist/cli/main-pkg.d.ts.map +1 -0
- package/dist/cli/main.js +2 -2
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/schema.d.ts +107 -0
- package/dist/cli/schema.d.ts.map +1 -0
- package/dist/cli/schema.js +294 -0
- package/dist/cli/schema.js.map +1 -0
- package/dist-pkg/acp.cjs +7725 -0
- package/dist-pkg/cli-loader.cjs +239018 -0
- package/dist-pkg/protocol.cjs +186 -0
- package/dist-pkg/thinkwell.cjs +20335 -0
- package/package.json +40 -12
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom script loader for the pkg-compiled binary.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the runtime infrastructure for loading and executing
|
|
5
|
+
* user scripts in the pkg binary. It handles:
|
|
6
|
+
*
|
|
7
|
+
* 1. **Module Resolution**: Routes imports to the appropriate source:
|
|
8
|
+
* - `thinkwell:*` imports → bundled packages via `global.__bundled__`
|
|
9
|
+
* - thinkwell packages → bundled packages via `global.__bundled__`
|
|
10
|
+
* - External packages → user's node_modules via `require.resolve()`
|
|
11
|
+
*
|
|
12
|
+
* 2. **Import Transformation**: Rewrites user script imports before execution:
|
|
13
|
+
* - `import { Agent } from "thinkwell:agent"` → bundled thinkwell
|
|
14
|
+
* - `import { Agent } from "thinkwell"` → bundled thinkwell
|
|
15
|
+
*
|
|
16
|
+
* 3. **@JSONSchema Processing**: Generates JSON schemas for marked types and
|
|
17
|
+
* injects namespace declarations with SchemaProvider implementations.
|
|
18
|
+
*
|
|
19
|
+
* 4. **Script Loading**: Uses Node's require() with temp files for transformed scripts
|
|
20
|
+
*
|
|
21
|
+
* Unlike the Bun plugin which runs at bundle time, this loader operates at
|
|
22
|
+
* runtime when the user script is executed.
|
|
23
|
+
*/
|
|
24
|
+
import { readFileSync, mkdirSync, writeFileSync, unlinkSync } from "node:fs";
|
|
25
|
+
import { dirname, join, isAbsolute, resolve } from "node:path";
|
|
26
|
+
import { createRequire } from "node:module";
|
|
27
|
+
import { hasJsonSchemaMarkers, transformJsonSchemas } from "./schema.js";
|
|
28
|
+
/**
|
|
29
|
+
* Maps thinkwell:* URI scheme to npm package names.
|
|
30
|
+
* Duplicated from bun-plugin for pkg binary independence.
|
|
31
|
+
*/
|
|
32
|
+
const THINKWELL_MODULES = {
|
|
33
|
+
agent: "thinkwell",
|
|
34
|
+
acp: "@thinkwell/acp",
|
|
35
|
+
protocol: "@thinkwell/protocol",
|
|
36
|
+
connectors: "thinkwell",
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Package names that should be resolved from bundled modules.
|
|
40
|
+
*/
|
|
41
|
+
const BUNDLED_PACKAGES = ["thinkwell", "@thinkwell/acp", "@thinkwell/protocol"];
|
|
42
|
+
/**
|
|
43
|
+
* Initialize the bundled module registry.
|
|
44
|
+
*
|
|
45
|
+
* This should be called from main-pkg.cjs with the bundled package exports.
|
|
46
|
+
* The registry is used by createCustomRequire to route thinkwell imports.
|
|
47
|
+
*
|
|
48
|
+
* @param modules - Map of package names to their exports
|
|
49
|
+
*/
|
|
50
|
+
export function initializeBundledRegistry(modules) {
|
|
51
|
+
global.__bundled__ = modules;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Check if a module name refers to a bundled package.
|
|
55
|
+
*/
|
|
56
|
+
function isBundledPackage(moduleName) {
|
|
57
|
+
return BUNDLED_PACKAGES.includes(moduleName);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Strip shebang line from source if present.
|
|
61
|
+
*
|
|
62
|
+
* Shebangs are valid for executable scripts but not valid JS/TS syntax.
|
|
63
|
+
* We need to strip them before Module._compile processes the source.
|
|
64
|
+
*
|
|
65
|
+
* @param source - The script source code
|
|
66
|
+
* @returns Tuple of [shebang line or empty string, rest of source]
|
|
67
|
+
*/
|
|
68
|
+
export function extractShebang(source) {
|
|
69
|
+
if (source.startsWith("#!")) {
|
|
70
|
+
const newlineIndex = source.indexOf("\n");
|
|
71
|
+
if (newlineIndex !== -1) {
|
|
72
|
+
return [source.slice(0, newlineIndex + 1), source.slice(newlineIndex + 1)];
|
|
73
|
+
}
|
|
74
|
+
return [source, ""];
|
|
75
|
+
}
|
|
76
|
+
return ["", source];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Transform thinkwell:* imports to use bundled packages.
|
|
80
|
+
*
|
|
81
|
+
* Rewrites import specifiers from the thinkwell:* URI scheme to
|
|
82
|
+
* their corresponding npm package names.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* // Input:
|
|
87
|
+
* import { Agent } from "thinkwell:agent";
|
|
88
|
+
*
|
|
89
|
+
* // Output:
|
|
90
|
+
* import { Agent } from "thinkwell";
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @param source - The script source code
|
|
94
|
+
* @returns The source with thinkwell:* imports rewritten
|
|
95
|
+
*/
|
|
96
|
+
export function rewriteThinkwellImports(source) {
|
|
97
|
+
// Match import/export statements with thinkwell:* specifiers
|
|
98
|
+
// Handles: import { x } from "thinkwell:foo"
|
|
99
|
+
// import x from 'thinkwell:foo'
|
|
100
|
+
// export { x } from "thinkwell:foo"
|
|
101
|
+
return source.replace(/(from\s+['"])thinkwell:(\w+)(['"])/g, (_, prefix, moduleName, suffix) => {
|
|
102
|
+
const npmPackage = THINKWELL_MODULES[moduleName];
|
|
103
|
+
if (npmPackage) {
|
|
104
|
+
return `${prefix}${npmPackage}${suffix}`;
|
|
105
|
+
}
|
|
106
|
+
// Unknown module - leave as is (will error at resolution)
|
|
107
|
+
return `${prefix}thinkwell:${moduleName}${suffix}`;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Transform imports to use the bundled module registry.
|
|
112
|
+
*
|
|
113
|
+
* In the pkg binary, we can't rely on Node's normal module resolution
|
|
114
|
+
* for bundled packages (they're in the /snapshot/ virtual filesystem).
|
|
115
|
+
* This transform rewrites imports to use global.__bundled__ directly.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* // Input:
|
|
120
|
+
* import { Agent } from "thinkwell";
|
|
121
|
+
*
|
|
122
|
+
* // Output:
|
|
123
|
+
* const { Agent } = global.__bundled__["thinkwell"];
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @param source - The script source code
|
|
127
|
+
* @returns The source with bundled package imports transformed
|
|
128
|
+
*/
|
|
129
|
+
export function transformVirtualImports(source) {
|
|
130
|
+
// Match named imports from thinkwell packages
|
|
131
|
+
// Pattern: import { x, y } from "thinkwell" or import { x } from "@thinkwell/acp"
|
|
132
|
+
const importPattern = /import\s+\{([^}]+)\}\s+from\s+['"](@thinkwell\/(?:acp|protocol)|thinkwell)['"]/g;
|
|
133
|
+
source = source.replace(importPattern, (_, imports, packageName) => {
|
|
134
|
+
const cleanImports = imports.trim();
|
|
135
|
+
return `const {${cleanImports}} = global.__bundled__["${packageName}"]`;
|
|
136
|
+
});
|
|
137
|
+
// Match default imports from thinkwell packages
|
|
138
|
+
// Pattern: import Foo from "thinkwell" or import Foo from "@thinkwell/acp"
|
|
139
|
+
const defaultImportPattern = /import\s+(\w+)\s+from\s+['"](@thinkwell\/(?:acp|protocol)|thinkwell)['"]/g;
|
|
140
|
+
source = source.replace(defaultImportPattern, (_, importName, packageName) => {
|
|
141
|
+
return `const ${importName} = global.__bundled__["${packageName}"].default || global.__bundled__["${packageName}"]`;
|
|
142
|
+
});
|
|
143
|
+
// Match namespace imports from thinkwell packages
|
|
144
|
+
// Pattern: import * as Foo from "thinkwell"
|
|
145
|
+
const namespaceImportPattern = /import\s+\*\s+as\s+(\w+)\s+from\s+['"](@thinkwell\/(?:acp|protocol)|thinkwell)['"]/g;
|
|
146
|
+
source = source.replace(namespaceImportPattern, (_, importName, packageName) => {
|
|
147
|
+
return `const ${importName} = global.__bundled__["${packageName}"]`;
|
|
148
|
+
});
|
|
149
|
+
// Match type-only imports (remove them - they're only for TypeScript)
|
|
150
|
+
// Pattern: import type { Foo } from "thinkwell"
|
|
151
|
+
const typeImportPattern = /import\s+type\s+\{[^}]+\}\s+from\s+['"](@thinkwell\/(?:acp|protocol)|thinkwell)['"]\s*;?/g;
|
|
152
|
+
source = source.replace(typeImportPattern, "");
|
|
153
|
+
return source;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Create a custom require function that routes imports appropriately.
|
|
157
|
+
*
|
|
158
|
+
* This function creates a require implementation that:
|
|
159
|
+
* 1. Checks bundled modules first (thinkwell packages)
|
|
160
|
+
* 2. Falls back to require.resolve from the script's directory
|
|
161
|
+
* 3. Falls back to global require for built-in modules
|
|
162
|
+
*
|
|
163
|
+
* @param scriptPath - Absolute path to the user script
|
|
164
|
+
* @returns A require function bound to the script's directory
|
|
165
|
+
*/
|
|
166
|
+
export function createCustomRequire(scriptPath) {
|
|
167
|
+
const scriptDir = dirname(scriptPath);
|
|
168
|
+
const nodeModulesPath = join(scriptDir, "node_modules");
|
|
169
|
+
// Create a base require function using Node's createRequire
|
|
170
|
+
const baseRequire = createRequire(scriptPath);
|
|
171
|
+
function customRequire(moduleName) {
|
|
172
|
+
// First check if it's a bundled module
|
|
173
|
+
if (global.__bundled__ && isBundledPackage(moduleName)) {
|
|
174
|
+
const bundled = global.__bundled__[moduleName];
|
|
175
|
+
if (bundled) {
|
|
176
|
+
return bundled;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
// Try to resolve from the script's directory using baseRequire
|
|
180
|
+
try {
|
|
181
|
+
const resolved = baseRequire.resolve(moduleName, {
|
|
182
|
+
paths: [scriptDir, nodeModulesPath],
|
|
183
|
+
});
|
|
184
|
+
return baseRequire(resolved);
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
// Fall back to the base require without custom paths
|
|
188
|
+
return baseRequire(moduleName);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// Copy over require properties that modules might depend on
|
|
192
|
+
customRequire.resolve = ((id, options) => {
|
|
193
|
+
// Check bundled first
|
|
194
|
+
if (global.__bundled__ && isBundledPackage(id)) {
|
|
195
|
+
// Return a fake path for bundled modules
|
|
196
|
+
return `/__bundled__/${id}`;
|
|
197
|
+
}
|
|
198
|
+
// Try script directory paths first
|
|
199
|
+
const paths = options?.paths ?? [scriptDir, nodeModulesPath];
|
|
200
|
+
try {
|
|
201
|
+
return baseRequire.resolve(id, { paths });
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
return baseRequire.resolve(id, options);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
// Stub paths property
|
|
208
|
+
customRequire.resolve.paths = baseRequire.resolve.paths;
|
|
209
|
+
customRequire.cache = baseRequire.cache;
|
|
210
|
+
customRequire.extensions = baseRequire.extensions;
|
|
211
|
+
customRequire.main = baseRequire.main;
|
|
212
|
+
return customRequire;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Check if source code needs transformation.
|
|
216
|
+
*
|
|
217
|
+
* @param source - The script source code
|
|
218
|
+
* @returns true if the source contains thinkwell imports or @JSONSchema markers
|
|
219
|
+
*/
|
|
220
|
+
function needsTransformation(source) {
|
|
221
|
+
// Check for thinkwell:* URI scheme imports
|
|
222
|
+
if (/from\s+['"]thinkwell:\w+['"]/.test(source)) {
|
|
223
|
+
return true;
|
|
224
|
+
}
|
|
225
|
+
// Check for bundled package imports
|
|
226
|
+
if (/from\s+['"](?:thinkwell|@thinkwell\/(?:acp|protocol))['"]/.test(source)) {
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
// Check for @JSONSchema markers
|
|
230
|
+
if (hasJsonSchemaMarkers(source)) {
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Generate a preamble that patches import.meta properties to point to the original script.
|
|
237
|
+
*
|
|
238
|
+
* When we transform a script and write it to a temp file, import.meta.url, dirname,
|
|
239
|
+
* and filename would point to the temp file instead of the original. This breaks
|
|
240
|
+
* scripts that use these properties to locate sibling files.
|
|
241
|
+
*
|
|
242
|
+
* We patch import.meta by redefining these properties to return values based on
|
|
243
|
+
* the original script's location.
|
|
244
|
+
*
|
|
245
|
+
* @param originalPath - Absolute path to the original script
|
|
246
|
+
* @returns JavaScript code to prepend to the transformed script
|
|
247
|
+
*/
|
|
248
|
+
function generateImportMetaPatch(originalPath) {
|
|
249
|
+
// Convert to file:// URL format
|
|
250
|
+
const fileUrl = `file://${originalPath}`;
|
|
251
|
+
// Get dirname and filename from the path
|
|
252
|
+
const originalDir = dirname(originalPath);
|
|
253
|
+
const originalFilename = originalPath;
|
|
254
|
+
// Escape backslashes and quotes for string literals
|
|
255
|
+
const escape = (s) => s.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
256
|
+
return [
|
|
257
|
+
`Object.defineProperty(import.meta, 'url', { value: '${escape(fileUrl)}', writable: false, configurable: true });`,
|
|
258
|
+
`Object.defineProperty(import.meta, 'dirname', { value: '${escape(originalDir)}', writable: false, configurable: true });`,
|
|
259
|
+
`Object.defineProperty(import.meta, 'filename', { value: '${escape(originalFilename)}', writable: false, configurable: true });`,
|
|
260
|
+
"",
|
|
261
|
+
].join("\n");
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Load and execute a user script with custom module resolution.
|
|
265
|
+
*
|
|
266
|
+
* This function handles two loading strategies:
|
|
267
|
+
*
|
|
268
|
+
* 1. **Direct require()** - For scripts that don't use thinkwell imports.
|
|
269
|
+
* This leverages Node's --experimental-strip-types for TypeScript support.
|
|
270
|
+
*
|
|
271
|
+
* 2. **Transform and compile** - For scripts that use thinkwell:* imports
|
|
272
|
+
* or import from bundled packages. The script is transformed and written
|
|
273
|
+
* to a temp file, then required (which applies type stripping).
|
|
274
|
+
*
|
|
275
|
+
* @param scriptPath - Absolute path to the script to load
|
|
276
|
+
* @returns The module exports from the script
|
|
277
|
+
* @throws Error if the script cannot be loaded or executed
|
|
278
|
+
*/
|
|
279
|
+
export function loadScript(scriptPath) {
|
|
280
|
+
// Ensure absolute path
|
|
281
|
+
const absolutePath = isAbsolute(scriptPath)
|
|
282
|
+
? scriptPath
|
|
283
|
+
: resolve(process.cwd(), scriptPath);
|
|
284
|
+
// Read the script source to check if transformation is needed
|
|
285
|
+
const rawSource = readFileSync(absolutePath, "utf-8");
|
|
286
|
+
// Strip shebang for analysis (shebang is stripped by Node's loader anyway)
|
|
287
|
+
const [, sourceWithoutShebang] = extractShebang(rawSource);
|
|
288
|
+
// Check if source needs our transformation
|
|
289
|
+
if (!needsTransformation(sourceWithoutShebang)) {
|
|
290
|
+
// No transformation needed - use direct require()
|
|
291
|
+
// This preserves Node's type stripping for TypeScript files
|
|
292
|
+
const baseRequire = createRequire(absolutePath);
|
|
293
|
+
return baseRequire(absolutePath);
|
|
294
|
+
}
|
|
295
|
+
// Source needs transformation - apply transforms and use a temp file
|
|
296
|
+
// Rewrite thinkwell:* imports to npm package names
|
|
297
|
+
let source = rewriteThinkwellImports(sourceWithoutShebang);
|
|
298
|
+
// Process @JSONSchema types (must happen before import transformation
|
|
299
|
+
// because it adds an import statement that also needs transformation)
|
|
300
|
+
source = transformJsonSchemas(absolutePath, source);
|
|
301
|
+
// Transform imports to use bundled modules (global.__bundled__)
|
|
302
|
+
source = transformVirtualImports(source);
|
|
303
|
+
// Prepend import.meta.url patch so scripts can locate sibling files
|
|
304
|
+
source = generateImportMetaPatch(absolutePath) + source;
|
|
305
|
+
// Write transformed source to a temp file
|
|
306
|
+
// Use the same extension to ensure Node applies the right loader
|
|
307
|
+
const ext = absolutePath.endsWith(".ts") ? ".ts" : ".js";
|
|
308
|
+
const tempDir = join(dirname(absolutePath), ".thinkwell-cache");
|
|
309
|
+
const tempFile = join(tempDir, `_transformed_${Date.now()}${ext}`);
|
|
310
|
+
try {
|
|
311
|
+
// Ensure temp directory exists
|
|
312
|
+
mkdirSync(tempDir, { recursive: true });
|
|
313
|
+
}
|
|
314
|
+
catch {
|
|
315
|
+
// Directory may already exist
|
|
316
|
+
}
|
|
317
|
+
try {
|
|
318
|
+
// Write transformed source
|
|
319
|
+
writeFileSync(tempFile, source, "utf-8");
|
|
320
|
+
// Require the transformed file - this uses Node's type stripping
|
|
321
|
+
const baseRequire = createRequire(absolutePath);
|
|
322
|
+
const result = baseRequire(tempFile);
|
|
323
|
+
return result;
|
|
324
|
+
}
|
|
325
|
+
finally {
|
|
326
|
+
// Clean up temp file
|
|
327
|
+
try {
|
|
328
|
+
unlinkSync(tempFile);
|
|
329
|
+
}
|
|
330
|
+
catch {
|
|
331
|
+
// Ignore cleanup errors
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Load and execute a user script, handling both sync and async exports.
|
|
337
|
+
*
|
|
338
|
+
* After loading, this function checks if the script exports a main function
|
|
339
|
+
* or default export and executes it if present.
|
|
340
|
+
*
|
|
341
|
+
* @param scriptPath - Absolute path to the script to load
|
|
342
|
+
* @param args - Additional arguments to pass to the script's argv
|
|
343
|
+
* @returns Promise that resolves when script execution completes
|
|
344
|
+
*/
|
|
345
|
+
export async function runScript(scriptPath, args = []) {
|
|
346
|
+
// Set up process.argv for the script
|
|
347
|
+
const originalArgv = process.argv;
|
|
348
|
+
process.argv = [process.execPath, scriptPath, ...args];
|
|
349
|
+
try {
|
|
350
|
+
const exports = loadScript(scriptPath);
|
|
351
|
+
// Check for common entry point patterns
|
|
352
|
+
if (exports && typeof exports === "object") {
|
|
353
|
+
const mod = exports;
|
|
354
|
+
// Pattern 1: default export function
|
|
355
|
+
if (typeof mod.default === "function") {
|
|
356
|
+
await mod.default();
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
// Pattern 2: main function
|
|
360
|
+
if (typeof mod.main === "function") {
|
|
361
|
+
await mod.main();
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
// Pattern 3: run function
|
|
365
|
+
if (typeof mod.run === "function") {
|
|
366
|
+
await mod.run();
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
// Pattern 4: direct function export
|
|
371
|
+
if (typeof exports === "function") {
|
|
372
|
+
await exports();
|
|
373
|
+
}
|
|
374
|
+
// Otherwise, the script executed its code at module level
|
|
375
|
+
}
|
|
376
|
+
finally {
|
|
377
|
+
// Restore original argv
|
|
378
|
+
process.argv = originalArgv;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/cli/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAezE;;;GAGG;AACH,MAAM,iBAAiB,GAA2B;IAChD,KAAK,EAAE,WAAW;IAClB,GAAG,EAAE,gBAAgB;IACrB,QAAQ,EAAE,qBAAqB;IAC/B,UAAU,EAAE,WAAW;CACxB,CAAC;AAEF;;GAEG;AACH,MAAM,gBAAgB,GAAG,CAAC,WAAW,EAAE,gBAAgB,EAAE,qBAAqB,CAAC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O,KAAK,UAAU,EAAE,CAAC;gBACtC,MAAM,GAAG,CAAC,OAAO,EAAE,CAAC;gBACpB,OAAO;YACT,CAAC;YAED,2BAA2B;YAC3B,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBACnC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;gBACjB,OAAO;YACT,CAAC;YAED,0BAA0B;YAC1B,IAAI,OAAO,GAAG,CAAC,GAAG,KAAK,UAAU,EAAE,CAAC;gBAClC,MAAM,GAAG,CAAC,GAAG,EAAE,CAAC;gBAChB,OAAO;YACT,CAAC;QACH,CAAC;QAED,oCAAoC;QACpC,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;YAClC,MAAM,OAAO,EAAE,CAAC;QAClB,CAAC;QAED,0DAA0D;IAC5D,CAAC;YAAS,CAAC;QACT,wBAAwB;QACxB,OAAO,CAAC,IAAI,GAAG,YAAY,CAAC;IAC9B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Thinkwell CLI - Node.js entry point for pkg-compiled binary.
|
|
4
|
+
*
|
|
5
|
+
* This is the main entry point for the pkg-compiled binary. Unlike the Bun
|
|
6
|
+
* entry point (main.ts), this runs in Node.js with --experimental-strip-types
|
|
7
|
+
* for native TypeScript support.
|
|
8
|
+
*
|
|
9
|
+
* The pkg binary uses a custom loader to:
|
|
10
|
+
* - Route thinkwell:* imports to bundled packages
|
|
11
|
+
* - Resolve external packages from user's node_modules
|
|
12
|
+
* - Handle @JSONSchema type processing
|
|
13
|
+
*
|
|
14
|
+
* Phase 1 stub: This is a minimal implementation to verify pkg bundling works.
|
|
15
|
+
* Full implementation will be added in Phase 2 (Loader) and Phase 3 (CLI).
|
|
16
|
+
*/
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=main-pkg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main-pkg.d.ts","sourceRoot":"","sources":["../../src/cli/main-pkg.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;GAcG"}
|
package/dist/cli/main.js
CHANGED
|
@@ -27,8 +27,8 @@ registerModule("thinkwell", thinkwell);
|
|
|
27
27
|
registerModule("@thinkwell/acp", thinkwellAcp);
|
|
28
28
|
registerModule("@thinkwell/protocol", thinkwellProtocol);
|
|
29
29
|
import { runInit } from "./init-command.js";
|
|
30
|
-
//
|
|
31
|
-
const VERSION = "0.3.
|
|
30
|
+
// Version must be updated manually to match package.json
|
|
31
|
+
const VERSION = "0.3.2";
|
|
32
32
|
function showHelp() {
|
|
33
33
|
console.log(`
|
|
34
34
|
thinkwell - Run TypeScript scripts with automatic schema generation
|
package/dist/cli/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":";AACA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,sEAAsE;AACtE,mFAAmF;AACnF,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,0EAA0E;AAC1E,gFAAgF;AAChF,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,YAAY,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,iBAAiB,MAAM,qBAAqB,CAAC;AAEzD,8DAA8D;AAC9D,kEAAkE;AAClE,cAAc,CAAC,WAAW,EAAE,SAAoC,CAAC,CAAC;AAClE,cAAc,CAAC,gBAAgB,EAAE,YAAuC,CAAC,CAAC;AAC1E,cAAc,CAAC,qBAAqB,EAAE,iBAA4C,CAAC,CAAC;AAEpF,OAAO,EAAE,OAAO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,KAAK,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAEzD,+CAA+C;IAC/C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAC5C,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAClB,OAAO,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;QAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,SAAS,CAAC,OAAO,CAAC,CAAC;AAC3B,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;IACnC,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,OAAO,IAAI,KAAK,EAAE,CAAC,CAAC;IAC7C,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;QACtB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone schema generation for the pkg binary.
|
|
3
|
+
*
|
|
4
|
+
* This module ports the essential schema generation functionality from
|
|
5
|
+
* @thinkwell/bun-plugin for use in the pkg-compiled binary. It handles:
|
|
6
|
+
*
|
|
7
|
+
* 1. **Type Discovery**: Finding types marked with @JSONSchema JSDoc tag
|
|
8
|
+
* 2. **Schema Generation**: Using ts-json-schema-generator to create JSON schemas
|
|
9
|
+
* 3. **Code Injection**: Generating namespace declarations with SchemaProvider
|
|
10
|
+
*
|
|
11
|
+
* Unlike the bun-plugin which operates at bundle time with caching across files,
|
|
12
|
+
* this module operates at runtime on individual user scripts.
|
|
13
|
+
*/
|
|
14
|
+
import ts from "typescript";
|
|
15
|
+
/**
|
|
16
|
+
* Information about a type marked with @JSONSchema.
|
|
17
|
+
*/
|
|
18
|
+
export interface TypeInfo {
|
|
19
|
+
/** The name of the type (interface, type alias, enum, or class) */
|
|
20
|
+
name: string;
|
|
21
|
+
/** The TypeScript AST node */
|
|
22
|
+
node: ts.Node;
|
|
23
|
+
/** The start position of the type declaration in the source */
|
|
24
|
+
startPosition: number;
|
|
25
|
+
/** The end position of the type declaration in the source */
|
|
26
|
+
endPosition: number;
|
|
27
|
+
/** 1-based line number of the type declaration */
|
|
28
|
+
line: number;
|
|
29
|
+
/** 1-based column number of the type declaration */
|
|
30
|
+
column: number;
|
|
31
|
+
/** Length of the type declaration keyword + name (for error underlining) */
|
|
32
|
+
declarationLength: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Find all types marked with @JSONSchema in the given source.
|
|
36
|
+
*
|
|
37
|
+
* @param path - The file path (used for source file creation)
|
|
38
|
+
* @param source - The TypeScript source code
|
|
39
|
+
* @returns Array of TypeInfo for each marked type
|
|
40
|
+
*/
|
|
41
|
+
export declare function findMarkedTypes(path: string, source: string): TypeInfo[];
|
|
42
|
+
/**
|
|
43
|
+
* Generate JSON schemas for the given types.
|
|
44
|
+
*
|
|
45
|
+
* @param path - The path to the TypeScript file
|
|
46
|
+
* @param types - The types to generate schemas for
|
|
47
|
+
* @param sourceCode - The source code (for error messages)
|
|
48
|
+
* @returns Map from type name to JSON schema object
|
|
49
|
+
*/
|
|
50
|
+
export declare function generateSchemas(path: string, types: TypeInfo[], sourceCode?: string): Map<string, object>;
|
|
51
|
+
/**
|
|
52
|
+
* An insertion to be made into the source code.
|
|
53
|
+
*/
|
|
54
|
+
export interface Insertion {
|
|
55
|
+
/** Position in the source to insert after */
|
|
56
|
+
position: number;
|
|
57
|
+
/** The code to insert */
|
|
58
|
+
code: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Generate insertions for namespace declarations.
|
|
62
|
+
*
|
|
63
|
+
* @param types - The types to generate namespaces for
|
|
64
|
+
* @param schemas - Map from type name to JSON schema object
|
|
65
|
+
* @returns Array of insertions sorted by position (descending)
|
|
66
|
+
*/
|
|
67
|
+
export declare function generateInsertions(types: TypeInfo[], schemas: Map<string, object>): Insertion[];
|
|
68
|
+
/**
|
|
69
|
+
* Generate the import statement for injected code.
|
|
70
|
+
*
|
|
71
|
+
* For the pkg binary, we use the bundled module registry instead of
|
|
72
|
+
* a real import, since the types are available at runtime via global.__bundled__.
|
|
73
|
+
*/
|
|
74
|
+
export declare function generateSchemaImport(): string;
|
|
75
|
+
/**
|
|
76
|
+
* Apply insertions to source code.
|
|
77
|
+
*
|
|
78
|
+
* @param source - The original source code
|
|
79
|
+
* @param insertions - Insertions to apply (must be sorted by position descending)
|
|
80
|
+
* @returns The modified source code
|
|
81
|
+
*/
|
|
82
|
+
export declare function applyInsertions(source: string, insertions: Insertion[]): string;
|
|
83
|
+
/**
|
|
84
|
+
* Check if source code contains @JSONSchema markers.
|
|
85
|
+
*
|
|
86
|
+
* This is a fast string check to avoid full AST parsing for files
|
|
87
|
+
* that don't use the feature.
|
|
88
|
+
*
|
|
89
|
+
* @param source - The script source code
|
|
90
|
+
* @returns true if the source may contain @JSONSchema types
|
|
91
|
+
*/
|
|
92
|
+
export declare function hasJsonSchemaMarkers(source: string): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Transform source code by processing @JSONSchema types.
|
|
95
|
+
*
|
|
96
|
+
* This function:
|
|
97
|
+
* 1. Finds types marked with @JSONSchema
|
|
98
|
+
* 2. Generates JSON schemas for each type
|
|
99
|
+
* 3. Injects namespace declarations with SchemaProvider implementations
|
|
100
|
+
* 4. Adds the necessary type import
|
|
101
|
+
*
|
|
102
|
+
* @param path - The file path
|
|
103
|
+
* @param source - The TypeScript source code
|
|
104
|
+
* @returns The transformed source code, or the original if no transforms needed
|
|
105
|
+
*/
|
|
106
|
+
export declare function transformJsonSchemas(path: string, source: string): string;
|
|
107
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/cli/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,MAAM,YAAY,CAAC;AAW5B;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;IACb,8BAA8B;IAC9B,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC;IACd,+DAA+D;IAC/D,aAAa,EAAE,MAAM,CAAC;IACtB,6DAA6D;IAC7D,WAAW,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;IACf,4EAA4E;IAC5E,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAUD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,QAAQ,EAAE,CA+CxE;AA0ED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,QAAQ,EAAE,EACjB,UAAU,CAAC,EAAE,MAAM,GAClB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CA0CrB;AAWD;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;CACd;AAoBD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,QAAQ,EAAE,EACjB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC3B,SAAS,EAAE,CAiBb;AAED;;;;;GAKG;AACH,wBAAgB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