From 741bfee670480bc17fdabfa952b8f460834ef40b Mon Sep 17 00:00:00 2001 From: bendtherules Date: Thu, 9 Apr 2026 10:05:09 +0530 Subject: [PATCH] Tools - Move all description to a named export toolMetadata --- .../tools/ask262-evaluate-in-engine262.ts | 19 ++++------ .opencode/tools/ask262-get-section-content.ts | 22 ++++-------- .../tools/ask262-search-spec-sections.ts | 16 ++++----- src/agent-tools/evaluateInEngine262.ts | 24 +++++++++---- src/agent-tools/getSectionContent.ts | 35 +++++++++++-------- src/agent-tools/index.ts | 15 ++++++-- src/agent-tools/searchSpecSections.ts | 22 +++++++++--- 7 files changed, 85 insertions(+), 68 deletions(-) diff --git a/.opencode/tools/ask262-evaluate-in-engine262.ts b/.opencode/tools/ask262-evaluate-in-engine262.ts index d20da28..543f8b3 100644 --- a/.opencode/tools/ask262-evaluate-in-engine262.ts +++ b/.opencode/tools/ask262-evaluate-in-engine262.ts @@ -4,22 +4,15 @@ */ import { tool } from "@opencode-ai/plugin"; -import { createEvaluateInEngine262Tool } from "../../src/agent-tools"; +import { + createEvaluateInEngine262Tool, + toolMetadata, +} from "../../src/agent-tools/evaluateInEngine262"; export default tool({ - description: - "Executes JavaScript code in the engine262 JavaScript engine and captures which ECMAScript specification sections are hit during execution. " + - "Returns JSON with importantSections and otherSections arrays. " + - "Use this to understand how specific JavaScript operations map to the ECMAScript spec. " + - "ask262Debug is available globally in the execution context (no import needed). " + - "Use ask262Debug.startImportant() and ask262Debug.stopImportant() to mark important sections. " + - "Example: ask262Debug.startImportant(); let x = 1 + 2; ask262Debug.stopImportant();", + description: toolMetadata.description, args: { - code: tool.schema - .string() - .describe( - "JavaScript code to execute in engine262 (e.g., '[1,2,3].map(x => x * 2)')", - ), + code: tool.schema.string().describe(toolMetadata.args.code), }, async execute(args) { const { code } = args; diff --git a/.opencode/tools/ask262-get-section-content.ts b/.opencode/tools/ask262-get-section-content.ts index 8d90406..3536a14 100644 --- a/.opencode/tools/ask262-get-section-content.ts +++ b/.opencode/tools/ask262-get-section-content.ts @@ -5,27 +5,19 @@ import { tool } from "@opencode-ai/plugin"; import * as lancedbSdk from "@lancedb/lancedb"; -import { createGetSectionContentTool } from "../../src/agent-tools"; +import { + createGetSectionContentTool, + toolMetadata, +} from "../../src/agent-tools/getSectionContent"; export default tool({ - description: - "Retrieves all text chunks from a specific ECMAScript specification section by section ID. " + - "Supports recursive fetching - if recursive=true and the section has children, it will fetch all descendants. " + - "Use this to get complete spec text when you know the section ID (e.g., 'sec-if-statement').", + description: toolMetadata.description, args: { - sectionId: tool.schema - .string() - .describe( - "The section ID (e.g., 'sec-if-statement', 'sec-array-prototype-map') to fetch content for", - ), + sectionId: tool.schema.string().describe(toolMetadata.args.sectionId), recursive: tool.schema .boolean() .default(true) - .describe( - "If true, recursively fetches content from all child sections and descendants. " + - "If false, only returns content from the specified section itself. " + - "Use false when you only need the specific section's content without subsections.", - ), + .describe(toolMetadata.args.recursive), }, async execute(args, context) { const { sectionId, recursive } = args; diff --git a/.opencode/tools/ask262-search-spec-sections.ts b/.opencode/tools/ask262-search-spec-sections.ts index e193f9a..3a4a5c4 100644 --- a/.opencode/tools/ask262-search-spec-sections.ts +++ b/.opencode/tools/ask262-search-spec-sections.ts @@ -6,19 +6,15 @@ import { tool } from "@opencode-ai/plugin"; import * as lancedbSdk from "@lancedb/lancedb"; import { OllamaEmbeddings } from "@langchain/ollama"; -import { createSearchSpecSectionsTool } from "../../src/agent-tools"; +import { + createSearchSpecSectionsTool, + toolMetadata, +} from "../../src/agent-tools/searchSpecSections"; export default tool({ - description: - "Vector search the ECMAScript specification for sections relevant to a query. " + - "Returns JSON array with sectionId, sectionTitle, score, partIndex, totalParts, and content. " + - "Use this when you need to find spec sections related to a JavaScript topic or question.", + description: toolMetadata.description, args: { - query: tool.schema - .string() - .describe( - "The search query to find relevant specification sections (e.g., 'how does array map work')", - ), + query: tool.schema.string().describe(toolMetadata.args.query), }, async execute(args, context) { const { query } = args; diff --git a/src/agent-tools/evaluateInEngine262.ts b/src/agent-tools/evaluateInEngine262.ts index 74fb255..45517a4 100644 --- a/src/agent-tools/evaluateInEngine262.ts +++ b/src/agent-tools/evaluateInEngine262.ts @@ -7,8 +7,23 @@ import { DynamicStructuredTool } from "@langchain/core/tools"; import { z } from "zod"; +/** + * Tool metadata for reuse in OpenCode tools. + */ +export const toolMetadata = { + description: + "Executes JavaScript code in the engine262 JavaScript engine and captures which ECMAScript specification sections are hit during execution. " + + "Returns the full marks array as JSON. Useful for understanding how specific JavaScript operations map to the ECMAScript spec. " + + "ask262Debug is available globally in the execution context (no import needed). " + + "Use ask262Debug.startImportant() and ask262Debug.stopImportant() to mark important sections. " + + "Example: ask262Debug.startImportant(); let x = 1 + 2; ask262Debug.stopImportant();", + args: { + code: "JavaScript code to execute in engine262 (e.g., '[1,2,3].map(x => x * 2)')", + }, +}; + const evaluateSchema = z.object({ - code: z.string().describe("JavaScript code to execute in engine262"), + code: z.string().describe(toolMetadata.args.code), }); // Type definitions for engine262 module @@ -41,12 +56,7 @@ async function loadEngine262() { export function createEvaluateInEngine262Tool() { return new DynamicStructuredTool({ name: "ask262_evaluate_in_engine262", - description: - "Executes JavaScript code in the engine262 JavaScript engine and captures which ECMAScript specification sections are hit during execution. " + - "Returns the full marks array as JSON. Useful for understanding how specific JavaScript operations map to the ECMAScript spec. " + - "ask262Debug is available globally in the execution context (no import needed). " + - "Use ask262Debug.startImportant() and ask262Debug.stopImportant() to mark important sections. " + - "Example: ask262Debug.startImportant(); let x = 1 + 2; ask262Debug.stopImportant();", + description: toolMetadata.description, schema: evaluateSchema, func: async ({ code }) => { try { diff --git a/src/agent-tools/getSectionContent.ts b/src/agent-tools/getSectionContent.ts index d05a564..df6ae53 100644 --- a/src/agent-tools/getSectionContent.ts +++ b/src/agent-tools/getSectionContent.ts @@ -7,18 +7,26 @@ import type { Table } from "@lancedb/lancedb"; import { DynamicStructuredTool } from "@langchain/core/tools"; import { z } from "zod"; -const getSectionContentSchema = z.object({ - sectionId: z - .string() - .describe("The section ID (e.g., 'sec-if-statement') to fetch chunks for"), - recursive: z - .boolean() - .default(true) - .describe( +/** + * Tool metadata for reuse in OpenCode tools. + */ +export const toolMetadata = { + description: + "Retrieves all text chunks from a specific specification section by sectionid. " + + "Supports recursive fetching - if recursive=true and the section has children, it will fetch all descendants. " + + "Use this to get complete content when you see 'Subsection available' or 'partial section' references.", + args: { + sectionId: "The section ID (e.g., 'sec-if-statement') to fetch chunks for", + recursive: "If true, recursively fetches content from all child sections and their descendants. " + - "If false, only returns content from the specified section itself. " + - "Use false when you only need the specific section's content without subsections.", - ), + "If false, only returns content from the specified section itself. " + + "Use false when you only need the specific section's content without subsections.", + }, +}; + +const getSectionContentSchema = z.object({ + sectionId: z.string().describe(toolMetadata.args.sectionId), + recursive: z.boolean().default(true).describe(toolMetadata.args.recursive), }); /** @@ -30,10 +38,7 @@ const getSectionContentSchema = z.object({ export function createGetSectionContentTool(table: Table) { return new DynamicStructuredTool({ name: "ask262_get_section_content", - description: - "Retrieves all text chunks from a specific specification section by sectionid. " + - "Supports recursive fetching - if recursive=true and the section has children, it will fetch all descendants. " + - "Use this to get complete content when you see 'Subsection available' or 'partial section' references.", + description: toolMetadata.description, schema: getSectionContentSchema, func: async ({ sectionId, recursive }) => { const allDocs: string[] = []; diff --git a/src/agent-tools/index.ts b/src/agent-tools/index.ts index 2a8d914..0ee8ce5 100644 --- a/src/agent-tools/index.ts +++ b/src/agent-tools/index.ts @@ -3,8 +3,17 @@ * Exports all tool factory functions and utilities. */ -export { createEvaluateInEngine262Tool } from "./evaluateInEngine262"; -export { createGetSectionContentTool } from "./getSectionContent"; +export { + createEvaluateInEngine262Tool, + toolMetadata as evaluateToolMetadata, +} from "./evaluateInEngine262"; +export { + createGetSectionContentTool, + toolMetadata as sectionContentToolMetadata, +} from "./getSectionContent"; export { createGraphExplorerTool } from "./graphExplorer"; export { type RerankResult, rerankDocuments } from "./reranker"; -export { createSearchSpecSectionsTool } from "./searchSpecSections"; +export { + createSearchSpecSectionsTool, + toolMetadata as searchSpecToolMetadata, +} from "./searchSpecSections"; diff --git a/src/agent-tools/searchSpecSections.ts b/src/agent-tools/searchSpecSections.ts index da4f2bd..0142246 100644 --- a/src/agent-tools/searchSpecSections.ts +++ b/src/agent-tools/searchSpecSections.ts @@ -8,10 +8,23 @@ import { DynamicStructuredTool } from "@langchain/core/tools"; import type { OllamaEmbeddings } from "@langchain/ollama"; import { z } from "zod"; +/** + * Tool metadata for reuse in OpenCode tools. + */ +export const toolMetadata = { + description: + "Vector search the ECMAScript specification for sections relevant to a query. " + + "Returns JSON array with sectionId, sectionTitle, score, partIndex, totalParts, and content. " + + "partIndex and totalParts indicate which chunk of a multi-part section this is " + + "(0-indexed, partIndex+1/totalParts), null if single-part.", + args: { + query: + "The search query to find relevant specification sections (e.g., 'how does array map work')", + }, +}; + const searchSpecSchema = z.object({ - query: z - .string() - .describe("The search query to find relevant specification sections"), + query: z.string().describe(toolMetadata.args.query), }); /** @@ -26,8 +39,7 @@ export function createSearchSpecSectionsTool( ) { return new DynamicStructuredTool({ name: "ask262_search_spec_sections", - description: - "Vector search the ECMAScript specification for sections relevant to a query. Returns JSON array with sectionId, sectionTitle, score, partIndex, totalParts, and content. partIndex and totalParts indicate which chunk of a multi-part section this is (0-indexed, partIndex+1/totalParts), null if single-part.", + description: toolMetadata.description, schema: searchSpecSchema, func: async ({ query }) => { // Generate embedding for the query