pi-ui-extend 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +307 -0
- package/bin/pix.mjs +219 -0
- package/dist/app/app.d.ts +96 -0
- package/dist/app/app.js +871 -0
- package/dist/app/blink-controller.d.ts +23 -0
- package/dist/app/blink-controller.js +82 -0
- package/dist/app/cli.d.ts +8 -0
- package/dist/app/cli.js +83 -0
- package/dist/app/clipboard.d.ts +1 -0
- package/dist/app/clipboard.js +24 -0
- package/dist/app/command-controller.d.ts +18 -0
- package/dist/app/command-controller.js +58 -0
- package/dist/app/command-host.d.ts +44 -0
- package/dist/app/command-host.js +1 -0
- package/dist/app/command-model-actions.d.ts +12 -0
- package/dist/app/command-model-actions.js +176 -0
- package/dist/app/command-navigation-actions.d.ts +19 -0
- package/dist/app/command-navigation-actions.js +267 -0
- package/dist/app/command-registry.d.ts +32 -0
- package/dist/app/command-registry.js +225 -0
- package/dist/app/command-runtime.d.ts +5 -0
- package/dist/app/command-runtime.js +32 -0
- package/dist/app/command-session-actions.d.ts +20 -0
- package/dist/app/command-session-actions.js +295 -0
- package/dist/app/constants.d.ts +52 -0
- package/dist/app/constants.js +103 -0
- package/dist/app/conversation-entry-renderer.d.ts +21 -0
- package/dist/app/conversation-entry-renderer.js +81 -0
- package/dist/app/conversation-shell-renderer.d.ts +5 -0
- package/dist/app/conversation-shell-renderer.js +43 -0
- package/dist/app/conversation-tool-renderer.d.ts +16 -0
- package/dist/app/conversation-tool-renderer.js +216 -0
- package/dist/app/conversation-viewport.d.ts +55 -0
- package/dist/app/conversation-viewport.js +252 -0
- package/dist/app/dcp-stats.d.ts +2 -0
- package/dist/app/dcp-stats.js +116 -0
- package/dist/app/editor-layout-renderer.d.ts +31 -0
- package/dist/app/editor-layout-renderer.js +211 -0
- package/dist/app/editor-panels.d.ts +4 -0
- package/dist/app/editor-panels.js +130 -0
- package/dist/app/extension-actions-controller.d.ts +22 -0
- package/dist/app/extension-actions-controller.js +60 -0
- package/dist/app/extension-event-bus.d.ts +3 -0
- package/dist/app/extension-event-bus.js +23 -0
- package/dist/app/extension-ui-controller.d.ts +57 -0
- package/dist/app/extension-ui-controller.js +532 -0
- package/dist/app/file-link-opener.d.ts +2 -0
- package/dist/app/file-link-opener.js +66 -0
- package/dist/app/file-links.d.ts +10 -0
- package/dist/app/file-links.js +117 -0
- package/dist/app/guards.d.ts +3 -0
- package/dist/app/guards.js +9 -0
- package/dist/app/icons.d.ts +37 -0
- package/dist/app/icons.js +97 -0
- package/dist/app/id.d.ts +1 -0
- package/dist/app/id.js +4 -0
- package/dist/app/image-click-targets.d.ts +5 -0
- package/dist/app/image-click-targets.js +32 -0
- package/dist/app/image-opener.d.ts +2 -0
- package/dist/app/image-opener.js +64 -0
- package/dist/app/input-action-controller.d.ts +47 -0
- package/dist/app/input-action-controller.js +209 -0
- package/dist/app/input-controller.d.ts +60 -0
- package/dist/app/input-controller.js +425 -0
- package/dist/app/input-paste-handler.d.ts +27 -0
- package/dist/app/input-paste-handler.js +146 -0
- package/dist/app/menu-items-controller.d.ts +32 -0
- package/dist/app/menu-items-controller.js +182 -0
- package/dist/app/message-content.d.ts +8 -0
- package/dist/app/message-content.js +115 -0
- package/dist/app/model-ref.d.ts +13 -0
- package/dist/app/model-ref.js +50 -0
- package/dist/app/model-usage-controller.d.ts +35 -0
- package/dist/app/model-usage-controller.js +99 -0
- package/dist/app/model-usage-status.d.ts +125 -0
- package/dist/app/model-usage-status.js +749 -0
- package/dist/app/mouse-controller.d.ts +182 -0
- package/dist/app/mouse-controller.js +968 -0
- package/dist/app/native-modifiers.d.ts +3 -0
- package/dist/app/native-modifiers.js +60 -0
- package/dist/app/nerd-font-controller.d.ts +11 -0
- package/dist/app/nerd-font-controller.js +90 -0
- package/dist/app/popup-action-controller.d.ts +44 -0
- package/dist/app/popup-action-controller.js +278 -0
- package/dist/app/popup-menu-controller.d.ts +183 -0
- package/dist/app/popup-menu-controller.js +1070 -0
- package/dist/app/prompt-enhancer-controller.d.ts +40 -0
- package/dist/app/prompt-enhancer-controller.js +215 -0
- package/dist/app/queued-message-controller.d.ts +62 -0
- package/dist/app/queued-message-controller.js +377 -0
- package/dist/app/render-controller.d.ts +41 -0
- package/dist/app/render-controller.js +378 -0
- package/dist/app/render-text.d.ts +19 -0
- package/dist/app/render-text.js +67 -0
- package/dist/app/request-history.d.ts +23 -0
- package/dist/app/request-history.js +131 -0
- package/dist/app/runtime.d.ts +39 -0
- package/dist/app/runtime.js +195 -0
- package/dist/app/screen-selection.d.ts +6 -0
- package/dist/app/screen-selection.js +9 -0
- package/dist/app/screen-styler.d.ts +34 -0
- package/dist/app/screen-styler.js +168 -0
- package/dist/app/scroll-controller.d.ts +51 -0
- package/dist/app/scroll-controller.js +207 -0
- package/dist/app/session-event-controller.d.ts +69 -0
- package/dist/app/session-event-controller.js +338 -0
- package/dist/app/session-history.d.ts +23 -0
- package/dist/app/session-history.js +164 -0
- package/dist/app/session-lifecycle-controller.d.ts +55 -0
- package/dist/app/session-lifecycle-controller.js +116 -0
- package/dist/app/session-search.d.ts +24 -0
- package/dist/app/session-search.js +215 -0
- package/dist/app/shell-command.d.ts +27 -0
- package/dist/app/shell-command.js +176 -0
- package/dist/app/shell-controller.d.ts +28 -0
- package/dist/app/shell-controller.js +124 -0
- package/dist/app/slash-commands.d.ts +6 -0
- package/dist/app/slash-commands.js +75 -0
- package/dist/app/startup-checks.d.ts +8 -0
- package/dist/app/startup-checks.js +59 -0
- package/dist/app/startup-info.d.ts +3 -0
- package/dist/app/startup-info.js +176 -0
- package/dist/app/status-controller.d.ts +35 -0
- package/dist/app/status-controller.js +105 -0
- package/dist/app/status-line-renderer.d.ts +68 -0
- package/dist/app/status-line-renderer.js +453 -0
- package/dist/app/subagents-files.d.ts +10 -0
- package/dist/app/subagents-files.js +193 -0
- package/dist/app/subagents-model.d.ts +23 -0
- package/dist/app/subagents-model.js +224 -0
- package/dist/app/subagents-widget-controller.d.ts +43 -0
- package/dist/app/subagents-widget-controller.js +311 -0
- package/dist/app/tab-line-renderer.d.ts +26 -0
- package/dist/app/tab-line-renderer.js +222 -0
- package/dist/app/tabs-controller.d.ts +100 -0
- package/dist/app/tabs-controller.js +885 -0
- package/dist/app/terminal-controller.d.ts +40 -0
- package/dist/app/terminal-controller.js +135 -0
- package/dist/app/terminal-edit-shortcuts.d.ts +23 -0
- package/dist/app/terminal-edit-shortcuts.js +138 -0
- package/dist/app/terminal-output-buffer.d.ts +20 -0
- package/dist/app/terminal-output-buffer.js +52 -0
- package/dist/app/toast-controller.d.ts +13 -0
- package/dist/app/toast-controller.js +40 -0
- package/dist/app/toast-renderer.d.ts +9 -0
- package/dist/app/toast-renderer.js +79 -0
- package/dist/app/todo-model.d.ts +22 -0
- package/dist/app/todo-model.js +179 -0
- package/dist/app/todo-widget-controller.d.ts +21 -0
- package/dist/app/todo-widget-controller.js +59 -0
- package/dist/app/tool-block-renderer.d.ts +26 -0
- package/dist/app/tool-block-renderer.js +439 -0
- package/dist/app/types.d.ts +550 -0
- package/dist/app/types.js +1 -0
- package/dist/app/update.d.ts +36 -0
- package/dist/app/update.js +315 -0
- package/dist/app/voice-controller.d.ts +52 -0
- package/dist/app/voice-controller.js +600 -0
- package/dist/app/workspace-actions-controller.d.ts +40 -0
- package/dist/app/workspace-actions-controller.js +215 -0
- package/dist/app/workspace-undo.d.ts +44 -0
- package/dist/app/workspace-undo.js +215 -0
- package/dist/config.d.ts +62 -0
- package/dist/config.js +527 -0
- package/dist/context-progress-bar.d.ts +17 -0
- package/dist/context-progress-bar.js +48 -0
- package/dist/default-pix-config.d.ts +1 -0
- package/dist/default-pix-config.js +375 -0
- package/dist/fuzzy.d.ts +23 -0
- package/dist/fuzzy.js +165 -0
- package/dist/input-editor-files.d.ts +15 -0
- package/dist/input-editor-files.js +62 -0
- package/dist/input-editor.d.ts +186 -0
- package/dist/input-editor.js +835 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +12 -0
- package/dist/markdown-format.d.ts +22 -0
- package/dist/markdown-format.js +542 -0
- package/dist/sdk.d.ts +3 -0
- package/dist/sdk.js +1 -0
- package/dist/syntax-highlight.d.ts +22 -0
- package/dist/syntax-highlight.js +528 -0
- package/dist/terminal-width.d.ts +6 -0
- package/dist/terminal-width.js +245 -0
- package/dist/theme.d.ts +56 -0
- package/dist/theme.js +118 -0
- package/dist/tool-renderers/apply-patch.d.ts +2 -0
- package/dist/tool-renderers/apply-patch.js +36 -0
- package/dist/tool-renderers/ast.d.ts +2 -0
- package/dist/tool-renderers/ast.js +5 -0
- package/dist/tool-renderers/compress.d.ts +2 -0
- package/dist/tool-renderers/compress.js +126 -0
- package/dist/tool-renderers/index.d.ts +3 -0
- package/dist/tool-renderers/index.js +44 -0
- package/dist/tool-renderers/question.d.ts +2 -0
- package/dist/tool-renderers/question.js +88 -0
- package/dist/tool-renderers/read.d.ts +2 -0
- package/dist/tool-renderers/read.js +36 -0
- package/dist/tool-renderers/repo.d.ts +2 -0
- package/dist/tool-renderers/repo.js +13 -0
- package/dist/tool-renderers/shell.d.ts +3 -0
- package/dist/tool-renderers/shell.js +27 -0
- package/dist/tool-renderers/skill.d.ts +2 -0
- package/dist/tool-renderers/skill.js +132 -0
- package/dist/tool-renderers/subagents.d.ts +2 -0
- package/dist/tool-renderers/subagents.js +51 -0
- package/dist/tool-renderers/todo.d.ts +2 -0
- package/dist/tool-renderers/todo.js +9 -0
- package/dist/tool-renderers/types.d.ts +42 -0
- package/dist/tool-renderers/types.js +1 -0
- package/dist/tool-renderers/utils.d.ts +31 -0
- package/dist/tool-renderers/utils.js +230 -0
- package/dist/tool-renderers/web.d.ts +3 -0
- package/dist/tool-renderers/web.js +9 -0
- package/dist/tool-renderers/write.d.ts +2 -0
- package/dist/tool-renderers/write.js +42 -0
- package/dist/ui.d.ts +56 -0
- package/dist/ui.js +94 -0
- package/docs/release.md +81 -0
- package/extensions/question/contract.ts +100 -0
- package/extensions/question/index.ts +34 -0
- package/extensions/question/render.ts +28 -0
- package/extensions/question/result.ts +86 -0
- package/extensions/question/tool-description.ts +11 -0
- package/extensions/question/tui.ts +629 -0
- package/extensions/question/types.ts +123 -0
- package/extensions/session-title/config.ts +169 -0
- package/extensions/session-title/index.ts +459 -0
- package/extensions/terminal-bell/index.ts +315 -0
- package/external/pi-tools-suite/README.md +242 -0
- package/external/pi-tools-suite/index.ts +1 -0
- package/external/pi-tools-suite/licenses/ollama-pi-web-search.MIT +21 -0
- package/external/pi-tools-suite/licenses/opencode-mystatus-MIT.txt +21 -0
- package/external/pi-tools-suite/package.json +53 -0
- package/external/pi-tools-suite/src/antigravity-auth/auth-store.ts +194 -0
- package/external/pi-tools-suite/src/antigravity-auth/commands.ts +80 -0
- package/external/pi-tools-suite/src/antigravity-auth/constants.ts +26 -0
- package/external/pi-tools-suite/src/antigravity-auth/headers.ts +20 -0
- package/external/pi-tools-suite/src/antigravity-auth/index.ts +104 -0
- package/external/pi-tools-suite/src/antigravity-auth/models.ts +86 -0
- package/external/pi-tools-suite/src/antigravity-auth/oauth.ts +305 -0
- package/external/pi-tools-suite/src/antigravity-auth/payload.ts +423 -0
- package/external/pi-tools-suite/src/antigravity-auth/status.ts +78 -0
- package/external/pi-tools-suite/src/antigravity-auth/stream.ts +302 -0
- package/external/pi-tools-suite/src/antigravity-auth/types.ts +113 -0
- package/external/pi-tools-suite/src/ast-grep/index.ts +6 -0
- package/external/pi-tools-suite/src/ast-grep/render.ts +70 -0
- package/external/pi-tools-suite/src/ast-grep/schema.ts +109 -0
- package/external/pi-tools-suite/src/ast-grep/tool.ts +345 -0
- package/external/pi-tools-suite/src/ast-grep/types.ts +55 -0
- package/external/pi-tools-suite/src/ast-grep/utils.ts +65 -0
- package/external/pi-tools-suite/src/async-subagents/async-subagents.sample.jsonc +222 -0
- package/external/pi-tools-suite/src/async-subagents/commands.ts +518 -0
- package/external/pi-tools-suite/src/async-subagents/constants.ts +11 -0
- package/external/pi-tools-suite/src/async-subagents/core/agent-strategy.ts +74 -0
- package/external/pi-tools-suite/src/async-subagents/core/attachment-bridge.ts +133 -0
- package/external/pi-tools-suite/src/async-subagents/core/cleanup.ts +66 -0
- package/external/pi-tools-suite/src/async-subagents/core/concurrency.ts +90 -0
- package/external/pi-tools-suite/src/async-subagents/core/config.ts +819 -0
- package/external/pi-tools-suite/src/async-subagents/core/log-limits.ts +166 -0
- package/external/pi-tools-suite/src/async-subagents/core/model-fallback.ts +133 -0
- package/external/pi-tools-suite/src/async-subagents/core/paths.ts +47 -0
- package/external/pi-tools-suite/src/async-subagents/core/pi-invocation.ts +35 -0
- package/external/pi-tools-suite/src/async-subagents/core/presets.ts +67 -0
- package/external/pi-tools-suite/src/async-subagents/core/process.ts +15 -0
- package/external/pi-tools-suite/src/async-subagents/core/prompt.ts +66 -0
- package/external/pi-tools-suite/src/async-subagents/core/registry.ts +224 -0
- package/external/pi-tools-suite/src/async-subagents/core/retry.ts +191 -0
- package/external/pi-tools-suite/src/async-subagents/core/routing.ts +259 -0
- package/external/pi-tools-suite/src/async-subagents/core/sessions.ts +138 -0
- package/external/pi-tools-suite/src/async-subagents/core/spawn.ts +688 -0
- package/external/pi-tools-suite/src/async-subagents/core/state.ts +281 -0
- package/external/pi-tools-suite/src/async-subagents/core/stop.ts +131 -0
- package/external/pi-tools-suite/src/async-subagents/core/structured-result.ts +237 -0
- package/external/pi-tools-suite/src/async-subagents/core/tool-guard.ts +34 -0
- package/external/pi-tools-suite/src/async-subagents/core/types.ts +150 -0
- package/external/pi-tools-suite/src/async-subagents/core/ultrawork-auto.ts +184 -0
- package/external/pi-tools-suite/src/async-subagents/core/utils.ts +11 -0
- package/external/pi-tools-suite/src/async-subagents/format.ts +41 -0
- package/external/pi-tools-suite/src/async-subagents/index.ts +422 -0
- package/external/pi-tools-suite/src/async-subagents/lib.ts +88 -0
- package/external/pi-tools-suite/src/async-subagents/live.ts +10 -0
- package/external/pi-tools-suite/src/async-subagents/polling.ts +83 -0
- package/external/pi-tools-suite/src/async-subagents/render.ts +230 -0
- package/external/pi-tools-suite/src/async-subagents/subagent-overlay.ts +77 -0
- package/external/pi-tools-suite/src/async-subagents/tasks.ts +120 -0
- package/external/pi-tools-suite/src/async-subagents/tools/cleanup.ts +99 -0
- package/external/pi-tools-suite/src/async-subagents/tools/result.ts +179 -0
- package/external/pi-tools-suite/src/async-subagents/tools/spawn.ts +372 -0
- package/external/pi-tools-suite/src/async-subagents/tools/status.ts +60 -0
- package/external/pi-tools-suite/src/async-subagents/tools/stop.ts +79 -0
- package/external/pi-tools-suite/src/async-subagents/tools/subagents.ts +152 -0
- package/external/pi-tools-suite/src/async-subagents/tools/wait.ts +67 -0
- package/external/pi-tools-suite/src/async-subagents/types.ts +45 -0
- package/external/pi-tools-suite/src/async-subagents/ui.ts +5 -0
- package/external/pi-tools-suite/src/compress/commands.ts +440 -0
- package/external/pi-tools-suite/src/compress/compress-tool.ts +368 -0
- package/external/pi-tools-suite/src/compress/compression-blocks.ts +524 -0
- package/external/pi-tools-suite/src/compress/config.ts +310 -0
- package/external/pi-tools-suite/src/compress/dcp-tui-filter.ts +498 -0
- package/external/pi-tools-suite/src/compress/index.ts +397 -0
- package/external/pi-tools-suite/src/compress/prompts.ts +269 -0
- package/external/pi-tools-suite/src/compress/pruner-candidates.ts +176 -0
- package/external/pi-tools-suite/src/compress/pruner-compression-blocks.ts +260 -0
- package/external/pi-tools-suite/src/compress/pruner-message-ids.ts +147 -0
- package/external/pi-tools-suite/src/compress/pruner-metadata.ts +268 -0
- package/external/pi-tools-suite/src/compress/pruner-nudge.ts +315 -0
- package/external/pi-tools-suite/src/compress/pruner-tools.ts +263 -0
- package/external/pi-tools-suite/src/compress/pruner-types.ts +25 -0
- package/external/pi-tools-suite/src/compress/pruner.ts +92 -0
- package/external/pi-tools-suite/src/compress/state.ts +486 -0
- package/external/pi-tools-suite/src/compress/ui.ts +308 -0
- package/external/pi-tools-suite/src/config.ts +176 -0
- package/external/pi-tools-suite/src/context-usage.ts +31 -0
- package/external/pi-tools-suite/src/default-pi-tools-suite-config.ts +355 -0
- package/external/pi-tools-suite/src/index.ts +46 -0
- package/external/pi-tools-suite/src/lib/lsp.ts +62 -0
- package/external/pi-tools-suite/src/lib/project.ts +42 -0
- package/external/pi-tools-suite/src/lib/tool-args.ts +137 -0
- package/external/pi-tools-suite/src/lsp/_shared/config.ts +156 -0
- package/external/pi-tools-suite/src/lsp/_shared/glob.ts +60 -0
- package/external/pi-tools-suite/src/lsp/_shared/output.ts +102 -0
- package/external/pi-tools-suite/src/lsp/_shared/paths.ts +138 -0
- package/external/pi-tools-suite/src/lsp/_shared/runner.ts +64 -0
- package/external/pi-tools-suite/src/lsp/_shared/template.ts +23 -0
- package/external/pi-tools-suite/src/lsp/_shared/trust.ts +116 -0
- package/external/pi-tools-suite/src/lsp/_shared/types.ts +98 -0
- package/external/pi-tools-suite/src/lsp/async.ts +29 -0
- package/external/pi-tools-suite/src/lsp/child-process.ts +81 -0
- package/external/pi-tools-suite/src/lsp/client.ts +340 -0
- package/external/pi-tools-suite/src/lsp/constants.ts +9 -0
- package/external/pi-tools-suite/src/lsp/diagnostics-store.ts +64 -0
- package/external/pi-tools-suite/src/lsp/documents.ts +24 -0
- package/external/pi-tools-suite/src/lsp/index.ts +31 -0
- package/external/pi-tools-suite/src/lsp/lsp-utils.ts +37 -0
- package/external/pi-tools-suite/src/lsp/manager.ts +190 -0
- package/external/pi-tools-suite/src/lsp/mutation-events.ts +78 -0
- package/external/pi-tools-suite/src/lsp/renderer.ts +1 -0
- package/external/pi-tools-suite/src/lsp/tool-result.ts +6 -0
- package/external/pi-tools-suite/src/lsp/tsserver.ts +107 -0
- package/external/pi-tools-suite/src/lsp/types.ts +15 -0
- package/external/pi-tools-suite/src/model-tools/apply-patch.ts +590 -0
- package/external/pi-tools-suite/src/model-tools/index.ts +430 -0
- package/external/pi-tools-suite/src/model-tools/path-utils.ts +6 -0
- package/external/pi-tools-suite/src/model-tools/tool-args.ts +11 -0
- package/external/pi-tools-suite/src/prompt-commands/index.ts +349 -0
- package/external/pi-tools-suite/src/repo-discovery/index.ts +384 -0
- package/external/pi-tools-suite/src/repo-discovery/project.ts +7 -0
- package/external/pi-tools-suite/src/startup-section.ts +13 -0
- package/external/pi-tools-suite/src/terminal-bell/index.ts +309 -0
- package/external/pi-tools-suite/src/todo/index.ts +201 -0
- package/external/pi-tools-suite/src/todo/state/auto-clear.ts +13 -0
- package/external/pi-tools-suite/src/todo/state/invariants.ts +21 -0
- package/external/pi-tools-suite/src/todo/state/persistence.ts +94 -0
- package/external/pi-tools-suite/src/todo/state/replay.ts +38 -0
- package/external/pi-tools-suite/src/todo/state/selectors.ts +49 -0
- package/external/pi-tools-suite/src/todo/state/state-reducer.ts +362 -0
- package/external/pi-tools-suite/src/todo/state/state.ts +18 -0
- package/external/pi-tools-suite/src/todo/state/store.ts +52 -0
- package/external/pi-tools-suite/src/todo/state/task-graph.ts +57 -0
- package/external/pi-tools-suite/src/todo/todo.ts +487 -0
- package/external/pi-tools-suite/src/todo/tool/response-envelope.ts +143 -0
- package/external/pi-tools-suite/src/todo/tool/types.ts +188 -0
- package/external/pi-tools-suite/src/todo/view/format.ts +18 -0
- package/external/pi-tools-suite/src/todo/view/labels.ts +13 -0
- package/external/pi-tools-suite/src/tool-descriptions.ts +369 -0
- package/external/pi-tools-suite/src/usage/index.ts +152 -0
- package/external/pi-tools-suite/src/usage/lib/copilot.ts +535 -0
- package/external/pi-tools-suite/src/usage/lib/google.ts +478 -0
- package/external/pi-tools-suite/src/usage/lib/openai.ts +268 -0
- package/external/pi-tools-suite/src/usage/lib/types.ts +114 -0
- package/external/pi-tools-suite/src/usage/lib/utils.ts +134 -0
- package/external/pi-tools-suite/src/usage/lib/zhipu.ts +228 -0
- package/external/pi-tools-suite/src/web-search/index.ts +397 -0
- package/package.json +89 -0
- package/skills/context7/SKILL.md +69 -0
- package/skills/context7/scripts/context7.sh +73 -0
- package/skills/handoff/SKILL.md +15 -0
- package/skills/pdf/LICENSE.txt +30 -0
- package/skills/pdf/SKILL.md +314 -0
- package/skills/pdf/forms.md +294 -0
- package/skills/pdf/reference.md +612 -0
- package/skills/pdf/scripts/check_bounding_boxes.py +65 -0
- package/skills/pdf/scripts/check_fillable_fields.py +11 -0
- package/skills/pdf/scripts/convert_pdf_to_images.py +33 -0
- package/skills/pdf/scripts/create_validation_image.py +37 -0
- package/skills/pdf/scripts/extract_form_field_info.py +122 -0
- package/skills/pdf/scripts/extract_form_structure.py +115 -0
- package/skills/pdf/scripts/fill_fillable_fields.py +98 -0
- package/skills/pdf/scripts/fill_pdf_form_with_annotations.py +107 -0
- package/skills/playwright-cli/SKILL.md +388 -0
- package/skills/playwright-cli/references/element-attributes.md +23 -0
- package/skills/playwright-cli/references/playwright-tests.md +39 -0
- package/skills/playwright-cli/references/request-mocking.md +87 -0
- package/skills/playwright-cli/references/running-code.md +241 -0
- package/skills/playwright-cli/references/session-management.md +225 -0
- package/skills/playwright-cli/references/spec-driven-testing.md +305 -0
- package/skills/playwright-cli/references/storage-state.md +275 -0
- package/skills/playwright-cli/references/test-generation.md +134 -0
- package/skills/playwright-cli/references/tracing.md +139 -0
- package/skills/playwright-cli/references/video-recording.md +143 -0
- package/skills/simplify/SKILL.md +51 -0
- package/skills/skill-creator/LICENSE.txt +202 -0
- package/skills/skill-creator/SKILL.md +485 -0
- package/skills/skill-creator/agents/analyzer.md +274 -0
- package/skills/skill-creator/agents/comparator.md +202 -0
- package/skills/skill-creator/agents/grader.md +223 -0
- package/skills/skill-creator/assets/eval_review.html +146 -0
- package/skills/skill-creator/eval-viewer/generate_review.py +471 -0
- package/skills/skill-creator/eval-viewer/viewer.html +1325 -0
- package/skills/skill-creator/references/schemas.md +430 -0
- package/skills/skill-creator/scripts/__init__.py +0 -0
- package/skills/skill-creator/scripts/aggregate_benchmark.py +401 -0
- package/skills/skill-creator/scripts/generate_report.py +326 -0
- package/skills/skill-creator/scripts/improve_description.py +247 -0
- package/skills/skill-creator/scripts/package_skill.py +136 -0
- package/skills/skill-creator/scripts/quick_validate.py +103 -0
- package/skills/skill-creator/scripts/run_eval.py +310 -0
- package/skills/skill-creator/scripts/run_loop.py +328 -0
- package/skills/skill-creator/scripts/utils.py +47 -0
|
@@ -0,0 +1,688 @@
|
|
|
1
|
+
import { spawn, type ChildProcess } from "node:child_process";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { selectSuitableToolsForModel } from "../../lib/tool-args.js";
|
|
6
|
+
import { validateBasename } from "./paths.js";
|
|
7
|
+
import { getPiInvocation } from "./pi-invocation.js";
|
|
8
|
+
import { writePromptFile } from "./prompt.js";
|
|
9
|
+
import { terminateProcess } from "./process.js";
|
|
10
|
+
import { getAgentSessionDir, SUBAGENT_PARENT_SESSION_FILE, SUBAGENT_RETURN_SESSION_FILE, SUBAGENT_SESSION_FILE, writeParentSessionLink, writeSessionFileLink } from "./sessions.js";
|
|
11
|
+
import { getAgentState } from "./state.js";
|
|
12
|
+
import { writeStructuredResult } from "./structured-result.js";
|
|
13
|
+
import { createBoundedFileWriter, createDeferredFileWriter, resolveSubagentLogLimits } from "./log-limits.js";
|
|
14
|
+
import { filterSubagentTools } from "./tool-guard.js";
|
|
15
|
+
import type { AgentCompletionHandler, AgentTask, RpcEventHandler, RpcEventRecord, SpawnedAgent } from "./types.js";
|
|
16
|
+
import { isRecord, isoNow, serializeJsonLine } from "./utils.js";
|
|
17
|
+
|
|
18
|
+
export interface SpawnAgentOptions {
|
|
19
|
+
parentSession?: string;
|
|
20
|
+
timeoutMs?: number;
|
|
21
|
+
maxResultBytes?: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const DEFAULT_AGENT_TIMEOUT_MS = 30 * 60 * 1000;
|
|
25
|
+
const AGENT_TIMEOUT_EXIT_CODE = 124;
|
|
26
|
+
const AGENT_TIMEOUT_KILL_GRACE_MS = 5_000;
|
|
27
|
+
const AGENT_END_TERMINATE_GRACE_MS = 50;
|
|
28
|
+
const AGENT_END_COMPLETION_FALLBACK_MS = 1_000;
|
|
29
|
+
const EXIT_STDIO_FLUSH_GRACE_MS = 10;
|
|
30
|
+
|
|
31
|
+
export function shouldPersistSubagentSessions(env: NodeJS.ProcessEnv = process.env): boolean {
|
|
32
|
+
return isTruthyEnv(env.ASYNC_SUBAGENTS_ENABLE_SESSIONS);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function spawnAgent(
|
|
36
|
+
runDir: string,
|
|
37
|
+
task: AgentTask,
|
|
38
|
+
cwd: string,
|
|
39
|
+
extraArgs: string[] = [],
|
|
40
|
+
onRpcEvent?: RpcEventHandler,
|
|
41
|
+
onComplete?: AgentCompletionHandler,
|
|
42
|
+
options: SpawnAgentOptions = {},
|
|
43
|
+
): SpawnedAgent {
|
|
44
|
+
validateBasename(task.id, "task.id");
|
|
45
|
+
const agentDir = path.join(runDir, task.id);
|
|
46
|
+
fs.mkdirSync(agentDir, { recursive: true });
|
|
47
|
+
|
|
48
|
+
// Clean previous state when reusing a run directory/agent id.
|
|
49
|
+
for (const f of [
|
|
50
|
+
"exit_code",
|
|
51
|
+
"finished_at",
|
|
52
|
+
"result.md",
|
|
53
|
+
"result.json",
|
|
54
|
+
"events.jsonl",
|
|
55
|
+
"stderr.log",
|
|
56
|
+
"session_dir",
|
|
57
|
+
"image_paths",
|
|
58
|
+
SUBAGENT_SESSION_FILE,
|
|
59
|
+
SUBAGENT_PARENT_SESSION_FILE,
|
|
60
|
+
SUBAGENT_RETURN_SESSION_FILE,
|
|
61
|
+
"timeout_ms",
|
|
62
|
+
"timed_out_at",
|
|
63
|
+
"stop_requested",
|
|
64
|
+
"stop_signal",
|
|
65
|
+
"retry_pending",
|
|
66
|
+
"next_retry_at",
|
|
67
|
+
]) {
|
|
68
|
+
try {
|
|
69
|
+
fs.unlinkSync(path.join(agentDir, f));
|
|
70
|
+
} catch {
|
|
71
|
+
/* ignore */
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
fs.rmSync(getAgentSessionDir(agentDir), { recursive: true, force: true });
|
|
75
|
+
|
|
76
|
+
// Write prompt file (also to prompts/ dir for planned status)
|
|
77
|
+
const promptPath = writePromptFile(runDir, task);
|
|
78
|
+
fs.copyFileSync(promptPath, path.join(agentDir, "prompt.md"));
|
|
79
|
+
|
|
80
|
+
// Build pi args. By default sub-agents use the parent/default model.
|
|
81
|
+
// E2E/live deployments can pin the real model explicitly through env so
|
|
82
|
+
// detached subprocesses do not depend on persisted local pi settings.
|
|
83
|
+
const persistSessions = shouldPersistSubagentSessions();
|
|
84
|
+
const sessionDir = persistSessions ? getAgentSessionDir(agentDir) : undefined;
|
|
85
|
+
if (sessionDir) fs.mkdirSync(sessionDir, { recursive: true });
|
|
86
|
+
const piArgs: string[] = ["--mode", "rpc"];
|
|
87
|
+
if (sessionDir) piArgs.push("--session-dir", sessionDir);
|
|
88
|
+
else piArgs.push("--no-session");
|
|
89
|
+
piArgs.push("--no-extensions");
|
|
90
|
+
piArgs.push("--extension", getModelToolsExtensionPath());
|
|
91
|
+
const envModel = task.model || getEnvModel();
|
|
92
|
+
if (envModel) piArgs.push("--model", envModel);
|
|
93
|
+
const selectedTools = task.tools ? filterSubagentTools(selectSuitableToolsForModel(envModel, task.tools)) : undefined;
|
|
94
|
+
if (selectedTools) {
|
|
95
|
+
if (selectedTools.length > 0) piArgs.push("--tools", selectedTools.join(","));
|
|
96
|
+
else piArgs.push("--no-tools");
|
|
97
|
+
}
|
|
98
|
+
if (task.thinking) piArgs.push("--thinking", task.thinking);
|
|
99
|
+
|
|
100
|
+
// User-supplied extra args (e.g. --thinking high)
|
|
101
|
+
piArgs.push(...extraArgs);
|
|
102
|
+
// Keep recursive/interactive parent-only tools disabled even if explicit
|
|
103
|
+
// sub-agent extraArgs load additional extensions or override --tools.
|
|
104
|
+
piArgs.push("--extension", getSubagentToolGuardExtensionPath());
|
|
105
|
+
|
|
106
|
+
// Read prompt content for stdin
|
|
107
|
+
const promptContent = fs.readFileSync(promptPath, "utf-8");
|
|
108
|
+
const promptImages = task.imagePaths && task.imagePaths.length > 0 ? readPromptImages(task.imagePaths, cwd) : undefined;
|
|
109
|
+
|
|
110
|
+
// Write metadata
|
|
111
|
+
fs.writeFileSync(path.join(agentDir, "project_cwd"), cwd, "utf-8");
|
|
112
|
+
fs.writeFileSync(path.join(agentDir, "pi_args"), piArgs.join("\n"), "utf-8");
|
|
113
|
+
if (sessionDir) fs.writeFileSync(path.join(agentDir, "session_dir"), sessionDir, "utf-8");
|
|
114
|
+
writeParentSessionLink(agentDir, options.parentSession);
|
|
115
|
+
if (task.subagentType) fs.writeFileSync(path.join(agentDir, "subagent_type"), task.subagentType, "utf-8");
|
|
116
|
+
if (task.model) fs.writeFileSync(path.join(agentDir, "model"), task.model, "utf-8");
|
|
117
|
+
if (task.imagePaths && task.imagePaths.length > 0) fs.writeFileSync(path.join(agentDir, "image_paths"), task.imagePaths.join("\n"), "utf-8");
|
|
118
|
+
fs.writeFileSync(path.join(agentDir, "started_at"), isoNow(), "utf-8");
|
|
119
|
+
|
|
120
|
+
const transcriptFile = path.join(agentDir, "events.jsonl");
|
|
121
|
+
const stderrFile = path.join(agentDir, "stderr.log");
|
|
122
|
+
const logLimits = resolveSubagentLogLimits();
|
|
123
|
+
|
|
124
|
+
const invocation = getPiInvocation(piArgs);
|
|
125
|
+
const stderrStream = createDeferredFileWriter(stderrFile, logLimits.stderrMaxBytes, "stderr.log");
|
|
126
|
+
const transcriptStream = createBoundedFileWriter(transcriptFile, logLimits.eventsMaxBytes, "events.jsonl");
|
|
127
|
+
|
|
128
|
+
const proc = spawn(invocation.command, invocation.args, {
|
|
129
|
+
cwd,
|
|
130
|
+
env: subagentEnvironment(process.env),
|
|
131
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
132
|
+
});
|
|
133
|
+
proc.stdin.on("error", (error: NodeJS.ErrnoException) => {
|
|
134
|
+
if (error.code === "EPIPE") return;
|
|
135
|
+
stderrStream.write(`${String(error)}\n`);
|
|
136
|
+
});
|
|
137
|
+
let completedFromAgentEnd = false;
|
|
138
|
+
let completionNotified = false;
|
|
139
|
+
let lastAssistantResult = "";
|
|
140
|
+
let lastAgentEndError = "";
|
|
141
|
+
let timedOut = false;
|
|
142
|
+
let shouldKeepStderr = false;
|
|
143
|
+
let timeoutTimer: NodeJS.Timeout | undefined;
|
|
144
|
+
let timeoutKillTimer: NodeJS.Timeout | undefined;
|
|
145
|
+
let agentEndKillTimer: NodeJS.Timeout | undefined;
|
|
146
|
+
let agentEndCompletionFallbackTimer: NodeJS.Timeout | undefined;
|
|
147
|
+
let exitFinalizationTimer: NodeJS.Timeout | undefined;
|
|
148
|
+
const suppressedRpcEventCounts = new Map<string, number>();
|
|
149
|
+
|
|
150
|
+
const notifyComplete = (exitCode: number) => {
|
|
151
|
+
if (completionNotified) return;
|
|
152
|
+
if (exitCode !== 0) shouldKeepStderr = true;
|
|
153
|
+
completionNotified = true;
|
|
154
|
+
if (timeoutTimer) clearTimeout(timeoutTimer);
|
|
155
|
+
if (timeoutKillTimer) clearTimeout(timeoutKillTimer);
|
|
156
|
+
if (agentEndKillTimer) clearTimeout(agentEndKillTimer);
|
|
157
|
+
if (agentEndCompletionFallbackTimer) clearTimeout(agentEndCompletionFallbackTimer);
|
|
158
|
+
if (exitFinalizationTimer) clearTimeout(exitFinalizationTimer);
|
|
159
|
+
if (!fs.existsSync(agentDir)) {
|
|
160
|
+
onComplete?.({
|
|
161
|
+
runDir,
|
|
162
|
+
agentId: task.id,
|
|
163
|
+
agentDir,
|
|
164
|
+
exitCode,
|
|
165
|
+
state: { id: task.id, status: exitCode === 0 ? "done" : "failed", exitCode },
|
|
166
|
+
});
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
fs.writeFileSync(
|
|
170
|
+
path.join(agentDir, "exit_code"),
|
|
171
|
+
fs.existsSync(path.join(agentDir, "stop_requested")) ? "stopped" : String(exitCode),
|
|
172
|
+
"utf-8",
|
|
173
|
+
);
|
|
174
|
+
fs.writeFileSync(path.join(agentDir, "finished_at"), isoNow(), "utf-8");
|
|
175
|
+
const state = getAgentState(runDir, task.id) ?? {
|
|
176
|
+
id: task.id,
|
|
177
|
+
status: exitCode === 0 ? "done" : "failed",
|
|
178
|
+
exitCode,
|
|
179
|
+
};
|
|
180
|
+
// Write structured result.json alongside result.md
|
|
181
|
+
try {
|
|
182
|
+
writeStructuredResult({
|
|
183
|
+
agentDir,
|
|
184
|
+
agentId: task.id,
|
|
185
|
+
state,
|
|
186
|
+
subagentType: task.subagentType,
|
|
187
|
+
model: task.model,
|
|
188
|
+
maxResultBytes: options.maxResultBytes,
|
|
189
|
+
});
|
|
190
|
+
} catch {
|
|
191
|
+
/* non-critical: do not block completion */
|
|
192
|
+
}
|
|
193
|
+
onComplete?.({ runDir, agentId: task.id, agentDir, exitCode, state });
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const finalizeCompletion = (code: number | null, signal: NodeJS.Signals | null) => {
|
|
197
|
+
if (completionNotified) return;
|
|
198
|
+
writeSuppressedRpcEventSummary(transcriptStream, suppressedRpcEventCounts);
|
|
199
|
+
const exitCode = resolveAgentExitCode({
|
|
200
|
+
timedOut,
|
|
201
|
+
completedFromAgentEnd,
|
|
202
|
+
lastAgentEndError,
|
|
203
|
+
code,
|
|
204
|
+
signal,
|
|
205
|
+
});
|
|
206
|
+
if (fs.existsSync(agentDir)) {
|
|
207
|
+
if (exitCode === 0 && !fs.existsSync(path.join(agentDir, "result.md")) && lastAssistantResult.trim()) {
|
|
208
|
+
fs.writeFileSync(path.join(agentDir, "result.md"), lastAssistantResult.trim(), "utf-8");
|
|
209
|
+
} else if (exitCode !== 0 && !fs.existsSync(path.join(agentDir, "result.md")) && lastAgentEndError) {
|
|
210
|
+
fs.writeFileSync(path.join(agentDir, "result.md"), lastAgentEndError, "utf-8");
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (shouldKeepStderr || exitCode !== 0 || logLimits.debugLogs) stderrStream.flush();
|
|
214
|
+
else stderrStream.discard();
|
|
215
|
+
transcriptStream.end();
|
|
216
|
+
notifyComplete(exitCode);
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const scheduleAgentEndTermination = () => {
|
|
220
|
+
if (agentEndKillTimer) return;
|
|
221
|
+
agentEndKillTimer = setTimeout(() => {
|
|
222
|
+
agentEndKillTimer = undefined;
|
|
223
|
+
try {
|
|
224
|
+
terminateChildProcess(proc, "SIGTERM");
|
|
225
|
+
} catch {
|
|
226
|
+
/* process may have exited before the graceful termination timer fired */
|
|
227
|
+
}
|
|
228
|
+
}, AGENT_END_TERMINATE_GRACE_MS);
|
|
229
|
+
agentEndKillTimer.unref?.();
|
|
230
|
+
agentEndCompletionFallbackTimer = setTimeout(() => {
|
|
231
|
+
if (completionNotified) return;
|
|
232
|
+
try {
|
|
233
|
+
terminateChildProcess(proc, "SIGKILL");
|
|
234
|
+
} catch {
|
|
235
|
+
/* process may already be gone */
|
|
236
|
+
}
|
|
237
|
+
proc.stdin.destroy();
|
|
238
|
+
proc.stdout?.destroy();
|
|
239
|
+
proc.stderr?.destroy();
|
|
240
|
+
proc.unref();
|
|
241
|
+
finalizeCompletion(0, null);
|
|
242
|
+
}, AGENT_END_COMPLETION_FALLBACK_MS);
|
|
243
|
+
agentEndCompletionFallbackTimer.unref?.();
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_AGENT_TIMEOUT_MS;
|
|
247
|
+
if (timeoutMs > 0) {
|
|
248
|
+
timeoutTimer = setTimeout(() => {
|
|
249
|
+
if (completionNotified) return;
|
|
250
|
+
timedOut = true;
|
|
251
|
+
const timeoutMessage = `Sub-agent timed out after ${Math.round(timeoutMs / 1000)} seconds.`;
|
|
252
|
+
if (fs.existsSync(agentDir)) {
|
|
253
|
+
fs.writeFileSync(path.join(agentDir, "timeout_ms"), String(timeoutMs), "utf-8");
|
|
254
|
+
fs.writeFileSync(path.join(agentDir, "timed_out_at"), isoNow(), "utf-8");
|
|
255
|
+
if (!fs.existsSync(path.join(agentDir, "result.md")))
|
|
256
|
+
fs.writeFileSync(path.join(agentDir, "result.md"), timeoutMessage, "utf-8");
|
|
257
|
+
stderrStream.write(`${timeoutMessage}\n`);
|
|
258
|
+
}
|
|
259
|
+
try {
|
|
260
|
+
terminateChildProcess(proc, "SIGTERM");
|
|
261
|
+
} catch {
|
|
262
|
+
/* process may have exited between the timer and signal */
|
|
263
|
+
}
|
|
264
|
+
timeoutKillTimer = setTimeout(() => {
|
|
265
|
+
if (completionNotified) return;
|
|
266
|
+
try {
|
|
267
|
+
terminateChildProcess(proc, "SIGKILL");
|
|
268
|
+
} catch {
|
|
269
|
+
/* process may have exited after SIGTERM */
|
|
270
|
+
}
|
|
271
|
+
}, AGENT_TIMEOUT_KILL_GRACE_MS);
|
|
272
|
+
timeoutKillTimer.unref?.();
|
|
273
|
+
}, timeoutMs);
|
|
274
|
+
timeoutTimer.unref?.();
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
proc.stderr.on("data", (chunk) => stderrStream.write(chunk));
|
|
278
|
+
attachJsonlLineReader(proc.stdout, (line) => {
|
|
279
|
+
const suppressedEventType = onRpcEvent ? undefined : suppressedRpcEventType(line);
|
|
280
|
+
if (suppressedEventType) {
|
|
281
|
+
suppressedRpcEventCounts.set(suppressedEventType, (suppressedRpcEventCounts.get(suppressedEventType) ?? 0) + 1);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
try {
|
|
285
|
+
const event = JSON.parse(line) as RpcEventRecord;
|
|
286
|
+
const storedEvent = compactRpcEventForTranscript(event, Buffer.byteLength(line, "utf8"));
|
|
287
|
+
if (storedEvent) transcriptStream.write(serializeJsonLine(storedEvent));
|
|
288
|
+
onRpcEvent?.(event);
|
|
289
|
+
const sessionFile = extractSessionFileFromEvent(event);
|
|
290
|
+
if (sessionFile) writeSessionFileLink(agentDir, sessionFile);
|
|
291
|
+
const assistantResult = extractAssistantResultFromEvent(event);
|
|
292
|
+
if (assistantResult.trim()) lastAssistantResult = assistantResult;
|
|
293
|
+
const messageEndError = extractMessageEndErrorMessage(event);
|
|
294
|
+
if (messageEndError) lastAgentEndError = messageEndError;
|
|
295
|
+
if (event.type === "response" && event.command === "prompt" && event.success === false) {
|
|
296
|
+
const errorText = typeof event.error === "string" ? event.error : "RPC prompt failed";
|
|
297
|
+
fs.writeFileSync(path.join(agentDir, "result.md"), errorText, "utf-8");
|
|
298
|
+
notifyComplete(1);
|
|
299
|
+
terminateChildProcess(proc, "SIGTERM");
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (event.type === "agent_end") {
|
|
303
|
+
const errorMessage = extractAgentEndErrorMessage(event);
|
|
304
|
+
if (errorMessage) {
|
|
305
|
+
lastAgentEndError = errorMessage;
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
completedFromAgentEnd = true;
|
|
309
|
+
const result = extractAgentEndResult(event);
|
|
310
|
+
if (result.trim())
|
|
311
|
+
fs.writeFileSync(path.join(agentDir, "result.md"), result, "utf-8");
|
|
312
|
+
scheduleAgentEndTermination();
|
|
313
|
+
}
|
|
314
|
+
} catch (error) {
|
|
315
|
+
stderrStream.write(`Invalid RPC JSON line: ${String(error)}\n${previewLine(line)}\n`);
|
|
316
|
+
transcriptStream.write(serializeJsonLine({ type: "invalid_json", bytes: Buffer.byteLength(line, "utf8") }));
|
|
317
|
+
}
|
|
318
|
+
}, {
|
|
319
|
+
maxLineChars: logLimits.rpcEventLineMaxChars,
|
|
320
|
+
onLineTooLongStart: (linePrefix) => {
|
|
321
|
+
const suppressedEventType = onRpcEvent ? undefined : suppressedRpcEventType(linePrefix);
|
|
322
|
+
if (suppressedEventType) {
|
|
323
|
+
suppressedRpcEventCounts.set(suppressedEventType, (suppressedRpcEventCounts.get(suppressedEventType) ?? 0) + 1);
|
|
324
|
+
return true;
|
|
325
|
+
}
|
|
326
|
+
if (!onRpcEvent && isAgentEndLine(linePrefix)) {
|
|
327
|
+
transcriptStream.write(serializeJsonLine({ type: "agent_end", oversized: true, bufferedChars: linePrefix.length }));
|
|
328
|
+
if (lastAgentEndError) {
|
|
329
|
+
fs.writeFileSync(path.join(agentDir, "result.md"), lastAgentEndError, "utf-8");
|
|
330
|
+
} else if (lastAssistantResult.trim()) {
|
|
331
|
+
completedFromAgentEnd = true;
|
|
332
|
+
fs.writeFileSync(path.join(agentDir, "result.md"), lastAssistantResult.trim(), "utf-8");
|
|
333
|
+
} else {
|
|
334
|
+
lastAgentEndError = "Sub-agent produced an oversized agent_end RPC event before a final result could be captured.";
|
|
335
|
+
fs.writeFileSync(path.join(agentDir, "result.md"), lastAgentEndError, "utf-8");
|
|
336
|
+
}
|
|
337
|
+
scheduleAgentEndTermination();
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
340
|
+
return false;
|
|
341
|
+
},
|
|
342
|
+
onLineTooLong: (lineChars) => {
|
|
343
|
+
const message = `RPC JSON line exceeded ${logLimits.rpcEventLineMaxChars} chars; dropped oversized event (${lineChars} chars).`;
|
|
344
|
+
stderrStream.write(`${message}\n`);
|
|
345
|
+
transcriptStream.write(serializeJsonLine({ type: "oversized_rpc_event", chars: lineChars }));
|
|
346
|
+
},
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
proc.once("exit", (code, signal) => {
|
|
350
|
+
exitFinalizationTimer = setTimeout(() => finalizeCompletion(code, signal), EXIT_STDIO_FLUSH_GRACE_MS);
|
|
351
|
+
exitFinalizationTimer.unref?.();
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
proc.once("error", (error) => {
|
|
355
|
+
const message = String(error);
|
|
356
|
+
stderrStream.write(`${message}\n`);
|
|
357
|
+
shouldKeepStderr = true;
|
|
358
|
+
if (fs.existsSync(agentDir) && !fs.existsSync(path.join(agentDir, "result.md"))) {
|
|
359
|
+
fs.writeFileSync(path.join(agentDir, "result.md"), message, "utf-8");
|
|
360
|
+
}
|
|
361
|
+
stderrStream.flush();
|
|
362
|
+
transcriptStream.end();
|
|
363
|
+
notifyComplete(1);
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
proc.stdin.write([
|
|
367
|
+
serializeJsonLine({
|
|
368
|
+
id: "sub_get_state",
|
|
369
|
+
type: "get_state",
|
|
370
|
+
}),
|
|
371
|
+
serializeJsonLine({
|
|
372
|
+
id: "sub_prompt",
|
|
373
|
+
type: "prompt",
|
|
374
|
+
message: promptContent,
|
|
375
|
+
...(promptImages ? { images: promptImages } : {}),
|
|
376
|
+
}),
|
|
377
|
+
].join(""));
|
|
378
|
+
proc.stdin.end();
|
|
379
|
+
|
|
380
|
+
const pid = proc.pid!;
|
|
381
|
+
fs.writeFileSync(path.join(agentDir, "pid"), String(pid), "utf-8");
|
|
382
|
+
|
|
383
|
+
return { pid, agentDir, process: proc };
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function getModelToolsExtensionPath(): string {
|
|
387
|
+
return path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "model-tools", "index.ts");
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function terminateChildProcess(proc: ChildProcess, signal: NodeJS.Signals): void {
|
|
391
|
+
if (proc.pid) {
|
|
392
|
+
terminateProcess(proc.pid, signal as "SIGTERM" | "SIGINT" | "SIGKILL");
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
proc.kill(signal);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function getSubagentToolGuardExtensionPath(): string {
|
|
399
|
+
return path.resolve(path.dirname(fileURLToPath(import.meta.url)), "tool-guard.ts");
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function resolveAgentExitCode(options: {
|
|
403
|
+
timedOut: boolean;
|
|
404
|
+
completedFromAgentEnd: boolean;
|
|
405
|
+
lastAgentEndError: string;
|
|
406
|
+
code: number | null;
|
|
407
|
+
signal: NodeJS.Signals | null;
|
|
408
|
+
}): number {
|
|
409
|
+
if (options.timedOut) return AGENT_TIMEOUT_EXIT_CODE;
|
|
410
|
+
if (options.completedFromAgentEnd) return 0;
|
|
411
|
+
if (options.lastAgentEndError) return 1;
|
|
412
|
+
if (typeof options.code === "number") return options.code;
|
|
413
|
+
if (options.signal) return 128;
|
|
414
|
+
return 1;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function readPromptImages(imagePaths: string[], cwd: string): Array<{ type: "image"; data: string; mimeType: string }> {
|
|
418
|
+
return imagePaths.map((imagePath) => {
|
|
419
|
+
const resolved = resolveImagePath(imagePath, cwd);
|
|
420
|
+
const mimeType = imageMimeType(resolved);
|
|
421
|
+
if (!mimeType) throw new Error(`Unsupported image type for sub-agent attachment: ${imagePath}`);
|
|
422
|
+
return {
|
|
423
|
+
type: "image" as const,
|
|
424
|
+
data: fs.readFileSync(resolved).toString("base64"),
|
|
425
|
+
mimeType,
|
|
426
|
+
};
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function resolveImagePath(imagePath: string, cwd: string): string {
|
|
431
|
+
const normalized = imagePath.startsWith("@") ? imagePath.slice(1) : imagePath;
|
|
432
|
+
return path.resolve(cwd, normalized);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function imageMimeType(filePath: string): string | undefined {
|
|
436
|
+
switch (path.extname(filePath).toLowerCase()) {
|
|
437
|
+
case ".jpg":
|
|
438
|
+
case ".jpeg":
|
|
439
|
+
return "image/jpeg";
|
|
440
|
+
case ".png":
|
|
441
|
+
return "image/png";
|
|
442
|
+
case ".gif":
|
|
443
|
+
return "image/gif";
|
|
444
|
+
case ".webp":
|
|
445
|
+
return "image/webp";
|
|
446
|
+
default:
|
|
447
|
+
return undefined;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function extractSessionFileFromEvent(event: RpcEventRecord): string | undefined {
|
|
452
|
+
if (event.type !== "response" || event.command !== "get_state" || event.success !== true)
|
|
453
|
+
return undefined;
|
|
454
|
+
if (!isRecord(event.data)) return undefined;
|
|
455
|
+
const sessionFile = event.data.sessionFile;
|
|
456
|
+
return typeof sessionFile === "string" && sessionFile.trim() ? sessionFile : undefined;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function attachJsonlLineReader(
|
|
460
|
+
stream: NodeJS.ReadableStream,
|
|
461
|
+
onLine: (line: string) => void,
|
|
462
|
+
options: {
|
|
463
|
+
maxLineChars?: number;
|
|
464
|
+
onLineTooLongStart?: (linePrefix: string) => boolean;
|
|
465
|
+
onLineTooLong?: (lineChars: number) => void;
|
|
466
|
+
} = {},
|
|
467
|
+
): void {
|
|
468
|
+
let buffer = "";
|
|
469
|
+
let droppingOversizedLine: false | "handled" | "report" = false;
|
|
470
|
+
let droppedChars = 0;
|
|
471
|
+
const maxLineChars = options.maxLineChars && options.maxLineChars > 0 ? options.maxLineChars : undefined;
|
|
472
|
+
|
|
473
|
+
stream.on("data", (chunk: string | Buffer) => {
|
|
474
|
+
buffer += typeof chunk === "string" ? chunk : chunk.toString("utf8");
|
|
475
|
+
|
|
476
|
+
while (true) {
|
|
477
|
+
const newlineIndex = buffer.indexOf("\n");
|
|
478
|
+
if (newlineIndex === -1) {
|
|
479
|
+
if (maxLineChars !== undefined && buffer.length > maxLineChars) {
|
|
480
|
+
droppingOversizedLine = options.onLineTooLongStart?.(buffer) ? "handled" : "report";
|
|
481
|
+
droppedChars += buffer.length;
|
|
482
|
+
buffer = "";
|
|
483
|
+
}
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
const line = buffer.slice(0, newlineIndex);
|
|
488
|
+
buffer = buffer.slice(newlineIndex + 1);
|
|
489
|
+
const normalized = line.endsWith("\r") ? line.slice(0, -1) : line;
|
|
490
|
+
if (droppingOversizedLine) {
|
|
491
|
+
droppedChars += normalized.length;
|
|
492
|
+
if (droppingOversizedLine === "report") options.onLineTooLong?.(droppedChars);
|
|
493
|
+
droppingOversizedLine = false;
|
|
494
|
+
droppedChars = 0;
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
497
|
+
if (maxLineChars !== undefined && normalized.length > maxLineChars) {
|
|
498
|
+
if (!options.onLineTooLongStart?.(normalized)) options.onLineTooLong?.(normalized.length);
|
|
499
|
+
continue;
|
|
500
|
+
}
|
|
501
|
+
onLine(normalized);
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
stream.on("end", () => {
|
|
506
|
+
if (droppingOversizedLine) {
|
|
507
|
+
droppedChars += buffer.length;
|
|
508
|
+
if (droppingOversizedLine === "report") options.onLineTooLong?.(droppedChars);
|
|
509
|
+
buffer = "";
|
|
510
|
+
droppingOversizedLine = false;
|
|
511
|
+
droppedChars = 0;
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
if (buffer.length > 0) {
|
|
515
|
+
const normalized = buffer.endsWith("\r") ? buffer.slice(0, -1) : buffer;
|
|
516
|
+
if (maxLineChars !== undefined && normalized.length > maxLineChars) {
|
|
517
|
+
if (!options.onLineTooLongStart?.(normalized)) options.onLineTooLong?.(normalized.length);
|
|
518
|
+
} else {
|
|
519
|
+
onLine(normalized);
|
|
520
|
+
}
|
|
521
|
+
buffer = "";
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function compactRpcEventForTranscript(event: RpcEventRecord, originalBytes: number): RpcEventRecord | undefined {
|
|
527
|
+
if (event.type === "message_update" || event.type === "tool_execution_update") return undefined;
|
|
528
|
+
if (event.type === "response") {
|
|
529
|
+
return stripUndefined({
|
|
530
|
+
type: event.type,
|
|
531
|
+
command: typeof event.command === "string" ? event.command : undefined,
|
|
532
|
+
success: typeof event.success === "boolean" ? event.success : undefined,
|
|
533
|
+
error: typeof event.error === "string" ? previewLine(event.error) : undefined,
|
|
534
|
+
bytes: originalBytes,
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
if (event.type === "agent_end") {
|
|
538
|
+
return {
|
|
539
|
+
type: event.type,
|
|
540
|
+
messageCount: Array.isArray(event.messages) ? event.messages.length : 0,
|
|
541
|
+
bytes: originalBytes,
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
if (event.type === "message_end") {
|
|
545
|
+
return stripUndefined({
|
|
546
|
+
type: event.type,
|
|
547
|
+
role: isRecord(event.message) && typeof event.message.role === "string" ? event.message.role : undefined,
|
|
548
|
+
stopReason: isRecord(event.message) && typeof event.message.stopReason === "string" ? event.message.stopReason : undefined,
|
|
549
|
+
bytes: originalBytes,
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
if (event.type === "turn_end") {
|
|
553
|
+
return {
|
|
554
|
+
type: event.type,
|
|
555
|
+
toolResultCount: Array.isArray(event.toolResults) ? event.toolResults.length : 0,
|
|
556
|
+
bytes: originalBytes,
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
if (event.type === "tool_execution_start" || event.type === "tool_execution_end") {
|
|
560
|
+
return stripUndefined({
|
|
561
|
+
type: event.type,
|
|
562
|
+
toolName: typeof event.toolName === "string" ? event.toolName : undefined,
|
|
563
|
+
toolCallId: typeof event.toolCallId === "string" ? event.toolCallId : undefined,
|
|
564
|
+
bytes: originalBytes,
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
return { type: event.type, bytes: originalBytes };
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
function suppressedRpcEventType(line: string): string | undefined {
|
|
571
|
+
if (line.includes('"type":"message_update"') || line.includes('"type": "message_update"')) return "message_update";
|
|
572
|
+
if (line.includes('"type":"tool_execution_update"') || line.includes('"type": "tool_execution_update"')) return "tool_execution_update";
|
|
573
|
+
return undefined;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
function isAgentEndLine(line: string): boolean {
|
|
577
|
+
return line.includes('"type":"agent_end"') || line.includes('"type": "agent_end"');
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
function writeSuppressedRpcEventSummary(transcriptStream: { write(chunk: string | Buffer): void }, counts: Map<string, number>): void {
|
|
581
|
+
for (const [eventType, count] of counts) {
|
|
582
|
+
if (count > 0) transcriptStream.write(serializeJsonLine({ type: "suppressed_rpc_events", eventType, count }));
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
function previewLine(text: string, maxChars = 4096): string {
|
|
587
|
+
return text.length <= maxChars ? text : `${text.slice(0, maxChars)}… [truncated ${text.length - maxChars} chars]`;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
function stripUndefined(record: RpcEventRecord): RpcEventRecord {
|
|
591
|
+
for (const key of Object.keys(record)) {
|
|
592
|
+
if (record[key] === undefined) delete record[key];
|
|
593
|
+
}
|
|
594
|
+
return record;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
function extractAgentEndErrorMessage(event: RpcEventRecord): string {
|
|
598
|
+
const messages = Array.isArray(event.messages) ? event.messages : [];
|
|
599
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
600
|
+
const message = messages[i];
|
|
601
|
+
const errorMessage = extractAssistantErrorMessage(message);
|
|
602
|
+
if (errorMessage) return errorMessage;
|
|
603
|
+
if (isRecord(message) && message.role === "assistant") return "";
|
|
604
|
+
}
|
|
605
|
+
return "";
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
function extractMessageEndErrorMessage(event: RpcEventRecord): string {
|
|
609
|
+
if (event.type !== "message_end") return "";
|
|
610
|
+
return extractAssistantErrorMessage(event.message);
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
function extractAssistantErrorMessage(message: unknown): string {
|
|
614
|
+
if (!isRecord(message) || message.role !== "assistant" || message.stopReason !== "error") return "";
|
|
615
|
+
return typeof message.errorMessage === "string" && message.errorMessage.trim()
|
|
616
|
+
? message.errorMessage.trim()
|
|
617
|
+
: "Sub-agent ended with an error.";
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
function extractAgentEndResult(event: RpcEventRecord): string {
|
|
621
|
+
const messages = Array.isArray(event.messages) ? event.messages : [];
|
|
622
|
+
const parts: string[] = [];
|
|
623
|
+
|
|
624
|
+
for (const message of messages) {
|
|
625
|
+
const text = extractAssistantMessageText(message);
|
|
626
|
+
if (text) parts.push(text);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
return parts.join("\n\n").trim();
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function extractAssistantResultFromEvent(event: RpcEventRecord): string {
|
|
633
|
+
const parts: string[] = [];
|
|
634
|
+
if (isRecord(event.message)) {
|
|
635
|
+
const text = extractAssistantMessageText(event.message);
|
|
636
|
+
if (text) parts.push(text);
|
|
637
|
+
}
|
|
638
|
+
if (isRecord(event.assistantMessageEvent)) {
|
|
639
|
+
const partial = event.assistantMessageEvent.partial;
|
|
640
|
+
if (isRecord(partial)) {
|
|
641
|
+
const text = extractAssistantMessageText(partial);
|
|
642
|
+
if (text) parts.push(text);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
return parts.join("\n\n").trim();
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function extractAssistantMessageText(message: unknown): string {
|
|
649
|
+
if (!isRecord(message)) return "";
|
|
650
|
+
if (message.role !== "assistant") return "";
|
|
651
|
+
const content = message.content;
|
|
652
|
+
if (!Array.isArray(content)) return "";
|
|
653
|
+
const parts: string[] = [];
|
|
654
|
+
for (const item of content) {
|
|
655
|
+
if (!isRecord(item)) continue;
|
|
656
|
+
if (item.type === "text" && typeof item.text === "string")
|
|
657
|
+
parts.push(item.text);
|
|
658
|
+
}
|
|
659
|
+
return parts.join("\n\n").trim();
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
function getEnvModel(): string | undefined {
|
|
663
|
+
const value = process.env.ASYNC_SUBAGENTS_MODEL || process.env.PI_SUBAGENTS_MODEL;
|
|
664
|
+
const trimmed = value?.trim();
|
|
665
|
+
return trimmed ? trimmed : undefined;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
function subagentEnvironment(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
|
|
669
|
+
return {
|
|
670
|
+
...env,
|
|
671
|
+
PI_MODEL_SUITABLE_TOOLS_PRESERVE_SELECTION: "1",
|
|
672
|
+
PI_TERMINAL_BELL_DISABLED: "1",
|
|
673
|
+
PI_TOOLS_SUITE_DISABLED_MODULES: appendEnvList(env.PI_TOOLS_SUITE_DISABLED_MODULES, [
|
|
674
|
+
"async-subagents",
|
|
675
|
+
"question",
|
|
676
|
+
"terminal-bell",
|
|
677
|
+
]),
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
function appendEnvList(value: string | undefined, items: readonly string[]): string {
|
|
682
|
+
const existing = value?.trim();
|
|
683
|
+
return existing ? `${existing},${items.join(",")}` : items.join(",");
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
function isTruthyEnv(value: string | undefined): boolean {
|
|
687
|
+
return /^(1|true|yes|on)$/i.test(value?.trim() ?? "");
|
|
688
|
+
}
|