@opencode/codemode 0.0.0-dev-1136 → 0.0.0-dev-1147

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/README.md CHANGED
@@ -61,6 +61,10 @@ only shape the model-visible signature. Without `output`, the signature uses `Pr
61
61
 
62
62
  Descriptions and schemas are model-visible contracts. Authorization belongs in `execute`.
63
63
 
64
+ Set `freeform: true` on a tool whose input is one required string field to let programs pass that string directly. For
65
+ `{ patchText: string }`, the catalog shows `tools.patch(patchText: string)`, and `tools.patch("*** Begin Patch...")`
66
+ delivers `{ patchText: "*** Begin Patch..." }` to validation, hooks and the executor. The object form still works.
67
+
64
68
  Nested records are the shorthand for ordinary namespaces. Use `Namespace.make` when a namespace needs a description:
65
69
 
66
70
  ```ts
@@ -1,6 +1,6 @@
1
1
  import { Cause, Effect, Exit, Formatter, Schema } from "effect";
2
2
  import { toolError } from "./tool-error.js";
3
- import { decodeInput as decodeToolInput, decodeOutput as decodeToolOutput, identifierSegment, inputProperties, inputTypeScript, isEmptyInput, outputTypeScript, } from "./tool-schema.js";
3
+ import { decodeInput as decodeToolInput, decodeOutput as decodeToolOutput, identifierSegment, inputProperties, inputTypeScript, isEmptyInput, outputTypeScript, stringParameter, } from "./tool-schema.js";
4
4
  import { isNamespace } from "./namespace.js";
5
5
  import { isTool } from "./tool.js";
6
6
  export const compareText = (left, right) => (left < right ? -1 : left > right ? 1 : 0);
@@ -92,7 +92,8 @@ const describeTool = (visible) => {
92
92
  // Joining the final fragments avoids retaining the rendering's intermediate string ropes in JSC.
93
93
  return (signature ??= [
94
94
  toolExpression(visible.path),
95
- isEmptyInput(visible.tool) ? "()" : `(${inputTypeScript(visible.tool, true)})`,
95
+ stringParameter(visible.tool)?.signature ??
96
+ (isEmptyInput(visible.tool) ? "()" : `(${inputTypeScript(visible.tool, true)})`),
96
97
  `: Promise<${outputTypeScript(visible.tool, true)}>`,
97
98
  ].join(""));
98
99
  },
@@ -253,8 +254,10 @@ export const make = (prepared, maxToolCalls, hooks = {}) => {
253
254
  const normalized = args.length === 0 ? [{}] : args;
254
255
  if (normalized.length !== 1)
255
256
  throw new ToolRuntimeError("InvalidToolInput", `Tool '${name}' expects at most one input object.`);
257
+ const input = normalized[0];
258
+ const field = typeof input === "string" ? stringParameter(tool)?.name : undefined;
256
259
  return yield* Effect.try({
257
- try: () => decodeToolInput(tool, normalized[0]),
260
+ try: () => decodeToolInput(tool, field === undefined ? input : { [field]: input }),
258
261
  catch: (cause) => new ToolRuntimeError("InvalidToolInput", `Invalid input for tool '${name}': ${String(cause)}`, name === "search" ? [] : ["The signature may have changed. Use search to get the current signature."]),
259
262
  });
260
263
  });
@@ -9,6 +9,11 @@ export type InputProperty = {
9
9
  readonly required: boolean;
10
10
  };
11
11
  export declare const inputProperties: <R>(tool: Tool<R>) => Array<InputProperty>;
12
+ /** A freeform tool whose input is one required string field takes that string directly: `tools.patch(patchText: string)`. */
13
+ export declare const stringParameter: <R>(tool: Tool<R>) => {
14
+ name: string;
15
+ signature: string;
16
+ } | undefined;
12
17
  export declare const inputTypeScript: <R>(tool: Tool<R>, pretty?: boolean) => string;
13
18
  export declare const isEmptyInput: <R>(tool: Tool<R>) => boolean;
14
19
  export declare const outputTypeScript: <R>(tool: Tool<R>, pretty?: boolean) => string;
@@ -237,22 +237,9 @@ export const jsonSchemaToTypeScript = (schema, pretty = false) => {
237
237
  };
