pi-extensions-tool-display 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +20 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-extensions-tool-display",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Pi tool display host and shared result-rendering protocol for extensions",
5
5
  "type": "module",
6
6
  "main": "./index.ts",
package/src/index.ts CHANGED
@@ -44,6 +44,14 @@ export function toolDisplayReloadRequired(
44
44
 
45
45
  const initializedHosts = new WeakSet<ExtensionAPI>();
46
46
 
47
+ function hasRegisteredToolDisplayCommand(pi: ExtensionAPI): boolean {
48
+ try {
49
+ return pi.getCommands().some((command) => command.name === "tool-display");
50
+ } catch {
51
+ return false;
52
+ }
53
+ }
54
+
47
55
  /**
48
56
  * Load the display host when a feature extension uses this package as a
49
57
  * dependency. Pi only auto-loads top-level packages, so relying on the
@@ -109,13 +117,18 @@ export function ensureToolDisplayHost(
109
117
  registerThinkingLabeling(pi);
110
118
  }
111
119
 
112
- pi.registerCommand("tool-display", {
113
- description: "Configure tool output rendering (OpenCode-style)",
114
- handler: async (args, ctx) => {
115
- const { runToolDisplayCommandHandler } = await import("./config-modal.js");
116
- await runToolDisplayCommandHandler(args, ctx, { getConfig, setConfig, getCapabilities });
117
- },
118
- });
120
+ // Each Pi extension has its own registration map, while getCommands() sees
121
+ // the shared runtime. Check the latter so feature extensions do not expose
122
+ // duplicate /tool-display entries when they initialize this host separately.
123
+ if (!hasRegisteredToolDisplayCommand(pi)) {
124
+ pi.registerCommand("tool-display", {
125
+ description: "Configure tool output rendering (OpenCode-style)",
126
+ handler: async (args, ctx) => {
127
+ const { runToolDisplayCommandHandler } = await import("./config-modal.js");
128
+ await runToolDisplayCommandHandler(args, ctx, { getConfig, setConfig, getCapabilities });
129
+ },
130
+ });
131
+ }
119
132
 
120
133
  pi.on("session_start", async (_event, ctx) => {
121
134
  refreshCapabilities();