@openchambery/web 1.19.22-beta.1 → 2.0.0-beta.10
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 +13 -7
- package/bin/cli-opencode.test.js +208 -0
- package/bin/cli.js +62 -9
- package/bin/lib/cli-startup.js +105 -2
- package/bin/lib/cli-startup.test.js +179 -0
- package/dist/assets/{AgentAvatar-CRaBJXKs.js → AgentAvatar-CzTtVMnI.js} +1 -1
- package/dist/assets/AssistantView-Cg1qQvVe.js +3 -0
- package/dist/assets/{DiagramView-D1LGK_s2.js → DiagramView-hOi72Wdx.js} +1 -1
- package/dist/assets/{FadeInOnReveal-B0kJo9Ii.js → FadeInOnReveal-DCqrQkkz.js} +1 -1
- package/dist/assets/Icon-B8fSTLdP.js +1 -0
- package/dist/assets/MarkdownRenderer-Cw74oVxV.js +2 -0
- package/dist/assets/{MarkdownRendererImpl-DfoCJ1Mq.js → MarkdownRendererImpl-YM7iRmzK.js} +3 -3
- package/dist/assets/MarkstreamRendererImpl-BDy_oGJQ.js +3 -0
- package/dist/assets/MobileDetailNavigation-iX_hb_Xt.js +1 -0
- package/dist/assets/{MobileShareBridge-2Yjn6wXg.js → MobileShareBridge-CAMUupwR.js} +2 -2
- package/dist/assets/MobileSurface-CHbdPcLH.js +2 -0
- package/dist/assets/{MultiRunWindow-tTbMFowS.js → MultiRunWindow-Ci1ODFFX.js} +1 -1
- package/dist/assets/{OnboardingScreen-CD2KtlF3.js → OnboardingScreen-O4cGdz5p.js} +1 -1
- package/dist/assets/OverlayScrollbar-CRfGtcmG.js +2 -0
- package/dist/assets/SettingsView-Dg8BtTV1.js +25 -0
- package/dist/assets/{SettingsWindow-zIa76s4t.js → SettingsWindow-B8d8qIQ7.js} +1 -1
- package/dist/assets/TerminalView-CMiw3s_c.js +8 -0
- package/dist/assets/{ToolOutputDialog-DNqA4uBl.js → ToolOutputDialog-ByaQYRTp.js} +2 -2
- package/dist/assets/appThemeRegistry-BGGHio8T.js +1 -0
- package/dist/assets/{assistant-attachment-cache-C0aRnFkj.js → assistant-attachment-cache-DphJleHr.js} +1 -1
- package/dist/assets/{button-CI7Q-Zw_.js → button-DIIrsMjW.js} +1 -1
- package/dist/assets/{collapsible-D5Phaykh.js → collapsible-CnvUeYst.js} +1 -1
- package/dist/assets/{context-menu-CubSDW2g.js → context-menu-BGBUpZEQ.js} +1 -1
- package/dist/assets/{desktopHosts-B1ixEylr.js → desktopHosts-JGFqhlaM.js} +1 -1
- package/dist/assets/{desktopRelayRestore-4JmFUw8r.js → desktopRelayRestore-CHEwrI93.js} +1 -1
- package/dist/assets/{diagram-DdLO8HZ9.js → diagram-rvn7_qBM.js} +1 -1
- package/dist/assets/{dialog-B6pnIYmp.js → dialog-CQ63sc9E.js} +1 -1
- package/dist/assets/es-Dsmc0A_3.js +15 -0
- package/dist/assets/fileMentionTouchSelection-BzzcWJCi.js +3 -0
- package/dist/assets/{fileQueries-DQc8EJUf.js → fileQueries-DN6gbLhM.js} +1 -1
- package/dist/assets/fr-C_ZlZDI2.js +13 -0
- package/dist/assets/gitApi-BF8vuoZc.js +10 -0
- package/dist/assets/{imageSource-BlAJJUEI.js → imageSource-BMztRu0c.js} +1 -1
- package/dist/assets/{input-D-__fwRi.js → input-BVu-iykl.js} +1 -1
- package/dist/assets/insertionBoundaries-EcAfGT2D.js +1 -0
- package/dist/assets/ja-BqqTaWTi.js +15 -0
- package/dist/assets/ko-DP2XPM37.js +15 -0
- package/dist/assets/main-B7t9lavz.js +2 -0
- package/dist/assets/main-D2BzpnUt.css +1 -0
- package/dist/assets/main-DWP-prNB.js +169 -0
- package/dist/assets/markdown-worker-bS5OgGO3.js +2 -0
- package/dist/assets/{markdownHeightCache-BhxqJOvf.js → markdownHeightCache-D9-B1wdY.js} +1 -1
- package/dist/assets/markdownTheme-DM5h1i18.js +1 -0
- package/dist/assets/mcpQueries-CfXrAkuU.js +1 -0
- package/dist/assets/miniChat-DgOrEQbN.js +2 -0
- package/dist/assets/mobile-Co_ZOHkZ.js +2 -0
- package/dist/assets/multirun-DelyUO6k.js +4 -0
- package/dist/assets/persistence-D0y7226-.js +3 -0
- package/dist/assets/pl-BCf5uLlK.js +15 -0
- package/dist/assets/platform-CurqO28D.js +6 -0
- package/dist/assets/{projectMeta-S1hJ7oBp.js → projectMeta-CPElzJ0n.js} +2 -2
- package/dist/assets/pt-BR-W09Q2pvn.js +15 -0
- package/dist/assets/{relay-image-stream-DM7atqJs.js → relay-image-stream-DrdVj99c.js} +1 -1
- package/dist/assets/renderElectronMiniChatApp-pOE93w86.js +2 -0
- package/dist/assets/renderMobileApp-F7ZSLcw8.js +28 -0
- package/dist/assets/runtime-fetch-Fs9ZV2V8.js +1 -0
- package/dist/assets/{runtimeConfig-CMkwoQ_X.js → runtimeConfig-DSS0KxG3.js} +1 -1
- package/dist/assets/runtimeEndpointReset-x2Wgx57R.js +149 -0
- package/dist/assets/sessionChangeSummary-BUGSYcHp.js +2 -0
- package/dist/assets/{sessionLookup-BrU3rFHJ.js → sessionLookup-Bss8M20i.js} +1 -1
- package/dist/assets/{sortable-tabs-strip-Fnfhf3K9.js → sortable-tabs-strip-CE7W7lJ9.js} +1 -1
- package/dist/assets/src-lS1keDVV.css +2 -0
- package/dist/assets/store-jaP79mqI.js +15 -0
- package/dist/assets/{terminalApi-xjqssKke.js → terminalApi-mDR2jXTo.js} +1 -1
- package/dist/assets/textarea-XD2oX_Ee.js +1 -0
- package/dist/assets/{tooltip-0T5jv0cu.js → tooltip-DYeQ_Hvy.js} +1 -1
- package/dist/assets/uk-BgFzz8m2.js +15 -0
- package/dist/assets/{url-_z7evzdK.js → url-CGbJbiJq.js} +1 -1
- package/dist/assets/{useAppFontEffects-C02YFyAv.js → useAppFontEffects-BAWHZ-t0.js} +64 -45
- package/dist/assets/{useAssistantUIStore-CMutVh9B.js → useAssistantUIStore-Bz4tRflF.js} +1 -1
- package/dist/assets/useDesktopWindowControlsLayout-hN_nLb7T.js +1 -0
- package/dist/assets/useEffectiveDirectory-Do9DQ453.js +1 -0
- package/dist/assets/{useFontPreferences-B1JYyzpK.js → useFontPreferences-Bjx8zkGM.js} +1 -1
- package/dist/assets/useMobileNavigationStore-BsY_gi_K.js +414 -0
- package/dist/assets/useSessionAutoCleanup-C4g5KmDf.js +2 -0
- package/dist/assets/useUIStore-syVmbuDA.js +1 -0
- package/dist/assets/{useWorkerHighlightedLines-C9z0ML1z.js → useWorkerHighlightedLines-B5QXxBok.js} +2 -2
- package/dist/assets/vendor-opencode-client-C12gfjag.js +12 -0
- package/dist/assets/{vendor-reactuses-core-BnW6GxJt.js → vendor-reactuses-core-Dq5ocTF8.js} +1 -1
- package/dist/assets/{vendor-yaml-DIcAK3EC.js → vendor-yaml-C9KlJAlj.js} +37 -37
- package/dist/assets/zh-CN-BhqSLgUY.js +15 -0
- package/dist/assets/zh-TW-BsaBgY-p.js +15 -0
- package/dist/index.html +12 -12
- package/dist/mini-chat.html +12 -12
- package/dist/mobile.html +12 -12
- package/package.json +3 -2
- package/server/index.js +423 -20
- package/server/lib/assistants/DOCUMENTATION.md +26 -21
- package/server/lib/assistants/assign.js +2 -1
- package/server/lib/assistants/contact-store.js +37 -19
- package/server/lib/assistants/contracts.js +11 -1
- package/server/lib/assistants/projection-history.test.js +454 -0
- package/server/lib/assistants/routes.js +11 -5
- package/server/lib/assistants/service.js +850 -294
- package/server/lib/assistants/service.test.js +588 -274
- package/server/lib/browser-provider/DOCUMENTATION.md +141 -0
- package/server/lib/browser-provider/contract.js +312 -0
- package/server/lib/browser-provider/host.js +421 -0
- package/server/lib/browser-provider/host.test.js +304 -0
- package/server/lib/browser-provider/routes.js +122 -0
- package/server/lib/browser-provider/routes.test.js +120 -0
- package/server/lib/browser-provider/selection-store.js +43 -0
- package/server/lib/browser-provider/selection-store.test.js +35 -0
- package/server/lib/conversations/DOCUMENTATION.md +5 -5
- package/server/lib/conversations/service.js +87 -57
- package/server/lib/conversations/service.test.js +132 -100
- package/server/lib/conversations/validation.js +11 -1
- package/server/lib/event-stream/DOCUMENTATION.md +3 -1
- package/server/lib/event-stream/directory-ws-bridge.js +13 -2
- package/server/lib/event-stream/global-hub.js +51 -5
- package/server/lib/event-stream/reasoning-projection.js +16 -1
- package/server/lib/event-stream/reasoning-projection.test.js +15 -0
- package/server/lib/event-stream/runtime.js +57 -20
- package/server/lib/event-stream/runtime.test.js +112 -0
- package/server/lib/llm/DOCUMENTATION.md +95 -84
- package/server/lib/llm/catalog.js +111 -45
- package/server/lib/llm/catalog.test.js +121 -59
- package/server/lib/llm/completions.js +41 -12
- package/server/lib/llm/completions.test.js +45 -4
- package/server/lib/llm/generate.js +516 -453
- package/server/lib/llm/generate.test.js +705 -484
- package/server/lib/llm/routes.js +8 -4
- package/server/lib/message-queue/DOCUMENTATION.md +5 -5
- package/server/lib/message-queue/opencode-adapter.js +191 -104
- package/server/lib/message-queue/opencode-adapter.test.js +328 -58
- package/server/lib/message-queue/runtime.js +15 -2
- package/server/lib/message-queue/runtime.test.js +6 -6
- package/server/lib/message-queue/worker.js +7 -1
- package/server/lib/notifications/DOCUMENTATION.md +3 -1
- package/server/lib/notifications/runtime.js +133 -31
- package/server/lib/notifications/runtime.test.js +103 -0
- package/server/lib/notifications/template-runtime.js +130 -38
- package/server/lib/notifications/template-runtime.test.js +96 -0
- package/server/lib/opencode/DOCUMENTATION.md +111 -16
- package/server/lib/opencode/agent-document.d.ts +28 -0
- package/server/lib/opencode/agent-document.js +280 -0
- package/server/lib/opencode/agent-document.test.js +137 -0
- package/server/lib/opencode/agents.js +96 -0
- package/server/lib/opencode/auth-state-runtime.js +5 -0
- package/server/lib/opencode/bootstrap-runtime.js +2 -0
- package/server/lib/opencode/config-entity-routes.js +117 -103
- package/server/lib/opencode/config-entity-routes.test.js +148 -10
- package/server/lib/opencode/config-hot-reload.integration.test.js +105 -0
- package/server/lib/opencode/ensure-cli.d.ts +8 -0
- package/server/lib/opencode/ensure-cli.js +238 -0
- package/server/lib/opencode/ensure-cli.test.js +119 -0
- package/server/lib/opencode/env-runtime.js +208 -111
- package/server/lib/opencode/env-runtime.test.js +211 -14
- package/server/lib/opencode/feature-routes-runtime.js +90 -5
- package/server/lib/opencode/feature-routes-runtime.test.js +25 -0
- package/server/lib/opencode/http-server-connections.js +98 -0
- package/server/lib/opencode/http-server-connections.test.js +321 -0
- package/server/lib/opencode/lifecycle.js +539 -95
- package/server/lib/opencode/lifecycle.test.js +698 -6
- package/server/lib/opencode/managed-capabilities-runtime.js +15 -2
- package/server/lib/opencode/managed-capabilities-runtime.test.js +1 -0
- package/server/lib/opencode/network-runtime.js +28 -16
- package/server/lib/opencode/network-runtime.test.js +68 -4
- package/server/lib/opencode/openchamber-routes.js +7 -1
- package/server/lib/opencode/opencode2-pin.js +139 -0
- package/server/lib/opencode/opencode2-pin.test.js +88 -0
- package/server/lib/opencode/opencode2-sidecar.e2e.test.js +326 -0
- package/server/lib/opencode/owned-runtime-upgrade.js +431 -0
- package/server/lib/opencode/owned-runtime-upgrade.test.js +160 -0
- package/server/lib/opencode/plugin-compatibility.js +15 -0
- package/server/lib/opencode/plugin-compatibility.test.js +21 -0
- package/server/lib/opencode/plugin-routes.js +3 -18
- package/server/lib/opencode/plugin-routes.test.js +9 -9
- package/server/lib/opencode/plugins.js +4 -3
- package/server/lib/opencode/plugins.test.js +12 -0
- package/server/lib/opencode/provider-catalog.js +58 -12
- package/server/lib/opencode/provider-catalog.test.js +48 -0
- package/server/lib/opencode/proxy.js +373 -28
- package/server/lib/opencode/proxy.test.js +353 -0
- package/server/lib/opencode/routes.js +333 -76
- package/server/lib/opencode/routes.test.js +315 -50
- package/server/lib/opencode/runtime-contract.js +401 -0
- package/server/lib/opencode/runtime-contract.test.js +214 -0
- package/server/lib/opencode/server-opencode-fetch.js +242 -0
- package/server/lib/opencode/server-opencode-fetch.test.js +130 -0
- package/server/lib/opencode/server-utils-runtime.js +35 -0
- package/server/lib/opencode/shared-service.integration.test.js +66 -0
- package/server/lib/opencode/shared-service.js +147 -0
- package/server/lib/opencode/shared-service.test.js +93 -0
- package/server/lib/opencode/shared.js +3 -3
- package/server/lib/opencode/shutdown-runtime.js +15 -6
- package/server/lib/opencode/shutdown-runtime.test.js +49 -1
- package/server/lib/opencode/skill-routes.js +26 -40
- package/server/lib/opencode/skill-routes.test.js +71 -7
- package/server/lib/opencode/skills.test.js +15 -0
- package/server/lib/opencode/startup-pipeline-runtime.js +4 -0
- package/server/lib/opencode/static-routes-runtime.js +3 -1
- package/server/lib/opencode/static-routes-runtime.test.js +33 -0
- package/server/lib/opencode/upgrade-screen.d.ts +30 -0
- package/server/lib/opencode/upgrade-screen.js +299 -0
- package/server/lib/opencode/upgrade-screen.test.js +196 -0
- package/server/lib/opencode/v1-migration-gate.js +157 -0
- package/server/lib/opencode/v1-migration-gate.test.js +111 -0
- package/server/lib/opencode/v2-client.js +60 -0
- package/server/lib/opencode/v2-plugin-host-shim/index.mjs +155 -0
- package/server/lib/opencode/v2-plugin-host-shim/package.json +4 -0
- package/server/lib/opencode/watcher.js +2 -1
- package/server/lib/opencode/watcher.test.js +1 -1
- package/server/lib/permission-auto-accept/DOCUMENTATION.md +5 -5
- package/server/lib/permission-auto-accept/runtime.js +14 -7
- package/server/lib/permission-auto-accept/runtime.test.js +27 -12
- package/server/lib/relay/reasoning-projection.e2e.test.ts +22 -7
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +79 -39
- package/server/lib/scheduled-tasks/managed-tool-route.js +31 -1
- package/server/lib/scheduled-tasks/managed-tool-route.test.js +23 -0
- package/server/lib/scheduled-tasks/routes.js +27 -0
- package/server/lib/scheduled-tasks/routes.test.js +94 -0
- package/server/lib/scheduled-tasks/runtime.js +381 -310
- package/server/lib/scheduled-tasks/runtime.test.js +600 -309
- package/server/lib/session-goal/DOCUMENTATION.md +173 -22
- package/server/lib/session-goal/capability.js +57 -0
- package/server/lib/session-goal/capability.test.js +33 -0
- package/server/lib/session-goal/routes.js +240 -2
- package/server/lib/session-goal/routes.test.js +211 -0
- package/server/lib/session-goal/runtime.js +1617 -113
- package/server/lib/session-goal/runtime.test.js +1500 -70
- package/server/lib/session-index/DOCUMENTATION.md +18 -15
- package/server/lib/session-index/event-ingest.js +89 -16
- package/server/lib/session-index/event-ingest.test.js +73 -0
- package/server/lib/session-index/host-authority-snapshot.js +92 -0
- package/server/lib/session-index/routes.host-archive.test.js +201 -0
- package/server/lib/session-index/routes.js +63 -10
- package/server/lib/session-index/routes.test.js +8 -8
- package/server/lib/session-index/service.js +7 -1
- package/server/lib/session-index/sync-runtime.js +171 -41
- package/server/lib/session-index/sync-runtime.test.js +164 -9
- package/server/lib/session-metadata/DOCUMENTATION.md +96 -0
- package/server/lib/session-metadata/opencode-session-record.d.ts +57 -0
- package/server/lib/session-metadata/opencode-session-record.js +316 -0
- package/server/lib/session-metadata/opencode-session-record.test.js +242 -0
- package/server/lib/session-metadata/routes.js +197 -0
- package/server/lib/session-metadata/routes.test.js +156 -0
- package/server/lib/session-metadata/session-archive.d.ts +73 -0
- package/server/lib/session-metadata/session-archive.js +654 -0
- package/server/lib/session-metadata/session-archive.test.js +359 -0
- package/server/lib/session-metadata/session-metadata-store.d.ts +38 -0
- package/server/lib/session-metadata/session-metadata-store.js +422 -0
- package/server/lib/session-metadata/session-metadata-store.test.js +379 -0
- package/server/lib/session-metadata/session-projection.d.ts +41 -0
- package/server/lib/session-metadata/session-projection.js +279 -0
- package/server/lib/session-metadata/session-projection.test.js +64 -0
- package/server/lib/session-metadata/system-session.js +55 -0
- package/server/lib/session-metadata/system-session.test.js +55 -0
- package/server/lib/session-title/DOCUMENTATION.md +40 -7
- package/server/lib/session-title/native-runtime.test.js +167 -0
- package/server/lib/session-title/runtime.js +69 -44
- package/server/lib/session-title/session-access.js +46 -0
- package/server/lib/session-title/session-access.test.js +91 -0
- package/server/lib/session-turn-pages/DOCUMENTATION.md +12 -11
- package/server/lib/session-turn-pages/reconcile.service.js +1 -1
- package/server/lib/session-turn-pages/reconcile.service.test.js +16 -0
- package/server/lib/session-turn-pages/routes.js +123 -75
- package/server/lib/session-turn-pages/routes.test.js +566 -0
- package/server/lib/session-turn-pages/service.js +6 -2
- package/server/lib/session-turn-pages/service.test.js +34 -0
- package/server/lib/session-turn-pages/session-message-projection.d.ts +13 -0
- package/server/lib/session-turn-pages/session-message-projection.js +281 -0
- package/server/lib/small-model/DOCUMENTATION.md +101 -146
- package/server/lib/small-model/catalog.js +84 -54
- package/server/lib/small-model/catalog.test.js +111 -9
- package/server/lib/small-model/custom-api.js +68 -0
- package/server/lib/small-model/custom-api.test.js +64 -0
- package/server/lib/small-model/index.js +125 -241
- package/server/lib/small-model/resolve.js +35 -120
- package/server/lib/small-model/resolve.test.js +20 -110
- package/server/lib/small-model/routes.js +1 -3
- package/server/lib/small-model/summary-settings.test.js +157 -253
- package/server/opencode-proxy.test.js +63 -12
- package/dist/assets/AssistantView-BUveAgc4.js +0 -3
- package/dist/assets/Icon-BgdfPhNs.js +0 -1
- package/dist/assets/MarkdownRenderer-BbrbDH6-.js +0 -2
- package/dist/assets/MarkstreamRendererImpl-D2dsW5Lg.js +0 -3
- package/dist/assets/MobileDetailNavigation-B0aqKXd7.js +0 -1
- package/dist/assets/MobileSurface-DW7WfPsy.js +0 -2
- package/dist/assets/OverlayScrollbar-DrA0Vsg5.js +0 -2
- package/dist/assets/SettingsView-PkXIavr7.js +0 -25
- package/dist/assets/TerminalView-CDdzF4yi.js +0 -8
- package/dist/assets/appThemeRegistry-D5Yxg4YF.js +0 -1
- package/dist/assets/es-DA3MqOo0.js +0 -15
- package/dist/assets/fileMentionTouchSelection-DNeiqns-.js +0 -4
- package/dist/assets/fr-Dbz0CdIA.js +0 -13
- package/dist/assets/gitApi-DXyC4MiV.js +0 -7
- package/dist/assets/insertionBoundaries-KlOVrHHt.js +0 -1
- package/dist/assets/ja-DumanVQA.js +0 -15
- package/dist/assets/ko-C0IkiUjQ.js +0 -15
- package/dist/assets/main-BPS5ylib.js +0 -2
- package/dist/assets/main-Cpd9VWYs.js +0 -169
- package/dist/assets/main-qSeeJRW1.css +0 -1
- package/dist/assets/markdown-worker-CptoICmq.js +0 -2
- package/dist/assets/markdownTheme-DOfGg-A7.js +0 -1
- package/dist/assets/miniChat-B8_KLWiY.js +0 -2
- package/dist/assets/mobile-CtktKrXn.js +0 -2
- package/dist/assets/multirun-CYfP9Cfm.js +0 -4
- package/dist/assets/persistence-Ce3AnpEr.js +0 -3
- package/dist/assets/pl-B9No6MQp.js +0 -15
- package/dist/assets/platform-0w_Q9_ji.js +0 -2
- package/dist/assets/pt-BR-DyQ0WTDh.js +0 -15
- package/dist/assets/renderElectronMiniChatApp-iK14LWm8.js +0 -2
- package/dist/assets/renderMobileApp-DORLPWnb.js +0 -28
- package/dist/assets/runtime-fetch-zIalUnbb.js +0 -1
- package/dist/assets/runtimeEndpointReset-ChOxt-J7.js +0 -147
- package/dist/assets/sessionChangeSummary-NnxcqCTI.js +0 -2
- package/dist/assets/src-rS3zCcsC.css +0 -2
- package/dist/assets/store-5B_LDnLM.js +0 -15
- package/dist/assets/textarea-bHYxZtfH.js +0 -1
- package/dist/assets/uk-C_1KkqyP.js +0 -15
- package/dist/assets/useDesktopWindowControlsLayout-Dnr-jX0C.js +0 -1
- package/dist/assets/useEffectiveDirectory-CZLLyarc.js +0 -1
- package/dist/assets/useMobileNavigationStore-CoCiqNgm.js +0 -413
- package/dist/assets/useSessionAutoCleanup-xQyETQkG.js +0 -2
- package/dist/assets/useUIStore-Bxv3f23A.js +0 -1
- package/dist/assets/vendor-opencode-sdk-C07HQypa.js +0 -7
- package/dist/assets/zh-CN-uWILgBdt.js +0 -15
- package/dist/assets/zh-TW-MYfdvhbD.js +0 -15
- package/server/lib/small-model/call.js +0 -427
- package/server/lib/small-model/call.test.js +0 -382
- package/server/lib/small-model/opencode-session.js +0 -339
- package/server/lib/small-model/opencode-session.test.js +0 -177
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode v2 agent markdown.
|
|
3
|
+
*
|
|
4
|
+
* A file is native only when every frontmatter key is a current agent field.
|
|
5
|
+
* Any older key makes the loader migrate the whole file, and native keys in
|
|
6
|
+
* that file are then treated as request body. Saving therefore rewrites the
|
|
7
|
+
* whole file as native markdown. Fields the runtime does not apply are reported
|
|
8
|
+
* and kept until the caller confirms they can be dropped.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const NATIVE_KEYS = new Set([
|
|
12
|
+
'model',
|
|
13
|
+
'variant',
|
|
14
|
+
'request',
|
|
15
|
+
'system',
|
|
16
|
+
'description',
|
|
17
|
+
'mode',
|
|
18
|
+
'hidden',
|
|
19
|
+
'color',
|
|
20
|
+
'steps',
|
|
21
|
+
'disabled',
|
|
22
|
+
'permissions',
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
const ACTION_RENAMES = {
|
|
26
|
+
bash: 'shell',
|
|
27
|
+
task: 'subagent',
|
|
28
|
+
write: 'edit',
|
|
29
|
+
patch: 'edit',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const HEX_COLOR = /^#[0-9a-fA-F]{6}$/;
|
|
33
|
+
const PROMPT_FILE = /^\{file:.+\}$/i;
|
|
34
|
+
const EFFECTS = new Set(['allow', 'ask', 'deny']);
|
|
35
|
+
|
|
36
|
+
export class DropConfirmationRequired extends Error {
|
|
37
|
+
/**
|
|
38
|
+
* @param {Array<{ key: string, reason: string }>} dropped
|
|
39
|
+
*/
|
|
40
|
+
constructor(dropped) {
|
|
41
|
+
super('Drop confirmation required');
|
|
42
|
+
this.code = 'drop-confirmation';
|
|
43
|
+
this.dropped = dropped;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const isEffect = (value) => typeof value === 'string' && EFFECTS.has(value);
|
|
48
|
+
|
|
49
|
+
const renameAction = (action) => ACTION_RENAMES[action] || action;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {unknown} config
|
|
53
|
+
* @returns {{ legacy: boolean, dropped: Array<{ key: string, reason: string }> }}
|
|
54
|
+
*/
|
|
55
|
+
export function inspectAgentConfig(config) {
|
|
56
|
+
const source = config && typeof config === 'object' && !Array.isArray(config) ? config : {};
|
|
57
|
+
/** @type {Array<{ key: string, reason: string }>} */
|
|
58
|
+
const dropped = [];
|
|
59
|
+
const keys = Object.keys(source);
|
|
60
|
+
|
|
61
|
+
for (const key of keys) {
|
|
62
|
+
if (key === 'temperature' || key === 'top_p') {
|
|
63
|
+
dropped.push({ key, reason: 'generation' });
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (key === 'options' && source.options && typeof source.options === 'object' && Object.keys(source.options).length > 0) {
|
|
67
|
+
dropped.push({ key, reason: 'unknown' });
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (key === 'prompt' && typeof source.prompt === 'string' && PROMPT_FILE.test(source.prompt.trim())) {
|
|
71
|
+
dropped.push({ key, reason: 'prompt-file' });
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (key === 'color' && source.color != null && source.color !== '' && !HEX_COLOR.test(String(source.color))) {
|
|
75
|
+
dropped.push({ key, reason: 'color' });
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (key === 'variant' && (typeof source.model !== 'string' || source.model.length === 0)) {
|
|
79
|
+
dropped.push({ key, reason: 'variant' });
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (!NATIVE_KEYS.has(key) && !isConvertibleKey(key)) {
|
|
83
|
+
dropped.push({ key, reason: 'unknown' });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const legacy = keys.some((key) => !NATIVE_KEYS.has(key)) || dropped.length > 0;
|
|
88
|
+
return { legacy, dropped };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const isConvertibleKey = (key) => (
|
|
92
|
+
key === 'prompt'
|
|
93
|
+
|| key === 'tools'
|
|
94
|
+
|| key === 'disable'
|
|
95
|
+
|| key === 'maxSteps'
|
|
96
|
+
|| key === 'permission'
|
|
97
|
+
|| key === 'name'
|
|
98
|
+
|| key === 'options'
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @param {unknown} config
|
|
103
|
+
* @returns {{ frontmatter: Record<string, unknown>, body: string, legacy: boolean, dropped: Array<{ key: string, reason: string }> }}
|
|
104
|
+
*/
|
|
105
|
+
export function convertAgentConfig(config) {
|
|
106
|
+
const source = config && typeof config === 'object' && !Array.isArray(config) ? { ...config } : {};
|
|
107
|
+
const inspection = inspectAgentConfig(source);
|
|
108
|
+
/** @type {Record<string, unknown>} */
|
|
109
|
+
const frontmatter = {};
|
|
110
|
+
|
|
111
|
+
if (typeof source.description === 'string' && source.description.trim()) {
|
|
112
|
+
frontmatter.description = source.description;
|
|
113
|
+
}
|
|
114
|
+
if (source.mode === 'primary' || source.mode === 'subagent' || source.mode === 'all') {
|
|
115
|
+
frontmatter.mode = source.mode;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const model = encodeModel(source.model, source.variant);
|
|
119
|
+
if (model) frontmatter.model = model;
|
|
120
|
+
|
|
121
|
+
if (source.hidden === true) frontmatter.hidden = true;
|
|
122
|
+
if (source.disabled === true || source.disable === true) frontmatter.disabled = true;
|
|
123
|
+
if (typeof source.color === 'string' && HEX_COLOR.test(source.color)) frontmatter.color = source.color;
|
|
124
|
+
|
|
125
|
+
const steps = positiveInt(source.steps) ?? positiveInt(source.maxSteps);
|
|
126
|
+
if (steps !== undefined) frontmatter.steps = steps;
|
|
127
|
+
|
|
128
|
+
if (isRequest(source.request)) frontmatter.request = source.request;
|
|
129
|
+
|
|
130
|
+
const permissions = normalizePermissions(source.permissions ?? source.permission, source.tools);
|
|
131
|
+
if (permissions.length > 0) frontmatter.permissions = permissions;
|
|
132
|
+
|
|
133
|
+
const body = readSystem(source);
|
|
134
|
+
return { frontmatter, body, legacy: inspection.legacy, dropped: inspection.dropped };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* @param {{ frontmatter: Record<string, unknown>, body: string }} current
|
|
139
|
+
* @param {Record<string, unknown>} patch
|
|
140
|
+
*/
|
|
141
|
+
export function applyNativePatch(current, patch) {
|
|
142
|
+
const frontmatter = { ...current.frontmatter };
|
|
143
|
+
let body = current.body;
|
|
144
|
+
const changes = patch && typeof patch === 'object' ? patch : {};
|
|
145
|
+
for (const [key, value] of Object.entries(changes)) {
|
|
146
|
+
if (value === undefined || key === 'name' || key === 'scope' || key === 'confirmDrop') continue;
|
|
147
|
+
if (key === 'system') {
|
|
148
|
+
body = value === null ? '' : String(value);
|
|
149
|
+
delete frontmatter.system;
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (value === null || value === false && (key === 'hidden' || key === 'disabled')) {
|
|
153
|
+
delete frontmatter[key];
|
|
154
|
+
if (key === 'model') delete frontmatter.variant;
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (key === 'color' && (typeof value !== 'string' || !HEX_COLOR.test(value))) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (key === 'steps') {
|
|
161
|
+
const steps = positiveInt(value);
|
|
162
|
+
if (steps === undefined) delete frontmatter.steps;
|
|
163
|
+
else frontmatter.steps = steps;
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
if (key === 'permissions') {
|
|
167
|
+
const permissions = normalizePermissions(value, undefined);
|
|
168
|
+
delete frontmatter.permission;
|
|
169
|
+
if (permissions.length === 0) delete frontmatter.permissions;
|
|
170
|
+
else frontmatter.permissions = permissions;
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
if (key === 'model') delete frontmatter.variant;
|
|
174
|
+
frontmatter[key] = value;
|
|
175
|
+
}
|
|
176
|
+
return { frontmatter, body };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Write only the keys in `patch` onto the existing markdown document.
|
|
181
|
+
* `confirmDrop` removes fields the current format cannot represent.
|
|
182
|
+
* Unmentioned fields, including permissions, stay as they are.
|
|
183
|
+
*
|
|
184
|
+
* @param {{ frontmatter?: Record<string, unknown>, body?: string }} existing
|
|
185
|
+
* @param {Record<string, unknown>} patch
|
|
186
|
+
* @param {boolean} confirmDrop
|
|
187
|
+
*/
|
|
188
|
+
export function writeAgentDocument(existing, patch, confirmDrop) {
|
|
189
|
+
const frontmatter = { ...(existing?.frontmatter || {}) };
|
|
190
|
+
let body = typeof existing?.body === 'string' ? existing.body : '';
|
|
191
|
+
if (confirmDrop) {
|
|
192
|
+
const inspection = inspectAgentConfig({
|
|
193
|
+
...frontmatter,
|
|
194
|
+
...(body.trim() ? { prompt: body } : {}),
|
|
195
|
+
});
|
|
196
|
+
for (const item of inspection.dropped) {
|
|
197
|
+
if (item.key === 'prompt') {
|
|
198
|
+
body = '';
|
|
199
|
+
delete frontmatter.prompt;
|
|
200
|
+
} else {
|
|
201
|
+
delete frontmatter[item.key];
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return applyNativePatch({ frontmatter, body }, patch);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const encodeModel = (model, variant) => {
|
|
209
|
+
if (typeof model !== 'string') return undefined;
|
|
210
|
+
const trimmed = model.trim();
|
|
211
|
+
if (!trimmed) return undefined;
|
|
212
|
+
if (trimmed.includes('#')) return trimmed;
|
|
213
|
+
if (typeof variant === 'string' && variant.trim() && !variant.includes('#')) {
|
|
214
|
+
return `${trimmed}#${variant.trim()}`;
|
|
215
|
+
}
|
|
216
|
+
return trimmed;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const positiveInt = (value) => {
|
|
220
|
+
const number = typeof value === 'number' ? value : typeof value === 'string' && value.trim() ? Number(value) : NaN;
|
|
221
|
+
if (!Number.isInteger(number) || number < 1) return undefined;
|
|
222
|
+
return number;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
const isRequest = (value) => {
|
|
226
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
|
|
227
|
+
const request = /** @type {Record<string, unknown>} */ (value);
|
|
228
|
+
return request.headers != null || request.body != null;
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const readSystem = (source) => {
|
|
232
|
+
if (typeof source.system === 'string') return source.system;
|
|
233
|
+
if (typeof source.prompt === 'string' && !PROMPT_FILE.test(source.prompt.trim())) return source.prompt;
|
|
234
|
+
return '';
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const normalizePermissions = (permission, tools) => {
|
|
238
|
+
/** @type {Array<{ action: string, resource: string, effect: string }>} */
|
|
239
|
+
const rules = [];
|
|
240
|
+
if (tools && typeof tools === 'object' && !Array.isArray(tools)) {
|
|
241
|
+
for (const [tool, enabled] of Object.entries(tools)) {
|
|
242
|
+
if (typeof enabled !== 'boolean') continue;
|
|
243
|
+
pushRule(rules, renameAction(tool), '*', enabled ? 'allow' : 'deny');
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (isEffect(permission)) {
|
|
247
|
+
pushRule(rules, '*', '*', permission);
|
|
248
|
+
} else if (Array.isArray(permission)) {
|
|
249
|
+
for (const rule of permission) {
|
|
250
|
+
if (!rule || typeof rule !== 'object') continue;
|
|
251
|
+
if (typeof rule.permission === 'string' && typeof rule.pattern === 'string') {
|
|
252
|
+
pushRule(rules, renameAction(rule.permission), rule.pattern, rule.action);
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
pushRule(rules, renameAction(rule.action), rule.resource, rule.effect);
|
|
256
|
+
}
|
|
257
|
+
} else if (permission && typeof permission === 'object') {
|
|
258
|
+
for (const [key, rule] of Object.entries(permission)) {
|
|
259
|
+
const action = renameAction(key);
|
|
260
|
+
if (isEffect(rule)) {
|
|
261
|
+
pushRule(rules, action, '*', rule);
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
if (rule && typeof rule === 'object' && !Array.isArray(rule)) {
|
|
265
|
+
for (const [resource, effect] of Object.entries(rule)) {
|
|
266
|
+
pushRule(rules, action, resource, effect);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return rules;
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const pushRule = (rules, action, resource, effect) => {
|
|
275
|
+
if (!action || !resource || !isEffect(effect)) return;
|
|
276
|
+
const index = rules.findIndex((rule) => rule.action === action && rule.resource === resource);
|
|
277
|
+
const next = { action, resource, effect };
|
|
278
|
+
if (index >= 0) rules[index] = next;
|
|
279
|
+
else rules.push(next);
|
|
280
|
+
};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { applyNativePatch, convertAgentConfig, inspectAgentConfig, writeAgentDocument } from './agent-document.js';
|
|
4
|
+
|
|
5
|
+
describe('inspectAgentConfig', () => {
|
|
6
|
+
it('treats a native file as current', () => {
|
|
7
|
+
expect(inspectAgentConfig({
|
|
8
|
+
description: 'Reviewer',
|
|
9
|
+
mode: 'subagent',
|
|
10
|
+
model: 'openai/gpt-5#high',
|
|
11
|
+
hidden: true,
|
|
12
|
+
color: '#ff6b6b',
|
|
13
|
+
steps: 5,
|
|
14
|
+
permissions: [{ action: 'shell', resource: '*', effect: 'ask' }],
|
|
15
|
+
})).toEqual({ legacy: false, dropped: [] });
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('reports fields the next request does not use', () => {
|
|
19
|
+
const inspection = inspectAgentConfig({
|
|
20
|
+
temperature: 0.2,
|
|
21
|
+
top_p: 0.9,
|
|
22
|
+
options: { reasoningEffort: 'high' },
|
|
23
|
+
prompt: '{file:./prompt.md}',
|
|
24
|
+
color: 'red',
|
|
25
|
+
variant: 'high',
|
|
26
|
+
extra: true,
|
|
27
|
+
});
|
|
28
|
+
expect(inspection.legacy).toBe(true);
|
|
29
|
+
expect(inspection.dropped).toEqual([
|
|
30
|
+
{ key: 'temperature', reason: 'generation' },
|
|
31
|
+
{ key: 'top_p', reason: 'generation' },
|
|
32
|
+
{ key: 'options', reason: 'unknown' },
|
|
33
|
+
{ key: 'prompt', reason: 'prompt-file' },
|
|
34
|
+
{ key: 'color', reason: 'color' },
|
|
35
|
+
{ key: 'variant', reason: 'variant' },
|
|
36
|
+
{ key: 'extra', reason: 'unknown' },
|
|
37
|
+
]);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe('convertAgentConfig', () => {
|
|
42
|
+
it('folds a legacy agent into native markdown fields', () => {
|
|
43
|
+
const converted = convertAgentConfig({
|
|
44
|
+
description: 'Reviewer',
|
|
45
|
+
mode: 'subagent',
|
|
46
|
+
model: 'openai/gpt-5',
|
|
47
|
+
variant: 'high',
|
|
48
|
+
temperature: 0.2,
|
|
49
|
+
prompt: 'Be careful.',
|
|
50
|
+
permission: { bash: 'ask', task: 'allow', write: 'deny' },
|
|
51
|
+
tools: { write: false },
|
|
52
|
+
maxSteps: 4,
|
|
53
|
+
disable: true,
|
|
54
|
+
color: '#112233',
|
|
55
|
+
request: { body: { temperature: 0.2 } },
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
expect(converted.legacy).toBe(true);
|
|
59
|
+
expect(converted.body).toBe('Be careful.');
|
|
60
|
+
expect(converted.frontmatter).toMatchObject({
|
|
61
|
+
description: 'Reviewer',
|
|
62
|
+
mode: 'subagent',
|
|
63
|
+
model: 'openai/gpt-5#high',
|
|
64
|
+
steps: 4,
|
|
65
|
+
disabled: true,
|
|
66
|
+
color: '#112233',
|
|
67
|
+
request: { body: { temperature: 0.2 } },
|
|
68
|
+
});
|
|
69
|
+
expect(converted.frontmatter).not.toHaveProperty('temperature');
|
|
70
|
+
expect(converted.frontmatter).not.toHaveProperty('hidden');
|
|
71
|
+
expect(converted.frontmatter.permissions).toEqual(expect.arrayContaining([
|
|
72
|
+
{ action: 'shell', resource: '*', effect: 'ask' },
|
|
73
|
+
{ action: 'subagent', resource: '*', effect: 'allow' },
|
|
74
|
+
{ action: 'edit', resource: '*', effect: 'deny' },
|
|
75
|
+
]));
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('applyNativePatch', () => {
|
|
80
|
+
it('patches only the keys present in the update', () => {
|
|
81
|
+
const next = applyNativePatch({
|
|
82
|
+
frontmatter: {
|
|
83
|
+
model: 'openai/gpt-5',
|
|
84
|
+
hidden: true,
|
|
85
|
+
permissions: [{ action: 'read', resource: '*', effect: 'allow' }],
|
|
86
|
+
variant: 'high',
|
|
87
|
+
temperature: 1,
|
|
88
|
+
},
|
|
89
|
+
body: 'old',
|
|
90
|
+
}, {
|
|
91
|
+
model: null,
|
|
92
|
+
hidden: false,
|
|
93
|
+
permissions: [],
|
|
94
|
+
system: null,
|
|
95
|
+
steps: 0,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
expect(next.body).toBe('');
|
|
99
|
+
expect(next.frontmatter).toEqual({
|
|
100
|
+
temperature: 1,
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe('writeAgentDocument', () => {
|
|
106
|
+
it('leaves unmentioned fields alone on a prompt-only patch', () => {
|
|
107
|
+
const next = writeAgentDocument({
|
|
108
|
+
frontmatter: {
|
|
109
|
+
temperature: 1,
|
|
110
|
+
permission: { bash: 'allow' },
|
|
111
|
+
},
|
|
112
|
+
body: 'legacy prompt',
|
|
113
|
+
}, {
|
|
114
|
+
system: 'Only the prompt changed.',
|
|
115
|
+
}, false);
|
|
116
|
+
|
|
117
|
+
expect(next.body).toBe('Only the prompt changed.');
|
|
118
|
+
expect(next.frontmatter.temperature).toBe(1);
|
|
119
|
+
expect(next.frontmatter.permission).toEqual({ bash: 'allow' });
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('drops legacy fields when confirmDrop is true', () => {
|
|
123
|
+
const next = writeAgentDocument({
|
|
124
|
+
frontmatter: {
|
|
125
|
+
temperature: 1,
|
|
126
|
+
permission: { bash: 'allow' },
|
|
127
|
+
},
|
|
128
|
+
body: 'legacy prompt',
|
|
129
|
+
}, {
|
|
130
|
+
system: 'Only the prompt changed.',
|
|
131
|
+
}, true);
|
|
132
|
+
|
|
133
|
+
expect(next.body).toBe('Only the prompt changed.');
|
|
134
|
+
expect(next.frontmatter.temperature).toBeUndefined();
|
|
135
|
+
expect(next.frontmatter.permission).toEqual({ bash: 'allow' });
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -16,6 +16,10 @@ import {
|
|
|
16
16
|
resolvePromptFilePath,
|
|
17
17
|
writePromptFile,
|
|
18
18
|
} from './shared.js';
|
|
19
|
+
import {
|
|
20
|
+
inspectAgentConfig,
|
|
21
|
+
writeAgentDocument,
|
|
22
|
+
} from './agent-document.js';
|
|
19
23
|
|
|
20
24
|
// ============== AGENT SCOPE HELPERS ==============
|
|
21
25
|
|
|
@@ -321,21 +325,100 @@ function getAgentSources(agentName, workingDirectory, lookupCache = createAgentL
|
|
|
321
325
|
}
|
|
322
326
|
};
|
|
323
327
|
|
|
328
|
+
const stored = {};
|
|
329
|
+
if (jsonSection && typeof jsonSection === 'object') {
|
|
330
|
+
Object.assign(stored, jsonSection);
|
|
331
|
+
}
|
|
324
332
|
if (mdExists) {
|
|
325
333
|
const { frontmatter, body } = parseMdFile(mdPath);
|
|
326
334
|
sources.md.fields = Object.keys(frontmatter);
|
|
327
335
|
if (body) {
|
|
328
336
|
sources.md.fields.push('prompt');
|
|
329
337
|
}
|
|
338
|
+
Object.assign(stored, frontmatter);
|
|
339
|
+
if (typeof body === 'string' && body.trim()) stored.prompt = body.trim();
|
|
330
340
|
}
|
|
331
341
|
|
|
332
342
|
if (jsonSection) {
|
|
333
343
|
sources.json.fields = Object.keys(jsonSection);
|
|
334
344
|
}
|
|
345
|
+
sources.document = inspectAgentConfig(stored);
|
|
335
346
|
|
|
336
347
|
return sources;
|
|
337
348
|
}
|
|
338
349
|
|
|
350
|
+
function listDisabledAgentOverrides(workingDirectory) {
|
|
351
|
+
/** @type {Array<{ name: string, scope: string, description?: string, mode?: string }>} */
|
|
352
|
+
const found = [];
|
|
353
|
+
const visit = (directory, scope) => {
|
|
354
|
+
if (!directory || !fs.existsSync(directory)) return;
|
|
355
|
+
const walk = (current, prefix) => {
|
|
356
|
+
let entries = [];
|
|
357
|
+
try {
|
|
358
|
+
entries = fs.readdirSync(current, { withFileTypes: true });
|
|
359
|
+
} catch {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
for (const entry of entries) {
|
|
363
|
+
if (found.length >= 200) return;
|
|
364
|
+
const full = path.join(current, entry.name);
|
|
365
|
+
if (entry.isDirectory()) {
|
|
366
|
+
walk(full, prefix ? `${prefix}/${entry.name}` : entry.name);
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
if (!entry.isFile() || !entry.name.endsWith('.md')) continue;
|
|
370
|
+
const base = entry.name.slice(0, -3);
|
|
371
|
+
const name = prefix ? `${prefix}/${base}` : base;
|
|
372
|
+
let frontmatter = {};
|
|
373
|
+
try {
|
|
374
|
+
frontmatter = parseMdFile(full).frontmatter || {};
|
|
375
|
+
} catch {
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
if (frontmatter.disabled !== true && frontmatter.disable !== true) continue;
|
|
379
|
+
found.push({
|
|
380
|
+
name,
|
|
381
|
+
scope,
|
|
382
|
+
...(typeof frontmatter.description === 'string' ? { description: frontmatter.description } : {}),
|
|
383
|
+
...(frontmatter.mode === 'primary' || frontmatter.mode === 'subagent' || frontmatter.mode === 'all'
|
|
384
|
+
? { mode: frontmatter.mode }
|
|
385
|
+
: {}),
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
walk(directory, '');
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
visit(AGENT_DIR, AGENT_SCOPE.USER);
|
|
393
|
+
if (workingDirectory) {
|
|
394
|
+
visit(path.join(workingDirectory, '.opencode', 'agents'), AGENT_SCOPE.PROJECT);
|
|
395
|
+
visit(path.join(workingDirectory, '.opencode', 'agent'), AGENT_SCOPE.PROJECT);
|
|
396
|
+
}
|
|
397
|
+
return found;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function nativeWritePath(agentName, workingDirectory, scope, lookupCache) {
|
|
401
|
+
if (scope === AGENT_SCOPE.PROJECT && workingDirectory) {
|
|
402
|
+
ensureProjectAgentDir(workingDirectory);
|
|
403
|
+
return getProjectAgentPath(workingDirectory, agentName);
|
|
404
|
+
}
|
|
405
|
+
if (scope === AGENT_SCOPE.USER) {
|
|
406
|
+
return getUserAgentPath(agentName, lookupCache);
|
|
407
|
+
}
|
|
408
|
+
const existing = getAgentWritePath(agentName, workingDirectory, undefined, lookupCache);
|
|
409
|
+
if (existing.path && fs.existsSync(existing.path)) return existing.path;
|
|
410
|
+
return getUserAgentPath(agentName, lookupCache);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function writeNativeAgent(agentName, patch, workingDirectory, scope, confirmDrop) {
|
|
414
|
+
ensureDirs();
|
|
415
|
+
const lookupCache = createAgentLookupCache();
|
|
416
|
+
const targetPath = nativeWritePath(agentName, workingDirectory, scope, lookupCache);
|
|
417
|
+
const existing = fs.existsSync(targetPath) ? parseMdFile(targetPath) : { frontmatter: {}, body: '' };
|
|
418
|
+
const next = writeAgentDocument(existing, patch && typeof patch === 'object' ? patch : {}, confirmDrop === true);
|
|
419
|
+
writeMdFile(targetPath, next.frontmatter, next.body);
|
|
420
|
+
}
|
|
421
|
+
|
|
339
422
|
function getAgentConfig(agentName, workingDirectory, lookupCache = createAgentLookupCache()) {
|
|
340
423
|
const projectPath = workingDirectory ? getProjectAgentPath(workingDirectory, agentName) : null;
|
|
341
424
|
const projectExists = projectPath && fs.existsSync(projectPath);
|
|
@@ -409,6 +492,12 @@ function createAgent(agentName, config, workingDirectory, scope) {
|
|
|
409
492
|
targetScope = AGENT_SCOPE.USER;
|
|
410
493
|
}
|
|
411
494
|
|
|
495
|
+
if (config && Object.prototype.hasOwnProperty.call(config, 'native')) {
|
|
496
|
+
writeNativeAgent(agentName, config.native, workingDirectory, targetScope, config.confirmDrop === true);
|
|
497
|
+
console.log(`Created new agent: ${agentName} (scope: ${targetScope})`);
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
|
|
412
501
|
const { prompt, scope: _scopeFromConfig, ...rawFrontmatter } = config;
|
|
413
502
|
const frontmatter = Object.fromEntries(
|
|
414
503
|
Object.entries(rawFrontmatter).filter(([, value]) => value !== null && value !== undefined)
|
|
@@ -419,6 +508,12 @@ function createAgent(agentName, config, workingDirectory, scope) {
|
|
|
419
508
|
}
|
|
420
509
|
|
|
421
510
|
function updateAgent(agentName, updates, workingDirectory) {
|
|
511
|
+
if (updates && Object.prototype.hasOwnProperty.call(updates, 'native')) {
|
|
512
|
+
writeNativeAgent(agentName, updates.native, workingDirectory, updates.scope, updates.confirmDrop === true);
|
|
513
|
+
console.log(`Updated agent: ${agentName}`);
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
|
|
422
517
|
ensureDirs();
|
|
423
518
|
const lookupCache = createAgentLookupCache();
|
|
424
519
|
|
|
@@ -693,6 +788,7 @@ function deleteAgent(agentName, workingDirectory, scope) {
|
|
|
693
788
|
export {
|
|
694
789
|
getAgentSources,
|
|
695
790
|
getAgentConfig,
|
|
791
|
+
listDisabledAgentOverrides,
|
|
696
792
|
createAgent,
|
|
697
793
|
updateAgent,
|
|
698
794
|
deleteAgent,
|
|
@@ -81,9 +81,14 @@ export const createOpenCodeAuthStateRuntime = (dependencies) => {
|
|
|
81
81
|
return generatedPassword;
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
+
// A server OpenChamber does not own (the shared official service) keeps its
|
|
85
|
+
// own password; adopt it instead of generating one.
|
|
86
|
+
const adoptOpenCodeServerPassword = (password, source) => setOpenCodeAuthState(password, source);
|
|
87
|
+
|
|
84
88
|
return {
|
|
85
89
|
getOpenCodeAuthHeaders,
|
|
86
90
|
isOpenCodeConnectionSecure,
|
|
87
91
|
ensureLocalOpenCodeServerPassword,
|
|
92
|
+
adoptOpenCodeServerPassword,
|
|
88
93
|
};
|
|
89
94
|
};
|
|
@@ -64,6 +64,7 @@ export const createBootstrapRuntime = (dependencies) => {
|
|
|
64
64
|
setAutoAcceptSession,
|
|
65
65
|
sessionIndexService,
|
|
66
66
|
sessionIndexSyncRuntime,
|
|
67
|
+
getCommittedHostMetadata = null,
|
|
67
68
|
transcriptCacheService,
|
|
68
69
|
} = options;
|
|
69
70
|
|
|
@@ -156,6 +157,7 @@ export const createBootstrapRuntime = (dependencies) => {
|
|
|
156
157
|
getCachedZenModels,
|
|
157
158
|
sessionIndexService,
|
|
158
159
|
sessionIndexSyncRuntime,
|
|
160
|
+
getCommittedHostMetadata,
|
|
159
161
|
transcriptCacheService,
|
|
160
162
|
express,
|
|
161
163
|
});
|