thinkwell 0.5.4 → 0.5.6

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.
Files changed (44) hide show
  1. package/dist/agent.d.ts.map +1 -1
  2. package/dist/agent.js +207 -279
  3. package/dist/agent.js.map +1 -1
  4. package/dist/build.js +44 -98
  5. package/dist/cli/build.js +92 -227
  6. package/dist/cli/bundle.js +570 -1136
  7. package/dist/cli/check.js +125 -214
  8. package/dist/cli/commands.js +63 -177
  9. package/dist/cli/compiler-host.js +81 -190
  10. package/dist/cli/dependency-check.js +125 -269
  11. package/dist/cli/dependency-errors.js +12 -84
  12. package/dist/cli/fmt.js +1 -13
  13. package/dist/cli/init-command.js +21 -68
  14. package/dist/cli/init.js +90 -220
  15. package/dist/cli/loader.js +95 -361
  16. package/dist/cli/new-command.js +25 -73
  17. package/dist/cli/package-manager.js +50 -117
  18. package/dist/cli/schema.js +89 -245
  19. package/dist/cli/workspace.js +92 -226
  20. package/dist/connectors/index.js +1 -7
  21. package/dist/generated/features.d.ts +5 -0
  22. package/dist/generated/features.d.ts.map +1 -0
  23. package/dist/generated/features.js +4 -0
  24. package/dist/generated/features.js.map +1 -0
  25. package/dist/index.js +0 -5
  26. package/dist/schema.js +3 -36
  27. package/dist/session.js +50 -82
  28. package/dist/think-builder.d.ts.map +1 -1
  29. package/dist/think-builder.js +269 -370
  30. package/dist/think-builder.js.map +1 -1
  31. package/dist/thought-event.d.ts +1 -0
  32. package/dist/thought-event.d.ts.map +1 -1
  33. package/dist/thought-event.js +0 -1
  34. package/dist/thought-stream.js +60 -96
  35. package/dist-pkg/acp.cjs +13385 -1876
  36. package/dist-pkg/cli-build.cjs +171 -369
  37. package/dist-pkg/cli-bundle.cjs +289 -690
  38. package/dist-pkg/cli-check.cjs +202 -415
  39. package/dist-pkg/cli-dependency-check.cjs +39 -82
  40. package/dist-pkg/cli-dependency-errors.cjs +9 -41
  41. package/dist-pkg/cli-loader.cjs +90 -173
  42. package/dist-pkg/protocol.cjs +2 -8
  43. package/dist-pkg/thinkwell.cjs +876 -1842
  44. package/package.json +7 -6
@@ -1,213 +1,104 @@
1
- /**
2
- * Custom TypeScript CompilerHost for thinkwell build and check commands.
3
- *
4
- * This module provides the shared infrastructure that intercepts TypeScript's
5
- * file reads and applies @JSONSchema namespace injection in memory. Files
6
- * without @JSONSchema markers pass through unchanged. Files from node_modules
7
- * and TypeScript lib files are always passed through unchanged.
8
- *
9
- * Used by `thinkwell build` (single-pass and watch mode) and `thinkwell check` (noEmit).
10
- */
11
1
  import ts from "typescript";
12
2
  import { resolve, dirname, join } from "node:path";
13
3
  import { existsSync } from "node:fs";
14
4
  import { transformJsonSchemas, hasJsonSchemaMarkers } from "./schema.js";
15
- /**
16
- * Get the TypeScript lib directory path.
17
- *
18
- * When running from the compiled binary (pkg snapshot), TypeScript's lib files
19
- * are bundled at dist-pkg/typescript-lib/. When running normally, use the
20
- * default TypeScript lib path.
21
- */
22
5
  function getTypeScriptLibDir() {
23
- // Check if we're running from a compiled binary (pkg sets process.pkg)
24
- if (typeof process.pkg !== "undefined") {
25
- // In the snapshot, the lib files are at /snapshot/.../dist-pkg/typescript-lib/
26
- const snapshotLibDir = "/snapshot/thinkwell/packages/thinkwell/dist-pkg/typescript-lib";
27
- if (existsSync(snapshotLibDir)) {
28
- return snapshotLibDir;
29
- }
30
- }
31
- // Default: use TypeScript's own lib directory
32
- return dirname(ts.getDefaultLibFilePath({}));
6
+ if (typeof process.pkg < "u") {
7
+ const snapshotLibDir = "/snapshot/thinkwell/packages/thinkwell/dist-pkg/typescript-lib";
8
+ if (existsSync(snapshotLibDir))
9
+ return snapshotLibDir;
10
+ }
11
+ return dirname(ts.getDefaultLibFilePath({}));
33
12
  }
