fix(coding-agent): unify source provenance, closes #1734
This commit is contained in:
@@ -1126,6 +1126,7 @@ The list matches the RPC `get_commands` ordering: extensions first, then templat
|
||||
```typescript
|
||||
const commands = pi.getCommands();
|
||||
const bySource = commands.filter((command) => command.source === "extension");
|
||||
const userScoped = commands.filter((command) => command.sourceInfo.scope === "user");
|
||||
```
|
||||
|
||||
Each entry has this shape:
|
||||
@@ -1135,11 +1136,18 @@ Each entry has this shape:
|
||||
name: string; // Command name without the leading slash
|
||||
description?: string;
|
||||
source: "extension" | "prompt" | "skill";
|
||||
location?: "user" | "project" | "path"; // For templates and skills
|
||||
path?: string; // Files backing templates, skills, and extensions
|
||||
sourceInfo: {
|
||||
path: string;
|
||||
source: string;
|
||||
scope: "user" | "project" | "temporary";
|
||||
origin: "package" | "top-level";
|
||||
baseDir?: string;
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
Use `sourceInfo` as the canonical provenance field. Do not infer ownership from command names or from ad hoc path parsing.
|
||||
|
||||
Built-in interactive commands (like `/model` and `/settings`) are not included here. They are handled only in interactive
|
||||
mode and would not execute if sent via `prompt`.
|
||||
|
||||
@@ -1191,12 +1199,27 @@ const result = await pi.exec("git", ["status"], { signal, timeout: 5000 });
|
||||
Manage active tools. This works for both built-in tools and dynamically registered tools.
|
||||
|
||||
```typescript
|
||||
const active = pi.getActiveTools(); // ["read", "bash", "edit", "write"]
|
||||
const all = pi.getAllTools(); // [{ name: "read", description: "Read file contents..." }, ...]
|
||||
const names = all.map(t => t.name); // Just names if needed
|
||||
const active = pi.getActiveTools();
|
||||
const all = pi.getAllTools();
|
||||
// [{
|
||||
// name: "read",
|
||||
// description: "Read file contents...",
|
||||
// parameters: ...,
|
||||
// sourceInfo: { path: "<builtin:read>", source: "builtin", scope: "temporary", origin: "top-level" }
|
||||
// }, ...]
|
||||
const names = all.map(t => t.name);
|
||||
const builtinTools = all.filter((t) => t.sourceInfo.source === "builtin");
|
||||
const extensionTools = all.filter((t) => t.sourceInfo.source !== "builtin" && t.sourceInfo.source !== "sdk");
|
||||
pi.setActiveTools(["read", "bash"]); // Switch to read-only
|
||||
```
|
||||
|
||||
`pi.getAllTools()` returns `name`, `description`, `parameters`, and `sourceInfo`.
|
||||
|
||||
Typical `sourceInfo.source` values:
|
||||
- `builtin` for built-in tools
|
||||
- `sdk` for tools passed via `createAgentSession({ customTools })`
|
||||
- extension source metadata for tools registered by extensions
|
||||
|
||||
### pi.setModel(model)
|
||||
|
||||
Set the current model. Returns `false` if no API key is available for the model. See [models.md](models.md) for configuring custom models.
|
||||
|
||||
Reference in New Issue
Block a user