UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

47 lines • 2.24 kB
import { getPowerShellConfig } from "../../utils/shell.js"; import { createLocalShellOperations, createShellToolDefinition, } from "./bash.js"; import { wrapToolDefinition } from "./tool-definition-wrapper.js"; const UTF8_OUTPUT_PREFIX = "try { [Console]::OutputEncoding=[System.Text.Encoding]::UTF8 } catch {}\n"; export const powershellToolSystemPromptContribution = { snippet: "Execute PowerShell commands", guidelines: ["PI_* env vars = current model + session details."], fullGuidelines: ["You can inspect PI_* environment variables for current model and session details."], }; export function createLocalPowerShellOperations(machine) { const operations = createLocalShellOperations("PowerShell", getPowerShellConfig, machine); return { exec: (command, cwd, options) => operations.exec(`${UTF8_OUTPUT_PREFIX}${command}`, cwd, options), }; } const powershellToolConfig = { name: "powershell", label: "powershell", shellName: "PowerShell", prompt: "PS>", promptSnippet: powershellToolSystemPromptContribution.snippet, promptGuidelines: powershellToolSystemPromptContribution.guidelines, fullPromptGuidelines: powershellToolSystemPromptContribution.fullGuidelines, tempFilePrefix: "pi-powershell", }; export function createPowerShellToolDefinition(cwd, options) { // The default PowerShell operations are local, not caller-injected: only a caller's own operations pin the tool. const { serverPinned: _defaultOperationsPin, ...definition } = createShellToolDefinition(cwd, powershellToolConfig, { ...options, operations: options?.operations ?? createLocalPowerShellOperations(options?.machine), }); return { ...definition, ...(options?.operations !== undefined || options?.spawnHook !== undefined ? { serverPinned: true } : {}), exposure: "eval", }; } export function createPowerShellTool(cwd, options) { const definition = createPowerShellToolDefinition(cwd, options); const tool = wrapToolDefinition(definition); Object.assign(tool, { promptSnippet: definition.promptSnippet, promptGuidelines: definition.promptGuidelines, }); return tool; } //# sourceMappingURL=powershell.js.map