thinkwell 0.4.0 → 0.4.2

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 CHANGED
@@ -58,6 +58,11 @@ function getTypesCommandPath() {
58
58
  return resolve(__dirname, "../dist/cli/types-command.js");
59
59
  }
60
60
 
61
+ // Get the path to the build command script
62
+ function getBuildCommandPath() {
63
+ return resolve(__dirname, "../dist/cli/build.js");
64
+ }
65
+
61
66
  // Get the path to the bundled CLI loader
62
67
  function getLoaderPath() {
63
68
  return resolve(__dirname, "../dist-pkg/cli-loader.cjs");
@@ -165,6 +170,7 @@ thinkwell - Run TypeScript scripts with automatic schema generation
165
170
  Usage:
166
171
  thinkwell <script.ts> [args...] Run a TypeScript script
167
172
  thinkwell run <script.ts> [args...] Explicit run command
173
+ thinkwell build <script.ts> Compile to standalone executable
168
174
  thinkwell init [project-name] Initialize a new project
169
175
  thinkwell types [dir] Generate .d.ts files for IDE support
170
176
  thinkwell types --watch [dir] Watch and regenerate .d.ts files
@@ -174,6 +180,7 @@ Usage:
174
180
  Examples:
175
181
  thinkwell hello.ts Run hello.ts
176
182
  thinkwell run hello.ts --verbose Run with arguments
183
+ thinkwell build src/agent.ts Compile to binary
177
184
  thinkwell init my-agent Create a new project
178
185
  ./script.ts Via shebang: #!/usr/bin/env thinkwell
179
186
  thinkwell types Generate declarations in current dir
@@ -275,6 +282,37 @@ async function runUserScript(scriptPath, args) {
275
282
  }
276
283
  }
277
284
 
285
+ /**
286
+ * Run the build command to compile scripts into standalone executables.
287
+ */
288
+ async function runBuildCommand(args) {
289
+ const buildCommandPath = getBuildCommandPath();
290
+ if (!existsSync(buildCommandPath)) {
291
+ console.error("Error: thinkwell installation appears to be corrupted.");
292
+ console.error(` - Build command not found: ${buildCommandPath}`);
293
+ console.error("\nTry reinstalling with: npm install thinkwell");
294
+ process.exit(1);
295
+ }
296
+
297
+ // Import and run the build command
298
+ const { parseBuildArgs, runBuild, showBuildHelp } = await import(buildCommandPath);
299
+
300
+ // Check for help flag
301
+ if (args.includes("--help") || args.includes("-h")) {
302
+ showBuildHelp();
303
+ process.exit(0);
304
+ }
305
+
306
+ try {
307
+ const options = parseBuildArgs(args);
308
+ await runBuild(options);
309
+ } catch (error) {
310
+ console.error(`Error: ${error.message}`);
311
+ process.exit(1);
312
+ }
313
+ process.exit(0);
314
+ }
315
+
278
316
  /**
279
317
  * Run the types command.
280
318
  *
@@ -327,8 +365,12 @@ async function main() {
327
365
  process.exit(0);
328
366
  }
329
367
 
330
- // Handle --help (global)
331
- if (args.includes("--help") || args.includes("-h") || args.length === 0) {
368
+ // Handle --help (global) - but not if it's a subcommand's help
369
+ // e.g., "thinkwell build --help" should show build help, not global help
370
+ const subcommands = ["init", "build", "types", "run"];
371
+ const firstArg = args[0];
372
+ const isSubcommandHelp = subcommands.includes(firstArg) && (args.includes("--help") || args.includes("-h"));
373
+ if (!isSubcommandHelp && (args.includes("--help") || args.includes("-h") || args.length === 0)) {
332
374
  showHelp();
333
375
  process.exit(0);
334
376
  }
@@ -346,6 +388,12 @@ async function main() {
346
388
  return;
347
389
  }
348
390
 
391
+ // Handle "build" subcommand
392
+ if (args[0] === "build") {
393
+ await runBuildCommand(args.slice(1));
394
+ return;
395
+ }
396
+
349
397
  // All script execution requires Node 24+ and proper installation
350
398
  validateNodeVersion();
351
399
  validateInstallation();
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Build command for creating self-contained executables from user scripts.
3
+ *
4
+ * This module provides the `thinkwell build` command that compiles user scripts
5
+ * into standalone binaries using the same pkg-based tooling as the thinkwell CLI.
6
+ *
7
+ * The build process follows a two-stage pipeline:
8
+ * 1. **Pre-bundle with esbuild** - Bundle user script + thinkwell packages into CJS
9
+ * 2. **Compile with pkg** - Create self-contained binary with Node.js runtime
10
+ */
11
+ export type Target = "darwin-arm64" | "darwin-x64" | "linux-x64" | "linux-arm64" | "host";
12
+ export interface BuildOptions {
13
+ /** Entry point TypeScript/JavaScript file */
14
+ entry: string;
15
+ /** Output file path (default: ./<entry-basename>-<target>) */
16
+ output?: string;
17
+ /** Target platforms (default: ["host"]) */
18
+ targets?: Target[];
19
+ /** Additional files to embed as assets */
20
+ include?: string[];
21
+ /** Packages to exclude from bundling (kept as external imports) */
22
+ external?: string[];
23
+ /** Show detailed build output */
24
+ verbose?: boolean;
25
+ /** Suppress all non-error output (for CI environments) */
26
+ quiet?: boolean;
27
+ /** Show what would be built without actually building */
28
+ dryRun?: boolean;
29
+ /** Minify the bundled output for smaller binaries */
30
+ minify?: boolean;
31
+ /** Watch for changes and rebuild automatically */
32
+ watch?: boolean;
33
+ }
34
+ /**
35
+ * Configuration that can be specified in package.json under "thinkwell.build".
36
+ */
37
+ export interface PackageJsonBuildConfig {
38
+ /** Default output path */
39
+ output?: string;
40
+ /** Default target platforms */
41
+ targets?: Target[];
42
+ /** Default assets to include */
43
+ include?: string[];
44
+ /** Default packages to exclude from bundling */
45
+ external?: string[];
46
+ /** Default minification setting */
47
+ minify?: boolean;
48
+ }
49
+ /**
50
+ * Parse and validate build options from command-line arguments.
51
+ */
52
+ export declare function parseBuildArgs(args: string[]): BuildOptions;
53
+ /**
54
+ * Main build function.
55
+ */
56
+ export declare function runBuild(options: BuildOptions): Promise<void>;
57
+ /**
58
+ * Show help for the build command.
59
+ */
60
+ export declare function showBuildHelp(): void;
61
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/cli/build.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA6IH,MAAM,MAAM,MAAM,GAAG,cAAc,GAAG,YAAY,GAAG,WAAW,GAAG,aAAa,GAAG,MAAM,CAAC;AA0B1F,MAAM,WAAW,YAAY;IAC3B,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,8DAA8D;IAC9D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,OAAO,CAAC,EAAE,M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