@kabmo-labs/kabmo 0.22.0 → 0.24.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 +1 -1
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +873 -524
- package/dist/client/static/js/{index-297dck9a.js → index-jcr5twtp.js} +799 -795
- package/dist/client/static/js/index-z3w7n85q.css +1 -0
- package/marketplace/plugins/stats/package.json +2 -2
- package/marketplace/plugins/stats/src/groups.test.ts +14 -0
- package/marketplace/plugins/stats/src/groups.ts +20 -0
- package/marketplace/plugins/stats/src/labels.test.ts +9 -0
- package/marketplace/plugins/stats/src/labels.ts +7 -0
- package/marketplace/plugins/stats/src/server.ts +1 -1
- package/package.json +1 -1
- package/src/client/App.tsx +20 -19
- package/src/client/components/common/ComposerTextarea.tsx +10 -1
- package/src/client/components/common/Modal.tsx +2 -6
- package/src/client/components/common/PWAInstallButton.tsx +3 -2
- package/src/client/components/common/Toast.test.tsx +298 -0
- package/src/client/components/common/Toast.tsx +103 -37
- package/src/client/components/common/ToastStack.tsx +33 -12
- package/src/client/components/common/ViewportSelector.tsx +122 -114
- package/src/client/components/common/context-usage-button/Ring.tsx +38 -1
- package/src/client/components/common/context-usage-button/index.test.tsx +19 -3
- package/src/client/components/common/context-usage-button/index.tsx +5 -2
- package/src/client/components/common/harness-glyph/brands.ts +65 -0
- package/src/client/components/common/harness-glyph/harness-glyph.test.ts +185 -0
- package/src/client/components/common/harness-glyph/index.tsx +131 -0
- package/src/client/components/common/header-controls/MoreMenu.tsx +2 -1
- package/src/client/components/common/header-controls/index.tsx +16 -8
- package/src/client/components/common/header-panel-buttons/index.tsx +4 -3
- package/src/client/components/common/panel-mark/index.test.tsx +2 -2
- package/src/client/components/common/panel-mark/index.tsx +11 -2
- package/src/client/components/common/search-select/index.tsx +305 -0
- package/src/client/components/common/search-select/search-select.test.tsx +217 -0
- package/src/client/components/common/server-control/index.tsx +3 -2
- package/src/client/components/common/session-row/index.tsx +18 -1
- package/src/client/components/common/toolbar-row/index.tsx +57 -20
- package/src/client/components/layout/desktop-layout/LeftColumn.tsx +1 -3
- package/src/client/components/layout/desktop-layout/TopNavbar.tsx +3 -2
- package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +7 -1
- package/src/client/components/layout/desktop-layout/index.tsx +1 -3
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +1 -0
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +18 -1
- package/src/client/components/layout/session-sidebar/SessionsView.tsx +1 -3
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.test.tsx +332 -0
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +310 -0
- package/src/client/components/layout/session-sidebar/about-modal/SocialLinks.tsx +63 -51
- package/src/client/components/layout/session-sidebar/about-modal/UpdateSection.tsx +4 -2
- package/src/client/components/layout/session-sidebar/about-modal/index.test.tsx +122 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +136 -35
- package/src/client/components/layout/session-sidebar/harness-mark.test.tsx +126 -0
- package/src/client/components/layout/session-sidebar/modern/ActionRow.tsx +4 -3
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +1 -0
- package/src/client/components/mobile/LayoutWrapper.tsx +1 -7
- package/src/client/components/mobile/SessionSidebar.tsx +1 -3
- package/src/client/components/mobile/mobile-main-view/Header.tsx +3 -2
- package/src/client/components/mobile/mobile-session-sidebar/Dialogs.tsx +0 -8
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +1 -0
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +17 -1
- package/src/client/components/settings/Modal.tsx +26 -22
- package/src/client/components/settings/Sidebar.tsx +45 -5
- package/src/client/components/settings/categories/HarnessSettings.tsx +207 -0
- package/src/client/components/settings/categories/ProjectSettings.tsx +1 -3
- package/src/client/components/settings/categories/ProviderSettings.tsx +0 -4
- package/src/client/components/settings/categories/SkillCatalogSettings.tsx +13 -23
- package/src/client/components/settings/categories/agent-settings/ModelPicker.tsx +23 -30
- package/src/client/components/settings/categories/appearance-settings/IconStyleSection.tsx +20 -11
- package/src/client/components/settings/categories/chat-settings/GoalSection.tsx +16 -16
- package/src/client/components/settings/categories/harness-settings/AddProviderForm.tsx +219 -0
- package/src/client/components/settings/categories/harness-settings/ConfigForm.tsx +268 -0
- package/src/client/components/settings/categories/harness-settings/EnvProviderForm.tsx +146 -0
- package/src/client/components/settings/categories/harness-settings/HarnessCard.tsx +278 -0
- package/src/client/components/settings/categories/harness-settings/ImportSection.tsx +195 -0
- package/src/client/components/settings/categories/harness-settings/ProviderPanel.tsx +152 -0
- package/src/client/components/settings/categories/harness-settings/ToggleList.tsx +147 -0
- package/src/client/components/settings/categories/harness-settings/parts.test.tsx +97 -0
- package/src/client/components/settings/categories/harness-settings/parts.tsx +84 -0
- package/src/client/components/settings/categories/harness-settings/provider-panel.test.tsx +313 -0
- package/src/client/components/settings/categories/omp-settings/RoleEditor.test.ts +60 -39
- package/src/client/components/settings/categories/omp-settings/RoleRow.tsx +32 -41
- package/src/client/components/settings/categories/omp-settings/role-picker.test-util.ts +45 -0
- package/src/client/components/settings/categories/panel-plugins/PluginMark.test.ts +1 -1
- package/src/client/components/settings/categories/panel-plugins/PluginMark.tsx +11 -4
- package/src/client/components/settings/groups.test.tsx +160 -0
- package/src/client/components/settings/harness-icons.test.tsx +134 -0
- package/src/client/components/workspace/browser-panel/AddressBar.tsx +3 -13
- package/src/client/components/workspace/browser-toolbar/clusters.tsx +237 -0
- package/src/client/components/workspace/browser-toolbar/index.test.tsx +167 -0
- package/src/client/components/workspace/browser-toolbar/index.tsx +99 -100
- package/src/client/components/workspace/btw-panel/Messages.tsx +4 -1
- package/src/client/components/workspace/btw-panel/index.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +11 -7
- package/src/client/components/workspace/chat-timeline/ChatOverlays.tsx +5 -2
- package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +13 -0
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +13 -0
- package/src/client/components/workspace/chat-timeline/GeneratingIndicator.test.ts +41 -0
- package/src/client/components/workspace/chat-timeline/GeneratingIndicator.tsx +19 -14
- package/src/client/components/workspace/chat-timeline/MessageList.test.ts +14 -0
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +6 -0
- package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +14 -0
- package/src/client/components/workspace/chat-timeline/RunFooter.tsx +4 -0
- package/src/client/components/workspace/chat-timeline/RunMark.tsx +58 -0
- package/src/client/components/workspace/chat-timeline/SubagentView.tsx +4 -1
- package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +4 -0
- package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +1 -0
- package/src/client/components/workspace/chat-timeline/chat-input/ComposerRows.tsx +11 -0
- package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.test.ts +13 -0
- package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.tsx +8 -1
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.test.ts +27 -1
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +48 -23
- package/src/client/components/workspace/chat-timeline/chat-input/composer-portal.test.tsx +1 -0
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +21 -1
- package/src/client/components/workspace/chat-timeline/chat-input/modes-props.ts +7 -0
- package/src/client/components/workspace/chat-timeline/chat-input/props.ts +13 -0
- package/src/client/components/workspace/chat-timeline/chat-input/selection.ts +11 -2
- package/src/client/components/workspace/chat-timeline/chat-input/styles.test.tsx +1 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +17 -15
- package/src/client/components/workspace/chat-timeline/pending-harness.test.tsx +157 -0
- package/src/client/components/workspace/chat-timeline/run-mark.test.ts +104 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FrameControl.tsx +11 -20
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/GroupedAsk.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/QuestionBlock.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/drafts.ts +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.tsx +2 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.test.ts +31 -3
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +5 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +56 -45
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +38 -94
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/wait-parts.tsx +76 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.ts +2 -1
- package/src/client/components/workspace/file-explorer/index.test.ts +25 -0
- package/src/client/components/workspace/file-explorer/index.tsx +10 -6
- package/src/client/components/workspace/git-panel/index.test.ts +13 -3
- package/src/client/components/workspace/git-panel/index.tsx +1 -3
- package/src/client/components/workspace/model-dropdown/Fullscreen.tsx +92 -0
- package/src/client/components/workspace/model-dropdown/HarnessTabs.tsx +290 -0
- package/src/client/components/workspace/model-dropdown/Item.tsx +11 -0
- package/src/client/components/workspace/model-dropdown/Panel.tsx +119 -8
- package/src/client/components/workspace/model-dropdown/Section.tsx +4 -0
- package/src/client/components/workspace/model-dropdown/fullscreen-picker.ts +51 -0
- package/src/client/components/workspace/model-dropdown/harness-models.test.ts +177 -0
- package/src/client/components/workspace/model-dropdown/harness-models.ts +148 -0
- package/src/client/components/workspace/model-dropdown/harness-tabs.test.tsx +336 -0
- package/src/client/components/workspace/model-dropdown/index.tsx +114 -85
- package/src/client/components/workspace/model-dropdown/placement.test.tsx +127 -0
- package/src/client/components/workspace/model-dropdown/popover-metrics.test.ts +107 -0
- package/src/client/components/workspace/model-dropdown/popover-metrics.ts +118 -0
- package/src/client/components/workspace/model-dropdown/row-mutations.ts +106 -0
- package/src/client/components/workspace/model-dropdown/trigger.test.ts +22 -2
- package/src/client/components/workspace/model-dropdown/use-popover-size.ts +89 -0
- package/src/client/data/settings/omp-schema.json +224 -17
- package/src/client/hooks/chat/composer/index.ts +11 -2
- package/src/client/hooks/chat/composer/items.test.ts +11 -0
- package/src/client/hooks/chat/composer/items.ts +4 -2
- package/src/client/hooks/chat/composer/model-selection.test.ts +110 -0
- package/src/client/hooks/chat/composer/model-selection.ts +45 -4
- package/src/client/hooks/chat/omp/prompt-send.ts +4 -2
- package/src/client/hooks/chat/timeline/actions.ts +10 -5
- package/src/client/hooks/chat/timeline/ask-frames.ts +5 -4
- package/src/client/hooks/chat/timeline/composer-local-actions.test.ts +19 -81
- package/src/client/hooks/chat/timeline/composer-modes.ts +11 -2
- package/src/client/hooks/chat/timeline/composer-refs.ts +16 -1
- package/src/client/hooks/chat/timeline/index.ts +27 -35
- package/src/client/hooks/chat/timeline/mode-availability.test.ts +51 -0
- package/src/client/hooks/chat/timeline/modes-contract.ts +6 -0
- package/src/client/hooks/chat/timeline/modes.ts +41 -2
- package/src/client/hooks/chat/timeline/new-chat-open.test.ts +86 -0
- package/src/client/hooks/chat/timeline/new-chat-open.ts +23 -5
- package/src/client/hooks/chat/timeline/new-chat.test.ts +32 -4
- package/src/client/hooks/chat/timeline/new-chat.ts +18 -6
- package/src/client/hooks/chat/timeline/prompt-text.test.ts +7 -0
- package/src/client/hooks/chat/timeline/prompt-text.ts +15 -6
- package/src/client/hooks/chat/timeline/rewind-actions.test.ts +51 -1
- package/src/client/hooks/chat/timeline/rewind-actions.ts +23 -1
- package/src/client/hooks/chat/timeline/run-identity.test.ts +52 -0
- package/src/client/hooks/chat/timeline/run-identity.ts +23 -11
- package/src/client/hooks/chat/timeline/send-execute.test.ts +55 -0
- package/src/client/hooks/chat/timeline/send-props.ts +11 -3
- package/src/client/hooks/chat/timeline/send-steer.test.ts +2 -3
- package/src/client/hooks/chat/timeline/send.test-util.ts +3 -2
- package/src/client/hooks/chat/timeline/send.test.ts +2 -3
- package/src/client/hooks/chat/timeline/send.ts +34 -8
- package/src/client/hooks/chat/timeline/session-harness.test.ts +163 -0
- package/src/client/hooks/chat/timeline/session-harness.ts +164 -0
- package/src/client/hooks/chat/timeline/session-load.test-util.ts +6 -2
- package/src/client/hooks/chat/timeline/session-load.test.ts +31 -0
- package/src/client/hooks/chat/timeline/session-load.ts +6 -14
- package/src/client/hooks/chat/timeline/session-shapes.ts +32 -0
- package/src/client/hooks/chat/timeline/spawn-harness.ts +41 -0
- package/src/client/hooks/chat/timeline/timeline-running.ts +55 -0
- package/src/client/hooks/chat/timeline/tui-only-guard.ts +9 -0
- package/src/client/hooks/chat/timeline/undo-confirmation.test.ts +131 -0
- package/src/client/hooks/models/harness-catalog.ts +114 -0
- package/src/client/hooks/models/provider-writes.test.ts +81 -0
- package/src/client/hooks/models/provider-writes.ts +144 -0
- package/src/client/hooks/models/use-harness-versions.test.ts +152 -0
- package/src/client/hooks/models/use-harness-versions.ts +136 -0
- package/src/client/hooks/models/use-harnesses-controller.ts +57 -0
- package/src/client/hooks/models/use-harnesses-signal.test.ts +128 -0
- package/src/client/hooks/models/use-harnesses.test.ts +187 -0
- package/src/client/hooks/models/use-harnesses.ts +215 -0
- package/src/client/hooks/settings/providers/index.ts +1 -3
- package/src/client/hooks/ui/editor-error-toast.ts +10 -3
- package/src/client/hooks/ui/icon-style.ts +28 -0
- package/src/client/hooks/ui/on-click-outside.test.ts +104 -0
- package/src/client/hooks/ui/on-click-outside.ts +14 -2
- package/src/client/hooks/ui/theme.ts +6 -0
- package/src/client/hooks/ui/toast-queue.test.ts +126 -0
- package/src/client/hooks/ui/toasts.ts +132 -27
- package/src/client/hooks/ui/ui-feedback.test.ts +4 -91
- package/src/client/lib/ui/control-plate.test.ts +76 -0
- package/src/client/lib/ui/control-plate.ts +65 -0
- package/src/client/tailwind.css +47 -1
- package/src/server/lib/assets/shell-attributes.server.ts +9 -2
- package/src/server/lib/assets/shell-attributes.test.ts +22 -6
- package/src/server/lib/db/schema.ts +4 -0
- package/src/server/lib/harness/acp/acp-audit.server.ts +107 -0
- package/src/server/lib/harness/acp/acp-goal-driver.server.ts +153 -0
- package/src/server/lib/harness/acp/acp-goal-state.server.ts +136 -0
- package/src/server/lib/harness/acp/acp-goal.server.ts +273 -0
- package/src/server/lib/harness/acp/acp-goal.test.ts +229 -0
- package/src/server/lib/harness/acp/acp-telemetry.server.ts +133 -0
- package/src/server/lib/harness/acp/acp-telemetry.test.ts +85 -0
- package/src/server/lib/harness/acp/acp-todos.server.ts +45 -0
- package/src/server/lib/harness/acp/acp-todos.test.ts +43 -0
- package/src/server/lib/harness/acp/activation.test.ts +81 -0
- package/src/server/lib/harness/acp/activation.ts +72 -0
- package/src/server/lib/harness/acp/calls.ts +97 -0
- package/src/server/lib/harness/acp/client.test.ts +73 -0
- package/src/server/lib/harness/acp/client.ts +339 -0
- package/src/server/lib/harness/acp/commands.test.ts +92 -0
- package/src/server/lib/harness/acp/commands.ts +165 -0
- package/src/server/lib/harness/acp/frames.test.ts +315 -0
- package/src/server/lib/harness/acp/frames.ts +349 -0
- package/src/server/lib/harness/acp/mapper.ts +204 -0
- package/src/server/lib/harness/acp/permissions.test.ts +66 -0
- package/src/server/lib/harness/acp/permissions.ts +155 -0
- package/src/server/lib/harness/acp/prompt.test.ts +130 -0
- package/src/server/lib/harness/acp/prompt.ts +134 -0
- package/src/server/lib/harness/acp/protocol.ts +162 -0
- package/src/server/lib/harness/acp/session-config.test.ts +73 -0
- package/src/server/lib/harness/acp/session-config.ts +148 -0
- package/src/server/lib/harness/acp/session-facts.ts +71 -0
- package/src/server/lib/harness/acp/session-handshake.ts +89 -0
- package/src/server/lib/harness/acp/session-idle.ts +51 -0
- package/src/server/lib/harness/acp/session-notifications.ts +95 -0
- package/src/server/lib/harness/acp/session-observers.test.ts +193 -0
- package/src/server/lib/harness/acp/session-options.ts +33 -0
- package/src/server/lib/harness/acp/session-permissions.test.ts +105 -0
- package/src/server/lib/harness/acp/session-permissions.ts +74 -0
- package/src/server/lib/harness/acp/session-reaper.test.ts +96 -0
- package/src/server/lib/harness/acp/session-turns.ts +95 -0
- package/src/server/lib/harness/acp/session-usage.ts +60 -0
- package/src/server/lib/harness/acp/session-web-state.ts +61 -0
- package/src/server/lib/harness/acp/session.test-util.ts +160 -0
- package/src/server/lib/harness/acp/session.test.ts +233 -0
- package/src/server/lib/harness/acp/session.ts +350 -0
- package/src/server/lib/harness/acp/turn.ts +199 -0
- package/src/server/lib/harness/acp/verbs.ts +87 -0
- package/src/server/lib/harness/auto-probe.server.test.ts +121 -0
- package/src/server/lib/harness/auto-probe.server.ts +178 -0
- package/src/server/lib/harness/capabilities.ts +67 -0
- package/src/server/lib/harness/config-invalidation.test.ts +91 -0
- package/src/server/lib/harness/config.server.test.ts +105 -0
- package/src/server/lib/harness/config.server.ts +98 -0
- package/src/server/lib/harness/enabled.server.test.ts +87 -0
- package/src/server/lib/harness/enabled.server.ts +61 -0
- package/src/server/lib/harness/launch-table.ts +195 -0
- package/src/server/lib/harness/launch.test.ts +220 -0
- package/src/server/lib/harness/launch.ts +216 -0
- package/src/server/lib/harness/probe-cache.server.test.ts +154 -0
- package/src/server/lib/harness/probe-cache.server.ts +177 -0
- package/src/server/lib/harness/provider-entry.ts +212 -0
- package/src/server/lib/harness/provider-file.server.ts +67 -0
- package/src/server/lib/harness/provider-import.test.ts +191 -0
- package/src/server/lib/harness/provider-probe.server.ts +123 -0
- package/src/server/lib/harness/provider-sources.server.test.ts +45 -0
- package/src/server/lib/harness/provider-sources.server.ts +308 -0
- package/src/server/lib/harness/provider-write-error.ts +19 -0
- package/src/server/lib/harness/provider-write.server.test.ts +308 -0
- package/src/server/lib/harness/provider-write.server.ts +339 -0
- package/src/server/lib/harness/provider-zcode.server.test.ts +270 -0
- package/src/server/lib/harness/provider-zcode.server.ts +324 -0
- package/src/server/lib/harness/register.server.ts +36 -0
- package/src/server/lib/harness/registry.ts +58 -0
- package/src/server/lib/harness/schema.server.ts +129 -0
- package/src/server/lib/harness/session-store.server.test.ts +175 -0
- package/src/server/lib/harness/session-store.server.ts +206 -0
- package/src/server/lib/harness/session-title.server.test.ts +109 -0
- package/src/server/lib/harness/session-title.server.ts +70 -0
- package/src/server/lib/harness/session.ts +74 -0
- package/src/server/lib/harness/spawn.server.ts +133 -0
- package/src/server/lib/harness/update-state.server.ts +185 -0
- package/src/server/lib/lifecycle/after-listen.ts +7 -0
- package/src/server/lib/models/provider-items.server.ts +1 -1
- package/src/server/lib/models/registry-refresh.server.test.ts +87 -0
- package/src/server/lib/models/registry-refresh.server.ts +98 -0
- package/src/server/lib/omp/config/models-config.ts +4 -0
- package/src/server/lib/omp/core/cli.ts +13 -0
- package/src/server/lib/omp/core/host-resolution.test.ts +6 -3
- package/src/server/lib/omp/rpc/child-config.ts +5 -4
- package/src/server/lib/omp/rpc/constants.test.ts +2 -1
- package/src/server/lib/omp/rpc/event-fanout.ts +9 -0
- package/src/server/lib/omp/rpc/forked-resume.test.ts +14 -3
- package/src/server/lib/omp/rpc/rpc-primitives.test.ts +11 -0
- package/src/server/lib/omp/rpc/session-registration.ts +7 -2
- package/src/server/lib/omp/rpc/session-registry.test.ts +2 -1
- package/src/server/lib/omp/rpc/session-registry.ts +74 -5
- package/src/server/lib/omp/session/acp-rows.server.ts +79 -0
- package/src/server/lib/omp/session/delete-flow.server.ts +15 -8
- package/src/server/lib/omp/session/delete.server.ts +12 -0
- package/src/server/lib/omp/session/sidebar-data.harness.test.ts +247 -0
- package/src/server/lib/omp/session/sidebar-data.server.ts +56 -3
- package/src/server/lib/queue/delivery.server.test.ts +4 -2
- package/src/server/lib/queue/payload.test.ts +67 -0
- package/src/server/lib/queue/payload.ts +9 -3
- package/src/server/lib/realtime/signals.server.test.ts +99 -0
- package/src/server/lib/realtime/signals.server.ts +25 -5
- package/src/server/lib/realtime/topics/session-data.server.ts +29 -0
- package/src/server/lib/realtime/topics/session.server.ts +3 -3
- package/src/server/routes/agent/command-resume.test.ts +77 -0
- package/src/server/routes/agent/command.test.ts +243 -2
- package/src/server/routes/agent/command.ts +78 -15
- package/src/server/routes/agent/harness-command.ts +133 -0
- package/src/server/routes/agent/new.ts +63 -1
- package/src/server/routes/chat/rewind.test.ts +147 -0
- package/src/server/routes/chat/rewind.ts +29 -7
- package/src/server/routes/chat/session.test.ts +240 -0
- package/src/server/routes/chat/session.ts +96 -4
- package/src/server/routes/harness/add-provider.test.ts +233 -0
- package/src/server/routes/harness/import-action.ts +272 -0
- package/src/server/routes/harness/import.test.ts +196 -0
- package/src/server/routes/harness/index.ts +13 -0
- package/src/server/routes/harness/root.ts +280 -0
- package/src/server/routes/harness/toggle.test.ts +127 -0
- package/src/server/routes/harness/update.ts +259 -0
- package/src/server/routes/harness/versions.test.ts +148 -0
- package/src/server/routes/harness/versions.ts +105 -0
- package/src/server/routes/index.ts +2 -0
- package/src/server/routes/sessions/delete-acp.test.ts +227 -0
- package/src/server/routes/sessions/queue.ts +7 -2
- package/src/server/routes/sessions/routes-queue.test.ts +52 -0
- package/src/server/routes/sessions/routes.test.ts +47 -13
- package/src/server/routes/sessions/session.ts +35 -0
- package/src/server/routes/settings/commands-harness.test.ts +92 -0
- package/src/server/routes/settings/commands.ts +26 -0
- package/src/server/routes/settings/model-override.ts +5 -2
- package/src/server/routes/settings/provider-entry.ts +2 -2
- package/src/server/routes/settings/provider-model.ts +2 -2
- package/src/server/routes/settings/provider-models.ts +2 -2
- package/src/server/routes/settings/provider-refresh.ts +6 -4
- package/src/server/routes/settings/providers.ts +3 -1
- package/src/server/routes/settings/settings-config-routes.test.ts +10 -2
- package/src/server/routes/settings/skills.ts +12 -0
- package/src/shared/lib/chat/ask-form/fields.ts +76 -0
- package/src/shared/lib/chat/ask-form/index.ts +323 -0
- package/src/shared/lib/chat/ask-form/tokens.ts +199 -0
- package/src/shared/lib/chat/ask-form/types.ts +43 -0
- package/src/shared/lib/chat/ask-form.test.ts +137 -0
- package/src/shared/lib/chat/ask-questions.test.ts +65 -1
- package/src/shared/lib/chat/ask-questions.ts +51 -145
- package/src/shared/lib/chat/ask-results.ts +198 -0
- package/src/shared/lib/chat/composer/client.ts +20 -8
- package/src/shared/lib/chat/context/usage.test.ts +8 -4
- package/src/shared/lib/chat/context/usage.ts +17 -3
- package/src/shared/lib/chat/omp/abort.test.ts +61 -0
- package/src/shared/lib/chat/omp/abort.ts +8 -2
- package/src/shared/lib/chat/omp/tool-frames.test.ts +23 -0
- package/src/shared/lib/chat/omp/tool-frames.ts +12 -2
- package/src/shared/lib/chat/timeline/omp-callbacks.ts +13 -1
- package/src/shared/lib/chat/timeline/prompt-error.test.ts +146 -0
- package/src/shared/lib/chat/timeline/prompt-error.ts +88 -0
- package/src/shared/lib/chat/tool/summary-wait.test.ts +18 -8
- package/src/shared/lib/chat/tool/wait-facts.ts +14 -8
- package/src/shared/lib/harness/brand-color.test.ts +66 -0
- package/src/shared/lib/harness/brand-color.ts +96 -0
- package/src/shared/lib/harness/catalog.test.ts +88 -0
- package/src/shared/lib/harness/catalog.ts +169 -0
- package/src/shared/lib/harness/config-fields.test.ts +139 -0
- package/src/shared/lib/harness/config-fields.ts +168 -0
- package/src/shared/lib/harness/config.test.ts +153 -0
- package/src/shared/lib/harness/config.ts +206 -0
- package/src/shared/lib/harness/dialects.test.ts +140 -0
- package/src/shared/lib/harness/dialects.ts +249 -0
- package/src/shared/lib/harness/enabled.test.ts +79 -0
- package/src/shared/lib/harness/enabled.ts +72 -0
- package/src/shared/lib/harness/menu.test.ts +94 -0
- package/src/shared/lib/harness/menu.ts +88 -0
- package/src/shared/lib/harness/provider-facts.test.ts +199 -0
- package/src/shared/lib/harness/provider-facts.ts +349 -0
- package/src/shared/lib/harness/provider-slug.ts +46 -0
- package/src/shared/lib/harness/providers.ts +175 -0
- package/src/shared/lib/harness/rewind.ts +24 -0
- package/src/shared/lib/harness/status.test.ts +158 -0
- package/src/shared/lib/harness/status.ts +112 -0
- package/src/shared/lib/harness/update-plan.test.ts +163 -0
- package/src/shared/lib/harness/update-plan.ts +140 -0
- package/src/shared/lib/harness/updates.test.ts +106 -0
- package/src/shared/lib/harness/updates.ts +177 -0
- package/src/shared/lib/icons/icon-paint-authority.test.ts +16 -4
- package/src/shared/lib/icons/icon-paint-authority.ts +57 -12
- package/src/shared/lib/icons/icon-paint-bucket.test.ts +84 -0
- package/src/shared/lib/icons/icon-paint-css.test.ts +23 -25
- package/src/shared/lib/icons/icon-paint-css.ts +69 -55
- package/src/shared/lib/icons/icon-paint-harness.test.ts +73 -0
- package/src/shared/lib/icons/icon-paint-harness.ts +75 -0
- package/src/shared/lib/icons/icon-paint-ink.ts +108 -0
- package/src/shared/lib/icons/icon-paint-panel.ts +19 -4
- package/src/shared/lib/icons/icon-paint-weight.ts +21 -2
- package/src/shared/lib/icons/icon-tone.ts +118 -21
- package/src/shared/lib/icons/tint-hues.generated.ts +100 -284
- package/src/shared/lib/icons/tint-tones.test.ts +79 -25
- package/src/shared/lib/icons/tint.ts +66 -6
- package/src/shared/lib/models/client.ts +10 -1
- package/src/shared/lib/models/provider/vendors.ts +72 -0
- package/src/shared/lib/omp/config/schema.test.ts +36 -0
- package/src/shared/lib/omp/dialog-methods.ts +4 -3
- package/src/shared/lib/omp/session/messages-map-trace.test.ts +42 -0
- package/src/shared/lib/omp/session/messages-map.ts +6 -1
- package/src/shared/lib/omp/session/parse-message-blocks-toolcall.test.ts +8 -0
- package/src/shared/lib/omp/session/parse-message-blocks.ts +6 -1
- package/src/shared/lib/omp/session/shell-trace.test.ts +69 -0
- package/src/shared/lib/omp/session/shell-trace.ts +63 -0
- package/src/shared/lib/omp/session/sidebar.ts +37 -10
- package/src/shared/lib/omp/session/wait-idle.test.ts +47 -0
- package/src/shared/lib/omp/session/wait-idle.ts +93 -0
- package/src/shared/lib/omp/session/wait.test.ts +34 -33
- package/src/shared/lib/omp/session/wait.ts +25 -39
- package/src/shared/lib/settings/sections.ts +24 -0
- package/src/shared/lib/theme/css.ts +2 -0
- package/src/shared/lib/theme/ink-scale.ts +21 -1
- package/src/shared/lib/theme/theme.test.ts +25 -9
- package/src/shared/lib/ui/safe-area.test.ts +28 -0
- package/src/shared/lib/ui/safe-area.ts +42 -0
- package/src/shared/lib/ui/toast-duration.test.ts +74 -0
- package/src/shared/lib/ui/toast-duration.ts +70 -0
- package/src/shared/types/harness-version.ts +59 -0
- package/src/shared/types/harness.ts +201 -0
- package/src/shared/types/index.ts +2 -0
- package/src/shared/types/omp/agent.ts +13 -0
- package/src/shared/types/settings/state.ts +10 -1
- package/src/shared/types/workspace.ts +10 -0
- package/src/test-support/env.ts +38 -0
- package/src/test-support/file-explorer-render.test-util.ts +37 -0
- package/src/test-support/file-explorer.test-util.ts +20 -18
- package/src/test-support/harness-table.test-util.ts +108 -0
- package/dist/client/static/js/index-7ppta1pb.css +0 -1
|
@@ -3,7 +3,7 @@ import type { ActionFunctionArgs } from '@/server/lib/remix-compat';
|
|
|
3
3
|
import { isMockMode } from '@/server/mock.server';
|
|
4
4
|
import { upsertOmpProviderModels } from '@/server/lib/omp/config/providers';
|
|
5
5
|
import { readOmpProviderApiKey } from '@/server/lib/omp/core/auth-credentials';
|
|
6
|
-
import {
|
|
6
|
+
import { refreshModelRegistryAfterWrite } from '@/server/lib/models/registry-refresh.server';
|
|
7
7
|
import {
|
|
8
8
|
enrichFromCatalog,
|
|
9
9
|
fetchRemoteModels,
|
|
@@ -161,7 +161,7 @@ export async function action({ request }: ActionFunctionArgs) {
|
|
|
161
161
|
...(body.replaceModels === true ? { replaceModels: true } : {}),
|
|
162
162
|
models: enriched.map(toOmpSeed),
|
|
163
163
|
});
|
|
164
|
-
if (upsert.written)
|
|
164
|
+
if (upsert.written) await refreshModelRegistryAfterWrite({ reprobe: true });
|
|
165
165
|
omp = {
|
|
166
166
|
written: upsert.written,
|
|
167
167
|
addedCount: upsert.addedModels.length,
|
|
@@ -31,7 +31,7 @@ import { getDb } from '@/server/db.server';
|
|
|
31
31
|
import { refreshModelCatalog } from '@/server/lib/models/catalog.server';
|
|
32
32
|
import { mergeProviders, PROVIDERS_SETTINGS_KEY } from '@/server/lib/models/provider-registry.server';
|
|
33
33
|
import { readSettingsJson } from '@/server/lib/db/settings-store';
|
|
34
|
-
import {
|
|
34
|
+
import { refreshModelRegistryAfterWrite } from '@/server/lib/models/registry-refresh.server';
|
|
35
35
|
import type { ProviderItem } from '@/shared/types';
|
|
36
36
|
|
|
37
37
|
async function readOverlay(): Promise<ProviderItem[]> {
|
|
@@ -63,9 +63,11 @@ export async function action({ request, params }: ActionFunctionArgs) {
|
|
|
63
63
|
if (!result.ok) {
|
|
64
64
|
return json({ success: false, ...result }, { status: 502 });
|
|
65
65
|
}
|
|
66
|
-
// Every listing that moved means the registry did too —
|
|
67
|
-
//
|
|
68
|
-
|
|
66
|
+
// Every listing that moved means the registry did too — recycle the pooled
|
|
67
|
+
// omp child (it caches the catalog it spawned with) and drop the probes that
|
|
68
|
+
// measured the old one, so the chat picker and the role dropdowns see the new
|
|
69
|
+
// rows immediately.
|
|
70
|
+
await refreshModelRegistryAfterWrite({ reprobe: true });
|
|
69
71
|
const merged = await mergeProviders(await readOverlay());
|
|
70
72
|
const changed = slug ? result.changed.filter((entry) => entry.slug === slug) : result.changed;
|
|
71
73
|
return json({
|
|
@@ -10,6 +10,7 @@ import { disableNativeProvider, enableNativeProvider } from '@/server/lib/omp/co
|
|
|
10
10
|
import { removeOmpProvider } from '@/server/lib/omp/config/providers';
|
|
11
11
|
import { PROVIDERS_SETTINGS_KEY as SETTINGS_KEY, deduplicateProviderItems, mergeProviders } from '@/server/lib/models/provider-registry.server';
|
|
12
12
|
import { invalidateModelsCaches } from '@/shared/lib/models/server-cache';
|
|
13
|
+
import { refreshModelRegistryAfterWrite } from '@/server/lib/models/registry-refresh.server';
|
|
13
14
|
|
|
14
15
|
const providersStore = createSettingsListStore<ProviderItem>({
|
|
15
16
|
key: SETTINGS_KEY,
|
|
@@ -173,7 +174,8 @@ export async function action({ request, params }: ActionFunctionArgs) {
|
|
|
173
174
|
});
|
|
174
175
|
}
|
|
175
176
|
}
|
|
176
|
-
|
|
177
|
+
if (removedFromOmp) await refreshModelRegistryAfterWrite({ reprobe: true });
|
|
178
|
+
else invalidateModelsCaches();
|
|
177
179
|
const after = await mergeProviders(list);
|
|
178
180
|
return json({ success: true, providers: after.providers, removedFromOmp, modelsRemoved });
|
|
179
181
|
}
|
|
@@ -31,6 +31,8 @@ import fs from 'fs';
|
|
|
31
31
|
import os from 'os';
|
|
32
32
|
import path from 'path';
|
|
33
33
|
import { parse as parseYaml } from 'yaml';
|
|
34
|
+
import { closeDb } from '@/server/db.server';
|
|
35
|
+
import { removeDir } from '@/test-support/remove-dir';
|
|
34
36
|
import { action as modelOverrideAction } from '@/server/routes/settings/model-override';
|
|
35
37
|
import { action as ompConfigAction, loader as ompConfigLoader } from '@/server/routes/settings/omp-config';
|
|
36
38
|
import { action as providerModelAction } from '@/server/routes/settings/provider-model';
|
|
@@ -58,12 +60,18 @@ afterEach(() => {
|
|
|
58
60
|
fs.rmSync(MODELS_YML, { force: true });
|
|
59
61
|
});
|
|
60
62
|
|
|
61
|
-
afterAll(() => {
|
|
63
|
+
afterAll(async () => {
|
|
64
|
+
// CLOSE the handle, then remove through `removeDir`. A bare `rmSync` with
|
|
65
|
+
// `force: true` reads as infallible and is not: on Windows an open
|
|
66
|
+
// `bun:sqlite` connection holds the temp tree and the delete fails with
|
|
67
|
+
// EBUSY, which reports from an `afterAll` as an unhandled error naming a line
|
|
68
|
+
// nobody can act on. Measured on the Windows gate.
|
|
69
|
+
await closeDb();
|
|
62
70
|
delete Bun.env.PI_CODING_AGENT_DIR;
|
|
63
71
|
delete Bun.env.KABMO_DB_PATH;
|
|
64
72
|
delete Bun.env.SYNC_WORKSPACE;
|
|
65
73
|
delete Bun.env.MOCK;
|
|
66
|
-
|
|
74
|
+
removeDir(ROOT);
|
|
67
75
|
});
|
|
68
76
|
|
|
69
77
|
type Handler = (args: never) => unknown;
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
import { runCatalogAction } from '@/server/routes/settings/skills-catalog-actions';
|
|
24
24
|
import { resolveDiscoveryScope, type DiscoveryScope } from '@/server/lib/omp/config/scope';
|
|
25
25
|
import { reloadLiveSessions } from '@/server/lib/omp/session/reload.server';
|
|
26
|
+
import { getLiveSession, harnessOfSession } from '@/server/lib/omp/rpc/session-registry';
|
|
26
27
|
|
|
27
28
|
/** Human label for an omp discovery source. */
|
|
28
29
|
const SOURCE_LABELS: Record<string, string> = {
|
|
@@ -93,6 +94,17 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
|
|
93
94
|
|
|
94
95
|
const db = await getDb();
|
|
95
96
|
const url = new URL(request.url);
|
|
97
|
+
// A live ACP chat's `/` pool is the AGENT's own command list. omp's skills
|
|
98
|
+
// are filesystem state from a different agent's vocabulary — measured, the
|
|
99
|
+
// popup offered them to every ACP chat, and typing one sent text the agent
|
|
100
|
+
// had never registered.
|
|
101
|
+
const sessionId = url.searchParams.get('sessionId');
|
|
102
|
+
if (sessionId) {
|
|
103
|
+
const live = getLiveSession(sessionId);
|
|
104
|
+
if (live?.isAlive() && harnessOfSession(live) !== 'omp-rpc') {
|
|
105
|
+
return json({ skills: [], catalogSources: [], catalogSkills: [], root: null, isMock: false });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
96
108
|
const scope = await resolveDiscoveryScope(url.searchParams.get('root'), url.searchParams.get('scope'));
|
|
97
109
|
const catalogSources = await readCatalogSources(db);
|
|
98
110
|
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The field drafts `ask-form/index.ts` collects while walking a form, and the
|
|
8
|
+
* turn from drafts to the questions the card draws.
|
|
9
|
+
*
|
|
10
|
+
* The question precedence is omp's `fieldQuestions`: the control's own label,
|
|
11
|
+
* else the text block right before it, else its `<fieldset>` legend, else a lone
|
|
12
|
+
* option's label, else the control name. A radio/checkbox group of two or more
|
|
13
|
+
* also gains the `Other (type your own)` row omp's fallback appends, because the
|
|
14
|
+
* card previews the rows the user will actually be offered.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { AskOption, AskQuestion } from '@/shared/lib/chat/ask-form/types';
|
|
18
|
+
import { oneLine } from '@/shared/lib/chat/ask-form/tokens';
|
|
19
|
+
|
|
20
|
+
/** The "Other" row omp's field-by-field fallback appends to a choice list. */
|
|
21
|
+
const OTHER_LABEL = 'Other (type your own)';
|
|
22
|
+
const OTHER_IN_OPTIONS = /^\s*other\b/i;
|
|
23
|
+
|
|
24
|
+
export interface DraftOption {
|
|
25
|
+
value: string;
|
|
26
|
+
label: string;
|
|
27
|
+
checked: boolean;
|
|
28
|
+
disabled: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface DraftField {
|
|
32
|
+
name: string;
|
|
33
|
+
kind: 'choice' | 'text';
|
|
34
|
+
multi: boolean;
|
|
35
|
+
select: boolean;
|
|
36
|
+
label: string;
|
|
37
|
+
options: DraftOption[];
|
|
38
|
+
/** Text field only. */
|
|
39
|
+
value: string;
|
|
40
|
+
multiline: boolean;
|
|
41
|
+
/** Caption in force when the field appeared, and its section's legend. */
|
|
42
|
+
caption: string;
|
|
43
|
+
section: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Named fields, in document order, as the questions the card renders. */
|
|
47
|
+
export function toQuestions(fields: DraftField[]): AskQuestion[] {
|
|
48
|
+
const questions: AskQuestion[] = [];
|
|
49
|
+
for (const field of fields) {
|
|
50
|
+
if (!field.name) continue;
|
|
51
|
+
const lone = field.kind === 'choice' && field.options.length === 1 ? oneLine(field.options[0].label) : '';
|
|
52
|
+
const question = oneLine(field.label) || field.caption || field.section || lone || field.name;
|
|
53
|
+
const options: AskOption[] = field.options.map((option) => ({
|
|
54
|
+
label: option.label || option.value,
|
|
55
|
+
value: option.value,
|
|
56
|
+
}));
|
|
57
|
+
if (
|
|
58
|
+
field.kind === 'choice' &&
|
|
59
|
+
!field.select &&
|
|
60
|
+
field.options.length >= 2 &&
|
|
61
|
+
!field.options.some((option) => OTHER_IN_OPTIONS.test(option.label))
|
|
62
|
+
) {
|
|
63
|
+
options.push({ label: OTHER_LABEL });
|
|
64
|
+
}
|
|
65
|
+
const checked = field.options.findIndex((option) => option.checked);
|
|
66
|
+
questions.push({
|
|
67
|
+
id: field.name,
|
|
68
|
+
question,
|
|
69
|
+
options,
|
|
70
|
+
multi: field.multi,
|
|
71
|
+
kind: field.kind,
|
|
72
|
+
recommended: field.kind === 'choice' && !field.multi && checked >= 0 ? checked : undefined,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return questions;
|
|
76
|
+
}
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Reads the HTML `<form>` omp's `ask` tool takes since 18.18.3.
|
|
8
|
+
*
|
|
9
|
+
* The tool used to take `questions[]`; it now takes one `{ html }` string and
|
|
10
|
+
* the RPC host walks the form's named controls one dialog at a time. Kabmo
|
|
11
|
+
* draws every question of the call at once, so it needs the same list omp
|
|
12
|
+
* derived: the field's own text, else the sentence right before it, else its
|
|
13
|
+
* `<fieldset>` legend, else a lone option's label, else the control name, plus
|
|
14
|
+
* the option rows and the free-text "Other" row omp appends. This mirrors
|
|
15
|
+
* `fieldQuestions`/`formAnswers` in omp's `pi-tui` (`html-form/data.ts`), which
|
|
16
|
+
* the browser cannot import.
|
|
17
|
+
*
|
|
18
|
+
* The parser is deliberately small: agent-written forms use labels, fieldsets,
|
|
19
|
+
* paragraphs, selects and plain inputs. Anything it cannot read degrades to the
|
|
20
|
+
* control's `name`, never to a blank card.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import type { AskQuestion } from '@/shared/lib/chat/ask-form/types';
|
|
24
|
+
import { toQuestions, type DraftField, type DraftOption } from '@/shared/lib/chat/ask-form/fields';
|
|
25
|
+
import {
|
|
26
|
+
BLOCK,
|
|
27
|
+
findChild,
|
|
28
|
+
hasControl,
|
|
29
|
+
HEADING,
|
|
30
|
+
matchingClose,
|
|
31
|
+
nameLabel,
|
|
32
|
+
oneLine,
|
|
33
|
+
SKIPPED,
|
|
34
|
+
textOf,
|
|
35
|
+
tokenize,
|
|
36
|
+
type Token,
|
|
37
|
+
} from '@/shared/lib/chat/ask-form/tokens';
|
|
38
|
+
|
|
39
|
+
const IGNORED_INPUTS: Record<string, true> = {
|
|
40
|
+
button: true,
|
|
41
|
+
file: true,
|
|
42
|
+
image: true,
|
|
43
|
+
reset: true,
|
|
44
|
+
submit: true,
|
|
45
|
+
hidden: true,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** Pre-pass: ids of controls, and the `<label for>` text that names them. */
|
|
49
|
+
function readLabelTargets(tokens: Token[]): Map<string, string> {
|
|
50
|
+
const ids = new Set<string>();
|
|
51
|
+
for (const token of tokens) {
|
|
52
|
+
if (token.kind !== 'open') continue;
|
|
53
|
+
if (token.tag !== 'input' && token.tag !== 'select' && token.tag !== 'textarea') continue;
|
|
54
|
+
if (token.attrs.id) ids.add(token.attrs.id);
|
|
55
|
+
}
|
|
56
|
+
const labels = new Map<string, string>();
|
|
57
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
58
|
+
const token = tokens[index];
|
|
59
|
+
if (token.kind !== 'open' || token.tag !== 'label' || token.selfClosing) continue;
|
|
60
|
+
const target = token.attrs.for;
|
|
61
|
+
if (!target || !ids.has(target) || labels.has(target)) continue;
|
|
62
|
+
labels.set(target, textOf(tokens, index + 1, matchingClose(tokens, index, 'label')));
|
|
63
|
+
}
|
|
64
|
+
return labels;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Fields of one form, in document order, with the question text omp derives. */
|
|
68
|
+
export function parseAskForm(html: string): AskQuestion[] {
|
|
69
|
+
if (!html.trim()) return [];
|
|
70
|
+
const form = /<form\b[^>]*>([\s\S]*)<\/form>/i.exec(html);
|
|
71
|
+
const tokens = tokenize(form ? form[1] : html);
|
|
72
|
+
const labelFor = readLabelTargets(tokens);
|
|
73
|
+
|
|
74
|
+
const fields: DraftField[] = [];
|
|
75
|
+
const groups = new Map<string, DraftField>();
|
|
76
|
+
let section = '';
|
|
77
|
+
let caption = '';
|
|
78
|
+
let inline = '';
|
|
79
|
+
|
|
80
|
+
const flush = () => {
|
|
81
|
+
const text = oneLine(inline);
|
|
82
|
+
inline = '';
|
|
83
|
+
if (text) caption = text;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const addField = (field: DraftField) => {
|
|
87
|
+
flush();
|
|
88
|
+
fields.push(field);
|
|
89
|
+
caption = '';
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const controlLabel = (attrs: Record<string, string>, wrapping: string | undefined): string => {
|
|
93
|
+
const own = wrapping !== undefined ? oneLine(wrapping) : '';
|
|
94
|
+
if (own) return own;
|
|
95
|
+
const detached = attrs.id ? labelFor.get(attrs.id) : undefined;
|
|
96
|
+
return detached ? oneLine(detached) : '';
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const addInput = (attrs: Record<string, string>, wrapping: string | undefined) => {
|
|
100
|
+
const type = (attrs.type ?? 'text').toLowerCase();
|
|
101
|
+
if (IGNORED_INPUTS[type]) return;
|
|
102
|
+
const name = attrs.name ?? '';
|
|
103
|
+
if (type === 'radio' || type === 'checkbox') {
|
|
104
|
+
const value = attrs.value ?? 'on';
|
|
105
|
+
const option: DraftOption = {
|
|
106
|
+
value,
|
|
107
|
+
label: controlLabel(attrs, wrapping) || value || name,
|
|
108
|
+
checked: 'checked' in attrs,
|
|
109
|
+
disabled: 'disabled' in attrs,
|
|
110
|
+
};
|
|
111
|
+
const key = `${type}\u0000${name}`;
|
|
112
|
+
const group = groups.get(key);
|
|
113
|
+
if (group) {
|
|
114
|
+
group.options.push(option);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const field: DraftField = {
|
|
118
|
+
name,
|
|
119
|
+
kind: 'choice',
|
|
120
|
+
multi: type === 'checkbox',
|
|
121
|
+
select: false,
|
|
122
|
+
label: '',
|
|
123
|
+
options: [option],
|
|
124
|
+
value: '',
|
|
125
|
+
multiline: false,
|
|
126
|
+
caption,
|
|
127
|
+
section,
|
|
128
|
+
};
|
|
129
|
+
groups.set(key, field);
|
|
130
|
+
addField(field);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
addField({
|
|
134
|
+
name,
|
|
135
|
+
kind: 'text',
|
|
136
|
+
multi: false,
|
|
137
|
+
select: false,
|
|
138
|
+
label: controlLabel(attrs, wrapping) || nameLabel(name),
|
|
139
|
+
options: [],
|
|
140
|
+
value: attrs.value ?? '',
|
|
141
|
+
multiline: false,
|
|
142
|
+
caption,
|
|
143
|
+
section,
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const addSelect = (attrs: Record<string, string>, inner: Token[], wrapping: string | undefined) => {
|
|
148
|
+
const options: DraftOption[] = [];
|
|
149
|
+
for (let index = 0; index < inner.length; index += 1) {
|
|
150
|
+
const token = inner[index];
|
|
151
|
+
if (token.kind !== 'open' || token.tag !== 'option') continue;
|
|
152
|
+
const end = token.selfClosing ? index + 1 : matchingClose(inner, index, 'option');
|
|
153
|
+
const text = textOf(inner, index + 1, end);
|
|
154
|
+
options.push({
|
|
155
|
+
value: token.attrs.value ?? text,
|
|
156
|
+
label: text,
|
|
157
|
+
checked: 'selected' in token.attrs,
|
|
158
|
+
disabled: 'disabled' in token.attrs,
|
|
159
|
+
});
|
|
160
|
+
index = end;
|
|
161
|
+
}
|
|
162
|
+
const multi = 'multiple' in attrs;
|
|
163
|
+
if (!multi && options.length > 0 && !options.some((option) => option.checked)) {
|
|
164
|
+
const first = options.find((option) => !option.disabled);
|
|
165
|
+
if (first) first.checked = true;
|
|
166
|
+
}
|
|
167
|
+
addField({
|
|
168
|
+
name: attrs.name ?? '',
|
|
169
|
+
kind: 'choice',
|
|
170
|
+
multi,
|
|
171
|
+
select: true,
|
|
172
|
+
label: controlLabel(attrs, wrapping),
|
|
173
|
+
options,
|
|
174
|
+
value: '',
|
|
175
|
+
multiline: false,
|
|
176
|
+
caption,
|
|
177
|
+
section,
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Walk a token range. `quiet` is a `<label>` that wraps controls: its text is
|
|
183
|
+
* the control's LABEL (already passed as `wrapping`), never a block of the
|
|
184
|
+
* form, so it must not caption the field it names.
|
|
185
|
+
*/
|
|
186
|
+
const walk = (
|
|
187
|
+
start: number,
|
|
188
|
+
end: number,
|
|
189
|
+
wrapping: string | undefined,
|
|
190
|
+
depth: number,
|
|
191
|
+
quiet = false,
|
|
192
|
+
): void => {
|
|
193
|
+
const settle = () => {
|
|
194
|
+
if (!quiet) flush();
|
|
195
|
+
};
|
|
196
|
+
for (let index = start; index < end; index += 1) {
|
|
197
|
+
const token = tokens[index];
|
|
198
|
+
if (token.kind === 'text') {
|
|
199
|
+
if (!quiet) inline += token.text;
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
const tag = token.tag;
|
|
203
|
+
if (tag.startsWith('/')) {
|
|
204
|
+
if (BLOCK[tag.slice(1)] || HEADING[tag.slice(1)] || tag === '/legend' || tag === '/pre' || tag === '/table') {
|
|
205
|
+
settle();
|
|
206
|
+
}
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
if (token.selfClosing) {
|
|
210
|
+
if (tag === 'br' && !quiet) inline += '\n';
|
|
211
|
+
else if (tag === 'hr') settle();
|
|
212
|
+
else if (tag === 'input') addInput(token.attrs, wrapping);
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
const close = matchingClose(tokens, index, tag);
|
|
216
|
+
if (SKIPPED[tag]) {
|
|
217
|
+
index = close;
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (tag === 'label') {
|
|
221
|
+
const target = token.attrs.for;
|
|
222
|
+
if (target && labelFor.has(target)) {
|
|
223
|
+
index = close;
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
walk(index + 1, close, textOf(tokens, index + 1, close), depth, true);
|
|
227
|
+
index = close;
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
if (tag === 'fieldset') {
|
|
231
|
+
settle();
|
|
232
|
+
const legendAt = findChild(tokens, index + 1, close, 'legend');
|
|
233
|
+
if (depth === 0 && !quiet) {
|
|
234
|
+
// omp starts a NEW section at a top-level fieldset: the blocks before
|
|
235
|
+
// it (a `<p>` caption included) do not reach the fields inside, which
|
|
236
|
+
// borrow the legend instead. Keeping the caption made a form's
|
|
237
|
+
// explanatory paragraph caption the first field — and since that
|
|
238
|
+
// paragraph is not the title omp shows, the live dialog could not be
|
|
239
|
+
// matched back to the question.
|
|
240
|
+
caption = '';
|
|
241
|
+
section = legendAt === -1 ? '' : textOf(tokens, legendAt + 1, matchingClose(tokens, legendAt, 'legend'));
|
|
242
|
+
if (legendAt === -1) {
|
|
243
|
+
walk(index + 1, close, wrapping, depth + 1);
|
|
244
|
+
} else {
|
|
245
|
+
walk(index + 1, legendAt, wrapping, depth + 1);
|
|
246
|
+
walk(matchingClose(tokens, legendAt, 'legend') + 1, close, wrapping, depth + 1);
|
|
247
|
+
}
|
|
248
|
+
section = '';
|
|
249
|
+
} else {
|
|
250
|
+
walk(index + 1, close, wrapping, depth + 1, quiet);
|
|
251
|
+
}
|
|
252
|
+
settle();
|
|
253
|
+
index = close;
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
if (tag === 'legend' || HEADING[tag]) {
|
|
257
|
+
settle();
|
|
258
|
+
walk(index + 1, close, wrapping, depth, quiet);
|
|
259
|
+
settle();
|
|
260
|
+
index = close;
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
if (BLOCK[tag]) {
|
|
264
|
+
settle();
|
|
265
|
+
walk(index + 1, close, wrapping, depth, quiet);
|
|
266
|
+
settle();
|
|
267
|
+
index = close;
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
if (tag === 'ul' || tag === 'ol' || tag === 'pre' || tag === 'table') {
|
|
271
|
+
settle();
|
|
272
|
+
// A list of controls is layout; any other list is a block, which clears
|
|
273
|
+
// the caption the next field would otherwise borrow.
|
|
274
|
+
if ((tag === 'ul' || tag === 'ol') && hasControl(tokens, index + 1, close)) {
|
|
275
|
+
walk(index + 1, close, wrapping, depth, quiet);
|
|
276
|
+
} else if (!quiet) {
|
|
277
|
+
caption = '';
|
|
278
|
+
}
|
|
279
|
+
settle();
|
|
280
|
+
index = close;
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
if (tag === 'input') {
|
|
284
|
+
addInput(token.attrs, wrapping);
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
if (tag === 'select') {
|
|
288
|
+
addSelect(token.attrs, tokens.slice(index + 1, close), wrapping);
|
|
289
|
+
index = close;
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
if (tag === 'textarea') {
|
|
293
|
+
addField({
|
|
294
|
+
name: token.attrs.name ?? '',
|
|
295
|
+
kind: 'text',
|
|
296
|
+
multi: false,
|
|
297
|
+
select: false,
|
|
298
|
+
label: controlLabel(token.attrs, wrapping) || nameLabel(token.attrs.name ?? ''),
|
|
299
|
+
options: [],
|
|
300
|
+
value: textOf(tokens, index + 1, close),
|
|
301
|
+
multiline: true,
|
|
302
|
+
caption,
|
|
303
|
+
section,
|
|
304
|
+
});
|
|
305
|
+
index = close;
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
if (tag === 'img') {
|
|
309
|
+
settle();
|
|
310
|
+
if (!quiet) caption = '';
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
// Inline markup (`code`, `strong`, `em`, `a`, `span`, …): keep its text.
|
|
314
|
+
walk(index + 1, close, wrapping, depth, quiet);
|
|
315
|
+
index = close;
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
walk(0, tokens.length, undefined, 0);
|
|
320
|
+
flush();
|
|
321
|
+
|
|
322
|
+
return toQuestions(fields);
|
|
323
|
+
}
|