@waq666/pneuma 0.0.0-stage → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +206 -3
- package/bin/dsc.js +91 -0
- package/bin/headless.cjs +40 -0
- package/lib/adapter/core-runtime.d.ts +11 -0
- package/lib/adapter/core-runtime.js +259 -0
- package/lib/adapter/host.d.ts +18 -0
- package/lib/adapter/host.js +14 -0
- package/lib/adapter/runtime.d.ts +15 -0
- package/lib/adapter/runtime.js +290 -0
- package/lib/adapter/transcript.d.ts +184 -0
- package/lib/adapter/transcript.js +605 -0
- package/lib/app/AgentsOverlay.d.ts +18 -0
- package/lib/app/AgentsOverlay.js +63 -0
- package/lib/app/App.d.ts +15 -0
- package/lib/app/App.js +1650 -0
- package/lib/app/App.js.nv-backup +1650 -0
- package/lib/app/ApprovalCard.d.ts +12 -0
- package/lib/app/ApprovalCard.js +76 -0
- package/lib/app/AskCard.d.ts +20 -0
- package/lib/app/AskCard.js +45 -0
- package/lib/app/ChatView.d.ts +63 -0
- package/lib/app/ChatView.js +310 -0
- package/lib/app/Composer.d.ts +50 -0
- package/lib/app/Composer.js +282 -0
- package/lib/app/DiffBlock.d.ts +6 -0
- package/lib/app/DiffBlock.js +37 -0
- package/lib/app/MarkdownView.d.ts +6 -0
- package/lib/app/MarkdownView.js +99 -0
- package/lib/app/ModelPicker.d.ts +7 -0
- package/lib/app/ModelPicker.js +18 -0
- package/lib/app/PlanReviewCard.d.ts +13 -0
- package/lib/app/PlanReviewCard.js +54 -0
- package/lib/app/PresetPicker.d.ts +11 -0
- package/lib/app/PresetPicker.js +19 -0
- package/lib/app/PreviewOverlay.d.ts +14 -0
- package/lib/app/PreviewOverlay.js +22 -0
- package/lib/app/SessionPicker.d.ts +43 -0
- package/lib/app/SessionPicker.js +56 -0
- package/lib/app/SettingsOverlay.d.ts +32 -0
- package/lib/app/SettingsOverlay.js +157 -0
- package/lib/app/SkillsPicker.d.ts +7 -0
- package/lib/app/SkillsPicker.js +19 -0
- package/lib/app/StatusBar.d.ts +22 -0
- package/lib/app/StatusBar.js +201 -0
- package/lib/app/TaskStrips.d.ts +13 -0
- package/lib/app/TaskStrips.js +40 -0
- package/lib/app/TimelineRail.d.ts +22 -0
- package/lib/app/TimelineRail.js +160 -0
- package/lib/app/TimelineRail.js.negbak +98 -0
- package/lib/app/TimelineRail.js.nv-backup +160 -0
- package/lib/app/ToolCard.d.ts +11 -0
- package/lib/app/ToolCard.js +64 -0
- package/lib/app/ToolCard.js.nv-backup +64 -0
- package/lib/app/TranscriptOverlay.d.ts +27 -0
- package/lib/app/TranscriptOverlay.js +36 -0
- package/lib/app/TranscriptViewport.d.ts +78 -0
- package/lib/app/TranscriptViewport.js +218 -0
- package/lib/app/Welcome.d.ts +6 -0
- package/lib/app/Welcome.js +71 -0
- package/lib/app/attach.d.ts +16 -0
- package/lib/app/attach.js +58 -0
- package/lib/app/click.d.ts +40 -0
- package/lib/app/click.js +103 -0
- package/lib/app/clipboard-image.d.ts +11 -0
- package/lib/app/clipboard-image.js +66 -0
- package/lib/app/cursor.d.ts +4 -0
- package/lib/app/cursor.js +24 -0
- package/lib/app/hello.d.ts +11 -0
- package/lib/app/hello.js +8 -0
- package/lib/app/history-store.d.ts +4 -0
- package/lib/app/history-store.js +41 -0
- package/lib/app/image-blocks.d.ts +12 -0
- package/lib/app/image-blocks.js +125 -0
- package/lib/app/keymap.d.ts +56 -0
- package/lib/app/keymap.js +56 -0
- package/lib/app/markdown.d.ts +54 -0
- package/lib/app/markdown.js +189 -0
- package/lib/app/mouse.d.ts +33 -0
- package/lib/app/mouse.js +35 -0
- package/lib/app/pointer.d.ts +16 -0
- package/lib/app/pointer.js +60 -0
- package/lib/app/scroll-model.d.ts +240 -0
- package/lib/app/scroll-model.js +347 -0
- package/lib/app/settings-model.d.ts +69 -0
- package/lib/app/settings-model.js +114 -0
- package/lib/app/snapshot-subscribe.d.ts +34 -0
- package/lib/app/snapshot-subscribe.js +110 -0
- package/lib/app/theme.d.ts +194 -0
- package/lib/app/theme.js +186 -0
- package/lib/app/ticker.d.ts +7 -0
- package/lib/app/ticker.js +53 -0
- package/lib/boot.d.ts +1 -0
- package/lib/boot.js +34 -0
- package/lib/commands.d.ts +49 -0
- package/lib/commands.js +115 -0
- package/lib/contract.d.ts +1973 -0
- package/lib/contract.js +36 -0
- package/lib/core/agent-roles.d.ts +52 -0
- package/lib/core/agent-roles.js +274 -0
- package/lib/core/approval-floor.d.ts +183 -0
- package/lib/core/approval-floor.js +679 -0
- package/lib/core/approval.d.ts +42 -0
- package/lib/core/approval.js +8 -0
- package/lib/core/audit.d.ts +61 -0
- package/lib/core/audit.js +59 -0
- package/lib/core/boot-notices.d.ts +6 -0
- package/lib/core/boot-notices.js +61 -0
- package/lib/core/cdp/actions.d.ts +182 -0
- package/lib/core/cdp/actions.js +649 -0
- package/lib/core/cdp/launch.d.ts +192 -0
- package/lib/core/cdp/launch.js +491 -0
- package/lib/core/cdp/snapshot.d.ts +139 -0
- package/lib/core/cdp/snapshot.js +316 -0
- package/lib/core/cdp/transport.d.ts +160 -0
- package/lib/core/cdp/transport.js +359 -0
- package/lib/core/command-policy.d.ts +108 -0
- package/lib/core/command-policy.js +580 -0
- package/lib/core/commands-completion.d.ts +78 -0
- package/lib/core/commands-completion.js +167 -0
- package/lib/core/compact-anchors.d.ts +76 -0
- package/lib/core/compact-anchors.js +284 -0
- package/lib/core/compact.d.ts +110 -0
- package/lib/core/compact.js +210 -0
- package/lib/core/config-store.d.ts +38 -0
- package/lib/core/config-store.js +307 -0
- package/lib/core/config.d.ts +36 -0
- package/lib/core/config.js +124 -0
- package/lib/core/connection-test.d.ts +60 -0
- package/lib/core/connection-test.js +84 -0
- package/lib/core/desktop-control.d.ts +298 -0
- package/lib/core/desktop-control.js +1311 -0
- package/lib/core/diff-text.d.ts +74 -0
- package/lib/core/diff-text.js +257 -0
- package/lib/core/dock-browser.d.ts +137 -0
- package/lib/core/dock-browser.js +146 -0
- package/lib/core/dock-ops.d.ts +59 -0
- package/lib/core/dock-ops.js +104 -0
- package/lib/core/dock-session.d.ts +39 -0
- package/lib/core/dock-session.js +28 -0
- package/lib/core/dsh-compat/hook.d.ts +18 -0
- package/lib/core/dsh-compat/hook.js +52 -0
- package/lib/core/dsh-compat/resolve-hook.d.ts +5 -0
- package/lib/core/dsh-compat/resolve-hook.js +59 -0
- package/lib/core/dsh-compat/tools-facade.d.ts +47 -0
- package/lib/core/dsh-compat/tools-facade.js +108 -0
- package/lib/core/err-text.d.ts +13 -0
- package/lib/core/err-text.js +15 -0
- package/lib/core/events.d.ts +149 -0
- package/lib/core/events.js +1 -0
- package/lib/core/git-exec.d.ts +23 -0
- package/lib/core/git-exec.js +72 -0
- package/lib/core/git-info.d.ts +47 -0
- package/lib/core/git-info.js +157 -0
- package/lib/core/goal.d.ts +89 -0
- package/lib/core/goal.js +189 -0
- package/lib/core/hooks.d.ts +272 -0
- package/lib/core/hooks.js +818 -0
- package/lib/core/host-browser-link.d.ts +59 -0
- package/lib/core/host-browser-link.js +9 -0
- package/lib/core/host-methods.d.ts +25 -0
- package/lib/core/host-methods.js +103 -0
- package/lib/core/image-diet.d.ts +77 -0
- package/lib/core/image-diet.js +127 -0
- package/lib/core/learnings/ledger.d.ts +73 -0
- package/lib/core/learnings/ledger.js +273 -0
- package/lib/core/learnings/skill-write.d.ts +250 -0
- package/lib/core/learnings/skill-write.js +854 -0
- package/lib/core/learnings/store.d.ts +102 -0
- package/lib/core/learnings/store.js +266 -0
- package/lib/core/lifecycle-hooks.d.ts +189 -0
- package/lib/core/lifecycle-hooks.js +576 -0
- package/lib/core/llm.d.ts +283 -0
- package/lib/core/llm.js +565 -0
- package/lib/core/lockfile.d.ts +17 -0
- package/lib/core/lockfile.js +110 -0
- package/lib/core/loop.d.ts +185 -0
- package/lib/core/loop.js +587 -0
- package/lib/core/lsp/client.d.ts +189 -0
- package/lib/core/lsp/client.js +690 -0
- package/lib/core/lsp/framing.d.ts +84 -0
- package/lib/core/lsp/framing.js +181 -0
- package/lib/core/lsp/line-shift.d.ts +28 -0
- package/lib/core/lsp/line-shift.js +127 -0
- package/lib/core/lsp/manager.d.ts +93 -0
- package/lib/core/lsp/manager.js +418 -0
- package/lib/core/lsp/normalize.d.ts +32 -0
- package/lib/core/lsp/normalize.js +139 -0
- package/lib/core/lsp/servers.d.ts +106 -0
- package/lib/core/lsp/servers.js +352 -0
- package/lib/core/lsp/uri.d.ts +76 -0
- package/lib/core/lsp/uri.js +179 -0
- package/lib/core/market.d.ts +51 -0
- package/lib/core/market.js +358 -0
- package/lib/core/mcp.d.ts +201 -0
- package/lib/core/mcp.js +836 -0
- package/lib/core/memory-eval.d.ts +158 -0
- package/lib/core/memory-eval.js +215 -0
- package/lib/core/memory.d.ts +266 -0
- package/lib/core/memory.js +703 -0
- package/lib/core/mention.d.ts +57 -0
- package/lib/core/mention.js +129 -0
- package/lib/core/microcompact.d.ts +48 -0
- package/lib/core/microcompact.js +79 -0
- package/lib/core/migrate.d.ts +56 -0
- package/lib/core/migrate.js +134 -0
- package/lib/core/model-caps.d.ts +83 -0
- package/lib/core/model-caps.js +150 -0
- package/lib/core/model-discovery.d.ts +19 -0
- package/lib/core/model-discovery.js +69 -0
- package/lib/core/modes.d.ts +72 -0
- package/lib/core/modes.js +152 -0
- package/lib/core/native-bridge.d.ts +135 -0
- package/lib/core/native-bridge.js +563 -0
- package/lib/core/path-policy.d.ts +32 -0
- package/lib/core/path-policy.js +248 -0
- package/lib/core/permission-presets.d.ts +67 -0
- package/lib/core/permission-presets.js +75 -0
- package/lib/core/plugin-loader.d.ts +36 -0
- package/lib/core/plugin-loader.js +294 -0
- package/lib/core/plugin-registry.d.ts +113 -0
- package/lib/core/plugin-registry.js +256 -0
- package/lib/core/prefs.d.ts +82 -0
- package/lib/core/prefs.js +372 -0
- package/lib/core/presets.d.ts +80 -0
- package/lib/core/presets.js +373 -0
- package/lib/core/pricing.d.ts +90 -0
- package/lib/core/pricing.js +126 -0
- package/lib/core/prompt.d.ts +92 -0
- package/lib/core/prompt.js +339 -0
- package/lib/core/ptc.d.ts +66 -0
- package/lib/core/ptc.js +70 -0
- package/lib/core/remote/frames.d.ts +91 -0
- package/lib/core/remote/frames.js +174 -0
- package/lib/core/remote/notify.d.ts +54 -0
- package/lib/core/remote/notify.js +77 -0
- package/lib/core/remote/owner.d.ts +32 -0
- package/lib/core/remote/owner.js +75 -0
- package/lib/core/remote/pairing.d.ts +104 -0
- package/lib/core/remote/pairing.js +261 -0
- package/lib/core/remote/push.d.ts +80 -0
- package/lib/core/remote/push.js +222 -0
- package/lib/core/remote/store.d.ts +18 -0
- package/lib/core/remote/store.js +59 -0
- package/lib/core/remote/tickets.d.ts +20 -0
- package/lib/core/remote/tickets.js +49 -0
- package/lib/core/remote/uploads.d.ts +63 -0
- package/lib/core/remote/uploads.js +161 -0
- package/lib/core/request-attribution.d.ts +26 -0
- package/lib/core/request-attribution.js +86 -0
- package/lib/core/request-invariant.d.ts +61 -0
- package/lib/core/request-invariant.js +199 -0
- package/lib/core/sandbox/backends.d.ts +64 -0
- package/lib/core/sandbox/backends.js +194 -0
- package/lib/core/sandbox/execpolicy.d.ts +93 -0
- package/lib/core/sandbox/execpolicy.js +452 -0
- package/lib/core/sandbox/net-proxy.d.ts +31 -0
- package/lib/core/sandbox/net-proxy.js +162 -0
- package/lib/core/sandbox/policy.d.ts +211 -0
- package/lib/core/sandbox/policy.js +559 -0
- package/lib/core/sandbox/win/abi.d.ts +161 -0
- package/lib/core/sandbox/win/abi.js +169 -0
- package/lib/core/sandbox/win/account.d.ts +71 -0
- package/lib/core/sandbox/win/account.js +206 -0
- package/lib/core/sandbox/win/acl.d.ts +54 -0
- package/lib/core/sandbox/win/acl.js +339 -0
- package/lib/core/sandbox/win/backend.d.ts +61 -0
- package/lib/core/sandbox/win/backend.js +249 -0
- package/lib/core/sandbox/win/doctor.d.ts +24 -0
- package/lib/core/sandbox/win/doctor.js +272 -0
- package/lib/core/sandbox/win/ffi.d.ts +107 -0
- package/lib/core/sandbox/win/ffi.js +166 -0
- package/lib/core/sandbox/win/net-abi.d.ts +154 -0
- package/lib/core/sandbox/win/net-abi.js +316 -0
- package/lib/core/sandbox/win/runner-entry.d.ts +35 -0
- package/lib/core/sandbox/win/runner-entry.js +391 -0
- package/lib/core/sandbox/win/setup.d.ts +60 -0
- package/lib/core/sandbox/win/setup.js +986 -0
- package/lib/core/sandbox/win/token.d.ts +35 -0
- package/lib/core/sandbox/win/token.js +238 -0
- package/lib/core/sandbox/win/wfp.d.ts +41 -0
- package/lib/core/sandbox/win/wfp.js +200 -0
- package/lib/core/sandbox/win/workspace-sid.d.ts +9 -0
- package/lib/core/sandbox/win/workspace-sid.js +45 -0
- package/lib/core/schedule/rule.d.ts +184 -0
- package/lib/core/schedule/rule.js +745 -0
- package/lib/core/schedule/runner.d.ts +185 -0
- package/lib/core/schedule/runner.js +678 -0
- package/lib/core/schedule/store.d.ts +182 -0
- package/lib/core/schedule/store.js +455 -0
- package/lib/core/secrets.d.ts +41 -0
- package/lib/core/secrets.js +150 -0
- package/lib/core/session-export.d.ts +18 -0
- package/lib/core/session-export.js +73 -0
- package/lib/core/session-index.d.ts +159 -0
- package/lib/core/session-index.js +683 -0
- package/lib/core/session-meta.d.ts +41 -0
- package/lib/core/session-meta.js +97 -0
- package/lib/core/session.d.ts +356 -0
- package/lib/core/session.js +998 -0
- package/lib/core/skills.d.ts +60 -0
- package/lib/core/skills.js +171 -0
- package/lib/core/spill.d.ts +159 -0
- package/lib/core/spill.js +329 -0
- package/lib/core/surface-registry.d.ts +45 -0
- package/lib/core/surface-registry.js +67 -0
- package/lib/core/team-board.d.ts +95 -0
- package/lib/core/team-board.js +316 -0
- package/lib/core/throughput.d.ts +46 -0
- package/lib/core/throughput.js +40 -0
- package/lib/core/todo-reminder.d.ts +44 -0
- package/lib/core/todo-reminder.js +55 -0
- package/lib/core/todo.d.ts +81 -0
- package/lib/core/todo.js +222 -0
- package/lib/core/token-estimate.d.ts +55 -0
- package/lib/core/token-estimate.js +82 -0
- package/lib/core/tool-guards.d.ts +103 -0
- package/lib/core/tool-guards.js +77 -0
- package/lib/core/tool-search.d.ts +152 -0
- package/lib/core/tool-search.js +311 -0
- package/lib/core/tools/bash.d.ts +281 -0
- package/lib/core/tools/bash.js +871 -0
- package/lib/core/tools/command-runner.d.ts +84 -0
- package/lib/core/tools/command-runner.js +68 -0
- package/lib/core/tools/fs-tools.d.ts +23 -0
- package/lib/core/tools/fs-tools.js +247 -0
- package/lib/core/tools/index.d.ts +8 -0
- package/lib/core/tools/index.js +4 -0
- package/lib/core/tools/sandbox-args.d.ts +51 -0
- package/lib/core/tools/sandbox-args.js +90 -0
- package/lib/core/tools/search-tools.d.ts +3 -0
- package/lib/core/tools/search-tools.js +153 -0
- package/lib/core/tools.d.ts +96 -0
- package/lib/core/tools.js +53 -0
- package/lib/core/ui-boot-source.d.ts +71 -0
- package/lib/core/ui-boot-source.js +121 -0
- package/lib/core/ui-bundles.d.ts +249 -0
- package/lib/core/ui-bundles.js +830 -0
- package/lib/core/ui-combo.d.ts +49 -0
- package/lib/core/ui-combo.js +55 -0
- package/lib/core/ui-events.d.ts +81 -0
- package/lib/core/ui-events.js +364 -0
- package/lib/core/ui-hmr.d.ts +36 -0
- package/lib/core/ui-hmr.js +128 -0
- package/lib/core/ui-methods.d.ts +69 -0
- package/lib/core/ui-methods.js +341 -0
- package/lib/core/ui-route.d.ts +69 -0
- package/lib/core/ui-route.js +122 -0
- package/lib/core/ui-server.d.ts +75 -0
- package/lib/core/ui-server.js +369 -0
- package/lib/core/ui-trust.d.ts +47 -0
- package/lib/core/ui-trust.js +164 -0
- package/lib/core/untrusted.d.ts +30 -0
- package/lib/core/untrusted.js +48 -0
- package/lib/core/update-check.d.ts +81 -0
- package/lib/core/update-check.js +177 -0
- package/lib/core/usage-log.d.ts +82 -0
- package/lib/core/usage-log.js +306 -0
- package/lib/core/version.d.ts +1 -0
- package/lib/core/version.js +37 -0
- package/lib/core/web-http.d.ts +57 -0
- package/lib/core/web-http.js +137 -0
- package/lib/core/web-static.d.ts +31 -0
- package/lib/core/web-static.js +75 -0
- package/lib/headless.d.ts +1 -0
- package/lib/headless.js +31 -0
- package/lib/host/kernel.d.ts +33 -0
- package/lib/host/kernel.js +451 -0
- package/lib/index.d.ts +41 -0
- package/lib/index.js +35 -0
- package/lib/plugins/agent.d.ts +2 -0
- package/lib/plugins/agent.js +274 -0
- package/lib/plugins/approval-floor.d.ts +2 -0
- package/lib/plugins/approval-floor.js +223 -0
- package/lib/plugins/approval.d.ts +16 -0
- package/lib/plugins/approval.js +674 -0
- package/lib/plugins/ask.d.ts +2 -0
- package/lib/plugins/ask.js +245 -0
- package/lib/plugins/browser.d.ts +68 -0
- package/lib/plugins/browser.js +1341 -0
- package/lib/plugins/commands.d.ts +23 -0
- package/lib/plugins/commands.js +498 -0
- package/lib/plugins/compact.d.ts +21 -0
- package/lib/plugins/compact.js +274 -0
- package/lib/plugins/computer-use.d.ts +47 -0
- package/lib/plugins/computer-use.js +539 -0
- package/lib/plugins/desktop-dock.d.ts +2 -0
- package/lib/plugins/desktop-dock.js +626 -0
- package/lib/plugins/dock-browser.d.ts +34 -0
- package/lib/plugins/dock-browser.js +765 -0
- package/lib/plugins/dsh-compat.d.ts +25 -0
- package/lib/plugins/dsh-compat.js +37 -0
- package/lib/plugins/file-review.d.ts +108 -0
- package/lib/plugins/file-review.js +393 -0
- package/lib/plugins/git.d.ts +26 -0
- package/lib/plugins/git.js +132 -0
- package/lib/plugins/goal.d.ts +20 -0
- package/lib/plugins/goal.js +245 -0
- package/lib/plugins/guards.d.ts +14 -0
- package/lib/plugins/guards.js +18 -0
- package/lib/plugins/hooks.d.ts +19 -0
- package/lib/plugins/hooks.js +583 -0
- package/lib/plugins/host-stdio.d.ts +88 -0
- package/lib/plugins/host-stdio.js +317 -0
- package/lib/plugins/image-diet.d.ts +17 -0
- package/lib/plugins/image-diet.js +85 -0
- package/lib/plugins/lifecycle-hooks.d.ts +26 -0
- package/lib/plugins/lifecycle-hooks.js +338 -0
- package/lib/plugins/llm.d.ts +13 -0
- package/lib/plugins/llm.js +215 -0
- package/lib/plugins/lsp.d.ts +54 -0
- package/lib/plugins/lsp.js +608 -0
- package/lib/plugins/mcp.d.ts +16 -0
- package/lib/plugins/mcp.js +673 -0
- package/lib/plugins/memory.d.ts +17 -0
- package/lib/plugins/memory.js +858 -0
- package/lib/plugins/microcompact.d.ts +18 -0
- package/lib/plugins/microcompact.js +119 -0
- package/lib/plugins/mode.d.ts +18 -0
- package/lib/plugins/mode.js +115 -0
- package/lib/plugins/permission-presets.d.ts +18 -0
- package/lib/plugins/permission-presets.js +135 -0
- package/lib/plugins/plan.d.ts +2 -0
- package/lib/plugins/plan.js +192 -0
- package/lib/plugins/plugin-manager.d.ts +2 -0
- package/lib/plugins/plugin-manager.js +165 -0
- package/lib/plugins/presets.d.ts +2 -0
- package/lib/plugins/presets.js +182 -0
- package/lib/plugins/prompt.d.ts +2 -0
- package/lib/plugins/prompt.js +264 -0
- package/lib/plugins/ptc.d.ts +2 -0
- package/lib/plugins/ptc.js +272 -0
- package/lib/plugins/remote/http.d.ts +11 -0
- package/lib/plugins/remote/http.js +11 -0
- package/lib/plugins/remote/routes.d.ts +24 -0
- package/lib/plugins/remote/routes.js +384 -0
- package/lib/plugins/remote/types.d.ts +135 -0
- package/lib/plugins/remote/types.js +87 -0
- package/lib/plugins/remote.d.ts +17 -0
- package/lib/plugins/remote.js +1028 -0
- package/lib/plugins/runtime-api.d.ts +16 -0
- package/lib/plugins/runtime-api.js +99 -0
- package/lib/plugins/runtime.d.ts +10 -0
- package/lib/plugins/runtime.js +451 -0
- package/lib/plugins/sandbox.d.ts +2 -0
- package/lib/plugins/sandbox.js +761 -0
- package/lib/plugins/schedule.d.ts +26 -0
- package/lib/plugins/schedule.js +538 -0
- package/lib/plugins/self-improve.d.ts +61 -0
- package/lib/plugins/self-improve.js +953 -0
- package/lib/plugins/session-search.d.ts +16 -0
- package/lib/plugins/session-search.js +308 -0
- package/lib/plugins/session-title.d.ts +19 -0
- package/lib/plugins/session-title.js +109 -0
- package/lib/plugins/session.d.ts +7 -0
- package/lib/plugins/session.js +296 -0
- package/lib/plugins/settings.d.ts +3 -0
- package/lib/plugins/settings.js +705 -0
- package/lib/plugins/skills.d.ts +2 -0
- package/lib/plugins/skills.js +360 -0
- package/lib/plugins/spill.d.ts +16 -0
- package/lib/plugins/spill.js +200 -0
- package/lib/plugins/subagent.d.ts +2 -0
- package/lib/plugins/subagent.js +896 -0
- package/lib/plugins/surfaces.d.ts +11 -0
- package/lib/plugins/surfaces.js +20 -0
- package/lib/plugins/team.d.ts +16 -0
- package/lib/plugins/team.js +149 -0
- package/lib/plugins/todo.d.ts +19 -0
- package/lib/plugins/todo.js +188 -0
- package/lib/plugins/tool-search.d.ts +2 -0
- package/lib/plugins/tool-search.js +434 -0
- package/lib/plugins/tool-search.js.nv-backup +434 -0
- package/lib/plugins/tools-default.d.ts +12 -0
- package/lib/plugins/tools-default.js +275 -0
- package/lib/plugins/tools.d.ts +16 -0
- package/lib/plugins/tools.js +62 -0
- package/lib/plugins/transcript.d.ts +15 -0
- package/lib/plugins/transcript.js +311 -0
- package/lib/plugins/tui.d.ts +2 -0
- package/lib/plugins/tui.js +98 -0
- package/lib/plugins/waiting.d.ts +12 -0
- package/lib/plugins/waiting.js +34 -0
- package/lib/plugins/web-search.d.ts +14 -0
- package/lib/plugins/web-search.js +263 -0
- package/lib/plugins/webserver.d.ts +48 -0
- package/lib/plugins/webserver.js +228 -0
- package/lib/remote/assets/app-DAcUCOEn.js +14 -0
- package/lib/remote/assets/icon-192.png +0 -0
- package/lib/remote/assets/icon-512.png +0 -0
- package/lib/remote/assets/index.html +34 -0
- package/lib/remote/assets/manifest.json +27 -0
- package/lib/remote/assets/style-DIB6729x.css +1 -0
- package/lib/remote/assets/sw.js +66 -0
- package/lib/services/types.d.ts +1228 -0
- package/lib/services/types.js +1 -0
- package/lib/tools/config-cli.d.ts +1 -0
- package/lib/tools/config-cli.js +89 -0
- package/lib/ui/arrival.d.ts +72 -0
- package/lib/ui/arrival.js +105 -0
- package/lib/ui/assets/app-B70nVIKd.js +69 -0
- package/lib/ui/assets/chunk-2UxHyX5q.js +1 -0
- package/lib/ui/assets/chunk-B1dDrJ26.js +1 -0
- package/lib/ui/assets/chunk-B6aJPvgy.js +1 -0
- package/lib/ui/assets/chunk-BEwlwnbL.js +1 -0
- package/lib/ui/assets/chunk-BGcgwlCI.js +12 -0
- package/lib/ui/assets/chunk-BIGW1oBm.js +1 -0
- package/lib/ui/assets/chunk-BPQ3VLAy.js +1 -0
- package/lib/ui/assets/chunk-BRH0KZbk.js +141 -0
- package/lib/ui/assets/chunk-BX6H_ySx.js +1 -0
- package/lib/ui/assets/chunk-B_P3UbPa.js +1 -0
- package/lib/ui/assets/chunk-B_TYUkTI.js +1 -0
- package/lib/ui/assets/chunk-B_vNuMnf.js +1 -0
- package/lib/ui/assets/chunk-BajyYBss.js +10 -0
- package/lib/ui/assets/chunk-BdnUsdx6.js +1 -0
- package/lib/ui/assets/chunk-Buea-lGh.js +1 -0
- package/lib/ui/assets/chunk-C0PvZCCE.js +1 -0
- package/lib/ui/assets/chunk-C0m74zRD.js +1 -0
- package/lib/ui/assets/chunk-C27-OAKa.js +1 -0
- package/lib/ui/assets/chunk-C2oV4EkX.js +1 -0
- package/lib/ui/assets/chunk-C7zT0LnQ.js +1 -0
- package/lib/ui/assets/chunk-C9GSunVT.js +1 -0
- package/lib/ui/assets/chunk-C9tS-k6U.js +1 -0
- package/lib/ui/assets/chunk-CHLpvVh8.js +1 -0
- package/lib/ui/assets/chunk-CLxacb5B.js +1 -0
- package/lib/ui/assets/chunk-COt5Ahok.js +1 -0
- package/lib/ui/assets/chunk-CPTIWCL2.js +1 -0
- package/lib/ui/assets/chunk-CQLl-L-p.js +1 -0
- package/lib/ui/assets/chunk-CUWRgxuq.js +55 -0
- package/lib/ui/assets/chunk-CWanVSXC.js +1 -0
- package/lib/ui/assets/chunk-Cf5RLm7j.js +1 -0
- package/lib/ui/assets/chunk-CickPsom.js +1 -0
- package/lib/ui/assets/chunk-Cj5Yp3dK.js +1 -0
- package/lib/ui/assets/chunk-Cmh6b_Ma.js +1 -0
- package/lib/ui/assets/chunk-Cp-IABpG.js +1 -0
- package/lib/ui/assets/chunk-CqE71os6.js +1 -0
- package/lib/ui/assets/chunk-CtKP3W-j.js +1 -0
- package/lib/ui/assets/chunk-Cvjx9yec.js +1 -0
- package/lib/ui/assets/chunk-CxGP3dtY.js +1 -0
- package/lib/ui/assets/chunk-CylS5w8V.js +1 -0
- package/lib/ui/assets/chunk-D38fbIBN.js +1 -0
- package/lib/ui/assets/chunk-D97Zzqfu.js +1 -0
- package/lib/ui/assets/chunk-DAi9KRSo.js +1 -0
- package/lib/ui/assets/chunk-DHK4yRfg.js +1 -0
- package/lib/ui/assets/chunk-DJeabLx-.js +1 -0
- package/lib/ui/assets/chunk-DNRxmY5a.js +1 -0
- package/lib/ui/assets/chunk-DNSN1z5r.js +1 -0
- package/lib/ui/assets/chunk-DNasK_ZG.js +1 -0
- package/lib/ui/assets/chunk-DPvrY3IQ.js +1 -0
- package/lib/ui/assets/chunk-DXmwc3jG.js +1 -0
- package/lib/ui/assets/chunk-Dd0kTxKP.js +1 -0
- package/lib/ui/assets/chunk-De0Btta0.js +1 -0
- package/lib/ui/assets/chunk-Des-eS-w.js +1 -0
- package/lib/ui/assets/chunk-Df6bDoY_.js +1 -0
- package/lib/ui/assets/chunk-DijEV5ha.js +1 -0
- package/lib/ui/assets/chunk-DkvoVjww.js +1 -0
- package/lib/ui/assets/chunk-DlC-OlHO.js +1 -0
- package/lib/ui/assets/chunk-DnzrXTVv.js +1 -0
- package/lib/ui/assets/chunk-Dualf0xi.js +1 -0
- package/lib/ui/assets/chunk-EXT84bkm.js +1 -0
- package/lib/ui/assets/chunk-GwR3hkPK.js +1 -0
- package/lib/ui/assets/chunk-P80f7IUj.js +1 -0
- package/lib/ui/assets/chunk-VOosw3JB.js +1 -0
- package/lib/ui/assets/chunk-YQ4lDkt_.js +140 -0
- package/lib/ui/assets/chunk-Yzrsuije.js +1 -0
- package/lib/ui/assets/chunk-Z72CF80r.js +1 -0
- package/lib/ui/assets/chunk-g9-lgVsj.js +1 -0
- package/lib/ui/assets/chunk-vGWfd6FD.js +1 -0
- package/lib/ui/assets/chunk-wDzz0qaB.js +1 -0
- package/lib/ui/assets/chunk-ySF7HWmS.js +1 -0
- package/lib/ui/assets/icon.png +0 -0
- package/lib/ui/assets/index.html +14 -0
- package/lib/ui/assets/pdf.worker.min-CjEcRF4W.mjs +28 -0
- package/lib/ui/assets/style-Bq01xH_b.css +1 -0
- package/lib/ui/frames.d.ts +67 -0
- package/lib/ui/frames.js +146 -0
- package/lib/ui/index.d.ts +59 -0
- package/lib/ui/index.js +50 -0
- package/lib/ui/manifest.d.ts +172 -0
- package/lib/ui/manifest.js +158 -0
- package/lib/ui/plugin.d.ts +161 -0
- package/lib/ui/plugin.js +7 -0
- package/lib/ui/plugins/browser/client.js +290 -0
- package/lib/ui/plugins/browser/icon.png +0 -0
- package/lib/ui/plugins/composer/client.js +1843 -0
- package/lib/ui/plugins/composer/icon.png +0 -0
- package/lib/ui/plugins/files/client.js +646 -0
- package/lib/ui/plugins/files/icon.png +0 -0
- package/lib/ui/plugins/manifest.json +107 -0
- package/lib/ui/plugins/plugins/client.js +682 -0
- package/lib/ui/plugins/plugins/icon.png +0 -0
- package/lib/ui/plugins/preview/client.js +197 -0
- package/lib/ui/plugins/preview/icon.png +0 -0
- package/lib/ui/plugins/prompt/client.js +653 -0
- package/lib/ui/plugins/prompt/icon.png +0 -0
- package/lib/ui/plugins/sessions/client.js +1577 -0
- package/lib/ui/plugins/sessions/icon.png +0 -0
- package/lib/ui/plugins/settings/client.js +5470 -0
- package/lib/ui/plugins/settings/icon.png +0 -0
- package/lib/ui/plugins/skills/client.js +485 -0
- package/lib/ui/plugins/skills/icon.png +0 -0
- package/lib/ui/plugins/status/client.js +1420 -0
- package/lib/ui/plugins/status/icon.png +0 -0
- package/lib/ui/plugins/statusbar/client.js +504 -0
- package/lib/ui/plugins/statusbar/icon.png +0 -0
- package/lib/ui/plugins/tasks/client.js +52 -0
- package/lib/ui/plugins/tasks/icon.png +0 -0
- package/lib/ui/plugins/team/client.js +527 -0
- package/lib/ui/plugins/team/icon.png +0 -0
- package/lib/ui/plugins/terminal/client.js +232 -0
- package/lib/ui/plugins/terminal/icon.png +0 -0
- package/lib/ui/plugins/trace/client.js +1376 -0
- package/lib/ui/plugins/trace/icon.png +0 -0
- package/lib/ui/plugins/transcript/client.js +2661 -0
- package/lib/ui/plugins/transcript/icon.png +0 -0
- package/lib/ui/scoped-slots.d.ts +20 -0
- package/lib/ui/scoped-slots.js +21 -0
- package/lib/ui/sdk/@dsc/ui/index.d.ts +242 -0
- package/lib/ui/sdk/@dsc/ui/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-core/contract.d.ts +1973 -0
- package/lib/ui/sdk/@dsc/ui-core/core/diff-text.d.ts +74 -0
- package/lib/ui/sdk/@dsc/ui-core/core/dock-browser.d.ts +137 -0
- package/lib/ui/sdk/@dsc/ui-core/core/dock-ops.d.ts +59 -0
- package/lib/ui/sdk/@dsc/ui-core/core/model-caps.d.ts +83 -0
- package/lib/ui/sdk/@dsc/ui-core/core/native-bridge.d.ts +135 -0
- package/lib/ui/sdk/@dsc/ui-core/core/token-estimate.d.ts +55 -0
- package/lib/ui/sdk/@dsc/ui-core/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/arrival.d.ts +72 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/frames.d.ts +67 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/index.d.ts +59 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/manifest.d.ts +172 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/plugin.d.ts +161 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/scoped-slots.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/services-react.d.ts +27 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/services.d.ts +63 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/slots-react.d.ts +28 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/slots.d.ts +481 -0
- package/lib/ui/sdk/@dsc/ui-core/ui/store.d.ts +89 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/dock-model.d.ts +238 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/dock-state.d.ts +163 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/dock.d.ts +24 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/index.d.ts +15 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-layout/app.d.ts +74 -0
- package/lib/ui/sdk/@dsc/ui-layout/appearance.d.ts +70 -0
- package/lib/ui/sdk/@dsc/ui-layout/host-channel.d.ts +112 -0
- package/lib/ui/sdk/@dsc/ui-layout/index.d.ts +34 -0
- package/lib/ui/sdk/@dsc/ui-layout/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-layout/page-state.d.ts +14 -0
- package/lib/ui/sdk/@dsc/ui-layout/review-pane.d.ts +21 -0
- package/lib/ui/sdk/@dsc/ui-layout/runtime-context.d.ts +44 -0
- package/lib/ui/sdk/@dsc/ui-layout/thread-view.d.ts +28 -0
- package/lib/ui/sdk/@dsc/ui-layout/update-button.d.ts +21 -0
- package/lib/ui/sdk/@dsc/ui-primitives/code-file-icon-artwork.d.ts +53 -0
- package/lib/ui/sdk/@dsc/ui-primitives/code-view.d.ts +15 -0
- package/lib/ui/sdk/@dsc/ui-primitives/compat.d.ts +27 -0
- package/lib/ui/sdk/@dsc/ui-primitives/completion-sound.d.ts +24 -0
- package/lib/ui/sdk/@dsc/ui-primitives/confirm.d.ts +33 -0
- package/lib/ui/sdk/@dsc/ui-primitives/css.d.ts +47 -0
- package/lib/ui/sdk/@dsc/ui-primitives/diff-rows.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-primitives/file-icons.d.ts +38 -0
- package/lib/ui/sdk/@dsc/ui-primitives/file-type-classify.d.ts +66 -0
- package/lib/ui/sdk/@dsc/ui-primitives/file-type-icon.d.ts +57 -0
- package/lib/ui/sdk/@dsc/ui-primitives/highlight.d.ts +24 -0
- package/lib/ui/sdk/@dsc/ui-primitives/hover-delay.d.ts +17 -0
- package/lib/ui/sdk/@dsc/ui-primitives/icons.d.ts +109 -0
- package/lib/ui/sdk/@dsc/ui-primitives/index.d.ts +55 -0
- package/lib/ui/sdk/@dsc/ui-primitives/lang-table.d.ts +10 -0
- package/lib/ui/sdk/@dsc/ui-primitives/markdown.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-primitives/native.d.ts +41 -0
- package/lib/ui/sdk/@dsc/ui-primitives/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-primitives/panels.d.ts +86 -0
- package/lib/ui/sdk/@dsc/ui-primitives/paths.d.ts +11 -0
- package/lib/ui/sdk/@dsc/ui-primitives/pdf-view.d.ts +13 -0
- package/lib/ui/sdk/@dsc/ui-primitives/plugin-text.d.ts +15 -0
- package/lib/ui/sdk/@dsc/ui-primitives/select.d.ts +35 -0
- package/lib/ui/sdk/@dsc/ui-primitives/table-view.d.ts +23 -0
- package/lib/ui/sdk/@dsc/ui-primitives/thread-resizer.d.ts +22 -0
- package/lib/ui/sdk/@dsc/ui-primitives/time.d.ts +33 -0
- package/lib/ui/sdk/@dsc/ui-primitives/toast.d.ts +16 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tokens.d.ts +14 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tool-args.d.ts +49 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tool-summary.d.ts +64 -0
- package/lib/ui/sdk/@dsc/ui-renderer/boot.d.ts +121 -0
- package/lib/ui/sdk/@dsc/ui-renderer/hmr.d.ts +43 -0
- package/lib/ui/sdk/@dsc/ui-renderer/index.d.ts +20 -0
- package/lib/ui/sdk/@dsc/ui-renderer/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-slots/index.d.ts +19 -0
- package/lib/ui/sdk/@dsc/ui-slots/package.json +16 -0
- package/lib/ui/sdk/@dsc/ui-slots/slots-react.d.ts +48 -0
- package/lib/ui/sdk/@dsc/ui-slots/slots.d.ts +102 -0
- package/lib/ui/services-react.d.ts +27 -0
- package/lib/ui/services-react.js +32 -0
- package/lib/ui/services.d.ts +63 -0
- package/lib/ui/services.js +121 -0
- package/lib/ui/slots-ink.d.ts +26 -0
- package/lib/ui/slots-ink.js +78 -0
- package/lib/ui/slots-react.d.ts +28 -0
- package/lib/ui/slots-react.js +88 -0
- package/lib/ui/slots.d.ts +481 -0
- package/lib/ui/slots.js +550 -0
- package/lib/ui/store.d.ts +89 -0
- package/lib/ui/store.js +62 -0
- package/lib/ui/tui-plugin-api.d.ts +23 -0
- package/lib/ui/tui-plugin-api.js +23 -0
- package/lib/ui/tui-plugins.d.ts +47 -0
- package/lib/ui/tui-plugins.js +220 -0
- package/package.json +58 -6
|
@@ -0,0 +1,745 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 定时任务的选择器:六种触发规则的解析、下一次触发时刻的计算,以及「本地墙上时刻 ↔ 绝对时刻」
|
|
3
|
+
* 的换算。整份文件是纯函数——不碰文件系统、不读 ctx、不缓存任何跨任务状态(时区格式化器除外),
|
|
4
|
+
* 所以能脱离宿主单独跑自检。
|
|
5
|
+
*
|
|
6
|
+
* 为什么这么设计:
|
|
7
|
+
* 1. **时间一律用绝对毫秒数(epoch ms)表示**,人读的「09:30」只在解析和显示时出现。
|
|
8
|
+
* 存绝对时刻能让「机器睡了两小时」和「时区改了」这两件事都变成一次减法。
|
|
9
|
+
* 2. **没有 Temporal**(Node 24 才有),所以用 `Intl.DateTimeFormat` 反解时区偏移:
|
|
10
|
+
* 把某一瞬间按目标时区格式化出墙上时刻,再和 UTC 的同一串数字相减,差就是偏移。
|
|
11
|
+
* 时区库(如 luxon)会引入 npm 依赖,dsc 插件不许带依赖,所以走内置 ICU。
|
|
12
|
+
* 3. **DST 两条规则是入参,不是副作用**:gap(夏令时跳表里不存在的本地时刻)算「没有这一次」,
|
|
13
|
+
* 返回 null 让调用方跳过;overlap(秋天重复的那一小时)只取较早的那一次。
|
|
14
|
+
* 这两个规则写在 wallTimeToInstant 里,所有选择器共用,不许各自再判一遍。
|
|
15
|
+
*
|
|
16
|
+
* @module dsc/core/schedule/rule
|
|
17
|
+
*/
|
|
18
|
+
/** 六种选择器的名字(给工具描述与报错文案用)。 */
|
|
19
|
+
export const SCHEDULE_RULE_KINDS = ['after', 'at', 'every', 'daily', 'weekly', 'cron'];
|
|
20
|
+
/** `every` 的间隔下限(秒):比一分钟更密的提醒用提醒本身没有意义,只会烧模型额度。 */
|
|
21
|
+
export const MIN_EVERY_SECONDS = 60;
|
|
22
|
+
/** 一次性任务(after / at)错过后的补跑宽限:两分钟。 */
|
|
23
|
+
export const ONE_SHOT_GRACE_MS = 120_000;
|
|
24
|
+
/** 周期任务补跑宽限的下限。 */
|
|
25
|
+
export const MIN_GRACE_MS = 120_000;
|
|
26
|
+
/** 周期任务补跑宽限的上限(两小时)。 */
|
|
27
|
+
export const MAX_GRACE_MS = 2 * 3600_000;
|
|
28
|
+
/** 一次扫描最多推进多少格(按天整段跳,所以 4000 格足够覆盖十几年)。 */
|
|
29
|
+
const CRON_SCAN_LIMIT = 4_000;
|
|
30
|
+
/** 一周七天的中文名,下标 1~7(1=周一)。 */
|
|
31
|
+
const WEEKDAY_NAMES = ['', '周一', '周二', '周三', '周四', '周五', '周六', '周日'];
|
|
32
|
+
// ── 时区工具 ──────────────────────────────────────────────────────────────────
|
|
33
|
+
const formatterCache = new Map();
|
|
34
|
+
const zoneValidCache = new Map();
|
|
35
|
+
/** 取(并缓存)某个时区的格式化器。每建一个都很贵,而 nextRunAt 会反复用到。 */
|
|
36
|
+
function formatterOf(timeZone) {
|
|
37
|
+
let cached = formatterCache.get(timeZone);
|
|
38
|
+
if (cached === undefined) {
|
|
39
|
+
cached = new Intl.DateTimeFormat('en-US', {
|
|
40
|
+
timeZone,
|
|
41
|
+
hourCycle: 'h23',
|
|
42
|
+
year: 'numeric',
|
|
43
|
+
month: '2-digit',
|
|
44
|
+
day: '2-digit',
|
|
45
|
+
hour: '2-digit',
|
|
46
|
+
minute: '2-digit',
|
|
47
|
+
second: '2-digit',
|
|
48
|
+
});
|
|
49
|
+
formatterCache.set(timeZone, cached);
|
|
50
|
+
}
|
|
51
|
+
return cached;
|
|
52
|
+
}
|
|
53
|
+
/** 这个 IANA 时区名认不认识(`Intl` 不认就抛 RangeError)。 */
|
|
54
|
+
export function isValidTimeZone(timeZone) {
|
|
55
|
+
if (typeof timeZone !== 'string' || timeZone.trim() === '')
|
|
56
|
+
return false;
|
|
57
|
+
const cached = zoneValidCache.get(timeZone);
|
|
58
|
+
if (cached !== undefined)
|
|
59
|
+
return cached;
|
|
60
|
+
let ok = true;
|
|
61
|
+
try {
|
|
62
|
+
formatterOf(timeZone);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
ok = false;
|
|
66
|
+
}
|
|
67
|
+
zoneValidCache.set(timeZone, ok);
|
|
68
|
+
return ok;
|
|
69
|
+
}
|
|
70
|
+
/** 本机系统时区;拿不到就 UTC(宁可跑偏也不要启动失败)。 */
|
|
71
|
+
export function systemTimeZone() {
|
|
72
|
+
try {
|
|
73
|
+
const zone = new Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
74
|
+
if (typeof zone === 'string' && isValidTimeZone(zone))
|
|
75
|
+
return zone;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// 环境缺 ICU:下面的 UTC 兜底
|
|
79
|
+
}
|
|
80
|
+
return 'UTC';
|
|
81
|
+
}
|
|
82
|
+
/** 某一瞬间在目标时区里的墙上时刻。 */
|
|
83
|
+
export function localWall(instantMs, timeZone) {
|
|
84
|
+
const parts = formatterOf(timeZone).formatToParts(new Date(instantMs));
|
|
85
|
+
const pick = (type) => {
|
|
86
|
+
const found = parts.find((part) => part.type === type);
|
|
87
|
+
return found === undefined ? 0 : Number(found.value);
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
year: pick('year'),
|
|
91
|
+
month: pick('month'),
|
|
92
|
+
day: pick('day'),
|
|
93
|
+
// 有些 ICU 版本在 h23 下仍会把午夜给成 "24",取模兜住。
|
|
94
|
+
hour: pick('hour') % 24,
|
|
95
|
+
minute: pick('minute'),
|
|
96
|
+
second: pick('second'),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/** 墙上时刻按 UTC 读出来的毫秒数(纯日历算术用,不代表真实瞬间)。 */
|
|
100
|
+
function wallToNaiveMs(wall) {
|
|
101
|
+
return Date.UTC(wall.year, wall.month - 1, wall.day, wall.hour, wall.minute, wall.second);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* 某一瞬间在目标时区的偏移(毫秒):`本地墙上时刻 - UTC 时刻`。
|
|
105
|
+
* 只取到秒——格式化器不给毫秒,带毫秒进来会多出一个亚秒误差。
|
|
106
|
+
*/
|
|
107
|
+
export function offsetAt(instantMs, timeZone) {
|
|
108
|
+
const base = Math.floor(instantMs / 1000) * 1000;
|
|
109
|
+
return wallToNaiveMs(localWall(base, timeZone)) - base;
|
|
110
|
+
}
|
|
111
|
+
/** 这个瞬间在目标时区读出来的墙上时刻是不是 wall。 */
|
|
112
|
+
function sameWall(instantMs, wall, timeZone) {
|
|
113
|
+
const got = localWall(Math.floor(instantMs / 1000) * 1000, timeZone);
|
|
114
|
+
return (got.year === wall.year &&
|
|
115
|
+
got.month === wall.month &&
|
|
116
|
+
got.day === wall.day &&
|
|
117
|
+
got.hour === wall.hour &&
|
|
118
|
+
got.minute === wall.minute &&
|
|
119
|
+
got.second === wall.second);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* 本地墙上时刻 → 绝对时刻。
|
|
123
|
+
*
|
|
124
|
+
* DST 两条规则都在这里:
|
|
125
|
+
* - **gap**(春天跳表那一小时里的时刻,例如 America/New_York 3 月某天的 02:30):
|
|
126
|
+
* 没有任何瞬间的墙上时刻等于它,返回 `null`。调用方据此「跳过这一次」。
|
|
127
|
+
* - **overlap**(秋天重复的那一小时,例如 11 月某天的 01:30 出现两次):
|
|
128
|
+
* 两个候选都合法,取较早的那个(`Math.min`)。
|
|
129
|
+
*
|
|
130
|
+
* 候选怎么来:真实瞬间 t 满足 `t = naive - offset(t)`,而一个时区在两天内几乎不会变两次偏移,
|
|
131
|
+
* 所以在 naive 前后各取几个采样点,把采样到的偏移各试一遍,再用「格式化回去是否相等」验证。
|
|
132
|
+
*/
|
|
133
|
+
export function wallTimeToInstant(wall, timeZone) {
|
|
134
|
+
const naive = wallToNaiveMs(wall);
|
|
135
|
+
const offsets = new Set();
|
|
136
|
+
for (const hours of [-26, -2, 0, 2, 26])
|
|
137
|
+
offsets.add(offsetAt(naive + hours * 3600_000, timeZone));
|
|
138
|
+
let best = null;
|
|
139
|
+
for (const offset of offsets) {
|
|
140
|
+
const candidate = naive - offset;
|
|
141
|
+
if (!sameWall(candidate, wall, timeZone))
|
|
142
|
+
continue;
|
|
143
|
+
if (best === null || candidate < best)
|
|
144
|
+
best = candidate;
|
|
145
|
+
}
|
|
146
|
+
return best;
|
|
147
|
+
}
|
|
148
|
+
/** 把绝对时刻按目标时区写成 `YYYY-MM-DD HH:MM:SS ±HH:MM`。 */
|
|
149
|
+
export function formatInstant(instantMs, timeZone) {
|
|
150
|
+
const wall = localWall(instantMs, timeZone);
|
|
151
|
+
const pad = (value) => String(value).padStart(2, '0');
|
|
152
|
+
const totalMinutes = Math.round(offsetAt(instantMs, timeZone) / 60_000);
|
|
153
|
+
const sign = totalMinutes < 0 ? '-' : '+';
|
|
154
|
+
const abs = Math.abs(totalMinutes);
|
|
155
|
+
return (`${wall.year}-${pad(wall.month)}-${pad(wall.day)} ` +
|
|
156
|
+
`${pad(wall.hour)}:${pad(wall.minute)}:${pad(wall.second)} ` +
|
|
157
|
+
`${sign}${pad(Math.floor(abs / 60))}:${pad(abs % 60)}`);
|
|
158
|
+
}
|
|
159
|
+
// ── 墙上时刻的日历算术 ────────────────────────────────────────────────────────
|
|
160
|
+
/** 从一个 UTC 读出值的 Date 折回墙上时刻。 */
|
|
161
|
+
function fromUtcDate(date) {
|
|
162
|
+
return {
|
|
163
|
+
year: date.getUTCFullYear(),
|
|
164
|
+
month: date.getUTCMonth() + 1,
|
|
165
|
+
day: date.getUTCDate(),
|
|
166
|
+
hour: date.getUTCHours(),
|
|
167
|
+
minute: date.getUTCMinutes(),
|
|
168
|
+
second: date.getUTCSeconds(),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/** 加 n 天(保留时分秒;跨月跨年由 Date 自己算)。 */
|
|
172
|
+
function addDays(wall, days) {
|
|
173
|
+
const date = new Date(wallToNaiveMs({ ...wall, hour: 0, minute: 0, second: 0 }));
|
|
174
|
+
date.setUTCDate(date.getUTCDate() + days);
|
|
175
|
+
return { ...fromUtcDate(date), hour: wall.hour, minute: wall.minute, second: wall.second };
|
|
176
|
+
}
|
|
177
|
+
/** 下一分钟(秒归零)。 */
|
|
178
|
+
function minuteAfter(wall) {
|
|
179
|
+
const date = new Date(wallToNaiveMs({ ...wall, second: 0 }));
|
|
180
|
+
date.setUTCMinutes(date.getUTCMinutes() + 1);
|
|
181
|
+
return fromUtcDate(date);
|
|
182
|
+
}
|
|
183
|
+
/** 下一个整点。 */
|
|
184
|
+
function nextHourStart(wall) {
|
|
185
|
+
const date = new Date(wallToNaiveMs({ ...wall, minute: 0, second: 0 }));
|
|
186
|
+
date.setUTCHours(date.getUTCHours() + 1);
|
|
187
|
+
return fromUtcDate(date);
|
|
188
|
+
}
|
|
189
|
+
/** 明天零点。 */
|
|
190
|
+
function nextDayStart(wall) {
|
|
191
|
+
const date = new Date(wallToNaiveMs({ ...wall, hour: 0, minute: 0, second: 0 }));
|
|
192
|
+
date.setUTCDate(date.getUTCDate() + 1);
|
|
193
|
+
return fromUtcDate(date);
|
|
194
|
+
}
|
|
195
|
+
/** 下个月一号零点。 */
|
|
196
|
+
function nextMonthStart(wall) {
|
|
197
|
+
return fromUtcDate(new Date(Date.UTC(wall.year, wall.month, 1, 0, 0, 0)));
|
|
198
|
+
}
|
|
199
|
+
/** 这个日期是星期几,1=周一 … 7=周日(ISO 口径)。 */
|
|
200
|
+
export function isoWeekday(wall) {
|
|
201
|
+
const day = new Date(Date.UTC(wall.year, wall.month - 1, wall.day)).getUTCDay();
|
|
202
|
+
return ((day + 6) % 7) + 1;
|
|
203
|
+
}
|
|
204
|
+
// ── 文本解析 ──────────────────────────────────────────────────────────────────
|
|
205
|
+
/**
|
|
206
|
+
* 把 `90` / `90s` / `5m` / `2h` / `1d` / `1h30m` 这类写法读成秒数。
|
|
207
|
+
* 不认的返回 null(调用方负责给报错文案)。
|
|
208
|
+
*/
|
|
209
|
+
export function parseDurationSeconds(text) {
|
|
210
|
+
const raw = text.trim().toLowerCase().replace(/\s+/g, '');
|
|
211
|
+
if (raw === '')
|
|
212
|
+
return null;
|
|
213
|
+
if (/^\d+$/.test(raw))
|
|
214
|
+
return Number(raw);
|
|
215
|
+
const single = /^(\d+)(s|sec|secs|second|seconds|m|min|mins|minute|minutes|h|hr|hrs|hour|hours|d|day|days)$/.exec(raw);
|
|
216
|
+
if (single !== null) {
|
|
217
|
+
const unit = single[2];
|
|
218
|
+
const factor = unit.startsWith('s') ? 1 : unit.startsWith('m') ? 60 : unit.startsWith('h') ? 3_600 : 86_400;
|
|
219
|
+
return Number(single[1]) * factor;
|
|
220
|
+
}
|
|
221
|
+
const compound = /^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?$/.exec(raw);
|
|
222
|
+
if (compound !== null &&
|
|
223
|
+
(compound[1] !== undefined || compound[2] !== undefined || compound[3] !== undefined)) {
|
|
224
|
+
return Number(compound[1] ?? 0) * 3_600 + Number(compound[2] ?? 0) * 60 + Number(compound[3] ?? 0);
|
|
225
|
+
}
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
/** 把 `HH:MM` / `H:MM` / `HH:MM:SS` 读成时分(秒直接丢掉:定时任务精确到分钟就够了)。 */
|
|
229
|
+
export function parseClock(text) {
|
|
230
|
+
const matched = /^(\d{1,2}):(\d{2})(?::\d{2})?$/.exec(text.trim());
|
|
231
|
+
if (matched === null)
|
|
232
|
+
return null;
|
|
233
|
+
const hour = Number(matched[1]);
|
|
234
|
+
const minute = Number(matched[2]);
|
|
235
|
+
if (hour > 23 || minute > 59)
|
|
236
|
+
return null;
|
|
237
|
+
return { hour, minute };
|
|
238
|
+
}
|
|
239
|
+
/** 把星期几读成 ISO 编号(1=周一 … 7=周日);认数字、英文三字母缩写与中文写法。 */
|
|
240
|
+
export function parseWeekday(text) {
|
|
241
|
+
const raw = text.trim().toLowerCase();
|
|
242
|
+
if (/^[1-7]$/.test(raw))
|
|
243
|
+
return Number(raw);
|
|
244
|
+
const english = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'].indexOf(raw.slice(0, 3));
|
|
245
|
+
if (english >= 0)
|
|
246
|
+
return english + 1;
|
|
247
|
+
const chinese = /^(?:周|星期|礼拜)\s*([一二三四五六日天])$/.exec(text.trim());
|
|
248
|
+
if (chinese !== null) {
|
|
249
|
+
const day = chinese[1];
|
|
250
|
+
if (day === '日' || day === '天')
|
|
251
|
+
return 7;
|
|
252
|
+
return '一二三四五六'.indexOf(day) + 1;
|
|
253
|
+
}
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* 解析五字段 Vixie cron(分钟 小时 日 月 周)。
|
|
258
|
+
*
|
|
259
|
+
* 明确拒绝:秒字段(六段)、`L` / `W` / `#` / `?`、月名与周名缩写、`@daily` 这类宏。
|
|
260
|
+
* 为什么拒:这些是 Quartz / cronitor 方言或 GNU 扩展,dsc 只做 Vixie 那一种——
|
|
261
|
+
* 同一份表达式在不同实现下的行为不一样,宁可当场报错也不猜。
|
|
262
|
+
*/
|
|
263
|
+
export function parseCron(expression) {
|
|
264
|
+
const raw = expression.trim();
|
|
265
|
+
if (raw === '')
|
|
266
|
+
return { ok: false, error: 'cron 表达式不能是空的' };
|
|
267
|
+
if (raw.startsWith('@')) {
|
|
268
|
+
return { ok: false, error: `不支持 ${raw} 这类宏,请写五字段表达式,例如 0 9 * * *` };
|
|
269
|
+
}
|
|
270
|
+
const parts = raw.split(/\s+/);
|
|
271
|
+
if (parts.length !== 5) {
|
|
272
|
+
return {
|
|
273
|
+
ok: false,
|
|
274
|
+
error: parts.length === 6
|
|
275
|
+
? '只认五字段 Vixie cron(分钟 小时 日 月 周),秒字段不支持:把秒那一段去掉,或并进分钟'
|
|
276
|
+
: `五字段 Vixie cron 要 5 段(分钟 小时 日 月 周),收到 ${parts.length} 段:${raw}`,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
for (const part of parts) {
|
|
280
|
+
if (/[LW#?]/.test(part)) {
|
|
281
|
+
return { ok: false, error: `不支持 L / W / # / ? 这些扩展写法(收到 ${part})` };
|
|
282
|
+
}
|
|
283
|
+
if (/[A-Za-z]/.test(part)) {
|
|
284
|
+
return { ok: false, error: `不支持月名 / 周名缩写(收到 ${part}),请用数字:1=一月、0 或 7=周日` };
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
const lows = [0, 0, 1, 1, 0];
|
|
288
|
+
const highs = [59, 23, 31, 12, 7];
|
|
289
|
+
const labels = ['分钟', '小时', '日', '月', '周'];
|
|
290
|
+
const columns = [];
|
|
291
|
+
for (let index = 0; index < 5; index += 1) {
|
|
292
|
+
const expanded = expandCronField(parts[index], lows[index], highs[index]);
|
|
293
|
+
if (!expanded.ok) {
|
|
294
|
+
return { ok: false, error: `${labels[index]}字段「${parts[index]}」:${expanded.error}` };
|
|
295
|
+
}
|
|
296
|
+
columns.push(expanded.values);
|
|
297
|
+
}
|
|
298
|
+
// 周字段 0 和 7 都是周日,归一成 0 再去重排序。
|
|
299
|
+
const dayOfWeek = [...new Set(columns[4].map((value) => value % 7))].sort((left, right) => left - right);
|
|
300
|
+
return {
|
|
301
|
+
ok: true,
|
|
302
|
+
fields: {
|
|
303
|
+
minute: columns[0],
|
|
304
|
+
hour: columns[1],
|
|
305
|
+
dayOfMonth: columns[2],
|
|
306
|
+
month: columns[3],
|
|
307
|
+
dayOfWeek,
|
|
308
|
+
dayOfMonthRestricted: parts[2] !== '*',
|
|
309
|
+
dayOfWeekRestricted: parts[4] !== '*',
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
/** 展开一段 cron 字段(`*`、`a`、`a-b`、`a,b`、带 `/step` 的各种组合)。 */
|
|
314
|
+
function expandCronField(text, min, max) {
|
|
315
|
+
const values = new Set();
|
|
316
|
+
for (const piece of text.split(',')) {
|
|
317
|
+
if (piece === '')
|
|
318
|
+
return { ok: false, error: '列表里有空的项' };
|
|
319
|
+
const slash = piece.split('/');
|
|
320
|
+
if (slash.length > 2)
|
|
321
|
+
return { ok: false, error: '斜杠只能有一个' };
|
|
322
|
+
const body = slash[0];
|
|
323
|
+
const stepText = slash[1];
|
|
324
|
+
let step = 1;
|
|
325
|
+
if (stepText !== undefined) {
|
|
326
|
+
if (!/^\d+$/.test(stepText))
|
|
327
|
+
return { ok: false, error: `步长「${stepText}」不是数字` };
|
|
328
|
+
step = Number(stepText);
|
|
329
|
+
if (step <= 0)
|
|
330
|
+
return { ok: false, error: '步长要大于 0' };
|
|
331
|
+
}
|
|
332
|
+
let from = min;
|
|
333
|
+
let to = max;
|
|
334
|
+
if (body !== '*') {
|
|
335
|
+
const dash = body.split('-');
|
|
336
|
+
if (dash.length > 2)
|
|
337
|
+
return { ok: false, error: '范围只能写成 a-b' };
|
|
338
|
+
if (dash.length === 2) {
|
|
339
|
+
if (!/^\d+$/.test(dash[0]) || !/^\d+$/.test(dash[1])) {
|
|
340
|
+
return { ok: false, error: '范围两端都要是数字' };
|
|
341
|
+
}
|
|
342
|
+
from = Number(dash[0]);
|
|
343
|
+
to = Number(dash[1]);
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
if (!/^\d+$/.test(body))
|
|
347
|
+
return { ok: false, error: `「${body}」不是数字` };
|
|
348
|
+
from = Number(body);
|
|
349
|
+
// Vixie 的写法:`5/15` 等于 `5-max/15`;光写 `5` 就只有 5 这一个值。
|
|
350
|
+
to = stepText === undefined ? from : max;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
if (from < min || to > max || from > to) {
|
|
354
|
+
return { ok: false, error: `取值要在 ${min}~${max} 之间,且左端不大于右端` };
|
|
355
|
+
}
|
|
356
|
+
for (let value = from; value <= to; value += step)
|
|
357
|
+
values.add(value);
|
|
358
|
+
}
|
|
359
|
+
if (values.size === 0)
|
|
360
|
+
return { ok: false, error: '没有可用的取值' };
|
|
361
|
+
return { ok: true, values: [...values].sort((left, right) => left - right) };
|
|
362
|
+
}
|
|
363
|
+
/** 解析 `at` 后面的时刻:带时区标识按绝对时刻读,不带就按任务时区的墙上时刻读。 */
|
|
364
|
+
function parseAtInstant(text, timeZone, nowMs) {
|
|
365
|
+
const raw = text.trim();
|
|
366
|
+
if (raw === '')
|
|
367
|
+
return { ok: false, error: 'at 后面要写时刻,例如 at:2026-03-09T09:30 或 at:2026-03-09T09:30:00Z' };
|
|
368
|
+
// 只有 HH:MM:按今天算,已经过了就明天(「今天 18:00 提醒我」这种最顺手的写法)。
|
|
369
|
+
if (/^\d{1,2}:\d{2}(?::\d{2})?$/.test(raw)) {
|
|
370
|
+
const clock = parseClock(raw);
|
|
371
|
+
if (clock === null)
|
|
372
|
+
return { ok: false, error: `「${raw}」不是合法时刻(小时 0~23、分钟 0~59)` };
|
|
373
|
+
const today = localWall(nowMs, timeZone);
|
|
374
|
+
for (const offset of [0, 1]) {
|
|
375
|
+
const day = addDays({ ...today, hour: clock.hour, minute: clock.minute, second: 0 }, offset);
|
|
376
|
+
const instant = wallTimeToInstant(day, timeZone);
|
|
377
|
+
if (instant !== null && instant > nowMs)
|
|
378
|
+
return { ok: true, atMs: instant };
|
|
379
|
+
}
|
|
380
|
+
return { ok: false, error: `算不出 ${raw} 对应的时刻(位于夏令时跳表的那一小时?)` };
|
|
381
|
+
}
|
|
382
|
+
const hasZone = /(?:z|[+-]\d{2}:?\d{2})$/i.test(raw);
|
|
383
|
+
if (hasZone) {
|
|
384
|
+
const parsed = Date.parse(raw);
|
|
385
|
+
if (Number.isNaN(parsed))
|
|
386
|
+
return { ok: false, error: `「${raw}」不是一个能读懂的时刻` };
|
|
387
|
+
return { ok: true, atMs: parsed };
|
|
388
|
+
}
|
|
389
|
+
const matched = /^(\d{4})-(\d{1,2})-(\d{1,2})(?:[T\s](\d{1,2}):(\d{2})(?::(\d{2}))?)?$/.exec(raw);
|
|
390
|
+
if (matched === null) {
|
|
391
|
+
return { ok: false, error: `「${raw}」不是一个能读懂的时刻,请写 2026-03-09T09:30 或 2026-03-09T09:30:00Z` };
|
|
392
|
+
}
|
|
393
|
+
const wall = {
|
|
394
|
+
year: Number(matched[1]),
|
|
395
|
+
month: Number(matched[2]),
|
|
396
|
+
day: Number(matched[3]),
|
|
397
|
+
hour: Number(matched[4] ?? 0),
|
|
398
|
+
minute: Number(matched[5] ?? 0),
|
|
399
|
+
second: Number(matched[6] ?? 0),
|
|
400
|
+
};
|
|
401
|
+
if (wall.month > 12 || wall.day > 31 || wall.hour > 23 || wall.minute > 59 || wall.second > 59) {
|
|
402
|
+
return { ok: false, error: `「${raw}」里的日期或时刻越界了` };
|
|
403
|
+
}
|
|
404
|
+
const instant = wallTimeToInstant(wall, timeZone);
|
|
405
|
+
if (instant === null) {
|
|
406
|
+
return { ok: false, error: `${raw} 这个本地时刻在 ${timeZone} 不存在(夏令时跳表的那一小时),换一个时刻` };
|
|
407
|
+
}
|
|
408
|
+
return { ok: true, atMs: instant };
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* 解析一条选择器文本。
|
|
412
|
+
*
|
|
413
|
+
* 认两种写法:带冒号的 `every:5m`,和空格分开的 `every 5m`(cron 一定是后者)。
|
|
414
|
+
* 单独写五段 cron 表达式(`30 9 * * *`)也认——模型最容易这么写。
|
|
415
|
+
*
|
|
416
|
+
* @param text - 用户 / 模型给的选择器
|
|
417
|
+
* @param timeZone - 任务时区(`at` 这种墙上时刻要靠它换算)
|
|
418
|
+
* @param nowMs - 现在(`after` 的起算点、`at` 的「是否已过去」判定都靠它;显式传入才好测)
|
|
419
|
+
*/
|
|
420
|
+
export function parseRule(text, timeZone, nowMs) {
|
|
421
|
+
const raw = text.trim();
|
|
422
|
+
if (raw === '') {
|
|
423
|
+
return { ok: false, error: `选择器不能是空的。六种写法:${SCHEDULE_RULE_KINDS.join(' / ')}` };
|
|
424
|
+
}
|
|
425
|
+
if (!isValidTimeZone(timeZone)) {
|
|
426
|
+
return { ok: false, error: `时区「${timeZone}」不认识,请写 IANA 名字,例如 Asia/Shanghai` };
|
|
427
|
+
}
|
|
428
|
+
// 切出「关键字」和「后面那一串」:先看首个冒号,再看首个空白,谁在前用谁。
|
|
429
|
+
const colonAt = raw.indexOf(':');
|
|
430
|
+
const spaceAt = raw.search(/\s/);
|
|
431
|
+
let head = raw;
|
|
432
|
+
let rest = '';
|
|
433
|
+
if (colonAt >= 0 && (spaceAt < 0 || colonAt < spaceAt)) {
|
|
434
|
+
head = raw.slice(0, colonAt);
|
|
435
|
+
rest = raw.slice(colonAt + 1);
|
|
436
|
+
}
|
|
437
|
+
else if (spaceAt >= 0) {
|
|
438
|
+
head = raw.slice(0, spaceAt);
|
|
439
|
+
rest = raw.slice(spaceAt + 1);
|
|
440
|
+
}
|
|
441
|
+
const kind = head.trim().toLowerCase();
|
|
442
|
+
switch (kind) {
|
|
443
|
+
case 'after': {
|
|
444
|
+
const seconds = parseDurationSeconds(rest);
|
|
445
|
+
if (seconds === null || seconds <= 0) {
|
|
446
|
+
return { ok: false, error: 'after 后面要写正数时长,例如 after:90s / after:5m / after:2h' };
|
|
447
|
+
}
|
|
448
|
+
return { ok: true, rule: { kind: 'after', seconds: Math.round(seconds), anchorMs: nowMs } };
|
|
449
|
+
}
|
|
450
|
+
case 'at': {
|
|
451
|
+
const parsed = parseAtInstant(rest, timeZone, nowMs);
|
|
452
|
+
if (!parsed.ok)
|
|
453
|
+
return { ok: false, error: parsed.error };
|
|
454
|
+
if (parsed.atMs <= nowMs) {
|
|
455
|
+
return { ok: false, error: `at 的那个时刻已经过去了(${formatInstant(parsed.atMs, timeZone)}),要定将来就往后写` };
|
|
456
|
+
}
|
|
457
|
+
return { ok: true, rule: { kind: 'at', atMs: parsed.atMs } };
|
|
458
|
+
}
|
|
459
|
+
case 'every': {
|
|
460
|
+
const seconds = parseDurationSeconds(rest);
|
|
461
|
+
if (seconds === null || seconds < MIN_EVERY_SECONDS) {
|
|
462
|
+
return {
|
|
463
|
+
ok: false,
|
|
464
|
+
error: `every 的间隔至少 ${MIN_EVERY_SECONDS} 秒(收到「${rest || '空'}」);更密的提醒请用别的方式`,
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
return { ok: true, rule: { kind: 'every', seconds: Math.round(seconds), anchorMs: nowMs } };
|
|
468
|
+
}
|
|
469
|
+
case 'daily': {
|
|
470
|
+
const clock = parseClock(rest);
|
|
471
|
+
if (clock === null)
|
|
472
|
+
return { ok: false, error: 'daily 后面要写 HH:MM,例如 daily:09:30' };
|
|
473
|
+
return { ok: true, rule: { kind: 'daily', hour: clock.hour, minute: clock.minute } };
|
|
474
|
+
}
|
|
475
|
+
case 'weekly': {
|
|
476
|
+
const fields = rest.trim().split(/\s+/);
|
|
477
|
+
// `weekly:mon 09:30` 与 `weekly:mon:09:30` 都认。
|
|
478
|
+
const pieces = fields.length >= 2 ? fields : rest.trim().split(':');
|
|
479
|
+
if (pieces.length < 2) {
|
|
480
|
+
return { ok: false, error: 'weekly 后面要写「星期几 时刻」,例如 weekly:mon 09:30' };
|
|
481
|
+
}
|
|
482
|
+
const weekday = parseWeekday(pieces[0]);
|
|
483
|
+
if (weekday === null)
|
|
484
|
+
return { ok: false, error: `认不出星期几「${pieces[0]}」,写 1~7、mon~sun 或 周一~周日` };
|
|
485
|
+
const clock = parseClock(pieces.slice(1).join(':'));
|
|
486
|
+
if (clock === null)
|
|
487
|
+
return { ok: false, error: `认不出时刻「${pieces.slice(1).join(' ')}」,写 HH:MM` };
|
|
488
|
+
return { ok: true, rule: { kind: 'weekly', weekday, hour: clock.hour, minute: clock.minute } };
|
|
489
|
+
}
|
|
490
|
+
case 'cron': {
|
|
491
|
+
const parsed = parseCron(rest);
|
|
492
|
+
if (!parsed.ok)
|
|
493
|
+
return { ok: false, error: parsed.error };
|
|
494
|
+
return { ok: true, rule: { kind: 'cron', expression: rest.trim(), fields: parsed.fields } };
|
|
495
|
+
}
|
|
496
|
+
default: {
|
|
497
|
+
// 没写关键字:整串当 cron 试一次(`30 9 * * *` 是模型最顺手的写法)。
|
|
498
|
+
const parsed = parseCron(raw);
|
|
499
|
+
if (parsed.ok)
|
|
500
|
+
return { ok: true, rule: { kind: 'cron', expression: raw, fields: parsed.fields } };
|
|
501
|
+
return {
|
|
502
|
+
ok: false,
|
|
503
|
+
error: `认不出选择器「${kind}」。六种写法:after:5m(多久后一次)/ at:2026-03-09T09:30(绝对时刻一次)/ every:30m(间隔,至少 ${MIN_EVERY_SECONDS} 秒)/ daily:09:30 / weekly:mon 09:30 / cron:0 9 * * *(五字段 Vixie)`,
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
// ── 下一次触发时刻 ────────────────────────────────────────────────────────────
|
|
509
|
+
/** 这条规则是不是「只跑一次」。 */
|
|
510
|
+
export function isOneShot(rule) {
|
|
511
|
+
return rule.kind === 'after' || rule.kind === 'at';
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* 严格晚于 `fromMs` 的下一次触发时刻;算不出来(一次性任务已经过期、cron 永远不匹配)返回 null。
|
|
515
|
+
*
|
|
516
|
+
* `every` 与 `after` 都以规则里的 `anchorMs` 为栅格起点,不用 `fromMs` 递推——
|
|
517
|
+
* 进程重启、tick 抖动都不会让「每 30 分钟」漂成 30 分零 7 秒。
|
|
518
|
+
*/
|
|
519
|
+
export function nextRunAt(rule, timeZone, fromMs) {
|
|
520
|
+
switch (rule.kind) {
|
|
521
|
+
case 'after': {
|
|
522
|
+
const at = rule.anchorMs + rule.seconds * 1_000;
|
|
523
|
+
return at > fromMs ? at : null;
|
|
524
|
+
}
|
|
525
|
+
case 'at':
|
|
526
|
+
return rule.atMs > fromMs ? rule.atMs : null;
|
|
527
|
+
case 'every': {
|
|
528
|
+
const period = rule.seconds * 1_000;
|
|
529
|
+
if (fromMs < rule.anchorMs)
|
|
530
|
+
return rule.anchorMs;
|
|
531
|
+
return rule.anchorMs + (Math.floor((fromMs - rule.anchorMs) / period) + 1) * period;
|
|
532
|
+
}
|
|
533
|
+
case 'daily':
|
|
534
|
+
return nextDaily(rule, timeZone, fromMs);
|
|
535
|
+
case 'weekly':
|
|
536
|
+
return nextWeekly(rule, timeZone, fromMs);
|
|
537
|
+
case 'cron':
|
|
538
|
+
return nextCron(rule.fields, timeZone, fromMs);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
/** 每天 HH:MM 的下一次;当天那个时刻在跳表里不存在(gap)就顺延到第二天。 */
|
|
542
|
+
function nextDaily(rule, timeZone, fromMs) {
|
|
543
|
+
const today = localWall(fromMs, timeZone);
|
|
544
|
+
// 最多往后看 8 天:正常一天就命中,gap 最多连跳一两次,8 天足够判出「这个时区的这一天根本没有 02:30」。
|
|
545
|
+
for (let offset = 0; offset <= 8; offset += 1) {
|
|
546
|
+
const day = addDays({ ...today, hour: rule.hour, minute: rule.minute, second: 0 }, offset);
|
|
547
|
+
const instant = wallTimeToInstant(day, timeZone);
|
|
548
|
+
if (instant !== null && instant > fromMs)
|
|
549
|
+
return instant;
|
|
550
|
+
}
|
|
551
|
+
return null;
|
|
552
|
+
}
|
|
553
|
+
/** 每周几 HH:MM 的下一次;同样对 gap 顺延。 */
|
|
554
|
+
function nextWeekly(rule, timeZone, fromMs) {
|
|
555
|
+
const today = localWall(fromMs, timeZone);
|
|
556
|
+
for (let offset = 0; offset <= 21; offset += 1) {
|
|
557
|
+
const day = addDays({ ...today, hour: rule.hour, minute: rule.minute, second: 0 }, offset);
|
|
558
|
+
if (isoWeekday(day) !== rule.weekday)
|
|
559
|
+
continue;
|
|
560
|
+
const instant = wallTimeToInstant(day, timeZone);
|
|
561
|
+
if (instant !== null && instant > fromMs)
|
|
562
|
+
return instant;
|
|
563
|
+
}
|
|
564
|
+
return null;
|
|
565
|
+
}
|
|
566
|
+
/** Vixie 的「日 / 周」判定:两个字段都不是 `*` 时是**或**的关系,只有一个受限时就按那一个。 */
|
|
567
|
+
function cronDayMatches(fields, wall) {
|
|
568
|
+
const dayOfMonth = fields.dayOfMonth.includes(wall.day);
|
|
569
|
+
const dayOfWeek = fields.dayOfWeek.includes(isoWeekday(wall) % 7);
|
|
570
|
+
if (fields.dayOfMonthRestricted && fields.dayOfWeekRestricted)
|
|
571
|
+
return dayOfMonth || dayOfWeek;
|
|
572
|
+
if (fields.dayOfMonthRestricted)
|
|
573
|
+
return dayOfMonth;
|
|
574
|
+
if (fields.dayOfWeekRestricted)
|
|
575
|
+
return dayOfWeek;
|
|
576
|
+
return true;
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* cron 的下一次触发。从「当前本地墙上时刻的下一分钟」起逐格推进:月不对整月跳、日不对整天跳、
|
|
580
|
+
* 小时不对整点跳,所以 `0 0 29 2 *`(四年一次)也不会退化成逐分钟死循环。
|
|
581
|
+
*
|
|
582
|
+
* 墙上时刻算出来以后交给 wallTimeToInstant 落成绝对时刻:gap 里的那一分钟返回 null,
|
|
583
|
+
* 自然被跳过(这就是「DST gap 跳过该次」);overlap 时函数返回较早那一次,
|
|
584
|
+
* 扫描从较早的瞬间往后走,因此重复的那一小时只会命中一次。
|
|
585
|
+
*/
|
|
586
|
+
function nextCron(fields, timeZone, fromMs) {
|
|
587
|
+
let wall = minuteAfter(localWall(fromMs, timeZone));
|
|
588
|
+
for (let guard = 0; guard < CRON_SCAN_LIMIT; guard += 1) {
|
|
589
|
+
if (!fields.month.includes(wall.month)) {
|
|
590
|
+
wall = nextMonthStart(wall);
|
|
591
|
+
continue;
|
|
592
|
+
}
|
|
593
|
+
if (!cronDayMatches(fields, wall)) {
|
|
594
|
+
wall = nextDayStart(wall);
|
|
595
|
+
continue;
|
|
596
|
+
}
|
|
597
|
+
if (!fields.hour.includes(wall.hour)) {
|
|
598
|
+
wall = nextHourStart(wall);
|
|
599
|
+
continue;
|
|
600
|
+
}
|
|
601
|
+
if (!fields.minute.includes(wall.minute)) {
|
|
602
|
+
wall = minuteAfter(wall);
|
|
603
|
+
continue;
|
|
604
|
+
}
|
|
605
|
+
const instant = wallTimeToInstant({ ...wall, second: 0 }, timeZone);
|
|
606
|
+
if (instant !== null && instant > fromMs)
|
|
607
|
+
return instant;
|
|
608
|
+
wall = minuteAfter(wall);
|
|
609
|
+
}
|
|
610
|
+
return null;
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* 两次触发之间大概隔多久(毫秒);一次性任务返回 null。
|
|
614
|
+
* 补跑宽限取它的一半,所以只要个「大概」,cron 就现算相邻两次。
|
|
615
|
+
*/
|
|
616
|
+
export function periodMs(rule, timeZone, fromMs) {
|
|
617
|
+
switch (rule.kind) {
|
|
618
|
+
case 'after':
|
|
619
|
+
case 'at':
|
|
620
|
+
return null;
|
|
621
|
+
case 'every':
|
|
622
|
+
return rule.seconds * 1_000;
|
|
623
|
+
case 'daily':
|
|
624
|
+
return 86_400_000;
|
|
625
|
+
case 'weekly':
|
|
626
|
+
return 7 * 86_400_000;
|
|
627
|
+
case 'cron': {
|
|
628
|
+
const first = nextRunAt(rule, timeZone, fromMs);
|
|
629
|
+
if (first === null)
|
|
630
|
+
return null;
|
|
631
|
+
const second = nextRunAt(rule, timeZone, first);
|
|
632
|
+
return second === null ? null : second - first;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* 错过多久之内还算「来得及补跑」。半周期,夹在 120s~2h;一次性任务固定 120s。
|
|
638
|
+
* 为什么要夹:`every:1m` 的任务补跑窗口不该是 30 秒(tick 都来不及),
|
|
639
|
+
* `daily` 的任务也不该给 12 小时(早上 9 点的提醒晚上 9 点才弹就成骚扰了)。
|
|
640
|
+
*/
|
|
641
|
+
export function graceMs(rule, timeZone, fromMs) {
|
|
642
|
+
const period = periodMs(rule, timeZone, fromMs);
|
|
643
|
+
if (period === null)
|
|
644
|
+
return ONE_SHOT_GRACE_MS;
|
|
645
|
+
return Math.min(Math.max(Math.round(period / 2), MIN_GRACE_MS), MAX_GRACE_MS);
|
|
646
|
+
}
|
|
647
|
+
// ── 给人看的文案 ──────────────────────────────────────────────────────────────
|
|
648
|
+
/** 把秒数写成「30 秒 / 5 分钟 / 2 小时 / 1 天 3 小时」这种人话。 */
|
|
649
|
+
export function formatDuration(seconds) {
|
|
650
|
+
if (seconds < 60)
|
|
651
|
+
return `${seconds} 秒`;
|
|
652
|
+
if (seconds < 3_600) {
|
|
653
|
+
const minutes = Math.floor(seconds / 60);
|
|
654
|
+
const rest = seconds % 60;
|
|
655
|
+
return rest === 0 ? `${minutes} 分钟` : `${minutes} 分 ${rest} 秒`;
|
|
656
|
+
}
|
|
657
|
+
if (seconds < 86_400) {
|
|
658
|
+
const hours = Math.floor(seconds / 3_600);
|
|
659
|
+
const rest = Math.floor((seconds % 3_600) / 60);
|
|
660
|
+
return rest === 0 ? `${hours} 小时` : `${hours} 小时 ${rest} 分`;
|
|
661
|
+
}
|
|
662
|
+
const days = Math.floor(seconds / 86_400);
|
|
663
|
+
const rest = Math.floor((seconds % 86_400) / 3_600);
|
|
664
|
+
return rest === 0 ? `${days} 天` : `${days} 天 ${rest} 小时`;
|
|
665
|
+
}
|
|
666
|
+
/** 规则的一句话描述(不含「下次什么时候」——那个要按当前时刻现算)。 */
|
|
667
|
+
export function describeRule(rule, timeZone) {
|
|
668
|
+
const pad = (value) => String(value).padStart(2, '0');
|
|
669
|
+
switch (rule.kind) {
|
|
670
|
+
case 'after':
|
|
671
|
+
return `${formatDuration(rule.seconds)}后跑一次`;
|
|
672
|
+
case 'at':
|
|
673
|
+
return `只跑一次 · ${formatInstant(rule.atMs, timeZone)}`;
|
|
674
|
+
case 'every':
|
|
675
|
+
return `每 ${formatDuration(rule.seconds)}`;
|
|
676
|
+
case 'daily':
|
|
677
|
+
return `每天 ${pad(rule.hour)}:${pad(rule.minute)}`;
|
|
678
|
+
case 'weekly':
|
|
679
|
+
return `每${WEEKDAY_NAMES[rule.weekday] ?? `周${rule.weekday}`} ${pad(rule.hour)}:${pad(rule.minute)}`;
|
|
680
|
+
case 'cron':
|
|
681
|
+
return `cron ${rule.expression}`;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
/** 「下次 2026-03-09 09:30:00 +08:00(Asia/Shanghai)」;没有下一次就说明白原因。 */
|
|
685
|
+
export function describeNext(rule, timeZone, nextMs) {
|
|
686
|
+
if (nextMs === null) {
|
|
687
|
+
return isOneShot(rule) ? '已经跑完(一次性任务)' : '算不出下一次触发时刻,请检查规则';
|
|
688
|
+
}
|
|
689
|
+
return `下次 ${formatInstant(nextMs, timeZone)}(${timeZone})`;
|
|
690
|
+
}
|
|
691
|
+
// ── 反序列化 ──────────────────────────────────────────────────────────────────
|
|
692
|
+
function isFiniteNumber(value) {
|
|
693
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* 把磁盘上读回来的东西收敛成一条合法规则;认不出就返回 null(调用方跳过这条任务并记账)。
|
|
697
|
+
* 磁盘上的文件是用户能手改的,属于不可信输入,所以每个字段都要过一遍。
|
|
698
|
+
*/
|
|
699
|
+
export function normalizeRule(value) {
|
|
700
|
+
if (value === null || typeof value !== 'object')
|
|
701
|
+
return null;
|
|
702
|
+
const raw = value;
|
|
703
|
+
switch (raw.kind) {
|
|
704
|
+
case 'after':
|
|
705
|
+
case 'every': {
|
|
706
|
+
if (!isFiniteNumber(raw.seconds) || raw.seconds <= 0)
|
|
707
|
+
return null;
|
|
708
|
+
if (!isFiniteNumber(raw.anchorMs))
|
|
709
|
+
return null;
|
|
710
|
+
if (raw.kind === 'every' && raw.seconds < MIN_EVERY_SECONDS)
|
|
711
|
+
return null;
|
|
712
|
+
return { kind: raw.kind, seconds: Math.round(raw.seconds), anchorMs: Math.round(raw.anchorMs) };
|
|
713
|
+
}
|
|
714
|
+
case 'at': {
|
|
715
|
+
if (!isFiniteNumber(raw.atMs) || raw.atMs <= 0)
|
|
716
|
+
return null;
|
|
717
|
+
return { kind: 'at', atMs: Math.round(raw.atMs) };
|
|
718
|
+
}
|
|
719
|
+
case 'daily': {
|
|
720
|
+
if (!isFiniteNumber(raw.hour) || !isFiniteNumber(raw.minute))
|
|
721
|
+
return null;
|
|
722
|
+
if (raw.hour < 0 || raw.hour > 23 || raw.minute < 0 || raw.minute > 59)
|
|
723
|
+
return null;
|
|
724
|
+
return { kind: 'daily', hour: Math.floor(raw.hour), minute: Math.floor(raw.minute) };
|
|
725
|
+
}
|
|
726
|
+
case 'weekly': {
|
|
727
|
+
if (!isFiniteNumber(raw.weekday) || raw.weekday < 1 || raw.weekday > 7)
|
|
728
|
+
return null;
|
|
729
|
+
if (!isFiniteNumber(raw.hour) || !isFiniteNumber(raw.minute))
|
|
730
|
+
return null;
|
|
731
|
+
if (raw.hour < 0 || raw.hour > 23 || raw.minute < 0 || raw.minute > 59)
|
|
732
|
+
return null;
|
|
733
|
+
return { kind: 'weekly', weekday: Math.floor(raw.weekday), hour: Math.floor(raw.hour), minute: Math.floor(raw.minute) };
|
|
734
|
+
}
|
|
735
|
+
case 'cron': {
|
|
736
|
+
const expression = typeof raw.expression === 'string' ? raw.expression : '';
|
|
737
|
+
const parsed = parseCron(expression);
|
|
738
|
+
if (!parsed.ok)
|
|
739
|
+
return null;
|
|
740
|
+
return { kind: 'cron', expression: expression.trim(), fields: parsed.fields };
|
|
741
|
+
}
|
|
742
|
+
default:
|
|
743
|
+
return null;
|
|
744
|
+
}
|
|
745
|
+
}
|