hostlet 0.0.0-stage → 0.1.0-alpha.2
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/LICENSE +21 -0
- package/README.md +233 -2
- package/bin/hostlet.js +61 -0
- package/console/app/api.js +1223 -0
- package/console/app/boot.js +165 -0
- package/console/app/cards.js +222 -0
- package/console/app/compose-quote.js +127 -0
- package/console/app/config-form.js +727 -0
- package/console/app/document-drafts.js +62 -0
- package/console/app/document-tools.mjs +67 -0
- package/console/app/documents.js +106 -0
- package/console/app/pages.js +6483 -0
- package/console/app/plugins.js +509 -0
- package/console/app/preview-tools.js +172 -0
- package/console/app/reference-labels.js +118 -0
- package/console/app/selection.js +372 -0
- package/console/app/store.js +57 -0
- package/console/app/text-anchor.js +26 -0
- package/console/app/topic-local.js +322 -0
- package/console/app/topic-nav.js +414 -0
- package/console/app/topic-status.js +109 -0
- package/console/app/views.js +43 -0
- package/console/apple-touch-icon.png +0 -0
- package/console/avatars/agy.svg +34 -0
- package/console/avatars/alhena.svg +36 -0
- package/console/avatars/castor.svg +38 -0
- package/console/avatars/claude.svg +34 -0
- package/console/avatars/codex.svg +34 -0
- package/console/avatars/devin.svg +34 -0
- package/console/avatars/echo.svg +34 -0
- package/console/avatars/kimi.svg +33 -0
- package/console/avatars/opencode.svg +33 -0
- package/console/avatars/pinion.svg +34 -0
- package/console/avatars/sprocket.svg +34 -0
- package/console/avatars/vela.svg +44 -0
- package/console/avatars/wasat.svg +38 -0
- package/console/clients/agy.svg +1 -0
- package/console/clients/claude.svg +1 -0
- package/console/clients/codex.svg +1 -0
- package/console/clients/devin.svg +1 -0
- package/console/clients/kimi.svg +1 -0
- package/console/clients/opencode.svg +1 -0
- package/console/favicon.ico +0 -0
- package/console/favicon.svg +16 -0
- package/console/index.html +99 -0
- package/console/pdl/engine/README.md +13 -0
- package/console/pdl/engine/anchor.js +195 -0
- package/console/pdl/engine/core.js +1340 -0
- package/console/pdl/engine/frame.js +1252 -0
- package/console/pdl/engine/i18n.js +67 -0
- package/console/pdl/engine/pdl-check.js +102 -0
- package/console/pdl/engine/pdl-doc.js +353 -0
- package/console/pdl/engine/pdl-view.js +280 -0
- package/console/pdl/engine/pdl.js +1064 -0
- package/console/pdl/engine/platform.js +18 -0
- package/console/pdl/engine/proj.js +279 -0
- package/console/pdl/engine/theme.js +176 -0
- package/console/pdl/engine/tree.js +171 -0
- package/console/pdl/engine/units.js +546 -0
- package/console/pdl/library/README.md +28 -0
- package/console/pdl/library/blocks.js +1512 -0
- package/console/pdl/library/buttons.js +86 -0
- package/console/pdl/library/capsules.js +130 -0
- package/console/pdl/library/charts.js +287 -0
- package/console/pdl/library/code.js +98 -0
- package/console/pdl/library/css/base.css +12 -0
- package/console/pdl/library/css/blocks.css +98 -0
- package/console/pdl/library/css/capsules.css +42 -0
- package/console/pdl/library/css/catalog-page.css +24 -0
- package/console/pdl/library/css/chat.css +100 -0
- package/console/pdl/library/css/composer-top.css +145 -0
- package/console/pdl/library/css/controls.css +195 -0
- package/console/pdl/library/css/drag.css +29 -0
- package/console/pdl/library/css/edit-layout.css +93 -0
- package/console/pdl/library/css/floating-window.css +30 -0
- package/console/pdl/library/css/hover.css +50 -0
- package/console/pdl/library/css/label-search.css +37 -0
- package/console/pdl/library/css/layers.css +43 -0
- package/console/pdl/library/css/library-parts.css +33 -0
- package/console/pdl/library/css/library.css +117 -0
- package/console/pdl/library/css/member-select.css +34 -0
- package/console/pdl/library/css/message.css +72 -0
- package/console/pdl/library/css/page.css +104 -0
- package/console/pdl/library/css/parts.css +338 -0
- package/console/pdl/library/css/responsive.css +40 -0
- package/console/pdl/library/css/roles.css +28 -0
- package/console/pdl/library/css/rows.css +231 -0
- package/console/pdl/library/css/settings-rows.css +37 -0
- package/console/pdl/library/css/shell.css +59 -0
- package/console/pdl/library/css/stream.css +296 -0
- package/console/pdl/library/css/theme-calculator.css +18 -0
- package/console/pdl/library/css/thumb-choice.css +69 -0
- package/console/pdl/library/css/tweaks.css +16 -0
- package/console/pdl/library/css/widgets.css +211 -0
- package/console/pdl/library/css/workbench.css +59 -0
- package/console/pdl/library/feedback.js +83 -0
- package/console/pdl/library/floating-window.mjs +100 -0
- package/console/pdl/library/fold.js +238 -0
- package/console/pdl/library/format.js +53 -0
- package/console/pdl/library/frames.js +123 -0
- package/console/pdl/library/icons.js +165 -0
- package/console/pdl/library/identity.js +149 -0
- package/console/pdl/library/inputs.js +801 -0
- package/console/pdl/library/label-search.js +214 -0
- package/console/pdl/library/markdown-text.js +115 -0
- package/console/pdl/library/markdown.js +150 -0
- package/console/pdl/library/media-viewer.js +293 -0
- package/console/pdl/library/member-select.mjs +32 -0
- package/console/pdl/library/message.js +105 -0
- package/console/pdl/library/motion.js +56 -0
- package/console/pdl/library/overlays.js +165 -0
- package/console/pdl/library/page.js +142 -0
- package/console/pdl/library/plugin-form.js +154 -0
- package/console/pdl/library/registry.js +198 -0
- package/console/pdl/library/rows.js +523 -0
- package/console/pdl/library/shell.js +151 -0
- package/console/pdl/library/stream.js +58 -0
- package/console/pdl/library/tabs.js +259 -0
- package/console/pdl/library/theme-calculator.js +300 -0
- package/console/pdl/library/widgets.js +114 -0
- package/console/pdl/load-order.json +74 -0
- package/console/pdl/platform/README.md +3 -0
- package/console/pdl/platform/rich-markdown.mjs +17 -0
- package/console/pdl/platform/web-links.js +26 -0
- package/console/pdl/platform/web.js +80 -0
- package/console/sdk-browser/mentions.d.mts +16 -0
- package/console/sdk-browser/mentions.mjs +84 -0
- package/console/theme/assets.js +21 -0
- package/console/theme/theme.json +9417 -0
- package/console/theme/tokens.json +444 -0
- package/dist/core/a2a.d.ts +288 -0
- package/dist/core/a2a.js +2197 -0
- package/dist/core/address.d.ts +34 -0
- package/dist/core/address.js +33 -0
- package/dist/core/approval-inputs.d.ts +17 -0
- package/dist/core/approval-inputs.js +70 -0
- package/dist/core/archive.d.ts +19 -0
- package/dist/core/archive.js +135 -0
- package/dist/core/attachments.d.ts +17 -0
- package/dist/core/attachments.js +143 -0
- package/dist/core/blocked-handoffs.d.ts +132 -0
- package/dist/core/blocked-handoffs.js +349 -0
- package/dist/core/config-schema.d.ts +124 -0
- package/dist/core/config-schema.js +192 -0
- package/dist/core/config.d.ts +117 -0
- package/dist/core/config.js +638 -0
- package/dist/core/disk-usage.d.ts +26 -0
- package/dist/core/disk-usage.js +83 -0
- package/dist/core/documents.d.ts +9 -0
- package/dist/core/documents.js +48 -0
- package/dist/core/entry.d.ts +316 -0
- package/dist/core/entry.js +711 -0
- package/dist/core/home.d.ts +76 -0
- package/dist/core/home.js +449 -0
- package/dist/core/i18n.d.ts +36 -0
- package/dist/core/i18n.js +458 -0
- package/dist/core/instances.d.ts +224 -0
- package/dist/core/instances.js +1272 -0
- package/dist/core/members.d.ts +190 -0
- package/dist/core/members.js +358 -0
- package/dist/core/mentions.d.ts +12 -0
- package/dist/core/mentions.js +49 -0
- package/dist/core/messages.d.ts +876 -0
- package/dist/core/messages.js +916 -0
- package/dist/core/notices.d.ts +88 -0
- package/dist/core/notices.js +54 -0
- package/dist/core/ops.d.ts +117 -0
- package/dist/core/ops.js +146 -0
- package/dist/core/package.d.ts +2 -0
- package/dist/core/package.js +14 -0
- package/dist/core/parts.d.ts +25 -0
- package/dist/core/parts.js +119 -0
- package/dist/core/plugins/catalog.d.ts +14 -0
- package/dist/core/plugins/catalog.js +54 -0
- package/dist/core/plugins/external.d.ts +7 -0
- package/dist/core/plugins/external.js +921 -0
- package/dist/core/plugins/index.d.ts +5 -0
- package/dist/core/plugins/index.js +51 -0
- package/dist/core/plugins/npm.d.ts +12 -0
- package/dist/core/plugins/npm.js +99 -0
- package/dist/core/plugins/plugin-manifest.d.ts +12 -0
- package/dist/core/plugins/plugin-manifest.js +231 -0
- package/dist/core/push.d.ts +22 -0
- package/dist/core/push.js +63 -0
- package/dist/core/resource.d.ts +77 -0
- package/dist/core/resource.js +48 -0
- package/dist/core/spawn.d.ts +12 -0
- package/dist/core/spawn.js +30 -0
- package/dist/core/storage-inventory.d.ts +118 -0
- package/dist/core/storage-inventory.js +279 -0
- package/dist/core/storage.d.ts +45 -0
- package/dist/core/storage.js +602 -0
- package/dist/core/store.d.ts +15 -0
- package/dist/core/store.js +33 -0
- package/dist/core/topic-index.d.ts +19 -0
- package/dist/core/topic-index.js +70 -0
- package/dist/core/topic-ops.d.ts +139 -0
- package/dist/core/topic-ops.js +507 -0
- package/dist/core/topic-status.d.ts +32 -0
- package/dist/core/topic-status.js +105 -0
- package/dist/core/topics.d.ts +327 -0
- package/dist/core/topics.js +786 -0
- package/dist/core/turn-clients.d.ts +1 -0
- package/dist/core/turn-clients.js +5 -0
- package/dist/core/types.d.ts +2866 -0
- package/dist/core/types.js +166 -0
- package/dist/core/util.d.ts +10 -0
- package/dist/core/util.js +47 -0
- package/dist/main.d.ts +12 -0
- package/dist/main.js +82 -0
- package/dist/plugins/adapter-acp/index.d.ts +3 -0
- package/dist/plugins/adapter-acp/index.js +57 -0
- package/dist/plugins/adapter-acp/plugin.yaml +100 -0
- package/dist/plugins/adapter-agy/command.d.ts +9 -0
- package/dist/plugins/adapter-agy/command.js +34 -0
- package/dist/plugins/adapter-agy/index.d.ts +5 -0
- package/dist/plugins/adapter-agy/index.js +65 -0
- package/dist/plugins/adapter-agy/quota.d.ts +2 -0
- package/dist/plugins/adapter-agy/quota.js +155 -0
- package/dist/plugins/adapter-agy/terminal.d.ts +6 -0
- package/dist/plugins/adapter-agy/terminal.js +132 -0
- package/dist/plugins/adapter-agy/version.d.ts +9 -0
- package/dist/plugins/adapter-agy/version.js +17 -0
- package/dist/plugins/adapter-claude/index.d.ts +43 -0
- package/dist/plugins/adapter-claude/index.js +412 -0
- package/dist/plugins/adapter-claude/quota.d.ts +14 -0
- package/dist/plugins/adapter-claude/quota.js +103 -0
- package/dist/plugins/adapter-codex/index.d.ts +4 -0
- package/dist/plugins/adapter-codex/index.js +688 -0
- package/dist/plugins/adapter-codex/responses-model.d.ts +9 -0
- package/dist/plugins/adapter-codex/responses-model.js +82 -0
- package/dist/plugins/adapter-kimi/index.d.ts +4 -0
- package/dist/plugins/adapter-kimi/index.js +51 -0
- package/dist/plugins/adapter-kimi/quota.d.ts +3 -0
- package/dist/plugins/adapter-kimi/quota.js +171 -0
- package/dist/plugins/adapter-opencode/index.d.ts +12 -0
- package/dist/plugins/adapter-opencode/index.js +64 -0
- package/dist/plugins/annotations/console/cards.css +189 -0
- package/dist/plugins/annotations/console/cards.mjs +439 -0
- package/dist/plugins/annotations/console/pdl.json +52 -0
- package/dist/plugins/annotations/console/view.mjs +241 -0
- package/dist/plugins/annotations/console/window.mjs +219 -0
- package/dist/plugins/annotations/followups.d.ts +51 -0
- package/dist/plugins/annotations/followups.js +112 -0
- package/dist/plugins/annotations/index.d.ts +3 -0
- package/dist/plugins/annotations/index.js +298 -0
- package/dist/plugins/annotations/plugin.yaml +3 -0
- package/dist/plugins/ask-choice/index.d.ts +9 -0
- package/dist/plugins/ask-choice/index.js +24 -0
- package/dist/plugins/ask-choice/plugin.yaml +2 -0
- package/dist/plugins/background/index.d.ts +2 -0
- package/dist/plugins/background/index.js +398 -0
- package/dist/plugins/background/plugin.yaml +7 -0
- package/dist/plugins/builtin.json +37 -0
- package/dist/plugins/cards/console/pdl.json +516 -0
- package/dist/plugins/cards/console/view.mjs +67 -0
- package/dist/plugins/cards/index.d.ts +8 -0
- package/dist/plugins/cards/index.js +627 -0
- package/dist/plugins/cards/plugin.yaml +3 -0
- package/dist/plugins/console/browser.d.ts +2 -0
- package/dist/plugins/console/browser.js +115 -0
- package/dist/plugins/console/console/pdl.json +38 -0
- package/dist/plugins/console/console/view.mjs +26 -0
- package/dist/plugins/console/index.d.ts +4 -0
- package/dist/plugins/console/index.js +94 -0
- package/dist/plugins/console/picker.d.ts +2 -0
- package/dist/plugins/console/picker.js +48 -0
- package/dist/plugins/console/plugin.yaml +3 -0
- package/dist/plugins/console/topic-view.d.ts +3 -0
- package/dist/plugins/console/topic-view.js +388 -0
- package/dist/plugins/handoff/index.d.ts +2 -0
- package/dist/plugins/handoff/index.js +147 -0
- package/dist/plugins/handoff/plugin.yaml +8 -0
- package/dist/plugins/host-api/index.d.ts +7 -0
- package/dist/plugins/host-api/index.js +310 -0
- package/dist/plugins/host-api/plugin.yaml +2 -0
- package/dist/plugins/host-api/signing.d.ts +63 -0
- package/dist/plugins/host-api/signing.js +427 -0
- package/dist/plugins/host-api/skills/host-ops/SKILL.md +28 -0
- package/dist/plugins/host-api/skills/hostlet-plugin-dev/SKILL.md +38 -0
- package/dist/plugins/inbox/index.d.ts +15 -0
- package/dist/plugins/inbox/index.js +161 -0
- package/dist/plugins/inbox/plugin.yaml +2 -0
- package/dist/plugins/keys/account-directories.d.ts +18 -0
- package/dist/plugins/keys/account-directories.js +86 -0
- package/dist/plugins/keys/account-storage.d.ts +18 -0
- package/dist/plugins/keys/account-storage.js +112 -0
- package/dist/plugins/keys/console/pdl.json +710 -0
- package/dist/plugins/keys/console/view.mjs +619 -0
- package/dist/plugins/keys/index.d.ts +7 -0
- package/dist/plugins/keys/index.js +842 -0
- package/dist/plugins/keys/login-link.d.ts +2 -0
- package/dist/plugins/keys/login-link.js +15 -0
- package/dist/plugins/keys/plugin.yaml +3 -0
- package/dist/plugins/keys/quota-history.d.ts +91 -0
- package/dist/plugins/keys/quota-history.js +420 -0
- package/dist/plugins/mcp/console/pdl.json +412 -0
- package/dist/plugins/mcp/console/view.mjs +207 -0
- package/dist/plugins/mcp/index.d.ts +7 -0
- package/dist/plugins/mcp/index.js +494 -0
- package/dist/plugins/mcp/plugin.yaml +3 -0
- package/dist/plugins/member-health/index.d.ts +2 -0
- package/dist/plugins/member-health/index.js +478 -0
- package/dist/plugins/member-health/plugin.yaml +2 -0
- package/dist/plugins/memory/capabilities.d.ts +10 -0
- package/dist/plugins/memory/capabilities.js +70 -0
- package/dist/plugins/memory/console/pdl.json +459 -0
- package/dist/plugins/memory/console/view.mjs +254 -0
- package/dist/plugins/memory/corpus.d.ts +60 -0
- package/dist/plugins/memory/corpus.js +521 -0
- package/dist/plugins/memory/engines/fts-tree-diversity.d.ts +8 -0
- package/dist/plugins/memory/engines/fts-tree-diversity.js +49 -0
- package/dist/plugins/memory/engines/fts-tree-text.d.ts +12 -0
- package/dist/plugins/memory/engines/fts-tree-text.js +93 -0
- package/dist/plugins/memory/engines/fts-tree.d.ts +4 -0
- package/dist/plugins/memory/engines/fts-tree.js +387 -0
- package/dist/plugins/memory/engines/search.d.ts +9 -0
- package/dist/plugins/memory/engines/search.js +35 -0
- package/dist/plugins/memory/index.d.ts +3 -0
- package/dist/plugins/memory/index.js +465 -0
- package/dist/plugins/memory/notes.d.ts +22 -0
- package/dist/plugins/memory/notes.js +140 -0
- package/dist/plugins/memory/plugin.yaml +23 -0
- package/dist/plugins/model-profiles/index.d.ts +2 -0
- package/dist/plugins/model-profiles/index.js +919 -0
- package/dist/plugins/model-profiles/plugin.yaml +13 -0
- package/dist/plugins/model-profiles/review-source.d.ts +11 -0
- package/dist/plugins/model-profiles/review-source.js +640 -0
- package/dist/plugins/model-profiles/rules.d.ts +132 -0
- package/dist/plugins/model-profiles/rules.js +767 -0
- package/dist/plugins/model-profiles/skills/model-profile/SKILL.md +60 -0
- package/dist/plugins/model-profiles/sources.d.ts +61 -0
- package/dist/plugins/model-profiles/sources.js +375 -0
- package/dist/plugins/model-profiles/storage.d.ts +104 -0
- package/dist/plugins/model-profiles/storage.js +352 -0
- package/dist/plugins/model-profiles/types.d.ts +187 -0
- package/dist/plugins/model-profiles/types.js +12 -0
- package/dist/plugins/model-profiles/wakeup.d.ts +29 -0
- package/dist/plugins/model-profiles/wakeup.js +390 -0
- package/dist/plugins/models/index.d.ts +2 -0
- package/dist/plugins/models/index.js +63 -0
- package/dist/plugins/models/plugin.yaml +8 -0
- package/dist/plugins/ops/collector.d.ts +22 -0
- package/dist/plugins/ops/collector.js +48 -0
- package/dist/plugins/ops/config.d.ts +11 -0
- package/dist/plugins/ops/config.js +13 -0
- package/dist/plugins/ops/console/pdl.json +676 -0
- package/dist/plugins/ops/console/view.mjs +700 -0
- package/dist/plugins/ops/index.d.ts +3 -0
- package/dist/plugins/ops/index.js +20 -0
- package/dist/plugins/ops/journal.d.ts +7 -0
- package/dist/plugins/ops/journal.js +109 -0
- package/dist/plugins/ops/metrics.d.ts +3 -0
- package/dist/plugins/ops/metrics.js +81 -0
- package/dist/plugins/ops/plugin.yaml +63 -0
- package/dist/plugins/ops/samples.d.ts +54 -0
- package/dist/plugins/ops/samples.js +100 -0
- package/dist/plugins/ops/trace.d.ts +3 -0
- package/dist/plugins/ops/trace.js +104 -0
- package/dist/plugins/ops/usage.d.ts +2 -0
- package/dist/plugins/ops/usage.js +152 -0
- package/dist/plugins/plans/acceptance.d.ts +284 -0
- package/dist/plugins/plans/acceptance.js +247 -0
- package/dist/plugins/plans/blocked.d.ts +25 -0
- package/dist/plugins/plans/blocked.js +66 -0
- package/dist/plugins/plans/console/pdl.json +639 -0
- package/dist/plugins/plans/console/view.d.mts +2 -0
- package/dist/plugins/plans/console/view.mjs +855 -0
- package/dist/plugins/plans/dependencies.d.ts +5 -0
- package/dist/plugins/plans/dependencies.js +21 -0
- package/dist/plugins/plans/index.d.ts +72 -0
- package/dist/plugins/plans/index.js +2057 -0
- package/dist/plugins/plans/plugin.yaml +44 -0
- package/dist/plugins/plans/progress.d.ts +82 -0
- package/dist/plugins/plans/progress.js +516 -0
- package/dist/plugins/prompt/index.d.ts +8 -0
- package/dist/plugins/prompt/index.js +361 -0
- package/dist/plugins/prompt/plugin.yaml +2 -0
- package/dist/plugins/recovery/console/pdl.json +50 -0
- package/dist/plugins/recovery/console/view.mjs +46 -0
- package/dist/plugins/recovery/index.d.ts +9 -0
- package/dist/plugins/recovery/index.js +454 -0
- package/dist/plugins/recovery/plugin.yaml +9 -0
- package/dist/plugins/recovery/probe.d.ts +11 -0
- package/dist/plugins/recovery/probe.js +128 -0
- package/dist/plugins/restart/console/pdl.json +112 -0
- package/dist/plugins/restart/console/view.mjs +85 -0
- package/dist/plugins/restart/index.d.ts +10 -0
- package/dist/plugins/restart/index.js +669 -0
- package/dist/plugins/restart/plugin.yaml +9 -0
- package/dist/plugins/restart/scope.d.ts +6 -0
- package/dist/plugins/restart/scope.js +44 -0
- package/dist/plugins/schedule/console/pdl.json +696 -0
- package/dist/plugins/schedule/console/view.mjs +398 -0
- package/dist/plugins/schedule/events.d.ts +76 -0
- package/dist/plugins/schedule/events.js +158 -0
- package/dist/plugins/schedule/index.d.ts +32 -0
- package/dist/plugins/schedule/index.js +1199 -0
- package/dist/plugins/schedule/plugin.yaml +26 -0
- package/dist/plugins/schedule/when.d.ts +14 -0
- package/dist/plugins/schedule/when.js +83 -0
- package/dist/plugins/sessions/console/pdl.json +259 -0
- package/dist/plugins/sessions/console/view.mjs +355 -0
- package/dist/plugins/sessions/index.d.ts +3 -0
- package/dist/plugins/sessions/index.js +126 -0
- package/dist/plugins/sessions/participants.d.ts +28 -0
- package/dist/plugins/sessions/participants.js +83 -0
- package/dist/plugins/sessions/plugin.yaml +3 -0
- package/dist/plugins/signals/console/pdl.json +802 -0
- package/dist/plugins/signals/console/view.mjs +284 -0
- package/dist/plugins/signals/content.d.ts +31 -0
- package/dist/plugins/signals/content.js +151 -0
- package/dist/plugins/signals/index.d.ts +2 -0
- package/dist/plugins/signals/index.js +601 -0
- package/dist/plugins/signals/plugin.yaml +32 -0
- package/dist/plugins/signals/skills/signal-sources/SKILL.md +27 -0
- package/dist/plugins/skills/console/pdl.json +254 -0
- package/dist/plugins/skills/console/view.mjs +204 -0
- package/dist/plugins/skills/index.d.ts +11 -0
- package/dist/plugins/skills/index.js +567 -0
- package/dist/plugins/skills/install.d.ts +69 -0
- package/dist/plugins/skills/install.js +265 -0
- package/dist/plugins/skills/plugin.yaml +24 -0
- package/dist/plugins/skills/safety-scan.d.ts +17 -0
- package/dist/plugins/skills/safety-scan.js +78 -0
- package/dist/plugins/skills/skills/skill-ops/SKILL.md +29 -0
- package/dist/plugins/terminal/console/pdl.json +115 -0
- package/dist/plugins/terminal/console/view.mjs +178 -0
- package/dist/plugins/terminal/index.d.ts +3 -0
- package/dist/plugins/terminal/index.js +204 -0
- package/dist/plugins/terminal/plugin.yaml +2 -0
- package/dist/plugins/tools/index.d.ts +3 -0
- package/dist/plugins/tools/index.js +458 -0
- package/dist/plugins/tools/plugin.yaml +2 -0
- package/dist/plugins/tools/token.d.ts +61 -0
- package/dist/plugins/tools/token.js +179 -0
- package/dist/plugins/topic-tools/index.d.ts +9 -0
- package/dist/plugins/topic-tools/index.js +29 -0
- package/dist/plugins/topic-tools/plugin.yaml +2 -0
- package/dist/plugins/topic-tools/skills/topic-tidy/SKILL.md +108 -0
- package/dist/plugins/works/console/pdl.json +120 -0
- package/dist/plugins/works/console/view.mjs +91 -0
- package/dist/plugins/works/document-words.d.ts +50 -0
- package/dist/plugins/works/document-words.js +27 -0
- package/dist/plugins/works/editors.d.ts +3 -0
- package/dist/plugins/works/editors.js +162 -0
- package/dist/plugins/works/events.d.ts +58 -0
- package/dist/plugins/works/events.js +82 -0
- package/dist/plugins/works/files.d.ts +23 -0
- package/dist/plugins/works/files.js +53 -0
- package/dist/plugins/works/index.d.ts +9 -0
- package/dist/plugins/works/index.js +1088 -0
- package/dist/plugins/works/plugin.yaml +9 -0
- package/dist/plugins/works/preview.d.ts +10 -0
- package/dist/plugins/works/preview.js +30 -0
- package/dist/plugins/works/project.d.ts +3 -0
- package/dist/plugins/works/project.js +245 -0
- package/dist/plugins/works/resource.d.ts +28 -0
- package/dist/plugins/works/resource.js +71 -0
- package/dist/plugins/works/retention.d.ts +36 -0
- package/dist/plugins/works/retention.js +295 -0
- package/dist/plugins/works/skills/works-ops/SKILL.md +14 -0
- package/dist/plugins/works/viewers.d.ts +13 -0
- package/dist/plugins/works/viewers.js +87 -0
- package/dist/plugins/works/web/anchors.js +94 -0
- package/dist/plugins/works/web/document-edit.js +245 -0
- package/dist/plugins/works/web/preview-bridge.js +142 -0
- package/dist/plugins/works/web/reading-position.js +74 -0
- package/dist/plugins/works/web/view.html +1118 -0
- package/dist/runtime/runtime.d.ts +210 -0
- package/dist/runtime/runtime.js +338 -0
- package/dist/sdk/adapter-kit.d.ts +1 -0
- package/dist/sdk/adapter-kit.js +1 -0
- package/dist/sdk/client.d.ts +163 -0
- package/dist/sdk/client.js +43 -0
- package/dist/sdk/contracts.d.ts +1263 -0
- package/dist/sdk/contracts.js +1 -0
- package/dist/sdk/index.d.ts +57 -0
- package/dist/sdk/index.js +27 -0
- package/dist/sdk/source-choice.d.ts +40 -0
- package/dist/sdk/source-choice.js +217 -0
- package/dist/sdk/topic-text.d.ts +5 -0
- package/dist/sdk/topic-text.js +26 -0
- package/dist/sdk/transport.d.ts +12 -0
- package/dist/sdk/transport.js +34 -0
- package/node_modules/@hostlet/adapter-kit/dist/acp.d.ts +88 -0
- package/node_modules/@hostlet/adapter-kit/dist/acp.js +674 -0
- package/node_modules/@hostlet/adapter-kit/dist/command.d.ts +18 -0
- package/node_modules/@hostlet/adapter-kit/dist/command.js +39 -0
- package/node_modules/@hostlet/adapter-kit/dist/index.d.ts +8 -0
- package/node_modules/@hostlet/adapter-kit/dist/index.js +6 -0
- package/node_modules/@hostlet/adapter-kit/dist/models.d.ts +29 -0
- package/node_modules/@hostlet/adapter-kit/dist/models.js +108 -0
- package/node_modules/@hostlet/adapter-kit/dist/quota.d.ts +3 -0
- package/node_modules/@hostlet/adapter-kit/dist/quota.js +4 -0
- package/node_modules/@hostlet/adapter-kit/dist/rpc.d.ts +29 -0
- package/node_modules/@hostlet/adapter-kit/dist/rpc.js +84 -0
- package/node_modules/@hostlet/adapter-kit/dist/upstream-failure.d.ts +5 -0
- package/node_modules/@hostlet/adapter-kit/dist/upstream-failure.js +37 -0
- package/node_modules/@hostlet/adapter-kit/package.json +16 -0
- package/node_modules/@hostlet/platform/dist/desktop.d.ts +16 -0
- package/node_modules/@hostlet/platform/dist/desktop.js +276 -0
- package/node_modules/@hostlet/platform/dist/files.d.ts +24 -0
- package/node_modules/@hostlet/platform/dist/files.js +113 -0
- package/node_modules/@hostlet/platform/dist/index.d.ts +6 -0
- package/node_modules/@hostlet/platform/dist/index.js +4 -0
- package/node_modules/@hostlet/platform/dist/paths.d.ts +4 -0
- package/node_modules/@hostlet/platform/dist/paths.js +9 -0
- package/node_modules/@hostlet/platform/dist/process.d.ts +45 -0
- package/node_modules/@hostlet/platform/dist/process.js +297 -0
- package/node_modules/@hostlet/platform/package.json +14 -0
- package/package.json +60 -4
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { commandLine, commandText, detectCommand } from "./command.js";
|
|
4
|
+
import { configuredContextWindow, contextWindowOption, keyedModel, keyedOptions, modelWindowFill, windowTokens } from "./models.js";
|
|
5
|
+
import { RpcFailure, startRpc, stopRpc } from "./rpc.js";
|
|
6
|
+
import { classifiedError, upstreamCode, upstreamStatus } from "./upstream-failure.js";
|
|
7
|
+
const CLIENT_INFO = { name: 'hostlet', version: '0.1.0' };
|
|
8
|
+
const BUSY_RETRY_MS = [2000, 5000, 15_000, 30_000];
|
|
9
|
+
const tokenCounts = ['inputTokens', 'outputTokens', 'cachedReadTokens', 'cachedWriteTokens', 'totalTokens'];
|
|
10
|
+
const prompt = (text) => [{ type: 'text', text }];
|
|
11
|
+
function clientCommand(client, stated, env) {
|
|
12
|
+
const override = String(stated ?? '').trim();
|
|
13
|
+
const command = override || !client.command.trim()
|
|
14
|
+
? commandLine(override, '')
|
|
15
|
+
: [client.command, ...client.args];
|
|
16
|
+
if (env && client.accountArgs) {
|
|
17
|
+
const args = typeof client.accountArgs === 'function' ? client.accountArgs(env, command.slice(1)) : client.accountArgs;
|
|
18
|
+
if (!Array.isArray(args))
|
|
19
|
+
return [command[0], ...args.args];
|
|
20
|
+
// ACP has no positional payload after a trailing option terminator.
|
|
21
|
+
const end = command.at(-1) === '--' ? command.length - 1 : command.length;
|
|
22
|
+
command.splice(end, 0, ...args);
|
|
23
|
+
}
|
|
24
|
+
return command;
|
|
25
|
+
}
|
|
26
|
+
/** `can`: what the client said it can do when it was greeted (`agentCapabilities`). */
|
|
27
|
+
async function connect(startChild, [command, ...args], cwd, options, started) {
|
|
28
|
+
const peer = startRpc(command, args, { cwd, tagged: true, startChild, ...options });
|
|
29
|
+
try {
|
|
30
|
+
started?.(peer);
|
|
31
|
+
const greeted = await peer.request('initialize', {
|
|
32
|
+
protocolVersion: 1,
|
|
33
|
+
clientCapabilities: { fs: { readTextFile: false, writeTextFile: false }, terminal: false },
|
|
34
|
+
clientInfo: CLIENT_INFO,
|
|
35
|
+
}, 30_000);
|
|
36
|
+
return Object.assign(peer, { can: greeted?.agentCapabilities ?? {} });
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
await peer.child.stop();
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const isBusy = (error) => error instanceof RpcFailure && (error.data?.code === 'turn.agent_busy' || /already in progress/i.test(error.message));
|
|
44
|
+
function acpFailure(client, error) {
|
|
45
|
+
if (error.code === -32000)
|
|
46
|
+
return 'account'; // ACP AuthRequired
|
|
47
|
+
const data = error.data;
|
|
48
|
+
if (data?.service === 'command')
|
|
49
|
+
return;
|
|
50
|
+
return (data && client.failure?.(data)) ?? upstreamCode(data?.code) ?? upstreamCode(data?.type) ?? upstreamStatus(data?.status);
|
|
51
|
+
}
|
|
52
|
+
function describeRpcError(error) {
|
|
53
|
+
const parts = error.code === undefined ? [] : [`code=${String(error.code)}`];
|
|
54
|
+
if (error.data !== undefined) {
|
|
55
|
+
try {
|
|
56
|
+
parts.push(`data=${JSON.stringify(error.data).slice(0, 400)}`);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
parts.push('data=[unserializable]');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return parts.join(' ') || 'no metadata';
|
|
63
|
+
}
|
|
64
|
+
const isModelOption = (option) => option.category === 'model' || option.id === 'model';
|
|
65
|
+
function modelOf(state) {
|
|
66
|
+
const option = state?.configOptions?.find(isModelOption);
|
|
67
|
+
const model = option ? option.currentValue : state?.models?.currentModelId;
|
|
68
|
+
return typeof model === 'string' && model.trim() ? model : undefined;
|
|
69
|
+
}
|
|
70
|
+
function open(host, client, ctx) {
|
|
71
|
+
let peer;
|
|
72
|
+
let sessionId = '';
|
|
73
|
+
let sessionModel;
|
|
74
|
+
let configuredModel;
|
|
75
|
+
let windowOverride;
|
|
76
|
+
let stopping = false;
|
|
77
|
+
let watchFailure;
|
|
78
|
+
/** Member-level text waiting for the first turn: ACP has no system channel. */
|
|
79
|
+
let preface;
|
|
80
|
+
let turn;
|
|
81
|
+
let temp;
|
|
82
|
+
const release = () => {
|
|
83
|
+
temp?.release();
|
|
84
|
+
temp = undefined;
|
|
85
|
+
};
|
|
86
|
+
const asks = new Map();
|
|
87
|
+
const end = (outcome, error, failure) => {
|
|
88
|
+
if (!turn)
|
|
89
|
+
return;
|
|
90
|
+
clearTimeout(turn.retry);
|
|
91
|
+
const id = turn.id;
|
|
92
|
+
turn = undefined;
|
|
93
|
+
for (const requestId of asks.values())
|
|
94
|
+
peer?.respond(requestId, { outcome: { outcome: 'cancelled' } });
|
|
95
|
+
asks.clear();
|
|
96
|
+
ctx.emit({
|
|
97
|
+
type: 'turn_end', turn: id, outcome,
|
|
98
|
+
...(error !== undefined ? { error } : {}),
|
|
99
|
+
...(failure ? { failure } : {}),
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
const usageOf = (source) => {
|
|
103
|
+
if (!source)
|
|
104
|
+
return undefined;
|
|
105
|
+
const tokenCount = (field) => source[field] ?? client.tokenFromMeta?.(source._meta ?? {}, field);
|
|
106
|
+
const usage = {
|
|
107
|
+
inputTokens: tokenCount('inputTokens'),
|
|
108
|
+
outputTokens: tokenCount('outputTokens'),
|
|
109
|
+
cachedReadTokens: tokenCount('cachedReadTokens'),
|
|
110
|
+
cachedWriteTokens: tokenCount('cachedWriteTokens'),
|
|
111
|
+
totalTokens: source.totalTokens,
|
|
112
|
+
contextUsed: source.used,
|
|
113
|
+
contextSize: windowTokens(source.size),
|
|
114
|
+
};
|
|
115
|
+
const fields = Object.entries(usage).filter(([, value]) => typeof value === 'number');
|
|
116
|
+
return fields.length ? Object.fromEntries(fields) : undefined;
|
|
117
|
+
};
|
|
118
|
+
const isGeneric = !client.command.trim();
|
|
119
|
+
const appendMode = isGeneric ? (ctx.member.options.append === true ? true : undefined) : client.append;
|
|
120
|
+
const excludesCache = isGeneric ? ctx.member.options.inputExcludesCache === true : client.inputExcludesCache === true;
|
|
121
|
+
const normalizeUsage = (snapshot) => {
|
|
122
|
+
const raw = snapshot.contextSize === undefined && snapshot.contextUsed !== undefined && windowOverride !== undefined
|
|
123
|
+
? { ...snapshot, contextSize: windowOverride } : snapshot;
|
|
124
|
+
const { inputTokens, cachedReadTokens = 0, cachedWriteTokens = 0 } = raw;
|
|
125
|
+
if (inputTokens === undefined)
|
|
126
|
+
return raw;
|
|
127
|
+
if (excludesCache) {
|
|
128
|
+
return { ...raw, inputTokens: inputTokens + cachedReadTokens + cachedWriteTokens };
|
|
129
|
+
}
|
|
130
|
+
// Explicitly clear the denominator in the host's merged snapshot until the client reports a valid one.
|
|
131
|
+
return Math.max(cachedReadTokens, cachedWriteTokens) > inputTokens ? { ...raw, inputTokens: undefined } : raw;
|
|
132
|
+
};
|
|
133
|
+
const recordUsage = (current, snapshot, fromPrompt = false) => {
|
|
134
|
+
if (snapshot) {
|
|
135
|
+
const tokens = current.prompts?.tokens;
|
|
136
|
+
if (tokens && fromPrompt) {
|
|
137
|
+
for (const field of tokenCounts) {
|
|
138
|
+
const count = snapshot[field];
|
|
139
|
+
if (count !== undefined)
|
|
140
|
+
tokens[field] = (tokens[field] ?? 0) + count;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// Context and live usage are snapshots. Only prompt replies contribute to the summed counters.
|
|
144
|
+
current.rawUsage = { ...current.rawUsage, ...snapshot, ...tokens };
|
|
145
|
+
}
|
|
146
|
+
const usage = current.rawUsage && normalizeUsage(current.rawUsage);
|
|
147
|
+
if (snapshot && usage)
|
|
148
|
+
ctx.emit({ type: 'usage', turn: current.id, usage });
|
|
149
|
+
return usage;
|
|
150
|
+
};
|
|
151
|
+
const outputOf = (content) => {
|
|
152
|
+
if (!Array.isArray(content))
|
|
153
|
+
return undefined;
|
|
154
|
+
const texts = content.map((c) => c?.content?.text ?? c?.text).filter((t) => typeof t === 'string');
|
|
155
|
+
return texts.length ? texts.join('\n').slice(-4000) : undefined;
|
|
156
|
+
};
|
|
157
|
+
const inputOf = (raw) => {
|
|
158
|
+
if (raw === undefined || raw === null)
|
|
159
|
+
return undefined;
|
|
160
|
+
if (typeof raw === 'string')
|
|
161
|
+
return raw;
|
|
162
|
+
if (typeof raw.command === 'string')
|
|
163
|
+
return raw.command;
|
|
164
|
+
return JSON.stringify(raw).slice(0, 2000);
|
|
165
|
+
};
|
|
166
|
+
const onNotification = (method, params) => {
|
|
167
|
+
if (method !== 'session/update')
|
|
168
|
+
return;
|
|
169
|
+
const update = params.update ?? {};
|
|
170
|
+
if (update.sessionUpdate === 'config_option_update') {
|
|
171
|
+
if (sessionId && params.sessionId !== sessionId)
|
|
172
|
+
return;
|
|
173
|
+
const model = modelOf(update);
|
|
174
|
+
if (model)
|
|
175
|
+
sessionModel = { name: model };
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (!turn) {
|
|
179
|
+
// Played back while a session loads, or output outside a turn: what was said is not said again, but how full the session's context is, is told.
|
|
180
|
+
const usage = update.sessionUpdate === 'usage_update' ? usageOf(update) : undefined;
|
|
181
|
+
if (usage)
|
|
182
|
+
ctx.emit({ type: 'usage', usage: normalizeUsage(usage) });
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const id = turn.id;
|
|
186
|
+
if (['agent_message_chunk', 'agent_thought_chunk', 'tool_call'].includes(update.sessionUpdate))
|
|
187
|
+
turn.said = true;
|
|
188
|
+
switch (update.sessionUpdate) {
|
|
189
|
+
case 'agent_message_chunk': {
|
|
190
|
+
const delta = update.content?.text;
|
|
191
|
+
if (typeof delta === 'string' && delta)
|
|
192
|
+
ctx.emit({ type: 'text', turn: id, delta });
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
case 'agent_thought_chunk':
|
|
196
|
+
if (update.content?.text)
|
|
197
|
+
ctx.emit({ type: 'thinking', turn: id, delta: update.content.text });
|
|
198
|
+
return;
|
|
199
|
+
case 'tool_call': {
|
|
200
|
+
const input = inputOf(update.rawInput);
|
|
201
|
+
// ACP has no kind for handing work to a sub-agent; clients name that tool Task or Agent.
|
|
202
|
+
const agent = /^(task|agent|sub-?agent)\b/i.test(update.title ?? '');
|
|
203
|
+
ctx.emit({ type: 'tool', turn: id, id: update.toolCallId, phase: 'start', name: update.title || update.kind || 'tool', ...(input ? { input } : {}), ...(agent ? { agent: true } : {}) });
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
case 'tool_call_update': {
|
|
207
|
+
const done = update.status === 'completed' || update.status === 'failed';
|
|
208
|
+
const output = outputOf(update.content);
|
|
209
|
+
const input = inputOf(update.rawInput);
|
|
210
|
+
ctx.emit({
|
|
211
|
+
type: 'tool', turn: id, id: update.toolCallId, phase: done ? 'end' : 'start',
|
|
212
|
+
...(update.title ? { name: update.title } : {}), ...(input ? { input } : {}), ...(output ? { output } : {}),
|
|
213
|
+
...(update.status === 'failed' ? { failed: true } : {}),
|
|
214
|
+
});
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
case 'usage_update':
|
|
218
|
+
recordUsage(turn, usageOf(update));
|
|
219
|
+
return;
|
|
220
|
+
default:
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
const onRequest = (id, method, params) => {
|
|
225
|
+
if (method !== 'session/request_permission' || !turn)
|
|
226
|
+
return peer?.reject(id, 'hostlet does not handle this request');
|
|
227
|
+
const askId = String(id);
|
|
228
|
+
asks.set(askId, id);
|
|
229
|
+
const call = params.toolCall;
|
|
230
|
+
const input = call?.rawInput;
|
|
231
|
+
const shell = call?.kind === 'execute';
|
|
232
|
+
const cwd = shell && typeof input?.cwd === 'string' ? input.cwd : undefined;
|
|
233
|
+
const locations = call?.locations;
|
|
234
|
+
const paths = Array.isArray(locations)
|
|
235
|
+
? locations.map((location) => location?.path).filter((path) => typeof path === 'string')
|
|
236
|
+
: [];
|
|
237
|
+
const target = cwd || paths.join('、') || [input?.file_path, input?.path, input?.target]
|
|
238
|
+
.find((value) => typeof value === 'string' && !!value);
|
|
239
|
+
const payload = typeof input === 'string' ? input : input == null ? undefined : JSON.stringify(input, null, 2);
|
|
240
|
+
ctx.emit({
|
|
241
|
+
type: 'ask', turn: turn.id, askId,
|
|
242
|
+
title: shell ? '执行命令' : call?.title || call?.kind || '请求权限',
|
|
243
|
+
options: (params.options ?? []).map((o) => ({ id: o.optionId, label: o.name ?? o.optionId, kind: o.kind })),
|
|
244
|
+
details: {
|
|
245
|
+
...(target ? { fields: [{ label: cwd ? '工作目录' : '目标', value: target }] } : {}),
|
|
246
|
+
...(payload ? { code: { label: shell && typeof input === 'string' ? '命令' : '操作参数', text: payload } } : {}),
|
|
247
|
+
},
|
|
248
|
+
});
|
|
249
|
+
};
|
|
250
|
+
const finishPrompt = (current, outcome, usage) => {
|
|
251
|
+
if ('error' in outcome) {
|
|
252
|
+
const { error } = outcome;
|
|
253
|
+
if (error instanceof RpcFailure && error.code === -32800)
|
|
254
|
+
end('canceled');
|
|
255
|
+
else {
|
|
256
|
+
const failure = error instanceof RpcFailure ? acpFailure(client, error) : undefined;
|
|
257
|
+
if (error instanceof RpcFailure && !failure)
|
|
258
|
+
ctx.log(`unclassified prompt rpc error (${describeRpcError(error)})`);
|
|
259
|
+
end('failed', host.errorText(error), failure);
|
|
260
|
+
}
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
const reason = outcome.result?.stopReason;
|
|
264
|
+
if (reason === 'end_turn') {
|
|
265
|
+
const observed = current.checkFailure?.();
|
|
266
|
+
if (observed) {
|
|
267
|
+
if (typeof observed === 'string')
|
|
268
|
+
end('failed', observed);
|
|
269
|
+
else
|
|
270
|
+
end('failed', observed.error, observed.failure);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
// Ended at once with nothing said and nothing spent: the client did not reach a model at all.
|
|
274
|
+
if (!current.said && !usage?.inputTokens && !usage?.outputTokens) {
|
|
275
|
+
end('failed', '客户端这一轮什么都没有输出,也没有用量——多半是它当前的模型用不了。到这个成员的「编辑」里换一个模型再试。');
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
end('completed');
|
|
279
|
+
}
|
|
280
|
+
else if (reason === 'cancelled')
|
|
281
|
+
end('canceled');
|
|
282
|
+
else {
|
|
283
|
+
const error = reason === 'error' ? outcome.result?.error : undefined;
|
|
284
|
+
const failure = error ? acpFailure(client, error) : undefined;
|
|
285
|
+
if (error && !failure)
|
|
286
|
+
ctx.log(`unclassified prompt result error (${describeRpcError(error)})`);
|
|
287
|
+
end('failed', typeof error?.message === 'string' ? error.message : `client stopped: ${reason}`, failure);
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
const run = (current, text, attempt) => {
|
|
291
|
+
if (stopping)
|
|
292
|
+
return;
|
|
293
|
+
if (attempt !== undefined) {
|
|
294
|
+
if (sessionModel)
|
|
295
|
+
ctx.emit({ type: 'model', turn: current.id, model: sessionModel.name, ...(configuredModel ? { configuredModel } : {}) });
|
|
296
|
+
current.checkFailure = watchFailure?.(sessionId);
|
|
297
|
+
}
|
|
298
|
+
const prompts = current.prompts;
|
|
299
|
+
const sequence = prompts ? ++prompts.sent : 0;
|
|
300
|
+
if (prompts)
|
|
301
|
+
prompts.pending++;
|
|
302
|
+
const settle = (outcome) => {
|
|
303
|
+
// stop() owns the final outcome once the host has decided to end the process.
|
|
304
|
+
if (turn !== current || stopping)
|
|
305
|
+
return;
|
|
306
|
+
if (prompts)
|
|
307
|
+
prompts.pending--;
|
|
308
|
+
// A busy first prompt can be retried while it is still the only prompt for this turn.
|
|
309
|
+
if ('error' in outcome && attempt !== undefined && attempt < BUSY_RETRY_MS.length &&
|
|
310
|
+
(!prompts || prompts.sent === sequence) && isBusy(outcome.error)) {
|
|
311
|
+
current.retry = setTimeout(() => {
|
|
312
|
+
current.retry = undefined;
|
|
313
|
+
run(current, text, attempt + 1);
|
|
314
|
+
}, BUSY_RETRY_MS[attempt]);
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
if (prompts && prompts.sent === sequence)
|
|
318
|
+
prompts.latest = outcome;
|
|
319
|
+
const usage = recordUsage(current, 'result' in outcome ? usageOf(outcome.result?.usage) : undefined, true);
|
|
320
|
+
if (prompts) {
|
|
321
|
+
if (prompts.pending === 0)
|
|
322
|
+
finishPrompt(current, prompts.latest, usage);
|
|
323
|
+
}
|
|
324
|
+
else if (attempt !== undefined)
|
|
325
|
+
finishPrompt(current, outcome, usage);
|
|
326
|
+
else if ('error' in outcome)
|
|
327
|
+
ctx.log(`append failed: ${host.errorText(outcome.error)}`);
|
|
328
|
+
};
|
|
329
|
+
void peer.request('session/prompt', { sessionId, prompt: prompt(text) }).then((result) => settle({ result }), (error) => settle({ error }));
|
|
330
|
+
};
|
|
331
|
+
return {
|
|
332
|
+
get pid() {
|
|
333
|
+
return peer?.child.pid;
|
|
334
|
+
},
|
|
335
|
+
async start(input) {
|
|
336
|
+
const classify = (error) => {
|
|
337
|
+
throw classifiedError(error, error instanceof RpcFailure ? acpFailure(client, error) : undefined, host.TurnFailureError);
|
|
338
|
+
};
|
|
339
|
+
const command = clientCommand(client, input.options.command, input.env);
|
|
340
|
+
const selected = input.key ? {
|
|
341
|
+
model: keyedModel(input.options, ctx.member.name),
|
|
342
|
+
contextWindow: client.keys?.contextWindow ? configuredContextWindow(input.options) : undefined,
|
|
343
|
+
} : undefined;
|
|
344
|
+
windowOverride = selected?.contextWindow;
|
|
345
|
+
const prepared = client.prepare?.({
|
|
346
|
+
topicId: ctx.topicId, memberId: ctx.member.id, cwd: input.cwd, command, options: input.options,
|
|
347
|
+
...(input.key ? { key: input.key, ...selected } : {}),
|
|
348
|
+
...(input.systemPrompt ? { systemPrompt: input.systemPrompt } : {}),
|
|
349
|
+
});
|
|
350
|
+
temp = prepared?.temp;
|
|
351
|
+
watchFailure = prepared?.watchFailure;
|
|
352
|
+
if (prepared?.model)
|
|
353
|
+
sessionModel = { name: prepared.model };
|
|
354
|
+
if (selected)
|
|
355
|
+
configuredModel = prepared?.model ?? selected.model;
|
|
356
|
+
const started = await connect(host.startChild, prepared?.command ?? command, input.cwd, {
|
|
357
|
+
onNotification, onRequest, env: { ...input.memberEnv, ...prepared?.env, ...input.env }, member: ctx.member,
|
|
358
|
+
}, (spawned) => {
|
|
359
|
+
peer = spawned;
|
|
360
|
+
if (temp) {
|
|
361
|
+
spawned.child.proc.once('close', () => {
|
|
362
|
+
try {
|
|
363
|
+
release();
|
|
364
|
+
}
|
|
365
|
+
catch (error) {
|
|
366
|
+
ctx.log(`could not remove client temp files: ${host.errorText(error)}`);
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
temp.track(spawned.child.pid);
|
|
370
|
+
}
|
|
371
|
+
}).catch(classify);
|
|
372
|
+
void started.child.exited.then(({ code, stderr }) => {
|
|
373
|
+
if (stopping)
|
|
374
|
+
return;
|
|
375
|
+
ctx.emit({ type: 'exit', reason: `${client.command || command[0]} 退出(code ${code})${stderr ? ` ${stderr.trim().split('\n').at(-1)}` : ''}` });
|
|
376
|
+
});
|
|
377
|
+
const mcpServers = input.mcpServers.map((server) => server.url
|
|
378
|
+
? { type: 'http', name: server.name, url: server.url, headers: Object.entries(server.headers ?? {}).map(([name, value]) => ({ name, value })) }
|
|
379
|
+
: { name: server.name, command: server.command ?? '', args: server.args ?? [], env: Object.entries(server.env ?? {}).map(([name, value]) => ({ name, value })) });
|
|
380
|
+
const opened = await (input.sessionId
|
|
381
|
+
? started.request('session/load', { sessionId: input.sessionId, cwd: input.cwd, mcpServers }, 120_000).catch((error) => {
|
|
382
|
+
if (error instanceof RpcFailure && acpFailure(client, error))
|
|
383
|
+
throw error;
|
|
384
|
+
const mapped = error instanceof RpcFailure ? client.loadError?.(error.data ?? {}) : undefined;
|
|
385
|
+
if (mapped instanceof Error)
|
|
386
|
+
throw mapped;
|
|
387
|
+
if (typeof mapped === 'string')
|
|
388
|
+
throw new Error(mapped);
|
|
389
|
+
if (error instanceof RpcFailure && (error.code === -32002
|
|
390
|
+
|| error.data?.code === 'session_not_found'
|
|
391
|
+
|| error.data?.errorKind === 'session_not_found'
|
|
392
|
+
|| /\bsession\b.*\bnot found\b|\bno such session\b|\bunknown session\b/i.test(error.message)))
|
|
393
|
+
throw new host.SessionGoneError(error.message, { cause: error });
|
|
394
|
+
throw error;
|
|
395
|
+
})
|
|
396
|
+
: started.request('session/new', { cwd: input.cwd, mcpServers }, 120_000)).catch(classify);
|
|
397
|
+
sessionId = input.sessionId || opened.sessionId;
|
|
398
|
+
const reported = modelOf(opened);
|
|
399
|
+
if (reported)
|
|
400
|
+
sessionModel = { name: reported };
|
|
401
|
+
if (!prepared?.system && input.systemPrompt) {
|
|
402
|
+
if (input.opening)
|
|
403
|
+
preface = input.systemPrompt;
|
|
404
|
+
else if (input.changed?.includes('prompt')) {
|
|
405
|
+
preface = `以下为更新后的完整规则,替换此前的规则。\n\n${input.systemPrompt}`;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
for (const option of (opened?.configOptions ?? [])) {
|
|
409
|
+
const modelOption = isModelOption(option);
|
|
410
|
+
// A keyed model ID can be written by hand. Use the same client value as the launch config.
|
|
411
|
+
const configured = modelOption && selected ? prepared?.model ?? selected.model : input.options[option.id];
|
|
412
|
+
if (typeof configured !== 'string')
|
|
413
|
+
continue;
|
|
414
|
+
const wanted = modelOption && !selected ? configured.trim() : configured;
|
|
415
|
+
if (!wanted || wanted === option.currentValue)
|
|
416
|
+
continue;
|
|
417
|
+
const before = sessionModel;
|
|
418
|
+
try {
|
|
419
|
+
const updated = await started.request('session/set_config_option', { sessionId, configId: option.id, value: wanted }, 30_000);
|
|
420
|
+
const model = modelOf(updated);
|
|
421
|
+
if (model) {
|
|
422
|
+
sessionModel = { name: model };
|
|
423
|
+
if (modelOption)
|
|
424
|
+
configuredModel = model;
|
|
425
|
+
}
|
|
426
|
+
else if (modelOption && sessionModel === before)
|
|
427
|
+
sessionModel = { name: wanted };
|
|
428
|
+
}
|
|
429
|
+
catch (error) {
|
|
430
|
+
if (modelOption && error instanceof RpcFailure && acpFailure(client, error))
|
|
431
|
+
classify(error);
|
|
432
|
+
ctx.log(`could not set ${option.id}=${wanted}: ${host.errorText(error)}`);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
return sessionId;
|
|
436
|
+
},
|
|
437
|
+
send(input) {
|
|
438
|
+
const current = { id: input.turnId };
|
|
439
|
+
if (appendMode === 'supersede')
|
|
440
|
+
current.prompts = { sent: 0, pending: 0, tokens: {} };
|
|
441
|
+
turn = current;
|
|
442
|
+
const text = preface ? `${preface}\n\n---\n\n${input.text}` : input.text;
|
|
443
|
+
preface = undefined;
|
|
444
|
+
run(current, text, 0);
|
|
445
|
+
},
|
|
446
|
+
...(appendMode
|
|
447
|
+
? {
|
|
448
|
+
async append(input) {
|
|
449
|
+
const current = turn;
|
|
450
|
+
if (!current || current.id !== input.turnId || stopping)
|
|
451
|
+
throw new Error('这一轮现在不能追加');
|
|
452
|
+
if (current.retry)
|
|
453
|
+
throw new Error('这一轮正在等待重试');
|
|
454
|
+
if (current.prompts?.latest || current.prompts?.pending === 0)
|
|
455
|
+
throw new Error('这一轮现在不能追加');
|
|
456
|
+
run(current, input.text);
|
|
457
|
+
},
|
|
458
|
+
}
|
|
459
|
+
: {}),
|
|
460
|
+
async interrupt() {
|
|
461
|
+
if (!turn)
|
|
462
|
+
return;
|
|
463
|
+
if (turn.retry)
|
|
464
|
+
return end('canceled');
|
|
465
|
+
for (const requestId of asks.values())
|
|
466
|
+
peer.respond(requestId, { outcome: { outcome: 'cancelled' } });
|
|
467
|
+
asks.clear();
|
|
468
|
+
peer.notify('session/cancel', { sessionId });
|
|
469
|
+
},
|
|
470
|
+
answer(askId, optionId) {
|
|
471
|
+
const id = asks.get(askId);
|
|
472
|
+
if (id === undefined)
|
|
473
|
+
return;
|
|
474
|
+
asks.delete(askId);
|
|
475
|
+
peer.respond(id, { outcome: { outcome: 'selected', optionId } });
|
|
476
|
+
},
|
|
477
|
+
async stop({ force }) {
|
|
478
|
+
stopping = true;
|
|
479
|
+
if (peer) {
|
|
480
|
+
if (force)
|
|
481
|
+
await stopRpc(peer, true);
|
|
482
|
+
if (!force || temp)
|
|
483
|
+
await peer.child.stop();
|
|
484
|
+
}
|
|
485
|
+
end('canceled', '实例被停止');
|
|
486
|
+
release();
|
|
487
|
+
},
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
export function acpAdapter(host, client) {
|
|
491
|
+
const fixedCommand = client.command.trim();
|
|
492
|
+
const readOptions = async (env) => {
|
|
493
|
+
const cwd = tmpdir();
|
|
494
|
+
const peer = await connect(host.startChild, clientCommand(client, undefined, env), cwd, { env, onNotification() { }, onRequest: (id) => peer.reject(id, 'not available') });
|
|
495
|
+
try {
|
|
496
|
+
const created = await peer.request('session/new', { cwd, mcpServers: [] }, 120_000);
|
|
497
|
+
return (created.configOptions ?? []);
|
|
498
|
+
}
|
|
499
|
+
finally {
|
|
500
|
+
await stopRpc(peer, true);
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
const fields = (options, windows) => options.flatMap((o) => {
|
|
504
|
+
if (o.type !== 'select' || !Array.isArray(o.options))
|
|
505
|
+
return [];
|
|
506
|
+
const model = isModelOption(o);
|
|
507
|
+
const current = typeof o.currentValue === 'string' ? o.currentValue : '';
|
|
508
|
+
const choice = (value, label) => ({
|
|
509
|
+
value, label,
|
|
510
|
+
...(model ? { fill: modelWindowFill(windows?.get(value || current)) } : {}),
|
|
511
|
+
});
|
|
512
|
+
const choices = [
|
|
513
|
+
choice('', `跟随 ${client.title} 的默认(${o.currentValue ?? ''})`),
|
|
514
|
+
...o.options.flatMap((c) => 'options' in c ? c.options : [c]).map((c) => choice(c.value, c.name ?? c.value)),
|
|
515
|
+
];
|
|
516
|
+
return [{
|
|
517
|
+
key: o.id, label: o.name ?? o.id, kind: model ? 'string' : 'select', default: '',
|
|
518
|
+
...(model ? { suggestions: choices } : { options: choices }),
|
|
519
|
+
}];
|
|
520
|
+
});
|
|
521
|
+
return {
|
|
522
|
+
title: client.title,
|
|
523
|
+
memberTemplate: client.memberTemplate,
|
|
524
|
+
icon: client.icon,
|
|
525
|
+
...(fixedCommand ? { detect: () => detectCommand(fixedCommand, host) } : {}),
|
|
526
|
+
// ACP lists a client's models only in the answer to session/new, so this opens a throwaway session.
|
|
527
|
+
...(fixedCommand ? { command: commandText([client.command, ...client.args]) } : { requiresCommand: true }),
|
|
528
|
+
...(client.skillsDir ? { skillsDir: client.skillsDir } : {}),
|
|
529
|
+
append: Boolean(client.append),
|
|
530
|
+
...(client.keys ? { protocols: client.keys.protocols } : {}),
|
|
531
|
+
...(client.account ? { account: client.account } : {}),
|
|
532
|
+
...(client.quota ? { quota: client.quota } : {}),
|
|
533
|
+
...(client.quotaAccountEnv ? { quotaAccountEnv: client.quotaAccountEnv } : {}),
|
|
534
|
+
...(client.sessions
|
|
535
|
+
? {
|
|
536
|
+
async sessions(cwd, options, env) {
|
|
537
|
+
// The client keeps the real path of the directory a session was used in, and matches it exactly.
|
|
538
|
+
const dir = existsSync(cwd) ? realpathSync(cwd) : cwd;
|
|
539
|
+
const peer = await connect(host.startChild, clientCommand(client, options.command, env), tmpdir(), { env, onNotification() { }, onRequest: (id) => peer.reject(id, 'not available') });
|
|
540
|
+
try {
|
|
541
|
+
if (!peer.can.sessionCapabilities?.list)
|
|
542
|
+
throw new Error(`${client.title} 这个版本没有说它能列出会话`);
|
|
543
|
+
const found = [];
|
|
544
|
+
let cursor;
|
|
545
|
+
do {
|
|
546
|
+
const page = await peer.request('session/list', { cwd: dir, ...(cursor ? { cursor } : {}) }, 30_000);
|
|
547
|
+
for (const s of page?.sessions ?? []) {
|
|
548
|
+
if (typeof s?.sessionId !== 'string')
|
|
549
|
+
continue;
|
|
550
|
+
const extra = client.sessionMeta?.(s._meta ?? {});
|
|
551
|
+
if (extra === false)
|
|
552
|
+
continue;
|
|
553
|
+
const at = Date.parse(s.updatedAt);
|
|
554
|
+
found.push({
|
|
555
|
+
id: s.sessionId,
|
|
556
|
+
...(typeof s.title === 'string' && s.title ? { title: s.title } : {}),
|
|
557
|
+
...(typeof s.cwd === 'string' ? { cwd: s.cwd } : {}),
|
|
558
|
+
...(Number.isFinite(at) ? { updatedAt: at } : {}),
|
|
559
|
+
...extra,
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
cursor = typeof page?.nextCursor === 'string' && page.nextCursor ? page.nextCursor : undefined;
|
|
563
|
+
} while (cursor && found.length < 200);
|
|
564
|
+
return found;
|
|
565
|
+
}
|
|
566
|
+
finally {
|
|
567
|
+
await stopRpc(peer, true);
|
|
568
|
+
}
|
|
569
|
+
},
|
|
570
|
+
}
|
|
571
|
+
: {}),
|
|
572
|
+
async options(_fresh, key, env) {
|
|
573
|
+
if (!fixedCommand) {
|
|
574
|
+
const commandField = {
|
|
575
|
+
key: 'command',
|
|
576
|
+
label: { default: '启动命令', translations: { zh: '启动命令', en: 'Launch command' } },
|
|
577
|
+
description: {
|
|
578
|
+
default: '启动这个 ACP 客户端的完整命令行,例如 goose acp 或 /opt/bin/my-acp --stdio。',
|
|
579
|
+
translations: {
|
|
580
|
+
zh: '启动这个 ACP 客户端的完整命令行,例如 goose acp 或 /opt/bin/my-acp --stdio。',
|
|
581
|
+
en: 'Full command line to start this ACP client, such as goose acp or /opt/bin/my-acp --stdio.',
|
|
582
|
+
},
|
|
583
|
+
},
|
|
584
|
+
kind: 'string',
|
|
585
|
+
required: true,
|
|
586
|
+
};
|
|
587
|
+
const modelField = {
|
|
588
|
+
key: 'model',
|
|
589
|
+
label: { default: '模型', translations: { zh: '模型', en: 'Model' } },
|
|
590
|
+
description: {
|
|
591
|
+
default: '留空使用客户端默认模型,或直接填写模型 ID。',
|
|
592
|
+
translations: {
|
|
593
|
+
zh: '留空使用客户端默认模型,或直接填写模型 ID。',
|
|
594
|
+
en: 'Leave blank for the client default, or enter a model ID directly.',
|
|
595
|
+
},
|
|
596
|
+
},
|
|
597
|
+
kind: 'string',
|
|
598
|
+
default: '',
|
|
599
|
+
};
|
|
600
|
+
const appendField = {
|
|
601
|
+
key: 'append',
|
|
602
|
+
label: { default: '支持回合中追加', translations: { zh: '支持回合中追加', en: 'Supports appending during a turn' } },
|
|
603
|
+
description: {
|
|
604
|
+
default: '实测确认回合进行中再发 prompt 会并入当前轮时才开启。',
|
|
605
|
+
translations: {
|
|
606
|
+
zh: '实测确认回合进行中再发 prompt 会并入当前轮时才开启。',
|
|
607
|
+
en: 'Enable only after verifying that prompts sent during a turn join the current turn.',
|
|
608
|
+
},
|
|
609
|
+
},
|
|
610
|
+
kind: 'boolean',
|
|
611
|
+
default: false,
|
|
612
|
+
};
|
|
613
|
+
const cacheField = {
|
|
614
|
+
key: 'inputExcludesCache',
|
|
615
|
+
label: { default: 'inputTokens 不含缓存', translations: { zh: 'inputTokens 不含缓存', en: 'inputTokens excludes cache' } },
|
|
616
|
+
description: {
|
|
617
|
+
default: '仅当客户端报告的 inputTokens 不含缓存读取和写入时开启。',
|
|
618
|
+
translations: {
|
|
619
|
+
zh: '仅当客户端报告的 inputTokens 不含缓存读取和写入时开启。',
|
|
620
|
+
en: 'Enable only when the client’s reported inputTokens exclude cache reads and writes.',
|
|
621
|
+
},
|
|
622
|
+
},
|
|
623
|
+
kind: 'boolean',
|
|
624
|
+
default: false,
|
|
625
|
+
};
|
|
626
|
+
return [commandField, modelField, contextWindowOption(false), appendField, cacheField];
|
|
627
|
+
}
|
|
628
|
+
if (!key || !client.keys) {
|
|
629
|
+
const window = contextWindowOption(false);
|
|
630
|
+
const [localOptions, windows] = await Promise.all([
|
|
631
|
+
readOptions(env),
|
|
632
|
+
client.modelWindows
|
|
633
|
+
? client.modelWindows(env).catch(() => {
|
|
634
|
+
window.error = `无法读取 ${client.title} 的模型窗口目录`;
|
|
635
|
+
return undefined;
|
|
636
|
+
})
|
|
637
|
+
: undefined,
|
|
638
|
+
]);
|
|
639
|
+
const result = fields(localOptions, windows);
|
|
640
|
+
result.splice(result.findIndex((option) => option.key === 'model' || option.kind === 'string') + 1, 0, window);
|
|
641
|
+
return result;
|
|
642
|
+
}
|
|
643
|
+
const [[model, window], options] = await Promise.all([
|
|
644
|
+
keyedOptions(key, contextWindowOption(client.keys.contextWindow === true), client.keys.value),
|
|
645
|
+
readOptions().catch((error) => ({ error: `读取客户端选项失败:${host.errorText(error)}` })),
|
|
646
|
+
]);
|
|
647
|
+
if (!Array.isArray(options)) {
|
|
648
|
+
model.error = model.error ? `${model.error}\n${options.error}` : options.error;
|
|
649
|
+
return [model, window];
|
|
650
|
+
}
|
|
651
|
+
return [model, window, ...fields(options.filter((option) => !isModelOption(option)))];
|
|
652
|
+
},
|
|
653
|
+
applies: { tools: 'restart', prompt: 'restart', model: 'restart', options: 'restart' },
|
|
654
|
+
open: (ctx) => open(host, client, ctx),
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
const ACP_CAUTION = '关掉后,用它的成员正在跑的回合会跑完再结束实例,空闲实例立即结束;这些成员也收不到新消息了。';
|
|
658
|
+
/**
|
|
659
|
+
* One ACP client as its own plugin: the protocol code is shared, what differs per client (how it is started,
|
|
660
|
+
* what it does with input while it works) is stated where the client is declared, from what was measured.
|
|
661
|
+
*/
|
|
662
|
+
export function acpClientPlugin(host, client, about) {
|
|
663
|
+
return {
|
|
664
|
+
name: `adapter-${client.id}`,
|
|
665
|
+
title: client.title,
|
|
666
|
+
about,
|
|
667
|
+
group: '客户端',
|
|
668
|
+
caution: ACP_CAUTION,
|
|
669
|
+
needs: ['instances'],
|
|
670
|
+
start(ctx) {
|
|
671
|
+
ctx.effect(ctx.get('instances').registerAdapter(client.id, acpAdapter(host, client)));
|
|
672
|
+
},
|
|
673
|
+
};
|
|
674
|
+
}
|