@oyasmi/pipiclaw 0.9.6-beta.1 → 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 +279 -215
- package/README.md +274 -213
- package/dist/agent/builtin-commands.d.ts +1 -1
- package/dist/agent/builtin-commands.js +1 -1
- package/dist/agent/channel-runner.d.ts +3 -2
- package/dist/agent/channel-runner.js +16 -27
- 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 +1 -1
- 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/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 +4 -2
- package/dist/agent/session/session-host.js +17 -15
- package/dist/agent/status-render.js +3 -0
- 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/types.d.ts +20 -2
- 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/channel-context.d.ts +6 -0
- package/dist/channel/config.d.ts +3 -0
- package/dist/channel/config.js +11 -5
- package/dist/commands/catalog.js +22 -6
- package/dist/desk/commands.d.ts +31 -4
- package/dist/desk/commands.js +101 -15
- package/dist/desk/paths.d.ts +6 -0
- package/dist/desk/paths.js +21 -1
- package/dist/desk/registry.d.ts +11 -0
- package/dist/desk/registry.js +53 -9
- package/dist/desk/types.d.ts +66 -1
- package/dist/dingtalk/config.js +10 -10
- package/dist/dingtalk/delivery.js +2 -0
- package/dist/dingtalk/inbound.js +2 -3
- package/dist/events/watcher.d.ts +1 -1
- package/dist/events/watcher.js +2 -2
- 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 +2 -1
- package/dist/memory/scheduler.d.ts +2 -1
- package/dist/memory/scheduler.js +1 -1
- package/dist/memory/session-corpus.js +7 -1
- package/dist/memory/session-search.d.ts +2 -1
- package/dist/memory/session-search.js +1 -1
- package/dist/memory/sidecar-worker.d.ts +2 -1
- package/dist/memory/sidecar-worker.js +2 -4
- 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 +19 -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 +4 -0
- package/dist/runtime/bootstrap.js +82 -22
- package/dist/runtime/daemon-lock.js +3 -3
- package/dist/runtime/desk-runtime.d.ts +33 -6
- package/dist/runtime/desk-runtime.js +302 -47
- package/dist/runtime/ingress-commands.js +24 -4
- package/dist/runtime/shutdown.d.ts +3 -1
- package/dist/runtime/shutdown.js +1 -0
- package/dist/runtime/task-close.d.ts +1 -1
- package/dist/runtime/task-close.js +6 -3
- package/dist/runtime/task-control.d.ts +1 -3
- package/dist/runtime/task-control.js +15 -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 +1 -0
- package/dist/runtime/task-lane.js +17 -14
- package/dist/runtime/task-step.d.ts +3 -3
- package/dist/runtime/task-step.js +23 -14
- package/dist/runtime/transports.js +6 -5
- package/dist/security/command-guard.js +23 -1
- package/dist/subagents/commands.js +14 -5
- package/dist/subagents/completion-wake.js +6 -0
- package/dist/subagents/dispatch.js +20 -18
- package/dist/subagents/external/dispatch.js +20 -14
- package/dist/subagents/external/run.js +10 -20
- package/dist/subagents/external/settlement.js +5 -1
- package/dist/subagents/internal/outcome.js +19 -12
- package/dist/subagents/internal/provider-retry.js +1 -3
- package/dist/subagents/internal/run.d.ts +1 -1
- package/dist/subagents/internal/run.js +27 -4
- package/dist/subagents/internal/state.d.ts +1 -3
- package/dist/subagents/internal/state.js +1 -2
- package/dist/subagents/internal/worker.js +17 -9
- package/dist/subagents/result.d.ts +5 -2
- package/dist/subagents/result.js +35 -6
- package/dist/subagents/run-record.d.ts +21 -0
- package/dist/subagents/run-record.js +5 -0
- package/dist/subagents/runs.d.ts +4 -7
- package/dist/subagents/runs.js +24 -35
- package/dist/subagents/task-envelope.js +5 -0
- package/dist/subagents/task-settlement.js +1 -0
- package/dist/subagents/types.d.ts +14 -4
- package/dist/subagents/workspace-lease.d.ts +37 -10
- package/dist/subagents/workspace-lease.js +121 -13
- package/dist/subagents/worktree.d.ts +47 -5
- package/dist/subagents/worktree.js +316 -30
- package/dist/tasks/brief.d.ts +5 -1
- package/dist/tasks/brief.js +19 -5
- package/dist/tasks/commands.d.ts +3 -1
- package/dist/tasks/commands.js +17 -6
- package/dist/tasks/control.d.ts +9 -0
- package/dist/tasks/loop-log.d.ts +10 -0
- package/dist/tasks/loop-log.js +1 -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 +27 -15
- package/dist/tools/contract/presentation.js +4 -1
- 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 +1 -2
- package/dist/tools/event-manage.js +27 -38
- 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 +4 -1
- package/dist/tools/index.js +7 -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 +29 -11
- package/dist/tools/session-search.d.ts +2 -1
- package/dist/tools/session-search.js +14 -4
- package/dist/tools/skill.js +13 -12
- package/dist/tools/subagent-manage.js +10 -3
- package/dist/tools/subagent.d.ts +22 -2
- package/dist/tools/subagent.js +19 -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 +39 -3
- package/dist/tools/task-manage/lifecycle.d.ts +2 -2
- package/dist/tools/task-manage/lifecycle.js +7 -4
- package/dist/tools/task-manage/shared.d.ts +1 -1
- package/dist/tools/task-manage/types.d.ts +1 -0
- 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 +5 -0
- package/dist/tui/cli.js +97 -31
- package/dist/tui/client.d.ts +5 -0
- package/dist/tui/client.js +63 -21
- 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/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 +9 -7
- 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 +8 -9
- 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/agy-main.md +0 -23
- 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/dist/agent/types.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PipiclawSettingsManager } from "../config/settings.js";
|
|
1
2
|
import { type BootstrapIO, type BootstrapPaths } from "./home.js";
|
|
2
3
|
export type ParsedAuth = {
|
|
3
4
|
kind: "status";
|
|
@@ -22,4 +23,28 @@ export type ParsedAuth = {
|
|
|
22
23
|
};
|
|
23
24
|
/** Parse `pipiclaw auth` arguments (everything after the `auth` subcommand, including the subcommand name itself). */
|
|
24
25
|
export declare function parseAuthArgs(args: string[]): ParsedAuth;
|
|
26
|
+
export interface ModelReadiness {
|
|
27
|
+
/** True when at least one model has usable credentials (or `ANTHROPIC_API_KEY` is present). */
|
|
28
|
+
ready: boolean;
|
|
29
|
+
/** Resolved initial model (`provider/id`). */
|
|
30
|
+
activeModelRef: string;
|
|
31
|
+
/** Non-empty when `models.json` failed to parse or validate. */
|
|
32
|
+
modelsError?: string;
|
|
33
|
+
}
|
|
34
|
+
/** Local, offline-safe check of whether any model credential is configured. */
|
|
35
|
+
export declare function inspectModelReadiness(paths?: BootstrapPaths, settingsManager?: PipiclawSettingsManager): Promise<ModelReadiness>;
|
|
36
|
+
export interface EnsureModelOnboardingOptions {
|
|
37
|
+
paths?: BootstrapPaths;
|
|
38
|
+
io?: BootstrapIO;
|
|
39
|
+
/** True only when attached to a live interactive terminal (never in daemons under systemd/pm2, `--print`, or tests). */
|
|
40
|
+
interactive: boolean;
|
|
41
|
+
/** Optional overrides for deterministic unit testing. */
|
|
42
|
+
confirmLogin?: () => Promise<boolean>;
|
|
43
|
+
performLogin?: () => Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Loudly surface `models.json` errors and missing model credentials on startup. When `interactive`
|
|
47
|
+
* is true and no model credentials exist yet, offers to run the interactive login flow right away.
|
|
48
|
+
*/
|
|
49
|
+
export declare function ensureModelOnboarding(options: EnsureModelOnboardingOptions): Promise<ModelReadiness>;
|
|
25
50
|
export declare function runAuth(argv: string[], io?: BootstrapIO, paths?: BootstrapPaths): Promise<void>;
|
package/dist/app/auth-command.js
CHANGED
|
@@ -6,18 +6,21 @@
|
|
|
6
6
|
* login is a short, one-shot operation (spec 039 §5.1).
|
|
7
7
|
*/
|
|
8
8
|
import { createInterface } from "node:readline/promises";
|
|
9
|
+
import { PipiclawSettingsManager } from "../config/settings.js";
|
|
9
10
|
import * as log from "../log.js";
|
|
11
|
+
import { flushModelCredentials } from "../models/credential-work.js";
|
|
10
12
|
import { ReadlineLoginUi } from "../models/login-ui.js";
|
|
11
13
|
import { LoginCancelledError, listProviderLoginOptions, loginProvider, logoutProvider, renderAuthStatus, } from "../models/provider-login.js";
|
|
12
14
|
import { formatModelReference } from "../models/reference.js";
|
|
13
|
-
import { createModelRuntime } from "../models/runtime.js";
|
|
15
|
+
import { createModelRuntime, resolveInitialModel, wrapModelRegistry } from "../models/runtime.js";
|
|
14
16
|
import { docsUrl } from "../paths.js";
|
|
17
|
+
import { withTimeout } from "../shared/with-timeout.js";
|
|
15
18
|
import { BootstrapExitError, bootstrapAppHome, DEFAULT_BOOTSTRAP_PATHS, printBootstrapSummary, readCliVersion, } from "./home.js";
|
|
16
19
|
import { prepareAppServices } from "./services.js";
|
|
17
20
|
/** Parse `pipiclaw auth` arguments (everything after the `auth` subcommand, including the subcommand name itself). */
|
|
18
21
|
export function parseAuthArgs(args) {
|
|
19
22
|
if (args.length === 0) {
|
|
20
|
-
return { kind: "error", message: "
|
|
23
|
+
return { kind: "error", message: "缺少子命令。用法:pipiclaw auth status|login|logout" };
|
|
21
24
|
}
|
|
22
25
|
if (args[0] === "--version")
|
|
23
26
|
return { kind: "version" };
|
|
@@ -29,7 +32,7 @@ export function parseAuthArgs(args) {
|
|
|
29
32
|
if (rest.some((arg) => arg === "--help" || arg === "-h"))
|
|
30
33
|
return { kind: "help" };
|
|
31
34
|
if (rest.length > 0)
|
|
32
|
-
return { kind: "error", message:
|
|
35
|
+
return { kind: "error", message: `未知参数:${rest[0]}` };
|
|
33
36
|
return { kind: "status" };
|
|
34
37
|
}
|
|
35
38
|
if (subcommand === "login") {
|
|
@@ -50,14 +53,14 @@ export function parseAuthArgs(args) {
|
|
|
50
53
|
else if (arg === "--help" || arg === "-h")
|
|
51
54
|
return { kind: "help" };
|
|
52
55
|
else if (arg.startsWith("--"))
|
|
53
|
-
return { kind: "error", message:
|
|
56
|
+
return { kind: "error", message: `未知参数:${arg}` };
|
|
54
57
|
else
|
|
55
58
|
positional.push(arg);
|
|
56
59
|
}
|
|
57
60
|
if (apiKey && oauth)
|
|
58
|
-
return { kind: "error", message: "--api-key
|
|
61
|
+
return { kind: "error", message: "--api-key 与 --oauth 不能同时使用" };
|
|
59
62
|
if (positional.length > 1)
|
|
60
|
-
return { kind: "error", message:
|
|
63
|
+
return { kind: "error", message: `多余的参数:${positional[1]}` };
|
|
61
64
|
return { kind: "login", provider: positional[0], apiKey, oauth, deviceCode, noBrowser };
|
|
62
65
|
}
|
|
63
66
|
if (subcommand === "logout") {
|
|
@@ -69,36 +72,34 @@ export function parseAuthArgs(args) {
|
|
|
69
72
|
else if (arg === "--help" || arg === "-h")
|
|
70
73
|
return { kind: "help" };
|
|
71
74
|
else if (arg.startsWith("--"))
|
|
72
|
-
return { kind: "error", message:
|
|
75
|
+
return { kind: "error", message: `未知参数:${arg}` };
|
|
73
76
|
else
|
|
74
77
|
positional.push(arg);
|
|
75
78
|
}
|
|
76
79
|
if (positional.length > 1)
|
|
77
|
-
return { kind: "error", message:
|
|
80
|
+
return { kind: "error", message: `多余的参数:${positional[1]}` };
|
|
78
81
|
return { kind: "logout", provider: positional[0], yes };
|
|
79
82
|
}
|
|
80
|
-
return { kind: "error", message:
|
|
83
|
+
return { kind: "error", message: `未知子命令:${subcommand}` };
|
|
81
84
|
}
|
|
82
85
|
function printAuthHelp(io) {
|
|
83
|
-
io.log("
|
|
86
|
+
io.log("用法:pipiclaw auth status|login|logout [options]");
|
|
84
87
|
io.log("");
|
|
85
|
-
io.log("
|
|
86
|
-
io.log("operation — it does not start the daemon, load memory, or touch any channel.");
|
|
88
|
+
io.log("管理保存在 auth.json 中的模型供应商凭据(订阅登录或 API Key)。");
|
|
87
89
|
io.log("");
|
|
88
90
|
io.log(" pipiclaw auth status");
|
|
89
|
-
io.log("
|
|
91
|
+
io.log(" 查看各供应商的配置状态、凭据类型与文件路径。");
|
|
90
92
|
io.log("");
|
|
91
93
|
io.log(" pipiclaw auth login [provider] [--api-key] [--oauth] [--device-code] [--no-browser]");
|
|
92
|
-
io.log("
|
|
93
|
-
io.log("
|
|
94
|
-
io.log(" --
|
|
95
|
-
io.log(" --
|
|
96
|
-
io.log(" --no-browser Print the auth URL only; never try to open a browser.");
|
|
94
|
+
io.log(" 交互式登录模型供应商。不传参数时依次选择认证方式与供应商。");
|
|
95
|
+
io.log(" --api-key / --oauth 直接指定认证方式,跳过第一步选择。");
|
|
96
|
+
io.log(" --device-code 无头服务器推荐使用设备码授权(无需本机浏览器与回调端口)。");
|
|
97
|
+
io.log(" --no-browser 仅打印授权链接,不尝试自动打开浏览器。");
|
|
97
98
|
io.log("");
|
|
98
99
|
io.log(" pipiclaw auth logout [provider] [--yes]");
|
|
99
|
-
io.log("
|
|
100
|
+
io.log(" 移除已保存的凭据(默认需二次确认,--yes 跳过确认)。");
|
|
100
101
|
io.log("");
|
|
101
|
-
io.log("
|
|
102
|
+
io.log("提示:已运行的会话可发送 `/reload` 或重启服务以加载新凭据。");
|
|
102
103
|
}
|
|
103
104
|
function providerAuthAvailable(runtime, option) {
|
|
104
105
|
const provider = runtime.getProvider(option.id);
|
|
@@ -116,10 +117,10 @@ function toTarget(runtime, option) {
|
|
|
116
117
|
async function askAuthTypeChoice(ui) {
|
|
117
118
|
const answer = await ui.ask({
|
|
118
119
|
type: "select",
|
|
119
|
-
message: "
|
|
120
|
+
message: "请选择认证方式:",
|
|
120
121
|
options: [
|
|
121
|
-
{ id: "oauth", label: "
|
|
122
|
-
{ id: "api_key", label: "API
|
|
122
|
+
{ id: "oauth", label: "订阅账号登录(OAuth)" },
|
|
123
|
+
{ id: "api_key", label: "填写 API Key" },
|
|
123
124
|
],
|
|
124
125
|
});
|
|
125
126
|
return answer === "api_key" ? "api_key" : "oauth";
|
|
@@ -132,16 +133,16 @@ async function resolveLoginTarget(runtime, parsed, ui) {
|
|
|
132
133
|
if (forcedAuthType)
|
|
133
134
|
candidates = candidates.filter((option) => option.authType === forcedAuthType);
|
|
134
135
|
if (candidates.length === 0) {
|
|
135
|
-
throw new Error(
|
|
136
|
+
throw new Error(`未知或不支持该认证方式的供应商:"${parsed.provider}"。可运行 \`pipiclaw auth status\` 查看支持的供应商。`);
|
|
136
137
|
}
|
|
137
138
|
let chosen = candidates[0];
|
|
138
139
|
if (candidates.length > 1) {
|
|
139
140
|
const authTypeId = await ui.ask({
|
|
140
141
|
type: "select",
|
|
141
|
-
message:
|
|
142
|
+
message: `请选择 ${chosen.name} 的登录方式:`,
|
|
142
143
|
options: candidates.map((candidate) => ({
|
|
143
144
|
id: candidate.authType,
|
|
144
|
-
label: candidate.authType === "oauth" ? (candidate.loginLabel ?? "OAuth") : "API
|
|
145
|
+
label: candidate.authType === "oauth" ? (candidate.loginLabel ?? "订阅登录(OAuth)") : "API Key",
|
|
145
146
|
})),
|
|
146
147
|
});
|
|
147
148
|
chosen = candidates.find((candidate) => candidate.authType === authTypeId) ?? chosen;
|
|
@@ -151,20 +152,20 @@ async function resolveLoginTarget(runtime, parsed, ui) {
|
|
|
151
152
|
const authType = forcedAuthType ?? (await askAuthTypeChoice(ui));
|
|
152
153
|
const options = listProviderLoginOptions(runtime, authType);
|
|
153
154
|
if (options.length === 0) {
|
|
154
|
-
throw new Error(
|
|
155
|
+
throw new Error(`当前没有支持${authType === "oauth" ? "订阅登录" : "API Key 登录"}的供应商。`);
|
|
155
156
|
}
|
|
156
157
|
const providerId = await ui.ask({
|
|
157
158
|
type: "select",
|
|
158
|
-
message: "
|
|
159
|
+
message: "请选择模型供应商:",
|
|
159
160
|
options: options.map((option) => ({
|
|
160
161
|
id: option.id,
|
|
161
162
|
label: option.name,
|
|
162
|
-
description: option.configured ?
|
|
163
|
+
description: option.configured ? `已配置(${option.configuredAs})` : "未配置",
|
|
163
164
|
})),
|
|
164
165
|
});
|
|
165
166
|
const chosen = options.find((option) => option.id === providerId);
|
|
166
167
|
if (!chosen)
|
|
167
|
-
throw new Error(
|
|
168
|
+
throw new Error(`未知供应商:"${providerId}"。`);
|
|
168
169
|
return toTarget(runtime, chosen);
|
|
169
170
|
}
|
|
170
171
|
function auditAuthEvent(action, providerId, authType, ok) {
|
|
@@ -174,17 +175,64 @@ function auditAuthEvent(action, providerId, authType, ok) {
|
|
|
174
175
|
// token/secret fragment.
|
|
175
176
|
log.logInfo(`auth ${action}: ${providerId}${authType ? ` (${authType})` : ""} — ${ok ? "ok" : "failed"}`);
|
|
176
177
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
178
|
+
const MAX_DEFAULT_MODEL_PROMPT_CHOICES = 12;
|
|
179
|
+
const SKIP_DEFAULT_MODEL_ID = "__skip__";
|
|
180
|
+
async function maybeOfferDefaultModelSelection(runtime, providerId, newModels, ui, io, paths) {
|
|
181
|
+
const available = runtime.getAvailableSnapshot();
|
|
182
|
+
const providerModels = (newModels.length > 0 ? newModels : available.filter((model) => model.provider === providerId))
|
|
183
|
+
.slice()
|
|
184
|
+
.sort((a, b) => formatModelReference(a).localeCompare(formatModelReference(b)));
|
|
185
|
+
if (providerModels.length === 0)
|
|
186
|
+
return;
|
|
187
|
+
const settingsManager = new PipiclawSettingsManager(paths.appHomeDir);
|
|
188
|
+
const savedProvider = settingsManager.getDefaultProvider();
|
|
189
|
+
const savedModel = settingsManager.getDefaultModel();
|
|
190
|
+
const hasValidSavedDefault = Boolean(savedProvider &&
|
|
191
|
+
savedModel &&
|
|
192
|
+
available.some((model) => model.provider === savedProvider && model.id === savedModel));
|
|
193
|
+
if (hasValidSavedDefault) {
|
|
194
|
+
io.log(`当前默认模型保持为 \`${savedProvider}/${savedModel}\`。如需切换可在会话中发送 \`/model\`。`);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (providerModels.length === 1) {
|
|
198
|
+
const only = providerModels[0];
|
|
199
|
+
settingsManager.setDefaultModelAndProvider(only.provider, only.id);
|
|
200
|
+
io.log(`已自动将默认模型设为 \`${formatModelReference(only)}\`(已写入 ${paths.settingsConfigPath})。`);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const shown = providerModels.slice(0, MAX_DEFAULT_MODEL_PROMPT_CHOICES);
|
|
204
|
+
const chosenRef = await ui.ask({
|
|
205
|
+
type: "select",
|
|
206
|
+
message: "请选择要设为默认的模型(直接回车选择第 1 项):",
|
|
207
|
+
options: [
|
|
208
|
+
...shown.map((model) => ({
|
|
209
|
+
id: formatModelReference(model),
|
|
210
|
+
label: formatModelReference(model),
|
|
211
|
+
...(model.name && model.name !== model.id ? { description: model.name } : {}),
|
|
212
|
+
})),
|
|
213
|
+
{ id: SKIP_DEFAULT_MODEL_ID, label: "暂不设置(稍后在会话中用 /model 切换)" },
|
|
214
|
+
],
|
|
182
215
|
});
|
|
216
|
+
if (chosenRef === SKIP_DEFAULT_MODEL_ID)
|
|
217
|
+
return;
|
|
218
|
+
const chosen = providerModels.find((model) => formatModelReference(model) === chosenRef);
|
|
219
|
+
if (chosen) {
|
|
220
|
+
settingsManager.setDefaultModelAndProvider(chosen.provider, chosen.id);
|
|
221
|
+
io.log(`已将默认模型设为 \`${formatModelReference(chosen)}\`(已写入 ${paths.settingsConfigPath})。`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
async function runLogin(runtime, parsed, io, signal, paths, uiOverride) {
|
|
225
|
+
const ui = uiOverride ??
|
|
226
|
+
new ReadlineLoginUi({
|
|
227
|
+
signal,
|
|
228
|
+
presetFirstSelect: parsed.deviceCode ? "device_code" : undefined,
|
|
229
|
+
noBrowser: parsed.noBrowser,
|
|
230
|
+
});
|
|
183
231
|
try {
|
|
184
232
|
const target = await resolveLoginTarget(runtime, parsed, ui);
|
|
185
233
|
if (target.kind === "unsupported") {
|
|
186
|
-
io.error(`"${target.name}"
|
|
187
|
-
io.error(
|
|
234
|
+
io.error(`"${target.name}" 使用环境变量或本地配置文件认证,不支持交互式登录。`);
|
|
235
|
+
io.error(`配置方式请参考:${docsUrl("configuration.md")}`);
|
|
188
236
|
throw new BootstrapExitError(1);
|
|
189
237
|
}
|
|
190
238
|
let result;
|
|
@@ -198,46 +246,33 @@ async function runLogin(runtime, parsed, io, signal, paths) {
|
|
|
198
246
|
throw error;
|
|
199
247
|
}
|
|
200
248
|
auditAuthEvent("login", target.providerId, target.authType, true);
|
|
201
|
-
io.log(
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
.slice()
|
|
205
|
-
.sort((a, b) => formatModelReference(a).localeCompare(formatModelReference(b)));
|
|
206
|
-
io.log("New models available:");
|
|
207
|
-
for (const model of sorted)
|
|
208
|
-
io.log(` - ${formatModelReference(model)}`);
|
|
209
|
-
io.log("");
|
|
210
|
-
io.log("This does not change your default model. To use one of these:");
|
|
211
|
-
io.log(` /model ${formatModelReference(sorted[0])} (inside \`pipiclaw tui\`)`);
|
|
212
|
-
io.log("or add to settings.json:");
|
|
213
|
-
io.log(` { "defaultProvider": "${sorted[0].provider}", "defaultModel": "${sorted[0].id}" }`);
|
|
214
|
-
}
|
|
215
|
-
io.log("A running daemon or TUI session must be restarted to see this credential.");
|
|
249
|
+
io.log(`✅ 登录成功:${target.providerId}(${result.credentialType})`);
|
|
250
|
+
await maybeOfferDefaultModelSelection(runtime, target.providerId, result.newModels, ui, io, paths);
|
|
251
|
+
io.log("提示:若已有正在运行的会话,发送 `/reload` 或重启服务即可加载新凭据。");
|
|
216
252
|
if (process.env.PIPICLAW_PROXY && !process.env.HTTPS_PROXY && !process.env.HTTP_PROXY) {
|
|
217
253
|
io.log("");
|
|
218
|
-
io.log("
|
|
219
|
-
"
|
|
220
|
-
`${docsUrl("configuration.md")}.`);
|
|
254
|
+
io.log("⚠️ 注意:当前设置了 PIPICLAW_PROXY 但未设置 HTTPS_PROXY / HTTP_PROXY。Codex 对话所使用的 WebSocket 连接仅识别 HTTPS_PROXY / HTTP_PROXY,详见 " +
|
|
255
|
+
`${docsUrl("configuration.md")}。`);
|
|
221
256
|
}
|
|
222
257
|
}
|
|
223
258
|
catch (error) {
|
|
224
259
|
if (error instanceof BootstrapExitError)
|
|
225
260
|
throw error;
|
|
226
261
|
if (error instanceof LoginCancelledError || signal.aborted) {
|
|
227
|
-
io.error("
|
|
262
|
+
io.error("已取消登录。");
|
|
228
263
|
throw new BootstrapExitError(130);
|
|
229
264
|
}
|
|
230
265
|
io.error(error instanceof Error ? error.message : String(error));
|
|
231
266
|
throw new BootstrapExitError(2);
|
|
232
267
|
}
|
|
233
268
|
finally {
|
|
234
|
-
ui.close();
|
|
269
|
+
ui.close?.();
|
|
235
270
|
}
|
|
236
271
|
}
|
|
237
272
|
async function runLogout(runtime, parsed, io, signal) {
|
|
238
273
|
const credentials = await runtime.listCredentials();
|
|
239
274
|
if (credentials.length === 0) {
|
|
240
|
-
io.log("
|
|
275
|
+
io.log("当前没有已保存的模型凭据。");
|
|
241
276
|
return;
|
|
242
277
|
}
|
|
243
278
|
const providerNames = new Map(runtime.getProviders().map((provider) => [provider.id, provider.name]));
|
|
@@ -249,7 +284,7 @@ async function runLogout(runtime, parsed, io, signal) {
|
|
|
249
284
|
const match = credentials.find((credential) => credential.providerId.toLowerCase() === needle ||
|
|
250
285
|
(providerNames.get(credential.providerId) ?? "").toLowerCase() === needle);
|
|
251
286
|
if (!match) {
|
|
252
|
-
io.error(
|
|
287
|
+
io.error(`未找到 "${providerId}" 的已保存凭据。可运行 \`pipiclaw auth status\` 查看已配置项。`);
|
|
253
288
|
throw new BootstrapExitError(1);
|
|
254
289
|
}
|
|
255
290
|
providerId = match.providerId;
|
|
@@ -258,7 +293,7 @@ async function runLogout(runtime, parsed, io, signal) {
|
|
|
258
293
|
providerId = credentials[0].providerId;
|
|
259
294
|
}
|
|
260
295
|
else {
|
|
261
|
-
io.error("
|
|
296
|
+
io.error("请选择要退出登录的供应商:");
|
|
262
297
|
credentials.forEach((credential, index) => {
|
|
263
298
|
io.error(` ${index + 1}) ${providerNames.get(credential.providerId) ?? credential.providerId} (${credential.type})`);
|
|
264
299
|
});
|
|
@@ -266,16 +301,18 @@ async function runLogout(runtime, parsed, io, signal) {
|
|
|
266
301
|
const index = Number.parseInt(raw, 10);
|
|
267
302
|
const match = Number.isInteger(index) ? credentials[index - 1] : undefined;
|
|
268
303
|
if (!match) {
|
|
269
|
-
io.error(
|
|
304
|
+
io.error(`输入无效:${raw}`);
|
|
270
305
|
throw new BootstrapExitError(1);
|
|
271
306
|
}
|
|
272
307
|
providerId = match.providerId;
|
|
273
308
|
}
|
|
274
309
|
const displayName = providerNames.get(providerId) ?? providerId;
|
|
275
310
|
if (!parsed.yes) {
|
|
276
|
-
const answer = (await rl.question(
|
|
311
|
+
const answer = (await rl.question(`确认退出 ${displayName} 的登录凭据? [y/N] `, { signal }))
|
|
312
|
+
.trim()
|
|
313
|
+
.toLowerCase();
|
|
277
314
|
if (answer !== "y" && answer !== "yes") {
|
|
278
|
-
io.log("
|
|
315
|
+
io.log("已取消。");
|
|
279
316
|
return;
|
|
280
317
|
}
|
|
281
318
|
}
|
|
@@ -288,13 +325,13 @@ async function runLogout(runtime, parsed, io, signal) {
|
|
|
288
325
|
throw new BootstrapExitError(2);
|
|
289
326
|
}
|
|
290
327
|
auditAuthEvent("logout", providerId, undefined, true);
|
|
291
|
-
io.log(
|
|
328
|
+
io.log(`已移除凭据:${displayName}`);
|
|
292
329
|
}
|
|
293
330
|
catch (error) {
|
|
294
331
|
if (error instanceof BootstrapExitError)
|
|
295
332
|
throw error;
|
|
296
333
|
if (signal.aborted) {
|
|
297
|
-
io.error("
|
|
334
|
+
io.error("已取消。");
|
|
298
335
|
throw new BootstrapExitError(130);
|
|
299
336
|
}
|
|
300
337
|
throw error;
|
|
@@ -303,6 +340,101 @@ async function runLogout(runtime, parsed, io, signal) {
|
|
|
303
340
|
rl.close();
|
|
304
341
|
}
|
|
305
342
|
}
|
|
343
|
+
/** Local, offline-safe check of whether any model credential is configured. */
|
|
344
|
+
export async function inspectModelReadiness(paths = DEFAULT_BOOTSTRAP_PATHS, settingsManager = new PipiclawSettingsManager(paths.appHomeDir)) {
|
|
345
|
+
const runtime = await createModelRuntime({
|
|
346
|
+
authConfigPath: paths.authConfigPath,
|
|
347
|
+
modelsConfigPath: paths.modelsConfigPath,
|
|
348
|
+
});
|
|
349
|
+
const registry = wrapModelRegistry(runtime);
|
|
350
|
+
const available = registry.getAvailable();
|
|
351
|
+
const active = resolveInitialModel(registry, settingsManager);
|
|
352
|
+
const ready = available.length > 0 || Boolean(process.env.ANTHROPIC_API_KEY?.trim());
|
|
353
|
+
const modelsError = runtime.getError();
|
|
354
|
+
return {
|
|
355
|
+
ready,
|
|
356
|
+
activeModelRef: formatModelReference(active),
|
|
357
|
+
...(modelsError ? { modelsError } : {}),
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
async function promptConfirmLoginOnTty(signal) {
|
|
361
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
362
|
+
try {
|
|
363
|
+
const answer = (await rl.question("是否现在进入交互式模型登录引导?(直接回车进入,输入 n 稍后配置)[Y/n] ", { signal }))
|
|
364
|
+
.trim()
|
|
365
|
+
.toLowerCase();
|
|
366
|
+
return answer === "" || answer === "y" || answer === "yes";
|
|
367
|
+
}
|
|
368
|
+
finally {
|
|
369
|
+
rl.close();
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Loudly surface `models.json` errors and missing model credentials on startup. When `interactive`
|
|
374
|
+
* is true and no model credentials exist yet, offers to run the interactive login flow right away.
|
|
375
|
+
*/
|
|
376
|
+
export async function ensureModelOnboarding(options) {
|
|
377
|
+
const paths = options.paths ?? DEFAULT_BOOTSTRAP_PATHS;
|
|
378
|
+
const io = options.io ?? console;
|
|
379
|
+
let readiness = await inspectModelReadiness(paths);
|
|
380
|
+
if (readiness.modelsError) {
|
|
381
|
+
io.error("==================================================================");
|
|
382
|
+
io.error(`❌ 模型配置文件存在错误(${paths.modelsConfigPath}):`);
|
|
383
|
+
io.error(readiness.modelsError);
|
|
384
|
+
io.error("==================================================================");
|
|
385
|
+
}
|
|
386
|
+
if (readiness.ready) {
|
|
387
|
+
return readiness;
|
|
388
|
+
}
|
|
389
|
+
io.error("==================================================================");
|
|
390
|
+
io.error("⚠️ 尚未检测到任何可用的大模型凭据!(未配置模型前无法正常对话)");
|
|
391
|
+
io.error(" 请任选以下一种方式配置模型:");
|
|
392
|
+
io.error(` 1) 订阅登录或填写内置供应商 API Key:运行 \`${paths.appName} auth login\``);
|
|
393
|
+
io.error(" 2) 环境变量:例如 `export ANTHROPIC_API_KEY=sk-...` 或 `export OPENAI_API_KEY=sk-...`");
|
|
394
|
+
io.error(` 3) 自定义网关 / DeepSeek / 通义 / Ollama:编辑 ${paths.modelsConfigPath}(内附示例)`);
|
|
395
|
+
io.error("==================================================================");
|
|
396
|
+
if (!options.interactive) {
|
|
397
|
+
return readiness;
|
|
398
|
+
}
|
|
399
|
+
const controller = new AbortController();
|
|
400
|
+
const onSigint = () => controller.abort();
|
|
401
|
+
process.once("SIGINT", onSigint);
|
|
402
|
+
try {
|
|
403
|
+
const wantsLogin = options.confirmLogin
|
|
404
|
+
? await options.confirmLogin()
|
|
405
|
+
: await promptConfirmLoginOnTty(controller.signal);
|
|
406
|
+
if (!wantsLogin) {
|
|
407
|
+
io.error(`已跳过模型登录引导;随时可在新终端运行 \`${paths.appName} auth login\` 完成配置。\n`);
|
|
408
|
+
return readiness;
|
|
409
|
+
}
|
|
410
|
+
if (options.performLogin) {
|
|
411
|
+
await options.performLogin();
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
prepareAppServices(paths);
|
|
415
|
+
const runtime = await createModelRuntime({
|
|
416
|
+
authConfigPath: paths.authConfigPath,
|
|
417
|
+
modelsConfigPath: paths.modelsConfigPath,
|
|
418
|
+
});
|
|
419
|
+
await runLogin(runtime, { kind: "login", apiKey: false, oauth: false, deviceCode: false, noBrowser: false }, io, controller.signal, paths);
|
|
420
|
+
}
|
|
421
|
+
readiness = await inspectModelReadiness(paths);
|
|
422
|
+
return readiness;
|
|
423
|
+
}
|
|
424
|
+
catch (error) {
|
|
425
|
+
if (error instanceof BootstrapExitError)
|
|
426
|
+
throw error;
|
|
427
|
+
if (controller.signal.aborted || error instanceof LoginCancelledError) {
|
|
428
|
+
io.error("\n已取消启动。");
|
|
429
|
+
throw new BootstrapExitError(130);
|
|
430
|
+
}
|
|
431
|
+
throw error;
|
|
432
|
+
}
|
|
433
|
+
finally {
|
|
434
|
+
process.removeListener("SIGINT", onSigint);
|
|
435
|
+
await withTimeout("credential writes", 15_000, () => flushModelCredentials(paths.authConfigPath));
|
|
436
|
+
}
|
|
437
|
+
}
|
|
306
438
|
export async function runAuth(argv, io = console, paths = DEFAULT_BOOTSTRAP_PATHS) {
|
|
307
439
|
const parsed = parseAuthArgs(argv.slice(3));
|
|
308
440
|
if (parsed.kind === "help") {
|
|
@@ -315,11 +447,11 @@ export async function runAuth(argv, io = console, paths = DEFAULT_BOOTSTRAP_PATH
|
|
|
315
447
|
}
|
|
316
448
|
if (parsed.kind === "error") {
|
|
317
449
|
io.error(parsed.message);
|
|
318
|
-
io.error("
|
|
450
|
+
io.error("运行 `pipiclaw auth --help` 查看用法。");
|
|
319
451
|
throw new BootstrapExitError(1);
|
|
320
452
|
}
|
|
321
453
|
if (parsed.kind !== "status" && process.stdin.isTTY !== true) {
|
|
322
|
-
io.error("pipiclaw auth login/logout
|
|
454
|
+
io.error("`pipiclaw auth login/logout` 需要交互式终端(当前 stdin 不是 TTY)。");
|
|
323
455
|
throw new BootstrapExitError(1);
|
|
324
456
|
}
|
|
325
457
|
printBootstrapSummary(bootstrapAppHome(paths), io, paths);
|
|
@@ -345,5 +477,6 @@ export async function runAuth(argv, io = console, paths = DEFAULT_BOOTSTRAP_PATH
|
|
|
345
477
|
}
|
|
346
478
|
finally {
|
|
347
479
|
process.removeListener("SIGINT", onSigint);
|
|
480
|
+
await withTimeout("credential writes", 15_000, () => flushModelCredentials(paths.authConfigPath));
|
|
348
481
|
}
|
|
349
482
|
}
|
package/dist/app/home.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ export interface BootstrapIO {
|
|
|
17
17
|
export interface BootstrapResult {
|
|
18
18
|
created: string[];
|
|
19
19
|
channelTemplateCreated: boolean;
|
|
20
|
+
/** Generated once when `channel.json` is first created; only its SHA-256 hash is written to disk. */
|
|
21
|
+
initialWebApiKey?: string;
|
|
20
22
|
}
|
|
21
23
|
export declare const DEFAULT_BOOTSTRAP_PATHS: BootstrapPaths;
|
|
22
24
|
export declare class BootstrapExitError extends Error {
|
|
@@ -27,16 +29,13 @@ export declare function isBootstrapExitError(error: unknown): error is Bootstrap
|
|
|
27
29
|
export declare function readCliVersion(): string;
|
|
28
30
|
export declare function bootstrapAppHome(paths?: BootstrapPaths): BootstrapResult;
|
|
29
31
|
export declare function printBootstrapSummary(result: BootstrapResult, io?: BootstrapIO, paths?: BootstrapPaths): void;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*/
|
|
35
|
-
export declare function printFirstRunGuide(io?: BootstrapIO, paths?: BootstrapPaths): void;
|
|
32
|
+
export declare function printStartupReadySummary(io: BootstrapIO, paths: BootstrapPaths, transportNames: readonly string[], modelStatus?: {
|
|
33
|
+
ready: boolean;
|
|
34
|
+
activeModelRef: string;
|
|
35
|
+
}): void;
|
|
36
36
|
/**
|
|
37
37
|
* The one place that lists `pipiclaw`'s top-level subcommands. `parseArgs`'s own `--help` uses it;
|
|
38
|
-
* `main.ts`'s unknown-subcommand branch
|
|
39
|
-
* 2026-08-24 §1.10) — it now calls this instead, so the two can't drift apart again.
|
|
38
|
+
* `main.ts`'s unknown-subcommand branch calls this too so the two cannot drift apart.
|
|
40
39
|
*/
|
|
41
40
|
export declare function formatCliCommandsHelp(appName: string): string[];
|
|
42
41
|
export declare function parseArgs(argv: string[], paths?: BootstrapPaths, io?: BootstrapIO): void;
|