pi-web-ui 0.116.0 → 0.118.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/CHANGELOG.md +83 -3
- package/README.md +69 -138
- package/README.zh-CN.md +70 -179
- package/README.zh-TW.md +3 -1
- package/bin/device-hub-cli.mjs +163 -36
- package/bin/frp-manager.mjs +4 -80
- package/bin/hub-upgrade.mjs +561 -0
- package/bin/pi-device-hub.mjs +0 -1
- package/bin/pi-web-ui.mjs +184 -504
- package/deploy/nginx-subpath.conf +0 -33
- package/deploy/pi-web-ui.service +0 -20
- package/dist/server/agent-formatters.js +4 -38
- package/dist/server/agent-service-daemon.js +203 -371
- package/dist/server/agent-service.js +1281 -3030
- package/dist/server/approval-audit.js +2 -23
- package/dist/server/approval-default-rules.js +0 -6
- package/dist/server/approval-rules.js +7 -105
- package/dist/server/ask-user-question-tool.js +1 -12
- package/dist/server/atomic-file.js +33 -5
- package/dist/server/attachment-store.js +0 -36
- package/dist/server/attachments.js +3 -112
- package/dist/server/auth-cookie.js +0 -21
- package/dist/server/bash-tool.js +1 -32
- package/dist/server/bg-servers.js +0 -96
- package/dist/server/browser-page-tool.js +11 -62
- package/dist/server/builtin-modules.js +7 -0
- package/dist/server/canvas/canvas-agent-tool.js +58 -47
- package/dist/server/canvas/canvas-cards.js +0 -14
- package/dist/server/canvas/canvas-dispatch.js +7 -4
- package/dist/server/canvas/canvas-orchestrator.js +167 -181
- package/dist/server/canvas/canvas-runtime-messages.js +30 -0
- package/dist/server/canvas/canvas-scheduled-task.js +0 -3
- package/dist/server/canvas/canvas-scheduler.js +5 -7
- package/dist/server/canvas/canvas-store.js +24 -35
- package/dist/server/canvas/canvas-validation.js +17 -14
- package/dist/server/canvas/canvas-workspace.js +42 -114
- package/dist/server/canvas/pstack-skills-data.js +0 -5
- package/dist/server/claim-files-tool.js +1 -15
- package/dist/server/claim-store.js +5 -49
- package/dist/server/client-id-utils.js +0 -16
- package/dist/server/client-state.js +36 -214
- package/dist/server/communicate-tool.js +0 -3
- package/dist/server/compact-context-tool.js +0 -30
- package/dist/server/compacted-history.js +0 -35
- package/dist/server/compaction-instructions.js +0 -13
- package/dist/server/compaction-markers.js +38 -92
- package/dist/server/compaction-state.js +0 -21
- package/dist/server/composer-drafts.js +0 -34
- package/dist/server/context-budget-runner.js +0 -11
- package/dist/server/context-budget.js +1 -70
- package/dist/server/context-evidence.js +0 -14
- package/dist/server/context-usage.js +0 -12
- package/dist/server/control-socket.js +4 -48
- package/dist/server/conversation-communication.js +0 -10
- package/dist/server/conversation-identity.js +0 -1
- package/dist/server/conversation-read-tool.js +0 -58
- package/dist/server/conversation-tool-names.js +0 -1
- package/dist/server/conversation-tool.js +0 -1
- package/dist/server/conversation-touches.js +4 -75
- package/dist/server/dangling-tools.js +142 -68
- package/dist/server/delegate-mode.js +0 -36
- package/dist/server/delegate-task.js +2 -28
- package/dist/server/device-center/approval-summary.js +0 -1
- package/dist/server/device-center/bot-catalog.js +0 -3
- package/dist/server/device-center/bot-execution.js +48 -9
- package/dist/server/device-center/bot-presets.js +0 -1
- package/dist/server/device-center/bots.js +0 -1
- package/dist/server/device-center/collab-service.js +27 -11
- package/dist/server/device-center/collab-tool.js +393 -27
- package/dist/server/device-center/connector.js +128 -48
- package/dist/server/device-center/delivery-authority.js +95 -0
- package/dist/server/device-center/delivery-subject.js +29 -0
- package/dist/server/device-center/desktop-linux.js +3 -15
- package/dist/server/device-center/desktop-native.js +1 -10
- package/dist/server/device-center/desktop-page.js +2 -3
- package/dist/server/device-center/desktop-setup.js +1 -3
- package/dist/server/device-center/desktop.js +1 -7
- package/dist/server/device-center/device-integration.js +452 -208
- package/dist/server/device-center/device-lan-access.js +403 -0
- package/dist/server/device-center/device-lan.js +484 -0
- package/dist/server/device-center/device-portals.js +0 -3
- package/dist/server/device-center/execution-failure.js +0 -2
- package/dist/server/device-center/execution-guides.js +15 -6
- package/dist/server/device-center/execution-instructions.js +0 -1
- package/dist/server/device-center/execution-settings.js +0 -1
- package/dist/server/device-center/execution-system-prompt.js +0 -3
- package/dist/server/device-center/execution-workspace.js +1 -4
- package/dist/server/device-center/executor.js +46 -31
- package/dist/server/device-center/file-sync-paths.js +0 -5
- package/dist/server/device-center/file-sync.js +0 -10
- package/dist/server/device-center/group-context-delta.js +0 -8
- package/dist/server/device-center/group-context-message.js +0 -14
- package/dist/server/device-center/group-context.js +0 -19
- package/dist/server/device-center/group-events.js +0 -2
- package/dist/server/device-center/group-plan-guard.js +1 -35
- package/dist/server/device-center/group-router-runtime.js +182 -0
- package/dist/server/device-center/group-router-worker.js +178 -0
- package/dist/server/device-center/group-router.js +359 -0
- package/dist/server/device-center/hub-auth.js +24 -2
- package/dist/server/device-center/hub-conversations.js +13 -15
- package/dist/server/device-center/hub-deliveries.js +119 -15
- package/dist/server/device-center/hub-integration.js +647 -334
- package/dist/server/device-center/hub-locks.js +1 -5
- package/dist/server/device-center/hub-mobile.js +147 -0
- package/dist/server/device-center/hub-orchestration.js +400 -0
- package/dist/server/device-center/hub-page.js +28 -9
- package/dist/server/device-center/hub-setup.js +23 -7
- package/dist/server/device-center/hub-transaction-log.js +175 -0
- package/dist/server/device-center/hub-upgrade.js +162 -0
- package/dist/server/device-center/hub-webhooks.js +1 -3
- package/dist/server/device-center/hub.js +946 -404
- package/dist/server/device-center/human-interaction.js +1 -4
- package/dist/server/device-center/integration-errors.js +0 -2
- package/dist/server/device-center/integration-verification.js +111 -0
- package/dist/server/device-center/local-hub.js +6 -4
- package/dist/server/device-center/local-publication.js +416 -0
- package/dist/server/device-center/local-verification-job.js +95 -0
- package/dist/server/device-center/local-verification.js +273 -0
- package/dist/server/device-center/local.js +341 -18
- package/dist/server/device-center/main.js +18 -2
- package/dist/server/device-center/mobile-notification-forwarder.js +292 -0
- package/dist/server/device-center/native-desktop/macos.js +0 -1
- package/dist/server/device-center/native-desktop/windows.js +0 -1
- package/dist/server/device-center/partition-log.js +52 -46
- package/dist/server/device-center/path-portal.js +42 -12
- package/dist/server/device-center/publication-journal.js +305 -0
- package/dist/server/device-center/publish-intent.js +374 -0
- package/dist/server/device-center/relay.js +217 -52
- package/dist/server/device-center/report-upload.js +0 -1
- package/dist/server/device-center/runtime.js +419 -52
- package/dist/server/device-center/store.js +223 -65
- package/dist/server/device-center/task-context-budget.js +0 -3
- package/dist/server/device-center/task-error.js +0 -1
- package/dist/server/device-center/task-journal.js +6 -23
- package/dist/server/device-center/task-outcome.js +68 -0
- package/dist/server/device-center/task-plan.js +0 -1
- package/dist/server/device-center/task-progress.js +0 -16
- package/dist/server/device-center/task-recovery.js +569 -227
- package/dist/server/device-center/task-report-outbox.js +0 -4
- package/dist/server/device-center/task-report.js +2 -10
- package/dist/server/device-center/task-scheduler.js +1 -35
- package/dist/server/device-center/task-settlement.js +335 -0
- package/dist/server/device-center/task-state.js +0 -12
- package/dist/server/device-center/task-workspace.js +393 -0
- package/dist/server/device-center/transfer-stream.js +5 -45
- package/dist/server/device-center/transfers.js +2 -10
- package/dist/server/device-center/verification-limits.js +9 -0
- package/dist/server/device-center/work-contract.js +923 -0
- package/dist/server/device-center/work-items.js +317 -0
- package/dist/server/device-center/workspaces.js +0 -1
- package/dist/server/dispatch-domain-handlers.js +202 -29
- package/dist/server/dispatch-plugin-handlers.js +2 -19
- package/dist/server/dsh/dsh-agent-service.js +78 -601
- package/dist/server/dsh/dsh-client.js +7 -111
- package/dist/server/dsh/dsh-market-service.js +4 -25
- package/dist/server/dsh/dsh-serialize.js +0 -49
- package/dist/server/dsh/dsh-sessions.js +0 -37
- package/dist/server/dsh/dsh-usage.js +0 -37
- package/dist/server/dsh/preset-clones.js +1 -65
- package/dist/server/dsh/runtime/custom-prompt.mjs +0 -14
- package/dist/server/dsh/runtime/goal-rpc.mjs +7 -176
- package/dist/server/dsh/runtime/launcher.mjs +2 -53
- package/dist/server/dsh/runtime/override.patch.yml +0 -29
- package/dist/server/dsh/runtime/runtime-root.mjs +0 -54
- package/dist/server/durable/durable-agent-service.js +5 -23
- package/dist/server/durable/durable-driver.js +12 -73
- package/dist/server/durable/durable-event-projector.js +1 -50
- package/dist/server/durable/durable-loader.js +0 -12
- package/dist/server/durable/durable-models.js +11 -80
- package/dist/server/durable/durable-storage.js +1 -17
- package/dist/server/durable/durable-tools.js +2 -20
- package/dist/server/durable/index.js +0 -3
- package/dist/server/edit-soft-tool.js +2 -81
- package/dist/server/engine-capabilities.js +0 -13
- package/dist/server/engine-catalog.js +74 -0
- package/dist/server/engine-cli.js +89 -0
- package/dist/server/engine-probe.js +35 -217
- package/dist/server/ensure-bash.js +2 -28
- package/dist/server/eval-tool.js +1 -50
- package/dist/server/evidence-tool-hooks.js +0 -2
- package/dist/server/file-archives.js +0 -10
- package/dist/server/file-save.js +1 -12
- package/dist/server/file-transfer-routes.js +0 -11
- package/dist/server/files-service.js +18 -271
- package/dist/server/global-loader.js +9 -89
- package/dist/server/goal-evidence.js +1 -35
- package/dist/server/goal-review-gate.js +0 -58
- package/dist/server/goal-service.js +19 -422
- package/dist/server/hashline-engine.js +8 -112
- package/dist/server/host-guard.js +0 -24
- package/dist/server/host-metrics.js +0 -6
- package/dist/server/http-proxy.js +1 -7
- package/dist/server/i18n.js +5 -72
- package/dist/server/icon-svg.js +0 -15
- package/dist/server/index.js +199 -677
- package/dist/server/json-utils.js +0 -12
- package/dist/server/launch-origin.js +0 -44
- package/dist/server/left-panel-running.js +0 -9
- package/dist/server/load-timing.js +1 -4
- package/dist/server/load-tools-tool.js +0 -20
- package/dist/server/locales.js +1 -46
- package/dist/server/lsp-tool.js +13 -126
- package/dist/server/managed.js +0 -48
- package/dist/server/marker-service.js +1 -22
- package/dist/server/markers/builtins/action.js +0 -19
- package/dist/server/markers/builtins/notify.js +1 -9
- package/dist/server/markers/builtins/rename.js +0 -13
- package/dist/server/markers/index.js +0 -3
- package/dist/server/markers/marker.js +0 -13
- package/dist/server/markers/registry.js +0 -3
- package/dist/server/markers/store.js +1 -12
- package/dist/server/market-service.js +7 -43
- package/dist/server/mcp-agent-tool.js +0 -10
- package/dist/server/mcp-bridge.js +6 -138
- package/dist/server/mcp-hot-reload.js +0 -25
- package/dist/server/mcp-manager.js +2 -44
- package/dist/server/mcp-oauth-login.js +0 -2
- package/dist/server/mcp-oauth-ui.js +1 -4
- package/dist/server/mcp-oauth.js +5 -79
- package/dist/server/mcp-project-runtime.js +0 -4
- package/dist/server/message-deletion.js +0 -2
- package/dist/server/message-entry-resolver.js +0 -8
- package/dist/server/message-window.js +0 -71
- package/dist/server/mobile-notification-events.js +16 -0
- package/dist/server/mobile-origin.js +79 -0
- package/dist/server/mobile-push.js +523 -0
- package/dist/server/model-admin.js +19 -358
- package/dist/server/model-enrich.js +0 -19
- package/dist/server/model-resolver.js +2 -61
- package/dist/server/native-cli-discovery.js +115 -0
- package/dist/server/native-cli-model.js +71 -0
- package/dist/server/native-cli-references.js +214 -0
- package/dist/server/native-cli-remote-cleanup.js +58 -0
- package/dist/server/native-cli-remote-files.js +282 -0
- package/dist/server/native-cli-routes.js +68 -0
- package/dist/server/native-cli-runtime.js +1 -0
- package/dist/server/native-cli-session-hooks.js +170 -0
- package/dist/server/native-cli-session.js +585 -0
- package/dist/server/native-cli-state.js +82 -0
- package/dist/server/native-cli.js +210 -0
- package/dist/server/net-guard.js +9 -71
- package/dist/server/office-parse.js +0 -50
- package/dist/server/orphan-manager.js +0 -18
- package/dist/server/patch-bash-process.js +0 -4
- package/dist/server/patch-executable-lookup.js +0 -77
- package/dist/server/patch-node-pty.js +6 -45
- package/dist/server/patch-remote-catalog.js +4 -34
- package/dist/server/patch-tool.js +0 -15
- package/dist/server/payload-limits.js +0 -5
- package/dist/server/pending-question.js +0 -5
- package/dist/server/permission-preset.js +4 -33
- package/dist/server/persona-chain.js +0 -26
- package/dist/server/pkg-info.js +1 -17
- package/dist/server/plan-manager.js +2 -49
- package/dist/server/plan-mode.js +0 -97
- package/dist/server/plan-update-tool.js +1 -15
- package/dist/server/plugin-api-catalog.js +6 -4
- package/dist/server/plugin-assets.js +1 -35
- package/dist/server/plugin-bundled.js +68 -0
- package/dist/server/plugin-catalog-sync.js +0 -37
- package/dist/server/plugin-catalog.js +13 -67
- package/dist/server/plugin-chat-attachments.js +0 -1
- package/dist/server/plugin-conversation-view.js +0 -20
- package/dist/server/plugin-dom.js +1 -23
- package/dist/server/plugin-facilities.js +4 -115
- package/dist/server/plugin-grants.js +2 -90
- package/dist/server/plugin-install-spec.js +0 -43
- package/dist/server/plugin-installer.js +34 -75
- package/dist/server/plugin-llm.js +4 -38
- package/dist/server/plugin-manifest-validate.js +0 -31
- package/dist/server/plugin-permissions.js +1 -24
- package/dist/server/plugin-project.js +7 -129
- package/dist/server/plugin-removal.js +1 -8
- package/dist/server/plugin-schedule.js +1 -38
- package/dist/server/plugin-secrets.js +3 -16
- package/dist/server/plugin-tool-guard.js +1 -28
- package/dist/server/plugin-ui-slots.js +0 -4
- package/dist/server/plugin-updater.js +15 -90
- package/dist/server/plugins.js +71 -619
- package/dist/server/present-files-tool.js +0 -57
- package/dist/server/preset-fields.js +24 -61
- package/dist/server/preset-plugin-dependencies.js +0 -2
- package/dist/server/preset-share.js +4 -172
- package/dist/server/process-utils.js +4 -80
- package/dist/server/prompt-assembler.js +2 -30
- package/dist/server/prompt-base-store.js +0 -47
- package/dist/server/prompt-composer.js +21 -98
- package/dist/server/prompt-templates.js +0 -2
- package/dist/server/protocol-version.js +1 -11
- package/dist/server/protocol.js +0 -5
- package/dist/server/queue-modes.js +0 -3
- package/dist/server/queue-utils.js +0 -40
- package/dist/server/quick-ask-context.js +384 -0
- package/dist/server/quick-ask-settings.js +61 -0
- package/dist/server/quick-ask.js +260 -0
- package/dist/server/read-tool.js +0 -65
- package/dist/server/reasoning-registry.js +1 -29
- package/dist/server/remote-cli-persistence.js +373 -0
- package/dist/server/remote-native-cli.js +78 -0
- package/dist/server/remote-ssh-service.js +481 -190
- package/dist/server/request-context.js +0 -9
- package/dist/server/resolve-global-sdk.js +55 -31
- package/dist/server/sandbox-data.js +0 -1
- package/dist/server/sandbox-engines.js +0 -1
- package/dist/server/sandbox-runtime-gate.js +0 -3
- package/dist/server/sandbox-service.js +0 -41
- package/dist/server/sandbox-tool.js +0 -20
- package/dist/server/schedule-agent-tool.js +2 -31
- package/dist/server/scheduler-tasks.js +32 -56
- package/dist/server/scm-commitmsg.js +0 -53
- package/dist/server/scm.js +3 -48
- package/dist/server/sdk-builtin-extensions.js +2 -29
- package/dist/server/sdk-origin.js +0 -45
- package/dist/server/serialize.js +2 -92
- package/dist/server/server-config.js +0 -11
- package/dist/server/session-branch.js +1 -87
- package/dist/server/session-list-scan.js +215 -0
- package/dist/server/session-open.js +69 -0
- package/dist/server/session-parser.js +4 -54
- package/dist/server/session-scan.js +81 -45
- package/dist/server/session-search.js +0 -56
- package/dist/server/settings-service.js +19 -126
- package/dist/server/setup-config.js +0 -2
- package/dist/server/setup-page.js +0 -9
- package/dist/server/skill-content-filler.js +0 -17
- package/dist/server/skill-discovery.js +5 -92
- package/dist/server/skill-maintenance.js +1 -28
- package/dist/server/skill-tool.js +0 -30
- package/dist/server/slash-commands.js +5 -50
- package/dist/server/soft-cap.js +3 -40
- package/dist/server/startup-banner.js +0 -8
- package/dist/server/subagent-handoff.js +0 -11
- package/dist/server/subagent-helpers.js +2 -17
- package/dist/server/subagent-notify.js +0 -19
- package/dist/server/subagent-security-gate.js +0 -50
- package/dist/server/subagent-task.js +0 -9
- package/dist/server/subagent-templates-hant.js +0 -10
- package/dist/server/subagent-templates.js +3 -103
- package/dist/server/subagents.js +1 -87
- package/dist/server/system-screenshot-windows.js +259 -0
- package/dist/server/system-screenshot.js +77 -0
- package/dist/server/tabs.js +3 -48
- package/dist/server/terminals.js +559 -586
- package/dist/server/text-quote.js +0 -12
- package/dist/server/text-sniff.js +2 -52
- package/dist/server/themes.js +2 -41
- package/dist/server/tool-approval.js +0 -47
- package/dist/server/tool-guards.js +0 -90
- package/dist/server/tool-host-factories.js +1 -16
- package/dist/server/tool-info.js +0 -13
- package/dist/server/tool-manager.js +1 -229
- package/dist/server/tool-overrides.js +1 -46
- package/dist/server/tool-prompt-overrides.js +1 -30
- package/dist/server/tool-prompts.js +0 -14
- package/dist/server/tool-signature.js +0 -25
- package/dist/server/transcript-prepare.js +55 -0
- package/dist/server/tts-routes.js +58 -0
- package/dist/server/tts-service.js +106 -0
- package/dist/server/tts-system.js +160 -0
- package/dist/server/turn-timing.js +0 -1
- package/dist/server/unauthorized-page.js +0 -8
- package/dist/server/universal/driver-base.js +2 -31
- package/dist/server/universal/drivers/claude-code.js +98 -194
- package/dist/server/universal/drivers/codex.js +12 -35
- package/dist/server/universal/drivers/mock-driver.js +1 -11
- package/dist/server/universal/index.js +0 -3
- package/dist/server/universal/session-store.js +4 -21
- package/dist/server/universal/universal-attachments.js +2 -36
- package/dist/server/universal/universal-service.js +5 -24
- package/dist/server/universal/universal-session.js +30 -148
- package/dist/server/universal/universal-types.js +0 -3
- package/dist/server/update-check.js +6 -182
- package/dist/server/uploads.js +4 -43
- package/dist/server/virtual-tui.js +2 -27
- package/dist/server/vision-bridge.js +0 -27
- package/dist/server/wait-subscription-scan.js +13 -115
- package/dist/server/webui-context.js +2 -87
- package/dist/server/workspace-handle.js +373 -0
- package/dist/server/workspace-snapshot.js +7 -113
- package/dist/server/worktree-service.js +2 -53
- package/dist/server/worktree-tool.js +0 -11
- package/dist/server/ws-client-id.js +0 -18
- package/dist/server/ws-pending-queue.js +0 -7
- package/dist/server/ws-unknown-types.js +0 -17
- package/docs/README.md +24 -17
- package/docs/architecture-plugins.md +55 -6
- package/docs/device-center.md +57 -23
- package/docs/device-desktop.md +3 -3
- package/docs/group-orchestration.md +142 -0
- package/docs/hub-upgrade-release-testing.md +46 -0
- package/extensions/webui.ts +3 -74
- package/package.json +9 -6
- package/plugin-sdk/README.md +22 -8
- package/plugin-sdk/client-utils.mjs +0 -7
- package/plugin-sdk/client.d.ts +26 -0
- package/plugin-sdk/client.mjs +52 -0
- package/plugin-sdk/import-check.mjs +4 -51
- package/plugin-sdk/index.d.ts +128 -117
- package/plugin-sdk/index.mjs +2 -687
- package/plugin-sdk/package.json +15 -4
- package/plugin-sdk/ssh-host-trust.mjs +0 -12
- package/plugin-sdk/testing.d.ts +9 -0
- package/plugin-sdk/testing.mjs +511 -0
- package/plugins/catalog.json +52 -4
- package/plugins/superagent/README.md +110 -0
- package/plugins/superagent/client/entry.mjs +21 -0
- package/plugins/superagent/index.mjs +8 -0
- package/plugins/superagent/main.mjs +218 -0
- package/plugins/superagent/manifest.json +15 -0
- package/plugins/superagent/server.mjs +572 -0
- package/plugins/superagent/style.css +167 -0
- package/themes/aetheris.css +1 -31
- package/themes/ayu-light.css +0 -1
- package/themes/bases/flow-base.css +2 -83
- package/themes/bases/obsidian-base.css +2 -37
- package/themes/bases/statusbar-flat-base.css +0 -1
- package/themes/bases/zhujian-base.css +0 -63
- package/themes/bases/zhupi-base.css +0 -64
- package/themes/catppuccin-latte.css +0 -1
- package/themes/catppuccin.css +0 -1
- package/themes/claude-code-dark.css +0 -1
- package/themes/codex.css +0 -1
- package/themes/dark-teal.css +22 -54
- package/themes/everforest-light.css +0 -1
- package/themes/flow-cristallo.css +160 -0
- package/themes/flow-ink.css +160 -0
- package/themes/flow-light.css +1 -10
- package/themes/flow-obsidian.css +160 -0
- package/themes/flow-zurich.css +160 -0
- package/themes/flow.css +1 -9
- package/themes/geist.css +0 -1
- package/themes/gruvbox-light.css +0 -1
- package/themes/kanagawa-lotus.css +0 -1
- package/themes/md-preview.css +1 -2
- package/themes/mist.css +0 -1
- package/themes/nord.css +0 -1
- package/themes/one-dark.css +0 -1
- package/themes/paper.css +0 -1
- package/themes/rose-pine-dawn.css +0 -1
- package/themes/sakura.css +0 -1
- package/themes/solarized-light.css +0 -1
- package/themes/tokyo-night.css +0 -1
- package/themes/translucent.css +4 -35
- package/themes/transparent.css +4 -41
- package/themes/vs-code-dark.css +0 -1
- package/themes/wallpaper-flow.css +3 -17
- package/themes/wallpaper-obsidian.css +1 -4
- package/themes/white.css +0 -1
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/{BgTasksModal-BDoOpj-F.js → BgTasksModal-D-x7kA63.js} +1 -1
- package/web/dist/assets/CanvasStudio-CAWcs9tm.js +1579 -0
- package/web/dist/assets/DeviceCenter-Dc0whRcu.js +3 -0
- package/web/dist/assets/DeviceExecutionSettings-BoX7-0h7.js +1 -0
- package/web/dist/assets/DeviceGroups-C_fZMNeK.js +1 -0
- package/web/dist/assets/{Dropdown-C4LIhshN.js → Dropdown-CTgVLUbp.js} +1 -1
- package/web/dist/assets/FilePreview-C6W0PvaK.js +2 -0
- package/web/dist/assets/GlobalSearchModal-HR9LSspC.js +1 -0
- package/web/dist/assets/GroupConversation-C81YjF2C.js +61 -0
- package/web/dist/assets/GroupWorkItems-BIvZtr10.js +1 -0
- package/web/dist/assets/{HintTip-c6d0TJoh.js → HintTip-Da6qc566.js} +1 -1
- package/web/dist/assets/ModelConfigModal-DhSyuIuV.js +2 -0
- package/web/dist/assets/NativeCliPanel-CU1rZmyu.js +5 -0
- package/web/dist/assets/{PiSetupModal-BmMrrgB9.js → PiSetupModal-DZKY5Wiw.js} +1 -1
- package/web/dist/assets/ProviderOAuthControls-CIL85nA7.js +1 -0
- package/web/dist/assets/SCMPanel-CuEgzAlO.js +2 -0
- package/web/dist/assets/SettingsModal-Cdu5h29p.js +33 -0
- package/web/dist/assets/TermXterm-Bt5WKAxP.js +3 -0
- package/web/dist/assets/TerminalPanel-BCIBV8se.js +1 -0
- package/web/dist/assets/TuiOverlayModal-3NDd9T97.js +1 -0
- package/web/dist/assets/app-globals-CZjFtI4F.js +129 -0
- package/web/dist/assets/canvas-client-WkhM55mR.js +1 -0
- package/web/dist/assets/composer-bridge-CImnjDHq.js +1 -0
- package/web/dist/assets/desktop-B8NZ3KW-.js +1 -0
- package/web/dist/assets/index-CQc3VrWa.css +1 -0
- package/web/dist/assets/index-D_AGu4Zv.js +404 -0
- package/web/dist/assets/plugin-host-uqZGpvCs.js +1 -0
- package/web/dist/assets/{remote-ssh-client-CfYSMEZg.js → remote-ssh-client-Cdf-cTUe.js} +1 -1
- package/web/dist/assets/theme-DGL7hLUs.js +1 -0
- package/web/dist/index.html +12 -11
- package/web/dist/sw.js +15 -61
- package/web/public/sw.js +14 -60
- package/dist/gh-comment-781.md +0 -5
- package/dist/server/device-center/local-page.js +0 -17
- package/dist/server/device-center/smoke-preview.js +0 -3
- package/dist/server/durable/durable-capabilities.js +0 -11
- package/dist/server/markers/builtins/services.js +0 -123
- package/dist/server/markers/builtins/todo.js +0 -189
- package/dist/server/markers-list-tool.js +0 -34
- package/dist/server/orchestrator.js +0 -109
- package/dist/server/patch-turn-end-boundary.js +0 -77
- package/dist/server/system-prompt-soul.js +0 -41
- package/dist/server/univer-service.js +0 -448
- package/dist/server/universal/drivers/dsh-driver.js +0 -379
- package/dist/test-artifact.md +0 -9
- package/dist/test-preview-modal.md +0 -11
- package/dist/test-report.html +0 -20
- package/web/dist/assets/BgTasksModal-C0i3O1FT.js +0 -1
- package/web/dist/assets/CanvasStudio-B8thymBN.js +0 -1579
- package/web/dist/assets/CanvasStudio-zSxyIx1R.js +0 -1579
- package/web/dist/assets/DeviceCenter-DfAHKcid.js +0 -3
- package/web/dist/assets/DeviceCenter-ydvOTlzE.js +0 -3
- package/web/dist/assets/DeviceExecutionSettings-q5Ik8oXg.js +0 -1
- package/web/dist/assets/DeviceGroups-CI14_SRb.js +0 -1
- package/web/dist/assets/DeviceGroups-DvsB5IEU.js +0 -1
- package/web/dist/assets/FilePreview-BgGongmv.js +0 -2
- package/web/dist/assets/FilePreview-D4NrhF-U.js +0 -2
- package/web/dist/assets/GlobalSearchModal-BWgU8yPd.js +0 -1
- package/web/dist/assets/GlobalSearchModal-F7fNimKk.js +0 -1
- package/web/dist/assets/GroupConversation-Dh71Pdb-.js +0 -17
- package/web/dist/assets/GroupConversation-ZK3nRmNm.js +0 -17
- package/web/dist/assets/ModelConfigModal-YVEgyy34.js +0 -2
- package/web/dist/assets/ModelConfigModal-vWtg3srp.js +0 -2
- package/web/dist/assets/ProviderOAuthControls-BGSBIKD7.js +0 -1
- package/web/dist/assets/SCMPanel-B8_EDxNr.js +0 -2
- package/web/dist/assets/SCMPanel-BU58qk3T.js +0 -2
- package/web/dist/assets/SettingsModal-CMUybq3J.js +0 -32
- package/web/dist/assets/SettingsModal-OBmGTh-5.js +0 -32
- package/web/dist/assets/TerminalPanel-0CYvD72B.js +0 -3
- package/web/dist/assets/TerminalPanel-DDavKvFr.js +0 -3
- package/web/dist/assets/TuiOverlayModal-BsA-QTvN.js +0 -1
- package/web/dist/assets/TuiOverlayModal-DzoVQBuG.js +0 -1
- package/web/dist/assets/app-globals-CZxzGvIo.js +0 -123
- package/web/dist/assets/canvas-client-CUnXlQYX.js +0 -1
- package/web/dist/assets/desktop-aAKpvKJV.js +0 -1
- package/web/dist/assets/index-C6DwztqE.css +0 -1
- package/web/dist/assets/index-CuN802Sj.js +0 -93
- package/web/dist/assets/index-EH5Fw9fa.js +0 -93
- package/web/dist/assets/plugin-host-BRWib9DF.js +0 -1
- package/web/dist/assets/theme-D2l_mLNo.js +0 -1
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { chmod, glob, lstat, mkdir, open, readdir, rename, writeFile } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { NATIVE_CLI_EVENT_BYTES, NATIVE_CLI_EVENT_LIMIT, nativeCliCodexHookConflicts, nativeCliEventId, nativeCliPiExtension, nativeCliPosixReporter, parseNativeCliHookEvent, quoteNativeCliShell as quote, } from "./native-cli-session-hooks.js";
|
|
6
|
+
const UUID = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i;
|
|
7
|
+
const EVENTS = ["SessionStart", "UserPromptSubmit", "PermissionRequest", "Stop", "PreToolUse", "PostToolUse"];
|
|
8
|
+
const EVENT_FILE = /^[a-zA-Z0-9_.-]{1,180}\.json$/;
|
|
9
|
+
function flag(args, names) {
|
|
10
|
+
return args.some((arg) => names.some((name) => arg === name ||
|
|
11
|
+
arg.startsWith(name + "=") ||
|
|
12
|
+
(name.length === 2 && !name.startsWith("--") && arg.startsWith(name))));
|
|
13
|
+
}
|
|
14
|
+
function flagValue(args, names) {
|
|
15
|
+
for (let index = 0; index < args.length; index++) {
|
|
16
|
+
for (const name of names) {
|
|
17
|
+
if (args[index].startsWith(name + "="))
|
|
18
|
+
return args[index].slice(name.length + 1);
|
|
19
|
+
if (name.length === 2 && !name.startsWith("--") && args[index].startsWith(name) && args[index].length > 2)
|
|
20
|
+
return args[index].slice(2);
|
|
21
|
+
if (args[index] === name && args[index + 1] && !args[index + 1].startsWith("-"))
|
|
22
|
+
return args[index + 1];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
function codexSubcommand(args) {
|
|
28
|
+
const values = new Set([
|
|
29
|
+
"--config",
|
|
30
|
+
"-c",
|
|
31
|
+
"--model",
|
|
32
|
+
"-m",
|
|
33
|
+
"--profile",
|
|
34
|
+
"-p",
|
|
35
|
+
"--sandbox",
|
|
36
|
+
"-s",
|
|
37
|
+
"--ask-for-approval",
|
|
38
|
+
"-a",
|
|
39
|
+
"--cd",
|
|
40
|
+
"-C",
|
|
41
|
+
"--image",
|
|
42
|
+
"-i",
|
|
43
|
+
"--add-dir",
|
|
44
|
+
"--enable",
|
|
45
|
+
"--disable",
|
|
46
|
+
"--local-provider",
|
|
47
|
+
]);
|
|
48
|
+
for (let index = 0; index < args.length; index++) {
|
|
49
|
+
if (args[index] === "--")
|
|
50
|
+
break;
|
|
51
|
+
if (values.has(args[index])) {
|
|
52
|
+
index++;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (args[index].startsWith("-"))
|
|
56
|
+
continue;
|
|
57
|
+
return args[index] === "resume" || args[index] === "fork" ? index : -1;
|
|
58
|
+
}
|
|
59
|
+
return -1;
|
|
60
|
+
}
|
|
61
|
+
function addOptions(args, options) {
|
|
62
|
+
const separator = args.indexOf("--");
|
|
63
|
+
return separator < 0 ? [...options, ...args] : [...args.slice(0, separator), ...options, ...args.slice(separator)];
|
|
64
|
+
}
|
|
65
|
+
async function boundedRead(file, limit) {
|
|
66
|
+
const handle = await open(file, "r");
|
|
67
|
+
try {
|
|
68
|
+
const stat = await handle.stat();
|
|
69
|
+
if (!stat.isFile() || stat.size > limit)
|
|
70
|
+
return "";
|
|
71
|
+
const bytes = Buffer.alloc(Math.min(stat.size, limit));
|
|
72
|
+
const { bytesRead } = await handle.read(bytes, 0, bytes.length, 0);
|
|
73
|
+
return bytes.subarray(0, bytesRead).toString("utf8");
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
await handle.close();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** Only the binding owner may choose key/cwd/preset; no cwd-based "latest" search is used here. */
|
|
80
|
+
export async function prepareNativeCliSessionLaunch(config, inputRef, ctx) {
|
|
81
|
+
if (!UUID.test(inputRef.key))
|
|
82
|
+
throw new Error("Invalid native CLI session binding key");
|
|
83
|
+
ctx.signal?.throwIfAborted();
|
|
84
|
+
const ref = { ...inputRef };
|
|
85
|
+
const args = [...(config.args ?? [])];
|
|
86
|
+
const optionArgs = args.slice(0, args.includes("--") ? args.indexOf("--") : args.length);
|
|
87
|
+
const remote = Boolean(ctx.service);
|
|
88
|
+
const exec = async (command) => {
|
|
89
|
+
ctx.signal?.throwIfAborted();
|
|
90
|
+
const result = await ctx.service.execInWorkspace(ctx.cwd, command, { timeoutMs: 5000, signal: ctx.signal });
|
|
91
|
+
ctx.signal?.throwIfAborted();
|
|
92
|
+
if (result.exitCode !== 0)
|
|
93
|
+
throw new Error("Native CLI session storage operation failed");
|
|
94
|
+
return result.stdout.trim();
|
|
95
|
+
};
|
|
96
|
+
const home = remote ? await exec("printf '%s' \"$HOME\"") : homedir();
|
|
97
|
+
if (!home || /[\x00-\x1f\x7f]/.test(home))
|
|
98
|
+
throw new Error("Invalid native CLI session home directory");
|
|
99
|
+
const join = remote ? path.posix.join : path.join;
|
|
100
|
+
const directory = remote
|
|
101
|
+
? join(home, ".pi-web", "native-cli", ref.key)
|
|
102
|
+
: path.resolve(ctx.dataDir, "native-cli", ref.key);
|
|
103
|
+
const eventsDirectory = join(directory, "events");
|
|
104
|
+
if (!ctx.observeOnly && remote) {
|
|
105
|
+
await exec(`umask 077; [ ! -L ${quote(directory)} ] && [ ! -L ${quote(eventsDirectory)} ] && mkdir -p ${quote(eventsDirectory)} && chmod 700 ${quote(directory)} ${quote(eventsDirectory)}`);
|
|
106
|
+
}
|
|
107
|
+
else if (!ctx.observeOnly) {
|
|
108
|
+
await mkdir(eventsDirectory, { recursive: true, mode: 0o700 });
|
|
109
|
+
for (const dir of [directory, eventsDirectory]) {
|
|
110
|
+
if ((await lstat(dir)).isSymbolicLink())
|
|
111
|
+
throw new Error("Native CLI session directory must not be a symlink");
|
|
112
|
+
await chmod(dir, 0o700);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const exists = async (file) => {
|
|
116
|
+
if (remote)
|
|
117
|
+
return (await exec(`if [ -f ${quote(file)} ]; then printf yes; fi`)) === "yes";
|
|
118
|
+
try {
|
|
119
|
+
return (await lstat(file)).isFile();
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
if (error.code === "ENOENT")
|
|
123
|
+
return false;
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
const readEvents = async () => {
|
|
128
|
+
let contents;
|
|
129
|
+
if (remote) {
|
|
130
|
+
const output = await exec(`[ -d ${quote(eventsDirectory)} ] && [ -r ${quote(eventsDirectory)} ] && [ ! -L ${quote(directory)} ] && [ ! -L ${quote(eventsDirectory)} ] || exit 1; n=0; for f in ${quote(eventsDirectory)}/*.json; do [ -f "$f" ] || continue; n=$((n+1)); [ "$n" -le ${NATIVE_CLI_EVENT_LIMIT} ] || break; size=$(wc -c < "$f"); [ "$size" -le ${NATIVE_CLI_EVENT_BYTES} ] || continue; dd if="$f" bs=${NATIVE_CLI_EVENT_BYTES} count=1 2>/dev/null; printf '\\n'; done`);
|
|
131
|
+
contents = output.split("\n");
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
if (ctx.observeOnly &&
|
|
135
|
+
((await lstat(directory)).isSymbolicLink() || (await lstat(eventsDirectory)).isSymbolicLink()))
|
|
136
|
+
throw new Error("Native CLI observer directory must not be a symlink");
|
|
137
|
+
const names = (await readdir(eventsDirectory))
|
|
138
|
+
.filter((name) => EVENT_FILE.test(name))
|
|
139
|
+
.sort()
|
|
140
|
+
.slice(-NATIVE_CLI_EVENT_LIMIT);
|
|
141
|
+
contents = await Promise.all(names.map(async (name) => {
|
|
142
|
+
try {
|
|
143
|
+
return await boundedRead(join(eventsDirectory, name), NATIVE_CLI_EVENT_BYTES);
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
if (error.code === "ENOENT")
|
|
147
|
+
return "";
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
return contents
|
|
153
|
+
.map(parseNativeCliHookEvent)
|
|
154
|
+
.filter((event) => Boolean(event))
|
|
155
|
+
.sort((a, b) => a.eventId.localeCompare(b.eventId));
|
|
156
|
+
};
|
|
157
|
+
const put = async (name, content) => {
|
|
158
|
+
const file = join(directory, name);
|
|
159
|
+
const temporary = file + "." + randomUUID() + ".tmp";
|
|
160
|
+
if (remote)
|
|
161
|
+
await exec(`umask 077; printf '%s' ${quote(content)} > ${quote(temporary)} && chmod 600 ${quote(temporary)} && mv -f ${quote(temporary)} ${quote(file)}`);
|
|
162
|
+
else {
|
|
163
|
+
try {
|
|
164
|
+
if ((await lstat(file)).isSymbolicLink())
|
|
165
|
+
throw new Error("Native CLI hook must not be a symlink");
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
if (error.code !== "ENOENT")
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
await writeFile(temporary, content, { mode: 0o600, flag: "wx" });
|
|
172
|
+
await rename(temporary, file);
|
|
173
|
+
}
|
|
174
|
+
return file.replace(/\\/g, "/");
|
|
175
|
+
};
|
|
176
|
+
let oldEvents = [];
|
|
177
|
+
let observationFailed = false;
|
|
178
|
+
try {
|
|
179
|
+
oldEvents = await readEvents();
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
if (!ctx.observeOnly || ctx.signal?.aborted)
|
|
183
|
+
throw error;
|
|
184
|
+
observationFailed = true;
|
|
185
|
+
}
|
|
186
|
+
let durableId;
|
|
187
|
+
const bindingFile = join(directory, "native-id");
|
|
188
|
+
try {
|
|
189
|
+
if (remote)
|
|
190
|
+
durableId = await exec(`if [ ! -L ${quote(directory)} ] && [ ! -L ${quote(bindingFile)} ] && [ -f ${quote(bindingFile)} ]; then size=$(wc -c < ${quote(bindingFile)}); [ "$size" -gt 1024 ] || dd if=${quote(bindingFile)} bs=1024 count=1 2>/dev/null; fi`);
|
|
191
|
+
else if (!(await lstat(directory)).isSymbolicLink() && !(await lstat(bindingFile)).isSymbolicLink())
|
|
192
|
+
durableId = await boundedRead(bindingFile, 1024);
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
if (ctx.signal?.aborted || (!ctx.observeOnly && error.code !== "ENOENT"))
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
if (durableId && /[\x00-\x1f\x7f]/.test(durableId))
|
|
199
|
+
durableId = undefined;
|
|
200
|
+
const explicit = config.preset === "claude"
|
|
201
|
+
? flag(optionArgs, ["--session-id", "--resume", "-r", "--continue", "-c"])
|
|
202
|
+
: config.preset === "codex"
|
|
203
|
+
? codexSubcommand(optionArgs) >= 0
|
|
204
|
+
: config.preset === "pi"
|
|
205
|
+
? flag(optionArgs, [
|
|
206
|
+
"--session",
|
|
207
|
+
"--session-id",
|
|
208
|
+
"--continue",
|
|
209
|
+
"-c",
|
|
210
|
+
"--resume",
|
|
211
|
+
"-r",
|
|
212
|
+
"--fork",
|
|
213
|
+
"--no-session",
|
|
214
|
+
])
|
|
215
|
+
: flag(optionArgs, ["--conversation", "--continue", "-c"]);
|
|
216
|
+
const recoveredId = durableId ||
|
|
217
|
+
[...oldEvents].reverse().find((event) => event.type === "session" && event.nativeId)?.nativeId ||
|
|
218
|
+
[...oldEvents].reverse().find((event) => event.nativeId)?.nativeId;
|
|
219
|
+
const launchOptions = [];
|
|
220
|
+
let capabilities = { resume: "none", events: "process" };
|
|
221
|
+
let observedId = ref.nativeId;
|
|
222
|
+
let acceptsEvents = false;
|
|
223
|
+
let confirmNativeId = async (_id) => true;
|
|
224
|
+
const scriptDirectory = directory.replace(/\\/g, "/");
|
|
225
|
+
const reporter = async () => `sh ${quote(await put("hook.sh", nativeCliPosixReporter(scriptDirectory)))}`;
|
|
226
|
+
if (ctx.observeOnly) {
|
|
227
|
+
if (durableId)
|
|
228
|
+
ref.nativeId = durableId;
|
|
229
|
+
observedId = ref.nativeId;
|
|
230
|
+
capabilities = {
|
|
231
|
+
resume: config.preset === "custom" ? "none" : config.preset === "agy" || !ref.nativeId ? "explicit-only" : "exact",
|
|
232
|
+
events: observationFailed ? "process" : "hooks",
|
|
233
|
+
};
|
|
234
|
+
acceptsEvents = true;
|
|
235
|
+
}
|
|
236
|
+
else if (config.preset === "claude") {
|
|
237
|
+
capabilities.resume = "exact";
|
|
238
|
+
const explicitId = flagValue(optionArgs, ["--session-id", "--resume", "-r"]);
|
|
239
|
+
if (explicit && (!explicitId || !UUID.test(explicitId)))
|
|
240
|
+
capabilities.resume = "explicit-only";
|
|
241
|
+
if (explicitId && UUID.test(explicitId))
|
|
242
|
+
observedId = explicitId;
|
|
243
|
+
let id = !explicit ? (ref.nativeId ?? ref.key) : explicitId;
|
|
244
|
+
if (id && !UUID.test(id))
|
|
245
|
+
throw new Error("Invalid bound Claude session ID");
|
|
246
|
+
const claudeRecord = async (nativeId) => {
|
|
247
|
+
const claudeHome = remote
|
|
248
|
+
? await exec("printf '%s' \"${CLAUDE_CONFIG_DIR:-$HOME/.claude}\"")
|
|
249
|
+
: process.env.CLAUDE_CONFIG_DIR || join(home, ".claude");
|
|
250
|
+
const projects = join(claudeHome, "projects");
|
|
251
|
+
if (remote)
|
|
252
|
+
return ((await exec(`for f in ${quote(projects)}/*/${quote(nativeId + ".jsonl")}; do if [ -f "$f" ]; then printf yes; break; fi; done`)) === "yes");
|
|
253
|
+
try {
|
|
254
|
+
for (const project of await readdir(projects))
|
|
255
|
+
if (await exists(join(projects, project, nativeId + ".jsonl")))
|
|
256
|
+
return true;
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
if (error.code === "ENOENT")
|
|
261
|
+
return false;
|
|
262
|
+
throw error;
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
confirmNativeId = claudeRecord;
|
|
266
|
+
if (!explicit) {
|
|
267
|
+
const candidate = durableId || (!ref.nativeId ? recoveredId : undefined);
|
|
268
|
+
if (candidate && UUID.test(candidate) && (await claudeRecord(candidate)))
|
|
269
|
+
id = candidate;
|
|
270
|
+
const persisted = await claudeRecord(id);
|
|
271
|
+
if (ref.nativeId && !persisted)
|
|
272
|
+
throw new Error("Bound Claude session no longer exists; create a new CLI conversation to start over");
|
|
273
|
+
if (persisted)
|
|
274
|
+
ref.nativeId = id;
|
|
275
|
+
launchOptions.push(persisted ? "--resume" : "--session-id", id);
|
|
276
|
+
}
|
|
277
|
+
// A second --settings flag would replace the user's explicit settings argument.
|
|
278
|
+
if (!flag(optionArgs, ["--settings", "--disable-hooks", "--bare"])) {
|
|
279
|
+
const command = await reporter();
|
|
280
|
+
const hook = (type, matcher) => [
|
|
281
|
+
{ ...(matcher ? { matcher } : {}), hooks: [{ type: "command", command: `${command} ${type}`, timeout: 5 }] },
|
|
282
|
+
];
|
|
283
|
+
launchOptions.push("--settings", JSON.stringify({
|
|
284
|
+
hooks: {
|
|
285
|
+
SessionStart: hook("session"),
|
|
286
|
+
UserPromptSubmit: hook("submitted"),
|
|
287
|
+
Stop: hook("done"),
|
|
288
|
+
PermissionRequest: hook("approval"),
|
|
289
|
+
Notification: hook("notification"),
|
|
290
|
+
StopFailure: hook("error"),
|
|
291
|
+
},
|
|
292
|
+
}));
|
|
293
|
+
capabilities.events = "hooks";
|
|
294
|
+
acceptsEvents = true;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
else if (config.preset === "pi") {
|
|
298
|
+
capabilities.resume = explicit && !flagValue(optionArgs, ["--session", "--session-id"]) ? "explicit-only" : "exact";
|
|
299
|
+
if (!explicit) {
|
|
300
|
+
ref.storeDir ??= join(directory, "sessions");
|
|
301
|
+
if (remote)
|
|
302
|
+
await exec(`umask 077; mkdir -p ${quote(ref.storeDir)} && chmod 700 ${quote(ref.storeDir)}`);
|
|
303
|
+
else {
|
|
304
|
+
await mkdir(ref.storeDir, { recursive: true, mode: 0o700 });
|
|
305
|
+
await chmod(ref.storeDir, 0o700);
|
|
306
|
+
}
|
|
307
|
+
let sessionPath = ref.nativeId ?? join(ref.storeDir, "session.jsonl");
|
|
308
|
+
const candidate = durableId || (!ref.nativeId ? recoveredId : undefined);
|
|
309
|
+
if (candidate && (await exists(candidate)))
|
|
310
|
+
sessionPath = candidate;
|
|
311
|
+
if (ref.nativeId && !(await exists(sessionPath)))
|
|
312
|
+
throw new Error("Bound Pi session no longer exists; create a new CLI conversation to start over");
|
|
313
|
+
if (await exists(sessionPath))
|
|
314
|
+
ref.nativeId = sessionPath;
|
|
315
|
+
launchOptions.push("--session-dir", ref.storeDir, "--session", sessionPath);
|
|
316
|
+
}
|
|
317
|
+
if (!flag(optionArgs, ["--no-extensions", "-ne"])) {
|
|
318
|
+
launchOptions.push("--extension", await put("pi-extension.mjs", nativeCliPiExtension(scriptDirectory)));
|
|
319
|
+
capabilities.events = "hooks";
|
|
320
|
+
acceptsEvents = true;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
else if (config.preset === "codex") {
|
|
324
|
+
const conflicts = new Set();
|
|
325
|
+
const configFiles = [join(process.env.CODEX_HOME || join(home, ".codex"), "config.toml")];
|
|
326
|
+
if (remote) {
|
|
327
|
+
const found = await exec(`scan() { [ -f "$1" ] || return 0; for ev in ${EVENTS.join(" ")}; do if grep -q "$ev" "$1"; then printf '%s\\n' "$ev"; fi; done; }; scan "\${CODEX_HOME:-$HOME/.codex}/config.toml"; d=$PWD; n=0; while [ "$n" -lt 32 ]; do scan "$d/.codex/config.toml"; [ "$d" = / ] && break; d=\${d%/*}; [ -n "$d" ] || d=/; n=$((n+1)); done`);
|
|
328
|
+
for (const name of found.split("\n"))
|
|
329
|
+
if (EVENTS.includes(name))
|
|
330
|
+
conflicts.add(name);
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
let current = path.resolve(ctx.cwd);
|
|
334
|
+
for (let depth = 0; depth < 32; depth++) {
|
|
335
|
+
configFiles.push(join(current, ".codex", "config.toml"));
|
|
336
|
+
const parent = path.dirname(current);
|
|
337
|
+
if (parent === current)
|
|
338
|
+
break;
|
|
339
|
+
current = parent;
|
|
340
|
+
}
|
|
341
|
+
for (const file of configFiles) {
|
|
342
|
+
try {
|
|
343
|
+
if ((await lstat(file)).size > 256 * 1024) {
|
|
344
|
+
for (const event of EVENTS)
|
|
345
|
+
conflicts.add(event);
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
for (const event of nativeCliCodexHookConflicts(await boundedRead(file, 256 * 1024)))
|
|
349
|
+
conflicts.add(event);
|
|
350
|
+
}
|
|
351
|
+
catch (error) {
|
|
352
|
+
if (error.code !== "ENOENT")
|
|
353
|
+
for (const event of EVENTS)
|
|
354
|
+
conflicts.add(event);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
for (const event of nativeCliCodexHookConflicts(optionArgs.join("\n")))
|
|
359
|
+
conflicts.add(event);
|
|
360
|
+
if (!explicit) {
|
|
361
|
+
const candidate = durableId || (!ref.nativeId ? recoveredId : undefined);
|
|
362
|
+
if (candidate && UUID.test(candidate)) {
|
|
363
|
+
const codexHome = remote
|
|
364
|
+
? await exec("printf '%s' \"${CODEX_HOME:-$HOME/.codex}\"")
|
|
365
|
+
: process.env.CODEX_HOME || join(home, ".codex");
|
|
366
|
+
const suffix = candidate.toLowerCase() + ".jsonl";
|
|
367
|
+
let persisted = false;
|
|
368
|
+
if (remote) {
|
|
369
|
+
persisted =
|
|
370
|
+
(await exec(`for f in ${quote(codexHome)}/sessions/*/*/*/rollout-*-${quote(suffix)} ${quote(codexHome)}/archived_sessions/rollout-*-${quote(suffix)}; do if [ -f "$f" ]; then printf yes; break; fi; done`)) === "yes";
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
const patterns = [
|
|
374
|
+
path.join(codexHome, "sessions", "*", "*", "*", "rollout-*-" + suffix),
|
|
375
|
+
path.join(codexHome, "archived_sessions", "rollout-*-" + suffix),
|
|
376
|
+
].map((pattern) => pattern.replace(/\\/g, "/"));
|
|
377
|
+
for await (const file of glob(patterns)) {
|
|
378
|
+
if (await exists(file)) {
|
|
379
|
+
persisted = true;
|
|
380
|
+
break;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (persisted)
|
|
385
|
+
ref.nativeId = candidate;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
const id = ref.nativeId;
|
|
389
|
+
let explicitExact = false;
|
|
390
|
+
if (explicit) {
|
|
391
|
+
const index = codexSubcommand(optionArgs);
|
|
392
|
+
if (index >= 0 && optionArgs[index] === "resume" && UUID.test(optionArgs[index + 1] ?? "")) {
|
|
393
|
+
observedId = optionArgs[index + 1];
|
|
394
|
+
explicitExact = true;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
else if (id) {
|
|
398
|
+
if (!UUID.test(id))
|
|
399
|
+
throw new Error("Invalid bound Codex session ID");
|
|
400
|
+
// Official resume handles an absent exact ID with an error, never --last.
|
|
401
|
+
args.unshift("resume", id);
|
|
402
|
+
}
|
|
403
|
+
const command = await reporter();
|
|
404
|
+
const mappings = [
|
|
405
|
+
["SessionStart", "session"],
|
|
406
|
+
["UserPromptSubmit", "submitted"],
|
|
407
|
+
["PermissionRequest", "approval"],
|
|
408
|
+
["Stop", "done"],
|
|
409
|
+
["PreToolUse", "question", "request_user_input"],
|
|
410
|
+
["PostToolUse", "working", "request_user_input"],
|
|
411
|
+
];
|
|
412
|
+
for (const [event, type, matcher] of mappings) {
|
|
413
|
+
if (conflicts.has(event))
|
|
414
|
+
continue;
|
|
415
|
+
const groups = [
|
|
416
|
+
{ ...(matcher ? { matcher } : {}), hooks: [{ type: "command", command: `${command} ${type}`, timeout: 5 }] },
|
|
417
|
+
];
|
|
418
|
+
const toml = groups
|
|
419
|
+
.map((group) => `{ ${matcher ? `matcher = ${JSON.stringify(matcher)}, ` : ""}hooks = [{ type = "command", command = ${JSON.stringify(group.hooks[0].command)}, timeout = 5 }] }`)
|
|
420
|
+
.join(", ");
|
|
421
|
+
launchOptions.push("--config", `hooks.${event}=[${toml}]`);
|
|
422
|
+
acceptsEvents = true;
|
|
423
|
+
}
|
|
424
|
+
capabilities = {
|
|
425
|
+
resume: explicit && !explicitExact
|
|
426
|
+
? "explicit-only"
|
|
427
|
+
: !conflicts.has("SessionStart") || Boolean(id)
|
|
428
|
+
? "exact"
|
|
429
|
+
: "explicit-only",
|
|
430
|
+
events: !conflicts.has("UserPromptSubmit") && !conflicts.has("Stop") ? "hooks" : "process",
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
else if (config.preset === "agy") {
|
|
434
|
+
capabilities.resume = "explicit-only";
|
|
435
|
+
if (!explicit && ref.nativeId)
|
|
436
|
+
launchOptions.push("--conversation", ref.nativeId);
|
|
437
|
+
}
|
|
438
|
+
if (!explicit)
|
|
439
|
+
observedId = ref.nativeId;
|
|
440
|
+
ctx.signal?.throwIfAborted();
|
|
441
|
+
let stopped = true;
|
|
442
|
+
let disposed = false;
|
|
443
|
+
let timer;
|
|
444
|
+
let pending;
|
|
445
|
+
let generation = 0;
|
|
446
|
+
const lastIndex = ctx.lastEventId
|
|
447
|
+
? oldEvents.findIndex((event) => event.eventId === ctx.lastEventId || event.eventId + ":session" === ctx.lastEventId)
|
|
448
|
+
: -1;
|
|
449
|
+
const historicalCutoff = ctx.lastEventId
|
|
450
|
+
? lastIndex < 0
|
|
451
|
+
? 0
|
|
452
|
+
: lastIndex + (ctx.lastEventId.endsWith(":session") && oldEvents[lastIndex].type !== "session" ? 0 : 1)
|
|
453
|
+
: oldEvents.length;
|
|
454
|
+
const seen = new Set(oldEvents.slice(0, historicalCutoff).map((event) => event.eventId));
|
|
455
|
+
if (!ctx.observeOnly) {
|
|
456
|
+
for (const event of oldEvents) {
|
|
457
|
+
if (["working", "question", "approval"].includes(event.type) || (event.type === "session" && ref.nativeId))
|
|
458
|
+
seen.add(event.eventId);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
const emit = (event) => {
|
|
462
|
+
if (stopped || disposed || ctx.signal?.aborted)
|
|
463
|
+
return;
|
|
464
|
+
try {
|
|
465
|
+
ctx.onEvent(event);
|
|
466
|
+
}
|
|
467
|
+
catch { }
|
|
468
|
+
};
|
|
469
|
+
const stop = () => {
|
|
470
|
+
stopped = true;
|
|
471
|
+
generation++;
|
|
472
|
+
if (timer)
|
|
473
|
+
clearTimeout(timer);
|
|
474
|
+
timer = undefined;
|
|
475
|
+
};
|
|
476
|
+
const poll = async (run) => {
|
|
477
|
+
if (stopped || disposed || ctx.signal?.aborted || generation !== run)
|
|
478
|
+
return;
|
|
479
|
+
try {
|
|
480
|
+
const events = await readEvents();
|
|
481
|
+
if (stopped || disposed || ctx.signal?.aborted || generation !== run)
|
|
482
|
+
return;
|
|
483
|
+
for (const event of events) {
|
|
484
|
+
if (seen.has(event.eventId))
|
|
485
|
+
continue;
|
|
486
|
+
// Child agents can inherit hooks. Only an official root SessionStart may switch identity.
|
|
487
|
+
if (event.nativeId && observedId && event.nativeId !== observedId && event.type !== "session") {
|
|
488
|
+
seen.add(event.eventId);
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
if (event.nativeId &&
|
|
492
|
+
event.nativeId !== ref.nativeId &&
|
|
493
|
+
(config.preset === "pi" || UUID.test(event.nativeId)) &&
|
|
494
|
+
(await confirmNativeId(event.nativeId))) {
|
|
495
|
+
if (stopped || disposed || ctx.signal?.aborted || generation !== run)
|
|
496
|
+
return;
|
|
497
|
+
observedId = event.nativeId;
|
|
498
|
+
ref.nativeId = event.nativeId;
|
|
499
|
+
emit({
|
|
500
|
+
type: "session",
|
|
501
|
+
nativeId: event.nativeId,
|
|
502
|
+
eventId: event.eventId + ":session",
|
|
503
|
+
...(event.type === "session" ? { cursor: event.eventId } : {}),
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
if (stopped || disposed || ctx.signal?.aborted || generation !== run)
|
|
507
|
+
return;
|
|
508
|
+
if (event.type === "error")
|
|
509
|
+
emit({
|
|
510
|
+
type: "error",
|
|
511
|
+
code: "cli_error",
|
|
512
|
+
message: "Native CLI reported a failed turn",
|
|
513
|
+
eventId: event.eventId,
|
|
514
|
+
});
|
|
515
|
+
else if (event.type === "done")
|
|
516
|
+
emit({ type: "done", eventId: event.eventId, ...(event.aborted ? { aborted: true } : {}) });
|
|
517
|
+
else if (event.type !== "session")
|
|
518
|
+
emit({ type: event.type, eventId: event.eventId });
|
|
519
|
+
if (stopped || disposed || ctx.signal?.aborted || generation !== run)
|
|
520
|
+
return;
|
|
521
|
+
seen.add(event.eventId);
|
|
522
|
+
}
|
|
523
|
+
if (seen.size > NATIVE_CLI_EVENT_LIMIT * 4) {
|
|
524
|
+
seen.clear();
|
|
525
|
+
for (const event of events)
|
|
526
|
+
seen.add(event.eventId);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
catch {
|
|
530
|
+
if (!stopped && !disposed && !ctx.signal?.aborted && generation === run)
|
|
531
|
+
emit({
|
|
532
|
+
type: "error",
|
|
533
|
+
eventId: nativeCliEventId(`${ref.key}:observer`),
|
|
534
|
+
code: "event_observer",
|
|
535
|
+
message: "Native CLI lifecycle event observation failed",
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
finally {
|
|
539
|
+
if (!stopped && !disposed && !ctx.signal?.aborted && generation === run) {
|
|
540
|
+
timer = setTimeout(() => {
|
|
541
|
+
queuePoll(run);
|
|
542
|
+
}, remote ? 1500 : 350);
|
|
543
|
+
timer.unref();
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
const queuePoll = (run) => {
|
|
548
|
+
pending = (pending ?? Promise.resolve()).then(() => {
|
|
549
|
+
if (timer)
|
|
550
|
+
clearTimeout(timer);
|
|
551
|
+
timer = undefined;
|
|
552
|
+
return poll(run);
|
|
553
|
+
});
|
|
554
|
+
return pending;
|
|
555
|
+
};
|
|
556
|
+
ctx.signal?.addEventListener("abort", stop, { once: true });
|
|
557
|
+
return {
|
|
558
|
+
config: ctx.observeOnly ? config : { ...config, args: addOptions(args, launchOptions) },
|
|
559
|
+
ref,
|
|
560
|
+
capabilities,
|
|
561
|
+
start() {
|
|
562
|
+
if (disposed || ctx.signal?.aborted || !acceptsEvents)
|
|
563
|
+
return () => { };
|
|
564
|
+
stop();
|
|
565
|
+
stopped = false;
|
|
566
|
+
const run = generation;
|
|
567
|
+
queuePoll(run);
|
|
568
|
+
return () => {
|
|
569
|
+
if (generation === run)
|
|
570
|
+
stop();
|
|
571
|
+
};
|
|
572
|
+
},
|
|
573
|
+
async flush() {
|
|
574
|
+
if (stopped || disposed || ctx.signal?.aborted || !acceptsEvents)
|
|
575
|
+
return;
|
|
576
|
+
await queuePoll(generation);
|
|
577
|
+
},
|
|
578
|
+
async dispose() {
|
|
579
|
+
disposed = true;
|
|
580
|
+
stop();
|
|
581
|
+
ctx.signal?.removeEventListener("abort", stop);
|
|
582
|
+
await pending;
|
|
583
|
+
},
|
|
584
|
+
};
|
|
585
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { normalizePathKey } from "./client-state.js";
|
|
3
|
+
export const NATIVE_CLI_STATE_ENTRY = "webui/native-cli-state";
|
|
4
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
5
|
+
const CONTROL = /[\x00-\x1f\x7f-\x9f]/;
|
|
6
|
+
export function isNativeCliStagingPath(value) {
|
|
7
|
+
return typeof value === "string" && /^\/tmp\/pi-native-cli-[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/.test(value);
|
|
8
|
+
}
|
|
9
|
+
function identifier(value, max = 4096) {
|
|
10
|
+
return typeof value === "string" && value.length > 0 && value.length <= max && !CONTROL.test(value);
|
|
11
|
+
}
|
|
12
|
+
export function createNativeCliBinding(config, cwd) {
|
|
13
|
+
return { version: 1, key: randomUUID(), preset: config.preset, cwd, seenEventIds: [] };
|
|
14
|
+
}
|
|
15
|
+
export function readNativeCliBinding(manager, config, cwd) {
|
|
16
|
+
const entry = [...manager.getEntries()]
|
|
17
|
+
.reverse()
|
|
18
|
+
.find((item) => item.type === "custom" && item.customType === NATIVE_CLI_STATE_ENTRY);
|
|
19
|
+
if (!entry || entry.type !== "custom")
|
|
20
|
+
return undefined;
|
|
21
|
+
const value = entry.data;
|
|
22
|
+
if (!value ||
|
|
23
|
+
value.version !== 1 ||
|
|
24
|
+
!identifier(value.key, 36) ||
|
|
25
|
+
!UUID.test(value.key) ||
|
|
26
|
+
value.preset !== config.preset ||
|
|
27
|
+
!identifier(value.cwd) ||
|
|
28
|
+
normalizePathKey(value.cwd) !== normalizePathKey(cwd) ||
|
|
29
|
+
(value.nativeId !== undefined && !identifier(value.nativeId)) ||
|
|
30
|
+
(value.processId !== undefined && (typeof value.processId !== "string" || !UUID.test(value.processId))) ||
|
|
31
|
+
(value.lastEventId !== undefined && !identifier(value.lastEventId, 512)) ||
|
|
32
|
+
!Array.isArray(value.seenEventIds) ||
|
|
33
|
+
value.seenEventIds.length > 256 ||
|
|
34
|
+
!value.seenEventIds.every((id) => identifier(id, 512)) ||
|
|
35
|
+
(value.stagingPaths !== undefined &&
|
|
36
|
+
(!Array.isArray(value.stagingPaths) ||
|
|
37
|
+
value.stagingPaths.length > 2048 ||
|
|
38
|
+
!value.stagingPaths.every(isNativeCliStagingPath))))
|
|
39
|
+
throw new Error("Invalid native CLI session binding or workspace mismatch");
|
|
40
|
+
return {
|
|
41
|
+
version: 1,
|
|
42
|
+
key: value.key,
|
|
43
|
+
preset: config.preset,
|
|
44
|
+
cwd,
|
|
45
|
+
...(value.nativeId ? { nativeId: value.nativeId } : {}),
|
|
46
|
+
...(value.processId ? { processId: value.processId } : {}),
|
|
47
|
+
...(value.lastEventId ? { lastEventId: value.lastEventId } : {}),
|
|
48
|
+
seenEventIds: [...value.seenEventIds],
|
|
49
|
+
...(value.stagingPaths?.length ? { stagingPaths: [...value.stagingPaths] } : {}),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export function persistNativeCliBinding(manager, binding) {
|
|
53
|
+
const data = {
|
|
54
|
+
version: 1,
|
|
55
|
+
key: binding.key,
|
|
56
|
+
preset: binding.preset,
|
|
57
|
+
cwd: binding.cwd,
|
|
58
|
+
...(binding.nativeId ? { nativeId: binding.nativeId } : {}),
|
|
59
|
+
...(binding.processId ? { processId: binding.processId } : {}),
|
|
60
|
+
...(binding.lastEventId ? { lastEventId: binding.lastEventId } : {}),
|
|
61
|
+
seenEventIds: binding.seenEventIds.slice(-256),
|
|
62
|
+
...(binding.stagingPaths?.length ? { stagingPaths: [...binding.stagingPaths] } : {}),
|
|
63
|
+
};
|
|
64
|
+
const previous = [...manager.getEntries()]
|
|
65
|
+
.reverse()
|
|
66
|
+
.find((entry) => entry.type === "custom" && entry.customType === NATIVE_CLI_STATE_ENTRY);
|
|
67
|
+
if (previous?.type === "custom" && JSON.stringify(previous.data) === JSON.stringify(data))
|
|
68
|
+
return;
|
|
69
|
+
manager.appendCustomEntry(NATIVE_CLI_STATE_ENTRY, data);
|
|
70
|
+
}
|
|
71
|
+
export function acceptNativeCliEvent(binding, eventId, advanceCursor = true, cursor = eventId) {
|
|
72
|
+
if (!identifier(eventId, 512) ||
|
|
73
|
+
(advanceCursor && !identifier(cursor, 512)) ||
|
|
74
|
+
binding.seenEventIds.includes(eventId))
|
|
75
|
+
return false;
|
|
76
|
+
if (advanceCursor)
|
|
77
|
+
binding.lastEventId = cursor;
|
|
78
|
+
binding.seenEventIds.push(eventId);
|
|
79
|
+
if (binding.seenEventIds.length > 256)
|
|
80
|
+
binding.seenEventIds.splice(0, binding.seenEventIds.length - 256);
|
|
81
|
+
return true;
|
|
82
|
+
}
|