@opencode/codemode 0.0.0-dev-19961 → 0.0.0-dev-19962

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.
@@ -109,6 +109,24 @@ const termForms = (term) => {
109
109
  forms.push(term.slice(0, -1));
110
110
  return forms;
111
111
  };
112
+ const rank = (entries, query) => {
113
+ const terms = tokenize(query).map(termForms);
114
+ return entries
115
+ .map((entry) => {
116
+ const path = entry.description.path.toLowerCase();
117
+ const description = entry.description.description.toLowerCase();
118
+ const score = terms.reduce((total, forms) => total +
119
+ (forms.some((form) => path === form || path.endsWith(`.${form}`)) ? 20 : 0) +
120
+ (forms.some((form) => entry.pathWords.includes(form)) ? 12 : 0) +
121
+ (forms.some((form) => path.includes(form)) ? 8 : 0) +
122
+ (forms.some((form) => description.includes(form)) ? 4 : 0) +
123
+ (forms.some((form) => entry.searchText.includes(form)) ? 2 : 0), 0);
124
+ return { entry, score };
125
+ })
126
+ .filter(({ score }) => terms.length === 0 || score > 0)
127
+ .sort((left, right) => right.score - left.score || compareText(left.entry.description.path, right.entry.description.path))
128
+ .map(({ entry }) => entry);
129
+ };
112
130
  const makeSearchTool = (searchIndex) => ({
113
131
  _tag: "CodeModeTool",
114
132
  description: "Search available tools",
@@ -133,24 +151,7 @@ const makeSearchTool = (searchIndex) => ({
133
151
  const exact = pathQuery === ""
134
152
  ? undefined
135
153
  : scoped.find((entry) => entry.description.path === pathQuery || toolExpression(entry.description.path) === trimmed);
136
- const terms = tokenize(query).map(termForms);
137
- const ranked = exact !== undefined
138
- ? [exact]
139
- : scoped
140
- .map((entry) => {
141
- const path = entry.description.path.toLowerCase();
142
- const description = entry.description.description.toLowerCase();
143
- const score = terms.reduce((total, forms) => total +
144
- (forms.some((form) => path === form || path.endsWith(`.${form}`)) ? 20 : 0) +
145
- (forms.some((form) => entry.pathWords.includes(form)) ? 12 : 0) +
146
- (forms.some((form) => path.includes(form)) ? 8 : 0) +
147
- (forms.some((form) => description.includes(form)) ? 4 : 0) +
148
- (forms.some((form) => entry.searchText.includes(form)) ? 2 : 0), 0);
149
- return { entry, score };
150
- })
151
- .filter(({ score }) => terms.length === 0 || score > 0)
152
- .sort((left, right) => right.score - left.score || compareText(left.entry.description.path, right.entry.description.path))
153
- .map(({ entry }) => entry);
154
+ const ranked = exact !== undefined ? [exact] : rank(scoped, query);
154
155
  const items = ranked.slice(offset, offset + (request.limit ?? defaultSearchLimit)).map(({ description }) => ({
155
156
  ...description,
156
157
  path: toolExpression(description.path),
@@ -207,13 +208,16 @@ const namespaceKeys = (root, path) => {
207
208
  }
208
209
  return Array.from(node.children.keys());
209
210
  };
210
- const resolve = (root, path) => {
211
+ const resolve = (root, path, index) => {
211
212
  const segments = canonicalSegments(path);
212
213
  const node = lookup(root, segments);
213
214
  if (node === undefined) {
214
- throw new ToolRuntimeError("UnknownTool", `Unknown tool '${segments.join(".")}'.`, [
215
- "The tool may have been removed or renamed. Use search to find available tools.",
216
- ]);
215
+ const name = segments.join(".");
216
+ const ns = segments.length > 1 && root.children.has(segments[0]) ? segments[0] : undefined;
217
+ const closest = rank(ns ? index.filter((entry) => entry.description.path.startsWith(`${ns}.`)) : index, ns ? segments.slice(1).join(" ") : name)[0];
218
+ throw new ToolRuntimeError("UnknownTool", closest
219
+ ? `Unknown tool '${name}'. Did you mean ${toolExpression(closest.description.path)}?`
220
+ : `Unknown tool '${name}'.`, ["Use search to find available tools."]);
217
221
  }
218
222
  if (node.tool === undefined) {
219
223
  throw new ToolRuntimeError("UnknownTool", `Tool '${segments.join(".")}' is not callable.`);
@@ -277,7 +281,7 @@ export const make = (prepared, maxToolCalls, hooks = {}) => {
277
281
  // Models often write `tools.search(...)` for the bare `search(...)`; honor it unless a tool owns that path.
278
282
  if (segments.length === 1 && segments[0] === "search" && lookup(root, segments) === undefined)
279
283
  return executeTool("search", makeSearchTool(prepared.searchIndex), args);
280
- return executeTool(segments.join("."), resolve(root, path), args);
284
+ return executeTool(segments.join("."), resolve(root, path, prepared.searchIndex), args);
281
285
  }),
282
286
  };
283
287
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@opencode/codemode",
4
- "version": "0.0.0-dev-19961",
4
+ "version": "0.0.0-dev-19962",
5
5
  "description": "Effect-native confined code execution over schema-described tools",
6
6
  "type": "module",
7
7
  "license": "MIT",