-
Notifications
You must be signed in to change notification settings - Fork 1
feat(run): emit tool_catalog NDJSON event at session start #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ddd5943
feat(run): emit tool_catalog NDJSON event at session start (#85)
035ea0f
refactor(skill): generalize version tracking into metadata-retention …
1a10f23
fix(tool-catalog): address code review findings from PR #88
8dae0c9
fix(tool-catalog): address round-2 review findings on PR #88
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| /** | ||
| * tool-catalog.ts — builds the resolved tool/skill inventory emitted in the | ||
| * `tool_catalog` NDJSON event (issue #85). | ||
| * | ||
| * Exported as a standalone module so it can be unit-tested independently of | ||
| * the full run.ts wiring. | ||
| */ | ||
| import { ToolRegistry } from "../../tool/registry" | ||
| import { MCP } from "../../mcp" | ||
| import { Skill } from "../../skill" | ||
|
|
||
| /** A single entry in the `tools[]` array of the `tool_catalog` event. */ | ||
| export interface ToolCatalogEntry { | ||
| /** Tool name as exposed to the model. Mirrors upstream ToolListItem.id. */ | ||
| name: string | ||
| /** Whether the tool is a builtin (local) or an MCP tool. */ | ||
| source: "builtin" | "mcp" | ||
| /** | ||
| * The MCP server name for source=mcp tools (sanitized client name). | ||
| * Omitted for builtin tools. | ||
| */ | ||
| server?: string | ||
| } | ||
|
|
||
| /** A single entry in the `skills[]` array of the `tool_catalog` event. */ | ||
| export interface SkillCatalogEntry { | ||
| /** Skill name from SKILL.md frontmatter. */ | ||
| name: string | ||
| /** | ||
| * Skill version from SKILL.md frontmatter `version` field. | ||
| * null when no version is declared in frontmatter. | ||
| */ | ||
| version: string | null | ||
| } | ||
|
|
||
| /** Result of buildToolCatalogItems(). */ | ||
| export interface ToolCatalogItems { | ||
| tools: ToolCatalogEntry[] | ||
| skills: SkillCatalogEntry[] | ||
| } | ||
|
|
||
| /** | ||
| * Dependency injection shape, used for testing to avoid touching real MCP | ||
| * state and the real filesystem. | ||
| */ | ||
| export interface ToolCatalogDeps { | ||
| /** | ||
| * Returns builtin tool IDs (the resolved set for the current instance). | ||
| * Defaults to ToolRegistry.ids(). | ||
| */ | ||
| getBuiltinIds?: () => Promise<string[]> | ||
|
|
||
| /** | ||
| * Returns connected MCP tools as { toolKey, serverName } pairs. | ||
| * toolKey = the combined `serverName_toolName` key given to the model. | ||
| * Defaults to an internal implementation using MCP.clients() + listTools(). | ||
| */ | ||
| getMcpTools?: () => Promise<{ toolKey: string; serverName: string }[]> | ||
|
|
||
| /** | ||
| * Returns the list of resolved skills. | ||
| * Defaults to Skill.all(). | ||
| */ | ||
| getSkills?: () => Promise<Skill.Info[]> | ||
| } | ||
|
|
||
| /** | ||
| * Collects the resolved tool catalog and skill list for the current session. | ||
| * | ||
| * Uses ToolRegistry.ids() for builtins (the instance-level superset, without | ||
| * model-specific filtering which only applies per-turn inside resolveTools). | ||
| * Uses MCP connected clients for MCP tools. | ||
| * Uses Skill.all() for skills with optional version from frontmatter. | ||
| */ | ||
| export async function buildToolCatalogItems(deps: ToolCatalogDeps = {}): Promise<ToolCatalogItems> { | ||
| const getBuiltinIds = deps.getBuiltinIds ?? (() => ToolRegistry.ids()) | ||
| const getMcpTools = deps.getMcpTools ?? defaultGetMcpTools | ||
| const getSkills = deps.getSkills ?? (() => Skill.all()) | ||
|
|
||
| const [builtinIds, mcpTools, skills] = await Promise.all([getBuiltinIds(), getMcpTools(), getSkills()]) | ||
|
|
||
| const tools: ToolCatalogEntry[] = [ | ||
| ...builtinIds.map( | ||
| (name): ToolCatalogEntry => ({ | ||
| name, | ||
| source: "builtin", | ||
| }), | ||
| ), | ||
| ...mcpTools.map( | ||
| ({ toolKey, serverName }): ToolCatalogEntry => ({ | ||
|
byapparov marked this conversation as resolved.
|
||
| name: toolKey, | ||
| source: "mcp", | ||
| server: serverName, | ||
| }), | ||
| ), | ||
| ] | ||
|
|
||
| const skillEntries: SkillCatalogEntry[] = skills.map((s) => ({ | ||
| name: s.name, | ||
| version: s.version ?? null, | ||
| })) | ||
|
|
||
| return { tools, skills: skillEntries } | ||
| } | ||
|
|
||
| /** | ||
| * Default MCP tool resolver: delegates to MCP.toolEntries() which queries | ||
| * each connected client's tool list and returns { toolKey, serverName } pairs | ||
| * (matching the key format used in SessionPrompt.resolveTools). | ||
| */ | ||
| async function defaultGetMcpTools(): Promise<{ toolKey: string; serverName: string }[]> { | ||
| return MCP.toolEntries() | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.