From d80ae9cda5ae392a9e7a6f3cc780c4b34892bbf1 Mon Sep 17 00:00:00 2001 From: devkade Date: Sun, 17 May 2026 20:43:10 +0900 Subject: [PATCH] refactor: rename presentation workflow helpers --- docs/product-name-audit.md | 1 + index.ts | 6 ++-- src/presentation/command-ui-actions.ts | 4 +-- src/presentation/extension-registration.ts | 6 ++-- src/presentation/pi-extension.ts | 18 ++++++------ src/presentation/tool-core-types.ts | 2 +- src/presentation/tools.ts | 34 +++++++++++----------- src/presentation/ui-resources.ts | 2 +- src/presentation/ui.ts | 14 ++++----- test/presentation-ui.test.ts | 6 ++-- 10 files changed, 47 insertions(+), 46 deletions(-) diff --git a/docs/product-name-audit.md b/docs/product-name-audit.md index 30c4a32..6d10f65 100644 --- a/docs/product-name-audit.md +++ b/docs/product-name-audit.md @@ -37,6 +37,7 @@ git grep -n -i -E 'kapi|ilchul' -- ':!package-lock.json' ':!node_modules' - Registry entry types now use the semantic `WorkflowRegistryEntry` name across the domain, adapter, CLI, presentation, and tests. - Store abstractions now use semantic `WorkflowStore` / `FileWorkflowStore` names across application ports, adapters, and runtime probe scripts; compatibility imports have been migrated and the temporary store alias has been removed. - Service source surfaces now use semantic `WorkflowService` in the implementation, local factory, presentation layer, runtime probe scripts, and active tests; the temporary `KapiService` export has been removed after migrating the large remaining test clusters. +- Presentation registration/UI action helpers now use semantic workflow names (`registerWorkflowExtension`, `registerWorkflowCommandsAndTools`, `registerWorkflowTools`, `WorkflowUiActionContext`, `installWorkflowAutocomplete`, `toggleWorkflowWidgetExpanded`) while leaving public `kapi_*` tool names and `/kapi-*` contracts intact. ## Residual scan after service filename rename diff --git a/index.ts b/index.ts index 82c8df7..dd7b19d 100644 --- a/index.ts +++ b/index.ts @@ -1,5 +1,5 @@ -import { registerKapiExtension, type ExtensionAPI } from "./src/presentation/pi-extension.js"; +import { registerWorkflowExtension, type ExtensionAPI } from "./src/presentation/pi-extension.js"; -export default function kapi(pi: ExtensionAPI): void { - registerKapiExtension(pi); +export default function extension(pi: ExtensionAPI): void { + registerWorkflowExtension(pi); } diff --git a/src/presentation/command-ui-actions.ts b/src/presentation/command-ui-actions.ts index 304a2a5..74169d7 100644 --- a/src/presentation/command-ui-actions.ts +++ b/src/presentation/command-ui-actions.ts @@ -1,8 +1,8 @@ import { isTerminalStatus } from "../domain/state-machine.js"; -import type { KapiUiActionContext } from "./tool-core-types.js"; +import type { WorkflowUiActionContext } from "./tool-core-types.js"; import { formatWorkflowError, labelLatestSessionEntry, resumeUiState, updateUi } from "./ui.js"; -interface CommandErrorInput extends KapiUiActionContext { +interface CommandErrorInput extends WorkflowUiActionContext { command: string; error: unknown; details?: Record; diff --git a/src/presentation/extension-registration.ts b/src/presentation/extension-registration.ts index d34845f..26de760 100644 --- a/src/presentation/extension-registration.ts +++ b/src/presentation/extension-registration.ts @@ -1,10 +1,10 @@ import type { ExtensionAPI, WorkflowService } from "./tool-core-types.js"; import { WORKFLOW_DEFINITIONS } from "../domain/workflows.js"; import { registerPrimaryWorkflowCommands, registerSupportCommands } from "./commands.js"; -import { registerKapiTools } from "./tools.js"; +import { registerWorkflowTools } from "./tools.js"; -export function registerKapiCommandsAndTools(pi: ExtensionAPI, service: WorkflowService): void { +export function registerWorkflowCommandsAndTools(pi: ExtensionAPI, service: WorkflowService): void { registerPrimaryWorkflowCommands(pi, service, WORKFLOW_DEFINITIONS); registerSupportCommands(pi, service); - registerKapiTools(pi, service); + registerWorkflowTools(pi, service); } diff --git a/src/presentation/pi-extension.ts b/src/presentation/pi-extension.ts index 812e5c7..73caa7c 100644 --- a/src/presentation/pi-extension.ts +++ b/src/presentation/pi-extension.ts @@ -1,16 +1,16 @@ import type { ExtensionAPI, ExtensionContext } from "@mariozechner/pi-coding-agent"; import { createLocalWorkflowService } from "../adapters/workflow-service-factory.js"; -import { registerKapiCommandsAndTools } from "./extension-registration.js"; -import { existingResourcePath, extensionRootFromImportMeta, installKapiAutocomplete, loadedSkillSummary, toggleKapiWidgetExpanded, updateUi } from "./ui.js"; +import { registerWorkflowCommandsAndTools } from "./extension-registration.js"; +import { existingResourcePath, extensionRootFromImportMeta, installWorkflowAutocomplete, loadedSkillSummary, toggleWorkflowWidgetExpanded, updateUi } from "./ui.js"; export type { ExtensionAPI }; -const KAPI_EXTENSION_ROOT = extensionRootFromImportMeta(import.meta.url); +const EXTENSION_ROOT = extensionRootFromImportMeta(import.meta.url); -export function registerKapiExtension(pi: ExtensionAPI): void { +export function registerWorkflowExtension(pi: ExtensionAPI): void { const service = createLocalWorkflowService(); - registerKapiCommandsAndTools(pi, service); + registerWorkflowCommandsAndTools(pi, service); const withActiveState = async (ctx: ExtensionContext, handler: (state: NonNullable>>) => void): Promise => { const state = await service.getActiveStatus(ctx.cwd); @@ -27,19 +27,19 @@ export function registerKapiExtension(pi: ExtensionAPI): void { ctx.ui.notify("Kapi: no active workflow to expand.", "info"); return; } - const expanded = toggleKapiWidgetExpanded(); + const expanded = toggleWorkflowWidgetExpanded(); updateUi(ctx, state); ctx.ui.notify(`Kapi status ${expanded ? "expanded" : "collapsed"}.`, "info"); }, }); pi.on("resources_discover", async () => ({ - skillPaths: existingResourcePath(KAPI_EXTENSION_ROOT, "skills"), - promptPaths: existingResourcePath(KAPI_EXTENSION_ROOT, "prompts"), + skillPaths: existingResourcePath(EXTENSION_ROOT, "skills"), + promptPaths: existingResourcePath(EXTENSION_ROOT, "prompts"), })); pi.on("session_start", async (_event, ctx) => { - installKapiAutocomplete(ctx); + installWorkflowAutocomplete(ctx); const state = await service.getActiveStatus(ctx.cwd); updateUi(ctx, state); }); diff --git a/src/presentation/tool-core-types.ts b/src/presentation/tool-core-types.ts index e9b4483..46dbf4f 100644 --- a/src/presentation/tool-core-types.ts +++ b/src/presentation/tool-core-types.ts @@ -5,7 +5,7 @@ import type { AgentToolResult, ExtensionAPI, ExtensionContext, Theme } from "@ma export type { AgentToolResult, ExtensionAPI, ExtensionContext, WorkflowService, LifecycleStatus, StartWorkflowInput, Theme, WorkflowDefinition, WorkflowId, WorkflowState, WriteArtifactInput }; -export interface KapiUiActionContext { +export interface WorkflowUiActionContext { pi: ExtensionAPI; service: WorkflowService; ctx: ExtensionContext; diff --git a/src/presentation/tools.ts b/src/presentation/tools.ts index 1aebfba..6695bc1 100644 --- a/src/presentation/tools.ts +++ b/src/presentation/tools.ts @@ -1,4 +1,4 @@ -import type { AgentToolResult, ExtensionAPI, ExtensionContext, WorkflowService, KapiUiActionContext, LifecycleStatus, StartWorkflowInput, WorkflowId, WriteArtifactInput } from "./tool-core-types.js"; +import type { AgentToolResult, ExtensionAPI, ExtensionContext, WorkflowService, WorkflowUiActionContext, LifecycleStatus, StartWorkflowInput, WorkflowId, WriteArtifactInput } from "./tool-core-types.js"; import { projectRunContract } from "../domain/run-contract.js"; import type { WorkflowState } from "../domain/types.js"; import { getWorkflowDefinition } from "../domain/workflows.js"; @@ -62,13 +62,13 @@ function workflowEvidenceInput(ctx: ExtensionContext, params: WorkflowEvidenceTo }; } -interface ToolErrorRequest extends KapiUiActionContext { +interface ToolErrorRequest extends WorkflowUiActionContext { tool: string; error: unknown; details?: Record; } -async function kapiToolError(request: ToolErrorRequest): Promise> { +async function workflowToolError(request: ToolErrorRequest): Promise> { const message = formatWorkflowError(request.error); request.pi.appendEntry("kapi-workflow", { event: "tool-error", tool: request.tool, message, ...(request.details ?? {}) }); updateToolUi(request.ctx, await request.service.getActiveStatus(request.ctx.cwd)); @@ -78,7 +78,7 @@ async function kapiToolError(request: ToolErrorRequest): Promise ({ diff --git a/src/presentation/ui.ts b/src/presentation/ui.ts index 92468f3..a3328fd 100644 --- a/src/presentation/ui.ts +++ b/src/presentation/ui.ts @@ -1,10 +1,10 @@ import { isTerminalStatus, statusWidgetLines, type ExtensionAPI, type ExtensionContext, type WorkflowService, type Theme, type WorkflowState } from "./ui-support.js"; -let kapiWidgetExpanded = false; +let workflowWidgetExpanded = false; -export function toggleKapiWidgetExpanded(): boolean { - kapiWidgetExpanded = !kapiWidgetExpanded; - return kapiWidgetExpanded; +export function toggleWorkflowWidgetExpanded(): boolean { + workflowWidgetExpanded = !workflowWidgetExpanded; + return workflowWidgetExpanded; } export function updateUi(ctx: ExtensionContext, state: WorkflowState | undefined): void { @@ -16,8 +16,8 @@ export function updateUi(ctx: ExtensionContext, state: WorkflowState | undefined } ctx.ui.setWidget("kapi", (_tui: unknown, theme: Theme) => ({ render(width: number): string[] { - const lines = statusWidgetLines(state, { expanded: kapiWidgetExpanded }); - const hint = kapiWidgetExpanded ? "ctrl+shift+t collapse" : "ctrl+shift+t expand"; + const lines = statusWidgetLines(state, { expanded: workflowWidgetExpanded }); + const hint = workflowWidgetExpanded ? "ctrl+shift+t collapse" : "ctrl+shift+t expand"; const dimHint = theme.fg ? theme.fg("dim", `│ ${hint}`) : `│ ${hint}`; const rendered = [...lines.slice(0, -1), `${lines.at(-1) ?? ""} ${dimHint}`]; return rendered.map((line) => (width > 0 && line.length > width ? `${line.slice(0, Math.max(0, width - 1))}…` : line)); @@ -41,4 +41,4 @@ export async function resumeUiState(service: WorkflowService, ctx: ExtensionCont return isTerminalStatus(resumed.status) ? service.getActiveStatus(ctx.cwd) : resumed; } -export { existingResourcePath, extensionRootFromImportMeta, installKapiAutocomplete, loadedSkillSummary } from "./ui-resources.js"; +export { existingResourcePath, extensionRootFromImportMeta, installWorkflowAutocomplete, loadedSkillSummary } from "./ui-resources.js"; diff --git a/test/presentation-ui.test.ts b/test/presentation-ui.test.ts index 2e3f6be..c2bf4e0 100644 --- a/test/presentation-ui.test.ts +++ b/test/presentation-ui.test.ts @@ -4,7 +4,7 @@ import os from "node:os"; import path from "node:path"; import { test } from "node:test"; import { formatStatus, statusWidgetLines } from "../src/presentation/messages.js"; -import { existingResourcePath, installKapiAutocomplete, labelLatestSessionEntry, loadedSkillSummary, updateUi } from "../src/presentation/ui.js"; +import { existingResourcePath, installWorkflowAutocomplete, labelLatestSessionEntry, loadedSkillSummary, updateUi } from "../src/presentation/ui.js"; import type { WorkflowState } from "../src/domain/types.js"; function activeWorkflow(): WorkflowState { @@ -126,7 +126,7 @@ test("presentation UI helpers preserve Pi skill context and session labels witho }); test("Kapi autocomplete no-ops when the Pi UI autocomplete API is unavailable", () => { - assert.doesNotThrow(() => installKapiAutocomplete({ ui: {} } as never)); + assert.doesNotThrow(() => installWorkflowAutocomplete({ ui: {} } as never)); }); test("Kapi autocomplete suggests workflow references only for @kapi prefix", async () => { @@ -150,7 +150,7 @@ test("Kapi autocomplete suggests workflow references only for @kapi prefix", asy }, }; - installKapiAutocomplete(ctx as never); + installWorkflowAutocomplete(ctx as never); const suggestions = await provider.getSuggestions(["please use @kapi:pla"], 0, "please use @kapi:pla".length, {}); assert.equal(suggestions.prefix, "@kapi:pla");