@particle-academy/agent-integrations 0.11.1 → 0.12.0
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.
- package/README.md +6 -0
- package/dist/bridges/terminal.d.cts +56 -24
- package/dist/bridges/terminal.d.ts +56 -24
- package/dist/bridges-terminal.cjs +116 -53
- package/dist/bridges-terminal.cjs.map +1 -1
- package/dist/bridges-terminal.js +1 -1
- package/dist/chunk-57KAMBAR.js +275 -0
- package/dist/chunk-57KAMBAR.js.map +1 -0
- package/dist/index.cjs +116 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-FZ7Q5NS3.js +0 -212
- package/dist/chunk-FZ7Q5NS3.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/mcp/server.ts","../src/presence/wrap-tool-with-activity.ts","../src/undo/undo-tools.ts","../src/bridges/terminal.ts"],"names":["emitActivity","undoOne","redoOne","readHistory"],"mappings":";;;;;AAgLO,SAAS,UAAA,CAAW,MAAc,UAAA,EAAkC;AACzE,EAAA,OAAO;AAAA,IACL,SAAS,CAAC,EAAE,IAAA,EAAM,MAAA,EAAQ,MAAM,CAAA;AAAA,IAChC,GAAI,UAAA,KAAe,MAAA,GAAY,EAAE,iBAAA,EAAmB,UAAA,KAAe;AAAC,GACtE;AACF;AAEO,SAAS,YAAY,IAAA,EAA8B;AACxD,EAAA,OAAO,EAAE,OAAA,EAAS,CAAC,EAAE,IAAA,EAAM,QAAQ,IAAA,EAAM,CAAA,EAAG,OAAA,EAAS,IAAA,EAAK;AAC5D;;;AC1IO,SAAS,oBAAA,CACd,SACA,OAAA,EAYoB;AACpB,EAAA,OAAO,OAAO,IAAA,KAAS;AACrB,IAAA,MAAM,MAAA,GAAS,MAAM,OAAA,CAAQ,IAAI,CAAA;AACjC,IAAA,IAAI,MAAA,CAA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AAA,IACF,CAAA;AAAA,IACA,MAAA,EAAQ,CAAC,EAAA,KAAe;AACtB,MAAA,MAAA,CAAO,OAAO,EAAE,CAAA;AAAA,IAClB,CAAA;AAAA,IACA,SAAS,MAAM,CAAC,GAAG,MAAA,CAAO,QAAQ;AAAA,GACpC;AACF","file":"bridges-terminal.cjs","sourcesContent":["import {\n type CallToolResult,\n type JsonObject,\n type JsonRpcMessage,\n type JsonRpcRequest,\n type JsonRpcId,\n type RegisteredTool,\n type ServerCapabilities,\n type ServerInfo,\n type ToolDefinition,\n type ToolHandler,\n JSONRPC_INTERNAL_ERROR,\n JSONRPC_INVALID_PARAMS,\n JSONRPC_METHOD_NOT_FOUND,\n MCP_PROTOCOL_VERSION,\n} from \"./types\";\nimport { ToolRegistry } from \"./tool-host\";\n\nexport type McpServerOptions = {\n info: ServerInfo;\n /** Defaults to { tools: { listChanged: true } } */\n capabilities?: ServerCapabilities;\n /** Free-text instructions surfaced to clients during initialize. */\n instructions?: string;\n};\n\nexport type Transport = {\n /** Called by the server when it has a message to deliver to the client. */\n send: (message: JsonRpcMessage) => void;\n /** Called by the server when it's torn down so the transport can clean up. */\n close?: () => void;\n};\n\n/**\n * MicroMcpServer — protocol-level MCP server, transport-agnostic.\n *\n * Use it like:\n *\n * const server = new MicroMcpServer({ info: { name: \"session\", version: \"0.1\" } });\n * server.registerTool({ name: \"...\", inputSchema: { type: \"object\" } }, async (args) => ({...}));\n * const transport = new InProcessTransport();\n * server.attach(transport);\n * transport.deliver({ ... }); // client → server frames\n *\n * The same server can serve multiple transports (e.g. an in-process agent\n * AND a relayed external client) by attaching each one.\n */\nexport class MicroMcpServer extends ToolRegistry {\n private transports = new Set<Transport>();\n private notifyListChangedScheduled = false;\n\n readonly info: ServerInfo;\n readonly capabilities: ServerCapabilities;\n readonly instructions?: string;\n\n constructor(options: McpServerOptions) {\n super();\n this.info = options.info;\n this.capabilities = options.capabilities ?? { tools: { listChanged: true } };\n this.instructions = options.instructions;\n }\n\n attach(transport: Transport): () => void {\n this.transports.add(transport);\n return () => this.detach(transport);\n }\n\n detach(transport: Transport): void {\n if (this.transports.delete(transport)) {\n transport.close?.();\n }\n }\n\n unregisterTool(name: string): void {\n if (this.tools.delete(name)) {\n this.scheduleListChangedNotification();\n }\n }\n\n protected onToolsChanged(): void {\n this.scheduleListChangedNotification();\n }\n\n /**\n * Receive a JSON-RPC frame from a client (called by the transport).\n * The transport is responsible for sending the response back.\n */\n async receive(transport: Transport, message: JsonRpcMessage): Promise<void> {\n if (!(\"method\" in message)) return; // It's a response, not a request — ignore.\n\n const isNotification = !(\"id\" in message);\n if (isNotification) {\n // Notifications are fire-and-forget. We ignore unknown methods.\n return;\n }\n\n const request = message as JsonRpcRequest;\n try {\n const result = await this.handle(request);\n transport.send({ jsonrpc: \"2.0\", id: request.id, result });\n } catch (err) {\n transport.send({\n jsonrpc: \"2.0\",\n id: request.id,\n error: this.toRpcError(err),\n });\n }\n }\n\n private async handle(request: JsonRpcRequest): Promise<any> {\n const { method, params } = request;\n switch (method) {\n case \"initialize\":\n return {\n protocolVersion: MCP_PROTOCOL_VERSION,\n capabilities: this.capabilities,\n serverInfo: this.info,\n ...(this.instructions ? { instructions: this.instructions } : {}),\n };\n\n case \"tools/list\":\n return { tools: this.listTools() };\n\n case \"tools/call\": {\n const name = params?.name;\n const args = (params?.arguments ?? {}) as JsonObject;\n if (typeof name !== \"string\") {\n throw rpcError(JSONRPC_INVALID_PARAMS, \"tools/call requires `name`\");\n }\n const tool = this.tools.get(name);\n if (!tool) {\n throw rpcError(JSONRPC_METHOD_NOT_FOUND, `Unknown tool: ${name}`);\n }\n const result = await tool.handler(args);\n return result satisfies CallToolResult;\n }\n\n case \"ping\":\n return {};\n\n default:\n throw rpcError(JSONRPC_METHOD_NOT_FOUND, `Unsupported method: ${method}`);\n }\n }\n\n private scheduleListChangedNotification(): void {\n if (this.notifyListChangedScheduled) return;\n this.notifyListChangedScheduled = true;\n queueMicrotask(() => {\n this.notifyListChangedScheduled = false;\n this.broadcast({ jsonrpc: \"2.0\", method: \"notifications/tools/list_changed\" });\n });\n }\n\n private broadcast(message: JsonRpcMessage): void {\n for (const t of this.transports) t.send(message);\n }\n\n private toRpcError(err: unknown): { code: number; message: string; data?: any } {\n if (err && typeof err === \"object\" && \"code\" in err && \"message\" in err) {\n return err as any;\n }\n return {\n code: JSONRPC_INTERNAL_ERROR,\n message: err instanceof Error ? err.message : String(err),\n };\n }\n}\n\nexport function rpcError(code: number, message: string, data?: any) {\n return { code, message, ...(data !== undefined ? { data } : {}) };\n}\n\n/**\n * Helper to build a CallToolResult from a string or structured value.\n */\nexport function textResult(text: string, structured?: any): CallToolResult {\n return {\n content: [{ type: \"text\", text }],\n ...(structured !== undefined ? { structuredContent: structured } : {}),\n };\n}\n\nexport function errorResult(text: string): CallToolResult {\n return { content: [{ type: \"text\", text }], isError: true };\n}\n\n// Internal helper so the JsonRpcId import isn't dropped by tsup\ntype _KeepIdImport = JsonRpcId;\n","import type { CallToolResult } from \"../mcp/types\";\nimport { emitActivity } from \"./registry\";\nimport type { AgentTarget } from \"./types\";\n\nexport type ActivityAgent = { id: string; name?: string; color?: string };\n\nexport type ActivityResolverContext<TArgs = Record<string, unknown>> = {\n /** Tool name as registered. */\n toolName: string;\n /** Arguments the tool was called with. */\n args: TArgs;\n /** The CallToolResult the underlying handler produced. */\n result: CallToolResult;\n};\n\n/**\n * Resolves an `AgentTarget` for an executed tool. Bridges declare one of\n * these per registration so the wrapper knows which surface / element /\n * screen the activity belongs to.\n *\n * The resolver runs AFTER the tool handler so it can inspect the result\n * (e.g. read a newly-created item id from `structuredContent`).\n */\nexport type ActivityTargetResolver<TArgs = Record<string, unknown>> = (\n ctx: ActivityResolverContext<TArgs>,\n) => AgentTarget | null;\n\nexport type ToolHandler<TArgs = Record<string, unknown>> = (\n args: TArgs,\n) => Promise<CallToolResult> | CallToolResult;\n\n/**\n * wrapToolWithActivity — decorate a bridge tool handler so every successful\n * call emits an `AgentActivityEvent`. Returns a new handler with the same shape.\n *\n * Usage in a bridge:\n *\n * server.registerTool(\n * definition,\n * wrapToolWithActivity(\n * handler,\n * { agent, kind: \"whiteboard\", resolveTarget: ({ args }) => ({\n * kind: \"whiteboard\", elementId: args.id as string,\n * }) },\n * ),\n * );\n */\nexport function wrapToolWithActivity<TArgs = Record<string, unknown>>(\n handler: ToolHandler<TArgs>,\n options: {\n toolName: string;\n agent: ActivityAgent;\n /** Optional fancy-screens screen id this bridge is scoped to. */\n screenId?: string;\n /** Default target kind if the resolver returns one without `kind`. */\n kind: AgentTarget[\"kind\"];\n /** Per-call resolver. Return `null` to skip emitting (e.g. for read-only tools). */\n resolveTarget?: ActivityTargetResolver<TArgs>;\n /** Optional ttl override. */\n ttlMs?: number;\n },\n): ToolHandler<TArgs> {\n return async (args) => {\n const result = await handler(args);\n if (result.isError) return result;\n\n let target: AgentTarget | null;\n if (options.resolveTarget) {\n target = options.resolveTarget({ toolName: options.toolName, args, result });\n } else {\n target = { kind: options.kind, screenId: options.screenId };\n }\n if (!target) return result;\n\n emitActivity({\n agentId: options.agent.id,\n agentName: options.agent.name,\n agentColor: options.agent.color,\n target: { ...target, kind: target.kind ?? options.kind, screenId: target.screenId ?? options.screenId },\n action: options.toolName,\n timestamp: Date.now(),\n meta: extractMeta(result),\n ttlMs: options.ttlMs,\n });\n return result;\n };\n}\n\nfunction extractMeta(result: CallToolResult): Record<string, unknown> | undefined {\n const sc = result.structuredContent;\n if (sc && typeof sc === \"object\" && !Array.isArray(sc)) {\n return sc as Record<string, unknown>;\n }\n return undefined;\n}\n","import { textResult, errorResult } from \"../mcp/server\";\nimport type { ToolHost } from \"../mcp/tool-host\";\nimport { readHistory, redoOne, undoOne } from \"./undo-stack\";\n\nexport type UndoToolsOptions = {\n /** Default agent id when the caller doesn't pass one. */\n defaultAgentId?: string;\n};\n\n/**\n * Idempotent tracker so multiple bridges on the same server only register\n * agent_undo / agent_redo / agent_history once.\n */\nconst installedHosts = new WeakSet<ToolHost>();\n\n/**\n * ensureUndoToolsRegistered — bridges call this on construction. Safe to\n * call repeatedly with the same server; subsequent calls are no-ops.\n */\nexport function ensureUndoToolsRegistered(host: ToolHost, options: UndoToolsOptions = {}): void {\n if (installedHosts.has(host)) return;\n installedHosts.add(host);\n registerUndoTools(host, options);\n}\n\n/**\n * registerUndoTools — add agent_undo / agent_redo / agent_history to the\n * server. Returns a disposer that unregisters all three.\n */\nexport function registerUndoTools(host: ToolHost, options: UndoToolsOptions = {}): () => void {\n const defaultAgent = options.defaultAgentId ?? \"agent\";\n const disposers: Array<() => void> = [];\n const agentOf = (args: any): string =>\n typeof args?.agentId === \"string\" ? args.agentId : defaultAgent;\n\n disposers.push(\n host.registerTool(\n {\n name: \"agent_undo\",\n description: \"Undo the most recent action on the agent's stack. Optional agentId targets a specific agent.\",\n inputSchema: {\n type: \"object\",\n properties: { agentId: { type: \"string\" } },\n additionalProperties: false,\n },\n },\n async (args) => {\n const entry = await undoOne(agentOf(args));\n if (!entry) return errorResult(\"Nothing to undo.\");\n return textResult(`Undid: ${entry.label}`, { entry: serialize(entry) });\n },\n ),\n );\n\n disposers.push(\n host.registerTool(\n {\n name: \"agent_redo\",\n description: \"Redo the most recently undone action.\",\n inputSchema: {\n type: \"object\",\n properties: { agentId: { type: \"string\" } },\n additionalProperties: false,\n },\n },\n async (args) => {\n const entry = await redoOne(agentOf(args));\n if (!entry) return errorResult(\"Nothing to redo.\");\n return textResult(`Redid: ${entry.label}`, { entry: serialize(entry) });\n },\n ),\n );\n\n disposers.push(\n host.registerTool(\n {\n name: \"agent_history\",\n description: \"List the agent's undo stack (oldest first). Useful for understanding what's reversible.\",\n inputSchema: {\n type: \"object\",\n properties: { agentId: { type: \"string\" } },\n additionalProperties: false,\n },\n },\n async (args) => {\n const history = readHistory(agentOf(args)).map(serialize);\n const text = history.map((e) => `${new Date(e.timestamp).toISOString()} ${e.bridgeId} ${e.action}: ${e.label}`).join(\"\\n\");\n return textResult(text || \"(empty)\", history);\n },\n ),\n );\n\n return () => disposers.forEach((d) => d());\n}\n\nfunction serialize(entry: import(\"./undo-stack\").UndoEntry) {\n return {\n timestamp: entry.timestamp,\n bridgeId: entry.bridgeId,\n action: entry.action,\n label: entry.label,\n };\n}\n","import { textResult, errorResult } from \"../mcp/server\";\nimport type { ToolHost } from \"../mcp/tool-host\";\nimport type { JsonObject } from \"../mcp/types\";\nimport type { Bridge } from \"./types\";\nimport { wrapToolWithActivity } from \"../presence/wrap-tool-with-activity\";\nimport { ensureUndoToolsRegistered } from \"../undo/undo-tools\";\nimport type { AgentTarget } from \"../presence/types\";\n\n/**\n * A shell/profile an agent can switch the terminal to. Mirrors fancy-term's\n * `ShellProfile` (kept local so the bridge never imports fancy-term).\n */\nexport type TerminalShell = { id: string; label: string; icon?: string };\n\n/**\n * Host-provided window into a terminal surface (e.g. a fancy-term `<Terminal>`'s\n * `TerminalHandle`). The bridge never touches the DOM — it reads + writes through\n * these functions, so it works with any terminal the host wires up.\n */\nexport type TerminalBridgeAdapter = {\n /** fancy-screens screen id (optional) so activity events know which screen the terminal lives in. */\n screenId?: string;\n /** Read the visible terminal buffer as text (wire to `TerminalHandle.getBuffer`). */\n getBuffer: () => string;\n /** Write raw data / keystrokes to the terminal (wire to `TerminalHandle.write`). */\n write: (data: string) => void;\n /** Run a command. Defaults to writing `${command}\\r` (submit to a PTY); override to call a real command runner. */\n runCommand?: (command: string) => void | Promise<void>;\n /** Optional: clear the terminal viewport (wire to `TerminalHandle.clear`). */\n clear?: () => void;\n /** Optional: the shells the host offers (cmd, powershell, git-bash, …). Enables `terminal_list_shells`. */\n listShells?: () => TerminalShell[];\n /** Optional: switch the active shell by id (wire to `TerminalHandle.setShell` + a host backend reconnect). Enables `terminal_set_shell`. */\n setShell?: (id: string) => void | Promise<void>;\n /** Optional: the currently active shell id (wire to `TerminalHandle.getShell`). */\n getShell?: () => string | undefined;\n};\n\ntype StagedKind = \"write\" | \"run\";\ntype Staged = { id: string; kind: StagedKind; data: string };\n\nexport type TerminalBridgeOptions = {\n adapter: TerminalBridgeAdapter;\n agent?: { id: string; name?: string; color?: string };\n /**\n * Trust-but-verify (Human+ contract for inhabited surfaces). When on,\n * `terminal_write` + `terminal_run` don't execute — they **stage** the command\n * (returning a pending id) and fire `onPending`. A human confirms via the\n * `terminal_confirm` tool or the returned bridge's `confirm(id)`. Default off.\n */\n pendingMode?: boolean;\n /** Notified when a command is staged (pendingMode) — show it + offer confirm / reject. */\n onPending?: (pending: Staged) => void;\n};\n\nexport type TerminalBridge = Bridge & {\n /** Execute a staged command by id — wire a host confirm button to this. No-op if not pending. */\n confirm: (id: string) => void;\n /** Drop a staged command by id without executing. */\n reject: (id: string) => void;\n /** Commands currently awaiting confirmation. */\n pending: () => Staged[];\n};\n\nconst DEFAULT_AGENT = { id: \"agent\", name: \"Agent\", color: \"#a855f7\" };\n\nconst truncate = (s: string, n = 60): string => (s.length > n ? s.slice(0, n) + \"…\" : s);\n\n/**\n * registerTerminalBridge — MCP access to a terminal surface. An agent reads the\n * visible buffer (`terminal_read`), writes input (`terminal_write`), and runs\n * commands (`terminal_run`) through the host adapter; every mutation broadcasts\n * an `AgentActivity` event. With `pendingMode`, destructive actions are staged\n * for human confirmation (`terminal_confirm` / `terminal_reject` /\n * `terminal_pending`). When the adapter offers shells, the agent can also list\n * (`terminal_list_shells`) and switch (`terminal_set_shell`) the active shell —\n * cmd, PowerShell, Git Bash, etc. Tool prefix `terminal_*`.\n */\nexport function registerTerminalBridge(host: ToolHost, options: TerminalBridgeOptions): TerminalBridge {\n const { adapter } = options;\n const agent = { ...DEFAULT_AGENT, ...(options.agent ?? {}) };\n const pendingMode = options.pendingMode ?? false;\n const disposers: Array<() => void> = [];\n const staged = new Map<string, Staged>();\n let seq = 0;\n\n // Enables agent_history (a log of what agents did across every bridge).\n ensureUndoToolsRegistered(host);\n\n const target = (label?: string): AgentTarget => ({\n kind: \"terminal\",\n screenId: adapter.screenId,\n elementId: adapter.screenId ?? \"terminal\",\n label: label ?? \"terminal\",\n });\n\n const reg = (\n name: string,\n description: string,\n properties: Record<string, unknown>,\n required: string[],\n handler: (args: JsonObject) => Promise<any> | any,\n isMutation: boolean,\n resolveTarget?: (args: JsonObject, result: any) => AgentTarget | null,\n ) => {\n const wrapped = async (args: JsonObject) => {\n try {\n return await handler(args);\n } catch (e) {\n return errorResult(e instanceof Error ? e.message : String(e));\n }\n };\n const final = isMutation\n ? wrapToolWithActivity(wrapped, {\n toolName: name,\n agent,\n kind: \"terminal\",\n screenId: adapter.screenId,\n resolveTarget: ({ args, result }) => resolveTarget?.(args, result) ?? target(),\n })\n : wrapped;\n disposers.push(\n host.registerTool(\n {\n name,\n description,\n inputSchema: { type: \"object\", properties: properties as any, required, additionalProperties: false },\n },\n final as any,\n ),\n );\n };\n\n async function exec(kind: StagedKind, data: string): Promise<void> {\n if (kind === \"run\") {\n if (adapter.runCommand) await adapter.runCommand(data);\n else adapter.write(data + \"\\r\");\n } else {\n adapter.write(data);\n }\n }\n\n async function stageOrExec(kind: StagedKind, data: string) {\n if (!pendingMode) {\n await exec(kind, data);\n return textResult(`${kind === \"run\" ? \"ran\" : \"wrote\"}: ${truncate(data)}`, { kind, data, executed: true });\n }\n const id = `t${++seq}`;\n const entry: Staged = { id, kind, data };\n staged.set(id, entry);\n options.onPending?.(entry);\n return textResult(\n `Staged ${kind} (id ${id}) — awaiting human confirmation: ${truncate(data)}`,\n { ...entry, pending: true },\n );\n }\n\n // ── Read ──────────────────────────────────────────────────────────────────\n reg(\n \"terminal_read\",\n \"Read the visible terminal buffer as text — what the user sees. Pass `tail` for only the last N lines.\",\n { tail: { type: \"number\", description: \"Return only the last N lines.\" } },\n [],\n (args) => {\n let buf = adapter.getBuffer();\n const tail = typeof args.tail === \"number\" ? args.tail : undefined;\n if (tail && tail > 0) buf = buf.split(\"\\n\").slice(-tail).join(\"\\n\");\n return textResult(buf, { buffer: buf });\n },\n false,\n );\n\n reg(\n \"terminal_pending\",\n \"List commands staged for human confirmation (pendingMode).\",\n {},\n [],\n () => {\n const list = [...staged.values()];\n return textResult(\n list.length ? list.map((s) => `${s.id}: ${s.kind} ${truncate(s.data)}`).join(\"\\n\") : \"(none)\",\n { pending: list },\n );\n },\n false,\n );\n\n // ── Mutations ───────────────────────────────────────────────────────────────\n reg(\n \"terminal_write\",\n \"Write raw data / keystrokes to the terminal (input, control chars, ANSI). In pendingMode this stages instead of executing.\",\n { data: { type: \"string\", description: \"Raw bytes to write.\" } },\n [\"data\"],\n (args) => stageOrExec(\"write\", String(args.data)),\n true,\n );\n\n reg(\n \"terminal_run\",\n \"Run a shell command — writes the command followed by Enter (or the host's command runner). In pendingMode this stages it for confirmation.\",\n { command: { type: \"string\", description: \"The command line to run.\" } },\n [\"command\"],\n (args) => stageOrExec(\"run\", String(args.command)),\n true,\n (args) => target(truncate(String(args.command ?? \"\"))),\n );\n\n reg(\n \"terminal_confirm\",\n \"Confirm + execute a staged command by id (pendingMode).\",\n { id: { type: \"string\" } },\n [\"id\"],\n async (args) => {\n const id = String(args.id);\n const entry = staged.get(id);\n if (!entry) return errorResult(`No staged command ${id}`);\n staged.delete(id);\n await exec(entry.kind, entry.data);\n return textResult(`Confirmed ${id}: ${entry.kind} ${truncate(entry.data)}`, { ...entry, executed: true });\n },\n true,\n );\n\n reg(\n \"terminal_reject\",\n \"Drop a staged command by id without executing it.\",\n { id: { type: \"string\" } },\n [\"id\"],\n (args) => {\n const id = String(args.id);\n if (!staged.delete(id)) return errorResult(`No staged command ${id}`);\n return textResult(`Rejected ${id}`, { id, rejected: true });\n },\n false,\n );\n\n if (adapter.clear) {\n reg(\n \"terminal_clear\",\n \"Clear the terminal viewport.\",\n {},\n [],\n () => {\n adapter.clear!();\n return textResult(\"cleared\");\n },\n true,\n );\n }\n\n // ── Shells ──────────────────────────────────────────────────────────────────\n if (adapter.listShells) {\n reg(\n \"terminal_list_shells\",\n \"List the shells the host can switch to (cmd, PowerShell, Git Bash, …) — id + label, with the active one marked.\",\n {},\n [],\n () => {\n const shells = adapter.listShells!();\n const active = adapter.getShell?.();\n const text = shells.length\n ? shells.map((s) => `${s.id === active ? \"* \" : \" \"}${s.id} — ${s.label}`).join(\"\\n\")\n : \"(none)\";\n return textResult(text, { shells, active });\n },\n false,\n );\n }\n\n if (adapter.setShell) {\n reg(\n \"terminal_set_shell\",\n \"Switch the active shell by id (e.g. 'powershell', 'git-bash'). Call terminal_list_shells first for valid ids. The host reconnects its backend to the chosen shell.\",\n { id: { type: \"string\", description: \"Shell id to switch to.\" } },\n [\"id\"],\n async (args) => {\n const id = String(args.id);\n const shells = adapter.listShells?.();\n if (shells && shells.length && !shells.some((s) => s.id === id)) {\n return errorResult(`Unknown shell '${id}'. Use terminal_list_shells for valid ids.`);\n }\n await adapter.setShell!(id);\n return textResult(`Switched shell to ${id}`, { shell: id });\n },\n true,\n (args) => target(`shell:${String(args.id ?? \"\")}`),\n );\n }\n\n return {\n id: \"terminal\",\n title: \"Terminal\",\n dispose: () => {\n disposers.forEach((d) => d());\n disposers.length = 0;\n staged.clear();\n },\n confirm: (id: string) => {\n const e = staged.get(id);\n if (e) {\n staged.delete(id);\n void exec(e.kind, e.data);\n }\n },\n reject: (id: string) => {\n staged.delete(id);\n },\n pending: () => [...staged.values()],\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/mcp/server.ts","../src/presence/wrap-tool-with-activity.ts","../src/undo/undo-tools.ts","../src/bridges/terminal.ts"],"names":["emitActivity","undoOne","redoOne","readHistory"],"mappings":";;;;;AAgLO,SAAS,UAAA,CAAW,MAAc,UAAA,EAAkC;AACzE,EAAA,OAAO;AAAA,IACL,SAAS,CAAC,EAAE,IAAA,EAAM,MAAA,EAAQ,MAAM,CAAA;AAAA,IAChC,GAAI,UAAA,KAAe,MAAA,GAAY,EAAE,iBAAA,EAAmB,UAAA,KAAe;AAAC,GACtE;AACF;AAEO,SAAS,YAAY,IAAA,EAA8B;AACxD,EAAA,OAAO,EAAE,OAAA,EAAS,CAAC,EAAE,IAAA,EAAM,QAAQ,IAAA,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A;AAAA,IAClB,CAAA;AAAA,IACA,SAAS,MAAM,CAAC,GAAG,MAAA,CAAO,QAAQ;AAAA,GACpC;AACF","file":"bridges-terminal.cjs","sourcesContent":["import {\n type CallToolResult,\n type JsonObject,\n type JsonRpcMessage,\n type JsonRpcRequest,\n type JsonRpcId,\n type RegisteredTool,\n type ServerCapabilities,\n type ServerInfo,\n type ToolDefinition,\n type ToolHandler,\n JSONRPC_INTERNAL_ERROR,\n JSONRPC_INVALID_PARAMS,\n JSONRPC_METHOD_NOT_FOUND,\n MCP_PROTOCOL_VERSION,\n} from \"./types\";\nimport { ToolRegistry } from \"./tool-host\";\n\nexport type McpServerOptions = {\n info: ServerInfo;\n /** Defaults to { tools: { listChanged: true } } */\n capabilities?: ServerCapabilities;\n /** Free-text instructions surfaced to clients during initialize. */\n instructions?: string;\n};\n\nexport type Transport = {\n /** Called by the server when it has a message to deliver to the client. */\n send: (message: JsonRpcMessage) => void;\n /** Called by the server when it's torn down so the transport can clean up. */\n close?: () => void;\n};\n\n/**\n * MicroMcpServer — protocol-level MCP server, transport-agnostic.\n *\n * Use it like:\n *\n * const server = new MicroMcpServer({ info: { name: \"session\", version: \"0.1\" } });\n * server.registerTool({ name: \"...\", inputSchema: { type: \"object\" } }, async (args) => ({...}));\n * const transport = new InProcessTransport();\n * server.attach(transport);\n * transport.deliver({ ... }); // client → server frames\n *\n * The same server can serve multiple transports (e.g. an in-process agent\n * AND a relayed external client) by attaching each one.\n */\nexport class MicroMcpServer extends ToolRegistry {\n private transports = new Set<Transport>();\n private notifyListChangedScheduled = false;\n\n readonly info: ServerInfo;\n readonly capabilities: ServerCapabilities;\n readonly instructions?: string;\n\n constructor(options: McpServerOptions) {\n super();\n this.info = options.info;\n this.capabilities = options.capabilities ?? { tools: { listChanged: true } };\n this.instructions = options.instructions;\n }\n\n attach(transport: Transport): () => void {\n this.transports.add(transport);\n return () => this.detach(transport);\n }\n\n detach(transport: Transport): void {\n if (this.transports.delete(transport)) {\n transport.close?.();\n }\n }\n\n unregisterTool(name: string): void {\n if (this.tools.delete(name)) {\n this.scheduleListChangedNotification();\n }\n }\n\n protected onToolsChanged(): void {\n this.scheduleListChangedNotification();\n }\n\n /**\n * Receive a JSON-RPC frame from a client (called by the transport).\n * The transport is responsible for sending the response back.\n */\n async receive(transport: Transport, message: JsonRpcMessage): Promise<void> {\n if (!(\"method\" in message)) return; // It's a response, not a request — ignore.\n\n const isNotification = !(\"id\" in message);\n if (isNotification) {\n // Notifications are fire-and-forget. We ignore unknown methods.\n return;\n }\n\n const request = message as JsonRpcRequest;\n try {\n const result = await this.handle(request);\n transport.send({ jsonrpc: \"2.0\", id: request.id, result });\n } catch (err) {\n transport.send({\n jsonrpc: \"2.0\",\n id: request.id,\n error: this.toRpcError(err),\n });\n }\n }\n\n private async handle(request: JsonRpcRequest): Promise<any> {\n const { method, params } = request;\n switch (method) {\n case \"initialize\":\n return {\n protocolVersion: MCP_PROTOCOL_VERSION,\n capabilities: this.capabilities,\n serverInfo: this.info,\n ...(this.instructions ? { instructions: this.instructions } : {}),\n };\n\n case \"tools/list\":\n return { tools: this.listTools() };\n\n case \"tools/call\": {\n const name = params?.name;\n const args = (params?.arguments ?? {}) as JsonObject;\n if (typeof name !== \"string\") {\n throw rpcError(JSONRPC_INVALID_PARAMS, \"tools/call requires `name`\");\n }\n const tool = this.tools.get(name);\n if (!tool) {\n throw rpcError(JSONRPC_METHOD_NOT_FOUND, `Unknown tool: ${name}`);\n }\n const result = await tool.handler(args);\n return result satisfies CallToolResult;\n }\n\n case \"ping\":\n return {};\n\n default:\n throw rpcError(JSONRPC_METHOD_NOT_FOUND, `Unsupported method: ${method}`);\n }\n }\n\n private scheduleListChangedNotification(): void {\n if (this.notifyListChangedScheduled) return;\n this.notifyListChangedScheduled = true;\n queueMicrotask(() => {\n this.notifyListChangedScheduled = false;\n this.broadcast({ jsonrpc: \"2.0\", method: \"notifications/tools/list_changed\" });\n });\n }\n\n private broadcast(message: JsonRpcMessage): void {\n for (const t of this.transports) t.send(message);\n }\n\n private toRpcError(err: unknown): { code: number; message: string; data?: any } {\n if (err && typeof err === \"object\" && \"code\" in err && \"message\" in err) {\n return err as any;\n }\n return {\n code: JSONRPC_INTERNAL_ERROR,\n message: err instanceof Error ? err.message : String(err),\n };\n }\n}\n\nexport function rpcError(code: number, message: string, data?: any) {\n return { code, message, ...(data !== undefined ? { data } : {}) };\n}\n\n/**\n * Helper to build a CallToolResult from a string or structured value.\n */\nexport function textResult(text: string, structured?: any): CallToolResult {\n return {\n content: [{ type: \"text\", text }],\n ...(structured !== undefined ? { structuredContent: structured } : {}),\n };\n}\n\nexport function errorResult(text: string): CallToolResult {\n return { content: [{ type: \"text\", text }], isError: true };\n}\n\n// Internal helper so the JsonRpcId import isn't dropped by tsup\ntype _KeepIdImport = JsonRpcId;\n","import type { CallToolResult } from \"../mcp/types\";\nimport { emitActivity } from \"./registry\";\nimport type { AgentTarget } from \"./types\";\n\nexport type ActivityAgent = { id: string; name?: string; color?: string };\n\nexport type ActivityResolverContext<TArgs = Record<string, unknown>> = {\n /** Tool name as registered. */\n toolName: string;\n /** Arguments the tool was called with. */\n args: TArgs;\n /** The CallToolResult the underlying handler produced. */\n result: CallToolResult;\n};\n\n/**\n * Resolves an `AgentTarget` for an executed tool. Bridges declare one of\n * these per registration so the wrapper knows which surface / element /\n * screen the activity belongs to.\n *\n * The resolver runs AFTER the tool handler so it can inspect the result\n * (e.g. read a newly-created item id from `structuredContent`).\n */\nexport type ActivityTargetResolver<TArgs = Record<string, unknown>> = (\n ctx: ActivityResolverContext<TArgs>,\n) => AgentTarget | null;\n\nexport type ToolHandler<TArgs = Record<string, unknown>> = (\n args: TArgs,\n) => Promise<CallToolResult> | CallToolResult;\n\n/**\n * wrapToolWithActivity — decorate a bridge tool handler so every successful\n * call emits an `AgentActivityEvent`. Returns a new handler with the same shape.\n *\n * Usage in a bridge:\n *\n * server.registerTool(\n * definition,\n * wrapToolWithActivity(\n * handler,\n * { agent, kind: \"whiteboard\", resolveTarget: ({ args }) => ({\n * kind: \"whiteboard\", elementId: args.id as string,\n * }) },\n * ),\n * );\n */\nexport function wrapToolWithActivity<TArgs = Record<string, unknown>>(\n handler: ToolHandler<TArgs>,\n options: {\n toolName: string;\n agent: ActivityAgent;\n /** Optional fancy-screens screen id this bridge is scoped to. */\n screenId?: string;\n /** Default target kind if the resolver returns one without `kind`. */\n kind: AgentTarget[\"kind\"];\n /** Per-call resolver. Return `null` to skip emitting (e.g. for read-only tools). */\n resolveTarget?: ActivityTargetResolver<TArgs>;\n /** Optional ttl override. */\n ttlMs?: number;\n },\n): ToolHandler<TArgs> {\n return async (args) => {\n const result = await handler(args);\n if (result.isError) return result;\n\n let target: AgentTarget | null;\n if (options.resolveTarget) {\n target = options.resolveTarget({ toolName: options.toolName, args, result });\n } else {\n target = { kind: options.kind, screenId: options.screenId };\n }\n if (!target) return result;\n\n emitActivity({\n agentId: options.agent.id,\n agentName: options.agent.name,\n agentColor: options.agent.color,\n target: { ...target, kind: target.kind ?? options.kind, screenId: target.screenId ?? options.screenId },\n action: options.toolName,\n timestamp: Date.now(),\n meta: extractMeta(result),\n ttlMs: options.ttlMs,\n });\n return result;\n };\n}\n\nfunction extractMeta(result: CallToolResult): Record<string, unknown> | undefined {\n const sc = result.structuredContent;\n if (sc && typeof sc === \"object\" && !Array.isArray(sc)) {\n return sc as Record<string, unknown>;\n }\n return undefined;\n}\n","import { textResult, errorResult } from \"../mcp/server\";\nimport type { ToolHost } from \"../mcp/tool-host\";\nimport { readHistory, redoOne, undoOne } from \"./undo-stack\";\n\nexport type UndoToolsOptions = {\n /** Default agent id when the caller doesn't pass one. */\n defaultAgentId?: string;\n};\n\n/**\n * Idempotent tracker so multiple bridges on the same server only register\n * agent_undo / agent_redo / agent_history once.\n */\nconst installedHosts = new WeakSet<ToolHost>();\n\n/**\n * ensureUndoToolsRegistered — bridges call this on construction. Safe to\n * call repeatedly with the same server; subsequent calls are no-ops.\n */\nexport function ensureUndoToolsRegistered(host: ToolHost, options: UndoToolsOptions = {}): void {\n if (installedHosts.has(host)) return;\n installedHosts.add(host);\n registerUndoTools(host, options);\n}\n\n/**\n * registerUndoTools — add agent_undo / agent_redo / agent_history to the\n * server. Returns a disposer that unregisters all three.\n */\nexport function registerUndoTools(host: ToolHost, options: UndoToolsOptions = {}): () => void {\n const defaultAgent = options.defaultAgentId ?? \"agent\";\n const disposers: Array<() => void> = [];\n const agentOf = (args: any): string =>\n typeof args?.agentId === \"string\" ? args.agentId : defaultAgent;\n\n disposers.push(\n host.registerTool(\n {\n name: \"agent_undo\",\n description: \"Undo the most recent action on the agent's stack. Optional agentId targets a specific agent.\",\n inputSchema: {\n type: \"object\",\n properties: { agentId: { type: \"string\" } },\n additionalProperties: false,\n },\n },\n async (args) => {\n const entry = await undoOne(agentOf(args));\n if (!entry) return errorResult(\"Nothing to undo.\");\n return textResult(`Undid: ${entry.label}`, { entry: serialize(entry) });\n },\n ),\n );\n\n disposers.push(\n host.registerTool(\n {\n name: \"agent_redo\",\n description: \"Redo the most recently undone action.\",\n inputSchema: {\n type: \"object\",\n properties: { agentId: { type: \"string\" } },\n additionalProperties: false,\n },\n },\n async (args) => {\n const entry = await redoOne(agentOf(args));\n if (!entry) return errorResult(\"Nothing to redo.\");\n return textResult(`Redid: ${entry.label}`, { entry: serialize(entry) });\n },\n ),\n );\n\n disposers.push(\n host.registerTool(\n {\n name: \"agent_history\",\n description: \"List the agent's undo stack (oldest first). Useful for understanding what's reversible.\",\n inputSchema: {\n type: \"object\",\n properties: { agentId: { type: \"string\" } },\n additionalProperties: false,\n },\n },\n async (args) => {\n const history = readHistory(agentOf(args)).map(serialize);\n const text = history.map((e) => `${new Date(e.timestamp).toISOString()} ${e.bridgeId} ${e.action}: ${e.label}`).join(\"\\n\");\n return textResult(text || \"(empty)\", history);\n },\n ),\n );\n\n return () => disposers.forEach((d) => d());\n}\n\nfunction serialize(entry: import(\"./undo-stack\").UndoEntry) {\n return {\n timestamp: entry.timestamp,\n bridgeId: entry.bridgeId,\n action: entry.action,\n label: entry.label,\n };\n}\n","import { textResult, errorResult } from \"../mcp/server\";\nimport type { ToolHost } from \"../mcp/tool-host\";\nimport type { JsonObject } from \"../mcp/types\";\nimport type { Bridge } from \"./types\";\nimport { wrapToolWithActivity } from \"../presence/wrap-tool-with-activity\";\nimport { ensureUndoToolsRegistered } from \"../undo/undo-tools\";\nimport type { AgentTarget } from \"../presence/types\";\n\n/**\n * A shell/profile an agent can switch a terminal to. Mirrors fancy-term's\n * `ShellProfile` (kept local so the bridge never imports fancy-term).\n */\nexport type TerminalShell = { id: string; label: string; icon?: string };\n\n/**\n * One terminal the bridge can drive. A Human+ app often hosts **several**\n * terminals on a screen (a build pane, a server pane, an agent scratch shell);\n * each is a `TerminalRef` with a stable `id` so an agent can read/write any of\n * them — not just \"its own\". Wire the function fields to that terminal's\n * fancy-term `TerminalHandle`.\n */\nexport type TerminalRef = {\n /** Stable id used to address this terminal (`terminal_list` enumerates them). */\n id: string;\n /** Human label, e.g. \"Build\", \"Server\". Defaults to the id. */\n label?: string;\n /** True for the focused terminal — the default target when no id is passed. */\n active?: boolean;\n /** Read the visible buffer as text (wire to `TerminalHandle.getBuffer`). */\n getBuffer: () => string;\n /** Write raw data / keystrokes (wire to `TerminalHandle.write`). */\n write: (data: string) => void;\n /** Run a command. Defaults to writing `${command}\\r`; override for a real runner. */\n runCommand?: (command: string) => void | Promise<void>;\n /** Clear the viewport (wire to `TerminalHandle.clear`). */\n clear?: () => void;\n /** Current text selection (wire to `TerminalHandle.getSelection`). */\n getSelection?: () => string;\n /** Shells this terminal offers (cmd, PowerShell, …). */\n listShells?: () => TerminalShell[];\n /** Switch this terminal's active shell by id. */\n setShell?: (id: string) => void | Promise<void>;\n /** This terminal's active shell id. */\n getShell?: () => string | undefined;\n};\n\n/**\n * Single-terminal adapter (back-compat). A `TerminalRef` without the\n * `id`/`label`/`active` bookkeeping — pass it as `{ adapter }` and the bridge\n * treats it as the one (active) terminal. Use `{ terminals }` for multiple.\n */\nexport type TerminalBridgeAdapter = Omit<TerminalRef, \"id\" | \"label\" | \"active\"> & {\n /** fancy-screens screen id (optional) so activity events know which screen the terminal lives in. */\n screenId?: string;\n};\n\ntype StagedKind = \"write\" | \"run\";\ntype Staged = { id: string; kind: StagedKind; data: string; terminalId: string };\n\nexport type TerminalBridgeOptions = {\n /** A single terminal (back-compat). Mutually exclusive with `terminals`. */\n adapter?: TerminalBridgeAdapter;\n /**\n * The live list of terminals on the screen. Use this when the app hosts more\n * than one terminal so an agent can `terminal_list` then target any of them by\n * id — i.e. reach into another terminal in the same screen.\n */\n terminals?: () => TerminalRef[];\n /** fancy-screens screen id for activity events (defaults to `adapter.screenId`). */\n screenId?: string;\n agent?: { id: string; name?: string; color?: string };\n /**\n * Trust-but-verify (Human+ contract for inhabited surfaces). When on,\n * `terminal_write` + `terminal_run` don't execute — they **stage** the command\n * (returning a pending id) and fire `onPending`. A human confirms via the\n * `terminal_confirm` tool or the returned bridge's `confirm(id)`. Default off.\n */\n pendingMode?: boolean;\n /** Notified when a command is staged (pendingMode) — show it + offer confirm / reject. */\n onPending?: (pending: Staged) => void;\n};\n\nexport type TerminalBridge = Bridge & {\n /** Execute a staged command by id — wire a host confirm button to this. No-op if not pending. */\n confirm: (id: string) => void;\n /** Drop a staged command by id without executing. */\n reject: (id: string) => void;\n /** Commands currently awaiting confirmation. */\n pending: () => Staged[];\n};\n\nconst DEFAULT_AGENT = { id: \"agent\", name: \"Agent\", color: \"#a855f7\" };\n\nconst truncate = (s: string, n = 60): string => (s.length > n ? s.slice(0, n) + \"…\" : s);\n\n/**\n * registerTerminalBridge — MCP access to one **or many** terminal surfaces on a\n * screen. An agent reads the visible buffer (`terminal_read`), writes input\n * (`terminal_write`), and runs commands (`terminal_run`) through the host; every\n * mutation broadcasts an `AgentActivity` event. With `pendingMode`, destructive\n * actions are staged for human confirmation (`terminal_confirm` / `terminal_reject`\n * / `terminal_pending`).\n *\n * **Multi-terminal:** pass `{ terminals }` (vs a single `{ adapter }`) and every\n * tool takes an optional `terminal` id; `terminal_list` enumerates them. This is\n * how an agent **reaches into another terminal in the same screen** rather than\n * being stuck in one. When a terminal offers shells, the agent can also list\n * (`terminal_list_shells`) and switch (`terminal_set_shell`) its shell. Tool\n * prefix `terminal_*`.\n */\nexport function registerTerminalBridge(host: ToolHost, options: TerminalBridgeOptions): TerminalBridge {\n const agent = { ...DEFAULT_AGENT, ...(options.agent ?? {}) };\n const pendingMode = options.pendingMode ?? false;\n const screenId = options.screenId ?? options.adapter?.screenId;\n const disposers: Array<() => void> = [];\n const staged = new Map<string, Staged>();\n let seq = 0;\n\n // Enables agent_history (a log of what agents did across every bridge).\n ensureUndoToolsRegistered(host);\n\n // The live terminal list — from `terminals()` (multi) or the single `adapter`\n // normalized to one active ref with the id \"terminal\".\n const listTerminals = (): TerminalRef[] => {\n if (options.terminals) return options.terminals();\n if (options.adapter) return [{ id: \"terminal\", label: \"Terminal\", active: true, ...options.adapter }];\n return [];\n };\n\n /** Resolve a terminal by id; with no id, the active one, else the first. */\n const resolve = (id?: unknown): TerminalRef | undefined => {\n const list = listTerminals();\n if (typeof id === \"string\" && id !== \"\") return list.find((t) => t.id === id);\n return list.find((t) => t.active) ?? list[0];\n };\n\n // Whether any host config can offer these capabilities (gates tool registration;\n // per-call we still check the *resolved* terminal supports it).\n const anyMulti = !!options.terminals;\n const canClear = anyMulti || !!options.adapter?.clear;\n const canShells = anyMulti || !!options.adapter?.listShells;\n const canSetShell = anyMulti || !!options.adapter?.setShell;\n\n const target = (label?: string, terminalId?: string): AgentTarget => ({\n kind: \"terminal\",\n screenId,\n elementId: terminalId ?? screenId ?? \"terminal\",\n label: label ?? \"terminal\",\n });\n\n const TERMINAL_ARG = {\n terminal: {\n type: \"string\",\n description: \"Terminal id to target (call terminal_list for ids). Omit for the active / only terminal.\",\n },\n };\n\n const reg = (\n name: string,\n description: string,\n properties: Record<string, unknown>,\n required: string[],\n handler: (args: JsonObject) => Promise<any> | any,\n isMutation: boolean,\n resolveTarget?: (args: JsonObject, result: any) => AgentTarget | null,\n ) => {\n const wrapped = async (args: JsonObject) => {\n try {\n return await handler(args);\n } catch (e) {\n return errorResult(e instanceof Error ? e.message : String(e));\n }\n };\n const final = isMutation\n ? wrapToolWithActivity(wrapped, {\n toolName: name,\n agent,\n kind: \"terminal\",\n screenId,\n resolveTarget: ({ args, result }) => resolveTarget?.(args, result) ?? target(),\n })\n : wrapped;\n disposers.push(\n host.registerTool(\n {\n name,\n description,\n inputSchema: { type: \"object\", properties: properties as any, required, additionalProperties: false },\n },\n final as any,\n ),\n );\n };\n\n /** Resolve the targeted terminal or throw a clear error for the agent. */\n const need = (args: JsonObject): TerminalRef => {\n const t = resolve(args.terminal);\n if (!t) {\n const ids = listTerminals().map((x) => x.id).join(\", \") || \"(none)\";\n throw new Error(\n typeof args.terminal === \"string\" && args.terminal\n ? `Unknown terminal '${args.terminal}'. Available: ${ids}. Use terminal_list.`\n : \"No terminal available.\",\n );\n }\n return t;\n };\n\n async function exec(t: TerminalRef, kind: StagedKind, data: string): Promise<void> {\n if (kind === \"run\") {\n if (t.runCommand) await t.runCommand(data);\n else t.write(data + \"\\r\");\n } else {\n t.write(data);\n }\n }\n\n async function stageOrExec(t: TerminalRef, kind: StagedKind, data: string) {\n if (!pendingMode) {\n await exec(t, kind, data);\n return textResult(`${kind === \"run\" ? \"ran\" : \"wrote\"} on ${t.id}: ${truncate(data)}`, {\n kind,\n data,\n terminal: t.id,\n executed: true,\n });\n }\n const id = `t${++seq}`;\n const entry: Staged = { id, kind, data, terminalId: t.id };\n staged.set(id, entry);\n options.onPending?.(entry);\n return textResult(\n `Staged ${kind} on ${t.id} (id ${id}) — awaiting human confirmation: ${truncate(data)}`,\n { ...entry, pending: true },\n );\n }\n\n // ── List ──────────────────────────────────────────────────────────────────\n reg(\n \"terminal_list\",\n \"List the terminals on this screen (id, label, which is active) — so you can reach into another terminal, not just the active one. Pass the chosen id as `terminal` to the other tools.\",\n {},\n [],\n () => {\n const list = listTerminals().map((t) => ({ id: t.id, label: t.label ?? t.id, active: !!t.active }));\n const text = list.length\n ? list.map((t) => `${t.active ? \"* \" : \" \"}${t.id} — ${t.label}`).join(\"\\n\")\n : \"(no terminals)\";\n return textResult(text, { terminals: list });\n },\n false,\n );\n\n // ── Read ──────────────────────────────────────────────────────────────────\n reg(\n \"terminal_read\",\n \"Read a terminal's visible buffer as text — what the user sees. Pass `tail` for only the last N lines, `terminal` to read a specific one.\",\n { ...TERMINAL_ARG, tail: { type: \"number\", description: \"Return only the last N lines.\" } },\n [],\n (args) => {\n const t = need(args);\n let buf = t.getBuffer();\n const tail = typeof args.tail === \"number\" ? args.tail : undefined;\n if (tail && tail > 0) buf = buf.split(\"\\n\").slice(-tail).join(\"\\n\");\n return textResult(buf, { buffer: buf, terminal: t.id });\n },\n false,\n );\n\n reg(\n \"terminal_pending\",\n \"List commands staged for human confirmation (pendingMode).\",\n {},\n [],\n () => {\n const list = [...staged.values()];\n return textResult(\n list.length ? list.map((s) => `${s.id}: ${s.kind} on ${s.terminalId} ${truncate(s.data)}`).join(\"\\n\") : \"(none)\",\n { pending: list },\n );\n },\n false,\n );\n\n // ── Mutations ───────────────────────────────────────────────────────────────\n reg(\n \"terminal_write\",\n \"Write raw data / keystrokes to a terminal (input, control chars, ANSI). Pass `terminal` to target a specific one. In pendingMode this stages instead of executing.\",\n { ...TERMINAL_ARG, data: { type: \"string\", description: \"Raw bytes to write.\" } },\n [\"data\"],\n (args) => stageOrExec(need(args), \"write\", String(args.data)),\n true,\n (args) => target(`write:${String(args.terminal ?? \"\")}`, resolve(args.terminal)?.id),\n );\n\n reg(\n \"terminal_run\",\n \"Run a shell command in a terminal — writes the command + Enter (or the host's runner). Pass `terminal` to target a specific one. In pendingMode this stages it for confirmation.\",\n { ...TERMINAL_ARG, command: { type: \"string\", description: \"The command line to run.\" } },\n [\"command\"],\n (args) => stageOrExec(need(args), \"run\", String(args.command)),\n true,\n (args) => target(truncate(String(args.command ?? \"\")), resolve(args.terminal)?.id),\n );\n\n reg(\n \"terminal_confirm\",\n \"Confirm + execute a staged command by id (pendingMode).\",\n { id: { type: \"string\" } },\n [\"id\"],\n async (args) => {\n const id = String(args.id);\n const entry = staged.get(id);\n if (!entry) return errorResult(`No staged command ${id}`);\n const t = resolve(entry.terminalId);\n if (!t) return errorResult(`Terminal '${entry.terminalId}' is gone — cannot run ${id}`);\n staged.delete(id);\n await exec(t, entry.kind, entry.data);\n return textResult(`Confirmed ${id}: ${entry.kind} on ${t.id} ${truncate(entry.data)}`, { ...entry, executed: true });\n },\n true,\n (args) => {\n const e = staged.get(String(args.id));\n return target(`confirm:${String(args.id ?? \"\")}`, e?.terminalId);\n },\n );\n\n reg(\n \"terminal_reject\",\n \"Drop a staged command by id without executing it.\",\n { id: { type: \"string\" } },\n [\"id\"],\n (args) => {\n const id = String(args.id);\n if (!staged.delete(id)) return errorResult(`No staged command ${id}`);\n return textResult(`Rejected ${id}`, { id, rejected: true });\n },\n false,\n );\n\n if (canClear) {\n reg(\n \"terminal_clear\",\n \"Clear a terminal's viewport. Pass `terminal` to target a specific one.\",\n { ...TERMINAL_ARG },\n [],\n (args) => {\n const t = need(args);\n if (!t.clear) return errorResult(`Terminal '${t.id}' can't be cleared.`);\n t.clear();\n return textResult(`cleared ${t.id}`, { terminal: t.id });\n },\n true,\n (args) => target(`clear:${String(args.terminal ?? \"\")}`, resolve(args.terminal)?.id),\n );\n }\n\n // ── Shells ──────────────────────────────────────────────────────────────────\n if (canShells) {\n reg(\n \"terminal_list_shells\",\n \"List the shells a terminal can switch to (cmd, PowerShell, Git Bash, …) — id + label, active one marked. Pass `terminal` to target a specific one.\",\n { ...TERMINAL_ARG },\n [],\n (args) => {\n const t = need(args);\n if (!t.listShells) return errorResult(`Terminal '${t.id}' has no switchable shells.`);\n const shells = t.listShells();\n const active = t.getShell?.();\n const text = shells.length\n ? shells.map((s) => `${s.id === active ? \"* \" : \" \"}${s.id} — ${s.label}`).join(\"\\n\")\n : \"(none)\";\n return textResult(text, { shells, active, terminal: t.id });\n },\n false,\n );\n }\n\n if (canSetShell) {\n reg(\n \"terminal_set_shell\",\n \"Switch a terminal's active shell by id (e.g. 'powershell', 'git-bash'). Call terminal_list_shells first for valid ids. Pass `terminal` to target a specific one.\",\n { ...TERMINAL_ARG, id: { type: \"string\", description: \"Shell id to switch to.\" } },\n [\"id\"],\n async (args) => {\n const t = need(args);\n if (!t.setShell) return errorResult(`Terminal '${t.id}' can't switch shells.`);\n const id = String(args.id);\n const shells = t.listShells?.();\n if (shells && shells.length && !shells.some((s) => s.id === id)) {\n return errorResult(`Unknown shell '${id}' for ${t.id}. Use terminal_list_shells for valid ids.`);\n }\n await t.setShell(id);\n return textResult(`Switched ${t.id} shell to ${id}`, { shell: id, terminal: t.id });\n },\n true,\n (args) => target(`shell:${String(args.id ?? \"\")}`, resolve(args.terminal)?.id),\n );\n }\n\n return {\n id: \"terminal\",\n title: \"Terminal\",\n dispose: () => {\n disposers.forEach((d) => d());\n disposers.length = 0;\n staged.clear();\n },\n confirm: (id: string) => {\n const e = staged.get(id);\n if (e) {\n const t = resolve(e.terminalId);\n staged.delete(id);\n if (t) void exec(t, e.kind, e.data);\n }\n },\n reject: (id: string) => {\n staged.delete(id);\n },\n pending: () => [...staged.values()],\n };\n}\n"]}
|
package/dist/bridges-terminal.js
CHANGED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { ensureUndoToolsRegistered } from './chunk-KJ5AOOV7.js';
|
|
2
|
+
import { wrapToolWithActivity } from './chunk-ULJL53DL.js';
|
|
3
|
+
import { textResult, errorResult } from './chunk-4KAIV6OD.js';
|
|
4
|
+
|
|
5
|
+
// src/bridges/terminal.ts
|
|
6
|
+
var DEFAULT_AGENT = { id: "agent", name: "Agent", color: "#a855f7" };
|
|
7
|
+
var truncate = (s, n = 60) => s.length > n ? s.slice(0, n) + "\u2026" : s;
|
|
8
|
+
function registerTerminalBridge(host, options) {
|
|
9
|
+
const agent = { ...DEFAULT_AGENT, ...options.agent ?? {} };
|
|
10
|
+
const pendingMode = options.pendingMode ?? false;
|
|
11
|
+
const screenId = options.screenId ?? options.adapter?.screenId;
|
|
12
|
+
const disposers = [];
|
|
13
|
+
const staged = /* @__PURE__ */ new Map();
|
|
14
|
+
let seq = 0;
|
|
15
|
+
ensureUndoToolsRegistered(host);
|
|
16
|
+
const listTerminals = () => {
|
|
17
|
+
if (options.terminals) return options.terminals();
|
|
18
|
+
if (options.adapter) return [{ id: "terminal", label: "Terminal", active: true, ...options.adapter }];
|
|
19
|
+
return [];
|
|
20
|
+
};
|
|
21
|
+
const resolve = (id) => {
|
|
22
|
+
const list = listTerminals();
|
|
23
|
+
if (typeof id === "string" && id !== "") return list.find((t) => t.id === id);
|
|
24
|
+
return list.find((t) => t.active) ?? list[0];
|
|
25
|
+
};
|
|
26
|
+
const anyMulti = !!options.terminals;
|
|
27
|
+
const canClear = anyMulti || !!options.adapter?.clear;
|
|
28
|
+
const canShells = anyMulti || !!options.adapter?.listShells;
|
|
29
|
+
const canSetShell = anyMulti || !!options.adapter?.setShell;
|
|
30
|
+
const target = (label, terminalId) => ({
|
|
31
|
+
kind: "terminal",
|
|
32
|
+
screenId,
|
|
33
|
+
elementId: terminalId ?? screenId ?? "terminal",
|
|
34
|
+
label: label ?? "terminal"
|
|
35
|
+
});
|
|
36
|
+
const TERMINAL_ARG = {
|
|
37
|
+
terminal: {
|
|
38
|
+
type: "string",
|
|
39
|
+
description: "Terminal id to target (call terminal_list for ids). Omit for the active / only terminal."
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const reg = (name, description, properties, required, handler, isMutation, resolveTarget) => {
|
|
43
|
+
const wrapped = async (args) => {
|
|
44
|
+
try {
|
|
45
|
+
return await handler(args);
|
|
46
|
+
} catch (e) {
|
|
47
|
+
return errorResult(e instanceof Error ? e.message : String(e));
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const final = isMutation ? wrapToolWithActivity(wrapped, {
|
|
51
|
+
toolName: name,
|
|
52
|
+
agent,
|
|
53
|
+
kind: "terminal",
|
|
54
|
+
screenId,
|
|
55
|
+
resolveTarget: ({ args, result }) => resolveTarget?.(args, result) ?? target()
|
|
56
|
+
}) : wrapped;
|
|
57
|
+
disposers.push(
|
|
58
|
+
host.registerTool(
|
|
59
|
+
{
|
|
60
|
+
name,
|
|
61
|
+
description,
|
|
62
|
+
inputSchema: { type: "object", properties, required, additionalProperties: false }
|
|
63
|
+
},
|
|
64
|
+
final
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
const need = (args) => {
|
|
69
|
+
const t = resolve(args.terminal);
|
|
70
|
+
if (!t) {
|
|
71
|
+
const ids = listTerminals().map((x) => x.id).join(", ") || "(none)";
|
|
72
|
+
throw new Error(
|
|
73
|
+
typeof args.terminal === "string" && args.terminal ? `Unknown terminal '${args.terminal}'. Available: ${ids}. Use terminal_list.` : "No terminal available."
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
return t;
|
|
77
|
+
};
|
|
78
|
+
async function exec(t, kind, data) {
|
|
79
|
+
if (kind === "run") {
|
|
80
|
+
if (t.runCommand) await t.runCommand(data);
|
|
81
|
+
else t.write(data + "\r");
|
|
82
|
+
} else {
|
|
83
|
+
t.write(data);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function stageOrExec(t, kind, data) {
|
|
87
|
+
if (!pendingMode) {
|
|
88
|
+
await exec(t, kind, data);
|
|
89
|
+
return textResult(`${kind === "run" ? "ran" : "wrote"} on ${t.id}: ${truncate(data)}`, {
|
|
90
|
+
kind,
|
|
91
|
+
data,
|
|
92
|
+
terminal: t.id,
|
|
93
|
+
executed: true
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
const id = `t${++seq}`;
|
|
97
|
+
const entry = { id, kind, data, terminalId: t.id };
|
|
98
|
+
staged.set(id, entry);
|
|
99
|
+
options.onPending?.(entry);
|
|
100
|
+
return textResult(
|
|
101
|
+
`Staged ${kind} on ${t.id} (id ${id}) \u2014 awaiting human confirmation: ${truncate(data)}`,
|
|
102
|
+
{ ...entry, pending: true }
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
reg(
|
|
106
|
+
"terminal_list",
|
|
107
|
+
"List the terminals on this screen (id, label, which is active) \u2014 so you can reach into another terminal, not just the active one. Pass the chosen id as `terminal` to the other tools.",
|
|
108
|
+
{},
|
|
109
|
+
[],
|
|
110
|
+
() => {
|
|
111
|
+
const list = listTerminals().map((t) => ({ id: t.id, label: t.label ?? t.id, active: !!t.active }));
|
|
112
|
+
const text = list.length ? list.map((t) => `${t.active ? "* " : " "}${t.id} \u2014 ${t.label}`).join("\n") : "(no terminals)";
|
|
113
|
+
return textResult(text, { terminals: list });
|
|
114
|
+
},
|
|
115
|
+
false
|
|
116
|
+
);
|
|
117
|
+
reg(
|
|
118
|
+
"terminal_read",
|
|
119
|
+
"Read a terminal's visible buffer as text \u2014 what the user sees. Pass `tail` for only the last N lines, `terminal` to read a specific one.",
|
|
120
|
+
{ ...TERMINAL_ARG, tail: { type: "number", description: "Return only the last N lines." } },
|
|
121
|
+
[],
|
|
122
|
+
(args) => {
|
|
123
|
+
const t = need(args);
|
|
124
|
+
let buf = t.getBuffer();
|
|
125
|
+
const tail = typeof args.tail === "number" ? args.tail : void 0;
|
|
126
|
+
if (tail && tail > 0) buf = buf.split("\n").slice(-tail).join("\n");
|
|
127
|
+
return textResult(buf, { buffer: buf, terminal: t.id });
|
|
128
|
+
},
|
|
129
|
+
false
|
|
130
|
+
);
|
|
131
|
+
reg(
|
|
132
|
+
"terminal_pending",
|
|
133
|
+
"List commands staged for human confirmation (pendingMode).",
|
|
134
|
+
{},
|
|
135
|
+
[],
|
|
136
|
+
() => {
|
|
137
|
+
const list = [...staged.values()];
|
|
138
|
+
return textResult(
|
|
139
|
+
list.length ? list.map((s) => `${s.id}: ${s.kind} on ${s.terminalId} ${truncate(s.data)}`).join("\n") : "(none)",
|
|
140
|
+
{ pending: list }
|
|
141
|
+
);
|
|
142
|
+
},
|
|
143
|
+
false
|
|
144
|
+
);
|
|
145
|
+
reg(
|
|
146
|
+
"terminal_write",
|
|
147
|
+
"Write raw data / keystrokes to a terminal (input, control chars, ANSI). Pass `terminal` to target a specific one. In pendingMode this stages instead of executing.",
|
|
148
|
+
{ ...TERMINAL_ARG, data: { type: "string", description: "Raw bytes to write." } },
|
|
149
|
+
["data"],
|
|
150
|
+
(args) => stageOrExec(need(args), "write", String(args.data)),
|
|
151
|
+
true,
|
|
152
|
+
(args) => target(`write:${String(args.terminal ?? "")}`, resolve(args.terminal)?.id)
|
|
153
|
+
);
|
|
154
|
+
reg(
|
|
155
|
+
"terminal_run",
|
|
156
|
+
"Run a shell command in a terminal \u2014 writes the command + Enter (or the host's runner). Pass `terminal` to target a specific one. In pendingMode this stages it for confirmation.",
|
|
157
|
+
{ ...TERMINAL_ARG, command: { type: "string", description: "The command line to run." } },
|
|
158
|
+
["command"],
|
|
159
|
+
(args) => stageOrExec(need(args), "run", String(args.command)),
|
|
160
|
+
true,
|
|
161
|
+
(args) => target(truncate(String(args.command ?? "")), resolve(args.terminal)?.id)
|
|
162
|
+
);
|
|
163
|
+
reg(
|
|
164
|
+
"terminal_confirm",
|
|
165
|
+
"Confirm + execute a staged command by id (pendingMode).",
|
|
166
|
+
{ id: { type: "string" } },
|
|
167
|
+
["id"],
|
|
168
|
+
async (args) => {
|
|
169
|
+
const id = String(args.id);
|
|
170
|
+
const entry = staged.get(id);
|
|
171
|
+
if (!entry) return errorResult(`No staged command ${id}`);
|
|
172
|
+
const t = resolve(entry.terminalId);
|
|
173
|
+
if (!t) return errorResult(`Terminal '${entry.terminalId}' is gone \u2014 cannot run ${id}`);
|
|
174
|
+
staged.delete(id);
|
|
175
|
+
await exec(t, entry.kind, entry.data);
|
|
176
|
+
return textResult(`Confirmed ${id}: ${entry.kind} on ${t.id} ${truncate(entry.data)}`, { ...entry, executed: true });
|
|
177
|
+
},
|
|
178
|
+
true,
|
|
179
|
+
(args) => {
|
|
180
|
+
const e = staged.get(String(args.id));
|
|
181
|
+
return target(`confirm:${String(args.id ?? "")}`, e?.terminalId);
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
reg(
|
|
185
|
+
"terminal_reject",
|
|
186
|
+
"Drop a staged command by id without executing it.",
|
|
187
|
+
{ id: { type: "string" } },
|
|
188
|
+
["id"],
|
|
189
|
+
(args) => {
|
|
190
|
+
const id = String(args.id);
|
|
191
|
+
if (!staged.delete(id)) return errorResult(`No staged command ${id}`);
|
|
192
|
+
return textResult(`Rejected ${id}`, { id, rejected: true });
|
|
193
|
+
},
|
|
194
|
+
false
|
|
195
|
+
);
|
|
196
|
+
if (canClear) {
|
|
197
|
+
reg(
|
|
198
|
+
"terminal_clear",
|
|
199
|
+
"Clear a terminal's viewport. Pass `terminal` to target a specific one.",
|
|
200
|
+
{ ...TERMINAL_ARG },
|
|
201
|
+
[],
|
|
202
|
+
(args) => {
|
|
203
|
+
const t = need(args);
|
|
204
|
+
if (!t.clear) return errorResult(`Terminal '${t.id}' can't be cleared.`);
|
|
205
|
+
t.clear();
|
|
206
|
+
return textResult(`cleared ${t.id}`, { terminal: t.id });
|
|
207
|
+
},
|
|
208
|
+
true,
|
|
209
|
+
(args) => target(`clear:${String(args.terminal ?? "")}`, resolve(args.terminal)?.id)
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
if (canShells) {
|
|
213
|
+
reg(
|
|
214
|
+
"terminal_list_shells",
|
|
215
|
+
"List the shells a terminal can switch to (cmd, PowerShell, Git Bash, \u2026) \u2014 id + label, active one marked. Pass `terminal` to target a specific one.",
|
|
216
|
+
{ ...TERMINAL_ARG },
|
|
217
|
+
[],
|
|
218
|
+
(args) => {
|
|
219
|
+
const t = need(args);
|
|
220
|
+
if (!t.listShells) return errorResult(`Terminal '${t.id}' has no switchable shells.`);
|
|
221
|
+
const shells = t.listShells();
|
|
222
|
+
const active = t.getShell?.();
|
|
223
|
+
const text = shells.length ? shells.map((s) => `${s.id === active ? "* " : " "}${s.id} \u2014 ${s.label}`).join("\n") : "(none)";
|
|
224
|
+
return textResult(text, { shells, active, terminal: t.id });
|
|
225
|
+
},
|
|
226
|
+
false
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
if (canSetShell) {
|
|
230
|
+
reg(
|
|
231
|
+
"terminal_set_shell",
|
|
232
|
+
"Switch a terminal's active shell by id (e.g. 'powershell', 'git-bash'). Call terminal_list_shells first for valid ids. Pass `terminal` to target a specific one.",
|
|
233
|
+
{ ...TERMINAL_ARG, id: { type: "string", description: "Shell id to switch to." } },
|
|
234
|
+
["id"],
|
|
235
|
+
async (args) => {
|
|
236
|
+
const t = need(args);
|
|
237
|
+
if (!t.setShell) return errorResult(`Terminal '${t.id}' can't switch shells.`);
|
|
238
|
+
const id = String(args.id);
|
|
239
|
+
const shells = t.listShells?.();
|
|
240
|
+
if (shells && shells.length && !shells.some((s) => s.id === id)) {
|
|
241
|
+
return errorResult(`Unknown shell '${id}' for ${t.id}. Use terminal_list_shells for valid ids.`);
|
|
242
|
+
}
|
|
243
|
+
await t.setShell(id);
|
|
244
|
+
return textResult(`Switched ${t.id} shell to ${id}`, { shell: id, terminal: t.id });
|
|
245
|
+
},
|
|
246
|
+
true,
|
|
247
|
+
(args) => target(`shell:${String(args.id ?? "")}`, resolve(args.terminal)?.id)
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
return {
|
|
251
|
+
id: "terminal",
|
|
252
|
+
title: "Terminal",
|
|
253
|
+
dispose: () => {
|
|
254
|
+
disposers.forEach((d) => d());
|
|
255
|
+
disposers.length = 0;
|
|
256
|
+
staged.clear();
|
|
257
|
+
},
|
|
258
|
+
confirm: (id) => {
|
|
259
|
+
const e = staged.get(id);
|
|
260
|
+
if (e) {
|
|
261
|
+
const t = resolve(e.terminalId);
|
|
262
|
+
staged.delete(id);
|
|
263
|
+
if (t) void exec(t, e.kind, e.data);
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
reject: (id) => {
|
|
267
|
+
staged.delete(id);
|
|
268
|
+
},
|
|
269
|
+
pending: () => [...staged.values()]
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export { registerTerminalBridge };
|
|
274
|
+
//# sourceMappingURL=chunk-57KAMBAR.js.map
|
|
275
|
+
//# sourceMappingURL=chunk-57KAMBAR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/bridges/terminal.ts"],"names":[],"mappings":";;;;;AA2FA,IAAM,gBAAgB,EAAE,EAAA,EAAI,SAAS,IAAA,EAAM,OAAA,EAAS,OAAO,SAAA,EAAU;AAErE,IAAM,QAAA,GAAW,CAAC,CAAA,EAAW,CAAA,GAAI,EAAA,KAAgB,CAAA,CAAE,MAAA,GAAS,CAAA,GAAI,CAAA,CAAE,KAAA,CAAM,CAAA,EAAG,CAAC,IAAI,QAAA,GAAM,CAAA;AAiB/E,SAAS,sBAAA,CAAuB,MAAgB,OAAA,EAAgD;AACrG,EAAA,MAAM,KAAA,GAAQ,EAAE,GAAG,aAAA,EAAe,GAAI,OAAA,CAAQ,KAAA,IAAS,EAAC,EAAG;AAC3D,EAAA,MAAM,WAAA,GAAc,QAAQ,WAAA,IAAe,KAAA;AAC3C,EAAA,MAAM,QAAA,GAAW,OAAA,CAAQ,QAAA,IAAY,OAAA,CAAQ,OAAA,EAAS,QAAA;AACtD,EAAA,MAAM,YAA+B,EAAC;AACtC,EAAA,MAAM,MAAA,uBAAa,GAAA,EAAoB;AACvC,EAAA,IAAI,GAAA,GAAM,CAAA;AAGV,EAAA,yBAAA,CAA0B,IAAI,CAAA;AAI9B,EAAA,MAAM,gBAAgB,MAAqB;AACzC,IAAA,IAAI,OAAA,CAAQ,SAAA,EAAW,OAAO,OAAA,CAAQ,SAAA,EAAU;AAChD,IAAA,IAAI,OAAA,CAAQ,OAAA,EAAS,OAAO,CAAC,EAAE,EAAA,EAAI,UAAA,EAAY,KAAA,EAAO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,CAAE,IAAI,CAAA;AAAA,MACpF,CAAA;AAAA,MACA,IAAA;AAAA,MACA,CAAC,IAAA,KAAS,MAAA,CAAO,CAAA,MAAA,EAAS,OAAO,IAAA,CAAK,EAAA,IAAM,EAAE,CAAC,CAAA,CAAA,EAAI,OAAA,CAAQ,IAAA,CAAK,QAAQ,GAAG,EAAE;AAAA,KAC/E;AAAA,EACF;AAEA,EAAA,OAAO;AAAA,IACL,EAAA,EAAI,UAAA;AAAA,IACJ,KAAA,EAAO,UAAA;AAAA,IACP,SAAS,MAAM;AACb,MAAA,SAAA,CAAU,OAAA,CAAQ,CAAC,CAAA,KAAM,CAAA,EAAG,CAAA;AAC5B,MAAA,SAAA,CAAU,MAAA,GAAS,CAAA;AACnB,MAAA,MAAA,CAAO,KAAA,EAAM;AAAA,IACf,CAAA;AAAA,IACA,OAAA,EAAS,CAAC,EAAA,KAAe;AACvB,MAAA,MAAM,CAAA,GAAI,MAAA,CAAO,GAAA,CAAI,EAAE,CAAA;AACvB,MAAA,IAAI,CAAA,EAAG;AACL,QAAA,MAAM,CAAA,GAAI,OAAA,CAAQ,CAAA,CAAE,UAAU,CAAA;AAC9B,QAAA,MAAA,CAAO,OAAO,EAAE,CAAA;AAChB,QAAA,IAAI,GAAG,KAAK,IAAA,CAAK,GAAG,CAAA,CAAE,IAAA,EAAM,EAAE,IAAI,CAAA;AAAA,MACpC;AAAA,IACF,CAAA;AAAA,IACA,MAAA,EAAQ,CAAC,EAAA,KAAe;AACtB,MAAA,MAAA,CAAO,OAAO,EAAE,CAAA;AAAA,IAClB,CAAA;AAAA,IACA,SAAS,MAAM,CAAC,GAAG,MAAA,CAAO,QAAQ;AAAA,GACpC;AACF","file":"chunk-57KAMBAR.js","sourcesContent":["import { textResult, errorResult } from \"../mcp/server\";\nimport type { ToolHost } from \"../mcp/tool-host\";\nimport type { JsonObject } from \"../mcp/types\";\nimport type { Bridge } from \"./types\";\nimport { wrapToolWithActivity } from \"../presence/wrap-tool-with-activity\";\nimport { ensureUndoToolsRegistered } from \"../undo/undo-tools\";\nimport type { AgentTarget } from \"../presence/types\";\n\n/**\n * A shell/profile an agent can switch a terminal to. Mirrors fancy-term's\n * `ShellProfile` (kept local so the bridge never imports fancy-term).\n */\nexport type TerminalShell = { id: string; label: string; icon?: string };\n\n/**\n * One terminal the bridge can drive. A Human+ app often hosts **several**\n * terminals on a screen (a build pane, a server pane, an agent scratch shell);\n * each is a `TerminalRef` with a stable `id` so an agent can read/write any of\n * them — not just \"its own\". Wire the function fields to that terminal's\n * fancy-term `TerminalHandle`.\n */\nexport type TerminalRef = {\n /** Stable id used to address this terminal (`terminal_list` enumerates them). */\n id: string;\n /** Human label, e.g. \"Build\", \"Server\". Defaults to the id. */\n label?: string;\n /** True for the focused terminal — the default target when no id is passed. */\n active?: boolean;\n /** Read the visible buffer as text (wire to `TerminalHandle.getBuffer`). */\n getBuffer: () => string;\n /** Write raw data / keystrokes (wire to `TerminalHandle.write`). */\n write: (data: string) => void;\n /** Run a command. Defaults to writing `${command}\\r`; override for a real runner. */\n runCommand?: (command: string) => void | Promise<void>;\n /** Clear the viewport (wire to `TerminalHandle.clear`). */\n clear?: () => void;\n /** Current text selection (wire to `TerminalHandle.getSelection`). */\n getSelection?: () => string;\n /** Shells this terminal offers (cmd, PowerShell, …). */\n listShells?: () => TerminalShell[];\n /** Switch this terminal's active shell by id. */\n setShell?: (id: string) => void | Promise<void>;\n /** This terminal's active shell id. */\n getShell?: () => string | undefined;\n};\n\n/**\n * Single-terminal adapter (back-compat). A `TerminalRef` without the\n * `id`/`label`/`active` bookkeeping — pass it as `{ adapter }` and the bridge\n * treats it as the one (active) terminal. Use `{ terminals }` for multiple.\n */\nexport type TerminalBridgeAdapter = Omit<TerminalRef, \"id\" | \"label\" | \"active\"> & {\n /** fancy-screens screen id (optional) so activity events know which screen the terminal lives in. */\n screenId?: string;\n};\n\ntype StagedKind = \"write\" | \"run\";\ntype Staged = { id: string; kind: StagedKind; data: string; terminalId: string };\n\nexport type TerminalBridgeOptions = {\n /** A single terminal (back-compat). Mutually exclusive with `terminals`. */\n adapter?: TerminalBridgeAdapter;\n /**\n * The live list of terminals on the screen. Use this when the app hosts more\n * than one terminal so an agent can `terminal_list` then target any of them by\n * id — i.e. reach into another terminal in the same screen.\n */\n terminals?: () => TerminalRef[];\n /** fancy-screens screen id for activity events (defaults to `adapter.screenId`). */\n screenId?: string;\n agent?: { id: string; name?: string; color?: string };\n /**\n * Trust-but-verify (Human+ contract for inhabited surfaces). When on,\n * `terminal_write` + `terminal_run` don't execute — they **stage** the command\n * (returning a pending id) and fire `onPending`. A human confirms via the\n * `terminal_confirm` tool or the returned bridge's `confirm(id)`. Default off.\n */\n pendingMode?: boolean;\n /** Notified when a command is staged (pendingMode) — show it + offer confirm / reject. */\n onPending?: (pending: Staged) => void;\n};\n\nexport type TerminalBridge = Bridge & {\n /** Execute a staged command by id — wire a host confirm button to this. No-op if not pending. */\n confirm: (id: string) => void;\n /** Drop a staged command by id without executing. */\n reject: (id: string) => void;\n /** Commands currently awaiting confirmation. */\n pending: () => Staged[];\n};\n\nconst DEFAULT_AGENT = { id: \"agent\", name: \"Agent\", color: \"#a855f7\" };\n\nconst truncate = (s: string, n = 60): string => (s.length > n ? s.slice(0, n) + \"…\" : s);\n\n/**\n * registerTerminalBridge — MCP access to one **or many** terminal surfaces on a\n * screen. An agent reads the visible buffer (`terminal_read`), writes input\n * (`terminal_write`), and runs commands (`terminal_run`) through the host; every\n * mutation broadcasts an `AgentActivity` event. With `pendingMode`, destructive\n * actions are staged for human confirmation (`terminal_confirm` / `terminal_reject`\n * / `terminal_pending`).\n *\n * **Multi-terminal:** pass `{ terminals }` (vs a single `{ adapter }`) and every\n * tool takes an optional `terminal` id; `terminal_list` enumerates them. This is\n * how an agent **reaches into another terminal in the same screen** rather than\n * being stuck in one. When a terminal offers shells, the agent can also list\n * (`terminal_list_shells`) and switch (`terminal_set_shell`) its shell. Tool\n * prefix `terminal_*`.\n */\nexport function registerTerminalBridge(host: ToolHost, options: TerminalBridgeOptions): TerminalBridge {\n const agent = { ...DEFAULT_AGENT, ...(options.agent ?? {}) };\n const pendingMode = options.pendingMode ?? false;\n const screenId = options.screenId ?? options.adapter?.screenId;\n const disposers: Array<() => void> = [];\n const staged = new Map<string, Staged>();\n let seq = 0;\n\n // Enables agent_history (a log of what agents did across every bridge).\n ensureUndoToolsRegistered(host);\n\n // The live terminal list — from `terminals()` (multi) or the single `adapter`\n // normalized to one active ref with the id \"terminal\".\n const listTerminals = (): TerminalRef[] => {\n if (options.terminals) return options.terminals();\n if (options.adapter) return [{ id: \"terminal\", label: \"Terminal\", active: true, ...options.adapter }];\n return [];\n };\n\n /** Resolve a terminal by id; with no id, the active one, else the first. */\n const resolve = (id?: unknown): TerminalRef | undefined => {\n const list = listTerminals();\n if (typeof id === \"string\" && id !== \"\") return list.find((t) => t.id === id);\n return list.find((t) => t.active) ?? list[0];\n };\n\n // Whether any host config can offer these capabilities (gates tool registration;\n // per-call we still check the *resolved* terminal supports it).\n const anyMulti = !!options.terminals;\n const canClear = anyMulti || !!options.adapter?.clear;\n const canShells = anyMulti || !!options.adapter?.listShells;\n const canSetShell = anyMulti || !!options.adapter?.setShell;\n\n const target = (label?: string, terminalId?: string): AgentTarget => ({\n kind: \"terminal\",\n screenId,\n elementId: terminalId ?? screenId ?? \"terminal\",\n label: label ?? \"terminal\",\n });\n\n const TERMINAL_ARG = {\n terminal: {\n type: \"string\",\n description: \"Terminal id to target (call terminal_list for ids). Omit for the active / only terminal.\",\n },\n };\n\n const reg = (\n name: string,\n description: string,\n properties: Record<string, unknown>,\n required: string[],\n handler: (args: JsonObject) => Promise<any> | any,\n isMutation: boolean,\n resolveTarget?: (args: JsonObject, result: any) => AgentTarget | null,\n ) => {\n const wrapped = async (args: JsonObject) => {\n try {\n return await handler(args);\n } catch (e) {\n return errorResult(e instanceof Error ? e.message : String(e));\n }\n };\n const final = isMutation\n ? wrapToolWithActivity(wrapped, {\n toolName: name,\n agent,\n kind: \"terminal\",\n screenId,\n resolveTarget: ({ args, result }) => resolveTarget?.(args, result) ?? target(),\n })\n : wrapped;\n disposers.push(\n host.registerTool(\n {\n name,\n description,\n inputSchema: { type: \"object\", properties: properties as any, required, additionalProperties: false },\n },\n final as any,\n ),\n );\n };\n\n /** Resolve the targeted terminal or throw a clear error for the agent. */\n const need = (args: JsonObject): TerminalRef => {\n const t = resolve(args.terminal);\n if (!t) {\n const ids = listTerminals().map((x) => x.id).join(\", \") || \"(none)\";\n throw new Error(\n typeof args.terminal === \"string\" && args.terminal\n ? `Unknown terminal '${args.terminal}'. Available: ${ids}. Use terminal_list.`\n : \"No terminal available.\",\n );\n }\n return t;\n };\n\n async function exec(t: TerminalRef, kind: StagedKind, data: string): Promise<void> {\n if (kind === \"run\") {\n if (t.runCommand) await t.runCommand(data);\n else t.write(data + \"\\r\");\n } else {\n t.write(data);\n }\n }\n\n async function stageOrExec(t: TerminalRef, kind: StagedKind, data: string) {\n if (!pendingMode) {\n await exec(t, kind, data);\n return textResult(`${kind === \"run\" ? \"ran\" : \"wrote\"} on ${t.id}: ${truncate(data)}`, {\n kind,\n data,\n terminal: t.id,\n executed: true,\n });\n }\n const id = `t${++seq}`;\n const entry: Staged = { id, kind, data, terminalId: t.id };\n staged.set(id, entry);\n options.onPending?.(entry);\n return textResult(\n `Staged ${kind} on ${t.id} (id ${id}) — awaiting human confirmation: ${truncate(data)}`,\n { ...entry, pending: true },\n );\n }\n\n // ── List ──────────────────────────────────────────────────────────────────\n reg(\n \"terminal_list\",\n \"List the terminals on this screen (id, label, which is active) — so you can reach into another terminal, not just the active one. Pass the chosen id as `terminal` to the other tools.\",\n {},\n [],\n () => {\n const list = listTerminals().map((t) => ({ id: t.id, label: t.label ?? t.id, active: !!t.active }));\n const text = list.length\n ? list.map((t) => `${t.active ? \"* \" : \" \"}${t.id} — ${t.label}`).join(\"\\n\")\n : \"(no terminals)\";\n return textResult(text, { terminals: list });\n },\n false,\n );\n\n // ── Read ──────────────────────────────────────────────────────────────────\n reg(\n \"terminal_read\",\n \"Read a terminal's visible buffer as text — what the user sees. Pass `tail` for only the last N lines, `terminal` to read a specific one.\",\n { ...TERMINAL_ARG, tail: { type: \"number\", description: \"Return only the last N lines.\" } },\n [],\n (args) => {\n const t = need(args);\n let buf = t.getBuffer();\n const tail = typeof args.tail === \"number\" ? args.tail : undefined;\n if (tail && tail > 0) buf = buf.split(\"\\n\").slice(-tail).join(\"\\n\");\n return textResult(buf, { buffer: buf, terminal: t.id });\n },\n false,\n );\n\n reg(\n \"terminal_pending\",\n \"List commands staged for human confirmation (pendingMode).\",\n {},\n [],\n () => {\n const list = [...staged.values()];\n return textResult(\n list.length ? list.map((s) => `${s.id}: ${s.kind} on ${s.terminalId} ${truncate(s.data)}`).join(\"\\n\") : \"(none)\",\n { pending: list },\n );\n },\n false,\n );\n\n // ── Mutations ───────────────────────────────────────────────────────────────\n reg(\n \"terminal_write\",\n \"Write raw data / keystrokes to a terminal (input, control chars, ANSI). Pass `terminal` to target a specific one. In pendingMode this stages instead of executing.\",\n { ...TERMINAL_ARG, data: { type: \"string\", description: \"Raw bytes to write.\" } },\n [\"data\"],\n (args) => stageOrExec(need(args), \"write\", String(args.data)),\n true,\n (args) => target(`write:${String(args.terminal ?? \"\")}`, resolve(args.terminal)?.id),\n );\n\n reg(\n \"terminal_run\",\n \"Run a shell command in a terminal — writes the command + Enter (or the host's runner). Pass `terminal` to target a specific one. In pendingMode this stages it for confirmation.\",\n { ...TERMINAL_ARG, command: { type: \"string\", description: \"The command line to run.\" } },\n [\"command\"],\n (args) => stageOrExec(need(args), \"run\", String(args.command)),\n true,\n (args) => target(truncate(String(args.command ?? \"\")), resolve(args.terminal)?.id),\n );\n\n reg(\n \"terminal_confirm\",\n \"Confirm + execute a staged command by id (pendingMode).\",\n { id: { type: \"string\" } },\n [\"id\"],\n async (args) => {\n const id = String(args.id);\n const entry = staged.get(id);\n if (!entry) return errorResult(`No staged command ${id}`);\n const t = resolve(entry.terminalId);\n if (!t) return errorResult(`Terminal '${entry.terminalId}' is gone — cannot run ${id}`);\n staged.delete(id);\n await exec(t, entry.kind, entry.data);\n return textResult(`Confirmed ${id}: ${entry.kind} on ${t.id} ${truncate(entry.data)}`, { ...entry, executed: true });\n },\n true,\n (args) => {\n const e = staged.get(String(args.id));\n return target(`confirm:${String(args.id ?? \"\")}`, e?.terminalId);\n },\n );\n\n reg(\n \"terminal_reject\",\n \"Drop a staged command by id without executing it.\",\n { id: { type: \"string\" } },\n [\"id\"],\n (args) => {\n const id = String(args.id);\n if (!staged.delete(id)) return errorResult(`No staged command ${id}`);\n return textResult(`Rejected ${id}`, { id, rejected: true });\n },\n false,\n );\n\n if (canClear) {\n reg(\n \"terminal_clear\",\n \"Clear a terminal's viewport. Pass `terminal` to target a specific one.\",\n { ...TERMINAL_ARG },\n [],\n (args) => {\n const t = need(args);\n if (!t.clear) return errorResult(`Terminal '${t.id}' can't be cleared.`);\n t.clear();\n return textResult(`cleared ${t.id}`, { terminal: t.id });\n },\n true,\n (args) => target(`clear:${String(args.terminal ?? \"\")}`, resolve(args.terminal)?.id),\n );\n }\n\n // ── Shells ──────────────────────────────────────────────────────────────────\n if (canShells) {\n reg(\n \"terminal_list_shells\",\n \"List the shells a terminal can switch to (cmd, PowerShell, Git Bash, …) — id + label, active one marked. Pass `terminal` to target a specific one.\",\n { ...TERMINAL_ARG },\n [],\n (args) => {\n const t = need(args);\n if (!t.listShells) return errorResult(`Terminal '${t.id}' has no switchable shells.`);\n const shells = t.listShells();\n const active = t.getShell?.();\n const text = shells.length\n ? shells.map((s) => `${s.id === active ? \"* \" : \" \"}${s.id} — ${s.label}`).join(\"\\n\")\n : \"(none)\";\n return textResult(text, { shells, active, terminal: t.id });\n },\n false,\n );\n }\n\n if (canSetShell) {\n reg(\n \"terminal_set_shell\",\n \"Switch a terminal's active shell by id (e.g. 'powershell', 'git-bash'). Call terminal_list_shells first for valid ids. Pass `terminal` to target a specific one.\",\n { ...TERMINAL_ARG, id: { type: \"string\", description: \"Shell id to switch to.\" } },\n [\"id\"],\n async (args) => {\n const t = need(args);\n if (!t.setShell) return errorResult(`Terminal '${t.id}' can't switch shells.`);\n const id = String(args.id);\n const shells = t.listShells?.();\n if (shells && shells.length && !shells.some((s) => s.id === id)) {\n return errorResult(`Unknown shell '${id}' for ${t.id}. Use terminal_list_shells for valid ids.`);\n }\n await t.setShell(id);\n return textResult(`Switched ${t.id} shell to ${id}`, { shell: id, terminal: t.id });\n },\n true,\n (args) => target(`shell:${String(args.id ?? \"\")}`, resolve(args.terminal)?.id),\n );\n }\n\n return {\n id: \"terminal\",\n title: \"Terminal\",\n dispose: () => {\n disposers.forEach((d) => d());\n disposers.length = 0;\n staged.clear();\n },\n confirm: (id: string) => {\n const e = staged.get(id);\n if (e) {\n const t = resolve(e.terminalId);\n staged.delete(id);\n if (t) void exec(t, e.kind, e.data);\n }\n },\n reject: (id: string) => {\n staged.delete(id);\n },\n pending: () => [...staged.values()],\n };\n}\n"]}
|