34
- /**
35
- * Read and parse a tsconfig.json file using the TypeScript compiler API.
36
- *
37
- * @param configPath - Absolute path to tsconfig.json
38
- * @returns Parsed configuration, or an error diagnostic if the file can't be read
39
- */
40
13
  export function parseTsConfig(configPath) {
41
- const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
42
- if (configFile.error) {
43
- return {
44
- options: {},
45
- fileNames: [],
46
- errors: [configFile.error],
47
- };
48
- }
49
- const configDir = dirname(configPath);
50
- const parsed = ts.parseJsonConfigFileContent(configFile.config, ts.sys, configDir,
51
- /* existingOptions */ undefined, configPath);
14
+ const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
15
+ if (configFile.error)
52
16
  return {
53
- options: parsed.options,
54
- fileNames: parsed.fileNames,
55
- errors: parsed.errors,
17
+ options: {},
18
+ fileNames: [],
19
+ errors: [configFile.error]
56
20
  };
21
+ const configDir = dirname(configPath), parsed = ts.parseJsonConfigFileContent(
22
+ configFile.config,
23
+ ts.sys,
24
+ configDir,
25
+ /* existingOptions */
26
+ void 0,
27
+ configPath
28
+ );
29
+ return {
30
+ options: parsed.options,
31
+ fileNames: parsed.fileNames,
32
+ errors: parsed.errors
33
+ };
57
34
  }
58
- /**
59
- * Determine whether a file path should receive @JSONSchema transformation.
60
- *
61
- * Only project source files are transformed. Files in node_modules and
62
- * TypeScript's own lib files are always passed through unchanged.
63
- */
64
35
  function shouldTransform(fileName) {
65
- if (fileName.includes("node_modules"))
66
- return false;
67
- if (fileName.includes("/lib/lib."))
68
- return false;
69
- return true;
36
+ return !(fileName.includes("node_modules") || fileName.includes("/lib/lib."));
70
37
  }
71
38
  function isThinkwellHostOptions(options) {
72
- return typeof options.compilerOptions === "object"
73
- && options.compilerOptions !== null
74
- && !Array.isArray(options.compilerOptions);
39
+ return typeof options.compilerOptions == "object" && options.compilerOptions !== null && !Array.isArray(options.compilerOptions);
75
40
  }
