thinkwell 0.2.0 → 0.3.0-alpha.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 ADDED
@@ -0,0 +1,257 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Thinkwell CLI launcher
5
+ *
6
+ * This Node.js script detects if Bun is available and delegates to it
7
+ * with the @thinkwell/bun-plugin preloaded.
8
+ */
9
+
10
+ import { execSync, spawn } from "node:child_process";
11
+ import { dirname, resolve } from "node:path";
12
+ import { fileURLToPath } from "node:url";
13
+ import { existsSync } from "node:fs";
14
+
15
+ const __dirname = dirname(fileURLToPath(import.meta.url));
16
+
17
+ // Check if Bun is available and return version or null
18
+ function getBunVersion() {
19
+ try {
20
+ const version = execSync("bun --version", { encoding: "utf-8" }).trim();
21
+ return version;
22
+ } catch {
23
+ return null;
24
+ }
25
+ }
26
+
27
+ // Get the path to the plugin
28
+ function getPluginPath() {
29
+ // When installed via npm, the plugin is in our node_modules
30
+ return resolve(__dirname, "../node_modules/@thinkwell/bun-plugin/dist/index.js");
31
+ }
32
+
33
+ // Get the path to our node_modules (where thinkwell packages are installed)
34
+ function getNodeModulesPath() {
35
+ return resolve(__dirname, "../node_modules");
36
+ }
37
+
38
+ // Get the path to the types command script
39
+ function getTypesCommandPath() {
40
+ return resolve(__dirname, "../dist/cli/types-command.js");
41
+ }
42
+
43
+ // Validate that required files exist for commands that require Bun
44
+ function validateInstallation() {
45
+ const pluginPath = getPluginPath();
46
+ const typesCommandPath = getTypesCommandPath();
47
+ const errors = [];
48
+
49
+ if (!existsSync(pluginPath)) {
50
+ errors.push(`Plugin not found: ${pluginPath}`);
51
+ }
52
+
53
+ if (!existsSync(typesCommandPath)) {
54
+ errors.push(`Types command not found: ${typesCommandPath}`);
55
+ }
56
+
57
+ if (errors.length > 0) {
58
+ console.error("Error: thinkwell installation appears to be corrupted.");
59
+ for (const error of errors) {
60
+ console.error(` - ${error}`);
61
+ }
62
+ console.error("\nTry reinstalling with: npm install thinkwell");
63
+ process.exit(1);
64
+ }
65
+ }
66
+
67
+ // Validate init command is available
68
+ function validateInitCommand() {
69
+ const initCommandPath = getInitCommandPath();
70
+ if (!existsSync(initCommandPath)) {
71
+ console.error("Error: thinkwell installation appears to be corrupted.");
72
+ console.error(` - Init command not found: ${initCommandPath}`);
73
+ console.error("\nTry reinstalling with: npm install thinkwell");
74
+ process.exit(1);
75
+ }
76
+ }
77
+
78
+ // Parse version from package.json
79
+ async function getVersion() {
80
+ const packagePath = resolve(__dirname, "../package.json");
81
+ const { default: pkg } = await import(packagePath, { with: { type: "json" } });
82
+ return pkg.version;
83
+ }
84
+
85
+ // Get the path to the init command script
86
+ function getInitCommandPath() {
87
+ return resolve(__dirname, "../dist/cli/init-command.js");
88
+ }
89
+
90
+ // Show help message
91
+ function showHelp() {
92
+ console.log(`
93
+ thinkwell - Run TypeScript scripts with automatic schema generation
94
+
95
+ Usage:
96
+ thinkwell <script.ts> [args...] Run a TypeScript script
97
+ thinkwell run <script.ts> [args...] Explicit run command
98
+ thinkwell init [project-name] Initialize a new project
99
+ thinkwell types [dir] Generate .d.ts files for IDE support
100
+ thinkwell types --watch [dir] Watch and regenerate .d.ts files
101
+ thinkwell --help Show this help message
102
+ thinkwell --version Show version
103
+
104
+ Examples:
105
+ thinkwell hello.ts Run hello.ts
106
+ thinkwell run hello.ts --verbose Run with arguments
107
+ thinkwell init my-agent Create a new project
108
+ ./script.ts Via shebang: #!/usr/bin/env thinkwell
109
+ thinkwell types Generate declarations in current dir
110
+ thinkwell types src Generate declarations in src/
111
+ thinkwell types --watch Watch for changes and regenerate
112
+
113
+ The thinkwell CLI automatically:
114
+ - Generates JSON Schema for types marked with @JSONSchema
115
+ - Resolves thinkwell:* imports to built-in modules
116
+ - Creates .thinkwell.d.ts files for IDE autocomplete (types command)
117
+
118
+ For more information, visit: https://github.com/dherman/thinkwell
119
+ `);
120
+ }
121
+
122
+ async function main() {
123
+ const args = process.argv.slice(2);
124
+
125
+ // Handle "init" subcommand first - does NOT require Bun
126
+ // Must be before global --help so "init --help" shows init-specific help
127
+ if (args[0] === "init") {
128
+ validateInitCommand();
129
+ const initArgs = args.slice(1);
130
+ const initCommandPath = getInitCommandPath();
131
+
132
+ // Import and run the init command
133
+ const { runInit } = await import(initCommandPath);
134
+ await runInit(initArgs);
135
+ process.exit(0);
136
+ }
137
+
138
+ // Handle --help (global)
139
+ if (args.includes("--help") || args.includes("-h") || args.length === 0) {
140
+ showHelp();
141
+ process.exit(0);
142
+ }
143
+
144
+ // Handle --version
145
+ if (args.includes("--version") || args.includes("-v")) {
146
+ const version = await getVersion();
147
+ console.log(`thinkwell ${version}`);
148
+ process.exit(0);
149
+ }
150
+
151
+ // All commands below require Bun
152
+ const bunVersion = getBunVersion();
153
+ if (!bunVersion) {
154
+ console.error("Error: Bun is required to run thinkwell scripts.");
155
+ console.error("");
156
+ console.error("The thinkwell runtime uses Bun for TypeScript execution and schema");
157
+ console.error("generation. This also enables features like compiled executables.");
158
+ console.error("");
159
+ console.error("To install Bun:");
160
+ console.error(" curl -fsSL https://bun.sh/install | bash");
161
+ console.error("");
162
+ console.error("Or via Homebrew:");
163
+ console.error(" brew install oven-sh/bun/bun");
164
+ console.error("");
165
+ console.error("For more information: https://bun.sh");
166
+ process.exit(1);
167
+ }
168
+
169
+ // Validate installation
170
+ validateInstallation();
171
+
172
+ // Handle "types" subcommand
173
+ if (args[0] === "types") {
174
+ const typesArgs = args.slice(1);
175
+ const typesCommandPath = getTypesCommandPath();
176
+ const bunArgs = [typesCommandPath, ...typesArgs];
177
+
178
+ const child = spawn("bun", bunArgs, {
179
+ stdio: "inherit",
180
+ env: process.env,
181
+ });
182
+
183
+ child.on("error", (err) => {
184
+ console.error(`Error: Failed to execute 'bun' command.`);
185
+ console.error(` ${err.message}`);
186
+ if (err.code === "ENOENT") {
187
+ console.error("");
188
+ console.error("Bun was detected but cannot be executed.");
189
+ console.error("Ensure 'bun' is in your PATH and has execute permissions.");
190
+ }
191
+ process.exit(1);
192
+ });
193
+
194
+ child.on("exit", (code) => {
195
+ process.exit(code ?? 0);
196
+ });
197
+
198
+ return;
199
+ }
200
+
201
+ // Handle "run" subcommand - just strip it
202
+ const runArgs = args[0] === "run" ? args.slice(1) : args;
203
+
204
+ // If no script provided after "run", show help
205
+ if (runArgs.length === 0) {
206
+ console.error("Error: No script provided.");
207
+ console.error("");
208
+ console.error("Usage: thinkwell run <script.ts> [args...]");
209
+ process.exit(1);
210
+ }
211
+
212
+ // Check if the script file exists
213
+ const scriptPath = runArgs[0];
214
+ if (!scriptPath.startsWith("-") && !existsSync(scriptPath)) {
215
+ // Try resolving relative to cwd
216
+ const resolvedPath = resolve(process.cwd(), scriptPath);
217
+ if (!existsSync(resolvedPath)) {
218
+ console.error(`Error: Script not found: ${scriptPath}`);
219
+ console.error("");
220
+ console.error("Make sure the file exists and the path is correct.");
221
+ process.exit(1);
222
+ }
223
+ }
224
+
225
+ // Delegate to bun with plugin preloaded
226
+ const pluginPath = getPluginPath();
227
+ const nodeModulesPath = getNodeModulesPath();
228
+ const bunArgs = ["--preload", pluginPath, ...runArgs];
229
+
230
+ // Add our node_modules to NODE_PATH so Bun can find thinkwell packages
231
+ // regardless of where the script is located
232
+ const nodePath = process.env.NODE_PATH
233
+ ? `${nodeModulesPath}:${process.env.NODE_PATH}`
234
+ : nodeModulesPath;
235
+
236
+ const child = spawn("bun", bunArgs, {
237
+ stdio: "inherit",
238
+ env: { ...process.env, NODE_PATH: nodePath },
239
+ });
240
+
241
+ child.on("error", (err) => {
242
+ console.error(`Error: Failed to execute 'bun' command.`);
243
+ console.error(` ${err.message}`);
244
+ if (err.code === "ENOENT") {
245
+ console.error("");
246
+ console.error("Bun was detected but cannot be executed.");
247
+ console.error("Ensure 'bun' is in your PATH and has execute permissions.");
248
+ }
249
+ process.exit(1);
250
+ });
251
+
252
+ child.on("exit", (code) => {
253
+ process.exit(code ?? 0);
254
+ });
255
+ }
256
+
257
+ main();
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Thinkwell CLI
3
+ *
4
+ * This module provides the Bun-native entry point for the thinkwell CLI.
5
+ * For npm distribution, see bin/thinkwell which is a Node.js launcher.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ export declare const VERSION = "0.2.0";
10
+ export { THINKWELL_MODULES } from "@thinkwell/bun-plugin";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,OAAO,UAAU,CAAC;AAE/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Thinkwell CLI
3
+ *
4
+ * This module provides the Bun-native entry point for the thinkwell CLI.
5
+ * For npm distribution, see bin/thinkwell which is a Node.js launcher.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ export const VERSION = "0.2.0";
10
+ export { THINKWELL_MODULES } from "@thinkwell/bun-plugin";
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAE/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * CLI command for initializing a new thinkwell project.
3
+ *
4
+ * This command scaffolds a new project with the necessary configuration
5
+ * and example files. It does not require Bun to run.
6
+ */
7
+ export declare function runInit(args: string[]): Promise<void>;
8
+ //# sourceMappingURL=init-command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init-command.d.ts","sourceRoot":"","sources":["../../src/cli/init-command.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAkHH,wBAAsB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAkD3D"}
@@ -0,0 +1,149 @@
1
+ /**
2
+ * CLI command for initializing a new thinkwell project.
3
+ *
4
+ * This command scaffolds a new project with the necessary configuration
5
+ * and example files. It does not require Bun to run.
6
+ */
7
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
8
+ import { basename, join, resolve } from "node:path";
9
+ const PACKAGE_JSON_TEMPLATE = (name) => `{
10
+ "name": "${name}",
11
+ "version": "0.1.0",
12
+ "type": "module",
13
+ "scripts": {
14
+ "start": "thinkwell src/main.ts",
15
+ "types": "thinkwell types src"
16
+ },
17
+ "dependencies": {
18
+ "thinkwell": "^0.2.0"
19
+ }
20
+ }
21
+ `;
22
+ const MAIN_TS_TEMPLATE = `import { Agent } from "thinkwell:agent";
23
+
24
+ /**
25
+ * A greeting response from the agent.
26
+ * @JSONSchema
27
+ */
28
+ export interface Greeting {
29
+ message: string;
30
+ }
31
+
32
+ async function main() {
33
+ // Connect to an agent (configure THINKWELL_AGENT_CMD in your environment)
34
+ const agent = await Agent.connect(process.env.THINKWELL_AGENT_CMD!);
35
+
36
+ // Ask the agent to generate a structured greeting
37
+ const greeting = await agent
38
+ .think(Greeting)
39
+ .text("Say hello and introduce yourself briefly.")
40
+ .run();
41
+
42
+ console.log(greeting.message);
43
+ }
44
+
45
+ main().catch(console.error);
46
+ `;
47
+ const TSCONFIG_TEMPLATE = `{
48
+ "compilerOptions": {
49
+ "target": "ES2022",
50
+ "module": "NodeNext",
51
+ "moduleResolution": "NodeNext",
52
+ "strict": true,
53
+ "esModuleInterop": true,
54
+ "skipLibCheck": true,
55
+ "declaration": true,
56
+ "outDir": "./dist"
57
+ },
58
+ "include": ["src/**/*"]
59
+ }
60
+ `;
61
+ const GITIGNORE_TEMPLATE = `node_modules/
62
+ dist/
63
+ *.thinkwell.d.ts
64
+ .env
65
+ `;
66
+ const ENV_EXAMPLE_TEMPLATE = `# Configure your agent command
67
+ # Example for Claude Code:
68
+ # THINKWELL_AGENT_CMD=claude --dangerously-skip-permissions
69
+ `;
70
+ function createProject(options) {
71
+ const { name, targetDir } = options;
72
+ // Create directories
73
+ mkdirSync(targetDir, { recursive: true });
74
+ mkdirSync(join(targetDir, "src"), { recursive: true });
75
+ // Write files
76
+ writeFileSync(join(targetDir, "package.json"), PACKAGE_JSON_TEMPLATE(name));
77
+ writeFileSync(join(targetDir, "src/main.ts"), MAIN_TS_TEMPLATE);
78
+ writeFileSync(join(targetDir, "tsconfig.json"), TSCONFIG_TEMPLATE);
79
+ writeFileSync(join(targetDir, ".gitignore"), GITIGNORE_TEMPLATE);
80
+ writeFileSync(join(targetDir, ".env.example"), ENV_EXAMPLE_TEMPLATE);
81
+ }
82
+ function showHelp() {
83
+ console.log(`
84
+ thinkwell init - Initialize a new thinkwell project
85
+
86
+ Usage:
87
+ thinkwell init [project-name]
88
+
89
+ Arguments:
90
+ project-name Name of the project directory (default: current directory)
91
+
92
+ Examples:
93
+ thinkwell init my-agent Create a new project in ./my-agent
94
+ thinkwell init Initialize in the current directory
95
+
96
+ This command creates:
97
+ - package.json with thinkwell dependency
98
+ - tsconfig.json for TypeScript
99
+ - src/main.ts with example agent code
100
+ - .gitignore
101
+ - .env.example
102
+ `);
103
+ }
104
+ export async function runInit(args) {
105
+ // Check for help flag
106
+ if (args.includes("--help") || args.includes("-h")) {
107
+ showHelp();
108
+ return;
109
+ }
110
+ // Get project name from args or use current directory
111
+ const projectArg = args.find((arg) => !arg.startsWith("-"));
112
+ const targetDir = projectArg ? resolve(projectArg) : process.cwd();
113
+ const name = projectArg || basename(process.cwd());
114
+ // Check if directory exists and is not empty
115
+ if (existsSync(targetDir)) {
116
+ const files = ["package.json", "tsconfig.json", "src/main.ts"];
117
+ const existingFiles = files.filter((f) => existsSync(join(targetDir, f)));
118
+ if (existingFiles.length > 0) {
119
+ console.error(`Error: Directory already contains project files:`);
120
+ for (const file of existingFiles) {
121
+ console.error(` - ${file}`);
122
+ }
123
+ console.error("");
124
+ console.error("Use a different directory or remove existing files.");
125
+ process.exit(1);
126
+ }
127
+ }
128
+ console.log(`Creating thinkwell project in ${targetDir}...`);
129
+ console.log("");
130
+ createProject({ name, targetDir });
131
+ console.log("Created files:");
132
+ console.log(" - package.json");
133
+ console.log(" - tsconfig.json");
134
+ console.log(" - src/main.ts");
135
+ console.log(" - .gitignore");
136
+ console.log(" - .env.example");
137
+ console.log("");
138
+ console.log("Next steps:");
139
+ console.log("");
140
+ if (projectArg) {
141
+ console.log(` cd ${projectArg}`);
142
+ }
143
+ console.log(" npm install # or: bun install");
144
+ console.log(" cp .env.example .env");
145
+ console.log(" # Edit .env to configure your agent");
146
+ console.log(" thinkwell src/main.ts");
147
+ console.log("");
148
+ }
149
+ //# sourceMappingURL=init-command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init-command.js","sourceRoot":"","sources":["../../src/cli/init-command.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpD,MAAM,qBAAqB,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC;aACnC,IAAI;;;;;;;;;;;CAWhB,CAAC;AAEF,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;CAwBxB,CAAC;AAEF,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;CAazB,CAAC;AAEF,MAAM,kBAAkB,GAAG;;;;CAI1B,CAAC;AAEF,MAAM,oBAAoB,GAAG;;;CAG5B,CAAC;AAEF,SAAS,aAAa,CAAC,OAAoB;IACzC,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAEpC,qBAAqB;IACrB,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;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AAC,CAAC;IAC3B,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,CAAC,GAAG,CAAC,QAAQ,UAAU,EAAE,CAAC,CAAC;IACpC,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;IACtD,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IACtC,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;IACrD,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IACvC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAClB,CAAC"}
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Thinkwell CLI - Bun-native entry point for compiled binary.
4
+ *
5
+ * This is the main entry point for the self-contained Bun-compiled binary.
6
+ * Unlike the Node.js launcher (bin/thinkwell), this runs directly in Bun
7
+ * and can be compiled with `bun build --compile`.
8
+ *
9
+ * The bun-plugin is imported at the top level, which registers it with Bun's
10
+ * plugin system. This means any TypeScript files loaded after this point
11
+ * will automatically have @JSONSchema types processed.
12
+ */
13
+ export {};
14
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":";AACA;;;;;;;;;;GAUG"}
@@ -0,0 +1,231 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Thinkwell CLI - Bun-native entry point for compiled binary.
4
+ *
5
+ * This is the main entry point for the self-contained Bun-compiled binary.
6
+ * Unlike the Node.js launcher (bin/thinkwell), this runs directly in Bun
7
+ * and can be compiled with `bun build --compile`.
8
+ *
9
+ * The bun-plugin is imported at the top level, which registers it with Bun's
10
+ * plugin system. This means any TypeScript files loaded after this point
11
+ * will automatically have @JSONSchema types processed.
12
+ */
13
+ import { existsSync } from "node:fs";
14
+ import { resolve, isAbsolute } from "node:path";
15
+ import { pathToFileURL } from "node:url";
16
+ // Import the bun-plugin - this registers it with Bun's plugin system.
17
+ // The plugin will intercept all .ts/.tsx file loads and process @JSONSchema types.
18
+ import { registerModule } from "@thinkwell/bun-plugin";
19
+ // Import thinkwell packages so they get bundled into the compiled binary.
20
+ // These are registered as virtual modules so user scripts can import from them.
21
+ import * as thinkwell from "thinkwell";
22
+ import * as thinkwellAcp from "@thinkwell/acp";
23
+ import * as thinkwellProtocol from "@thinkwell/protocol";
24
+ // Register modules for virtual resolution in compiled binary.
25
+ // This enables user scripts to import from "thinkwell:agent" etc.
26
+ registerModule("thinkwell", thinkwell);
27
+ registerModule("@thinkwell/acp", thinkwellAcp);
28
+ registerModule("@thinkwell/protocol", thinkwellProtocol);
29
+ import { runInit } from "./init-command.js";
30
+ // Get version from package.json at build time
31
+ const VERSION = "0.3.0-alpha.2"; // Will be replaced by build script
32
+ function showHelp() {
33
+ console.log(`
34
+ thinkwell - Run TypeScript scripts with automatic schema generation
35
+
36
+ Usage:
37
+ thinkwell <script.ts> [args...] Run a TypeScript script
38
+ thinkwell run <script.ts> [args...] Explicit run command
39
+ thinkwell init [project-name] Initialize a new project
40
+ thinkwell types [dir] Generate .d.ts files for IDE support
41
+ thinkwell types --watch [dir] Watch and regenerate .d.ts files
42
+ thinkwell --help Show this help message
43
+ thinkwell --version Show version
44
+
45
+ Examples:
46
+ thinkwell hello.ts Run hello.ts
47
+ thinkwell run hello.ts --verbose Run with arguments
48
+ thinkwell init my-agent Create a new project
49
+ ./script.ts Via shebang: #!/usr/bin/env thinkwell
50
+ thinkwell types Generate declarations in current dir
51
+ thinkwell types src Generate declarations in src/
52
+ thinkwell types --watch Watch for changes and regenerate
53
+
54
+ The thinkwell CLI automatically:
55
+ - Generates JSON Schema for types marked with @JSONSchema
56
+ - Resolves thinkwell:* imports to built-in modules
57
+ - Creates .thinkwell.d.ts files for IDE autocomplete (types command)
58
+
59
+ For more information, visit: https://github.com/dherman/thinkwell
60
+ `);
61
+ }
62
+ async function runTypes(args) {
63
+ // Import the types command implementation from the bundled bun-plugin
64
+ const { generateDeclarations, watchDeclarations } = await import("@thinkwell/bun-plugin");
65
+ const watchMode = args.includes("--watch") || args.includes("-w");
66
+ const dirArg = args.find((arg) => !arg.startsWith("-"));
67
+ const rootDir = dirArg ? resolve(dirArg) : process.cwd();
68
+ // Validate directory exists
69
+ if (!existsSync(rootDir)) {
70
+ console.error(`Error: Directory not found: ${rootDir}`);
71
+ process.exit(1);
72
+ }
73
+ const formatError = (error, sourceFile) => {
74
+ const lines = [`Error processing: ${sourceFile}`, ` ${error.message}`];
75
+ if (process.env.DEBUG) {
76
+ lines.push(` Stack: ${error.stack?.split("\n").slice(1, 3).join("\n ")}`);
77
+ }
78
+ return lines.join("\n");
79
+ };
80
+ if (watchMode) {
81
+ console.log(`Watching for changes in ${rootDir}...`);
82
+ console.log("Press Ctrl+C to stop.\n");
83
+ const watcher = watchDeclarations({
84
+ rootDir,
85
+ onWrite: (_source, decl) => {
86
+ console.log(`✓ ${decl}`);
87
+ },
88
+ onRemove: (_source, decl) => {
89
+ console.log(`✗ ${decl} (removed)`);
90
+ },
91
+ onError: (error, source) => {
92
+ console.error(formatError(error, source));
93
+ },
94
+ });
95
+ // Initial generation
96
+ console.log("Generating initial declarations...\n");
97
+ await generateDeclarations({
98
+ rootDir,
99
+ onWrite: (_source, decl) => {
100
+ console.log(`✓ ${decl}`);
101
+ },
102
+ onError: (error, source) => {
103
+ console.error(formatError(error, source));
104
+ },
105
+ });
106
+ console.log("\nWatching for changes...\n");
107
+ // Keep process alive
108
+ process.on("SIGINT", () => {
109
+ watcher.stop();
110
+ console.log("\nStopped watching.");
111
+ process.exit(0);
112
+ });
113
+ // Prevent the process from exiting
114
+ await new Promise(() => { });
115
+ }
116
+ else {
117
+ console.log(`Generating declarations in ${rootDir}...\n`);
118
+ let errorCount = 0;
119
+ const generated = await generateDeclarations({
120
+ rootDir,
121
+ onWrite: (_source, decl) => {
122
+ console.log(`✓ ${decl}`);
123
+ },
124
+ onError: (error, source) => {
125
+ errorCount++;
126
+ console.error(formatError(error, source));
127
+ },
128
+ });
129
+ if (generated.length === 0 && errorCount === 0) {
130
+ console.log("No @JSONSchema types found.");
131
+ console.log("");
132
+ console.log("To mark a type for schema generation, add the @JSONSchema JSDoc tag:");
133
+ console.log("");
134
+ console.log(" /** @JSONSchema */");
135
+ console.log(" interface MyType {");
136
+ console.log(" name: string;");
137
+ console.log(" }");
138
+ }
139
+ else {
140
+ console.log(`\nGenerated ${generated.length} declaration file(s).`);
141
+ if (errorCount > 0) {
142
+ console.log(`Encountered ${errorCount} error(s).`);
143
+ process.exit(1);
144
+ }
145
+ }
146
+ }
147
+ }
148
+ async function runScript(args) {
149
+ const scriptPath = args[0];
150
+ // Resolve the script path
151
+ const resolvedPath = isAbsolute(scriptPath)
152
+ ? scriptPath
153
+ : resolve(process.cwd(), scriptPath);
154
+ // Check if the script file exists
155
+ if (!existsSync(resolvedPath)) {
156
+ console.error(`Error: Script not found: ${scriptPath}`);
157
+ console.error("");
158
+ console.error("Make sure the file exists and the path is correct.");
159
+ process.exit(1);
160
+ }
161
+ // Set up process.argv for the script
162
+ // The script should see: [bun, script.ts, ...args]
163
+ const originalArgv = process.argv;
164
+ process.argv = [process.argv[0], resolvedPath, ...args.slice(1)];
165
+ try {
166
+ // Dynamically import the script.
167
+ // Because the bun-plugin is registered, it will intercept this import
168
+ // and process any @JSONSchema types in the file.
169
+ const scriptUrl = pathToFileURL(resolvedPath).href;
170
+ await import(scriptUrl);
171
+ }
172
+ catch (error) {
173
+ // Restore argv before handling error
174
+ process.argv = originalArgv;
175
+ if (error instanceof Error) {
176
+ // Check if it's a module not found error for thinkwell packages
177
+ if (error.message.includes("Cannot find module") ||
178
+ error.message.includes("Cannot find package")) {
179
+ console.error(`Error: ${error.message}`);
180
+ console.error("");
181
+ console.error("If your script uses thinkwell:* imports, make sure to use");
182
+ console.error("the import syntax like: import { Agent } from 'thinkwell:agent'");
183
+ process.exit(1);
184
+ }
185
+ throw error;
186
+ }
187
+ throw error;
188
+ }
189
+ }
190
+ async function main() {
191
+ const args = process.argv.slice(2);
192
+ // Handle "init" subcommand first - does NOT require schema plugin
193
+ if (args[0] === "init") {
194
+ await runInit(args.slice(1));
195
+ process.exit(0);
196
+ }
197
+ // Handle --help (global)
198
+ if (args.includes("--help") || args.includes("-h") || args.length === 0) {
199
+ showHelp();
200
+ process.exit(0);
201
+ }
202
+ // Handle --version
203
+ if (args.includes("--version") || args.includes("-v")) {
204
+ console.log(`thinkwell ${VERSION}`);
205
+ process.exit(0);
206
+ }
207
+ // Handle "types" subcommand
208
+ if (args[0] === "types") {
209
+ await runTypes(args.slice(1));
210
+ process.exit(0);
211
+ }
212
+ // Handle "run" subcommand - just strip it
213
+ const runArgs = args[0] === "run" ? args.slice(1) : args;
214
+ // If no script provided after "run", show help
215
+ if (runArgs.length === 0) {
216
+ console.error("Error: No script provided.");
217
+ console.error("");
218
+ console.error("Usage: thinkwell run <script.ts> [args...]");
219
+ process.exit(1);
220
+ }
221
+ await runScript(runArgs);
222
+ }
223
+ main().catch((error) => {
224
+ console.error("Unexpected error:");
225
+ console.error(` ${error.message || error}`);
226
+ if (process.env.DEBUG) {
227
+ console.error(error.stack);
228
+ }
229
+ process.exit(1);
230
+ });
231
+ //# sourceMappingURL=main.js.map
@@ -0,0 +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,MAA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AAC,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,8 @@
1
+ /**
2
+ * CLI command for generating declaration files.
3
+ *
4
+ * This script is invoked by the thinkwell CLI when the user runs
5
+ * `thinkwell types` or `thinkwell types --watch`.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=types-command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-command.d.ts","sourceRoot":"","sources":["../../src/cli/types-command.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * CLI command for generating declaration files.
3
+ *
4
+ * This script is invoked by the thinkwell CLI when the user runs
5
+ * `thinkwell types` or `thinkwell types --watch`.
6
+ */
7
+ import { existsSync } from "node:fs";
8
+ import { resolve } from "node:path";
9
+ import { generateDeclarations, watchDeclarations, } from "@thinkwell/bun-plugin";
10
+ /**
11
+ * Format an error for console output.
12
+ */
13
+ function formatError(error, sourceFile) {
14
+ const lines = [
15
+ `Error processing: ${sourceFile}`,
16
+ ` ${error.message}`,
17
+ ];
18
+ // Add stack trace hint for debugging
19
+ if (process.env.DEBUG) {
20
+ lines.push(` Stack: ${error.stack?.split("\n").slice(1, 3).join("\n ")}`);
21
+ }
22
+ return lines.join("\n");
23
+ }
24
+ async function main() {
25
+ const args = process.argv.slice(2);
26
+ const watchMode = args.includes("--watch") || args.includes("-w");
27
+ const dirArg = args.find((arg) => !arg.startsWith("-"));
28
+ const rootDir = dirArg ? resolve(dirArg) : process.cwd();
29
+ // Validate directory exists
30
+ if (!existsSync(rootDir)) {
31
+ console.error(`Error: Directory not found: ${rootDir}`);
32
+ process.exit(1);
33
+ }
34
+ if (watchMode) {
35
+ console.log(`Watching for changes in ${rootDir}...`);
36
+ console.log("Press Ctrl+C to stop.\n");
37
+ const watcher = watchDeclarations({
38
+ rootDir,
39
+ onWrite: (source, decl) => {
40
+ console.log(`✓ ${decl}`);
41
+ },
42
+ onRemove: (source, decl) => {
43
+ console.log(`✗ ${decl} (removed)`);
44
+ },
45
+ onError: (error, source) => {
46
+ console.error(formatError(error, source));
47
+ },
48
+ });
49
+ // Initial generation
50
+ console.log("Generating initial declarations...\n");
51
+ await generateDeclarations({
52
+ rootDir,
53
+ onWrite: (source, decl) => {
54
+ console.log(`✓ ${decl}`);
55
+ },
56
+ onError: (error, source) => {
57
+ console.error(formatError(error, source));
58
+ },
59
+ });
60
+ console.log("\nWatching for changes...\n");
61
+ // Keep process alive
62
+ process.on("SIGINT", () => {
63
+ watcher.stop();
64
+ console.log("\nStopped watching.");
65
+ process.exit(0);
66
+ });
67
+ // Prevent the process from exiting
68
+ await new Promise(() => { });
69
+ }
70
+ else {
71
+ console.log(`Generating declarations in ${rootDir}...\n`);
72
+ let errorCount = 0;
73
+ const generated = await generateDeclarations({
74
+ rootDir,
75
+ onWrite: (source, decl) => {
76
+ console.log(`✓ ${decl}`);
77
+ },
78
+ onError: (error, source) => {
79
+ errorCount++;
80
+ console.error(formatError(error, source));
81
+ },
82
+ });
83
+ if (generated.length === 0 && errorCount === 0) {
84
+ console.log("No @JSONSchema types found.");
85
+ console.log("");
86
+ console.log("To mark a type for schema generation, add the @JSONSchema JSDoc tag:");
87
+ console.log("");
88
+ console.log(" /** @JSONSchema */");
89
+ console.log(" interface MyType {");
90
+ console.log(" name: string;");
91
+ console.log(" }");
92
+ }
93
+ else {
94
+ console.log(`\nGenerated ${generated.length} declaration file(s).`);
95
+ if (errorCount > 0) {
96
+ console.log(`Encountered ${errorCount} error(s).`);
97
+ process.exit(1);
98
+ }
99
+ }
100
+ }
101
+ }
102
+ main().catch((error) => {
103
+ console.error("Unexpected error:");
104
+ console.error(` ${error.message || error}`);
105
+ if (process.env.DEBUG) {
106
+ console.error(error.stack);
107
+ }
108
+ process.exit(1);
109
+ });
110
+ //# sourceMappingURL=types-command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-command.js","sourceRoot":"","sources":["../../src/cli/types-command.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAE/B;;GAEG;AACH,SAAS,WAAW,CAAC,KAAY,EAAE,UAAkB;IACnD,MAAM,KAAK,GAAG;QACZ,qBAAqB,UAAU,EAAE;QACjC,KAAK,KAAK,CAAC,OAAO,EAAE;KACrB,CAAC;IAEF,qCAAqC;IACrC,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;QACtB,KAAK,CAAC,IAAI,CAAC,YAAY,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC9E,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,KAAK,UAAU,IAAI;IACjB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAEnC,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,C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,CAAC,EAAE,CAAC,CAAC;YAChB,OAAO,CAAC,GAAG,CAAC,sEAAsE,CAAC,CAAC;YACpF,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAChB,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;YACpC,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;YACpC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;YACjC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,eAAe,SAAS,CAAC,MAAM,uBAAuB,CAAC,CAAC;YACpE,IAAI,UAAU,GAAG,CAAC,EAAE,CAAC;gBACnB,OAAO,CAAC,GAAG,CAAC,eAAe,UAAU,YAAY,CAAC,CAAC;gBACnD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;QACH,CAAC;IACH,CAAC;AACH,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"}
package/dist/index.d.ts CHANGED
@@ -4,4 +4,5 @@ export { Session } from "./session.js";
4
4
  export { ThinkBuilder } from "./think-builder.js";
