feat(coding-agent): add ExtensionAPI.getCommands()

This commit is contained in:
warren 2026-02-03 06:06:29 +01:00 committed by Mario Zechner
parent ff9a3f0660
commit 2613754c47
10 changed files with 156 additions and 45 deletions

View file

@ -67,6 +67,7 @@ import { expandPromptTemplate, type PromptTemplate } from "./prompt-templates.js
import type { ResourceExtensionPaths, ResourceLoader } from "./resource-loader.js";
import type { BranchSummaryEntry, CompactionEntry, SessionManager } from "./session-manager.js";
import type { SettingsManager } from "./settings-manager.js";
import { BUILTIN_SLASH_COMMANDS, type SlashCommandInfo, type SlashCommandLocation } from "./slash-commands.js";
import { buildSystemPrompt } from "./system-prompt.js";
import type { BashOperations } from "./tools/bash.js";
import { createAllTools } from "./tools/index.js";
@ -1775,6 +1776,45 @@ export class AgentSession {
}
private _bindExtensionCore(runner: ExtensionRunner): void {
const normalizeLocation = (source: string): SlashCommandLocation | undefined => {
if (source === "user" || source === "project" || source === "path") {
return source;
}
return undefined;
};
const reservedBuiltins = new Set(BUILTIN_SLASH_COMMANDS.map((command) => command.name));
const getCommands = (): SlashCommandInfo[] => {
const extensionCommands: SlashCommandInfo[] = runner
.getRegisteredCommandsWithPaths()
.filter(({ command }) => !reservedBuiltins.has(command.name))
.map(({ command, extensionPath }) => ({
name: command.name,
description: command.description,
source: "extension",
path: extensionPath,
}));
const templates: SlashCommandInfo[] = this.promptTemplates.map((template) => ({
name: template.name,
description: template.description,
source: "template",
location: normalizeLocation(template.source),
path: template.filePath,
}));
const skills: SlashCommandInfo[] = this._resourceLoader.getSkills().skills.map((skill) => ({
name: `skill:${skill.name}`,
description: skill.description,
source: "skill",
location: normalizeLocation(skill.source),
path: skill.filePath,
}));
return [...extensionCommands, ...templates, ...skills];
};
runner.bindCore(
{
sendMessage: (message, options) => {
@ -1810,6 +1850,7 @@ export class AgentSession {
getActiveTools: () => this.getActiveToolNames(),
getAllTools: () => this.getAllTools(),
setActiveTools: (toolNames) => this.setActiveToolsByName(toolNames),
getCommands,
setModel: async (model) => {
const key = await this.modelRegistry.getApiKey(model);
if (!key) return false;