@pellux/goodvibes-agent 0.1.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/.goodvibes/GOODVIBES.md +35 -0
- package/.goodvibes/agents/reviewer.md +48 -0
- package/.goodvibes/skills/add-provider/SKILL.md +199 -0
- package/CHANGELOG.md +25 -0
- package/README.md +74 -0
- package/bin/goodvibes-agent.ts +2 -0
- package/docs/README.md +23 -0
- package/docs/deployment-and-services.md +57 -0
- package/docs/getting-started.md +53 -0
- package/docs/release-and-publishing.md +46 -0
- package/package.json +134 -0
- package/scripts/check-bun.sh +20 -0
- package/src/audio/player.ts +156 -0
- package/src/audio/spoken-turn-controller.ts +203 -0
- package/src/audio/spoken-turn-model-routing.ts +117 -0
- package/src/audio/spoken-turn-wiring.ts +44 -0
- package/src/audio/text-chunker.ts +110 -0
- package/src/cli/bundle-command.ts +227 -0
- package/src/cli/completion.ts +90 -0
- package/src/cli/config-overrides.ts +159 -0
- package/src/cli/endpoints.ts +63 -0
- package/src/cli/entrypoint.ts +172 -0
- package/src/cli/help.ts +299 -0
- package/src/cli/index.ts +11 -0
- package/src/cli/management-commands.ts +426 -0
- package/src/cli/management.ts +744 -0
- package/src/cli/network-posture.ts +46 -0
- package/src/cli/package-verification.ts +123 -0
- package/src/cli/parser.ts +369 -0
- package/src/cli/provider-auth-routes.ts +22 -0
- package/src/cli/provider-classification.ts +107 -0
- package/src/cli/redaction.ts +105 -0
- package/src/cli/service-command.ts +26 -0
- package/src/cli/service-posture.ts +482 -0
- package/src/cli/status.ts +383 -0
- package/src/cli/surface-command.ts +247 -0
- package/src/cli/tui-startup.ts +32 -0
- package/src/cli/types.ts +69 -0
- package/src/cli-flags.ts +21 -0
- package/src/config/goodvibes-home-audit.ts +465 -0
- package/src/config/index.ts +57 -0
- package/src/config/provider-model.ts +23 -0
- package/src/config/secret-config.ts +119 -0
- package/src/config/secrets.ts +71 -0
- package/src/config/surface.ts +1 -0
- package/src/core/composer-state.ts +61 -0
- package/src/core/conversation-rendering.ts +359 -0
- package/src/core/conversation.ts +551 -0
- package/src/core/history.ts +45 -0
- package/src/core/orchestrator.ts +7 -0
- package/src/core/system-message-router.ts +171 -0
- package/src/daemon/cli.ts +55 -0
- package/src/daemon/safe-serve.ts +61 -0
- package/src/input/agent-workspace.ts +428 -0
- package/src/input/autocomplete.ts +96 -0
- package/src/input/bookmark-modal.ts +115 -0
- package/src/input/command-args-hint.ts +36 -0
- package/src/input/command-registry.ts +329 -0
- package/src/input/commands/agent-externalized-tui.ts +73 -0
- package/src/input/commands/agent-workspace-runtime.ts +17 -0
- package/src/input/commands/branch-runtime.ts +72 -0
- package/src/input/commands/cloudflare-runtime.ts +370 -0
- package/src/input/commands/config.ts +18 -0
- package/src/input/commands/control-room-runtime.ts +255 -0
- package/src/input/commands/conversation-runtime.ts +207 -0
- package/src/input/commands/discovery-runtime.ts +52 -0
- package/src/input/commands/eval.ts +204 -0
- package/src/input/commands/experience-runtime.ts +278 -0
- package/src/input/commands/guidance-runtime.ts +106 -0
- package/src/input/commands/health-runtime.ts +434 -0
- package/src/input/commands/hooks-runtime.ts +148 -0
- package/src/input/commands/incident-runtime.ts +95 -0
- package/src/input/commands/integration-runtime.ts +394 -0
- package/src/input/commands/intelligence-runtime.ts +223 -0
- package/src/input/commands/knowledge.ts +531 -0
- package/src/input/commands/local-auth-runtime.ts +105 -0
- package/src/input/commands/local-provider-runtime.ts +170 -0
- package/src/input/commands/local-runtime.ts +392 -0
- package/src/input/commands/local-setup-review.ts +199 -0
- package/src/input/commands/local-setup-transfer.ts +135 -0
- package/src/input/commands/local-setup.ts +282 -0
- package/src/input/commands/managed-runtime.ts +209 -0
- package/src/input/commands/marketplace-runtime.ts +290 -0
- package/src/input/commands/mcp-runtime.ts +432 -0
- package/src/input/commands/memory-product-runtime.ts +111 -0
- package/src/input/commands/memory.ts +151 -0
- package/src/input/commands/notify-runtime.ts +83 -0
- package/src/input/commands/onboarding-runtime.ts +14 -0
- package/src/input/commands/operator-panel-runtime.ts +146 -0
- package/src/input/commands/operator-runtime.ts +392 -0
- package/src/input/commands/planning-runtime.ts +205 -0
- package/src/input/commands/platform-access-runtime.ts +422 -0
- package/src/input/commands/platform-services-runtime.ts +246 -0
- package/src/input/commands/policy-dispatch.ts +339 -0
- package/src/input/commands/policy.ts +17 -0
- package/src/input/commands/product-runtime.ts +351 -0
- package/src/input/commands/profile-sync-runtime.ts +99 -0
- package/src/input/commands/provider-accounts-runtime.ts +113 -0
- package/src/input/commands/provider.ts +363 -0
- package/src/input/commands/qrcode-runtime.ts +20 -0
- package/src/input/commands/quit-shared.ts +162 -0
- package/src/input/commands/recall-bundle.ts +132 -0
- package/src/input/commands/recall-capture.ts +152 -0
- package/src/input/commands/recall-query.ts +229 -0
- package/src/input/commands/recall-review.ts +98 -0
- package/src/input/commands/recall-shared.ts +22 -0
- package/src/input/commands/remote-runtime-pool.ts +106 -0
- package/src/input/commands/remote-runtime-setup.ts +199 -0
- package/src/input/commands/remote-runtime.ts +431 -0
- package/src/input/commands/replay-runtime.ts +18 -0
- package/src/input/commands/runtime-services.ts +291 -0
- package/src/input/commands/schedule-runtime.ts +91 -0
- package/src/input/commands/services-runtime.ts +209 -0
- package/src/input/commands/session-content.ts +408 -0
- package/src/input/commands/session-workflow.ts +464 -0
- package/src/input/commands/session.ts +375 -0
- package/src/input/commands/settings-sync-runtime.ts +174 -0
- package/src/input/commands/share-runtime.ts +119 -0
- package/src/input/commands/shell-core.ts +307 -0
- package/src/input/commands/skills-runtime.ts +221 -0
- package/src/input/commands/subscription-runtime.ts +434 -0
- package/src/input/commands/tasks-runtime.ts +230 -0
- package/src/input/commands/teamwork-runtime.ts +339 -0
- package/src/input/commands/teleport-runtime.ts +57 -0
- package/src/input/commands/tts-runtime.ts +29 -0
- package/src/input/commands/work-plan-runtime.ts +169 -0
- package/src/input/commands.ts +131 -0
- package/src/input/feed-context-factory.ts +254 -0
- package/src/input/file-picker.ts +192 -0
- package/src/input/handler-command-route.ts +180 -0
- package/src/input/handler-content-actions.ts +497 -0
- package/src/input/handler-feed-routes.ts +648 -0
- package/src/input/handler-feed.ts +452 -0
- package/src/input/handler-interactions.ts +281 -0
- package/src/input/handler-modal-routes.ts +418 -0
- package/src/input/handler-modal-stack.ts +263 -0
- package/src/input/handler-modal-token-routes.ts +329 -0
- package/src/input/handler-onboarding-cloudflare.ts +391 -0
- package/src/input/handler-onboarding.ts +620 -0
- package/src/input/handler-picker-routes.ts +472 -0
- package/src/input/handler-prompt-buffer.ts +320 -0
- package/src/input/handler-shortcuts.ts +213 -0
- package/src/input/handler-ui-state.ts +372 -0
- package/src/input/handler.ts +729 -0
- package/src/input/input-history.ts +297 -0
- package/src/input/keybindings.ts +292 -0
- package/src/input/mcp-workspace.ts +554 -0
- package/src/input/model-picker-provider-filter.ts +28 -0
- package/src/input/model-picker-types.ts +137 -0
- package/src/input/model-picker.ts +797 -0
- package/src/input/onboarding/handler-onboarding-routes.ts +125 -0
- package/src/input/onboarding/onboarding-runtime-status.ts +87 -0
- package/src/input/onboarding/onboarding-wizard-apply.ts +277 -0
- package/src/input/onboarding/onboarding-wizard-cloudflare-step.ts +494 -0
- package/src/input/onboarding/onboarding-wizard-cloudflare.ts +204 -0
- package/src/input/onboarding/onboarding-wizard-constants.ts +158 -0
- package/src/input/onboarding/onboarding-wizard-external-surface-extra-specs.ts +130 -0
- package/src/input/onboarding/onboarding-wizard-external-surfaces.ts +762 -0
- package/src/input/onboarding/onboarding-wizard-helpers.ts +167 -0
- package/src/input/onboarding/onboarding-wizard-rules.ts +256 -0
- package/src/input/onboarding/onboarding-wizard-state.ts +365 -0
- package/src/input/onboarding/onboarding-wizard-steps.ts +798 -0
- package/src/input/onboarding/onboarding-wizard-types.ts +195 -0
- package/src/input/onboarding/onboarding-wizard.ts +711 -0
- package/src/input/panel-integration-actions.ts +78 -0
- package/src/input/profile-picker-modal.ts +222 -0
- package/src/input/search.ts +100 -0
- package/src/input/selection-modal.ts +163 -0
- package/src/input/selection.ts +135 -0
- package/src/input/session-picker-modal.ts +136 -0
- package/src/input/settings-modal-behavior.ts +37 -0
- package/src/input/settings-modal-secrets.ts +41 -0
- package/src/input/settings-modal-subscriptions.ts +95 -0
- package/src/input/settings-modal-types.ts +91 -0
- package/src/input/settings-modal.ts +793 -0
- package/src/input/submission-intent.ts +17 -0
- package/src/input/submission-router.ts +59 -0
- package/src/input/tts-settings-actions.ts +100 -0
- package/src/main.ts +792 -0
- package/src/mcp/runtime-reload.ts +81 -0
- package/src/panels/agent-inspector-panel.ts +521 -0
- package/src/panels/agent-inspector-shared.ts +94 -0
- package/src/panels/agent-logs-panel.ts +559 -0
- package/src/panels/agent-logs-shared.ts +129 -0
- package/src/panels/approval-panel.ts +150 -0
- package/src/panels/automation-control-panel.ts +212 -0
- package/src/panels/base-panel.ts +254 -0
- package/src/panels/builtin/agent.ts +117 -0
- package/src/panels/builtin/development.ts +31 -0
- package/src/panels/builtin/knowledge.ts +26 -0
- package/src/panels/builtin/operations.ts +349 -0
- package/src/panels/builtin/session.ts +129 -0
- package/src/panels/builtin/shared.ts +274 -0
- package/src/panels/builtin-panels.ts +23 -0
- package/src/panels/cockpit-panel.ts +183 -0
- package/src/panels/communication-panel.ts +153 -0
- package/src/panels/confirm-state.ts +61 -0
- package/src/panels/context-visualizer-panel.ts +204 -0
- package/src/panels/control-plane-panel.ts +211 -0
- package/src/panels/cost-tracker-panel.ts +444 -0
- package/src/panels/debug-panel.ts +432 -0
- package/src/panels/diff-panel.ts +520 -0
- package/src/panels/docs-panel.ts +283 -0
- package/src/panels/eval-panel.ts +399 -0
- package/src/panels/file-explorer-panel.ts +584 -0
- package/src/panels/file-preview-panel.ts +434 -0
- package/src/panels/forensics-panel.ts +364 -0
- package/src/panels/git-panel.ts +638 -0
- package/src/panels/hooks-panel.ts +239 -0
- package/src/panels/incident-review-panel.ts +197 -0
- package/src/panels/index.ts +46 -0
- package/src/panels/intelligence-panel.ts +176 -0
- package/src/panels/knowledge-panel.ts +345 -0
- package/src/panels/local-auth-panel.ts +130 -0
- package/src/panels/marketplace-panel.ts +212 -0
- package/src/panels/memory-panel.ts +225 -0
- package/src/panels/ops-control-panel.ts +150 -0
- package/src/panels/ops-strategy-panel.ts +235 -0
- package/src/panels/orchestration-panel.ts +273 -0
- package/src/panels/panel-list-panel.ts +509 -0
- package/src/panels/panel-manager.ts +570 -0
- package/src/panels/panel-picker.ts +106 -0
- package/src/panels/plan-dashboard-panel.ts +274 -0
- package/src/panels/plugins-panel.ts +178 -0
- package/src/panels/policy-panel.ts +308 -0
- package/src/panels/polish.ts +717 -0
- package/src/panels/project-planning-panel.ts +711 -0
- package/src/panels/provider-account-snapshot.ts +259 -0
- package/src/panels/provider-accounts-panel.ts +218 -0
- package/src/panels/provider-health-domains.ts +215 -0
- package/src/panels/provider-health-panel.ts +727 -0
- package/src/panels/provider-health-tracker.ts +115 -0
- package/src/panels/provider-stats-panel.ts +366 -0
- package/src/panels/qr-panel.ts +182 -0
- package/src/panels/remote-panel.ts +449 -0
- package/src/panels/routes-panel.ts +178 -0
- package/src/panels/sandbox-panel.ts +283 -0
- package/src/panels/schedule-panel.ts +329 -0
- package/src/panels/scrollable-list-panel.ts +491 -0
- package/src/panels/search-focus.ts +32 -0
- package/src/panels/security-panel.ts +295 -0
- package/src/panels/services-panel.ts +231 -0
- package/src/panels/session-browser-panel.ts +400 -0
- package/src/panels/session-maintenance.ts +125 -0
- package/src/panels/settings-sync-panel.ts +120 -0
- package/src/panels/skills-panel.ts +431 -0
- package/src/panels/subscription-panel.ts +263 -0
- package/src/panels/symbol-outline-panel.ts +486 -0
- package/src/panels/system-messages-panel.ts +230 -0
- package/src/panels/tasks-panel.ts +399 -0
- package/src/panels/thinking-panel.ts +304 -0
- package/src/panels/token-budget-panel.ts +475 -0
- package/src/panels/tool-inspector-panel.ts +429 -0
- package/src/panels/types.ts +54 -0
- package/src/panels/watchers-panel.ts +193 -0
- package/src/panels/work-plan-panel.ts +175 -0
- package/src/panels/worktree-panel.ts +182 -0
- package/src/panels/wrfc-panel.ts +609 -0
- package/src/permissions/prompt.ts +165 -0
- package/src/planning/project-planning-coordinator.ts +543 -0
- package/src/plugins/loader.ts +15 -0
- package/src/renderer/agent-detail-modal.ts +331 -0
- package/src/renderer/agent-workspace.ts +238 -0
- package/src/renderer/ansi-sanitize.ts +76 -0
- package/src/renderer/autocomplete-overlay.ts +154 -0
- package/src/renderer/block-actions.ts +76 -0
- package/src/renderer/bookmark-modal.ts +101 -0
- package/src/renderer/bottom-bar.ts +58 -0
- package/src/renderer/buffer.ts +113 -0
- package/src/renderer/code-block.ts +373 -0
- package/src/renderer/compositor.ts +283 -0
- package/src/renderer/context-inspector.ts +219 -0
- package/src/renderer/conversation-layout.ts +67 -0
- package/src/renderer/conversation-overlays.ts +140 -0
- package/src/renderer/conversation-surface.ts +260 -0
- package/src/renderer/diff-view.ts +132 -0
- package/src/renderer/diff.ts +130 -0
- package/src/renderer/file-picker-overlay.ts +101 -0
- package/src/renderer/file-tree.ts +153 -0
- package/src/renderer/fullscreen-primitives.ts +130 -0
- package/src/renderer/fullscreen-workspace.ts +199 -0
- package/src/renderer/git-status.ts +89 -0
- package/src/renderer/help-overlay.ts +267 -0
- package/src/renderer/history-search-overlay.ts +73 -0
- package/src/renderer/layout-engine.ts +97 -0
- package/src/renderer/layout.ts +32 -0
- package/src/renderer/live-tail-modal.ts +156 -0
- package/src/renderer/markdown.ts +635 -0
- package/src/renderer/mcp-workspace.ts +237 -0
- package/src/renderer/modal-factory.ts +467 -0
- package/src/renderer/modal-utils.ts +24 -0
- package/src/renderer/model-picker-overlay.ts +473 -0
- package/src/renderer/model-workspace.ts +488 -0
- package/src/renderer/onboarding/onboarding-wizard.ts +615 -0
- package/src/renderer/overlay-box.ts +146 -0
- package/src/renderer/overlay-viewport.ts +104 -0
- package/src/renderer/panel-composite.ts +158 -0
- package/src/renderer/panel-picker-overlay.ts +202 -0
- package/src/renderer/panel-tab-bar.ts +69 -0
- package/src/renderer/panel-workspace-bar.ts +42 -0
- package/src/renderer/process-indicator.ts +96 -0
- package/src/renderer/process-modal.ts +656 -0
- package/src/renderer/process-summary.ts +67 -0
- package/src/renderer/profile-picker-modal.ts +129 -0
- package/src/renderer/progress.ts +98 -0
- package/src/renderer/qr-renderer.ts +120 -0
- package/src/renderer/search-overlay.ts +54 -0
- package/src/renderer/selection-modal-overlay.ts +214 -0
- package/src/renderer/semantic-diff.ts +369 -0
- package/src/renderer/session-picker-modal.ts +127 -0
- package/src/renderer/settings-modal-helpers.ts +193 -0
- package/src/renderer/settings-modal.ts +537 -0
- package/src/renderer/shell-surface.ts +88 -0
- package/src/renderer/status-glyphs.ts +21 -0
- package/src/renderer/status-token.ts +67 -0
- package/src/renderer/surface-layout.ts +101 -0
- package/src/renderer/syntax-highlighter.ts +542 -0
- package/src/renderer/system-message.ts +83 -0
- package/src/renderer/tab-strip.ts +108 -0
- package/src/renderer/text-layout.ts +31 -0
- package/src/renderer/thinking.ts +17 -0
- package/src/renderer/tool-call.ts +234 -0
- package/src/renderer/ui-factory.ts +524 -0
- package/src/renderer/ui-primitives.ts +96 -0
- package/src/runtime/bootstrap-command-context.ts +278 -0
- package/src/runtime/bootstrap-command-parts.ts +386 -0
- package/src/runtime/bootstrap-core.ts +540 -0
- package/src/runtime/bootstrap-hook-bridge.ts +112 -0
- package/src/runtime/bootstrap-shell.ts +283 -0
- package/src/runtime/bootstrap.ts +575 -0
- package/src/runtime/cloudflare-control-plane.ts +349 -0
- package/src/runtime/context.ts +142 -0
- package/src/runtime/diagnostics/panels/index.ts +24 -0
- package/src/runtime/diagnostics/panels/ops.ts +156 -0
- package/src/runtime/diagnostics/panels/panel-resources.ts +118 -0
- package/src/runtime/diagnostics/panels/policy.ts +177 -0
- package/src/runtime/index.ts +662 -0
- package/src/runtime/onboarding/apply.ts +642 -0
- package/src/runtime/onboarding/derivation.ts +534 -0
- package/src/runtime/onboarding/index.ts +7 -0
- package/src/runtime/onboarding/markers.ts +148 -0
- package/src/runtime/onboarding/snapshot.ts +406 -0
- package/src/runtime/onboarding/state.ts +141 -0
- package/src/runtime/onboarding/types.ts +404 -0
- package/src/runtime/onboarding/verify.ts +171 -0
- package/src/runtime/operator-token-cleanup.ts +27 -0
- package/src/runtime/perf/panel-contracts.ts +32 -0
- package/src/runtime/perf/panel-health-monitor.ts +18 -0
- package/src/runtime/sandbox-public-gaps.ts +358 -0
- package/src/runtime/services.ts +670 -0
- package/src/runtime/store/domains/domain-read-matrix.ts +15 -0
- package/src/runtime/store/domains/index.ts +222 -0
- package/src/runtime/store/domains/panels.ts +117 -0
- package/src/runtime/store/domains/ui-perf.ts +103 -0
- package/src/runtime/store/index.ts +305 -0
- package/src/runtime/store/selectors/index.ts +359 -0
- package/src/runtime/store/state.ts +145 -0
- package/src/runtime/surface-feature-flags.ts +65 -0
- package/src/runtime/terminal-output-guard.ts +228 -0
- package/src/runtime/ui/index.ts +39 -0
- package/src/runtime/ui/model-picker/data-provider.ts +182 -0
- package/src/runtime/ui/model-picker/health-enrichment.ts +228 -0
- package/src/runtime/ui/model-picker/index.ts +59 -0
- package/src/runtime/ui/model-picker/types.ts +149 -0
- package/src/runtime/ui/provider-health/data-provider.ts +244 -0
- package/src/runtime/ui/provider-health/fallback-visualizer.ts +71 -0
- package/src/runtime/ui/provider-health/index.ts +46 -0
- package/src/runtime/ui/provider-health/types.ts +146 -0
- package/src/runtime/ui-events.ts +1 -0
- package/src/runtime/ui-read-model-helpers.ts +1 -0
- package/src/runtime/ui-read-models-observability-maintenance.ts +1 -0
- package/src/runtime/ui-read-models-observability-options.ts +1 -0
- package/src/runtime/ui-read-models-observability-remote.ts +1 -0
- package/src/runtime/ui-read-models-observability-security.ts +1 -0
- package/src/runtime/ui-read-models-observability-system.ts +1 -0
- package/src/runtime/ui-read-models-observability.ts +1 -0
- package/src/runtime/ui-read-models.ts +61 -0
- package/src/runtime/ui-service-queries.ts +1 -0
- package/src/runtime/ui-services.ts +190 -0
- package/src/scripts/process-messages.ts +42 -0
- package/src/shell/blocking-input.ts +98 -0
- package/src/shell/service-settings-sync.ts +273 -0
- package/src/shell/ui-openers.ts +352 -0
- package/src/tools/index.ts +1 -0
- package/src/tools/wrfc-agent-guard.ts +49 -0
- package/src/types/grid.ts +48 -0
- package/src/types/sql-js.d.ts +15 -0
- package/src/utils/clipboard.ts +22 -0
- package/src/utils/splash-lines.ts +46 -0
- package/src/utils/terminal-width.ts +185 -0
- package/src/verification/live-verifier.ts +430 -0
- package/src/verification/verification-ledger.ts +242 -0
- package/src/version.ts +17 -0
- package/src/widget/index.ts +2 -0
- package/src/widget/types.ts +9 -0
- package/src/widget/widget.ts +8 -0
- package/src/work-plans/work-plan-store.ts +374 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { loadSkillByTrigger } from '@pellux/goodvibes-sdk/platform/tools';
|
|
2
|
+
import type { CommandContext, CommandRegistry } from './command-registry.ts';
|
|
3
|
+
import type { AutocompleteEngine } from './autocomplete.ts';
|
|
4
|
+
import type { InputToken } from '@pellux/goodvibes-sdk/platform/core';
|
|
5
|
+
import type { ConversationManager } from '../core/conversation';
|
|
6
|
+
import type { PanelManager } from '../panels/panel-manager.ts';
|
|
7
|
+
import { handleClipboardPaste, type ClipboardPasteSource } from './handler-content-actions.ts';
|
|
8
|
+
|
|
9
|
+
export type CommandModeRouteState = {
|
|
10
|
+
commandMode: boolean;
|
|
11
|
+
prompt: string;
|
|
12
|
+
cursorPos: number;
|
|
13
|
+
autocomplete: AutocompleteEngine | null;
|
|
14
|
+
modalStack: string[];
|
|
15
|
+
commandRegistry: CommandRegistry | null;
|
|
16
|
+
commandContext?: CommandContext;
|
|
17
|
+
panelFocused: boolean;
|
|
18
|
+
panelManager: PanelManager;
|
|
19
|
+
conversationManager: ConversationManager | null;
|
|
20
|
+
requestRender: () => void;
|
|
21
|
+
handleEscape: () => void;
|
|
22
|
+
projectRoot: string;
|
|
23
|
+
pasteRegistry: Map<string, string>;
|
|
24
|
+
imageRegistry: Map<string, { data: string; mediaType: string }>;
|
|
25
|
+
nextPasteId: number;
|
|
26
|
+
nextImageId: number;
|
|
27
|
+
saveUndoState: () => void;
|
|
28
|
+
ensureInputCursorVisible: () => void;
|
|
29
|
+
clipboard?: ClipboardPasteSource;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export function handleCommandModeToken(state: CommandModeRouteState, token: InputToken): boolean {
|
|
33
|
+
if (!state.commandMode) return false;
|
|
34
|
+
|
|
35
|
+
const closeCommandMode = (): void => {
|
|
36
|
+
state.commandMode = false;
|
|
37
|
+
for (let i = state.modalStack.length - 1; i >= 0; i--) {
|
|
38
|
+
if (state.modalStack[i] === 'command') state.modalStack.splice(i, 1);
|
|
39
|
+
}
|
|
40
|
+
state.autocomplete?.reset();
|
|
41
|
+
state.prompt = '';
|
|
42
|
+
state.cursorPos = 0;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
if (token.type !== 'key') return false;
|
|
46
|
+
|
|
47
|
+
if (token.logicalName === 'escape') {
|
|
48
|
+
state.handleEscape();
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
if (token.logicalName === 'up') {
|
|
52
|
+
state.autocomplete?.moveUp();
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
if (token.logicalName === 'down') {
|
|
56
|
+
state.autocomplete?.moveDown();
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
if (token.logicalName === 'tab') {
|
|
60
|
+
const selected = state.autocomplete?.getSelected();
|
|
61
|
+
if (selected) {
|
|
62
|
+
state.prompt = `/${selected.name} `;
|
|
63
|
+
state.cursorPos = state.prompt.length;
|
|
64
|
+
state.autocomplete?.reset();
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
if (token.logicalName === 'backspace') {
|
|
69
|
+
if (state.cursorPos > 0) {
|
|
70
|
+
state.prompt = state.prompt.slice(0, state.cursorPos - 1) + state.prompt.slice(state.cursorPos);
|
|
71
|
+
state.cursorPos--;
|
|
72
|
+
}
|
|
73
|
+
if (state.prompt === '') {
|
|
74
|
+
closeCommandMode();
|
|
75
|
+
state.autocomplete?.reset();
|
|
76
|
+
} else {
|
|
77
|
+
const query = state.prompt.startsWith('/') ? state.prompt.slice(1) : '';
|
|
78
|
+
const spaceIdx = query.indexOf(' ');
|
|
79
|
+
if (spaceIdx === -1) state.autocomplete?.update(query);
|
|
80
|
+
}
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
if (token.logicalName === 'enter') {
|
|
84
|
+
const selectedCmd = state.autocomplete?.isActive ? state.autocomplete.getSelected() : undefined;
|
|
85
|
+
const raw = selectedCmd ? `/${selectedCmd.name}` : state.prompt.trim();
|
|
86
|
+
if (raw.startsWith('/') && state.commandRegistry && state.commandContext) {
|
|
87
|
+
closeCommandMode();
|
|
88
|
+
const parts = raw.slice(1).trim().split(/\s+/);
|
|
89
|
+
const name = parts[0];
|
|
90
|
+
const args = parts.slice(1);
|
|
91
|
+
const ctx = withPanelFocusSync(state.commandContext, state);
|
|
92
|
+
const commandPromise = state.commandRegistry.get(name)
|
|
93
|
+
? state.commandRegistry.execute(name, args, ctx)
|
|
94
|
+
: (ctx.executeCommand?.(name, args) ?? Promise.resolve(false));
|
|
95
|
+
commandPromise.then((handled) => {
|
|
96
|
+
if (handled) {
|
|
97
|
+
state.requestRender();
|
|
98
|
+
} else {
|
|
99
|
+
const shellPaths = state.commandContext?.workspace.shellPaths;
|
|
100
|
+
const skillContent = shellPaths
|
|
101
|
+
? loadSkillByTrigger('/' + name, {
|
|
102
|
+
workingDirectory: shellPaths.workingDirectory,
|
|
103
|
+
homeDirectory: shellPaths.homeDirectory,
|
|
104
|
+
})
|
|
105
|
+
: null;
|
|
106
|
+
if (skillContent) {
|
|
107
|
+
state.commandContext?.submitInput?.(skillContent);
|
|
108
|
+
} else {
|
|
109
|
+
state.conversationManager?.log(`Unknown command: /${name}. Type /help for available commands.`, { fg: '#ef4444' });
|
|
110
|
+
state.requestRender();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
} else {
|
|
115
|
+
closeCommandMode();
|
|
116
|
+
}
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return token.logicalName !== 'left' && token.logicalName !== 'right';
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function withPanelFocusSync(context: CommandContext, state: CommandModeRouteState): CommandContext {
|
|
124
|
+
const panelIsFocusable = (): boolean =>
|
|
125
|
+
state.panelManager.isVisible() && state.panelManager.getAllOpen().length > 0;
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
...context,
|
|
129
|
+
openPanelPicker: context.openPanelPicker
|
|
130
|
+
? () => {
|
|
131
|
+
context.openPanelPicker?.();
|
|
132
|
+
state.panelFocused = panelIsFocusable();
|
|
133
|
+
}
|
|
134
|
+
: undefined,
|
|
135
|
+
showPanel: context.showPanel
|
|
136
|
+
? (panelId, pane) => {
|
|
137
|
+
context.showPanel?.(panelId, pane);
|
|
138
|
+
state.panelFocused = true;
|
|
139
|
+
}
|
|
140
|
+
: undefined,
|
|
141
|
+
focusPanels: context.focusPanels
|
|
142
|
+
? () => {
|
|
143
|
+
context.focusPanels?.();
|
|
144
|
+
state.panelFocused = panelIsFocusable();
|
|
145
|
+
}
|
|
146
|
+
: undefined,
|
|
147
|
+
focusPrompt: context.focusPrompt
|
|
148
|
+
? () => {
|
|
149
|
+
context.focusPrompt?.();
|
|
150
|
+
state.panelFocused = false;
|
|
151
|
+
}
|
|
152
|
+
: undefined,
|
|
153
|
+
pasteFromClipboard: () => {
|
|
154
|
+
const result = handleClipboardPaste({
|
|
155
|
+
prompt: state.prompt,
|
|
156
|
+
cursorPos: state.cursorPos,
|
|
157
|
+
pasteRegistry: state.pasteRegistry,
|
|
158
|
+
nextPasteId: state.nextPasteId,
|
|
159
|
+
imageRegistry: state.imageRegistry,
|
|
160
|
+
nextImageId: state.nextImageId,
|
|
161
|
+
saveUndoState: state.saveUndoState,
|
|
162
|
+
ensureInputCursorVisible: state.ensureInputCursorVisible,
|
|
163
|
+
requestRender: state.requestRender,
|
|
164
|
+
}, context.workspace.shellPaths?.workingDirectory ?? state.projectRoot, state.clipboard);
|
|
165
|
+
state.prompt = result.prompt;
|
|
166
|
+
state.cursorPos = result.cursorPos;
|
|
167
|
+
state.nextImageId = result.nextImageId;
|
|
168
|
+
state.nextPasteId = result.nextPasteId;
|
|
169
|
+
return result;
|
|
170
|
+
},
|
|
171
|
+
executeCommand: async (name, args) => {
|
|
172
|
+
const wrapped = withPanelFocusSync(context, state);
|
|
173
|
+
const handled = state.commandRegistry?.get(name)
|
|
174
|
+
? await state.commandRegistry.execute(name, args, wrapped)
|
|
175
|
+
: false;
|
|
176
|
+
if (handled) return true;
|
|
177
|
+
return (await context.executeCommand?.(name, args)) ?? false;
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
}
|
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync, existsSync } from 'node:fs';
|
|
2
|
+
import { copyToClipboard, pasteFromClipboard, pasteImageFromClipboard } from '../utils/clipboard.ts';
|
|
3
|
+
import type { InfiniteBuffer } from '../core/history.ts';
|
|
4
|
+
import type { ConversationManager } from '../core/conversation';
|
|
5
|
+
import type { PermissionCategory } from '@pellux/goodvibes-sdk/platform/permissions';
|
|
6
|
+
import type { ContentPart } from '@pellux/goodvibes-sdk/platform/providers';
|
|
7
|
+
import type { CommandContext } from './command-registry.ts';
|
|
8
|
+
import type { BookmarkManager } from '@pellux/goodvibes-sdk/platform/bookmarks';
|
|
9
|
+
import { resolveAndValidatePath } from '@pellux/goodvibes-sdk/platform/utils';
|
|
10
|
+
import { analyzePermissionRequest } from '@pellux/goodvibes-sdk/platform/permissions';
|
|
11
|
+
import { logger } from '@pellux/goodvibes-sdk/platform/utils';
|
|
12
|
+
import type { SelectionManager } from './selection.ts';
|
|
13
|
+
import { summarizeError } from '@pellux/goodvibes-sdk/platform/utils';
|
|
14
|
+
|
|
15
|
+
export const MARKER_REGEX = /\[(TEXT|IMAGE): [^\]]+\]/g;
|
|
16
|
+
|
|
17
|
+
export const IMAGE_PREFIXES: { prefix: string; mediaType: string }[] = [
|
|
18
|
+
{ prefix: 'iVBORw0KGgo', mediaType: 'image/png' },
|
|
19
|
+
{ prefix: '/9j/', mediaType: 'image/jpeg' },
|
|
20
|
+
{ prefix: 'UklGR', mediaType: 'image/webp' },
|
|
21
|
+
{ prefix: 'R0lGOD', mediaType: 'image/gif' },
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
export const BINARY_IMAGE_MAGIC: {
|
|
25
|
+
magic: number[];
|
|
26
|
+
mediaType: string;
|
|
27
|
+
extraCheck?: (b: Buffer) => boolean;
|
|
28
|
+
}[] = [
|
|
29
|
+
{ magic: [0x89, 0x50, 0x4E, 0x47], mediaType: 'image/png' },
|
|
30
|
+
{ magic: [0xFF, 0xD8, 0xFF], mediaType: 'image/jpeg' },
|
|
31
|
+
{ magic: [0x52, 0x49, 0x46, 0x46], mediaType: 'image/webp', extraCheck: (b: Buffer) => b.length > 11 && b[8] === 0x57 && b[9] === 0x45 && b[10] === 0x42 && b[11] === 0x50 },
|
|
32
|
+
{ magic: [0x47, 0x49, 0x46], mediaType: 'image/gif' },
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
export const IMAGE_EXTENSIONS = ['.png', '.jpg', '.jpeg', '.webp', '.gif'];
|
|
36
|
+
|
|
37
|
+
export function formatFileSize(bytes: number): string {
|
|
38
|
+
if (bytes < 1024) return `${bytes}B`;
|
|
39
|
+
if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)}KB`;
|
|
40
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function mediaTypeFromExt(ext: string): string {
|
|
44
|
+
switch (ext.toLowerCase()) {
|
|
45
|
+
case '.png': return 'image/png';
|
|
46
|
+
case '.webp': return 'image/webp';
|
|
47
|
+
case '.gif': return 'image/gif';
|
|
48
|
+
default: return 'image/jpeg';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type PasteRegistryState = {
|
|
53
|
+
pasteRegistry: Map<string, string>;
|
|
54
|
+
nextPasteId: number;
|
|
55
|
+
imageRegistry: Map<string, { data: string; mediaType: string }>;
|
|
56
|
+
nextImageId: number;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type ClipboardPasteKind = 'image' | 'text' | 'none';
|
|
60
|
+
|
|
61
|
+
export interface ClipboardPasteResult {
|
|
62
|
+
prompt: string;
|
|
63
|
+
cursorPos: number;
|
|
64
|
+
nextImageId: number;
|
|
65
|
+
nextPasteId: number;
|
|
66
|
+
pasted: boolean;
|
|
67
|
+
kind: ClipboardPasteKind;
|
|
68
|
+
marker?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface ClipboardPasteSource {
|
|
72
|
+
pasteImageFromClipboard: typeof pasteImageFromClipboard;
|
|
73
|
+
pasteFromClipboard: typeof pasteFromClipboard;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function registerPaste(
|
|
77
|
+
state: PasteRegistryState,
|
|
78
|
+
content: string,
|
|
79
|
+
projectRoot: string,
|
|
80
|
+
): { marker: string; nextPasteId: number; nextImageId: number } {
|
|
81
|
+
const bytes = Buffer.from(content, 'binary');
|
|
82
|
+
if (bytes.length > 100) {
|
|
83
|
+
for (const { magic, mediaType, extraCheck } of BINARY_IMAGE_MAGIC) {
|
|
84
|
+
if (magic.every((b, i) => bytes[i] === b) && (!extraCheck || extraCheck(bytes))) {
|
|
85
|
+
const id = `img${state.nextImageId++}`;
|
|
86
|
+
const base64 = bytes.toString('base64');
|
|
87
|
+
const sizeKB = Math.round(bytes.length / 1024);
|
|
88
|
+
state.imageRegistry.set(id, { data: base64, mediaType });
|
|
89
|
+
return { marker: `[IMAGE: ${id}, clipboard, ${sizeKB}KB]`, nextPasteId: state.nextPasteId, nextImageId: state.nextImageId };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const trimmed = content.trim();
|
|
95
|
+
if (trimmed.length > 100) {
|
|
96
|
+
for (const { prefix, mediaType } of IMAGE_PREFIXES) {
|
|
97
|
+
if (trimmed.startsWith(prefix)) {
|
|
98
|
+
const id = `img${state.nextImageId++}`;
|
|
99
|
+
const sizeKB = Math.round(trimmed.length * 3 / 4 / 1024);
|
|
100
|
+
state.imageRegistry.set(id, { data: trimmed, mediaType });
|
|
101
|
+
return { marker: `[IMAGE: ${id}, clipboard, ${sizeKB}KB]`, nextPasteId: state.nextPasteId, nextImageId: state.nextImageId };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (IMAGE_EXTENSIONS.some(ext => trimmed.toLowerCase().endsWith(ext))) {
|
|
107
|
+
try {
|
|
108
|
+
const resolvedPath = resolveAndValidatePath(trimmed, projectRoot);
|
|
109
|
+
if (existsSync(resolvedPath)) {
|
|
110
|
+
const data = readFileSync(resolvedPath);
|
|
111
|
+
const base64 = data.toString('base64');
|
|
112
|
+
const ext = trimmed.slice(trimmed.lastIndexOf('.'));
|
|
113
|
+
const mediaType = mediaTypeFromExt(ext);
|
|
114
|
+
const filename = trimmed.split('/').pop() ?? 'image';
|
|
115
|
+
const id = `img${state.nextImageId++}`;
|
|
116
|
+
state.imageRegistry.set(id, { data: base64, mediaType });
|
|
117
|
+
return { marker: `[IMAGE: ${id}, ${filename}, ${formatFileSize(data.length)}]`, nextPasteId: state.nextPasteId, nextImageId: state.nextImageId };
|
|
118
|
+
}
|
|
119
|
+
} catch (err) {
|
|
120
|
+
logger.debug('registerPaste: could not read image file path', { err });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const lines = content.split('\n');
|
|
125
|
+
if (lines.length <= 8) return { marker: content, nextPasteId: state.nextPasteId, nextImageId: state.nextImageId };
|
|
126
|
+
const id = `p${state.nextPasteId++}`;
|
|
127
|
+
state.pasteRegistry.set(id, content);
|
|
128
|
+
return { marker: `[TEXT: ${id}, ${lines.length} lines]`, nextPasteId: state.nextPasteId, nextImageId: state.nextImageId };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function expandPrompt(
|
|
132
|
+
pasteRegistry: Map<string, string>,
|
|
133
|
+
imageRegistry: Map<string, { data: string; mediaType: string }>,
|
|
134
|
+
text: string,
|
|
135
|
+
projectRoot: string,
|
|
136
|
+
): string | ContentPart[] {
|
|
137
|
+
const foundPasteIds = new Set<string>();
|
|
138
|
+
const markerRegex = /\[TEXT: (p\d+), (\d+) lines\]/g;
|
|
139
|
+
|
|
140
|
+
const replacements: { marker: string; index: number; content: string }[] = [];
|
|
141
|
+
let match;
|
|
142
|
+
while ((match = markerRegex.exec(text)) !== null) {
|
|
143
|
+
const id = match[1];
|
|
144
|
+
const content = pasteRegistry.get(id);
|
|
145
|
+
if (content) {
|
|
146
|
+
replacements.push({ marker: match[0], index: match.index, content });
|
|
147
|
+
foundPasteIds.add(id);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
let expanded = text;
|
|
152
|
+
for (let i = replacements.length - 1; i >= 0; i--) {
|
|
153
|
+
const { marker, index, content } = replacements[i]!;
|
|
154
|
+
expanded = expanded.slice(0, index) + content + expanded.slice(index + marker.length);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
for (const id of pasteRegistry.keys()) {
|
|
158
|
+
if (!foundPasteIds.has(id)) {
|
|
159
|
+
pasteRegistry.delete(id);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const injectRegex = /(?:^|(?<=\s))!@(\S+)/g;
|
|
164
|
+
let injectMatch;
|
|
165
|
+
while ((injectMatch = injectRegex.exec(expanded)) !== null) {
|
|
166
|
+
const filePath = injectMatch[1];
|
|
167
|
+
try {
|
|
168
|
+
const resolvedPath = resolveAndValidatePath(filePath, projectRoot);
|
|
169
|
+
const content = readFileSync(resolvedPath, 'utf-8');
|
|
170
|
+
expanded = expanded.slice(0, injectMatch.index) + content + expanded.slice(injectMatch.index + injectMatch[0].length);
|
|
171
|
+
injectRegex.lastIndex = injectMatch.index + content.length;
|
|
172
|
+
} catch (err) {
|
|
173
|
+
logger.debug('expandPrompt: failed to read injected file', { path: filePath, error: summarizeError(err) });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const imageMarkerRegex = /\[IMAGE: (img\d+), [^\]]+\]/g;
|
|
178
|
+
const imageMarkers: { marker: string; index: number; id: string }[] = [];
|
|
179
|
+
let imgMatch;
|
|
180
|
+
while ((imgMatch = imageMarkerRegex.exec(expanded)) !== null) {
|
|
181
|
+
imageMarkers.push({ marker: imgMatch[0], index: imgMatch.index, id: imgMatch[1] });
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (imageMarkers.length === 0) {
|
|
185
|
+
imageRegistry.clear();
|
|
186
|
+
return expanded;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const parts: ContentPart[] = [];
|
|
190
|
+
let lastIndex = 0;
|
|
191
|
+
const usedIds = new Set<string>();
|
|
192
|
+
|
|
193
|
+
for (const { marker, index, id } of imageMarkers) {
|
|
194
|
+
if (index > lastIndex) {
|
|
195
|
+
const textSegment = expanded.slice(lastIndex, index);
|
|
196
|
+
if (textSegment) parts.push({ type: 'text', text: textSegment });
|
|
197
|
+
}
|
|
198
|
+
const img = imageRegistry.get(id);
|
|
199
|
+
if (img) {
|
|
200
|
+
parts.push({ type: 'image', data: img.data, mediaType: img.mediaType });
|
|
201
|
+
usedIds.add(id);
|
|
202
|
+
}
|
|
203
|
+
lastIndex = index + marker.length;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (lastIndex < expanded.length) {
|
|
207
|
+
const textSegment = expanded.slice(lastIndex);
|
|
208
|
+
if (textSegment) parts.push({ type: 'text', text: textSegment });
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
for (const id of imageRegistry.keys()) {
|
|
212
|
+
if (!usedIds.has(id)) imageRegistry.delete(id);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return parts;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export function cleanupMarkerRegistry(
|
|
219
|
+
imageRegistry: Map<string, { data: string; mediaType: string }>,
|
|
220
|
+
markerText: string,
|
|
221
|
+
): void {
|
|
222
|
+
const match = /^\[IMAGE: (img\d+),/.exec(markerText);
|
|
223
|
+
if (match) {
|
|
224
|
+
imageRegistry.delete(match[1]!);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export function findMarkerAtPos(prompt: string, pos: number): { start: number; end: number } | null {
|
|
229
|
+
const markerRegex = new RegExp(MARKER_REGEX.source, 'g');
|
|
230
|
+
let m;
|
|
231
|
+
while ((m = markerRegex.exec(prompt)) !== null) {
|
|
232
|
+
const start = m.index;
|
|
233
|
+
const end = m.index + m[0].length;
|
|
234
|
+
if (pos > start && pos <= end) {
|
|
235
|
+
return { start, end };
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export function handleCopy(
|
|
242
|
+
selection: SelectionManager,
|
|
243
|
+
getHistory: () => InfiniteBuffer,
|
|
244
|
+
requestRender: () => void,
|
|
245
|
+
onCopied: () => void,
|
|
246
|
+
): void {
|
|
247
|
+
if (!selection.hasSelection()) return;
|
|
248
|
+
copyToClipboard(selection.getSelectedText(getHistory()));
|
|
249
|
+
onCopied();
|
|
250
|
+
requestRender();
|
|
251
|
+
setTimeout(() => requestRender(), 2005);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export function handleBlockCopy(
|
|
255
|
+
conversationManager: ConversationManager | null,
|
|
256
|
+
getScrollTop: () => number,
|
|
257
|
+
requestRender: () => void,
|
|
258
|
+
onCopied: () => void,
|
|
259
|
+
): void {
|
|
260
|
+
if (!conversationManager) return;
|
|
261
|
+
const lineIndex = getScrollTop();
|
|
262
|
+
const content = conversationManager.getBlockContentAtLine(lineIndex);
|
|
263
|
+
if (!content) return;
|
|
264
|
+
copyToClipboard(content);
|
|
265
|
+
onCopied();
|
|
266
|
+
requestRender();
|
|
267
|
+
setTimeout(() => requestRender(), 2005);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export function handleBookmark(
|
|
271
|
+
conversationManager: ConversationManager | null,
|
|
272
|
+
getScrollTop: () => number,
|
|
273
|
+
requestRender: () => void,
|
|
274
|
+
bookmarkManager: BookmarkManager,
|
|
275
|
+
): void {
|
|
276
|
+
if (!conversationManager) return;
|
|
277
|
+
const lineIndex = getScrollTop();
|
|
278
|
+
const nearest = conversationManager.findNearestBlock(lineIndex);
|
|
279
|
+
if (!nearest) {
|
|
280
|
+
conversationManager.log('[Ctrl+B: No block found nearby]', { fg: '240' });
|
|
281
|
+
requestRender();
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const label = `${nearest.type}: ${nearest.rawContent.slice(0, 40).replace(/\n/g, ' ')}`;
|
|
285
|
+
const added = bookmarkManager.toggle(nearest.collapseKey, label);
|
|
286
|
+
const msg = added
|
|
287
|
+
? `[Bookmarked: ${nearest.collapseKey}]`
|
|
288
|
+
: `[Bookmark removed: ${nearest.collapseKey}]`;
|
|
289
|
+
conversationManager.log(msg, { fg: added ? '#22c55e' : '244' });
|
|
290
|
+
requestRender();
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export function handleBlockSave(
|
|
294
|
+
conversationManager: ConversationManager | null,
|
|
295
|
+
getScrollTop: () => number,
|
|
296
|
+
requestRender: () => void,
|
|
297
|
+
bookmarkManager: BookmarkManager,
|
|
298
|
+
): void {
|
|
299
|
+
if (!conversationManager) return;
|
|
300
|
+
const lineIndex = getScrollTop();
|
|
301
|
+
const content = conversationManager.getBlockContentAtLine(lineIndex);
|
|
302
|
+
if (!content) {
|
|
303
|
+
conversationManager.log('[Ctrl+S: No block found nearby]', { fg: '240' });
|
|
304
|
+
requestRender();
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
const nearest = conversationManager.findNearestBlock(lineIndex);
|
|
308
|
+
const label = nearest?.type ?? 'block';
|
|
309
|
+
try {
|
|
310
|
+
const filePath = bookmarkManager.saveToFile(content, label);
|
|
311
|
+
const homePath = process.env.HOME || process.env.USERPROFILE || '';
|
|
312
|
+
const displayPath = homePath ? filePath.replace(homePath, '~') : filePath;
|
|
313
|
+
conversationManager.log(`[Saved to: ${displayPath}]`, { fg: '#22c55e' });
|
|
314
|
+
} catch (err) {
|
|
315
|
+
const msg = summarizeError(err);
|
|
316
|
+
conversationManager.log(`[Save failed: ${msg}]`, { fg: '#ef4444' });
|
|
317
|
+
}
|
|
318
|
+
requestRender();
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export function handleBlockRerun(
|
|
322
|
+
conversationManager: ConversationManager | null,
|
|
323
|
+
getScrollTop: () => number,
|
|
324
|
+
requestRender: () => void,
|
|
325
|
+
): void {
|
|
326
|
+
if (!conversationManager) return;
|
|
327
|
+
const lineIndex = getScrollTop();
|
|
328
|
+
const nearest = conversationManager.findNearestBlock(lineIndex, 'tool');
|
|
329
|
+
if (!nearest) {
|
|
330
|
+
conversationManager.log('[Re-run: No tool block found nearby]', { fg: '240' });
|
|
331
|
+
requestRender();
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
requestRender();
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export function handleBlockToggle(
|
|
338
|
+
conversationManager: ConversationManager | null,
|
|
339
|
+
getScrollTop: () => number,
|
|
340
|
+
requestRender: () => void,
|
|
341
|
+
): void {
|
|
342
|
+
if (!conversationManager) return;
|
|
343
|
+
const lineIndex = getScrollTop();
|
|
344
|
+
const blockIdx = conversationManager.toggleCollapseAtLine(lineIndex);
|
|
345
|
+
if (blockIdx >= 0) {
|
|
346
|
+
requestRender();
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export function handleDiffApply(
|
|
351
|
+
conversationManager: ConversationManager | null,
|
|
352
|
+
getScrollTop: () => number,
|
|
353
|
+
commandContext: CommandContext | undefined,
|
|
354
|
+
requestRender: () => void,
|
|
355
|
+
getCallId: () => string,
|
|
356
|
+
category: PermissionCategory,
|
|
357
|
+
): boolean {
|
|
358
|
+
if (!conversationManager) return false;
|
|
359
|
+
const lineIndex = getScrollTop();
|
|
360
|
+
const diff = conversationManager.getDiffAtLine(lineIndex);
|
|
361
|
+
if (!diff || !diff.filePath) return false;
|
|
362
|
+
const projectRoot = commandContext?.workspace.shellPaths?.workingDirectory
|
|
363
|
+
?? commandContext?.platform.configManager.getWorkingDirectory();
|
|
364
|
+
|
|
365
|
+
commandContext?.requestPermission?.({
|
|
366
|
+
callId: getCallId(),
|
|
367
|
+
tool: 'edit',
|
|
368
|
+
args: { path: diff.filePath, original: diff.original, updated: diff.updated },
|
|
369
|
+
category,
|
|
370
|
+
analysis: analyzePermissionRequest(
|
|
371
|
+
'edit',
|
|
372
|
+
{ path: diff.filePath, original: diff.original, updated: diff.updated },
|
|
373
|
+
category,
|
|
374
|
+
),
|
|
375
|
+
}).then(({ approved }) => {
|
|
376
|
+
if (!approved) return;
|
|
377
|
+
if (!projectRoot) {
|
|
378
|
+
conversationManager.log('[Diff apply failed: missing working directory]', { fg: '#ef4444' });
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
let resolvedPath: string;
|
|
382
|
+
try {
|
|
383
|
+
resolvedPath = resolveAndValidatePath(diff.filePath!, projectRoot);
|
|
384
|
+
} catch (err) {
|
|
385
|
+
conversationManager.log(`[Diff apply failed: ${err instanceof Error ? err.message : err}]`, { fg: '#ef4444' });
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
try {
|
|
389
|
+
const content = readFileSync(resolvedPath, 'utf-8');
|
|
390
|
+
if (diff.original && content.includes(diff.original)) {
|
|
391
|
+
const occurrenceCount = content.split(diff.original).length - 1;
|
|
392
|
+
if (occurrenceCount > 1) {
|
|
393
|
+
conversationManager.log(`[Diff apply failed: pattern found ${occurrenceCount} times in ${diff.filePath} - ambiguous]`, { fg: '#ef4444' });
|
|
394
|
+
} else {
|
|
395
|
+
const newContent = content.replace(diff.original, diff.updated);
|
|
396
|
+
writeFileSync(resolvedPath, newContent, 'utf-8');
|
|
397
|
+
conversationManager.log(`[Applied diff to ${diff.filePath}]`, { fg: '#22c55e' });
|
|
398
|
+
}
|
|
399
|
+
} else {
|
|
400
|
+
conversationManager.log(`[Diff apply failed: original text not found in ${diff.filePath}]`, { fg: '#ef4444' });
|
|
401
|
+
}
|
|
402
|
+
} catch (err) {
|
|
403
|
+
const msg = summarizeError(err);
|
|
404
|
+
conversationManager.log(`[Diff apply error: ${msg}]`, { fg: '#ef4444' });
|
|
405
|
+
}
|
|
406
|
+
requestRender();
|
|
407
|
+
}).catch((err) => {
|
|
408
|
+
conversationManager.log(`[Diff apply error: ${summarizeError(err)}]`, { fg: '#ef4444' });
|
|
409
|
+
requestRender();
|
|
410
|
+
});
|
|
411
|
+
return true;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
export function handleCtrlC(
|
|
415
|
+
prompt: string,
|
|
416
|
+
saveUndoState: () => void,
|
|
417
|
+
setPrompt: (value: string) => void,
|
|
418
|
+
setCursorPos: (value: number) => void,
|
|
419
|
+
cancelGeneration: (() => void) | undefined,
|
|
420
|
+
exitApp: () => void,
|
|
421
|
+
requestRender: () => void,
|
|
422
|
+
lastCtrlCTime: number,
|
|
423
|
+
setLastCtrlCTime: (value: number) => void,
|
|
424
|
+
setShowExitNotice: (value: boolean) => void,
|
|
425
|
+
): void {
|
|
426
|
+
if (prompt.length > 0) {
|
|
427
|
+
saveUndoState();
|
|
428
|
+
setPrompt('');
|
|
429
|
+
setCursorPos(0);
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
cancelGeneration?.();
|
|
433
|
+
const now = Date.now();
|
|
434
|
+
if (now - lastCtrlCTime < 1000) {
|
|
435
|
+
exitApp();
|
|
436
|
+
} else {
|
|
437
|
+
setLastCtrlCTime(now);
|
|
438
|
+
setShowExitNotice(true);
|
|
439
|
+
requestRender();
|
|
440
|
+
setTimeout(() => {
|
|
441
|
+
setShowExitNotice(false);
|
|
442
|
+
requestRender();
|
|
443
|
+
}, 1000);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export function handleClipboardPaste(
|
|
448
|
+
state: PasteRegistryState & {
|
|
449
|
+
prompt: string;
|
|
450
|
+
cursorPos: number;
|
|
451
|
+
saveUndoState: () => void;
|
|
452
|
+
ensureInputCursorVisible: () => void;
|
|
453
|
+
requestRender: () => void;
|
|
454
|
+
},
|
|
455
|
+
projectRoot: string,
|
|
456
|
+
clipboard: ClipboardPasteSource = { pasteImageFromClipboard, pasteFromClipboard },
|
|
457
|
+
): ClipboardPasteResult {
|
|
458
|
+
const img = clipboard.pasteImageFromClipboard();
|
|
459
|
+
let pasted = false;
|
|
460
|
+
let kind: ClipboardPasteKind = 'none';
|
|
461
|
+
let insertedMarker: string | undefined;
|
|
462
|
+
|
|
463
|
+
if (img) {
|
|
464
|
+
state.saveUndoState();
|
|
465
|
+
const id = `img${state.nextImageId++}`;
|
|
466
|
+
const sizeKB = Math.round(img.data.length * 3 / 4 / 1024);
|
|
467
|
+
state.imageRegistry.set(id, img);
|
|
468
|
+
const marker = `[IMAGE: ${id}, clipboard, ${sizeKB}KB]`;
|
|
469
|
+
state.prompt = state.prompt.slice(0, state.cursorPos) + marker + state.prompt.slice(state.cursorPos);
|
|
470
|
+
state.cursorPos += marker.length;
|
|
471
|
+
pasted = true;
|
|
472
|
+
kind = 'image';
|
|
473
|
+
insertedMarker = marker;
|
|
474
|
+
} else {
|
|
475
|
+
const raw = clipboard.pasteFromClipboard();
|
|
476
|
+
if (raw) {
|
|
477
|
+
state.saveUndoState();
|
|
478
|
+
const { marker } = registerPaste(state, raw, projectRoot);
|
|
479
|
+
state.prompt = state.prompt.slice(0, state.cursorPos) + marker + state.prompt.slice(state.cursorPos);
|
|
480
|
+
state.cursorPos += marker.length;
|
|
481
|
+
pasted = true;
|
|
482
|
+
kind = marker.startsWith('[IMAGE:') ? 'image' : 'text';
|
|
483
|
+
insertedMarker = marker;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
state.ensureInputCursorVisible();
|
|
487
|
+
state.requestRender();
|
|
488
|
+
return {
|
|
489
|
+
prompt: state.prompt,
|
|
490
|
+
cursorPos: state.cursorPos,
|
|
491
|
+
nextImageId: state.nextImageId,
|
|
492
|
+
nextPasteId: state.nextPasteId,
|
|
493
|
+
pasted,
|
|
494
|
+
kind,
|
|
495
|
+
marker: insertedMarker,
|
|
496
|
+
};
|
|
497
|
+
}
|