76
41
  export function createThinkwellHost(options) {
77
- let compilerOptions;
78
- let fileFilter;
79
- let projectDir;
80
- if (isThinkwellHostOptions(options)) {
81
- compilerOptions = options.compilerOptions;
82
- fileFilter = options.fileFilter;
83
- projectDir = options.projectDir;
84
- }
85
- else {
86
- compilerOptions = options;
87
- fileFilter = undefined;
88
- projectDir = undefined;
42
+ let compilerOptions, fileFilter, projectDir;
43
+ isThinkwellHostOptions(options) ? (compilerOptions = options.compilerOptions, fileFilter = options.fileFilter, projectDir = options.projectDir) : (compilerOptions = options, fileFilter = void 0, projectDir = void 0);
44
+ const defaultHost = ts.createCompilerHost(compilerOptions), tsLibDir = getTypeScriptLibDir();
45
+ return {
46
+ ...defaultHost,
47
+ // Override getDefaultLibLocation to point to our bundled TypeScript lib files
48
+ // when running from the compiled binary. This is necessary because bundled
49
+ // TypeScript code can't find its .d.ts files in the pkg snapshot.
50
+ getDefaultLibLocation() {
51
+ return tsLibDir;
52
+ },
53
+ getDefaultLibFileName(options2) {
54
+ return join(tsLibDir, ts.getDefaultLibFileName(options2));
55
+ },
56
+ getSourceFile(fileName, languageVersionOrOptions) {
57
+ const source = ts.sys.readFile(fileName);
58
+ if (source !== void 0) {
59
+ if (shouldTransform(fileName) && hasJsonSchemaMarkers(source) && (!fileFilter || fileFilter(fileName))) {
60
+ const transformed = transformJsonSchemas(fileName, source, projectDir);
61
+ return ts.createSourceFile(fileName, transformed, languageVersionOrOptions);
62
+ }
63
+ return ts.createSourceFile(fileName, source, languageVersionOrOptions);
64
+ }
89
65
  }
90
- const defaultHost = ts.createCompilerHost(compilerOptions);
91
- const tsLibDir = getTypeScriptLibDir();
92
- return {
93
- ...defaultHost,
94
- // Override getDefaultLibLocation to point to our bundled TypeScript lib files
95
- // when running from the compiled binary. This is necessary because bundled
96
- // TypeScript code can't find its .d.ts files in the pkg snapshot.
97
- getDefaultLibLocation() {
98
- return tsLibDir;
99
- },
100
- getDefaultLibFileName(options) {
101
- return join(tsLibDir, ts.getDefaultLibFileName(options));
102
- },
103
- getSourceFile(fileName, languageVersionOrOptions) {
104
- const source = ts.sys.readFile(fileName);
105
- if (source === undefined) {
106
- return undefined;
107
- }
108
- // Only transform project source files that contain @JSONSchema markers.
109
- // If a fileFilter is provided, also check that the file passes the filter.
110
- if (shouldTransform(fileName) && hasJsonSchemaMarkers(source)) {
111
- if (!fileFilter || fileFilter(fileName)) {
112
- const transformed = transformJsonSchemas(fileName, source, projectDir);
113
- return ts.createSourceFile(fileName, transformed, languageVersionOrOptions);
114
- }
115
- }
116
- // Pass through unchanged
117
- return ts.createSourceFile(fileName, source, languageVersionOrOptions);
118
- },
119
- };
66
+ };
120
67
  }
121
- /**
122
- * Create a TypeScript Program wired to the custom CompilerHost.
123
- *
124
- * This is the main entry point for both `thinkwell build` and `thinkwell check`.
125
- * The returned program can be used with `ts.getPreEmitDiagnostics()` for type
126
- * checking or `program.emit()` for producing output files.
127
- *
128
- * @param configPathOrOptions - Absolute path to tsconfig.json, or a CreateProgramOptions object
129
- * @returns The ts.Program and any config-level diagnostics, or null with errors
130
- */
131
68
  export function createThinkwellProgram(configPathOrOptions) {
132
- const configPath = typeof configPathOrOptions === "string"
133
- ? configPathOrOptions
134
- : configPathOrOptions.configPath;
135
- const fileFilter = typeof configPathOrOptions === "object"
136
- ? configPathOrOptions.fileFilter
137
- : undefined;
138
- const projectDir = typeof configPathOrOptions === "object"
139
- ? configPathOrOptions.projectDir
140
- : undefined;
141
- const resolvedConfigPath = resolve(configPath);
142
- const { options, fileNames, errors } = parseTsConfig(resolvedConfigPath);
143
- function makeHost() {
144
- return (fileFilter || projectDir)
145
- ? createThinkwellHost({ compilerOptions: options, fileFilter, projectDir })
146
- : createThinkwellHost(options);
147
- }
148
- // If there are fatal config errors, still return them so callers can report
149
- if (errors.length > 0) {
150
- // Check if any errors are fatal (not just warnings)
151
- const fatalErrors = errors.filter((d) => d.category === ts.DiagnosticCategory.Error);
152
- if (fatalErrors.length > 0) {
153
- // Create a minimal program so callers have a consistent interface
154
- const host = makeHost();
155
- const program = ts.createProgram([], options, host);
156
- return { program, configErrors: errors };
157
- }
158
- }
159
- const host = makeHost();
160
- const program = ts.createProgram(fileNames, options, host);
161
- return { program, configErrors: errors };
69
+ const configPath = typeof configPathOrOptions == "string" ? configPathOrOptions : configPathOrOptions.configPath, fileFilter = typeof configPathOrOptions == "object" ? configPathOrOptions.fileFilter : void 0, projectDir = typeof configPathOrOptions == "object" ? configPathOrOptions.projectDir : void 0, resolvedConfigPath = resolve(configPath), { options, fileNames, errors } = parseTsConfig(resolvedConfigPath);
70
+ function makeHost() {
71
+ return createThinkwellHost(fileFilter || projectDir ? { compilerOptions: options, fileFilter, projectDir } : options);
72
+ }
73
+ if (errors.length > 0 && errors.filter((d) => d.category === ts.DiagnosticCategory.Error).length > 0) {
74
+ const host2 = makeHost();
75
+ return { program: ts.createProgram([], options, host2), configErrors: errors };
76
+ }
77
+ const host = makeHost();
78
+ return { program: ts.createProgram(fileNames, options, host), configErrors: errors };
162
79
  }
163
- /**
164
- * Patch a CompilerHost to apply @JSONSchema transformation and use bundled lib files.
165
- *
166
- * This is used by watch mode to wrap the host that TypeScript's watch system
167
- * provides, preserving its internal state while intercepting file reads.
168
- */
169
80
  function patchHost(host, fileFilter, projectDir) {
170
- const originalGetSourceFile = host.getSourceFile.bind(host);
171
- const tsLibDir = getTypeScriptLibDir();
172
- // Override lib location for compiled binary
173
- host.getDefaultLibLocation = () => tsLibDir;
174
- host.getDefaultLibFileName = (options) => join(tsLibDir, ts.getDefaultLibFileName(options));
175
- host.getSourceFile = (fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile) => {
176
- const source = ts.sys.readFile(fileName);
177
- if (source === undefined) {
178
- return originalGetSourceFile(fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile);
179
- }
180
- if (shouldTransform(fileName) && hasJsonSchemaMarkers(source)) {
181
- if (!fileFilter || fileFilter(fileName)) {
182
- const transformed = transformJsonSchemas(fileName, source, projectDir);
183
- return ts.createSourceFile(fileName, transformed, languageVersionOrOptions);
184
- }
185
- }
186
- return ts.createSourceFile(fileName, source, languageVersionOrOptions);
187
- };
81
+ const originalGetSourceFile = host.getSourceFile.bind(host), tsLibDir = getTypeScriptLibDir();
82
+ host.getDefaultLibLocation = () => tsLibDir, host.getDefaultLibFileName = (options) => join(tsLibDir, ts.getDefaultLibFileName(options)), host.getSourceFile = (fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile) => {
83
+ const source = ts.sys.readFile(fileName);
84
+ if (source === void 0)
85
+ return originalGetSourceFile(fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile);
86
+ if (shouldTransform(fileName) && hasJsonSchemaMarkers(source) && (!fileFilter || fileFilter(fileName))) {
87
+ const transformed = transformJsonSchemas(fileName, source, projectDir);
88
+ return ts.createSourceFile(fileName, transformed, languageVersionOrOptions);
89
+ }
90
+ return ts.createSourceFile(fileName, source, languageVersionOrOptions);
91
+ };
188
92
  }
189
- /**
190
- * Create a watch-mode compiler host with @JSONSchema transformation.
191
- *
192
- * Uses TypeScript's `ts.createWatchCompilerHost` (config-file mode) with a
193
- * custom `createProgram` callback that patches the host's `getSourceFile()`
194
- * to apply `@JSONSchema` namespace injection. TypeScript handles file watching,
195
- * debouncing, and incremental re-compilation automatically.
196
- *
197
- * @param options - Watch host configuration
198
- * @returns A watch compiler host ready to pass to `ts.createWatchProgram()`
199
- */
200
93
  export function createThinkwellWatchHost(options) {
201
- const { configPath, fileFilter, projectDir, reportDiagnostic, reportWatchStatus } = options;
202
- const createProgram = (rootNames, compilerOptions, host, oldProgram, configFileParsingDiagnostics, projectReferences) => {
203
- // Patch the host that TypeScript's watch system created, rather than
204
- // replacing it entirely. This preserves watch-specific internal state.
205
- if (host) {
206
- patchHost(host, fileFilter, projectDir);
207
- }
208
- return ts.createEmitAndSemanticDiagnosticsBuilderProgram(rootNames, compilerOptions, host, oldProgram, configFileParsingDiagnostics, projectReferences);
209
- };
210
- return ts.createWatchCompilerHost(resolve(configPath),
211
- /* optionsToExtend */ undefined, ts.sys, createProgram, reportDiagnostic, reportWatchStatus);
94
+ const { configPath, fileFilter, projectDir, reportDiagnostic, reportWatchStatus } = options, createProgram = (rootNames, compilerOptions, host, oldProgram, configFileParsingDiagnostics, projectReferences) => (host && patchHost(host, fileFilter, projectDir), ts.createEmitAndSemanticDiagnosticsBuilderProgram(rootNames, compilerOptions, host, oldProgram, configFileParsingDiagnostics, projectReferences));
95
+ return ts.createWatchCompilerHost(
96
+ resolve(configPath),
97
+ /* optionsToExtend */
98
+ void 0,
99
+ ts.sys,
100
+ createProgram,
101
+ reportDiagnostic,
102
+ reportWatchStatus
103
+ );
212
104
  }
213
- //# sourceMappingURL=compiler-host.js.map