5
5
  export { schemaOf } from "./schema.js";
6
6
  export type { JsonSchema, SchemaProvider, JsonValue, JsonObject } from "@thinkwell/acp";
7
+ export * from "./connectors/index.js";
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGxF,cAAc,uBAAuB,CAAC"}
package/dist/index.js CHANGED
@@ -5,4 +5,6 @@ export { Session } from "./session.js";
5
5
  export { ThinkBuilder } from "./think-builder.js";
6
6
  // Schema helpers
7
7
  export { schemaOf } from "./schema.js";
8
+ // Re-export connectors for convenient single-package import
9
+ export * from "./connectors/index.js";
8
10
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,gBAAgB;AAChB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,iBAAiB;AACjB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,gBAAgB;AAChB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,iBAAiB;AACjB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAKvC,4DAA4D;AAC5D,cAAc,uBAAuB,CAAC"}
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "thinkwell",
3
- "version": "0.2.0",
3
+ "version": "0.3.0-alpha.2",
4
4
  "description": "TypeScript library for blending deterministic code with LLM-powered reasoning",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
+ "bin": {
9
+ "thinkwell": "./bin/thinkwell"
10
+ },
8
11
  "exports": {
9
12
  ".": {
10
13
  "types": "./dist/index.d.ts",
@@ -15,7 +18,11 @@
15
18
  "import": "./dist/connectors/index.js"
16
19
  }
17
20
  },
