From 1b338ffed7d7b017b2631db60ff1cdad33de12c5 Mon Sep 17 00:00:00 2001 From: bendtherules Date: Wed, 8 Apr 2026 19:04:29 +0530 Subject: [PATCH] build: Add opencode tools for testing --- .../tools/ask262-evaluate-in-engine262.ts | 31 +++++++++++++ .opencode/tools/ask262-get-section-content.ts | 37 ++++++++++++++++ .../tools/ask262-search-spec-sections.ts | 43 +++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 .opencode/tools/ask262-evaluate-in-engine262.ts create mode 100644 .opencode/tools/ask262-get-section-content.ts create mode 100644 .opencode/tools/ask262-search-spec-sections.ts diff --git a/.opencode/tools/ask262-evaluate-in-engine262.ts b/.opencode/tools/ask262-evaluate-in-engine262.ts new file mode 100644 index 0000000..168fda8 --- /dev/null +++ b/.opencode/tools/ask262-evaluate-in-engine262.ts @@ -0,0 +1,31 @@ +/** + * OpenCode custom tool: ask262_evaluate_in_engine262 + * Executes JavaScript code in the engine262 engine and captures spec sections. + */ + +import { tool } from "@opencode-ai/plugin"; +import { createEvaluateInEngine262Tool } from "../../src/agent-tools"; + +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. " + + "You can use ask262Debug.startImportant() and ask262Debug.stopImportant() in the code to mark important sections.", + args: { + code: tool.schema + .string() + .describe( + "JavaScript code to execute in engine262 (e.g., '[1,2,3].map(x => x * 2)')", + ), + }, + async execute(args) { + const { code } = args; + + // Create and execute tool (no external dependencies needed) + const evaluateTool = createEvaluateInEngine262Tool(); + const result = await evaluateTool.func({ code }); + + return result; + }, +}); diff --git a/.opencode/tools/ask262-get-section-content.ts b/.opencode/tools/ask262-get-section-content.ts new file mode 100644 index 0000000..ef09293 --- /dev/null +++ b/.opencode/tools/ask262-get-section-content.ts @@ -0,0 +1,37 @@ +/** + * OpenCode custom tool: ask262_get_section_content + * Retrieves full content from a specific ECMAScript spec section. + */ + +import { tool } from "@opencode-ai/plugin"; +import * as lancedbSdk from "@lancedb/lancedb"; +import { createGetSectionContentTool } from "../../src/agent-tools"; + +export default tool({ + description: + "Retrieves all text chunks from a specific ECMAScript specification section by section ID. " + + "Supports recursive fetching - if a 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').", + args: { + sectionId: tool.schema + .string() + .describe( + "The section ID (e.g., 'sec-if-statement', 'sec-array-prototype-map') to fetch content for", + ), + }, + async execute(args, context) { + const { sectionId } = args; + const { worktree } = context; + + // Connect to LanceDB + const storageDir = `${worktree}/storage`; + const db = await lancedbSdk.connect(storageDir); + const table = await db.openTable("spec_vectors"); + + // Create and execute tool + const contentTool = createGetSectionContentTool(table); + const result = await contentTool.func({ sectionId }); + + return result; + }, +}); diff --git a/.opencode/tools/ask262-search-spec-sections.ts b/.opencode/tools/ask262-search-spec-sections.ts new file mode 100644 index 0000000..337d5de --- /dev/null +++ b/.opencode/tools/ask262-search-spec-sections.ts @@ -0,0 +1,43 @@ +/** + * OpenCode custom tool: ask262_search_spec_sections + * Searches the ECMAScript specification for relevant sections. + */ + +import { tool } from "@opencode-ai/plugin"; +import * as lancedbSdk from "@lancedb/lancedb"; +import { OllamaEmbeddings } from "@langchain/ollama"; +import { createSearchSpecSectionsTool } from "../../src/agent-tools"; + +export default tool({ + description: + "Searches 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.", + args: { + query: tool.schema + .string() + .describe( + "The search query to find relevant specification sections (e.g., 'how does array map work')", + ), + }, + async execute(args, context) { + const { query } = args; + const { worktree } = context; + + // Initialize embeddings + const embeddings = new OllamaEmbeddings({ + model: "qwen3-embedding:0.6b", + }); + + // Connect to LanceDB + const storageDir = `${worktree}/storage`; + const db = await lancedbSdk.connect(storageDir); + const table = await db.openTable("spec_vectors"); + + // Create and execute tool + const searchTool = createSearchSpecSectionsTool(table, embeddings); + const result = await searchTool.func({ query }); + + return result; + }, +});