@waq666/pneuma 0.0.0-stage → 0.7.0
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 +144 -2
- 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 +13 -0
- package/lib/app/App.js +1498 -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 +32 -0
- package/lib/app/ChatView.js +198 -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 +272 -0
- package/lib/app/TaskStrips.d.ts +13 -0
- package/lib/app/TaskStrips.js +40 -0
- package/lib/app/ToolCard.d.ts +5 -0
- package/lib/app/ToolCard.js +40 -0
- package/lib/app/TranscriptOverlay.d.ts +12 -0
- package/lib/app/TranscriptOverlay.js +17 -0
- package/lib/app/Welcome.d.ts +6 -0
- package/lib/app/Welcome.js +66 -0
- package/lib/app/attach.d.ts +16 -0
- package/lib/app/attach.js +58 -0
- package/lib/app/click.d.ts +27 -0
- package/lib/app/click.js +89 -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/markdown.d.ts +54 -0
- package/lib/app/markdown.js +189 -0
- package/lib/app/settings-model.d.ts +69 -0
- package/lib/app/settings-model.js +114 -0
- package/lib/app/theme.d.ts +166 -0
- package/lib/app/theme.js +141 -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 +272 -0
- package/lib/core/llm.js +548 -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 +862 -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 +425 -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,678 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 调度器:把「到点了」这件事变成一次投递。整个插件里只有这一个文件认识时间轮。
|
|
3
|
+
*
|
|
4
|
+
* 为什么这么设计:
|
|
5
|
+
* 1. **单个自重排 setTimeout,不用 setInterval**。下一次该醒的时刻是能从任务表里现算出来的,
|
|
6
|
+
* 用 setInterval 只会得到一个「不管有没有事都每分钟醒一次」的忙轮询;自重排则让空表时
|
|
7
|
+
* 一次睡到下一次触发点。超长的延迟要**分段**(每次最多 6 小时):`setTimeout` 的延迟是
|
|
8
|
+
* 32 位有符号数,超过约 24.8 天会被当成 1 毫秒立即触发,那会变成死循环。`timer.unref()`
|
|
9
|
+
* 是最后一道:只剩这一个定时器时,进程照样能退出,宿主关掉不该被定时任务拖住。
|
|
10
|
+
* 2. **`.lock` 互斥**:同一份 tasks.json 被两个 dsc 进程一起推 `nextRunAt` 必然写坏一次排期。
|
|
11
|
+
* 锁里存 `pid + 进程启动时刻指纹`(光靠 pid 会被回收骗过去),拿不到锁的进程只读——
|
|
12
|
+
* 它照样能 list / create,但不推进、不投递,等锁空出来自然接管。
|
|
13
|
+
* 3. **catch-up 只在启动后自然发生**:tick 本来就按「nextRunAt <= now」挑任务,
|
|
14
|
+
* 睡了两小时醒来会一次看见错过的那些,所以关键是**决定跑几次**:至多一次。
|
|
15
|
+
* 规则照 hermes `cron/jobs.py::_fast_forward_missed_recurring` 与
|
|
16
|
+
* `_retire_expired_oneshot`:宽限内正常补跑;超宽限则把积压合并成一次并快进排期;
|
|
17
|
+
* 一次性任务超宽限直接退休(记录里写清跳过原因,绝不静默丢槽位)。
|
|
18
|
+
* 4. **pre-dispatch 校验**照 hermes `cron/scheduler_preflight.py`:凭据解析不出来、
|
|
19
|
+
* 投递目标不知道、沙箱不让写数据目录——这三种情况**一个模型请求都不发**,
|
|
20
|
+
* 直接把任务标 blocked 并写下原因。自动化最贵的浪费是「明知会失败还去烧一次额度」。
|
|
21
|
+
* 5. **投递前问 `waiting.any`**:界面上有审批卡、计划卡、提问卡挂着的时候不隔着一张卡硬推,
|
|
22
|
+
* 整批推迟到下一 tick。人的决定排在机器前面。
|
|
23
|
+
* 6. **不改 goal 的 rounds、不给 goal 上膛**(`src/core/goal.ts:230-242`、`:96-97`)。
|
|
24
|
+
* 定时任务和会话目标是两码事:目标是「用户在场、说了一句就跑到完」,定时任务是
|
|
25
|
+
* 「用户不在场、跑一次就收」。给 goal 上膛等于让无人值守的定时任务自己去点着一条
|
|
26
|
+
* 可以无限续跑的链,那是把两个刹车一起拆掉——所以这个文件从头到尾不碰 `ctx.goal`。
|
|
27
|
+
*
|
|
28
|
+
* @module dsc/core/schedule/runner
|
|
29
|
+
*/
|
|
30
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
31
|
+
import { formatDuration, formatInstant, graceMs, isOneShot, nextRunAt } from './rule.js';
|
|
32
|
+
import { errorText } from './store.js';
|
|
33
|
+
/** 一次定时器最多睡多久:超长延迟分段,避开 setTimeout 的 32 位溢出。 */
|
|
34
|
+
export const TIMER_SLICE_MS = 6 * 3600_000;
|
|
35
|
+
/** 「完全没到模型」的瞬时网络错重试阶梯:5 / 15 / 30 分钟(照 Claude Cowork 那三级)。 */
|
|
36
|
+
export const RETRY_LADDER_MS = [5 * 60_000, 15 * 60_000, 30 * 60_000];
|
|
37
|
+
/** 配额类错误拿不到 `retry after` 时的默认停靠时长。 */
|
|
38
|
+
export const DEFAULT_QUOTA_HOLD_MS = 15 * 60_000;
|
|
39
|
+
function secondsText(ms) {
|
|
40
|
+
return formatDuration(Math.max(1, Math.round(ms / 1_000)));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 决定一个已到点的槽位怎么处理。这就是 catch-up 策略的全部:**至多跑一次,绝不补积压**。
|
|
44
|
+
*
|
|
45
|
+
* - 一次性任务(after / at):宽限 120 秒内照跑;超了不跑(`missed`),排期收尾。
|
|
46
|
+
* - 周期任务:宽限内 = 补一次迟到的;超宽限 = 把积压合并成这一次跑掉,排期直接快进到现在之后。
|
|
47
|
+
*
|
|
48
|
+
* @param rule - 触发规则
|
|
49
|
+
* @param timeZone - 任务时区(宽限与下一次都按时区算)
|
|
50
|
+
* @param nextMs - 已经到点(或已错过)的那个槽位
|
|
51
|
+
* @param nowMs - 现在
|
|
52
|
+
*/
|
|
53
|
+
export function decideOccurrence(rule, timeZone, nextMs, nowMs) {
|
|
54
|
+
if (nextMs === null)
|
|
55
|
+
return { fire: false, slot: 0, next: null, verdict: 'idle', reason: '还没有排期' };
|
|
56
|
+
if (nextMs > nowMs)
|
|
57
|
+
return { fire: false, slot: nextMs, next: nextMs, verdict: 'idle', reason: '还没到点' };
|
|
58
|
+
const lateMs = nowMs - nextMs;
|
|
59
|
+
const grace = graceMs(rule, timeZone, nextMs);
|
|
60
|
+
if (isOneShot(rule)) {
|
|
61
|
+
if (lateMs <= grace) {
|
|
62
|
+
return { fire: true, slot: nextMs, next: null, verdict: 'due', reason: `一次性任务,迟到 ${secondsText(lateMs)}(宽限 ${secondsText(grace)} 内),照跑` };
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
fire: false,
|
|
66
|
+
slot: nextMs,
|
|
67
|
+
next: null,
|
|
68
|
+
verdict: 'missed',
|
|
69
|
+
reason: `一次性任务迟到 ${secondsText(lateMs)},超过 ${secondsText(grace)} 宽限:不补跑,直接收尾`,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const next = nextRunAt(rule, timeZone, nowMs);
|
|
73
|
+
if (lateMs <= grace) {
|
|
74
|
+
return lateMs <= 60_000
|
|
75
|
+
? { fire: true, slot: nextMs, next, verdict: 'due', reason: '到点' }
|
|
76
|
+
: { fire: true, slot: nextMs, next, verdict: 'late', reason: `迟到 ${secondsText(lateMs)}(宽限 ${secondsText(grace)} 内),补跑一次` };
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
fire: true,
|
|
80
|
+
slot: nextMs,
|
|
81
|
+
next,
|
|
82
|
+
verdict: 'catch-up',
|
|
83
|
+
reason: `错过 ${secondsText(lateMs)},超过 ${secondsText(grace)} 宽限:${secondsText(lateMs)} 里的积压合并成这一次,不逐次重放`,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const QUOTA_PATTERNS = [
|
|
87
|
+
/\b429\b/,
|
|
88
|
+
/rate[\s_-]?limit/i,
|
|
89
|
+
/too many requests/i,
|
|
90
|
+
/quota/i,
|
|
91
|
+
/insufficient[\s_-]?(quota|balance|credit)/i,
|
|
92
|
+
/额度|配额|余额不足|欠费|限流/,
|
|
93
|
+
];
|
|
94
|
+
const TRANSIENT_PATTERNS = [
|
|
95
|
+
/econnrefused/i,
|
|
96
|
+
/econnreset/i,
|
|
97
|
+
/etimedout/i,
|
|
98
|
+
/enotfound/i,
|
|
99
|
+
/eai_again/i,
|
|
100
|
+
/epipe/i,
|
|
101
|
+
/fetch failed/i,
|
|
102
|
+
/socket hang up/i,
|
|
103
|
+
/network/i,
|
|
104
|
+
/timed? ?out/i,
|
|
105
|
+
/连接超时|网络|连不上|超时|连接被重置|拒绝连接/,
|
|
106
|
+
];
|
|
107
|
+
/**
|
|
108
|
+
* 认一次失败是不是「完全没到模型」的瞬时网络错,或配额类。
|
|
109
|
+
* 依赖错误原文是没办法的办法:`agent.followup` 是排队投递、不回传结果,
|
|
110
|
+
* 只能从错误文本与「有没有等到回合结束」这两条弱信号里推断(见 noteTurnEnd)。
|
|
111
|
+
*/
|
|
112
|
+
export function classifyFailure(message) {
|
|
113
|
+
for (const pattern of QUOTA_PATTERNS)
|
|
114
|
+
if (pattern.test(message))
|
|
115
|
+
return 'quota';
|
|
116
|
+
for (const pattern of TRANSIENT_PATTERNS)
|
|
117
|
+
if (pattern.test(message))
|
|
118
|
+
return 'transient';
|
|
119
|
+
return 'other';
|
|
120
|
+
}
|
|
121
|
+
/** 从配额错误原文里抠出「恢复点还有多久」:`retry after 300s` / `300 秒后重试`,抠不到就用默认值。 */
|
|
122
|
+
export function quotaHoldMs(message) {
|
|
123
|
+
const english = /retry[\s_-]*after[\s:]*(\d+)\s*s/i.exec(message);
|
|
124
|
+
if (english !== null)
|
|
125
|
+
return Number(english[1]) * 1_000 + 60_000;
|
|
126
|
+
const chinese = /(\d+)\s*秒后/.exec(message);
|
|
127
|
+
if (chinese !== null)
|
|
128
|
+
return Number(chinese[1]) * 1_000 + 60_000;
|
|
129
|
+
const millis = /retry[\s_-]*after[\s:]*(\d+)\s*ms/i.exec(message);
|
|
130
|
+
if (millis !== null)
|
|
131
|
+
return Number(millis[1]) + 60_000;
|
|
132
|
+
return DEFAULT_QUOTA_HOLD_MS;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* 算一次失败该怎么记账。纯函数,自检直接调它。
|
|
136
|
+
*
|
|
137
|
+
* - 配额类:`nextRunAt` 停到恢复点(原文给了 `retry after` 就用它,否则 15 分钟)。
|
|
138
|
+
* - 瞬时网络错:走 5/15/30 分钟阶梯,且**只在整个阶梯还没用完、且比自然排期更早**时才插队。
|
|
139
|
+
* - 其它:不动排期,只记失败——到过模型的失败不该被自动重发(可能已经有副作用了)。
|
|
140
|
+
*/
|
|
141
|
+
export function planFailure(rule, timeZone, nextRunAtMs, nowMs, message, usedRungs) {
|
|
142
|
+
const kind = classifyFailure(message);
|
|
143
|
+
if (kind === 'quota') {
|
|
144
|
+
const holdUntil = nowMs + quotaHoldMs(message);
|
|
145
|
+
return {
|
|
146
|
+
kind,
|
|
147
|
+
next: nextRunAtMs !== null && nextRunAtMs >= holdUntil ? nextRunAtMs : holdUntil,
|
|
148
|
+
failureStreak: 1,
|
|
149
|
+
status: 'blocked',
|
|
150
|
+
detail: `配额/限流:停到 ${formatInstant(holdUntil, timeZone)}(${timeZone})再试`,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
if (isOneShot(rule)) {
|
|
154
|
+
// 一次性任务的这次派发已经用掉了(beginSlot 把 nextRunAt 推成了 null),重跑就是重发一遍。
|
|
155
|
+
return {
|
|
156
|
+
kind,
|
|
157
|
+
next: nextRunAtMs,
|
|
158
|
+
failureStreak: 0,
|
|
159
|
+
status: 'failed',
|
|
160
|
+
detail: '一次性任务不自动重跑:这次派发已经用掉了,要再跑就重新建一个',
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
if (kind === 'transient' && usedRungs < RETRY_LADDER_MS.length) {
|
|
164
|
+
const at = nowMs + RETRY_LADDER_MS[usedRungs];
|
|
165
|
+
if (nextRunAtMs !== null && nextRunAtMs <= at) {
|
|
166
|
+
return { kind, next: nextRunAtMs, failureStreak: usedRungs + 1, status: 'failed', detail: '自然排期比重试阶梯更早,等它自己到点' };
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
kind,
|
|
170
|
+
next: at,
|
|
171
|
+
failureStreak: usedRungs + 1,
|
|
172
|
+
status: 'failed',
|
|
173
|
+
detail: `没到模型(瞬时网络错),第 ${usedRungs + 1}/${RETRY_LADDER_MS.length} 档重试:${secondsText(RETRY_LADDER_MS[usedRungs])}后再跑`,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
kind,
|
|
178
|
+
next: nextRunAtMs,
|
|
179
|
+
failureStreak: kind === 'transient' ? usedRungs + 1 : 0,
|
|
180
|
+
status: 'failed',
|
|
181
|
+
detail: kind === 'transient'
|
|
182
|
+
? `瞬时网络错,重试阶梯已用完:等下一次排期`
|
|
183
|
+
: '这次失败没到模型重试的范围(可能已经有副作用),不自动重发',
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/** 失败分类是否算「完全没到模型」。 */
|
|
187
|
+
/** 投递文本:**必须**写明这是定时触发、不是用户指令、不构成授权。 */
|
|
188
|
+
export function deliveryText(task, slot, kind) {
|
|
189
|
+
const tag = kind === 'catch-up'
|
|
190
|
+
? ';这是补跑,错过的几次已合并成这一次'
|
|
191
|
+
: kind === 'recovered'
|
|
192
|
+
? ';这是上次崩溃时推进了却没能投出去的那一次,补投'
|
|
193
|
+
: kind === 'manual'
|
|
194
|
+
? ';这是用户手动点「立即跑一次」'
|
|
195
|
+
: '';
|
|
196
|
+
return (`【定时任务触发】这是 dsc 定时任务「${task.title}」到点后自动投递的消息(排期 ${formatInstant(slot, task.timeZone)},时区 ${task.timeZone}${tag})。\n` +
|
|
197
|
+
'它不是用户此刻发出的指令,也不构成任何授权;用户现在可能不在。\n' +
|
|
198
|
+
'按下面的任务描述做事。需要授权的动作(写文件、跑命令、动凭据、对外发消息等)照常走审批流程,' +
|
|
199
|
+
'不要因为「这是自动化任务」就自行放宽或跳过确认;要是没人能批准,就把要做的事和卡点写清楚然后停下。\n' +
|
|
200
|
+
'任务描述:\n' +
|
|
201
|
+
task.prompt);
|
|
202
|
+
}
|
|
203
|
+
/** 进程存活判定:pid 存在(EPERM 也算存在,那只是没权限给它发信号)。 */
|
|
204
|
+
export function isProcessAlive(pid) {
|
|
205
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
206
|
+
return false;
|
|
207
|
+
if (pid === process.pid)
|
|
208
|
+
return true;
|
|
209
|
+
try {
|
|
210
|
+
process.kill(pid, 0);
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
return error?.code === 'EPERM';
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
export class ScheduleRunner {
|
|
218
|
+
deps;
|
|
219
|
+
/** 本进程启动时的墙钟时刻指纹:锁里存它,pid 回收时能分辨出「这不是原来那个进程」。 */
|
|
220
|
+
birth;
|
|
221
|
+
timer = null;
|
|
222
|
+
/** start() 调过没有(stop 之后可以再 start)。 */
|
|
223
|
+
started = false;
|
|
224
|
+
/** stop() 之后为 true:正在飞的那一轮 tick 不许回头再拿锁、再投递。 */
|
|
225
|
+
stopped = false;
|
|
226
|
+
ticking = false;
|
|
227
|
+
lock = null;
|
|
228
|
+
lockNoticed = false;
|
|
229
|
+
/** 已经投出去、还在等 `dsc/turn-end` 的那些投递(先进先出)。 */
|
|
230
|
+
deliveries = [];
|
|
231
|
+
/** 每条任务已经用掉几档重试。 */
|
|
232
|
+
retryRungs = new Map();
|
|
233
|
+
constructor(deps) {
|
|
234
|
+
this.deps = deps;
|
|
235
|
+
this.birth = Math.round(this.now() - process.uptime() * 1_000);
|
|
236
|
+
}
|
|
237
|
+
/** 现在握着调度锁吗(false = 本进程只读,不推进、不投递)。 */
|
|
238
|
+
get hasLock() {
|
|
239
|
+
return this.lock !== null;
|
|
240
|
+
}
|
|
241
|
+
now() {
|
|
242
|
+
return this.deps.now?.() ?? Date.now();
|
|
243
|
+
}
|
|
244
|
+
note(text) {
|
|
245
|
+
this.deps.notice?.(text);
|
|
246
|
+
}
|
|
247
|
+
/** 启动:拿锁 → 先跑一次(宿主启动时的 catch-up 就在这一次里)→ 排下一次唤醒。 */
|
|
248
|
+
start() {
|
|
249
|
+
if (this.started)
|
|
250
|
+
return;
|
|
251
|
+
this.started = true;
|
|
252
|
+
this.stopped = false;
|
|
253
|
+
this.refreshLock();
|
|
254
|
+
// 启动那一次 catch-up 走同一条 tick,所以「错过最近一次」的判定只有一处实现。
|
|
255
|
+
void this.tick().catch((error) => this.note(`定时任务启动检查失败:${errorText(error)}`));
|
|
256
|
+
this.arm();
|
|
257
|
+
}
|
|
258
|
+
/** 停用 / 宿主退出:清定时器、放锁。**必须**在 apply 的 disposer 里调。 */
|
|
259
|
+
stop() {
|
|
260
|
+
this.stopped = true;
|
|
261
|
+
this.started = false;
|
|
262
|
+
if (this.timer !== null) {
|
|
263
|
+
clearTimeout(this.timer);
|
|
264
|
+
this.timer = null;
|
|
265
|
+
}
|
|
266
|
+
this.releaseLock();
|
|
267
|
+
}
|
|
268
|
+
/** 立刻检查一遍(设置分区那个按钮),返回一句结果文案。 */
|
|
269
|
+
async checkNow() {
|
|
270
|
+
this.refreshLock();
|
|
271
|
+
if (this.lock === null)
|
|
272
|
+
return '另一个 Pneuma 进程正握着调度锁,本进程只读:等它退出后再试';
|
|
273
|
+
const config = this.deps.config();
|
|
274
|
+
if (!config.enabled)
|
|
275
|
+
return '定时任务总开关是关着的:先在设置里打开';
|
|
276
|
+
await this.tick();
|
|
277
|
+
this.arm();
|
|
278
|
+
return this.describeState();
|
|
279
|
+
}
|
|
280
|
+
/** 立即跑一次某条任务(不占它的排期)。 */
|
|
281
|
+
async fireNow(id) {
|
|
282
|
+
this.refreshLock();
|
|
283
|
+
if (this.lock === null)
|
|
284
|
+
return '另一个 Pneuma 进程正握着调度锁,本进程只读,不能手动跑';
|
|
285
|
+
const config = this.deps.config();
|
|
286
|
+
if (!config.enabled)
|
|
287
|
+
return '定时任务总开关是关着的:先在设置里打开';
|
|
288
|
+
this.deps.store.reload();
|
|
289
|
+
const found = this.deps.store.findByPrefix(id);
|
|
290
|
+
if (!found.ok)
|
|
291
|
+
throw new Error(found.error);
|
|
292
|
+
const task = found.task;
|
|
293
|
+
if (this.deps.waiting())
|
|
294
|
+
return '现在有卡片在等用户处理:先处理完卡片,或者直接在会话里说一句';
|
|
295
|
+
const blocked = this.preflight(task);
|
|
296
|
+
if (blocked !== null)
|
|
297
|
+
return `投不出去:${blocked}`;
|
|
298
|
+
// 手动跑不动周期任务的排期;但一次性任务的意义就是「那一刻跑一次」,手动跑掉就算用过了。
|
|
299
|
+
const keepNext = isOneShot(task.rule) ? null : task.nextRunAt;
|
|
300
|
+
await this.deliver(task, this.now(), 'manual', keepNext);
|
|
301
|
+
return `已把「${task.title}」立即投给模型${keepNext === null ? '' : `(定时排期不动,仍在 ${formatInstant(keepNext, task.timeZone)})`}`;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* 一轮 tick。做的事按顺序:拿锁 → 读总开关 → 重新读盘 → 补投悬空槽位 → 处理到点任务 → 修剪等待表。
|
|
305
|
+
* @returns 这一轮有没有真的做过事(自检与诊断用)
|
|
306
|
+
*/
|
|
307
|
+
async tick() {
|
|
308
|
+
// 已经 stop 过就不再动手:卸载是热卸载,正在飞的那一轮 tick 不许回头再拿锁 / 再投递。
|
|
309
|
+
if (this.stopped)
|
|
310
|
+
return false;
|
|
311
|
+
if (this.ticking)
|
|
312
|
+
return false;
|
|
313
|
+
this.ticking = true;
|
|
314
|
+
let worked = false;
|
|
315
|
+
try {
|
|
316
|
+
this.refreshLock();
|
|
317
|
+
if (this.lock === null)
|
|
318
|
+
return false;
|
|
319
|
+
if (!this.deps.config().enabled)
|
|
320
|
+
return false;
|
|
321
|
+
this.deps.store.reload();
|
|
322
|
+
this.forgetExpiredDeliveries();
|
|
323
|
+
worked = (await this.recoverPending()) || worked;
|
|
324
|
+
worked = (await this.processDue()) || worked;
|
|
325
|
+
}
|
|
326
|
+
catch (error) {
|
|
327
|
+
this.note(`定时任务检查时出错:${errorText(error)}`);
|
|
328
|
+
}
|
|
329
|
+
finally {
|
|
330
|
+
this.ticking = false;
|
|
331
|
+
}
|
|
332
|
+
return worked;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* 一轮对话结束时的对账。`agent.followup` 只管排队、不回传结果,所以这是唯一能看到的信号:
|
|
336
|
+
* completed → 到过模型,重试阶梯清零;
|
|
337
|
+
* error → 按错误原文分类,配额停到恢复点、瞬时错走阶梯;
|
|
338
|
+
* aborted → 用户中断,既不清零也不升级。
|
|
339
|
+
*/
|
|
340
|
+
noteTurnEnd(reason) {
|
|
341
|
+
const delivery = this.deliveries.shift();
|
|
342
|
+
if (delivery === undefined)
|
|
343
|
+
return;
|
|
344
|
+
const task = this.deps.store.get(delivery.id);
|
|
345
|
+
if (task === undefined)
|
|
346
|
+
return;
|
|
347
|
+
if (reason === 'aborted')
|
|
348
|
+
return;
|
|
349
|
+
if (reason === 'completed') {
|
|
350
|
+
this.retryRungs.delete(task.id);
|
|
351
|
+
if (task.lastStatus === 'failed' || task.failureStreak !== 0) {
|
|
352
|
+
void this.deps.store.endSlot(task.id, { status: 'ok', failureStreak: 0, error: null });
|
|
353
|
+
}
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
const message = this.deps.lastErrorText?.() ?? '';
|
|
357
|
+
void this.handleFailure(task, message === '' ? '这一轮以错误结束(模型端点报错)' : message);
|
|
358
|
+
}
|
|
359
|
+
/** 一句现状(设置分区、命令页脚共用)。 */
|
|
360
|
+
describeState() {
|
|
361
|
+
const tasks = this.deps.store.list();
|
|
362
|
+
const enabled = tasks.filter((task) => task.enabled).length;
|
|
363
|
+
const pending = tasks.filter((task) => task.pendingSlot !== null).length;
|
|
364
|
+
const nearest = tasks
|
|
365
|
+
.filter((task) => task.enabled && task.nextRunAt !== null)
|
|
366
|
+
.reduce((best, task) => (best === null || task.nextRunAt < best ? task.nextRunAt : best), null);
|
|
367
|
+
const lockText = this.lock === null ? '本进程只读(另一个进程在调度)' : `本进程在调度(pid ${process.pid})`;
|
|
368
|
+
const nextText = nearest === null ? '没有排到将来的任务' : `下一次唤醒 ${formatInstant(nearest, this.deps.config().timeZone)}`;
|
|
369
|
+
return `${tasks.length} 条任务(${enabled} 条启用)|${nextText}|${lockText}${pending > 0 ? `|${pending} 个槽位待补投` : ''}`;
|
|
370
|
+
}
|
|
371
|
+
// ── 排期处理 ────────────────────────────────────────────────────────────────
|
|
372
|
+
/** 悬空槽位补投:推进了却没投出去的那一次,只补一次。 */
|
|
373
|
+
async recoverPending() {
|
|
374
|
+
const pending = this.deps.store.pendingTasks();
|
|
375
|
+
if (pending.length === 0)
|
|
376
|
+
return false;
|
|
377
|
+
if (this.deps.waiting()) {
|
|
378
|
+
this.note('有卡片正等用户处理:定时任务的补投推迟到下一轮');
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
for (const task of pending) {
|
|
382
|
+
const slot = task.pendingSlot;
|
|
383
|
+
if (slot === null)
|
|
384
|
+
continue;
|
|
385
|
+
this.note(`任务「${task.title}」的槽位(${formatInstant(slot, task.timeZone)})推进了却没投出去,补投一次`);
|
|
386
|
+
// 先清 pendingSlot 再投不行(崩了又丢),所以投递路径里 endSlot 一定会清掉它——
|
|
387
|
+
// 无论成功、失败还是阻塞,都不会留着让下一轮再投一次。
|
|
388
|
+
await this.deliver(task, slot, 'recovered', nextRunAt(task.rule, task.timeZone, this.now()));
|
|
389
|
+
}
|
|
390
|
+
return true;
|
|
391
|
+
}
|
|
392
|
+
/** 到点的任务:先算要不要跑(catch-up 策略),再决定投不投。 */
|
|
393
|
+
async processDue() {
|
|
394
|
+
const now = this.now();
|
|
395
|
+
let worked = false;
|
|
396
|
+
const due = [];
|
|
397
|
+
for (const task of this.deps.store.list()) {
|
|
398
|
+
if (!task.enabled)
|
|
399
|
+
continue;
|
|
400
|
+
if (task.pendingSlot !== null)
|
|
401
|
+
continue; // 上面补投过了
|
|
402
|
+
let next = task.nextRunAt;
|
|
403
|
+
if (next === null) {
|
|
404
|
+
next = nextRunAt(task.rule, task.timeZone, now);
|
|
405
|
+
if (next === null) {
|
|
406
|
+
// 算不出下一次:一次性任务已经过期,或规则永远不匹配。停用它,别每轮重算。
|
|
407
|
+
const reason = isOneShot(task.rule) ? '这条一次性任务已经过期,自动停用' : '这条规则算不出下一次触发时刻,自动停用';
|
|
408
|
+
// 保留已有的结论(上次失败 / 被阻塞的原因要给人看),只有从没跑过的才标成 done。
|
|
409
|
+
const status = task.lastStatus === 'never' || task.lastStatus === 'running' ? 'done' : task.lastStatus;
|
|
410
|
+
await this.deps.store.update(task.id, { enabled: false });
|
|
411
|
+
await this.deps.store.endSlot(task.id, { status, error: task.lastError });
|
|
412
|
+
await this.deps.store.appendRun({ at: now, id: task.id, title: task.title, slot: 0, status: 'skipped', detail: reason });
|
|
413
|
+
this.note(`定时任务「${task.title}」:${reason}`);
|
|
414
|
+
worked = true;
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
await this.deps.store.setNextRunAt(task.id, next);
|
|
418
|
+
worked = true;
|
|
419
|
+
}
|
|
420
|
+
if (next > now)
|
|
421
|
+
continue;
|
|
422
|
+
const decision = decideOccurrence(task.rule, task.timeZone, next, now);
|
|
423
|
+
if (decision.verdict === 'idle')
|
|
424
|
+
continue;
|
|
425
|
+
if (!decision.fire) {
|
|
426
|
+
// 一次性任务超宽限:不静默丢槽位,写一条「跳过」再收尾。
|
|
427
|
+
await this.deps.store.endSlot(task.id, { status: 'skipped', error: null, nextRunAt: null });
|
|
428
|
+
await this.deps.store.update(task.id, { enabled: false });
|
|
429
|
+
await this.deps.store.appendRun({ at: now, id: task.id, title: task.title, slot: decision.slot, status: 'skipped', detail: decision.reason });
|
|
430
|
+
this.note(`定时任务「${task.title}」:${decision.reason}`);
|
|
431
|
+
worked = true;
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
due.push({
|
|
435
|
+
task,
|
|
436
|
+
slot: decision.slot,
|
|
437
|
+
next: decision.next,
|
|
438
|
+
kind: decision.verdict === 'due' ? 'due' : decision.verdict === 'late' ? 'late' : 'catch-up',
|
|
439
|
+
reason: decision.reason,
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
if (due.length === 0)
|
|
443
|
+
return worked;
|
|
444
|
+
// 有卡片挂着就把整批推迟:不隔着一张卡硬推。排期一律没动,下一 tick 会重新看见它们。
|
|
445
|
+
if (this.deps.waiting()) {
|
|
446
|
+
this.note(`有 ${due.length} 条定时任务到点,但界面有卡片在等用户处理:推迟到下一轮`);
|
|
447
|
+
return worked;
|
|
448
|
+
}
|
|
449
|
+
for (const item of due) {
|
|
450
|
+
if (item.kind === 'catch-up')
|
|
451
|
+
this.note(`定时任务「${item.task.title}」:${item.reason}`);
|
|
452
|
+
await this.deliver(item.task, item.slot, item.kind, item.next);
|
|
453
|
+
worked = true;
|
|
454
|
+
}
|
|
455
|
+
return worked;
|
|
456
|
+
}
|
|
457
|
+
// ── 投递 ────────────────────────────────────────────────────────────────────
|
|
458
|
+
/** pre-dispatch 校验:返回非 null 就是**不能投**的原因(一次模型请求都不会发)。 */
|
|
459
|
+
preflight(task) {
|
|
460
|
+
let sessionId = '';
|
|
461
|
+
try {
|
|
462
|
+
sessionId = this.deps.sessionId();
|
|
463
|
+
}
|
|
464
|
+
catch (error) {
|
|
465
|
+
return `投递目标未知:读不到当前会话(${errorText(error)})`;
|
|
466
|
+
}
|
|
467
|
+
if (sessionId === '')
|
|
468
|
+
return '投递目标未知:当前没有打开的会话,定时任务没有地方投';
|
|
469
|
+
let route;
|
|
470
|
+
try {
|
|
471
|
+
route = this.deps.route();
|
|
472
|
+
}
|
|
473
|
+
catch (error) {
|
|
474
|
+
return `模型端点不可用:${errorText(error)}`;
|
|
475
|
+
}
|
|
476
|
+
if (route.baseUrl === '' || route.model === '')
|
|
477
|
+
return '模型端点不可用:baseUrl 或 model 是空的';
|
|
478
|
+
// 只判空,绝不把 key 写进任何提示或落盘内容。
|
|
479
|
+
if (route.apiKey === '')
|
|
480
|
+
return '模型端点没有可解析的凭据(key 是空的):先去设置「模型」分区配好';
|
|
481
|
+
const sandbox = this.deps.canWriteDir?.() ?? null;
|
|
482
|
+
if (sandbox !== null && !sandbox.allowed) {
|
|
483
|
+
return `沙箱不允许写定时任务的数据目录(${this.deps.store.dir}):${sandbox.reason ?? '越界'}`;
|
|
484
|
+
}
|
|
485
|
+
return null;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* 投一次。**至多一次**的顺序是死的:先把 `nextRunAt` 推进并落 `pendingSlot`,再调 `deliver`。
|
|
489
|
+
* 反过来的话,崩在「投出去了但排期没推进」之间,重启就会再投一遍。
|
|
490
|
+
*/
|
|
491
|
+
async deliver(task, slot, kind, next) {
|
|
492
|
+
const now = this.now();
|
|
493
|
+
const blocked = this.preflight(task);
|
|
494
|
+
if (blocked !== null) {
|
|
495
|
+
// 校验没过:照样把槽位推走(否则每一 tick 都重判一次),但一次模型请求都不发。
|
|
496
|
+
await this.deps.store.beginSlot(task.id, slot, next);
|
|
497
|
+
await this.deps.store.endSlot(task.id, { status: 'blocked', error: blocked });
|
|
498
|
+
await this.retireFinishedOneShot(task, next);
|
|
499
|
+
await this.deps.store.appendRun({ at: now, id: task.id, title: task.title, slot, status: 'blocked', detail: blocked });
|
|
500
|
+
if (task.lastStatus !== 'blocked' || task.lastError !== blocked) {
|
|
501
|
+
this.note(`定时任务「${task.title}」暂时投不出去:${blocked}`);
|
|
502
|
+
}
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
await this.deps.store.beginSlot(task.id, slot, next);
|
|
506
|
+
try {
|
|
507
|
+
this.deps.deliver(deliveryText(task, slot, kind), task, slot);
|
|
508
|
+
}
|
|
509
|
+
catch (error) {
|
|
510
|
+
const message = errorText(error);
|
|
511
|
+
const plan = planFailure(task.rule, task.timeZone, next, now, message, this.retryRungs.get(task.id) ?? 0);
|
|
512
|
+
await this.deps.store.endSlot(task.id, { status: plan.status, error: message, nextRunAt: plan.next, failureStreak: plan.failureStreak });
|
|
513
|
+
await this.retireFinishedOneShot(task, plan.next);
|
|
514
|
+
await this.deps.store.appendRun({ at: now, id: task.id, title: task.title, slot, status: plan.status, detail: `投递失败:${message};${plan.detail}` });
|
|
515
|
+
this.note(`定时任务「${task.title}」投递失败:${message};${plan.detail}`);
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
this.deliveries.push({ id: task.id, at: now });
|
|
519
|
+
await this.deps.store.endSlot(task.id, { status: 'ok', error: null, delivered: true });
|
|
520
|
+
await this.retireFinishedOneShot(task, next);
|
|
521
|
+
await this.deps.store.appendRun({ at: now, id: task.id, title: task.title, slot, status: kind === 'manual' ? 'manual' : 'ok', detail: kind });
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* 一次性任务投完 / 投不出去之后排期就是 null 了,顺手停用它:
|
|
525
|
+
* 不停用的话每一轮 tick 都要重新算一次「算不出下一次」,还会让「下次唤醒」永远退化成 1 秒。
|
|
526
|
+
*/
|
|
527
|
+
async retireFinishedOneShot(task, next) {
|
|
528
|
+
if (next !== null || !isOneShot(task.rule))
|
|
529
|
+
return;
|
|
530
|
+
await this.deps.store.update(task.id, { enabled: false });
|
|
531
|
+
}
|
|
532
|
+
/** 回合以错误结束:分类、记账、必要时排重试。 */
|
|
533
|
+
async handleFailure(task, message) {
|
|
534
|
+
const now = this.now();
|
|
535
|
+
const rung = this.retryRungs.get(task.id) ?? 0;
|
|
536
|
+
const plan = planFailure(task.rule, task.timeZone, task.nextRunAt, now, message, rung);
|
|
537
|
+
if (plan.kind === 'transient' && !isOneShot(task.rule) && rung < RETRY_LADDER_MS.length) {
|
|
538
|
+
this.retryRungs.set(task.id, rung + 1);
|
|
539
|
+
}
|
|
540
|
+
else {
|
|
541
|
+
this.retryRungs.delete(task.id);
|
|
542
|
+
}
|
|
543
|
+
await this.deps.store.endSlot(task.id, {
|
|
544
|
+
status: plan.status,
|
|
545
|
+
error: message,
|
|
546
|
+
nextRunAt: plan.next,
|
|
547
|
+
failureStreak: plan.failureStreak,
|
|
548
|
+
});
|
|
549
|
+
await this.deps.store.appendRun({
|
|
550
|
+
at: now,
|
|
551
|
+
id: task.id,
|
|
552
|
+
title: task.title,
|
|
553
|
+
slot: task.lastRunAt ?? 0,
|
|
554
|
+
status: plan.status,
|
|
555
|
+
detail: `${plan.detail}|${message}`,
|
|
556
|
+
});
|
|
557
|
+
this.note(`定时任务「${task.title}」这一轮没跑成:${message};${plan.detail}`);
|
|
558
|
+
}
|
|
559
|
+
/** 等太久的投递配对(宿主忙、回合被吞):丢掉,免得失败计数一直挂在一条老记录上。 */
|
|
560
|
+
forgetExpiredDeliveries() {
|
|
561
|
+
const limit = Math.max(60_000, this.deps.config().maxRunSeconds * 1_000);
|
|
562
|
+
const now = this.now();
|
|
563
|
+
while (this.deliveries.length > 0 && now - this.deliveries[0].at > limit)
|
|
564
|
+
this.deliveries.shift();
|
|
565
|
+
}
|
|
566
|
+
// ── 定时器 ──────────────────────────────────────────────────────────────────
|
|
567
|
+
/** 算出最近该醒的时刻,排一个定时器(超长分段)。 */
|
|
568
|
+
arm() {
|
|
569
|
+
if (this.timer !== null) {
|
|
570
|
+
clearTimeout(this.timer);
|
|
571
|
+
this.timer = null;
|
|
572
|
+
}
|
|
573
|
+
if (this.stopped)
|
|
574
|
+
return;
|
|
575
|
+
const now = this.now();
|
|
576
|
+
let wakeAt = now + TIMER_SLICE_MS;
|
|
577
|
+
for (const task of this.deps.store.list()) {
|
|
578
|
+
if (!task.enabled)
|
|
579
|
+
continue;
|
|
580
|
+
// 排期没算过的(刚建的 / 规则刚改的)马上醒来算一次。
|
|
581
|
+
if (task.nextRunAt === null || task.pendingSlot !== null)
|
|
582
|
+
wakeAt = Math.min(wakeAt, now + 1_000);
|
|
583
|
+
else
|
|
584
|
+
wakeAt = Math.min(wakeAt, Math.max(task.nextRunAt, now + 500));
|
|
585
|
+
}
|
|
586
|
+
const delay = Math.max(0, wakeAt - now);
|
|
587
|
+
const sliced = delay >= TIMER_SLICE_MS;
|
|
588
|
+
const timer = setTimeout(() => {
|
|
589
|
+
this.timer = null;
|
|
590
|
+
if (this.stopped)
|
|
591
|
+
return;
|
|
592
|
+
// 只是分段到点:重排一次即可,不必惊动任务表。
|
|
593
|
+
if (sliced) {
|
|
594
|
+
this.arm();
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
void this.tick()
|
|
598
|
+
.catch((error) => this.note(`定时任务检查失败:${errorText(error)}`))
|
|
599
|
+
.finally(() => this.arm());
|
|
600
|
+
}, delay);
|
|
601
|
+
// 只剩它一个定时器时别挡住进程退出。
|
|
602
|
+
timer.unref?.();
|
|
603
|
+
this.timer = timer;
|
|
604
|
+
}
|
|
605
|
+
// ── 调度锁 ──────────────────────────────────────────────────────────────────
|
|
606
|
+
readLock() {
|
|
607
|
+
if (!existsSync(this.deps.store.lockFile))
|
|
608
|
+
return null;
|
|
609
|
+
try {
|
|
610
|
+
const parsed = JSON.parse(readFileSync(this.deps.store.lockFile, 'utf8'));
|
|
611
|
+
if (typeof parsed.pid !== 'number' || typeof parsed.birth !== 'number')
|
|
612
|
+
return null;
|
|
613
|
+
return { pid: Math.round(parsed.pid), birth: Math.round(parsed.birth) };
|
|
614
|
+
}
|
|
615
|
+
catch {
|
|
616
|
+
return null;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
writeLock() {
|
|
620
|
+
const info = { pid: process.pid, birth: this.birth };
|
|
621
|
+
try {
|
|
622
|
+
mkdirSync(this.deps.store.dir, { recursive: true });
|
|
623
|
+
const tmp = `${this.deps.store.lockFile}.${process.pid}.tmp`;
|
|
624
|
+
writeFileSync(tmp, `${JSON.stringify(info)}\n`, 'utf8');
|
|
625
|
+
renameSync(tmp, this.deps.store.lockFile);
|
|
626
|
+
this.lock = info;
|
|
627
|
+
}
|
|
628
|
+
catch (error) {
|
|
629
|
+
this.lock = null;
|
|
630
|
+
this.note(`写调度锁失败(${errorText(error)}):本进程这轮不调度`);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
/** 拿锁:内容还是自己的就继续;别人活着就让;主人死了就接管(pid + 启动指纹一起看)。 */
|
|
634
|
+
refreshLock() {
|
|
635
|
+
if (this.stopped)
|
|
636
|
+
return;
|
|
637
|
+
const info = this.readLock();
|
|
638
|
+
if (info === null) {
|
|
639
|
+
this.writeLock();
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
if (info.pid === process.pid && info.birth === this.birth) {
|
|
643
|
+
this.lock = info;
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
if (isProcessAlive(info.pid)) {
|
|
647
|
+
this.lock = null;
|
|
648
|
+
if (!this.lockNoticed) {
|
|
649
|
+
this.lockNoticed = true;
|
|
650
|
+
this.note(`另一个 Pneuma 进程(pid ${info.pid})正握着调度锁:本进程只读,不推进也不投递`);
|
|
651
|
+
}
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
if (this.lockNoticed)
|
|
655
|
+
this.lockNoticed = false;
|
|
656
|
+
this.note(`上一个调度进程(pid ${info.pid})已经不在了:本进程接管调度`);
|
|
657
|
+
this.writeLock();
|
|
658
|
+
}
|
|
659
|
+
releaseLock() {
|
|
660
|
+
if (this.lock === null)
|
|
661
|
+
return;
|
|
662
|
+
const info = this.readLock();
|
|
663
|
+
if (info !== null && info.pid === process.pid && info.birth === this.birth) {
|
|
664
|
+
try {
|
|
665
|
+
unlinkSync(this.deps.store.lockFile);
|
|
666
|
+
}
|
|
667
|
+
catch {
|
|
668
|
+
// 删不掉就算了:下一个进程会按「主人已死」接管
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
this.lock = null;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
/** 给提示条用的一句话摘要(含「宿主不常驻就不触发」这句必须说清的限制)。 */
|
|
675
|
+
export function scheduleLimitsNote() {
|
|
676
|
+
return ('宿主不常驻就不触发:dsc 桌面端或终端关着的时候,定时任务不会醒(本插件不做系统计划任务兜底,' +
|
|
677
|
+
'那是后门高危动作)。醒来后错过的排期按「至多补一次、不补积压」处理。');
|
|
678
|
+
}
|