238
238
  export const inputProperties = (tool) => {
239
239
  try {
240
- const document = isEffectSchema(tool.input)
241
- ? Schema.toJsonSchemaDocument(tool.input, { onExcessProperty: "error" })
242
- : {
243
- schema: tool.input,
244
- definitions: { ...(tool.input.definitions ?? {}), ...(tool.input.$defs ?? {}) },
245
- };
246
- let schema = document.schema;
247
- if (schema.$ref !== undefined) {
248
- const name = definitionName(schema.$ref);
249
- const resolved = name === undefined ? undefined : document.definitions[name];
250
- if (resolved === undefined)
251
- return [];
252
- schema = resolved;
253
- }
254
- const required = new Set(schema.required ?? []);
255
- return Object.entries(schema.properties ?? {}).map(([name, value]) => ({
240
+ const schema = inputDocument(tool)?.schema;
241
+ const required = new Set(schema?.required ?? []);
242
+ return Object.entries(schema?.properties ?? {}).map(([name, value]) => ({
256
243
  name,
257
244
  description: typeof value.description === "string" ? value.description : undefined,
258
245
  required: required.has(name),
@@ -262,6 +249,39 @@ export const inputProperties = (tool) => {
262
249
  return [];
263
250
  }
264
251
  };
252
+ /** A freeform tool whose input is one required string field takes that string directly: `tools.patch(patchText: string)`. */
253
+ export const stringParameter = (tool) => {
254
+ if (!tool.freeform)
255
+ return undefined;
256
+ try {
257
+ const document = inputDocument(tool);
258
+ const fields = Object.entries(document?.schema.properties ?? {});
259
+ if (document === undefined || fields.length !== 1)
260
+ return undefined;
261
+ const [name, field] = fields[0];
262
+ if (field.type !== "string" || !document.schema.required?.includes(name))
263
+ return undefined;
264
+ const label = identifierSegment.test(name) ? name : "input";
265
+ const type = renderSchema(field, { definitions: document.definitions, pretty: false });
266
+ return { name, signature: `(${jsdoc(field, "").replace(/\n$/, " ")}${label}: ${type})` };
267
+ }
268
+ catch {
269
+ return undefined;
270
+ }
271
+ };
272
+ const inputDocument = (tool) => {
273
+ const document = isEffectSchema(tool.input)
274
+ ? Schema.toJsonSchemaDocument(tool.input, { onExcessProperty: "error" })
275
+ : {
276
+ schema: tool.input,
277
+ definitions: { ...(tool.input.definitions ?? {}), ...(tool.input.$defs ?? {}) },
278
+ };
279
+ if (document.schema.$ref === undefined)
280
+ return document;
281
+ const name = definitionName(document.schema.$ref);
282
+ const schema = name === undefined ? undefined : document.definitions[name];
283
+ return schema && { schema, definitions: document.definitions };
284
+ };
265
285
  export const inputTypeScript = (tool, pretty = false) => isEffectSchema(tool.input) ? toTypeScript(tool.input, false, pretty) : jsonSchemaToTypeScript(tool.input, pretty);
266
286
  // Effect inputs are empty only when their encoded root is Effect's empty-struct marker, which records and checked
267
287
  // structs never are. Raw JSON Schema inputs keep the `{}` rendering check, which treats `{ type: "object" }` as empty.
package/dist/tool.d.ts CHANGED
@@ -78,6 +78,7 @@ export type Tool<R = never> = {
78
78
  readonly _tag: "CodeModeTool";
79
79
  readonly description: string;
80
80
  readonly input: SchemaType;
81
+ readonly freeform?: boolean;
81
82
  readonly output: SchemaType | undefined;
82
83
  readonly execute: (input: unknown, context?: ToolContext) => Effect.Effect<unknown, unknown, R>;
83
84
  readonly mode?: Idempotent<unknown, unknown, R> | Durable<unknown, unknown, R> | undefined;
@@ -88,6 +89,11 @@ type ResultType<S> = S extends undefined ? void : S extends Schema.Decoder<unkno
88
89
  export type Options<I extends SchemaType, O extends SchemaType | undefined, R = never> = {
89
90
  readonly description: string;
90
91
  readonly input: I;
92
+ /**
93
+ * The tool's input is one required string field that programs pass directly, as in `tools.patch("...")`.
94
+ * The object form still works, and the executor receives the object either way.
95
+ */
96
+ readonly freeform?: boolean;
91
97
  readonly output?: O;
92
98
  readonly execute: ExecuteFn<InputType<I>, ResultType<O>, R> | Idempotent<InputType<I>, ResultType<O>, R> | Durable<InputType<I>, ResultType<O>, R>;
93
99
  };
package/dist/tool.js CHANGED
@@ -32,6 +32,7 @@ export const make = (options) => {
32
32
  _tag: "CodeModeTool",
33
33
  description: options.description,
34
34
  input: options.input,
35
+ ...(options.freeform && { freeform: true }),
35
36
  output: options.output,
36
37
  ...(mode === undefined ? {} : { mode }),
37
38
  execute: (input, context = { key: crypto.randomUUID() }) => spec(input, context),
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-1136",
4
+ "version": "0.0.0-dev-1147",
5
5
  "description": "Effect-native confined code execution over schema-described tools",
6
6
  "type": "module",
7
7
  "license": "MIT",