@opencode/codemode 0.0.0-dev-19919 → 0.0.0-dev-19925

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.
@@ -28,21 +28,27 @@ const loopExit = (result, labels) => {
28
28
  return result;
29
29
  return undefined;
30
30
  };
31
- const calleeDescription = (callee) => {
32
- if (callee?.type === "Identifier")
33
- return callee.name;
34
- if (callee?.type === "MemberExpression") {
35
- const object = callee.object;
36
- const property = callee.property;
37
- const key = !callee.computed && property.type === "Identifier"
38
- ? property.name
39
- : property.type === "Literal" && typeof property.value === "string"
40
- ? property.value
41
- : undefined;
42
- if (object.type === "Identifier" && key !== undefined)
43
- return `${object.name}.${key}`;
44
- }
45
- return "The called value";
31
+ // Native engines name the callee (`search(...).catch is not a function`), including call chains. Returns
32
+ // undefined when a link cannot be named, so a chain is either named completely or not at all.
33
+ const calleeDescription = (node) => {
34
+ if (node?.type === "Identifier")
35
+ return node.name;
36
+ if (node?.type === "CallExpression") {
37
+ const target = calleeDescription(node.callee);
38
+ return target === undefined ? undefined : `${target}(...)`;
39
+ }
40
+ if (node?.type !== "MemberExpression")
41
+ return undefined;
42
+ const property = node.property;
43
+ const key = !node.computed && property.type === "Identifier"
44
+ ? property.name
45
+ : property.type === "Literal" && typeof property.value === "string"
46
+ ? property.value
47
+ : undefined;
48
+ if (key === undefined)
49
+ return undefined;
50
+ const object = calleeDescription(node.object);
51
+ return object === undefined ? undefined : `${object}.${key}`;
46
52
  };
47
53
  // OrdinaryHasInstance: walk the left operand's chain looking for the constructor's `prototype`.
48
54
  const instanceofValue = (lhs, rhs, node) => {
@@ -1026,7 +1032,7 @@ class Frame {
1026
1032
  // `new` itself is supported, so a non-constructible callee is a TypeError like JS rather than
1027
1033
  // unsupported syntax. Built-ins like Number are real constructors in JS, so do not claim
1028
1034
  // otherwise; say `new` is unsupported for them and point at the plain call.
1029
- const name = calleeDescription(node.callee);
1035
+ const name = calleeDescription(node.callee) ?? "The called value";
1030
1036
  const message = callee instanceof Fn
1031
1037
  ? `${name} cannot be constructed: user-defined constructors and classes are not supported. Call it as a function that returns a plain object instead.`
1032
1038
  : callee instanceof Native
@@ -1313,7 +1319,7 @@ class Frame {
1313
1319
  if (callable instanceof Native) {
1314
1320
  return yield* self.native(() => callable.call(thisValue, args), node);
1315
1321
  }
1316
- throw typeError(`${calleeDescription(callee)} is not a function.`, callee ?? node);
1322
+ throw typeError(`${calleeDescription(callee) ?? "The called value"} is not a function.`, callee ?? node);
1317
1323
  });
1318
1324
  }
1319
1325
  // Built-ins throw without a location, synchronously or inside their Effect; the call site supplies it.
@@ -52,9 +52,10 @@ export const uriError = failure("URIError");
52
52
  export const supportedSyntaxMessage = "This is a restricted JavaScript-like language. Supported: plain and async functions, data literals, destructuring, standard control flow, await and Promise, and built-ins such as Array, Object, Math, JSON, Date, RegExp, Map, Set, and URL. Unsupported: classes, this, getters/setters, tagged templates, BigInt, and custom Symbols. Use plain functions and data objects instead.";
53
53
  export const unsupportedSyntax = (kind, node) => new PendingThrow("SyntaxError", `Syntax '${kind}' is not supported. ${supportedSyntaxMessage}`, node, "UnsupportedSyntax", [supportedSyntaxMessage]);
54
54
  export const isRecord = (value) => typeof value === "object" && value !== null;
55
+ // Acorn lines are 1-based and its columns are 0-based. Diagnostics use 1-based columns of the submitted source.
55
56
  export const sourceLocation = (node) => ({
56
- line: Math.max(1, (node.loc?.start.line ?? 2) - 1),
57
- column: Math.max(1, (node.loc?.start.column ?? 4) - 3),
57
+ line: node.loc?.start.line ?? 1,
58
+ column: (node.loc?.start.column ?? 0) + 1,
58
59
  });
59
60
  export const formatLocation = (node) => {
60
61
  if (!node?.loc)
@@ -66,6 +66,8 @@ export type Prepared<R = never> = {
66
66
  };
67
67
  export type SearchEntry = {
68
68
  readonly description: ToolDescription;
69
+ /** The path split into words, so `zones` matches `get_zones` as a word rather than as a substring of `timezones`. */
70
+ readonly pathWords: ReadonlyArray<string>;
69
71
  readonly searchText: string;
70
72
  };
71
73
  /** Exact callable signature of the built-in `search` function, for host-owned instructions. */
@@ -136,6 +136,7 @@ const makeSearchTool = (searchIndex) => ({
136
136
  const description = entry.description.description.toLowerCase();
137
137
  const score = terms.reduce((total, forms) => total +
138
138
  (forms.some((form) => path === form || path.endsWith(`.${form}`)) ? 20 : 0) +
139
+ (forms.some((form) => entry.pathWords.includes(form)) ? 12 : 0) +
139
140
  (forms.some((form) => path.includes(form)) ? 8 : 0) +
140
141
  (forms.some((form) => description.includes(form)) ? 4 : 0) +
141
142
  (forms.some((form) => entry.searchText.includes(form)) ? 2 : 0), 0);
@@ -163,6 +164,7 @@ export const searchSignature = (() => {
163
164
  })();
164
165
  const toSearchEntry = (visible) => ({
165
166
  description: describeTool(visible),
167
+ pathWords: tokenize(visible.path),
166
168
  searchText: [
167
169
  visible.path,
168
170
  visible.tool.description,
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-19919",
4
+ "version": "0.0.0-dev-19925",
5
5
  "description": "Effect-native confined code execution over schema-described tools",
6
6
  "type": "module",
7
7
  "license": "MIT",