21
+ "engines": {
22
+ "node": ">=18"
23
+ },
18
24
  "files": [
25
+ "bin",
19
26
  "dist"
20
27
  ],
21
28
  "keywords": [
@@ -28,8 +35,10 @@
28
35
  "license": "MIT",
29
36
  "dependencies": {
30
37
  "@agentclientprotocol/sdk": "^0.12.0",
31
- "@thinkwell/acp": "0.2.0",
32
- "@thinkwell/conductor": "0.2.0"
38
+ "@thinkwell/acp": "0.3.0-alpha.2",
39
+ "@thinkwell/bun-plugin": "0.3.0-alpha.2",
40
+ "@thinkwell/protocol": "0.3.0-alpha.2",
41
+ "@thinkwell/conductor": "0.3.0-alpha.2"
33
42
  },
34
43
  "devDependencies": {
35
44
  "@types/node": "^24.10.4",
@@ -38,7 +47,8 @@
38
47
  },
39
48
  "scripts": {
40
49
  "build": "tsc",
41
- "clean": "rm -rf dist",
50
+ "build:binary": "bun scripts/build-binary.ts",
51
+ "clean": "rm -rf dist dist-bin",
42
52
  "test": "node --test --import tsx src/**/*.test.ts"
43
53
  }
44
54
  }