@kabmo-labs/kabmo 0.23.0 → 0.25.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/dist/client/index.html +1 -1
- package/dist/client/index.js +805 -736
- package/dist/client/static/js/index-bc9aa4mx.css +1 -0
- package/dist/client/static/js/{index-ph0q59rs.js → index-ga8cbpt4.js} +1071 -1171
- package/package.json +2 -4
- package/src/cli/lib/args.js +24 -1
- package/src/cli/lib/args.test.js +16 -0
- package/src/cli/lib/commands/session.js +233 -0
- package/src/cli/lib/commands/session.test.js +103 -0
- package/src/cli/main.js +1 -1
- package/src/client/components/common/ComposerPicker.tsx +3 -0
- package/src/client/components/common/Modal.tsx +2 -6
- package/src/client/components/common/code-surface/shiki.test.ts +82 -0
- package/src/client/components/common/code-surface/shiki.ts +28 -7
- package/src/client/components/common/session-actions-menu/NewChildSessionDialog.tsx +113 -0
- package/src/client/components/common/session-actions-menu/index.tsx +33 -2
- package/src/client/components/common/session-row/StatusSlot.tsx +4 -4
- package/src/client/components/common/session-row/index.tsx +27 -1
- package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +7 -1
- package/src/client/components/layout/desktop-layout/resizer/separator-drag.ts +3 -3
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +25 -12
- package/src/client/components/layout/session-sidebar/ChildSessionList.tsx +66 -0
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +28 -3
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.test.tsx +20 -0
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +59 -12
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +94 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.test.tsx +130 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +120 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +47 -0
- 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 +55 -46
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +18 -5
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +21 -4
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +27 -5
- package/src/client/components/settings/categories/harness-settings/EnvProviderForm.tsx +31 -0
- package/src/client/components/settings/categories/harness-settings/provider-panel.test.tsx +49 -0
- package/src/client/components/workspace/chat-timeline/ChatOverlays.tsx +5 -2
- package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +64 -70
- package/src/client/components/workspace/chat-timeline/ComposerDockFrame.tsx +35 -0
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +135 -118
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +22 -1
- package/src/client/components/workspace/chat-timeline/MessageList.test.ts +14 -0
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +4 -0
- package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +3 -0
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +4 -3
- package/src/client/components/workspace/chat-timeline/composer-dock-frame.test.tsx +155 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +5 -2
- package/src/client/components/workspace/chat-timeline/pending-harness.test.tsx +1 -1
- 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/file-explorer/index.test.ts +25 -0
- package/src/client/components/workspace/file-explorer/index.tsx +9 -3
- package/src/client/components/workspace/model-dropdown/harness-models.test.ts +17 -0
- package/src/client/components/workspace/model-dropdown/harness-models.ts +33 -18
- package/src/client/components/workspace/model-dropdown/index.tsx +3 -3
- package/src/client/components/workspace/model-dropdown/popover-metrics.ts +4 -1
- package/src/client/components/workspace/terminal-panel/KeyBar.tsx +10 -8
- package/src/client/components/workspace/terminal-panel/{RealtimeXtermView.tsx → RealtimeTerminalView.tsx} +51 -58
- package/src/client/components/workspace/terminal-panel/fit.test.ts +37 -0
- package/src/client/components/workspace/terminal-panel/fit.ts +64 -0
- package/src/client/components/workspace/terminal-panel/fonts.test.ts +161 -0
- package/src/client/components/workspace/terminal-panel/fonts.ts +164 -0
- package/src/client/components/workspace/terminal-panel/grid.test.ts +52 -0
- package/src/client/components/workspace/terminal-panel/grid.ts +118 -0
- package/src/client/components/workspace/terminal-panel/index.tsx +25 -21
- package/src/client/components/workspace/terminal-panel/mount.ts +247 -223
- package/src/client/components/workspace/terminal-panel/navigation.test.ts +54 -0
- package/src/client/components/workspace/terminal-panel/navigation.ts +47 -0
- package/src/client/data/settings/omp-schema.json +5 -5
- package/src/client/data/theme/terminal.test.ts +25 -0
- package/src/client/data/theme/terminal.ts +96 -79
- package/src/client/hooks/chat/composer/items.test.ts +12 -26
- package/src/client/hooks/chat/composer/pick-mapping.test.ts +42 -0
- package/src/client/hooks/chat/omp/prompt-send.test.ts +7 -7
- package/src/client/hooks/chat/omp/prompt-send.ts +26 -14
- package/src/client/hooks/chat/timeline/actions.ts +2 -2
- package/src/client/hooks/chat/timeline/ask-frames.ts +5 -4
- 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 +34 -1
- package/src/client/hooks/chat/timeline/prompt-text.ts +47 -20
- package/src/client/hooks/chat/timeline/rewind-actions.test.ts +24 -1
- package/src/client/hooks/chat/timeline/rewind-actions.ts +15 -11
- 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 +56 -0
- package/src/client/hooks/chat/timeline/send-helpers.ts +30 -1
- package/src/client/hooks/chat/timeline/send-props.ts +5 -3
- package/src/client/hooks/chat/timeline/send-steer.test.ts +4 -4
- package/src/client/hooks/chat/timeline/send.test-util.ts +8 -2
- package/src/client/hooks/chat/timeline/send.test.ts +4 -4
- package/src/client/hooks/chat/timeline/send.ts +59 -53
- 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/use-fork-session.ts +49 -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 +10 -3
- package/src/client/hooks/models/use-harness-update.test.ts +193 -0
- package/src/client/hooks/models/use-harness-update.ts +202 -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 +2 -1
- package/src/client/hooks/models/use-harnesses.ts +48 -114
- package/src/client/hooks/workspace/child-expansion.ts +33 -0
- package/src/client/hooks/workspace/terminal/index.ts +17 -3
- package/src/client/hooks/workspace/terminal/socket.ts +9 -4
- package/src/client/lib/session-tree.test.ts +50 -0
- package/src/client/lib/session-tree.ts +59 -0
- package/src/client/tailwind.css +26 -12
- package/src/server/index.ts +2 -0
- package/src/server/lib/auth/guard.ts +10 -0
- package/src/server/lib/btw/session-copy.server.ts +6 -44
- package/src/server/lib/btw/session-copy.test.ts +2 -1
- package/src/server/lib/db/schema.ts +4 -0
- package/src/server/lib/db/seed-terminal.test.ts +1 -1
- package/src/server/lib/db/seed.test.ts +1 -1
- 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/background-work.test.ts +262 -0
- package/src/server/lib/harness/acp/background-work.ts +320 -0
- package/src/server/lib/harness/acp/client.ts +2 -2
- package/src/server/lib/harness/acp/frames.test.ts +50 -1
- package/src/server/lib/harness/acp/frames.ts +17 -5
- package/src/server/lib/harness/acp/gateway-env.test.ts +64 -0
- package/src/server/lib/harness/acp/gateway-env.ts +70 -0
- package/src/server/lib/harness/acp/mapper.ts +6 -4
- package/src/server/lib/harness/acp/prompt.test.ts +20 -0
- package/src/server/lib/harness/acp/prompt.ts +19 -3
- package/src/server/lib/harness/acp/session-background.test.ts +129 -0
- package/src/server/lib/harness/acp/session-config.test.ts +73 -0
- package/src/server/lib/harness/acp/session-config.ts +87 -6
- package/src/server/lib/harness/acp/session-exit.ts +31 -0
- package/src/server/lib/harness/acp/session-handshake.test.ts +108 -0
- package/src/server/lib/harness/acp/session-handshake.ts +36 -3
- package/src/server/lib/harness/acp/session-idle.ts +51 -0
- package/src/server/lib/harness/acp/session-listeners.ts +31 -0
- package/src/server/lib/harness/acp/session-notifications.ts +19 -3
- package/src/server/lib/harness/acp/session-observers.test.ts +9 -0
- package/src/server/lib/harness/acp/session-options.ts +33 -0
- package/src/server/lib/harness/acp/session-reaper.test.ts +96 -0
- package/src/server/lib/harness/acp/session-requests.ts +47 -0
- package/src/server/lib/harness/acp/session-turns.ts +20 -5
- package/src/server/lib/harness/acp/session.test-util.ts +54 -3
- package/src/server/lib/harness/acp/session.test.ts +65 -3
- package/src/server/lib/harness/acp/session.ts +79 -79
- package/src/server/lib/harness/acp/turn.test.ts +81 -0
- package/src/server/lib/harness/acp/turn.ts +54 -13
- package/src/server/lib/harness/acp/verbs.ts +12 -2
- 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/config.server.test.ts +1 -1
- package/src/server/lib/harness/config.server.ts +1 -1
- package/src/server/lib/harness/launch-table.ts +195 -0
- package/src/server/lib/harness/launch.test.ts +37 -0
- package/src/server/lib/harness/launch.ts +16 -116
- package/src/server/lib/harness/provider-entry.ts +32 -0
- package/src/server/lib/harness/provider-file.server.ts +3 -0
- package/src/server/lib/harness/provider-sources.server.test.ts +45 -0
- package/src/server/lib/harness/provider-sources.server.ts +26 -2
- package/src/server/lib/harness/provider-write.server.ts +21 -32
- 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/spawn.server.ts +15 -2
- package/src/server/lib/harness/update-job-store.test.ts +126 -0
- package/src/server/lib/harness/update-job-store.ts +109 -0
- package/src/server/lib/harness/update-job.server.ts +203 -0
- package/src/server/lib/harness/update-state.server.ts +15 -20
- package/src/server/lib/harness/update-worker.test.ts +153 -0
- package/src/server/lib/harness/update-worker.ts +197 -0
- package/src/server/lib/lifecycle/after-listen.ts +7 -0
- package/src/server/lib/lifecycle/paths.ts +23 -0
- 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/rpc/child-config.ts +5 -4
- package/src/server/lib/omp/rpc/constants.test.ts +2 -1
- package/src/server/lib/omp/rpc/forked-resume.test.ts +14 -3
- package/src/server/lib/omp/rpc/manager.ts +5 -5
- package/src/server/lib/omp/rpc/prewarm-pool.ts +12 -3
- package/src/server/lib/omp/rpc/session-registry.ts +14 -2
- package/src/server/lib/omp/rpc/terminal-settle.ts +53 -5
- package/src/server/lib/omp/session/delete-flow.server.ts +62 -8
- package/src/server/lib/omp/session/delete.server.ts +17 -0
- package/src/server/lib/omp/session/rewind-file.ts +39 -21
- package/src/server/lib/omp/session/sidebar-data.server.ts +6 -6
- package/src/server/lib/omp/session/transcript-copy.ts +123 -0
- package/src/server/lib/sessions/agent-token.server.test.ts +64 -0
- package/src/server/lib/sessions/agent-token.server.ts +134 -0
- package/src/server/lib/sessions/answers.server.test.ts +33 -0
- package/src/server/lib/sessions/answers.server.ts +37 -0
- package/src/server/lib/sessions/dispatch.server.test.ts +143 -0
- package/src/server/lib/sessions/dispatch.server.ts +128 -0
- package/src/server/lib/sessions/fork.server.test.ts +209 -0
- package/src/server/lib/sessions/fork.server.ts +304 -0
- package/src/server/lib/sessions/lifecycle.server.test.ts +75 -0
- package/src/server/lib/sessions/lifecycle.server.ts +71 -0
- package/src/server/lib/sessions/notify.server.test.ts +112 -0
- package/src/server/lib/sessions/notify.server.ts +212 -0
- package/src/server/lib/sessions/relation-types.ts +76 -0
- package/src/server/lib/sessions/relations.server.test.ts +207 -0
- package/src/server/lib/sessions/relations.server.ts +337 -0
- package/src/server/lib/sessions/resolve.server.ts +106 -0
- package/src/server/lib/sessions/schema.server.ts +82 -0
- package/src/server/lib/sessions/sidebar-relations.server.test.ts +61 -0
- package/src/server/lib/sessions/sidebar-relations.server.ts +47 -0
- package/src/server/lib/sessions/spawn.server.test.ts +196 -0
- package/src/server/lib/sessions/spawn.server.ts +310 -0
- package/src/server/lib/terminal/attach-replay.test.ts +2 -2
- package/src/server/lib/terminal/output.test.ts +2 -2
- package/src/server/lib/terminal/output.ts +1 -1
- package/src/server/lib/terminal/resize.test.ts +99 -0
- package/src/server/lib/terminal/runtime.server.ts +26 -6
- package/src/server/lib/terminal/send-result.test.ts +18 -1
- package/src/server/lib/terminal/send-result.ts +26 -2
- package/src/server/lib/terminal/session.server.ts +6 -6
- package/src/server/lib/usage/new-api.test.ts +92 -0
- package/src/server/lib/usage/new-api.ts +131 -0
- package/src/server/lib/usage/provider-endpoint.test.ts +106 -0
- package/src/server/lib/usage/provider-key.ts +33 -0
- package/src/server/lib/usage/providers.server.ts +10 -3
- package/src/server/lib/usage/vendor-balance.server.ts +4 -53
- package/src/server/lib/usage/vendor-http.ts +41 -0
- package/src/server/lib/usage/window.ts +55 -0
- package/src/server/routes/agent/command.ts +14 -1
- package/src/server/routes/agent/harness-command.ts +6 -0
- package/src/server/routes/agent/new.ts +15 -0
- 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 +165 -10
- package/src/server/routes/chat/session.ts +60 -7
- package/src/server/routes/harness/add-provider.test.ts +9 -1
- package/src/server/routes/harness/import-action.ts +22 -4
- package/src/server/routes/harness/import.test.ts +1 -1
- package/src/server/routes/harness/index.ts +5 -1
- package/src/server/routes/harness/root.ts +8 -49
- package/src/server/routes/harness/toggle.test.ts +20 -0
- package/src/server/routes/harness/update-status.ts +26 -0
- package/src/server/routes/harness/update.test.ts +119 -0
- package/src/server/routes/harness/update.ts +67 -113
- package/src/server/routes/harness/versions.ts +5 -1
- package/src/server/routes/sessions/answer.ts +24 -0
- package/src/server/routes/sessions/batch-delete.ts +11 -5
- package/src/server/routes/sessions/delete-acp.test.ts +227 -0
- package/src/server/routes/sessions/delete.ts +4 -2
- package/src/server/routes/sessions/fork.ts +74 -0
- package/src/server/routes/sessions/index.ts +14 -0
- package/src/server/routes/sessions/relations.ts +85 -0
- package/src/server/routes/sessions/session.ts +4 -0
- package/src/server/routes/sessions/spawn.ts +134 -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/terminal/ws.ts +3 -3
- 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 +31 -2
- package/src/shared/lib/chat/composer/delegation.test.ts +93 -0
- package/src/shared/lib/chat/composer/delegation.ts +206 -0
- package/src/shared/lib/chat/notice-text.ts +1 -1
- 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 +11 -0
- package/src/shared/lib/code/ansi.ts +1 -1
- package/src/shared/lib/fonts/nerd-symbols.css +4 -3
- package/src/shared/lib/fonts/nerd-symbols.test.ts +9 -9
- package/src/shared/lib/harness/catalog.test.ts +1 -1
- package/src/shared/lib/harness/config-fields.test.ts +4 -0
- package/src/shared/lib/harness/config-fields.ts +19 -4
- package/src/shared/lib/harness/dialects.test.ts +8 -0
- package/src/shared/lib/harness/dialects.ts +12 -0
- package/src/shared/lib/harness/provider-facts.test.ts +59 -8
- package/src/shared/lib/harness/provider-facts.ts +46 -11
- package/src/shared/lib/harness/providers.ts +44 -1
- package/src/shared/lib/harness/rewind.ts +24 -0
- package/src/shared/lib/harness/update-job.ts +33 -0
- package/src/shared/lib/harness/update-plan.test.ts +69 -4
- package/src/shared/lib/harness/update-plan.ts +57 -9
- package/src/shared/lib/harness/updates.test.ts +22 -0
- package/src/shared/lib/harness/updates.ts +24 -1
- package/src/shared/lib/models/client.ts +10 -1
- package/src/shared/lib/omp/dialog-methods.ts +4 -3
- package/src/shared/lib/omp/session/wait-idle.test.ts +11 -0
- package/src/shared/lib/omp/session/wait-idle.ts +12 -2
- package/src/shared/lib/theme/catalog.test.ts +13 -9
- package/src/shared/lib/theme/color.test.ts +2 -2
- package/src/shared/lib/theme/color.ts +4 -4
- 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 +26 -10
- 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/workspace/terminal/input.test.ts +27 -0
- package/src/shared/lib/workspace/terminal/input.ts +33 -0
- package/src/shared/lib/workspace/terminal/keys.test.ts +1 -1
- package/src/shared/lib/workspace/terminal/keys.ts +7 -7
- package/src/shared/types/chat.ts +1 -1
- package/src/shared/types/harness-update.ts +65 -0
- package/src/shared/types/harness.ts +30 -4
- package/src/shared/types/omp/agent.ts +19 -2
- package/src/shared/types/workspace.ts +4 -0
- package/src/test-support/fake-omp-fork.ts +16 -2
- 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 +21 -4
- package/dist/client/static/js/index-jhmg4w91.css +0 -1
- package/src/client/components/workspace/terminal-panel/webgl.test.ts +0 -75
- package/src/client/components/workspace/terminal-panel/webgl.ts +0 -108
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
|
|
29
29
|
import { hashPassword, deriveCredentialKey, readSessionSecret, writeSessionSecret, type ActiveAuthConfig } from '@/server/lib/auth/config';
|
|
30
30
|
import { readSessionCookie, verifySessionToken } from '@/server/lib/auth/token';
|
|
31
|
+
import { agentTokenScopeForPath, bearerToken, verifyAgentToken } from '@/server/lib/sessions/agent-token.server';
|
|
31
32
|
import { rememberClientAddress } from '@/server/lib/auth/client-address';
|
|
32
33
|
import type { CredentialHandover } from '@/shared/lib/auth/handover';
|
|
33
34
|
|
|
@@ -290,6 +291,15 @@ export function authGate(request: Request, clientAddress?: string): Response | u
|
|
|
290
291
|
return undefined;
|
|
291
292
|
}
|
|
292
293
|
|
|
294
|
+
// An agent subprocess carries a bearer token instead of a cookie. It is
|
|
295
|
+
// scoped by path to the session it names; spawn is the one path a child may
|
|
296
|
+
// call under its own token (to create its own children).
|
|
297
|
+
const scope = agentTokenScopeForPath(pathname);
|
|
298
|
+
if (scope) {
|
|
299
|
+
const agentSession = verifyAgentToken(bearerToken(request));
|
|
300
|
+
if (agentSession && (scope === 'any' || scope === agentSession)) return undefined;
|
|
301
|
+
}
|
|
302
|
+
|
|
293
303
|
const wantsHtml = (request.headers.get('accept') ?? '').includes('text/html');
|
|
294
304
|
return rejectionResponse(pathname, wantsHtml);
|
|
295
305
|
}
|
|
@@ -35,7 +35,12 @@ import fs from 'fs';
|
|
|
35
35
|
import * as path from 'path';
|
|
36
36
|
import { getDatabasePath } from '@/server/db.server';
|
|
37
37
|
import { clearSessionFileCaches } from '@/server/lib/omp/session/files';
|
|
38
|
-
import {
|
|
38
|
+
import {
|
|
39
|
+
buildTitleLine,
|
|
40
|
+
completeLines,
|
|
41
|
+
lastEntryId,
|
|
42
|
+
parseJsonObject,
|
|
43
|
+
} from '@/server/lib/omp/session/transcript-copy';
|
|
39
44
|
import { isRecord } from '@/shared/lib/util/guards';
|
|
40
45
|
|
|
41
46
|
/** Root holding every topic workspace, beside Kabmo database. */
|
|
@@ -45,37 +50,6 @@ export async function getBtwRoot(): Promise<string> {
|
|
|
45
50
|
return root;
|
|
46
51
|
}
|
|
47
52
|
|
|
48
|
-
function parseJsonObject(line: string): Record<string, unknown> | null {
|
|
49
|
-
try {
|
|
50
|
-
const value: unknown = JSON.parse(line);
|
|
51
|
-
return value && typeof value === 'object' && !Array.isArray(value) ? (value as Record<string, unknown>) : null;
|
|
52
|
-
} catch {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* The file's lines, minus a torn tail. A snapshot taken while the parent is
|
|
59
|
-
* mid-append can end in a partial line; keeping it would make the side child
|
|
60
|
-
* fail to load the transcript.
|
|
61
|
-
*/
|
|
62
|
-
function completeLines(text: string): string[] {
|
|
63
|
-
const lines = text.split('\n');
|
|
64
|
-
if (lines[lines.length - 1] === '') lines.pop();
|
|
65
|
-
const last = lines[lines.length - 1];
|
|
66
|
-
if (last !== undefined && parseJsonObject(last) === null) lines.pop();
|
|
67
|
-
return lines;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/** The transcript's leaf: the id of its last entry. */
|
|
71
|
-
export function lastEntryId(lines: string[]): string | null {
|
|
72
|
-
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
73
|
-
const record = parseJsonObject(lines[index]);
|
|
74
|
-
if (record && typeof record.id === 'string') return record.id;
|
|
75
|
-
}
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
53
|
/** Read a transcript's leaf id straight from disk. */
|
|
80
54
|
export async function readTranscriptLeaf(sessionFile: string): Promise<string | null> {
|
|
81
55
|
try {
|
|
@@ -85,18 +59,6 @@ export async function readTranscriptLeaf(sessionFile: string): Promise<string |
|
|
|
85
59
|
}
|
|
86
60
|
}
|
|
87
61
|
|
|
88
|
-
/** The title slot line, padded to the fixed slot omp rewrites in place, with
|
|
89
|
-
* the trailing newline removed (the writer here joins lines itself).
|
|
90
|
-
*
|
|
91
|
-
* Delegates to the repo's slot serializer rather than re-deriving the width:
|
|
92
|
-
* that one truncates the title by code point, so a question written in CJK
|
|
93
|
-
* (up to 3 UTF-8 bytes each) still fits — clipping by character count alone
|
|
94
|
-
* would overflow the slot and fail promotion outright. */
|
|
95
|
-
export function buildTitleLine(title: string, source: string, updatedAt: string): string {
|
|
96
|
-
const line = serializeTitleSlot({ title, source: source === 'auto' ? 'auto' : 'user', updatedAt });
|
|
97
|
-
return line.endsWith('\n') ? line.slice(0, -1) : line;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
62
|
export interface BtwWorkspace {
|
|
101
63
|
dir: string;
|
|
102
64
|
sessionFile: string;
|
|
@@ -13,7 +13,8 @@ import { afterEach, describe, expect, test } from 'bun:test';
|
|
|
13
13
|
import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'fs';
|
|
14
14
|
import { tmpdir } from 'os';
|
|
15
15
|
import { join } from 'path';
|
|
16
|
-
import { buildTitleLine
|
|
16
|
+
import { buildTitleLine } from '@/server/lib/omp/session/transcript-copy';
|
|
17
|
+
import { createBtwWorkspace, getBtwRoot, promoteBtwTopic, readTranscriptLeaf } from '@/server/lib/btw/session-copy.server';
|
|
17
18
|
|
|
18
19
|
const timestamp = '2026-09-23T08:41:10.683Z';
|
|
19
20
|
const createdDirs: string[] = [];
|
|
@@ -23,6 +23,7 @@ import { ensureUsageIndexSchema } from '@/server/lib/usage/index-schema.server';
|
|
|
23
23
|
import { ensureWorktreeSchema } from '@/server/lib/db/worktree-registry.server';
|
|
24
24
|
import { ensureReviewSchema } from '@/server/lib/review/schema.server';
|
|
25
25
|
import { ensureHarnessSchema } from '@/server/lib/harness/schema.server';
|
|
26
|
+
import { ensureSessionRelationsSchema } from '@/server/lib/sessions/schema.server';
|
|
26
27
|
import { migrateWorkspaceFolderColumns } from '@/shared/lib/workspace/schema-migrations';
|
|
27
28
|
import { migrateSessionStreamStateColumns } from '@/shared/lib/omp/session/schema-migrations';
|
|
28
29
|
|
|
@@ -141,6 +142,9 @@ export async function initSchema(db: DbClient): Promise<void> {
|
|
|
141
142
|
// Harness ownership per session: the sidebar's mark needs it, and it has to
|
|
142
143
|
// outlive the process that spawned the child (a restart, a second instance).
|
|
143
144
|
await ensureHarnessSchema(db);
|
|
145
|
+
// Session trees: parent, cleanup ownership and fork origin. Keyed by the id
|
|
146
|
+
// the sidebar and the URL use, so it works for omp files and ACP sessions.
|
|
147
|
+
await ensureSessionRelationsSchema(db);
|
|
144
148
|
await db.exec(`
|
|
145
149
|
CREATE TABLE IF NOT EXISTS files (
|
|
146
150
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
*
|
|
23
23
|
* The `terminal/session.server.ts` helpers are pinned alongside because they
|
|
24
24
|
* need no PTY: the viewer fan-out drop rule (a viewer that cannot keep up is
|
|
25
|
-
* dropped, never skipped, or
|
|
25
|
+
* dropped, never skipped, or the renderer's parser is left mid-sequence), the snapshot
|
|
26
26
|
* shape, and the process-group signalling fallback for a session with no child.
|
|
27
27
|
* Anything requiring a real PTY spawn is deliberately not tested here.
|
|
28
28
|
*/
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
*
|
|
17
17
|
* The `terminal/session.server.ts` helpers are pinned alongside because they
|
|
18
18
|
* need no PTY: the viewer fan-out drop rule (a viewer that cannot keep up is
|
|
19
|
-
* dropped, never skipped, or
|
|
19
|
+
* dropped, never skipped, or the renderer's parser is left mid-sequence), the snapshot
|
|
20
20
|
* shape, and the process-group signalling fallback for a session with no child.
|
|
21
21
|
* Anything requiring a real PTY spawn is deliberately not tested here.
|
|
22
22
|
*/
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The wait that turns opencode's five-second plugin-activation refusal into a
|
|
8
|
+
* session, without turning a real refusal into a two-minute hang.
|
|
9
|
+
*
|
|
10
|
+
* Measured on 2.2.5: `session/new` answered `ServiceUnavailableError` at +6 s
|
|
11
|
+
* while the Claude-bridge plugin list was still activating, and the same
|
|
12
|
+
* process answered a real session at +80 s.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, expect, test } from 'bun:test';
|
|
16
|
+
import {
|
|
17
|
+
newSessionAfterActivation,
|
|
18
|
+
pluginActivationPending,
|
|
19
|
+
} from '@/server/lib/harness/acp/activation';
|
|
20
|
+
|
|
21
|
+
const pending = () => new Error(
|
|
22
|
+
'Internal error: Internal service failure: {"errorName":"ServiceUnavailableError"}',
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
describe('pluginActivationPending', () => {
|
|
26
|
+
test('names the wire error the transport folds into the message', () => {
|
|
27
|
+
expect(pluginActivationPending(pending())).toBe(true);
|
|
28
|
+
expect(pluginActivationPending(new Error('Authentication required'))).toBe(false);
|
|
29
|
+
expect(pluginActivationPending('ServiceUnavailableError')).toBe(true);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('newSessionAfterActivation', () => {
|
|
34
|
+
test('retries the same process while opencode activates its plugins', async () => {
|
|
35
|
+
let calls = 0;
|
|
36
|
+
const result = await newSessionAfterActivation(
|
|
37
|
+
'opencode',
|
|
38
|
+
'/tmp/work',
|
|
39
|
+
async (cwd, timeoutMs) => {
|
|
40
|
+
calls += 1;
|
|
41
|
+
expect(cwd).toBe('/tmp/work');
|
|
42
|
+
expect(timeoutMs).toBe(120_000);
|
|
43
|
+
if (calls < 3) throw pending();
|
|
44
|
+
return { sessionId: 'ses_1' };
|
|
45
|
+
},
|
|
46
|
+
{ retryMs: 1 },
|
|
47
|
+
);
|
|
48
|
+
expect(result.sessionId).toBe('ses_1');
|
|
49
|
+
expect(calls).toBe(3);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('a non-activation refusal is final', async () => {
|
|
53
|
+
let calls = 0;
|
|
54
|
+
const failure = newSessionAfterActivation('opencode', '/tmp/work', async () => {
|
|
55
|
+
calls += 1;
|
|
56
|
+
throw new Error('Authentication required');
|
|
57
|
+
});
|
|
58
|
+
await expect(failure).rejects.toThrow('Authentication required');
|
|
59
|
+
expect(calls).toBe(1);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('other harnesses are never retried', async () => {
|
|
63
|
+
let calls = 0;
|
|
64
|
+
const failure = newSessionAfterActivation('omp-acp', '/tmp/work', async () => {
|
|
65
|
+
calls += 1;
|
|
66
|
+
throw pending();
|
|
67
|
+
}, { retryMs: 1 });
|
|
68
|
+
await expect(failure).rejects.toThrow('ServiceUnavailableError');
|
|
69
|
+
expect(calls).toBe(1);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('a plugin that never activates still ends in a stated refusal', async () => {
|
|
73
|
+
let calls = 0;
|
|
74
|
+
const failure = newSessionAfterActivation('opencode', '/tmp/work', async () => {
|
|
75
|
+
calls += 1;
|
|
76
|
+
throw pending();
|
|
77
|
+
}, { retryMs: 1, totalMs: 0 });
|
|
78
|
+
await expect(failure).rejects.toThrow('plugin activation did not finish within 0s');
|
|
79
|
+
expect(calls).toBe(1);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Wait out opencode's plugin activation before asking it for a session.
|
|
8
|
+
*
|
|
9
|
+
* opencode 2.x boots "Location plugins" per directory asynchronously and guards
|
|
10
|
+
* every request that needs them with a HARD five-second wait
|
|
11
|
+
* (`Location plugins did not finish activating` -> `ServiceUnavailableError`).
|
|
12
|
+
* The activation itself is unbounded: measured 2.2.5 on a real config, one
|
|
13
|
+
* Claude-bridge plugin finished at ~30 s and the full plugin list at ~80 s, so a
|
|
14
|
+
* single `session/new` answered at +6 s with `ServiceUnavailableError` and the
|
|
15
|
+
* probe card read as blocked while the agent was still booting.
|
|
16
|
+
*
|
|
17
|
+
* Retrying the SAME process is the fix, not respawning: the activation is
|
|
18
|
+
* per-process state, and a fresh agent restarts the clock. The wait is bounded
|
|
19
|
+
* because a plugin that never settles must still end in a refusal, with a
|
|
20
|
+
* reason the settings card can show.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import type { AcpSessionNewResult } from '@/server/lib/harness/acp/protocol';
|
|
24
|
+
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
25
|
+
|
|
26
|
+
/** Enough headroom over the measured 80 s, not an open-ended probe. */
|
|
27
|
+
export const ACTIVATION_TIMEOUT_MS = 150_000;
|
|
28
|
+
/** Each retry only needs to let the five-second gate expire. */
|
|
29
|
+
const ACTIVATION_RETRY_MS = 3_000;
|
|
30
|
+
|
|
31
|
+
/** Is this the agent's "plugins are still activating" refusal? The ACP error
|
|
32
|
+
* carries the name in `data`, which the transport folds into the message. */
|
|
33
|
+
export function pluginActivationPending(error: unknown): boolean {
|
|
34
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
35
|
+
return message.includes('ServiceUnavailableError');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ActivationWait {
|
|
39
|
+
totalMs?: number;
|
|
40
|
+
retryMs?: number;
|
|
41
|
+
perAttemptMs?: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* `session/new`, retried while opencode reports pending plugin activation.
|
|
46
|
+
*
|
|
47
|
+
* Only opencode has this gate. Every other harness's first refusal is final —
|
|
48
|
+
* retrying an `Authentication required` would hide it behind a two-minute wait.
|
|
49
|
+
*/
|
|
50
|
+
export async function newSessionAfterActivation(
|
|
51
|
+
harness: HarnessId,
|
|
52
|
+
cwd: string,
|
|
53
|
+
newSession: (cwd: string, timeoutMs?: number) => Promise<AcpSessionNewResult>,
|
|
54
|
+
wait: ActivationWait = {},
|
|
55
|
+
): Promise<AcpSessionNewResult> {
|
|
56
|
+
const { totalMs = ACTIVATION_TIMEOUT_MS, retryMs = ACTIVATION_RETRY_MS, perAttemptMs = 120_000 } = wait;
|
|
57
|
+
if (harness !== 'opencode') return newSession(cwd, perAttemptMs);
|
|
58
|
+
|
|
59
|
+
const giveUpAt = Date.now() + totalMs;
|
|
60
|
+
for (;;) {
|
|
61
|
+
try {
|
|
62
|
+
return await newSession(cwd, perAttemptMs);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if (!pluginActivationPending(error)) throw error;
|
|
65
|
+
if (Date.now() >= giveUpAt) {
|
|
66
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
67
|
+
throw new Error(`${reason} (plugin activation did not finish within ${Math.round(totalMs / 1000)}s)`);
|
|
68
|
+
}
|
|
69
|
+
await Bun.sleep(retryMs);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The delayed-answer probe: antigravity ends a turn when it SPAWNS a subagent
|
|
8
|
+
* and holds the completion until the next request (upstream #1461), so Kabmo
|
|
9
|
+
* replays the transcript with `session/load` and emits only the text the
|
|
10
|
+
* operator has not seen.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { describe, expect, test } from 'bun:test';
|
|
14
|
+
import {
|
|
15
|
+
AcpBackgroundProbe,
|
|
16
|
+
backgroundNotice,
|
|
17
|
+
backgroundNoticeFrames,
|
|
18
|
+
spawnsBackgroundWork,
|
|
19
|
+
} from '@/server/lib/harness/acp/background-work';
|
|
20
|
+
|
|
21
|
+
const toolCall = (name: string) => ({
|
|
22
|
+
role: 'assistant',
|
|
23
|
+
content: [{ type: 'toolCall', id: 't1', name }],
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const chunk = (update: Record<string, unknown>) => ({ update });
|
|
27
|
+
const textChunk = (kind: 'user_message_chunk' | 'agent_message_chunk', text: string) =>
|
|
28
|
+
chunk({ sessionUpdate: kind, content: { type: 'text', text } });
|
|
29
|
+
|
|
30
|
+
interface FakeTimer {
|
|
31
|
+
fn: () => void;
|
|
32
|
+
ms: number;
|
|
33
|
+
cancelled: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isFakeTimer(value: unknown): value is FakeTimer {
|
|
37
|
+
return (
|
|
38
|
+
typeof value === 'object' &&
|
|
39
|
+
value !== null &&
|
|
40
|
+
'fn' in value &&
|
|
41
|
+
'ms' in value &&
|
|
42
|
+
'cancelled' in value &&
|
|
43
|
+
typeof value.fn === 'function' &&
|
|
44
|
+
typeof value.ms === 'number' &&
|
|
45
|
+
typeof value.cancelled === 'boolean'
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The probe arms a timer; cases drive it themselves so nothing sleeps. */
|
|
50
|
+
function timers() {
|
|
51
|
+
const scheduled: FakeTimer[] = [];
|
|
52
|
+
return {
|
|
53
|
+
schedule: (fn: () => void, ms: number): unknown => {
|
|
54
|
+
const handle: FakeTimer = { fn, ms, cancelled: false };
|
|
55
|
+
scheduled.push(handle);
|
|
56
|
+
return handle;
|
|
57
|
+
},
|
|
58
|
+
cancel: (handle: unknown): void => {
|
|
59
|
+
if (isFakeTimer(handle)) handle.cancelled = true;
|
|
60
|
+
},
|
|
61
|
+
next: (): FakeTimer | undefined => scheduled.shift(),
|
|
62
|
+
pending: () => scheduled.filter((handle) => !handle.cancelled),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function settle(): Promise<void> {
|
|
67
|
+
for (let i = 0; i < 6; i += 1) await Promise.resolve();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
describe('background work detection', () => {
|
|
71
|
+
test('a spawned subagent tool call is background work', () => {
|
|
72
|
+
expect(spawnsBackgroundWork(toolCall('invoke_subagent'))).toBe(true);
|
|
73
|
+
expect(spawnsBackgroundWork(toolCall('spawn_subagent'))).toBe(true);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('an awaited tool call is not', () => {
|
|
77
|
+
expect(spawnsBackgroundWork(toolCall('run_command'))).toBe(false);
|
|
78
|
+
expect(spawnsBackgroundWork({ role: 'assistant', content: [{ type: 'text', text: 'hi' }] })).toBe(false);
|
|
79
|
+
expect(spawnsBackgroundWork(undefined)).toBe(false);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('delayed notice extraction', () => {
|
|
84
|
+
test('returns only the text past the answer already shown', () => {
|
|
85
|
+
expect(backgroundNotice('Sedang membuat…', 'Sedang membuat…\nBerikut gambarnya')).toBe('Berikut gambarnya');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('a replay of the same answer is not a notice', () => {
|
|
89
|
+
expect(backgroundNotice('Sedang membuat…', 'Sedang membuat…')).toBeNull();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('a diverged replay is not guessed at', () => {
|
|
93
|
+
expect(backgroundNotice('Sedang membuat…', 'Jawaban lain')).toBeNull();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('an empty baseline accepts the whole segment', () => {
|
|
97
|
+
expect(backgroundNotice('', 'Berikut gambarnya')).toBe('Berikut gambarnya');
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe('background notice frames', () => {
|
|
102
|
+
test('form a complete run so the client releases its generating flag', () => {
|
|
103
|
+
const frames = backgroundNoticeFrames('Berikut gambarnya');
|
|
104
|
+
expect(frames.map((frame) => frame.type)).toEqual([
|
|
105
|
+
'agent_start',
|
|
106
|
+
'turn_start',
|
|
107
|
+
'message_update',
|
|
108
|
+
'message_end',
|
|
109
|
+
'agent_end',
|
|
110
|
+
]);
|
|
111
|
+
expect(frames[3]).toMatchObject({
|
|
112
|
+
type: 'message_end',
|
|
113
|
+
message: { role: 'assistant', content: [{ type: 'text', text: 'Berikut gambarnya' }] },
|
|
114
|
+
});
|
|
115
|
+
expect(frames[4]).toMatchObject({ type: 'agent_end', isTerminal: true });
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe('AcpBackgroundProbe', () => {
|
|
120
|
+
test('backs off and emits once a replay carries new text', async () => {
|
|
121
|
+
const clock = timers();
|
|
122
|
+
const emitted: string[] = [];
|
|
123
|
+
let probe!: AcpBackgroundProbe;
|
|
124
|
+
const replays = ['Sedang membuat…', 'Sedang membuat…\nBerikut gambarnya', 'Sedang membuat…\nBerikut gambarnya'];
|
|
125
|
+
let attempts = 0;
|
|
126
|
+
probe = new AcpBackgroundProbe({
|
|
127
|
+
load: async () => {
|
|
128
|
+
const text = replays[Math.min(attempts, replays.length - 1)];
|
|
129
|
+
attempts += 1;
|
|
130
|
+
probe.consume('session/update', textChunk('user_message_chunk', 'buat gambar'));
|
|
131
|
+
for (const piece of text.split('\n')) {
|
|
132
|
+
probe.consume('session/update', textChunk('agent_message_chunk', piece));
|
|
133
|
+
}
|
|
134
|
+
return {};
|
|
135
|
+
},
|
|
136
|
+
resetIdle: () => {},
|
|
137
|
+
emit: (text) => emitted.push(text),
|
|
138
|
+
firstDelayMs: 10,
|
|
139
|
+
maxDelayMs: 40,
|
|
140
|
+
now: () => 0,
|
|
141
|
+
schedule: clock.schedule,
|
|
142
|
+
cancel: clock.cancel,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
probe.start('Sedang membuat…');
|
|
146
|
+
const first = clock.next();
|
|
147
|
+
expect(first?.ms).toBe(10);
|
|
148
|
+
first?.fn();
|
|
149
|
+
await settle();
|
|
150
|
+
expect(attempts).toBe(1);
|
|
151
|
+
expect(emitted).toEqual([]);
|
|
152
|
+
// No notice yet: the next attempt is scheduled with a doubled delay.
|
|
153
|
+
const second = clock.next();
|
|
154
|
+
expect(second?.ms).toBe(20);
|
|
155
|
+
second?.fn();
|
|
156
|
+
await settle();
|
|
157
|
+
expect(attempts).toBe(2);
|
|
158
|
+
// A first sighting is a prefix while the agent is still writing.
|
|
159
|
+
expect(emitted).toEqual([]);
|
|
160
|
+
const third = clock.next();
|
|
161
|
+
expect(third?.ms).toBe(10);
|
|
162
|
+
third?.fn();
|
|
163
|
+
await settle();
|
|
164
|
+
expect(attempts).toBe(3);
|
|
165
|
+
expect(emitted).toEqual(['Berikut gambarnya']);
|
|
166
|
+
expect(clock.pending()).toHaveLength(0);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test('swallows the replay, and stops swallowing once its load resolves', async () => {
|
|
170
|
+
const clock = timers();
|
|
171
|
+
const deferred = Promise.withResolvers<unknown>();
|
|
172
|
+
let probe!: AcpBackgroundProbe;
|
|
173
|
+
probe = new AcpBackgroundProbe({
|
|
174
|
+
load: () => deferred.promise,
|
|
175
|
+
resetIdle: () => {},
|
|
176
|
+
emit: () => {},
|
|
177
|
+
schedule: clock.schedule,
|
|
178
|
+
cancel: clock.cancel,
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
expect(probe.consume('session/update', textChunk('agent_message_chunk', 'x'))).toBe(false);
|
|
182
|
+
probe.start('wait');
|
|
183
|
+
clock.next()?.fn();
|
|
184
|
+
await settle();
|
|
185
|
+
expect(probe.consume('session/update', textChunk('agent_message_chunk', 'replay'))).toBe(true);
|
|
186
|
+
|
|
187
|
+
deferred.resolve({});
|
|
188
|
+
await settle();
|
|
189
|
+
expect(probe.consume('session/update', textChunk('agent_message_chunk', 'live'))).toBe(false);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test('a stopped probe still swallows the replay its load is waiting on', async () => {
|
|
193
|
+
const clock = timers();
|
|
194
|
+
const deferred = Promise.withResolvers<unknown>();
|
|
195
|
+
let probe!: AcpBackgroundProbe;
|
|
196
|
+
probe = new AcpBackgroundProbe({
|
|
197
|
+
load: () => deferred.promise,
|
|
198
|
+
resetIdle: () => {},
|
|
199
|
+
emit: () => {},
|
|
200
|
+
schedule: clock.schedule,
|
|
201
|
+
cancel: clock.cancel,
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
probe.start('wait');
|
|
205
|
+
clock.next()?.fn();
|
|
206
|
+
await settle();
|
|
207
|
+
probe.stop();
|
|
208
|
+
expect(probe.consume('session/update', textChunk('agent_message_chunk', 'replay'))).toBe(true);
|
|
209
|
+
deferred.resolve({});
|
|
210
|
+
await settle();
|
|
211
|
+
expect(probe.consume('session/update', textChunk('agent_message_chunk', 'live'))).toBe(false);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test('retries a failed load, then gives up instead of spinning', async () => {
|
|
215
|
+
const clock = timers();
|
|
216
|
+
let loads = 0;
|
|
217
|
+
const probe = new AcpBackgroundProbe({
|
|
218
|
+
load: async () => {
|
|
219
|
+
loads += 1;
|
|
220
|
+
throw new Error('session/load is busy');
|
|
221
|
+
},
|
|
222
|
+
resetIdle: () => {},
|
|
223
|
+
emit: () => {},
|
|
224
|
+
timeoutMs: 60_000,
|
|
225
|
+
firstDelayMs: 10,
|
|
226
|
+
now: () => 0,
|
|
227
|
+
schedule: clock.schedule,
|
|
228
|
+
cancel: clock.cancel,
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
probe.start('wait');
|
|
232
|
+
for (let attempt = 1; attempt <= 3; attempt += 1) {
|
|
233
|
+
clock.next()?.fn();
|
|
234
|
+
await settle();
|
|
235
|
+
expect(loads).toBe(attempt);
|
|
236
|
+
}
|
|
237
|
+
expect(clock.pending()).toHaveLength(0);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
test('gives up at its deadline instead of polling forever', async () => {
|
|
241
|
+
const clock = timers();
|
|
242
|
+
let loads = 0;
|
|
243
|
+
const probe = new AcpBackgroundProbe({
|
|
244
|
+
load: async () => {
|
|
245
|
+
loads += 1;
|
|
246
|
+
return {};
|
|
247
|
+
},
|
|
248
|
+
resetIdle: () => {},
|
|
249
|
+
emit: () => {},
|
|
250
|
+
timeoutMs: 0,
|
|
251
|
+
firstDelayMs: 10,
|
|
252
|
+
schedule: clock.schedule,
|
|
253
|
+
cancel: clock.cancel,
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
probe.start('wait');
|
|
257
|
+
clock.next()?.fn();
|
|
258
|
+
await settle();
|
|
259
|
+
expect(loads).toBe(1);
|
|
260
|
+
expect(clock.pending()).toHaveLength(0);
|
|
261
|
+
});
|
|
262
|
+
});
|