From fbd8382edbfa3f5fc25e3ac9474b885142035fcf Mon Sep 17 00:00:00 2001 From: roboomp Date: Fri, 24 Jul 2026 03:59:10 +0000 Subject: [PATCH] fix(coding-agent): restored legacy keyText export - Added the upstream keyText helper to the legacy package-root shim. - Covered active keybinding formatting and documented the compatibility fix. Fixes #6470 --- packages/coding-agent/CHANGELOG.md | 1 + .../legacy-pi-coding-agent-shim.ts | 8 ++++++- .../test/keybindings-display.test.ts | 22 ++++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md index a1021572a..6ac884951 100644 --- a/packages/coding-agent/CHANGELOG.md +++ b/packages/coding-agent/CHANGELOG.md @@ -38,6 +38,7 @@ ### Fixed +- Fixed legacy Pi extensions failing validation when importing the upstream `keyText` keybinding helper ([#6470](https://github.com/can1357/oh-my-pi/issues/6470)). - Fixed a path traversal vulnerability in blob reference resolution by rejecting non-canonical hashes in `parseBlobRef`. - Fixed multiple edge cases in the secret obfuscation and redaction engine, including handling of context-sensitive regexes, placeholder key requirements in unwritable directories, friendly-name forgery vulnerabilities, and regex match boundaries straddling existing placeholders. - Fixed a first-use race condition in `ArtifactManager` where concurrent callers could allocate duplicate artifact IDs. diff --git a/packages/coding-agent/src/extensibility/legacy-pi-coding-agent-shim.ts b/packages/coding-agent/src/extensibility/legacy-pi-coding-agent-shim.ts index ef2c08a6e..f9fa65396 100644 --- a/packages/coding-agent/src/extensibility/legacy-pi-coding-agent-shim.ts +++ b/packages/coding-agent/src/extensibility/legacy-pi-coding-agent-shim.ts @@ -17,7 +17,7 @@ import * as fs from "node:fs"; import * as path from "node:path"; import type { AgentToolResult, AgentToolUpdateCallback } from "@oh-my-pi/pi-agent-core"; import { type AuthCredential, SqliteAuthCredentialStore, type TSchema } from "@oh-my-pi/pi-ai"; -import { Text } from "@oh-my-pi/pi-tui"; +import { getKeybindings, type Keybinding, Text } from "@oh-my-pi/pi-tui"; import { getAgentDbPath, getAgentDir, @@ -26,6 +26,7 @@ import { parseFrontmatter as parseOmpFrontmatter, } from "@oh-my-pi/pi-utils"; import { getPackageDir as getOmpPackageDir } from "../config"; +import { formatKeyHints } from "../config/keybindings"; import type { PromptTemplate } from "../config/prompt-templates"; import { type SettingPath, Settings } from "../config/settings"; import { EditTool } from "../edit"; @@ -373,6 +374,11 @@ async function executeLegacyBashOperations( } } +/** Format the active shortcut for legacy extensions that render keybinding hints. */ +export function keyText(action: Keybinding): string { + return formatKeyHints(getKeybindings().getKeys(action)); +} + /** Parse frontmatter using the historical Pi package-root helper. */ export interface ParsedFrontmatter = Record> { frontmatter: T; diff --git a/packages/coding-agent/test/keybindings-display.test.ts b/packages/coding-agent/test/keybindings-display.test.ts index 3fafef3ff..e2f191831 100644 --- a/packages/coding-agent/test/keybindings-display.test.ts +++ b/packages/coding-agent/test/keybindings-display.test.ts @@ -1,5 +1,7 @@ -import { describe, expect, it } from "bun:test"; +import { afterEach, beforeEach, describe, expect, it } from "bun:test"; import { getDefaultPasteImageKeys, KeybindingsManager } from "@oh-my-pi/pi-coding-agent/config/keybindings"; +import { keyText } from "@oh-my-pi/pi-coding-agent/extensibility/legacy-pi-coding-agent-shim"; +import { getKeybindings, setKeybindings, type KeybindingsManager as TuiKeybindingsManager } from "@oh-my-pi/pi-tui"; describe("KeybindingsManager.getDisplayString", () => { it("formats a single binding as a human-readable key hint", () => { @@ -33,6 +35,24 @@ describe("KeybindingsManager.getDisplayString", () => { }); }); +describe("legacy keyText", () => { + let previous: TuiKeybindingsManager; + + beforeEach(() => { + previous = getKeybindings(); + }); + + afterEach(() => { + setKeybindings(previous); + }); + + it("formats the active binding for legacy extensions", () => { + setKeybindings(KeybindingsManager.inMemory({ "app.tools.expand": "alt+e" })); + + expect(keyText("app.tools.expand")).toBe("Alt+E"); + }); +}); + describe("getDefaultPasteImageKeys", () => { it("keeps Ctrl+V registered for image paste on Windows alongside the terminal-safe fallback", () => { expect(getDefaultPasteImageKeys("win32")).toEqual(["ctrl+v", "alt+v"]);