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,276 @@
|
|
|
1
|
+
import childProcess from 'node:child_process';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { once } from 'node:events';
|
|
4
|
+
import { existsSync, globSync, readFileSync, statSync } from 'node:fs';
|
|
5
|
+
import { homedir } from 'node:os';
|
|
6
|
+
import { dirname, join, posix, resolve } from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
const APPLE_CATALOGUE = [
|
|
9
|
+
"ObjC.import('AppKit');",
|
|
10
|
+
'function run(args) {',
|
|
11
|
+
' const workspace = $.NSWorkspace.sharedWorkspace;',
|
|
12
|
+
" const url = $.NSURL.URLWithString('https://example.invalid/');",
|
|
13
|
+
' const handlers = workspace.URLsForApplicationsToOpenURL(url);',
|
|
14
|
+
' const html = workspace.URLsForApplicationsToOpenURL($.NSURL.fileURLWithPath(args[0]));',
|
|
15
|
+
' const htmlApps = [];',
|
|
16
|
+
' for (let i = 0; i < html.count; i++) htmlApps.push(html.objectAtIndex(i).path.js);',
|
|
17
|
+
' const browsers = [];',
|
|
18
|
+
' for (let i = 0; i < handlers.count; i++) {',
|
|
19
|
+
' const app = handlers.objectAtIndex(i);',
|
|
20
|
+
' if (!htmlApps.includes(app.path.js)) continue;',
|
|
21
|
+
' const id = $.NSBundle.bundleWithURL(app).bundleIdentifier.js;',
|
|
22
|
+
' const name = $.NSFileManager.defaultManager.displayNameAtPath(app.path).js;',
|
|
23
|
+
" if (id && name) browsers.push({ id, label: name.replace(/\\.app$/, ''), target: id });",
|
|
24
|
+
' }',
|
|
25
|
+
' return JSON.stringify(browsers);',
|
|
26
|
+
'}',
|
|
27
|
+
].join('\n');
|
|
28
|
+
const WINDOWS_CATALOGUE = [
|
|
29
|
+
"$ErrorActionPreference = 'Stop'",
|
|
30
|
+
'[Console]::OutputEncoding = [Text.UTF8Encoding]::new($false)',
|
|
31
|
+
'$browsers = @(foreach ($hive in @("HKCU:", "HKLM:")) {',
|
|
32
|
+
' $programs = Get-Item "$hive\\Software\\RegisteredApplications" -ErrorAction SilentlyContinue',
|
|
33
|
+
' if (!$programs) { continue }',
|
|
34
|
+
' foreach ($id in $programs.GetValueNames()) {',
|
|
35
|
+
' $path = $programs.GetValue($id)',
|
|
36
|
+
' $types = Get-Item "$hive\\$path\\URLAssociations" -ErrorAction SilentlyContinue',
|
|
37
|
+
' if (!$types -or !$types.GetValue("http") -or !$types.GetValue("https")) { continue }',
|
|
38
|
+
' $prog = $types.GetValue("https")',
|
|
39
|
+
' $open = Get-Item "Registry::HKEY_CLASSES_ROOT\\$prog\\shell\\open\\command" -ErrorAction SilentlyContinue',
|
|
40
|
+
' if (!$open) { continue }',
|
|
41
|
+
' $command = $open.GetValue("")',
|
|
42
|
+
' if ($command -match \'^"([^"]+\\.exe)"|^(.+?\\.exe)(?:\\s|$)\') {',
|
|
43
|
+
' $target = if ($Matches[1]) { $Matches[1] } else { $Matches[2] }',
|
|
44
|
+
' if (Test-Path -LiteralPath $target -PathType Leaf) {',
|
|
45
|
+
' $label = (Get-Item "$hive\\$path").GetValue("ApplicationName")',
|
|
46
|
+
' if (!$label -or $label.StartsWith("@")) { $label = $id }',
|
|
47
|
+
' @{ id = $id; label = $label; target = $target }',
|
|
48
|
+
' }',
|
|
49
|
+
' }',
|
|
50
|
+
' }',
|
|
51
|
+
'})',
|
|
52
|
+
'ConvertTo-Json -Compress -InputObject $browsers',
|
|
53
|
+
].join('\n');
|
|
54
|
+
const APPLE_PICK_FOLDER = [
|
|
55
|
+
'on run argv',
|
|
56
|
+
' set promptText to item 1 of argv',
|
|
57
|
+
' set startPath to item 2 of argv',
|
|
58
|
+
' try',
|
|
59
|
+
' if startPath is not "" then',
|
|
60
|
+
' set chosen to choose folder with prompt promptText default location (POSIX file startPath)',
|
|
61
|
+
' else',
|
|
62
|
+
' set chosen to choose folder with prompt promptText',
|
|
63
|
+
' end if',
|
|
64
|
+
' return POSIX path of chosen',
|
|
65
|
+
' on error number -128',
|
|
66
|
+
' return ""',
|
|
67
|
+
' end try',
|
|
68
|
+
'end run',
|
|
69
|
+
].join('\n');
|
|
70
|
+
// Hidden powershell.exe has no visible window, so an unowned dialog opens behind the browser and appears hung.
|
|
71
|
+
// An unshown TopMost Form keeps ownership in-process without compiling C# or disabling another process's window.
|
|
72
|
+
const windowsPicker = (dialogClass, configure, onOk) => [
|
|
73
|
+
"$ErrorActionPreference = 'Stop'",
|
|
74
|
+
'[Console]::OutputEncoding = [Text.UTF8Encoding]::new($false)',
|
|
75
|
+
'Add-Type -AssemblyName System.Windows.Forms',
|
|
76
|
+
'$owner = New-Object System.Windows.Forms.Form -Property @{ TopMost = $true }',
|
|
77
|
+
`$dialog = New-Object System.Windows.Forms.${dialogClass}`,
|
|
78
|
+
'try {',
|
|
79
|
+
...configure.map((line) => ` ${line}`),
|
|
80
|
+
` if ($dialog.ShowDialog($owner) -eq [System.Windows.Forms.DialogResult]::OK) { ${onOk} }`,
|
|
81
|
+
'} finally {',
|
|
82
|
+
' $dialog.Dispose()',
|
|
83
|
+
' $owner.Dispose()',
|
|
84
|
+
'}',
|
|
85
|
+
].join('\n');
|
|
86
|
+
const WINDOWS_PICK_FOLDER = windowsPicker('FolderBrowserDialog', [
|
|
87
|
+
'if ($env:HOSTLET_PICK_TITLE) { $dialog.Description = $env:HOSTLET_PICK_TITLE }',
|
|
88
|
+
'if ($env:HOSTLET_PICK_INITIAL -and (Test-Path -LiteralPath $env:HOSTLET_PICK_INITIAL -PathType Container)) { $dialog.SelectedPath = $env:HOSTLET_PICK_INITIAL }',
|
|
89
|
+
], '[Console]::Write($dialog.SelectedPath)');
|
|
90
|
+
const APPLE_PICK_FILES = `
|
|
91
|
+
function run(argv) {
|
|
92
|
+
const app = Application.currentApplication();
|
|
93
|
+
app.includeStandardAdditions = true;
|
|
94
|
+
const [title, multiple, ...extensions] = argv;
|
|
95
|
+
const options = { withPrompt: title, multipleSelectionsAllowed: multiple === 'true' };
|
|
96
|
+
if (extensions.length) options.ofType = extensions;
|
|
97
|
+
try {
|
|
98
|
+
const picked = app.chooseFile(options);
|
|
99
|
+
return JSON.stringify([].concat(picked).map(file => file.toString()));
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (error.errorNumber === -128) return '[]';
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
}`;
|
|
105
|
+
const WINDOWS_PICK_FILES = windowsPicker('OpenFileDialog', [
|
|
106
|
+
'$dialog.Title = $env:HOSTLET_PICK_TITLE',
|
|
107
|
+
"$dialog.Multiselect = $env:HOSTLET_PICK_MULTIPLE -eq 'true'",
|
|
108
|
+
'if ($env:HOSTLET_PICK_FILTER) { $dialog.Filter = $env:HOSTLET_PICK_FILTER }',
|
|
109
|
+
], 'ConvertTo-Json -Compress -InputObject @($dialog.FileNames)');
|
|
110
|
+
const ps = (command, sta = false) => ['-NoLogo', '-NoProfile', '-NonInteractive', ...(sta ? ['-STA'] : []), '-Command', command];
|
|
111
|
+
function run(command, args, options = {}) {
|
|
112
|
+
return new Promise((resolve, reject) => {
|
|
113
|
+
childProcess.execFile(command, args, { windowsHide: true, ...options, encoding: 'utf8' }, (error, stdout) => error ? reject(error) : resolve(stdout));
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
async function desktopHandlers(type) {
|
|
117
|
+
const output = await run('gio', ['mime', type], { env: { ...process.env, LC_ALL: 'C' } });
|
|
118
|
+
return new Set([...output.matchAll(/^[\t ]+(\S+\.desktop)$/gm)].map((match) => match[1]));
|
|
119
|
+
}
|
|
120
|
+
async function linuxBrowsers() {
|
|
121
|
+
const [https, html] = await Promise.all([desktopHandlers('x-scheme-handler/https'), desktopHandlers('text/html')]);
|
|
122
|
+
const dirs = [
|
|
123
|
+
process.env.XDG_DATA_HOME || join(homedir(), '.local/share'),
|
|
124
|
+
...(process.env.XDG_DATA_DIRS || '/usr/local/share:/usr/share').split(':'),
|
|
125
|
+
];
|
|
126
|
+
const browsers = [];
|
|
127
|
+
for (const dir of dirs) {
|
|
128
|
+
const applications = join(dir, 'applications');
|
|
129
|
+
if (!existsSync(applications))
|
|
130
|
+
continue;
|
|
131
|
+
for (const file of globSync('**/*.desktop', { cwd: applications })) {
|
|
132
|
+
const id = file.replaceAll('/', '-');
|
|
133
|
+
if (!https.has(id) || !html.has(id))
|
|
134
|
+
continue;
|
|
135
|
+
https.delete(id); // The user's registration takes precedence over a system copy.
|
|
136
|
+
const target = join(applications, file);
|
|
137
|
+
const entry = readFileSync(target, 'utf8').split(/^\[/m).find((section) => section.startsWith('Desktop Entry]')) ?? '';
|
|
138
|
+
const label = /^Name=(.+)$/m.exec(entry)?.[1]?.trim();
|
|
139
|
+
if (label && !/^(Hidden|NoDisplay)=true$/m.test(entry))
|
|
140
|
+
browsers.push({ id, label, target });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return browsers;
|
|
144
|
+
}
|
|
145
|
+
export async function listBrowsers(htmlPath, platform = process.platform) {
|
|
146
|
+
if (platform === 'darwin') {
|
|
147
|
+
return JSON.parse(await run('/usr/bin/osascript', ['-l', 'JavaScript', '-e', APPLE_CATALOGUE, htmlPath]));
|
|
148
|
+
}
|
|
149
|
+
if (platform === 'win32')
|
|
150
|
+
return JSON.parse(await run('powershell.exe', ps(WINDOWS_CATALOGUE)));
|
|
151
|
+
if (platform === 'linux')
|
|
152
|
+
return linuxBrowsers();
|
|
153
|
+
return [];
|
|
154
|
+
}
|
|
155
|
+
export async function openBrowser(url, target, platform = process.platform) {
|
|
156
|
+
if (platform === 'darwin') {
|
|
157
|
+
await run('/usr/bin/open', [...(target !== undefined ? ['-b', target] : []), url.href]);
|
|
158
|
+
}
|
|
159
|
+
else if (platform === 'win32') {
|
|
160
|
+
const command = target !== undefined
|
|
161
|
+
? 'Start-Process -FilePath $env:HOSTLET_BROWSER_APP -ArgumentList $env:HOSTLET_BROWSER_URL -ErrorAction Stop'
|
|
162
|
+
: 'Start-Process -FilePath $env:HOSTLET_BROWSER_URL -ErrorAction Stop';
|
|
163
|
+
await run('powershell.exe', ps(command), { env: { ...process.env, HOSTLET_BROWSER_APP: target, HOSTLET_BROWSER_URL: url.href } });
|
|
164
|
+
}
|
|
165
|
+
else if (target !== undefined) {
|
|
166
|
+
await run('gio', ['launch', target, url.href]);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
// Some xdg-open delegates wait until the browser exits.
|
|
170
|
+
const opener = childProcess.spawn('xdg-open', [url.href], { detached: true, stdio: 'ignore' });
|
|
171
|
+
await once(opener, 'spawn');
|
|
172
|
+
opener.unref();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
async function linuxDialog(zenityArgs, kdeArgs) {
|
|
176
|
+
try {
|
|
177
|
+
return { output: await run('zenity', zenityArgs), kde: false };
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
const { code } = error;
|
|
181
|
+
if (Number(code) === 1)
|
|
182
|
+
return null;
|
|
183
|
+
if (code !== 'ENOENT')
|
|
184
|
+
throw error;
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
return { output: await run('kdialog', kdeArgs), kde: true };
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
if (Number(error.code) === 1)
|
|
191
|
+
return null;
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function existingDirectory(candidate) {
|
|
196
|
+
const trimmed = candidate?.trim();
|
|
197
|
+
if (!trimmed)
|
|
198
|
+
return '';
|
|
199
|
+
try {
|
|
200
|
+
let full = resolve(trimmed);
|
|
201
|
+
while (!statSync(full, { throwIfNoEntry: false })?.isDirectory()) {
|
|
202
|
+
const parent = dirname(full);
|
|
203
|
+
if (parent === full)
|
|
204
|
+
return '';
|
|
205
|
+
full = parent;
|
|
206
|
+
}
|
|
207
|
+
return full;
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
return '';
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
export async function pickDirectory(title, candidate, platform = process.platform) {
|
|
214
|
+
const initial = existingDirectory(candidate);
|
|
215
|
+
if (platform === 'darwin') {
|
|
216
|
+
const out = (await run('/usr/bin/osascript', ['-e', APPLE_PICK_FOLDER, '--', title, initial])).trim();
|
|
217
|
+
return out ? resolve(out) : null;
|
|
218
|
+
}
|
|
219
|
+
if (platform === 'win32') {
|
|
220
|
+
const out = (await run('powershell.exe', ps(WINDOWS_PICK_FOLDER, true), {
|
|
221
|
+
env: { ...process.env, HOSTLET_PICK_TITLE: title, HOSTLET_PICK_INITIAL: initial },
|
|
222
|
+
})).trim();
|
|
223
|
+
return out ? resolve(out) : null;
|
|
224
|
+
}
|
|
225
|
+
if (platform === 'linux') {
|
|
226
|
+
const reply = await linuxDialog(['--file-selection', '--directory', `--title=${title}`, ...(initial ? [`--filename=${initial}/`] : [])], ['--getexistingdirectory', initial || '.', '--title', title]);
|
|
227
|
+
const path = reply?.output.trim();
|
|
228
|
+
return path ? resolve(path) : null;
|
|
229
|
+
}
|
|
230
|
+
throw new Error(`unsupported platform: ${platform}`);
|
|
231
|
+
}
|
|
232
|
+
export async function pickFiles(title, multiple, accept, platform = process.platform) {
|
|
233
|
+
const extensions = accept.split(',').map((value) => value.trim()).filter((value) => /^\.[\w.-]+$/.test(value));
|
|
234
|
+
const patterns = extensions.map((ext) => '*' + ext);
|
|
235
|
+
if (platform === 'darwin') {
|
|
236
|
+
const types = extensions.map((ext) => ext.slice(ext.lastIndexOf('.') + 1));
|
|
237
|
+
const out = await run('/usr/bin/osascript', ['-l', 'JavaScript', '-e', APPLE_PICK_FILES, '--', title, String(multiple), ...new Set(types)]);
|
|
238
|
+
return JSON.parse(out);
|
|
239
|
+
}
|
|
240
|
+
if (platform === 'win32') {
|
|
241
|
+
const filter = patterns.join(';');
|
|
242
|
+
const out = await run('powershell.exe', ps(WINDOWS_PICK_FILES, true), { env: { ...process.env, HOSTLET_PICK_TITLE: title,
|
|
243
|
+
HOSTLET_PICK_MULTIPLE: String(multiple), HOSTLET_PICK_FILTER: filter ? `${filter}|${filter}` : '' } });
|
|
244
|
+
return out.trim() ? JSON.parse(out) : [];
|
|
245
|
+
}
|
|
246
|
+
if (platform === 'linux') {
|
|
247
|
+
// Paths may contain any printable separator, including a newline.
|
|
248
|
+
const separator = randomUUID(), filter = patterns.join(' ');
|
|
249
|
+
const reply = await linuxDialog(['--file-selection', `--title=${title}`, ...(multiple ? ['--multiple', `--separator=${separator}`] : []), ...(filter ? [`--file-filter=${filter}`] : [])], ['--getopenurl', '.', filter, '--title', title, ...(multiple ? ['--multiple', '--separate-output'] : [])]);
|
|
250
|
+
if (!reply?.output.trim())
|
|
251
|
+
return [];
|
|
252
|
+
const output = reply.output.replace(/\n$/, '');
|
|
253
|
+
return reply.kde ? output.split('\n').map((url) => fileURLToPath(url)) : output.split(separator);
|
|
254
|
+
}
|
|
255
|
+
throw new Error(`unsupported platform: ${platform}`);
|
|
256
|
+
}
|
|
257
|
+
export function revealCommand(platform, target, directory) {
|
|
258
|
+
if (platform === 'darwin')
|
|
259
|
+
return { command: 'open', args: directory ? [target] : ['-R', target] };
|
|
260
|
+
if (platform === 'win32') {
|
|
261
|
+
// Explorer parses /select separately from the quoted native path.
|
|
262
|
+
return { command: 'explorer.exe', args: [directory ? `"${target}"` : `/select,"${target}"`], options: { windowsVerbatimArguments: true } };
|
|
263
|
+
}
|
|
264
|
+
return { command: 'xdg-open', args: [directory ? target : posix.dirname(target)] };
|
|
265
|
+
}
|
|
266
|
+
export async function revealFile(target, directory) {
|
|
267
|
+
const { command, args, options } = revealCommand(process.platform, target, directory);
|
|
268
|
+
await new Promise((resolve, reject) => {
|
|
269
|
+
childProcess.execFile(command, args, options, (error) => {
|
|
270
|
+
if (error && (command !== 'explorer.exe' || error.code !== 1))
|
|
271
|
+
reject(error);
|
|
272
|
+
else
|
|
273
|
+
resolve();
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Serialize async commits touching the same canonical file so retries cannot interleave. */
|
|
2
|
+
export declare function createFileLock(platform?: NodeJS.Platform): <T>(file: string, task: () => Promise<T>) => Promise<T>;
|
|
3
|
+
export interface ReplaceFileOptions {
|
|
4
|
+
platform?: NodeJS.Platform;
|
|
5
|
+
rename?: (from: string, to: string) => void;
|
|
6
|
+
sleep?: (ms: number) => Promise<void>;
|
|
7
|
+
delays?: readonly number[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Atomically replace `target` with `source`, re-running `prepare()` before every attempt.
|
|
11
|
+
* On Windows, transient readers (in-process async reads, search indexers, AV) can reject
|
|
12
|
+
* rename-over-existing with EPERM/EACCES/EBUSY until their handle closes; backing off
|
|
13
|
+
* asynchronously lets the event loop drain and re-verifying preserves 409 conflict semantics.
|
|
14
|
+
*/
|
|
15
|
+
export declare function replaceFile<T>(source: string, target: string, prepare: () => T, options?: ReplaceFileOptions): Promise<T>;
|
|
16
|
+
/** Reserve empty files with an exclusive DACL before the caller writes private bytes on Windows. */
|
|
17
|
+
export declare function preparePrivateFiles(paths: readonly string[]): void;
|
|
18
|
+
/** Open with O_NOFOLLOW where the OS supports it. */
|
|
19
|
+
export declare function openNoFollow(path: string, flags: number, mode?: number): number;
|
|
20
|
+
/** Refresh the timestamps on the same file descriptor after a successful read. */
|
|
21
|
+
export declare function readAndTouchFile<T>(path: string, used: Date, read: (fd: number) => T): T;
|
|
22
|
+
/** Stage a new file with the original POSIX mode even under a different umask. */
|
|
23
|
+
export declare function writeExclusiveFile(path: string, bytes: Uint8Array, mode: number): void;
|
|
24
|
+
export declare function linkDirectory(source: string, target: string): void;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { chmodSync, closeSync, constants, futimesSync, openSync, renameSync, symlinkSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
const WINDOWS_REPLACE_DELAYS_MS = [10, 20, 40, 80, 150, 250, 400, 500];
|
|
5
|
+
const RETRYABLE_RENAME_CODES = new Set(['EPERM', 'EACCES', 'EBUSY']);
|
|
6
|
+
/** Serialize async commits touching the same canonical file so retries cannot interleave. */
|
|
7
|
+
export function createFileLock(platform = process.platform) {
|
|
8
|
+
const tails = new Map();
|
|
9
|
+
return async function withFileLock(file, task) {
|
|
10
|
+
const key = platform === 'win32' ? file.toLowerCase() : file;
|
|
11
|
+
const prior = tails.get(key) ?? Promise.resolve();
|
|
12
|
+
let release;
|
|
13
|
+
const gate = new Promise((resolve) => { release = resolve; });
|
|
14
|
+
const tail = prior.then(() => gate);
|
|
15
|
+
tails.set(key, tail);
|
|
16
|
+
await prior;
|
|
17
|
+
try {
|
|
18
|
+
return await task();
|
|
19
|
+
}
|
|
20
|
+
finally {
|
|
21
|
+
release();
|
|
22
|
+
if (tails.get(key) === tail)
|
|
23
|
+
tails.delete(key);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Atomically replace `target` with `source`, re-running `prepare()` before every attempt.
|
|
29
|
+
* On Windows, transient readers (in-process async reads, search indexers, AV) can reject
|
|
30
|
+
* rename-over-existing with EPERM/EACCES/EBUSY until their handle closes; backing off
|
|
31
|
+
* asynchronously lets the event loop drain and re-verifying preserves 409 conflict semantics.
|
|
32
|
+
*/
|
|
33
|
+
export async function replaceFile(source, target, prepare, options = {}) {
|
|
34
|
+
const platform = options.platform ?? process.platform;
|
|
35
|
+
const rename = options.rename ?? renameSync;
|
|
36
|
+
const sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
37
|
+
const delays = platform === 'win32' ? (options.delays ?? WINDOWS_REPLACE_DELAYS_MS) : [];
|
|
38
|
+
for (let attempt = 0;; attempt++) {
|
|
39
|
+
const result = prepare();
|
|
40
|
+
try {
|
|
41
|
+
rename(source, target);
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
const code = error.code;
|
|
46
|
+
if (!code || !RETRYABLE_RENAME_CODES.has(code) || attempt >= delays.length)
|
|
47
|
+
throw error;
|
|
48
|
+
await sleep(delays[attempt]);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const WINDOWS_CREATE_PRIVATE_FILES = `
|
|
53
|
+
$ErrorActionPreference = 'Stop'
|
|
54
|
+
$user = [System.Security.Principal.WindowsIdentity]::GetCurrent().User
|
|
55
|
+
$security = [System.Security.AccessControl.FileSecurity]::new()
|
|
56
|
+
$sections = [System.Security.AccessControl.AccessControlSections]::Access
|
|
57
|
+
$security.SetSecurityDescriptorSddlForm("D:P(A;;FA;;;$($user.Value))", $sections)
|
|
58
|
+
foreach ($path in $env:HOSTLET_PRIVATE_DOCUMENTS.Split([char]10)) {
|
|
59
|
+
$file = [System.IO.FileStream]::new($path, [System.IO.FileMode]::CreateNew,
|
|
60
|
+
[System.Security.AccessControl.FileSystemRights]::Write,
|
|
61
|
+
[System.IO.FileShare]::None, 4096, [System.IO.FileOptions]::None, $security)
|
|
62
|
+
$file.Dispose()
|
|
63
|
+
$actual = [System.IO.File]::GetAccessControl($path, $sections)
|
|
64
|
+
$rules = @($actual.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier]))
|
|
65
|
+
if (-not $actual.AreAccessRulesProtected -or $rules.Length -ne 1 -or
|
|
66
|
+
$rules[0].IdentityReference.Value -ne $user.Value -or $rules[0].IsInherited -or
|
|
67
|
+
$rules[0].AccessControlType -ne [System.Security.AccessControl.AccessControlType]::Allow -or
|
|
68
|
+
$rules[0].FileSystemRights -ne [System.Security.AccessControl.FileSystemRights]::FullControl) {
|
|
69
|
+
throw 'The filesystem did not apply the private file ACL.'
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
`;
|
|
73
|
+
/** Reserve empty files with an exclusive DACL before the caller writes private bytes on Windows. */
|
|
74
|
+
export function preparePrivateFiles(paths) {
|
|
75
|
+
if (process.platform !== 'win32' || !paths.length)
|
|
76
|
+
return;
|
|
77
|
+
const powershell = join(process.env.SystemRoot ?? 'C:\\Windows', 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe');
|
|
78
|
+
execFileSync(powershell, [
|
|
79
|
+
'-NoLogo', '-NoProfile', '-NonInteractive', '-EncodedCommand',
|
|
80
|
+
Buffer.from(WINDOWS_CREATE_PRIVATE_FILES, 'utf16le').toString('base64'),
|
|
81
|
+
], {
|
|
82
|
+
// Windows paths cannot contain a line feed. Splitting them needs no PowerShell module.
|
|
83
|
+
env: { ...process.env, HOSTLET_PRIVATE_DOCUMENTS: paths.join('\n') },
|
|
84
|
+
// Include PowerShell engine startup, which can dominate under process contention.
|
|
85
|
+
stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true, timeout: 30_000,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/** Open with O_NOFOLLOW where the OS supports it. */
|
|
89
|
+
export function openNoFollow(path, flags, mode) {
|
|
90
|
+
return openSync(path, flags | (constants.O_NOFOLLOW ?? 0), mode);
|
|
91
|
+
}
|
|
92
|
+
/** Refresh the timestamps on the same file descriptor after a successful read. */
|
|
93
|
+
export function readAndTouchFile(path, used, read) {
|
|
94
|
+
// O_RDWR grants FILE_WRITE_ATTRIBUTES on Windows for futimesSync.
|
|
95
|
+
const fd = openNoFollow(path, constants.O_RDWR);
|
|
96
|
+
try {
|
|
97
|
+
const value = read(fd);
|
|
98
|
+
futimesSync(fd, used, used);
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
closeSync(fd);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** Stage a new file with the original POSIX mode even under a different umask. */
|
|
106
|
+
export function writeExclusiveFile(path, bytes, mode) {
|
|
107
|
+
writeFileSync(path, bytes, { flag: 'wx', mode });
|
|
108
|
+
if (process.platform !== 'win32')
|
|
109
|
+
chmodSync(path, mode);
|
|
110
|
+
}
|
|
111
|
+
export function linkDirectory(source, target) {
|
|
112
|
+
symlinkSync(source, target, process.platform === 'win32' ? 'junction' : 'dir');
|
|
113
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { listBrowsers, openBrowser, pickDirectory, pickFiles, revealCommand, revealFile } from './desktop.ts';
|
|
2
|
+
export type { Browser } from './desktop.ts';
|
|
3
|
+
export { createFileLock, linkDirectory, openNoFollow, preparePrivateFiles, readAndTouchFile, replaceFile, writeExclusiveFile, } from './files.ts';
|
|
4
|
+
export { isNativeFileName } from './paths.ts';
|
|
5
|
+
export { firstLine, firstLineSync, interactiveShell, isProcessAlive, isProcessTreeAlive, onPath, quoteWindowsCommandArg, startChild } from './process.ts';
|
|
6
|
+
export type { Child, ChildOptions } from './process.ts';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { listBrowsers, openBrowser, pickDirectory, pickFiles, revealCommand, revealFile } from "./desktop.js";
|
|
2
|
+
export { createFileLock, linkDirectory, openNoFollow, preparePrivateFiles, readAndTouchFile, replaceFile, writeExclusiveFile, } from "./files.js";
|
|
3
|
+
export { isNativeFileName } from "./paths.js";
|
|
4
|
+
export { firstLine, firstLineSync, interactiveShell, isProcessAlive, isProcessTreeAlive, onPath, quoteWindowsCommandArg, startChild } from "./process.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function isNativeFileName(name, { rejectDeviceNames = false, platform = process.platform } = {}) {
|
|
2
|
+
if (/[/\0]/.test(name))
|
|
3
|
+
return false;
|
|
4
|
+
if (platform !== 'win32')
|
|
5
|
+
return true;
|
|
6
|
+
if (/[<>:"\\|?*\x00-\x1f]|[. ]$/.test(name))
|
|
7
|
+
return false;
|
|
8
|
+
return !rejectDeviceNames || !/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(name);
|
|
9
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type ChildProcess } from 'node:child_process';
|
|
2
|
+
/**
|
|
3
|
+
* A managed subprocess and its process-tree and stdio lifecycle.
|
|
4
|
+
*/
|
|
5
|
+
export interface Child {
|
|
6
|
+
readonly pid: number | undefined;
|
|
7
|
+
readonly proc: ChildProcess;
|
|
8
|
+
/** Write one line to the child's stdin. */
|
|
9
|
+
write(line: string): void;
|
|
10
|
+
/** End the child and what it started. `force` does not wait for it to finish on its own. */
|
|
11
|
+
kill(force?: boolean): void;
|
|
12
|
+
/** End a short-lived child tree and wait for its inherited stdio to close. */
|
|
13
|
+
stop(): Promise<void>;
|
|
14
|
+
exited: Promise<{
|
|
15
|
+
code: number | null;
|
|
16
|
+
signal: string | null;
|
|
17
|
+
stderr: string;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Quote one Windows executable or argument for `cmd.exe /d /s /c` so spaces and cmd metacharacters
|
|
22
|
+
* stay in one argv entry. Rejects `"`, `%`, and line breaks because cmd.exe does not honor `\"`
|
|
23
|
+
* escaping and expands `%VAR%` even inside double quotes.
|
|
24
|
+
*/
|
|
25
|
+
export declare function quoteWindowsCommandArg(value: string): string;
|
|
26
|
+
export interface ChildOptions {
|
|
27
|
+
cwd: string;
|
|
28
|
+
env: NodeJS.ProcessEnv;
|
|
29
|
+
/** Run `command` as a shell command line instead of launching one executable with argv. */
|
|
30
|
+
shell?: boolean;
|
|
31
|
+
onLine(line: string): void;
|
|
32
|
+
/** Return true to consume a diagnostic line without keeping it in the child's error tail. */
|
|
33
|
+
onStderrLine?(line: string): boolean;
|
|
34
|
+
}
|
|
35
|
+
export declare function startChild(command: string, args: readonly string[], opts: ChildOptions): Child;
|
|
36
|
+
/** Whether `command` can be started from PATH. */
|
|
37
|
+
export declare function onPath(command: string, env: NodeJS.ProcessEnv): Promise<boolean>;
|
|
38
|
+
/** First line a command prints, or undefined when it cannot run. */
|
|
39
|
+
export declare function firstLine(command: string, args: readonly string[], env: NodeJS.ProcessEnv): Promise<string | undefined>;
|
|
40
|
+
/** Synchronous first-line probe with the same timeout and output rules. */
|
|
41
|
+
export declare function firstLineSync(command: string, args: readonly string[], env: NodeJS.ProcessEnv): string | undefined;
|
|
42
|
+
export declare function interactiveShell(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): [string, ...string[]];
|
|
43
|
+
export declare function isProcessAlive(pid: number): boolean;
|
|
44
|
+
/** The managed child has its own process group on POSIX. */
|
|
45
|
+
export declare function isProcessTreeAlive(pid: number): boolean;
|