@howaboua/pi-codex-conversion 1.0.0 → 1.0.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 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@howaboua/pi-codex-conversion",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Codex-oriented tool and prompt adapter for pi coding agent",
5
5
  "type": "module",
6
6
  "repository": {
package/src/index.ts CHANGED
@@ -15,6 +15,8 @@ interface AdapterState {
15
15
  promptSkills: PromptSkill[];
16
16
  }
17
17
 
18
+ const ADAPTER_TOOL_NAMES = [...CORE_ADAPTER_TOOL_NAMES, VIEW_IMAGE_TOOL_NAME];
19
+
18
20
  function getCommandArg(args: unknown): string | undefined {
19
21
  if (!args || typeof args !== "object" || !("cmd" in args) || typeof args.cmd !== "string") {
20
22
  return undefined;
@@ -80,7 +82,7 @@ function syncAdapter(pi: ExtensionAPI, ctx: ExtensionContext, state: AdapterStat
80
82
  }
81
83
 
82
84
  function enableAdapter(pi: ExtensionAPI, ctx: ExtensionContext, state: AdapterState): void {
83
- const toolNames = getAdapterToolNames(ctx);
85
+ const toolNames = mergeAdapterTools(pi.getActiveTools(), getAdapterToolNames(ctx));
84
86
  if (!state.enabled) {
85
87
  // Preserve the previous active set once so switching away from Codex-like
86
88
  // models restores the user's existing Pi tool configuration.
@@ -93,7 +95,8 @@ function enableAdapter(pi: ExtensionAPI, ctx: ExtensionContext, state: AdapterSt
93
95
 
94
96
  function disableAdapter(pi: ExtensionAPI, ctx: ExtensionContext, state: AdapterState): void {
95
97
  if (state.enabled) {
96
- pi.setActiveTools(state.previousToolNames && state.previousToolNames.length > 0 ? state.previousToolNames : DEFAULT_TOOL_NAMES);
98
+ const previousToolNames = state.previousToolNames && state.previousToolNames.length > 0 ? state.previousToolNames : DEFAULT_TOOL_NAMES;
99
+ pi.setActiveTools(restoreTools(previousToolNames, pi.getActiveTools()));
97
100
  state.enabled = false;
98
101
  }
99
102
  setStatus(ctx, false);
@@ -110,3 +113,18 @@ function getAdapterToolNames(ctx: ExtensionContext): string[] {
110
113
  }
111
114
  return [...CORE_ADAPTER_TOOL_NAMES];
112
115
  }
116
+
117
+ export function mergeAdapterTools(activeTools: string[], adapterTools: string[]): string[] {
118
+ const preservedTools = activeTools.filter((toolName) => !DEFAULT_TOOL_NAMES.includes(toolName) && !ADAPTER_TOOL_NAMES.includes(toolName));
119
+ return [...adapterTools, ...preservedTools];
120
+ }
121
+
122
+ export function restoreTools(previousTools: string[], activeTools: string[]): string[] {
123
+ const restored = [...previousTools];
124
+ for (const toolName of activeTools) {
125
+ if (!ADAPTER_TOOL_NAMES.includes(toolName) && !restored.includes(toolName)) {
126
+ restored.push(toolName);
127
+ }
128
+ }
129
+ return restored;
130
+ }