thinkwell 0.5.2 → 0.5.4

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 (67) hide show
  1. package/bin/thinkwell +6 -4
  2. package/dist/agent.d.ts +3 -3
  3. package/dist/agent.d.ts.map +1 -1
  4. package/dist/agent.js +3 -3
  5. package/dist/agent.js.map +1 -1
  6. package/dist/build.d.ts +28 -0
  7. package/dist/build.d.ts.map +1 -0
  8. package/dist/build.js +110 -0
  9. package/dist/build.js.map +1 -0
  10. package/dist/cli/build.d.ts.map +1 -1
  11. package/dist/cli/build.js +7 -4
  12. package/dist/cli/build.js.map +1 -1
  13. package/dist/cli/bundle.d.ts.map +1 -1
  14. package/dist/cli/bundle.js +21 -3
  15. package/dist/cli/bundle.js.map +1 -1
  16. package/dist/cli/check.d.ts.map +1 -1
  17. package/dist/cli/check.js +7 -4
  18. package/dist/cli/check.js.map +1 -1
  19. package/dist/cli/commands.d.ts +15 -2
  20. package/dist/cli/commands.d.ts.map +1 -1
  21. package/dist/cli/commands.js +152 -7
  22. package/dist/cli/commands.js.map +1 -1
  23. package/dist/cli/compiler-host.d.ts +16 -0
  24. package/dist/cli/compiler-host.d.ts.map +1 -1
  25. package/dist/cli/compiler-host.js +13 -7
  26. package/dist/cli/compiler-host.js.map +1 -1
  27. package/dist/cli/dependency-check.d.ts +7 -0
  28. package/dist/cli/dependency-check.d.ts.map +1 -1
  29. package/dist/cli/dependency-check.js +20 -1
  30. package/dist/cli/dependency-check.js.map +1 -1
  31. package/dist/cli/dependency-errors.d.ts +17 -0
  32. package/dist/cli/dependency-errors.d.ts.map +1 -1
  33. package/dist/cli/dependency-errors.js +31 -0
  34. package/dist/cli/dependency-errors.js.map +1 -1
  35. package/dist/cli/loader.d.ts +9 -0
  36. package/dist/cli/loader.d.ts.map +1 -1
  37. package/dist/cli/loader.js +43 -12
  38. package/dist/cli/loader.js.map +1 -1
  39. package/dist/cli/schema.d.ts +15 -3
  40. package/dist/cli/schema.d.ts.map +1 -1
  41. package/dist/cli/schema.js +48 -76
  42. package/dist/cli/schema.js.map +1 -1
  43. package/dist/index.d.ts +2 -2
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +2 -2
  46. package/dist/index.js.map +1 -1
  47. package/dist/session.d.ts +3 -3
  48. package/dist/session.d.ts.map +1 -1
  49. package/dist/session.js +3 -3
  50. package/dist/session.js.map +1 -1
  51. package/dist/think-builder.d.ts +31 -105
  52. package/dist/think-builder.d.ts.map +1 -1
  53. package/dist/think-builder.js +82 -116
  54. package/dist/think-builder.js.map +1 -1
  55. package/dist/thought-stream.d.ts +1 -1
  56. package/dist/thought-stream.d.ts.map +1 -1
  57. package/dist/thought-stream.js +1 -1
  58. package/dist/thought-stream.js.map +1 -1
  59. package/dist-pkg/cli-build.cjs +166 -125
  60. package/dist-pkg/cli-bundle.cjs +560 -185
  61. package/dist-pkg/cli-check.cjs +156 -119
  62. package/dist-pkg/cli-dependency-check.cjs +312 -0
  63. package/dist-pkg/cli-dependency-errors.cjs +92 -0
  64. package/dist-pkg/cli-loader.cjs +144 -103
  65. package/dist-pkg/pkg-cli.cjs +119 -1
  66. package/dist-pkg/thinkwell.cjs +80 -109
  67. package/package.json +9 -4
