@xyit/wellspring 0.0.0-stage → 1.1.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 +853 -2
- package/dist/agent/pending-asks.d.ts +20 -0
- package/dist/agent/pending-asks.js +70 -0
- package/dist/agent/pending-asks.js.map +1 -0
- package/dist/agent/task-registry.d.ts +14 -0
- package/dist/agent/task-registry.js +80 -0
- package/dist/agent/task-registry.js.map +1 -0
- package/dist/agent/tool-context.d.ts +30 -0
- package/dist/agent/tool-context.js +10 -0
- package/dist/agent/tool-context.js.map +1 -0
- package/dist/agent/usage.d.ts +40 -0
- package/dist/agent/usage.js +122 -0
- package/dist/agent/usage.js.map +1 -0
- package/dist/api/host/agent.d.ts +165 -0
- package/dist/api/host/agent.js +5 -0
- package/dist/api/host/agent.js.map +1 -0
- package/dist/api/host/events.d.ts +2 -0
- package/dist/api/host/events.js +6 -0
- package/dist/api/host/events.js.map +1 -0
- package/dist/api/host/exec.d.ts +36 -0
- package/dist/api/host/exec.js +10 -0
- package/dist/api/host/exec.js.map +1 -0
- package/dist/api/host/fs.d.ts +24 -0
- package/dist/api/host/fs.js +7 -0
- package/dist/api/host/fs.js.map +1 -0
- package/dist/api/host/hooks.d.ts +210 -0
- package/dist/api/host/hooks.js +401 -0
- package/dist/api/host/hooks.js.map +1 -0
- package/dist/api/host/host.d.ts +36 -0
- package/dist/api/host/host.js +53 -0
- package/dist/api/host/host.js.map +1 -0
- package/dist/api/host/http.d.ts +58 -0
- package/dist/api/host/http.js +6 -0
- package/dist/api/host/http.js.map +1 -0
- package/dist/api/host/index.d.ts +15 -0
- package/dist/api/host/index.js +20 -0
- package/dist/api/host/index.js.map +1 -0
- package/dist/api/host/models.d.ts +65 -0
- package/dist/api/host/models.js +8 -0
- package/dist/api/host/models.js.map +1 -0
- package/dist/api/host/network.d.ts +22 -0
- package/dist/api/host/network.js +7 -0
- package/dist/api/host/network.js.map +1 -0
- package/dist/api/host/plugin.d.ts +138 -0
- package/dist/api/host/plugin.js +6 -0
- package/dist/api/host/plugin.js.map +1 -0
- package/dist/api/host/plugins.d.ts +49 -0
- package/dist/api/host/plugins.js +6 -0
- package/dist/api/host/plugins.js.map +1 -0
- package/dist/api/host/pty.d.ts +55 -0
- package/dist/api/host/pty.js +21 -0
- package/dist/api/host/pty.js.map +1 -0
- package/dist/api/host/session.d.ts +5 -0
- package/dist/api/host/session.js +52 -0
- package/dist/api/host/session.js.map +1 -0
- package/dist/api/host/version.d.ts +2 -0
- package/dist/api/host/version.js +3 -0
- package/dist/api/host/version.js.map +1 -0
- package/dist/api/host/workspace.d.ts +38 -0
- package/dist/api/host/workspace.js +9 -0
- package/dist/api/host/workspace.js.map +1 -0
- package/dist/api/plugin/http-client.d.ts +42 -0
- package/dist/api/plugin/http-client.js +364 -0
- package/dist/api/plugin/http-client.js.map +1 -0
- package/dist/api/plugin/http-protocol.d.ts +152 -0
- package/dist/api/plugin/http-protocol.js +49 -0
- package/dist/api/plugin/http-protocol.js.map +1 -0
- package/dist/api/result/result.d.ts +16 -0
- package/dist/api/result/result.js +43 -0
- package/dist/api/result/result.js.map +1 -0
- package/dist/commands/agent-turn.d.ts +63 -0
- package/dist/commands/agent-turn.js +687 -0
- package/dist/commands/agent-turn.js.map +1 -0
- package/dist/commands/ask-prompt.d.ts +6 -0
- package/dist/commands/ask-prompt.js +49 -0
- package/dist/commands/ask-prompt.js.map +1 -0
- package/dist/commands/config.d.ts +2 -0
- package/dist/commands/config.js +283 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/conversation.d.ts +51 -0
- package/dist/commands/conversation.js +630 -0
- package/dist/commands/conversation.js.map +1 -0
- package/dist/commands/doctor.d.ts +2 -0
- package/dist/commands/doctor.js +77 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/exec-approval.d.ts +3 -0
- package/dist/commands/exec-approval.js +80 -0
- package/dist/commands/exec-approval.js.map +1 -0
- package/dist/commands/help.d.ts +2 -0
- package/dist/commands/help.js +35 -0
- package/dist/commands/help.js.map +1 -0
- package/dist/commands/key.d.ts +2 -0
- package/dist/commands/key.js +226 -0
- package/dist/commands/key.js.map +1 -0
- package/dist/commands/plugin.d.ts +2 -0
- package/dist/commands/plugin.js +190 -0
- package/dist/commands/plugin.js.map +1 -0
- package/dist/commands/session.d.ts +2 -0
- package/dist/commands/session.js +167 -0
- package/dist/commands/session.js.map +1 -0
- package/dist/commands/shared.d.ts +35 -0
- package/dist/commands/shared.js +66 -0
- package/dist/commands/shared.js.map +1 -0
- package/dist/commands/start.d.ts +2 -0
- package/dist/commands/start.js +75 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/commands/stop.d.ts +2 -0
- package/dist/commands/stop.js +24 -0
- package/dist/commands/stop.js.map +1 -0
- package/dist/commands/version.d.ts +2 -0
- package/dist/commands/version.js +33 -0
- package/dist/commands/version.js.map +1 -0
- package/dist/config/codes.d.ts +13 -0
- package/dist/config/codes.js +15 -0
- package/dist/config/codes.js.map +1 -0
- package/dist/config/credentials.d.ts +67 -0
- package/dist/config/credentials.js +214 -0
- package/dist/config/credentials.js.map +1 -0
- package/dist/config/defaults.d.ts +5 -0
- package/dist/config/defaults.js +31 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.js +10 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/loader.d.ts +10 -0
- package/dist/config/loader.js +68 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/providers.d.ts +30 -0
- package/dist/config/providers.js +97 -0
- package/dist/config/providers.js.map +1 -0
- package/dist/config/types.d.ts +75 -0
- package/dist/config/types.js +4 -0
- package/dist/config/types.js.map +1 -0
- package/dist/config/validate.d.ts +4 -0
- package/dist/config/validate.js +391 -0
- package/dist/config/validate.js.map +1 -0
- package/dist/display/markdown.d.ts +7 -0
- package/dist/display/markdown.js +116 -0
- package/dist/display/markdown.js.map +1 -0
- package/dist/display/tool-label.d.ts +6 -0
- package/dist/display/tool-label.js +81 -0
- package/dist/display/tool-label.js.map +1 -0
- package/dist/event/event.d.ts +27 -0
- package/dist/event/event.js +152 -0
- package/dist/event/event.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +308 -0
- package/dist/index.js.map +1 -0
- package/dist/input/codes.d.ts +15 -0
- package/dist/input/codes.js +20 -0
- package/dist/input/codes.js.map +1 -0
- package/dist/input/commands.d.ts +10 -0
- package/dist/input/commands.js +65 -0
- package/dist/input/commands.js.map +1 -0
- package/dist/input/help.d.ts +8 -0
- package/dist/input/help.js +51 -0
- package/dist/input/help.js.map +1 -0
- package/dist/input/index.d.ts +6 -0
- package/dist/input/index.js +10 -0
- package/dist/input/index.js.map +1 -0
- package/dist/input/parse-options.d.ts +11 -0
- package/dist/input/parse-options.js +51 -0
- package/dist/input/parse-options.js.map +1 -0
- package/dist/input/parse.d.ts +3 -0
- package/dist/input/parse.js +119 -0
- package/dist/input/parse.js.map +1 -0
- package/dist/input/types.d.ts +17 -0
- package/dist/input/types.js +2 -0
- package/dist/input/types.js.map +1 -0
- package/dist/logger/elog4js.d.ts +65 -0
- package/dist/logger/elog4js.js +305 -0
- package/dist/logger/elog4js.js.map +1 -0
- package/dist/logger/logger.d.ts +37 -0
- package/dist/logger/logger.js +196 -0
- package/dist/logger/logger.js.map +1 -0
- package/dist/network/index.d.ts +2 -0
- package/dist/network/index.js +6 -0
- package/dist/network/index.js.map +1 -0
- package/dist/network/openai.d.ts +117 -0
- package/dist/network/openai.js +443 -0
- package/dist/network/openai.js.map +1 -0
- package/dist/network/proxy.d.ts +9 -0
- package/dist/network/proxy.js +72 -0
- package/dist/network/proxy.js.map +1 -0
- package/dist/network/web.d.ts +34 -0
- package/dist/network/web.js +152 -0
- package/dist/network/web.js.map +1 -0
- package/dist/platform/clipboard.d.ts +15 -0
- package/dist/platform/clipboard.js +82 -0
- package/dist/platform/clipboard.js.map +1 -0
- package/dist/platform/exec.d.ts +28 -0
- package/dist/platform/exec.js +95 -0
- package/dist/platform/exec.js.map +1 -0
- package/dist/platform/file.d.ts +38 -0
- package/dist/platform/file.js +197 -0
- package/dist/platform/file.js.map +1 -0
- package/dist/platform/index.d.ts +7 -0
- package/dist/platform/index.js +12 -0
- package/dist/platform/index.js.map +1 -0
- package/dist/platform/notification.d.ts +14 -0
- package/dist/platform/notification.js +82 -0
- package/dist/platform/notification.js.map +1 -0
- package/dist/platform/open-external.d.ts +10 -0
- package/dist/platform/open-external.js +105 -0
- package/dist/platform/open-external.js.map +1 -0
- package/dist/platform/os.d.ts +20 -0
- package/dist/platform/os.js +86 -0
- package/dist/platform/os.js.map +1 -0
- package/dist/platform/path.d.ts +32 -0
- package/dist/platform/path.js +154 -0
- package/dist/platform/path.js.map +1 -0
- package/dist/plugin/access-guard.d.ts +1 -0
- package/dist/plugin/access-guard.js +40 -0
- package/dist/plugin/access-guard.js.map +1 -0
- package/dist/plugin/agent-service.d.ts +25 -0
- package/dist/plugin/agent-service.js +809 -0
- package/dist/plugin/agent-service.js.map +1 -0
- package/dist/plugin/agent-tools.d.ts +12 -0
- package/dist/plugin/agent-tools.js +31 -0
- package/dist/plugin/agent-tools.js.map +1 -0
- package/dist/plugin/capabilities.d.ts +26 -0
- package/dist/plugin/capabilities.js +192 -0
- package/dist/plugin/capabilities.js.map +1 -0
- package/dist/plugin/console-guard.d.ts +2 -0
- package/dist/plugin/console-guard.js +52 -0
- package/dist/plugin/console-guard.js.map +1 -0
- package/dist/plugin/data-access.d.ts +15 -0
- package/dist/plugin/data-access.js +57 -0
- package/dist/plugin/data-access.js.map +1 -0
- package/dist/plugin/fs.d.ts +3 -0
- package/dist/plugin/fs.js +93 -0
- package/dist/plugin/fs.js.map +1 -0
- package/dist/plugin/host-alias.d.ts +2 -0
- package/dist/plugin/host-alias.js +57 -0
- package/dist/plugin/host-alias.js.map +1 -0
- package/dist/plugin/index.d.ts +7 -0
- package/dist/plugin/index.js +11 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/install.d.ts +17 -0
- package/dist/plugin/install.js +163 -0
- package/dist/plugin/install.js.map +1 -0
- package/dist/plugin/loader.d.ts +45 -0
- package/dist/plugin/loader.js +739 -0
- package/dist/plugin/loader.js.map +1 -0
- package/dist/plugin/manage.d.ts +31 -0
- package/dist/plugin/manage.js +271 -0
- package/dist/plugin/manage.js.map +1 -0
- package/dist/plugin/models-service.d.ts +15 -0
- package/dist/plugin/models-service.js +317 -0
- package/dist/plugin/models-service.js.map +1 -0
- package/dist/plugin/network-service.d.ts +10 -0
- package/dist/plugin/network-service.js +87 -0
- package/dist/plugin/network-service.js.map +1 -0
- package/dist/plugin/package-manager.d.ts +46 -0
- package/dist/plugin/package-manager.js +148 -0
- package/dist/plugin/package-manager.js.map +1 -0
- package/dist/plugin/paths.d.ts +6 -0
- package/dist/plugin/paths.js +15 -0
- package/dist/plugin/paths.js.map +1 -0
- package/dist/plugin/registry.d.ts +17 -0
- package/dist/plugin/registry.js +82 -0
- package/dist/plugin/registry.js.map +1 -0
- package/dist/plugin/runtime.d.ts +9 -0
- package/dist/plugin/runtime.js +43 -0
- package/dist/plugin/runtime.js.map +1 -0
- package/dist/plugin/scaffold.d.ts +13 -0
- package/dist/plugin/scaffold.js +132 -0
- package/dist/plugin/scaffold.js.map +1 -0
- package/dist/plugin/state.d.ts +6 -0
- package/dist/plugin/state.js +38 -0
- package/dist/plugin/state.js.map +1 -0
- package/dist/plugin/zip.d.ts +7 -0
- package/dist/plugin/zip.js +138 -0
- package/dist/plugin/zip.js.map +1 -0
- package/dist/sandbox/audit.d.ts +12 -0
- package/dist/sandbox/audit.js +20 -0
- package/dist/sandbox/audit.js.map +1 -0
- package/dist/sandbox/backends/bwrap.d.ts +28 -0
- package/dist/sandbox/backends/bwrap.js +197 -0
- package/dist/sandbox/backends/bwrap.js.map +1 -0
- package/dist/sandbox/backends/direct.d.ts +7 -0
- package/dist/sandbox/backends/direct.js +32 -0
- package/dist/sandbox/backends/direct.js.map +1 -0
- package/dist/sandbox/bridge-state.d.ts +13 -0
- package/dist/sandbox/bridge-state.js +12 -0
- package/dist/sandbox/bridge-state.js.map +1 -0
- package/dist/sandbox/index.d.ts +5 -0
- package/dist/sandbox/index.js +6 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/sandbox/manager.d.ts +8 -0
- package/dist/sandbox/manager.js +325 -0
- package/dist/sandbox/manager.js.map +1 -0
- package/dist/sandbox/memory-limit.d.ts +44 -0
- package/dist/sandbox/memory-limit.js +193 -0
- package/dist/sandbox/memory-limit.js.map +1 -0
- package/dist/sandbox/plugin-client.d.ts +80 -0
- package/dist/sandbox/plugin-client.js +1601 -0
- package/dist/sandbox/plugin-client.js.map +1 -0
- package/dist/sandbox/plugin-host.d.ts +1 -0
- package/dist/sandbox/plugin-host.js +1001 -0
- package/dist/sandbox/plugin-host.js.map +1 -0
- package/dist/sandbox/protocol.d.ts +43 -0
- package/dist/sandbox/protocol.js +96 -0
- package/dist/sandbox/protocol.js.map +1 -0
- package/dist/sandbox/rpc-timeouts.d.ts +28 -0
- package/dist/sandbox/rpc-timeouts.js +15 -0
- package/dist/sandbox/rpc-timeouts.js.map +1 -0
- package/dist/sandbox/supervisor.d.ts +31 -0
- package/dist/sandbox/supervisor.js +114 -0
- package/dist/sandbox/supervisor.js.map +1 -0
- package/dist/sandbox/types.d.ts +124 -0
- package/dist/sandbox/types.js +17 -0
- package/dist/sandbox/types.js.map +1 -0
- package/dist/service/control.d.ts +32 -0
- package/dist/service/control.js +117 -0
- package/dist/service/control.js.map +1 -0
- package/dist/session/compress.d.ts +3 -0
- package/dist/session/compress.js +42 -0
- package/dist/session/compress.js.map +1 -0
- package/dist/session/index.d.ts +4 -0
- package/dist/session/index.js +8 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/registry.d.ts +4 -0
- package/dist/session/registry.js +12 -0
- package/dist/session/registry.js.map +1 -0
- package/dist/session/replay.d.ts +10 -0
- package/dist/session/replay.js +109 -0
- package/dist/session/replay.js.map +1 -0
- package/dist/session/session.d.ts +40 -0
- package/dist/session/session.js +108 -0
- package/dist/session/session.js.map +1 -0
- package/dist/session/store.d.ts +58 -0
- package/dist/session/store.js +382 -0
- package/dist/session/store.js.map +1 -0
- package/dist/session/types.d.ts +56 -0
- package/dist/session/types.js +3 -0
- package/dist/session/types.js.map +1 -0
- package/dist/workspace/index.d.ts +7 -0
- package/dist/workspace/index.js +17 -0
- package/dist/workspace/index.js.map +1 -0
- package/dist/workspace/registry.d.ts +25 -0
- package/dist/workspace/registry.js +293 -0
- package/dist/workspace/registry.js.map +1 -0
- package/package.json +73 -5
- package/scripts/build-node-pty.mjs +55 -0
- package/scripts/rewrite-dts.mjs +36 -0
- package/scripts/run-tests.mjs +41 -0
- package/scripts/verify-sandbox.ts +98 -0
- package/src/agent/pending-asks.ts +88 -0
- package/src/agent/task-registry.ts +108 -0
- package/src/agent/tool-context.ts +47 -0
- package/src/agent/usage.ts +170 -0
- package/src/api/host/agent.ts +162 -0
- package/src/api/host/events.ts +7 -0
- package/src/api/host/exec.ts +47 -0
- package/src/api/host/fs.ts +33 -0
- package/src/api/host/hooks.ts +635 -0
- package/src/api/host/host.ts +99 -0
- package/src/api/host/http.ts +79 -0
- package/src/api/host/index.ts +20 -0
- package/src/api/host/models.ts +81 -0
- package/src/api/host/network.ts +32 -0
- package/src/api/host/plugin.ts +158 -0
- package/src/api/host/plugins.ts +59 -0
- package/src/api/host/pty.ts +73 -0
- package/src/api/host/session.ts +61 -0
- package/src/api/host/version.ts +2 -0
- package/src/api/host/workspace.ts +51 -0
- package/src/api/plugin/http-client.ts +492 -0
- package/src/api/plugin/http-protocol.ts +231 -0
- package/src/api/result/result.ts +52 -0
- package/src/commands/agent-turn.ts +817 -0
- package/src/commands/ask-prompt.ts +52 -0
- package/src/commands/config.ts +306 -0
- package/src/commands/conversation.ts +777 -0
- package/src/commands/doctor.ts +92 -0
- package/src/commands/exec-approval.ts +91 -0
- package/src/commands/help.ts +41 -0
- package/src/commands/key.ts +281 -0
- package/src/commands/plugin.ts +222 -0
- package/src/commands/session.ts +179 -0
- package/src/commands/shared.ts +103 -0
- package/src/commands/start.ts +88 -0
- package/src/commands/stop.ts +24 -0
- package/src/commands/version.ts +40 -0
- package/src/config/codes.ts +17 -0
- package/src/config/credentials.ts +302 -0
- package/src/config/defaults.ts +32 -0
- package/src/config/index.ts +10 -0
- package/src/config/loader.ts +80 -0
- package/src/config/providers.ts +133 -0
- package/src/config/types.ts +88 -0
- package/src/config/validate.ts +458 -0
- package/src/display/markdown.ts +137 -0
- package/src/display/tool-label.ts +87 -0
- package/src/event/event.ts +171 -0
- package/src/index.ts +344 -0
- package/src/input/codes.ts +21 -0
- package/src/input/commands.ts +76 -0
- package/src/input/help.ts +60 -0
- package/src/input/index.ts +10 -0
- package/src/input/parse-options.ts +66 -0
- package/src/input/parse.ts +138 -0
- package/src/input/types.ts +19 -0
- package/src/logger/elog4js.ts +366 -0
- package/src/logger/logger.ts +251 -0
- package/src/network/index.ts +6 -0
- package/src/network/openai.ts +571 -0
- package/src/network/proxy.ts +80 -0
- package/src/network/web.ts +206 -0
- package/src/platform/clipboard.ts +107 -0
- package/src/platform/exec.ts +128 -0
- package/src/platform/file.ts +235 -0
- package/src/platform/index.ts +12 -0
- package/src/platform/notification.ts +108 -0
- package/src/platform/open-external.ts +132 -0
- package/src/platform/os.ts +101 -0
- package/src/platform/path.ts +214 -0
- package/src/plugin/access-guard.ts +46 -0
- package/src/plugin/agent-service.ts +969 -0
- package/src/plugin/agent-tools.ts +43 -0
- package/src/plugin/capabilities.ts +240 -0
- package/src/plugin/console-guard.ts +66 -0
- package/src/plugin/data-access.ts +70 -0
- package/src/plugin/fs.ts +109 -0
- package/src/plugin/host-alias.ts +61 -0
- package/src/plugin/index.ts +11 -0
- package/src/plugin/install.ts +213 -0
- package/src/plugin/loader.ts +952 -0
- package/src/plugin/manage.ts +338 -0
- package/src/plugin/models-service.ts +383 -0
- package/src/plugin/network-service.ts +102 -0
- package/src/plugin/package-manager.ts +214 -0
- package/src/plugin/paths.ts +19 -0
- package/src/plugin/registry.ts +103 -0
- package/src/plugin/runtime.ts +57 -0
- package/src/plugin/scaffold.ts +158 -0
- package/src/plugin/state.ts +52 -0
- package/src/plugin/zip.ts +156 -0
- package/src/sandbox/audit.ts +38 -0
- package/src/sandbox/backends/bwrap.ts +251 -0
- package/src/sandbox/backends/direct.ts +43 -0
- package/src/sandbox/bridge-state.ts +29 -0
- package/src/sandbox/index.ts +5 -0
- package/src/sandbox/manager.ts +406 -0
- package/src/sandbox/memory-limit.ts +245 -0
- package/src/sandbox/plugin-client.ts +1881 -0
- package/src/sandbox/plugin-host.ts +1282 -0
- package/src/sandbox/protocol.ts +142 -0
- package/src/sandbox/pty-bridge.py +154 -0
- package/src/sandbox/rpc-timeouts.ts +43 -0
- package/src/sandbox/supervisor.ts +172 -0
- package/src/sandbox/types.ts +149 -0
- package/src/service/control.ts +155 -0
- package/src/session/compress.ts +47 -0
- package/src/session/index.ts +8 -0
- package/src/session/registry.ts +17 -0
- package/src/session/replay.ts +132 -0
- package/src/session/session.ts +134 -0
- package/src/session/store.ts +468 -0
- package/src/session/types.ts +61 -0
- package/src/workspace/index.ts +21 -0
- package/src/workspace/registry.ts +356 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* 帮助文本生成。内置命令来自命令表,插件命令来自注册表。
|
|
3
|
+
*/
|
|
4
|
+
import { BUILTIN_COMMANDS, findBuiltin } from "./commands.js";
|
|
5
|
+
export function formatGlobalHelp(pluginCommands) {
|
|
6
|
+
const lines = [];
|
|
7
|
+
lines.push("Wellspring 源泉 —— 聚合式 Agent 平台");
|
|
8
|
+
lines.push("");
|
|
9
|
+
lines.push("用法:wellspring <command> [args] [options]");
|
|
10
|
+
lines.push("");
|
|
11
|
+
lines.push("命令:");
|
|
12
|
+
for (const spec of BUILTIN_COMMANDS) {
|
|
13
|
+
lines.push(` ${spec.name.padEnd(9)} ${spec.summary}`);
|
|
14
|
+
}
|
|
15
|
+
if (pluginCommands.length > 0) {
|
|
16
|
+
lines.push("");
|
|
17
|
+
lines.push("插件命令:");
|
|
18
|
+
for (const command of pluginCommands) {
|
|
19
|
+
lines.push(` ${command.name.padEnd(9)} ${command.summary}(来自 ${command.plugin})`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
lines.push("");
|
|
23
|
+
lines.push("全局参数:");
|
|
24
|
+
lines.push(" -c, --config <file> 指定配置文件");
|
|
25
|
+
lines.push(" --home <dir> 便携模式根目录");
|
|
26
|
+
lines.push(" -l, --log-level <level> 日志级别");
|
|
27
|
+
lines.push(" --json 机器可读输出");
|
|
28
|
+
lines.push(" -q, --quiet 静默");
|
|
29
|
+
lines.push(" -h, --help 帮助");
|
|
30
|
+
lines.push(" -v, --version 版本");
|
|
31
|
+
lines.push("");
|
|
32
|
+
lines.push('示例:wellspring chat "解释一下 EventBus"');
|
|
33
|
+
lines.push(' wellspring run --session-id 20261021-173000-ab12 "读取 package.json"');
|
|
34
|
+
return lines.join("\n");
|
|
35
|
+
}
|
|
36
|
+
export function formatCommandHelp(name, pluginCommand) {
|
|
37
|
+
const spec = findBuiltin(name);
|
|
38
|
+
if (spec !== undefined) {
|
|
39
|
+
return [`用法:${spec.usage}`, "", spec.summary].join("\n");
|
|
40
|
+
}
|
|
41
|
+
if (pluginCommand !== undefined) {
|
|
42
|
+
return [
|
|
43
|
+
`用法:${pluginCommand.usage}`,
|
|
44
|
+
"",
|
|
45
|
+
pluginCommand.summary,
|
|
46
|
+
`来自插件:${pluginCommand.plugin}`,
|
|
47
|
+
].join("\n");
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=help.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"help.js","sourceRoot":"","sources":["../../src/input/help.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,eAAe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AC,CAAA;IACzC,KAAK,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAA;IACzC,KAAK,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAA;IACzC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACd,KAAK,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAA;IAChD,KAAK,CAAC,IAAI,CAAC,0EAA0E,CAAC,CAAA;IACtF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC3B,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAY,EAAE,aAAiC;IAC7E,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAA;IAC9B,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACrB,OAAO,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC5D,CAAC;IACD,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;QAC9B,OAAO;YACH,MAAM,aAAa,CAAC,KAAK,EAAE;YAC3B,EAAE;YACF,aAAa,CAAC,OAAO;YACrB,QAAQ,aAAa,CAAC,MAAM,EAAE;SACjC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAChB,CAAC;IACD,OAAO,IAAI,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/input/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,cAAc,oBAAoB,CAAA;AAClC,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ParseArgsOptionsConfig } from "node:util";
|
|
2
|
+
import { Result } from "../api/result/result.js";
|
|
3
|
+
export type CommandValues = Readonly<Record<string, string | boolean | undefined>>;
|
|
4
|
+
export interface ParsedCommandLine {
|
|
5
|
+
readonly values: CommandValues;
|
|
6
|
+
readonly positionals: readonly string[];
|
|
7
|
+
}
|
|
8
|
+
export declare function parseCommandArgs(argv: readonly string[], options: ParseArgsOptionsConfig): Result<ParsedCommandLine>;
|
|
9
|
+
/** 把 unknown 值转成字符串参数 */
|
|
10
|
+
export declare function stringValue(values: CommandValues, name: string): string | undefined;
|
|
11
|
+
export declare function booleanValue(values: CommandValues, name: string): boolean;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* 命令级参数解析。
|
|
3
|
+
* 统一走 node:util parseArgs,未知参数严格报错并映射为 usage.* 错误码。
|
|
4
|
+
*/
|
|
5
|
+
import { parseArgs } from "node:util";
|
|
6
|
+
import { Result } from "../api/result/result.js";
|
|
7
|
+
import { USAGE_CODES, usageCode } from "./codes.js";
|
|
8
|
+
function optionName(message) {
|
|
9
|
+
const match = /(--?[A-Za-z][\w-]*)/.exec(message);
|
|
10
|
+
return match?.[1];
|
|
11
|
+
}
|
|
12
|
+
function mapParseError(error) {
|
|
13
|
+
const candidate = error;
|
|
14
|
+
const message = candidate.message ?? "";
|
|
15
|
+
switch (candidate.code) {
|
|
16
|
+
case "ERR_PARSE_ARGS_UNKNOWN_OPTION":
|
|
17
|
+
return usageCode(USAGE_CODES.unknownOption, optionName(message));
|
|
18
|
+
case "ERR_PARSE_ARGS_MISSING_OPTION_ARG":
|
|
19
|
+
return usageCode(USAGE_CODES.missingValue, optionName(message));
|
|
20
|
+
case "ERR_PARSE_ARGS_INVALID_OPTION_VALUE":
|
|
21
|
+
return usageCode(USAGE_CODES.invalidValue, optionName(message));
|
|
22
|
+
default:
|
|
23
|
+
return usageCode(USAGE_CODES.invalidValue);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function parseCommandArgs(argv, options) {
|
|
27
|
+
try {
|
|
28
|
+
const parsed = parseArgs({
|
|
29
|
+
args: [...argv],
|
|
30
|
+
options,
|
|
31
|
+
strict: true,
|
|
32
|
+
allowPositionals: true,
|
|
33
|
+
});
|
|
34
|
+
return Result.successWithData({
|
|
35
|
+
values: parsed.values,
|
|
36
|
+
positionals: parsed.positionals,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
return Result.error(mapParseError(error));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** 把 unknown 值转成字符串参数 */
|
|
44
|
+
export function stringValue(values, name) {
|
|
45
|
+
const value = values[name];
|
|
46
|
+
return typeof value === "string" ? value : undefined;
|
|
47
|
+
}
|
|
48
|
+
export function booleanValue(values, name) {
|
|
49
|
+
return values[name] === true;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=parse-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-options.js","sourceRoot":"","sources":["../../src/input/parse-options.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAA+B,MAAM,WAAW,CAAA;AAElE,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AASnD,SAAS,UAAU,CAAC,OAAe;IAC/B,MAAM,KAAK,GAAG,qBAAqB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACjD,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,CAAA;AACrB,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACjC,MAAM,SAAS,GAAG,KAA4C,CAAA;IAC9D,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,IAAI,EAAE,CAAA;IACvC,QAAQ,SAAS,CAAC,IAAI,EAAE,CAAC;QACrB,KAAK,+BAA+B;YAChC,OAAO,SAAS,CAAC,WAAW,CAAC,aAAa,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,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解析,其余原样交给命令或插件。
|
|
4
|
+
*/
|
|
5
|
+
import { parseArgs } from "node:util";
|
|
6
|
+
import { Result } from "../api/result/result.js";
|
|
7
|
+
import { USAGE_CODES, usageCode } from "./codes.js";
|
|
8
|
+
const LEVELS = new Set([
|
|
9
|
+
"fatal",
|
|
10
|
+
"error",
|
|
11
|
+
"warn",
|
|
12
|
+
"info",
|
|
13
|
+
"debug",
|
|
14
|
+
"trace",
|
|
15
|
+
"silent",
|
|
16
|
+
]);
|
|
17
|
+
function optionName(message) {
|
|
18
|
+
const match = /(--?[A-Za-z][\w-]*)/.exec(message);
|
|
19
|
+
return match?.[1];
|
|
20
|
+
}
|
|
21
|
+
function mapParseError(error) {
|
|
22
|
+
const candidate = error;
|
|
23
|
+
const message = candidate.message ?? "";
|
|
24
|
+
switch (candidate.code) {
|
|
25
|
+
case "ERR_PARSE_ARGS_UNKNOWN_OPTION":
|
|
26
|
+
return usageCode(USAGE_CODES.unknownOption, optionName(message));
|
|
27
|
+
case "ERR_PARSE_ARGS_MISSING_OPTION_ARG":
|
|
28
|
+
return usageCode(USAGE_CODES.missingValue, optionName(message));
|
|
29
|
+
case "ERR_PARSE_ARGS_INVALID_OPTION_VALUE":
|
|
30
|
+
return usageCode(USAGE_CODES.invalidValue, optionName(message));
|
|
31
|
+
default:
|
|
32
|
+
return usageCode(USAGE_CODES.invalidValue);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function text(value) {
|
|
36
|
+
return typeof value === "string" ? value : undefined;
|
|
37
|
+
}
|
|
38
|
+
const VALUE_OPTIONS = new Set([
|
|
39
|
+
"-c",
|
|
40
|
+
"--config",
|
|
41
|
+
"--home",
|
|
42
|
+
"-l",
|
|
43
|
+
"--log-level",
|
|
44
|
+
]);
|
|
45
|
+
/** 手工切出全局参数前缀:遇到第一个位置参数(命令名)即停止,后续 token 全部原样保留 */
|
|
46
|
+
function splitGlobalPrefix(argv) {
|
|
47
|
+
const globalArgs = [];
|
|
48
|
+
let index = 0;
|
|
49
|
+
while (index < argv.length) {
|
|
50
|
+
const token = argv[index];
|
|
51
|
+
if (token === undefined) {
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
if (token === "--") {
|
|
55
|
+
index += 1;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
if (!token.startsWith("-") || token === "-") {
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
globalArgs.push(token);
|
|
62
|
+
const equals = token.indexOf("=");
|
|
63
|
+
const name = equals === -1 ? token : token.slice(0, equals);
|
|
64
|
+
if (VALUE_OPTIONS.has(name) && equals === -1) {
|
|
65
|
+
const value = argv[index + 1];
|
|
66
|
+
if (value !== undefined) {
|
|
67
|
+
globalArgs.push(value);
|
|
68
|
+
index += 2;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
index += 1;
|
|
73
|
+
}
|
|
74
|
+
const command = argv[index] ?? null;
|
|
75
|
+
return {
|
|
76
|
+
globalArgs,
|
|
77
|
+
command,
|
|
78
|
+
commandArgv: index < argv.length ? [...argv.slice(index + 1)] : [],
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export function parseGlobal(argv) {
|
|
82
|
+
const { globalArgs, command, commandArgv } = splitGlobalPrefix(argv);
|
|
83
|
+
let values;
|
|
84
|
+
try {
|
|
85
|
+
const parsed = parseArgs({
|
|
86
|
+
args: globalArgs,
|
|
87
|
+
options: {
|
|
88
|
+
config: { type: "string", short: "c" },
|
|
89
|
+
home: { type: "string" },
|
|
90
|
+
"log-level": { type: "string", short: "l" },
|
|
91
|
+
json: { type: "boolean" },
|
|
92
|
+
quiet: { type: "boolean", short: "q" },
|
|
93
|
+
help: { type: "boolean", short: "h" },
|
|
94
|
+
version: { type: "boolean", short: "v" },
|
|
95
|
+
},
|
|
96
|
+
strict: true,
|
|
97
|
+
allowPositionals: false,
|
|
98
|
+
});
|
|
99
|
+
values = parsed.values;
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
return Result.error(mapParseError(error));
|
|
103
|
+
}
|
|
104
|
+
const rawLevel = text(values["log-level"]);
|
|
105
|
+
if (rawLevel !== undefined && !LEVELS.has(rawLevel)) {
|
|
106
|
+
return Result.error(usageCode(USAGE_CODES.invalidValue, "--log-level"));
|
|
107
|
+
}
|
|
108
|
+
const options = {
|
|
109
|
+
config: text(values["config"]),
|
|
110
|
+
home: text(values["home"]),
|
|
111
|
+
logLevel: rawLevel,
|
|
112
|
+
json: values["json"] === true,
|
|
113
|
+
quiet: values["quiet"] === true,
|
|
114
|
+
help: values["help"] === true,
|
|
115
|
+
version: values["version"] === true,
|
|
116
|
+
};
|
|
117
|
+
return Result.successWithData({ options, command, commandArgv });
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/input/parse.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAIrC,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAGnD,MAAM,MAAM,GAAwB,IAAI,GAAG,CAAkB;IACzD,OAAO;IACP,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;IACP,QAAQ;CACX,CAAC,CAAA;AAEF,SAAS,UAAU,CAAC,OAAe;IAC/B,MAAM,KAAK,GAAG,qBAAqB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACjD,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,CAAA;AACrB,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACjC,MAAM,SAAS,GAAG,KAA4C,CAAA;IAC9D,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,IAAI,EAAE,CAAA;IACvC,QAAQ,SAAS,CAA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AAI;KACtC,CAAA;IACD,OAAO,MAAM,CAAC,eAAe,CAAe,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAA;AAClF,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { LevelWithSilent } from "pino";
|
|
2
|
+
export interface GlobalOptions {
|
|
3
|
+
readonly config?: string;
|
|
4
|
+
readonly home?: string;
|
|
5
|
+
readonly logLevel?: LevelWithSilent;
|
|
6
|
+
readonly json: boolean;
|
|
7
|
+
readonly quiet: boolean;
|
|
8
|
+
readonly help: boolean;
|
|
9
|
+
readonly version: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface ParsedGlobal {
|
|
12
|
+
readonly options: GlobalOptions;
|
|
13
|
+
/** 命令名;没有子命令时为 null */
|
|
14
|
+
readonly command: string | null;
|
|
15
|
+
/** 命令名之后的原始参数,原样交给命令或插件 */
|
|
16
|
+
readonly commandArgv: readonly string[];
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/input/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export type ElogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal";
|
|
2
|
+
export interface ElogStream {
|
|
3
|
+
write(text: string): unknown;
|
|
4
|
+
}
|
|
5
|
+
export interface ElogOptions {
|
|
6
|
+
readonly stdout?: ElogStream;
|
|
7
|
+
readonly stderr?: ElogStream;
|
|
8
|
+
/** 未指定时按 TTY 与 NO_COLOR 自动判断 */
|
|
9
|
+
readonly color?: boolean;
|
|
10
|
+
readonly json?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare class Elog {
|
|
13
|
+
#private;
|
|
14
|
+
constructor(options?: ElogOptions);
|
|
15
|
+
setJson(json: boolean): void;
|
|
16
|
+
isJson(): boolean;
|
|
17
|
+
setSessionName(name: string): void;
|
|
18
|
+
getSessionName(): string;
|
|
19
|
+
setColor(color: boolean): void;
|
|
20
|
+
/** 普通信息,stdout */
|
|
21
|
+
info(text: string): void;
|
|
22
|
+
/** 成功信息,stdout */
|
|
23
|
+
success(text: string): void;
|
|
24
|
+
debug(text: string): void;
|
|
25
|
+
warn(text: string): void;
|
|
26
|
+
error(text: string): void;
|
|
27
|
+
/** Agent 输出前缀 */
|
|
28
|
+
agentStart(): void;
|
|
29
|
+
/** Agent 输出行 */
|
|
30
|
+
agent(text: string): void;
|
|
31
|
+
/** 步骤分隔行 */
|
|
32
|
+
step(step: number, total?: number): void;
|
|
33
|
+
/** 操作请求块 */
|
|
34
|
+
action(title: string, rows: readonly {
|
|
35
|
+
readonly label: string;
|
|
36
|
+
readonly value: string;
|
|
37
|
+
readonly code?: boolean;
|
|
38
|
+
}[]): void;
|
|
39
|
+
/** 工具调用行:换行后单独一行显示中文动作名与参数摘要 */
|
|
40
|
+
toolCall(label: string, summary?: string): void;
|
|
41
|
+
/** 工具结果/错误行:缩进在工具调用下面 */
|
|
42
|
+
toolResult(text: string): void;
|
|
43
|
+
/** 操作结果行 */
|
|
44
|
+
actionStatus(name: string, status: string): void;
|
|
45
|
+
/** 只带级别标签,不再拼插件名 */
|
|
46
|
+
tag(level: ElogLevel, text: string): void;
|
|
47
|
+
/** 插件输出:`[LEVEL] [plugin] message` */
|
|
48
|
+
plugin(level: ElogLevel, pluginName: string, message: string): void;
|
|
49
|
+
/** 流式写正文,不加换行与标签 */
|
|
50
|
+
stream(text: string): void;
|
|
51
|
+
/** 结束当前流式行 */
|
|
52
|
+
line(): void;
|
|
53
|
+
/** 提示行,stderr,无级别标签 */
|
|
54
|
+
notice(text: string): void;
|
|
55
|
+
/** 纯文本行,stdout */
|
|
56
|
+
print(text?: string): void;
|
|
57
|
+
/** 清屏,仅 TTY 有效 */
|
|
58
|
+
clear(): void;
|
|
59
|
+
}
|
|
60
|
+
/** 初始化全局 elog4js;重复调用会替换实例 */
|
|
61
|
+
export declare function initElog(options?: ElogOptions): Elog;
|
|
62
|
+
/** 取全局 elog4js,未初始化时按默认参数创建 */
|
|
63
|
+
export declare function getElog(): Elog;
|
|
64
|
+
/** 重置全局实例,供测试使用 */
|
|
65
|
+
export declare function resetElog(): void;
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* 终端 UI 输出器(elog4js)。
|
|
3
|
+
* human 模式专用:级别标签、颜色、流式输出;Pino 只负责结构化日志与文件。
|
|
4
|
+
* --json 模式下所有方法静默,stdout 只留给 Result envelope。
|
|
5
|
+
*/
|
|
6
|
+
const TAGS = {
|
|
7
|
+
trace: "[TRACE]",
|
|
8
|
+
debug: "[DEBUG]",
|
|
9
|
+
info: "[INFO ]",
|
|
10
|
+
warn: "[WARN ]",
|
|
11
|
+
error: "[ERROR]",
|
|
12
|
+
fatal: "[FATAL]",
|
|
13
|
+
};
|
|
14
|
+
const COLORS = {
|
|
15
|
+
trace: "\x1b[90m",
|
|
16
|
+
debug: "\x1b[36m",
|
|
17
|
+
info: "\x1b[32m",
|
|
18
|
+
warn: "\x1b[33m",
|
|
19
|
+
error: "\x1b[31m",
|
|
20
|
+
fatal: "\x1b[35m",
|
|
21
|
+
};
|
|
22
|
+
const RESET = "\x1b[0m";
|
|
23
|
+
// 字符显示宽度
|
|
24
|
+
function charWidth(codePoint) {
|
|
25
|
+
if (codePoint === 0x200b) {
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
return codePoint >= 0x1100 &&
|
|
29
|
+
(codePoint <= 0x115f ||
|
|
30
|
+
codePoint === 0x2329 ||
|
|
31
|
+
codePoint === 0x232a ||
|
|
32
|
+
(codePoint >= 0x2e80 && codePoint <= 0xa4cf) ||
|
|
33
|
+
(codePoint >= 0xac00 && codePoint <= 0xd7a3) ||
|
|
34
|
+
(codePoint >= 0xf900 && codePoint <= 0xfaff) ||
|
|
35
|
+
(codePoint >= 0xfe10 && codePoint <= 0xfe19) ||
|
|
36
|
+
(codePoint >= 0xfe30 && codePoint <= 0xfe6f) ||
|
|
37
|
+
(codePoint >= 0xff00 && codePoint <= 0xff60) ||
|
|
38
|
+
(codePoint >= 0xffe0 && codePoint <= 0xffe6) ||
|
|
39
|
+
(codePoint >= 0x1f300 && codePoint <= 0x1f64f) ||
|
|
40
|
+
(codePoint >= 0x1f900 && codePoint <= 0x1f9ff))
|
|
41
|
+
? 2
|
|
42
|
+
: 1;
|
|
43
|
+
}
|
|
44
|
+
function displayWidth(text) {
|
|
45
|
+
let width = 0;
|
|
46
|
+
for (const char of text) {
|
|
47
|
+
width += charWidth(char.codePointAt(0) ?? 0);
|
|
48
|
+
}
|
|
49
|
+
return width;
|
|
50
|
+
}
|
|
51
|
+
function wrapLine(text, width) {
|
|
52
|
+
if (displayWidth(text) <= width) {
|
|
53
|
+
return [text];
|
|
54
|
+
}
|
|
55
|
+
const chunks = [];
|
|
56
|
+
let rest = text;
|
|
57
|
+
while (displayWidth(rest) > width) {
|
|
58
|
+
let taken = 0;
|
|
59
|
+
let current = 0;
|
|
60
|
+
let lastSpace = -1;
|
|
61
|
+
for (const char of rest) {
|
|
62
|
+
const next = charWidth(char.codePointAt(0) ?? 0);
|
|
63
|
+
if (current + next > width) {
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
current += next;
|
|
67
|
+
taken += char.length;
|
|
68
|
+
if (char === " ") {
|
|
69
|
+
lastSpace = taken;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const cut = lastSpace > 0 ? lastSpace : taken;
|
|
73
|
+
chunks.push(rest.slice(0, cut));
|
|
74
|
+
rest = rest.slice(cut);
|
|
75
|
+
}
|
|
76
|
+
chunks.push(rest);
|
|
77
|
+
return chunks;
|
|
78
|
+
}
|
|
79
|
+
function detectColor(stream) {
|
|
80
|
+
const force = process.env["FORCE_COLOR"];
|
|
81
|
+
if (force === "0") {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
if (force !== undefined && force !== "") {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
if (process.env["NO_COLOR"] !== undefined) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
if (process.env["TERM"] === "dumb") {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
return stream?.isTTY === true;
|
|
94
|
+
}
|
|
95
|
+
export class Elog {
|
|
96
|
+
#stdout;
|
|
97
|
+
#stderr;
|
|
98
|
+
#colorStdout;
|
|
99
|
+
#colorStderr;
|
|
100
|
+
#json;
|
|
101
|
+
#sessionName = "";
|
|
102
|
+
#streaming = false;
|
|
103
|
+
constructor(options = {}) {
|
|
104
|
+
this.#stdout = options.stdout ?? process.stdout;
|
|
105
|
+
this.#stderr = options.stderr ?? process.stderr;
|
|
106
|
+
this.#colorStdout = options.color ?? detectColor(this.#stdout);
|
|
107
|
+
this.#colorStderr = options.color ?? detectColor(this.#stderr);
|
|
108
|
+
this.#json = options.json ?? false;
|
|
109
|
+
}
|
|
110
|
+
setJson(json) {
|
|
111
|
+
this.#json = json;
|
|
112
|
+
}
|
|
113
|
+
isJson() {
|
|
114
|
+
return this.#json;
|
|
115
|
+
}
|
|
116
|
+
setSessionName(name) {
|
|
117
|
+
this.#sessionName = name;
|
|
118
|
+
}
|
|
119
|
+
getSessionName() {
|
|
120
|
+
return this.#sessionName;
|
|
121
|
+
}
|
|
122
|
+
setColor(color) {
|
|
123
|
+
this.#colorStdout = color;
|
|
124
|
+
this.#colorStderr = color;
|
|
125
|
+
}
|
|
126
|
+
/** 普通信息,stdout */
|
|
127
|
+
info(text) {
|
|
128
|
+
this.#line("info", text, this.#stdout);
|
|
129
|
+
}
|
|
130
|
+
/** 成功信息,stdout */
|
|
131
|
+
success(text) {
|
|
132
|
+
this.#line("info", text, this.#stdout, "[ OK ]");
|
|
133
|
+
}
|
|
134
|
+
debug(text) {
|
|
135
|
+
this.#line("debug", text, this.#stderr);
|
|
136
|
+
}
|
|
137
|
+
warn(text) {
|
|
138
|
+
this.#line("warn", text, this.#stderr);
|
|
139
|
+
}
|
|
140
|
+
error(text) {
|
|
141
|
+
this.#line("error", text, this.#stderr);
|
|
142
|
+
}
|
|
143
|
+
/** Agent 输出前缀 */
|
|
144
|
+
agentStart() {
|
|
145
|
+
if (this.#json) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const color = this.#colorStdout;
|
|
149
|
+
const prefix = color ? `\x1b[36m[Agent]\x1b[0m` : "[Agent]";
|
|
150
|
+
this.#stdout.write(`\n${prefix}\n`);
|
|
151
|
+
}
|
|
152
|
+
/** Agent 输出行 */
|
|
153
|
+
agent(text) {
|
|
154
|
+
if (this.#json) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
this.agentStart();
|
|
158
|
+
this.#stdout.write(`${text}\n`);
|
|
159
|
+
}
|
|
160
|
+
/** 步骤分隔行 */
|
|
161
|
+
step(step, total) {
|
|
162
|
+
if (this.#json) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const color = this.#colorStdout;
|
|
166
|
+
const text = total === undefined ? `── step ${step} ──` : `── step ${step}/${total} ──`;
|
|
167
|
+
this.#stdout.write(`\n${color ? `\x1b[36m${text}\x1b[0m` : text}\n`);
|
|
168
|
+
}
|
|
169
|
+
/** 代码块 */
|
|
170
|
+
#codeBlock(label, code) {
|
|
171
|
+
const columns = process.stdout.columns ?? 80;
|
|
172
|
+
const width = Math.max(40, columns - 2);
|
|
173
|
+
const inner = width - 4;
|
|
174
|
+
const color = this.#colorStdout;
|
|
175
|
+
const border = (text) => (color ? `\x1b[90m${text}\x1b[0m` : text);
|
|
176
|
+
const header = `┌ [${label}]`;
|
|
177
|
+
this.#stdout.write(`${border(`${header}${"─".repeat(Math.max(1, width - header.length - 1))}┐`)}\n`);
|
|
178
|
+
for (const source of code.split("\n")) {
|
|
179
|
+
const text = source.replace(/\t/g, " ");
|
|
180
|
+
for (let index = 0; index < Math.max(1, text.length); index += inner) {
|
|
181
|
+
const chunk = text.slice(index, index + inner);
|
|
182
|
+
this.#stdout.write(`${border("│")} ${chunk.padEnd(inner)} ${border("│")}\n`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
this.#stdout.write(`${border(`└${"─".repeat(width - 2)}┘`)}\n`);
|
|
186
|
+
}
|
|
187
|
+
/** 操作请求块 */
|
|
188
|
+
action(title, rows) {
|
|
189
|
+
if (this.#json) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const color = this.#colorStdout;
|
|
193
|
+
const label = color ? `\x1b[33m${title}\x1b[0m` : title;
|
|
194
|
+
this.#stdout.write(`\n${label}\n`);
|
|
195
|
+
for (const row of rows) {
|
|
196
|
+
if (row.code === true) {
|
|
197
|
+
this.#stdout.write(` ${row.label}\n`);
|
|
198
|
+
this.#codeBlock("bash", row.value);
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
this.#stdout.write(` ${row.label} ${row.value}\n`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/** 工具调用行:换行后单独一行显示中文动作名与参数摘要 */
|
|
205
|
+
toolCall(label, summary = "") {
|
|
206
|
+
if (this.#json) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const color = this.#colorStdout;
|
|
210
|
+
const name = color ? `\x1b[36m${label}\x1b[0m` : label;
|
|
211
|
+
const line = summary === "" ? name : `${name} ${summary}`;
|
|
212
|
+
this.#stdout.write(`\n${line}\n`);
|
|
213
|
+
}
|
|
214
|
+
/** 工具结果/错误行:缩进在工具调用下面 */
|
|
215
|
+
toolResult(text) {
|
|
216
|
+
if (this.#json || text === "") {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
const color = this.#colorStdout;
|
|
220
|
+
const line = ` ${text}`;
|
|
221
|
+
this.#stdout.write(`${color ? `\x1b[90m${line}\x1b[0m` : line}\n`);
|
|
222
|
+
}
|
|
223
|
+
/** 操作结果行 */
|
|
224
|
+
actionStatus(name, status) {
|
|
225
|
+
if (this.#json) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const color = this.#colorStdout;
|
|
229
|
+
const label = color ? `\x1b[90m[操作]\x1b[0m` : "[操作]";
|
|
230
|
+
this.#stdout.write(`${label} ${name} ${status}\n`);
|
|
231
|
+
}
|
|
232
|
+
/** 只带级别标签,不再拼插件名 */
|
|
233
|
+
tag(level, text) {
|
|
234
|
+
const stream = level === "error" || level === "warn" ? this.#stderr : this.#stdout;
|
|
235
|
+
this.#line(level, text, stream);
|
|
236
|
+
}
|
|
237
|
+
/** 插件输出:`[LEVEL] [plugin] message` */
|
|
238
|
+
plugin(level, pluginName, message) {
|
|
239
|
+
const stream = level === "error" || level === "warn" ? this.#stderr : this.#stdout;
|
|
240
|
+
this.#line(level, `[${pluginName}] ${message}`, stream);
|
|
241
|
+
}
|
|
242
|
+
/** 流式写正文,不加换行与标签 */
|
|
243
|
+
stream(text) {
|
|
244
|
+
if (this.#json || text === "") {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
this.#streaming = true;
|
|
248
|
+
this.#stdout.write(text);
|
|
249
|
+
}
|
|
250
|
+
/** 结束当前流式行 */
|
|
251
|
+
line() {
|
|
252
|
+
if (this.#json || !this.#streaming) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
this.#streaming = false;
|
|
256
|
+
this.#stdout.write("\n");
|
|
257
|
+
}
|
|
258
|
+
/** 提示行,stderr,无级别标签 */
|
|
259
|
+
notice(text) {
|
|
260
|
+
if (this.#json) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
this.#stderr.write(`${text}\n`);
|
|
264
|
+
}
|
|
265
|
+
/** 纯文本行,stdout */
|
|
266
|
+
print(text = "") {
|
|
267
|
+
if (this.#json) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
this.#stdout.write(`${text}\n`);
|
|
271
|
+
}
|
|
272
|
+
/** 清屏,仅 TTY 有效 */
|
|
273
|
+
clear() {
|
|
274
|
+
if (this.#json || process.stdout.isTTY !== true) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
process.stdout.write("\x1b[2J\x1b[H");
|
|
278
|
+
}
|
|
279
|
+
#line(level, text, stream, tag = TAGS[level]) {
|
|
280
|
+
if (this.#json) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const color = stream === this.#stdout ? this.#colorStdout : this.#colorStderr;
|
|
284
|
+
const coloredTag = color ? `${COLORS[level]}${tag}${RESET}` : tag;
|
|
285
|
+
stream.write(`${coloredTag} ${text}\n`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
let singleton = null;
|
|
289
|
+
/** 初始化全局 elog4js;重复调用会替换实例 */
|
|
290
|
+
export function initElog(options = {}) {
|
|
291
|
+
singleton = new Elog(options);
|
|
292
|
+
return singleton;
|
|
293
|
+
}
|
|
294
|
+
/** 取全局 elog4js,未初始化时按默认参数创建 */
|
|
295
|
+
export function getElog() {
|
|
296
|
+
if (singleton === null) {
|
|
297
|
+
singleton = new Elog();
|
|
298
|
+
}
|
|
299
|
+
return singleton;
|
|
300
|
+
}
|
|
301
|
+
/** 重置全局实例,供测试使用 */
|
|
302
|
+
export function resetElog() {
|
|
303
|
+
singleton = null;
|
|
304
|
+
}
|
|
305
|
+
//# sourceMappingURL=elog4js.js.map
|