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

@@ -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(),