@@ -219,8 +219,8 @@ var init_stdio = __esm({
219
219
  var index_exports = {};
220
220
  __export(index_exports, {
221
221
  Session: () => Session,
222
- ThinkBuilder: () => ThinkBuilder,
223
222
  ThoughtStream: () => ThoughtStream,
223
+ createPlan: () => createPlan,
224
224
  open: () => open,
225
225
  schemaOf: () => schemaOf
226
226
  });
@@ -19986,7 +19986,7 @@ var ThoughtStream = class {
19986
19986
  * @internal
19987
19987
  */
19988
19988
  rejectResult(error40) {
19989
- this._rejectResult(error40);
19989
+ this._rejectResult(error40 instanceof Error ? error40 : new Error(String(error40?.message ?? error40)));
19990
19990
  }
19991
19991
  [Symbol.asyncIterator]() {
19992
19992
  return {
@@ -20070,60 +20070,59 @@ var ThinkSession = class {
20070
20070
  this._updateResolvers = [];
20071
20071
  }
20072
20072
  };
20073
- var ThinkBuilder = class {
20073
+ var PlanImpl = class _PlanImpl {
20074
20074
  static {
20075
- __name(this, "ThinkBuilder");
20075
+ __name(this, "PlanImpl");
20076
20076
  }
20077
20077
  _conn;
20078
- _promptParts = [];
20079
- _tools = /* @__PURE__ */ new Map();
20080
- _skills = [];
20078
+ _promptParts;
20079
+ _tools;
20080
+ _skills;
20081
20081
  _schemaProvider;
20082
20082
  _cwd;
20083
20083
  _existingSessionId;
20084
- constructor(conn, schema, existingSessionId) {
20085
- this._conn = conn;
20086
- this._schemaProvider = schema;
20087
- this._existingSessionId = existingSessionId;
20084
+ constructor(state) {
20085
+ this._conn = state.conn;
20086
+ this._promptParts = state.promptParts;
20087
+ this._tools = state.tools;
20088
+ this._skills = state.skills;
20089
+ this._schemaProvider = state.schemaProvider;
20090
+ this._cwd = state.cwd;
20091
+ this._existingSessionId = state.existingSessionId;
20092
+ }
20093
+ _clone(overrides) {
20094
+ return new _PlanImpl({
20095
+ conn: this._conn,
20096
+ promptParts: this._promptParts,
20097
+ tools: this._tools,
20098
+ skills: this._skills,
20099
+ schemaProvider: this._schemaProvider,
20100
+ cwd: this._cwd,
20101
+ existingSessionId: this._existingSessionId,
20102
+ ...overrides
20103
+ });
20088
20104
  }
20089
- /**
20090
- * Add literal text to the prompt
20091
- */
20092
20105
  text(content) {
20093
- this._promptParts.push(content);
20094
- return this;
20106
+ return this._clone({ promptParts: [...this._promptParts, content] });
20095
20107
  }
20096
- /**
20097
- * Add a line of text with newline
20098
- */
20099
20108
  textln(content) {
20100
- this._promptParts.push(content + "\n");
20101
- return this;
20109
+ return this._clone({ promptParts: [...this._promptParts, content + "\n"] });
20102
20110
  }
20103
- /**
20104
- * Quote some content delimited by XML-style tags.
20105
- */
20106
20111
  quote(content, tag = "quote") {
20107
- if (!content.includes("\n")) {
20108
- this._promptParts.push(`<${tag}>${content}</${tag}>
20109
- `);
20110
- } else {
20111
- this._promptParts.push(`<${tag}>
20112
+ const part = !content.includes("\n") ? `<${tag}>${content}</${tag}>
20113
+ ` : `<${tag}>
20112
20114
  ${content}
20113
20115
  </${tag}>
20114
- `);
20115
- }
20116
- return this;
20116
+ `;
20117
+ return this._clone({ promptParts: [...this._promptParts, part] });
20117
20118
  }
20118
- /**
20119
- * Quote some content as a Markdown-style code block.
20120
- */
20121
20119
  code(content, language = "") {
20122
- this._promptParts.push(`\`\`\`${language}
20120
+ return this._clone({
20121
+ promptParts: [...this._promptParts, `\`\`\`${language}
20123
20122
  ${content}
20124
20123
  \`\`\`
20125
- `);
20126
- return this;
20124
+ `]
20125
+ });
20127
20126
  }
20128
20127
  tool(name, description, inputSchemaOrHandler, outputSchemaOrHandler, handler) {
20129
20128
  let inputSchema;
@@ -20142,7 +20141,8 @@ ${content}
20142
20141
  outputSchema = outputSchemaOrHandler;
20143
20142
  actualHandler = handler;
20144
20143
  }
20145
- this._tools.set(name, {
20144
+ const newTools = new Map(this._tools);
20145
+ newTools.set(name, {
20146
20146
  name,
20147
20147
  description,
20148
20148
  handler: actualHandler,
@@ -20150,7 +20150,7 @@ ${content}
20150
20150
  outputSchema,
20151
20151
  includeInPrompt: true
20152
20152
  });
20153
- return this;
20153
+ return this._clone({ tools: newTools });
20154
20154
  }
20155
20155
  defineTool(name, description, inputSchemaOrHandler, outputSchemaOrHandler, handler) {
20156
20156
  let inputSchema;
@@ -20169,7 +20169,8 @@ ${content}
20169
20169
  outputSchema = outputSchemaOrHandler;
20170
20170
  actualHandler = handler;
20171
20171
  }
20172
- this._tools.set(name, {
20172
+ const newTools = new Map(this._tools);
20173
+ newTools.set(name, {
20173
20174
  name,
20174
20175
  description,
20175
20176
  handler: actualHandler,
@@ -20177,53 +20178,30 @@ ${content}
20177
20178
  outputSchema,
20178
20179
  includeInPrompt: false
20179
20180
  });
20180
- return this;
20181
+ return this._clone({ tools: newTools });
20181
20182
  }
20182
- /**
20183
- * Attach a skill to this prompt.
20184
- *
20185
- * When called with a string, it is treated as a path to a SKILL.md file
20186
- * that will be parsed at run() time (deferred stored skill).
20187
- *
20188
- * When called with an object, it is treated as a virtual skill definition
20189
- * and validated eagerly.
20190
- *
20191
- * @param pathOrDef - Path to a SKILL.md file, or a virtual skill definition
20192
- */
20193
20183
  skill(pathOrDef) {
20194
20184
  if (typeof pathOrDef === "string") {
20195
- this._skills.push({ type: "stored", path: pathOrDef });
20185
+ return this._clone({ skills: [...this._skills, { type: "stored", path: pathOrDef }] });
20196
20186
  } else {
20197
20187
  validateSkillName(pathOrDef.name);
20198
20188
  validateSkillDescription(pathOrDef.description);
20199
- this._skills.push({
20200
- type: "virtual",
20201
- skill: {
20202
- name: pathOrDef.name,
20203
- description: pathOrDef.description,
20204
- body: pathOrDef.body,
20205
- tools: pathOrDef.tools
20206
- }
20189
+ return this._clone({
20190
+ skills: [...this._skills, {
20191
+ type: "virtual",
20192
+ skill: {
20193
+ name: pathOrDef.name,
20194
+ description: pathOrDef.description,
20195
+ body: pathOrDef.body,
20196
+ tools: pathOrDef.tools
20197
+ }
20198
+ }]
20207
20199
  });
20208
20200
  }
20209
- return this;
20210
20201
  }
20211
- /**
20212
- * Set the working directory for the session
20213
- */
20214
20202
  cwd(path) {
20215
- this._cwd = path;
20216
- return this;
20203
+ return this._clone({ cwd: path });
20217
20204
  }
20218
- /**
20219
- * Resolve all deferred skills into ResolvedSkill instances.
20220
- *
20221
- * - Virtual skills are passed through as-is.
20222
- * - Stored skills are loaded from disk: SKILL.md is parsed and basePath is
20223
- * set to the directory containing the file.
20224
- *
20225
- * Skills are returned in attachment order.
20226
- */
20227
20205
  async _resolveSkills() {
20228
20206
  const resolved = [];
20229
20207
  for (const deferred of this._skills) {
@@ -20243,12 +20221,6 @@ ${content}
20243
20221
  }
20244
20222
  return resolved;
20245
20223
  }
20246
- /**
20247
- * Build the `<available_skills>` XML block and infrastructure instructions.
20248
- *
20249
- * Returns the string to prepend before the user's prompt parts, or an
20250
- * empty string when no skills are attached.
20251
- */
20252
20224
  _buildSkillsPrompt(skills) {
20253
20225
  if (skills.length === 0)
20254
20226
  return "";
@@ -20271,30 +20243,15 @@ ${content}
20271
20243
  xml += "If the skill references files, use `read_skill_file` to access them.\n";
20272
20244
  return xml + "\n";
20273
20245
  }
20274
- /**
20275
- * Execute the prompt and return the result.
20276
- *
20277
- * This method:
20278
- * 1. Builds the final prompt from all text parts
20279
- * 2. Creates an MCP server with all registered tools
20280
- * 3. Adds a return_result tool for the output
20281
- * 4. Sends the prompt to the agent
20282
- * 5. Handles tool calls until the agent returns a result
20283
- * 6. Returns the typed result
20284
- */
20285
20246
  async run() {
20286
20247
  return this.stream().result;
20287
20248
  }
20288
- /**
20289
- * Start executing the prompt, returning a stream handle that provides
20290
- * both an async iterable of intermediate `ThoughtEvent`s and a `.result`
20291
- * promise for the final typed output.
20292
- *
20293
- * Execution begins eagerly — the returned stream is already "hot".
20294
- */
20295
20249
  stream() {
20296
20250
  const stream = new ThoughtStream();
20297
- this._executeStream(stream).catch((err) => stream.rejectResult(err));
20251
+ this._executeStream(stream).catch((err) => {
20252
+ stream.rejectResult(err instanceof Error ? err : new Error(String(err?.message ?? err)));
20253
+ stream.close();
20254
+ });
20298
20255
  return stream;
20299
20256
  }
20300
20257
  async _executeStream(stream) {
@@ -20318,10 +20275,12 @@ ${content}
20318
20275
  const serverBuilder = mcpServer("thinkwell");
20319
20276
  let resultReceived = false;
20320
20277
  let result;
20321
- const outputSchema = this._schemaProvider?.toJsonSchema() ?? { type: "object" };
20278
+ const rawSchema = this._schemaProvider?.toJsonSchema() ?? { type: "object" };
20279
+ const needsWrap = rawSchema.type !== "object";
20280
+ const outputSchema = needsWrap ? { type: "object", properties: { result: rawSchema }, required: ["result"] } : rawSchema;
20322
20281
  prompt += "\n\nWhen you have your answer, call the `return_result` MCP tool with the result.";
20323
20282
  serverBuilder.tool("return_result", "Return the final result", outputSchema, { type: "object", properties: { success: { type: "boolean" } } }, async (input) => {
20324
- result = input;
20283
+ result = needsWrap ? input.result : input;
20325
20284
  resultReceived = true;
20326
20285
  return { success: true };
20327
20286
  });
@@ -20396,6 +20355,18 @@ ${content}
20396
20355
  }
20397
20356
  }
20398
20357
  };
20358
+ function createPlan(conn, schema, existingSessionId) {
20359
+ return new PlanImpl({
20360
+ conn,
20361
+ promptParts: [],
20362
+ tools: /* @__PURE__ */ new Map(),
20363
+ skills: [],
20364
+ schemaProvider: schema,
20365
+ cwd: void 0,
20366
+ existingSessionId
20367
+ });
20368
+ }
20369
+ __name(createPlan, "createPlan");
20399
20370
 
20400
20371
  // dist/session.js
20401
20372
  var Session = class {
@@ -20421,7 +20392,7 @@ var Session = class {
20421
20392
  return this._sessionId;
20422
20393
  }
20423
20394
  /**
20424
- * Create a new think builder for constructing a prompt with tools.
20395
+ * Create a new plan for constructing a prompt with tools.
20425
20396
  *
20426
20397
  * Unlike `agent.think()`, prompts sent through a session maintain
20427
20398
  * conversation context - the agent remembers previous interactions.
@@ -20444,7 +20415,7 @@ var Session = class {
20444
20415
  if (this._closed) {
20445
20416
  throw new Error("Session is closed");
20446
20417
  }
20447
- return new ThinkBuilder(this._conn, schema, this._sessionId);
20418
+ return createPlan(this._conn, schema, this._sessionId);
20448
20419
  }
20449
20420
  /**
20450
20421
  * Close the session.
@@ -20459,7 +20430,7 @@ var Session = class {
20459
20430
 
20460
20431
  // dist/agent.js
20461
20432
  var AGENT_COMMANDS = {
20462
- claude: "npx -y @zed-industries/claude-code-acp",
20433
+ claude: "npx -y @zed-industries/claude-agent-acp",
20463
20434
  codex: "npx -y @zed-industries/codex-acp",
20464
20435
  gemini: "npx -y @google/gemini-cli --experimental-acp",
20465
20436
  kiro: "kiro-cli acp",
@@ -20479,7 +20450,7 @@ var AgentImpl = class {
20479
20450
  this._conn = conn;
20480
20451
  }
20481
20452
  think(schema) {
20482
- return new ThinkBuilder(this._conn, schema);
20453
+ return createPlan(this._conn, schema);
20483
20454
  }
20484
20455
  async createSession(options) {
20485
20456
  await this._initialize();
@@ -20727,8 +20698,8 @@ __name(schemaOf, "schemaOf");
20727
20698
  // Annotate the CommonJS export names for ESM import in node:
20728
20699
  0 && (module.exports = {
20729
20700
  Session,
20730
- ThinkBuilder,
20731
20701
  ThoughtStream,
20702
+ createPlan,
20732
20703
  open,
20733
20704
  schemaOf
20734
20705
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thinkwell",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "TypeScript library for blending deterministic code with LLM-powered reasoning",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -13,6 +13,11 @@
13
13
  "types": "./dist/index.d.ts",
14
14
  "import": "./dist/index.js",
15
15
  "default": "./dist/index.js"
16
+ },
17
+ "./build": {
18
+ "types": "./dist/build.d.ts",
19
+ "import": "./dist/build.js",
20
+ "default": "./dist/build.js"
16
21
  }
17
22
  },
18
23
  "engines": {
@@ -35,9 +40,9 @@
35
40
  "@agentclientprotocol/sdk": "^0.12.0",
36
41
  "ts-json-schema-generator": "^2.4.0",
37
42
  "typescript": "^5.7.2",
38
- "@thinkwell/conductor": "0.5.2",
39
- "@thinkwell/acp": "0.5.2",
40
- "@thinkwell/protocol": "0.5.2"
43
+ "@thinkwell/acp": "0.5.4",
44
+ "@thinkwell/conductor": "0.5.4",
45
+ "@thinkwell/protocol": "0.5.4"
41
46
  },
42
47
  "devDependencies": {
43
48
  "@types/node": "^24.10.4",