fix(coding-agent): unify source provenance, closes #1734

This commit is contained in:
Mario Zechner
2026-03-23 02:02:42 +01:00
parent 883862a354
commit 4e5af01d73
26 changed files with 340 additions and 157 deletions

View File

@@ -2,7 +2,7 @@
* Extension system for lifecycle events and custom tools.
*/
export type { SlashCommandInfo, SlashCommandLocation, SlashCommandSource } from "../slash-commands.js";
export type { SlashCommandInfo, SlashCommandSource } from "../slash-commands.js";
export type { SourceInfo } from "../source-info.js";
export {
createExtensionRuntime,

View File

@@ -26,6 +26,7 @@ import * as _bundledPiCodingAgent from "../../index.js";
import { createEventBus, type EventBus } from "../event-bus.js";
import type { ExecOptions } from "../exec.js";
import { execCommand } from "../exec.js";
import { createSyntheticSourceInfo } from "../source-info.js";
import type {
Extension,
ExtensionAPI,
@@ -174,15 +175,14 @@ function createExtensionAPI(
registerTool(tool: ToolDefinition): void {
extension.tools.set(tool.name, {
definition: tool,
extensionPath: extension.path,
sourceInfo: extension.sourceInfo,
});
runtime.refreshTools();
},
registerCommand(name: string, options: Omit<RegisteredCommand, "name" | "extensionPath">): void {
registerCommand(name: string, options: Omit<RegisteredCommand, "name" | "sourceInfo">): void {
extension.commands.set(name, {
name,
extensionPath: extension.path,
sourceInfo: extension.sourceInfo,
...options,
});
@@ -307,9 +307,16 @@ async function loadExtensionModule(extensionPath: string) {
* Create an Extension object with empty collections.
*/
function createExtension(extensionPath: string, resolvedPath: string): Extension {
const source =
extensionPath.startsWith("<") && extensionPath.endsWith(">")
? extensionPath.slice(1, -1).split(":")[0] || "temporary"
: "local";
const baseDir = extensionPath.startsWith("<") ? undefined : path.dirname(resolvedPath);
return {
path: extensionPath,
resolvedPath,
sourceInfo: createSyntheticSourceInfo(extensionPath, { source, baseDir }),
handlers: new Map(),
tools: new Map(),
messageRenderers: new Map(),

View File

@@ -961,8 +961,7 @@ export type MessageRenderer<T = unknown> = (
export interface RegisteredCommand {
name: string;
extensionPath: string;
sourceInfo?: SourceInfo;
sourceInfo: SourceInfo;
description?: string;
getArgumentCompletions?: (argumentPrefix: string) => AutocompleteItem[] | null;
handler: (args: string, ctx: ExtensionCommandContext) => Promise<void>;
@@ -1038,7 +1037,7 @@ export interface ExtensionAPI {
// =========================================================================
/** Register a custom command. */
registerCommand(name: string, options: Omit<RegisteredCommand, "name" | "extensionPath">): void;
registerCommand(name: string, options: Omit<RegisteredCommand, "name" | "sourceInfo">): void;
/** Register a keyboard shortcut. */
registerShortcut(
@@ -1110,7 +1109,7 @@ export interface ExtensionAPI {
/** Get the list of currently active tool names. */
getActiveTools(): string[];
/** Get all configured tools with name and description. */
/** Get all configured tools with parameter schema and source metadata. */
getAllTools(): ToolInfo[];
/** Set the active tools by name. */
@@ -1277,7 +1276,7 @@ export type ExtensionFactory = (pi: ExtensionAPI) => void | Promise<void>;
export interface RegisteredTool {
definition: ToolDefinition;
extensionPath: string;
sourceInfo: SourceInfo;
}
export interface ExtensionFlag {
@@ -1315,8 +1314,10 @@ export type GetSessionNameHandler = () => string | undefined;
export type GetActiveToolsHandler = () => string[];
/** Tool info with name, description, and parameter schema */
export type ToolInfo = Pick<ToolDefinition, "name" | "description" | "parameters">;
/** Tool info with name, description, parameter schema, and source metadata */
export type ToolInfo = Pick<ToolDefinition, "name" | "description" | "parameters"> & {
sourceInfo: SourceInfo;
};
export type GetAllToolsHandler = () => ToolInfo[];
@@ -1417,7 +1418,7 @@ export interface ExtensionRuntime extends ExtensionRuntimeState, ExtensionAction
export interface Extension {
path: string;
resolvedPath: string;
sourceInfo?: SourceInfo;
sourceInfo: SourceInfo;
handlers: Map<string, HandlerFn[]>;
tools: Map<string, RegisteredTool>;
messageRenderers: Map<string, MessageRenderer>;