Tools - Move all description to a named export toolMetadata

This commit is contained in:
2026-04-09 10:05:09 +05:30
parent bc28df017f
commit 741bfee670
7 changed files with 85 additions and 68 deletions
@@ -4,22 +4,15 @@
*/ */
import { tool } from "@opencode-ai/plugin"; import { tool } from "@opencode-ai/plugin";
import { createEvaluateInEngine262Tool } from "../../src/agent-tools"; import {
createEvaluateInEngine262Tool,
toolMetadata,
} from "../../src/agent-tools/evaluateInEngine262";
export default tool({ export default tool({
description: description: toolMetadata.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();",
args: { args: {
code: tool.schema code: tool.schema.string().describe(toolMetadata.args.code),
.string()
.describe(
"JavaScript code to execute in engine262 (e.g., '[1,2,3].map(x => x * 2)')",
),
}, },
async execute(args) { async execute(args) {
const { code } = args; const { code } = args;
+7 -15
View File
@@ -5,27 +5,19 @@
import { tool } from "@opencode-ai/plugin"; import { tool } from "@opencode-ai/plugin";
import * as lancedbSdk from "@lancedb/lancedb"; import * as lancedbSdk from "@lancedb/lancedb";
import { createGetSectionContentTool } from "../../src/agent-tools"; import {
createGetSectionContentTool,
toolMetadata,
} from "../../src/agent-tools/getSectionContent";
export default tool({ export default tool({
description: description: toolMetadata.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').",
args: { args: {
sectionId: tool.schema sectionId: tool.schema.string().describe(toolMetadata.args.sectionId),
.string()
.describe(
"The section ID (e.g., 'sec-if-statement', 'sec-array-prototype-map') to fetch content for",
),
recursive: tool.schema recursive: tool.schema
.boolean() .boolean()
.default(true) .default(true)
.describe( .describe(toolMetadata.args.recursive),
"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.",
),
}, },
async execute(args, context) { async execute(args, context) {
const { sectionId, recursive } = args; const { sectionId, recursive } = args;
+6 -10
View File
@@ -6,19 +6,15 @@
import { tool } from "@opencode-ai/plugin"; import { tool } from "@opencode-ai/plugin";
import * as lancedbSdk from "@lancedb/lancedb"; import * as lancedbSdk from "@lancedb/lancedb";
import { OllamaEmbeddings } from "@langchain/ollama"; import { OllamaEmbeddings } from "@langchain/ollama";
import { createSearchSpecSectionsTool } from "../../src/agent-tools"; import {
createSearchSpecSectionsTool,
toolMetadata,
} from "../../src/agent-tools/searchSpecSections";
export default tool({ export default tool({
description: description: toolMetadata.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.",
args: { args: {
query: tool.schema query: tool.schema.string().describe(toolMetadata.args.query),
.string()
.describe(
"The search query to find relevant specification sections (e.g., 'how does array map work')",
),
}, },
async execute(args, context) { async execute(args, context) {
const { query } = args; const { query } = args;
+17 -7
View File
@@ -7,8 +7,23 @@
import { DynamicStructuredTool } from "@langchain/core/tools"; import { DynamicStructuredTool } from "@langchain/core/tools";
import { z } from "zod"; 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({ 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 // Type definitions for engine262 module
@@ -41,12 +56,7 @@ async function loadEngine262() {
export function createEvaluateInEngine262Tool() { export function createEvaluateInEngine262Tool() {
return new DynamicStructuredTool({ return new DynamicStructuredTool({
name: "ask262_evaluate_in_engine262", name: "ask262_evaluate_in_engine262",
description: description: 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();",
schema: evaluateSchema, schema: evaluateSchema,
func: async ({ code }) => { func: async ({ code }) => {
try { try {
+18 -13
View File
@@ -7,18 +7,26 @@ import type { Table } from "@lancedb/lancedb";
import { DynamicStructuredTool } from "@langchain/core/tools"; import { DynamicStructuredTool } from "@langchain/core/tools";
import { z } from "zod"; import { z } from "zod";
const getSectionContentSchema = z.object({ /**
sectionId: z * Tool metadata for reuse in OpenCode tools.
.string() */
.describe("The section ID (e.g., 'sec-if-statement') to fetch chunks for"), export const toolMetadata = {
recursive: z description:
.boolean() "Retrieves all text chunks from a specific specification section by sectionid. " +
.default(true) "Supports recursive fetching - if recursive=true and the section has children, it will fetch all descendants. " +
.describe( "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 true, recursively fetches content from all child sections and their descendants. " +
"If false, only returns content from the specified section itself. " + "If false, only returns content from the specified section itself. " +
"Use false when you only need the specific section's content without subsections.", "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) { export function createGetSectionContentTool(table: Table) {
return new DynamicStructuredTool({ return new DynamicStructuredTool({
name: "ask262_get_section_content", name: "ask262_get_section_content",
description: description: 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.",
schema: getSectionContentSchema, schema: getSectionContentSchema,
func: async ({ sectionId, recursive }) => { func: async ({ sectionId, recursive }) => {
const allDocs: string[] = []; const allDocs: string[] = [];
+12 -3
View File
@@ -3,8 +3,17 @@
* Exports all tool factory functions and utilities. * Exports all tool factory functions and utilities.
*/ */
export { createEvaluateInEngine262Tool } from "./evaluateInEngine262"; export {
export { createGetSectionContentTool } from "./getSectionContent"; createEvaluateInEngine262Tool,
toolMetadata as evaluateToolMetadata,
} from "./evaluateInEngine262";
export {
createGetSectionContentTool,
toolMetadata as sectionContentToolMetadata,
} from "./getSectionContent";
export { createGraphExplorerTool } from "./graphExplorer"; export { createGraphExplorerTool } from "./graphExplorer";
export { type RerankResult, rerankDocuments } from "./reranker"; export { type RerankResult, rerankDocuments } from "./reranker";
export { createSearchSpecSectionsTool } from "./searchSpecSections"; export {
createSearchSpecSectionsTool,
toolMetadata as searchSpecToolMetadata,
} from "./searchSpecSections";
+17 -5
View File
@@ -8,10 +8,23 @@ import { DynamicStructuredTool } from "@langchain/core/tools";
import type { OllamaEmbeddings } from "@langchain/ollama"; import type { OllamaEmbeddings } from "@langchain/ollama";
import { z } from "zod"; 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({ const searchSpecSchema = z.object({
query: z query: z.string().describe(toolMetadata.args.query),
.string()
.describe("The search query to find relevant specification sections"),
}); });
/** /**
@@ -26,8 +39,7 @@ export function createSearchSpecSectionsTool(
) { ) {
return new DynamicStructuredTool({ return new DynamicStructuredTool({
name: "ask262_search_spec_sections", name: "ask262_search_spec_sections",
description: description: 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.",
schema: searchSpecSchema, schema: searchSpecSchema,
func: async ({ query }) => { func: async ({ query }) => {
// Generate embedding for the query // Generate embedding for the query