@oyasmi/pipiclaw 0.9.5 → 0.9.6-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 +300 -142
- package/README.md +295 -140
- package/dist/agent/builtin-commands.d.ts +1 -1
- package/dist/agent/builtin-commands.js +1 -1
- package/dist/agent/channel-runner.d.ts +4 -3
- package/dist/agent/channel-runner.js +17 -28
- package/dist/agent/maintenance-context.js +2 -2
- package/dist/agent/prompt/builder.d.ts +1 -1
- package/dist/agent/prompt/builder.js +1 -1
- package/dist/agent/prompt/extension.d.ts +1 -1
- package/dist/agent/prompt/extension.js +1 -1
- package/dist/agent/prompt/manifest.d.ts +6 -1
- package/dist/agent/prompt/manifest.js +12 -5
- package/dist/agent/prompt/resources.d.ts +0 -3
- package/dist/agent/prompt/resources.js +0 -6
- package/dist/agent/prompt/sections.d.ts +2 -2
- package/dist/agent/prompt/sections.js +36 -26
- package/dist/agent/prompt/types.d.ts +3 -2
- package/dist/agent/runner-factory.js +1 -1
- package/dist/agent/session/command-extension.js +3 -1
- package/dist/agent/session/compaction-summary.js +3 -6
- package/dist/agent/session/compaction.d.ts +2 -0
- package/dist/agent/session/compaction.js +22 -14
- package/dist/agent/session/event-guards.d.ts +2 -1
- package/dist/agent/session/event-guards.js +6 -0
- package/dist/agent/session/model-selection.d.ts +2 -1
- package/dist/agent/session/model-selection.js +5 -5
- package/dist/agent/session/session-events.js +31 -4
- package/dist/agent/session/session-host.d.ts +5 -3
- package/dist/agent/session/session-host.js +20 -16
- package/dist/agent/status-render.js +3 -0
- package/dist/agent/stop-watchdog.js +5 -1
- package/dist/agent/turn/task-digest.d.ts +2 -5
- package/dist/agent/turn/task-digest.js +25 -45
- package/dist/agent/turn/turn-context.js +4 -6
- package/dist/agent/turn/turn-error.d.ts +1 -1
- package/dist/agent/turn/turn-error.js +9 -0
- package/dist/agent/turn/turn-pipeline.d.ts +10 -5
- package/dist/agent/turn/turn-pipeline.js +36 -7
- package/dist/agent/turn/turn-prompt.d.ts +2 -0
- package/dist/agent/turn/turn-prompt.js +2 -1
- package/dist/agent/turn/turn-recovery.js +4 -1
- package/dist/agent/turn/turn-state.d.ts +2 -0
- package/dist/agent/turn/turn-state.js +2 -1
- package/dist/agent/types.d.ts +23 -3
- package/dist/agent/types.js +2 -0
- package/dist/app/auth-command.d.ts +25 -0
- package/dist/app/auth-command.js +200 -67
- package/dist/app/home.d.ts +7 -8
- package/dist/app/home.js +143 -56
- package/dist/channel/attachments.d.ts +4 -0
- package/dist/channel/attachments.js +4 -0
- package/dist/channel/channel-context.d.ts +6 -0
- package/dist/channel/config.d.ts +3 -0
- package/dist/channel/config.js +11 -5
- package/dist/channel/store.d.ts +1 -1
- package/dist/commands/catalog.js +42 -10
- package/dist/commands/router.js +5 -1
- package/dist/desk/commands.d.ts +44 -5
- package/dist/desk/commands.js +162 -28
- package/dist/desk/paths.d.ts +6 -0
- package/dist/desk/paths.js +21 -1
- package/dist/desk/registry.d.ts +17 -2
- package/dist/desk/registry.js +122 -12
- package/dist/desk/types.d.ts +83 -1
- package/dist/dingtalk/bot.d.ts +1 -1
- package/dist/dingtalk/bot.js +4 -3
- package/dist/dingtalk/config.js +10 -10
- package/dist/dingtalk/delivery.js +15 -8
- package/dist/dingtalk/inbound-media.d.ts +36 -14
- package/dist/dingtalk/inbound-media.js +71 -12
- package/dist/dingtalk/inbound.d.ts +9 -2
- package/dist/dingtalk/inbound.js +17 -2
- package/dist/dingtalk/media.d.ts +4 -10
- package/dist/dingtalk/media.js +58 -32
- package/dist/events/commands.d.ts +2 -0
- package/dist/events/commands.js +13 -8
- package/dist/events/history.d.ts +9 -0
- package/dist/events/history.js +66 -0
- package/dist/events/parse.js +7 -3
- package/dist/events/types.d.ts +3 -0
- package/dist/events/watcher.d.ts +4 -8
- package/dist/events/watcher.js +53 -58
- package/dist/jobs/kill.d.ts +23 -0
- package/dist/jobs/kill.js +65 -0
- package/dist/jobs/manager.d.ts +19 -18
- package/dist/jobs/manager.js +36 -103
- package/dist/main.js +15 -3
- package/dist/memory/boundary-work.d.ts +2 -1
- package/dist/memory/boundary-work.js +1 -1
- package/dist/memory/lifecycle.d.ts +2 -1
- package/dist/memory/lifecycle.js +2 -2
- package/dist/memory/reflect-job.d.ts +2 -1
- package/dist/memory/reflect-job.js +1 -1
- package/dist/memory/reflect.d.ts +2 -1
- package/dist/memory/reflect.js +25 -4
- package/dist/memory/scheduler.d.ts +2 -1
- package/dist/memory/scheduler.js +1 -1
- package/dist/memory/session-corpus.d.ts +1 -1
- package/dist/memory/session-corpus.js +76 -1
- package/dist/memory/session-search.d.ts +2 -1
- package/dist/memory/session-search.js +14 -12
- package/dist/memory/sidecar-worker.d.ts +2 -1
- package/dist/memory/sidecar-worker.js +2 -4
- package/dist/memory/store.d.ts +2 -0
- package/dist/memory/store.js +19 -9
- package/dist/models/credential-work.d.ts +7 -0
- package/dist/models/credential-work.js +36 -0
- package/dist/models/login-ui.js +4 -4
- package/dist/models/provider-login.js +7 -6
- package/dist/models/requests.d.ts +8 -0
- package/dist/models/requests.js +69 -0
- package/dist/models/runtime.d.ts +3 -1
- package/dist/models/runtime.js +9 -2
- package/dist/playbooks/agent-delegation.md +20 -45
- package/dist/playbooks/background-jobs.md +1 -1
- package/dist/playbooks/catalog.js +1 -1
- package/dist/playbooks/delegation-inline.md +25 -0
- package/dist/playbooks/delegation-recovery.md +28 -0
- package/dist/playbooks/event-scheduling.md +18 -37
- package/dist/playbooks/event-sensors.md +26 -0
- package/dist/playbooks/event-task-template.md +22 -0
- package/dist/playbooks/learning-and-skills.md +26 -0
- package/dist/playbooks/memory-operations.md +36 -0
- package/dist/playbooks/outbound-media.md +2 -2
- package/dist/playbooks/runtime-files.md +29 -0
- package/dist/playbooks/runtime-operations.md +25 -0
- package/dist/playbooks/runtime-orientation.md +18 -53
- package/dist/playbooks/task-lead.md +22 -68
- package/dist/playbooks/task-manage.md +38 -0
- package/dist/playbooks/task-recovery.md +24 -0
- package/dist/playbooks/task-verify.md +22 -0
- package/dist/runtime/bootstrap.d.ts +10 -0
- package/dist/runtime/bootstrap.js +93 -29
- package/dist/runtime/daemon-lock.js +3 -3
- package/dist/runtime/desk-runtime.d.ts +40 -7
- package/dist/runtime/desk-runtime.js +330 -44
- package/dist/runtime/durable-dispatch.d.ts +14 -2
- package/dist/runtime/durable-dispatch.js +207 -65
- package/dist/runtime/ingress-busy.js +17 -8
- package/dist/runtime/ingress-commands.js +24 -4
- package/dist/runtime/ingress-deps.d.ts +4 -1
- package/dist/runtime/ingress.js +6 -1
- package/dist/runtime/request-execution.js +7 -6
- package/dist/runtime/shutdown.d.ts +4 -1
- package/dist/runtime/shutdown.js +88 -35
- package/dist/runtime/task-close.d.ts +1 -1
- package/dist/runtime/task-close.js +6 -3
- package/dist/runtime/task-control.d.ts +2 -3
- package/dist/runtime/task-control.js +38 -11
- package/dist/runtime/task-input.js +1 -1
- package/dist/runtime/task-lane-types.d.ts +12 -2
- package/dist/runtime/task-lane-types.js +9 -0
- package/dist/runtime/task-lane.d.ts +2 -0
- package/dist/runtime/task-lane.js +38 -20
- package/dist/runtime/task-step.d.ts +3 -3
- package/dist/runtime/task-step.js +34 -16
- package/dist/runtime/transports.js +6 -5
- package/dist/runtime/turn-run.js +103 -66
- package/dist/security/command-guard.d.ts +1 -1
- package/dist/security/command-guard.js +259 -314
- package/dist/security/path-guard.js +48 -7
- package/dist/security/shell-parse.d.ts +10 -0
- package/dist/security/shell-parse.js +224 -0
- package/dist/security/types.d.ts +2 -0
- package/dist/subagents/commands.d.ts +1 -1
- package/dist/subagents/commands.js +14 -5
- package/dist/subagents/completion-wake.js +6 -0
- package/dist/subagents/detached-discovery.d.ts +1 -1
- package/dist/subagents/discovery.d.ts +18 -199
- package/dist/subagents/discovery.js +35 -289
- package/dist/subagents/dispatch.d.ts +1 -2
- package/dist/subagents/dispatch.js +50 -29
- package/dist/subagents/external/antigravity-cli.d.ts +2 -0
- package/dist/subagents/external/antigravity-cli.js +517 -0
- package/dist/subagents/external/claude-code.js +8 -17
- package/dist/subagents/external/codex-cli.js +8 -18
- package/dist/subagents/external/cursor-cli.js +34 -31
- package/dist/subagents/external/dispatch.d.ts +21 -7
- package/dist/subagents/external/dispatch.js +146 -12
- package/dist/subagents/external/exec.js +3 -0
- package/dist/subagents/external/harness.d.ts +57 -33
- package/dist/subagents/external/harness.js +69 -40
- package/dist/subagents/external/reconciliation.js +1 -0
- package/dist/subagents/external/registry.js +4 -1
- package/dist/subagents/external/role-warnings.d.ts +4 -13
- package/dist/subagents/external/role-warnings.js +4 -28
- package/dist/subagents/external/run.d.ts +1 -2
- package/dist/subagents/external/run.js +16 -26
- package/dist/subagents/external/settlement.d.ts +2 -0
- package/dist/subagents/external/settlement.js +13 -3
- package/dist/subagents/format.d.ts +1 -1
- package/dist/subagents/format.js +1 -1
- package/dist/subagents/internal/outcome.d.ts +1 -2
- package/dist/subagents/internal/outcome.js +19 -12
- package/dist/subagents/internal/provider-retry.d.ts +1 -2
- package/dist/subagents/internal/provider-retry.js +2 -4
- package/dist/subagents/internal/run.d.ts +2 -3
- package/dist/subagents/internal/run.js +27 -4
- package/dist/subagents/internal/state.d.ts +2 -5
- package/dist/subagents/internal/state.js +1 -2
- package/dist/subagents/internal/worker.d.ts +1 -2
- package/dist/subagents/internal/worker.js +20 -10
- package/dist/subagents/resolve.d.ts +56 -0
- package/dist/subagents/resolve.js +202 -0
- package/dist/subagents/result.d.ts +6 -4
- package/dist/subagents/result.js +39 -6
- package/dist/subagents/run-record.d.ts +54 -2
- package/dist/subagents/run-record.js +7 -0
- package/dist/subagents/runs.d.ts +6 -31
- package/dist/subagents/runs.js +26 -31
- package/dist/subagents/task-envelope.d.ts +1 -2
- package/dist/subagents/task-envelope.js +13 -4
- package/dist/subagents/task-settlement.js +1 -0
- package/dist/subagents/types.d.ts +105 -6
- package/dist/subagents/types.js +16 -1
- package/dist/subagents/workspace-lease.d.ts +41 -24
- package/dist/subagents/workspace-lease.js +159 -24
- package/dist/subagents/worktree.d.ts +52 -0
- package/dist/subagents/worktree.js +363 -0
- package/dist/tasks/archive.js +4 -0
- package/dist/tasks/brief.d.ts +5 -1
- package/dist/tasks/brief.js +19 -5
- package/dist/tasks/commands.d.ts +6 -1
- package/dist/tasks/commands.js +32 -7
- package/dist/tasks/control.d.ts +11 -0
- package/dist/tasks/delivery.d.ts +2 -0
- package/dist/tasks/delivery.js +141 -21
- package/dist/tasks/loop-log.d.ts +12 -0
- package/dist/tasks/loop-log.js +10 -1
- package/dist/tasks/receipts.d.ts +7 -3
- package/dist/tasks/receipts.js +34 -5
- package/dist/tools/bash.d.ts +3 -0
- package/dist/tools/bash.js +29 -15
- package/dist/tools/contract/presentation.js +7 -5
- package/dist/tools/edit-diff.d.ts +11 -0
- package/dist/tools/edit-diff.js +148 -0
- package/dist/tools/edit-match.d.ts +18 -0
- package/dist/tools/edit-match.js +242 -0
- package/dist/tools/edit.d.ts +10 -2
- package/dist/tools/edit.js +91 -361
- package/dist/tools/event-manage.d.ts +2 -1
- package/dist/tools/event-manage.js +46 -39
- package/dist/tools/file-observations.d.ts +9 -0
- package/dist/tools/file-observations.js +50 -0
- package/dist/tools/glob-match.d.ts +3 -1
- package/dist/tools/glob-match.js +40 -17
- package/dist/tools/glob.d.ts +1 -0
- package/dist/tools/glob.js +39 -19
- package/dist/tools/grep-command.d.ts +13 -0
- package/dist/tools/grep-command.js +77 -0
- package/dist/tools/grep.js +96 -201
- package/dist/tools/index.d.ts +6 -2
- package/dist/tools/index.js +9 -4
- package/dist/tools/job.js +12 -11
- package/dist/tools/read.d.ts +2 -0
- package/dist/tools/read.js +10 -2
- package/dist/tools/registry.d.ts +16 -11
- package/dist/tools/registry.js +32 -12
- package/dist/tools/send-media.js +9 -5
- package/dist/tools/session-search.d.ts +2 -1
- package/dist/tools/session-search.js +15 -5
- package/dist/tools/skill.js +13 -12
- package/dist/tools/subagent-manage.d.ts +1 -1
- package/dist/tools/subagent-manage.js +25 -152
- package/dist/tools/subagent.d.ts +24 -2
- package/dist/tools/subagent.js +24 -18
- package/dist/tools/task-manage/control-tools.js +1 -1
- package/dist/tools/task-manage/factory.d.ts +2 -2
- package/dist/tools/task-manage/factory.js +40 -4
- package/dist/tools/task-manage/lifecycle.d.ts +3 -3
- package/dist/tools/task-manage/lifecycle.js +56 -13
- package/dist/tools/task-manage/schema.d.ts +4 -1
- package/dist/tools/task-manage/schema.js +4 -1
- package/dist/tools/task-manage/shared.d.ts +1 -1
- package/dist/tools/task-manage/types.d.ts +5 -1
- package/dist/tools/write-content.d.ts +7 -1
- package/dist/tools/write-content.js +18 -6
- package/dist/tools/write.d.ts +3 -0
- package/dist/tools/write.js +6 -2
- package/dist/tui/cli.d.ts +6 -6
- package/dist/tui/cli.js +120 -28
- package/dist/tui/client.d.ts +7 -0
- package/dist/tui/client.js +67 -16
- package/dist/tui/frontend.d.ts +2 -0
- package/dist/tui/pitui-frontend.d.ts +4 -0
- package/dist/tui/pitui-frontend.js +27 -0
- package/dist/tui/render.d.ts +1 -0
- package/dist/tui/render.js +5 -0
- package/dist/tui/session.js +6 -0
- package/dist/usage/ledger.d.ts +1 -1
- package/dist/usage/render.js +1 -1
- package/dist/web/client.d.ts +1 -0
- package/dist/web/client.js +11 -0
- package/dist/web/fetch.js +6 -3
- package/dist/webapi/auth.d.ts +0 -3
- package/dist/webapi/auth.js +3 -7
- package/dist/webapi/config.js +17 -14
- package/dist/webapi/key-command.js +41 -41
- package/dist/webapi/response-state.d.ts +7 -1
- package/dist/webapi/response-state.js +166 -3
- package/dist/webapi/routes/websocket.js +24 -1
- package/dist/webapi/server.d.ts +3 -1
- package/dist/webapi/server.js +32 -1
- package/dist/webapi/service.js +8 -0
- package/dist/webapi/transport.d.ts +2 -0
- package/dist/webapi/transport.js +11 -1
- package/examples/sub-agents/README.md +43 -75
- package/examples/sub-agents/agy-main.md +21 -0
- package/examples/sub-agents/claude-high.md +21 -0
- package/examples/sub-agents/claude-main.md +21 -0
- package/examples/sub-agents/codex-flash.md +21 -0
- package/examples/sub-agents/codex-high.md +21 -0
- package/examples/sub-agents/codex-main.md +21 -0
- package/examples/sub-agents/codex-review.md +20 -0
- package/examples/sub-agents/cursor-high.md +20 -0
- package/examples/sub-agents/cursor-main.md +20 -0
- package/examples/sub-agents/glm-flash.md +21 -0
- package/examples/sub-agents/glm-high.md +21 -0
- package/examples/sub-agents/pi-scout.md +20 -0
- package/package.json +11 -12
- package/dist/agent/session/request-tools.d.ts +0 -3
- package/dist/agent/session/request-tools.js +0 -20
- package/dist/models/api-keys.d.ts +0 -11
- package/dist/models/api-keys.js +0 -22
- package/dist/playbooks/memory-and-learning.md +0 -55
- package/examples/sub-agents/agents/claude-high.md +0 -23
- package/examples/sub-agents/agents/claude-main.md +0 -23
- package/examples/sub-agents/agents/codex-flash.md +0 -23
- package/examples/sub-agents/agents/codex-high.md +0 -23
- package/examples/sub-agents/agents/codex-main.md +0 -23
- package/examples/sub-agents/agents/codex-review.md +0 -23
- package/examples/sub-agents/agents/cursor-high.md +0 -22
- package/examples/sub-agents/agents/cursor-main.md +0 -22
- package/examples/sub-agents/agents/glm-flash.md +0 -23
- package/examples/sub-agents/agents/glm-high.md +0 -23
- package/examples/sub-agents/agents/scout.md +0 -30
- package/examples/sub-agents/roles/builder-hard.md +0 -34
- package/examples/sub-agents/roles/builder.md +0 -34
- package/examples/sub-agents/roles/explorer.md +0 -39
- package/examples/sub-agents/roles/git-committer.md +0 -43
- package/examples/sub-agents/roles/planner.md +0 -33
- package/examples/sub-agents/roles/reviewer.md +0 -33
- package/examples/sub-agents/roles/verifier.md +0 -35
- package/examples/sub-agents/roles/worker.md +0 -34
package/dist/tui/cli.js
CHANGED
|
@@ -4,8 +4,13 @@
|
|
|
4
4
|
* the daemon's socket, or — when no daemon is running — to a runtime it starts inside this
|
|
5
5
|
* process (D26, `startEmbeddedRuntime`, supplied by the entry so `tui/` never imports `runtime/`).
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
7
|
+
import { homedir } from "node:os";
|
|
8
|
+
import { resolve } from "node:path";
|
|
9
|
+
import { ensureModelOnboarding } from "../app/auth-command.js";
|
|
10
|
+
import { BootstrapExitError, bootstrapAppHome, DEFAULT_BOOTSTRAP_PATHS, printBootstrapSummary, readCliVersion, } from "../app/home.js";
|
|
8
11
|
import { PipiclawSettingsManager } from "../config/settings.js";
|
|
12
|
+
import { getDeskDir } from "../desk/paths.js";
|
|
13
|
+
import { resolveDeskCwdSync } from "../desk/registry.js";
|
|
9
14
|
import * as log from "../log.js";
|
|
10
15
|
import { errorMessage } from "../shared/text-utils.js";
|
|
11
16
|
import { createLink, createSocketClient, openConversation, printOnce, requireSocket } from "./client.js";
|
|
@@ -16,6 +21,8 @@ import { TuiSession } from "./session.js";
|
|
|
16
21
|
/** Parse `pipiclaw tui` arguments (everything after the `tui` subcommand). */
|
|
17
22
|
export function parseTuiArgs(args) {
|
|
18
23
|
let desk;
|
|
24
|
+
let cwd;
|
|
25
|
+
let here = false;
|
|
19
26
|
let create = false;
|
|
20
27
|
let fresh = false;
|
|
21
28
|
let print = false;
|
|
@@ -27,12 +34,24 @@ export function parseTuiArgs(args) {
|
|
|
27
34
|
if (arg === "--desk") {
|
|
28
35
|
desk = args[index + 1];
|
|
29
36
|
if (!desk || desk.startsWith("-"))
|
|
30
|
-
return { kind: "error", message: "--desk
|
|
37
|
+
return { kind: "error", message: "--desk 需要指定工位名称;省略时默认打开 default 工位。" };
|
|
31
38
|
index += 1;
|
|
32
39
|
}
|
|
33
40
|
else if (arg.startsWith("--desk=")) {
|
|
34
41
|
desk = arg.slice("--desk=".length);
|
|
35
42
|
}
|
|
43
|
+
else if (arg === "--cwd") {
|
|
44
|
+
cwd = args[index + 1];
|
|
45
|
+
if (!cwd || cwd.startsWith("-"))
|
|
46
|
+
return { kind: "error", message: "--cwd 需要指定目录路径。" };
|
|
47
|
+
index += 1;
|
|
48
|
+
}
|
|
49
|
+
else if (arg.startsWith("--cwd=")) {
|
|
50
|
+
cwd = arg.slice("--cwd=".length);
|
|
51
|
+
}
|
|
52
|
+
else if (arg === "--here") {
|
|
53
|
+
here = true;
|
|
54
|
+
}
|
|
36
55
|
else if (arg === "--create") {
|
|
37
56
|
create = true;
|
|
38
57
|
}
|
|
@@ -57,33 +76,50 @@ export function parseTuiArgs(args) {
|
|
|
57
76
|
else if (arg.startsWith("--")) {
|
|
58
77
|
// An unknown long option is a typo, not part of the prompt — reject it
|
|
59
78
|
// instead of silently sending `--pritn` to the model as prompt text.
|
|
60
|
-
return { kind: "error", message:
|
|
79
|
+
return { kind: "error", message: `未知参数:${arg}` };
|
|
61
80
|
}
|
|
62
81
|
else {
|
|
63
82
|
positional.push(arg);
|
|
64
83
|
}
|
|
65
84
|
}
|
|
66
|
-
|
|
85
|
+
if (here && (desk !== undefined || cwd !== undefined)) {
|
|
86
|
+
return {
|
|
87
|
+
kind: "error",
|
|
88
|
+
message: "--here 会自动打开或创建当前目录对应的工位,不能与 --desk 或 --cwd 同时指定。",
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
kind: "run",
|
|
93
|
+
desk,
|
|
94
|
+
...(cwd !== undefined ? { cwd } : {}),
|
|
95
|
+
here,
|
|
96
|
+
create,
|
|
97
|
+
fresh,
|
|
98
|
+
print,
|
|
99
|
+
quiet,
|
|
100
|
+
plain,
|
|
101
|
+
positional,
|
|
102
|
+
};
|
|
67
103
|
}
|
|
68
104
|
function printTuiHelp(io) {
|
|
69
|
-
io.log("
|
|
105
|
+
io.log("用法:pipiclaw tui [options] [prompt]");
|
|
70
106
|
io.log("");
|
|
71
|
-
io.log("
|
|
72
|
-
io.log("same assistant as the DingTalk runtime.");
|
|
107
|
+
io.log("在终端中与 Pipiclaw 助手对话(与后台服务共享同一套配置、记忆、任务与文件)。");
|
|
73
108
|
io.log("");
|
|
74
|
-
io.log("
|
|
75
|
-
io.log("
|
|
76
|
-
io.log("default
|
|
77
|
-
io.log("tasks and files with the channels bound to it.");
|
|
109
|
+
io.log("终端通过本机 Web API socket 连接服务:若后台服务已在运行则直接连接;");
|
|
110
|
+
io.log("否则在当前终端进程内自动启动运行时,退出终端时一并关闭。");
|
|
111
|
+
io.log("默认打开 default 工位并续接该工位上次的终端会话。");
|
|
78
112
|
io.log("");
|
|
79
|
-
io.log("
|
|
80
|
-
io.log(" --
|
|
81
|
-
io.log(" --
|
|
82
|
-
io.log(" --
|
|
83
|
-
io.log(" --
|
|
84
|
-
io.log(" --
|
|
85
|
-
io.log(" --
|
|
86
|
-
io.log(" --
|
|
113
|
+
io.log("选项:");
|
|
114
|
+
io.log(" --here 打开或自动创建当前目录对应的专属工位(自动绑定工作目录)");
|
|
115
|
+
io.log(" --desk <名称> 打开指定工位(默认:default)");
|
|
116
|
+
io.log(" --cwd <目录> 设置该工位的工作目录(如 `--cwd .` 绑定当前仓库)");
|
|
117
|
+
io.log(" --create 先新建该工位(等价于 `/desk new`)");
|
|
118
|
+
io.log(" --new 开启全新会话而非续接上次会话");
|
|
119
|
+
io.log(" --print, -p 单次执行:运行 [prompt](或标准输入),输出结果后退出");
|
|
120
|
+
io.log(" --plain 使用行模式输出替代全屏终端界面");
|
|
121
|
+
io.log(" --quiet, -q 仅输出最终回复,不展示中间进度(自动启用 --plain)");
|
|
122
|
+
io.log(" --version 输出当前版本号并退出");
|
|
87
123
|
}
|
|
88
124
|
async function readStdin() {
|
|
89
125
|
const chunks = [];
|
|
@@ -104,22 +140,52 @@ export async function runTui(argv, hooks, io = console, paths = DEFAULT_BOOTSTRA
|
|
|
104
140
|
}
|
|
105
141
|
if (parsed.kind === "error") {
|
|
106
142
|
io.error(parsed.message);
|
|
107
|
-
io.error(`
|
|
143
|
+
io.error("运行 `pipiclaw tui --help` 查看用法。");
|
|
108
144
|
throw new BootstrapExitError(1);
|
|
109
145
|
}
|
|
110
146
|
let initialPrompt = parsed.positional.join(" ").trim() || undefined;
|
|
111
147
|
if (parsed.print && !initialPrompt && process.stdin.isTTY !== true) {
|
|
112
148
|
initialPrompt = (await readStdin()).trim() || undefined;
|
|
113
149
|
}
|
|
150
|
+
const boot = bootstrapAppHome(paths);
|
|
151
|
+
printBootstrapSummary(boot, io, paths);
|
|
152
|
+
let readiness;
|
|
153
|
+
if (!parsed.print) {
|
|
154
|
+
const interactive = hooks.interactive ?? (io === console && process.stdin.isTTY === true && process.stderr.isTTY === true);
|
|
155
|
+
readiness = await ensureModelOnboarding({
|
|
156
|
+
paths,
|
|
157
|
+
io,
|
|
158
|
+
interactive,
|
|
159
|
+
confirmLogin: hooks.confirmModelLogin,
|
|
160
|
+
performLogin: hooks.performModelLogin,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
114
163
|
// The pi-tui frontend owns stdout; the plain frontend prints only the final answer. Either way
|
|
115
164
|
// the console log sink would corrupt the output, so logging goes to its file sink only.
|
|
116
165
|
log.setConsoleLoggingEnabled(false);
|
|
117
166
|
const embedded = await hooks.startEmbeddedRuntime(paths, io);
|
|
167
|
+
let stoppingEmbedded = false;
|
|
168
|
+
const stopEmbedded = async () => {
|
|
169
|
+
if (!embedded || stoppingEmbedded)
|
|
170
|
+
return;
|
|
171
|
+
stoppingEmbedded = true;
|
|
172
|
+
process.stderr.write("正在关闭运行时…\n");
|
|
173
|
+
await embedded.stop();
|
|
174
|
+
};
|
|
175
|
+
const onSignal = () => {
|
|
176
|
+
void stopEmbedded().finally(() => {
|
|
177
|
+
process.exitCode = 0;
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
if (embedded) {
|
|
181
|
+
process.once("SIGTERM", onSignal);
|
|
182
|
+
process.once("SIGHUP", onSignal);
|
|
183
|
+
}
|
|
118
184
|
try {
|
|
119
185
|
if (!embedded)
|
|
120
186
|
requireSocket(paths, io);
|
|
121
187
|
try {
|
|
122
|
-
await runClient(parsed, initialPrompt, paths, io);
|
|
188
|
+
await runClient(parsed, initialPrompt, paths, io, boot.initialWebApiKey, readiness);
|
|
123
189
|
}
|
|
124
190
|
catch (error) {
|
|
125
191
|
if (error instanceof BootstrapExitError)
|
|
@@ -131,14 +197,22 @@ export async function runTui(argv, hooks, io = console, paths = DEFAULT_BOOTSTRA
|
|
|
131
197
|
}
|
|
132
198
|
finally {
|
|
133
199
|
if (embedded) {
|
|
134
|
-
process.
|
|
135
|
-
|
|
200
|
+
process.off("SIGTERM", onSignal);
|
|
201
|
+
process.off("SIGHUP", onSignal);
|
|
202
|
+
await stopEmbedded();
|
|
136
203
|
}
|
|
137
204
|
}
|
|
138
205
|
}
|
|
139
|
-
async function runClient(parsed, initialPrompt, paths, io) {
|
|
206
|
+
async function runClient(parsed, initialPrompt, paths, io, initialWebApiKey, readiness) {
|
|
140
207
|
const client = createSocketClient(paths);
|
|
141
|
-
const
|
|
208
|
+
const resolvedCwdArg = parsed.cwd ? resolve(parsed.cwd) : undefined;
|
|
209
|
+
const { id, desk: deskName, replies, } = await openConversation(client, paths, {
|
|
210
|
+
desk: parsed.desk,
|
|
211
|
+
cwd: resolvedCwdArg,
|
|
212
|
+
here: parsed.here,
|
|
213
|
+
create: parsed.create,
|
|
214
|
+
fresh: parsed.fresh,
|
|
215
|
+
}, io);
|
|
142
216
|
if (parsed.print) {
|
|
143
217
|
const frontend = createFrontend({ plain: true, quiet: parsed.quiet, interactive: false });
|
|
144
218
|
for (const reply of replies)
|
|
@@ -148,20 +222,38 @@ async function runClient(parsed, initialPrompt, paths, io) {
|
|
|
148
222
|
frontend.stop();
|
|
149
223
|
return;
|
|
150
224
|
}
|
|
225
|
+
const deskCwd = resolveDeskCwdSync(paths.workspaceDir, deskName);
|
|
226
|
+
const defaultDeskDir = getDeskDir(paths.workspaceDir, deskName);
|
|
227
|
+
const notices = [...replies];
|
|
228
|
+
if (initialWebApiKey) {
|
|
229
|
+
notices.unshift(`🔑 已自动生成本机 Web API 默认密钥(仅展示一次,请保存):\`${initialWebApiKey}\`(接口:http://127.0.0.1:8787/v1)`);
|
|
230
|
+
}
|
|
231
|
+
if (readiness && !readiness.ready) {
|
|
232
|
+
notices.push("⚠️ 当前尚未配置可用模型凭据;可退出后执行 `pipiclaw auth login`,或配置环境变量 / `models.json` 后发送 `/reload`。");
|
|
233
|
+
}
|
|
234
|
+
const launchCwd = process.cwd();
|
|
235
|
+
if (!parsed.cwd &&
|
|
236
|
+
!parsed.here &&
|
|
237
|
+
deskCwd === defaultDeskDir &&
|
|
238
|
+
launchCwd !== deskCwd &&
|
|
239
|
+
launchCwd !== homedir() &&
|
|
240
|
+
!launchCwd.startsWith(paths.appHomeDir)) {
|
|
241
|
+
notices.push(`💡 当前工位工作目录为默认目录;如需操作当前终端所在目录,可发送 \`/desk cwd ${launchCwd}\`(或下次用 \`pipiclaw tui --here\` 打开当前目录专属工位)。`);
|
|
242
|
+
}
|
|
151
243
|
const frontend = createFrontend({
|
|
152
244
|
plain: parsed.plain,
|
|
153
245
|
quiet: parsed.quiet,
|
|
154
246
|
interactive: true,
|
|
155
247
|
commands: TUI_SLASH_COMMANDS,
|
|
156
|
-
basePath:
|
|
248
|
+
basePath: deskCwd,
|
|
157
249
|
});
|
|
158
250
|
const traits = traitsOf(new PipiclawSettingsManager(paths.appHomeDir).getTuiSettings().responseMode);
|
|
159
251
|
const session = new TuiSession({
|
|
160
252
|
link: createLink(client, paths, id),
|
|
161
253
|
frontend,
|
|
162
254
|
traits,
|
|
163
|
-
label: `终端 · ${
|
|
164
|
-
notices
|
|
255
|
+
label: `终端 · 工位 ${deskName} · 目录 ${deskCwd}`,
|
|
256
|
+
notices,
|
|
165
257
|
});
|
|
166
258
|
await session.startInteractive(initialPrompt);
|
|
167
259
|
}
|
package/dist/tui/client.d.ts
CHANGED
|
@@ -4,6 +4,12 @@ import type { SessionLink } from "./session.js";
|
|
|
4
4
|
export interface OpenOptions {
|
|
5
5
|
/** The desk to work in; defaults to `default`. */
|
|
6
6
|
desk?: string;
|
|
7
|
+
/** Optional repository / working directory to configure on the desk (`--cwd`). */
|
|
8
|
+
cwd?: string;
|
|
9
|
+
/** Automatically open or create a desk dedicated to `hereDir ?? process.cwd()` (`--here`). */
|
|
10
|
+
here?: boolean;
|
|
11
|
+
/** Override `process.cwd()` for `--here` in deterministic tests. */
|
|
12
|
+
hereDir?: string;
|
|
7
13
|
/** Create the desk first — an explicit creation, like `/desk new`. */
|
|
8
14
|
create: boolean;
|
|
9
15
|
/** Start a new conversation instead of resuming the desk's last one. */
|
|
@@ -20,6 +26,7 @@ export declare function createLink(client: OpenAI, paths: BootstrapPaths, conver
|
|
|
20
26
|
*/
|
|
21
27
|
export declare function openConversation(client: OpenAI, paths: BootstrapPaths, options: OpenOptions, io: BootstrapIO): Promise<{
|
|
22
28
|
id: string;
|
|
29
|
+
desk: string;
|
|
23
30
|
replies: string[];
|
|
24
31
|
}>;
|
|
25
32
|
/** `--print`: one synchronous request, the answer on stdout. */
|
package/dist/tui/client.js
CHANGED
|
@@ -6,13 +6,14 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
8
8
|
import { connect } from "node:net";
|
|
9
|
-
import { dirname, join } from "node:path";
|
|
9
|
+
import { dirname, join, resolve } from "node:path";
|
|
10
10
|
import OpenAI from "openai";
|
|
11
11
|
import { ResponsesWS } from "openai/resources/responses/ws";
|
|
12
12
|
import { Agent, fetch as undiciFetch } from "undici";
|
|
13
13
|
import { BootstrapExitError } from "../app/home.js";
|
|
14
14
|
import { loadBindings } from "../desk/bindings.js";
|
|
15
|
-
import { DEFAULT_DESK, isDeskName, normalizeDeskName } from "../desk/paths.js";
|
|
15
|
+
import { DEFAULT_DESK, deriveDeskNameFromPath, isDeskName, normalizeDeskName } from "../desk/paths.js";
|
|
16
|
+
import { listDesks, readDeskRecordSync } from "../desk/registry.js";
|
|
16
17
|
import { webapiSocketPath } from "../paths.js";
|
|
17
18
|
import { writeFileAtomically } from "../shared/atomic-file.js";
|
|
18
19
|
import { isPlainObject } from "../shared/type-guards.js";
|
|
@@ -51,11 +52,22 @@ export function requireSocket(paths, io) {
|
|
|
51
52
|
const socketPath = webapiSocketPath(paths.appHomeDir);
|
|
52
53
|
if (existsSync(socketPath))
|
|
53
54
|
return;
|
|
55
|
+
let lockDetail = "";
|
|
56
|
+
try {
|
|
57
|
+
const raw = JSON.parse(readFileSync(join(paths.appHomeDir, "state", "daemon.lock"), "utf-8"));
|
|
58
|
+
if (isPlainObject(raw) && typeof raw.pid === "number") {
|
|
59
|
+
const started = typeof raw.startedAt === "string" ? `,启动于 ${raw.startedAt}` : "";
|
|
60
|
+
lockDetail = `(进程 PID ${raw.pid}${started})`;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// Lock file unreadable or absent; omit holder details.
|
|
65
|
+
}
|
|
54
66
|
io.error([
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
67
|
+
`无法连接本机 Web API socket(${socketPath})。`,
|
|
68
|
+
`检测到后台已有 Pipiclaw 服务正在运行${lockDetail},但未开启本机 socket。你可以:`,
|
|
69
|
+
` 1) 在 ${paths.channelConfigPath} 中设置 \`"webapi": { "enabled": true, "socket": true }\` 并重启后台服务;或`,
|
|
70
|
+
" 2) 先停止后台服务,再直接运行 `pipiclaw tui`(由终端内嵌启动运行时)。",
|
|
59
71
|
].join("\n"));
|
|
60
72
|
throw new BootstrapExitError(1);
|
|
61
73
|
}
|
|
@@ -112,6 +124,30 @@ async function ask(client, conversationId, input) {
|
|
|
112
124
|
}
|
|
113
125
|
return response.output_text;
|
|
114
126
|
}
|
|
127
|
+
async function resolveHereTarget(paths, targetCwd, fail) {
|
|
128
|
+
const desks = await listDesks(paths.workspaceDir);
|
|
129
|
+
const matchedByCwd = desks.find((entry) => entry.availability === "available" && (entry.record?.cwd ?? entry.deskDir) === targetCwd);
|
|
130
|
+
if (matchedByCwd) {
|
|
131
|
+
return { desk: matchedByCwd.name, create: false };
|
|
132
|
+
}
|
|
133
|
+
const slug = deriveDeskNameFromPath(targetCwd);
|
|
134
|
+
const summary = readDeskRecordSync(paths.workspaceDir, slug);
|
|
135
|
+
if (summary.availability === "missing") {
|
|
136
|
+
const { bindings } = await loadBindings(paths.workspaceDir);
|
|
137
|
+
if (Object.values(bindings).some((binding) => binding.desk === slug)) {
|
|
138
|
+
fail(`工位 "${slug}" 已有绑定但记录缺失,请联系部署者恢复,或改用 \`--desk <新名称> --create --cwd .\`。`);
|
|
139
|
+
}
|
|
140
|
+
return { desk: slug, cwd: targetCwd, create: true };
|
|
141
|
+
}
|
|
142
|
+
if (!summary.record) {
|
|
143
|
+
fail(`工位 "${slug}" 当前不可用(desk.json 有误),请检查后再试,或改用 \`--desk <新名称> --create --cwd .\`。`);
|
|
144
|
+
}
|
|
145
|
+
const existingCwd = summary.record.cwd ?? summary.deskDir;
|
|
146
|
+
if (existingCwd !== targetCwd) {
|
|
147
|
+
fail(`同名工位 "${slug}" 已存在且绑定到其他目录(${existingCwd})。请改用 \`pipiclaw tui --desk <新名称> --create --cwd .\` 指定不重名的工位。`);
|
|
148
|
+
}
|
|
149
|
+
return { desk: slug, create: false };
|
|
150
|
+
}
|
|
115
151
|
/**
|
|
116
152
|
* Find or make the conversation for `--desk`: resume the desk's last one while it is still bound
|
|
117
153
|
* to that desk, else start one and bind it (`/desk new` first with `--create`). Returns the
|
|
@@ -122,34 +158,49 @@ export async function openConversation(client, paths, options, io) {
|
|
|
122
158
|
io.error(message);
|
|
123
159
|
throw new BootstrapExitError(1);
|
|
124
160
|
};
|
|
125
|
-
const
|
|
161
|
+
const resolvedHere = options.here
|
|
162
|
+
? await resolveHereTarget(paths, resolve(options.hereDir ?? process.cwd()), fail)
|
|
163
|
+
: undefined;
|
|
164
|
+
const desk = resolvedHere ? resolvedHere.desk : normalizeDeskName(options.desk ?? DEFAULT_DESK);
|
|
165
|
+
const create = resolvedHere ? resolvedHere.create : options.create;
|
|
166
|
+
const cwd = resolvedHere ? resolvedHere.cwd : options.cwd;
|
|
126
167
|
if (!isDeskName(desk)) {
|
|
127
|
-
fail(
|
|
168
|
+
fail(`工位名称 "${desk}" 不合法:请使用 1–32 位小写字母、数字或连字符 '-',且首尾不能为 '-'。`);
|
|
128
169
|
}
|
|
129
170
|
const state = readState(paths);
|
|
130
|
-
if (!options.fresh && !
|
|
171
|
+
if (!options.fresh && !create && state[desk]) {
|
|
131
172
|
const id = state[desk];
|
|
132
173
|
const exists = await client.conversations.retrieve(id).then(() => true, (error) => (error.status === 404 ? false : Promise.reject(error)));
|
|
133
174
|
// A conversation rebound to another desk since is not this desk's any more.
|
|
134
175
|
const bound = exists ? await boundDesk(paths, id) : undefined;
|
|
135
|
-
|
|
136
|
-
|
|
176
|
+
const isArchived = Boolean(readDeskRecordSync(paths.workspaceDir, desk).record?.archivedAt);
|
|
177
|
+
if (!isArchived && exists && (bound === desk || (bound === undefined && desk === DEFAULT_DESK))) {
|
|
178
|
+
const replies = cwd ? [await ask(client, id, `/desk cwd ${cwd}`)] : [];
|
|
179
|
+
return { id, desk, replies };
|
|
180
|
+
}
|
|
137
181
|
}
|
|
138
182
|
const id = (await client.conversations.create({})).id;
|
|
139
183
|
const replies = [];
|
|
140
184
|
// A conversation starts on the default desk by itself; any other desk is an explicit request.
|
|
141
|
-
if (desk !== DEFAULT_DESK ||
|
|
142
|
-
if (
|
|
143
|
-
replies.push(await ask(client, id, `/desk new ${desk}`));
|
|
185
|
+
if (desk !== DEFAULT_DESK || create) {
|
|
186
|
+
if (create) {
|
|
187
|
+
replies.push(await ask(client, id, cwd ? `/desk new ${desk} ${cwd}` : `/desk new ${desk}`));
|
|
188
|
+
}
|
|
144
189
|
replies.push(await ask(client, id, `/desk bind ${desk}`));
|
|
145
190
|
if ((await boundDesk(paths, id)) !== desk) {
|
|
146
191
|
for (const reply of replies)
|
|
147
192
|
io.error(reply);
|
|
148
|
-
fail(
|
|
193
|
+
fail(`无法打开工位 "${desk}"。`);
|
|
194
|
+
}
|
|
195
|
+
if (cwd && !create) {
|
|
196
|
+
replies.push(await ask(client, id, `/desk cwd ${cwd}`));
|
|
149
197
|
}
|
|
150
198
|
}
|
|
199
|
+
else if (cwd) {
|
|
200
|
+
replies.push(await ask(client, id, `/desk cwd ${cwd}`));
|
|
201
|
+
}
|
|
151
202
|
await writeState(paths, { ...state, [desk]: id });
|
|
152
|
-
return { id, replies };
|
|
203
|
+
return { id, desk, replies };
|
|
153
204
|
}
|
|
154
205
|
/** `--print`: one synchronous request, the answer on stdout. */
|
|
155
206
|
export async function printOnce(client, conversationId, prompt) {
|
package/dist/tui/frontend.d.ts
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
export interface TranscriptRenderer {
|
|
14
14
|
/** A streamed progress line (tool call, thinking, assistant increment, error). */
|
|
15
15
|
appendProgress(text: string): void;
|
|
16
|
+
/** Incremental assistant text delta for live preview before the message completes. */
|
|
17
|
+
streamText?(delta: string): void;
|
|
16
18
|
/** The final answer for a turn, rendered prominently (Markdown where supported). */
|
|
17
19
|
showFinal(markdown: string): void;
|
|
18
20
|
/** A side notice (skill change, model fallback), rendered subtly. */
|
|
@@ -26,6 +26,8 @@ export declare class PiTuiFrontend implements Frontend {
|
|
|
26
26
|
private readonly loader;
|
|
27
27
|
private readonly editorContainer;
|
|
28
28
|
private turnProgress;
|
|
29
|
+
private streamPreview;
|
|
30
|
+
private streamBuffer;
|
|
29
31
|
private removeInputListener;
|
|
30
32
|
private spinnerShown;
|
|
31
33
|
constructor(options?: PiTuiFrontendOptions);
|
|
@@ -34,9 +36,11 @@ export declare class PiTuiFrontend implements Frontend {
|
|
|
34
36
|
/** Echo the user's submitted message into the transcript. */
|
|
35
37
|
showUser(text: string): void;
|
|
36
38
|
appendProgress(text: string): void;
|
|
39
|
+
streamText(delta: string): void;
|
|
37
40
|
showFinal(markdown: string): void;
|
|
38
41
|
showNotice(text: string): void;
|
|
39
42
|
clearProgress(): void;
|
|
43
|
+
private clearStreamPreview;
|
|
40
44
|
setWorking(on: boolean): void;
|
|
41
45
|
setStatus(text: string): void;
|
|
42
46
|
setBusy(busy: boolean): void;
|
|
@@ -44,6 +44,7 @@ export class PiTuiFrontend {
|
|
|
44
44
|
this.spinnerContainer = new Container();
|
|
45
45
|
this.editorContainer = new Container();
|
|
46
46
|
this.turnProgress = [];
|
|
47
|
+
this.streamBuffer = "";
|
|
47
48
|
this.spinnerShown = false;
|
|
48
49
|
this.ui = new TuiMainScreen(new ProcessTerminal(), true);
|
|
49
50
|
this.editor = new Editor(this.ui, EDITOR_THEME, { paddingX: 1 });
|
|
@@ -93,12 +94,27 @@ export class PiTuiFrontend {
|
|
|
93
94
|
this.ui.requestRender();
|
|
94
95
|
}
|
|
95
96
|
appendProgress(text) {
|
|
97
|
+
this.clearStreamPreview();
|
|
96
98
|
const line = new Text(dim(text), 1, 0);
|
|
97
99
|
this.transcript.addChild(line);
|
|
98
100
|
this.turnProgress.push(line);
|
|
99
101
|
this.ui.requestRender();
|
|
100
102
|
}
|
|
103
|
+
streamText(delta) {
|
|
104
|
+
if (!delta)
|
|
105
|
+
return;
|
|
106
|
+
this.streamBuffer += delta;
|
|
107
|
+
if (!this.streamPreview) {
|
|
108
|
+
this.streamPreview = new Markdown(this.streamBuffer, 1, 1, MARKDOWN_THEME, undefined, { renderLatex: false });
|
|
109
|
+
this.transcript.addChild(this.streamPreview);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
this.streamPreview.setText(this.streamBuffer);
|
|
113
|
+
}
|
|
114
|
+
this.ui.requestRender();
|
|
115
|
+
}
|
|
101
116
|
showFinal(markdown) {
|
|
117
|
+
this.clearStreamPreview();
|
|
102
118
|
this.transcript.addChild(new Markdown(markdown, 1, 1, MARKDOWN_THEME, undefined, { renderLatex: false }));
|
|
103
119
|
// The turn's progress becomes permanent scrollback; stop tracking it so a
|
|
104
120
|
// later clearProgress cannot retract it.
|
|
@@ -106,16 +122,25 @@ export class PiTuiFrontend {
|
|
|
106
122
|
this.ui.requestRender();
|
|
107
123
|
}
|
|
108
124
|
showNotice(text) {
|
|
125
|
+
this.clearStreamPreview();
|
|
109
126
|
this.transcript.addChild(new Text(gray(text), 1, 0));
|
|
110
127
|
this.ui.requestRender();
|
|
111
128
|
}
|
|
112
129
|
clearProgress() {
|
|
130
|
+
this.clearStreamPreview();
|
|
113
131
|
for (const component of this.turnProgress) {
|
|
114
132
|
this.transcript.removeChild(component);
|
|
115
133
|
}
|
|
116
134
|
this.turnProgress = [];
|
|
117
135
|
this.ui.requestRender();
|
|
118
136
|
}
|
|
137
|
+
clearStreamPreview() {
|
|
138
|
+
if (this.streamPreview) {
|
|
139
|
+
this.transcript.removeChild(this.streamPreview);
|
|
140
|
+
this.streamPreview = undefined;
|
|
141
|
+
}
|
|
142
|
+
this.streamBuffer = "";
|
|
143
|
+
}
|
|
119
144
|
setWorking(on) {
|
|
120
145
|
this.showSpinner(on);
|
|
121
146
|
}
|
|
@@ -124,6 +149,8 @@ export class PiTuiFrontend {
|
|
|
124
149
|
this.ui.requestRender();
|
|
125
150
|
}
|
|
126
151
|
setBusy(busy) {
|
|
152
|
+
if (!busy)
|
|
153
|
+
this.clearStreamPreview();
|
|
127
154
|
this.showSpinner(busy);
|
|
128
155
|
}
|
|
129
156
|
showSpinner(on) {
|
package/dist/tui/render.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare function traitsOf(mode: TuiResponseMode): DeliveryTraits;
|
|
|
14
14
|
/** The parts of a Response event the terminal reads (the SDK's union is much wider). */
|
|
15
15
|
export interface StreamEvent {
|
|
16
16
|
type: string;
|
|
17
|
+
delta?: string;
|
|
17
18
|
item?: {
|
|
18
19
|
id?: string;
|
|
19
20
|
type?: string;
|
package/dist/tui/render.js
CHANGED
|
@@ -48,6 +48,11 @@ export class EventRenderer {
|
|
|
48
48
|
this.progress("tool", describeToolCall(event.item.name ?? "", parseArguments(event.item.arguments)));
|
|
49
49
|
}
|
|
50
50
|
return;
|
|
51
|
+
case "response.output_text.delta":
|
|
52
|
+
if (this.traits.finalDelivery === "plain" && !this.answered && event.delta) {
|
|
53
|
+
this.out.streamText?.(event.delta);
|
|
54
|
+
}
|
|
55
|
+
return;
|
|
51
56
|
case "response.output_item.done":
|
|
52
57
|
this.itemDone(event.item);
|
|
53
58
|
return;
|
package/dist/tui/session.js
CHANGED
|
@@ -152,10 +152,12 @@ export class TuiSession {
|
|
|
152
152
|
}
|
|
153
153
|
stop() {
|
|
154
154
|
const connection = this.connection;
|
|
155
|
+
const target = this.lastSteerTarget;
|
|
155
156
|
this.connection = undefined;
|
|
156
157
|
this.connectionId++;
|
|
157
158
|
this.resetCounters();
|
|
158
159
|
this.followups.length = 0;
|
|
160
|
+
connection?.send({ type: "response.cancel", ...(target ? { response_id: target } : {}) });
|
|
159
161
|
connection?.close();
|
|
160
162
|
this.options.frontend.showNotice("已停止。");
|
|
161
163
|
this.afterStateChange();
|
|
@@ -168,6 +170,10 @@ export class TuiSession {
|
|
|
168
170
|
}
|
|
169
171
|
// ---- events ----------------------------------------------------------------------------
|
|
170
172
|
onEvent(event) {
|
|
173
|
+
const errorCode = event.error?.code;
|
|
174
|
+
if (event.type === "error" && errorCode === "websocket_connection_limit_reached" && !this.busy) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
171
177
|
this.renderer.handle(event);
|
|
172
178
|
if (event.type === "response.output_item.done" && event.item?.id)
|
|
173
179
|
this.shown.add(event.item.id);
|
package/dist/usage/ledger.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export interface UsageLedgerEntry {
|
|
|
32
32
|
cost: UsageCost;
|
|
33
33
|
/** False when the harness cannot report tokens at all (external `cursor-cli`/`exec`). Display as "unknown", not 0. */
|
|
34
34
|
usageKnown?: boolean;
|
|
35
|
-
/** False when the harness omits a cost field (external `cursor-cli`/`codex-cli`/`exec`). Display as "unknown", not 0. */
|
|
35
|
+
/** False when the harness omits a cost field (external `cursor-cli`/`codex-cli`/`antigravity-cli`/`exec`). Display as "unknown", not 0. */
|
|
36
36
|
costKnown?: boolean;
|
|
37
37
|
}
|
|
38
38
|
export interface UsageSummary {
|
package/dist/usage/render.js
CHANGED
|
@@ -50,7 +50,7 @@ function renderKindBreakdown(summary) {
|
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Some harnesses cannot report tokens or cost at all (`cursor-cli` and `exec` report neither;
|
|
53
|
-
* `codex-cli`
|
|
53
|
+
* `codex-cli` and `antigravity-cli` report no cost). Those runs are never dropped from the ledger (spec 040, T7) but their totals are
|
|
54
54
|
* always 0 by construction, so the aggregate total must say so explicitly — otherwise "$0.0000"
|
|
55
55
|
* reads as "these runs cost nothing" instead of "cost unknown for some of these runs".
|
|
56
56
|
*/
|
package/dist/web/client.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export interface WebHttpRequestOptions {
|
|
|
32
32
|
export declare class WebHttpClient {
|
|
33
33
|
private readonly context;
|
|
34
34
|
constructor(context: WebRuntimeContext);
|
|
35
|
+
validateTarget(url: string): Promise<void>;
|
|
35
36
|
request(options: WebHttpRequestOptions): Promise<WebHttpResponse>;
|
|
36
37
|
requestJson<T>(options: WebHttpRequestOptions): Promise<{
|
|
37
38
|
response: WebHttpResponse;
|
package/dist/web/client.js
CHANGED
|
@@ -112,6 +112,17 @@ export class WebHttpClient {
|
|
|
112
112
|
constructor(context) {
|
|
113
113
|
this.context = context;
|
|
114
114
|
}
|
|
115
|
+
async validateTarget(url) {
|
|
116
|
+
try {
|
|
117
|
+
await validateNetworkTarget(url, { config: this.context.securityConfig });
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
if (error instanceof NetworkGuardError) {
|
|
121
|
+
await logBlockedRequest(this.context, error);
|
|
122
|
+
}
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
115
126
|
async request(options) {
|
|
116
127
|
const maxRedirects = options.maxRedirects ?? this.context.securityConfig.networkGuard.maxRedirects;
|
|
117
128
|
let currentUrl = buildUrlWithParams(options.url, options.params);
|
package/dist/web/fetch.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NetworkGuardError } from "../security/network.js";
|
|
1
2
|
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
2
3
|
import { createWebHttpClient } from "./client.js";
|
|
3
4
|
import { extractReadableContent } from "./extract.js";
|
|
@@ -55,6 +56,7 @@ async function tryFetchViaJina(context, url, maxChars, maxResponseBytes, signal)
|
|
|
55
56
|
workspaceDir: context.workspaceDir,
|
|
56
57
|
channelId: context.channelId,
|
|
57
58
|
});
|
|
59
|
+
await client.validateTarget(url);
|
|
58
60
|
const headers = { Accept: "application/json" };
|
|
59
61
|
if (context.webConfig.search.apiKey && context.webConfig.search.provider === "jina") {
|
|
60
62
|
headers.Authorization = `Bearer ${context.webConfig.search.apiKey}`;
|
|
@@ -171,9 +173,10 @@ export async function runWebFetch(context, request, signal) {
|
|
|
171
173
|
return await fetchDirect(context, request.url, request.extractMode, request.maxChars, request.maxImageBytes, request.maxResponseBytes, signal);
|
|
172
174
|
}
|
|
173
175
|
catch (error) {
|
|
174
|
-
// A binary payload is a definitive answer, not a transient
|
|
175
|
-
//
|
|
176
|
-
|
|
176
|
+
// A binary payload or a network-guard refusal is a definitive answer, not a transient
|
|
177
|
+
// direct-fetch failure — falling back to Jina on a blocked target would leak internal URLs
|
|
178
|
+
// and bypass the SSRF guard.
|
|
179
|
+
if (error instanceof WebFetchBinaryError || error instanceof NetworkGuardError || !request.enableJinaFallback) {
|
|
177
180
|
throw error;
|
|
178
181
|
}
|
|
179
182
|
const jinaResult = await tryFetchViaJina(context, request.url, request.maxChars, request.maxResponseBytes, signal);
|
package/dist/webapi/auth.d.ts
CHANGED
|
@@ -7,7 +7,4 @@ export interface Principal {
|
|
|
7
7
|
local: boolean;
|
|
8
8
|
}
|
|
9
9
|
export declare const LOCAL_PRINCIPAL: Principal;
|
|
10
|
-
export declare const hashKey: (key: string) => string;
|
|
11
|
-
/** A new key: `pk_` and 256 random bits. Shown once; only its hash is kept. */
|
|
12
|
-
export declare function generateKey(): string;
|
|
13
10
|
export declare function authenticate(authorization: string | undefined, keys: readonly WebApiKey[]): Principal | undefined;
|
package/dist/webapi/auth.js
CHANGED
|
@@ -3,13 +3,9 @@
|
|
|
3
3
|
* a TCP request must carry a bearer key whose SHA-256 matches a configured one. The comparison
|
|
4
4
|
* visits every stored hash, so how long it takes does not say which key was close.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { timingSafeEqual } from "node:crypto";
|
|
7
|
+
import { hashWebApiKey } from "../channel/config.js";
|
|
7
8
|
export const LOCAL_PRINCIPAL = { name: "local", local: true };
|
|
8
|
-
export const hashKey = (key) => createHash("sha256").update(key).digest("hex");
|
|
9
|
-
/** A new key: `pk_` and 256 random bits. Shown once; only its hash is kept. */
|
|
10
|
-
export function generateKey() {
|
|
11
|
-
return `pk_${randomBytes(32).toString("base64url")}`;
|
|
12
|
-
}
|
|
13
9
|
function bearerToken(header) {
|
|
14
10
|
const match = /^Bearer[ \t]+(\S+)$/i.exec(header ?? "");
|
|
15
11
|
return match?.[1];
|
|
@@ -18,7 +14,7 @@ export function authenticate(authorization, keys) {
|
|
|
18
14
|
const token = bearerToken(authorization);
|
|
19
15
|
if (token === undefined)
|
|
20
16
|
return undefined;
|
|
21
|
-
const presented = Buffer.from(
|
|
17
|
+
const presented = Buffer.from(hashWebApiKey(token), "hex");
|
|
22
18
|
let match;
|
|
23
19
|
for (const key of keys) {
|
|
24
20
|
// Every stored hash is compared, whether or not an earlier one already matched.
|