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,76 @@
|
|
|
1
|
+
import { openStorage } from './storage.ts';
|
|
2
|
+
export declare const DEFAULT_MIGRATION_TIMEOUT_MS = 60000;
|
|
3
|
+
export interface PendingMigration {
|
|
4
|
+
home?: string;
|
|
5
|
+
topics?: string;
|
|
6
|
+
requestedAt: number;
|
|
7
|
+
}
|
|
8
|
+
export interface MigrationOutcome {
|
|
9
|
+
target: 'home' | 'topics';
|
|
10
|
+
from: string;
|
|
11
|
+
to: string;
|
|
12
|
+
ok: boolean;
|
|
13
|
+
timedOut?: boolean;
|
|
14
|
+
error?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface HomeLocations {
|
|
17
|
+
/** Active runtime data directory for this running host. */
|
|
18
|
+
home: string;
|
|
19
|
+
/** Active topics root directory for this running host. */
|
|
20
|
+
topics: string;
|
|
21
|
+
/** Configured target paths that will take effect on next start (may differ from active until restart). */
|
|
22
|
+
configured: {
|
|
23
|
+
home: string;
|
|
24
|
+
topics: string;
|
|
25
|
+
homeLocked?: 'env';
|
|
26
|
+
topicsLocked?: 'env';
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface Home {
|
|
30
|
+
/** The data root. Host runtime state lives under it. */
|
|
31
|
+
root: string;
|
|
32
|
+
/** Bootstrap root from `--home` / `HOSTLET_HOME` / default `~/.hostlet` before following `.env` `HOSTLET_HOME`. */
|
|
33
|
+
bootstrapRoot: string;
|
|
34
|
+
/** The topics tree directory. Defaults to `<root>/topics`, or can be configured independently via `HOSTLET_TOPICS_DIR`. */
|
|
35
|
+
topicsDir: string;
|
|
36
|
+
/** This start checks that the host can load and then exits. */
|
|
37
|
+
checkOnly: boolean;
|
|
38
|
+
path(...parts: string[]): string;
|
|
39
|
+
topicsPath(...parts: string[]): string;
|
|
40
|
+
storage: ReturnType<typeof openStorage>;
|
|
41
|
+
/** `.env` entries: the few settings that only take effect on restart. */
|
|
42
|
+
env: Record<string, string>;
|
|
43
|
+
/** Directory migration outcomes recorded during startup before services booted. */
|
|
44
|
+
migrations: readonly MigrationOutcome[];
|
|
45
|
+
/** The commit of the code this process started from, when it runs from a repository; what is on disk later may differ. */
|
|
46
|
+
codeCommit?: string;
|
|
47
|
+
/** Whether that commit describes the worktree at startup. */
|
|
48
|
+
codeCommitClean?: boolean;
|
|
49
|
+
/** Configured directory targets (mutable when user schedules or cancels a directory migration before restart). */
|
|
50
|
+
locations(): HomeLocations;
|
|
51
|
+
setLocation(target: 'home' | 'topics', nextPath: string): HomeLocations & {
|
|
52
|
+
restartRequired: boolean;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export type PathValidationError = 'pathAbsolute' | 'pathNotDir' | 'pathOverlap' | 'pathNotEmpty';
|
|
56
|
+
/** Validate a directory move destination. Same path as `from` is allowed (cancels any pending move). */
|
|
57
|
+
export declare function validateMigrationTarget(from: string, to: string): {
|
|
58
|
+
ok: true;
|
|
59
|
+
resolved: string;
|
|
60
|
+
same: boolean;
|
|
61
|
+
} | {
|
|
62
|
+
ok: false;
|
|
63
|
+
code: PathValidationError;
|
|
64
|
+
};
|
|
65
|
+
export interface MigrationOptions {
|
|
66
|
+
timeoutMs?: number;
|
|
67
|
+
/** Test hook: bypass same-filesystem atomic rename and exercise the streaming copy + timeout path. */
|
|
68
|
+
forceCopy?: boolean;
|
|
69
|
+
/** Test hook: optional per-file delay in ms during streaming copy to deterministically exercise timeout handling. */
|
|
70
|
+
copyDelayMs?: number;
|
|
71
|
+
}
|
|
72
|
+
/** Execute any scheduled directory migration before opening SQLite/plugins; failure or timeout never blocks startup. */
|
|
73
|
+
export declare function prepareHome(argv?: readonly string[], options?: MigrationOptions): Promise<Home>;
|
|
74
|
+
/** `--home <dir>` wins over `HOSTLET_HOME`; the default is `~/.hostlet`. */
|
|
75
|
+
export declare function openHome(argv?: readonly string[], migrations?: readonly MigrationOutcome[]): Home;
|
|
76
|
+
export declare function updateEnvFile(file: string, key: string, value: string | null): void;
|
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
import { chmodSync, createReadStream, createWriteStream, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, readlinkSync, renameSync, rmdirSync, rmSync, symlinkSync, unlinkSync, writeFileSync, } from 'node:fs';
|
|
2
|
+
import { execFileSync } from 'node:child_process';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
5
|
+
import { pipeline } from 'node:stream/promises';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { openStorage } from "./storage.js";
|
|
8
|
+
import { errorText, log } from "./util.js";
|
|
9
|
+
const PENDING_FILE = 'pending-migration.json';
|
|
10
|
+
export const DEFAULT_MIGRATION_TIMEOUT_MS = 60_000;
|
|
11
|
+
function isSubpath(parent, child) {
|
|
12
|
+
const rel = relative(parent, child);
|
|
13
|
+
return rel !== '' && !rel.startsWith('..') && !isAbsolute(rel);
|
|
14
|
+
}
|
|
15
|
+
/** Validate a directory move destination. Same path as `from` is allowed (cancels any pending move). */
|
|
16
|
+
export function validateMigrationTarget(from, to) {
|
|
17
|
+
const trimmed = to.trim();
|
|
18
|
+
if (!trimmed || !isAbsolute(trimmed))
|
|
19
|
+
return { ok: false, code: 'pathAbsolute' };
|
|
20
|
+
const resolvedFrom = resolve(from);
|
|
21
|
+
const resolved = resolve(trimmed);
|
|
22
|
+
if (resolved === resolvedFrom)
|
|
23
|
+
return { ok: true, resolved, same: true };
|
|
24
|
+
if (isSubpath(resolvedFrom, resolved) || isSubpath(resolved, resolvedFrom))
|
|
25
|
+
return { ok: false, code: 'pathOverlap' };
|
|
26
|
+
const info = lstatSync(resolved, { throwIfNoEntry: false });
|
|
27
|
+
if (info && !info.isDirectory())
|
|
28
|
+
return { ok: false, code: 'pathNotDir' };
|
|
29
|
+
if (info && readdirSync(resolved).length > 0)
|
|
30
|
+
return { ok: false, code: 'pathNotEmpty' };
|
|
31
|
+
return { ok: true, resolved, same: false };
|
|
32
|
+
}
|
|
33
|
+
function resolveRoots(argv) {
|
|
34
|
+
const flag = argv.indexOf('--home');
|
|
35
|
+
const cliHome = flag >= 0 && argv[flag + 1] ? argv[flag + 1] : undefined;
|
|
36
|
+
const envHome = !cliHome && process.env.HOSTLET_HOME?.trim() ? process.env.HOSTLET_HOME.trim() : undefined;
|
|
37
|
+
const bootstrapRoot = resolve(cliHome ?? envHome ?? join(homedir(), '.hostlet'));
|
|
38
|
+
const bootstrapEnv = readEnv(join(bootstrapRoot, '.env'));
|
|
39
|
+
const redirected = !envHome && bootstrapEnv.HOSTLET_HOME?.trim() ? resolve(bootstrapEnv.HOSTLET_HOME.trim()) : undefined;
|
|
40
|
+
const root = redirected ?? bootstrapRoot;
|
|
41
|
+
const env = root === bootstrapRoot ? bootstrapEnv : readEnv(join(root, '.env'));
|
|
42
|
+
const envTopics = process.env.HOSTLET_TOPICS_DIR?.trim() ? process.env.HOSTLET_TOPICS_DIR.trim() : undefined;
|
|
43
|
+
const configuredTopicsRaw = envTopics ?? (env.HOSTLET_TOPICS_DIR?.trim() || undefined);
|
|
44
|
+
const topicsDir = resolve(configuredTopicsRaw ?? join(root, 'topics'));
|
|
45
|
+
return {
|
|
46
|
+
bootstrapRoot,
|
|
47
|
+
root,
|
|
48
|
+
env,
|
|
49
|
+
topicsDir,
|
|
50
|
+
homeLocked: envHome ? 'env' : undefined,
|
|
51
|
+
topicsLocked: envTopics ? 'env' : undefined,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function readPending(root) {
|
|
55
|
+
const file = join(root, PENDING_FILE);
|
|
56
|
+
if (!existsSync(file))
|
|
57
|
+
return null;
|
|
58
|
+
try {
|
|
59
|
+
const parsed = JSON.parse(readFileSync(file, 'utf8'));
|
|
60
|
+
if (!parsed || typeof parsed !== 'object')
|
|
61
|
+
return null;
|
|
62
|
+
const out = { requestedAt: typeof parsed.requestedAt === 'number' ? parsed.requestedAt : Date.now() };
|
|
63
|
+
if (typeof parsed.home === 'string' && parsed.home.trim())
|
|
64
|
+
out.home = resolve(parsed.home.trim());
|
|
65
|
+
if (typeof parsed.topics === 'string' && parsed.topics.trim())
|
|
66
|
+
out.topics = resolve(parsed.topics.trim());
|
|
67
|
+
return out.home || out.topics ? out : null;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function writePending(root, pending) {
|
|
74
|
+
const file = join(root, PENDING_FILE);
|
|
75
|
+
if (!pending || (!pending.home && !pending.topics)) {
|
|
76
|
+
if (existsSync(file))
|
|
77
|
+
unlinkSync(file);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
writeFileSync(file, `${JSON.stringify(pending, null, 2)}\n`, 'utf8');
|
|
81
|
+
}
|
|
82
|
+
class MigrationTimeoutError extends Error {
|
|
83
|
+
constructor() {
|
|
84
|
+
super('MIGRATION_TIMEOUT');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async function copyFileAbortable(src, dst, mode, signal, delayMs) {
|
|
88
|
+
if (signal.aborted)
|
|
89
|
+
throw new MigrationTimeoutError();
|
|
90
|
+
if (delayMs && delayMs > 0) {
|
|
91
|
+
await new Promise((resolveDelay, rejectDelay) => {
|
|
92
|
+
const onAbort = () => {
|
|
93
|
+
clearTimeout(timer);
|
|
94
|
+
rejectDelay(new MigrationTimeoutError());
|
|
95
|
+
};
|
|
96
|
+
const timer = setTimeout(() => {
|
|
97
|
+
signal.removeEventListener('abort', onAbort);
|
|
98
|
+
resolveDelay();
|
|
99
|
+
}, delayMs);
|
|
100
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
await pipeline(createReadStream(src), createWriteStream(dst, { mode }), { signal });
|
|
105
|
+
try {
|
|
106
|
+
chmodSync(dst, mode & 0o777);
|
|
107
|
+
}
|
|
108
|
+
catch { /* ignore unsupported mode changes */ }
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
if (signal.aborted)
|
|
112
|
+
throw new MigrationTimeoutError();
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async function copyTreeAbortable(from, to, signal, skipTopLevel, delayMs, topLevel = true) {
|
|
117
|
+
if (signal.aborted)
|
|
118
|
+
throw new MigrationTimeoutError();
|
|
119
|
+
mkdirSync(to, { recursive: true });
|
|
120
|
+
for (const entry of readdirSync(from, { withFileTypes: true })) {
|
|
121
|
+
if (signal.aborted)
|
|
122
|
+
throw new MigrationTimeoutError();
|
|
123
|
+
if (topLevel && skipTopLevel.has(entry.name))
|
|
124
|
+
continue;
|
|
125
|
+
const src = join(from, entry.name);
|
|
126
|
+
const dst = join(to, entry.name);
|
|
127
|
+
const info = lstatSync(src);
|
|
128
|
+
if (info.isSymbolicLink()) {
|
|
129
|
+
symlinkSync(readlinkSync(src), dst);
|
|
130
|
+
}
|
|
131
|
+
else if (info.isDirectory()) {
|
|
132
|
+
await copyTreeAbortable(src, dst, signal, skipTopLevel, delayMs, false);
|
|
133
|
+
}
|
|
134
|
+
else if (info.isFile()) {
|
|
135
|
+
await copyFileAbortable(src, dst, info.mode, signal, delayMs);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function cleanupTarget(to, existedBefore) {
|
|
140
|
+
try {
|
|
141
|
+
if (!existsSync(to))
|
|
142
|
+
return;
|
|
143
|
+
if (!existedBefore) {
|
|
144
|
+
rmSync(to, { recursive: true, force: true });
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
for (const entry of readdirSync(to)) {
|
|
148
|
+
rmSync(join(to, entry), { recursive: true, force: true });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
log('storage', `清理未完成迁移目标目录失败:${to}`, errorText(error));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function parseTimeout(raw, fallback) {
|
|
156
|
+
const n = Number(raw);
|
|
157
|
+
return Number.isFinite(n) && n > 0 ? n : fallback;
|
|
158
|
+
}
|
|
159
|
+
function copyNonHomeEnvEntries(fromEnvFile, toEnvFile) {
|
|
160
|
+
const entries = readEnv(fromEnvFile);
|
|
161
|
+
for (const [key, value] of Object.entries(entries)) {
|
|
162
|
+
if (key === 'HOSTLET_HOME')
|
|
163
|
+
continue;
|
|
164
|
+
updateEnvFile(toEnvFile, key, value);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async function migrateTopics(from, to, activeRoot, opts) {
|
|
168
|
+
const check = validateMigrationTarget(from, to);
|
|
169
|
+
if (!check.ok)
|
|
170
|
+
return { target: 'topics', from, to, ok: false, error: check.code };
|
|
171
|
+
if (check.same)
|
|
172
|
+
return { target: 'topics', from, to: check.resolved, ok: true };
|
|
173
|
+
if (!existsSync(from))
|
|
174
|
+
return { target: 'topics', from, to: check.resolved, ok: false, error: 'sourceMissing' };
|
|
175
|
+
const target = check.resolved;
|
|
176
|
+
const existedBefore = existsSync(target);
|
|
177
|
+
const commitEnv = () => {
|
|
178
|
+
const defaultTopics = join(activeRoot, 'topics');
|
|
179
|
+
updateEnvFile(join(activeRoot, '.env'), 'HOSTLET_TOPICS_DIR', target === defaultTopics ? null : target);
|
|
180
|
+
};
|
|
181
|
+
if (!opts.forceCopy) {
|
|
182
|
+
try {
|
|
183
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
184
|
+
if (existedBefore)
|
|
185
|
+
rmdirSync(target);
|
|
186
|
+
renameSync(from, target);
|
|
187
|
+
commitEnv();
|
|
188
|
+
return { target: 'topics', from, to: target, ok: true };
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
if (error.code !== 'EXDEV') {
|
|
192
|
+
if (existedBefore && !existsSync(target)) {
|
|
193
|
+
try {
|
|
194
|
+
mkdirSync(target, { recursive: true });
|
|
195
|
+
}
|
|
196
|
+
catch { /* ignore */ }
|
|
197
|
+
}
|
|
198
|
+
return { target: 'topics', from, to: target, ok: false, error: errorText(error) };
|
|
199
|
+
}
|
|
200
|
+
if (existedBefore && !existsSync(target))
|
|
201
|
+
mkdirSync(target, { recursive: true });
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const controller = new AbortController();
|
|
205
|
+
const timer = setTimeout(() => controller.abort(new MigrationTimeoutError()), opts.timeoutMs);
|
|
206
|
+
timer.unref?.();
|
|
207
|
+
try {
|
|
208
|
+
await copyTreeAbortable(from, target, controller.signal, new Set(), opts.copyDelayMs);
|
|
209
|
+
commitEnv();
|
|
210
|
+
try {
|
|
211
|
+
rmSync(from, { recursive: true, force: true });
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
log('storage', `移除旧主题目录失败:${from}`, errorText(error));
|
|
215
|
+
}
|
|
216
|
+
return { target: 'topics', from, to: target, ok: true };
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
cleanupTarget(target, existedBefore);
|
|
220
|
+
const timedOut = error instanceof MigrationTimeoutError || controller.signal.aborted;
|
|
221
|
+
return { target: 'topics', from, to: target, ok: false, timedOut, error: timedOut ? 'timeout' : errorText(error) };
|
|
222
|
+
}
|
|
223
|
+
finally {
|
|
224
|
+
clearTimeout(timer);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async function migrateHome(from, to, bootstrapRoot, opts) {
|
|
228
|
+
const check = validateMigrationTarget(from, to);
|
|
229
|
+
if (!check.ok)
|
|
230
|
+
return { target: 'home', from, to, ok: false, error: check.code };
|
|
231
|
+
if (check.same)
|
|
232
|
+
return { target: 'home', from, to: check.resolved, ok: true };
|
|
233
|
+
if (!existsSync(from))
|
|
234
|
+
return { target: 'home', from, to: check.resolved, ok: false, error: 'sourceMissing' };
|
|
235
|
+
const target = check.resolved;
|
|
236
|
+
const existedBefore = existsSync(target);
|
|
237
|
+
const skip = new Set(['.env', PENDING_FILE]);
|
|
238
|
+
const commitEnv = () => {
|
|
239
|
+
const fromEnv = join(from, '.env');
|
|
240
|
+
const toEnv = join(target, '.env');
|
|
241
|
+
if (existsSync(fromEnv))
|
|
242
|
+
copyNonHomeEnvEntries(fromEnv, toEnv);
|
|
243
|
+
mkdirSync(bootstrapRoot, { recursive: true });
|
|
244
|
+
updateEnvFile(join(bootstrapRoot, '.env'), 'HOSTLET_HOME', target === bootstrapRoot ? null : target);
|
|
245
|
+
};
|
|
246
|
+
if (!opts.forceCopy) {
|
|
247
|
+
const moved = [];
|
|
248
|
+
let crossDevice = false;
|
|
249
|
+
try {
|
|
250
|
+
mkdirSync(target, { recursive: true });
|
|
251
|
+
for (const entry of readdirSync(from, { withFileTypes: true })) {
|
|
252
|
+
if (skip.has(entry.name))
|
|
253
|
+
continue;
|
|
254
|
+
renameSync(join(from, entry.name), join(target, entry.name));
|
|
255
|
+
moved.push(entry.name);
|
|
256
|
+
}
|
|
257
|
+
commitEnv();
|
|
258
|
+
if (from !== bootstrapRoot) {
|
|
259
|
+
try {
|
|
260
|
+
rmSync(from, { recursive: true, force: true });
|
|
261
|
+
}
|
|
262
|
+
catch (error) {
|
|
263
|
+
log('storage', `移除旧数据目录失败:${from}`, errorText(error));
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return { target: 'home', from, to: target, ok: true };
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
for (const name of moved.reverse()) {
|
|
270
|
+
try {
|
|
271
|
+
renameSync(join(target, name), join(from, name));
|
|
272
|
+
}
|
|
273
|
+
catch { /* best-effort rollback */ }
|
|
274
|
+
}
|
|
275
|
+
if (error.code === 'EXDEV') {
|
|
276
|
+
crossDevice = true;
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
cleanupTarget(target, existedBefore);
|
|
280
|
+
return { target: 'home', from, to: target, ok: false, error: errorText(error) };
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (!crossDevice)
|
|
284
|
+
return { target: 'home', from, to: target, ok: false, error: 'unknown' };
|
|
285
|
+
}
|
|
286
|
+
const controller = new AbortController();
|
|
287
|
+
const timer = setTimeout(() => controller.abort(new MigrationTimeoutError()), opts.timeoutMs);
|
|
288
|
+
timer.unref?.();
|
|
289
|
+
try {
|
|
290
|
+
await copyTreeAbortable(from, target, controller.signal, skip, opts.copyDelayMs);
|
|
291
|
+
commitEnv();
|
|
292
|
+
for (const entry of readdirSync(from, { withFileTypes: true })) {
|
|
293
|
+
if (skip.has(entry.name))
|
|
294
|
+
continue;
|
|
295
|
+
try {
|
|
296
|
+
rmSync(join(from, entry.name), { recursive: true, force: true });
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
log('storage', `清理旧数据项失败:${entry.name}`, errorText(error));
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (from !== bootstrapRoot) {
|
|
303
|
+
try {
|
|
304
|
+
rmSync(from, { recursive: true, force: true });
|
|
305
|
+
}
|
|
306
|
+
catch { /* ignore */ }
|
|
307
|
+
}
|
|
308
|
+
return { target: 'home', from, to: target, ok: true };
|
|
309
|
+
}
|
|
310
|
+
catch (error) {
|
|
311
|
+
cleanupTarget(target, existedBefore);
|
|
312
|
+
const timedOut = error instanceof MigrationTimeoutError || controller.signal.aborted;
|
|
313
|
+
return { target: 'home', from, to: target, ok: false, timedOut, error: timedOut ? 'timeout' : errorText(error) };
|
|
314
|
+
}
|
|
315
|
+
finally {
|
|
316
|
+
clearTimeout(timer);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
/** Execute any scheduled directory migration before opening SQLite/plugins; failure or timeout never blocks startup. */
|
|
320
|
+
export async function prepareHome(argv = process.argv.slice(2), options = {}) {
|
|
321
|
+
if (argv.includes('--check'))
|
|
322
|
+
return openHome(argv);
|
|
323
|
+
const initial = resolveRoots(argv);
|
|
324
|
+
const pending = readPending(initial.root);
|
|
325
|
+
if (!pending)
|
|
326
|
+
return openHome(argv);
|
|
327
|
+
// Consume the pending marker immediately so a crash during migration never loops on subsequent boots.
|
|
328
|
+
writePending(initial.root, null);
|
|
329
|
+
const timeoutMs = options.timeoutMs ?? parseTimeout(process.env.HOSTLET_MIGRATION_TIMEOUT_MS, DEFAULT_MIGRATION_TIMEOUT_MS);
|
|
330
|
+
const runOpts = { ...options, timeoutMs };
|
|
331
|
+
const outcomes = [];
|
|
332
|
+
if (pending.topics && !initial.topicsLocked) {
|
|
333
|
+
const outcome = await migrateTopics(initial.topicsDir, pending.topics, initial.root, runOpts);
|
|
334
|
+
outcomes.push(outcome);
|
|
335
|
+
if (!outcome.ok)
|
|
336
|
+
log('storage', `主题目录迁移未完成(${outcome.from} -> ${outcome.to})`, outcome.error ?? 'unknown');
|
|
337
|
+
}
|
|
338
|
+
if (pending.home && !initial.homeLocked) {
|
|
339
|
+
const outcome = await migrateHome(initial.root, pending.home, initial.bootstrapRoot, runOpts);
|
|
340
|
+
outcomes.push(outcome);
|
|
341
|
+
if (!outcome.ok)
|
|
342
|
+
log('storage', `数据目录迁移未完成(${outcome.from} -> ${outcome.to})`, outcome.error ?? 'unknown');
|
|
343
|
+
}
|
|
344
|
+
return openHome(argv, outcomes);
|
|
345
|
+
}
|
|
346
|
+
/** Read with the startup modules, before a data migration can wait on I/O. */
|
|
347
|
+
function readBootCode() {
|
|
348
|
+
const dir = fileURLToPath(new URL('../../', import.meta.url));
|
|
349
|
+
if (!existsSync(join(dir, '.git')))
|
|
350
|
+
return {};
|
|
351
|
+
const git = (...args) => execFileSync('git', ['--no-optional-locks', '-C', dir, ...args], {
|
|
352
|
+
encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'],
|
|
353
|
+
});
|
|
354
|
+
const boot = {};
|
|
355
|
+
try {
|
|
356
|
+
boot.codeCommit = git('rev-parse', '--short', 'HEAD').trim() || undefined;
|
|
357
|
+
boot.codeCommitClean = git('status', '--porcelain', '-z', '--untracked-files=normal', '--ignore-submodules=none') === '';
|
|
358
|
+
}
|
|
359
|
+
catch {
|
|
360
|
+
// An unavailable worktree status does not invalidate the version label.
|
|
361
|
+
}
|
|
362
|
+
return boot;
|
|
363
|
+
}
|
|
364
|
+
const bootCode = readBootCode();
|
|
365
|
+
/** `--home <dir>` wins over `HOSTLET_HOME`; the default is `~/.hostlet`. */
|
|
366
|
+
export function openHome(argv = process.argv.slice(2), migrations = []) {
|
|
367
|
+
const { bootstrapRoot, root, env, topicsDir, homeLocked, topicsLocked } = resolveRoots(argv);
|
|
368
|
+
for (const dir of ['', 'plugins', 'secrets']) {
|
|
369
|
+
mkdirSync(join(root, dir), { recursive: true, ...(dir === 'secrets' ? { mode: 0o700 } : {}) });
|
|
370
|
+
}
|
|
371
|
+
mkdirSync(topicsDir, { recursive: true });
|
|
372
|
+
const initialPending = readPending(root);
|
|
373
|
+
let pendingHome = initialPending?.home;
|
|
374
|
+
let pendingTopics = initialPending?.topics;
|
|
375
|
+
const locations = () => ({
|
|
376
|
+
home: root,
|
|
377
|
+
topics: topicsDir,
|
|
378
|
+
configured: {
|
|
379
|
+
home: pendingHome ?? root,
|
|
380
|
+
topics: pendingTopics ?? topicsDir,
|
|
381
|
+
...(homeLocked ? { homeLocked } : {}),
|
|
382
|
+
...(topicsLocked ? { topicsLocked } : {}),
|
|
383
|
+
},
|
|
384
|
+
});
|
|
385
|
+
const setLocation = (target, nextPath) => {
|
|
386
|
+
const resolved = resolve(nextPath);
|
|
387
|
+
if (target === 'home') {
|
|
388
|
+
pendingHome = resolved === root ? undefined : resolved;
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
pendingTopics = resolved === topicsDir ? undefined : resolved;
|
|
392
|
+
}
|
|
393
|
+
const nextPending = pendingHome || pendingTopics
|
|
394
|
+
? { ...(pendingHome ? { home: pendingHome } : {}), ...(pendingTopics ? { topics: pendingTopics } : {}), requestedAt: Date.now() }
|
|
395
|
+
: null;
|
|
396
|
+
writePending(root, nextPending);
|
|
397
|
+
const next = locations();
|
|
398
|
+
return { ...next, restartRequired: next.configured.home !== root || next.configured.topics !== topicsDir };
|
|
399
|
+
};
|
|
400
|
+
return {
|
|
401
|
+
root,
|
|
402
|
+
bootstrapRoot,
|
|
403
|
+
topicsDir,
|
|
404
|
+
checkOnly: argv.includes('--check'),
|
|
405
|
+
path: (...parts) => join(root, ...parts),
|
|
406
|
+
topicsPath: (...parts) => join(topicsDir, ...parts),
|
|
407
|
+
env,
|
|
408
|
+
migrations,
|
|
409
|
+
...bootCode,
|
|
410
|
+
storage: openStorage(root),
|
|
411
|
+
locations,
|
|
412
|
+
setLocation,
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
function readEnv(file) {
|
|
416
|
+
if (!existsSync(file))
|
|
417
|
+
return {};
|
|
418
|
+
const out = {};
|
|
419
|
+
for (const line of readFileSync(file, 'utf8').split(/\r?\n/)) {
|
|
420
|
+
const match = /^\s*([A-Z0-9_]+)\s*=\s*(.*?)\s*$/.exec(line);
|
|
421
|
+
if (match)
|
|
422
|
+
out[match[1]] = match[2].replace(/^(['"])(.*)\1$/, '$2');
|
|
423
|
+
}
|
|
424
|
+
return out;
|
|
425
|
+
}
|
|
426
|
+
function formatEnvValue(value) {
|
|
427
|
+
return /[\s#"'\\]/.test(value) ? JSON.stringify(value) : value;
|
|
428
|
+
}
|
|
429
|
+
export function updateEnvFile(file, key, value) {
|
|
430
|
+
const existing = existsSync(file) ? readFileSync(file, 'utf8').split(/\r?\n/) : [];
|
|
431
|
+
if (existing.length && existing.at(-1) === '')
|
|
432
|
+
existing.pop();
|
|
433
|
+
const pattern = new RegExp(`^\\s*${key}\\s*=`);
|
|
434
|
+
const nextLines = [];
|
|
435
|
+
let replaced = false;
|
|
436
|
+
for (const line of existing) {
|
|
437
|
+
if (pattern.test(line)) {
|
|
438
|
+
if (value !== null && !replaced) {
|
|
439
|
+
nextLines.push(`${key}=${formatEnvValue(value)}`);
|
|
440
|
+
replaced = true;
|
|
441
|
+
}
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
nextLines.push(line);
|
|
445
|
+
}
|
|
446
|
+
if (value !== null && !replaced)
|
|
447
|
+
nextLines.push(`${key}=${formatEnvValue(value)}`);
|
|
448
|
+
writeFileSync(file, nextLines.length ? `${nextLines.join('\n')}\n` : '', 'utf8');
|
|
449
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Disposer, Plugin } from '../runtime/runtime.ts';
|
|
2
|
+
export declare const SUPPORTED_LANGS: readonly ["zh", "en"];
|
|
3
|
+
export type Lang = (typeof SUPPORTED_LANGS)[number];
|
|
4
|
+
/** Structured localizable text: rendered dynamically in the active language on both host and console. */
|
|
5
|
+
export type LText = {
|
|
6
|
+
key: string;
|
|
7
|
+
args?: Record<string, unknown> | unknown[];
|
|
8
|
+
} | {
|
|
9
|
+
join: Array<LText | string>;
|
|
10
|
+
sep?: LText | string;
|
|
11
|
+
};
|
|
12
|
+
export type I18nDict = Record<string, unknown>;
|
|
13
|
+
export type I18nPacks = Partial<Record<Lang, I18nDict>>;
|
|
14
|
+
export declare function isLText(value: unknown): value is LText;
|
|
15
|
+
export declare function ltext(key: string, args?: Record<string, unknown> | unknown[]): LText;
|
|
16
|
+
export declare function ljoin(parts: Array<LText | string | false | null | undefined>, sep?: LText | string): LText;
|
|
17
|
+
export declare function normalizeLang(value: unknown): Lang;
|
|
18
|
+
/** Shared backend message packs (notices, errors, config descriptions, plugin metadata). */
|
|
19
|
+
export declare const CORE_I18N_PACKS: Record<string, Record<Lang, I18nDict>>;
|
|
20
|
+
export interface I18n {
|
|
21
|
+
lang(): Lang;
|
|
22
|
+
setLang(lang: Lang): void;
|
|
23
|
+
register(ns: string, packs: I18nPacks): Disposer;
|
|
24
|
+
t(key: string, args?: Record<string, unknown> | unknown[], lang?: Lang): string;
|
|
25
|
+
render(value: LText | string | undefined, fallback?: string, lang?: Lang): string;
|
|
26
|
+
packs(): Record<Lang, Record<string, I18nDict>>;
|
|
27
|
+
}
|
|
28
|
+
declare module '../runtime/runtime.ts' {
|
|
29
|
+
interface Services {
|
|
30
|
+
i18n: I18n;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export declare function createI18n(getLang: () => Lang, setLang: (lang: Lang) => void): I18n;
|
|
34
|
+
/** Standalone helper for code paths without a runtime (tests, pure helpers). */
|
|
35
|
+
export declare const defaultI18n: I18n;
|
|
36
|
+
export declare const i18nPlugin: Plugin;
|