@oyasmi/pipiclaw 0.9.4-beta.2 → 0.9.5-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +28 -22
- package/README.md +27 -21
- package/dist/agent/builtin-commands.d.ts +7 -2
- package/dist/agent/builtin-commands.js +19 -23
- package/dist/agent/channel-runner.d.ts +13 -13
- package/dist/agent/channel-runner.js +93 -76
- package/dist/agent/maintenance-context.d.ts +6 -5
- package/dist/agent/maintenance-context.js +15 -15
- package/dist/agent/prompt/manifest.js +1 -1
- package/dist/agent/prompt/resources.d.ts +1 -1
- package/dist/agent/prompt/resources.js +1 -1
- package/dist/agent/prompt/sections.js +4 -4
- package/dist/agent/runner-factory.d.ts +6 -6
- package/dist/agent/runner-factory.js +6 -7
- package/dist/agent/session/compaction-input.d.ts +6 -0
- package/dist/agent/session/compaction-input.js +75 -0
- package/dist/agent/session/compaction-snapshot.d.ts +30 -0
- package/dist/agent/session/compaction-snapshot.js +154 -0
- package/dist/agent/session/compaction-summary.d.ts +39 -0
- package/dist/agent/session/compaction-summary.js +158 -0
- package/dist/agent/session/compaction.d.ts +35 -0
- package/dist/agent/session/compaction.js +294 -0
- package/dist/agent/session/context-input.d.ts +15 -0
- package/dist/agent/session/context-input.js +82 -0
- package/dist/agent/session/context-snapshot.d.ts +11 -0
- package/dist/agent/session/context-snapshot.js +72 -0
- package/dist/agent/session/event-guards.d.ts +2 -0
- package/dist/agent/session/event-guards.js +4 -0
- package/dist/agent/session/request-tools.d.ts +3 -0
- package/dist/agent/session/request-tools.js +20 -0
- package/dist/agent/session/session-adapter.d.ts +2 -1
- package/dist/agent/session/session-adapter.js +6 -3
- package/dist/agent/session/session-events.d.ts +5 -4
- package/dist/agent/session/session-events.js +46 -59
- package/dist/agent/session/session-host.d.ts +29 -41
- package/dist/agent/session/session-host.js +86 -69
- package/dist/agent/session/settings-diagnostics.d.ts +5 -0
- package/dist/agent/session/settings-diagnostics.js +21 -0
- package/dist/agent/status-render.js +5 -2
- package/dist/{runtime → agent}/stop-watchdog.d.ts +3 -1
- package/dist/{runtime → agent}/stop-watchdog.js +7 -3
- package/dist/agent/turn/progress-formatter.d.ts +1 -3
- package/dist/agent/turn/progress-formatter.js +3 -22
- package/dist/agent/turn/task-digest.d.ts +4 -2
- package/dist/agent/turn/task-digest.js +7 -4
- package/dist/agent/turn/turn-context.d.ts +11 -7
- package/dist/agent/turn/turn-context.js +26 -18
- package/dist/agent/turn/turn-finish.d.ts +17 -5
- package/dist/agent/turn/turn-finish.js +51 -77
- package/dist/agent/turn/turn-input.d.ts +2 -2
- package/dist/agent/turn/turn-input.js +4 -3
- package/dist/agent/turn/turn-output.d.ts +19 -0
- package/dist/agent/turn/turn-output.js +41 -0
- package/dist/agent/turn/turn-pipeline.d.ts +11 -8
- package/dist/agent/turn/turn-pipeline.js +54 -55
- package/dist/agent/turn/turn-prompt.d.ts +1 -1
- package/dist/agent/turn/turn-recovery.d.ts +11 -10
- package/dist/agent/turn/turn-recovery.js +14 -29
- package/dist/agent/types.d.ts +31 -12
- package/dist/agent/types.js +2 -1
- package/dist/app/auth-command.js +1 -1
- package/dist/app/home.js +31 -15
- package/dist/channel/active-session-store.d.ts +14 -12
- package/dist/channel/active-session-store.js +29 -25
- package/dist/channel/attachments.d.ts +25 -0
- package/dist/channel/attachments.js +56 -0
- package/dist/channel/channel-context.d.ts +87 -96
- package/dist/channel/channel-context.js +1 -66
- package/dist/channel/channel-event.d.ts +51 -41
- package/dist/channel/channel-event.js +6 -11
- package/dist/channel/channel-id.d.ts +22 -0
- package/dist/channel/channel-id.js +13 -0
- package/dist/channel/channel-index.d.ts +17 -34
- package/dist/channel/channel-index.js +41 -80
- package/dist/channel/config.d.ts +10 -0
- package/dist/channel/config.js +55 -0
- package/dist/channel/ingress.d.ts +101 -0
- package/dist/channel/ingress.js +5 -0
- package/dist/channel/store.d.ts +13 -15
- package/dist/channel/store.js +21 -25
- package/dist/channel/transport.d.ts +99 -0
- package/dist/channel/turn-context.d.ts +23 -0
- package/dist/channel/turn-context.js +1 -0
- package/dist/commands/catalog.d.ts +4 -7
- package/dist/commands/catalog.js +24 -31
- package/dist/commands/router.d.ts +23 -12
- package/dist/commands/router.js +22 -24
- package/dist/config/settings.d.ts +5 -4
- package/dist/desk/bindings.d.ts +6 -0
- package/dist/desk/bindings.js +105 -0
- package/dist/desk/commands.d.ts +81 -0
- package/dist/desk/commands.js +145 -0
- package/dist/desk/default.d.ts +4 -0
- package/dist/desk/default.js +11 -0
- package/dist/desk/paths.d.ts +41 -0
- package/dist/desk/paths.js +81 -0
- package/dist/desk/registry.d.ts +17 -0
- package/dist/desk/registry.js +191 -0
- package/dist/desk/startup-error.d.ts +4 -0
- package/dist/desk/startup-error.js +7 -0
- package/dist/desk/types.d.ts +72 -0
- package/dist/desk/types.js +7 -0
- package/dist/dingtalk/bot.d.ts +18 -35
- package/dist/dingtalk/bot.js +21 -204
- package/dist/dingtalk/channel-ids.d.ts +15 -0
- package/dist/dingtalk/channel-ids.js +39 -0
- package/dist/dingtalk/config.d.ts +6 -3
- package/dist/dingtalk/config.js +13 -25
- package/dist/dingtalk/connection.d.ts +1 -0
- package/dist/dingtalk/connection.js +5 -4
- package/dist/dingtalk/conversation-meta.d.ts +10 -5
- package/dist/dingtalk/conversation-meta.js +72 -50
- package/dist/dingtalk/delivery.d.ts +30 -14
- package/dist/dingtalk/delivery.js +189 -62
- package/dist/dingtalk/inbound-media.d.ts +2 -18
- package/dist/dingtalk/inbound-media.js +0 -53
- package/dist/dingtalk/inbound.d.ts +10 -11
- package/dist/dingtalk/inbound.js +12 -19
- package/dist/dingtalk/media.d.ts +9 -11
- package/dist/dingtalk/media.js +18 -31
- package/dist/dingtalk/progress.d.ts +8 -0
- package/dist/dingtalk/progress.js +20 -0
- package/dist/dingtalk/response-mode.d.ts +13 -0
- package/dist/dingtalk/response-mode.js +31 -0
- package/dist/dingtalk/transport.d.ts +47 -0
- package/dist/dingtalk/transport.js +71 -0
- package/dist/events/commands.d.ts +7 -2
- package/dist/events/commands.js +40 -22
- package/dist/events/pre-action-error.d.ts +10 -0
- package/dist/events/pre-action-error.js +10 -0
- package/dist/events/types.d.ts +20 -2
- package/dist/events/watcher.d.ts +14 -7
- package/dist/events/watcher.js +49 -26
- package/dist/index.d.ts +4 -2
- package/dist/jobs/completion-wake.d.ts +14 -0
- package/dist/jobs/completion-wake.js +36 -0
- package/dist/jobs/manager.d.ts +27 -22
- package/dist/jobs/manager.js +58 -91
- package/dist/jobs/record.d.ts +2 -0
- package/dist/jobs/record.js +2 -0
- package/dist/log.d.ts +0 -1
- package/dist/log.js +1 -1
- package/dist/main.js +10 -3
- package/dist/memory/boundary-work.d.ts +17 -0
- package/dist/memory/boundary-work.js +162 -0
- package/dist/memory/commands.d.ts +4 -3
- package/dist/memory/commands.js +16 -16
- package/dist/memory/desk-memory-queue.d.ts +18 -0
- package/dist/memory/desk-memory-queue.js +33 -0
- package/dist/memory/index-budget.d.ts +3 -3
- package/dist/memory/index-budget.js +3 -3
- package/dist/memory/journal.d.ts +6 -6
- package/dist/memory/journal.js +14 -14
- package/dist/memory/lifecycle.d.ts +14 -21
- package/dist/memory/lifecycle.js +73 -103
- package/dist/memory/maintenance-state.d.ts +14 -15
- package/dist/memory/maintenance-state.js +43 -42
- package/dist/memory/reflect-job.d.ts +5 -4
- package/dist/memory/reflect-job.js +21 -15
- package/dist/memory/reflect.d.ts +2 -1
- package/dist/memory/reflect.js +13 -12
- package/dist/memory/render.d.ts +1 -1
- package/dist/memory/render.js +2 -2
- package/dist/memory/review-log.d.ts +4 -4
- package/dist/memory/review-log.js +5 -5
- package/dist/memory/scheduler.d.ts +12 -19
- package/dist/memory/scheduler.js +28 -64
- package/dist/memory/session-corpus.d.ts +4 -1
- package/dist/memory/session-corpus.js +70 -29
- package/dist/memory/session-search.d.ts +11 -3
- package/dist/memory/session-search.js +14 -11
- package/dist/memory/sidecar-worker.d.ts +1 -0
- package/dist/memory/sidecar-worker.js +57 -76
- package/dist/memory/source-window.d.ts +0 -6
- package/dist/memory/source-window.js +0 -20
- package/dist/memory/store.d.ts +12 -12
- package/dist/memory/store.js +44 -44
- package/dist/paths.d.ts +2 -0
- package/dist/paths.js +2 -0
- package/dist/playbooks/agent-delegation.md +16 -16
- package/dist/playbooks/background-jobs.md +5 -3
- package/dist/playbooks/event-scheduling.md +7 -5
- package/dist/playbooks/memory-and-learning.md +16 -12
- package/dist/playbooks/outbound-media.md +1 -1
- package/dist/playbooks/runtime-orientation.md +35 -23
- package/dist/playbooks/task-lead.md +13 -11
- package/dist/runtime/bootstrap.d.ts +36 -13
- package/dist/runtime/bootstrap.js +310 -138
- package/dist/runtime/channel-queue.d.ts +23 -0
- package/dist/{dingtalk → runtime}/channel-queue.js +20 -9
- package/dist/runtime/daemon-lock.d.ts +12 -0
- package/dist/runtime/daemon-lock.js +28 -0
- package/dist/runtime/desk-runtime.d.ts +131 -0
- package/dist/runtime/desk-runtime.js +402 -0
- package/dist/runtime/durable-dispatch.d.ts +11 -5
- package/dist/runtime/durable-dispatch.js +20 -8
- package/dist/runtime/inbound-images.d.ts +32 -10
- package/dist/runtime/inbound-images.js +95 -21
- package/dist/runtime/ingress-busy.d.ts +26 -0
- package/dist/runtime/ingress-busy.js +211 -0
- package/dist/runtime/ingress-commands.d.ts +7 -0
- package/dist/runtime/ingress-commands.js +162 -0
- package/dist/runtime/ingress-deps.d.ts +62 -0
- package/dist/runtime/ingress-deps.js +1 -0
- package/dist/runtime/ingress.d.ts +22 -0
- package/dist/runtime/ingress.js +376 -0
- package/dist/runtime/request-execution.d.ts +19 -0
- package/dist/runtime/request-execution.js +88 -0
- package/dist/runtime/shutdown.d.ts +13 -5
- package/dist/runtime/shutdown.js +10 -4
- package/dist/runtime/task-driver.d.ts +38 -22
- package/dist/runtime/task-driver.js +142 -116
- package/dist/runtime/task-spawn.d.ts +4 -4
- package/dist/runtime/task-spawn.js +6 -5
- package/dist/runtime/task-wake.d.ts +6 -4
- package/dist/runtime/task-wake.js +7 -7
- package/dist/runtime/transports.d.ts +32 -0
- package/dist/runtime/transports.js +101 -0
- package/dist/runtime/turn-run.d.ts +18 -9
- package/dist/runtime/turn-run.js +302 -71
- package/dist/runtime/wake-coalescing.d.ts +11 -3
- package/dist/runtime/wake-coalescing.js +10 -0
- package/dist/security/config.js +5 -10
- package/dist/security/logger.js +1 -1
- package/dist/security/path-guard.js +7 -63
- package/dist/security/types.d.ts +27 -30
- package/dist/security/types.js +0 -1
- package/dist/shared/atomic-file.d.ts +2 -0
- package/dist/shared/atomic-file.js +14 -1
- package/dist/shared/file-lock.d.ts +35 -0
- package/dist/shared/file-lock.js +195 -0
- package/dist/shared/with-timeout.d.ts +2 -0
- package/dist/shared/with-timeout.js +21 -0
- package/dist/skills/loader.d.ts +1 -1
- package/dist/skills/loader.js +2 -2
- package/dist/skills/workspace.js +2 -2
- package/dist/subagents/completion-wake.d.ts +11 -2
- package/dist/subagents/completion-wake.js +22 -9
- package/dist/subagents/discovery.js +1 -1
- package/dist/subagents/dispatch.d.ts +0 -10
- package/dist/subagents/dispatch.js +10 -28
- package/dist/subagents/external/dispatch.js +1 -1
- package/dist/subagents/external/run.d.ts +1 -1
- package/dist/subagents/external/run.js +3 -3
- package/dist/subagents/internal/run.js +1 -1
- package/dist/subagents/internal/worker.js +6 -14
- package/dist/subagents/run-archive.d.ts +11 -0
- package/dist/subagents/run-archive.js +49 -0
- package/dist/subagents/run-record.d.ts +9 -8
- package/dist/subagents/run-record.js +3 -3
- package/dist/subagents/run-registry.d.ts +5 -3
- package/dist/subagents/run-registry.js +22 -45
- package/dist/subagents/runs.d.ts +23 -13
- package/dist/subagents/runs.js +75 -82
- package/dist/subagents/task-envelope.js +9 -11
- package/dist/subagents/types.d.ts +6 -5
- package/dist/tasks/board.d.ts +1 -1
- package/dist/tasks/board.js +2 -2
- package/dist/tasks/bound-work.d.ts +2 -2
- package/dist/tasks/bound-work.js +7 -7
- package/dist/tasks/brief.d.ts +1 -1
- package/dist/tasks/brief.js +9 -9
- package/dist/tasks/commands.d.ts +11 -2
- package/dist/tasks/commands.js +66 -41
- package/dist/tasks/contract.d.ts +0 -2
- package/dist/tasks/contract.js +1 -3
- package/dist/tasks/create.d.ts +3 -1
- package/dist/tasks/create.js +10 -4
- package/dist/tasks/frontmatter.d.ts +6 -2
- package/dist/tasks/frontmatter.js +10 -10
- package/dist/tasks/loop-log.d.ts +7 -13
- package/dist/tasks/loop-log.js +14 -17
- package/dist/tasks/mutation-lock.d.ts +7 -5
- package/dist/tasks/mutation-lock.js +32 -9
- package/dist/tasks/session-path.d.ts +3 -3
- package/dist/tasks/session-path.js +5 -5
- package/dist/tasks/steer.d.ts +5 -5
- package/dist/tasks/steer.js +42 -40
- package/dist/tasks/store.d.ts +11 -11
- package/dist/tasks/store.js +32 -29
- package/dist/tools/bash.d.ts +5 -5
- package/dist/tools/bash.js +19 -18
- package/dist/tools/contract/names.d.ts +7 -0
- package/dist/tools/contract/names.js +22 -0
- package/dist/tools/edit.js +1 -1
- package/dist/tools/event-manage.d.ts +3 -1
- package/dist/tools/event-manage.js +34 -33
- package/dist/tools/glob.js +5 -5
- package/dist/tools/grep.js +2 -2
- package/dist/tools/index.d.ts +9 -8
- package/dist/tools/index.js +12 -16
- package/dist/tools/job.d.ts +4 -2
- package/dist/tools/job.js +11 -8
- package/dist/tools/memory-manage.d.ts +5 -3
- package/dist/tools/memory-manage.js +24 -24
- package/dist/tools/read.js +1 -1
- package/dist/tools/registry.d.ts +12 -8
- package/dist/tools/registry.js +13 -9
- package/dist/tools/send-media.d.ts +2 -2
- package/dist/tools/send-media.js +3 -3
- package/dist/tools/session-search.d.ts +3 -1
- package/dist/tools/session-search.js +8 -6
- package/dist/tools/subagent-manage.d.ts +2 -8
- package/dist/tools/subagent-manage.js +19 -15
- package/dist/tools/subagent.js +1 -1
- package/dist/tools/task-manage/create.js +1 -1
- package/dist/tools/task-manage/factory.js +2 -2
- package/dist/tools/task-manage/lifecycle.js +3 -1
- package/dist/tools/task-manage/log-view.js +2 -2
- package/dist/tools/task-manage/shared.js +3 -3
- package/dist/tools/task-manage/step-end.js +3 -3
- package/dist/tools/task-manage/types.d.ts +8 -3
- package/dist/tools/web-cache.d.ts +3 -3
- package/dist/tools/web-cache.js +12 -12
- package/dist/tools/web-fetch.d.ts +2 -2
- package/dist/tools/web-fetch.js +7 -7
- package/dist/tools/write-content.js +1 -1
- package/dist/tui/cli.d.ts +17 -5
- package/dist/tui/cli.js +90 -27
- package/dist/tui/client.d.ts +26 -0
- package/dist/tui/client.js +157 -0
- package/dist/tui/colors.d.ts +0 -1
- package/dist/tui/colors.js +0 -1
- package/dist/tui/commands.d.ts +10 -51
- package/dist/tui/commands.js +16 -39
- package/dist/tui/frontend.d.ts +2 -2
- package/dist/tui/frontend.js +2 -2
- package/dist/tui/pitui-frontend.d.ts +0 -2
- package/dist/tui/pitui-frontend.js +1 -6
- package/dist/tui/render.d.ts +62 -0
- package/dist/tui/render.js +123 -0
- package/dist/tui/session.d.ts +92 -0
- package/dist/tui/session.js +317 -0
- package/dist/usage/ledger.d.ts +5 -0
- package/dist/usage/ledger.js +2 -0
- package/dist/usage/render.d.ts +6 -1
- package/dist/usage/render.js +18 -13
- package/dist/webapi/auth.d.ts +13 -0
- package/dist/webapi/auth.js +29 -0
- package/dist/webapi/config.d.ts +29 -0
- package/dist/webapi/config.js +100 -0
- package/dist/webapi/errors.d.ts +39 -0
- package/dist/webapi/errors.js +32 -0
- package/dist/webapi/http.d.ts +25 -0
- package/dist/webapi/http.js +4 -0
- package/dist/webapi/ids.d.ts +9 -0
- package/dist/webapi/ids.js +20 -0
- package/dist/webapi/input.d.ts +17 -0
- package/dist/webapi/input.js +229 -0
- package/dist/webapi/items.d.ts +37 -0
- package/dist/webapi/items.js +48 -0
- package/dist/webapi/key-command.d.ts +2 -0
- package/dist/webapi/key-command.js +110 -0
- package/dist/webapi/limits.d.ts +47 -0
- package/dist/webapi/limits.js +48 -0
- package/dist/webapi/request-policy.d.ts +17 -0
- package/dist/webapi/request-policy.js +160 -0
- package/dist/webapi/response-record.d.ts +68 -0
- package/dist/webapi/response-record.js +58 -0
- package/dist/webapi/response-state.d.ts +90 -0
- package/dist/webapi/response-state.js +347 -0
- package/dist/webapi/routes/conversations.d.ts +8 -0
- package/dist/webapi/routes/conversations.js +80 -0
- package/dist/webapi/routes/models.d.ts +3 -0
- package/dist/webapi/routes/models.js +12 -0
- package/dist/webapi/routes/responses.d.ts +8 -0
- package/dist/webapi/routes/responses.js +118 -0
- package/dist/webapi/routes/websocket.d.ts +9 -0
- package/dist/webapi/routes/websocket.js +328 -0
- package/dist/webapi/server.d.ts +24 -0
- package/dist/webapi/server.js +229 -0
- package/dist/webapi/service.d.ts +130 -0
- package/dist/webapi/service.js +588 -0
- package/dist/webapi/store.d.ts +46 -0
- package/dist/webapi/store.js +245 -0
- package/dist/webapi/stream.d.ts +13 -0
- package/dist/webapi/stream.js +76 -0
- package/dist/webapi/transport.d.ts +43 -0
- package/dist/webapi/transport.js +100 -0
- package/package.json +9 -2
- package/dist/channel/channel-paths.d.ts +0 -16
- package/dist/channel/channel-paths.js +0 -53
- package/dist/channel/commands.d.ts +0 -32
- package/dist/channel/commands.js +0 -109
- package/dist/channel/project-scope-store.d.ts +0 -51
- package/dist/channel/project-scope-store.js +0 -112
- package/dist/dingtalk/channel-queue.d.ts +0 -19
- package/dist/dingtalk/handler.d.ts +0 -90
- package/dist/memory/channel-maintenance-queue.d.ts +0 -5
- package/dist/memory/channel-maintenance-queue.js +0 -8
- package/dist/runtime/task-migration.d.ts +0 -30
- package/dist/runtime/task-migration.js +0 -465
- package/dist/runtime/turn-handler.d.ts +0 -47
- package/dist/runtime/turn-handler.js +0 -318
- package/dist/security/project-scope.d.ts +0 -45
- package/dist/security/project-scope.js +0 -105
- package/dist/tui/app.d.ts +0 -16
- package/dist/tui/app.js +0 -166
- package/dist/tui/terminal-context.d.ts +0 -27
- package/dist/tui/terminal-context.js +0 -84
- package/dist/tui/terminal-media-sender.d.ts +0 -9
- package/dist/tui/terminal-media-sender.js +0 -15
- package/dist/tui/turn-controller.d.ts +0 -64
- package/dist/tui/turn-controller.js +0 -311
- /package/dist/{dingtalk/handler.js → channel/transport.js} +0 -0
package/dist/tools/web-fetch.js
CHANGED
|
@@ -87,20 +87,20 @@ export function createWebFetchTool(options) {
|
|
|
87
87
|
label: "web_fetch",
|
|
88
88
|
description: "Fetch a public URL and extract readable content. Returns text for HTML/JSON/text pages and image content " +
|
|
89
89
|
"blocks for images (binary downloads like PDFs are refused — download then read). Long pages are cached " +
|
|
90
|
-
"per
|
|
90
|
+
"per desk as a snapshot; page through with offset (no refetch), or pass refresh:true for current content.",
|
|
91
91
|
parameters: webFetchSchema,
|
|
92
92
|
execute: async (_toolCallId, { url, extractMode, maxChars, offset, refresh, }, signal) => {
|
|
93
93
|
const request = resolveWebFetchRequest(options.webConfig.fetch, url, extractMode, maxChars);
|
|
94
94
|
const displayMaxChars = request.maxChars;
|
|
95
95
|
const startOffset = offset && offset > 0 ? offset : 0;
|
|
96
|
-
// Cache is per-
|
|
96
|
+
// Cache is per-desk; when no deskDir is available (e.g. sub-agent path) fall back to a
|
|
97
97
|
// plain single-shot fetch with the requested maxChars. An `offset` here would otherwise be
|
|
98
98
|
// silently dropped -- the caller gets the first screen back with no way to tell "reached
|
|
99
99
|
// the end" from "pagination just doesn't work here" (fix plan §4.5), and can spin retrying
|
|
100
100
|
// the same offset forever.
|
|
101
|
-
if (!options.
|
|
101
|
+
if (!options.deskDir) {
|
|
102
102
|
if (startOffset > 0) {
|
|
103
|
-
throw new RecoverableToolError("This context does not support web_fetch pagination (no per-
|
|
103
|
+
throw new RecoverableToolError("This context does not support web_fetch pagination (no per-desk cache available); " +
|
|
104
104
|
"offset is ignored here. Increase maxChars instead, or have the main agent fetch the page.");
|
|
105
105
|
}
|
|
106
106
|
return runWebFetch({
|
|
@@ -112,10 +112,10 @@ export function createWebFetchTool(options) {
|
|
|
112
112
|
}
|
|
113
113
|
const key = webCacheKey(url, request.extractMode);
|
|
114
114
|
if (refresh) {
|
|
115
|
-
await clearWebCacheEntry(options.
|
|
115
|
+
await clearWebCacheEntry(options.deskDir, key);
|
|
116
116
|
}
|
|
117
117
|
else {
|
|
118
|
-
const cached = await readWebCache(options.
|
|
118
|
+
const cached = await readWebCache(options.deskDir, key);
|
|
119
119
|
if (cached) {
|
|
120
120
|
return windowResult(cached, url, startOffset, displayMaxChars, true);
|
|
121
121
|
}
|
|
@@ -149,7 +149,7 @@ export function createWebFetchTool(options) {
|
|
|
149
149
|
contentType: result.details.contentType,
|
|
150
150
|
sourceTruncated: result.details.truncated === true,
|
|
151
151
|
};
|
|
152
|
-
await writeWebCache(options.
|
|
152
|
+
await writeWebCache(options.deskDir, key, entry);
|
|
153
153
|
return windowResult(entry, url, startOffset, displayMaxChars, false);
|
|
154
154
|
},
|
|
155
155
|
};
|
|
@@ -5,7 +5,7 @@ export async function writeContent(fileStore, path, content, signal, options) {
|
|
|
5
5
|
const securityConfig = options?.securityConfig ?? DEFAULT_SECURITY_CONFIG;
|
|
6
6
|
const securityContext = options?.securityContext ?? {
|
|
7
7
|
agentWorkspaceDir: process.cwd(),
|
|
8
|
-
|
|
8
|
+
cwd: process.cwd(),
|
|
9
9
|
};
|
|
10
10
|
const target = await checkPathGuard(path, "write", securityConfig, securityContext, {
|
|
11
11
|
tool: options?.toolName ?? "write",
|
package/dist/tui/cli.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `pipiclaw tui` CLI: argument parsing and entry. Parsing is a pure function
|
|
3
|
-
*
|
|
2
|
+
* `pipiclaw tui` CLI: argument parsing and entry. Parsing is a pure function (`parseTuiArgs`) so
|
|
3
|
+
* it can be unit-tested. The terminal is a client of the Web API (spec 061, D25): it connects to
|
|
4
|
+
* the daemon's socket, or — when no daemon is running — to a runtime it starts inside this
|
|
5
|
+
* process (D26, `startEmbeddedRuntime`, supplied by the entry so `tui/` never imports `runtime/`).
|
|
4
6
|
*/
|
|
5
|
-
import { type BootstrapIO } from "../app/home.js";
|
|
7
|
+
import { type BootstrapIO, type BootstrapPaths } from "../app/home.js";
|
|
6
8
|
export type ParsedTui = {
|
|
7
9
|
kind: "run";
|
|
8
|
-
|
|
10
|
+
desk?: string;
|
|
11
|
+
create: boolean;
|
|
12
|
+
fresh: boolean;
|
|
9
13
|
print: boolean;
|
|
10
14
|
quiet: boolean;
|
|
11
15
|
plain: boolean;
|
|
@@ -20,4 +24,12 @@ export type ParsedTui = {
|
|
|
20
24
|
};
|
|
21
25
|
/** Parse `pipiclaw tui` arguments (everything after the `tui` subcommand). */
|
|
22
26
|
export declare function parseTuiArgs(args: string[]): ParsedTui;
|
|
23
|
-
|
|
27
|
+
/** A runtime this process started for the terminal. */
|
|
28
|
+
export interface EmbeddedRuntimeHandle {
|
|
29
|
+
stop(): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
export interface TuiHooks {
|
|
32
|
+
/** Start the runtime in this process, or `undefined` when a daemon already holds the app home. */
|
|
33
|
+
startEmbeddedRuntime(paths: BootstrapPaths, io: BootstrapIO): Promise<EmbeddedRuntimeHandle | undefined>;
|
|
34
|
+
}
|
|
35
|
+
export declare function runTui(argv: string[], hooks: TuiHooks, io?: BootstrapIO, paths?: BootstrapPaths): Promise<void>;
|
package/dist/tui/cli.js
CHANGED
|
@@ -1,24 +1,43 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `pipiclaw tui` CLI: argument parsing and entry. Parsing is a pure function
|
|
3
|
-
*
|
|
2
|
+
* `pipiclaw tui` CLI: argument parsing and entry. Parsing is a pure function (`parseTuiArgs`) so
|
|
3
|
+
* it can be unit-tested. The terminal is a client of the Web API (spec 061, D25): it connects to
|
|
4
|
+
* the daemon's socket, or — when no daemon is running — to a runtime it starts inside this
|
|
5
|
+
* process (D26, `startEmbeddedRuntime`, supplied by the entry so `tui/` never imports `runtime/`).
|
|
4
6
|
*/
|
|
5
|
-
import { BootstrapExitError, readCliVersion } from "../app/home.js";
|
|
6
|
-
import {
|
|
7
|
+
import { BootstrapExitError, DEFAULT_BOOTSTRAP_PATHS, readCliVersion, } from "../app/home.js";
|
|
8
|
+
import { PipiclawSettingsManager } from "../config/settings.js";
|
|
9
|
+
import * as log from "../log.js";
|
|
10
|
+
import { errorMessage } from "../shared/text-utils.js";
|
|
11
|
+
import { createLink, createSocketClient, openConversation, printOnce, requireSocket } from "./client.js";
|
|
12
|
+
import { TUI_SLASH_COMMANDS } from "./commands.js";
|
|
13
|
+
import { traitsOf } from "./render.js";
|
|
14
|
+
import { createFrontend } from "./renderer.js";
|
|
15
|
+
import { TuiSession } from "./session.js";
|
|
7
16
|
/** Parse `pipiclaw tui` arguments (everything after the `tui` subcommand). */
|
|
8
17
|
export function parseTuiArgs(args) {
|
|
9
|
-
let
|
|
18
|
+
let desk;
|
|
19
|
+
let create = false;
|
|
20
|
+
let fresh = false;
|
|
10
21
|
let print = false;
|
|
11
22
|
let quiet = false;
|
|
12
23
|
let plain = false;
|
|
13
24
|
const positional = [];
|
|
14
25
|
for (let index = 0; index < args.length; index += 1) {
|
|
15
26
|
const arg = args[index];
|
|
16
|
-
if (arg === "--
|
|
17
|
-
|
|
27
|
+
if (arg === "--desk") {
|
|
28
|
+
desk = args[index + 1];
|
|
29
|
+
if (!desk || desk.startsWith("-"))
|
|
30
|
+
return { kind: "error", message: "--desk needs a name; omit it to open default." };
|
|
18
31
|
index += 1;
|
|
19
32
|
}
|
|
20
|
-
else if (arg.startsWith("--
|
|
21
|
-
|
|
33
|
+
else if (arg.startsWith("--desk=")) {
|
|
34
|
+
desk = arg.slice("--desk=".length);
|
|
35
|
+
}
|
|
36
|
+
else if (arg === "--create") {
|
|
37
|
+
create = true;
|
|
38
|
+
}
|
|
39
|
+
else if (arg === "--new") {
|
|
40
|
+
fresh = true;
|
|
22
41
|
}
|
|
23
42
|
else if (arg === "--print" || arg === "-p") {
|
|
24
43
|
print = true;
|
|
@@ -44,28 +63,27 @@ export function parseTuiArgs(args) {
|
|
|
44
63
|
positional.push(arg);
|
|
45
64
|
}
|
|
46
65
|
}
|
|
47
|
-
return { kind: "run",
|
|
66
|
+
return { kind: "run", desk, create, fresh, print, quiet, plain, positional };
|
|
48
67
|
}
|
|
49
68
|
function printTuiHelp(io) {
|
|
50
69
|
io.log("Usage: pipiclaw tui [options] [prompt]");
|
|
51
70
|
io.log("");
|
|
52
|
-
io.log("Chat with the pipiclaw agent in the terminal,
|
|
53
|
-
io.log("
|
|
71
|
+
io.log("Chat with the pipiclaw agent in the terminal, using the same config and the");
|
|
72
|
+
io.log("same assistant as the DingTalk runtime.");
|
|
54
73
|
io.log("");
|
|
55
|
-
io.log("
|
|
56
|
-
io.log("
|
|
57
|
-
io.log("
|
|
58
|
-
io.log("
|
|
74
|
+
io.log("The terminal is a client of the Web API's local socket. With a daemon running it");
|
|
75
|
+
io.log("connects to it; otherwise it runs the runtime itself until you exit. It opens the");
|
|
76
|
+
io.log("default desk and resumes this desk's last conversation, sharing the desk's memory,");
|
|
77
|
+
io.log("tasks and files with the channels bound to it.");
|
|
59
78
|
io.log("");
|
|
60
79
|
io.log("Options:");
|
|
61
|
-
io.log(" --
|
|
62
|
-
io.log("
|
|
80
|
+
io.log(" --desk <name> Open a desk (default: default)");
|
|
81
|
+
io.log(" --create Create the desk first (like `/desk new`)");
|
|
82
|
+
io.log(" --new Start a new conversation instead of resuming");
|
|
63
83
|
io.log(" --print, -p One-shot: run [prompt] (or stdin), print the answer, exit");
|
|
64
84
|
io.log(" --plain Use the line-based frontend instead of the full-screen UI");
|
|
65
85
|
io.log(" --quiet, -q Print only the final answer, no progress (implies --plain)");
|
|
66
86
|
io.log(" --version Print the version and exit");
|
|
67
|
-
io.log("");
|
|
68
|
-
io.log("Note: do not attach --channel to a DingTalk conversation the daemon is actively serving.");
|
|
69
87
|
}
|
|
70
88
|
async function readStdin() {
|
|
71
89
|
const chunks = [];
|
|
@@ -74,7 +92,7 @@ async function readStdin() {
|
|
|
74
92
|
}
|
|
75
93
|
return Buffer.concat(chunks).toString("utf8");
|
|
76
94
|
}
|
|
77
|
-
export async function runTui(argv, io = console) {
|
|
95
|
+
export async function runTui(argv, hooks, io = console, paths = DEFAULT_BOOTSTRAP_PATHS) {
|
|
78
96
|
const parsed = parseTuiArgs(argv.slice(3));
|
|
79
97
|
if (parsed.kind === "help") {
|
|
80
98
|
printTuiHelp(io);
|
|
@@ -93,12 +111,57 @@ export async function runTui(argv, io = console) {
|
|
|
93
111
|
if (parsed.print && !initialPrompt && process.stdin.isTTY !== true) {
|
|
94
112
|
initialPrompt = (await readStdin()).trim() || undefined;
|
|
95
113
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
114
|
+
// The pi-tui frontend owns stdout; the plain frontend prints only the final answer. Either way
|
|
115
|
+
// the console log sink would corrupt the output, so logging goes to its file sink only.
|
|
116
|
+
log.setConsoleLoggingEnabled(false);
|
|
117
|
+
const embedded = await hooks.startEmbeddedRuntime(paths, io);
|
|
118
|
+
try {
|
|
119
|
+
if (!embedded)
|
|
120
|
+
requireSocket(paths, io);
|
|
121
|
+
try {
|
|
122
|
+
await runClient(parsed, initialPrompt, paths, io);
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
if (error instanceof BootstrapExitError)
|
|
126
|
+
throw error;
|
|
127
|
+
// A refused or failed request is a message for the user, not a stack trace.
|
|
128
|
+
io.error(errorMessage(error));
|
|
129
|
+
throw new BootstrapExitError(1);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
if (embedded) {
|
|
134
|
+
process.stderr.write("正在关闭运行时…\n");
|
|
135
|
+
await embedded.stop();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async function runClient(parsed, initialPrompt, paths, io) {
|
|
140
|
+
const client = createSocketClient(paths);
|
|
141
|
+
const { id, replies } = await openConversation(client, paths, { desk: parsed.desk, create: parsed.create, fresh: parsed.fresh }, io);
|
|
142
|
+
if (parsed.print) {
|
|
143
|
+
const frontend = createFrontend({ plain: true, quiet: parsed.quiet, interactive: false });
|
|
144
|
+
for (const reply of replies)
|
|
145
|
+
frontend.showNotice(reply);
|
|
146
|
+
if (initialPrompt)
|
|
147
|
+
frontend.showFinal(await printOnce(client, id, initialPrompt));
|
|
148
|
+
frontend.stop();
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const frontend = createFrontend({
|
|
100
152
|
plain: parsed.plain,
|
|
101
|
-
|
|
102
|
-
|
|
153
|
+
quiet: parsed.quiet,
|
|
154
|
+
interactive: true,
|
|
155
|
+
commands: TUI_SLASH_COMMANDS,
|
|
156
|
+
basePath: paths.workspaceDir,
|
|
157
|
+
});
|
|
158
|
+
const traits = traitsOf(new PipiclawSettingsManager(paths.appHomeDir).getTuiSettings().responseMode);
|
|
159
|
+
const session = new TuiSession({
|
|
160
|
+
link: createLink(client, paths, id),
|
|
161
|
+
frontend,
|
|
162
|
+
traits,
|
|
163
|
+
label: `终端 · ${parsed.desk ?? "default"}`,
|
|
164
|
+
notices: replies,
|
|
103
165
|
});
|
|
166
|
+
await session.startInteractive(initialPrompt);
|
|
104
167
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import OpenAI from "openai";
|
|
2
|
+
import { type BootstrapIO, type BootstrapPaths } from "../app/home.js";
|
|
3
|
+
import type { SessionLink } from "./session.js";
|
|
4
|
+
export interface OpenOptions {
|
|
5
|
+
/** The desk to work in; defaults to `default`. */
|
|
6
|
+
desk?: string;
|
|
7
|
+
/** Create the desk first — an explicit creation, like `/desk new`. */
|
|
8
|
+
create: boolean;
|
|
9
|
+
/** Start a new conversation instead of resuming the desk's last one. */
|
|
10
|
+
fresh: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** The SDK client for the local socket; the socket needs no key. */
|
|
13
|
+
export declare function createSocketClient(paths: BootstrapPaths): OpenAI;
|
|
14
|
+
export declare function requireSocket(paths: BootstrapPaths, io: BootstrapIO): void;
|
|
15
|
+
export declare function createLink(client: OpenAI, paths: BootstrapPaths, conversationId: string): SessionLink;
|
|
16
|
+
/**
|
|
17
|
+
* Find or make the conversation for `--desk`: resume the desk's last one while it is still bound
|
|
18
|
+
* to that desk, else start one and bind it (`/desk new` first with `--create`). Returns the
|
|
19
|
+
* conversation and what the server said while setting it up.
|
|
20
|
+
*/
|
|
21
|
+
export declare function openConversation(client: OpenAI, paths: BootstrapPaths, options: OpenOptions, io: BootstrapIO): Promise<{
|
|
22
|
+
id: string;
|
|
23
|
+
replies: string[];
|
|
24
|
+
}>;
|
|
25
|
+
/** `--print`: one synchronous request, the answer on stdout. */
|
|
26
|
+
export declare function printOnce(client: OpenAI, conversationId: string, prompt: string): Promise<string>;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The terminal's connection to the Web API (spec 061, D25): the official SDK over the daemon's
|
|
3
|
+
* local socket, the conversation it keeps per desk (`state/tui/conversations.json`), and the
|
|
4
|
+
* one-shot `--print` request. The terminal holds no runtime of its own — what it shows is what a
|
|
5
|
+
* script using the same API would get.
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
8
|
+
import { connect } from "node:net";
|
|
9
|
+
import { dirname, join } from "node:path";
|
|
10
|
+
import OpenAI from "openai";
|
|
11
|
+
import { ResponsesWS } from "openai/resources/responses/ws";
|
|
12
|
+
import { Agent, fetch as undiciFetch } from "undici";
|
|
13
|
+
import { BootstrapExitError } from "../app/home.js";
|
|
14
|
+
import { loadBindings } from "../desk/bindings.js";
|
|
15
|
+
import { DEFAULT_DESK, isDeskName, normalizeDeskName } from "../desk/paths.js";
|
|
16
|
+
import { webapiSocketPath } from "../paths.js";
|
|
17
|
+
import { writeFileAtomically } from "../shared/atomic-file.js";
|
|
18
|
+
import { isPlainObject } from "../shared/type-guards.js";
|
|
19
|
+
const stateFile = (paths) => join(paths.appHomeDir, "state", "tui", "conversations.json");
|
|
20
|
+
/** Desk name → the conversation this terminal last used in it. */
|
|
21
|
+
function readState(paths) {
|
|
22
|
+
try {
|
|
23
|
+
const parsed = JSON.parse(readFileSync(stateFile(paths), "utf-8"));
|
|
24
|
+
if (!isPlainObject(parsed))
|
|
25
|
+
return {};
|
|
26
|
+
return Object.fromEntries(Object.entries(parsed).filter(([, value]) => typeof value === "string"));
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function writeState(paths, state) {
|
|
33
|
+
mkdirSync(dirname(stateFile(paths)), { recursive: true });
|
|
34
|
+
await writeFileAtomically(stateFile(paths), `${JSON.stringify(state, null, 2)}\n`);
|
|
35
|
+
}
|
|
36
|
+
/** The SDK client for the local socket; the socket needs no key. */
|
|
37
|
+
export function createSocketClient(paths) {
|
|
38
|
+
const dispatcher = new Agent({ connect: { socketPath: webapiSocketPath(paths.appHomeDir) } });
|
|
39
|
+
return new OpenAI({
|
|
40
|
+
apiKey: "local-socket",
|
|
41
|
+
baseURL: "http://localhost/v1",
|
|
42
|
+
maxRetries: 0,
|
|
43
|
+
// A synchronous `--print` request lasts as long as the agent works.
|
|
44
|
+
timeout: 30 * 60 * 1000,
|
|
45
|
+
// Node's built-in fetch cannot take an npm undici dispatcher; the npm one can.
|
|
46
|
+
fetch: undiciFetch,
|
|
47
|
+
fetchOptions: { dispatcher },
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
export function requireSocket(paths, io) {
|
|
51
|
+
const socketPath = webapiSocketPath(paths.appHomeDir);
|
|
52
|
+
if (existsSync(socketPath))
|
|
53
|
+
return;
|
|
54
|
+
io.error([
|
|
55
|
+
`Cannot reach the Web API socket (${socketPath}).`,
|
|
56
|
+
"A Pipiclaw daemon is running, but it has no Web API socket. Either:",
|
|
57
|
+
' - set `"webapi": { "enabled": true, "socket": true }` in channel.json and restart the daemon, or',
|
|
58
|
+
" - stop the daemon, and `pipiclaw tui` will run the runtime itself.",
|
|
59
|
+
].join("\n"));
|
|
60
|
+
throw new BootstrapExitError(1);
|
|
61
|
+
}
|
|
62
|
+
/** Wrap the SDK's WebSocket as the session's `Connection`. */
|
|
63
|
+
function openConnection(client, socketPath, onEvent, onClose) {
|
|
64
|
+
const ws = new ResponsesWS(client, { createConnection: () => connect(socketPath) });
|
|
65
|
+
ws.on("event", (event) => onEvent(event));
|
|
66
|
+
ws.on("error", () => undefined);
|
|
67
|
+
ws.on("close", () => onClose());
|
|
68
|
+
return {
|
|
69
|
+
send: (event) => ws.send(event),
|
|
70
|
+
close: () => ws.close(),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export function createLink(client, paths, conversationId) {
|
|
74
|
+
const socketPath = webapiSocketPath(paths.appHomeDir);
|
|
75
|
+
return {
|
|
76
|
+
conversationId,
|
|
77
|
+
connect: (onEvent, onClose) => openConnection(client, socketPath, onEvent, onClose),
|
|
78
|
+
// The runtime removes its socket when it shuts down.
|
|
79
|
+
reachable: () => existsSync(socketPath),
|
|
80
|
+
async lastItemId() {
|
|
81
|
+
const page = await client.conversations.items.list(conversationId, { order: "desc", limit: 1 });
|
|
82
|
+
return page.data[0]?.id;
|
|
83
|
+
},
|
|
84
|
+
async listItems(after) {
|
|
85
|
+
const items = [];
|
|
86
|
+
let cursor = after;
|
|
87
|
+
for (;;) {
|
|
88
|
+
const page = await client.conversations.items.list(conversationId, {
|
|
89
|
+
order: "asc",
|
|
90
|
+
limit: 100,
|
|
91
|
+
...(cursor ? { after: cursor } : {}),
|
|
92
|
+
});
|
|
93
|
+
items.push(...page.data);
|
|
94
|
+
if (!page.has_more || page.data.length === 0)
|
|
95
|
+
return items;
|
|
96
|
+
cursor = page.data.at(-1)?.id;
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/** The desk a conversation is bound to, read from the workspace's bindings (the terminal never writes them). */
|
|
102
|
+
async function boundDesk(paths, conversationId) {
|
|
103
|
+
const { bindings } = await loadBindings(paths.workspaceDir);
|
|
104
|
+
const entry = Object.entries(bindings).find(([channelId]) => channelId.endsWith(`:${conversationId}`));
|
|
105
|
+
return entry?.[1].desk;
|
|
106
|
+
}
|
|
107
|
+
/** One request, answered synchronously; the reply text. */
|
|
108
|
+
async function ask(client, conversationId, input) {
|
|
109
|
+
const response = await client.responses.create({ model: "pipiclaw", conversation: conversationId, input });
|
|
110
|
+
if (response.status !== "completed") {
|
|
111
|
+
throw new Error(response.error?.message ?? `The request ended as ${response.status}.`);
|
|
112
|
+
}
|
|
113
|
+
return response.output_text;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Find or make the conversation for `--desk`: resume the desk's last one while it is still bound
|
|
117
|
+
* to that desk, else start one and bind it (`/desk new` first with `--create`). Returns the
|
|
118
|
+
* conversation and what the server said while setting it up.
|
|
119
|
+
*/
|
|
120
|
+
export async function openConversation(client, paths, options, io) {
|
|
121
|
+
const fail = (message) => {
|
|
122
|
+
io.error(message);
|
|
123
|
+
throw new BootstrapExitError(1);
|
|
124
|
+
};
|
|
125
|
+
const desk = normalizeDeskName(options.desk ?? DEFAULT_DESK);
|
|
126
|
+
if (!isDeskName(desk)) {
|
|
127
|
+
fail(`Invalid desk name "${desk}": use 1-32 lowercase letters, digits or hyphens, not starting or ending with "-".`);
|
|
128
|
+
}
|
|
129
|
+
const state = readState(paths);
|
|
130
|
+
if (!options.fresh && !options.create && state[desk]) {
|
|
131
|
+
const id = state[desk];
|
|
132
|
+
const exists = await client.conversations.retrieve(id).then(() => true, (error) => (error.status === 404 ? false : Promise.reject(error)));
|
|
133
|
+
// A conversation rebound to another desk since is not this desk's any more.
|
|
134
|
+
const bound = exists ? await boundDesk(paths, id) : undefined;
|
|
135
|
+
if (exists && (bound === desk || (bound === undefined && desk === DEFAULT_DESK)))
|
|
136
|
+
return { id, replies: [] };
|
|
137
|
+
}
|
|
138
|
+
const id = (await client.conversations.create({})).id;
|
|
139
|
+
const replies = [];
|
|
140
|
+
// A conversation starts on the default desk by itself; any other desk is an explicit request.
|
|
141
|
+
if (desk !== DEFAULT_DESK || options.create) {
|
|
142
|
+
if (options.create)
|
|
143
|
+
replies.push(await ask(client, id, `/desk new ${desk}`));
|
|
144
|
+
replies.push(await ask(client, id, `/desk bind ${desk}`));
|
|
145
|
+
if ((await boundDesk(paths, id)) !== desk) {
|
|
146
|
+
for (const reply of replies)
|
|
147
|
+
io.error(reply);
|
|
148
|
+
fail(`Could not open desk "${desk}".`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
await writeState(paths, { ...state, [desk]: id });
|
|
152
|
+
return { id, replies };
|
|
153
|
+
}
|
|
154
|
+
/** `--print`: one synchronous request, the answer on stdout. */
|
|
155
|
+
export async function printOnce(client, conversationId, prompt) {
|
|
156
|
+
return ask(client, conversationId, prompt);
|
|
157
|
+
}
|
package/dist/tui/colors.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ export declare const dim: (text: string) => string;
|
|
|
3
3
|
export declare const italic: (text: string) => string;
|
|
4
4
|
export declare const underline: (text: string) => string;
|
|
5
5
|
export declare const strikethrough: (text: string) => string;
|
|
6
|
-
export declare const red: (text: string) => string;
|
|
7
6
|
export declare const yellow: (text: string) => string;
|
|
8
7
|
export declare const cyan: (text: string) => string;
|
|
9
8
|
export declare const gray: (text: string) => string;
|
package/dist/tui/colors.js
CHANGED
|
@@ -14,7 +14,6 @@ export const dim = sgr(2, 22);
|
|
|
14
14
|
export const italic = sgr(3, 23);
|
|
15
15
|
export const underline = sgr(4, 24);
|
|
16
16
|
export const strikethrough = sgr(9, 29);
|
|
17
|
-
export const red = sgr(31);
|
|
18
17
|
export const yellow = sgr(33);
|
|
19
18
|
export const cyan = sgr(36);
|
|
20
19
|
export const gray = sgr(90);
|
package/dist/tui/commands.d.ts
CHANGED
|
@@ -1,63 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Transport-layer commands (`/help /stop /steer /followup /status /usage
|
|
5
|
-
* /events`, plus the TUI-only `/exit`) are handled locally and never reach the
|
|
6
|
-
* runner. Everything else — session commands (`/model /new /compact /session`)
|
|
7
|
-
* and plain messages — becomes a `run` intent; the SDK command extension handles
|
|
8
|
-
* session commands inside the turn (results are delivered back through the
|
|
9
|
-
* channel context), so the TUI gets them for free.
|
|
10
|
-
*
|
|
11
|
-
* `dispatch` is pure over its injected deps: it returns an intent the app acts
|
|
12
|
-
* on, and renders info-command text via the deps. Steer/followup semantics
|
|
13
|
-
* depend on whether a turn is running, which only the app knows — so those come
|
|
14
|
-
* back as intents rather than being applied here.
|
|
15
|
-
*/
|
|
16
|
-
import { type RuntimeCommandName } from "../commands/catalog.js";
|
|
17
|
-
export type DispatchOutcome =
|
|
18
|
-
/** Text to show the user immediately (help/status/usage/events output, or a hint). */
|
|
19
|
-
{
|
|
20
|
-
kind: "reply";
|
|
1
|
+
export type Intent = {
|
|
2
|
+
kind: "send";
|
|
21
3
|
text: string;
|
|
22
|
-
}
|
|
23
|
-
/** Send this text to the runner as a normal turn. */
|
|
24
|
-
| {
|
|
25
|
-
kind: "run";
|
|
26
|
-
text: string;
|
|
27
|
-
}
|
|
28
|
-
/** Steer the in-flight turn (app falls back to `run` when idle). */
|
|
29
|
-
| {
|
|
4
|
+
} | {
|
|
30
5
|
kind: "steer";
|
|
31
6
|
text: string;
|
|
32
|
-
}
|
|
33
|
-
/** Queue this to run after the current turn (app runs it now when idle). */
|
|
34
|
-
| {
|
|
7
|
+
} | {
|
|
35
8
|
kind: "followup";
|
|
36
9
|
text: string;
|
|
37
|
-
}
|
|
38
|
-
/** Abort the in-flight turn. */
|
|
39
|
-
| {
|
|
10
|
+
} | {
|
|
40
11
|
kind: "stop";
|
|
41
|
-
}
|
|
42
|
-
/** Leave the TUI. */
|
|
43
|
-
| {
|
|
12
|
+
} | {
|
|
44
13
|
kind: "exit";
|
|
45
|
-
}
|
|
46
|
-
/** Nothing to do; optional hint to show. */
|
|
47
|
-
| {
|
|
14
|
+
} | {
|
|
48
15
|
kind: "noop";
|
|
49
|
-
|
|
16
|
+
hint?: string;
|
|
50
17
|
};
|
|
51
|
-
export
|
|
52
|
-
|
|
53
|
-
/** The stateless report commands (`/status /context /usage /events /tasks /subagents /project /skills`). */
|
|
54
|
-
runReport(name: RuntimeCommandName, args: string): Promise<string>;
|
|
55
|
-
}
|
|
56
|
-
export declare function dispatch(input: string, deps: DispatchDeps): Promise<DispatchOutcome>;
|
|
57
|
-
/**
|
|
58
|
-
* Slash commands offered in editor autocomplete: transport + session (both
|
|
59
|
-
* derived from the shared command tables) plus the TUI-only `/exit`.
|
|
60
|
-
*/
|
|
18
|
+
export declare function interpret(input: string): Intent;
|
|
19
|
+
/** Slash commands offered in editor autocomplete: the server's, plus the terminal's own `/exit`. */
|
|
61
20
|
export declare const TUI_SLASH_COMMANDS: Array<{
|
|
62
21
|
name: string;
|
|
63
22
|
description: string;
|
package/dist/tui/commands.js
CHANGED
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* runner. Everything else — session commands (`/model /new /compact /session`)
|
|
7
|
-
* and plain messages — becomes a `run` intent; the SDK command extension handles
|
|
8
|
-
* session commands inside the turn (results are delivered back through the
|
|
9
|
-
* channel context), so the TUI gets them for free.
|
|
10
|
-
*
|
|
11
|
-
* `dispatch` is pure over its injected deps: it returns an intent the app acts
|
|
12
|
-
* on, and renders info-command text via the deps. Steer/followup semantics
|
|
13
|
-
* depend on whether a turn is running, which only the app knows — so those come
|
|
14
|
-
* back as intents rather than being applied here.
|
|
2
|
+
* What the terminal does with a line of input. Only `/exit`, `/quit`, `/stop`, `/steer` and
|
|
3
|
+
* `/followup` mean something to the terminal itself — they are about this connection and its
|
|
4
|
+
* turn. Every other line, slash command or not, goes to the server as the next message, which is
|
|
5
|
+
* the one place that knows what a command means (spec 061, D25).
|
|
15
6
|
*/
|
|
16
7
|
import { BUILT_IN_COMMANDS, formatMissingQueueMessage, parseBuiltInCommand, SESSION_COMMANDS, } from "../commands/catalog.js";
|
|
17
|
-
export
|
|
8
|
+
export function interpret(input) {
|
|
18
9
|
const trimmed = input.trim();
|
|
19
10
|
if (!trimmed)
|
|
20
11
|
return { kind: "noop" };
|
|
@@ -22,41 +13,27 @@ export async function dispatch(input, deps) {
|
|
|
22
13
|
if (lower === "/exit" || lower === "/quit")
|
|
23
14
|
return { kind: "exit" };
|
|
24
15
|
const command = parseBuiltInCommand(trimmed);
|
|
25
|
-
|
|
26
|
-
// Session commands (/model, /new, /compact, /session) and plain messages.
|
|
27
|
-
return { kind: "run", text: input };
|
|
28
|
-
}
|
|
29
|
-
switch (command.name) {
|
|
30
|
-
case "help":
|
|
31
|
-
return { kind: "reply", text: deps.renderHelp(command.args) };
|
|
32
|
-
case "status":
|
|
33
|
-
case "context":
|
|
34
|
-
case "usage":
|
|
35
|
-
case "events":
|
|
36
|
-
case "tasks":
|
|
37
|
-
case "subagents":
|
|
38
|
-
case "project":
|
|
39
|
-
case "skills":
|
|
40
|
-
return { kind: "reply", text: await deps.runReport(command.name, command.args) };
|
|
16
|
+
switch (command?.name) {
|
|
41
17
|
case "stop":
|
|
42
18
|
return { kind: "stop" };
|
|
43
19
|
case "steer":
|
|
44
20
|
return command.args.trim()
|
|
45
21
|
? { kind: "steer", text: command.args }
|
|
46
|
-
: { kind: "noop",
|
|
22
|
+
: { kind: "noop", hint: formatMissingQueueMessage("steer") };
|
|
47
23
|
case "followup":
|
|
48
24
|
return command.args.trim()
|
|
49
25
|
? { kind: "followup", text: command.args }
|
|
50
|
-
: { kind: "noop",
|
|
26
|
+
: { kind: "noop", hint: formatMissingQueueMessage("followup") };
|
|
27
|
+
default:
|
|
28
|
+
return { kind: "send", text: input };
|
|
51
29
|
}
|
|
52
30
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
*/
|
|
31
|
+
const toAutocompleteEntry = (spec) => ({
|
|
32
|
+
name: spec.name,
|
|
33
|
+
description: spec.description,
|
|
34
|
+
argumentHint: spec.argumentHint,
|
|
35
|
+
});
|
|
36
|
+
/** Slash commands offered in editor autocomplete: the server's, plus the terminal's own `/exit`. */
|
|
60
37
|
export const TUI_SLASH_COMMANDS = [
|
|
61
38
|
...BUILT_IN_COMMANDS.map(toAutocompleteEntry),
|
|
62
39
|
...SESSION_COMMANDS.map(toAutocompleteEntry),
|
package/dist/tui/frontend.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Rendering + input contracts for the terminal TUI.
|
|
3
3
|
*
|
|
4
|
-
* `TranscriptRenderer` is the output-only surface the
|
|
5
|
-
* (`
|
|
4
|
+
* `TranscriptRenderer` is the output-only surface the event renderer
|
|
5
|
+
* (`render.ts`) writes to — progress, final answers, notices. It is
|
|
6
6
|
* deliberately small so it is trivial to fake in tests.
|
|
7
7
|
*
|
|
8
8
|
* `Frontend` is the full interactive shell the app drives: a `TranscriptRenderer`
|
package/dist/tui/frontend.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Rendering + input contracts for the terminal TUI.
|
|
3
3
|
*
|
|
4
|
-
* `TranscriptRenderer` is the output-only surface the
|
|
5
|
-
* (`
|
|
4
|
+
* `TranscriptRenderer` is the output-only surface the event renderer
|
|
5
|
+
* (`render.ts`) writes to — progress, final answers, notices. It is
|
|
6
6
|
* deliberately small so it is trivial to fake in tests.
|
|
7
7
|
*
|
|
8
8
|
* `Frontend` is the full interactive shell the app drives: a `TranscriptRenderer`
|