@polderlabs/bizar 3.23.1 → 4.2.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 +83 -16
- package/bizar-dash/.bizar/activity.log +3 -0
- package/bizar-dash/.bizar/graph/.graphify_analysis.json +1540 -0
- package/bizar-dash/.bizar/graph/.graphify_labels.json +1 -0
- package/bizar-dash/.bizar/graph/GRAPH_REPORT.md +404 -0
- package/bizar-dash/.bizar/graph/cache/ast/v0.8.46/0661b816358db84dfdb7f10443db8a61152fd20b3fee950caf8fbf32920a1790.json +1 -0
- package/bizar-dash/.bizar/graph/cache/ast/v0.8.46/16da06d774142a6e5d74829ad982531286a6193ef798de8f593db029e123ec32.json +1 -0
- package/bizar-dash/.bizar/graph/cache/ast/v0.8.46/27e5697c01254c69c64c5a33896669073b40afb5ba88375102ae77fa5404136d.json +1 -0
- package/bizar-dash/.bizar/graph/cache/ast/v0.8.46/532997898027254aa4c0932243dc71d2f55888181232b65974961934997dc85b.json +1 -0
- package/bizar-dash/.bizar/graph/cache/ast/v0.8.46/84e3451a64c7f99f0cd6a88b0748d7426780486f53ab4935b7476b28c08f8293.json +1 -0
- package/bizar-dash/.bizar/graph/cache/ast/v0.8.46/88e5ea5f3e78fa69353fe9e6a8d1a05391d54605e25600cb125531eb5a6432ff.json +1 -0
- package/bizar-dash/.bizar/graph/cache/stat-index.json +1 -0
- package/bizar-dash/.bizar/graph/graph.html +307 -0
- package/bizar-dash/.bizar/graph/graph.json +40267 -0
- package/bizar-dash/.bizar/graph/manifest.json +762 -0
- package/bizar-dash/.graphifyignore +40 -0
- package/bizar-dash/.obsidian/README.md +14 -0
- package/bizar-dash/.obsidian/daily/2026-06-25.md +9 -0
- package/bizar-dash/.obsidian/vault.json +7 -0
- package/bizar-dash/.od-skills/web-prototype-e1429c1737/SKILL.md +103 -0
- package/bizar-dash/.od-skills/web-prototype-e1429c1737/assets/template.html +338 -0
- package/bizar-dash/.od-skills/web-prototype-e1429c1737/example.html +81 -0
- package/bizar-dash/.od-skills/web-prototype-e1429c1737/open-design.json +172 -0
- package/bizar-dash/.od-skills/web-prototype-e1429c1737/references/checklist.md +44 -0
- package/bizar-dash/.od-skills/web-prototype-e1429c1737/references/layouts.md +247 -0
- package/bizar-dash/CHANGELOG.md +474 -0
- package/bizar-dash/DESIGN.md +136 -0
- package/bizar-dash/dist/assets/main-B3RgW6FS.js +331 -0
- package/bizar-dash/dist/assets/main-B3RgW6FS.js.map +1 -0
- package/bizar-dash/dist/assets/main-DlJ8wgLR.css +1 -0
- package/bizar-dash/dist/assets/mobile-CsZQAswA.css +1 -0
- package/bizar-dash/dist/assets/mobile-DbxIw8BG.js +2 -0
- package/bizar-dash/dist/assets/mobile-DbxIw8BG.js.map +1 -0
- package/bizar-dash/dist/assets/mobile-Dvq2d53Y.js +354 -0
- package/bizar-dash/dist/assets/mobile-Dvq2d53Y.js.map +1 -0
- package/bizar-dash/dist/index.html +40 -0
- package/bizar-dash/dist/mobile.html +22 -0
- package/bizar-dash/plans/debug-plan/comments.json +1 -0
- package/bizar-dash/plans/debug-plan/meta.json +10 -0
- package/bizar-dash/plans/debug-plan/plan.json +174 -0
- package/bizar-dash/scripts/smoke-bg-retry.mjs +246 -0
- package/bizar-dash/src/cli/dashboard-ports.mjs +488 -0
- package/bizar-dash/src/cli.mjs +522 -0
- package/bizar-dash/src/server/activity-log.mjs +174 -0
- package/bizar-dash/src/server/agents-store.mjs +465 -0
- package/bizar-dash/src/server/api.mjs +138 -0
- package/bizar-dash/src/server/artifact-template.html +810 -0
- package/bizar-dash/src/server/artifacts-store.mjs +733 -0
- package/bizar-dash/src/server/auth.mjs +381 -0
- package/bizar-dash/src/server/background-store.mjs +447 -0
- package/bizar-dash/src/server/bg-poller.mjs +305 -0
- package/bizar-dash/src/server/bg-retry.mjs +574 -0
- package/bizar-dash/src/server/browser.mjs +40 -0
- package/bizar-dash/src/server/diagnostics-store.mjs +148 -0
- package/bizar-dash/src/server/dialog-poller.mjs +105 -0
- package/bizar-dash/src/server/dialog-store.mjs +177 -0
- package/bizar-dash/src/server/glyphs/mdx-compiler.mjs +583 -0
- package/bizar-dash/src/server/lib/path-safe.mjs +283 -0
- package/bizar-dash/src/server/memory-git.mjs +329 -0
- package/bizar-dash/src/server/memory-lightrag.mjs +767 -0
- package/bizar-dash/src/server/memory-schema.mjs +145 -0
- package/bizar-dash/src/server/memory-secrets.mjs +84 -0
- package/bizar-dash/src/server/memory-store.mjs +471 -0
- package/bizar-dash/src/server/mod-security.mjs +398 -0
- package/bizar-dash/src/server/mods-loader.mjs +1067 -0
- package/bizar-dash/src/server/notifications-store.mjs +243 -0
- package/bizar-dash/src/server/obsidian-store.mjs +318 -0
- package/bizar-dash/src/server/opencode-runner.mjs +279 -0
- package/bizar-dash/src/server/pair-store.mjs +138 -0
- package/bizar-dash/src/server/projects-store.mjs +364 -0
- package/bizar-dash/src/server/providers-store.mjs +789 -0
- package/bizar-dash/src/server/routes/_shared.mjs +415 -0
- package/bizar-dash/src/server/routes/activity.mjs +110 -0
- package/bizar-dash/src/server/routes/agents.mjs +134 -0
- package/bizar-dash/src/server/routes/artifacts.mjs +279 -0
- package/bizar-dash/src/server/routes/auth.mjs +69 -0
- package/bizar-dash/src/server/routes/background.mjs +165 -0
- package/bizar-dash/src/server/routes/chat.mjs +485 -0
- package/bizar-dash/src/server/routes/config.mjs +129 -0
- package/bizar-dash/src/server/routes/diagnostics.mjs +50 -0
- package/bizar-dash/src/server/routes/dialogs.mjs +86 -0
- package/bizar-dash/src/server/routes/fs.mjs +429 -0
- package/bizar-dash/src/server/routes/history.mjs +78 -0
- package/bizar-dash/src/server/routes/memory.mjs +658 -0
- package/bizar-dash/src/server/routes/misc.mjs +89 -0
- package/bizar-dash/src/server/routes/mods.mjs +359 -0
- package/bizar-dash/src/server/routes/notifications.mjs +54 -0
- package/bizar-dash/src/server/routes/obsidian.mjs +239 -0
- package/bizar-dash/src/server/routes/opencode-sessions.mjs +55 -0
- package/bizar-dash/src/server/routes/overview.mjs +91 -0
- package/bizar-dash/src/server/routes/pair.mjs +67 -0
- package/bizar-dash/src/server/routes/projects.mjs +175 -0
- package/bizar-dash/src/server/routes/providers.mjs +47 -0
- package/bizar-dash/src/server/routes/schedules.mjs +104 -0
- package/bizar-dash/src/server/routes/settings.mjs +51 -0
- package/bizar-dash/src/server/routes/skills.mjs +76 -0
- package/bizar-dash/src/server/routes/tasks.mjs +468 -0
- package/bizar-dash/src/server/routes/themes.mjs +51 -0
- package/bizar-dash/src/server/routes-v2/auth.mjs +59 -0
- package/bizar-dash/src/server/routes-v2/events.mjs +107 -0
- package/bizar-dash/src/server/routes-v2/health.mjs +21 -0
- package/bizar-dash/src/server/routes-v2/index.mjs +90 -0
- package/bizar-dash/src/server/routes-v2/sessions.mjs +111 -0
- package/bizar-dash/src/server/schedules-runner.mjs +369 -0
- package/bizar-dash/src/server/schedules-store.mjs +268 -0
- package/bizar-dash/src/server/search-store.mjs +220 -0
- package/bizar-dash/src/server/serve-info.mjs +684 -0
- package/bizar-dash/src/server/server.mjs +796 -0
- package/bizar-dash/src/server/settings-store.mjs +45 -0
- package/bizar-dash/src/server/skills-store.mjs +300 -0
- package/bizar-dash/src/server/state.mjs +437 -0
- package/bizar-dash/src/server/tailscale-store.mjs +113 -0
- package/bizar-dash/src/server/task-delegator.mjs +824 -0
- package/bizar-dash/src/server/tasks-store.mjs +508 -0
- package/bizar-dash/src/server/tui.mjs +923 -0
- package/bizar-dash/src/server/update-store.mjs +168 -0
- package/bizar-dash/src/server/v2-auth-file.mjs +99 -0
- package/bizar-dash/src/server/v2-event-bus.mjs +128 -0
- package/bizar-dash/src/server/watcher.mjs +81 -0
- package/bizar-dash/src/server/yaml.mjs +238 -0
- package/bizar-dash/src/web/App.tsx +718 -0
- package/bizar-dash/src/web/MobileApp.tsx +408 -0
- package/bizar-dash/src/web/components/ArtifactCreateDialog.tsx +95 -0
- package/bizar-dash/src/web/components/ArtifactListDialog.tsx +55 -0
- package/bizar-dash/src/web/components/ArtifactViewer.tsx +143 -0
- package/bizar-dash/src/web/components/AuditDialog.tsx +79 -0
- package/bizar-dash/src/web/components/BgStatusBadge.tsx +32 -0
- package/bizar-dash/src/web/components/Button.tsx +56 -0
- package/bizar-dash/src/web/components/CanvasContextMenu.tsx +68 -0
- package/bizar-dash/src/web/components/Card.tsx +40 -0
- package/bizar-dash/src/web/components/CollapsibleSection.tsx +72 -0
- package/bizar-dash/src/web/components/CommandDialog.tsx +66 -0
- package/bizar-dash/src/web/components/EmptyState.tsx +30 -0
- package/bizar-dash/src/web/components/FileBrowser.tsx +633 -0
- package/bizar-dash/src/web/components/HelpDialog.tsx +55 -0
- package/bizar-dash/src/web/components/KillConfirmDialog.tsx +88 -0
- package/bizar-dash/src/web/components/Modal.tsx +215 -0
- package/bizar-dash/src/web/components/Notifications.tsx +241 -0
- package/bizar-dash/src/web/components/SearchModal.tsx +224 -0
- package/bizar-dash/src/web/components/Sidebar.tsx +66 -0
- package/bizar-dash/src/web/components/Spinner.tsx +19 -0
- package/bizar-dash/src/web/components/StatusBadge.tsx +25 -0
- package/bizar-dash/src/web/components/Tag.tsx +28 -0
- package/bizar-dash/src/web/components/Toast.tsx +150 -0
- package/bizar-dash/src/web/components/Topbar.tsx +368 -0
- package/bizar-dash/src/web/components/VisualPlanDialog.tsx +58 -0
- package/bizar-dash/src/web/components/chat/AgentChip.tsx +68 -0
- package/bizar-dash/src/web/components/chat/ChatBubble.tsx +60 -0
- package/bizar-dash/src/web/components/chat/ChatThread.tsx +88 -0
- package/bizar-dash/src/web/components/chat/ChatTopBar.tsx +50 -0
- package/bizar-dash/src/web/components/chat/Composer.tsx +164 -0
- package/bizar-dash/src/web/components/chat/ConfirmModal.tsx +54 -0
- package/bizar-dash/src/web/components/chat/EmptyState.tsx +21 -0
- package/bizar-dash/src/web/components/chat/FirstRunGreeting.tsx +18 -0
- package/bizar-dash/src/web/components/chat/FloatingComposer.tsx +32 -0
- package/bizar-dash/src/web/components/chat/InfoPanel.tsx +119 -0
- package/bizar-dash/src/web/components/chat/LoadingSkeleton.tsx +19 -0
- package/bizar-dash/src/web/components/chat/MessageBubble.tsx +60 -0
- package/bizar-dash/src/web/components/chat/SessionList.tsx +153 -0
- package/bizar-dash/src/web/components/chat/StreamingIndicator.tsx +9 -0
- package/bizar-dash/src/web/components/chat/SuggestionCards.tsx +55 -0
- package/bizar-dash/src/web/components/chat/WelcomeScreen.tsx +36 -0
- package/bizar-dash/src/web/components/chat/index.ts +20 -0
- package/bizar-dash/src/web/components/chat/useAutoGrowTextarea.ts +18 -0
- package/bizar-dash/src/web/components/chat/useChat.ts +219 -0
- package/bizar-dash/src/web/components/chat/useSlashCommands.ts +47 -0
- package/bizar-dash/src/web/index.html +37 -0
- package/bizar-dash/src/web/lib/api.ts +193 -0
- package/bizar-dash/src/web/lib/markdown.tsx +59 -0
- package/bizar-dash/src/web/lib/types.ts +668 -0
- package/bizar-dash/src/web/lib/utils.ts +114 -0
- package/bizar-dash/src/web/lib/ws.ts +176 -0
- package/bizar-dash/src/web/main.tsx +34 -0
- package/bizar-dash/src/web/mobile/MobileApp.tsx +278 -0
- package/bizar-dash/src/web/mobile/MobileBottomNav.tsx +38 -0
- package/bizar-dash/src/web/mobile/MobileTopbar.tsx +115 -0
- package/bizar-dash/src/web/mobile/components/MobileBottomSheet.tsx +182 -0
- package/bizar-dash/src/web/mobile/components/MobileListItem.tsx +64 -0
- package/bizar-dash/src/web/mobile/components/MobileModal.tsx +123 -0
- package/bizar-dash/src/web/mobile/views/MobileActivity.tsx +273 -0
- package/bizar-dash/src/web/mobile/views/MobileAgents.tsx +374 -0
- package/bizar-dash/src/web/mobile/views/MobileArtifactCanvas.tsx +439 -0
- package/bizar-dash/src/web/mobile/views/MobileArtifacts.tsx +143 -0
- package/bizar-dash/src/web/mobile/views/MobileChat.tsx +180 -0
- package/bizar-dash/src/web/mobile/views/MobileConfig.tsx +175 -0
- package/bizar-dash/src/web/mobile/views/MobileHistory.tsx +191 -0
- package/bizar-dash/src/web/mobile/views/MobileMods.tsx +149 -0
- package/bizar-dash/src/web/mobile/views/MobileMore.tsx +121 -0
- package/bizar-dash/src/web/mobile/views/MobileNotifications.tsx +137 -0
- package/bizar-dash/src/web/mobile/views/MobilePlans.tsx +26 -0
- package/bizar-dash/src/web/mobile/views/MobileSchedules.tsx +685 -0
- package/bizar-dash/src/web/mobile/views/MobileSearchModal.tsx +172 -0
- package/bizar-dash/src/web/mobile/views/MobileSettings.tsx +388 -0
- package/bizar-dash/src/web/mobile/views/MobileSkills.tsx +153 -0
- package/bizar-dash/src/web/mobile/views/MobileTasks.tsx +564 -0
- package/bizar-dash/src/web/mobile.html +20 -0
- package/bizar-dash/src/web/mobile.tsx +13 -0
- package/bizar-dash/src/web/styles/chat.css +198 -0
- package/bizar-dash/src/web/styles/glyphs.css +960 -0
- package/bizar-dash/src/web/styles/main.css +8855 -0
- package/bizar-dash/src/web/styles/mobile-chat.css +5 -0
- package/bizar-dash/src/web/styles/mobile.css +1960 -0
- package/bizar-dash/src/web/views/Activity.tsx +1203 -0
- package/bizar-dash/src/web/views/Agents.tsx +701 -0
- package/bizar-dash/src/web/views/Artifacts.tsx +1480 -0
- package/bizar-dash/src/web/views/BackgroundAgents.tsx +450 -0
- package/bizar-dash/src/web/views/Chat.tsx +190 -0
- package/bizar-dash/src/web/views/Config.tsx +2063 -0
- package/bizar-dash/src/web/views/History.tsx +335 -0
- package/bizar-dash/src/web/views/ModView.tsx +207 -0
- package/bizar-dash/src/web/views/Mods.tsx +693 -0
- package/bizar-dash/src/web/views/Overview.tsx +812 -0
- package/bizar-dash/src/web/views/Providers.tsx +302 -0
- package/bizar-dash/src/web/views/Schedules.tsx +802 -0
- package/bizar-dash/src/web/views/Settings.tsx +1787 -0
- package/bizar-dash/src/web/views/Skills.tsx +431 -0
- package/bizar-dash/src/web/views/Tasks.tsx +1523 -0
- package/bizar-dash/src/web/views/glyphs/GlyphRenderer.tsx +613 -0
- package/bizar-dash/src/web/views/glyphs/components.tsx +1098 -0
- package/bizar-dash/templates/mod/FORMAT.md +76 -0
- package/bizar-dash/templates/mod/hello-mod/README.md +19 -0
- package/bizar-dash/templates/mod/hello-mod/agents/greeter.md +8 -0
- package/bizar-dash/templates/mod/hello-mod/commands/hello.md +6 -0
- package/bizar-dash/templates/mod/hello-mod/mod.json +20 -0
- package/bizar-dash/templates/mod/hello-mod/routes/ping.mjs +9 -0
- package/bizar-dash/templates/mod/hello-mod/views/HelloView.tsx +10 -0
- package/bizar-dash/tests/dashboard-ports.test.mjs +138 -0
- package/bizar-dash/tests/graphify-mod-spawn.node.test.mjs +90 -0
- package/bizar-dash/tests/memory-cli.test.mjs +542 -0
- package/bizar-dash/tests/memory-config.test.mjs +422 -0
- package/bizar-dash/tests/memory-git.test.mjs +246 -0
- package/bizar-dash/tests/memory-lightrag.test.mjs +153 -0
- package/bizar-dash/tests/memory-protocol-drift.test.mjs +45 -0
- package/bizar-dash/tests/memory-schema.test.mjs +198 -0
- package/bizar-dash/tests/memory-secrets.test.mjs +121 -0
- package/bizar-dash/tests/memory-store.test.mjs +390 -0
- package/bizar-dash/tests/memory-sync.test.mjs +141 -0
- package/bizar-dash/tests/mod-instructions.node.test.mjs +188 -0
- package/bizar-dash/tests/mod-security.test.mjs +273 -0
- package/bizar-dash/tests/mod-upgrade.node.test.mjs +357 -0
- package/bizar-dash/tests/no-agent-browser.node.test.mjs +98 -0
- package/bizar-dash/tests/obsidian-back-compat.test.mjs +199 -0
- package/bizar-dash/tests/opencode-runner.test.mjs +172 -0
- package/bizar-dash/tests/path-safe.test.mjs +108 -0
- package/bizar-dash/tests/providers-store-backup-keys.node.test.mjs +333 -0
- package/bizar-dash/tests/smoke-v2.mjs +212 -0
- package/bizar-dash/tests/strip-thinking.test.mjs +175 -0
- package/bizar-dash/tests/submit-feedback.test.mjs +353 -0
- package/bizar-dash/tests/tmux-wrap.test.mjs +145 -0
- package/bizar-dash/tests/yaml.test.mjs +128 -0
- package/bizar-dash/tsconfig.json +23 -0
- package/bizar-dash/vite.config.ts +27 -0
- package/cli/atomic.mjs +73 -0
- package/cli/banner.mjs +1 -1
- package/cli/bin.mjs +44 -47
- package/cli/bootstrap.mjs +1 -1
- package/cli/copy.mjs +25 -16
- package/cli/dev-link.mjs +17 -1
- package/cli/doctor.mjs +4 -4
- package/cli/doctor.test.mjs +2 -2
- package/cli/init.mjs +135 -1
- package/cli/install.mjs +31 -39
- package/cli/memory-constants.mjs +59 -0
- package/cli/memory.mjs +1436 -0
- package/cli/service.mjs +5 -6
- package/cli/utils.mjs +6 -3
- package/config/AGENTS.md +7 -7
- package/config/agents/_shared/AGENT_BASELINE.md +59 -61
- package/config/opencode.json +13 -38
- package/config/skills/memory-protocol/SKILL.md +105 -0
- package/config/skills/obsidian/SKILL.md +270 -65
- package/install.sh +59 -19
- package/package.json +49 -14
- package/packages/sdk/LICENSE +21 -0
- package/packages/sdk/README.md +80 -0
- package/packages/sdk/src/client.ts +183 -0
- package/packages/sdk/src/errors.ts +120 -0
- package/packages/sdk/src/events.ts +153 -0
- package/packages/sdk/src/index.ts +63 -0
- package/packages/sdk/src/types.ts +176 -0
- package/packages/sdk/src/version.ts +4 -0
- package/packages/sdk/tests/client.test.ts +217 -0
- package/packages/sdk/tests/errors.test.ts +108 -0
- package/packages/sdk/tests/events.test.ts +139 -0
- package/packages/sdk/tests/fixtures/fetch-mock.ts +152 -0
- package/packages/sdk/tests/fixtures/sse-mock.ts +30 -0
- package/packages/sdk/tsconfig.json +25 -0
- package/packages/sdk/vitest.config.ts +9 -0
- package/plugins/bizar/LICENSE +21 -0
- package/plugins/bizar/README.md +448 -0
- package/plugins/bizar/dist/index.js +29901 -0
- package/plugins/bizar/index.ts +1491 -0
- package/plugins/bizar/scripts/check-forbidden-imports.sh +33 -0
- package/plugins/bizar/src/background-state.ts +551 -0
- package/plugins/bizar/src/background.ts +1250 -0
- package/plugins/bizar/src/commands-impl.ts +464 -0
- package/plugins/bizar/src/commands.ts +1168 -0
- package/plugins/bizar/src/dashboard-client.ts +233 -0
- package/plugins/bizar/src/event-stream.ts +606 -0
- package/plugins/bizar/src/fingerprint.ts +120 -0
- package/plugins/bizar/src/handoff.ts +79 -0
- package/plugins/bizar/src/http-client.ts +467 -0
- package/plugins/bizar/src/key-rotation.ts +218 -0
- package/plugins/bizar/src/logger.ts +144 -0
- package/plugins/bizar/src/loop.ts +176 -0
- package/plugins/bizar/src/opencode-runner.ts +390 -0
- package/plugins/bizar/src/options.ts +421 -0
- package/plugins/bizar/src/plan-fs.ts +323 -0
- package/plugins/bizar/src/reasoning-clean.ts +454 -0
- package/plugins/bizar/src/report.ts +178 -0
- package/plugins/bizar/src/research-prompt.ts +35 -0
- package/plugins/bizar/src/serve-info.ts +228 -0
- package/plugins/bizar/src/serve.ts +496 -0
- package/plugins/bizar/src/settings.ts +349 -0
- package/plugins/bizar/src/state.ts +298 -0
- package/plugins/bizar/src/tools/bg-collect.ts +104 -0
- package/plugins/bizar/src/tools/bg-get-comments.ts +239 -0
- package/plugins/bizar/src/tools/bg-kill.ts +87 -0
- package/plugins/bizar/src/tools/bg-spawn.ts +401 -0
- package/plugins/bizar/src/tools/bg-status.ts +99 -0
- package/plugins/bizar/src/tools/open-kb.ts +191 -0
- package/plugins/bizar/src/tools/plan-action.ts +767 -0
- package/plugins/bizar/src/tools/read-glyph-feedback.ts +170 -0
- package/plugins/bizar/src/tools/wait-for-feedback.ts +402 -0
- package/plugins/bizar/tests/attach-handler-bug.test.ts +169 -0
- package/plugins/bizar/tests/background-state.test.ts +277 -0
- package/plugins/bizar/tests/background.test.ts +402 -0
- package/plugins/bizar/tests/block.test.ts +195 -0
- package/plugins/bizar/tests/canonical-key-order.test.ts +75 -0
- package/plugins/bizar/tests/commands-impl.test.ts +442 -0
- package/plugins/bizar/tests/commands.test.ts +584 -0
- package/plugins/bizar/tests/config.test.ts +122 -0
- package/plugins/bizar/tests/dashboard-client.test.ts +159 -0
- package/plugins/bizar/tests/dispose.test.ts +336 -0
- package/plugins/bizar/tests/event-stream.test.ts +409 -0
- package/plugins/bizar/tests/event.test.ts +262 -0
- package/plugins/bizar/tests/fingerprint.test.ts +162 -0
- package/plugins/bizar/tests/http-client.test.ts +404 -0
- package/plugins/bizar/tests/init-helpers.test.ts +203 -0
- package/plugins/bizar/tests/integration/slash-command.test.ts +348 -0
- package/plugins/bizar/tests/integration/tool-routing.test.ts +314 -0
- package/plugins/bizar/tests/key-rotation.test.ts +396 -0
- package/plugins/bizar/tests/loop.test.ts +397 -0
- package/plugins/bizar/tests/options.test.ts +276 -0
- package/plugins/bizar/tests/reasoning-clean.test.ts +422 -0
- package/plugins/bizar/tests/serve.test.ts +339 -0
- package/plugins/bizar/tests/settings.test.ts +351 -0
- package/plugins/bizar/tests/stall-think.test.ts +750 -0
- package/plugins/bizar/tests/state.test.ts +276 -0
- package/plugins/bizar/tests/tools/bg-collect.test.ts +337 -0
- package/plugins/bizar/tests/tools/bg-get-comments.test.ts +485 -0
- package/plugins/bizar/tests/tools/bg-kill.test.ts +235 -0
- package/plugins/bizar/tests/tools/bg-spawn-delegation.test.ts +147 -0
- package/plugins/bizar/tests/tools/bg-spawn.test.ts +311 -0
- package/plugins/bizar/tests/tools/bg-status.test.ts +217 -0
- package/plugins/bizar/tests/tools/opencode-runner.test.ts +115 -0
- package/plugins/bizar/tests/tools/plan-action.test.ts +599 -0
- package/plugins/bizar/tests/tools/read-glyph-feedback.test.ts +253 -0
- package/plugins/bizar/tests/tools/wait-for-feedback.test.ts +390 -0
- package/plugins/bizar/tests/update-deadlock.test.ts +145 -0
- package/plugins/bizar/tsconfig.json +29 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* read-glyph-feedback.ts
|
|
3
|
+
*
|
|
4
|
+
* `read_glyph_feedback` tool (v3.22.0).
|
|
5
|
+
*
|
|
6
|
+
* Reads the structured `feedback.md` file the user wrote when they
|
|
7
|
+
* clicked "Submit to agent" on a glyph in the dashboard. Returns:
|
|
8
|
+
* - parsed frontmatter (glyph, submittedAt, submittedBy, commentCount, questionCount)
|
|
9
|
+
* - the markdown body (Free-placed comments / Open-question answers / Full MDX source)
|
|
10
|
+
* - the parsed counts
|
|
11
|
+
*
|
|
12
|
+
* File location: `<worktree>/artifacts/<slug>/feedback.md`. The dashboard
|
|
13
|
+
* writes this file via `POST /api/artifacts/:slug/submit` and marks the
|
|
14
|
+
* artifact's `meta.json` `status` as `review`.
|
|
15
|
+
*
|
|
16
|
+
* Companion tools:
|
|
17
|
+
* - `bizar_get_plan_comments` — legacy canvas comment reader
|
|
18
|
+
* - `bizar_plan_action` — CRUD on the v2 canvas
|
|
19
|
+
*
|
|
20
|
+
* Read-only — available to ALL agents. Never throws.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { tool } from "@opencode-ai/plugin";
|
|
24
|
+
import { z } from "zod";
|
|
25
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
26
|
+
import { join } from "node:path";
|
|
27
|
+
|
|
28
|
+
import type { Logger } from "../logger.js";
|
|
29
|
+
|
|
30
|
+
export interface ReadGlyphFeedbackDeps {
|
|
31
|
+
/** The project's working directory (e.g. /home/user/proj). `artifacts/` is here. */
|
|
32
|
+
worktree: string;
|
|
33
|
+
logger: Logger;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// --- Constants -----------------------------------------------------------
|
|
37
|
+
|
|
38
|
+
/** Same slug rule used everywhere in the project. */
|
|
39
|
+
const SLUG_REGEX = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
40
|
+
|
|
41
|
+
// --- Return type ---------------------------------------------------------
|
|
42
|
+
|
|
43
|
+
export interface ReadGlyphFeedbackResult {
|
|
44
|
+
ok: true;
|
|
45
|
+
found: true;
|
|
46
|
+
slug: string;
|
|
47
|
+
meta: Record<string, string>;
|
|
48
|
+
body: string;
|
|
49
|
+
feedbackFile: string;
|
|
50
|
+
commentCount: number;
|
|
51
|
+
questionCount: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface ReadGlyphFeedbackMissing {
|
|
55
|
+
ok: true;
|
|
56
|
+
found: false;
|
|
57
|
+
slug: string;
|
|
58
|
+
message: string;
|
|
59
|
+
feedbackFile: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface ReadGlyphFeedbackError {
|
|
63
|
+
ok: false;
|
|
64
|
+
error: string;
|
|
65
|
+
slug: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type ReadGlyphFeedbackOutcome =
|
|
69
|
+
| ReadGlyphFeedbackResult
|
|
70
|
+
| ReadGlyphFeedbackMissing
|
|
71
|
+
| ReadGlyphFeedbackError;
|
|
72
|
+
|
|
73
|
+
// --- Pure core: readGlyphFeedback ----------------------------------------
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Read `artifacts/<slug>/feedback.md` from disk and parse it. Exported
|
|
77
|
+
* so tests can drive the same code path the real tool uses.
|
|
78
|
+
*
|
|
79
|
+
* Behavior:
|
|
80
|
+
* - Invalid slug → returns `{ ok: false, error }`
|
|
81
|
+
* - File missing → returns `{ ok: true, found: false, message }`
|
|
82
|
+
* - File present, parseable → returns `{ ok: true, found: true, meta, body, ... }`
|
|
83
|
+
* - File present, corrupt → returns `{ ok: true, found: true, meta: {}, body: raw }`
|
|
84
|
+
*
|
|
85
|
+
* Never throws.
|
|
86
|
+
*/
|
|
87
|
+
export function readGlyphFeedback(
|
|
88
|
+
worktree: string,
|
|
89
|
+
slug: string,
|
|
90
|
+
): ReadGlyphFeedbackOutcome {
|
|
91
|
+
if (!SLUG_REGEX.test(slug)) {
|
|
92
|
+
return {
|
|
93
|
+
ok: false,
|
|
94
|
+
error: `Invalid slug: "${slug}". Must match ^[a-z0-9][a-z0-9-]{0,63}$.`,
|
|
95
|
+
slug,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const feedbackFile = join(worktree, "artifacts", slug, "feedback.md");
|
|
100
|
+
if (!existsSync(feedbackFile)) {
|
|
101
|
+
return {
|
|
102
|
+
ok: true,
|
|
103
|
+
found: false,
|
|
104
|
+
slug,
|
|
105
|
+
message: `No feedback.md in artifacts/${slug}/ — has the user submitted feedback yet?`,
|
|
106
|
+
feedbackFile,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const raw = readFileSync(feedbackFile, "utf-8");
|
|
111
|
+
|
|
112
|
+
// Parse the YAML frontmatter. We only support scalar values (string /
|
|
113
|
+
// number) because the dashboard's writer only emits scalars.
|
|
114
|
+
const meta: Record<string, string> = {};
|
|
115
|
+
const fm = raw.match(/^---\n([\s\S]+?)\n---/);
|
|
116
|
+
let body = raw;
|
|
117
|
+
if (fm) {
|
|
118
|
+
for (const line of fm[1].split("\n")) {
|
|
119
|
+
const m = line.match(/^(\w+):\s*(.*)$/);
|
|
120
|
+
if (m) meta[m[1]] = m[2];
|
|
121
|
+
}
|
|
122
|
+
body = raw.slice(fm[0].length).replace(/^\s+/, "");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const commentCount = parseInt(meta.commentCount || "0", 10) || 0;
|
|
126
|
+
const questionCount = parseInt(meta.questionCount || "0", 10) || 0;
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
ok: true,
|
|
130
|
+
found: true,
|
|
131
|
+
slug,
|
|
132
|
+
meta,
|
|
133
|
+
body,
|
|
134
|
+
feedbackFile,
|
|
135
|
+
commentCount,
|
|
136
|
+
questionCount,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// --- Tool factory --------------------------------------------------------
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Build the `read_glyph_feedback` tool. The plugin wires the result
|
|
144
|
+
* into `Hooks.tool`. The `deps` closure carries the worktree and logger.
|
|
145
|
+
*/
|
|
146
|
+
export function createReadGlyphFeedbackTool(deps: ReadGlyphFeedbackDeps) {
|
|
147
|
+
return tool({
|
|
148
|
+
description:
|
|
149
|
+
"Reads feedback.md for a glyph the user submitted for review. " +
|
|
150
|
+
"Returns free-placed comments with (x, y) coordinates, answers to " +
|
|
151
|
+
"OpenQuestions, and the original MDX source. Use this to understand " +
|
|
152
|
+
"exactly what the user wants changed before regenerating the glyph.",
|
|
153
|
+
args: {
|
|
154
|
+
slug: z
|
|
155
|
+
.string()
|
|
156
|
+
.min(1)
|
|
157
|
+
.max(64)
|
|
158
|
+
.regex(/^[a-z0-9][a-z0-9-]{0,63}$/, "Must match ^[a-z0-9][a-z0-9-]{0,63}$")
|
|
159
|
+
.describe("The artifact slug (e.g., 'dashboard-stale-pid-fix')."),
|
|
160
|
+
},
|
|
161
|
+
execute: async (rawArgs) => {
|
|
162
|
+
const args = rawArgs as { slug: string };
|
|
163
|
+
const result = readGlyphFeedback(deps.worktree, args.slug);
|
|
164
|
+
if (!result.ok) {
|
|
165
|
+
deps.logger.warn(`bizar: read_glyph_feedback(${args.slug}) failed: ${result.error}`);
|
|
166
|
+
}
|
|
167
|
+
return { output: JSON.stringify(result) };
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
}
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wait-for-feedback.ts
|
|
3
|
+
*
|
|
4
|
+
* `bizar_wait_for_feedback` tool (v0.4.0).
|
|
5
|
+
*
|
|
6
|
+
* Blocks the agent's turn until one of the following happens:
|
|
7
|
+
* 1. A new comment is added to the plan canvas (filtered by
|
|
8
|
+
* `sinceTimestamp` if provided).
|
|
9
|
+
* 2. `meta.json.status` becomes "approved" or "rejected".
|
|
10
|
+
* 3. `timeoutMs` is reached.
|
|
11
|
+
*
|
|
12
|
+
* Implementation:
|
|
13
|
+
* - Polls every 2 seconds via `setTimeout`. NOT a busy loop.
|
|
14
|
+
* - Each tick reads `plan.json` and `meta.json` from disk.
|
|
15
|
+
* - Returns immediately on success; on timeout returns
|
|
16
|
+
* `status: "timed_out"`.
|
|
17
|
+
*
|
|
18
|
+
* The tool never throws. All errors return a structured result.
|
|
19
|
+
*
|
|
20
|
+
* Companion tools:
|
|
21
|
+
* - `bizar_plan_action` — CRUD on the canvas (add comments, etc.)
|
|
22
|
+
* - `bizar_get_plan_comments` — read-only access to comments
|
|
23
|
+
*
|
|
24
|
+
* v0.4.0 MVP — this is the polling version. A future v0.5.0 will
|
|
25
|
+
* switch to SSE-based push notifications from the plan server.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { tool } from "@opencode-ai/plugin";
|
|
29
|
+
import { z } from "zod";
|
|
30
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
31
|
+
import { join } from "node:path";
|
|
32
|
+
|
|
33
|
+
import type { Logger } from "../logger.js";
|
|
34
|
+
|
|
35
|
+
// --- On-disk shapes (subset) ---------------------------------------------
|
|
36
|
+
|
|
37
|
+
interface PlanComment {
|
|
38
|
+
id?: string;
|
|
39
|
+
elementId?: string | null;
|
|
40
|
+
author?: string;
|
|
41
|
+
text?: string;
|
|
42
|
+
created?: string;
|
|
43
|
+
thread?: Array<{ id?: string; author?: string; created?: string }>;
|
|
44
|
+
[key: string]: unknown;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface PlanCanvas {
|
|
48
|
+
schemaVersion?: number;
|
|
49
|
+
elements?: unknown[];
|
|
50
|
+
connections?: unknown[];
|
|
51
|
+
comments?: PlanComment[];
|
|
52
|
+
[key: string]: unknown;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface PlanMeta {
|
|
56
|
+
status?: string;
|
|
57
|
+
[key: string]: unknown;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// --- Constants -----------------------------------------------------------
|
|
61
|
+
|
|
62
|
+
/** Polling interval in ms. 2 seconds — short enough for snappy UX,
|
|
63
|
+
* long enough that 5 ticks of polling per 10s window doesn't hammer disk. */
|
|
64
|
+
const POLL_INTERVAL_MS = 2_000;
|
|
65
|
+
|
|
66
|
+
/** Min/max/default timeout per spec. */
|
|
67
|
+
const TIMEOUT_MIN_MS = 5_000;
|
|
68
|
+
const TIMEOUT_MAX_MS = 1_800_000;
|
|
69
|
+
const TIMEOUT_DEFAULT_MS = 600_000;
|
|
70
|
+
|
|
71
|
+
/** Same slug rule used everywhere in the project. */
|
|
72
|
+
const SLUG_REGEX = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
73
|
+
|
|
74
|
+
// --- Return type ---------------------------------------------------------
|
|
75
|
+
|
|
76
|
+
export type WaitOutcome =
|
|
77
|
+
| "feedback_received"
|
|
78
|
+
| "approved"
|
|
79
|
+
| "rejected"
|
|
80
|
+
| "timed_out";
|
|
81
|
+
|
|
82
|
+
export type PlanStatusOutcome =
|
|
83
|
+
| "draft"
|
|
84
|
+
| "approved"
|
|
85
|
+
| "rejected"
|
|
86
|
+
| "in-progress"
|
|
87
|
+
| "done";
|
|
88
|
+
|
|
89
|
+
export interface WaitResult {
|
|
90
|
+
ok: true;
|
|
91
|
+
status: WaitOutcome;
|
|
92
|
+
planSlug: string;
|
|
93
|
+
planStatus: PlanStatusOutcome;
|
|
94
|
+
newComments: PlanComment[];
|
|
95
|
+
waitedMs: number;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface WaitError {
|
|
99
|
+
ok: false;
|
|
100
|
+
status: "error";
|
|
101
|
+
planSlug: string;
|
|
102
|
+
error: string;
|
|
103
|
+
waitedMs: number;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export type WaitForFeedbackResult = WaitResult | WaitError;
|
|
107
|
+
|
|
108
|
+
// --- Pure core: waitForFeedback ------------------------------------------
|
|
109
|
+
|
|
110
|
+
export interface WaitForFeedbackArgs {
|
|
111
|
+
planSlug: string;
|
|
112
|
+
timeoutMs?: number;
|
|
113
|
+
sinceTimestamp?: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface WaitForFeedbackDeps {
|
|
117
|
+
worktree: string;
|
|
118
|
+
logger: Logger;
|
|
119
|
+
/**
|
|
120
|
+
* Override the polling interval. Tests pass a small value (e.g. 5ms)
|
|
121
|
+
* to keep the suite fast. Defaults to POLL_INTERVAL_MS.
|
|
122
|
+
*/
|
|
123
|
+
pollIntervalMs?: number;
|
|
124
|
+
/** Override the sleep function (tests use this). Defaults to global setTimeout. */
|
|
125
|
+
sleep?: (ms: number) => Promise<void>;
|
|
126
|
+
/** Override the current-time source (tests). Defaults to Date.now. */
|
|
127
|
+
now?: () => number;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function clampTimeout(raw: number | undefined): number {
|
|
131
|
+
if (raw === undefined) return TIMEOUT_DEFAULT_MS;
|
|
132
|
+
if (!Number.isFinite(raw) || raw < TIMEOUT_MIN_MS) return TIMEOUT_MIN_MS;
|
|
133
|
+
if (raw > TIMEOUT_MAX_MS) return TIMEOUT_MAX_MS;
|
|
134
|
+
return Math.floor(raw);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function defaultSleep(ms: number): Promise<void> {
|
|
138
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Read the plan.json from disk. Returns null on missing/corrupt.
|
|
143
|
+
*/
|
|
144
|
+
function readCanvas(planPath: string): PlanCanvas | null {
|
|
145
|
+
if (!existsSync(planPath)) return null;
|
|
146
|
+
try {
|
|
147
|
+
const raw = readFileSync(planPath, "utf-8");
|
|
148
|
+
const parsed = JSON.parse(raw) as unknown;
|
|
149
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
return parsed as PlanCanvas;
|
|
153
|
+
} catch {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Read meta.json. Returns null on missing/corrupt.
|
|
160
|
+
*/
|
|
161
|
+
function readMeta(metaPath: string): PlanMeta | null {
|
|
162
|
+
if (!existsSync(metaPath)) return null;
|
|
163
|
+
try {
|
|
164
|
+
const raw = readFileSync(metaPath, "utf-8");
|
|
165
|
+
const parsed = JSON.parse(raw) as unknown;
|
|
166
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
return parsed as PlanMeta;
|
|
170
|
+
} catch {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Sort comments oldest-first by `created`. Missing timestamps go to the end. */
|
|
176
|
+
function sortByCreated(comments: PlanComment[]): PlanComment[] {
|
|
177
|
+
return comments.slice().sort((a, b) => {
|
|
178
|
+
const at = String(a.created ?? "");
|
|
179
|
+
const bt = String(b.created ?? "");
|
|
180
|
+
if (at === bt) return 0;
|
|
181
|
+
if (at === "") return 1;
|
|
182
|
+
if (bt === "") return -1;
|
|
183
|
+
return at.localeCompare(bt);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Filter comments to only those with `created` strictly greater than the
|
|
188
|
+
* cutoff. If `sinceTimestamp` is undefined, returns the input as-is. */
|
|
189
|
+
function filterNewComments(
|
|
190
|
+
comments: PlanComment[],
|
|
191
|
+
sinceTimestamp: string | undefined,
|
|
192
|
+
): PlanComment[] {
|
|
193
|
+
if (sinceTimestamp === undefined || sinceTimestamp === "") {
|
|
194
|
+
return comments;
|
|
195
|
+
}
|
|
196
|
+
return comments.filter((c) => {
|
|
197
|
+
const created = String(c.created ?? "");
|
|
198
|
+
return created !== "" && created > sinceTimestamp;
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function normalizeStatus(raw: string | undefined): PlanStatusOutcome {
|
|
203
|
+
if (raw === "draft" || raw === "approved" || raw === "rejected" ||
|
|
204
|
+
raw === "in-progress" || raw === "done") {
|
|
205
|
+
return raw;
|
|
206
|
+
}
|
|
207
|
+
return "draft";
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Poll the plan until feedback arrives, status changes, or the timeout
|
|
212
|
+
* is reached. Extracted from the tool factory so tests can drive the same
|
|
213
|
+
* code path with a tiny `pollIntervalMs` and an injectable sleep.
|
|
214
|
+
*
|
|
215
|
+
* Never throws. Returns a structured `WaitForFeedbackResult`.
|
|
216
|
+
*/
|
|
217
|
+
export async function waitForFeedback(
|
|
218
|
+
deps: WaitForFeedbackDeps,
|
|
219
|
+
args: WaitForFeedbackArgs,
|
|
220
|
+
): Promise<WaitForFeedbackResult> {
|
|
221
|
+
const start = (deps.now ?? Date.now)();
|
|
222
|
+
const now = deps.now ?? Date.now;
|
|
223
|
+
const sleep = deps.sleep ?? defaultSleep;
|
|
224
|
+
const pollInterval = deps.pollIntervalMs ?? POLL_INTERVAL_MS;
|
|
225
|
+
|
|
226
|
+
if (!SLUG_REGEX.test(args.planSlug)) {
|
|
227
|
+
return {
|
|
228
|
+
ok: false,
|
|
229
|
+
status: "error",
|
|
230
|
+
planSlug: args.planSlug,
|
|
231
|
+
error: `Invalid planSlug: "${args.planSlug}". Must match ^[a-z0-9][a-z0-9-]{0,63}$.`,
|
|
232
|
+
waitedMs: 0,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const timeoutMs = clampTimeout(args.timeoutMs);
|
|
237
|
+
const planDir = join(deps.worktree, "plans", args.planSlug);
|
|
238
|
+
const planPath = join(planDir, "plan.json");
|
|
239
|
+
const metaPath = join(planDir, "meta.json");
|
|
240
|
+
|
|
241
|
+
// If the plan doesn't even exist, that's an error (the agent shouldn't
|
|
242
|
+
// wait for feedback on a nonexistent plan).
|
|
243
|
+
if (!existsSync(planPath) && !existsSync(metaPath)) {
|
|
244
|
+
return {
|
|
245
|
+
ok: false,
|
|
246
|
+
status: "error",
|
|
247
|
+
planSlug: args.planSlug,
|
|
248
|
+
error: `Plan not found: ${args.planSlug}`,
|
|
249
|
+
waitedMs: 0,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Tick: read both files, evaluate exit conditions.
|
|
254
|
+
// Returns null when no exit condition was met; returns the final
|
|
255
|
+
// result when one was met.
|
|
256
|
+
async function tick(): Promise<WaitForFeedbackResult | null> {
|
|
257
|
+
const meta = readMeta(metaPath);
|
|
258
|
+
const canvas = readCanvas(planPath);
|
|
259
|
+
const status = normalizeStatus(meta?.status);
|
|
260
|
+
|
|
261
|
+
// Status-driven exit (approved / rejected)
|
|
262
|
+
if (status === "approved") {
|
|
263
|
+
return {
|
|
264
|
+
ok: true,
|
|
265
|
+
status: "approved",
|
|
266
|
+
planSlug: args.planSlug,
|
|
267
|
+
planStatus: status,
|
|
268
|
+
newComments: [],
|
|
269
|
+
waitedMs: now() - start,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
if (status === "rejected") {
|
|
273
|
+
return {
|
|
274
|
+
ok: true,
|
|
275
|
+
status: "rejected",
|
|
276
|
+
planSlug: args.planSlug,
|
|
277
|
+
planStatus: status,
|
|
278
|
+
newComments: [],
|
|
279
|
+
waitedMs: now() - start,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Comment-driven exit
|
|
284
|
+
if (canvas !== null) {
|
|
285
|
+
const all = Array.isArray(canvas.comments) ? canvas.comments : [];
|
|
286
|
+
const newOnes = sortByCreated(filterNewComments(all, args.sinceTimestamp));
|
|
287
|
+
if (newOnes.length > 0) {
|
|
288
|
+
return {
|
|
289
|
+
ok: true,
|
|
290
|
+
status: "feedback_received",
|
|
291
|
+
planSlug: args.planSlug,
|
|
292
|
+
planStatus: status,
|
|
293
|
+
newComments: newOnes,
|
|
294
|
+
waitedMs: now() - start,
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// First tick — gives us immediate feedback if it's already there.
|
|
303
|
+
const first = await tick();
|
|
304
|
+
if (first !== null) return first;
|
|
305
|
+
|
|
306
|
+
// Loop with `setTimeout`, NOT a busy loop. We use a `deadline` so the
|
|
307
|
+
// final sleep doesn't overshoot the timeout by much.
|
|
308
|
+
const deadline = start + timeoutMs;
|
|
309
|
+
while (now() < deadline) {
|
|
310
|
+
const remaining = deadline - now();
|
|
311
|
+
const waitMs = Math.max(0, Math.min(pollInterval, remaining));
|
|
312
|
+
if (waitMs === 0) break;
|
|
313
|
+
await sleep(waitMs);
|
|
314
|
+
if (now() >= deadline) break;
|
|
315
|
+
|
|
316
|
+
const result = await tick();
|
|
317
|
+
if (result !== null) return result;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// Timed out — return the current state with the timeout flag.
|
|
321
|
+
const finalMeta = readMeta(metaPath);
|
|
322
|
+
const finalStatus = normalizeStatus(finalMeta?.status);
|
|
323
|
+
const finalCanvas = readCanvas(planPath);
|
|
324
|
+
const finalComments = sortByCreated(
|
|
325
|
+
filterNewComments(
|
|
326
|
+
Array.isArray(finalCanvas?.comments) ? (finalCanvas!.comments as PlanComment[]) : [],
|
|
327
|
+
args.sinceTimestamp,
|
|
328
|
+
),
|
|
329
|
+
);
|
|
330
|
+
return {
|
|
331
|
+
ok: true,
|
|
332
|
+
status: "timed_out",
|
|
333
|
+
planSlug: args.planSlug,
|
|
334
|
+
planStatus: finalStatus,
|
|
335
|
+
newComments: finalComments,
|
|
336
|
+
waitedMs: now() - start,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// --- Zod schema + tool factory ------------------------------------------
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Build the `bizar_wait_for_feedback` tool. The plugin wires the result
|
|
344
|
+
* into `Hooks.tool`. The `deps` closure carries the worktree and logger.
|
|
345
|
+
*/
|
|
346
|
+
export function createWaitForFeedbackTool(deps: WaitForFeedbackDeps) {
|
|
347
|
+
return tool({
|
|
348
|
+
description:
|
|
349
|
+
"Block until the user provides feedback on a plan, approves it, " +
|
|
350
|
+
"rejects it, or the timeout is reached. Polls every 2 seconds. " +
|
|
351
|
+
"Use this after calling `bizar_plan_action` to add a comment or " +
|
|
352
|
+
"present the plan for approval. Returns when feedback arrives, " +
|
|
353
|
+
"when meta.json.status changes to approved/rejected, or on timeout. " +
|
|
354
|
+
"Never throws. Available to all agents (heavy poll — Odin preferred).",
|
|
355
|
+
args: {
|
|
356
|
+
planSlug: z
|
|
357
|
+
.string()
|
|
358
|
+
.min(1)
|
|
359
|
+
.max(64)
|
|
360
|
+
.regex(/^[a-z0-9][a-z0-9-]{0,63}$/, "Must match ^[a-z0-9][a-z0-9-]{0,63}$")
|
|
361
|
+
.describe("The plan's slug (e.g. 'my-feature')."),
|
|
362
|
+
timeoutMs: z
|
|
363
|
+
.number()
|
|
364
|
+
.int()
|
|
365
|
+
.positive()
|
|
366
|
+
.min(TIMEOUT_MIN_MS)
|
|
367
|
+
.max(TIMEOUT_MAX_MS)
|
|
368
|
+
.optional()
|
|
369
|
+
.describe(
|
|
370
|
+
`How long to wait, in milliseconds. Default ${TIMEOUT_DEFAULT_MS} (10 min). ` +
|
|
371
|
+
`Range [${TIMEOUT_MIN_MS}, ${TIMEOUT_MAX_MS}] (5 s..30 min).`,
|
|
372
|
+
),
|
|
373
|
+
sinceTimestamp: z
|
|
374
|
+
.string()
|
|
375
|
+
.optional()
|
|
376
|
+
.describe(
|
|
377
|
+
"Optional ISO timestamp. Only comments with `created` strictly " +
|
|
378
|
+
"after this value count as feedback. If omitted, the first poll " +
|
|
379
|
+
"returns any existing non-empty comment set as feedback.",
|
|
380
|
+
),
|
|
381
|
+
},
|
|
382
|
+
execute: async (rawArgs) => {
|
|
383
|
+
const args = rawArgs as WaitForFeedbackArgs;
|
|
384
|
+
try {
|
|
385
|
+
const result = await waitForFeedback(deps, args);
|
|
386
|
+
return { output: JSON.stringify(result) };
|
|
387
|
+
} catch (err: unknown) {
|
|
388
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
389
|
+
deps.logger.warn(`bizar: wait_for_feedback crashed: ${msg}`);
|
|
390
|
+
return {
|
|
391
|
+
output: JSON.stringify({
|
|
392
|
+
ok: false,
|
|
393
|
+
status: "error",
|
|
394
|
+
planSlug: args.planSlug,
|
|
395
|
+
error: `Internal error: ${msg}`,
|
|
396
|
+
waitedMs: 0,
|
|
397
|
+
}),
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
},
|
|
401
|
+
});
|
|
402
|
+
}
|