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,458 @@
|
|
|
1
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
+
import { basename, join } from 'node:path';
|
|
3
|
+
import { address, ArgsError, check, HANDLED, HttpError, log, memberInput, object, operationErrorText, OWNER_ID, referenceMark, findMentions, messageGist, requireTopic, withExcerpts, withFiles, } from 'hostlet/sdk';
|
|
4
|
+
import { createMcpTokenAuthority } from "./token.js";
|
|
5
|
+
const KEY_ROTATION_CHECK_MS = 6 * 3_600_000;
|
|
6
|
+
export function toolsPlugin(home) {
|
|
7
|
+
return {
|
|
8
|
+
name: 'tools',
|
|
9
|
+
title: '成员工具',
|
|
10
|
+
about: '通过 MCP 给成员的工具:读和发消息、查平台现状和发生过什么。每个插件的工具是它自己的一组。',
|
|
11
|
+
group: '给成员的工具',
|
|
12
|
+
needs: ['entry', 'store', 'members', 'topics', 'messages', 'instances', 'a2a'],
|
|
13
|
+
start(ctx) {
|
|
14
|
+
const entry = ctx.get('entry');
|
|
15
|
+
const { db } = ctx.get('store');
|
|
16
|
+
const members = ctx.get('members');
|
|
17
|
+
const topics = ctx.get('topics');
|
|
18
|
+
const messages = ctx.get('messages');
|
|
19
|
+
const a2a = ctx.get('a2a');
|
|
20
|
+
const registry = new Map();
|
|
21
|
+
const mounted = new Map();
|
|
22
|
+
const authority = createMcpTokenAuthority(home);
|
|
23
|
+
const cachedTokens = new Map();
|
|
24
|
+
const probeTokens = new Set();
|
|
25
|
+
const rotationTimer = setInterval(() => {
|
|
26
|
+
try {
|
|
27
|
+
authority.ensureFresh();
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
ctx.runtime.onError('tools mcp key rotation', error);
|
|
31
|
+
}
|
|
32
|
+
}, KEY_ROTATION_CHECK_MS);
|
|
33
|
+
rotationTimer.unref();
|
|
34
|
+
ctx.effect(() => clearInterval(rotationTimer));
|
|
35
|
+
const declared = () => entry.ops().ops.filter((op) => op.agent === true && op.tool);
|
|
36
|
+
const rejectMounted = (server) => {
|
|
37
|
+
if (mounted.has(server))
|
|
38
|
+
throw new Error(`MCP server already mounted: ${server}`);
|
|
39
|
+
};
|
|
40
|
+
// Check both registration orders at the declaration boundary without coupling entry to MCP.
|
|
41
|
+
const declare = entry.op;
|
|
42
|
+
entry.op = (op) => {
|
|
43
|
+
if (op.agent === true && op.tool)
|
|
44
|
+
rejectMounted(op.tool.server);
|
|
45
|
+
return declare(op);
|
|
46
|
+
};
|
|
47
|
+
ctx.effect(() => { entry.op = declare; });
|
|
48
|
+
const sourceOf = (server, plugin, isCoreOp = false) => {
|
|
49
|
+
const name = plugin ?? (isCoreOp ? undefined : ctx.runtime.list().find((p) => p.name === server)?.name);
|
|
50
|
+
if (name) {
|
|
51
|
+
const info = ctx.runtime.list().find((p) => p.name === name);
|
|
52
|
+
return { plugin: name, title: info?.title ?? name };
|
|
53
|
+
}
|
|
54
|
+
return isCoreOp ? { core: true, title: '宿主核心' } : { title: server };
|
|
55
|
+
};
|
|
56
|
+
/** The tools of a group: the operations declared as its tools, then what plugins registered. */
|
|
57
|
+
const groupOf = (server, ops = declared()) => new Map([
|
|
58
|
+
...ops.filter((op) => op.tool.server === server).map((op) => ({
|
|
59
|
+
owner: op.plugin,
|
|
60
|
+
coreOp: !op.plugin && !op.tool.plugin,
|
|
61
|
+
tool: {
|
|
62
|
+
name: op.tool.name,
|
|
63
|
+
description: op.about,
|
|
64
|
+
input: memberInput(op.input, op),
|
|
65
|
+
plugin: op.plugin ?? op.tool.plugin,
|
|
66
|
+
run: (args, caller) => entry.say(op.name, args, caller),
|
|
67
|
+
},
|
|
68
|
+
})),
|
|
69
|
+
...(registry.get(server)?.values() ?? []),
|
|
70
|
+
].map((registered) => [registered.tool.name, registered]));
|
|
71
|
+
const names = (ops = declared()) => [...new Set([...registry.keys(), ...ops.map((op) => op.tool.server), ...mounted.keys()])];
|
|
72
|
+
const allowed = (topicId, registration) => topics.pluginEnabled(topicId, registration.owner);
|
|
73
|
+
const visible = (group, topicId) => [...group.values()].filter((registered) => allowed(topicId, registered));
|
|
74
|
+
const hasVisibleTools = (server, topicId, ops = declared()) => {
|
|
75
|
+
const mount = mounted.get(server);
|
|
76
|
+
return mount ? allowed(topicId, mount) : visible(groupOf(server, ops), topicId).length > 0;
|
|
77
|
+
};
|
|
78
|
+
const register = (server, tool, owner = tool.plugin) => {
|
|
79
|
+
rejectMounted(server);
|
|
80
|
+
const group = registry.get(server) ?? new Map();
|
|
81
|
+
registry.set(server, group);
|
|
82
|
+
const { name } = tool;
|
|
83
|
+
if (group.has(name))
|
|
84
|
+
throw new Error(`tool already registered: ${server}.${name}`);
|
|
85
|
+
group.set(name, { tool, owner, local: true });
|
|
86
|
+
return () => {
|
|
87
|
+
group.delete(name);
|
|
88
|
+
if (!group.size)
|
|
89
|
+
registry.delete(server);
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
const mount = (server, handler, owner = handler.plugin) => {
|
|
93
|
+
if (names().includes(server))
|
|
94
|
+
throw new Error(`MCP server already registered: ${server}`);
|
|
95
|
+
mounted.set(server, { handler, owner });
|
|
96
|
+
return () => { mounted.delete(server); };
|
|
97
|
+
};
|
|
98
|
+
// What happened on the platform, kept so a member can ask afterwards.
|
|
99
|
+
db.exec('CREATE TABLE IF NOT EXISTS journal (id INTEGER PRIMARY KEY AUTOINCREMENT, at INTEGER NOT NULL, type TEXT NOT NULL, summary TEXT NOT NULL)');
|
|
100
|
+
const note = (type, summary) => db.prepare('INSERT INTO journal (at, type, summary) VALUES (?, ?, ?)').run(Date.now(), type, summary);
|
|
101
|
+
const tools = {
|
|
102
|
+
register,
|
|
103
|
+
mount,
|
|
104
|
+
servers(topicId) {
|
|
105
|
+
const ops = declared();
|
|
106
|
+
return names(ops).flatMap((server) => {
|
|
107
|
+
const mountedGroup = mounted.get(server);
|
|
108
|
+
const group = mountedGroup ? [] : visible(groupOf(server, ops), topicId);
|
|
109
|
+
if (mountedGroup ? !allowed(topicId, mountedGroup) : !group.length)
|
|
110
|
+
return [];
|
|
111
|
+
const list = mountedGroup
|
|
112
|
+
? (mountedGroup.handler.tools?.() ?? []).map(({ name, description, inputSchema }) => ({
|
|
113
|
+
name, description, inputSchema: inputSchema ?? {}, source: sourceOf(server, mountedGroup.owner),
|
|
114
|
+
}))
|
|
115
|
+
: group.map(({ tool: { name, description, input, plugin }, owner, coreOp }) => ({
|
|
116
|
+
name, description, inputSchema: input, source: sourceOf(server, owner ?? plugin, coreOp),
|
|
117
|
+
}));
|
|
118
|
+
return [{ server, url: `${entry.url}/mcp/${server}`, tools: list }];
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
async probe(server) {
|
|
122
|
+
if (!names().includes(server))
|
|
123
|
+
throw new HttpError(404, '没有这个服务');
|
|
124
|
+
const token = randomBytes(18).toString('base64url');
|
|
125
|
+
probeTokens.add(token);
|
|
126
|
+
const url = `${entry.url}/mcp/${server}`;
|
|
127
|
+
const call = async (method, params, id) => {
|
|
128
|
+
const res = await fetch(url, {
|
|
129
|
+
method: 'POST', signal: AbortSignal.timeout(10_000),
|
|
130
|
+
headers: { 'content-type': 'application/json', authorization: `Bearer ${token}` },
|
|
131
|
+
body: JSON.stringify({ jsonrpc: '2.0', ...(id ? { id } : {}), method, params }),
|
|
132
|
+
});
|
|
133
|
+
if (!res.ok)
|
|
134
|
+
throw new Error(`${res.status} ${res.statusText}`);
|
|
135
|
+
if (!id)
|
|
136
|
+
return undefined;
|
|
137
|
+
const message = await res.json();
|
|
138
|
+
if (message.error)
|
|
139
|
+
throw new Error(message.error.message ?? '服务报错');
|
|
140
|
+
return message.result;
|
|
141
|
+
};
|
|
142
|
+
try {
|
|
143
|
+
await call('initialize', { protocolVersion: '2025-03-26', capabilities: {}, clientInfo: { name: 'hostlet-probe', version: '0.1.0' } }, 1);
|
|
144
|
+
await call('notifications/initialized', {});
|
|
145
|
+
const result = await call('tools/list', {}, 2);
|
|
146
|
+
return (Array.isArray(result?.tools) ? result.tools : []).map((t) => ({
|
|
147
|
+
name: String(t.name),
|
|
148
|
+
description: String(t.description ?? ''),
|
|
149
|
+
...(t.inputSchema && typeof t.inputSchema === 'object' ? { inputSchema: t.inputSchema } : {}),
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
probeTokens.delete(token);
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
recordEvent: note,
|
|
157
|
+
};
|
|
158
|
+
ctx.provide('tools', tools, ({ name }) => ({
|
|
159
|
+
...tools,
|
|
160
|
+
register: (server, tool) => register(server, tool, name),
|
|
161
|
+
mount: (server, handler) => mount(server, handler, name),
|
|
162
|
+
}));
|
|
163
|
+
const enabledServers = (topicId, ops = declared()) => names(ops)
|
|
164
|
+
.filter((server) => topics.uses(topicId, `tools:${server}`, true) && hasVisibleTools(server, topicId, ops)).sort();
|
|
165
|
+
// One cached signed token per (topic, member) while backed by the current key version.
|
|
166
|
+
const serversFor = (topicId, member) => {
|
|
167
|
+
const servers = enabledServers(topicId);
|
|
168
|
+
if (!servers.length)
|
|
169
|
+
return [];
|
|
170
|
+
const pair = `${topicId}:${member.id}`;
|
|
171
|
+
let issued = cachedTokens.get(pair);
|
|
172
|
+
if (!issued || !authority.isCurrent(issued)) {
|
|
173
|
+
issued = authority.issue(topicId, member.id);
|
|
174
|
+
cachedTokens.set(pair, issued);
|
|
175
|
+
}
|
|
176
|
+
return servers.map((server) => ({
|
|
177
|
+
name: server, url: `${entry.url}/mcp/${server}`,
|
|
178
|
+
headers: { Authorization: `Bearer ${issued.token}` },
|
|
179
|
+
}));
|
|
180
|
+
};
|
|
181
|
+
ctx.note('session.mcp', { title: '平台自己的工具组,每组一个 MCP 地址', when: '这个主题启用的工具组。每次调用带着一个持久签名 token(HTTP header),说明是哪个主题、哪个成员,调用按它归属。' });
|
|
182
|
+
ctx.hook('session.mcp', ({ topicId, member }) => serversFor(topicId, member));
|
|
183
|
+
// A stable endpoint can gain or lose local tools without changing its URL.
|
|
184
|
+
// Remote handlers manage their own catalogue; probing them is never part of session startup.
|
|
185
|
+
ctx.note('session.input', { title: '已启用工具组中的本地工具声明和主题插件开关', when: '在工具、参数或有效插件开关变化后按客户端策略刷新' });
|
|
186
|
+
ctx.hook('session.input', ({ topicId }) => {
|
|
187
|
+
const ops = declared();
|
|
188
|
+
const catalogue = enabledServers(topicId, ops).filter((server) => !mounted.has(server)).map((server) => [
|
|
189
|
+
server, visible(groupOf(server, ops), topicId).map(({ tool }) => tool).sort((a, b) => a.name.localeCompare(b.name))
|
|
190
|
+
.map(({ name, description, input }) => [name, description, input]),
|
|
191
|
+
]);
|
|
192
|
+
const switches = new Set(topics.path(topicId).flatMap(({ caps }) => Object.keys(caps)));
|
|
193
|
+
const disabled = [...switches].filter((key) => key.startsWith('plugin:') && !topics.pluginEnabled(topicId, key.slice('plugin:'.length))).sort();
|
|
194
|
+
return { tools: createHash('sha256').update(JSON.stringify(disabled.length ? { catalogue, disabled } : catalogue)).digest('hex') };
|
|
195
|
+
});
|
|
196
|
+
ctx.hook('topic.caps', ({ topicId }) => {
|
|
197
|
+
const ops = declared();
|
|
198
|
+
return tools.servers().map(({ server, tools: list }) => ({
|
|
199
|
+
id: `tools:${server}`, title: server, about: list.map((t) => t.name).join('、'), group: '平台工具', default: true,
|
|
200
|
+
...(!hasVisibleTools(server, topicId, ops) ? { blockedByPlugin: true } : {}),
|
|
201
|
+
}));
|
|
202
|
+
});
|
|
203
|
+
// Streamable HTTP without a stream: answers are plain JSON, so a client asking to open one is told no.
|
|
204
|
+
ctx.effect(entry.route('GET', '/mcp/:server', ({ res }) => {
|
|
205
|
+
res.writeHead(405, { allow: 'POST' }).end();
|
|
206
|
+
return HANDLED;
|
|
207
|
+
}));
|
|
208
|
+
ctx.effect(entry.route('POST', '/mcp/:server', async ({ params, body, raw, res }) => {
|
|
209
|
+
const bearer = /^Bearer (.+)$/i.exec(raw.headers.authorization ?? '')?.[1] ?? '';
|
|
210
|
+
const probing = probeTokens.has(bearer);
|
|
211
|
+
const verified = probing || !bearer ? undefined : authority.verify(bearer);
|
|
212
|
+
const who = verified?.ok ? verified.payload : undefined;
|
|
213
|
+
const member = who ? members.get(who.memberId) : undefined;
|
|
214
|
+
const topic = who ? topics.get(who.topicId) : undefined;
|
|
215
|
+
// (Not 401: a client that is told so goes looking for a login, and there is none.)
|
|
216
|
+
if (!probing && !who) {
|
|
217
|
+
const reason = !raw.headers.authorization ? 'no token'
|
|
218
|
+
: verified && !verified.ok && verified.reason === 'expired' ? 'expired token' : 'invalid token';
|
|
219
|
+
log('mcp', `${params.server} ${body?.method ?? ''} refused: ${reason}`);
|
|
220
|
+
throw new HttpError(403, '宿主的工具要带着宿主给这个实例的 token 调(Authorization: Bearer …)');
|
|
221
|
+
}
|
|
222
|
+
if (who && (!member || member.kind !== 'agent' || !member.enabled)) {
|
|
223
|
+
log('mcp', `${params.server} ${body?.method ?? ''} refused: ${member ? `disabled member ${member.handle}` : `unknown member ${who.memberId}`}`);
|
|
224
|
+
throw new HttpError(403, '这个成员已停用或不存在');
|
|
225
|
+
}
|
|
226
|
+
if (who && !topic) {
|
|
227
|
+
log('mcp', `${params.server} ${body?.method ?? ''} refused: unknown topic ${who.topicId}`);
|
|
228
|
+
throw new HttpError(403, '这个主题不存在');
|
|
229
|
+
}
|
|
230
|
+
const server = params.server;
|
|
231
|
+
const ops = declared();
|
|
232
|
+
if (!names(ops).includes(server))
|
|
233
|
+
throw new HttpError(404, 'unknown MCP address');
|
|
234
|
+
if (who && !topics.uses(who.topicId, `tools:${server}`, true))
|
|
235
|
+
throw new HttpError(403, '这个主题已停用此工具组');
|
|
236
|
+
if (who && !hasVisibleTools(server, who.topicId, ops))
|
|
237
|
+
throw new HttpError(403, '此工具组所属插件已在本主题关闭');
|
|
238
|
+
if (probing && (Array.isArray(body) ? body : [body]).some((message) => message?.method === 'tools/call')) {
|
|
239
|
+
throw new HttpError(403, '探测令牌只能读取工具清单,不能调用工具');
|
|
240
|
+
}
|
|
241
|
+
log('mcp', `${server} ${body?.method ?? 'batch'}${body?.params?.name ? ` ${body.params.name}` : ''} from ${probing ? 'probe' : member.handle}`);
|
|
242
|
+
const handler = mounted.get(server)?.handler;
|
|
243
|
+
const accept = () => {
|
|
244
|
+
res.writeHead(202).end();
|
|
245
|
+
return HANDLED;
|
|
246
|
+
};
|
|
247
|
+
if (handler) {
|
|
248
|
+
const version = raw.headers['mcp-protocol-version'];
|
|
249
|
+
const response = await handler.handle(body, who && { topicId: who.topicId, member: member }, typeof version === 'string' ? { protocolVersion: version } : {});
|
|
250
|
+
const notification = typeof body?.method === 'string' && body.id === undefined;
|
|
251
|
+
return notification || response === undefined ? accept() : response;
|
|
252
|
+
}
|
|
253
|
+
const group = groupOf(server, ops);
|
|
254
|
+
if (body.id === undefined) {
|
|
255
|
+
return accept();
|
|
256
|
+
}
|
|
257
|
+
const reply = (result) => ({ jsonrpc: '2.0', id: body.id, result });
|
|
258
|
+
switch (body.method) {
|
|
259
|
+
case 'initialize':
|
|
260
|
+
return reply({ protocolVersion: body.params?.protocolVersion ?? '2025-03-26', capabilities: { tools: {} }, serverInfo: { name: `hostlet-${params.server}`, version: '0.1.0' } });
|
|
261
|
+
case 'tools/list':
|
|
262
|
+
return reply({ tools: visible(group, who?.topicId).map(({ tool }) => ({ name: tool.name, description: tool.description, inputSchema: tool.input })) });
|
|
263
|
+
case 'tools/call': {
|
|
264
|
+
const name = body.params?.name;
|
|
265
|
+
const registered = group.get(name);
|
|
266
|
+
if (!registered)
|
|
267
|
+
return reply({ isError: true, content: [{ type: 'text', text: `no such tool: ${name}` }] });
|
|
268
|
+
if (!allowed(who?.topicId, registered))
|
|
269
|
+
throw new HttpError(403, '此工具所属插件已在本主题关闭');
|
|
270
|
+
const { tool, local } = registered;
|
|
271
|
+
try {
|
|
272
|
+
const args = body.params?.arguments === undefined ? {} : body.params.arguments;
|
|
273
|
+
if (local) {
|
|
274
|
+
const problem = check(tool.input, args, '', true);
|
|
275
|
+
if (problem)
|
|
276
|
+
throw new ArgsError(tool.description ? `${problem}\n${tool.description}` : problem);
|
|
277
|
+
}
|
|
278
|
+
const result = await tool.run(args, { topicId: who.topicId, member: member });
|
|
279
|
+
return reply({ content: [{ type: 'text', text: typeof result === 'string' ? result : JSON.stringify(result, null, 2) }] });
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
return reply({ isError: true, content: [{ type: 'text', text: operationErrorText(error) }] });
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
case 'ping':
|
|
286
|
+
return reply({});
|
|
287
|
+
default:
|
|
288
|
+
return { jsonrpc: '2.0', id: body.id, error: { code: -32601, message: `method not found: ${body.method}` } };
|
|
289
|
+
}
|
|
290
|
+
}));
|
|
291
|
+
ctx.on('config.changed', ({ scope, key }) => note('config', key ? `${scope} 的 ${key} 被修改` : `${scope} 被手动修改`));
|
|
292
|
+
ctx.on('members.changed', ({ id, removed }) => note('members', removed ? `成员 ${id} 被移除` : `成员 ${members.get(id)?.name ?? id} 被添加或修改`));
|
|
293
|
+
note('host', '宿主启动');
|
|
294
|
+
const nameOf = (from) => from.kind === 'member' ? (members.get(from.id)?.name ?? from.id) : from.kind === 'system' ? '系统' : from.id;
|
|
295
|
+
const terminalNote = (m) => {
|
|
296
|
+
if (!m.terminal)
|
|
297
|
+
return '';
|
|
298
|
+
const reason = m.terminal.reason?.slice(0, 300);
|
|
299
|
+
if (m.terminal.status === 'failed')
|
|
300
|
+
return `(这一轮失败了,没有做完${reason ? `:${reason}` : ''})`;
|
|
301
|
+
return `(这一轮已取消${reason ? `:${reason}` : ''})`;
|
|
302
|
+
};
|
|
303
|
+
const line = (m) => `#${m.seq}(${m.id}${m.thread ? `,在 ${m.thread} 那一楼里` : ''}${m.replyTo ? `,回复 ${m.replyTo}` : ''})[${new Date(m.createdAt).toLocaleString()}] ${nameOf(m.from)}${referenceMark(m)}: ${withExcerpts(m, withFiles(m, topics.get(m.topicId)?.dir ?? '') + terminalNote(m))}`;
|
|
304
|
+
const floorOf = (m) => m.thread ?? ((m.threadable ?? m.from.kind === 'member') ? m.id : undefined);
|
|
305
|
+
const core = (tool) => ctx.effect(tools.register('hostlet', { ...tool, plugin: 'tools' }));
|
|
306
|
+
core({
|
|
307
|
+
name: 'topic_read',
|
|
308
|
+
description: '读当前主题的消息,每条开头的 #数字 是它的序号,括号里是它的编号,以及它在哪一楼里、回复的是哪条(有的话)。不带参数是最近 20 条;after 是从这个序号之后往后读,before 是这个序号之前的;thread 只读指定楼。读到的消息里发给你的,只有属于当前楼(或当前没有回合)才算你读过。连续读完当前楼才算看过这段楼内背景。历史也在主题目录的 channel.jsonl 里,可以直接 grep。',
|
|
309
|
+
input: object({
|
|
310
|
+
limit: { type: 'number' }, after: { type: 'number', description: '从这个序号之后往后读' }, before: { type: 'number', description: '只要这个序号之前的' },
|
|
311
|
+
thread: { type: 'string', description: '只读指定楼(楼主消息编号 msg_…)' },
|
|
312
|
+
}),
|
|
313
|
+
run({ limit = 20, after, before, thread }, { topicId, member }) {
|
|
314
|
+
const page = messages.forMember(member.id).page(topicId, {
|
|
315
|
+
limit: Math.min(limit, 100),
|
|
316
|
+
...(thread !== undefined ? { thread } : {}),
|
|
317
|
+
...(after !== undefined ? { after } : before !== undefined ? { before } : {}),
|
|
318
|
+
});
|
|
319
|
+
const live = a2a.live(topicId).find((turn) => turn.memberId === member.id);
|
|
320
|
+
for (const message of page)
|
|
321
|
+
if (message.to.includes(member.id) && (!live || floorOf(message) === live.thread))
|
|
322
|
+
a2a.markRead(topicId, member.id, message.id);
|
|
323
|
+
if (thread !== undefined)
|
|
324
|
+
a2a.markCovered(topicId, member.id, thread, page);
|
|
325
|
+
return page.map(line).join('\n\n') || '(没有消息)';
|
|
326
|
+
},
|
|
327
|
+
});
|
|
328
|
+
core({
|
|
329
|
+
name: 'message_get',
|
|
330
|
+
description: '按编号读消息的全文,一次可以读几条(任何主题的都行)。其他主题的消息只读、不消耗待读;当前主题里读了的每一条,只有属于当前楼(或当前没有回合)才算你读过。',
|
|
331
|
+
input: object({ ids: { type: 'array', items: { type: 'string' } } }, ['ids']),
|
|
332
|
+
run({ ids }, { topicId, member }) {
|
|
333
|
+
const history = messages.forMember(member.id);
|
|
334
|
+
return ids.map((id) => {
|
|
335
|
+
const message = history.get(id, { includeDeleted: true });
|
|
336
|
+
if (!message || message.seq === null)
|
|
337
|
+
return `${id}:没有这条消息`;
|
|
338
|
+
if (message.deletedAt !== undefined)
|
|
339
|
+
return `${message.id}:这条消息已删除`;
|
|
340
|
+
const live = message.topicId === topicId ? a2a.live(topicId).find((turn) => turn.memberId === member.id) : undefined;
|
|
341
|
+
if (message.topicId === topicId && (!live || floorOf(message) === live.thread))
|
|
342
|
+
a2a.markRead(topicId, member.id, message.id);
|
|
343
|
+
return line(message);
|
|
344
|
+
}).join('\n\n');
|
|
345
|
+
},
|
|
346
|
+
});
|
|
347
|
+
const calls = (sent) => (sent.targets.length ? `,并叫了 ${sent.targets.map((id) => members.get(id)?.name ?? id).join('、')}` : '');
|
|
348
|
+
core({
|
|
349
|
+
name: 'post_message',
|
|
350
|
+
description: '在当前主题里另发一条消息。带 replyTo 时进被回消息的楼,若它在主线就以它开楼。若本轮已读过这条,就由这次回复认领它。省略 replyTo 时在主线平级新开话题。需要另一位成员继续处理或请机主确认时,用 targets 指定收件人,正文写清要求。省略 targets 时兼容行首 @;空名单只留知会。单纯知会可直接写在本轮正文。本轮应给出的答复都已发出时,最终只输出一行 NO_REPLY。叫另一位成员算一层接力,超出深度上限时返回错误。要发到别的主题,用 post_to_topic。',
|
|
351
|
+
input: object({
|
|
352
|
+
content: { type: 'string' },
|
|
353
|
+
replyTo: { type: 'string', description: '要回复的消息编号(当前主题里的 msg_…)。省略时在主线平级发新话题' },
|
|
354
|
+
targets: { type: 'array', items: { type: 'string' }, description: '收件人的成员 ID 或句柄,句柄可带 @。填空数组时只发知会,省略时按正文行首 @ 投递。显式指定但无人可接收时会报错。' },
|
|
355
|
+
}, ['content']),
|
|
356
|
+
run({ content, replyTo, targets }, { topicId: here, member }) {
|
|
357
|
+
const byHandle = targets?.length
|
|
358
|
+
? new Map([...members.list(), ...members.people()].map(({ id, handle }) => [handle.toLowerCase(), id]))
|
|
359
|
+
: undefined;
|
|
360
|
+
const sent = a2a.send({
|
|
361
|
+
topicId: here, from: { kind: 'member', id: member.id }, content, replyTo,
|
|
362
|
+
targets: targets?.map((target) => members.get(target)?.id ?? byHandle?.get(target.replace(/^@/, '').toLowerCase()) ?? target),
|
|
363
|
+
requireRecipient: Boolean(targets?.length),
|
|
364
|
+
});
|
|
365
|
+
const { id, thread, read } = sent.message;
|
|
366
|
+
if (!thread)
|
|
367
|
+
return `已在主线平级发出(${id})${calls(sent)}。不影响本轮原楼回复。`;
|
|
368
|
+
const head = messages.forMember(member.id).get(thread);
|
|
369
|
+
const excerpt = head && messageGist(head).replace(/\s+/g, ' ').trim().slice(0, 60);
|
|
370
|
+
const floor = excerpt ? `「${excerpt}」那一楼(${thread})` : `${thread} 那一楼`;
|
|
371
|
+
const remaining = a2a.live(here).find((turn) => turn.memberId === member.id)?.read.length;
|
|
372
|
+
return `已发到${floor},消息 ${id}${calls(sent)}。` +
|
|
373
|
+
(read.length ? `已认领 ${read[0]}。` : '') +
|
|
374
|
+
(remaining === undefined ? '' : `本轮剩余未认领消息 ${remaining} 条。`) +
|
|
375
|
+
(remaining === 0 ? '如无补充请直接输出 NO_REPLY。' : '');
|
|
376
|
+
},
|
|
377
|
+
});
|
|
378
|
+
ctx.effect(entry.op({
|
|
379
|
+
name: 'channel.relay',
|
|
380
|
+
about: '把工作发到对应主题,正文直接写任务和必要背景。行首用 @名字 指定收件人,自己跨主题接手时单独一行写自己的 @handle,收到后直接办理,无需回复确认。普通交办和附原消息的转发未点名时,依次找目标主题默认成员、全局默认成员、能在目标主题接手的发送成员。无人可接会退回。完整正文保存在目标主题,当前主题留下回执。成员间投递计入接力深度,发给人的消息不受此限制。',
|
|
381
|
+
http: ['POST', '/api/topics/:topicId/relay'], agent: true, topic: 'fromTopic',
|
|
382
|
+
tool: { server: 'hostlet', name: 'post_to_topic', plugin: 'tools' },
|
|
383
|
+
input: object({
|
|
384
|
+
topicId: { type: 'string', description: '发到哪个主题(主题编号 top_…,topic_tree 里有)' },
|
|
385
|
+
fromTopic: { type: 'string', description: '投递的来源主题' },
|
|
386
|
+
fromThread: { type: 'string', description: '回执落在来源主题的哪栋楼(楼主消息编号)。成员在回合里投递不用填,回执随本轮回复' },
|
|
387
|
+
content: { type: 'string', description: '交接正文。转发原消息时可填写说明,行首 @ 可选收件人。说明留空或未点名时按跨主题默认规则投递。' },
|
|
388
|
+
messageIds: { type: 'array', items: { type: 'string' }, minItems: 1, description: '转发来源主题里的消息。宿主按时间整理摘录和原地址' },
|
|
389
|
+
summary: { type: 'string', description: '目标主题要处理的事,留在当前主题的回执中,最多保留 120 字,省略时取正文首句摘录' },
|
|
390
|
+
outsideSource: { type: 'boolean', description: '要求目标在来源主题的子树以外。交接后会归档来源时填 true' },
|
|
391
|
+
}, ['topicId', 'fromTopic', 'content']),
|
|
392
|
+
run({ topicId, fromTopic, fromThread, content, messageIds, summary, outsideSource }, caller) {
|
|
393
|
+
if (!topicId)
|
|
394
|
+
throw new Error('要说发到哪个主题(topicId)');
|
|
395
|
+
if (topicId === fromTopic)
|
|
396
|
+
throw new Error('这就是你所在的主题:在这里发用 post_message,或直接写在回复里。');
|
|
397
|
+
requireTopic(topics, fromTopic);
|
|
398
|
+
if (outsideSource && topics.path(topicId).some((topic) => topic.id === fromTopic)) {
|
|
399
|
+
throw new HttpError(409, '目标仍在来源主题的子树内');
|
|
400
|
+
}
|
|
401
|
+
const memberId = caller.member?.id ?? OWNER_ID;
|
|
402
|
+
let targets;
|
|
403
|
+
if (messageIds) {
|
|
404
|
+
if (!messageIds.length)
|
|
405
|
+
throw new ArgsError('至少选择一条消息');
|
|
406
|
+
const history = messages.forMember(memberId);
|
|
407
|
+
const selected = [...new Set(messageIds)].map((id) => {
|
|
408
|
+
const message = history.get(id);
|
|
409
|
+
if (!message || message.topicId !== fromTopic || message.seq === null || message.status === 'processing') {
|
|
410
|
+
throw new HttpError(404, `来源主题里找不到这条已发出的消息:${id}`);
|
|
411
|
+
}
|
|
412
|
+
return message;
|
|
413
|
+
}).sort((a, b) => a.createdAt - b.createdAt || a.seq - b.seq);
|
|
414
|
+
const floor = selected[0].thread ?? selected[0].id;
|
|
415
|
+
if (fromThread === undefined && selected.every((m) => (m.thread ?? m.id) === floor) && history.get(floor))
|
|
416
|
+
fromThread = floor;
|
|
417
|
+
const handles = [...members.list(), ...members.people()].map((member) => ({ memberId: member.id, handle: member.handle }));
|
|
418
|
+
targets = findMentions(content, handles);
|
|
419
|
+
a2a.checkTargets(topicId, targets);
|
|
420
|
+
const forwarded = selected.map((message) => {
|
|
421
|
+
const gist = messageGist(message) || message.attachments.map((file) => basename(file)).join('、') || '(无正文)';
|
|
422
|
+
const excerpt = gist.replace(/\s+/gu, ' ').trim().replace(/[\\`*_<>[\]]/g, '\\$&');
|
|
423
|
+
return `[${message.id}](#${address.message(fromTopic, message.id)})\n> ${excerpt}`;
|
|
424
|
+
});
|
|
425
|
+
content = [content.trim(), ...forwarded].filter(Boolean).join('\n\n');
|
|
426
|
+
summary ??= `转发 ${selected.length} 条消息`;
|
|
427
|
+
}
|
|
428
|
+
const sent = a2a.send({ topicId, from: { kind: 'member', id: memberId }, content, targets, fromTopic, fromThread, summary, sourceIds: messageIds });
|
|
429
|
+
return { ...sent, open: address.message(topicId, sent.message.id) };
|
|
430
|
+
},
|
|
431
|
+
approval: ({ topicId, summary }) => ({ title: '投递交接', target: topics.get(topicId)?.title ?? topicId, impact: summary }),
|
|
432
|
+
text: (sent) => `已发到主题「${topics.get(sent.message.topicId)?.title ?? sent.message.topicId}」${calls(sent)}。`,
|
|
433
|
+
}));
|
|
434
|
+
core({
|
|
435
|
+
name: 'defer_message',
|
|
436
|
+
description: '把本轮附带或中途追加进来、但与当前话题无关的消息标为「已读,等本轮结束后再处理」。宿主会把它们从本轮回复的已读列表中移出,当前回合结束后再按正常流程为你开新回合、在各自的原楼里处理。本轮的触发消息本身不能延后。',
|
|
437
|
+
input: object({
|
|
438
|
+
ids: { type: 'array', items: { type: 'string' }, description: '要延后到本轮结束后处理的消息编号(msg_…)' },
|
|
439
|
+
}, ['ids']),
|
|
440
|
+
run({ ids }, { topicId, member }) {
|
|
441
|
+
if (!ids.length)
|
|
442
|
+
throw new Error('至少传一条要延后的消息编号(ids)');
|
|
443
|
+
const { deferred, remaining } = a2a.defer(topicId, member.id, ids);
|
|
444
|
+
return `已将 ${deferred.join('、')} 标为「本轮结束后再处理」(本轮仍需处理 ${remaining} 条消息)。继续完成当前回合,结束后宿主会自动唤醒你处理延后的消息。`;
|
|
445
|
+
},
|
|
446
|
+
});
|
|
447
|
+
const op = (decl) => ctx.effect(entry.op(decl));
|
|
448
|
+
op({
|
|
449
|
+
name: 'host.events', about: '宿主上发生过什么:配置修改、成员增减、宿主启动等,最近的在前。',
|
|
450
|
+
input: object({ limit: { type: 'number' } }), http: ['GET', '/api/host/events'], agent: true,
|
|
451
|
+
run: ({ limit = 30 }) => db.prepare('SELECT at, type, summary FROM journal ORDER BY id DESC LIMIT ?').all(Math.min(limit, 200)),
|
|
452
|
+
text: (events) => events.map((e) => `[${new Date(e.at).toLocaleString()}] ${e.type}: ${e.summary}`).join('\n') || '(还没有)',
|
|
453
|
+
});
|
|
454
|
+
op({ name: 'host.tools', about: '宿主给成员的工具:每个工具组和组里每个工具的说明。', http: ['GET', '/api/tools'], agent: true, run: (_args, caller) => tools.servers(caller.member ? caller.topicId : undefined) });
|
|
455
|
+
},
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
export default toolsPlugin;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type JsonWebKey } from 'node:crypto';
|
|
2
|
+
import { type Home } from 'hostlet/sdk';
|
|
3
|
+
/** Lifetime of each generated Ed25519 signing key version (180 days). */
|
|
4
|
+
export declare const MCP_KEY_TTL_MS: number;
|
|
5
|
+
/** Rotate to a fresh signing key this long before the current key expires (30 days). */
|
|
6
|
+
export declare const MCP_KEY_ROTATE_BEFORE_MS: number;
|
|
7
|
+
/** Lifetime of each signed MCP bearer token (30 days, capped at its signing key's expiry). */
|
|
8
|
+
export declare const MCP_TOKEN_TTL_MS: number;
|
|
9
|
+
/** Refresh cached in-process tokens when less than 15 days remain so sessions never hit expiry mid-flight. */
|
|
10
|
+
export declare const MCP_TOKEN_REFRESH_MARGIN_MS: number;
|
|
11
|
+
export interface SigningKeyRecord {
|
|
12
|
+
kid: string;
|
|
13
|
+
alg: 'Ed25519';
|
|
14
|
+
createdAt: number;
|
|
15
|
+
expiresAt: number;
|
|
16
|
+
jwk: JsonWebKey;
|
|
17
|
+
}
|
|
18
|
+
export interface SigningKeyringFile {
|
|
19
|
+
current: SigningKeyRecord;
|
|
20
|
+
previous?: SigningKeyRecord;
|
|
21
|
+
}
|
|
22
|
+
export interface McpTokenPayload {
|
|
23
|
+
topicId: string;
|
|
24
|
+
memberId: string;
|
|
25
|
+
kid: string;
|
|
26
|
+
iat: number;
|
|
27
|
+
exp: number;
|
|
28
|
+
jti: string;
|
|
29
|
+
}
|
|
30
|
+
export interface IssuedMcpToken extends McpTokenPayload {
|
|
31
|
+
token: string;
|
|
32
|
+
}
|
|
33
|
+
export type McpTokenVerifyResult = {
|
|
34
|
+
ok: true;
|
|
35
|
+
payload: McpTokenPayload;
|
|
36
|
+
} | {
|
|
37
|
+
ok: false;
|
|
38
|
+
reason: 'invalid' | 'expired';
|
|
39
|
+
};
|
|
40
|
+
export interface McpTokenAuthority {
|
|
41
|
+
/** Ensure the active key exists and has at least the rotation overlap window remaining. */
|
|
42
|
+
ensureFresh(): SigningKeyRecord;
|
|
43
|
+
/** Sign a persistent MCP bearer token using the current key version. */
|
|
44
|
+
issue(topicId: string, memberId: string): IssuedMcpToken;
|
|
45
|
+
/** Whether a cached token is still backed by the current key and outside the refresh margin. */
|
|
46
|
+
isCurrent(issued: IssuedMcpToken): boolean;
|
|
47
|
+
/** Verify a bearer token against current first, then previous. */
|
|
48
|
+
verify(token: string): McpTokenVerifyResult;
|
|
49
|
+
/** Read-only metadata of the loaded key versions (never exposes key material). */
|
|
50
|
+
versions(): {
|
|
51
|
+
current: Pick<SigningKeyRecord, 'kid' | 'alg' | 'createdAt' | 'expiresAt'>;
|
|
52
|
+
previous?: Pick<SigningKeyRecord, 'kid' | 'alg' | 'createdAt' | 'expiresAt'>;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Native Ed25519 signing authority for platform MCP bearer tokens.
|
|
57
|
+
* Keeps at most two key versions (`current` + `previous`) in `secrets/mcp-signing.json` with 0600 / Windows private ACL.
|
|
58
|
+
*/
|
|
59
|
+
export declare function createMcpTokenAuthority(home: Home, opts?: {
|
|
60
|
+
now?: () => number;
|
|
61
|
+
}): McpTokenAuthority;
|