explorbot 0.0.1 → 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/README.md +80 -26
- package/bin/explorbot-cli.ts +680 -0
- package/boat/api-tester/src/ai/chief/styles.ts +15 -0
- package/boat/api-tester/src/ai/chief.ts +335 -0
- package/boat/api-tester/src/ai/curler-tools.ts +278 -0
- package/boat/api-tester/src/ai/curler.ts +306 -0
- package/boat/api-tester/src/api-client.ts +28 -0
- package/boat/api-tester/src/apibot.ts +203 -0
- package/boat/api-tester/src/cli.ts +301 -0
- package/boat/api-tester/src/config.ts +190 -0
- package/dist/bin/explorbot-cli.js +23 -101
- package/dist/boat/api-tester/bin/apibot-cli.js +0 -1
- package/dist/boat/api-tester/src/ai/chief/styles.js +0 -1
- package/dist/boat/api-tester/src/ai/chief.js +0 -1
- package/dist/boat/api-tester/src/ai/curler-tools.js +0 -1
- package/dist/boat/api-tester/src/ai/curler.js +0 -1
- package/dist/boat/api-tester/src/api-client.js +0 -1
- package/dist/boat/api-tester/src/apibot.js +0 -1
- package/dist/boat/api-tester/src/cli.js +0 -1
- package/dist/boat/api-tester/src/config.js +0 -1
- package/dist/src/action-result.js +0 -1
- package/dist/src/action.js +14 -12
- package/dist/src/activity.js +0 -1
- package/dist/src/ai/agent.js +0 -1
- package/dist/src/ai/bosun.js +0 -1
- package/dist/src/ai/captain/idle-mode.js +0 -1
- package/dist/src/ai/captain/mixin.js +0 -1
- package/dist/src/ai/captain/test-mode.js +0 -1
- package/dist/src/ai/captain/web-mode.js +0 -1
- package/dist/src/ai/captain.js +0 -1
- package/dist/src/ai/conversation.js +0 -1
- package/dist/src/ai/experience-compactor.js +0 -1
- package/dist/src/ai/fisherman-tools.js +0 -1
- package/dist/src/ai/fisherman.js +0 -1
- package/dist/src/ai/historian.js +0 -1
- package/dist/src/ai/navigator.js +0 -1
- package/dist/src/ai/pilot.js +0 -1
- package/dist/src/ai/planner/session-dedup.js +0 -1
- package/dist/src/ai/planner/styles.js +0 -1
- package/dist/src/ai/planner/subpages.js +42 -7
- package/dist/src/ai/planner.js +15 -4
- package/dist/src/ai/provider.js +0 -1
- package/dist/src/ai/quartermaster.js +0 -1
- package/dist/src/ai/researcher/cache.js +13 -9
- package/dist/src/ai/researcher/coordinates.js +4 -3
- package/dist/src/ai/researcher/deep-analysis.js +16 -20
- package/dist/src/ai/researcher/fingerprint-worker.js +0 -1
- package/dist/src/ai/researcher/focus.js +0 -1
- package/dist/src/ai/researcher/locators.js +1 -2
- package/dist/src/ai/researcher/mixin.js +0 -1
- package/dist/src/ai/researcher/parser.js +4 -4
- package/dist/src/ai/researcher/research-result.js +2 -1
- package/dist/src/ai/researcher.js +6 -6
- package/dist/src/ai/rules.js +0 -1
- package/dist/src/ai/task-agent.js +0 -1
- package/dist/src/ai/tester.js +0 -1
- package/dist/src/ai/tools.js +4 -1
- package/dist/src/api/api-client.js +0 -1
- package/dist/src/api/request-result.js +0 -1
- package/dist/src/api/request-store.js +0 -1
- package/dist/src/api/spec-reader.js +0 -1
- package/dist/src/api/xhr-capture.js +0 -1
- package/dist/src/browser-server.js +0 -1
- package/dist/src/command-handler.js +0 -1
- package/dist/src/commands/add-rule-command.js +0 -1
- package/dist/src/commands/base-command.js +0 -1
- package/dist/src/commands/clean-command.js +0 -1
- package/dist/src/commands/context-aria-command.js +0 -1
- package/dist/src/commands/context-command.js +2 -3
- package/dist/src/commands/context-data-command.js +0 -1
- package/dist/src/commands/context-experience-command.js +0 -1
- package/dist/src/commands/context-html-command.js +0 -1
- package/dist/src/commands/context-knowledge-command.js +0 -1
- package/dist/src/commands/debug-command.js +0 -1
- package/dist/src/commands/drill-command.js +0 -1
- package/dist/src/commands/exit-command.js +0 -1
- package/dist/src/commands/explore-command.js +3 -3
- package/dist/src/commands/freesail-command.js +0 -1
- package/dist/src/commands/help-command.js +0 -1
- package/dist/src/commands/index.js +0 -1
- package/dist/src/commands/init-command.js +117 -0
- package/dist/src/commands/knows-command.js +0 -1
- package/dist/src/commands/learn-command.js +0 -1
- package/dist/src/commands/navigate-command.js +0 -1
- package/dist/src/commands/path-command.js +0 -1
- package/dist/src/commands/plan-clear-command.js +0 -1
- package/dist/src/commands/plan-command.js +6 -2
- package/dist/src/commands/plan-edit-command.js +0 -1
- package/dist/src/commands/plan-load-command.js +0 -1
- package/dist/src/commands/plan-reload-command.js +0 -1
- package/dist/src/commands/plan-save-command.js +0 -1
- package/dist/src/commands/research-command.js +0 -1
- package/dist/src/commands/start-command.js +0 -1
- package/dist/src/commands/status-command.js +0 -1
- package/dist/src/commands/test-command.js +0 -1
- package/dist/src/components/ActivityPane.js +0 -1
- package/dist/src/components/AddKnowledge.js +0 -1
- package/dist/src/components/AddRule.js +0 -1
- package/dist/src/components/App.js +0 -1
- package/dist/src/components/Autocomplete.js +0 -1
- package/dist/src/components/InputPane.js +0 -1
- package/dist/src/components/InputReadline.js +0 -1
- package/dist/src/components/LogPane.js +0 -1
- package/dist/src/components/PlanEditor.js +0 -1
- package/dist/src/components/PlanPane.js +0 -1
- package/dist/src/components/SessionTimer.js +0 -1
- package/dist/src/components/StateTransitionPane.js +0 -1
- package/dist/src/components/StatusPane.js +0 -1
- package/dist/src/components/TaskPane.js +0 -1
- package/dist/src/components/Welcome.js +0 -1
- package/dist/src/components/WelcomeChecklist.js +0 -1
- package/dist/src/components/WelcomeCommands.js +0 -1
- package/dist/src/components/autocomplete-store.js +0 -1
- package/dist/src/components/parse-keypress.js +0 -1
- package/dist/src/config.js +0 -1
- package/dist/src/execution-controller.js +0 -1
- package/dist/src/experience-tracker.js +0 -1
- package/dist/src/explorbot.js +1 -2
- package/dist/src/explorer.js +58 -17
- package/dist/src/index.js +0 -1
- package/dist/src/knowledge-tracker.js +2 -2
- package/dist/src/observability.js +0 -1
- package/dist/src/reporter.js +0 -1
- package/dist/src/state-manager.js +0 -1
- package/dist/src/stats.js +0 -1
- package/dist/src/test-plan.js +0 -1
- package/dist/src/utils/aria.js +0 -1
- package/dist/src/utils/cli-name.js +16 -0
- package/dist/src/utils/code-extractor.js +0 -1
- package/dist/src/utils/context-formatter.js +0 -1
- package/dist/src/utils/error-page.js +0 -1
- package/dist/src/utils/expandable.js +0 -1
- package/dist/src/utils/hooks-runner.js +0 -1
- package/dist/src/utils/html-diff.js +0 -1
- package/dist/src/utils/html.js +0 -1
- package/dist/src/utils/logger.js +0 -1
- package/dist/src/utils/loop.js +0 -1
- package/dist/src/utils/markdown-parser.js +0 -1
- package/dist/src/utils/markdown-query.js +0 -1
- package/dist/src/utils/markdown-terminal.js +0 -1
- package/dist/src/utils/research-parser.js +0 -1
- package/dist/src/utils/retry.js +0 -1
- package/dist/src/utils/rules-loader.js +0 -1
- package/dist/src/utils/strings.js +0 -1
- package/dist/src/utils/test-plan-markdown.js +0 -1
- package/dist/src/utils/throttle.js +0 -1
- package/dist/src/utils/unique-names.js +0 -1
- package/dist/src/utils/url-matcher.js +0 -1
- package/dist/src/utils/web-element.js +6 -5
- package/dist/src/utils/xpath.js +0 -1
- package/package.json +28 -4
- package/src/action-result.ts +694 -0
- package/src/action.ts +449 -0
- package/src/activity.ts +111 -0
- package/src/ai/agent.ts +3 -0
- package/src/ai/bosun.ts +557 -0
- package/src/ai/captain/idle-mode.ts +116 -0
- package/src/ai/captain/mixin.ts +22 -0
- package/src/ai/captain/test-mode.ts +262 -0
- package/src/ai/captain/web-mode.ts +136 -0
- package/src/ai/captain.ts +504 -0
- package/src/ai/conversation.ts +205 -0
- package/src/ai/experience-compactor.ts +284 -0
- package/src/ai/fisherman-tools.ts +181 -0
- package/src/ai/fisherman.ts +223 -0
- package/src/ai/historian.ts +457 -0
- package/src/ai/navigator.ts +572 -0
- package/src/ai/pilot.ts +776 -0
- package/src/ai/planner/session-dedup.ts +35 -0
- package/src/ai/planner/styles.ts +17 -0
- package/src/ai/planner/subpages.ts +171 -0
- package/src/ai/planner.ts +549 -0
- package/src/ai/provider.ts +613 -0
- package/src/ai/quartermaster.ts +286 -0
- package/src/ai/researcher/cache.ts +109 -0
- package/src/ai/researcher/coordinates.ts +239 -0
- package/src/ai/researcher/deep-analysis.ts +412 -0
- package/src/ai/researcher/fingerprint-worker.ts +59 -0
- package/src/ai/researcher/focus.ts +42 -0
- package/src/ai/researcher/locators.ts +282 -0
- package/src/ai/researcher/mixin.ts +4 -0
- package/src/ai/researcher/parser.ts +186 -0
- package/src/ai/researcher/research-result.ts +116 -0
- package/src/ai/researcher.ts +858 -0
- package/src/ai/rules.ts +376 -0
- package/src/ai/task-agent.ts +141 -0
- package/src/ai/tester.ts +939 -0
- package/src/ai/tools.ts +1122 -0
- package/src/api/api-client.ts +109 -0
- package/src/api/request-result.ts +212 -0
- package/src/api/request-store.ts +130 -0
- package/src/api/spec-reader.ts +174 -0
- package/src/api/xhr-capture.ts +100 -0
- package/src/browser-server.ts +74 -0
- package/src/command-handler.ts +454 -0
- package/src/commands/add-rule-command.ts +63 -0
- package/src/commands/base-command.ts +27 -0
- package/src/commands/clean-command.ts +73 -0
- package/src/commands/context-aria-command.ts +22 -0
- package/src/commands/context-command.ts +67 -0
- package/src/commands/context-data-command.ts +30 -0
- package/src/commands/context-experience-command.ts +48 -0
- package/src/commands/context-html-command.ts +33 -0
- package/src/commands/context-knowledge-command.ts +43 -0
- package/src/commands/debug-command.ts +13 -0
- package/src/commands/drill-command.ts +34 -0
- package/src/commands/exit-command.ts +32 -0
- package/src/commands/explore-command.ts +129 -0
- package/src/commands/freesail-command.ts +95 -0
- package/src/commands/help-command.ts +8 -0
- package/src/commands/index.ts +69 -0
- package/src/commands/init-command.ts +131 -0
- package/src/commands/knows-command.ts +68 -0
- package/src/commands/learn-command.ts +44 -0
- package/src/commands/navigate-command.ts +18 -0
- package/src/commands/path-command.ts +83 -0
- package/src/commands/plan-clear-command.ts +14 -0
- package/src/commands/plan-command.ts +46 -0
- package/src/commands/plan-edit-command.ts +9 -0
- package/src/commands/plan-load-command.ts +18 -0
- package/src/commands/plan-reload-command.ts +28 -0
- package/src/commands/plan-save-command.ts +25 -0
- package/src/commands/research-command.ts +45 -0
- package/src/commands/start-command.ts +13 -0
- package/src/commands/status-command.tsx +23 -0
- package/src/commands/test-command.ts +84 -0
- package/src/components/ActivityPane.tsx +80 -0
- package/src/components/AddKnowledge.tsx +169 -0
- package/src/components/AddRule.tsx +174 -0
- package/src/components/App.tsx +377 -0
- package/src/components/Autocomplete.tsx +63 -0
- package/src/components/InputPane.tsx +259 -0
- package/src/components/InputReadline.tsx +704 -0
- package/src/components/LogPane.tsx +187 -0
- package/src/components/PlanEditor.tsx +150 -0
- package/src/components/PlanPane.tsx +71 -0
- package/src/components/SessionTimer.tsx +35 -0
- package/src/components/StateTransitionPane.tsx +149 -0
- package/src/components/StatusPane.tsx +62 -0
- package/src/components/TaskPane.tsx +119 -0
- package/src/components/Welcome.tsx +83 -0
- package/src/components/WelcomeChecklist.tsx +118 -0
- package/src/components/WelcomeCommands.tsx +102 -0
- package/src/components/autocomplete-store.ts +35 -0
- package/src/components/parse-keypress.ts +170 -0
- package/src/config.ts +491 -0
- package/src/execution-controller.ts +109 -0
- package/src/experience-tracker.ts +350 -0
- package/src/explorbot.ts +405 -0
- package/src/explorer.ts +760 -0
- package/src/index.tsx +62 -0
- package/src/knowledge-tracker.ts +230 -0
- package/src/observability.ts +150 -0
- package/src/reporter.ts +224 -0
- package/src/state-manager.ts +556 -0
- package/src/stats.ts +53 -0
- package/src/test-plan.ts +432 -0
- package/src/utils/aria.ts +629 -0
- package/src/utils/cli-name.ts +13 -0
- package/src/utils/code-extractor.ts +22 -0
- package/src/utils/context-formatter.ts +239 -0
- package/src/utils/error-page.ts +23 -0
- package/src/utils/expandable.ts +38 -0
- package/src/utils/hooks-runner.ts +79 -0
- package/src/utils/html-diff.ts +918 -0
- package/src/utils/html.ts +1316 -0
- package/src/utils/logger.ts +534 -0
- package/src/utils/loop.ts +176 -0
- package/src/utils/markdown-parser.ts +127 -0
- package/src/utils/markdown-query.ts +466 -0
- package/src/utils/markdown-terminal.ts +43 -0
- package/src/utils/research-parser.ts +11 -0
- package/src/utils/retry.ts +73 -0
- package/src/utils/rules-loader.ts +118 -0
- package/src/utils/strings.ts +13 -0
- package/src/utils/test-plan-markdown.ts +332 -0
- package/src/utils/throttle.ts +18 -0
- package/src/utils/unique-names.ts +14 -0
- package/src/utils/url-matcher.ts +45 -0
- package/src/utils/web-element.ts +147 -0
- package/src/utils/xpath.ts +129 -0
- package/dist/bin/explorbot-cli.js.map +0 -1
- package/dist/boat/api-tester/bin/apibot-cli.js.map +0 -1
- package/dist/boat/api-tester/example/apibot.config.js +0 -31
- package/dist/boat/api-tester/example/apibot.config.js.map +0 -1
- package/dist/boat/api-tester/src/ai/chief/styles.js.map +0 -1
- package/dist/boat/api-tester/src/ai/chief.js.map +0 -1
- package/dist/boat/api-tester/src/ai/curler-tools.js.map +0 -1
- package/dist/boat/api-tester/src/ai/curler.js.map +0 -1
- package/dist/boat/api-tester/src/api-client.js.map +0 -1
- package/dist/boat/api-tester/src/apibot.js.map +0 -1
- package/dist/boat/api-tester/src/cli.js.map +0 -1
- package/dist/boat/api-tester/src/config.js.map +0 -1
- package/dist/prompts/audit-rules.md +0 -124
- package/dist/src/action-result.js.map +0 -1
- package/dist/src/action.js.map +0 -1
- package/dist/src/activity.js.map +0 -1
- package/dist/src/ai/agent.js.map +0 -1
- package/dist/src/ai/bosun.js.map +0 -1
- package/dist/src/ai/captain/idle-mode.js.map +0 -1
- package/dist/src/ai/captain/mixin.js.map +0 -1
- package/dist/src/ai/captain/test-mode.js.map +0 -1
- package/dist/src/ai/captain/web-mode.js.map +0 -1
- package/dist/src/ai/captain.js.map +0 -1
- package/dist/src/ai/conversation.js.map +0 -1
- package/dist/src/ai/experience-compactor.js.map +0 -1
- package/dist/src/ai/fisherman-tools.js.map +0 -1
- package/dist/src/ai/fisherman.js.map +0 -1
- package/dist/src/ai/historian.js.map +0 -1
- package/dist/src/ai/navigator.js.map +0 -1
- package/dist/src/ai/pilot.js.map +0 -1
- package/dist/src/ai/planner/session-dedup.js.map +0 -1
- package/dist/src/ai/planner/styles.js.map +0 -1
- package/dist/src/ai/planner/subpages.js.map +0 -1
- package/dist/src/ai/planner.js.map +0 -1
- package/dist/src/ai/provider.js.map +0 -1
- package/dist/src/ai/quartermaster.js.map +0 -1
- package/dist/src/ai/researcher/cache.js.map +0 -1
- package/dist/src/ai/researcher/coordinates.js.map +0 -1
- package/dist/src/ai/researcher/deep-analysis.js.map +0 -1
- package/dist/src/ai/researcher/fingerprint-worker.js.map +0 -1
- package/dist/src/ai/researcher/focus.js.map +0 -1
- package/dist/src/ai/researcher/locators.js.map +0 -1
- package/dist/src/ai/researcher/mixin.js.map +0 -1
- package/dist/src/ai/researcher/parser.js.map +0 -1
- package/dist/src/ai/researcher/research-result.js.map +0 -1
- package/dist/src/ai/researcher.js.map +0 -1
- package/dist/src/ai/rules.js.map +0 -1
- package/dist/src/ai/task-agent.js.map +0 -1
- package/dist/src/ai/tester.js.map +0 -1
- package/dist/src/ai/tools.js.map +0 -1
- package/dist/src/api/api-client.js.map +0 -1
- package/dist/src/api/request-result.js.map +0 -1
- package/dist/src/api/request-store.js.map +0 -1
- package/dist/src/api/spec-reader.js.map +0 -1
- package/dist/src/api/xhr-capture.js.map +0 -1
- package/dist/src/browser-server.js.map +0 -1
- package/dist/src/command-handler.js.map +0 -1
- package/dist/src/commands/add-rule-command.js.map +0 -1
- package/dist/src/commands/base-command.js.map +0 -1
- package/dist/src/commands/clean-command.js.map +0 -1
- package/dist/src/commands/context-aria-command.js.map +0 -1
- package/dist/src/commands/context-command.js.map +0 -1
- package/dist/src/commands/context-data-command.js.map +0 -1
- package/dist/src/commands/context-experience-command.js.map +0 -1
- package/dist/src/commands/context-html-command.js.map +0 -1
- package/dist/src/commands/context-knowledge-command.js.map +0 -1
- package/dist/src/commands/debug-command.js.map +0 -1
- package/dist/src/commands/drill-command.js.map +0 -1
- package/dist/src/commands/exit-command.js.map +0 -1
- package/dist/src/commands/explore-command.js.map +0 -1
- package/dist/src/commands/freesail-command.js.map +0 -1
- package/dist/src/commands/help-command.js.map +0 -1
- package/dist/src/commands/index.js.map +0 -1
- package/dist/src/commands/knows-command.js.map +0 -1
- package/dist/src/commands/learn-command.js.map +0 -1
- package/dist/src/commands/navigate-command.js.map +0 -1
- package/dist/src/commands/path-command.js.map +0 -1
- package/dist/src/commands/plan-clear-command.js.map +0 -1
- package/dist/src/commands/plan-command.js.map +0 -1
- package/dist/src/commands/plan-edit-command.js.map +0 -1
- package/dist/src/commands/plan-load-command.js.map +0 -1
- package/dist/src/commands/plan-reload-command.js.map +0 -1
- package/dist/src/commands/plan-save-command.js.map +0 -1
- package/dist/src/commands/research-command.js.map +0 -1
- package/dist/src/commands/start-command.js.map +0 -1
- package/dist/src/commands/status-command.js.map +0 -1
- package/dist/src/commands/test-command.js.map +0 -1
- package/dist/src/components/ActivityPane.js.map +0 -1
- package/dist/src/components/AddKnowledge.js.map +0 -1
- package/dist/src/components/AddRule.js.map +0 -1
- package/dist/src/components/App.js.map +0 -1
- package/dist/src/components/Autocomplete.js.map +0 -1
- package/dist/src/components/InputPane.js.map +0 -1
- package/dist/src/components/InputReadline.js.map +0 -1
- package/dist/src/components/LogPane.js.map +0 -1
- package/dist/src/components/PlanEditor.js.map +0 -1
- package/dist/src/components/PlanPane.js.map +0 -1
- package/dist/src/components/SessionTimer.js.map +0 -1
- package/dist/src/components/StateTransitionPane.js.map +0 -1
- package/dist/src/components/StatusPane.js.map +0 -1
- package/dist/src/components/TaskPane.js.map +0 -1
- package/dist/src/components/Welcome.js.map +0 -1
- package/dist/src/components/WelcomeChecklist.js.map +0 -1
- package/dist/src/components/WelcomeCommands.js.map +0 -1
- package/dist/src/components/autocomplete-store.js.map +0 -1
- package/dist/src/components/parse-keypress.js.map +0 -1
- package/dist/src/config.js.map +0 -1
- package/dist/src/execution-controller.js.map +0 -1
- package/dist/src/experience-tracker.js.map +0 -1
- package/dist/src/explorbot.js.map +0 -1
- package/dist/src/explorer.js.map +0 -1
- package/dist/src/index.js.map +0 -1
- package/dist/src/knowledge-tracker.js.map +0 -1
- package/dist/src/observability.js.map +0 -1
- package/dist/src/reporter.js.map +0 -1
- package/dist/src/state-manager.js.map +0 -1
- package/dist/src/stats.js.map +0 -1
- package/dist/src/test-plan.js.map +0 -1
- package/dist/src/utils/aria.js.map +0 -1
- package/dist/src/utils/code-extractor.js.map +0 -1
- package/dist/src/utils/context-formatter.js.map +0 -1
- package/dist/src/utils/error-page.js.map +0 -1
- package/dist/src/utils/expandable.js.map +0 -1
- package/dist/src/utils/hooks-runner.js.map +0 -1
- package/dist/src/utils/html-diff.js.map +0 -1
- package/dist/src/utils/html.js.map +0 -1
- package/dist/src/utils/logger.js.map +0 -1
- package/dist/src/utils/loop.js.map +0 -1
- package/dist/src/utils/markdown-parser.js.map +0 -1
- package/dist/src/utils/markdown-query.js.map +0 -1
- package/dist/src/utils/markdown-terminal.js.map +0 -1
- package/dist/src/utils/research-parser.js.map +0 -1
- package/dist/src/utils/retry.js.map +0 -1
- package/dist/src/utils/rules-loader.js.map +0 -1
- package/dist/src/utils/strings.js.map +0 -1
- package/dist/src/utils/test-plan-markdown.js.map +0 -1
- package/dist/src/utils/throttle.js.map +0 -1
- package/dist/src/utils/unique-names.js.map +0 -1
- package/dist/src/utils/url-matcher.js.map +0 -1
- package/dist/src/utils/web-element.js.map +0 -1
- package/dist/src/utils/xpath.js.map +0 -1
- package/prompts/audit-rules.md +0 -124
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { Box, Text, useInput } from 'ink';
|
|
2
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { CommandHandler } from '../command-handler.js';
|
|
4
|
+
import type { ExplorbotConfig } from '../config.js';
|
|
5
|
+
import { executionController } from '../execution-controller.ts';
|
|
6
|
+
import type { ExplorBot, ExplorBotOptions } from '../explorbot.ts';
|
|
7
|
+
import type { KnowledgeTracker } from '../knowledge-tracker.js';
|
|
8
|
+
import type { StateTransition, WebPageState } from '../state-manager.js';
|
|
9
|
+
import { Test } from '../test-plan.ts';
|
|
10
|
+
import { tag } from '../utils/logger.js';
|
|
11
|
+
import ActivityPane from './ActivityPane.js';
|
|
12
|
+
import Autocomplete from './Autocomplete.js';
|
|
13
|
+
import InputPane from './InputPane.js';
|
|
14
|
+
import InputReadline from './InputReadline.js';
|
|
15
|
+
import LogPane from './LogPane.js';
|
|
16
|
+
import PlanEditor from './PlanEditor.js';
|
|
17
|
+
import PlanPane, { type PlanSummary } from './PlanPane.js';
|
|
18
|
+
import SessionTimer from './SessionTimer.js';
|
|
19
|
+
import StateTransitionPane from './StateTransitionPane.js';
|
|
20
|
+
import TaskPane, { WINDOW_SIZE } from './TaskPane.js';
|
|
21
|
+
import WelcomeChecklist from './WelcomeChecklist.js';
|
|
22
|
+
import WelcomeCommands from './WelcomeCommands.js';
|
|
23
|
+
|
|
24
|
+
interface AppProps {
|
|
25
|
+
explorBot: ExplorBot;
|
|
26
|
+
initialShowInput?: boolean;
|
|
27
|
+
exitOnEmptyInput?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function App({ explorBot, initialShowInput = false, exitOnEmptyInput = false }: AppProps) {
|
|
31
|
+
const sessionStartedAtRef = useRef<number>(Date.now());
|
|
32
|
+
const InputComponent = InputReadline;
|
|
33
|
+
const [showSessionTimer, setShowSessionTimer] = useState(false);
|
|
34
|
+
const [showInput, setShowInput] = useState(initialShowInput);
|
|
35
|
+
const [interruptPrompt, setInterruptPrompt] = useState<string | null>(null);
|
|
36
|
+
const [currentState, setCurrentState] = useState<WebPageState | null>(null);
|
|
37
|
+
const [lastTransition, setLastTransition] = useState<StateTransition | null>(null);
|
|
38
|
+
const [tasks, setTasks] = useState<Test[]>([]);
|
|
39
|
+
const tasksRef = useRef<Test[]>([]);
|
|
40
|
+
const [showPlanEditor, setShowPlanEditor] = useState(false);
|
|
41
|
+
const [taskScrollOffset, setTaskScrollOffset] = useState(0);
|
|
42
|
+
const [commandHandler] = useState(() => new CommandHandler(explorBot));
|
|
43
|
+
const [checklistData, setChecklistData] = useState<{ config: ExplorbotConfig; knowledgeTracker: KnowledgeTracker } | null>(null);
|
|
44
|
+
const [showWelcome, setShowWelcome] = useState(false);
|
|
45
|
+
const userInputPromiseRef = useRef<{
|
|
46
|
+
resolve: (value: string | null) => void;
|
|
47
|
+
reject: (reason?: any) => void;
|
|
48
|
+
} | null>(null);
|
|
49
|
+
const interruptResolveRef = useRef<((value: string | null) => void) | null>(null);
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
// biome-ignore lint/style/useConst: assigned after declaration in useEffect pattern
|
|
53
|
+
let unsubscribe: (() => void) | undefined;
|
|
54
|
+
let mounted = true;
|
|
55
|
+
|
|
56
|
+
process.env.INK_RUNNING = 'true';
|
|
57
|
+
|
|
58
|
+
explorBot.setUserResolve(async (error?: Error, showWelcomeFlag?: boolean) => {
|
|
59
|
+
if (error) {
|
|
60
|
+
console.error('Error occurred:', error.message);
|
|
61
|
+
}
|
|
62
|
+
if (showWelcomeFlag) {
|
|
63
|
+
setShowWelcome(true);
|
|
64
|
+
}
|
|
65
|
+
setShowInput(true);
|
|
66
|
+
|
|
67
|
+
return new Promise<string | null>((resolve, reject) => {
|
|
68
|
+
userInputPromiseRef.current = { resolve, reject };
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const manager = explorBot.getExplorer().getStateManager();
|
|
73
|
+
|
|
74
|
+
unsubscribe = manager.onStateChange((transition: StateTransition) => {
|
|
75
|
+
if (mounted) {
|
|
76
|
+
setLastTransition(transition);
|
|
77
|
+
setCurrentState(transition.toState);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const initialState = manager.getCurrentState();
|
|
82
|
+
if (initialState && mounted) {
|
|
83
|
+
setCurrentState(initialState);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return () => {
|
|
87
|
+
mounted = false;
|
|
88
|
+
if (unsubscribe) {
|
|
89
|
+
unsubscribe();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}, [explorBot]);
|
|
93
|
+
|
|
94
|
+
const [inputCallbackReady, setInputCallbackReady] = useState(false);
|
|
95
|
+
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
executionController.setInputCallback(async (prompt: string) => {
|
|
98
|
+
setInterruptPrompt(prompt);
|
|
99
|
+
setShowInput(true);
|
|
100
|
+
|
|
101
|
+
return new Promise<string | null>((resolve) => {
|
|
102
|
+
interruptResolveRef.current = resolve;
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const handleIdle = () => {
|
|
107
|
+
setShowInput(true);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
executionController.on('idle', handleIdle);
|
|
111
|
+
setInputCallbackReady(true);
|
|
112
|
+
|
|
113
|
+
return () => {
|
|
114
|
+
executionController.off('idle', handleIdle);
|
|
115
|
+
executionController.reset();
|
|
116
|
+
};
|
|
117
|
+
}, []);
|
|
118
|
+
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (!inputCallbackReady) return;
|
|
121
|
+
|
|
122
|
+
let mounted = true;
|
|
123
|
+
|
|
124
|
+
const visitInitial = async () => {
|
|
125
|
+
try {
|
|
126
|
+
await explorBot.visitInitialState();
|
|
127
|
+
} catch (error) {
|
|
128
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
129
|
+
tag('error').log('Failed to start:', message);
|
|
130
|
+
}
|
|
131
|
+
if (!mounted) return;
|
|
132
|
+
setChecklistData({
|
|
133
|
+
config: explorBot.getConfig(),
|
|
134
|
+
knowledgeTracker: explorBot.getKnowledgeTracker(),
|
|
135
|
+
});
|
|
136
|
+
setShowWelcome(true);
|
|
137
|
+
setShowInput(true);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
visitInitial();
|
|
141
|
+
|
|
142
|
+
return () => {
|
|
143
|
+
mounted = false;
|
|
144
|
+
};
|
|
145
|
+
}, [explorBot, inputCallbackReady]);
|
|
146
|
+
|
|
147
|
+
const planRef = useRef<ReturnType<typeof explorBot.getCurrentPlan>>(undefined);
|
|
148
|
+
const unsubscribeRef = useRef<(() => void) | undefined>(undefined);
|
|
149
|
+
const [completedPlans, setCompletedPlans] = useState<PlanSummary[]>([]);
|
|
150
|
+
const [activePlanInfo, setActivePlanInfo] = useState<PlanSummary | null>(null);
|
|
151
|
+
|
|
152
|
+
useEffect(() => {
|
|
153
|
+
const makeSummary = (plan: NonNullable<ReturnType<typeof explorBot.getCurrentPlan>>): PlanSummary => {
|
|
154
|
+
const enabled = plan.tests.filter((t) => t.enabled);
|
|
155
|
+
return {
|
|
156
|
+
title: plan.title,
|
|
157
|
+
testCount: enabled.length,
|
|
158
|
+
passed: enabled.filter((t) => t.isSuccessful).length,
|
|
159
|
+
failed: enabled.filter((t) => t.hasFailed).length,
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const subscribeToPlan = (plan: NonNullable<ReturnType<typeof explorBot.getCurrentPlan>>) => {
|
|
164
|
+
if (unsubscribeRef.current) unsubscribeRef.current();
|
|
165
|
+
|
|
166
|
+
if (planRef.current && planRef.current !== plan && planRef.current.tests.length > 0) {
|
|
167
|
+
const summary = makeSummary(planRef.current);
|
|
168
|
+
setCompletedPlans((prev) => {
|
|
169
|
+
if (prev.some((p) => p.title === summary.title)) return prev;
|
|
170
|
+
return [...prev, summary];
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
planRef.current = plan;
|
|
175
|
+
tasksRef.current = [...plan.tests];
|
|
176
|
+
setTasks(tasksRef.current);
|
|
177
|
+
setTaskScrollOffset(0);
|
|
178
|
+
setActivePlanInfo(makeSummary(plan));
|
|
179
|
+
|
|
180
|
+
let lastInProgressIdx = -1;
|
|
181
|
+
unsubscribeRef.current = plan.onTestsChange((updatedTests) => {
|
|
182
|
+
tasksRef.current = [...updatedTests];
|
|
183
|
+
setTasks(tasksRef.current);
|
|
184
|
+
setActivePlanInfo(makeSummary(plan));
|
|
185
|
+
const inProgressIdx = updatedTests.findIndex((t) => t.status === 'in_progress' && t.enabled);
|
|
186
|
+
if (inProgressIdx >= 0 && inProgressIdx !== lastInProgressIdx) {
|
|
187
|
+
lastInProgressIdx = inProgressIdx;
|
|
188
|
+
setTaskScrollOffset(Math.max(0, inProgressIdx - Math.floor(WINDOW_SIZE / 2)));
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const initialPlan = explorBot.getCurrentPlan();
|
|
194
|
+
if (initialPlan) subscribeToPlan(initialPlan);
|
|
195
|
+
|
|
196
|
+
const interval = setInterval(() => {
|
|
197
|
+
const currentPlan = explorBot.getCurrentPlan();
|
|
198
|
+
if (currentPlan && currentPlan !== planRef.current) {
|
|
199
|
+
subscribeToPlan(currentPlan);
|
|
200
|
+
} else if (!currentPlan && planRef.current) {
|
|
201
|
+
if (unsubscribeRef.current) unsubscribeRef.current();
|
|
202
|
+
if (planRef.current.tests.length > 0) {
|
|
203
|
+
const summary = makeSummary(planRef.current);
|
|
204
|
+
setCompletedPlans((prev) => {
|
|
205
|
+
if (prev.some((p) => p.title === summary.title)) return prev;
|
|
206
|
+
return [...prev, summary];
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
planRef.current = undefined;
|
|
210
|
+
tasksRef.current = [];
|
|
211
|
+
setTasks([]);
|
|
212
|
+
setActivePlanInfo(null);
|
|
213
|
+
}
|
|
214
|
+
}, 2000);
|
|
215
|
+
|
|
216
|
+
return () => {
|
|
217
|
+
clearInterval(interval);
|
|
218
|
+
if (unsubscribeRef.current) unsubscribeRef.current();
|
|
219
|
+
};
|
|
220
|
+
}, [explorBot]);
|
|
221
|
+
|
|
222
|
+
useInput((input, key) => {
|
|
223
|
+
if (key.escape) {
|
|
224
|
+
if (!showInput) {
|
|
225
|
+
executionController.interrupt();
|
|
226
|
+
}
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (key.ctrl) {
|
|
231
|
+
if (input === 'c') {
|
|
232
|
+
explorBot.stop().then(() => {
|
|
233
|
+
process.exit(0);
|
|
234
|
+
});
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (input === 't') {
|
|
238
|
+
setShowSessionTimer((prev) => !prev);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
if (input === 'e' && tasksRef.current.length > 0) {
|
|
242
|
+
setShowPlanEditor(true);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (!showInput && !showPlanEditor) {
|
|
248
|
+
if (key.upArrow) {
|
|
249
|
+
setTaskScrollOffset((prev) => Math.max(0, prev - 1));
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (key.downArrow) {
|
|
253
|
+
setTaskScrollOffset((prev) => prev + 1);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
const handleInputSubmit = useCallback(
|
|
260
|
+
async (input: string) => {
|
|
261
|
+
const trimmed = input.trim();
|
|
262
|
+
if (!trimmed) return;
|
|
263
|
+
|
|
264
|
+
if (trimmed.toLowerCase() === '/help') {
|
|
265
|
+
setShowWelcome(true);
|
|
266
|
+
} else {
|
|
267
|
+
setShowWelcome(false);
|
|
268
|
+
}
|
|
269
|
+
tag('input').log(`> ${trimmed}`);
|
|
270
|
+
|
|
271
|
+
const isCommand = trimmed.startsWith('/') || trimmed.startsWith('I.') || trimmed.startsWith('page.') || trimmed.startsWith('await ');
|
|
272
|
+
|
|
273
|
+
if (trimmed.toLowerCase() === '/plan:edit') {
|
|
274
|
+
if (tasksRef.current.length > 0) setShowPlanEditor(true);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (isCommand) {
|
|
279
|
+
setInterruptPrompt(null);
|
|
280
|
+
setShowInput(false);
|
|
281
|
+
interruptResolveRef.current = null;
|
|
282
|
+
executionController.startExecution();
|
|
283
|
+
try {
|
|
284
|
+
await commandHandler.executeCommand(trimmed);
|
|
285
|
+
} catch (error: any) {
|
|
286
|
+
if (error?.name === 'AbortError') {
|
|
287
|
+
tag('info').log('Operation cancelled');
|
|
288
|
+
} else {
|
|
289
|
+
throw error;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
setShowInput(true);
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (interruptResolveRef.current) {
|
|
297
|
+
interruptResolveRef.current(input);
|
|
298
|
+
interruptResolveRef.current = null;
|
|
299
|
+
setInterruptPrompt(null);
|
|
300
|
+
setShowInput(false);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (userInputPromiseRef.current) {
|
|
305
|
+
userInputPromiseRef.current.resolve(input);
|
|
306
|
+
userInputPromiseRef.current = null;
|
|
307
|
+
setShowInput(false);
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
setShowInput(false);
|
|
312
|
+
executionController.startExecution();
|
|
313
|
+
try {
|
|
314
|
+
await commandHandler.executeCommand(trimmed);
|
|
315
|
+
} catch (error: any) {
|
|
316
|
+
if (error?.name === 'AbortError') {
|
|
317
|
+
tag('info').log('Operation cancelled');
|
|
318
|
+
} else {
|
|
319
|
+
throw error;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
setShowInput(true);
|
|
323
|
+
},
|
|
324
|
+
[commandHandler]
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
const handleCommandStart = useCallback(() => {
|
|
328
|
+
setShowInput(false);
|
|
329
|
+
}, []);
|
|
330
|
+
|
|
331
|
+
const handleCommandComplete = useCallback(() => {
|
|
332
|
+
setShowInput(true);
|
|
333
|
+
}, []);
|
|
334
|
+
|
|
335
|
+
return (
|
|
336
|
+
<Box flexDirection="column">
|
|
337
|
+
{checklistData && <WelcomeChecklist config={checklistData.config} knowledgeTracker={checklistData.knowledgeTracker} />}
|
|
338
|
+
<Box flexDirection="column" flexGrow={1}>
|
|
339
|
+
<LogPane verboseMode={explorBot.getOptions()?.verbose || false} />
|
|
340
|
+
</Box>
|
|
341
|
+
|
|
342
|
+
{showPlanEditor && <PlanEditor tasks={tasks} onClose={() => setShowPlanEditor(false)} isActive={showPlanEditor} />}
|
|
343
|
+
|
|
344
|
+
<Box height={3} flexDirection="row" justifyContent="space-between" alignItems="center" paddingX={1}>
|
|
345
|
+
<ActivityPane isInputVisible={showInput} />
|
|
346
|
+
{showSessionTimer && <SessionTimer startedAt={sessionStartedAtRef.current} />}
|
|
347
|
+
</Box>
|
|
348
|
+
|
|
349
|
+
{showWelcome && <WelcomeCommands hasKnowledge={explorBot.getKnowledgeTracker().listAllKnowledge().length > 0} />}
|
|
350
|
+
{showInput && <Box height={1} />}
|
|
351
|
+
{interruptPrompt && showInput && (
|
|
352
|
+
<Box paddingX={1}>
|
|
353
|
+
<Text color="yellow">{interruptPrompt}</Text>
|
|
354
|
+
</Box>
|
|
355
|
+
)}
|
|
356
|
+
<Box display={showInput ? 'flex' : 'none'}>
|
|
357
|
+
<InputComponent commandHandler={commandHandler} onSubmit={handleInputSubmit} onCommandStart={handleCommandStart} onCommandComplete={handleCommandComplete} isActive={showInput && !showPlanEditor} visible={true} />
|
|
358
|
+
</Box>
|
|
359
|
+
|
|
360
|
+
<Box flexDirection="row" alignItems="flex-start" columnGap={1} minHeight={5}>
|
|
361
|
+
{currentState && (
|
|
362
|
+
<Box width={tasks.length > 0 ? '50%' : '100%'}>
|
|
363
|
+
<StateTransitionPane currentState={currentState} />
|
|
364
|
+
</Box>
|
|
365
|
+
)}
|
|
366
|
+
{tasks.length > 0 && (
|
|
367
|
+
<Box width={currentState ? '50%' : '100%'}>
|
|
368
|
+
<TaskPane tasks={tasks} scrollOffset={taskScrollOffset} />
|
|
369
|
+
</Box>
|
|
370
|
+
)}
|
|
371
|
+
<Autocomplete />
|
|
372
|
+
</Box>
|
|
373
|
+
|
|
374
|
+
<PlanPane completedPlans={completedPlans} activePlan={activePlanInfo} />
|
|
375
|
+
</Box>
|
|
376
|
+
);
|
|
377
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Box, Text } from 'ink';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useAutocompleteState } from './autocomplete-store.js';
|
|
4
|
+
|
|
5
|
+
const Autocomplete: React.FC = () => {
|
|
6
|
+
const { suggestions, selectedIndex, visible, argumentHint } = useAutocompleteState();
|
|
7
|
+
|
|
8
|
+
if (!visible) {
|
|
9
|
+
if (!argumentHint) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (!suggestions.length) {
|
|
15
|
+
return (
|
|
16
|
+
<Box position="absolute" top={0} left={0} width="100%" paddingX={1}>
|
|
17
|
+
<Text dimColor>{argumentHint}</Text>
|
|
18
|
+
</Box>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const effectiveSelectedIndex = Math.min(selectedIndex, suggestions.length - 1);
|
|
23
|
+
const maxHeight = 7;
|
|
24
|
+
const rowsPerColumn = Math.min(Math.max(1, maxHeight - 2), suggestions.length);
|
|
25
|
+
const columns: (typeof suggestions)[] = [];
|
|
26
|
+
for (let index = 0; index < suggestions.length; index += rowsPerColumn) {
|
|
27
|
+
columns.push(suggestions.slice(index, index + rowsPerColumn));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<Box position="absolute" top={0} left={0} width="100%" maxHeight={maxHeight} overflow="hidden" paddingX={1} paddingY={1} backgroundColor="#2a2a2a" flexDirection="row" columnGap={2}>
|
|
32
|
+
{columns.map((column, columnIndex) => (
|
|
33
|
+
<Box key={columnIndex} flexDirection="column">
|
|
34
|
+
{column.map((suggestion, rowIndex) => {
|
|
35
|
+
const index = columnIndex * rowsPerColumn + rowIndex;
|
|
36
|
+
const isSelected = index === effectiveSelectedIndex;
|
|
37
|
+
let display = suggestion.display;
|
|
38
|
+
if (display.length > 24) {
|
|
39
|
+
display = `${display.slice(0, 21)}...`;
|
|
40
|
+
}
|
|
41
|
+
let color = 'white';
|
|
42
|
+
let backgroundColor = '#2a2a2a';
|
|
43
|
+
if (isSelected) {
|
|
44
|
+
color = 'black';
|
|
45
|
+
backgroundColor = '#e6e6e6';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<Box key={suggestion.display} marginBottom={1}>
|
|
50
|
+
<Text color={color} backgroundColor={backgroundColor}>
|
|
51
|
+
{' '}
|
|
52
|
+
{display}{' '}
|
|
53
|
+
</Text>
|
|
54
|
+
</Box>
|
|
55
|
+
);
|
|
56
|
+
})}
|
|
57
|
+
</Box>
|
|
58
|
+
))}
|
|
59
|
+
</Box>
|
|
60
|
+
);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export default Autocomplete;
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { Box, Text, useInput } from 'ink';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
|
+
import type { CommandHandler } from '../command-handler.js';
|
|
5
|
+
import AutocompletePane from './AutocompletePane.js';
|
|
6
|
+
|
|
7
|
+
interface InputPaneProps {
|
|
8
|
+
commandHandler: CommandHandler;
|
|
9
|
+
exitOnEmptyInput?: boolean;
|
|
10
|
+
onSubmit?: (value: string) => Promise<void>;
|
|
11
|
+
onCommandStart?: () => void;
|
|
12
|
+
onCommandComplete?: () => void;
|
|
13
|
+
isActive?: boolean;
|
|
14
|
+
visible?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const InputPane: React.FC<InputPaneProps> = ({ commandHandler, exitOnEmptyInput = false, onSubmit, onCommandStart, onCommandComplete, isActive = true, visible = true }) => {
|
|
18
|
+
const [inputValue, setInputValue] = useState('');
|
|
19
|
+
const [cursorPosition, setCursorPosition] = useState(0);
|
|
20
|
+
const [showAutocomplete, setShowAutocomplete] = useState(false);
|
|
21
|
+
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
22
|
+
const [autoCompleteTriggered, setAutoCompleteTriggered] = useState(false);
|
|
23
|
+
const inputRef = useRef(inputValue);
|
|
24
|
+
const cursorRef = useRef(cursorPosition);
|
|
25
|
+
|
|
26
|
+
const addLog = useCallback((entry: string) => {
|
|
27
|
+
// For now, just console.log - in a real implementation this would integrate with the logger
|
|
28
|
+
console.log(entry);
|
|
29
|
+
}, []);
|
|
30
|
+
|
|
31
|
+
const handleSubmit = useCallback(
|
|
32
|
+
async (value: string) => {
|
|
33
|
+
const trimmedValue = value.trim();
|
|
34
|
+
|
|
35
|
+
if (!trimmedValue) {
|
|
36
|
+
if (exitOnEmptyInput) {
|
|
37
|
+
console.log('\nExiting...');
|
|
38
|
+
process.exit(0);
|
|
39
|
+
}
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Always call onCommandStart to hide input field
|
|
44
|
+
onCommandStart?.();
|
|
45
|
+
|
|
46
|
+
// Check if this is a command (starts with / or I.) or is 'exit'
|
|
47
|
+
const isCommand = trimmedValue.startsWith('/') || trimmedValue.startsWith('I.') || trimmedValue.startsWith('page.') || trimmedValue.startsWith('await ') || trimmedValue === 'exit' || trimmedValue === 'quit';
|
|
48
|
+
|
|
49
|
+
if (isCommand) {
|
|
50
|
+
if (onSubmit) {
|
|
51
|
+
await onSubmit(trimmedValue);
|
|
52
|
+
}
|
|
53
|
+
// Execute as command directly
|
|
54
|
+
try {
|
|
55
|
+
await commandHandler.executeCommand(trimmedValue);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
addLog(`Command failed: ${error}`);
|
|
58
|
+
} finally {
|
|
59
|
+
onCommandComplete?.();
|
|
60
|
+
}
|
|
61
|
+
} else if (onSubmit) {
|
|
62
|
+
// Use the provided submit callback for non-commands
|
|
63
|
+
await onSubmit(trimmedValue);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Reset state after submission
|
|
67
|
+
setInputValue('');
|
|
68
|
+
setCursorPosition(0);
|
|
69
|
+
setShowAutocomplete(false);
|
|
70
|
+
setSelectedIndex(0);
|
|
71
|
+
inputRef.current = '';
|
|
72
|
+
cursorRef.current = 0;
|
|
73
|
+
},
|
|
74
|
+
[commandHandler, exitOnEmptyInput, onSubmit, onCommandStart, onCommandComplete, addLog]
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
inputRef.current = inputValue;
|
|
79
|
+
}, [inputValue]);
|
|
80
|
+
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
cursorRef.current = cursorPosition;
|
|
83
|
+
}, [cursorPosition]);
|
|
84
|
+
|
|
85
|
+
const shouldShowAutocomplete = useCallback((value: string) => {
|
|
86
|
+
if (!value) return false;
|
|
87
|
+
if (value.startsWith('/')) return true;
|
|
88
|
+
if (value.startsWith('I.') || value.startsWith('page.') || value.startsWith('await ')) return true;
|
|
89
|
+
const lowered = value.toLowerCase();
|
|
90
|
+
return 'exit'.startsWith(lowered);
|
|
91
|
+
}, []);
|
|
92
|
+
|
|
93
|
+
useInput(
|
|
94
|
+
(input, key) => {
|
|
95
|
+
if (key.ctrl && input === 'c') {
|
|
96
|
+
console.log('\n🛑 Received Ctrl-C, exiting...');
|
|
97
|
+
process.exit(0);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (key.return) {
|
|
102
|
+
if (showAutocomplete) {
|
|
103
|
+
const filteredCommands = commandHandler.getFilteredCommands(inputRef.current);
|
|
104
|
+
const chosen = filteredCommands[selectedIndex] || filteredCommands[0];
|
|
105
|
+
if (chosen) {
|
|
106
|
+
inputRef.current = chosen;
|
|
107
|
+
cursorRef.current = chosen.length;
|
|
108
|
+
setInputValue(chosen);
|
|
109
|
+
setCursorPosition(chosen.length);
|
|
110
|
+
handleSubmit(chosen);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
handleSubmit(inputRef.current);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (key.ctrl && key.leftArrow) {
|
|
119
|
+
const nextCursor = Math.max(0, cursorRef.current - 1);
|
|
120
|
+
cursorRef.current = nextCursor;
|
|
121
|
+
setCursorPosition(nextCursor);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (key.ctrl && key.rightArrow) {
|
|
126
|
+
const nextCursor = Math.min(inputRef.current.length, cursorRef.current + 1);
|
|
127
|
+
cursorRef.current = nextCursor;
|
|
128
|
+
setCursorPosition(nextCursor);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (key.leftArrow) {
|
|
133
|
+
const nextCursor = Math.max(0, cursorRef.current - 1);
|
|
134
|
+
cursorRef.current = nextCursor;
|
|
135
|
+
setCursorPosition(nextCursor);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (key.rightArrow) {
|
|
140
|
+
const nextCursor = Math.min(inputRef.current.length, cursorRef.current + 1);
|
|
141
|
+
cursorRef.current = nextCursor;
|
|
142
|
+
setCursorPosition(nextCursor);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Handle autocomplete navigation
|
|
147
|
+
if (showAutocomplete && (key.upArrow || (key.shift && key.leftArrow))) {
|
|
148
|
+
const filteredCommands = commandHandler.getFilteredCommands(inputRef.current);
|
|
149
|
+
setSelectedIndex((prev) => (prev > 0 ? prev - 1 : filteredCommands.length - 1));
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (showAutocomplete && (key.downArrow || (key.shift && key.rightArrow))) {
|
|
154
|
+
const filteredCommands = commandHandler.getFilteredCommands(inputRef.current);
|
|
155
|
+
setSelectedIndex((prev) => (prev < filteredCommands.length - 1 ? prev + 1 : 0));
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (key.tab) {
|
|
160
|
+
const filteredCommands = commandHandler.getFilteredCommands(inputRef.current);
|
|
161
|
+
if (selectedIndex < filteredCommands.length) {
|
|
162
|
+
const selectedCommand = filteredCommands[selectedIndex];
|
|
163
|
+
inputRef.current = selectedCommand;
|
|
164
|
+
cursorRef.current = selectedCommand.length;
|
|
165
|
+
setInputValue(selectedCommand);
|
|
166
|
+
setShowAutocomplete(false);
|
|
167
|
+
setSelectedIndex(0);
|
|
168
|
+
setCursorPosition(selectedCommand.length);
|
|
169
|
+
setAutoCompleteTriggered(true);
|
|
170
|
+
}
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (key.backspace || key.delete) {
|
|
175
|
+
if (cursorRef.current > 0) {
|
|
176
|
+
const currentValue = inputRef.current;
|
|
177
|
+
const currentCursor = cursorRef.current;
|
|
178
|
+
const newValue = currentValue.slice(0, currentCursor - 1) + currentValue.slice(currentCursor);
|
|
179
|
+
const nextCursor = Math.max(0, currentCursor - 1);
|
|
180
|
+
inputRef.current = newValue;
|
|
181
|
+
cursorRef.current = nextCursor;
|
|
182
|
+
setInputValue(newValue);
|
|
183
|
+
setCursorPosition(nextCursor);
|
|
184
|
+
setSelectedIndex(0);
|
|
185
|
+
setAutoCompleteTriggered(false);
|
|
186
|
+
setShowAutocomplete(shouldShowAutocomplete(newValue));
|
|
187
|
+
}
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (input && input.length === 1) {
|
|
192
|
+
const currentValue = inputRef.current;
|
|
193
|
+
const currentCursor = cursorRef.current;
|
|
194
|
+
const newValue = currentValue.slice(0, currentCursor) + input + currentValue.slice(currentCursor);
|
|
195
|
+
const nextCursor = currentCursor + 1;
|
|
196
|
+
inputRef.current = newValue;
|
|
197
|
+
cursorRef.current = nextCursor;
|
|
198
|
+
setInputValue(newValue);
|
|
199
|
+
setCursorPosition(nextCursor);
|
|
200
|
+
setSelectedIndex(0);
|
|
201
|
+
setAutoCompleteTriggered(false);
|
|
202
|
+
setShowAutocomplete(shouldShowAutocomplete(newValue));
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
{ isActive }
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
// Register with command handler on mount, unregister on unmount
|
|
209
|
+
useEffect(() => {
|
|
210
|
+
const unregister = commandHandler.registerInputPane(addLog, handleSubmit);
|
|
211
|
+
commandHandler.setExitOnEmptyInput(exitOnEmptyInput);
|
|
212
|
+
|
|
213
|
+
return unregister;
|
|
214
|
+
}, [commandHandler, addLog, handleSubmit, exitOnEmptyInput]);
|
|
215
|
+
|
|
216
|
+
const displayValue = inputValue || '';
|
|
217
|
+
const beforeCursor = displayValue.slice(0, cursorPosition);
|
|
218
|
+
const afterCursor = displayValue.slice(cursorPosition);
|
|
219
|
+
|
|
220
|
+
const filteredCommands = commandHandler.getFilteredCommands(inputValue);
|
|
221
|
+
|
|
222
|
+
if (!visible) {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return (
|
|
227
|
+
<Box flexDirection="column">
|
|
228
|
+
<Box>
|
|
229
|
+
<Text color="green">> </Text>
|
|
230
|
+
<Text>{beforeCursor}</Text>
|
|
231
|
+
<Text backgroundColor="white" color="black">
|
|
232
|
+
{' '}
|
|
233
|
+
</Text>
|
|
234
|
+
<Text>{afterCursor}</Text>
|
|
235
|
+
</Box>
|
|
236
|
+
|
|
237
|
+
<AutocompletePane
|
|
238
|
+
commands={filteredCommands}
|
|
239
|
+
input={inputValue}
|
|
240
|
+
selectedIndex={selectedIndex}
|
|
241
|
+
onSelect={(index: number) => {
|
|
242
|
+
if (index < filteredCommands.length) {
|
|
243
|
+
const selectedCommand = filteredCommands[index];
|
|
244
|
+
inputRef.current = selectedCommand;
|
|
245
|
+
cursorRef.current = selectedCommand.length;
|
|
246
|
+
setInputValue(selectedCommand);
|
|
247
|
+
setShowAutocomplete(false);
|
|
248
|
+
setSelectedIndex(0);
|
|
249
|
+
setCursorPosition(selectedCommand.length);
|
|
250
|
+
setAutoCompleteTriggered(true);
|
|
251
|
+
}
|
|
252
|
+
}}
|
|
253
|
+
visible={showAutocomplete}
|
|
254
|
+
/>
|
|
255
|
+
</Box>
|
|
256
|
+
);
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
export default InputPane;
|