hostlet 0.0.0-stage → 0.1.0-alpha.1
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 +916 -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 +130 -0
- package/dist/plugins/model-profiles/rules.js +729 -0
- package/dist/plugins/model-profiles/skills/model-profile/SKILL.md +59 -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 +84 -0
- package/dist/plugins/model-profiles/storage.js +315 -0
- package/dist/plugins/model-profiles/types.d.ts +179 -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 +455 -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 +270 -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,398 @@
|
|
|
1
|
+
import { appendFileSync, existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { address, addressLink, errorText, HttpError, log, newId, object, OWNER_ID, readJson, startChild, writeDocuments, } from 'hostlet/sdk';
|
|
4
|
+
const RESTARTED = '宿主重启,命令中断';
|
|
5
|
+
const MINUTE = 60_000;
|
|
6
|
+
const historyFile = (dir) => join(dir, 'background.jsonl');
|
|
7
|
+
const appendRecord = (file, record) => appendFileSync(file, `${JSON.stringify(record)}\n`);
|
|
8
|
+
const resultStatus = ({ code, stopped, timedOut, service }) => timedOut ? 'failed' : stopped ? 'canceled' : !service && code === 0 ? 'completed' : 'failed';
|
|
9
|
+
function commandSummary(command) {
|
|
10
|
+
const compact = command.replace(/\s+/g, ' ').trim();
|
|
11
|
+
return compact.slice(0, 60).replaceAll('`', '`') + (compact.length > 60 ? '…' : '');
|
|
12
|
+
}
|
|
13
|
+
function fencedBlock(text) {
|
|
14
|
+
const lines = text.replace(/\r\n?/g, '\n').split('\n');
|
|
15
|
+
const first = lines.findIndex((line) => line.trim());
|
|
16
|
+
const last = lines.findLastIndex((line) => line.trim());
|
|
17
|
+
const body = lines.slice(first, last + 1).join('\n');
|
|
18
|
+
let maxRun = 2;
|
|
19
|
+
for (const [run] of body.matchAll(/`+/g))
|
|
20
|
+
maxRun = Math.max(maxRun, run.length);
|
|
21
|
+
const fence = '`'.repeat(maxRun + 1);
|
|
22
|
+
return `${fence}\n${body}\n${fence}`;
|
|
23
|
+
}
|
|
24
|
+
function readHistory(file) {
|
|
25
|
+
if (!existsSync(file))
|
|
26
|
+
return [];
|
|
27
|
+
const latest = new Map();
|
|
28
|
+
for (const line of readFileSync(file, 'utf8').split('\n').filter(Boolean)) {
|
|
29
|
+
const record = JSON.parse(line);
|
|
30
|
+
latest.set(record.id, record);
|
|
31
|
+
}
|
|
32
|
+
return [...latest.values()];
|
|
33
|
+
}
|
|
34
|
+
/** The tool group that carries job_start. Another group may register a tool of the same name. */
|
|
35
|
+
const JOB_SERVER = 'hostlet';
|
|
36
|
+
export default function backgroundPlugin(home, ext) {
|
|
37
|
+
return {
|
|
38
|
+
name: 'background',
|
|
39
|
+
title: '后台任务',
|
|
40
|
+
about: '成员用它启动耗时命令,命令由宿主管,结束时在主题里叫醒它。',
|
|
41
|
+
group: '给成员的工具',
|
|
42
|
+
needs: ['topics', 'messages', 'members', 'a2a', 'entry', 'push', 'i18n'],
|
|
43
|
+
async start(ctx) {
|
|
44
|
+
ctx.hook('topic.records', () => 'background.jsonl');
|
|
45
|
+
// Every client may have background tools of its own; what they start belongs to that client, not to the topic.
|
|
46
|
+
ctx.note('session.init', { title: '耗时命令走 job_start,客户端自带的后台任务结果不回主题', when: '每段会话开头' });
|
|
47
|
+
// Only when the member can actually call job_start here: the tool group may be switched off for this topic or above it.
|
|
48
|
+
const jobStartHere = (topicId) => ctx.runtime.has('tools') && ctx.get('tools').servers(topicId)
|
|
49
|
+
.some(({ server, tools }) => server === JOB_SERVER && ctx.get('topics').uses(topicId, `tools:${server}`, true) && tools.some((tool) => tool.name === 'job_start'));
|
|
50
|
+
ctx.hook('session.init', ({ topicId }) => !jobStartHere(topicId) ? undefined : ctx.get('i18n').lang() === 'en'
|
|
51
|
+
? '- Run long commands with job_start; the topic is told when they end. Background tasks of your client itself may be ended by a restart, and their results do not come back to the topic.'
|
|
52
|
+
: '- 耗时命令用 job_start,结束后会通知主题。客户端自带的后台任务重启可能中断,结果也不会回到主题。');
|
|
53
|
+
ctx.effect(ext.config.declare([
|
|
54
|
+
{
|
|
55
|
+
key: 'checkEvery', kind: 'number',
|
|
56
|
+
label: { default: '状态检查间隔',
|
|
57
|
+
translations: { en: 'Status check interval' } },
|
|
58
|
+
description: { default: '每隔多少秒检查一次后台命令的运行状态。',
|
|
59
|
+
translations: { en: 'How often to check whether background commands are still running.' } },
|
|
60
|
+
default: 30, minimum: 1, unit: 'seconds', integer: true, presets: [10, 30, 60, 120, 300],
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
key: 'timeout', kind: 'number',
|
|
64
|
+
label: { default: '后台任务超时',
|
|
65
|
+
translations: { en: 'Background task timeout' } },
|
|
66
|
+
description: { default: '后台命令最多运行多少秒;0 表示不限制。',
|
|
67
|
+
translations: { en: 'Maximum runtime of a background command in seconds; 0 means unlimited.' } },
|
|
68
|
+
default: 240, minimum: 0, unit: 'seconds', integer: true, presets: [0, 60, 120, 240, 600, 1800],
|
|
69
|
+
},
|
|
70
|
+
]));
|
|
71
|
+
const notifier = ctx.get('members').register(ctx, { name: '后台任务', handle: 'background', icon: 'terminal', color: { primary: '#7762a4' } });
|
|
72
|
+
const topics = ctx.get('topics');
|
|
73
|
+
const messages = ctx.get('messages');
|
|
74
|
+
const members = ctx.get('members');
|
|
75
|
+
const a2a = ctx.get('a2a');
|
|
76
|
+
const entry = ctx.get('entry');
|
|
77
|
+
const push = ctx.get('push');
|
|
78
|
+
ctx.effect(ctx.get('i18n').register('background', {
|
|
79
|
+
zh: { checkEvery: '检查间隔(分钟)', timeout: '超时上限(分钟,0 为不限)' },
|
|
80
|
+
en: { checkEvery: 'Check interval (minutes)', timeout: 'Timeout (minutes, 0 for no limit)' },
|
|
81
|
+
}));
|
|
82
|
+
const jobs = new Map();
|
|
83
|
+
const openFile = home.path('plugins', 'background', 'open.json');
|
|
84
|
+
const openJobs = new Map(readJson(openFile, []).map((job) => [job.jobId, job]));
|
|
85
|
+
const saveOpen = () => writeDocuments(home, [{ path: openFile, value: [...openJobs.values()] }]);
|
|
86
|
+
const hasSchedule = () => entry.ops().ops.some(({ name }) => name === 'schedule.create');
|
|
87
|
+
const visibleMessage = (topicId, messageId) => {
|
|
88
|
+
if (!messageId)
|
|
89
|
+
return false;
|
|
90
|
+
if (a2a.live(topicId).some((turn) => turn.messageId === messageId))
|
|
91
|
+
return true;
|
|
92
|
+
const message = messages.get(messageId, { includeDeleted: true });
|
|
93
|
+
return message?.topicId === topicId && message.deletedAt === undefined;
|
|
94
|
+
};
|
|
95
|
+
const jobChatTarget = ({ topicId, startedMessageId, thread }) => visibleMessage(topicId, startedMessageId) ? startedMessageId
|
|
96
|
+
: visibleMessage(topicId, thread) ? thread
|
|
97
|
+
: undefined;
|
|
98
|
+
const runningView = ({ child, output: _output, stopped: _stopped, ...record }) => {
|
|
99
|
+
const target = jobChatTarget(record);
|
|
100
|
+
return {
|
|
101
|
+
...record, status: 'running', runningFor: `${Math.round((Date.now() - record.startedAt) / 1000)}s`, pid: child.pid,
|
|
102
|
+
...(target ? { address: address.message(record.topicId, target) } : {}),
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
const historyView = (record) => {
|
|
106
|
+
if (record.endedAt === undefined)
|
|
107
|
+
return { ...record, status: 'failed', error: RESTARTED };
|
|
108
|
+
const view = { ...record, status: resultStatus(record), durationMs: record.endedAt - record.startedAt };
|
|
109
|
+
const message = record.messageId ? messages.get(record.messageId, { includeDeleted: true }) : undefined;
|
|
110
|
+
if (message?.topicId !== record.topicId)
|
|
111
|
+
return view;
|
|
112
|
+
return message.deletedAt !== undefined ? { ...view, messageDeleted: true } : { ...view, address: address.message(record.topicId, message.id) };
|
|
113
|
+
};
|
|
114
|
+
const report = (job, title, result, output, hint = '') => {
|
|
115
|
+
const heading = /[\r\n`]/.test(job.command)
|
|
116
|
+
? `${title}(${result}):\n${fencedBlock(job.command)}`
|
|
117
|
+
: `${title}:\`${job.command}\`(${result})`;
|
|
118
|
+
const tail = output.trim();
|
|
119
|
+
return notifier.send({
|
|
120
|
+
topicId: job.topicId, targets: [job.memberId], thread: job.thread,
|
|
121
|
+
content: [
|
|
122
|
+
heading,
|
|
123
|
+
job.note ? `启动时的备注:${job.note}` : '',
|
|
124
|
+
tail ? `输出(末尾部分):\n${fencedBlock(tail)}` : '没有输出。',
|
|
125
|
+
hint,
|
|
126
|
+
].filter(Boolean).join('\n\n'),
|
|
127
|
+
}).message.id;
|
|
128
|
+
};
|
|
129
|
+
const forget = ({ jobId }) => {
|
|
130
|
+
openJobs.delete(jobId);
|
|
131
|
+
saveOpen();
|
|
132
|
+
};
|
|
133
|
+
const clearCheck = async (open) => {
|
|
134
|
+
if (open.checkTaskId) {
|
|
135
|
+
if (!hasSchedule())
|
|
136
|
+
return;
|
|
137
|
+
await entry.invoke('schedule.remove', { id: open.checkTaskId }).catch((error) => {
|
|
138
|
+
// The task may have been canceled by the owner or already removed before a restart.
|
|
139
|
+
if (!(error instanceof HttpError) || error.status !== 404)
|
|
140
|
+
throw error;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
forget(open);
|
|
144
|
+
};
|
|
145
|
+
const finish = async (open, dir, record, result, output = '') => {
|
|
146
|
+
const endedAt = Date.now();
|
|
147
|
+
const seconds = Math.round((endedAt - record.startedAt) / 1000);
|
|
148
|
+
const { code, signal, stopped, timedOut, error } = result;
|
|
149
|
+
const identity = { jobId: record.id, topicId: record.topicId, memberId: record.memberId };
|
|
150
|
+
const finished = { ...identity, code, signal, stopped, error };
|
|
151
|
+
const interrupted = error === RESTARTED;
|
|
152
|
+
const title = record.service
|
|
153
|
+
? interrupted ? '服务已停止(宿主重启)' : stopped ? '服务已停止' : '服务意外退出'
|
|
154
|
+
: interrupted ? '后台任务中断(宿主重启)' : timedOut ? '后台任务超时' : stopped ? '后台任务被停止' : '后台任务结束';
|
|
155
|
+
const hint = record.service && interrupted ? '如果还需要此服务,可用原命令再次调用 `job_start`,并传入 `service: true`。' : '';
|
|
156
|
+
const reason = error ?? (code === null ? `信号 ${signal}` : `退出码 ${code}`);
|
|
157
|
+
try {
|
|
158
|
+
finished.messageId = report(record, title, `${reason},用时 ${seconds} 秒`, output, hint);
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
finished.error ??= errorText(error);
|
|
162
|
+
}
|
|
163
|
+
const { messageId } = finished;
|
|
164
|
+
try {
|
|
165
|
+
if (existsSync(dir)) {
|
|
166
|
+
appendRecord(historyFile(dir), {
|
|
167
|
+
...record, checkTaskId: open.checkTaskId,
|
|
168
|
+
endedAt, code, signal, stopped, timedOut, messageId, error: finished.error,
|
|
169
|
+
});
|
|
170
|
+
push.send('background.changed', {
|
|
171
|
+
...identity, status: resultStatus({ ...result, service: record.service }), ...(messageId ? { messageId } : {}),
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
await clearCheck(open);
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
log('background', `could not finalize ${record.id}`, error);
|
|
178
|
+
}
|
|
179
|
+
ctx.runtime.emit('background.finished', finished);
|
|
180
|
+
};
|
|
181
|
+
const reconcile = async (open) => {
|
|
182
|
+
const topic = topics.get(open.topicId);
|
|
183
|
+
if (!topic) {
|
|
184
|
+
forget(open);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const record = readHistory(historyFile(topic.dir)).find(({ id }) => id === open.jobId);
|
|
188
|
+
if (!record || record.endedAt !== undefined) {
|
|
189
|
+
await clearCheck(open);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
await finish(open, topic.dir, record, { code: null, signal: null, stopped: false, error: RESTARTED });
|
|
193
|
+
};
|
|
194
|
+
const background = {
|
|
195
|
+
start({ topicId, memberId, command, note = '', thread, startedMessageId, checkEvery, timeout, service }) {
|
|
196
|
+
const topic = topics.get(topicId);
|
|
197
|
+
if (!topic || topic.deletedAt)
|
|
198
|
+
throw new HttpError(404, '没有这个主题');
|
|
199
|
+
if (topic.archivedAt !== null)
|
|
200
|
+
throw new HttpError(409, '主题已归档');
|
|
201
|
+
const recipient = members.get(memberId);
|
|
202
|
+
if (!recipient?.enabled)
|
|
203
|
+
throw new Error('没有这个成员,或者它停用了');
|
|
204
|
+
if (!a2a.worksIn(topicId, memberId))
|
|
205
|
+
throw new Error(`成员 ${recipient.name} 不在这个主题的成员里`);
|
|
206
|
+
if (!command.trim())
|
|
207
|
+
throw new Error('命令不能为空');
|
|
208
|
+
let mode;
|
|
209
|
+
if (service) {
|
|
210
|
+
if (checkEvery !== undefined || timeout !== undefined)
|
|
211
|
+
throw new HttpError(400, '常驻服务不能同时设置 checkEvery 或 timeout');
|
|
212
|
+
mode = { service: true };
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
const settings = ext.config.all();
|
|
216
|
+
checkEvery ??= Number(settings.checkEvery);
|
|
217
|
+
timeout ??= Number(settings.timeout);
|
|
218
|
+
if (checkEvery < 1 || timeout < 0)
|
|
219
|
+
throw new HttpError(400, '检查间隔至少 1 分钟,超时上限不能为负数');
|
|
220
|
+
mode = { checkEvery, timeout };
|
|
221
|
+
}
|
|
222
|
+
const record = {
|
|
223
|
+
id: newId('job'), topicId, memberId, command, note, startedAt: Date.now(),
|
|
224
|
+
...mode,
|
|
225
|
+
...(thread ? { thread } : {}),
|
|
226
|
+
...(startedMessageId ? { startedMessageId } : {}),
|
|
227
|
+
};
|
|
228
|
+
const file = historyFile(topic.dir);
|
|
229
|
+
const open = { jobId: record.id, topicId };
|
|
230
|
+
const job = {
|
|
231
|
+
...record, output: '',
|
|
232
|
+
child: startChild(`${command} 2>&1`, [], {
|
|
233
|
+
cwd: topic.dir,
|
|
234
|
+
shell: true,
|
|
235
|
+
onLine: (line) => (job.output = `${job.output}${line}\n`.slice(-6000)),
|
|
236
|
+
}),
|
|
237
|
+
};
|
|
238
|
+
try {
|
|
239
|
+
appendRecord(file, record);
|
|
240
|
+
openJobs.set(job.id, open);
|
|
241
|
+
saveOpen();
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
openJobs.delete(job.id);
|
|
245
|
+
job.child.kill(true);
|
|
246
|
+
throw error;
|
|
247
|
+
}
|
|
248
|
+
jobs.set(job.id, job);
|
|
249
|
+
const registration = !job.service && hasSchedule() ? entry.invoke('schedule.create', {
|
|
250
|
+
when: { kind: 'every', minutes: Math.max(1, Math.min(job.checkEvery, job.timeout || job.checkEvery)), from: job.startedAt },
|
|
251
|
+
op: 'instances.job_check', args: { jobId: job.id }, topicId, about: commandSummary(command),
|
|
252
|
+
}).then((task) => {
|
|
253
|
+
const { id } = task;
|
|
254
|
+
open.checkTaskId = job.checkTaskId = id;
|
|
255
|
+
saveOpen();
|
|
256
|
+
appendRecord(file, { ...record, checkTaskId: id });
|
|
257
|
+
return undefined;
|
|
258
|
+
}).catch((error) => {
|
|
259
|
+
job.child.kill(true);
|
|
260
|
+
return `检查登记失败:${errorText(error)}`;
|
|
261
|
+
}) : undefined;
|
|
262
|
+
void job.child.exited.then(async ({ code, signal }) => {
|
|
263
|
+
const error = await registration;
|
|
264
|
+
if (!jobs.delete(job.id))
|
|
265
|
+
return;
|
|
266
|
+
await finish(open, topic.dir, record, { code, signal, stopped: job.stopped === true, timedOut: job.timedOut, error }, job.output);
|
|
267
|
+
});
|
|
268
|
+
ctx.runtime.emit('background.started', { topicId });
|
|
269
|
+
push.send('background.changed', { jobId: job.id, topicId, memberId, status: 'running' });
|
|
270
|
+
return job.id;
|
|
271
|
+
},
|
|
272
|
+
get: (id) => jobs.get(id),
|
|
273
|
+
running: (topicId) => [...jobs.values()].filter((job) => job.topicId === topicId && !job.stopped)
|
|
274
|
+
.map(({ memberId, thread, startedAt }) => ({ memberId, thread, startedAt })),
|
|
275
|
+
};
|
|
276
|
+
ctx.provide('background', background);
|
|
277
|
+
const stop = (job) => {
|
|
278
|
+
job.stopped = true;
|
|
279
|
+
job.child.kill(true);
|
|
280
|
+
};
|
|
281
|
+
ctx.on('topic.updated', ({ topic }) => {
|
|
282
|
+
if (!topic.deletedAt && topic.archivedAt === null)
|
|
283
|
+
return;
|
|
284
|
+
for (const job of jobs.values())
|
|
285
|
+
if (job.topicId === topic.id)
|
|
286
|
+
stop(job);
|
|
287
|
+
});
|
|
288
|
+
ctx.effect(entry.op({
|
|
289
|
+
name: 'instances.job_start', about: '在主题目录启动耗时后台命令,命令结束后平台会在主题里发消息通知指定成员(启动后可直接结束本轮;不要依赖 CLI 自带的后台任务,其通知到不了主题)。',
|
|
290
|
+
input: object({
|
|
291
|
+
topicId: { type: 'string', description: '命令运行的主题编号' },
|
|
292
|
+
memberId: { type: 'string', member: true, description: '接收完成消息的成员,省略时通知调用者' },
|
|
293
|
+
command: { type: 'string' },
|
|
294
|
+
note: { type: 'string', description: '随完成消息附上的备注' },
|
|
295
|
+
checkEvery: { type: 'number', minimum: 1, description: '检查间隔(分钟),省略时沿用插件配置' },
|
|
296
|
+
timeout: { type: 'number', minimum: 0, description: '超时上限(分钟),0 为不限,省略时沿用插件配置' },
|
|
297
|
+
service: { type: 'boolean', description: '托管常驻服务。设为 true 时免检查和超时,不阻塞宿主重启,不能与 checkEvery 或 timeout 同传' },
|
|
298
|
+
}, ['topicId', 'command']),
|
|
299
|
+
http: ['POST', '/api/jobs'], topic: 'topicId', agent: true,
|
|
300
|
+
tool: { server: JOB_SERVER, name: 'job_start', plugin: ctx.name },
|
|
301
|
+
run({ topicId, memberId, command, note, checkEvery, timeout, service }, { member }) {
|
|
302
|
+
const live = member && a2a.live(topicId).find((turn) => turn.memberId === member.id);
|
|
303
|
+
const id = background.start({
|
|
304
|
+
topicId, memberId: memberId ?? member?.id ?? OWNER_ID, command, note, checkEvery, timeout, service,
|
|
305
|
+
...(live?.thread ? { thread: live.thread } : {}),
|
|
306
|
+
...(live?.messageId ? { startedMessageId: live.messageId } : {}),
|
|
307
|
+
});
|
|
308
|
+
return { id, open: address.topic(topicId) };
|
|
309
|
+
},
|
|
310
|
+
text: ({ id }) => `已启动,任务号 ${id}。现在可以结束这一轮,结束后会有消息叫你。`,
|
|
311
|
+
}));
|
|
312
|
+
ctx.effect(entry.op({
|
|
313
|
+
name: 'instances.job_check', about: '日程检查后台命令,提醒发起成员、停止已超时的命令或补报中断。',
|
|
314
|
+
input: object({ jobId: { type: 'string', description: '任务编号' } }, ['jobId']),
|
|
315
|
+
http: ['POST', '/api/jobs/:jobId/check'],
|
|
316
|
+
async run({ jobId }) {
|
|
317
|
+
const job = jobs.get(jobId);
|
|
318
|
+
if (!job) {
|
|
319
|
+
const open = openJobs.get(jobId);
|
|
320
|
+
if (open)
|
|
321
|
+
await reconcile(open);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (job.service || job.stopped)
|
|
325
|
+
return;
|
|
326
|
+
const elapsed = Date.now() - job.startedAt;
|
|
327
|
+
if (job.timeout > 0 && elapsed >= job.timeout * MINUTE) {
|
|
328
|
+
job.timedOut = true;
|
|
329
|
+
stop(job);
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
report(job, '后台任务仍在运行', `已运行 ${Math.round(elapsed / 1000)} 秒`, job.output);
|
|
333
|
+
},
|
|
334
|
+
}));
|
|
335
|
+
ctx.effect(entry.op({
|
|
336
|
+
name: 'instances.jobs', about: '列出运行中的后台任务。指定主题可同时读取已记录的历史,成员只看当前主题。',
|
|
337
|
+
input: object({
|
|
338
|
+
topic: { type: 'string', description: '主题编号,省略时列出所有运行中的任务' },
|
|
339
|
+
history: { type: 'boolean', description: '同时读取指定主题里的历史任务' },
|
|
340
|
+
}),
|
|
341
|
+
http: ['GET', '/api/jobs'], topic: 'topic', agent: true,
|
|
342
|
+
run({ topic: topicId, history }) {
|
|
343
|
+
if (topicId === undefined) {
|
|
344
|
+
if (history)
|
|
345
|
+
throw new HttpError(400, '读取历史要指定主题(topic)');
|
|
346
|
+
return [...jobs.values()].map(runningView);
|
|
347
|
+
}
|
|
348
|
+
const topic = topics.get(topicId);
|
|
349
|
+
if (!topic || topic.deletedAt)
|
|
350
|
+
throw new HttpError(404, '没有这个主题');
|
|
351
|
+
const running = [...jobs.values()].filter((job) => job.topicId === topic.id);
|
|
352
|
+
if (!history)
|
|
353
|
+
return running.map(runningView);
|
|
354
|
+
const records = readHistory(historyFile(topic.dir))
|
|
355
|
+
.filter((record) => record.topicId === topic.id && !jobs.has(record.id))
|
|
356
|
+
.sort((a, b) => (b.endedAt ?? b.startedAt) - (a.endedAt ?? a.startedAt));
|
|
357
|
+
return [...running.sort((a, b) => b.startedAt - a.startedAt).map(runningView), ...records.map(historyView)];
|
|
358
|
+
},
|
|
359
|
+
}));
|
|
360
|
+
ctx.effect(entry.op({
|
|
361
|
+
name: 'instances.job_stop', about: '停止一个后台任务。成员可以停止当前主题里的任务。',
|
|
362
|
+
input: object({ id: { type: 'string', description: '任务编号' } }, ['id']),
|
|
363
|
+
http: ['POST', '/api/jobs/:id/stop'], agent: true,
|
|
364
|
+
run({ id }, { member, topicId }) {
|
|
365
|
+
const job = jobs.get(id);
|
|
366
|
+
if (!job)
|
|
367
|
+
throw new HttpError(404, '没有这个任务,可能已经结束。');
|
|
368
|
+
if (member && job.topicId !== topicId)
|
|
369
|
+
throw new HttpError(403, '成员只能停止当前主题的后台任务。');
|
|
370
|
+
stop(job);
|
|
371
|
+
},
|
|
372
|
+
text: () => '已停止。',
|
|
373
|
+
}));
|
|
374
|
+
ctx.hook('restart.busy', () => [...jobs.values()].filter(({ service }) => !service).map((job) => {
|
|
375
|
+
const { id, topicId, memberId, command } = job;
|
|
376
|
+
const targetMid = jobChatTarget(job);
|
|
377
|
+
const base = targetMid ? address.message(topicId, targetMid) : address.topic(topicId);
|
|
378
|
+
const topic = addressLink(`${base}?job=${encodeURIComponent(id)}`, topics.get(topicId)?.title ?? topicId);
|
|
379
|
+
const member = (members.get(memberId)?.name ?? memberId).replace(/\s+/g, ' ');
|
|
380
|
+
return `后台任务 · ${member} · ${topic} · \`${commandSummary(command)}\``;
|
|
381
|
+
}));
|
|
382
|
+
ctx.effect(() => {
|
|
383
|
+
for (const job of jobs.values())
|
|
384
|
+
job.child.kill(true);
|
|
385
|
+
jobs.clear();
|
|
386
|
+
});
|
|
387
|
+
if (!home.checkOnly) {
|
|
388
|
+
const restore = async () => {
|
|
389
|
+
await Promise.all([...openJobs.values()].filter(({ jobId }) => !jobs.has(jobId)).map(reconcile));
|
|
390
|
+
};
|
|
391
|
+
if (ctx.runtime.ready)
|
|
392
|
+
await restore();
|
|
393
|
+
else
|
|
394
|
+
ctx.hook('host.ready', restore);
|
|
395
|
+
}
|
|
396
|
+
},
|
|
397
|
+
};
|
|
398
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"installed": [
|
|
3
|
+
{"id": "prompt", "version": null, "source": {"kind": "builtin", "path": "./prompt"}, "installedAt": 0, "updatedAt": 0},
|
|
4
|
+
{"id": "tools", "version": null, "source": {"kind": "builtin", "path": "./tools"}, "installedAt": 0, "updatedAt": 0},
|
|
5
|
+
{"id": "cards", "version": null, "source": {"kind": "builtin", "path": "./cards"}, "installedAt": 0, "updatedAt": 0},
|
|
6
|
+
{"id": "ask-choice", "version": null, "source": {"kind": "builtin", "path": "./ask-choice"}, "installedAt": 0, "updatedAt": 0},
|
|
7
|
+
{"id": "models", "version": null, "source": {"kind": "builtin", "path": "./models"}, "installedAt": 0, "updatedAt": 0},
|
|
8
|
+
{"id": "host-api", "version": null, "source": {"kind": "builtin", "path": "./host-api"}, "installedAt": 0, "updatedAt": 0},
|
|
9
|
+
{"id": "topic-tools", "version": null, "source": {"kind": "builtin", "path": "./topic-tools"}, "installedAt": 0, "updatedAt": 0},
|
|
10
|
+
{"id": "inbox", "version": null, "source": {"kind": "builtin", "path": "./inbox"}, "installedAt": 0, "updatedAt": 0},
|
|
11
|
+
{"id": "works", "version": null, "source": {"kind": "builtin", "path": "./works"}, "installedAt": 0, "updatedAt": 0},
|
|
12
|
+
{"id": "annotations", "version": null, "source": {"kind": "builtin", "path": "./annotations"}, "installedAt": 0, "updatedAt": 0},
|
|
13
|
+
{"id": "plans", "version": null, "source": {"kind": "builtin", "path": "./plans"}, "installedAt": 0, "updatedAt": 0},
|
|
14
|
+
{"id": "signals", "version": null, "source": {"kind": "builtin", "path": "./signals"}, "installedAt": 0, "updatedAt": 0},
|
|
15
|
+
{"id": "background", "version": null, "source": {"kind": "builtin", "path": "./background"}, "installedAt": 0, "updatedAt": 0},
|
|
16
|
+
{"id": "schedule", "version": null, "source": {"kind": "builtin", "path": "./schedule"}, "installedAt": 0, "updatedAt": 0},
|
|
17
|
+
{"id": "skills", "version": null, "source": {"kind": "builtin", "path": "./skills"}, "installedAt": 0, "updatedAt": 0},
|
|
18
|
+
{"id": "mcp", "version": null, "source": {"kind": "builtin", "path": "./mcp"}, "installedAt": 0, "updatedAt": 0},
|
|
19
|
+
{"id": "memory", "version": null, "source": {"kind": "builtin", "path": "./memory"}, "installedAt": 0, "updatedAt": 0},
|
|
20
|
+
{"id": "handoff", "version": null, "source": {"kind": "builtin", "path": "./handoff"}, "installedAt": 0, "updatedAt": 0},
|
|
21
|
+
{"id": "keys", "version": null, "source": {"kind": "builtin", "path": "./keys"}, "installedAt": 0, "updatedAt": 0},
|
|
22
|
+
{"id": "sessions", "version": null, "source": {"kind": "builtin", "path": "./sessions"}, "installedAt": 0, "updatedAt": 0},
|
|
23
|
+
{"id": "adapter-codex", "version": null, "source": {"kind": "builtin", "path": "./adapter-codex"}, "installedAt": 0, "updatedAt": 0},
|
|
24
|
+
{"id": "adapter-claude", "version": null, "source": {"kind": "builtin", "path": "./adapter-claude"}, "installedAt": 0, "updatedAt": 0},
|
|
25
|
+
{"id": "adapter-kimi", "version": null, "source": {"kind": "builtin", "path": "./adapter-kimi"}, "installedAt": 0, "updatedAt": 0},
|
|
26
|
+
{"id": "adapter-opencode", "version": null, "source": {"kind": "builtin", "path": "./adapter-opencode"}, "installedAt": 0, "updatedAt": 0},
|
|
27
|
+
{"id": "adapter-agy", "version": null, "source": {"kind": "builtin", "path": "./adapter-agy"}, "installedAt": 0, "updatedAt": 0},
|
|
28
|
+
{"id": "adapter-acp", "version": null, "source": {"kind": "builtin", "path": "./adapter-acp"}, "installedAt": 0, "updatedAt": 0},
|
|
29
|
+
{"id": "terminal", "version": null, "source": {"kind": "builtin", "path": "./terminal"}, "installedAt": 0, "updatedAt": 0},
|
|
30
|
+
{"id": "console", "version": null, "source": {"kind": "builtin", "path": "./console"}, "installedAt": 0, "updatedAt": 0},
|
|
31
|
+
{"id": "ops", "version": null, "source": {"kind": "builtin", "path": "./ops"}, "installedAt": 0, "updatedAt": 0},
|
|
32
|
+
{"id": "restart", "version": null, "source": {"kind": "builtin", "path": "./restart"}, "installedAt": 0, "updatedAt": 0},
|
|
33
|
+
{"id": "recovery", "version": null, "source": {"kind": "builtin", "path": "./recovery"}, "installedAt": 0, "updatedAt": 0},
|
|
34
|
+
{"id": "member-health", "version": null, "source": {"kind": "builtin", "path": "./member-health"}, "installedAt": 0, "updatedAt": 0},
|
|
35
|
+
{"id": "model-profiles", "version": null, "source": {"kind": "builtin", "path": "./model-profiles"}, "installedAt": 0, "updatedAt": 0}
|
|
36
|
+
]
|
|
37
|
+
}
|