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.
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +207 -279
- package/dist/agent.js.map +1 -1
- package/dist/build.js +44 -98
- package/dist/cli/build.js +92 -227
- package/dist/cli/bundle.js +570 -1136
- package/dist/cli/check.js +125 -214
- package/dist/cli/commands.js +63 -177
- package/dist/cli/compiler-host.js +81 -190
- package/dist/cli/dependency-check.js +125 -269
- package/dist/cli/dependency-errors.js +12 -84
- package/dist/cli/fmt.js +1 -13
- package/dist/cli/init-command.js +21 -68
- package/dist/cli/init.js +90 -220
- package/dist/cli/loader.js +95 -361
- package/dist/cli/new-command.js +25 -73
- package/dist/cli/package-manager.js +50 -117
- package/dist/cli/schema.js +89 -245
- package/dist/cli/workspace.js +92 -226
- package/dist/connectors/index.js +1 -7
- package/dist/generated/features.d.ts +5 -0
- package/dist/generated/features.d.ts.map +1 -0
- package/dist/generated/features.js +4 -0
- package/dist/generated/features.js.map +1 -0
- package/dist/index.js +0 -5
- package/dist/schema.js +3 -36
- package/dist/session.js +50 -82
- package/dist/think-builder.d.ts.map +1 -1
- package/dist/think-builder.js +269 -370
- package/dist/think-builder.js.map +1 -1
- package/dist/thought-event.d.ts +1 -0
- package/dist/thought-event.d.ts.map +1 -1
- package/dist/thought-event.js +0 -1
- package/dist/thought-stream.js +60 -96
- package/dist-pkg/acp.cjs +13385 -1876
- package/dist-pkg/cli-build.cjs +171 -369
- package/dist-pkg/cli-bundle.cjs +289 -690
- package/dist-pkg/cli-check.cjs +202 -415
- package/dist-pkg/cli-dependency-check.cjs +39 -82
- package/dist-pkg/cli-dependency-errors.cjs +9 -41
- package/dist-pkg/cli-loader.cjs +90 -173
- package/dist-pkg/protocol.cjs +2 -8
- package/dist-pkg/thinkwell.cjs +876 -1842
- package/package.json +7 -6
|
@@ -41,33 +41,25 @@ var LOCKFILES = [
|
|
|
41
41
|
function detectByLockfile(projectDir) {
|
|
42
42
|
for (const { file, pm } of LOCKFILES) {
|
|
43
43
|
const lockfilePath = (0, import_node_path.join)(projectDir, file);
|
|
44
|
-
if ((0, import_node_fs.existsSync)(lockfilePath))
|
|
44
|
+
if ((0, import_node_fs.existsSync)(lockfilePath))
|
|
45
45
|
return { pm, lockfile: file };
|
|
46
|
-
}
|
|
47
46
|
}
|
|
48
47
|
return null;
|
|
49
48
|
}
|
|
50
49
|
__name(detectByLockfile, "detectByLockfile");
|
|
51
50
|
function parsePackageManagerField(value) {
|
|
52
|
-
if (typeof value
|
|
51
|
+
if (typeof value != "string")
|
|
53
52
|
return null;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const name = atIndex > 0 ? value.slice(0, atIndex) : value;
|
|
57
|
-
if (name === "pnpm" || name === "npm" || name === "yarn") {
|
|
58
|
-
return name;
|
|
59
|
-
}
|
|
60
|
-
return null;
|
|
53
|
+
const atIndex = value.indexOf("@"), name = atIndex > 0 ? value.slice(0, atIndex) : value;
|
|
54
|
+
return name === "pnpm" || name === "npm" || name === "yarn" ? name : null;
|
|
61
55
|
}
|
|
62
56
|
__name(parsePackageManagerField, "parsePackageManagerField");
|
|
63
57
|
function detectByPackageJson(projectDir) {
|
|
64
58
|
const pkgPath = (0, import_node_path.join)(projectDir, "package.json");
|
|
65
|
-
if (!(0, import_node_fs.existsSync)(pkgPath))
|
|
59
|
+
if (!(0, import_node_fs.existsSync)(pkgPath))
|
|
66
60
|
return null;
|
|
67
|
-
}
|
|
68
61
|
try {
|
|
69
|
-
const content = (0, import_node_fs.readFileSync)(pkgPath, "utf-8");
|
|
70
|
-
const pkg = JSON.parse(content);
|
|
62
|
+
const content = (0, import_node_fs.readFileSync)(pkgPath, "utf-8"), pkg = JSON.parse(content);
|
|
71
63
|
return parsePackageManagerField(pkg.packageManager);
|
|
72
64
|
} catch {
|
|
73
65
|
return null;
|
|
@@ -103,23 +95,18 @@ function createPackageManagerInfo(name, lockfile) {
|
|
|
103
95
|
__name(createPackageManagerInfo, "createPackageManagerInfo");
|
|
104
96
|
function detectPackageManager(projectDir) {
|
|
105
97
|
const lockfileResult = detectByLockfile(projectDir);
|
|
106
|
-
if (lockfileResult)
|
|
98
|
+
if (lockfileResult)
|
|
107
99
|
return createPackageManagerInfo(lockfileResult.pm, lockfileResult.lockfile);
|
|
108
|
-
}
|
|
109
100
|
const fromField = detectByPackageJson(projectDir);
|
|
110
|
-
|
|
111
|
-
return createPackageManagerInfo(fromField, null);
|
|
112
|
-
}
|
|
113
|
-
return createPackageManagerInfo("npm", null);
|
|
101
|
+
return createPackageManagerInfo(fromField || "npm", null);
|
|
114
102
|
}
|
|
115
103
|
__name(detectPackageManager, "detectPackageManager");
|
|
116
104
|
|
|
117
105
|
// dist/cli/dependency-check.js
|
|
118
106
|
function readPackageJson(dir) {
|
|
119
107
|
const pkgPath = (0, import_node_path2.join)(dir, "package.json");
|
|
120
|
-
if (!(0, import_node_fs2.existsSync)(pkgPath))
|
|
108
|
+
if (!(0, import_node_fs2.existsSync)(pkgPath))
|
|
121
109
|
return null;
|
|
122
|
-
}
|
|
123
110
|
try {
|
|
124
111
|
const content = (0, import_node_fs2.readFileSync)(pkgPath, "utf-8");
|
|
125
112
|
return JSON.parse(content);
|
|
@@ -135,42 +122,31 @@ function checkPackageJsonDirect(pkg, packageName) {
|
|
|
135
122
|
pkg.peerDependencies,
|
|
136
123
|
pkg.optionalDependencies
|
|
137
124
|
];
|
|
138
|
-
for (const deps of depTypes)
|
|
139
|
-
if (deps && packageName in deps)
|
|
125
|
+
for (const deps of depTypes)
|
|
126
|
+
if (deps && packageName in deps)
|
|
140
127
|
return {
|
|
141
128
|
found: true,
|
|
142
129
|
version: deps[packageName],
|
|
143
130
|
source: "package.json"
|
|
144
131
|
};
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
132
|
return null;
|
|
148
133
|
}
|
|
149
134
|
__name(checkPackageJsonDirect, "checkPackageJsonDirect");
|
|
150
135
|
function execCommand(cmd, cwd) {
|
|
151
136
|
return new Promise((resolve, reject) => {
|
|
152
|
-
const [command, ...args] = cmd
|
|
153
|
-
const proc = (0, import_node_child_process.spawn)(command, args, {
|
|
137
|
+
const [command, ...args] = cmd, proc = (0, import_node_child_process.spawn)(command, args, {
|
|
154
138
|
cwd,
|
|
155
139
|
stdio: ["ignore", "pipe", "pipe"]
|
|
156
140
|
});
|
|
157
|
-
let stdout = "";
|
|
158
|
-
let stderr = "";
|
|
141
|
+
let stdout = "", stderr = "";
|
|
159
142
|
proc.stdout.on("data", (data) => {
|
|
160
143
|
stdout += data.toString();
|
|
161
|
-
})
|
|
162
|
-
proc.stderr.on("data", (data) => {
|
|
144
|
+
}), proc.stderr.on("data", (data) => {
|
|
163
145
|
stderr += data.toString();
|
|
164
|
-
})
|
|
165
|
-
proc.on("error", (err) => {
|
|
146
|
+
}), proc.on("error", (err) => {
|
|
166
147
|
reject(err);
|
|
167
|
-
})
|
|
168
|
-
|
|
169
|
-
if (code === 0) {
|
|
170
|
-
resolve({ stdout, stderr });
|
|
171
|
-
} else {
|
|
172
|
-
reject(new Error(`Command failed with exit code ${code}: ${stderr}`));
|
|
173
|
-
}
|
|
148
|
+
}), proc.on("close", (code) => {
|
|
149
|
+
code === 0 ? resolve({ stdout, stderr }) : reject(new Error(`Command failed with exit code ${code}: ${stderr}`));
|
|
174
150
|
});
|
|
175
151
|
});
|
|
176
152
|
}
|
|
@@ -178,15 +154,11 @@ __name(execCommand, "execCommand");
|
|
|
178
154
|
function parsePnpmWhyOutput(stdout, packageName) {
|
|
179
155
|
try {
|
|
180
156
|
const result = JSON.parse(stdout);
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
source: "workspace"
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
return null;
|
|
157
|
+
return result && typeof result == "object" && packageName in result ? {
|
|
158
|
+
found: true,
|
|
159
|
+
version: result[packageName]?.version,
|
|
160
|
+
source: "workspace"
|
|
161
|
+
} : null;
|
|
190
162
|
} catch {
|
|
191
163
|
return null;
|
|
192
164
|
}
|
|
@@ -195,15 +167,11 @@ __name(parsePnpmWhyOutput, "parsePnpmWhyOutput");
|
|
|
195
167
|
function parseNpmWhyOutput(stdout, _packageName) {
|
|
196
168
|
try {
|
|
197
169
|
const result = JSON.parse(stdout);
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
source: "workspace"
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
return null;
|
|
170
|
+
return Array.isArray(result) && result.length > 0 ? {
|
|
171
|
+
found: true,
|
|
172
|
+
version: result[0]?.version,
|
|
173
|
+
source: "workspace"
|
|
174
|
+
} : null;
|
|
207
175
|
} catch {
|
|
208
176
|
return null;
|
|
209
177
|
}
|
|
@@ -213,7 +181,8 @@ function parseYarnWhyOutput(stdout, _packageName) {
|
|
|
213
181
|
if (stdout.trim().length > 0) {
|
|
214
182
|
let version;
|
|
215
183
|
try {
|
|
216
|
-
const lines = stdout.trim().split(
|
|
184
|
+
const lines = stdout.trim().split(`
|
|
185
|
+
`);
|
|
217
186
|
for (const line of lines) {
|
|
218
187
|
const obj = JSON.parse(line);
|
|
219
188
|
if (obj.type === "info" && obj.data) {
|
|
@@ -253,31 +222,21 @@ async function checkViaPackageManager(pm, packageName, cwd) {
|
|
|
253
222
|
}
|
|
254
223
|
__name(checkViaPackageManager, "checkViaPackageManager");
|
|
255
224
|
async function checkDependencies(projectDir) {
|
|
256
|
-
const pm = detectPackageManager(projectDir);
|
|
257
|
-
|
|
258
|
-
let thinkwellStatus = { found: false };
|
|
259
|
-
let typescriptStatus = { found: false };
|
|
225
|
+
const pm = detectPackageManager(projectDir), pkg = readPackageJson(projectDir);
|
|
226
|
+
let thinkwellStatus = { found: false }, typescriptStatus = { found: false };
|
|
260
227
|
if (pkg) {
|
|
261
228
|
const thinkwellDirect = checkPackageJsonDirect(pkg, "thinkwell");
|
|
262
|
-
|
|
263
|
-
thinkwellStatus = thinkwellDirect;
|
|
264
|
-
}
|
|
229
|
+
thinkwellDirect && (thinkwellStatus = thinkwellDirect);
|
|
265
230
|
const typescriptDirect = checkPackageJsonDirect(pkg, "typescript");
|
|
266
|
-
|
|
267
|
-
typescriptStatus = typescriptDirect;
|
|
268
|
-
}
|
|
231
|
+
typescriptDirect && (typescriptStatus = typescriptDirect);
|
|
269
232
|
}
|
|
270
233
|
if (!thinkwellStatus.found) {
|
|
271
234
|
const result = await checkViaPackageManager(pm, "thinkwell", projectDir);
|
|
272
|
-
|
|
273
|
-
thinkwellStatus = result;
|
|
274
|
-
}
|
|
235
|
+
result && (thinkwellStatus = result);
|
|
275
236
|
}
|
|
276
237
|
if (!typescriptStatus.found) {
|
|
277
238
|
const result = await checkViaPackageManager(pm, "typescript", projectDir);
|
|
278
|
-
|
|
279
|
-
typescriptStatus = result;
|
|
280
|
-
}
|
|
239
|
+
result && (typescriptStatus = result);
|
|
281
240
|
}
|
|
282
241
|
return {
|
|
283
242
|
thinkwell: thinkwellStatus,
|
|
@@ -292,14 +251,12 @@ function hasPackageJson(projectDir) {
|
|
|
292
251
|
__name(hasPackageJson, "hasPackageJson");
|
|
293
252
|
function findProjectRoot(startDir) {
|
|
294
253
|
let dir = startDir;
|
|
295
|
-
|
|
296
|
-
if ((0, import_node_fs2.existsSync)((0, import_node_path2.join)(dir, "package.json")))
|
|
254
|
+
for (; ; ) {
|
|
255
|
+
if ((0, import_node_fs2.existsSync)((0, import_node_path2.join)(dir, "package.json")))
|
|
297
256
|
return dir;
|
|
298
|
-
}
|
|
299
257
|
const parent = (0, import_node_path2.dirname)(dir);
|
|
300
|
-
if (parent === dir)
|
|
301
|
-
return
|
|
302
|
-
}
|
|
258
|
+
if (parent === dir)
|
|
259
|
+
return;
|
|
303
260
|
dir = parent;
|
|
304
261
|
}
|
|
305
262
|
}
|
|
@@ -28,34 +28,12 @@ __export(dependency_errors_exports, {
|
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(dependency_errors_exports);
|
|
30
30
|
function formatMissingDependencyError(result) {
|
|
31
|
-
const { thinkwell, typescript, packageManager } = result;
|
|
32
|
-
|
|
33
|
-
const missing = [];
|
|
34
|
-
if (!thinkwell.found)
|
|
35
|
-
missing.push("thinkwell");
|
|
36
|
-
if (!typescript.found)
|
|
37
|
-
missing.push("typescript");
|
|
38
|
-
if (missing.length === 0) {
|
|
31
|
+
const { thinkwell, typescript, packageManager } = result, pm = packageManager, missing = [];
|
|
32
|
+
if (thinkwell.found || missing.push("thinkwell"), typescript.found || missing.push("typescript"), missing.length === 0)
|
|
39
33
|
return "";
|
|
40
|
-
}
|
|
41
34
|
const lines = [];
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
} else {
|
|
45
|
-
lines.push(`Error: This project has a package.json but is missing required dependencies.`);
|
|
46
|
-
}
|
|
47
|
-
lines.push("");
|
|
48
|
-
lines.push("When a project has explicit configuration, thinkwell expects explicit dependencies.");
|
|
49
|
-
lines.push("This ensures you get the versions you expect, not versions bundled with the CLI.");
|
|
50
|
-
lines.push("");
|
|
51
|
-
lines.push("Run 'thinkwell init' to add the required dependencies, or add them manually:");
|
|
52
|
-
if (!thinkwell.found) {
|
|
53
|
-
lines.push(` ${pm.addCommand("thinkwell")}`);
|
|
54
|
-
}
|
|
55
|
-
if (!typescript.found) {
|
|
56
|
-
lines.push(` ${pm.addCommand("typescript", true)}`);
|
|
57
|
-
}
|
|
58
|
-
return lines.join("\n");
|
|
35
|
+
return missing.length === 1 ? lines.push(`Error: This project has a package.json but no dependency on '${missing[0]}'.`) : lines.push("Error: This project has a package.json but is missing required dependencies."), lines.push(""), lines.push("When a project has explicit configuration, thinkwell expects explicit dependencies."), lines.push("This ensures you get the versions you expect, not versions bundled with the CLI."), lines.push(""), lines.push("Run 'thinkwell init' to add the required dependencies, or add them manually:"), thinkwell.found || lines.push(` ${pm.addCommand("thinkwell")}`), typescript.found || lines.push(` ${pm.addCommand("typescript", true)}`), lines.join(`
|
|
36
|
+
`);
|
|
59
37
|
}
|
|
60
38
|
__name(formatMissingDependencyError, "formatMissingDependencyError");
|
|
61
39
|
function hasMissingDependencies(result) {
|
|
@@ -63,24 +41,14 @@ function hasMissingDependencies(result) {
|
|
|
63
41
|
}
|
|
64
42
|
__name(hasMissingDependencies, "hasMissingDependencies");
|
|
65
43
|
function hasMissingDeps(result, options) {
|
|
66
|
-
|
|
67
|
-
return true;
|
|
68
|
-
if (options.requireTypescript && !result.typescript.found)
|
|
69
|
-
return true;
|
|
70
|
-
return false;
|
|
44
|
+
return !!(!result.thinkwell.found || options.requireTypescript && !result.typescript.found);
|
|
71
45
|
}
|
|
72
46
|
__name(hasMissingDeps, "hasMissingDeps");
|
|
73
47
|
function formatMissingDepsError(result, options) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return formatMissingDependencyError({
|
|
79
|
-
...result,
|
|
80
|
-
typescript: { found: true }
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
return formatMissingDependencyError(result);
|
|
48
|
+
return !options.requireTypescript && result.thinkwell.found ? "" : options.requireTypescript ? formatMissingDependencyError(result) : formatMissingDependencyError({
|
|
49
|
+
...result,
|
|
50
|
+
typescript: { found: true }
|
|
51
|
+
});
|
|
84
52
|
}
|
|
85
53
|
__name(formatMissingDepsError, "formatMissingDepsError");
|
|
86
54
|
// Annotate the CommonJS export names for ESM import in node:
|