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,5 @@
|
|
|
1
|
+
import type { Plugin } from '../../runtime/runtime.ts';
|
|
2
|
+
import type { Home } from '../home.ts';
|
|
3
|
+
import type { ExternalPluginContext } from 'hostlet/sdk';
|
|
4
|
+
/** A package exports a plugin definition or a factory. Every read starts a fresh package module graph. */
|
|
5
|
+
export declare function readPlugin(file: string, home: Home, ext: ExternalPluginContext): Promise<Plugin>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import { realpathSync } from 'node:fs';
|
|
10
|
+
import { createRequire, registerHooks } from 'node:module';
|
|
11
|
+
import { sep } from 'node:path';
|
|
12
|
+
import { pathToFileURL } from 'node:url';
|
|
13
|
+
let reads = 0;
|
|
14
|
+
let packageImports;
|
|
15
|
+
const commonJS = createRequire(import.meta.url);
|
|
16
|
+
/** Version the entrypoint and its package-local imports. The SDK and shared dependencies keep their normal URLs. */
|
|
17
|
+
function versionPackage(url, dir) {
|
|
18
|
+
packageImports ??= registerHooks({
|
|
19
|
+
resolve(specifier, context, next) {
|
|
20
|
+
if (!context.parentURL?.includes('hostlet-read='))
|
|
21
|
+
return next(specifier, context);
|
|
22
|
+
if (specifier === 'hostlet/sdk' || specifier === 'hostlet/adapter-kit')
|
|
23
|
+
return next(specifier, { ...context, parentURL: import.meta.url });
|
|
24
|
+
const result = next(specifier, context);
|
|
25
|
+
const parent = new URL(context.parentURL);
|
|
26
|
+
const root = parent.searchParams.get('hostlet-root');
|
|
27
|
+
if (!root || !result.url.startsWith(root))
|
|
28
|
+
return result;
|
|
29
|
+
const inside = new URL(result.url);
|
|
30
|
+
inside.searchParams.set('hostlet-root', root);
|
|
31
|
+
inside.searchParams.set('hostlet-read', parent.searchParams.get('hostlet-read'));
|
|
32
|
+
return { ...result, url: inside.href };
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
const root = realpathSync(dir) + sep;
|
|
36
|
+
for (const path of Object.keys(commonJS.cache))
|
|
37
|
+
if (path.startsWith(root))
|
|
38
|
+
delete commonJS.cache[path];
|
|
39
|
+
url.searchParams.set('hostlet-root', pathToFileURL(root).href);
|
|
40
|
+
url.searchParams.set('hostlet-read', String(++reads));
|
|
41
|
+
}
|
|
42
|
+
/** A package exports a plugin definition or a factory. Every read starts a fresh package module graph. */
|
|
43
|
+
export async function readPlugin(file, home, ext) {
|
|
44
|
+
const url = pathToFileURL(file);
|
|
45
|
+
versionPackage(url, ext.dir);
|
|
46
|
+
const made = (await import(__rewriteRelativeImportExtension(url.href))).default;
|
|
47
|
+
const plugin = typeof made === 'function' ? made(home, ext) : made;
|
|
48
|
+
if (typeof plugin?.start !== 'function' || typeof plugin.name !== 'string' || !plugin.name)
|
|
49
|
+
throw new Error('the default export is not a plugin');
|
|
50
|
+
return plugin;
|
|
51
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface NpmRelease {
|
|
2
|
+
package: string;
|
|
3
|
+
version: string;
|
|
4
|
+
integrity: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function isNpmPackage(value: unknown): value is string;
|
|
7
|
+
export declare function isNpmVersion(value: unknown): value is string;
|
|
8
|
+
export declare function newerNpmVersion(candidate: string, installed: string): boolean;
|
|
9
|
+
export declare function sha512Integrity(value: unknown): string | undefined;
|
|
10
|
+
/** Let npm resolve config, scoped registries, credentials, and mirrors. Only exact names and versions reach the CLI. */
|
|
11
|
+
export declare function npmRelease(name: string, version?: string): Promise<NpmRelease>;
|
|
12
|
+
export declare function npmArchive(release: NpmRelease, dir: string): Promise<Buffer>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { lstatSync, readdirSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import semver from 'semver';
|
|
5
|
+
import { PLUGIN_ARCHIVE_LIMIT } from "../archive.js";
|
|
6
|
+
import { HttpError } from "../entry.js";
|
|
7
|
+
import { startChild } from "../spawn.js";
|
|
8
|
+
const packageName = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/;
|
|
9
|
+
export function isNpmPackage(value) {
|
|
10
|
+
return typeof value === 'string' && value.length <= 214 && packageName.test(value);
|
|
11
|
+
}
|
|
12
|
+
export function isNpmVersion(value) {
|
|
13
|
+
if (typeof value !== 'string' || value.length > 128)
|
|
14
|
+
return false;
|
|
15
|
+
const parsed = semver.parse(value);
|
|
16
|
+
return !!parsed && (parsed.version + (parsed.build.length ? '+' + parsed.build.join('.') : '')) === value;
|
|
17
|
+
}
|
|
18
|
+
export function newerNpmVersion(candidate, installed) {
|
|
19
|
+
return semver.gt(candidate, installed);
|
|
20
|
+
}
|
|
21
|
+
export function sha512Integrity(value) {
|
|
22
|
+
if (typeof value !== 'string')
|
|
23
|
+
return undefined;
|
|
24
|
+
return value.split(/\s+/).find((part) => /^sha512-[A-Za-z0-9+/]{86}==$/.test(part));
|
|
25
|
+
}
|
|
26
|
+
async function npm(args) {
|
|
27
|
+
let output = '';
|
|
28
|
+
let problem;
|
|
29
|
+
const child = startChild('npm', [
|
|
30
|
+
'--loglevel=error', '--prefer-online', '--fetch-retries=0', '--fetch-timeout=20000', ...args,
|
|
31
|
+
], {
|
|
32
|
+
cwd: process.cwd(),
|
|
33
|
+
onLine(line) {
|
|
34
|
+
if (problem)
|
|
35
|
+
return;
|
|
36
|
+
if (output.length + line.length > 64 * 1024) {
|
|
37
|
+
problem = new HttpError(502, 'npm 返回的数据太多');
|
|
38
|
+
child.kill();
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
output += line + '\n';
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
const timer = setTimeout(() => {
|
|
46
|
+
problem = new HttpError(504, '等待 npm Registry 超时');
|
|
47
|
+
child.kill();
|
|
48
|
+
}, 30_000);
|
|
49
|
+
try {
|
|
50
|
+
const result = await child.exited;
|
|
51
|
+
if (problem)
|
|
52
|
+
throw problem;
|
|
53
|
+
if (result.code !== 0)
|
|
54
|
+
throw new HttpError(502, 'npm 请求失败。请检查 npm 命令、Registry 设置及包名');
|
|
55
|
+
return output;
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
clearTimeout(timer);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** Let npm resolve config, scoped registries, credentials, and mirrors. Only exact names and versions reach the CLI. */
|
|
62
|
+
export async function npmRelease(name, version) {
|
|
63
|
+
if (!isNpmPackage(name) || (version !== undefined && !isNpmVersion(version))) {
|
|
64
|
+
throw new HttpError(400, '请提供 npm 包名和精确版本');
|
|
65
|
+
}
|
|
66
|
+
const payload = await npm(['view', '--json', `${name}@${version ?? 'latest'}`, 'name', 'version', 'dist.integrity']);
|
|
67
|
+
let data;
|
|
68
|
+
try {
|
|
69
|
+
data = JSON.parse(payload);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
throw new HttpError(502, 'npm 返回的版本信息无效');
|
|
73
|
+
}
|
|
74
|
+
if (!data || typeof data !== 'object' || !('name' in data) || data.name !== name || !('version' in data) ||
|
|
75
|
+
!isNpmVersion(data.version) || (version && data.version !== version)) {
|
|
76
|
+
throw new HttpError(502, 'npm 返回的包名或版本不匹配');
|
|
77
|
+
}
|
|
78
|
+
const integrity = sha512Integrity('dist.integrity' in data ? data['dist.integrity'] : undefined);
|
|
79
|
+
if (!integrity)
|
|
80
|
+
throw new HttpError(502, 'npm 版本缺少 SHA-512 完整性记录');
|
|
81
|
+
return { package: name, version: data.version, integrity };
|
|
82
|
+
}
|
|
83
|
+
export async function npmArchive(release, dir) {
|
|
84
|
+
await npm(['pack', '--ignore-scripts', '--json', '--pack-destination', dir, `${release.package}@${release.version}`]);
|
|
85
|
+
const files = readdirSync(dir);
|
|
86
|
+
if (files.length !== 1 || !files[0].endsWith('.tgz'))
|
|
87
|
+
throw new HttpError(502, 'npm 没有返回一个插件离线包');
|
|
88
|
+
const file = join(dir, files[0]);
|
|
89
|
+
const info = lstatSync(file);
|
|
90
|
+
if (!info.isFile())
|
|
91
|
+
throw new HttpError(502, 'npm 插件离线包无效');
|
|
92
|
+
if (info.size > PLUGIN_ARCHIVE_LIMIT)
|
|
93
|
+
throw new HttpError(413, '插件离线包太大');
|
|
94
|
+
const archive = readFileSync(file);
|
|
95
|
+
if (`sha512-${createHash('sha512').update(archive).digest('base64')}` !== release.integrity) {
|
|
96
|
+
throw new HttpError(400, 'npm 插件包 SHA-512 校验失败');
|
|
97
|
+
}
|
|
98
|
+
return archive;
|
|
99
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ConsoleFragment, PluginManifest } from 'hostlet/sdk';
|
|
2
|
+
import type { ConfigField } from '../config-schema.ts';
|
|
3
|
+
export interface PluginPackage {
|
|
4
|
+
manifest?: PluginManifest;
|
|
5
|
+
entrypoint: string;
|
|
6
|
+
fragment?: ConsoleFragment;
|
|
7
|
+
}
|
|
8
|
+
export declare const PLUGIN_ID: RegExp;
|
|
9
|
+
export declare function validateConfigFields(fields: ConfigField[], knownFields?: ConfigField[], nested?: boolean): void;
|
|
10
|
+
/** Return a file strictly inside the package, also checking existing symbolic links. */
|
|
11
|
+
export declare function pluginEntry(dir: string, entrypoint: string, field?: string): string;
|
|
12
|
+
export declare function readPluginPackage(dir: string): PluginPackage;
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { existsSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
2
|
+
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
|
3
|
+
import { parse } from 'yaml';
|
|
4
|
+
import { localizedTextSchema, required, validateConfigRecord, validateConfigValue, } from "../config-schema.js";
|
|
5
|
+
import { array, check, object } from "../ops.js";
|
|
6
|
+
import { errorText } from "../util.js";
|
|
7
|
+
export const PLUGIN_ID = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
8
|
+
const FIELD_KEY = /^[A-Za-z][A-Za-z0-9._-]*$/;
|
|
9
|
+
const ENTRIES = ['index.js', 'index.mjs', 'index.ts'];
|
|
10
|
+
const str = { type: 'string' };
|
|
11
|
+
const bool = { type: 'boolean' };
|
|
12
|
+
const scalar = { type: ['string', 'number', 'boolean'] };
|
|
13
|
+
const dict = (value) => ({ type: 'object', additionalProperties: value });
|
|
14
|
+
const num = { type: 'number' };
|
|
15
|
+
const VALUE_KINDS = ['string', 'number', 'url', 'boolean', 'select', 'list', 'member', 'map'];
|
|
16
|
+
const option = object({
|
|
17
|
+
value: str, label: localizedTextSchema, hint: localizedTextSchema, docsUrl: str,
|
|
18
|
+
fill: dict(str), allowedValues: dict(array(str)),
|
|
19
|
+
}, ['value', 'label']);
|
|
20
|
+
const fieldProps = {
|
|
21
|
+
key: str, label: localizedTextSchema, description: localizedTextSchema, required: bool, hidden: bool,
|
|
22
|
+
minimum: num, maximum: num, integer: bool, unit: { type: 'string', enum: ['days', 'minutes', 'seconds', 'levels', 'items', 'count', 'chars', 'percent'] },
|
|
23
|
+
visibility: { type: 'string', enum: ['system', 'private'] }, readonly: bool, inherited: num, error: localizedTextSchema,
|
|
24
|
+
refreshAction: str, approvalRisk: localizedTextSchema, section: str, managedBy: str,
|
|
25
|
+
default: {}, suggestions: array(option),
|
|
26
|
+
requiredWhen: object({ key: str, value: { type: ['string', 'number', 'boolean', 'array'], items: scalar } }, ['key', 'value']),
|
|
27
|
+
options: array(option),
|
|
28
|
+
};
|
|
29
|
+
const { visibility: _nestedVisibility, ...recordFieldProps } = fieldProps;
|
|
30
|
+
const valueField = object({ ...recordFieldProps, kind: { type: 'string', enum: [...VALUE_KINDS] } }, ['key', 'kind']);
|
|
31
|
+
const operationRef = object({ method: str }, ['method']);
|
|
32
|
+
const configurationStep = object({
|
|
33
|
+
id: str, label: str, render: { enum: ['button', 'polling'] }, resultRender: { enum: ['img', 'text', 'status'] },
|
|
34
|
+
action: operationRef, next: str, rollback: str, cancel: str, timeout: num,
|
|
35
|
+
}, ['id', 'label', 'render', 'action']);
|
|
36
|
+
const configField = object({
|
|
37
|
+
...fieldProps, kind: { type: 'string', enum: [...VALUE_KINDS, 'secret', 'records', 'operation'] },
|
|
38
|
+
recordFields: array(valueField), presets: array(num), recordPresets: array(object({ id: str, label: localizedTextSchema, value: { type: 'object' } }, ['id', 'label', 'value'])),
|
|
39
|
+
actions: array(configurationStep), target: array(str), status: operationRef,
|
|
40
|
+
}, ['key', 'kind']);
|
|
41
|
+
const variantTest = object({ const: str, enum: array(str) });
|
|
42
|
+
const variants = object({
|
|
43
|
+
discriminator: str,
|
|
44
|
+
branches: array(object({
|
|
45
|
+
id: str, when: object({ properties: dict(variantTest), required: array(str) }, ['properties']), fields: array(str),
|
|
46
|
+
}, ['id', 'when', 'fields'])),
|
|
47
|
+
}, ['discriminator', 'branches']);
|
|
48
|
+
const localizedStep = { ...object({ text: localizedTextSchema, mode: str }, ['text']), type: ['string', 'object'] };
|
|
49
|
+
const pluginTopicView = object({
|
|
50
|
+
main: str, panel: str, tabs: array(str), preset: str, args: dict(scalar),
|
|
51
|
+
}, ['main']);
|
|
52
|
+
const manifestSchema = { ...object({
|
|
53
|
+
pluginId: str, version: str, name: str, icon: str, console: str,
|
|
54
|
+
foundation: bool, topicSwitch: bool,
|
|
55
|
+
description: localizedTextSchema, title: localizedTextSchema,
|
|
56
|
+
steps: array(localizedStep),
|
|
57
|
+
configuration: array(configField), configurationVariants: variants,
|
|
58
|
+
visibility: { type: 'string', enum: ['system', 'private'] }, approvalRisk: localizedTextSchema,
|
|
59
|
+
topic: object({ title: str, summary: str, pinned: bool, view: pluginTopicView }, ['title', 'summary']),
|
|
60
|
+
runtime: { ...object({ entrypoint: str }), additionalProperties: true },
|
|
61
|
+
}, ['pluginId']), additionalProperties: true };
|
|
62
|
+
function matches(test, value) {
|
|
63
|
+
return 'const' in test ? value === test.const : test.enum.includes(value);
|
|
64
|
+
}
|
|
65
|
+
function validateVariants(v, fields) {
|
|
66
|
+
const discriminator = fields.find((field) => field.key === v.discriminator);
|
|
67
|
+
if (discriminator?.kind !== 'select')
|
|
68
|
+
throw new Error('configurationVariants.discriminator 必须是 select 字段');
|
|
69
|
+
const options = discriminator.options.map(({ value }) => value);
|
|
70
|
+
for (const branch of v.branches) {
|
|
71
|
+
const test = branch.when.properties[v.discriminator];
|
|
72
|
+
if (Object.keys(branch.when.properties).length !== 1 || !test || Object.keys(test).length !== 1) {
|
|
73
|
+
throw new Error(`配置分支 ${branch.id} 必须以 ${v.discriminator} 的 const 或 enum 作为条件`);
|
|
74
|
+
}
|
|
75
|
+
if (!branch.fields.every((key) => key !== v.discriminator && fields.some((field) => field.key === key))) {
|
|
76
|
+
throw new Error(`配置分支 ${branch.id} 引用了无效的字段`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!options.every((value) => v.branches.filter((branch) => matches(branch.when.properties[v.discriminator], value)).length === 1)) {
|
|
80
|
+
throw new Error('configurationVariants 的每个选项必须匹配一个分支');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function validateOperation(field, fields) {
|
|
84
|
+
const { key, actions, target, status } = field;
|
|
85
|
+
if (!actions?.length || actions[0]?.render !== 'button')
|
|
86
|
+
throw new Error(`${key} 需要以按钮开头的 actions`);
|
|
87
|
+
if (!target || new Set(target).size !== target.length || !target.every((name) => {
|
|
88
|
+
const value = fields.find((one) => one.key === name);
|
|
89
|
+
return value && value.kind !== 'operation' && !value.readonly;
|
|
90
|
+
}))
|
|
91
|
+
throw new Error(`${key} 的 target 必须列出已声明的可写入值字段`);
|
|
92
|
+
const ids = new Set(actions.map((step) => step.id));
|
|
93
|
+
if (ids.size !== actions.length || actions.some((step) => !FIELD_KEY.test(step.id))) {
|
|
94
|
+
throw new Error(`${key} 有无效或重复的步骤 ID`);
|
|
95
|
+
}
|
|
96
|
+
const validMethod = (ref) => /^[a-z_][a-z0-9_]*\.[a-z_]+$/.test(ref.method);
|
|
97
|
+
if ((status && !validMethod(status)) || actions.some((step) => !validMethod(step.action))) {
|
|
98
|
+
throw new Error(`${key} 的 method 必须引用 entry.op 操作名`);
|
|
99
|
+
}
|
|
100
|
+
for (const step of actions) {
|
|
101
|
+
if ((step.next !== undefined && !ids.has(step.next)) || (step.rollback !== undefined && !ids.has(step.rollback))) {
|
|
102
|
+
throw new Error(`${key}.${step.id} 引用了不存在的 next 或 rollback`);
|
|
103
|
+
}
|
|
104
|
+
if (step.cancel !== undefined && (step.cancel === step.id || actions.find((one) => one.id === step.cancel)?.render !== 'button')) {
|
|
105
|
+
throw new Error(`${key}.${step.id} 的 cancel 必须指向另一个按钮步骤`);
|
|
106
|
+
}
|
|
107
|
+
if (step.render === 'polling' && (!Number.isInteger(step.timeout) || step.timeout <= 0)) {
|
|
108
|
+
throw new Error(`${key}.${step.id} 需要以秒为单位的正整数 timeout`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export function validateConfigFields(fields, knownFields = fields, nested = false) {
|
|
113
|
+
const keys = new Set();
|
|
114
|
+
for (const field of fields) {
|
|
115
|
+
if (!FIELD_KEY.test(field.key) || Object.hasOwn(Object.prototype, field.key) || keys.has(field.key)) {
|
|
116
|
+
throw new Error(`配置字段名无效或重复:${field.key}`);
|
|
117
|
+
}
|
|
118
|
+
keys.add(field.key);
|
|
119
|
+
if (nested && field.visibility !== undefined)
|
|
120
|
+
throw new Error(`记录子字段 ${field.key} 不支持声明 visibility`);
|
|
121
|
+
if (field.visibility !== undefined && field.visibility !== 'system' && field.visibility !== 'private')
|
|
122
|
+
throw new Error(`配置项 ${field.key} 的 visibility 只能是 system 或 private`);
|
|
123
|
+
if (field.kind === 'operation') {
|
|
124
|
+
for (const prop of ['default', 'readonly', 'recordFields', 'presets', 'recordPresets', 'options', 'minimum', 'maximum', 'integer', 'unit', 'requiredWhen', 'inherited', 'suggestions']) {
|
|
125
|
+
if (Object.hasOwn(field, prop))
|
|
126
|
+
throw new Error(`操作字段 ${field.key} 不支持 ${prop}`);
|
|
127
|
+
}
|
|
128
|
+
validateOperation(field, knownFields);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (['actions', 'target', 'status'].some((prop) => Object.hasOwn(field, prop))) {
|
|
132
|
+
throw new Error(`配置项 ${field.key} 需要 kind: operation 才能声明操作步骤`);
|
|
133
|
+
}
|
|
134
|
+
if (field.kind === 'select' && !field.options?.length)
|
|
135
|
+
throw new Error(`${field.key} 需要 options`);
|
|
136
|
+
if (field.kind !== 'number' && (field.minimum !== undefined || field.maximum !== undefined || field.integer !== undefined || field.unit !== undefined || field.presets !== undefined || field.inherited !== undefined)) {
|
|
137
|
+
throw new Error(`${field.key} 只有 number 字段支持 minimum / maximum / integer / unit / presets / inherited`);
|
|
138
|
+
}
|
|
139
|
+
if (field.kind === 'number' && field.minimum !== undefined && field.maximum !== undefined && field.minimum > field.maximum) {
|
|
140
|
+
throw new Error(`${field.key} 的 minimum 不能大于 maximum`);
|
|
141
|
+
}
|
|
142
|
+
if (field.kind !== 'records' && (field.recordFields !== undefined || field.recordPresets !== undefined)) {
|
|
143
|
+
throw new Error(`${field.key} 只有 records 字段支持 recordFields / recordPresets`);
|
|
144
|
+
}
|
|
145
|
+
if (field.kind === 'records') {
|
|
146
|
+
if (!field.recordFields?.length)
|
|
147
|
+
throw new Error(`${field.key} 需要 recordFields`);
|
|
148
|
+
validateConfigFields(field.recordFields, field.recordFields, true);
|
|
149
|
+
for (const preset of field.recordPresets ?? [])
|
|
150
|
+
validateConfigRecord(field.recordFields, preset.value, `${field.key}.${preset.id}`, false);
|
|
151
|
+
}
|
|
152
|
+
if (field.kind === 'secret') {
|
|
153
|
+
if (Object.hasOwn(field, 'default'))
|
|
154
|
+
throw new Error(`密钥 ${field.key} 不能写在 plugin.yaml 的默认值中`);
|
|
155
|
+
if (field.readonly)
|
|
156
|
+
throw new Error(`密钥 ${field.key} 不能设为只读`);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
if (field.readonly && field.default === undefined)
|
|
160
|
+
throw new Error(`只读配置项 ${field.key} 需要声明默认值`);
|
|
161
|
+
if (field.default !== undefined)
|
|
162
|
+
validateConfigValue(field, field.default, `${field.key}.default`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
for (const field of fields) {
|
|
166
|
+
if (field.kind === 'operation' || !field.requiredWhen)
|
|
167
|
+
continue;
|
|
168
|
+
const ref = fields.find((one) => one.key === field.requiredWhen.key);
|
|
169
|
+
if (!ref || ref.kind === 'operation')
|
|
170
|
+
throw new Error(`${field.key} 的 requiredWhen 引用了未声明的值字段`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/** Return a file strictly inside the package, also checking existing symbolic links. */
|
|
174
|
+
export function pluginEntry(dir, entrypoint, field = 'runtime.entrypoint') {
|
|
175
|
+
const inside = (part) => part && !isAbsolute(part) && part !== '..' && !part.startsWith(`..${sep}`);
|
|
176
|
+
if (!entrypoint || isAbsolute(entrypoint) || entrypoint.includes('\\') || /^[A-Za-z]:/.test(entrypoint) || entrypoint.includes('\0')) {
|
|
177
|
+
throw new Error(`${field} 必须是插件目录内的相对路径`);
|
|
178
|
+
}
|
|
179
|
+
const path = resolve(dir, entrypoint);
|
|
180
|
+
if (!inside(relative(dir, path)))
|
|
181
|
+
throw new Error(`${field} 必须在插件目录内`);
|
|
182
|
+
if (!existsSync(path) || !statSync(path).isFile())
|
|
183
|
+
throw new Error(`找不到 ${field} 指向的文件:${entrypoint}`);
|
|
184
|
+
if (!inside(relative(realpathSync(dir), realpathSync(path))))
|
|
185
|
+
throw new Error(`${field} 必须在插件目录内`);
|
|
186
|
+
return path;
|
|
187
|
+
}
|
|
188
|
+
export function readPluginPackage(dir) {
|
|
189
|
+
const file = resolve(dir, 'plugin.yaml');
|
|
190
|
+
let manifest;
|
|
191
|
+
let fragment;
|
|
192
|
+
if (existsSync(file)) {
|
|
193
|
+
try {
|
|
194
|
+
const raw = parse(readFileSync(file, 'utf8'));
|
|
195
|
+
const problem = check(manifestSchema, raw);
|
|
196
|
+
if (problem)
|
|
197
|
+
throw new Error(problem);
|
|
198
|
+
manifest = raw;
|
|
199
|
+
if (!PLUGIN_ID.test(manifest.pluginId))
|
|
200
|
+
throw new Error('pluginId 需要使用小写字母、数字、点、下划线或连字符');
|
|
201
|
+
if (manifest.icon !== undefined)
|
|
202
|
+
pluginEntry(dir, manifest.icon, 'icon');
|
|
203
|
+
if (manifest.console !== undefined) {
|
|
204
|
+
const pdl = pluginEntry(dir, `${manifest.console}/pdl.json`, 'console');
|
|
205
|
+
const raw = JSON.parse(readFileSync(pdl, 'utf8'));
|
|
206
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
207
|
+
throw new Error('console/pdl.json 必须是对象');
|
|
208
|
+
const module = `${manifest.console}/view.mjs`;
|
|
209
|
+
fragment = raw;
|
|
210
|
+
if (existsSync(resolve(dir, module))) {
|
|
211
|
+
fragment.components = { ...fragment.components, module: readFileSync(pluginEntry(dir, module, 'console'), 'utf8') };
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (manifest.topic && (!manifest.topic.title.trim() || !manifest.topic.summary.trim() || manifest.topic.view && !manifest.topic.view.main.trim())) {
|
|
215
|
+
throw new Error('topic 需要非空的 title、summary;声明 view 时需要非空的 main');
|
|
216
|
+
}
|
|
217
|
+
const fields = manifest.configuration ?? [];
|
|
218
|
+
validateConfigFields(fields);
|
|
219
|
+
if (manifest.configurationVariants)
|
|
220
|
+
validateVariants(manifest.configurationVariants, fields);
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
throw new Error(`plugin.yaml:${errorText(error)}`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const entrypoint = manifest?.runtime?.entrypoint ?? ENTRIES.find((file) => existsSync(resolve(dir, file)));
|
|
227
|
+
if (entrypoint === undefined)
|
|
228
|
+
throw new Error('找不到插件入口 index.js、index.mjs 或 index.ts');
|
|
229
|
+
pluginEntry(dir, entrypoint);
|
|
230
|
+
return { manifest, entrypoint, fragment };
|
|
231
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ServerResponse } from 'node:http';
|
|
2
|
+
import type { Disposer, Events, Plugin } from '../runtime/runtime.ts';
|
|
3
|
+
/** Plugins name the events of their own that the console should hear about. */
|
|
4
|
+
export interface Push {
|
|
5
|
+
/** Send to all consoles, or to one connection identified by push.connected. */
|
|
6
|
+
send(event: string, payload: unknown, client?: string): void;
|
|
7
|
+
forward(event: keyof Events & string): Disposer;
|
|
8
|
+
connect(res: ServerResponse): void;
|
|
9
|
+
/** Associate work with a live browser connection. Replacing it or disconnecting releases it. */
|
|
10
|
+
follow(client: string, key: string, acquire?: () => Disposer): boolean;
|
|
11
|
+
}
|
|
12
|
+
declare module '../runtime/runtime.ts' {
|
|
13
|
+
interface Services {
|
|
14
|
+
push: Push;
|
|
15
|
+
}
|
|
16
|
+
interface Events {
|
|
17
|
+
'push.connected': {
|
|
18
|
+
id: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export declare const pushPlugin: Plugin;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { newId } from "./util.js";
|
|
2
|
+
/** Forwards console updates as server-sent events. */
|
|
3
|
+
const FORWARDED = [
|
|
4
|
+
'topic.updated', 'topic.purged', 'members.changed', 'config.changed', 'plugin.changed',
|
|
5
|
+
];
|
|
6
|
+
export const pushPlugin = {
|
|
7
|
+
name: 'push',
|
|
8
|
+
core: true,
|
|
9
|
+
start(ctx) {
|
|
10
|
+
const clients = new Map();
|
|
11
|
+
const send = (name, payload, client) => {
|
|
12
|
+
if (!clients.size)
|
|
13
|
+
return;
|
|
14
|
+
const frame = `event: ${name}\ndata: ${JSON.stringify(payload)}\n\n`;
|
|
15
|
+
if (client !== undefined) {
|
|
16
|
+
clients.get(client)?.res.write(frame);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
for (const { res } of clients.values())
|
|
20
|
+
res.write(frame);
|
|
21
|
+
};
|
|
22
|
+
for (const name of FORWARDED) {
|
|
23
|
+
ctx.on(name, (payload) => send(name, payload));
|
|
24
|
+
ctx.note(name, { title: '把这件事推给控制台,页面跟着更新(不往成员的上下文里加东西)' });
|
|
25
|
+
}
|
|
26
|
+
const push = {
|
|
27
|
+
send,
|
|
28
|
+
forward: (event) => ctx.runtime._listen(event, (payload) => push.send(event, payload)),
|
|
29
|
+
connect(res) {
|
|
30
|
+
res.writeHead(200, { 'content-type': 'text/event-stream', 'cache-control': 'no-cache', connection: 'keep-alive' });
|
|
31
|
+
const id = newId('sse'), held = new Map();
|
|
32
|
+
clients.set(id, { res, held });
|
|
33
|
+
res.once('close', () => {
|
|
34
|
+
clients.delete(id);
|
|
35
|
+
for (const release of held.values())
|
|
36
|
+
release();
|
|
37
|
+
});
|
|
38
|
+
res.write(': connected\n\n');
|
|
39
|
+
send('push.connected', { id }, id);
|
|
40
|
+
ctx.runtime.emit('push.connected', { id });
|
|
41
|
+
},
|
|
42
|
+
follow(client, key, acquire) {
|
|
43
|
+
const held = clients.get(client)?.held;
|
|
44
|
+
if (!held)
|
|
45
|
+
return false;
|
|
46
|
+
const release = acquire?.();
|
|
47
|
+
held.get(key)?.();
|
|
48
|
+
if (release)
|
|
49
|
+
held.set(key, release);
|
|
50
|
+
else
|
|
51
|
+
held.delete(key);
|
|
52
|
+
return true;
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
ctx.provide('push', push);
|
|
56
|
+
const beat = setInterval(() => clients.forEach(({ res }) => res.write(': beat\n\n')), 25_000);
|
|
57
|
+
beat.unref();
|
|
58
|
+
ctx.effect(() => {
|
|
59
|
+
clearInterval(beat);
|
|
60
|
+
clients.forEach(({ res }) => res.end());
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export type ResourceRef = `res:topic/${string}/${string}` | `res:ref/${string}/${string}` | `res:work/${string}/${string}`;
|
|
2
|
+
export type ResourceChange = {
|
|
3
|
+
topicId: string;
|
|
4
|
+
resource: ResourceRef;
|
|
5
|
+
entry?: {
|
|
6
|
+
path: string;
|
|
7
|
+
nextPath?: string;
|
|
8
|
+
};
|
|
9
|
+
} & ({
|
|
10
|
+
kind: 'created' | 'updated' | 'deleted' | 'retention';
|
|
11
|
+
} | {
|
|
12
|
+
kind: 'moved';
|
|
13
|
+
nextResource: ResourceRef;
|
|
14
|
+
});
|
|
15
|
+
export type ResourceLocation = {
|
|
16
|
+
kind: 'topic';
|
|
17
|
+
topicId: string;
|
|
18
|
+
path: string;
|
|
19
|
+
} | {
|
|
20
|
+
kind: 'ref';
|
|
21
|
+
refId: string;
|
|
22
|
+
path: string;
|
|
23
|
+
} | {
|
|
24
|
+
kind: 'work';
|
|
25
|
+
topicId: string;
|
|
26
|
+
workId: string;
|
|
27
|
+
};
|
|
28
|
+
export declare const encodedPath: (path: string) => string;
|
|
29
|
+
export declare const topicPathResource: (topicId: string, path: string) => ResourceRef;
|
|
30
|
+
/** A topic's formal outputs live in `artifacts/`; storage cleanup never scans it. */
|
|
31
|
+
export declare const topicResource: (topicId: string, path: string) => ResourceRef;
|
|
32
|
+
export declare const inTopicArtifacts: (topicId: string, resource: ResourceRef) => boolean;
|
|
33
|
+
export declare const refResource: (refId: string, path: string) => ResourceRef;
|
|
34
|
+
export declare const workResource: (topicId: string, workId: string) => ResourceRef;
|
|
35
|
+
export declare const resourceWithin: (resource: string, parent: ResourceRef) => boolean;
|
|
36
|
+
/** Decode canonical resource addresses, rejecting ambiguous paths before any file lookup. */
|
|
37
|
+
export declare function parseResource(resource: string): ResourceLocation | undefined;
|
|
38
|
+
export interface Locator extends Record<string, unknown> {
|
|
39
|
+
page?: number;
|
|
40
|
+
time?: number;
|
|
41
|
+
text?: string;
|
|
42
|
+
prefix?: string;
|
|
43
|
+
suffix?: string;
|
|
44
|
+
}
|
|
45
|
+
export declare const resourceField: {
|
|
46
|
+
readonly type: "string";
|
|
47
|
+
readonly description: "资源的规范地址(res:…)";
|
|
48
|
+
};
|
|
49
|
+
export declare const locatorField: {
|
|
50
|
+
readonly type: "object";
|
|
51
|
+
readonly properties: {
|
|
52
|
+
readonly page: {
|
|
53
|
+
readonly type: "integer";
|
|
54
|
+
};
|
|
55
|
+
readonly time: {
|
|
56
|
+
readonly type: "number";
|
|
57
|
+
};
|
|
58
|
+
readonly text: {
|
|
59
|
+
readonly type: "string";
|
|
60
|
+
};
|
|
61
|
+
readonly prefix: {
|
|
62
|
+
readonly type: "string";
|
|
63
|
+
readonly description: "紧邻所选文字之前的上下文";
|
|
64
|
+
};
|
|
65
|
+
readonly suffix: {
|
|
66
|
+
readonly type: "string";
|
|
67
|
+
readonly description: "紧邻所选文字之后的上下文";
|
|
68
|
+
};
|
|
69
|
+
readonly selector: {
|
|
70
|
+
readonly type: "string";
|
|
71
|
+
};
|
|
72
|
+
readonly jsonPath: {
|
|
73
|
+
readonly type: "string";
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
export declare function validateLocator(locator?: Locator): void;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { sep } from 'node:path';
|
|
2
|
+
import { HttpError } from "./entry.js";
|
|
3
|
+
export const encodedPath = (path) => path.split('/').map(encodeURIComponent).join('/');
|
|
4
|
+
export const topicPathResource = (topicId, path) => `res:topic/${topicId}/${encodedPath(path)}`;
|
|
5
|
+
/** A topic's formal outputs live in `artifacts/`; storage cleanup never scans it. */
|
|
6
|
+
export const topicResource = (topicId, path) => topicPathResource(topicId, 'artifacts/' + path);
|
|
7
|
+
export const inTopicArtifacts = (topicId, resource) => resource.startsWith(`res:topic/${topicId}/artifacts/`);
|
|
8
|
+
export const refResource = (refId, path) => `res:ref/${refId}/${encodedPath(path)}`;
|
|
9
|
+
export const workResource = (topicId, workId) => `res:work/${topicId}/${encodeURIComponent(workId)}`;
|
|
10
|
+
export const resourceWithin = (resource, parent) => resource === parent || resource.startsWith(parent.endsWith('/') ? parent : parent + '/');
|
|
11
|
+
/** Decode canonical resource addresses, rejecting ambiguous paths before any file lookup. */
|
|
12
|
+
export function parseResource(resource) {
|
|
13
|
+
const [prefix, owner, ...rest] = resource.split('/');
|
|
14
|
+
if (!owner || !/^[\w-]+$/.test(owner))
|
|
15
|
+
return;
|
|
16
|
+
if (!rest.length || (prefix === 'res:work' && rest.length !== 1))
|
|
17
|
+
return;
|
|
18
|
+
let parts;
|
|
19
|
+
try {
|
|
20
|
+
parts = rest.map(decodeURIComponent);
|
|
21
|
+
if (parts.some((part, i) => encodeURIComponent(part) !== rest[i] || part.includes('/') || part.includes('\0') ||
|
|
22
|
+
(sep === '\\' && part.includes('\\')) || part === '.' || part === '..' || (!part && parts.length !== 1)))
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return;
|
|
27
|
+
} // malformed encoding in a supplied address
|
|
28
|
+
const path = parts.join('/');
|
|
29
|
+
if (prefix === 'res:topic' && path)
|
|
30
|
+
return { kind: 'topic', topicId: owner, path };
|
|
31
|
+
if (prefix === 'res:ref')
|
|
32
|
+
return { kind: 'ref', refId: owner, path };
|
|
33
|
+
if (prefix === 'res:work' && path)
|
|
34
|
+
return { kind: 'work', topicId: owner, workId: path };
|
|
35
|
+
}
|
|
36
|
+
export const resourceField = { type: 'string', description: '资源的规范地址(res:…)' };
|
|
37
|
+
export const locatorField = { type: 'object', properties: {
|
|
38
|
+
page: { type: 'integer' }, time: { type: 'number' }, text: { type: 'string' },
|
|
39
|
+
prefix: { type: 'string', description: '紧邻所选文字之前的上下文' },
|
|
40
|
+
suffix: { type: 'string', description: '紧邻所选文字之后的上下文' },
|
|
41
|
+
selector: { type: 'string' }, jsonPath: { type: 'string' },
|
|
42
|
+
} };
|
|
43
|
+
export function validateLocator(locator) {
|
|
44
|
+
if (locator?.page !== undefined && locator.page < 1)
|
|
45
|
+
throw new HttpError(400, 'locator.page 从 1 开始');
|
|
46
|
+
if (locator?.time !== undefined && locator.time < 0)
|
|
47
|
+
throw new HttpError(400, 'locator.time 从 0 开始');
|
|
48
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Child, ChildOptions } from '#platform';
|
|
2
|
+
import type { Member } from './types.ts';
|
|
3
|
+
export type { Child } from '#platform';
|
|
4
|
+
type ChildMember = Pick<Member, 'id' | 'handle' | 'name'>;
|
|
5
|
+
type HostChildOptions = Omit<ChildOptions, 'env'> & {
|
|
6
|
+
env?: NodeJS.ProcessEnv;
|
|
7
|
+
member?: ChildMember;
|
|
8
|
+
};
|
|
9
|
+
export declare function startChild(command: string, args: readonly string[], { env, member, ...opts }: HostChildOptions): Child;
|
|
10
|
+
export declare function onPath(command: string): Promise<boolean>;
|
|
11
|
+
export declare function firstLine(command: string, args: readonly string[]): Promise<string | undefined>;
|
|
12
|
+
export declare function firstLineSync(command: string, args: readonly string[]): string | undefined;
|