@oyasmi/pipiclaw 0.8.10 → 0.8.11-beta.3
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.md +3 -3
- package/dist/agent/channel-runner.d.ts +11 -0
- package/dist/agent/channel-runner.js +58 -27
- package/dist/agent/commands.js +2 -3
- package/dist/agent/effect-ledger.d.ts +1 -1
- package/dist/agent/effect-ledger.js +2 -2
- package/dist/agent/prompt/sections.js +3 -3
- package/dist/agent/runner-factory.d.ts +2 -0
- package/dist/agent/session-events.js +1 -1
- package/dist/main.js +6 -0
- package/dist/memory/commands.js +6 -1
- package/dist/memory/consolidation.d.ts +8 -1
- package/dist/memory/consolidation.js +34 -6
- package/dist/memory/extraction.d.ts +11 -3
- package/dist/memory/extraction.js +19 -6
- package/dist/memory/files.d.ts +2 -0
- package/dist/memory/files.js +14 -0
- package/dist/memory/maintenance-gates.d.ts +3 -0
- package/dist/memory/maintenance-gates.js +5 -2
- package/dist/memory/maintenance-jobs.js +19 -2
- package/dist/memory/maintenance-state.d.ts +29 -0
- package/dist/memory/maintenance-state.js +100 -8
- package/dist/memory/metadata.d.ts +9 -0
- package/dist/memory/metadata.js +5 -0
- package/dist/memory/probation.d.ts +21 -0
- package/dist/memory/probation.js +48 -0
- package/dist/memory/promotion.d.ts +26 -1
- package/dist/memory/promotion.js +34 -4
- package/dist/memory/recall.js +38 -19
- package/dist/memory/session-corpus.js +12 -11
- package/dist/memory/session-search.js +25 -6
- package/dist/memory/sidecar-worker.js +2 -0
- package/dist/memory/task-digest.d.ts +3 -2
- package/dist/memory/task-digest.js +22 -8
- package/dist/models/auth-cli.d.ts +25 -0
- package/dist/models/auth-cli.js +344 -0
- package/dist/models/login-ui.d.ts +35 -0
- package/dist/models/login-ui.js +145 -0
- package/dist/models/provider-login.d.ts +41 -0
- package/dist/models/provider-login.js +126 -0
- package/dist/models/utils.d.ts +6 -0
- package/dist/models/utils.js +10 -0
- package/dist/playbooks/memory-and-learning.md +7 -1
- package/dist/playbooks/outbound-media.md +7 -33
- package/dist/playbooks/runtime-orientation.md +2 -0
- package/dist/playbooks/task-closeout.md +22 -35
- package/dist/playbooks/task-delegation.md +13 -35
- package/dist/playbooks/task-driving.md +36 -56
- package/dist/playbooks/task-planning.md +26 -45
- package/dist/runtime/bootstrap.js +48 -14
- package/dist/runtime/delivery.js +8 -2
- package/dist/runtime/dingtalk.d.ts +6 -3
- package/dist/runtime/dingtalk.js +6 -39
- package/dist/runtime/events.js +4 -3
- package/dist/runtime/proxy.d.ts +36 -0
- package/dist/runtime/proxy.js +68 -0
- package/dist/runtime/store.d.ts +8 -2
- package/dist/runtime/store.js +12 -6
- package/dist/runtime/task-commands.d.ts +0 -2
- package/dist/runtime/task-commands.js +99 -112
- package/dist/runtime/task-driver.d.ts +5 -0
- package/dist/runtime/task-driver.js +155 -53
- package/dist/runtime/task-migration.d.ts +9 -0
- package/dist/runtime/task-migration.js +75 -2
- package/dist/security/command-guard.js +51 -17
- package/dist/security/path-guard.js +72 -14
- package/dist/shared/open-browser.d.ts +6 -0
- package/dist/shared/open-browser.js +22 -0
- package/dist/shared/recoverable-error.d.ts +1 -1
- package/dist/shared/recoverable-error.js +1 -1
- package/dist/subagents/tool.js +2 -0
- package/dist/tasks/control.d.ts +38 -67
- package/dist/tasks/control.js +90 -152
- package/dist/tasks/ledger.d.ts +104 -22
- package/dist/tasks/ledger.js +419 -56
- package/dist/tasks/store.d.ts +11 -10
- package/dist/tasks/store.js +58 -27
- package/dist/tasks/transitions.d.ts +8 -36
- package/dist/tasks/transitions.js +29 -54
- package/dist/tasks/verification.d.ts +2 -2
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.js +1 -0
- package/dist/tools/memory-manage.js +8 -1
- package/dist/tools/read.js +19 -5
- package/dist/tools/registry.d.ts +1 -0
- package/dist/tools/registry.js +1 -0
- package/dist/tools/task-manage/lifecycle.d.ts +1 -7
- package/dist/tools/task-manage/lifecycle.js +76 -77
- package/dist/tools/task-manage/schema.d.ts +10 -5
- package/dist/tools/task-manage/schema.js +35 -21
- package/dist/tools/task-manage/shared.d.ts +1 -1
- package/dist/tools/task-manage/shared.js +29 -30
- package/dist/tools/task-manage/types.d.ts +7 -1
- package/dist/tools/task-manage/verification.d.ts +4 -5
- package/dist/tools/task-manage/verification.js +43 -15
- package/dist/tools/task-manage.d.ts +1 -1
- package/dist/tools/task-manage.js +9 -9
- package/dist/tui/app.js +1 -2
- package/dist/tui/commands.d.ts +1 -1
- package/dist/tui/commands.js +1 -1
- package/dist/tui/turn-controller.d.ts +1 -1
- package/dist/usage/ledger.d.ts +1 -1
- package/dist/usage/ledger.js +47 -22
- package/dist/usage/render.d.ts +1 -1
- package/dist/usage/render.js +8 -6
- package/package.json +7 -6
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* readline-based `LoginUi` for `pipiclaw auth login`. All rendering goes to
|
|
3
|
+
* stderr so stdout stays free for script-consumable output (spec §5.3). The
|
|
4
|
+
* only other implementation this file's contract anticipates is a future TUI
|
|
5
|
+
* modal (spec §10) — none of this is imported from there.
|
|
6
|
+
*/
|
|
7
|
+
import { createInterface } from "node:readline/promises";
|
|
8
|
+
import { openBrowser } from "../shared/open-browser.js";
|
|
9
|
+
import { LoginCancelledError } from "./provider-login.js";
|
|
10
|
+
function hyperlink(url, label) {
|
|
11
|
+
// OSC 8 hyperlink escape; terminals that don't support it just show the fallback text.
|
|
12
|
+
return `\x1b]8;;${url}\x07${label ?? url}\x1b]8;;\x07`;
|
|
13
|
+
}
|
|
14
|
+
export class ReadlineLoginUi {
|
|
15
|
+
constructor(options = {}) {
|
|
16
|
+
this.firstSelectConsumed = false;
|
|
17
|
+
const input = options.input ?? process.stdin;
|
|
18
|
+
this.output = options.output ?? process.stderr;
|
|
19
|
+
this.rl = createInterface({ input, output: this.output });
|
|
20
|
+
this.signal = options.signal ?? new AbortController().signal;
|
|
21
|
+
this.presetFirstSelect = options.presetFirstSelect;
|
|
22
|
+
this.noBrowser = options.noBrowser ?? false;
|
|
23
|
+
}
|
|
24
|
+
async ask(prompt) {
|
|
25
|
+
if (prompt.type === "select" && this.presetFirstSelect !== undefined && !this.firstSelectConsumed) {
|
|
26
|
+
this.firstSelectConsumed = true;
|
|
27
|
+
const match = prompt.options.find((option) => option.id === this.presetFirstSelect);
|
|
28
|
+
if (match)
|
|
29
|
+
return match.id;
|
|
30
|
+
// Preset doesn't apply to this particular select — fall through to asking interactively.
|
|
31
|
+
}
|
|
32
|
+
switch (prompt.type) {
|
|
33
|
+
case "text":
|
|
34
|
+
return this.question(this.formatPrompt(prompt.message, prompt.placeholder), prompt.signal);
|
|
35
|
+
case "manual_code":
|
|
36
|
+
return this.question(this.formatPrompt(prompt.message, prompt.placeholder), prompt.signal);
|
|
37
|
+
case "secret":
|
|
38
|
+
return this.askSecret(prompt.message, prompt.placeholder, prompt.signal);
|
|
39
|
+
case "select":
|
|
40
|
+
return this.askSelect(prompt);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
notify(event) {
|
|
44
|
+
switch (event.type) {
|
|
45
|
+
case "info": {
|
|
46
|
+
this.output.write(`${event.message}\n`);
|
|
47
|
+
for (const link of event.links ?? []) {
|
|
48
|
+
this.output.write(` ${hyperlink(link.url, link.label)}\n`);
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case "auth_url": {
|
|
53
|
+
this.output.write(`${event.instructions ?? "Open this URL to continue:"}\n`);
|
|
54
|
+
this.output.write(` ${hyperlink(event.url)}\n`);
|
|
55
|
+
if (!this.noBrowser)
|
|
56
|
+
openBrowser(event.url);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
case "device_code": {
|
|
60
|
+
this.output.write(`Open ${hyperlink(event.verificationUri)} and enter this code:\n`);
|
|
61
|
+
this.output.write(` ${event.userCode}\n`);
|
|
62
|
+
if (event.expiresInSeconds) {
|
|
63
|
+
const minutes = Math.round(event.expiresInSeconds / 60);
|
|
64
|
+
this.output.write(` (expires in ~${minutes} min)\n`);
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
case "progress": {
|
|
69
|
+
this.output.write(`${event.message}\n`);
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** Release stdin so the process can exit after the login flow finishes. */
|
|
75
|
+
close() {
|
|
76
|
+
this.rl.close();
|
|
77
|
+
}
|
|
78
|
+
formatPrompt(message, placeholder) {
|
|
79
|
+
return placeholder ? `${message} (e.g. ${placeholder}) ` : `${message} `;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Shared question path. Combines the overall SIGINT signal (→
|
|
83
|
+
* `LoginCancelledError`) with a per-prompt signal (→ quiet empty-string
|
|
84
|
+
* resolution, used when `manual_code` loses its race against the OAuth
|
|
85
|
+
* callback server).
|
|
86
|
+
*/
|
|
87
|
+
async question(promptText, promptSignal) {
|
|
88
|
+
const signals = [this.signal, promptSignal].filter((value) => value !== undefined);
|
|
89
|
+
const combined = signals.length > 1 ? AbortSignal.any(signals) : signals[0];
|
|
90
|
+
try {
|
|
91
|
+
return await this.rl.question(promptText, { signal: combined });
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
if (this.signal.aborted) {
|
|
95
|
+
throw new LoginCancelledError();
|
|
96
|
+
}
|
|
97
|
+
if (promptSignal?.aborted) {
|
|
98
|
+
return "";
|
|
99
|
+
}
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async askSecret(message, placeholder, promptSignal) {
|
|
104
|
+
const promptText = this.formatPrompt(message, placeholder);
|
|
105
|
+
const rlInternal = this.rl;
|
|
106
|
+
const originalWrite = rlInternal._writeToOutput;
|
|
107
|
+
if (rlInternal.terminal !== true || !originalWrite) {
|
|
108
|
+
// Non-TTY streams (pipes, tests) are never locally echoed by readline anyway.
|
|
109
|
+
return this.question(promptText, promptSignal);
|
|
110
|
+
}
|
|
111
|
+
this.output.write(promptText);
|
|
112
|
+
rlInternal._writeToOutput = (text) => {
|
|
113
|
+
if (text === "\n" || text === "\r\n") {
|
|
114
|
+
originalWrite.call(this.rl, text);
|
|
115
|
+
}
|
|
116
|
+
// Swallow everything else so keystrokes never echo.
|
|
117
|
+
};
|
|
118
|
+
try {
|
|
119
|
+
return await this.question("", promptSignal);
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
rlInternal._writeToOutput = originalWrite;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async askSelect(prompt) {
|
|
126
|
+
this.output.write(`${prompt.message}\n`);
|
|
127
|
+
prompt.options.forEach((option, index) => {
|
|
128
|
+
const description = option.description ? ` — ${option.description}` : "";
|
|
129
|
+
this.output.write(` ${index + 1}) ${option.label}${description}\n`);
|
|
130
|
+
});
|
|
131
|
+
while (true) {
|
|
132
|
+
const raw = (await this.question("> ", prompt.signal)).trim();
|
|
133
|
+
if (raw === "")
|
|
134
|
+
return prompt.options[0].id;
|
|
135
|
+
const index = Number.parseInt(raw, 10);
|
|
136
|
+
if (Number.isInteger(index) && index >= 1 && index <= prompt.options.length) {
|
|
137
|
+
return prompt.options[index - 1].id;
|
|
138
|
+
}
|
|
139
|
+
const byId = prompt.options.find((option) => option.id.toLowerCase() === raw.toLowerCase());
|
|
140
|
+
if (byId)
|
|
141
|
+
return byId.id;
|
|
142
|
+
this.output.write(`Invalid choice: ${raw}. Enter a number 1-${prompt.options.length}.\n`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport-neutral provider login/logout/status orchestration. Imports no
|
|
3
|
+
* terminal code — the human-machine interface is the injected `LoginUi`, so a
|
|
4
|
+
* future TUI `/login` can supply a different implementation without touching
|
|
5
|
+
* this file (see docs/specs/039-provider-login-cli/design.md §10).
|
|
6
|
+
*/
|
|
7
|
+
import { type Api, type AuthEvent, type AuthPrompt, type AuthType, type Model } from "@earendil-works/pi-ai";
|
|
8
|
+
import type { ModelRuntime } from "@earendil-works/pi-coding-agent";
|
|
9
|
+
export declare class LoginCancelledError extends Error {
|
|
10
|
+
constructor(message?: string);
|
|
11
|
+
}
|
|
12
|
+
/** Human-machine interface for a login flow. Readline is the only implementation today. */
|
|
13
|
+
export interface LoginUi {
|
|
14
|
+
/** Resolves to the entered/selected value; `select` resolves to the option id. Rejects with `LoginCancelledError` on cancel. */
|
|
15
|
+
ask(prompt: AuthPrompt): Promise<string>;
|
|
16
|
+
notify(event: AuthEvent): void;
|
|
17
|
+
/** Aborts the whole login flow (SIGINT). */
|
|
18
|
+
signal: AbortSignal;
|
|
19
|
+
}
|
|
20
|
+
export interface ProviderLoginOption {
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
authType: AuthType;
|
|
24
|
+
/** OAuth subscription login label, e.g. "OpenAI (ChatGPT Plus/Pro)". */
|
|
25
|
+
loginLabel?: string;
|
|
26
|
+
configured: boolean;
|
|
27
|
+
configuredAs?: AuthType;
|
|
28
|
+
source?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface ProviderLoginResult {
|
|
31
|
+
providerId: string;
|
|
32
|
+
credentialType: AuthType;
|
|
33
|
+
/** Models newly available after login (before/after `getAvailableSnapshot()` diff). */
|
|
34
|
+
newModels: Model<Api>[];
|
|
35
|
+
}
|
|
36
|
+
/** List every provider x auth-type combination the provider supports (not just ones with an interactive `login`). */
|
|
37
|
+
export declare function listProviderLoginOptions(runtime: ModelRuntime, authType?: AuthType): ProviderLoginOption[];
|
|
38
|
+
export declare function loginProvider(runtime: ModelRuntime, providerId: string, authType: AuthType, ui: LoginUi): Promise<ProviderLoginResult>;
|
|
39
|
+
export declare function logoutProvider(runtime: ModelRuntime, providerId: string): Promise<void>;
|
|
40
|
+
/** Render the `pipiclaw auth status` report: one row per provider, plus the auth.json path and any models.json error. */
|
|
41
|
+
export declare function renderAuthStatus(runtime: ModelRuntime, authPath: string): Promise<string>;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport-neutral provider login/logout/status orchestration. Imports no
|
|
3
|
+
* terminal code — the human-machine interface is the injected `LoginUi`, so a
|
|
4
|
+
* future TUI `/login` can supply a different implementation without touching
|
|
5
|
+
* this file (see docs/specs/039-provider-login-cli/design.md §10).
|
|
6
|
+
*/
|
|
7
|
+
import { ModelsError, } from "@earendil-works/pi-ai";
|
|
8
|
+
export class LoginCancelledError extends Error {
|
|
9
|
+
constructor(message = "登录已取消") {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "LoginCancelledError";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function modelKey(model) {
|
|
15
|
+
return `${model.provider}/${model.id}`;
|
|
16
|
+
}
|
|
17
|
+
/** List every provider x auth-type combination the provider supports (not just ones with an interactive `login`). */
|
|
18
|
+
export function listProviderLoginOptions(runtime, authType) {
|
|
19
|
+
const options = [];
|
|
20
|
+
for (const provider of runtime.getProviders()) {
|
|
21
|
+
const status = runtime.getProviderAuthStatus(provider.id);
|
|
22
|
+
const configuredAs = status.configured
|
|
23
|
+
? runtime.isUsingOAuth(provider.id)
|
|
24
|
+
? "oauth"
|
|
25
|
+
: "api_key"
|
|
26
|
+
: undefined;
|
|
27
|
+
if (provider.auth.oauth && (!authType || authType === "oauth")) {
|
|
28
|
+
options.push({
|
|
29
|
+
id: provider.id,
|
|
30
|
+
name: provider.name,
|
|
31
|
+
authType: "oauth",
|
|
32
|
+
loginLabel: provider.auth.oauth.loginLabel ?? provider.auth.oauth.name,
|
|
33
|
+
configured: status.configured,
|
|
34
|
+
configuredAs,
|
|
35
|
+
source: status.source,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (provider.auth.apiKey && (!authType || authType === "api_key")) {
|
|
39
|
+
options.push({
|
|
40
|
+
id: provider.id,
|
|
41
|
+
name: provider.name,
|
|
42
|
+
authType: "api_key",
|
|
43
|
+
configured: status.configured,
|
|
44
|
+
configuredAs,
|
|
45
|
+
source: status.source,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return options.sort((a, b) => a.name.localeCompare(b.name) || a.authType.localeCompare(b.authType));
|
|
50
|
+
}
|
|
51
|
+
/** Turn an SDK-level failure into a message with an actionable next step. Cancellation passes through untouched. */
|
|
52
|
+
function humanizeLoginError(providerId, error) {
|
|
53
|
+
if (error instanceof LoginCancelledError)
|
|
54
|
+
return error;
|
|
55
|
+
if (error instanceof ModelsError) {
|
|
56
|
+
const hint = error.code === "oauth"
|
|
57
|
+
? "OAuth 流程失败,请重新执行 `pipiclaw auth login` 并在有效期内完成授权(device code 有效期 15 分钟)。"
|
|
58
|
+
: error.code === "auth"
|
|
59
|
+
? "认证失败,请确认输入的凭据正确后重试。"
|
|
60
|
+
: error.code === "provider"
|
|
61
|
+
? `provider "${providerId}" 配置有误,请检查 models.json。`
|
|
62
|
+
: "请重试;如反复失败可改用 --api-key 或 --oauth 明确认证方式。";
|
|
63
|
+
return new Error(`${error.message}\n${hint}`, { cause: error });
|
|
64
|
+
}
|
|
65
|
+
if (error instanceof Error) {
|
|
66
|
+
return new Error(`登录失败:${error.message}\n请检查网络连接后重试;如配置了 PIPICLAW_PROXY,确认代理可达。`, {
|
|
67
|
+
cause: error,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return new Error(`登录失败:${String(error)}`);
|
|
71
|
+
}
|
|
72
|
+
export async function loginProvider(runtime, providerId, authType, ui) {
|
|
73
|
+
const before = runtime.getAvailableSnapshot();
|
|
74
|
+
let credential;
|
|
75
|
+
try {
|
|
76
|
+
credential = await runtime.login(providerId, authType, {
|
|
77
|
+
signal: ui.signal,
|
|
78
|
+
prompt: (prompt) => ui.ask(prompt),
|
|
79
|
+
notify: (event) => ui.notify(event),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
throw humanizeLoginError(providerId, error);
|
|
84
|
+
}
|
|
85
|
+
const after = runtime.getAvailableSnapshot();
|
|
86
|
+
const beforeKeys = new Set(before.map(modelKey));
|
|
87
|
+
const newModels = after.filter((model) => !beforeKeys.has(modelKey(model)));
|
|
88
|
+
return { providerId, credentialType: credential.type, newModels };
|
|
89
|
+
}
|
|
90
|
+
export async function logoutProvider(runtime, providerId) {
|
|
91
|
+
await runtime.logout(providerId);
|
|
92
|
+
}
|
|
93
|
+
/** Render the `pipiclaw auth status` report: one row per provider, plus the auth.json path and any models.json error. */
|
|
94
|
+
export async function renderAuthStatus(runtime, authPath) {
|
|
95
|
+
const providers = runtime
|
|
96
|
+
.getProviders()
|
|
97
|
+
.slice()
|
|
98
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
99
|
+
const rows = providers.map((provider) => {
|
|
100
|
+
const status = runtime.getProviderAuthStatus(provider.id);
|
|
101
|
+
const type = status.configured ? (runtime.isUsingOAuth(provider.id) ? "oauth" : "api_key") : "-";
|
|
102
|
+
return {
|
|
103
|
+
name: provider.name,
|
|
104
|
+
configured: status.configured ? "yes" : "no",
|
|
105
|
+
type,
|
|
106
|
+
source: status.source ?? status.label ?? "-",
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
const nameWidth = Math.max(8, ...rows.map((row) => row.name.length));
|
|
110
|
+
const configuredWidth = Math.max(10, ...rows.map((row) => row.configured.length));
|
|
111
|
+
const typeWidth = Math.max(4, ...rows.map((row) => row.type.length));
|
|
112
|
+
const lines = [
|
|
113
|
+
`${"Provider".padEnd(nameWidth)} ${"Configured".padEnd(configuredWidth)} ${"Type".padEnd(typeWidth)} Source`,
|
|
114
|
+
];
|
|
115
|
+
for (const row of rows) {
|
|
116
|
+
lines.push(`${row.name.padEnd(nameWidth)} ${row.configured.padEnd(configuredWidth)} ${row.type.padEnd(typeWidth)} ${row.source}`);
|
|
117
|
+
}
|
|
118
|
+
lines.push("");
|
|
119
|
+
lines.push(`auth.json: ${authPath}`);
|
|
120
|
+
const modelsError = runtime.getError();
|
|
121
|
+
if (modelsError) {
|
|
122
|
+
lines.push(`models.json error: ${modelsError}`);
|
|
123
|
+
}
|
|
124
|
+
lines.push("Note: a running daemon or TUI session must be restarted to pick up new credentials.");
|
|
125
|
+
return lines.join("\n");
|
|
126
|
+
}
|
package/dist/models/utils.d.ts
CHANGED
|
@@ -6,6 +6,12 @@ export declare const defaultModel: Model<"anthropic-messages">;
|
|
|
6
6
|
* Construct the canonical async model/auth runtime (replaces the old
|
|
7
7
|
* `AuthStorage.create` + `ModelRegistry` pairing). pi 0.80.8+ folded auth and
|
|
8
8
|
* model resolution into a single async `ModelRuntime`.
|
|
9
|
+
*
|
|
10
|
+
* `authConfigPath` must always be given explicitly and be absolute: pipiclaw
|
|
11
|
+
* never wants `AuthStorage`'s undefined-path fallback to `~/.pi/agent/auth.json`
|
|
12
|
+
* (spec 039 §4). Do not call the SDK's `getAuthPath()` / `getAgentDir()` /
|
|
13
|
+
* no-arg `readStoredCredential()`, and do not set `PI_CODING_AGENT_DIR` —
|
|
14
|
+
* all three can silently move credential I/O away from `APP_HOME_DIR`.
|
|
9
15
|
*/
|
|
10
16
|
export declare function createModelRuntime(options: {
|
|
11
17
|
authConfigPath: string;
|
package/dist/models/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isAbsolute } from "node:path";
|
|
1
2
|
import { getBuiltinModel as getModel } from "@earendil-works/pi-ai/providers/all";
|
|
2
3
|
import { ModelRegistry, ModelRuntime } from "@earendil-works/pi-coding-agent";
|
|
3
4
|
// Default model - will be overridden by ModelRegistry if custom models are configured
|
|
@@ -6,8 +7,17 @@ export const defaultModel = getModel("anthropic", "claude-sonnet-4-5");
|
|
|
6
7
|
* Construct the canonical async model/auth runtime (replaces the old
|
|
7
8
|
* `AuthStorage.create` + `ModelRegistry` pairing). pi 0.80.8+ folded auth and
|
|
8
9
|
* model resolution into a single async `ModelRuntime`.
|
|
10
|
+
*
|
|
11
|
+
* `authConfigPath` must always be given explicitly and be absolute: pipiclaw
|
|
12
|
+
* never wants `AuthStorage`'s undefined-path fallback to `~/.pi/agent/auth.json`
|
|
13
|
+
* (spec 039 §4). Do not call the SDK's `getAuthPath()` / `getAgentDir()` /
|
|
14
|
+
* no-arg `readStoredCredential()`, and do not set `PI_CODING_AGENT_DIR` —
|
|
15
|
+
* all three can silently move credential I/O away from `APP_HOME_DIR`.
|
|
9
16
|
*/
|
|
10
17
|
export async function createModelRuntime(options) {
|
|
18
|
+
if (!options.authConfigPath || !isAbsolute(options.authConfigPath)) {
|
|
19
|
+
throw new Error(`createModelRuntime: authConfigPath must be a non-empty absolute path, got ${JSON.stringify(options.authConfigPath)}`);
|
|
20
|
+
}
|
|
11
21
|
return ModelRuntime.create({
|
|
12
22
|
authPath: options.authConfigPath,
|
|
13
23
|
modelsPath: options.modelsConfigPath,
|
|
@@ -25,10 +25,16 @@ priority: 20
|
|
|
25
25
|
|
|
26
26
|
## 什么时候立即写 durable memory
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
用户明确说”记住、以后默认、偏好、不要再做、忘掉”时,立即调用 `memory_manage`,不要等待后台 consolidation。只保存未来仍有用的事实;一次性进度、猜测、临时计划放 task 或留在当前会话。这条路径写入的记忆立即是永久的,不受下面的试用期约束。
|
|
29
29
|
|
|
30
30
|
查找时先用具体关键词。忘记或替换旧规则时用 `forget`,不要追加一条互相矛盾的新记忆。
|
|
31
31
|
|
|
32
|
+
## 后台自动写入与试用期
|
|
33
|
+
|
|
34
|
+
后台 consolidation 按两档写入 channel `MEMORY.md`:明确会导致未来回合出错的硬约束(`necessity: high`)直接永久写入;日常运作知识——谁负责哪块、术语默认含义、发布或命名惯例、流程签批人(`necessity: medium`)——以**试用期**条目写入,默认 30 天。试用期条目在这期间被召回一次即转正为永久;从未被用到则到期后自动失效。失效不是遗忘:内容仍可在之后被重新学到,只是这一次没被用上。
|
|
35
|
+
|
|
36
|
+
不要把这套阈值当作可调节的旋钮——它是代码常量,不在 `settings.json` 里。
|
|
37
|
+
|
|
32
38
|
## ENVIRONMENT.md
|
|
33
39
|
|
|
34
40
|
记录未来回合需要知道的机器事实,例如安装的工具、重要环境变量来源、代码仓库之外修改的配置、运行前提。不要放聊天摘要、任务进度、密钥值或用户偏好。
|
|
@@ -7,39 +7,13 @@ priority: 25
|
|
|
7
7
|
|
|
8
8
|
# 附件交付(outbound media)
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
产物真正到了用户手里才算交付。使用 `send_media` 发送 workspace 内的文件;成功后把附件名、目标 channel、message id 和时间写进任务 Current Cycle 或 completion evidence。
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
发送前检查:
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
- 文件已经生成且非空;
|
|
15
|
+
- 目标仍在 task Goal 范围内;
|
|
16
|
+
- 查询或记录已有 message/request id,避免 crash replay 重复发送;
|
|
17
|
+
- 发送后查询真实投递状态,失败则 progress 为 active/waiting 并写 recovery source。
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
- 给自己看文件内容用 `read`,不要先发给用户再阅读。
|
|
19
|
-
- 几行文本、一小段代码、一个结论:直接写在回复里,附件反而更难读。
|
|
20
|
-
- 只把路径贴给用户(如 `/home/.../report.pdf`)。用户在钉钉里打不开主机路径;这正是本工具存在的原因。
|
|
21
|
-
|
|
22
|
-
## 调用约定
|
|
23
|
-
|
|
24
|
-
```
|
|
25
|
-
send_media label="本周巡检报告" path="reports/2026-W29.pdf" fileName="巡检报告-2026-W29.pdf"
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
- `label`:说明你在发什么、为什么发,会展示给用户。
|
|
29
|
-
- `path`:workspace 相对路径或绝对路径,经与 `read` 相同的 path guard。
|
|
30
|
-
- `fileName`:可选的收件显示名,默认取文件本身的名字。想让用户看到有意义的名字就显式传。
|
|
31
|
-
|
|
32
|
-
`.jpg .jpeg .png .gif .webp .bmp` 按图片内联,其余一律按文件下载。**目标 channel 由运行时绑定**,不是参数——你无法也不需要指定发给谁,当前对话就是目的地。
|
|
33
|
-
|
|
34
|
-
## 失败与下一步
|
|
35
|
-
|
|
36
|
-
| 报错 | 含义 | 下一步 |
|
|
37
|
-
|---|---|---|
|
|
38
|
-
| `Path blocked [...]` | 路径被 path guard 拒绝 | 把产物写到 workspace 内再发,不要绕守卫 |
|
|
39
|
-
| `not a regular file (does it exist?)` | 路径不存在或是目录 | 先确认产物真的生成了;目录先打包成单个文件 |
|
|
40
|
-
| `the file is empty` | 生成步骤静默失败了 | 回去查生成命令的退出码和输出,别重发空文件 |
|
|
41
|
-
| 发送失败(transport 报错) | 渠道侧拒绝或超限 | 文件过大时改发摘要 + 关键片段,或拆分后重试 |
|
|
42
|
-
|
|
43
|
-
## 与任务台账的关系
|
|
44
|
-
|
|
45
|
-
任务(task)的产物交付属于**结果**,不是日志:发送成功后,把"已作为附件发给用户"写进该轮的 progress note 或 done evidence,让后续唤醒不会重复投递同一份产物。若发送是任务的外部副作用(`sideEffects: external`)的一部分,遵守 `task-closeout.md` 的审批(approval)门禁,不要先发后批。
|
|
19
|
+
send_media 的 path guard、文件类型和 transport 失败信息会给出可执行 next step。不要把主机路径当作用户可下载附件;不要因为一次调用返回成功就跳过真实结果核对。
|
|
@@ -1,52 +1,39 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: task-closeout
|
|
3
|
-
description: 独立验收(verify
|
|
3
|
+
description: 独立验收(verify)、导入判定,或 complete/skip/cancel 任务前。
|
|
4
4
|
requires-tools: task_manage
|
|
5
5
|
priority: 42
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
#
|
|
9
|
-
|
|
10
|
-
本文件是验收(verify)与外部审批(approval)门禁规则的唯一真相源,`task-driving.md` 与 `task-planning.md` 只保留指针。
|
|
8
|
+
# 验收与闭环
|
|
11
9
|
|
|
12
10
|
## 独立验收
|
|
13
11
|
|
|
14
|
-
1.
|
|
15
|
-
2.
|
|
16
|
-
3. checker
|
|
17
|
-
4.
|
|
18
|
-
5.
|
|
19
|
-
|
|
20
|
-
FAIL 后用 progress 记录失败证据、status 回 active,修复后重新 candidate。不要让 verifier 顺手修实现。
|
|
21
|
-
|
|
22
|
-
**PASS 绑定契约、不绑日志**:PASS 之后照常 `progress` 记 Current Cycle 日志不会使 PASS 失效;只有改动契约段(Goal/DoD/Manual/Verification 或勾选状态)才会失效。改了契约就诚实重跑验收。
|
|
23
|
-
|
|
24
|
-
## 外部副作用
|
|
25
|
-
|
|
26
|
-
`sideEffects: external` 要求用户通过 `/tasks approve <id>` 授权;agent 不能自授予。授权同样绑定契约段 hash:批准后照常记日志无妨,但改动契约正文会要求重新授权。
|
|
27
|
-
|
|
28
|
-
只做 external、无需 independent verification 时:准备动作 → progress 置 waiting 并请求审批 → 用户 approve → 执行动作 → 直接 done。
|
|
29
|
-
|
|
30
|
-
## independent + external 同时存在
|
|
31
|
-
|
|
32
|
-
契约-绑定的 hash 让两个门不再相互误伤,日常顺序很简单:
|
|
12
|
+
1. 只有在证据成立后勾选 DoD/Verification checklist。
|
|
13
|
+
2. 调用 `task_manage request-verification`;任务进入 `waiting + waitingFor: verification`,runtime 直接入队 checker。
|
|
14
|
+
3. checker 使用 `purpose: verify`、`taskId`,只读检查,结尾返回 `VERDICT: PASS` 或 `VERDICT: FAIL`。
|
|
15
|
+
4. 主回合用 `task_manage verify` 导入 runId。attestation 必须属于当前 task、未改变 workspace,且 contract body hash 与 artifact subject 新鲜。
|
|
16
|
+
5. PASS/FAIL 都恢复 active;PASS 后 complete 仍会重新校验 attestation、contract hash 和 artifact subject。
|
|
33
17
|
|
|
34
|
-
|
|
35
|
-
2. candidate → verifier → `task_manage verify` 得到 PASS。
|
|
36
|
-
3. 等待审批:用 `task_manage set wake=<合理时间>` 保留在 `verifying` 车道(**只改 wake,不换状态**——离开 verifying 的 set 会作废 PASS),并请求用户 `/tasks approve <id>`。此时记日志无妨。
|
|
37
|
-
4. 用户批准后,driver 在 wake 到期接续;确认 PASS、approvalBodyHash 与当前产物仍新鲜。
|
|
38
|
-
5. 执行已批准的外部动作,然后直接 done;结果写入 done 的 summary/evidence。
|
|
18
|
+
PASS 绑定 Goal/DoD/Manual/Verification contract segment,不绑定 Current Cycle、History 或 Plan 日志。改动 contract 或被验收的产物后必须重新验收。不要让 verifier 顺手修实现。
|
|
39
19
|
|
|
40
|
-
|
|
20
|
+
## 外部动作的幂等闭环
|
|
41
21
|
|
|
42
|
-
|
|
22
|
+
外部发送、发布、部署或修改前:
|
|
43
23
|
|
|
44
|
-
|
|
24
|
+
1. 读任务 Goal 和 DoD,确认动作仍在范围内。
|
|
25
|
+
2. 查询目标真实状态,确认此前没有已经成功的同一动作。
|
|
26
|
+
3. 使用稳定 request/message/idempotency key 执行。
|
|
27
|
+
4. 查询并记录真实结果、目标标识、时间和证据到 Current Cycle。
|
|
28
|
+
5. 只有结果已满足 DoD 才 complete;失败则 progress 为 active 或 waiting 并写 recovery source。
|
|
45
29
|
|
|
46
|
-
|
|
30
|
+
Task 创建即持续委托;能力边界和任务 scope 是 authority。不要扩大目标、渠道、环境或对象范围,也不要把“本次调用返回成功”当成外部状态已落地。
|
|
47
31
|
|
|
48
|
-
|
|
32
|
+
## complete / skip / cancel
|
|
49
33
|
|
|
50
|
-
|
|
34
|
+
- `task_manage complete` 需要 summary、evidence 和已满足的 acceptance checklist;required verification 必须有有效 PASS。one-shot 会写 `outcome: completed`、`closedAt` 并移入 archive。
|
|
35
|
+
- recurring complete 写 completion evidence、清理 task-owned events、计算下一 occurrence,回到 sleeping。
|
|
36
|
+
- `task_manage skip` 只接受 recurring active/waiting,记录 reason,不伪造 DoD 或 completion evidence,然后 sleeping。
|
|
37
|
+
- `task_manage cancel` 从任一 live status 归档为 `outcome: cancelled`,记录 reason 并清理 task-owned events。
|
|
51
38
|
|
|
52
|
-
|
|
39
|
+
如果 occurrence 已被更早的触发完成,使用 skip 写明原因并回复 `[SILENT]`;否则向用户说明结果、风险和下一步。
|
|
@@ -1,52 +1,30 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: task-delegation
|
|
3
|
-
description:
|
|
3
|
+
description: 拆分任务(task)、委派子代理(subagent),或等待外部 agent/job 的恢复信号时。
|
|
4
4
|
requires-tools: task_manage, subagent
|
|
5
5
|
priority: 45
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# 任务分解与委派
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
只拆真正可分离、可独立验收的工作。任务之间没有依赖字段;先后条件写进后继任务 Goal/Manual 或由 wake 错开。
|
|
11
11
|
|
|
12
|
-
##
|
|
12
|
+
## 子代理
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
委派说明必须包含目标、范围、路径、约束、验收方法和返回格式。独立验收使用 `purpose: verify` + `taskId`,verifier 不能 write/edit,结果写 durable attestation。主 Agent 负责 review、验证和台账闭环。
|
|
15
15
|
|
|
16
|
-
##
|
|
16
|
+
## 外部 agent 与等待
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
本页是 waiting 两种形态的唯一真相源;`waiting + wake` 是定时等待,`waiting` 无 wake 是停泊信号等待。后台作业的实现细节见 `background-jobs.md`。
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
runtime 不假设第三方工具的命令、状态协议或检测脚本。优先使用用户提供的 skill;等待形态按恢复能力选择:
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
1. 有阻塞等待命令:用 `bash async` + `taskId`,progress 为 `waiting`、`waitingFor: job`、不设 wake。job 完成时 runtime 只恢复所属 task。
|
|
23
|
+
2. 只有状态查询:用 event sensor 或 `waiting + wake`,把回访条件写进 blockedReason。
|
|
24
|
+
3. 没有可用信号:等待用户时 `waitingFor: user`、无 wake,或让用户用 `/tasks run <id>`。
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
普通 driver 不轮询 `waiting` 无 wake。所有外部动作都要写任务 scope、实例标识、工作目录、预期产物、验收方法、幂等 request id 和 recovery plan。
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
## 产物与闭环
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
## 文件系统隔离
|
|
31
|
-
|
|
32
|
-
没有。子代理默认与主代理共享同一个 checkout,只隔离对话上下文。需要在独立检出上作业时,在宿主侧自行 `git worktree add`,把该路径作为 `workingDirectory` 传给子代理(它是子代理的 shell cwd 与相对路径根,必须已存在),并自己负责 review、merge 与清理。`purpose: verify` 的 attestation 会绑定该目录的 git 产物状态,后续 `task_manage verify` / `done` 也在同一目录复算。
|
|
33
|
-
|
|
34
|
-
## 外部 agent 工具
|
|
35
|
-
|
|
36
|
-
Pipiclaw 不内置或假设第三方 agent 工具的命令、状态 JSON、检测脚本。如何启动、探活、取回、steer 由用户安装的可执行文件和 workspace skill 决定——先读那份 skill,再决定用哪条命令,不要临时复制来源不明的脚本。
|
|
37
|
-
|
|
38
|
-
启动、纠偏、取回、停止都是秒级的同步命令,直接 `bash` 调用即可。runtime 只补它们补不了的那一块:**你不在场的那段等待**。按用户工具的能力从优到劣选一条:
|
|
39
|
-
|
|
40
|
-
1. **阻塞等待包成后台作业(首选)**:工具若提供"等到外部实例结束/空闲才返回"的命令,用 `bash async` + `taskId` 跑它,`progress` 置 `waiting` 且**不设 wake**,然后结束回合——作业结束时 runtime 自动叫醒你并带上输出尾部,见 `background-jobs.md`。作业超时只终止等待本身,不会杀掉外部实例:醒来确认对方还在跑,再起一个等待作业即可。给等待作业一个明显长于预计耗时的 `timeout`,别让它每五分钟叫你一次。
|
|
41
|
-
2. **稳定的完成态检测命令**:只有状态查询、没有阻塞等待时,按 `event-scheduling.md` 用 periodic + preAction 门控——对方忙就静默跳过,零 token。
|
|
42
|
-
3. **wake 轮询(兜底)**:两者都没有时才用,`progress` 置 `waiting` + 合理 `wake`,醒来查状态、更新证据、必要时把 wake 推后。
|
|
43
|
-
|
|
44
|
-
两种等待形态就这两个(本节是唯一真相源):**`waiting` 且无 `wake` = 停泊**,driver 不会来打扰,只有后台作业结束、用户消息或 `/tasks run` 会叫醒你;**`waiting` + `wake` = 定时回访**,到点由 driver 接续。
|
|
45
|
-
|
|
46
|
-
无论走哪条,三条纪律不变:
|
|
47
|
-
|
|
48
|
-
1. 委派时把工具、实例标识、工作目录/分支、预期产物和验收方法写进 task 正文,等谁、等什么写进 `blockedReason`。重启后这些是唯一能恢复现场的东西。
|
|
49
|
-
2. 取回后自己 review 和验证。对方报告完成、进程退出码为 0、实例回到空闲,都不是验收证据。
|
|
50
|
-
3. task 闭环前清理临时事件和外部实例。
|
|
51
|
-
|
|
52
|
-
任何委派都不能转移最终交付责任。父代理必须确认成果已进入目标 checkout,而不是只停留在外部实例或口头报告中。
|
|
30
|
+
重要产物写入目标 checkout,不只留在 stdout 或 subagent 返回文本。取回后核对真实文件和测试结果,再 progress/verify/complete。task cancel/complete 会清理 task-owned events;不要遗留一个会继续唤醒已归档任务的事件。
|